Gfxprim
Threads by month
- ----- 2026 -----
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- 929 discussions
[repo.or.cz] gfxprim.git branch master updated: 2b7d85a804de2382d10e8f6ea2153b0e47b3e6e0
by metan 12 May '12
by metan 12 May '12
12 May '12
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project gfxprim.git.
The branch, master has been updated
via 2b7d85a804de2382d10e8f6ea2153b0e47b3e6e0 (commit)
from 790d61419cab392ce0c0b2468bf43f2c554c666b (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
http://repo.or.cz/w/gfxprim.git/commit/2b7d85a804de2382d10e8f6ea2153b0e47b3…
commit 2b7d85a804de2382d10e8f6ea2153b0e47b3e6e0
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Sat May 12 18:12:58 2012 +0200
backend, input: Add optional support for console keys.
diff --git a/include/backends/GP_LinuxFB.h b/include/backends/GP_LinuxFB.h
index 1fac9a4..2dcc1c9 100644
--- a/include/backends/GP_LinuxFB.h
+++ b/include/backends/GP_LinuxFB.h
@@ -35,7 +35,9 @@
* deinitalized and the structure is freed by backed->Exit(backend); call.
*
* Upon failure NULL is returned.
+ *
+ * If flag is set, the konsole kbd is used to push events into event queue.
*/
-GP_Backend *GP_BackendLinuxFBInit(const char *path);
+GP_Backend *GP_BackendLinuxFBInit(const char *path, int flag);
#endif /* BACKENDS_GP_FRAMEBUFFER_H */
diff --git a/include/backends/GP_LinuxFB.h b/include/input/GP_InputDriverKBD.h
similarity index 77%
copy from include/backends/GP_LinuxFB.h
copy to include/input/GP_InputDriverKBD.h
index 1fac9a4..4212bd7 100644
--- a/include/backends/GP_LinuxFB.h
+++ b/include/input/GP_InputDriverKBD.h
@@ -20,22 +20,17 @@
* *
*****************************************************************************/
-#ifndef BACKENDS_GP_FRAMEBUFFER_H
-#define BACKENDS_GP_FRAMEBUFFER_H
+/*
+
+
+ */
-#include "GP_Backend.h"
+#ifndef GP_INPUT_DRIVER_KBD_H
+#define GP_INPUT_DRIVER_KBD_H
/*
- * Initalize framebuffer.
- *
- * The path should point to framebuffer device eg. "/dev/fb0" for first
- * framebuffer device.
- *
- * The GP_Backend structure is allocated and returned, the resources are
- * deinitalized and the structure is freed by backed->Exit(backend); call.
- *
- * Upon failure NULL is returned.
+ * Converts KBD event to GFXprim event and puts it into the queue.
*/
-GP_Backend *GP_BackendLinuxFBInit(const char *path);
+void GP_InputDriverKBDEventPut(unsigned char ev);
-#endif /* BACKENDS_GP_FRAMEBUFFER_H */
+#endif /* GP_INPUT_DRIVER_KBD_H */
diff --git a/libs/backends/GP_BackendInit.c b/libs/backends/GP_BackendInit.c
index 0f8e8d4..fb49b92 100644
--- a/libs/backends/GP_BackendInit.c
+++ b/libs/backends/GP_BackendInit.c
@@ -121,7 +121,7 @@ static GP_Backend *backend_fb_init(char *params, const char *caption,
if (params != NULL)
fb = params;
- return GP_BackendLinuxFBInit(fb);
+ return GP_BackendLinuxFBInit(fb, 1);
}
static void backend_x11_help(FILE *help, const char *err)
diff --git a/libs/backends/GP_LinuxFB.c b/libs/backends/GP_LinuxFB.c
index 3a511c3..654989d 100644
--- a/libs/backends/GP_LinuxFB.c
+++ b/libs/backends/GP_LinuxFB.c
@@ -27,12 +27,15 @@
#include <fcntl.h>
#include <string.h>
#include <errno.h>
+#include <termios.h>
+#include <unistd.h>
#include <linux/fb.h>
#include <linux/kd.h>
#include <linux/vt.h>
#include "core/GP_Debug.h"
+#include "input/GP_InputDriverKBD.h"
#include "GP_LinuxFB.h"
struct fb_priv {
@@ -48,23 +51,23 @@ struct fb_priv {
/*
* Allocates and switches to newly allocated console.
*/
-static int allocate_console(struct fb_priv *fb)
+static int allocate_console(struct fb_priv *fb, int flag)
{
struct vt_stat vts;
int fd, nr;
char buf[255];
/* allocate and switch to new console */
- fd = open("/dev/tty1", O_WRONLY);
+ fd = open("/dev/tty0", O_WRONLY);
if (fd < 0) {
- GP_DEBUG(1, "Opening console /dev/tty1 failed: %s",
+ GP_DEBUG(1, "Opening console /dev/tty0 failed: %s",
strerror(errno));
return -1;
}
if (ioctl(fd, VT_OPENQRY, &nr) < 0) {
- GP_DEBUG(1, "Failed to ioctl VT_OPENQRY /dev/tty1: %s",
+ GP_DEBUG(1, "Failed to ioctl VT_OPENQRY /dev/tty0: %s",
strerror(errno));
close(fd);
return -1;
@@ -100,14 +103,35 @@ static int allocate_console(struct fb_priv *fb)
close(fd);
return -1;
}
-
+
/* turn off blinking cursor */
if (ioctl(fd, KDSETMODE, KD_GRAPHICS) < 0) {
GP_DEBUG(1, "Failed to ioctl KDSETMODE %s: %s",
buf, strerror(errno));
close(fd);
+ return -1;
}
+
+ /* set keyboard to raw mode */
+ if (flag) {
+ struct termios t;
+ cfmakeraw(&t);
+
+ if (tcsetattr(fd, TCSANOW, &t) < 0) {
+ GP_DEBUG(1, "Failed to tcsetattr(): %s",
+ strerror(errno));
+ close(fd);
+ return -1;
+ }
+ if (ioctl(fd, KDSKBMODE, K_MEDIUMRAW) < 0) {
+ GP_DEBUG(1, "Failed to ioctl KDSKBMODE %s: %s",
+ buf, strerror(errno));
+ close(fd);
+ return -1;
+ }
+ }
+
fb->con_nr = nr;
fb->con_fd = fd;
@@ -130,6 +154,18 @@ static void fb_update_rect_noop(GP_Backend *self __attribute__((unused)),
}
+static void fb_poll(GP_Backend *self)
+{
+ struct fb_priv *fb = GP_BACKEND_PRIV(self);
+ unsigned char buf[16];
+ int i, res;
+
+ res = read(fb->con_fd, buf, sizeof(buf));
+
+ for (i = 0; i < res; i++)
+ GP_InputDriverKBDEventPut(buf[i]);
+}
+
static void fb_exit(GP_Backend *self)
{
struct fb_priv *fb = GP_BACKEND_PRIV(self);
@@ -149,7 +185,7 @@ static void fb_exit(GP_Backend *self)
free(self);
}
-GP_Backend *GP_BackendLinuxFBInit(const char *path)
+GP_Backend *GP_BackendLinuxFBInit(const char *path, int flag)
{
GP_Backend *backend;
struct fb_priv *fb;
@@ -165,7 +201,7 @@ GP_Backend *GP_BackendLinuxFBInit(const char *path)
fb = GP_BACKEND_PRIV(backend);
- if (allocate_console(fb))
+ if (allocate_console(fb, flag))
goto err1;
/* open and mmap framebuffer */
@@ -240,7 +276,7 @@ GP_Backend *GP_BackendLinuxFBInit(const char *path)
backend->Exit = fb_exit;
backend->SetAttributes = NULL;
backend->fd_list = NULL;
- backend->Poll = NULL;
+ backend->Poll = flag ? fb_poll : NULL;
return backend;
err3:
diff --git a/libs/input/GP_InputDriverKBD.c b/libs/input/GP_InputDriverKBD.c
new file mode 100644
index 0000000..c598c37
--- /dev/null
+++ b/libs/input/GP_InputDriverKBD.c
@@ -0,0 +1,79 @@
+/*****************************************************************************
+ * This file is part of gfxprim library. *
+ * *
+ * Gfxprim is free software; you can redistribute it and/or *
+ * modify it under the terms of the GNU Lesser General Public *
+ * License as published by the Free Software Foundation; either *
+ * version 2.1 of the License, or (at your option) any later version. *
+ * *
+ * Gfxprim is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with gfxprim; if not, write to the Free Software *
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
+ * Boston, MA 02110-1301 USA *
+ * *
+ * Copyright (C) 2009-2012 Cyril Hrubis <metan(a)ucw.cz> *
+ * *
+ *****************************************************************************/
+
+#include "core/GP_Debug.h"
+#include "GP_Event.h"
+#include "GP_InputDriverKBD.h"
+
+/* KBD raw mode keycodes */
+static uint16_t keycode_table[] = {
+ GP_KEY_ESC, GP_KEY_1, GP_KEY_2, GP_KEY_3,
+ GP_KEY_4, GP_KEY_5, GP_KEY_6, GP_KEY_7,
+ GP_KEY_8, GP_KEY_9, GP_KEY_0, GP_KEY_MINUS,
+ GP_KEY_EQUAL, GP_KEY_BACKSPACE, GP_KEY_TAB, GP_KEY_Q,
+ GP_KEY_W, GP_KEY_E, GP_KEY_R, GP_KEY_T,
+ GP_KEY_Y, GP_KEY_U, GP_KEY_I, GP_KEY_O,
+ GP_KEY_P, GP_KEY_LEFT_BRACE, GP_KEY_RIGHT_BRACE, GP_KEY_ENTER,
+ GP_KEY_LEFT_CTRL, GP_KEY_A, GP_KEY_S, GP_KEY_D,
+ GP_KEY_F, GP_KEY_G, GP_KEY_H, GP_KEY_J,
+ GP_KEY_K, GP_KEY_L, GP_KEY_SEMICOLON, GP_KEY_APOSTROPHE,
+ GP_KEY_GRAVE, GP_KEY_LEFT_SHIFT, GP_KEY_BACKSLASH, GP_KEY_Z,
+ GP_KEY_X, GP_KEY_C, GP_KEY_V, GP_KEY_B,
+ GP_KEY_N, GP_KEY_M, GP_KEY_COMMA, 0,
+ GP_KEY_SLASH, GP_KEY_RIGHT_SHIFT, GP_KEY_KP_ASTERISK, GP_KEY_LEFT_ALT,
+ GP_KEY_SPACE, GP_KEY_CAPS_LOCK, GP_KEY_F1, GP_KEY_F2,
+ GP_KEY_F3, GP_KEY_F4, GP_KEY_F5, GP_KEY_F6,
+ GP_KEY_F7, GP_KEY_F8, GP_KEY_F9, GP_KEY_F10,
+ GP_KEY_NUM_LOCK, GP_KEY_SCROLL_LOCK, GP_KEY_KP_7, GP_KEY_KP_8,
+ GP_KEY_KP_MINUS, GP_KEY_KP_9, GP_KEY_KP_4, GP_KEY_KP_5,
+ GP_KEY_KP_6, GP_KEY_KP_PLUS, GP_KEY_KP_1, GP_KEY_KP_2,
+ GP_KEY_KP_3, GP_KEY_KP_0, GP_KEY_KP_COMMA, 0,
+ 0, 0, GP_KEY_F11, GP_KEY_F12,
+ 0, 0, 0, 0,
+ 0, 0, 0, GP_KEY_KP_ENTER,
+ GP_KEY_RIGHT_CTRL, GP_KEY_KP_ASTERISK, 0/*PRINT_SCREEN*/, GP_KEY_RIGHT_ALT,
+ 0, GP_KEY_HOME, 0, GP_KEY_PAGE_UP,
+ 0, 0, GP_KEY_END, 0,
+ GP_KEY_PAGE_DOWN, GP_KEY_INSERT,
+};
+
+static const uint16_t keycode_table_size = sizeof(keycode_table)/2;
+
+void GP_InputDriverKBDEventPut(unsigned char ev)
+{
+ int press = !(ev & 0x80);
+ int keycode = ev & 0x7f;
+ int key;
+
+ printf("Press %i keycode %in", press, keycode);
+
+ if (keycode > 0 && keycode <= keycode_table_size) {
+ key = keycode_table[keycode - 1];
+
+ if (key != 0) {
+ GP_EventPushKey(key, press, NULL);
+ return;
+ }
+ }
+
+ GP_DEBUG(0, "Unmapped key %i", keycode);
+}
-----------------------------------------------------------------------
Summary of changes:
include/backends/GP_LinuxFB.h | 4 +-
include/input/{GP_Input.h => GP_InputDriverKBD.h} | 15 +++--
libs/backends/GP_BackendInit.c | 2 +-
libs/backends/GP_LinuxFB.c | 52 ++++++++++++--
libs/input/GP_InputDriverKBD.c | 79 +++++++++++++++++++++
5 files changed, 137 insertions(+), 15 deletions(-)
copy include/input/{GP_Input.h => GP_InputDriverKBD.h} (88%)
create mode 100644 libs/input/GP_InputDriverKBD.c
repo.or.cz automatic notification. Contact project admin jiri.bluebear.dluhos(a)gmail.com
if you want to unsubscribe, or site admin admin(a)repo.or.cz if you receive
no reply.
--
gfxprim.git ("A simple 2D graphics library with emphasis on correctness and well-defined operation.")
1
0
[repo.or.cz] gfxprim.git branch master updated: 790d61419cab392ce0c0b2468bf43f2c554c666b
by metan 12 May '12
by metan 12 May '12
12 May '12
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project gfxprim.git.
The branch, master has been updated
via 790d61419cab392ce0c0b2468bf43f2c554c666b (commit)
via 853705c02b23d77e8d9c973224e66d59ab4637d9 (commit)
via 0efc7277bb74f43e38de741c7af24174f45b8820 (commit)
from 263af6f5f591eda466248479aade49b8c3b27f29 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
http://repo.or.cz/w/gfxprim.git/commit/790d61419cab392ce0c0b2468bf43f2c554c…
commit 790d61419cab392ce0c0b2468bf43f2c554c666b
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Sat May 12 14:18:25 2012 +0200
doc: Add gfx example.
diff --git a/doc/examples.txt b/doc/examples.txt
index 053b3c6..5c426f0 100644
--- a/doc/examples.txt
+++ b/doc/examples.txt
@@ -31,6 +31,20 @@ Example in Python
include::../demos/py_simple/loaders_example.py[]
------------------------------------------------------------------
+GFX Examples
+------------
+
+Drawing Lines
+~~~~~~~~~~~~~
+
+Example in C
+^^^^^^^^^^^^
+
+[source,c]
+------------------------------------------------------------------
+include::../demos/c_simple/gfx_koch.c[]
+------------------------------------------------------------------
+
Filters
-------
http://repo.or.cz/w/gfxprim.git/commit/853705c02b23d77e8d9c973224e66d59ab46…
commit 853705c02b23d77e8d9c973224e66d59ab4637d9
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Sat May 12 14:17:14 2012 +0200
examples: Fix loaders return value.
diff --git a/demos/c_simple/loaders.c b/demos/c_simple/loaders.c
index 1446d52..8239b90 100644
--- a/demos/c_simple/loaders.c
+++ b/demos/c_simple/loaders.c
@@ -60,7 +60,7 @@ int main(int argc, char *argv[])
if (argc != 2) {
fprintf(stderr, "Takes an image as an parametern");
- return 0;
+ return 1;
}
priv.op = "Loading";
diff --git a/demos/c_simple/loaders_example.c b/demos/c_simple/loaders_example.c
index ab0b5b4..76ffe07 100644
--- a/demos/c_simple/loaders_example.c
+++ b/demos/c_simple/loaders_example.c
@@ -41,7 +41,7 @@ int main(int argc, char *argv[])
if (argc != 2) {
fprintf(stderr, "Takes an image as an parametern");
- return 0;
+ return 1;
}
img = GP_LoadImage(argv[1], NULL);
http://repo.or.cz/w/gfxprim.git/commit/0efc7277bb74f43e38de741c7af24174f45b…
commit 0efc7277bb74f43e38de741c7af24174f45b8820
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Sat May 12 14:04:44 2012 +0200
examples: Add simple gfx C example.
diff --git a/demos/c_simple/Makefile b/demos/c_simple/Makefile
index de507b3..323ae99 100644
--- a/demos/c_simple/Makefile
+++ b/demos/c_simple/Makefile
@@ -5,7 +5,7 @@ CSOURCES=$(shell echo *.c)
INCLUDE=
LDLIBS+=-lGP -lGP_backends -lSDL -L$(TOPDIR)/build/
-APPS=backend_example loaders_example loaders filters_symmetry
+APPS=backend_example loaders_example loaders filters_symmetry gfx_koch
include $(TOPDIR)/pre.mk
include $(TOPDIR)/app.mk
diff --git a/demos/c_simple/gfx_koch.c b/demos/c_simple/gfx_koch.c
new file mode 100644
index 0000000..dda5e80
--- /dev/null
+++ b/demos/c_simple/gfx_koch.c
@@ -0,0 +1,135 @@
+/*****************************************************************************
+ * This file is part of gfxprim library. *
+ * *
+ * Gfxprim is free software; you can redistribute it and/or *
+ * modify it under the terms of the GNU Lesser General Public *
+ * License as published by the Free Software Foundation; either *
+ * version 2.1 of the License, or (at your option) any later version. *
+ * *
+ * Gfxprim is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with gfxprim; if not, write to the Free Software *
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
+ * Boston, MA 02110-1301 USA *
+ * *
+ * Copyright (C) 2009-2012 Cyril Hrubis <metan(a)ucw.cz> *
+ * *
+ *****************************************************************************/
+
+ /*
+
+ Simple GFX Example.
+
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+
+#include <GP.h>
+
+/* Set to 1 to use Anti Aliased drawing */
+static int aa_flag = 0;
+
+/*
+ * Generate color depending on distance from center
+ *
+ * We could do this only and only because the context
+ * pixel type is fixed to GP_PIXEL_RGB888.
+ */
+static GP_Pixel do_color(int xc, int yc, float x, float y)
+{
+ float dx = GP_ABS(1.00 * xc - x)/(2*xc);
+ float dy = GP_ABS(1.00 * yc - y)/(2*yc);
+
+ float dc = sqrt(dx*dx + dy*dy);
+
+ int rmask = 0;
+ int gmask = 0xff * sqrt(dc);
+ int bmask = 0xff * (1 - dc);
+
+ if (dc < 0.1) {
+ rmask = 0xff * (1 - dc);
+ bmask = 0x00;
+ }
+
+ if (dc > 0.55) {
+ rmask = 0xff * dc;
+ gmask /= 6;
+ bmask = 0x00;
+ }
+
+ return bmask | (gmask<<8) | (rmask << 16);
+}
+
+static void draw(GP_Context *img, int level, float x0, float y0, float x1, float y1)
+{
+ if (level == 0) {
+ GP_Pixel pixel;
+
+ pixel = do_color(img->w/2, img->h/2, 1.00 * (x0+x1)/2, 1.00 * (y0 + y1)/2);
+
+ if (aa_flag)
+ GP_LineAA(img, x0 * 256, y0 * 256, x1 * 256, y1 * 256, pixel);
+ else
+ GP_Line(img, x0, y0, x1, y1, pixel);
+
+ return;
+ }
+
+ /* Compute varation of Koch curve */
+ float x34 = (x0 + 3 * x1) / 4;
+ float y34 = (y0 + 3 * y1) / 4;
+
+ float x14 = (3 * x0 + x1) / 4;
+ float y14 = (3 * y0 + y1) / 4;
+
+ float x12 = (x0 + x1)/2;
+ float y12 = (y0 + y1)/2;
+
+ float dx = (x1 - x0)/4;
+ float dy = (y1 - y0)/4;
+
+ draw(img, level - 1, x0, y0, x14, y14);
+ draw(img, level - 1, x14, y14, x14 - dy, y14 + dx);
+ draw(img, level - 1, x14 - dy, y14 + dx, x12 - dy, y12 + dx);
+ draw(img, level - 1, x12 - dy, y12 + dx, x12, y12);
+ draw(img, level - 1, x12, y12, x12 + dy, y12 - dx);
+ draw(img, level - 1, x12 + dy, y12 - dx, x34 + dy, y34 - dx);
+ draw(img, level - 1, x34 + dy, y34 - dx, x34, y34);
+ draw(img, level - 1, x1, y1, x34, y34);
+}
+
+int main(void)
+{
+ GP_Context *img;
+
+ /* Create RGB 24 bit image */
+ img = GP_ContextAlloc(600, 600, GP_PIXEL_RGB888);
+
+ if (img == NULL) {
+ fprintf(stderr, "Failed to allocate context");
+ return 1;
+ }
+
+ /* Clean up the bitmap */
+ GP_Fill(img, 0);
+
+ /* Draw a fractal */
+ draw(img, 4, 0, 0, img->w - 1, img->h - 1);
+ draw(img, 4, 0, img->h - 1, img->w - 1, 0);
+
+ if (GP_SavePNG(img, "out.png", NULL)) {
+ fprintf(stderr, "Failed to save image %s", strerror(errno));
+ return 1;
+ }
+
+ /* Cleanup */
+ GP_ContextFree(img);
+
+ return 0;
+}
-----------------------------------------------------------------------
Summary of changes:
demos/c_simple/Makefile | 2 +-
demos/c_simple/gfx_koch.c | 135 ++++++++++++++++++++++++++++++++++++++
demos/c_simple/loaders.c | 2 +-
demos/c_simple/loaders_example.c | 2 +-
doc/examples.txt | 14 ++++
5 files changed, 152 insertions(+), 3 deletions(-)
create mode 100644 demos/c_simple/gfx_koch.c
repo.or.cz automatic notification. Contact project admin jiri.bluebear.dluhos(a)gmail.com
if you want to unsubscribe, or site admin admin(a)repo.or.cz if you receive
no reply.
--
gfxprim.git ("A simple 2D graphics library with emphasis on correctness and well-defined operation.")
1
0
[repo.or.cz] gfxprim.git branch master updated: 263af6f5f591eda466248479aade49b8c3b27f29
by metan 12 May '12
by metan 12 May '12
12 May '12
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project gfxprim.git.
The branch, master has been updated
via 263af6f5f591eda466248479aade49b8c3b27f29 (commit)
via 22558f86de3b76b3a9262ee5df3f8802b4c38f88 (commit)
via 59c8a325a33dcdbb0afdeb0f08b33e7359246d55 (commit)
from 7f40abdf975259a1285023927c27a9fe4c394bbd (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
http://repo.or.cz/w/gfxprim.git/commit/263af6f5f591eda466248479aade49b8c3b2…
commit 263af6f5f591eda466248479aade49b8c3b27f29
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Sat May 12 00:52:53 2012 +0200
examples: python: Fix image saving usage.
diff --git a/demos/py_simple/loaders_example.py b/demos/py_simple/loaders_example.py
index 3cebc4d..c9db630 100755
--- a/demos/py_simple/loaders_example.py
+++ b/demos/py_simple/loaders_example.py
@@ -1,4 +1,5 @@
#!/usr/bin/env python
+
import sys
import gfxprim.core as core
@@ -12,7 +13,7 @@ def main():
# Load Image
img = loaders.LoadImage(sys.argv[1], None)
# Save result
- loaders.SavePNG("out.png", img, None)
+ img.Save("out.png");
if __name__ == '__main__':
main()
diff --git a/demos/py_simple/rotate90.py b/demos/py_simple/rotate90.py
index d14022d..d93756b 100755
--- a/demos/py_simple/rotate90.py
+++ b/demos/py_simple/rotate90.py
@@ -18,7 +18,7 @@ def main():
# Rotate by 90 degrees
res = filters.FilterRotate90Alloc(src, None)
# Save Image
- loaders.SaveImage(res, sys.argv[2], None);
+ res.Save(sys.argv[2])
if __name__ == '__main__':
main()
http://repo.or.cz/w/gfxprim.git/commit/22558f86de3b76b3a9262ee5df3f8802b4c3…
commit 22558f86de3b76b3a9262ee5df3f8802b4c38f88
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Sat May 12 00:51:30 2012 +0200
pywrap: Fix the loaders extend context after API change.
diff --git a/pylib/gfxprim/loaders/_extend_context.py b/pylib/gfxprim/loaders/_extend_context.py
index 5e0b8c4..e252b4b 100644
--- a/pylib/gfxprim/loaders/_extend_context.py
+++ b/pylib/gfxprim/loaders/_extend_context.py
@@ -15,7 +15,7 @@ def extend_context(_context):
return c
@extend(_context)
- def Save(self, filename, format=None):
+ def Save(self, filename, format=None, callback=None):
"""Save the image in given format (or guess it from the extension)
Currently, JPG, PNG and P[BGP]M are supported, but not for all
@@ -25,15 +25,15 @@ def extend_context(_context):
format = filename.rsplit('.', 1)[-1]
format = format.lower()
if format == 'jpg':
- res = loaders_c.GP_SaveJPG(filename, self, None)
+ res = loaders_c.GP_SaveJPG(self, filename, callback)
elif format == 'png':
- res = loaders_c.GP_SavePNG(filename, self, None)
+ res = loaders_c.GP_SavePNG(self, filename, callback)
elif format == 'pbm':
- res = loaders_c.GP_SavePBM(filename, self, None)
+ res = loaders_c.GP_SavePBM(filename, self, callback)
elif format == 'pgm':
- res = loaders_c.GP_SavePGM(filename, self, None)
+ res = loaders_c.GP_SavePGM(filename, self, callback)
elif format == 'ppm':
- res = loaders_c.GP_SavePPM(filename, self, None)
+ res = loaders_c.GP_SavePPM(filename, self, callback)
else:
raise Exception("Format %r not supported.", format)
if res != 0:
http://repo.or.cz/w/gfxprim.git/commit/59c8a325a33dcdbb0afdeb0f08b33e735924…
commit 59c8a325a33dcdbb0afdeb0f08b33e7359246d55
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Sat May 12 00:41:21 2012 +0200
pywrap: Update _extend_backend.py.
diff --git a/pylib/gfxprim/backends/_extend_backend.py b/pylib/gfxprim/backends/_extend_backend.py
index 2f739fc..31c56ef 100644
--- a/pylib/gfxprim/backends/_extend_backend.py
+++ b/pylib/gfxprim/backends/_extend_backend.py
@@ -28,3 +28,12 @@ def extend_backend(_backend):
"Poll the backend for events."
return backends_c.GP_BackendPoll(self)
+ @extend(_backend)
+ def SetCaption(self, caption):
+ "Set backend window caption (if possible)"
+ return backends_c.GP_BackendSetCaption(self, caption)
+
+ @extend(_backend)
+ def Resize(self, w, h):
+ "Resize backend window (if possible)"
+ return backends_c.GP_BackendResize(self, w, h)
-----------------------------------------------------------------------
Summary of changes:
demos/py_simple/loaders_example.py | 3 ++-
demos/py_simple/rotate90.py | 2 +-
pylib/gfxprim/backends/_extend_backend.py | 9 +++++++++
pylib/gfxprim/loaders/_extend_context.py | 12 ++++++------
4 files changed, 18 insertions(+), 8 deletions(-)
repo.or.cz automatic notification. Contact project admin jiri.bluebear.dluhos(a)gmail.com
if you want to unsubscribe, or site admin admin(a)repo.or.cz if you receive
no reply.
--
gfxprim.git ("A simple 2D graphics library with emphasis on correctness and well-defined operation.")
1
0
[repo.or.cz] gfxprim.git branch master updated: 7f40abdf975259a1285023927c27a9fe4c394bbd
by metan 12 May '12
by metan 12 May '12
12 May '12
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project gfxprim.git.
The branch, master has been updated
via 7f40abdf975259a1285023927c27a9fe4c394bbd (commit)
via f26e8c4084153dc28b77d603162662744d84a1ac (commit)
from 4f9126b65e5597524ac218023ac7520e6219ad23 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
http://repo.or.cz/w/gfxprim.git/commit/7f40abdf975259a1285023927c27a9fe4c39…
commit 7f40abdf975259a1285023927c27a9fe4c394bbd
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Sat May 12 00:26:06 2012 +0200
pywrap: Add pywrap for input module.
diff --git a/pylib/gfxprim/Makefile b/pylib/gfxprim/Makefile
index 3032f62..afcad67 100644
--- a/pylib/gfxprim/Makefile
+++ b/pylib/gfxprim/Makefile
@@ -1,4 +1,4 @@
TOPDIR=../..
-SUBDIRS=core loaders backends gfx filters text
+SUBDIRS=core loaders backends gfx filters text input
CLEAN+=*.pyc
include $(TOPDIR)/post.mk
diff --git a/pylib/gfxprim/input/C.py b/pylib/gfxprim/input/C.py
new file mode 100644
index 0000000..c8f987f
--- /dev/null
+++ b/pylib/gfxprim/input/C.py
@@ -0,0 +1,3 @@
+"""
+Submodule for constants
+"""
diff --git a/pylib/gfxprim/input/Makefile b/pylib/gfxprim/input/Makefile
new file mode 100644
index 0000000..3430bc9
--- /dev/null
+++ b/pylib/gfxprim/input/Makefile
@@ -0,0 +1,8 @@
+TOPDIR=../../..
+LIBNAME=input
+
+include $(TOPDIR)/pre.mk
+include $(TOPDIR)/pywrap.mk
+include $(TOPDIR)/post.mk
+
+include ../silence_swig_warnings.mk
diff --git a/pylib/gfxprim/input/__init__.py b/pylib/gfxprim/input/__init__.py
new file mode 100644
index 0000000..31c371f
--- /dev/null
+++ b/pylib/gfxprim/input/__init__.py
@@ -0,0 +1,29 @@
+"""
+Module wrapping GfxPrim Input.
+"""
+
+from . import input_c
+
+# Constants module
+from . import C
+
+def _init(module):
+ # Import some members from the SWIG module
+ from ..utils import import_members
+ import re
+ def strip_GP(s):
+ return re.sub('^GP_', '', s)
+
+ # Constants
+ const_regexes = ['^GP_[A-Z0-9_]*$']
+ import_members(input_c, C, include=const_regexes, sub=strip_GP)
+
+ # Functions
+ import_members(input_c, module, sub=strip_GP,
+ exclude=const_regexes + [
+ '^gfxprim$',
+ '^w+_swigregister$',
+ '^_w+$'])
+
+_init(locals())
+del _init
diff --git a/pylib/gfxprim/input/input.i b/pylib/gfxprim/input/input.i
new file mode 100644
index 0000000..f870e10
--- /dev/null
+++ b/pylib/gfxprim/input/input.i
@@ -0,0 +1,7 @@
+%module(package="gfxprim.input") input_c
+
+%{
+#include "input/GP_Input.h"
+%}
+
+%include "GP_Event.h"
http://repo.or.cz/w/gfxprim.git/commit/f26e8c4084153dc28b77d603162662744d84…
commit f26e8c4084153dc28b77d603162662744d84a1ac
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Sat May 12 00:00:31 2012 +0200
pywrap: backends: Update swig bindings.
diff --git a/pylib/gfxprim/backends/backends.i b/pylib/gfxprim/backends/backends.i
index 4785281..dd1394d 100644
--- a/pylib/gfxprim/backends/backends.i
+++ b/pylib/gfxprim/backends/backends.i
@@ -33,12 +33,12 @@
%include "GP_Backend.h"
-
/*
* Particular backends. We need to list every header separately.
*/
-
-%include "GP_Backends.h"
+/* Overall backend init header */
+%newobject GP_BackendInit;
+%include "GP_BackendInit.h"
%newobject GP_BackendLinuxFBInit;
%include "GP_LinuxFB.h"
@@ -46,3 +46,5 @@
%newobject GP_BackendSDLInit;
%include "GP_SDL.h"
+%newobject GP_BackendX11Init;
+%include "GP_X11.h"
-----------------------------------------------------------------------
Summary of changes:
pylib/gfxprim/Makefile | 2 +-
pylib/gfxprim/backends/backends.i | 8 +++++---
pylib/gfxprim/{backends => input}/C.py | 0
pylib/gfxprim/{core => input}/Makefile | 2 +-
pylib/gfxprim/{gfx => input}/__init__.py | 24 +++++++++++++-----------
pylib/gfxprim/input/input.i | 7 +++++++
6 files changed, 27 insertions(+), 16 deletions(-)
copy pylib/gfxprim/{backends => input}/C.py (100%)
copy pylib/gfxprim/{core => input}/Makefile (90%)
copy pylib/gfxprim/{gfx => input}/__init__.py (52%)
create mode 100644 pylib/gfxprim/input/input.i
repo.or.cz automatic notification. Contact project admin jiri.bluebear.dluhos(a)gmail.com
if you want to unsubscribe, or site admin admin(a)repo.or.cz if you receive
no reply.
--
gfxprim.git ("A simple 2D graphics library with emphasis on correctness and well-defined operation.")
1
0
[repo.or.cz] gfxprim.git branch master updated: 4f9126b65e5597524ac218023ac7520e6219ad23
by metan 11 May '12
by metan 11 May '12
11 May '12
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project gfxprim.git.
The branch, master has been updated
via 4f9126b65e5597524ac218023ac7520e6219ad23 (commit)
via 037b907e62d1a4427002d6a76f58eb5ee08a40b3 (commit)
via f8d41db7b4077dd701a37cc0624011f5b62f9fbf (commit)
via cbd1de31159606e98f46ac6d4ad281e15cc94344 (commit)
via 8d627e19fbffb76c6e4a11c320018676da2eac4e (commit)
via d75426b6d9542c45ea93f4ab5f918f71f7c286d0 (commit)
via 0cfd38954aa140631a8faa6a72d6294a27c25f76 (commit)
via d7ea6a77dc9ea5567ef84607cf98a36f6ed13c3b (commit)
via abb8f83cb3e09d8206a071d4043be6c47dc077ea (commit)
via 762943f4d1602fd118aa6efb380a956a03daf8d8 (commit)
via 8e6577ea43f37eba91ebae68d8998d37a17edbe0 (commit)
via 4e15e1706ca21c382ca73ea1de111e04bffc34e9 (commit)
via aa053ead0e51edb99977b8a0aee8eb4488238473 (commit)
via 043238394f939389538ed8666144c875428b65cc (commit)
via d2aa0848db79445801a3ca718ced2204c7e4d783 (commit)
via 53fcdc5357cb56708be84b483bf6facd0c380108 (commit)
via 953585da5ceb2376fbb96db9965268a3566b26b4 (commit)
via c696193212ee6fb4704cbb12c0d56d189647ccb8 (commit)
via 6585778ebe915cccfe630d49782e6db6c0ac6c94 (commit)
via c9ca2a9c99541ef2a206db9344c9feda39426db7 (commit)
via 3275310a73bb7a599d6e1da9a4f6debf1e358635 (commit)
via ba095a866ae6547879193c256d9c206585efbfe7 (commit)
from 179ad0f8718479d653783f56c3128ef4cad8d880 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
http://repo.or.cz/w/gfxprim.git/commit/4f9126b65e5597524ac218023ac7520e6219…
commit 4f9126b65e5597524ac218023ac7520e6219ad23
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Fri May 11 23:43:10 2012 +0200
doc: Add new example.
diff --git a/doc/examples.txt b/doc/examples.txt
index a3eed9a..053b3c6 100644
--- a/doc/examples.txt
+++ b/doc/examples.txt
@@ -45,6 +45,14 @@ Example in C
include::../demos/c_simple/filters_symmetry.c[]
------------------------------------------------------------------
+Example in Python
+^^^^^^^^^^^^^^^^^
+
+[source,python]
+------------------------------------------------------------------
+include::../demos/py_simple/rotate90.py[]
+------------------------------------------------------------------
+
Simple backend example
----------------------
http://repo.or.cz/w/gfxprim.git/commit/037b907e62d1a4427002d6a76f58eb5ee08a…
commit 037b907e62d1a4427002d6a76f58eb5ee08a40b3
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Fri May 11 23:40:45 2012 +0200
examples: Add pyton filter rotate example.
diff --git a/demos/py_simple/loaders_example.py b/demos/py_simple/loaders_example.py
index 1bf9c2c..3cebc4d 100755
--- a/demos/py_simple/loaders_example.py
+++ b/demos/py_simple/loaders_example.py
@@ -3,7 +3,6 @@ import sys
import gfxprim.core as core
import gfxprim.loaders as loaders
-import gfxprim.filters as filters
def main():
if len(sys.argv) != 2:
@@ -11,7 +10,7 @@ def main():
sys.exit(1)
# Load Image
- img = loaders.LoadImage(sys.argv[2], None)
+ img = loaders.LoadImage(sys.argv[1], None)
# Save result
loaders.SavePNG("out.png", img, None)
diff --git a/demos/py_simple/rotate90.py b/demos/py_simple/rotate90.py
new file mode 100755
index 0000000..d14022d
--- /dev/null
+++ b/demos/py_simple/rotate90.py
@@ -0,0 +1,24 @@
+#!/usr/bin/env python
+import sys
+
+import gfxprim.core as core
+import gfxprim.loaders as loaders
+import gfxprim.filters as filters
+
+def main():
+ if len(sys.argv) != 3:
+ print("USAGE: %s imput_image output_image" % sys.argv[0]);
+ sys.exit(1)
+
+ # Turns on debug messages
+ core.SetDebugLevel(10);
+
+ # Load Image
+ src = loaders.LoadImage(sys.argv[1], None)
+ # Rotate by 90 degrees
+ res = filters.FilterRotate90Alloc(src, None)
+ # Save Image
+ loaders.SaveImage(res, sys.argv[2], None);
+
+if __name__ == '__main__':
+ main()
http://repo.or.cz/w/gfxprim.git/commit/f8d41db7b4077dd701a37cc0624011f5b62f…
commit f8d41db7b4077dd701a37cc0624011f5b62f9fbf
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Fri May 11 23:29:59 2012 +0200
pywrap: filters: Mark allocating functions.
diff --git a/pylib/gfxprim/filters/filters.i b/pylib/gfxprim/filters/filters.i
index 34baeb9..b617508 100644
--- a/pylib/gfxprim/filters/filters.i
+++ b/pylib/gfxprim/filters/filters.i
@@ -24,3 +24,11 @@
%include "GP_Linear.h"
%include "GP_Resize.h"
/* %include "GP_Dither.h" -- missing symbols */
+
+/* Functions returning new allocated context */
+%newobject GP_FilterMirrorHAlloc;
+%newobject GP_FilterMirrorVAlloc;
+%newobject GP_FilterRotate90Alloc;
+%newobject GP_FilterRotate180Alloc;
+%newobject GP_FilterRotate270Alloc;
+%newobject GP_FilterSymmetryAlloc;
http://repo.or.cz/w/gfxprim.git/commit/cbd1de31159606e98f46ac6d4ad281e15cc9…
commit cbd1de31159606e98f46ac6d4ad281e15cc94344
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Fri May 11 23:05:04 2012 +0200
filters: Finish rotate filters API change.
diff --git a/demos/grinder/grinder.c b/demos/grinder/grinder.c
index 01e8a06..7229781 100644
--- a/demos/grinder/grinder.c
+++ b/demos/grinder/grinder.c
@@ -227,13 +227,13 @@ static GP_RetCode rotate(GP_Context **c, const char *params)
switch (rot) {
case 0:
- res = GP_FilterRotate90(*c, NULL, progress_callback);
+ res = GP_FilterRotate90Alloc(*c, progress_callback);
break;
case 1:
- res = GP_FilterRotate180(*c, NULL, progress_callback);
+ res = GP_FilterRotate180Alloc(*c, progress_callback);
break;
case 2:
- res = GP_FilterRotate270(*c, NULL, progress_callback);
+ res = GP_FilterRotate270Alloc(*c, progress_callback);
break;
}
@@ -262,10 +262,10 @@ static GP_RetCode mirror(GP_Context **c, const char *params)
return GP_EINVAL;
if (vert)
- GP_FilterMirrorV_Raw(*c, *c, progress_callback);
+ GP_FilterMirrorV(*c, *c, progress_callback);
if (horiz)
- GP_FilterMirrorH_Raw(*c, *c, progress_callback);
+ GP_FilterMirrorH(*c, *c, progress_callback);
return GP_ESUCCESS;
}
diff --git a/demos/spiv/spiv.c b/demos/spiv/spiv.c
index 18cfabc..ce97389 100644
--- a/demos/spiv/spiv.c
+++ b/demos/spiv/spiv.c
@@ -215,15 +215,15 @@ static void *image_loader(void *ptr)
break;
case 90:
callback.priv = "Rotating image (90)";
- img = GP_FilterRotate90(ret, NULL, &callback);
+ img = GP_FilterRotate90Alloc(ret, &callback);
break;
case 180:
callback.priv = "Rotating image (180)";
- img = GP_FilterRotate180(ret, NULL, &callback);
+ img = GP_FilterRotate180Alloc(ret, &callback);
break;
case 270:
callback.priv = "Rotating image (270)";
- img = GP_FilterRotate270(ret, NULL, &callback);
+ img = GP_FilterRotate270Alloc(ret, &callback);
break;
}
diff --git a/include/filters/GP_Rotate.h b/include/filters/GP_Rotate.h
index 26f878f..0957010 100644
--- a/include/filters/GP_Rotate.h
+++ b/include/filters/GP_Rotate.h
@@ -118,18 +118,25 @@ int GP_FilterRotate270_Raw(const GP_Context *src, GP_Context *dst,
/*
* Rotate the context by 90, 180, 270.
*
- * If dst is NULL, new bitmap is allocated.
- *
* Returns pointer to destination bitmap or NULL if allocation failed.
*/
-GP_Context *GP_FilterRotate90(const GP_Context *src, GP_Context *dst,
- GP_ProgressCallback *callback);
+int GP_FilterRotate90(const GP_Context *src, GP_Context *dst,
+ GP_ProgressCallback *callback);
+
+GP_Context *GP_FilterRotate90Alloc(const GP_Context *src,
+ GP_ProgressCallback *callback);
-GP_Context *GP_FilterRotate180(const GP_Context *src, GP_Context *dst,
- GP_ProgressCallback *callback);
+int GP_FilterRotate180(const GP_Context *src, GP_Context *dst,
+ GP_ProgressCallback *callback);
-GP_Context *GP_FilterRotate270(const GP_Context *src, GP_Context *dst,
- GP_ProgressCallback *callback);
+GP_Context *GP_FilterRotate180Alloc(const GP_Context *src,
+ GP_ProgressCallback *callback);
+
+int GP_FilterRotate270(const GP_Context *src, GP_Context *dst,
+ GP_ProgressCallback *callback);
+
+GP_Context *GP_FilterRotate270Alloc(const GP_Context *src,
+ GP_ProgressCallback *callback);
/*
* Calls a symmetry filter on bitmap.
@@ -165,4 +172,8 @@ GP_Context *GP_FilterSymmetryAlloc(const GP_Context *src,
GP_FilterSymmetries symmetry,
GP_ProgressCallback *callback);
+int GP_FilterSymmetry(const GP_Context *src, GP_Context *dst,
+ GP_FilterSymmetries symmetry,
+ GP_ProgressCallback *callback);
+
#endif /* FILTERS_GP_ROTATE_H */
diff --git a/libs/filters/GP_Rotate.c b/libs/filters/GP_Rotate.c
index 5a7be3d..d758535 100644
--- a/libs/filters/GP_Rotate.c
+++ b/libs/filters/GP_Rotate.c
@@ -74,7 +74,7 @@ int GP_FilterMirrorH(const GP_Context *src, GP_Context *dst,
"The src and dst pixel types must match");
GP_ASSERT(src->w <= dst->w && src->h <= dst->h,
- "Destination is not big enough");
+ "Destination is not large enough");
if (GP_FilterMirrorH_Raw(src, dst, callback)) {
GP_DEBUG(1, "Operation aborted");
@@ -108,7 +108,7 @@ int GP_FilterMirrorV(const GP_Context *src, GP_Context *dst,
GP_ASSERT(src->pixel_type == dst->pixel_type,
"The src and dst pixel types must match");
GP_ASSERT(src->w <= dst->w && src->h <= dst->h,
- "Destination is not big enough");
+ "Destination is not large enough");
if (GP_FilterMirrorV_Raw(src, dst, callback)) {
GP_DEBUG(1, "Operation aborted");
@@ -147,87 +147,105 @@ int GP_FilterRotate180_Raw(const GP_Context *src, GP_Context *dst,
return 0;
}
-GP_Context *GP_FilterRotate90(const GP_Context *src, GP_Context *dst,
- GP_ProgressCallback *callback)
+int GP_FilterRotate90(const GP_Context *src, GP_Context *dst,
+ GP_ProgressCallback *callback)
{
- GP_Context *res = dst;
-
- if (res == NULL) {
- res = GP_ContextAlloc(src->h, src->w, src->pixel_type);
-
- if (res == NULL)
- return NULL;
- } else {
- GP_ASSERT(src->pixel_type == dst->pixel_type,
- "The src and dst pixel types must match");
- GP_ASSERT(src->w <= dst->h && src->h <= dst->w,
- "Destination is not big enough");
- }
+ GP_ASSERT(src->pixel_type == dst->pixel_type,
+ "The src and dst pixel types must match");
+ GP_ASSERT(src->w <= dst->h && src->h <= dst->w,
+ "Destination is not large enough");
- if (GP_FilterRotate90_Raw(src, res, callback)) {
+ if (GP_FilterRotate90_Raw(src, dst, callback)) {
GP_DEBUG(1, "Operation aborted");
+ return 1;
+ }
- if (dst == NULL)
- GP_ContextFree(res);
+ return 0;
+}
+GP_Context *GP_FilterRotate90Alloc(const GP_Context *src,
+ GP_ProgressCallback *callback)
+{
+ GP_Context *res;
+
+ res = GP_ContextAlloc(src->h, src->w, src->pixel_type);
+
+ if (res == NULL)
+ return NULL;
+
+ if (GP_FilterRotate90_Raw(src, res, callback)) {
+ GP_DEBUG(1, "Operation aborted");
+ GP_ContextFree(res);
return NULL;
}
return res;
}
-GP_Context *GP_FilterRotate180(const GP_Context *src, GP_Context *dst,
- GP_ProgressCallback *callback)
+int GP_FilterRotate180(const GP_Context *src, GP_Context *dst,
+ GP_ProgressCallback *callback)
{
- GP_Context *res = dst;
-
- if (res == NULL) {
- res = GP_ContextCopy(src, 0);
-
- if (res == NULL)
- return NULL;
- } else {
- GP_ASSERT(src->pixel_type == dst->pixel_type,
- "The src and dst pixel types must match");
- GP_ASSERT(src->w <= dst->w && src->h <= dst->h,
- "Destination is not big enough");
- }
+ GP_ASSERT(src->pixel_type == dst->pixel_type,
+ "The src and dst pixel types must match");
+ GP_ASSERT(src->w <= dst->w && src->h <= dst->h,
+ "Destination is not large enough");
- if (GP_FilterRotate180_Raw(src, res, callback)) {
+ if (GP_FilterRotate180_Raw(src, dst, callback)) {
GP_DEBUG(1, "Operation aborted");
+ return 1;
+ }
- if (dst == NULL)
- GP_ContextFree(res);
+ return 0;
+}
+GP_Context *GP_FilterRotate180Alloc(const GP_Context *src,
+ GP_ProgressCallback *callback)
+{
+ GP_Context *res;
+
+ res = GP_ContextCopy(src, 0);
+
+ if (res == NULL)
+ return NULL;
+
+ if (GP_FilterRotate180_Raw(src, res, callback)) {
+ GP_DEBUG(1, "Operation aborted");
+ GP_ContextFree(res);
return NULL;
}
return res;
}
-GP_Context *GP_FilterRotate270(const GP_Context *src, GP_Context *dst,
- GP_ProgressCallback *callback)
+int GP_FilterRotate270(const GP_Context *src, GP_Context *dst,
+ GP_ProgressCallback *callback)
{
- GP_Context *res = dst;
-
- if (res == NULL) {
- res = GP_ContextAlloc(src->h, src->w, src->pixel_type);
-
- if (res == NULL)
- return NULL;
- } else {
- GP_ASSERT(src->pixel_type == dst->pixel_type,
- "The src and dst pixel types must match");
- GP_ASSERT(src->w <= dst->h && src->h <= dst->w,
- "Destination is not big enough");
- }
+ GP_ASSERT(src->pixel_type == dst->pixel_type,
+ "The src and dst pixel types must match");
+ GP_ASSERT(src->w <= dst->h && src->h <= dst->w,
+ "Destination is not large enough");
- if (GP_FilterRotate270_Raw(src, res, callback)) {
+ if (GP_FilterRotate270_Raw(src, dst, callback)) {
GP_DEBUG(1, "Operation aborted");
+ return 1;
+ }
- if (dst == NULL)
- GP_ContextFree(res);
+ return 0;
+}
+GP_Context *GP_FilterRotate270Alloc(const GP_Context *src,
+ GP_ProgressCallback *callback)
+{
+ GP_Context *res;
+
+ res = GP_ContextAlloc(src->h, src->w, src->pixel_type);
+
+ if (res == NULL)
+ return NULL;
+
+ if (GP_FilterRotate270_Raw(src, res, callback)) {
+ GP_DEBUG(1, "Operation aborted");
+ GP_ContextFree(res);
return NULL;
}
@@ -262,11 +280,11 @@ GP_Context *GP_FilterSymmetryAlloc(const GP_Context *src,
{
switch (symmetry) {
case GP_ROTATE_90:
- return GP_FilterRotate90(src, NULL, callback);
+ return GP_FilterRotate90Alloc(src, callback);
case GP_ROTATE_180:
- return GP_FilterRotate180(src, NULL, callback);
+ return GP_FilterRotate180Alloc(src, callback);
case GP_ROTATE_270:
- return GP_FilterRotate270(src, NULL, callback);
+ return GP_FilterRotate270Alloc(src, callback);
case GP_MIRROR_H:
return GP_FilterMirrorHAlloc(src, callback);
case GP_MIRROR_V:
@@ -276,3 +294,24 @@ GP_Context *GP_FilterSymmetryAlloc(const GP_Context *src,
return NULL;
}
}
+
+int GP_FilterSymmetry(const GP_Context *src, GP_Context *dst,
+ GP_FilterSymmetries symmetry,
+ GP_ProgressCallback *callback)
+{
+ switch (symmetry) {
+ case GP_ROTATE_90:
+ return GP_FilterRotate90(src, dst, callback);
+ case GP_ROTATE_180:
+ return GP_FilterRotate180(src, dst, callback);
+ case GP_ROTATE_270:
+ return GP_FilterRotate270(src, dst, callback);
+ case GP_MIRROR_H:
+ return GP_FilterMirrorH(src, dst, callback);
+ case GP_MIRROR_V:
+ return GP_FilterMirrorV(src, dst, callback);
+ default:
+ GP_DEBUG(1, "Invalid symmetry %i", (int) symmetry);
+ return 1;
+ }
+}
http://repo.or.cz/w/gfxprim.git/commit/8d627e19fbffb76c6e4a11c320018676da2e…
commit 8d627e19fbffb76c6e4a11c320018676da2eac4e
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Fri May 11 20:34:24 2012 +0200
doc: Add symmetry example to examples.
diff --git a/doc/examples.txt b/doc/examples.txt
index 87b8f63..a3eed9a 100644
--- a/doc/examples.txt
+++ b/doc/examples.txt
@@ -31,6 +31,20 @@ Example in Python
include::../demos/py_simple/loaders_example.py[]
------------------------------------------------------------------
+Filters
+-------
+
+Symmetry filters (Rotation, Mirroring)
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Example in C
+^^^^^^^^^^^^
+
+[source,c]
+------------------------------------------------------------------
+include::../demos/c_simple/filters_symmetry.c[]
+------------------------------------------------------------------
+
Simple backend example
----------------------
http://repo.or.cz/w/gfxprim.git/commit/d75426b6d9542c45ea93f4ab5f918f71f7c2…
commit d75426b6d9542c45ea93f4ab5f918f71f7c286d0
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Fri May 11 20:31:42 2012 +0200
examples: Add filter symmetry C example.
diff --git a/demos/c_simple/Makefile b/demos/c_simple/Makefile
index 528152f..de507b3 100644
--- a/demos/c_simple/Makefile
+++ b/demos/c_simple/Makefile
@@ -5,7 +5,7 @@ CSOURCES=$(shell echo *.c)
INCLUDE=
LDLIBS+=-lGP -lGP_backends -lSDL -L$(TOPDIR)/build/
-APPS=backend_example loaders_example loaders filters_mirror
+APPS=backend_example loaders_example loaders filters_symmetry
include $(TOPDIR)/pre.mk
include $(TOPDIR)/app.mk
diff --git a/demos/c_simple/filters_symmetry.c b/demos/c_simple/filters_symmetry.c
new file mode 100644
index 0000000..3f130a4
--- /dev/null
+++ b/demos/c_simple/filters_symmetry.c
@@ -0,0 +1,116 @@
+/*****************************************************************************
+ * This file is part of gfxprim library. *
+ * *
+ * Gfxprim is free software; you can redistribute it and/or *
+ * modify it under the terms of the GNU Lesser General Public *
+ * License as published by the Free Software Foundation; either *
+ * version 2.1 of the License, or (at your option) any later version. *
+ * *
+ * Gfxprim is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with gfxprim; if not, write to the Free Software *
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
+ * Boston, MA 02110-1301 USA *
+ * *
+ * Copyright (C) 2009-2012 Cyril Hrubis <metan(a)ucw.cz> *
+ * *
+ *****************************************************************************/
+
+ /*
+
+ Symmetry filter example.
+
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include <getopt.h>
+
+#include <GP.h>
+
+static void usage_and_exit(int ret)
+{
+ int i;
+ printf("filter_symmetry [-d debug_level] -s {");
+
+ for (i = 0; GP_FilterSymmetryNames[i+1] != NULL; i++)
+ printf("%s, ", GP_FilterSymmetryNames[i]);
+
+ printf("%s} image_in image_outn", GP_FilterSymmetryNames[i]);
+
+ exit(ret);
+}
+
+int main(int argc, char *argv[])
+{
+ GP_Context *src, *res;
+ const char *symmetry = NULL;
+ int opt, sym, debug = 0;
+
+ /* Parse program options */
+ while ((opt = getopt(argc, argv, "d:hs:")) != -1) {
+ switch (opt) {
+ case 's':
+ symmetry = optarg;
+ break;
+ case 'h':
+ usage_and_exit(0);
+ break;
+ case 'd':
+ debug = atoi(optarg);
+ break;
+ default:
+ usage_and_exit(1);
+ }
+ }
+
+ /* Turn on debug messages */
+ GP_SetDebugLevel(debug);
+
+ if (symmetry == NULL) {
+ printf("Symmetry not specifiedn");
+ usage_and_exit(1);
+ }
+
+ if (argc - optind != 2) {
+ printf("Input and output image not specifiedn");
+ usage_and_exit(1);
+ }
+
+ sym = GP_FilterSymmetryByName(symmetry);
+
+ if (sym < 0) {
+ printf("Invalid symmetry name '%s'n", symmetry);
+ usage_and_exit(1);
+ }
+
+ /* Load Image */
+ src = GP_LoadImage(argv[optind], NULL);
+
+ if (src == NULL) {
+ fprintf(stderr, "Failed to load image '%s': %sn",
+ argv[optind], strerror(errno));
+ return 1;
+ }
+
+ /* Apply a symmetry filter */
+ res = GP_FilterSymmetryAlloc(src, sym, NULL);
+
+ /* Save Image */
+ if (GP_SaveImage(res, argv[optind+1], NULL)) {
+ fprintf(stderr, "Failed to save image '%s': %sn",
+ argv[optind+1], strerror(errno));
+ return 1;
+ }
+
+ /* Cleanup */
+ GP_ContextFree(src);
+ GP_ContextFree(res);
+
+ return 0;
+}
http://repo.or.cz/w/gfxprim.git/commit/0cfd38954aa140631a8faa6a72d6294a27c2…
commit 0cfd38954aa140631a8faa6a72d6294a27c25f76
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Fri May 11 20:30:19 2012 +0200
filters: Starting to change filter API.
diff --git a/include/filters/GP_Rotate.h b/include/filters/GP_Rotate.h
index 515d2b5..26f878f 100644
--- a/include/filters/GP_Rotate.h
+++ b/include/filters/GP_Rotate.h
@@ -16,7 +16,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, *
* Boston, MA 02110-1301 USA *
* *
- * Copyright (C) 2009-2011 Cyril Hrubis <metan(a)ucw.cz> *
+ * Copyright (C) 2009-2012 Cyril Hrubis <metan(a)ucw.cz> *
* *
*****************************************************************************/
@@ -36,6 +36,8 @@
* Mirror horizontally.
*
* Works 'in place'. The contexts must have equal pixel_type and size.
+ *
+ * This is semi-internal function without any assertions on destination.
*/
int GP_FilterMirrorH_Raw(const GP_Context *src, GP_Context *dst,
GP_ProgressCallback *callback);
@@ -43,17 +45,32 @@ int GP_FilterMirrorH_Raw(const GP_Context *src, GP_Context *dst,
/*
* Mirrors bitmap horizontally.
*
- * If dst is NULL, new bitmap is allocated.
+ * The dst must be at least as big as source.
*
- * Returns pointer to destination bitmap or NULL if allocation failed.
+ * The filter works 'in-place' which means that src and dst
+ * may be very same context. Note that when aborting in-place operation
+ * the image buffer gets into an inconsitent state.
+ *
+ * Retruns zero on success, non-zero if operation was aborted.
+ */
+int GP_FilterMirrorH(const GP_Context *src, GP_Context *dst,
+ GP_ProgressCallback *callback);
+
+/*
+ * Mirrors bitmap horizontally.
+ *
+ * Returns pointer to newly allocated context, or NULL if malloc() has failed
+ * or operation was aborted from withing a callback.
*/
-GP_Context *GP_FilterMirrorH(const GP_Context *src, GP_Context *dst,
- GP_ProgressCallback *callback);
+GP_Context *GP_FilterMirrorHAlloc(const GP_Context *src,
+ GP_ProgressCallback *callback);
/*
* Mirror vertically
*
* Works 'in place'. The contexts must have equal pixel_type and size.
+ *
+ * This is semi-internal function without any assertions on destination.
*/
int GP_FilterMirrorV_Raw(const GP_Context *src, GP_Context *dst,
GP_ProgressCallback *callback);
@@ -61,18 +78,33 @@ int GP_FilterMirrorV_Raw(const GP_Context *src, GP_Context *dst,
/*
* Mirrors bitmap vertically.
*
- * If dst is NULL, new bitmap is allocated.
+ * The dst must be at least as big as source.
*
- * Returns pointer to destination bitmap or NULL if allocation failed.
+ * The filter works 'in-place' which means that src and dst
+ * may be very same context. Note that when aborting in-place operation
+ * the image buffer gets into an inconsitent state.
+ *
+ * Retruns zero on success, non-zero if operation was aborted.
*/
-GP_Context *GP_FilterMirrorV(const GP_Context *src, GP_Context *dst,
- GP_ProgressCallback *callback);
+int GP_FilterMirrorV(const GP_Context *src, GP_Context *dst,
+ GP_ProgressCallback *callback);
+
+/*
+ * Mirrors bitmap vertically.
+ *
+ * Returns pointer to newly allocated context, or NULL if malloc() has failed
+ * or operation was aborted from withing a callback.
+ */
+GP_Context *GP_FilterMirrorVAlloc(const GP_Context *src,
+ GP_ProgressCallback *callback);
/*
* Rotate context by 90, 180 and 270.
*
* Doesn't work 'in place'. The contexts must have equal pixel_type size must
* match the rotated size (is equal for 180 and swapped for 90 and 270).
+ *
+ * These are semi-internal functions without any assertions on destination.
*/
int GP_FilterRotate90_Raw(const GP_Context *src, GP_Context *dst,
GP_ProgressCallback *callback);
@@ -107,7 +139,7 @@ GP_Context *GP_FilterRotate270(const GP_Context *src, GP_Context *dst,
* Returns pointer to destination bitmap or NULL if allocation failed.
*/
typedef enum GP_FilterSymmetries {
- GP_ROTATE_90,
+ GP_ROTATE_90 = 0,
GP_ROTATE_CW = GP_ROTATE_90,
GP_ROTATE_180,
GP_ROTATE_270,
@@ -116,8 +148,21 @@ typedef enum GP_FilterSymmetries {
GP_MIRROR_V,
} GP_FilterSymmetries;
-GP_Context *GP_FilterSymmetry(const GP_Context *src, GP_Context *dst,
- GP_FilterSymmetries symmetry,
- GP_ProgressCallback *callback);
+/*
+ * NULL-terminated array of symmetry names (C strings).
+ */
+extern const char **GP_FilterSymmetryNames;
+
+/*
+ * Symmetry by name (as defined in GP_FilerSymmetryNames).
+ *
+ * Returns either one of the GP_FilterSymmetries enums or -1 in case of
+ * failure.
+ */
+int GP_FilterSymmetryByName(const char *symmetry);
+
+GP_Context *GP_FilterSymmetryAlloc(const GP_Context *src,
+ GP_FilterSymmetries symmetry,
+ GP_ProgressCallback *callback);
#endif /* FILTERS_GP_ROTATE_H */
diff --git a/libs/filters/GP_Rotate.c b/libs/filters/GP_Rotate.c
index 1409e06..5a7be3d 100644
--- a/libs/filters/GP_Rotate.c
+++ b/libs/filters/GP_Rotate.c
@@ -67,62 +67,72 @@ int GP_FilterMirrorH_Raw(const GP_Context *src, GP_Context *dst,
return 0;
}
-GP_Context *GP_FilterMirrorH(const GP_Context *src, GP_Context *dst,
- GP_ProgressCallback *callback)
+int GP_FilterMirrorH(const GP_Context *src, GP_Context *dst,
+ GP_ProgressCallback *callback)
{
- GP_Context *res = dst;
+ GP_ASSERT(src->pixel_type == dst->pixel_type,
+ "The src and dst pixel types must match");
+
+ GP_ASSERT(src->w <= dst->w && src->h <= dst->h,
+ "Destination is not big enough");
- if (res == NULL) {
- res = GP_ContextCopy(src, 0);
-
- if (res == NULL)
- return NULL;
- } else {
- GP_ASSERT(src->pixel_type == dst->pixel_type,
- "The src and dst pixel types must match");
- GP_ASSERT(src->w <= dst->w && src->h <= dst->h,
- "Destination is not big enough");
+ if (GP_FilterMirrorH_Raw(src, dst, callback)) {
+ GP_DEBUG(1, "Operation aborted");
+ return 1;
}
- if (GP_FilterMirrorH_Raw(src, res, callback)) {
- GP_DEBUG(1, "Operation aborted");
+ return 0;
+}
+
+GP_Context *GP_FilterMirrorHAlloc(const GP_Context *src,
+ GP_ProgressCallback *callback)
+{
+ GP_Context *res;
+
+ res = GP_ContextCopy(src, 0);
- if (dst == NULL)
- GP_ContextFree(res);
+ if (res == NULL)
+ return NULL;
+ if (GP_FilterMirrorH_Raw(src, res, callback)) {
+ GP_ContextFree(res);
return NULL;
}
-
+
return res;
}
-
-GP_Context *GP_FilterMirrorV(const GP_Context *src, GP_Context *dst,
- GP_ProgressCallback *callback)
+int GP_FilterMirrorV(const GP_Context *src, GP_Context *dst,
+ GP_ProgressCallback *callback)
{
- GP_Context *res = dst;
+ GP_ASSERT(src->pixel_type == dst->pixel_type,
+ "The src and dst pixel types must match");
+ GP_ASSERT(src->w <= dst->w && src->h <= dst->h,
+ "Destination is not big enough");
- if (res == NULL) {
- res = GP_ContextCopy(src, 0);
-
- if (res == NULL)
- return NULL;
- } else {
- GP_ASSERT(src->pixel_type == dst->pixel_type,
- "The src and dst pixel types must match");
- GP_ASSERT(src->w <= dst->w && src->h <= dst->h,
- "Destination is not big enough");
- }
-
if (GP_FilterMirrorV_Raw(src, dst, callback)) {
GP_DEBUG(1, "Operation aborted");
+ return 1;
+ }
+
+ return 0;
+}
+
+GP_Context *GP_FilterMirrorVAlloc(const GP_Context *src,
+ GP_ProgressCallback *callback)
+{
+ GP_Context *res;
+
+ res = GP_ContextCopy(src, 0);
- if (dst == NULL)
- GP_ContextFree(res);
+ if (res == NULL)
+ return NULL;
+ if (GP_FilterMirrorV_Raw(src, res, callback)) {
+ GP_ContextFree(res);
return NULL;
}
-
+
return res;
}
@@ -224,24 +234,45 @@ GP_Context *GP_FilterRotate270(const GP_Context *src, GP_Context *dst,
return res;
}
-GP_Context *GP_FilterSymmetry(const GP_Context *src, GP_Context *dst,
- GP_FilterSymmetries symmetry,
- GP_ProgressCallback *callback)
+static const char *symmetry_names[] = {
+ "90",
+ "180",
+ "270",
+ "H",
+ "V",
+ NULL,
+};
+
+const char **GP_FilterSymmetryNames = symmetry_names;
+
+int GP_FilterSymmetryByName(const char *symmetry)
+{
+ int i;
+
+ for (i = 0; symmetry_names[i] != NULL; i++)
+ if (!strcasecmp(symmetry, symmetry_names[i]))
+ return i;
+
+ return -1;
+}
+
+GP_Context *GP_FilterSymmetryAlloc(const GP_Context *src,
+ GP_FilterSymmetries symmetry,
+ GP_ProgressCallback *callback)
{
switch (symmetry) {
case GP_ROTATE_90:
- return GP_FilterRotate90(src, dst, callback);
+ return GP_FilterRotate90(src, NULL, callback);
case GP_ROTATE_180:
- return GP_FilterRotate180(src, dst, callback);
+ return GP_FilterRotate180(src, NULL, callback);
case GP_ROTATE_270:
- return GP_FilterRotate270(src, dst, callback);
+ return GP_FilterRotate270(src, NULL, callback);
case GP_MIRROR_H:
- return GP_FilterMirrorH(src, dst, callback);
+ return GP_FilterMirrorHAlloc(src, callback);
case GP_MIRROR_V:
- return GP_FilterMirrorV(src, dst, callback);
+ return GP_FilterMirrorVAlloc(src, callback);
+ default:
+ GP_DEBUG(1, "Invalid symmetry %i", (int) symmetry);
+ return NULL;
}
-
- GP_DEBUG(1, "Invalid symmetry %i", (int) symmetry);
-
- return NULL;
}
http://repo.or.cz/w/gfxprim.git/commit/d7ea6a77dc9ea5567ef84607cf98a36f6ed1…
commit d7ea6a77dc9ea5567ef84607cf98a36f6ed13c3b
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Fri May 11 20:26:15 2012 +0200
loaders: Add debug message when saving JPG/PNG image.
diff --git a/libs/loaders/GP_JPG.c b/libs/loaders/GP_JPG.c
index 51e20fc..54507b1 100644
--- a/libs/loaders/GP_JPG.c
+++ b/libs/loaders/GP_JPG.c
@@ -209,6 +209,8 @@ int GP_SaveJPG(const GP_Context *src, const char *dst_path,
struct my_jpg_err my_err;
int err;
+ GP_DEBUG(1, "Saving JPG Image '%s'", dst_path);
+
if (src->pixel_type != GP_PIXEL_RGB888 &&
src->pixel_type != GP_PIXEL_G8) {
GP_DEBUG(1, "Can't save png with pixel type %s",
diff --git a/libs/loaders/GP_PNG.c b/libs/loaders/GP_PNG.c
index 33f18fc..381039c 100644
--- a/libs/loaders/GP_PNG.c
+++ b/libs/loaders/GP_PNG.c
@@ -243,6 +243,8 @@ int GP_SavePNG(const GP_Context *src, const char *dst_path,
png_infop png_info = NULL;
int err;
+ GP_DEBUG(1, "Saving PNG Image '%s'", dst_path);
+
if (src->pixel_type != GP_PIXEL_RGB888) {
GP_DEBUG(1, "Can't save png with pixel type %s",
GP_PixelTypeName(src->pixel_type));
http://repo.or.cz/w/gfxprim.git/commit/abb8f83cb3e09d8206a071d4043be6c47dc0…
commit abb8f83cb3e09d8206a071d4043be6c47dc077ea
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Fri May 11 20:24:09 2012 +0200
doc: Update loaders docs.
* Fix GP_SaveXXX() functions
* Add GP_SaveImage()
diff --git a/doc/loaders.txt b/doc/loaders.txt
index 472a735..72aae8c 100644
--- a/doc/loaders.txt
+++ b/doc/loaders.txt
@@ -29,6 +29,24 @@ GP_Context *GP_LoadImage(const char *src_path, GP_ProgressCallback *callback);
Loads image from a file. The format is now matched by an image file extension.
File sinature loading method is on the TODO.
+[source,c]
+-------------------------------------------------------------------------------
+#include <loaders/GP_Loaders.h>
+/* or */
+#include <GP.h>
+
+int GP_SaveImage(GP_Context *src, const char *dst_path,
+ GP_ProgressCallback *callback);
+-------------------------------------------------------------------------------
+
+Saves a context into a file. The file format is matched accordingly to the
+file extension, if extension is invalid or if support for request image format
+wasn't compiled in, non-zero is returned and 'errno' is set to 'ENOSYS'.
+
+Returns zero on succes and non-zero on failure and 'errno' is set. The
+possible errno values are 'ENOSYS' for unknown format and anything that could
+be returned by 'fopen()', 'open()', 'fwrite()', 'write()', 'seek()', etc...
+
PNG
~~~
The 'PNG' loading support is optionaly implemented by libpng.
@@ -85,7 +103,7 @@ signature. Basically this combines both of the calls above.
/* or */
#include <GP.h>
-int GP_SavePNG(const char *dst_path, const GP_Context *src,
+int GP_SavePNG(const GP_Context *src, const char *dst_path,
GP_ProgressCallback *callback);
-------------------------------------------------------------------------------
@@ -152,7 +170,7 @@ signature. Basically this combines both of the calls above.
/* or */
#include <GP.h>
-int GP_SaveJPG(const char *dst_path, const GP_Context *src,
+int GP_SaveJPG(const GP_Context *src, const char *dst_path,
GP_ProgressCallback *callback);
-------------------------------------------------------------------------------
http://repo.or.cz/w/gfxprim.git/commit/762943f4d1602fd118aa6efb380a956a03da…
commit 762943f4d1602fd118aa6efb380a956a03daf8d8
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Fri May 11 20:23:04 2012 +0200
loaders: Change parameters of GP_SaveXXX() functions.
diff --git a/demos/c_simple/Makefile b/demos/c_simple/Makefile
index c6a4e24..528152f 100644
--- a/demos/c_simple/Makefile
+++ b/demos/c_simple/Makefile
@@ -5,7 +5,7 @@ CSOURCES=$(shell echo *.c)
INCLUDE=
LDLIBS+=-lGP -lGP_backends -lSDL -L$(TOPDIR)/build/
-APPS=backend_example loaders_example loaders
+APPS=backend_example loaders_example loaders filters_mirror
include $(TOPDIR)/pre.mk
include $(TOPDIR)/app.mk
diff --git a/demos/c_simple/loaders.c b/demos/c_simple/loaders.c
index 8bd9b0e..1446d52 100644
--- a/demos/c_simple/loaders.c
+++ b/demos/c_simple/loaders.c
@@ -80,7 +80,7 @@ int main(int argc, char *argv[])
priv.op = "Saving";
priv.name = "out.png";
- if (GP_SavePNG("out.png", img, &callback)) {
+ if (GP_SavePNG(img, "out.png", &callback)) {
fprintf(stderr, "Failed to save image %s", strerror(errno));
return 1;
}
diff --git a/demos/c_simple/loaders_example.c b/demos/c_simple/loaders_example.c
index b05c0b5..ab0b5b4 100644
--- a/demos/c_simple/loaders_example.c
+++ b/demos/c_simple/loaders_example.c
@@ -52,7 +52,7 @@ int main(int argc, char *argv[])
return 1;
}
- if (GP_SavePNG("out.png", img, NULL)) {
+ if (GP_SavePNG(img, "out.png", NULL)) {
fprintf(stderr, "Failed to save image %s", strerror(errno));
return 1;
}
diff --git a/demos/grinder/grinder.c b/demos/grinder/grinder.c
index be3bf09..01e8a06 100644
--- a/demos/grinder/grinder.c
+++ b/demos/grinder/grinder.c
@@ -477,7 +477,7 @@ static GP_RetCode save_jpg(GP_Context **c, const char *params)
return GP_EINVAL;
}
- GP_SaveJPG(file, *c, progress_callback);
+ GP_SaveJPG(*c, file, progress_callback);
return GP_ESUCCESS;
}
@@ -501,7 +501,7 @@ static GP_RetCode save_png(GP_Context **c, const char *params)
return GP_EINVAL;
}
- GP_SavePNG(file, *c, progress_callback);
+ GP_SavePNG(*c, file, progress_callback);
return GP_ESUCCESS;
}
@@ -836,9 +836,9 @@ static void save_by_fmt(struct GP_Context *bitmap, const char *name, const char
if (!strcmp(fmt, "ppm"))
ret = GP_SavePPM(name, bitmap, "b");
else if (!strcmp(fmt, "jpg"))
- ret = GP_SaveJPG(name, bitmap, progress_callback);
+ ret = GP_SaveJPG(bitmap, name, progress_callback);
else if (!strcmp(fmt, "png"))
- ret = GP_SavePNG(name, bitmap, progress_callback);
+ ret = GP_SavePNG(bitmap, name, progress_callback);
if (ret) {
fprintf(stderr, "Failed to save bitmap: %sn", GP_RetCodeName(ret));
diff --git a/demos/grinder/histogram.c b/demos/grinder/histogram.c
index 24fc9a7..ab6929a 100644
--- a/demos/grinder/histogram.c
+++ b/demos/grinder/histogram.c
@@ -74,7 +74,7 @@ void histogram_to_png(const GP_Context *src, const char *filename)
}
}
- GP_SavePNG(filename, res, NULL);
+ GP_SavePNG(res, filename, NULL);
GP_ContextFree(res);
GP_FilterHistogramFree(params);
diff --git a/demos/ttf2img/ttf2img.c b/demos/ttf2img/ttf2img.c
index 0dea1fe..d027139 100644
--- a/demos/ttf2img/ttf2img.c
+++ b/demos/ttf2img/ttf2img.c
@@ -88,7 +88,7 @@ int main(int argc, char *argv[])
GP_Text(context, &style, img_w/2, img_h/2, GP_ALIGN_CENTER|GP_VALIGN_CENTER,
black_pixel, white_pixel, string);
- GP_SavePNG(img_path, context, NULL);
+ GP_SavePNG(context, img_path, NULL);
GP_ContextFree(context);
diff --git a/include/loaders/GP_JPG.h b/include/loaders/GP_JPG.h
index 32dd5ca..7cbbd36 100644
--- a/include/loaders/GP_JPG.h
+++ b/include/loaders/GP_JPG.h
@@ -51,7 +51,7 @@ GP_Context *GP_LoadJPG(const char *src_path, GP_ProgressCallback *callback);
/*
* Saves JPG to a file.
*/
-int GP_SaveJPG(const char *dst_path, const GP_Context *src,
+int GP_SaveJPG(const GP_Context *src, const char *dst_path,
GP_ProgressCallback *callback);
#endif /* LOADERS_GP_JPG_H */
diff --git a/include/loaders/GP_PNG.h b/include/loaders/GP_PNG.h
index 937baf5..b866b7d 100644
--- a/include/loaders/GP_PNG.h
+++ b/include/loaders/GP_PNG.h
@@ -68,7 +68,7 @@ GP_Context *GP_LoadPNG(const char *src_path, GP_ProgressCallback *callback);
* Saves PNG to a file. Zero is returned on succes. Upon failure non-zero is
* returned and errno is filled accordingly.
*/
-int GP_SavePNG(const char *dst_path, const GP_Context *src,
+int GP_SavePNG(const GP_Context *src, const char *dst_path,
GP_ProgressCallback *callback);
#endif /* LOADERS_GP_PNG_H */
diff --git a/libs/loaders/GP_JPG.c b/libs/loaders/GP_JPG.c
index 950ca11..51e20fc 100644
--- a/libs/loaders/GP_JPG.c
+++ b/libs/loaders/GP_JPG.c
@@ -201,7 +201,7 @@ GP_Context *GP_LoadJPG(const char *src_path, GP_ProgressCallback *callback)
return GP_ReadJPG(f, callback);
}
-int GP_SaveJPG(const char *dst_path, const GP_Context *src,
+int GP_SaveJPG(const GP_Context *src, const char *dst_path,
GP_ProgressCallback *callback)
{
FILE *f;
@@ -320,8 +320,8 @@ GP_Context *GP_LoadJPG(const char GP_UNUSED(*src_path),
return NULL;
}
-int GP_SaveJPG(const char GP_UNUSED(*dst_path),
- const GP_Context GP_UNUSED(*src),
+int GP_SaveJPG(const GP_Context GP_UNUSED(*src),
+ const char GP_UNUSED(*dst_path),
GP_ProgressCallback GP_UNUSED(*callback))
{
errno = ENOSYS;
diff --git a/libs/loaders/GP_Loaders.c b/libs/loaders/GP_Loaders.c
index f3754a1..a6349bc 100644
--- a/libs/loaders/GP_Loaders.c
+++ b/libs/loaders/GP_Loaders.c
@@ -169,13 +169,13 @@ int GP_SaveImage(const GP_Context *src, const char *dst_path,
case 'N':
if (dst_path[len - 3] == 'p' ||
dst_path[len - 3] == 'P')
- return GP_SavePNG(dst_path, src, callback);
+ return GP_SavePNG(src, dst_path, callback);
break;
case 'p':
case 'P':
if (dst_path[len - 3] == 'j' ||
dst_path[len - 3] == 'J')
- return GP_SaveJPG(dst_path, src, callback);
+ return GP_SaveJPG(src, dst_path, callback);
break;
case 'e':
case 'E':
@@ -183,7 +183,7 @@ int GP_SaveImage(const GP_Context *src, const char *dst_path,
dst_path[len - 3] == 'P') &&
(dst_path[len - 4] == 'j' ||
dst_path[len - 4] == 'J'))
- return GP_SaveJPG(dst_path, src, callback);
+ return GP_SaveJPG(src, dst_path, callback);
break;
}
break;
diff --git a/libs/loaders/GP_PNG.c b/libs/loaders/GP_PNG.c
index dc1b60b..33f18fc 100644
--- a/libs/loaders/GP_PNG.c
+++ b/libs/loaders/GP_PNG.c
@@ -235,7 +235,7 @@ GP_Context *GP_LoadPNG(const char *src_path, GP_ProgressCallback *callback)
return GP_ReadPNG(f, callback);
}
-int GP_SavePNG(const char *dst_path, const GP_Context *src,
+int GP_SavePNG(const GP_Context *src, const char *dst_path,
GP_ProgressCallback *callback)
{
FILE *f;
@@ -351,8 +351,8 @@ GP_Context *GP_LoadPNG(const char GP_UNUSED(*src_path),
return NULL;
}
-int GP_SavePNG(const char GP_UNUSED(*dst_path),
- const GP_Context GP_UNUSED(*src),
+int GP_SavePNG(const GP_Context GP_UNUSED(*src),
+ const char GP_UNUSED(*dst_path),
GP_ProgressCallback GP_UNUSED(*callback))
{
errno = ENOSYS;
http://repo.or.cz/w/gfxprim.git/commit/8e6577ea43f37eba91ebae68d8998d37a17e…
commit 8e6577ea43f37eba91ebae68d8998d37a17edbe0
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Fri May 11 20:07:51 2012 +0200
loaders: GP_ImageLoad(): Set ENOSYS on unknowns image format.
diff --git a/libs/loaders/GP_Loaders.c b/libs/loaders/GP_Loaders.c
index 1a61902..f3754a1 100644
--- a/libs/loaders/GP_Loaders.c
+++ b/libs/loaders/GP_Loaders.c
@@ -65,13 +65,13 @@ GP_Context *GP_LoadImage(const char *src_path, GP_ProgressCallback *callback)
case 'N':
if (src_path[len - 3] == 'p' ||
src_path[len - 3] == 'P')
- res = GP_LoadPNG(src_path, callback);
+ return GP_LoadPNG(src_path, callback);
break;
case 'p':
case 'P':
if (src_path[len - 3] == 'j' ||
src_path[len - 3] == 'J')
- res = GP_LoadJPG(src_path, callback);
+ return GP_LoadJPG(src_path, callback);
break;
case 'e':
case 'E':
@@ -79,7 +79,7 @@ GP_Context *GP_LoadImage(const char *src_path, GP_ProgressCallback *callback)
src_path[len - 3] == 'P') &&
(src_path[len - 4] == 'j' ||
src_path[len - 4] == 'J'))
- res = GP_LoadJPG(src_path, callback);
+ return GP_LoadJPG(src_path, callback);
break;
}
break;
@@ -89,21 +89,29 @@ GP_Context *GP_LoadImage(const char *src_path, GP_ProgressCallback *callback)
switch (src_path[len - 2]) {
case 'b':
case 'B':
+ //TODO: Fix this!!!
if (src_path[len - 3] == 'p' ||
- src_path[len - 3] == 'P')
+ src_path[len - 3] == 'P') {
GP_LoadPBM(src_path, &res);
+ return res;
+ }
break;
case 'g':
case 'G':
+ //TODO: Fix this!!!
if (src_path[len - 3] == 'p' ||
- src_path[len - 3] == 'P')
+ src_path[len - 3] == 'P') {
GP_LoadPGM(src_path, &res);
+ return res;
+ }
break;
case 'p':
case 'P':
if (src_path[len - 3] == 'p' ||
- src_path[len - 3] == 'P')
+ src_path[len - 3] == 'P') {
GP_LoadPPM(src_path, &res);
+ return res;
+ }
break;
}
break;
@@ -115,7 +123,7 @@ GP_Context *GP_LoadImage(const char *src_path, GP_ProgressCallback *callback)
case 'm':
if (src_path[len - 3] == 'B' ||
src_path[len - 3] == 'b')
- res = GP_LoadBMP(src_path, callback);
+ return GP_LoadBMP(src_path, callback);
break;
}
break;
@@ -127,7 +135,7 @@ GP_Context *GP_LoadImage(const char *src_path, GP_ProgressCallback *callback)
case 'i':
if (src_path[len - 3] == 'G' ||
src_path[len - 3] == 'g')
- res = GP_LoadGIF(src_path, callback);
+ return GP_LoadGIF(src_path, callback);
break;
}
break;
@@ -136,7 +144,8 @@ GP_Context *GP_LoadImage(const char *src_path, GP_ProgressCallback *callback)
skip_filename_check:
//TODO file signature based check
- return res;
+ errno = ENOSYS;
+ return NULL;
}
int GP_SaveImage(const GP_Context *src, const char *dst_path,
http://repo.or.cz/w/gfxprim.git/commit/4e15e1706ca21c382ca73ea1de111e04bffc…
commit 4e15e1706ca21c382ca73ea1de111e04bffc34e9
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Fri May 11 20:04:04 2012 +0200
loaders: Add GP_ImageSave() function.
diff --git a/include/loaders/GP_Loaders.h b/include/loaders/GP_Loaders.h
index 2b7d0d0..38633c7 100644
--- a/include/loaders/GP_Loaders.h
+++ b/include/loaders/GP_Loaders.h
@@ -51,4 +51,21 @@
*/
GP_Context *GP_LoadImage(const char *src_path, GP_ProgressCallback *callback);
+/*
+ * Simple saving function, the image format is matched by file extension.
+ *
+ * Retruns zero on succes.
+ *
+ * On failure non-zero is returned.
+ *
+ * When file type wasn't recognized by extension or if support for requested
+ * image format wasn't compiled in non-zero is returned and errno is set to
+ * ENOSYS.
+ *
+ * The resulting errno may also be set to any possible error from fopen(3), open(3),
+ * write(3), fwrite(3), seek(3), etc..
+ */
+int GP_SaveImage(const GP_Context *src, const char *dst_path,
+ GP_ProgressCallback *callback);
+
#endif /* LOADERS_GP_LOADERS_H */
diff --git a/libs/loaders/GP_Loaders.c b/libs/loaders/GP_Loaders.c
index 6cb39e2..1a61902 100644
--- a/libs/loaders/GP_Loaders.c
+++ b/libs/loaders/GP_Loaders.c
@@ -16,13 +16,13 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, *
* Boston, MA 02110-1301 USA *
* *
- * Copyright (C) 2009-2011 Cyril Hrubis <metan(a)ucw.cz> *
+ * Copyright (C) 2009-2012 Cyril Hrubis <metan(a)ucw.cz> *
* *
*****************************************************************************/
/*
- General functions for loading bitmaps.
+ General functions for loading and saving bitmaps.
*/
@@ -138,3 +138,48 @@ skip_filename_check:
//TODO file signature based check
return res;
}
+
+int GP_SaveImage(const GP_Context *src, const char *dst_path,
+ GP_ProgressCallback *callback)
+{
+ int len;
+
+ len = strlen(dst_path);
+
+ if (len < 3) {
+ errno = ENOSYS;
+ return 1;
+ }
+
+ switch (dst_path[len - 1]) {
+ /* PNG, JPG, JPEG */
+ case 'g':
+ case 'G':
+ switch (dst_path[len - 2]) {
+ case 'n':
+ case 'N':
+ if (dst_path[len - 3] == 'p' ||
+ dst_path[len - 3] == 'P')
+ return GP_SavePNG(dst_path, src, callback);
+ break;
+ case 'p':
+ case 'P':
+ if (dst_path[len - 3] == 'j' ||
+ dst_path[len - 3] == 'J')
+ return GP_SaveJPG(dst_path, src, callback);
+ break;
+ case 'e':
+ case 'E':
+ if ((dst_path[len - 3] == 'p' ||
+ dst_path[len - 3] == 'P') &&
+ (dst_path[len - 4] == 'j' ||
+ dst_path[len - 4] == 'J'))
+ return GP_SaveJPG(dst_path, src, callback);
+ break;
+ }
+ break;
+ }
+
+ errno = ENOSYS;
+ return 1;
+}
http://repo.or.cz/w/gfxprim.git/commit/aa053ead0e51edb99977b8a0aee8eb448823…
commit aa053ead0e51edb99977b8a0aee8eb4488238473
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Fri May 11 19:38:00 2012 +0200
examples: Add runtest.sh script.
diff --git a/demos/c_simple/runtest.sh b/demos/c_simple/runtest.sh
new file mode 100755
index 0000000..0794707
--- /dev/null
+++ b/demos/c_simple/runtest.sh
@@ -0,0 +1,9 @@
+#!/bin/bash
+#
+# Run dynamically linked test.
+#
+
+PROG="$1"
+shift
+
+LD_LIBRARY_PATH=../../build/ ./$PROG "$@"
http://repo.or.cz/w/gfxprim.git/commit/043238394f939389538ed8666144c875428b…
commit 043238394f939389538ed8666144c875428b65cc
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Fri May 11 18:37:58 2012 +0200
doc: Add new example, fix paths.
diff --git a/doc/Makefile b/doc/Makefile
index 4bb74ee..d709a78 100644
--- a/doc/Makefile
+++ b/doc/Makefile
@@ -4,7 +4,7 @@ api.html: general.txt api.txt context.txt loaders.txt filters.txt basic_types.txt drawing_api.txt
asciidoc -a toc api.txt
-examples.html: examples.txt ../demos/simple/*.c ../demos/py_simple/*.py
+examples.html: examples.txt ../demos/c_simple/*.c ../demos/py_simple/*.py
asciidoc -a toc examples.txt
api.pdf: api.txt
diff --git a/doc/examples.txt b/doc/examples.txt
index c4566f2..87b8f63 100644
--- a/doc/examples.txt
+++ b/doc/examples.txt
@@ -1,31 +1,50 @@
-Simple backend example
+GFXprim Code Examples
+=====================
+Cyril Hrubis <metan(a)ucw.cz>
+
+Image loaders examples
----------------------
-Basic backend code example. Initalizes backends, draws a cross and dumps
-events.
+Loads an image and saves it into 'out.png' png image.
+
+Example in C
+~~~~~~~~~~~~
[source,c]
------------------------------------------------------------------
-include::../demos/simple/backend_example.c[]
+include::../demos/c_simple/loaders_example.c[]
------------------------------------------------------------------
-Simple loaders example
-----------------------
-
-Loads an image and saves it into 'out.png' png image.
+Example in C utilizing progress callback
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[source,c]
------------------------------------------------------------------
-include::../demos/simple/loaders_example.c[]
+include::../demos/c_simple/loaders.c[]
------------------------------------------------------------------
-And the same in python
+Example in Python
+~~~~~~~~~~~~~~~~~
[source,python]
------------------------------------------------------------------
include::../demos/py_simple/loaders_example.py[]
------------------------------------------------------------------
+Simple backend example
+----------------------
+
+Basic backend code example. Initalizes backends, draws a cross and dumps
+events.
+
+Example in C
+~~~~~~~~~~~~
+
+[source,c]
+------------------------------------------------------------------
+include::../demos/c_simple/backend_example.c[]
+------------------------------------------------------------------
+
GFXprim + PyGTK
---------------
http://repo.or.cz/w/gfxprim.git/commit/d2aa0848db79445801a3ca718ced2204c7e4…
commit d2aa0848db79445801a3ca718ced2204c7e4d783
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Fri May 11 18:31:06 2012 +0200
examples: Add loaders example utilizing progress callback.
diff --git a/demos/c_simple/Makefile b/demos/c_simple/Makefile
index 7fd7505..c6a4e24 100644
--- a/demos/c_simple/Makefile
+++ b/demos/c_simple/Makefile
@@ -5,7 +5,7 @@ CSOURCES=$(shell echo *.c)
INCLUDE=
LDLIBS+=-lGP -lGP_backends -lSDL -L$(TOPDIR)/build/
-APPS=backend_example loaders_example
+APPS=backend_example loaders_example loaders
include $(TOPDIR)/pre.mk
include $(TOPDIR)/app.mk
diff --git a/demos/c_simple/loaders.c b/demos/c_simple/loaders.c
new file mode 100644
index 0000000..8bd9b0e
--- /dev/null
+++ b/demos/c_simple/loaders.c
@@ -0,0 +1,91 @@
+/*****************************************************************************
+ * This file is part of gfxprim library. *
+ * *
+ * Gfxprim is free software; you can redistribute it and/or *
+ * modify it under the terms of the GNU Lesser General Public *
+ * License as published by the Free Software Foundation; either *
+ * version 2.1 of the License, or (at your option) any later version. *
+ * *
+ * Gfxprim is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with gfxprim; if not, write to the Free Software *
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
+ * Boston, MA 02110-1301 USA *
+ * *
+ * Copyright (C) 2009-2012 Cyril Hrubis <metan(a)ucw.cz> *
+ * *
+ *****************************************************************************/
+
+ /*
+
+ Simple loaders example utilizing progress callback.
+
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+
+#include <GP.h>
+
+struct callback_priv {
+ char *op;
+ char *name;
+};
+
+static int progress_callback(GP_ProgressCallback *self)
+{
+ struct callback_priv *priv = self->priv;
+
+ printf("r%s '%s' %3.1f%%", priv->op, priv->name, self->percentage);
+ fflush(stdout);
+
+ /*
+ * It's important to return zero as non-zero return value
+ * aborts the operation.
+ */
+ return 0;
+}
+
+int main(int argc, char *argv[])
+{
+ GP_Context *img;
+ struct callback_priv priv;
+ GP_ProgressCallback callback = {.callback = progress_callback,
+ .priv = &priv};
+
+ if (argc != 2) {
+ fprintf(stderr, "Takes an image as an parametern");
+ return 0;
+ }
+
+ priv.op = "Loading";
+ priv.name = argv[1];
+
+ img = GP_LoadImage(argv[1], &callback);
+
+ if (img == NULL) {
+ fprintf(stderr, "Failed to load image '%s':%sn", argv[1],
+ strerror(errno));
+ return 1;
+ }
+
+ printf("n");
+
+
+ priv.op = "Saving";
+ priv.name = "out.png";
+
+ if (GP_SavePNG("out.png", img, &callback)) {
+ fprintf(stderr, "Failed to save image %s", strerror(errno));
+ return 1;
+ }
+
+ printf("n");
+
+ return 0;
+}
http://repo.or.cz/w/gfxprim.git/commit/53fcdc5357cb56708be84b483bf6facd0c38…
commit 53fcdc5357cb56708be84b483bf6facd0c380108
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Fri May 11 18:14:00 2012 +0200
examples: Move simple c examples into c_simple directory.
diff --git a/demos/Makefile b/demos/Makefile
index 6cbebf6..ec4885b 100644
--- a/demos/Makefile
+++ b/demos/Makefile
@@ -1,3 +1,3 @@
TOPDIR=..
-SUBDIRS=grinder spiv particle ttf2img simple
+SUBDIRS=grinder spiv particle ttf2img c_simple
include $(TOPDIR)/post.mk
diff --git a/demos/simple/Makefile b/demos/c_simple/Makefile
similarity index 100%
rename from demos/simple/Makefile
rename to demos/c_simple/Makefile
diff --git a/demos/simple/backend_example.c b/demos/c_simple/backend_example.c
similarity index 100%
rename from demos/simple/backend_example.c
rename to demos/c_simple/backend_example.c
diff --git a/demos/simple/loaders_example.c b/demos/c_simple/loaders_example.c
similarity index 100%
rename from demos/simple/loaders_example.c
rename to demos/c_simple/loaders_example.c
http://repo.or.cz/w/gfxprim.git/commit/953585da5ceb2376fbb96db9965268a3566b…
commit 953585da5ceb2376fbb96db9965268a3566b26b4
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Fri May 11 18:03:23 2012 +0200
Remove unused file.
diff --git a/LICENSE b/LICENSE
deleted file mode 100644
index 240f484..0000000
--- a/LICENSE
+++ /dev/null
@@ -1,24 +0,0 @@
-/*****************************************************************************
- * This file is part of gfxprim library. *
- * *
- * Gfxprim is free software; you can redistribute it and/or *
- * modify it under the terms of the GNU Lesser General Public *
- * License as published by the Free Software Foundation; either *
- * version 2.1 of the License, or (at your option) any later version. *
- * *
- * Gfxprim is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with gfxprim; if not, write to the Free Software *
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
- * Boston, MA 02110-1301 USA *
- * *
- * Copyright (C) 2009-2010 Jiri "BlueBear" Dluhos *
- * <jiri.bluebear.dluhos(a)gmail.com> *
- * *
- * Copyright (C) 2009-2010 Cyril Hrubis <metan(a)ucw.cz> *
- * *
- *****************************************************************************/
http://repo.or.cz/w/gfxprim.git/commit/c696193212ee6fb4704cbb12c0d56d189647…
commit c696193212ee6fb4704cbb12c0d56d189647ccb8
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Fri May 11 18:02:32 2012 +0200
Remove finished tasks from TODO.
diff --git a/TODO b/TODO
index ac6d898..04e7bdc 100644
--- a/TODO
+++ b/TODO
@@ -1,22 +1,9 @@
What's not implemented (and should be)
--------------------------------------
-* bitmaps and blitting
- - blit bitmaps (should respect rotation and pixel formats)
- * IN PROGRESS
- - loading bitmaps from image files (jpg, png, bmp, pnm ...)
- * IN NEARLY FINISHED
-
-* backends
- - finish framebuffer backend (SDL does not work on most of my framebuffers)
- - other than SDL X backend (SDL does support only one window)
- - some overall initialization routines
- - backed event handling
-
* Meditate about bit endians and why these aren't separate pixel types
(which would make our lives a bit easier)
-
Advanced features
-----------------
@@ -26,5 +13,3 @@ Advanced features
* gfx primitives
- drawing with alpha channel
- anti aliasing
-
-* freetype support
http://repo.or.cz/w/gfxprim.git/commit/6585778ebe915cccfe630d49782e6db6c0ac…
commit 6585778ebe915cccfe630d49782e6db6c0ac6c94
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Fri May 11 17:59:18 2012 +0200
input: Do not include internal headers in GP_Input.h
This fixes SDL-less and Xlib less build.
diff --git a/include/input/GP_Input.h b/include/input/GP_Input.h
index 07724ae..80ebe2b 100644
--- a/include/input/GP_Input.h
+++ b/include/input/GP_Input.h
@@ -28,10 +28,4 @@
*/
#include "input/GP_Event.h"
-/*
- * Input drivers (semi internal).
- */
-#include "input/GP_InputDriverSDL.h"
-#include "input/GP_InputDriverLinux.h"
-
#endif /* INPUT_GP_INPUT_H */
http://repo.or.cz/w/gfxprim.git/commit/c9ca2a9c99541ef2a206db9344c9feda3942…
commit c9ca2a9c99541ef2a206db9344c9feda39426db7
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Fri May 11 17:56:04 2012 +0200
build: gfxprim-config: print error on invalid option.
diff --git a/configure b/configure
index 3e05d42..bd08e4b 100755
--- a/configure
+++ b/configure
@@ -214,7 +214,8 @@ def write_gfxprim_config(cfg, libs):
ldflags += '-lGP_backends '
ldflags += libs.get_linker_flags(i)
f.write('t--libs-%s) echo -n "%s ";;n' % (i, ldflags))
-
+
+ f.write('t*) echo "Invalid option '$1'"; echo $USAGE; exit 1;;n')
f.write('tesacntshiftndonenechon')
f.close()
http://repo.or.cz/w/gfxprim.git/commit/3275310a73bb7a599d6e1da9a4f6debf1e35…
commit 3275310a73bb7a599d6e1da9a4f6debf1e358635
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Fri May 11 17:52:16 2012 +0200
buid: Use list rather than dict in list of modules.
diff --git a/configure b/configure
index dee4a4f..3e05d42 100755
--- a/configure
+++ b/configure
@@ -233,26 +233,26 @@ if __name__ == '__main__':
#
# Library detection/enable disable
#
- # name, description, [detection], cflags, ldflags, dict of modules library is needed for
+ # name, description, [detection], cflags, ldflags, list of modules library is needed for
#
l = libraries([["libpng",
"Portable Network Graphics Library",
- [header_exists, "png.h"], "", "-lpng", {"loaders"}],
+ [header_exists, "png.h"], "", "-lpng", ["loaders"]],
["libsdl",
"Simple Direct Media Layer",
- [header_exists, "SDL/SDL.h"], "", "`sdl-config --libs`", {"backends"}],
+ [header_exists, "SDL/SDL.h"], "", "`sdl-config --libs`", ["backends"]],
["jpeg",
"Library to load, handle and manipulate images in the JPEG format",
- [header_exists, "jpeglib.h"], "", "-ljpeg", {"loaders"}],
+ [header_exists, "jpeglib.h"], "", "-ljpeg", ["loaders"]],
["giflib",
"Library to handle, display and manipulate GIF images",
- [header_exists, "gif_lib.h"], "", "-lgif", {"loaders"}],
+ [header_exists, "gif_lib.h"], "", "-lgif", ["loaders"]],
["libX11",
"X11 library",
- [header_exists, "X11/Xlib.h"], "", "-lX11", {"backends"}],
+ [header_exists, "X11/Xlib.h"], "", "-lX11", ["backends"]],
["freetype",
"A high-quality and portable font engine",
- [header_exists, "ft2build.h"], "", "`freetype-config --libs`", {"core"}]], cfg)
+ [header_exists, "ft2build.h"], "", "`freetype-config --libs`", ["core"]]], cfg)
parser = OptionParser();
http://repo.or.cz/w/gfxprim.git/commit/ba095a866ae6547879193c256d9c206585ef…
commit ba095a866ae6547879193c256d9c206585efbfe7
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Fri May 11 17:48:14 2012 +0200
build: Make configure die verbosely on missing compilers.
diff --git a/configure b/configure
index aa1d268..dee4a4f 100755
--- a/configure
+++ b/configure
@@ -142,13 +142,26 @@ class libraries:
res += " " + i[4]
return res
+def die_screaming(msg):
+ sys.stderr.write("n************************************n")
+ sys.stderr.write("ERROR: ")
+ sys.stderr.write(msg)
+ sys.stderr.write("n************************************n")
+ exit(1)
+
+#
+# Check for basic compiling tools
+#
def basic_checks(cfg):
sys.stderr.write("Basic checksn")
sys.stderr.write("------------n")
+
if not c_compiler_exists(cfg):
- exit(1)
+ die_screaming("No C compiler found")
+
if not python_module_installed(cfg, 'jinja2'):
- exit(1)
+ die_screaming("No jinja2 python module found")
+
check_for_swig(cfg)
sys.stderr.write("n")
@@ -194,7 +207,6 @@ def write_gfxprim_config(cfg, libs):
f.write('t--cflags) echo -n "-I/usr/include/GP/ ";;n')
f.write('t--libs) echo -n "-lGP %s ";;n' % libs.get_linker_flags('core'))
-
# ldflags for specific modules
for i in modules:
ldflags = ''
-----------------------------------------------------------------------
Summary of changes:
LICENSE | 24 --
TODO | 15 --
configure | 35 ++-
demos/Makefile | 2 +-
demos/{simple => c_simple}/Makefile | 2 +-
demos/{simple => c_simple}/backend_example.c | 0
.../filters_symmetry.c} | 81 +++++-
.../loaders_example.c => c_simple/loaders.c} | 42 +++-
demos/{simple => c_simple}/loaders_example.c | 2 +-
demos/{particle => c_simple}/runtest.sh | 0
demos/grinder/grinder.c | 18 +-
demos/grinder/histogram.c | 2 +-
demos/py_simple/loaders_example.py | 3 +-
demos/py_simple/rotate90.py | 24 ++
demos/spiv/spiv.c | 6 +-
demos/ttf2img/ttf2img.c | 2 +-
doc/Makefile | 2 +-
doc/examples.txt | 61 ++++-
doc/loaders.txt | 22 ++-
include/filters/GP_Rotate.h | 98 ++++++--
include/input/GP_Input.h | 6 -
include/loaders/GP_JPG.h | 2 +-
include/loaders/GP_Loaders.h | 17 ++
include/loaders/GP_PNG.h | 2 +-
libs/filters/GP_Rotate.c | 266 ++++++++++++-------
libs/loaders/GP_JPG.c | 8 +-
libs/loaders/GP_Loaders.c | 76 +++++-
libs/loaders/GP_PNG.c | 8 +-
pylib/gfxprim/filters/filters.i | 8 +
29 files changed, 589 insertions(+), 245 deletions(-)
delete mode 100644 LICENSE
rename demos/{simple => c_simple}/Makefile (74%)
rename demos/{simple => c_simple}/backend_example.c (100%)
copy demos/{simple/loaders_example.c => c_simple/filters_symmetry.c} (55%)
copy demos/{simple/loaders_example.c => c_simple/loaders.c} (73%)
rename demos/{simple => c_simple}/loaders_example.c (98%)
copy demos/{particle => c_simple}/runtest.sh (100%)
create mode 100755 demos/py_simple/rotate90.py
repo.or.cz automatic notification. Contact project admin jiri.bluebear.dluhos(a)gmail.com
if you want to unsubscribe, or site admin admin(a)repo.or.cz if you receive
no reply.
--
gfxprim.git ("A simple 2D graphics library with emphasis on correctness and well-defined operation.")
1
0
[repo.or.cz] gfxprim.git branch master updated: 179ad0f8718479d653783f56c3128ef4cad8d880
by metan 09 May '12
by metan 09 May '12
09 May '12
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project gfxprim.git.
The branch, master has been updated
via 179ad0f8718479d653783f56c3128ef4cad8d880 (commit)
from e418052b3d66f20cca5780f21f9c493a37f3d5af (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
http://repo.or.cz/w/gfxprim.git/commit/179ad0f8718479d653783f56c3128ef4cad8…
commit 179ad0f8718479d653783f56c3128ef4cad8d880
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Wed May 9 01:28:29 2012 +0200
backends: X11 fix off-by-one.
diff --git a/libs/backends/GP_X11.c b/libs/backends/GP_X11.c
index 02137bd..af98a67 100644
--- a/libs/backends/GP_X11.c
+++ b/libs/backends/GP_X11.c
@@ -69,7 +69,7 @@ static void x11_update_rect(GP_Backend *self, GP_Coord x0, GP_Coord y0,
XLockDisplay(x11->dpy);
XPutImage(x11->dpy, x11->win, DefaultGC(x11->dpy, x11->scr),
- x11->img, x0, y0, x0, y0, x1-x0, y1-y0);
+ x11->img, x0, y0, x0, y0, x1-x0+1, y1-y0+1);
XFlush(x11->dpy);
x11->resized_flag = 0;
@@ -117,8 +117,8 @@ static void x11_poll(GP_Backend *self)
break;
x11_update_rect(self, ev.xexpose.x, ev.xexpose.y,
- ev.xexpose.x + ev.xexpose.width,
- ev.xexpose.y + ev.xexpose.height);
+ ev.xexpose.x + ev.xexpose.width - 1,
+ ev.xexpose.y + ev.xexpose.height - 1);
break;
case ConfigureNotify:
if (ev.xconfigure.width == (int)self->context->w &&
-----------------------------------------------------------------------
Summary of changes:
libs/backends/GP_X11.c | 6 +++---
1 files changed, 3 insertions(+), 3 deletions(-)
repo.or.cz automatic notification. Contact project admin jiri.bluebear.dluhos(a)gmail.com
if you want to unsubscribe, or site admin admin(a)repo.or.cz if you receive
no reply.
--
gfxprim.git ("A simple 2D graphics library with emphasis on correctness and well-defined operation.")
1
0
[repo.or.cz] gfxprim.git branch master updated: e418052b3d66f20cca5780f21f9c493a37f3d5af
by metan 09 May '12
by metan 09 May '12
09 May '12
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project gfxprim.git.
The branch, master has been updated
via e418052b3d66f20cca5780f21f9c493a37f3d5af (commit)
via c2924a18ba98b3241d9ae2b912f6889d5bafbb9c (commit)
from 64f27b70dc6f1ae231c627ac30beda08aef45a7b (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
http://repo.or.cz/w/gfxprim.git/commit/e418052b3d66f20cca5780f21f9c493a37f3…
commit e418052b3d66f20cca5780f21f9c493a37f3d5af
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Wed May 9 01:04:39 2012 +0200
spiv: Show progress when window was resized.
diff --git a/demos/spiv/spiv.c b/demos/spiv/spiv.c
index 06e507a..18cfabc 100644
--- a/demos/spiv/spiv.c
+++ b/demos/spiv/spiv.c
@@ -520,6 +520,8 @@ int main(int argc, char *argv[])
switch (ev.code) {
case GP_EV_SYS_RESIZE:
GP_BackendResize(backend, ev.val.sys.w, ev.val.sys.h);
+ GP_Fill(backend->context, 0);
+ params.show_progress_once = 1;
show_image(¶ms);
break;
case GP_EV_SYS_QUIT:
http://repo.or.cz/w/gfxprim.git/commit/c2924a18ba98b3241d9ae2b912f6889d5baf…
commit c2924a18ba98b3241d9ae2b912f6889d5bafbb9c
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Wed May 9 01:03:56 2012 +0200
backends: X11 ignore expose events until Update or Flip is called.
diff --git a/libs/backends/GP_X11.c b/libs/backends/GP_X11.c
index fb95a52..02137bd 100644
--- a/libs/backends/GP_X11.c
+++ b/libs/backends/GP_X11.c
@@ -37,6 +37,8 @@ struct x11_priv {
Window win;
Visual *vis;
XImage *img;
+
+ int resized_flag;
};
static void x11_exit(GP_Backend *self)
@@ -70,6 +72,8 @@ static void x11_update_rect(GP_Backend *self, GP_Coord x0, GP_Coord y0,
x11->img, x0, y0, x0, y0, x1-x0, y1-y0);
XFlush(x11->dpy);
+ x11->resized_flag = 0;
+
XUnlockDisplay(x11->dpy);
}
@@ -86,6 +90,8 @@ static void x11_flip(GP_Backend *self)
XPutImage(x11->dpy, x11->win, DefaultGC(x11->dpy, x11->scr),
x11->img, 0, 0, 0, 0, w, h);
XFlush(x11->dpy);
+
+ x11->resized_flag = 0;
XUnlockDisplay(x11->dpy);
}
@@ -106,6 +112,10 @@ static void x11_poll(GP_Backend *self)
ev.xexpose.x, ev.xexpose.y,
ev.xexpose.width, ev.xexpose.height,
ev.xexpose.count);
+
+ if (x11->resized_flag)
+ break;
+
x11_update_rect(self, ev.xexpose.x, ev.xexpose.y,
ev.xexpose.x + ev.xexpose.width,
ev.xexpose.y + ev.xexpose.height);
@@ -170,6 +180,8 @@ static int x11_set_attributes(struct GP_Backend *self,
/* Resize X11 window */
XResizeWindow(x11->dpy, x11->win, w, h);
XFlush(x11->dpy);
+
+ x11->resized_flag = 1;
}
XUnlockDisplay(x11->dpy);
@@ -227,7 +239,7 @@ GP_Backend *GP_BackendX11Init(const char *display, int x, int y,
GP_DEBUG(1, "Failed to create window");
goto err2;
}
-
+
/* Select events */
XSelectInput(x11->dpy, x11->win, ExposureMask | StructureNotifyMask |
KeyPressMask | KeyReleaseMask |
@@ -241,6 +253,9 @@ GP_Backend *GP_BackendX11Init(const char *display, int x, int y,
/* Show window */
XMapWindow(x11->dpy, x11->win);
XFlush(x11->dpy);
+
+ x11->resized_flag = 0;
+
/*
enum GP_PixelType pixel_type;
@@ -266,6 +281,7 @@ GP_Backend *GP_BackendX11Init(const char *display, int x, int y,
backend->Poll = x11_poll;
backend->SetAttributes = x11_set_attributes;
+
return backend;
//err3:
// XDestroyWindow(x11->dpy, x11->win);
-----------------------------------------------------------------------
Summary of changes:
demos/spiv/spiv.c | 2 ++
libs/backends/GP_X11.c | 18 +++++++++++++++++-
2 files changed, 19 insertions(+), 1 deletions(-)
repo.or.cz automatic notification. Contact project admin jiri.bluebear.dluhos(a)gmail.com
if you want to unsubscribe, or site admin admin(a)repo.or.cz if you receive
no reply.
--
gfxprim.git ("A simple 2D graphics library with emphasis on correctness and well-defined operation.")
1
0
[repo.or.cz] gfxprim.git branch master updated: 64f27b70dc6f1ae231c627ac30beda08aef45a7b
by metan 09 May '12
by metan 09 May '12
09 May '12
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project gfxprim.git.
The branch, master has been updated
via 64f27b70dc6f1ae231c627ac30beda08aef45a7b (commit)
via f30503b333e5373c182ec8a7122edc8fea1140e3 (commit)
from be0a281e8050b1bd51dfd575d6f9d3296c521b88 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
http://repo.or.cz/w/gfxprim.git/commit/64f27b70dc6f1ae231c627ac30beda08aef4…
commit 64f27b70dc6f1ae231c627ac30beda08aef45a7b
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Wed May 9 00:48:00 2012 +0200
backends: Do not reset rotation flags on resize.
diff --git a/libs/backends/GP_SDL.c b/libs/backends/GP_SDL.c
index ae0e8c6..3923619 100644
--- a/libs/backends/GP_SDL.c
+++ b/libs/backends/GP_SDL.c
@@ -111,11 +111,6 @@ int context_from_surface(GP_Context *context, SDL_Surface *surf)
context->w = surf->w;
context->h = surf->h;
- /* orientation */
- context->axes_swap = 0;
- context->x_swap = 0;
- context->y_swap = 0;
-
return 0;
}
@@ -196,7 +191,7 @@ GP_Backend *GP_BackendSDLInit(GP_Size w, GP_Size h, uint8_t bpp, uint8_t flags,
SDL_Quit();
return NULL;
}
-
+
backend.context = &context;
}
diff --git a/libs/backends/GP_X11.c b/libs/backends/GP_X11.c
index 8f9b519..fb95a52 100644
--- a/libs/backends/GP_X11.c
+++ b/libs/backends/GP_X11.c
@@ -138,7 +138,6 @@ static int x11_set_attributes(struct GP_Backend *self,
}
if (w != 0 || h != 0) {
- GP_Context *context;
XImage *img;
if (w == 0)
@@ -154,20 +153,17 @@ static int x11_set_attributes(struct GP_Backend *self,
w, h, 32, 0);
/* Allocate new context */
- context = GP_ContextAlloc(w, h, GP_PIXEL_xRGB8888);
- if (context == NULL) {
+ if (GP_ContextResize(self->context, w, h)) {
XDestroyImage(img);
return 1;
}
- /* Free old image and context */
- GP_ContextFree(self->context);
+ /* Free old image */
x11->img->data = NULL;
XDestroyImage(x11->img);
/* Swap the pointers */
- self->context = context;
img->data = (char*)self->context->pixels;
x11->img = img;
http://repo.or.cz/w/gfxprim.git/commit/f30503b333e5373c182ec8a7122edc8fea11…
commit f30503b333e5373c182ec8a7122edc8fea1140e3
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Wed May 9 00:47:42 2012 +0200
core: Add GP_ContextResize().
diff --git a/include/core/GP_Context.h b/include/core/GP_Context.h
index a6b76df..95a6863 100644
--- a/include/core/GP_Context.h
+++ b/include/core/GP_Context.h
@@ -106,6 +106,13 @@ void GP_ContextInit(GP_Context *context, GP_Size w, GP_Size h,
GP_PixelType type, void *pixels);
/*
+ * Resizes context->pixels array and changes metadata to match.
+ *
+ * Returns non-zero on failure (remalloc() has failed).
+ */
+int GP_ContextResize(GP_Context *context, GP_Size w, GP_Size h);
+
+/*
* If passed the pixels are copied to newly created context, otherwise
* the pixels are allocated but uninitalized.
*/
diff --git a/libs/core/GP_Context.c b/libs/core/GP_Context.c
index 87a44d1..967edcb 100644
--- a/libs/core/GP_Context.c
+++ b/libs/core/GP_Context.c
@@ -70,12 +70,17 @@ GP_Context *GP_ContextCopy(const GP_Context *src, int flag)
return new;
}
+static uint32_t get_bpr(uint32_t bpp, uint32_t w)
+{
+ return (bpp * w) / 8 + !!((bpp * w) % 8);
+}
+
GP_Context *GP_ContextAlloc(GP_Size w, GP_Size h, GP_PixelType type)
{
GP_CHECK_VALID_PIXELTYPE(type);
GP_Context *context = malloc(sizeof(GP_Context));
uint32_t bpp = GP_PixelSize(type);
- uint32_t bpr = (bpp * w) / 8 + !!((bpp * w) % 8);
+ uint32_t bpr = get_bpr(bpp, w);
void *pixels;
pixels = malloc(bpr * h);
@@ -108,11 +113,29 @@ GP_Context *GP_ContextAlloc(GP_Size w, GP_Size h, GP_PixelType type)
return context;
}
+int GP_ContextResize(GP_Context *context, GP_Size w, GP_Size h)
+{
+ uint32_t bpr = get_bpr(context->bpp, w);
+ void *pixels;
+
+ pixels = realloc(context->pixels, bpr * h);
+
+ if (pixels == NULL)
+ return 1;
+
+ context->w = w;
+ context->h = h;
+ context->bytes_per_row = bpr;
+ context->pixels = pixels;
+
+ return 0;
+}
+
void GP_ContextInit(GP_Context *context, GP_Size w, GP_Size h,
GP_PixelType type, void *pixels)
{
uint32_t bpp = GP_PixelSize(type);
- uint32_t bpr = (bpp * w) / 8 + !!((bpp * w) % 8);
+ uint32_t bpr = get_bpr(bpp, w);
context->pixels = pixels;
context->bpp = bpp;
-----------------------------------------------------------------------
Summary of changes:
include/core/GP_Context.h | 7 +++++++
libs/backends/GP_SDL.c | 7 +------
libs/backends/GP_X11.c | 8 ++------
libs/core/GP_Context.c | 27 +++++++++++++++++++++++++--
4 files changed, 35 insertions(+), 14 deletions(-)
repo.or.cz automatic notification. Contact project admin jiri.bluebear.dluhos(a)gmail.com
if you want to unsubscribe, or site admin admin(a)repo.or.cz if you receive
no reply.
--
gfxprim.git ("A simple 2D graphics library with emphasis on correctness and well-defined operation.")
1
0
[repo.or.cz] gfxprim.git branch master updated: be0a281e8050b1bd51dfd575d6f9d3296c521b88
by metan 09 May '12
by metan 09 May '12
09 May '12
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project gfxprim.git.
The branch, master has been updated
via be0a281e8050b1bd51dfd575d6f9d3296c521b88 (commit)
via 1f439d7f38b1ce547311f98f00727d482d33b3e8 (commit)
via 71db1f001c26932cbcd61e28365e62d491f7f61e (commit)
via f2de66cdd44a7250114d04992265239db3ecd3e3 (commit)
via 31cd248d65bc525ab2f8587bf51fdf9cc39965ef (commit)
from bcc7ec1a9edd6f0caf76bcce92eb0c4a827d99b1 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
http://repo.or.cz/w/gfxprim.git/commit/be0a281e8050b1bd51dfd575d6f9d3296c52…
commit be0a281e8050b1bd51dfd575d6f9d3296c521b88
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Tue May 8 23:57:16 2012 +0200
spiv: Fix rounding error when centering image.
diff --git a/demos/spiv/spiv.c b/demos/spiv/spiv.c
index 42b40ba..06e507a 100644
--- a/demos/spiv/spiv.c
+++ b/demos/spiv/spiv.c
@@ -246,8 +246,8 @@ static void *image_loader(void *ptr)
/* clean up the rest of the display */
GP_FillRectXYWH(context, 0, 0, cx, context->h, black_pixel);
GP_FillRectXYWH(context, 0, 0, context->w, cy, black_pixel);
- GP_FillRectXYWH(context, ret->w+cx, 0, cx, context->h, black_pixel);
- GP_FillRectXYWH(context, 0, ret->h+cy, context->w, cy, black_pixel);
+ GP_FillRectXYWH(context, ret->w+cx, 0, context->w - ret->w - cx, context->h, black_pixel);
+ GP_FillRectXYWH(context, 0, ret->h+cy, context->w, context->h - ret->h - cy, black_pixel);
cpu_timer_stop(&sum_timer);
http://repo.or.cz/w/gfxprim.git/commit/1f439d7f38b1ce547311f98f00727d482d33…
commit 1f439d7f38b1ce547311f98f00727d482d33b3e8
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Tue May 8 23:46:04 2012 +0200
spiv: Make use of the SYS_RESIZE and SYS_QUIT events.
diff --git a/demos/spiv/spiv.c b/demos/spiv/spiv.c
index da4a97b..42b40ba 100644
--- a/demos/spiv/spiv.c
+++ b/demos/spiv/spiv.c
@@ -42,7 +42,6 @@ static GP_Pixel black_pixel;
static GP_Pixel white_pixel;
static GP_Backend *backend = NULL;
-static GP_Context *context = NULL;
/* image loader thread */
static int abort_flag = 0;
@@ -53,6 +52,7 @@ static int resampling_method = GP_INTERP_LINEAR_LF_INT;
static int image_loader_callback(GP_ProgressCallback *self)
{
static GP_Size size = 0;
+ GP_Context *c = backend->context;
if (abort_flag)
return 1;
@@ -65,8 +65,6 @@ static int image_loader_callback(GP_ProgressCallback *self)
snprintf(buf, sizeof(buf), "%s ... %-3.1f%%",
(const char*)self->priv, self->percentage);
- GP_Context *c = context;
-
int align = GP_ALIGN_CENTER|GP_VALIGN_ABOVE;
GP_TextClear(c, NULL, c->w/2, c->h - 4, align,
@@ -126,7 +124,7 @@ static void *image_loader(void *ptr)
GP_ProgressCallback callback = {.callback = image_loader_callback};
struct cpu_timer timer;
struct cpu_timer sum_timer;
- GP_Context *img;
+ GP_Context *img, *context = backend->context;
cpu_timer_start(&sum_timer, "sum");
@@ -331,6 +329,7 @@ static void init_backend(const char *backend_opts)
int main(int argc, char *argv[])
{
GP_InputDriverLinux *drv = NULL;
+ GP_Context *context = NULL;
const char *input_dev = NULL;
const char *backend_opts = "SDL";
int sleep_sec = -1;
@@ -517,6 +516,18 @@ int main(int argc, char *argv[])
break;
}
break;
+ case GP_EV_SYS:
+ switch (ev.code) {
+ case GP_EV_SYS_RESIZE:
+ GP_BackendResize(backend, ev.val.sys.w, ev.val.sys.h);
+ show_image(¶ms);
+ break;
+ case GP_EV_SYS_QUIT:
+ GP_BackendExit(backend);
+ return 0;
+ break;
+ }
+ break;
}
}
}
http://repo.or.cz/w/gfxprim.git/commit/71db1f001c26932cbcd61e28365e62d491f7…
commit 71db1f001c26932cbcd61e28365e62d491f7f61e
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Tue May 8 23:45:38 2012 +0200
debug: Print debug level too.
diff --git a/include/core/GP_Debug.h b/include/core/GP_Debug.h
index 2c935ee..235f001 100644
--- a/include/core/GP_Debug.h
+++ b/include/core/GP_Debug.h
@@ -45,12 +45,13 @@
#define GP_DEFAULT_DEBUG_LEVEL 0
-#define GP_DEBUG(level, ...) do { - if (level <= GP_GetDebugLevel()) { - fprintf(stderr, "%s:%s():%u: ", __FILE__, __FUNCTION__, __LINE__); - fprintf(stderr, __VA_ARGS__); - fputc('n', stderr); - } +#define GP_DEBUG(level, ...) do { + if (level <= GP_GetDebugLevel()) { + fprintf(stderr, "%u: %s:%s():%u: ", level, __FILE__, + __FUNCTION__, __LINE__); + fprintf(stderr, __VA_ARGS__); + fputc('n', stderr); + } } while (0)
void GP_SetDebugLevel(unsigned int level);
http://repo.or.cz/w/gfxprim.git/commit/f2de66cdd44a7250114d04992265239db3ec…
commit f2de66cdd44a7250114d04992265239db3ecd3e3
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Tue May 8 23:33:20 2012 +0200
input, backends: Add support for SYS_RESIZE and SYS_QUIT.
diff --git a/libs/backends/GP_BackendInit.c b/libs/backends/GP_BackendInit.c
index 5f6a470..0f8e8d4 100644
--- a/libs/backends/GP_BackendInit.c
+++ b/libs/backends/GP_BackendInit.c
@@ -73,7 +73,7 @@ static GP_Backend *backend_sdl_init(char *params, const char *caption,
return GP_BackendSDLInit(0, 0, 0, 0, caption);
GP_Size w = 0, h = 0;
- uint8_t flags = 0;
+ uint8_t flags = GP_SDL_RESIZABLE;
char *s = params;
diff --git a/libs/backends/GP_X11.c b/libs/backends/GP_X11.c
index f11cd6a..8f9b519 100644
--- a/libs/backends/GP_X11.c
+++ b/libs/backends/GP_X11.c
@@ -110,9 +110,10 @@ static void x11_poll(GP_Backend *self)
ev.xexpose.x + ev.xexpose.width,
ev.xexpose.y + ev.xexpose.height);
break;
- case MapNotify:
- GP_DEBUG(1, "Shown");
- break;
+ case ConfigureNotify:
+ if (ev.xconfigure.width == (int)self->context->w &&
+ ev.xconfigure.height == (int)self->context->h)
+ break;
default:
GP_InputDriverX11EventPut(&ev);
break;
@@ -130,9 +131,11 @@ static int x11_set_attributes(struct GP_Backend *self,
XLockDisplay(x11->dpy);
- if (caption != NULL)
+ if (caption != NULL) {
+ GP_DEBUG(3, "Setting window caption to '%s'", caption);
XmbSetWMProperties(x11->dpy, x11->win, caption, caption,
NULL, 0, NULL, NULL, NULL);
+ }
if (w != 0 || h != 0) {
GP_Context *context;
@@ -143,6 +146,8 @@ static int x11_set_attributes(struct GP_Backend *self,
if (h == 0)
h = self->context->h;
+
+ GP_DEBUG(3, "Setting window size to %ux%u", w, h);
/* Create new X image */
img = XCreateImage(x11->dpy, x11->vis, 24, ZPixmap, 0, NULL,
@@ -228,7 +233,7 @@ GP_Backend *GP_BackendX11Init(const char *display, int x, int y,
}
/* Select events */
- XSelectInput(x11->dpy, x11->win, StructureNotifyMask | ExposureMask |
+ XSelectInput(x11->dpy, x11->win, ExposureMask | StructureNotifyMask |
KeyPressMask | KeyReleaseMask |
ButtonPressMask | ButtonReleaseMask |
PointerMotionMask);
diff --git a/libs/input/GP_InputDriverSDL.c b/libs/input/GP_InputDriverSDL.c
index 3b7ec01..b954127 100644
--- a/libs/input/GP_InputDriverSDL.c
+++ b/libs/input/GP_InputDriverSDL.c
@@ -132,8 +132,10 @@ void GP_InputDriverSDLEventPut(SDL_Event *ev)
GP_EventPushKey(key, ev->key.state, NULL);
break;
case SDL_VIDEORESIZE:
+ GP_EventPushResize(ev->resize.w, ev->resize.h, NULL);
break;
case SDL_QUIT:
+ GP_EventPush(GP_EV_SYS, GP_EV_SYS_QUIT, 0, NULL);
break;
}
}
diff --git a/libs/input/GP_InputDriverX11.c b/libs/input/GP_InputDriverX11.c
index 719ef3b..bab3b2a 100644
--- a/libs/input/GP_InputDriverX11.c
+++ b/libs/input/GP_InputDriverX11.c
@@ -90,6 +90,11 @@ void GP_InputDriverX11EventPut(XEvent *ev)
GP_EventPush(GP_EV_KEY, key, press, NULL);
break;
+ case ConfigureNotify:
+ GP_EventPushResize(ev->xconfigure.width,
+ ev->xconfigure.height, NULL);
+ break;
+ break;
case MotionNotify:
GP_EventPushRelTo(ev->xmotion.x, ev->xmotion.y, NULL);
break;
@@ -108,6 +113,8 @@ void GP_InputDriverX11EventPut(XEvent *ev)
GP_EventPushKey(key, press, NULL);
break;
+ default:
+ GP_DEBUG(0, "Unhandled X11 event type %u", ev->type);
}
}
http://repo.or.cz/w/gfxprim.git/commit/31cd248d65bc525ab2f8587bf51fdf9cc399…
commit 31cd248d65bc525ab2f8587bf51fdf9cc39965ef
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Tue May 8 23:32:39 2012 +0200
input: Prepare for SYS_RESIZE and SYS_QUIT events.
diff --git a/include/input/GP_Event.h b/include/input/GP_Event.h
index e12d9ae..962c71c 100644
--- a/include/input/GP_Event.h
+++ b/include/input/GP_Event.h
@@ -45,7 +45,8 @@ enum GP_EventType {
GP_EV_KEY = 1, /* key/button press event */
GP_EV_REL = 2, /* relative event */
GP_EV_ABS = 3, /* absolute event */
- GP_EV_MAX = 3, /* maximum, greater values are free */
+ GP_EV_SYS = 4, /* system events window close, resize... */
+ GP_EV_MAX = 4, /* maximum, greater values are free */
};
enum GP_EventKeyCode {
@@ -220,6 +221,11 @@ enum GP_EventAbsCode {
GP_EV_ABS_POS = 0,
};
+enum GP_EventSysCode {
+ GP_EV_SYS_QUIT = 0,
+ GP_EV_SYS_RESIZE = 1,
+};
+
struct GP_EventPosRel {
int32_t rx;
int32_t ry;
@@ -236,14 +242,20 @@ struct GP_EventKey {
char ascii;
};
+struct GP_EventSys {
+ uint32_t w, h;
+};
+
union GP_EventValue {
/* generic one integer value */
int32_t val;
/* key */
struct GP_EventKey key;
- /* possition */
+ /* position */
struct GP_EventPosRel rel;
struct GP_EventPosAbs abs;
+ /* system event */
+ struct GP_EventSys sys;
};
typedef struct GP_Event {
@@ -327,6 +339,11 @@ void GP_EventPushAbs(uint32_t x, uint32_t y, uint32_t pressure,
void GP_EventPushKey(uint32_t key, uint8_t code, struct timeval *time);
/*
+ * Inject window resize event
+ */
+void GP_EventPushResize(uint32_t w, uint32_t h, struct timeval *time);
+
+/*
* Inject common event.
*/
void GP_EventPush(uint16_t type, uint32_t code, int32_t value,
diff --git a/libs/input/GP_Event.c b/libs/input/GP_Event.c
index 161c0de..fe118ff 100644
--- a/libs/input/GP_Event.c
+++ b/libs/input/GP_Event.c
@@ -16,7 +16,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, *
* Boston, MA 02110-1301 USA *
* *
- * Copyright (C) 2009-2011 Cyril Hrubis <metan(a)ucw.cz> *
+ * Copyright (C) 2009-2012 Cyril Hrubis <metan(a)ucw.cz> *
* *
*****************************************************************************/
@@ -163,6 +163,18 @@ static void dump_abs(struct GP_Event *ev)
}
}
+static void dump_sys(struct GP_Event *ev)
+{
+ switch (ev->code) {
+ case GP_EV_SYS_QUIT:
+ printf("Sys Quitn");
+ break;
+ case GP_EV_SYS_RESIZE:
+ printf("Sys Resize %ux%un", ev->val.sys.w, ev->val.sys.h);
+ break;
+ }
+}
+
void GP_EventDump(struct GP_Event *ev)
{
printf("Event (%u) ", (unsigned int)ev->time.tv_sec % 10000);
@@ -177,6 +189,9 @@ void GP_EventDump(struct GP_Event *ev)
case GP_EV_ABS:
dump_abs(ev);
break;
+ case GP_EV_SYS:
+ dump_sys(ev);
+ break;
default:
printf("Unknown %un", ev->type);
}
@@ -276,6 +291,21 @@ void GP_EventPushAbs(uint32_t x, uint32_t y, uint32_t pressure,
event_put(&cur_state);
}
+void GP_EventPushResize(uint32_t w, uint32_t h, struct timeval *time)
+{
+ /* event header */
+ cur_state.type = GP_EV_SYS;
+ cur_state.code = GP_EV_SYS_RESIZE;
+
+ cur_state.val.sys.w = w;
+ cur_state.val.sys.h = h;
+
+ set_time(time);
+
+ /* put it into queue */
+ event_put(&cur_state);
+}
+
static char keys_to_ascii[] = {
0x00, 0x1b, '1', '2', '3', '4', '5', '6', '7', '8',
'9', '0', '-', '=', 0x08, 't', 'q', 'w', 'e', 'r',
-----------------------------------------------------------------------
Summary of changes:
demos/spiv/spiv.c | 23 +++++++++++++++++------
include/core/GP_Debug.h | 13 +++++++------
include/input/GP_Event.h | 21 +++++++++++++++++++--
libs/backends/GP_BackendInit.c | 2 +-
libs/backends/GP_X11.c | 15 ++++++++++-----
libs/input/GP_Event.c | 32 +++++++++++++++++++++++++++++++-
libs/input/GP_InputDriverSDL.c | 2 ++
libs/input/GP_InputDriverX11.c | 7 +++++++
8 files changed, 94 insertions(+), 21 deletions(-)
repo.or.cz automatic notification. Contact project admin jiri.bluebear.dluhos(a)gmail.com
if you want to unsubscribe, or site admin admin(a)repo.or.cz if you receive
no reply.
--
gfxprim.git ("A simple 2D graphics library with emphasis on correctness and well-defined operation.")
1
0
[repo.or.cz] gfxprim.git branch master updated: bcc7ec1a9edd6f0caf76bcce92eb0c4a827d99b1
by metan 08 May '12
by metan 08 May '12
08 May '12
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project gfxprim.git.
The branch, master has been updated
via bcc7ec1a9edd6f0caf76bcce92eb0c4a827d99b1 (commit)
via 2d381801266820dab9804fd1539d910bb3cfd352 (commit)
from c80b947b60c5cb4af6b5498b070a33b5baa15e69 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
http://repo.or.cz/w/gfxprim.git/commit/bcc7ec1a9edd6f0caf76bcce92eb0c4a827d…
commit bcc7ec1a9edd6f0caf76bcce92eb0c4a827d99b1
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Tue May 8 21:53:37 2012 +0200
spiv: Make use of new backend fucntions.
diff --git a/demos/spiv/spiv.c b/demos/spiv/spiv.c
index 7ecf094..da4a97b 100644
--- a/demos/spiv/spiv.c
+++ b/demos/spiv/spiv.c
@@ -108,7 +108,16 @@ static const char *img_name(const char *img_path)
return &img_path[i+1];
}
- return NULL;
+ return img_path;
+}
+
+static void set_caption(const char *path, float rat)
+{
+ char buf[256];
+
+ snprintf(buf, sizeof(buf), "Spiv ~ %s 1:%3.3f", img_name(path), rat);
+
+ GP_BackendSetCaption(backend, buf);
}
static void *image_loader(void *ptr)
@@ -155,6 +164,19 @@ static void *image_loader(void *ptr)
break;
}
+ /* Try to resize window */
+ /*
+ if (!GP_BackendResize(backend, img->w, img->h)) {
+ context = backend->context;
+
+ GP_Blit_Raw(img, 0, 0, img->w, img->h, context, 0, 0);
+ GP_BackendFlip(backend);
+ set_caption(params->img_path, 1);
+
+ return NULL;
+ }
+ */
+
float rat = calc_img_size(img->w, img->h, w, h);
w = img->w;
@@ -231,6 +253,8 @@ static void *image_loader(void *ptr)
cpu_timer_stop(&sum_timer);
+ set_caption(params->img_path, rat);
+
if (!params->show_info) {
GP_BackendFlip(backend);
return NULL;
http://repo.or.cz/w/gfxprim.git/commit/2d381801266820dab9804fd1539d910bb3cf…
commit 2d381801266820dab9804fd1539d910bb3cfd352
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Tue May 8 21:53:13 2012 +0200
backends: Add support for resize and caption on-the-fly.
diff --git a/include/backends/GP_Backend.h b/include/backends/GP_Backend.h
index c83a411..1f8428e 100644
--- a/include/backends/GP_Backend.h
+++ b/include/backends/GP_Backend.h
@@ -72,7 +72,7 @@ typedef struct GP_Backend {
* If display is buffered, this copies content
* of context onto display.
*
- * If display is not buffered, this is no-op.
+ * If display is not buffered, this is no-op (set to NULL).
*/
void (*Flip)(struct GP_Backend *self);
@@ -82,13 +82,26 @@ typedef struct GP_Backend {
* In contrast to flip operation, the context
* must not change (this is intended for updating very small areas).
*
- * If display is not buffered, this is no-op.
+ * If display is not buffered, this is no-op (set to NULL).
*/
void (*UpdateRect)(struct GP_Backend *self,
GP_Coord x0, GP_Coord y0,
GP_Coord x1, GP_Coord y1);
/*
+ * Callback to change attributes.
+ *
+ * If w and h are zero, only caption is changed.
+ *
+ * If caption is NULL only w and h are changed.
+ *
+ * Use the inline wrappers instead.
+ */
+ int (*SetAttributes)(struct GP_Backend *self,
+ uint32_t w, uint32_t h,
+ const char *caption);
+
+ /*
* Exits the backend.
*/
void (*Exit)(struct GP_Backend *self);
@@ -146,4 +159,30 @@ static inline void GP_BackendPoll(GP_Backend *backend)
backend->Poll(backend);
}
+/*
+ * Sets backend caption, if supported.
+ *
+ * When setting caption is not possible/implemented non zero is returned.
+ */
+static inline int GP_BackendSetCaption(GP_Backend *backend,
+ const char *caption)
+{
+ if (backend->SetAttributes == NULL)
+ return 1;
+
+ return backend->SetAttributes(backend, 0, 0, caption);
+}
+
+/*
+ * Resize backend, if supported.
+ *
+ * When resizing is not possible/implemented non zero is returned.
+ *
+ * When the backend size matches the passed width and height,
+ * no action is done.
+ *
+ * Note that after calling this, the backend->context pointer may change.
+ */
+int GP_BackendResize(GP_Backend *backend, uint32_t w, uint32_t h);
+
#endif /* BACKENDS_GP_BACKEND_H */
diff --git a/libs/backends/GP_Backend.c b/libs/backends/GP_Backend.c
index d878760..fc37449 100644
--- a/libs/backends/GP_Backend.c
+++ b/libs/backends/GP_Backend.c
@@ -40,3 +40,15 @@ void GP_BackendUpdateRect(GP_Backend *backend,
backend->UpdateRect(backend, x0, y0, x1, y1);
}
+
+
+int GP_BackendResize(GP_Backend *backend, uint32_t w, uint32_t h)
+{
+ if (backend->SetAttributes == NULL)
+ return 1;
+
+ if (backend->context->w == w && backend->context->h == h)
+ return 0;
+
+ return backend->SetAttributes(backend, w, h, NULL);
+}
diff --git a/libs/backends/GP_LinuxFB.c b/libs/backends/GP_LinuxFB.c
index d0ad3c7..3a511c3 100644
--- a/libs/backends/GP_LinuxFB.c
+++ b/libs/backends/GP_LinuxFB.c
@@ -233,13 +233,14 @@ GP_Backend *GP_BackendLinuxFBInit(const char *path)
fb->context.pixel_type = pixel_type;
/* update API */
- backend->name = "Linux FB";
- backend->context = &fb->context;
- backend->Flip = fb_flip_noop;
- backend->UpdateRect = fb_update_rect_noop;
- backend->Exit = fb_exit;
- backend->fd_list = NULL;
- backend->Poll = NULL;
+ backend->name = "Linux FB";
+ backend->context = &fb->context;
+ backend->Flip = fb_flip_noop;
+ backend->UpdateRect = fb_update_rect_noop;
+ backend->Exit = fb_exit;
+ backend->SetAttributes = NULL;
+ backend->fd_list = NULL;
+ backend->Poll = NULL;
return backend;
err3:
diff --git a/libs/backends/GP_SDL.c b/libs/backends/GP_SDL.c
index 6a8d0d4..ae0e8c6 100644
--- a/libs/backends/GP_SDL.c
+++ b/libs/backends/GP_SDL.c
@@ -39,6 +39,8 @@ static SDL_Surface *sdl_surface;
static SDL_mutex *mutex;
static GP_Context context;
+static uint32_t sdl_flags = SDL_SWSURFACE;
+
/* Backend API funcitons */
static void sdl_flip(struct GP_Backend *self __attribute__((unused)))
@@ -79,29 +81,6 @@ static void sdl_poll(struct GP_Backend *self __attribute__((unused)))
SDL_mutexV(mutex);
}
-static void sdl_exit(struct GP_Backend *self __attribute__((unused)));
-
-static struct GP_Backend backend = {
- .name = "SDL",
- .context = NULL,
- .Flip = sdl_flip,
- .UpdateRect = sdl_update_rect,
- .Exit = sdl_exit,
- .fd_list = NULL,
- .Poll = sdl_poll,
-};
-
-static void sdl_exit(struct GP_Backend *self __attribute__((unused)))
-{
- SDL_mutexP(mutex);
-
- SDL_Quit();
-
- SDL_DestroyMutex(mutex);
-
- backend.context = NULL;
-}
-
int context_from_surface(GP_Context *context, SDL_Surface *surf)
{
/* sanity checks on the SDL surface */
@@ -140,6 +119,49 @@ int context_from_surface(GP_Context *context, SDL_Surface *surf)
return 0;
}
+static int sdl_set_attributes(struct GP_Backend *self __attribute__((unused)),
+ uint32_t w, uint32_t h,
+ const char *caption)
+{
+ SDL_mutexP(mutex);
+
+ if (caption != NULL)
+ SDL_WM_SetCaption(caption, caption);
+
+ if (w != 0 && h != 0) {
+ sdl_surface = SDL_SetVideoMode(w, h, 0, sdl_flags);
+ context_from_surface(&context, sdl_surface);
+ }
+
+ SDL_mutexV(mutex);
+
+ return 0;
+}
+
+static void sdl_exit(struct GP_Backend *self __attribute__((unused)));
+
+static struct GP_Backend backend = {
+ .name = "SDL",
+ .context = NULL,
+ .Flip = sdl_flip,
+ .UpdateRect = sdl_update_rect,
+ .SetAttributes = sdl_set_attributes,
+ .Exit = sdl_exit,
+ .fd_list = NULL,
+ .Poll = sdl_poll,
+};
+
+static void sdl_exit(struct GP_Backend *self __attribute__((unused)))
+{
+ SDL_mutexP(mutex);
+
+ SDL_Quit();
+
+ SDL_DestroyMutex(mutex);
+
+ backend.context = NULL;
+}
+
GP_Backend *GP_BackendSDLInit(GP_Size w, GP_Size h, uint8_t bpp, uint8_t flags,
const char *caption)
{
@@ -150,8 +172,6 @@ GP_Backend *GP_BackendSDLInit(GP_Size w, GP_Size h, uint8_t bpp, uint8_t flags,
return NULL;
}
- uint32_t sdl_flags = SDL_SWSURFACE;
-
if (flags & GP_SDL_FULLSCREEN)
sdl_flags |= SDL_FULLSCREEN;
diff --git a/libs/backends/GP_X11.c b/libs/backends/GP_X11.c
index a19ea7b..f11cd6a 100644
--- a/libs/backends/GP_X11.c
+++ b/libs/backends/GP_X11.c
@@ -37,21 +37,23 @@ struct x11_priv {
Window win;
Visual *vis;
XImage *img;
-
- GP_Context *context;
};
static void x11_exit(GP_Backend *self)
{
struct x11_priv *x11 = GP_BACKEND_PRIV(self);
+
+ XLockDisplay(x11->dpy);
+
+ GP_ContextFree(self->context);
x11->img->data = NULL;
XDestroyImage(x11->img);
XDestroyWindow(x11->dpy, x11->win);
+ /* I wonder if this is right sequence... */
+ XUnlockDisplay(x11->dpy);
XCloseDisplay(x11->dpy);
- GP_ContextFree(x11->context);
-
free(self);
}
@@ -74,8 +76,8 @@ static void x11_update_rect(GP_Backend *self, GP_Coord x0, GP_Coord y0,
static void x11_flip(GP_Backend *self)
{
struct x11_priv *x11 = GP_BACKEND_PRIV(self);
- unsigned int w = x11->context->w;
- unsigned int h = x11->context->h;
+ unsigned int w = self->context->w;
+ unsigned int h = self->context->h;
GP_DEBUG(4, "Flipping context");
@@ -120,6 +122,60 @@ static void x11_poll(GP_Backend *self)
XUnlockDisplay(x11->dpy);
}
+static int x11_set_attributes(struct GP_Backend *self,
+ uint32_t w, uint32_t h,
+ const char *caption)
+{
+ struct x11_priv *x11 = GP_BACKEND_PRIV(self);
+
+ XLockDisplay(x11->dpy);
+
+ if (caption != NULL)
+ XmbSetWMProperties(x11->dpy, x11->win, caption, caption,
+ NULL, 0, NULL, NULL, NULL);
+
+ if (w != 0 || h != 0) {
+ GP_Context *context;
+ XImage *img;
+
+ if (w == 0)
+ w = self->context->w;
+
+ if (h == 0)
+ h = self->context->h;
+
+ /* Create new X image */
+ img = XCreateImage(x11->dpy, x11->vis, 24, ZPixmap, 0, NULL,
+ w, h, 32, 0);
+
+ /* Allocate new context */
+ context = GP_ContextAlloc(w, h, GP_PIXEL_xRGB8888);
+
+ if (context == NULL) {
+ XDestroyImage(img);
+ return 1;
+ }
+
+ /* Free old image and context */
+ GP_ContextFree(self->context);
+ x11->img->data = NULL;
+ XDestroyImage(x11->img);
+
+ /* Swap the pointers */
+ self->context = context;
+ img->data = (char*)self->context->pixels;
+ x11->img = img;
+
+ /* Resize X11 window */
+ XResizeWindow(x11->dpy, x11->win, w, h);
+ XFlush(x11->dpy);
+ }
+
+ XUnlockDisplay(x11->dpy);
+
+ return 0;
+}
+
GP_Backend *GP_BackendX11Init(const char *display, int x, int y,
unsigned int w, unsigned int h,
const char *caption)
@@ -137,9 +193,9 @@ GP_Backend *GP_BackendX11Init(const char *display, int x, int y,
x11 = GP_BACKEND_PRIV(backend);
- x11->context = GP_ContextAlloc(w, h, GP_PIXEL_xRGB8888);
+ backend->context = GP_ContextAlloc(w, h, GP_PIXEL_xRGB8888);
- if (x11->context == NULL)
+ if (backend->context == NULL)
goto err0;
//TODO: Error checking
@@ -159,7 +215,7 @@ GP_Backend *GP_BackendX11Init(const char *display, int x, int y,
x11->img = XCreateImage(x11->dpy, x11->vis, 24, ZPixmap, 0, NULL,
w, h, 32, 0);
- x11->img->data = (char*)x11->context->pixels;
+ x11->img->data = (char*)backend->context->pixels;
x11->win = XCreateWindow(x11->dpy, DefaultRootWindow(x11->dpy),
x, y, w, h, 0, CopyFromParent,
@@ -201,13 +257,13 @@ GP_Backend *GP_BackendX11Init(const char *display, int x, int y,
*/
- backend->name = "X11";
- backend->context = x11->context;
- backend->Flip = x11_flip;
- backend->UpdateRect = x11_update_rect;
- backend->Exit = x11_exit;
- backend->fd_list = NULL;
- backend->Poll = x11_poll;
+ backend->name = "X11";
+ backend->Flip = x11_flip;
+ backend->UpdateRect = x11_update_rect;
+ backend->Exit = x11_exit;
+ backend->fd_list = NULL;
+ backend->Poll = x11_poll;
+ backend->SetAttributes = x11_set_attributes;
return backend;
//err3:
@@ -215,7 +271,7 @@ GP_Backend *GP_BackendX11Init(const char *display, int x, int y,
err2:
XCloseDisplay(x11->dpy);
err1:
- GP_ContextFree(x11->context);
+ GP_ContextFree(backend->context);
err0:
free(backend);
return NULL;
-----------------------------------------------------------------------
Summary of changes:
demos/spiv/spiv.c | 26 +++++++++++-
include/backends/GP_Backend.h | 43 ++++++++++++++++++-
libs/backends/GP_Backend.c | 12 +++++
libs/backends/GP_LinuxFB.c | 15 ++++---
libs/backends/GP_SDL.c | 70 ++++++++++++++++++++-----------
libs/backends/GP_X11.c | 90 +++++++++++++++++++++++++++++++++--------
6 files changed, 204 insertions(+), 52 deletions(-)
repo.or.cz automatic notification. Contact project admin jiri.bluebear.dluhos(a)gmail.com
if you want to unsubscribe, or site admin admin(a)repo.or.cz if you receive
no reply.
--
gfxprim.git ("A simple 2D graphics library with emphasis on correctness and well-defined operation.")
1
0