Gfxprim
Threads by month
- ----- 2026 -----
- February
- 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
December 2012
- 3 participants
- 79 discussions
[repo.or.cz] gfxprim.git branch master updated: 5f214b37219110e2e9051b3bfffbbd65498002b7
by gavento 18 Dec '12
by gavento 18 Dec '12
18 Dec '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 5f214b37219110e2e9051b3bfffbbd65498002b7 (commit)
from 910d31f9711c5e518189c5e5f47761125ef06207 (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/5f214b37219110e2e9051b3bfffbbd654980…
commit 5f214b37219110e2e9051b3bfffbbd65498002b7
Author: Tomas Gavenciak <gavento(a)ucw.cz>
Date: Tue Dec 18 14:33:22 2012 +0100
Grammar fix
diff --git a/doc/input.txt b/doc/input.txt
index 44da370..6a85ebf 100644
--- a/doc/input.txt
+++ b/doc/input.txt
@@ -38,7 +38,7 @@ typedef struct GP_Event {
struct timeval time;
/*
- * Cursor possition, possition on screen accumulated
+ * Cursor position, possition on screen accumulated
* from all pointer devices
*/
uint32_t cursor_x;
diff --git a/include/input/GP_Event.h b/include/input/GP_Event.h
index de5d93e..162a5d2 100644
--- a/include/input/GP_Event.h
+++ b/include/input/GP_Event.h
@@ -271,7 +271,7 @@ typedef struct GP_Event {
struct timeval time;
/*
- * Cursor possition, possition on screen accumulated
+ * Cursor position, position on screen accumulated
* from all pointer devices
*/
uint32_t cursor_x;
@@ -290,7 +290,7 @@ typedef struct GP_Event {
void GP_EventSetScreenSize(uint32_t w, uint32_t h);
/*
- * Sets global cursor possition, doesn't generate event.
+ * Sets global cursor position, doesn't generate an event.
*
* Use for initial cursor placement.
*/
diff --git a/include/loaders/GP_JPG.h b/include/loaders/GP_JPG.h
index 5906b11..5ee57ce 100644
--- a/include/loaders/GP_JPG.h
+++ b/include/loaders/GP_JPG.h
@@ -40,7 +40,7 @@
int GP_OpenJPG(const char *src_path, FILE **f);
/*
- * Reads JPG from an open FILE. Expects the file possition set after the eight
+ * Reads JPG from an open FILE. Expects the file position set after the eight
* bytes JPG signature.
*/
GP_Context *GP_ReadJPG(FILE *f, GP_ProgressCallback *callback);
diff --git a/include/loaders/GP_PNG.h b/include/loaders/GP_PNG.h
index 4b6e3bb..cbb4b70 100644
--- a/include/loaders/GP_PNG.h
+++ b/include/loaders/GP_PNG.h
@@ -47,13 +47,13 @@
/*
* Opens up file and checks signature. Upon successful return (zero is
- * returned) the file possition would be set to eight bytes (exactly after the
+ * returned) the file position would be set to eight bytes (exactly after the
* PNG signature).
*/
int GP_OpenPNG(const char *src_path, FILE **f);
/*
- * Reads PNG from an open FILE. Expects the file possition set after the eight
+ * Reads PNG from an open FILE. Expects the file position set after the eight
* bytes PNG signature.
*
* Upon succesfull return pointer to newly allocated context is returned.
diff --git a/libs/input/GP_Event.c b/libs/input/GP_Event.c
index cb66c4f..efd82c9 100644
--- a/libs/input/GP_Event.c
+++ b/libs/input/GP_Event.c
@@ -29,7 +29,7 @@
#include "GP_Event.h"
-/* Screen size for clipping the cursor possition */
+/* Screen size for clipping the cursor position */
static uint32_t screen_w = 0, screen_h = 0;
/* Event queue */
diff --git a/libs/loaders/GP_PNM.h b/libs/loaders/GP_PNM.h
index af59319..2ce48a3 100644
--- a/libs/loaders/GP_PNM.h
+++ b/libs/loaders/GP_PNM.h
@@ -32,7 +32,7 @@
#include <stdint.h>
/*
- * Loads image header, returns pointer to FILE* (with file possition pointing
+ * Loads image header, returns pointer to FILE* (with file position pointing
* to the start of the data stream) on success, fills image metadata into
* arguments.
*/
-----------------------------------------------------------------------
Summary of changes:
doc/input.txt | 2 +-
include/input/GP_Event.h | 4 ++--
include/loaders/GP_JPG.h | 2 +-
include/loaders/GP_PNG.h | 4 ++--
libs/input/GP_Event.c | 2 +-
libs/loaders/GP_PNM.h | 2 +-
6 files changed, 8 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: 910d31f9711c5e518189c5e5f47761125ef06207
by metan 18 Dec '12
by metan 18 Dec '12
18 Dec '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 910d31f9711c5e518189c5e5f47761125ef06207 (commit)
via 6812b812594d07e3a6b7543400e710424ce23597 (commit)
from 89909d1774eb1b3ac35e2e643401bab3b79c9dc2 (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/910d31f9711c5e518189c5e5f47761125ef0…
commit 910d31f9711c5e518189c5e5f47761125ef06207
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Tue Dec 18 13:55:12 2012 +0100
doc: input: Add input events docs + code cleanup.
diff --git a/build/syms/Event_symbols.txt b/build/syms/Event_symbols.txt
index 9f80506..6dc7e12 100644
--- a/build/syms/Event_symbols.txt
+++ b/build/syms/Event_symbols.txt
@@ -9,7 +9,7 @@ GP_EventDump
GP_EventPushResize
GP_EventPushRelTo
GP_EventSetScreenCursor
-GP_EventQueued
+GP_EventsQueued
GP_InputDriverLinuxRead
GP_InputDriverSDLEventPut
diff --git a/demos/c_simple/Makefile b/demos/c_simple/Makefile
index e64dda7..cce46d8 100644
--- a/demos/c_simple/Makefile
+++ b/demos/c_simple/Makefile
@@ -16,9 +16,9 @@ LDLIBS+=-lrt `$(TOPDIR)/gfxprim-config --libs --libs-backends`
APPS=backend_example loaders_example loaders filters_symmetry gfx_koch virtual_backend_example meta_data meta_data_dump tmp_file showimage- v4l2_show v4l2_grab convolution weighted_median shapetest koch input- fileview linetest randomshapetest fonttest loaders_register blittest- textaligntest
+ v4l2_show v4l2_grab convolution weighted_median shapetest koch + input_example fileview linetest randomshapetest fonttest+ loaders_register blittest textaligntest
ifeq ($(HAVE_LIBSDL),yes)
APPS+=SDL_glue
diff --git a/demos/c_simple/input.c b/demos/c_simple/input_example.c
similarity index 98%
rename from demos/c_simple/input.c
rename to demos/c_simple/input_example.c
index 6a083e2..38cc1e3 100644
--- a/demos/c_simple/input.c
+++ b/demos/c_simple/input_example.c
@@ -56,7 +56,7 @@ static void event_loop(void)
for (;;) {
GP_BackendWait(backend);
- while (GP_EventQueued()) {
+ while (GP_EventsQueued()) {
GP_Event ev;
GP_EventGet(&ev);
@@ -128,8 +128,6 @@ int main(int argc, char *argv[])
}
}
-// GP_SetDebugLevel(10);
-
backend = GP_BackendInit(backend_opts, "Input Test", stderr);
if (backend == NULL) {
diff --git a/doc/Makefile b/doc/Makefile
index 4160ae0..f72b8c3 100644
--- a/doc/Makefile
+++ b/doc/Makefile
@@ -1,6 +1,6 @@
SOURCES=general.txt context.txt loaders.txt filters.txt basic_types.txt drawing_api.txt backends.txt gamma.txt grabbers.txt - environment_variables.txt debug.txt core.txt api.txt
+ environment_variables.txt debug.txt core.txt api.txt input.txt
EXAMPLE_SOURCES=$(wildcard example_*.txt)
diff --git a/doc/api.txt b/doc/api.txt
index aff68ea..cee4d1a 100644
--- a/doc/api.txt
+++ b/doc/api.txt
@@ -49,6 +49,11 @@ Cyril Hrubis <metan(a)ucw.cz>
+
Backends API for drawing on the screen or into a window.
+
+. link:input.html[Input Events]
+ +
+ Input event handling such as key presses, mouse coordinates, touchscreens
+ and window manager events such as window close or window resize.
+ +
. link:grabbers.html[Grabbers]
+
Video grabbers interface such as V4L2.
diff --git a/doc/backends.txt b/doc/backends.txt
index 86d5d51..d760daf 100644
--- a/doc/backends.txt
+++ b/doc/backends.txt
@@ -274,3 +274,20 @@ returned. If backend size already matches w and h, nothing is done.
Note that backend->context pointer may change upon calling this function and
at least backend->context->pixels pointer will change.
+[source,c]
+-------------------------------------------------------------------------------
+#include <backends/GP_Backend.h>
+/* or */
+#include <GP.h>
+
+int GP_BackendResizeAck(GP_Backend *self);
+-------------------------------------------------------------------------------
+
+If backend is resizeable by user interaction (for example X Window) you will
+get resize event for each change of window size, however the backend context
+will not be resized untill you call this function. This is usefull in
+multithreaded application where one threads waits for events and others draws
+into the buffer so you can stop the drawing threads before the backend context
+size change.
+
+See input link:input.html[input events] for more information.
diff --git a/doc/example_input.txt b/doc/example_input.txt
new file mode 100644
index 0000000..15b7233
--- /dev/null
+++ b/doc/example_input.txt
@@ -0,0 +1,7 @@
+Input Events Example
+--------------------
+
+[source,c]
+------------------------------------------------------------------
+include::../demos/c_simple/input_example.c[]
+------------------------------------------------------------------
diff --git a/doc/input.txt b/doc/input.txt
new file mode 100644
index 0000000..44da370
--- /dev/null
+++ b/doc/input.txt
@@ -0,0 +1,271 @@
+Input Events
+------------
+
+Input events are somehow tied to the link:backends.html[backends]. Possibly in
+contrast with other libraries there is not always 1:1 correspondence between
+input driver and backend graphics driver. That means that you can, for
+example, use linux input events together with X Window without any problems.
+You can even write application that doesn't draw any graphics at all and still
+use some of the input drivers. There are, of course, cases where input driver
+is created only together with graphics driver, this is the case for example
+for X Window backends or SDL backends.
+
+The basic structure is roughly modeled after Linux kernel input API. The main
+difference is that events that belongs together are delivered together. For
+example mouse coordinates are bundled in one event.
+
+For example usage see backend link:example_input.html[example].
+
+Event Structure Description
+~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+[source,c]
+-------------------------------------------------------------------------------
+#include <GP.h>
+/* or */
+#include <input/GP_Event.h>
+
+typedef struct GP_Event {
+ /* event */
+ uint16_t type;
+ uint32_t code;
+ union GP_EventValue val;
+
+ /* input device id */
+ uint32_t dev_id;
+
+ /* event timestamp */
+ struct timeval time;
+
+ /*
+ * Cursor possition, possition on screen accumulated
+ * from all pointer devices
+ */
+ uint32_t cursor_x;
+ uint32_t cursor_y;
+
+ /*
+ * Bitmap of pressed keys including mouse buttons
+ * accumulated for all input devices.
+ */
+ uint8_t keys_pressed[GP_EVENT_KEYMAP_BYTES];
+} GP_Event;
+-------------------------------------------------------------------------------
+
+The GP_Event structure is basic block that describes input event (i.e. key was
+pressed/released, mouse was moved, window was resized by user).
+
+[source,c]
+-------------------------------------------------------------------------------
+enum GP_EventType {
+ GP_EV_KEY, /* key/button press event */
+ GP_EV_REL, /* relative event */
+ GP_EV_ABS, /* absolute event */
+ GP_EV_SYS, /* system events window close, resize... */
+ GP_EV_MAX = GP_EV_SYS, /* maximum, greater values are free */
+};
+-------------------------------------------------------------------------------
+
+The event 'type' determines highlevel nature of the event.
+
+* Key events covers keyboard button presses, mouse buttons, etc.
+* Relative events covers mostly mouse coordinates
+* Absolute events covers touchscreens and tablets
+* System events are used mostly for propagating window close and window
+ resize events
+* Values greater than 'GP_EV_MAX' are free for user events
+
+[source,c]
+-------------------------------------------------------------------------------
+enum GP_EventKeyCode {
+ GP_EV_KEY_UP,
+ GP_EV_KEY_DOWN,
+ GP_EV_KEY_REPEAT,
+};
+
+enum GP_EventRelCode {
+ GP_EV_REL_POS,
+ GP_EV_REL_WHEEL,
+};
+
+enum GP_EventAbsCode {
+ GP_EV_ABS_POS,
+};
+
+enum GP_EventSysCode {
+ GP_EV_SYS_QUIT,
+ GP_EV_SYS_RESIZE,
+};
+-------------------------------------------------------------------------------
+
+The event 'code' specifies the event nature more closely, it has different
+meaning for each event type. The names are (hopefully) self explanatory.
+
+[source,c]
+-------------------------------------------------------------------------------
+union GP_EventValue {
+ /* generic one integer value */
+ int32_t val;
+ /* key */
+ struct GP_EventKey key;
+ /* position */
+ struct GP_EventPosRel rel;
+ struct GP_EventPosAbs abs;
+ /* system event */
+ struct GP_EventSys sys;
+};
+
+struct GP_EventPosRel {
+ int32_t rx;
+ int32_t ry;
+};
+
+struct GP_EventPosAbs {
+ uint32_t x, x_max; /* the x is between 0 and x_max */
+ uint32_t y, y_max;
+ uint32_t pressure, pressure_max;
+};
+
+struct GP_EventKey {
+ uint32_t key;
+ char ascii;
+};
+
+struct GP_EventSys {
+ uint32_t w, h;
+};
+-------------------------------------------------------------------------------
+
+The event value is a union that could hold different information. The right
+format of the data is known from the 'type' and 'code'. For some types of the
+events it's not used at all.
+
+* The relative coordinates are used for 'GP_EV_REL_POS' and absolute coordinates
+ for 'GP_EV_ABS_POS'.
+
+* The key event value is used for keypresses, additionally it holds the key
+ value mapped to ASCII if conversion is applicable otherwise it's set to
+ zero. You should consult the header 'input/GP_Event.h' for comprehensive
+ list of key values.
+
+* And finally the system event is used with 'GP_EV_SYS_RESIZE' and informs you
+ of the new window size.
+
+The 'dev_id' is not used at the moment and may be removed.
+
+The timeval structure 'time' holds time when the event was created (or
+received by GFXprim input driver).
+
+The 'cursor_x' and 'cursor_y' holds pointer coodinates merged from all input
+sources.
+
+The 'key_pressed' is bitflag array of currently pressed keys which is useful
+for using keys as modificators. The array holds most of the standard keyboard
+keys and mouse buttons.
+
+Event API
+~~~~~~~~~
+
+[source,c]
+-------------------------------------------------------------------------------
+#include <GP.h>
+/* or */
+#include <input/GP_Event.h>
+
+unsigned int GP_EventsQueued(void);
+-------------------------------------------------------------------------------
+
+The 'GP_EventsQueued' returns number of queued events.
+
+[source,c]
+-------------------------------------------------------------------------------
+#include <GP.h>
+/* or */
+#include <input/GP_Event.h>
+
+int GP_EventGet(struct GP_Event *ev);
+-------------------------------------------------------------------------------
+
+The 'GP_EventGet' returns nonzero if event was copied to the structure pointed
+by ev pointer.
+
+[source,c]
+-------------------------------------------------------------------------------
+#include <GP.h>
+/* or */
+#include <input/GP_Event.h>
+
+void GP_EventDump(struct GP_Event *ev);
+-------------------------------------------------------------------------------
+
+Dumps event in human-readable format into the 'stdout'.
+
+[source,c]
+-------------------------------------------------------------------------------
+#include <GP.h>
+/* or */
+#include <input/GP_Event.h>
+
+void GP_EventSetScreenSize(uint32_t w, uint32_t h);
+
+void GP_EventSetScreenCursor(uint32_t x, uint32_t y);
+-------------------------------------------------------------------------------
+
+Sets screen size and pointer position, which is needed for calculating the
+'cursor_x' and 'cursor_y' coordinates.
+
+void GP_EventPushRel(int32_t rx, int32_t ry, struct timeval *time);
+
+[source,c]
+-------------------------------------------------------------------------------
+#include <GP.h>
+/* or */
+#include <input/GP_Event.h>
+
+/*
+ * Produces relative event that moves to the point x, y
+ */
+void GP_EventPushRelTo(uint32_t x, uint32_t y, struct timeval *time);
+
+/*
+ * Inject absolute event.
+ */
+void GP_EventPushAbs(uint32_t x, uint32_t y, uint32_t pressure,
+ uint32_t x_max, uint32_t y_max, uint32_t pressure_max,
+ struct timeval *time);
+
+/*
+ * Inject event that changes key state.
+ */
+void GP_EventPushKey(uint32_t key, uint8_t code, struct timeval *time);
+
+/*
+ * Inject common event.
+ */
+void GP_EventPush(uint16_t type, uint32_t code, int32_t value,
+ struct timeval *time);
+-------------------------------------------------------------------------------
+
+Following functions are used for adding events into the event queue. If
+pointer to the timeval structure is 'NULL' the event 'time' will be filled
+with exact time the event was added to the queue.
+
+[source,c]
+-------------------------------------------------------------------------------
+#include <GP.h>
+/* or */
+#include <input/GP_Event.h>
+
+void GP_EventSetKey(struct GP_Event *ev, uint32_t key)
+
+GP_EventGetKey(struct GP_Event *ev, uint32_t key)
+
+GP_EventResetKey(struct GP_Event *ev, uint32_t key)
+-------------------------------------------------------------------------------
+
+These functions are helpers for setting/getting key pressed bits in the
+'keys_pressed' bit array.
+
+You will mostly need the 'GP_EventGetKey' function to figure out if some of
+the modificator keys (such as Ctrl or Shift) was pressed at the time the event
+was received.
diff --git a/include/input/GP_Event.h b/include/input/GP_Event.h
index 71eef60..de5d93e 100644
--- a/include/input/GP_Event.h
+++ b/include/input/GP_Event.h
@@ -299,7 +299,7 @@ void GP_EventSetScreenCursor(uint32_t x, uint32_t y);
/*
* Returns number of queued events.
*/
-uint32_t GP_EventQueued(void);
+unsigned int GP_EventsQueued(void);
/*
* Dump event into stdout.
diff --git a/libs/input/GP_Event.c b/libs/input/GP_Event.c
index eab6b2e..cb66c4f 100644
--- a/libs/input/GP_Event.c
+++ b/libs/input/GP_Event.c
@@ -89,7 +89,7 @@ void GP_EventSetScreenCursor(uint32_t x, uint32_t y)
cur_state.cursor_y = y;
}
-uint32_t GP_EventQueued(void)
+unsigned int GP_EventsQueued(void)
{
if (queue_first <= queue_last)
return queue_last - queue_first;
http://repo.or.cz/w/gfxprim.git/commit/6812b812594d07e3a6b7543400e710424ce2…
commit 6812b812594d07e3a6b7543400e710424ce23597
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Tue Dec 18 11:49:01 2012 +0100
backends: Add GP_BackendResizeAck().
This is not yet finished but seems
to work fine. More testing is required.
diff --git a/build/syms/Backend_symbols.txt b/build/syms/Backend_symbols.txt
index 7eddbe5..abcd681 100644
--- a/build/syms/Backend_symbols.txt
+++ b/build/syms/Backend_symbols.txt
@@ -7,4 +7,5 @@ GP_BackendSDLInit
GP_ContextFromSurface
GP_BackendResize
+GP_BackendResizeAck
GP_BackendUpdateRectXYXY
diff --git a/demos/spiv/spiv.c b/demos/spiv/spiv.c
index abe7395..79de755 100644
--- a/demos/spiv/spiv.c
+++ b/demos/spiv/spiv.c
@@ -350,24 +350,6 @@ GP_Context *load_resized_image(struct loader_params *params, GP_Size w, GP_Size
return img;
}
-/*
- * This function tries to resize spiv window
- * and if succedes blits the image directly to the screen.
- */
-static int resize_backend_and_blit(struct loader_params *params)
-{
- GP_Context *img = load_image(params, 1);
-
- if (GP_BackendResize(backend, img->w, img->h))
- return 1;
-
- GP_Blit_Raw(img, 0, 0, img->w, img->h, backend->context, 0, 0);
- GP_BackendFlip(backend);
- set_caption(params->img_path, 1);
-
- return 0;
-}
-
static void *image_loader(void *ptr)
{
struct loader_params *params = ptr;
@@ -565,6 +547,23 @@ static void init_caches(struct loader_params *params)
// params->img_orig_cache = NULL;
}
+/*
+ * Ask backend to resize window. Once window is resized we will
+ * get SYS_RESIZE event, see the main event loop.
+ */
+static void resize_backend(struct loader_params *params, float ratio, int shift_flag)
+{
+ GP_Context *img = load_image(params, 1);
+
+ if (!shift_flag)
+ ratio = 1.00 / ratio;
+
+ unsigned int w = img->w * ratio + 0.5;
+ unsigned int h = img->h * ratio + 0.5;
+
+ GP_BackendResize(backend, w, h);
+}
+
static void print_help(void)
{
printf("Usage: spiv [opts] imagesnn");
@@ -601,6 +600,15 @@ static void print_help(void)
printf("Downn");
printf("BckSpc - move to the prev imagen");
printf("n");
+ printf("1 - resize spiv window to the image sizen");
+ printf("2 - resize spiv window to the half of the image sizen");
+ printf("3 - resize spiv window to the third of the image sizen");
+ printf("...n");
+ printf("9 - resize spiv window to the ninth of the image sizen");
+ printf("n");
+ printf("Shift 2 - resize spiv window twice of the image sizen");
+ printf("Shift 3 - resize spiv window three times of the image sizen");
+ printf("...nn");
printf("Some cool options to try:nn");
printf("spiv -e G1 -f imagesn");
@@ -618,6 +626,7 @@ int main(int argc, char *argv[])
const char *backend_opts = "X11";
int sleep_sec = -1;
int opt, debug_level = 0;
+ int shift_flag;
GP_PixelType emul_type = GP_PIXEL_UNKNOWN;
struct loader_params params = {
@@ -734,7 +743,10 @@ int main(int argc, char *argv[])
while (GP_EventGet(&ev)) {
GP_EventDump(&ev);
-
+
+ shift_flag = GP_EventGetKey(&ev, GP_KEY_LEFT_SHIFT) ||
+ GP_EventGetKey(&ev, GP_KEY_RIGHT_SHIFT);
+
switch (ev.type) {
case GP_EV_REL:
switch (ev.code) {
@@ -863,7 +875,31 @@ int main(int argc, char *argv[])
show_image(¶ms, argv[argn]);
break;
case GP_KEY_1:
- resize_backend_and_blit(¶ms);
+ resize_backend(¶ms, 1, shift_flag);
+ break;
+ case GP_KEY_2:
+ resize_backend(¶ms, 2, shift_flag);
+ break;
+ case GP_KEY_3:
+ resize_backend(¶ms, 3, shift_flag);
+ break;
+ case GP_KEY_4:
+ resize_backend(¶ms, 4, shift_flag);
+ break;
+ case GP_KEY_5:
+ resize_backend(¶ms, 5, shift_flag);
+ break;
+ case GP_KEY_6:
+ resize_backend(¶ms, 6, shift_flag);
+ break;
+ case GP_KEY_7:
+ resize_backend(¶ms, 7, shift_flag);
+ break;
+ case GP_KEY_8:
+ resize_backend(¶ms, 8, shift_flag);
+ break;
+ case GP_KEY_9:
+ resize_backend(¶ms, 9, shift_flag);
break;
}
break;
@@ -872,7 +908,7 @@ int main(int argc, char *argv[])
case GP_EV_SYS_RESIZE:
/* stop loader thread before resizing backend buffer */
stop_loader();
- GP_BackendResize(backend, ev.val.sys.w, ev.val.sys.h);
+ GP_BackendResizeAck(backend);
GP_Fill(backend->context, 0);
params.show_progress_once = 1;
show_image(¶ms, NULL);
diff --git a/include/backends/GP_Backend.h b/include/backends/GP_Backend.h
index 64b504d..01bf3c1 100644
--- a/include/backends/GP_Backend.h
+++ b/include/backends/GP_Backend.h
@@ -95,6 +95,13 @@ typedef struct GP_Backend {
const char *caption);
/*
+ * Resize acknowledge callback. This must be called
+ * after you got resize event in order to resize
+ * backend buffers.
+ */
+ int (*ResizeAck)(struct GP_Backend *self);
+
+ /*
* Exits the backend.
*/
void (*Exit)(struct GP_Backend *self);
@@ -207,4 +214,18 @@ static inline int GP_BackendSetCaption(GP_Backend *backend,
*/
int GP_BackendResize(GP_Backend *backend, uint32_t w, uint32_t h);
+
+/*
+ * Resize acknowledge. You must call this right after you application has
+ * received resize event.
+ *
+ * This will resize backend buffers. After this call returns the backend width
+ * height and context pointer are most likely different.
+ *
+ * This function returns zero on succes. Non zero on failure. If it fails the
+ * best action to take is to save application data and exit (as the backend
+ * may be in undefined state).
+ */
+int GP_BackendResizeAck(GP_Backend *self);
+
#endif /* BACKENDS_GP_BACKEND_H */
diff --git a/libs/backends/GP_Backend.c b/libs/backends/GP_Backend.c
index b81808e..6839187 100644
--- a/libs/backends/GP_Backend.c
+++ b/libs/backends/GP_Backend.c
@@ -83,3 +83,13 @@ int GP_BackendResize(GP_Backend *backend, uint32_t w, uint32_t h)
return backend->SetAttributes(backend, w, h, NULL);
}
+
+int GP_BackendResizeAck(GP_Backend *self)
+{
+ GP_DEBUG(2, "Calling backend %s ResizeAck()", self->name);
+
+ if (self->ResizeAck)
+ return self->ResizeAck(self);
+
+ return 0;
+}
diff --git a/libs/backends/GP_LinuxFB.c b/libs/backends/GP_LinuxFB.c
index 6d69ce4..e819ae5 100644
--- a/libs/backends/GP_LinuxFB.c
+++ b/libs/backends/GP_LinuxFB.c
@@ -324,6 +324,7 @@ GP_Backend *GP_BackendLinuxFBInit(const char *path, int flag)
backend->UpdateRect = fb_update_rect_noop;
backend->Exit = fb_exit;
backend->SetAttributes = NULL;
+ backend->ResizeAck = NULL;
backend->Poll = flag ? fb_poll : NULL;
backend->Wait = flag ? fb_wait : NULL;
backend->fd = fb->con_fd;
diff --git a/libs/backends/GP_SDL.c b/libs/backends/GP_SDL.c
index 0faff30..d3afcca 100644
--- a/libs/backends/GP_SDL.c
+++ b/libs/backends/GP_SDL.c
@@ -164,6 +164,7 @@ static struct GP_Backend backend = {
.Flip = sdl_flip,
.UpdateRect = sdl_update_rect,
.SetAttributes = sdl_set_attributes,
+ .ResizeAck = NULL,
.Exit = sdl_exit,
.fd = -1,
.Poll = sdl_poll,
diff --git a/libs/backends/GP_X11.c b/libs/backends/GP_X11.c
index afe38fd..e543d48 100644
--- a/libs/backends/GP_X11.c
+++ b/libs/backends/GP_X11.c
@@ -45,6 +45,7 @@
#include "GP_X11.h"
struct x11_priv {
+ /* Connection details */
Display *dpy;
int scr;
Screen *scr_ptr;
@@ -52,6 +53,7 @@ struct x11_priv {
Window win;
Visual *vis;
+ /* Image details */
XImage *img;
#ifdef HAVE_X_SHM
@@ -61,31 +63,27 @@ struct x11_priv {
int resized_flag:1;
int shm_flag:1;
-};
-static void destroy_ximage(GP_Backend *self);
-static void destroy_shm_ximage(GP_Backend *self);
+ /* used to store width and height from ConfigureNotify event */
+ unsigned int new_w;
+ unsigned int new_h;
+};
static int resize_ximage(GP_Backend *self, int w, int h);
static int resize_shm_ximage(GP_Backend *self, int w, int h);
-static void x11_exit(GP_Backend *self)
+static void putimage(struct GP_Backend *self, int x0, int y0, int x1, int y1)
{
struct x11_priv *x11 = GP_BACKEND_PRIV(self);
-
- XLockDisplay(x11->dpy);
+#ifdef HAVE_X_SHM
if (x11->shm_flag)
- destroy_shm_ximage(self);
+ XShmPutImage(x11->dpy, x11->win, DefaultGC(x11->dpy, x11->scr),
+ x11->img, x0, y0, x0, y0, x1-x0+1, y1-y0+1, False);
else
- destroy_ximage(self);
-
- XDestroyWindow(x11->dpy, x11->win);
- /* I wonder if this is right sequence... */
- XUnlockDisplay(x11->dpy);
- XCloseDisplay(x11->dpy);
-
- free(self);
+#endif /* HAVE_X_SHM */
+ XPutImage(x11->dpy, x11->win, DefaultGC(x11->dpy, x11->scr),
+ x11->img, x0, y0, x0, y0, x1-x0+1, y1-y0+1);
}
static void x11_update_rect(GP_Backend *self, GP_Coord x0, GP_Coord y0,
@@ -94,19 +92,15 @@ static void x11_update_rect(GP_Backend *self, GP_Coord x0, GP_Coord y0,
struct x11_priv *x11 = GP_BACKEND_PRIV(self);
GP_DEBUG(4, "Updating rect %ix%i-%ix%i", x0, y0, x1, y1);
-
+
+ if (x11->resized_flag) {
+ GP_DEBUG(4, "Ignoring update rect, waiting for resize ack");
+ return;
+ }
+
XLockDisplay(x11->dpy);
-#ifdef HAVE_X_SHM
- if (x11->shm_flag)
- XShmPutImage(x11->dpy, x11->win, DefaultGC(x11->dpy, x11->scr),
- x11->img, x0, y0, x0, y0, x1-x0+1, y1-y0+1, False);
- else
-#endif /* HAVE_X_SHM */
- XPutImage(x11->dpy, x11->win, DefaultGC(x11->dpy, x11->scr),
- x11->img, x0, y0, x0, y0, x1-x0+1, y1-y0+1);
-
- XFlush(x11->dpy);
+ putimage(self, x0, y0, x1, y1);
XUnlockDisplay(x11->dpy);
}
@@ -118,12 +112,22 @@ static void x11_flip(GP_Backend *self)
unsigned int h = self->context->h;
GP_DEBUG(4, "Flipping context");
-
+
+ if (x11->resized_flag) {
+ GP_DEBUG(4, "Ignoring flip, waiting for resize ack");
+ return;
+ }
+
XLockDisplay(x11->dpy);
- XPutImage(x11->dpy, x11->win, DefaultGC(x11->dpy, x11->scr),
- x11->img, 0, 0, 0, 0, w, h);
- XFlush(x11->dpy);
+#ifdef HAVE_X_SHM
+ if (x11->shm_flag)
+ XShmPutImage(x11->dpy, x11->win, DefaultGC(x11->dpy, x11->scr),
+ x11->img, 0, 0, 0, 0, w, h, False);
+ else
+#endif /* HAVE_X_SHM */
+ XPutImage(x11->dpy, x11->win, DefaultGC(x11->dpy, x11->scr),
+ x11->img, 0, 0, 0, 0, w, h);
XUnlockDisplay(x11->dpy);
}
@@ -138,14 +142,22 @@ static void x11_ev(GP_Backend *self, XEvent *ev)
ev->xexpose.x, ev->xexpose.y,
ev->xexpose.width, ev->xexpose.height,
ev->xexpose.count);
-
- /*
- * Ignore Expose events in case user wasn't notified
- * about change and acked image resize.
- */
+
if (x11->resized_flag)
break;
+ /* Safety measure */
+ if (ev->xexpose.x + ev->xexpose.width > (int)self->context->w) {
+ GP_WARN("Expose x + w > context->w");
+ break;
+ }
+
+ if (ev->xexpose.y + ev->xexpose.height > (int)self->context->h) {
+ GP_WARN("Expose y + h > context->h");
+ break;
+ }
+
+ /* Update the rectangle */
x11_update_rect(self, ev->xexpose.x, ev->xexpose.y,
ev->xexpose.x + ev->xexpose.width - 1,
ev->xexpose.y + ev->xexpose.height - 1);
@@ -154,10 +166,17 @@ static void x11_ev(GP_Backend *self, XEvent *ev)
if (ev->xconfigure.width == (int)self->context->w &&
ev->xconfigure.height == (int)self->context->h)
break;
-
- /*
- * Window has been resized, set flag.
- */
+
+ if (ev->xconfigure.width == (int)x11->new_w &&
+ ev->xconfigure.height == (int)x11->new_h)
+ break;
+
+ x11->new_w = ev->xconfigure.width;
+ x11->new_h = ev->xconfigure.height;
+
+ GP_DEBUG(4, "Configure Notify %ux%u", x11->new_w, x11->new_h);
+
+ /* Window has been resized, set flag. */
x11->resized_flag = 1;
default:
GP_InputDriverX11EventPut(ev);
@@ -193,6 +212,21 @@ static void x11_wait(GP_Backend *self)
XUnlockDisplay(x11->dpy);
}
+static int resize_buffer(struct GP_Backend *self, uint32_t w, uint32_t h)
+{
+ struct x11_priv *x11 = GP_BACKEND_PRIV(self);
+
+ if (x11->shm_flag) {
+ if (resize_shm_ximage(self, w, h))
+ return 1;
+ } else {
+ if (resize_ximage(self, w, h))
+ return 1;
+ }
+
+ return 0;
+}
+
static int x11_set_attributes(struct GP_Backend *self,
uint32_t w, uint32_t h,
const char *caption)
@@ -209,20 +243,7 @@ static int x11_set_attributes(struct GP_Backend *self,
if (w != 0 && h != 0) {
GP_DEBUG(3, "Setting window size to %ux%u", w, h);
-
- if (x11->shm_flag) {
- if (resize_shm_ximage(self, w, h))
- return 1;
- } else {
- if (resize_ximage(self, w, h))
- return 1;
- }
-
- /* Resize X11 window */
- // XResizeWindow(x11->dpy, x11->win, w, h);
- XFlush(x11->dpy);
-
- x11->resized_flag = 0;
+ XResizeWindow(x11->dpy, x11->win, w, h);
}
XUnlockDisplay(x11->dpy);
@@ -230,6 +251,26 @@ static int x11_set_attributes(struct GP_Backend *self,
return 0;
}
+static int x11_resize_ack(struct GP_Backend *self)
+{
+ struct x11_priv *x11 = GP_BACKEND_PRIV(self);
+ int ret;
+
+ XLockDisplay(x11->dpy);
+
+ GP_DEBUG(3, "Setting buffer size to %ux%u", x11->new_w, x11->new_h);
+
+ ret = resize_buffer(self, x11->new_w, x11->new_h);
+
+ x11->resized_flag = 0;
+
+ GP_DEBUG(3, "Done");
+
+ XUnlockDisplay(x11->dpy);
+
+ return ret;
+}
+
static void match_pixel_type(struct x11_priv *x11,
enum GP_PixelType *pixel_type, int *depth)
{
@@ -261,12 +302,16 @@ static int create_shm_ximage(GP_Backend *self, GP_Size w, GP_Size h)
return 1;
}
- GP_DEBUG(1, "Using MIT SHM Extension");
+ if (self->context == NULL)
+ GP_DEBUG(1, "Using MIT SHM Extension");
enum GP_PixelType pixel_type;
int depth;
- match_pixel_type(x11, &pixel_type, &depth);
+ if (self->context == NULL)
+ match_pixel_type(x11, &pixel_type, &depth);
+ else
+ pixel_type = self->context->pixel_type;
if (pixel_type == GP_PIXEL_UNKNOWN) {
GP_DEBUG(1, "Unknown pixel type");
@@ -283,13 +328,13 @@ static int create_shm_ximage(GP_Backend *self, GP_Size w, GP_Size h)
size_t size = x11->img->bytes_per_line * x11->img->height;
- x11->shminfo.shmid = shmget(IPC_PRIVATE, size, IPC_CREAT|0777);
+ x11->shminfo.shmid = shmget(IPC_PRIVATE, size, 0600);
if (x11->shminfo.shmid == -1) {
GP_WARN("Calling shmget() failed: %s", strerror(errno));
goto err0;
}
-
+
x11->shminfo.shmaddr = x11->img->data = shmat(x11->shminfo.shmid, 0, 0);
if (x11->shminfo.shmaddr == (void *)-1) {
@@ -297,6 +342,13 @@ static int create_shm_ximage(GP_Backend *self, GP_Size w, GP_Size h)
goto err1;
}
+ /* Mark SHM for deletion after detach */
+ if (shmctl(x11->shminfo.shmid, IPC_RMID, 0)) {
+ GP_WARN("Calling shmctl(..., IPC_RMID), 0) failed: %s",
+ strerror(errno));
+ goto err2;
+ }
+
x11->shminfo.readOnly = False;
if (XShmAttach(x11->dpy, &x11->shminfo) == False) {
@@ -311,6 +363,9 @@ static int create_shm_ximage(GP_Backend *self, GP_Size w, GP_Size h)
x11->shm_flag = 1;
+ //FIXME: Proper synchronization
+ XSync(x11->dpy, True);
+
return 0;
err2:
shmdt(x11->shminfo.shmaddr);
@@ -324,22 +379,34 @@ err0:
static void destroy_shm_ximage(GP_Backend *self)
{
struct x11_priv *x11 = GP_BACKEND_PRIV(self);
+
+ XLockDisplay(x11->dpy);
XShmDetach(x11->dpy, &x11->shminfo);
XFlush(x11->dpy);
shmdt(x11->shminfo.shmaddr);
- shmctl(x11->shminfo.shmid, IPC_RMID, 0);
XDestroyImage(x11->img);
+ XFlush(x11->dpy);
+
+ XUnlockDisplay(x11->dpy);
}
static int resize_shm_ximage(GP_Backend *self, int w, int h)
{
+ struct x11_priv *x11 = GP_BACKEND_PRIV(self);
+ int ret;
+
GP_DEBUG(4, "Resizing XShmImage %ux%u -> %ux%u",
self->context->w, self->context->h, w, h);
+ XLockDisplay(x11->dpy);
+
destroy_shm_ximage(self);
-
- return create_shm_ximage(self, w, h);
+ ret = create_shm_ximage(self, w, h);
+
+ XUnlockDisplay(x11->dpy);
+
+ return ret;
}
#else
@@ -406,7 +473,6 @@ static void destroy_ximage(GP_Backend *self)
XDestroyImage(x11->img);
}
-
static int resize_ximage(GP_Backend *self, int w, int h)
{
struct x11_priv *x11 = GP_BACKEND_PRIV(self);
@@ -423,7 +489,7 @@ static int resize_ximage(GP_Backend *self, int w, int h)
/* Resize context */
if (GP_ContextResize(self->context, w, h)) {
- XDestroyImage(img);
+ XDestroyImage(img);
return 1;
}
@@ -438,6 +504,37 @@ static int resize_ximage(GP_Backend *self, int w, int h)
return 0;
}
+static void window_close(GP_Backend *self)
+{
+ struct x11_priv *x11 = GP_BACKEND_PRIV(self);
+
+ XLockDisplay(x11->dpy);
+
+ if (x11->shm_flag)
+ destroy_shm_ximage(self);
+ else
+ destroy_ximage(self);
+
+ XDestroyWindow(x11->dpy, x11->win);
+
+ XUnlockDisplay(x11->dpy);
+}
+
+static void x11_exit(GP_Backend *self)
+{
+ struct x11_priv *x11 = GP_BACKEND_PRIV(self);
+
+ XLockDisplay(x11->dpy);
+
+ window_close(self);
+
+ /* I wonder if this is right sequence... */
+ //XUnlockDisplay(x11->dpy);
+ XCloseDisplay(x11->dpy);
+
+ free(self);
+}
+
static void create_window(struct x11_priv *x11, int x, int y,
unsigned int *w, unsigned int *h,
const char *caption, enum GP_BackendX11Flags flags)
@@ -658,6 +755,8 @@ GP_Backend *GP_BackendX11Init(const char *display, int x, int y,
if (x11->dpy == NULL)
goto err0;
+ //XSynchronize(x11->dpy, True);
+
x11->scr = DefaultScreen(x11->dpy);
x11->vis = DefaultVisual(x11->dpy, x11->scr);
x11->scr_ptr = DefaultScreenOfDisplay(x11->dpy);
@@ -673,6 +772,8 @@ GP_Backend *GP_BackendX11Init(const char *display, int x, int y,
goto err1;
}
+ backend->context = NULL;
+
if (create_shm_ximage(backend, w, h))
if (create_ximage(backend, w, h))
goto err1;
@@ -688,6 +789,7 @@ GP_Backend *GP_BackendX11Init(const char *display, int x, int y,
backend->Poll = x11_poll;
backend->Wait = x11_wait;
backend->SetAttributes = x11_set_attributes;
+ backend->ResizeAck = x11_resize_ack;
backend->fd = XConnectionNumber(x11->dpy);
return backend;
-----------------------------------------------------------------------
Summary of changes:
build/syms/Backend_symbols.txt | 1 +
build/syms/Event_symbols.txt | 2 +-
demos/c_simple/Makefile | 6 +-
demos/c_simple/{input.c => input_example.c} | 4 +-
demos/spiv/spiv.c | 78 ++++--
doc/Makefile | 2 +-
doc/api.txt | 5 +
doc/backends.txt | 17 ++
...ers_progress_callback.txt => example_input.txt} | 6 +-
doc/input.txt | 271 ++++++++++++++++++++
include/backends/GP_Backend.h | 21 ++
include/input/GP_Event.h | 2 +-
libs/backends/GP_Backend.c | 10 +
libs/backends/GP_LinuxFB.c | 1 +
libs/backends/GP_SDL.c | 1 +
libs/backends/GP_X11.c | 226 ++++++++++++-----
libs/input/GP_Event.c | 2 +-
17 files changed, 559 insertions(+), 96 deletions(-)
rename demos/c_simple/{input.c => input_example.c} (98%)
copy doc/{example_loaders_progress_callback.txt => example_input.txt} (62%)
create mode 100644 doc/input.txt
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: 89909d1774eb1b3ac35e2e643401bab3b79c9dc2
by bluebear 17 Dec '12
by bluebear 17 Dec '12
17 Dec '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 89909d1774eb1b3ac35e2e643401bab3b79c9dc2 (commit)
from 23a690342a49f0f96aad7ce26eb0d7290349d4f3 (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/89909d1774eb1b3ac35e2e643401bab3b79c…
commit 89909d1774eb1b3ac35e2e643401bab3b79c9dc2
Author: Jiri BlueBear Dluhos <jiri.bluebear.dluhos(a)gmail.com>
Date: Mon Dec 17 23:55:01 2012 +0100
Templatized HLine, modernized WritePixel slightly.
diff --git a/include/core/GP_WritePixel.h b/include/core/GP_WritePixel.h
index 0d1a875..d9530f9 100644
--- a/include/core/GP_WritePixel.h
+++ b/include/core/GP_WritePixel.h
@@ -50,16 +50,27 @@ void GP_WritePixels_4BPP_LE(uint8_t *start, uint8_t off,
size_t cnt, uint8_t val);
/*
- * These calls are not byte aligned, thuss needs start offset.
+ * These calls are not byte aligned, thus need start offset.
*/
-void GP_WritePixels1bpp(uint8_t *start, uint8_t off, size_t cnt, uint8_t val);
-void GP_WritePixels2bpp(uint8_t *start, uint8_t off, size_t cnt, uint8_t val);
-void GP_WritePixels4bpp(uint8_t *start, uint8_t off, size_t cnt, uint8_t val);
-void GP_WritePixels18bpp(void *start, uint8_t off, size_t count, uint32_t value);
+void GP_WritePixels_1BPP_BE(uint8_t *start, uint8_t off, size_t cnt, uint8_t val);
+void GP_WritePixels_2BPP_BE(uint8_t *start, uint8_t off, size_t cnt, uint8_t val);
+void GP_WritePixels_4BPP_BE(uint8_t *start, uint8_t off, size_t cnt, uint8_t val);
+void GP_WritePixels_18BPP_BE(void *start, uint8_t off, size_t count, uint32_t value);
-void GP_WritePixels8bpp(void *start, size_t count, uint8_t value);
-void GP_WritePixels16bpp(void *start, size_t count, uint16_t value);
-void GP_WritePixels24bpp(void *start, size_t count, uint32_t value);
-void GP_WritePixels32bpp(void *start, size_t count, uint32_t value);
+/* Byte-aligned calls. */
+void GP_WritePixels_8BPP(void *start, size_t count, uint8_t value);
+void GP_WritePixels_16BPP(void *start, size_t count, uint16_t value);
+void GP_WritePixels_24BPP(void *start, size_t count, uint32_t value);
+void GP_WritePixels_32BPP(void *start, size_t count, uint32_t value);
+
+/* aliases for older names */
+#define GP_WritePixels1bpp GP_WritePixels_1BPP_BE
+#define GP_WritePixels2bpp GP_WritePixels_2BPP_BE
+#define GP_WritePixels4bpp GP_WritePixels_4BPP_BE
+#define GP_WritePixels18bpp GP_WritePixels_18BPP_BE
+#define GP_WritePixels8bpp GP_WritePixels_8BPP
+#define GP_WritePixels16bpp GP_WritePixels_16BPP
+#define GP_WritePixels24bpp GP_WritePixels_24BPP
+#define GP_WritePixels32bpp GP_WritePixels_32BPP
#endif /* GP_WRITEPIXEL_H */
diff --git a/libs/core/GP_WritePixel.c b/libs/core/GP_WritePixel.c
index bc57ea1..a6829b0 100644
--- a/libs/core/GP_WritePixel.c
+++ b/libs/core/GP_WritePixel.c
@@ -41,40 +41,40 @@ void GP_WritePixels_1BPP_LE(uint8_t *start, uint8_t off,
break;
case 1:
GP_SET_BITS1_ALIGNED(1, 1, start, val);
-
+
if (--len == 0)
return;
case 2:
GP_SET_BITS1_ALIGNED(2, 1, start, val);
-
+
if (--len == 0)
return;
case 3:
GP_SET_BITS1_ALIGNED(3, 1, start, val);
-
+
if (--len == 0)
return;
case 4:
GP_SET_BITS1_ALIGNED(4, 1, start, val);
-
+
if (--len == 0)
return;
case 5:
GP_SET_BITS1_ALIGNED(5, 1, start, val);
-
+
if (--len == 0)
return;
case 6:
GP_SET_BITS1_ALIGNED(6, 1, start, val);
-
+
if (--len == 0)
return;
case 7:
GP_SET_BITS1_ALIGNED(7, 1, start, val);
-
+
if (--len == 0)
return;
-
+
start++;
break;
}
@@ -117,27 +117,27 @@ void GP_WritePixels_2BPP_LE(uint8_t *start, uint8_t off,
break;
case 1:
GP_SET_BITS1_ALIGNED(2, 2, start, val);
-
+
if (--len == 0)
return;
case 2:
GP_SET_BITS1_ALIGNED(4, 2, start, val);
-
+
if (--len == 0)
return;
case 3:
GP_SET_BITS1_ALIGNED(6, 2, start, val);
-
+
if (--len == 0)
return;
-
+
start++;
- break;
+ break;
}
-
+
/* Write as many bytes as possible */
memset(start, bytes_2BPP[val & 0x03], len/4);
-
+
start+=len/4;
/* And the rest */
@@ -168,17 +168,17 @@ void GP_WritePixels_4BPP_LE(uint8_t *start, uint8_t off,
break;
case 1:
GP_SET_BITS1_ALIGNED(4, 4, start, val);
-
+
if (--len == 0)
return;
-
+
start++;
- break;
+ break;
}
/* Write as many bytes as possible */
memset(start, bytes_4BPP[val & 0x0f], len/2);
-
+
start+=len/2;
/* And the rest */
@@ -193,7 +193,7 @@ static const uint8_t chunks_1bpp[8] = {
0x00, 0x80, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc, 0xfe,
};
-void GP_WritePixels1bpp(uint8_t *start, uint8_t off, size_t cnt, uint8_t val)
+void GP_WritePixels_1BPP_BE(uint8_t *start, uint8_t off, size_t cnt, uint8_t val)
{
uint8_t s_off = off % 8;
uint8_t e_off = (cnt + s_off) % 8;
@@ -218,7 +218,7 @@ void GP_WritePixels1bpp(uint8_t *start, uint8_t off, size_t cnt, uint8_t val)
/* write len - 2 bytes */
if (len > 1)
- GP_WritePixels8bpp(start + 1, len - 2, col);
+ GP_WritePixels_8BPP(start + 1, len - 2, col);
/* deal with the start and end */
if (val) {
@@ -236,7 +236,7 @@ static const uint8_t colors_2bpp[4] = {
#define PUT_PIXEL_2BPP(p, off, pix) *(p) = (*(p) & ~(0xc0>>(off))) | (pix<<(6 - off))
-void GP_WritePixels2bpp(uint8_t *start, uint8_t off, size_t cnt, uint8_t val)
+void GP_WritePixels_2BPP_BE(uint8_t *start, uint8_t off, size_t cnt, uint8_t val)
{
uint8_t s_off = off % 4;
uint8_t e_off = 2 * ((cnt + s_off) % 4);
@@ -252,7 +252,7 @@ void GP_WritePixels2bpp(uint8_t *start, uint8_t off, size_t cnt, uint8_t val)
for (off = s_off; off < max; off+=2)
PUT_PIXEL_2BPP(start, off, val);
-
+
if (len <= 8)
return;
@@ -264,7 +264,7 @@ void GP_WritePixels2bpp(uint8_t *start, uint8_t off, size_t cnt, uint8_t val)
/* write len - 2 bytes */
if (len > 1)
- GP_WritePixels8bpp(start + 1, len - 2, colors_2bpp[val]);
+ GP_WritePixels_8BPP(start + 1, len - 2, colors_2bpp[val]);
/* handle start and end */
start[0] = (start[0] & (0xff << (8 - s_off))) |
@@ -275,7 +275,7 @@ void GP_WritePixels2bpp(uint8_t *start, uint8_t off, size_t cnt, uint8_t val)
}
-void GP_WritePixels4bpp(uint8_t *start, uint8_t off, size_t cnt, uint8_t val)
+void GP_WritePixels_4BPP_BE(uint8_t *start, uint8_t off, size_t cnt, uint8_t val)
{
uint8_t s_off = off % 2;
uint8_t e_off = (cnt + s_off) % 2;
@@ -285,20 +285,20 @@ void GP_WritePixels4bpp(uint8_t *start, uint8_t off, size_t cnt, uint8_t val)
uint8_t col = (val << 4)& val;
if (len > 0)
- GP_WritePixels8bpp(start + s_off, len, val);
+ GP_WritePixels_8BPP(start + s_off, len, val);
/* handle start and end */
if (s_off) GP_SET_BITS(4, 4, start[0], col);
if (e_off) GP_SET_BITS(0, 4, start[len+s_off], val);
}
-void GP_WritePixels8bpp(void *start, size_t count, uint8_t value)
+void GP_WritePixels_8BPP(void *start, size_t count, uint8_t value)
{
-
+
memset(start, value, count);
}
-void GP_WritePixels16bpp(void *start, size_t count, uint16_t value)
+void GP_WritePixels_16BPP(void *start, size_t count, uint16_t value)
{
uint16_t *p = (uint16_t *) start;
size_t i;
@@ -323,12 +323,17 @@ void GP_WritePixels16bpp(void *start, size_t count, uint16_t value)
}
}
-void GP_WritePixels18bpp(void *start, uint8_t off, size_t count, uint32_t value)
+void GP_WritePixels_18BPP_LE(void *start, uint8_t off, size_t count, uint32_t value)
+{
+ #warning TODO
+}
+
+void GP_WritePixels_18BPP_BE(void *start, uint8_t off, size_t count, uint32_t value)
{
#warning TODO
}
-void GP_WritePixels24bpp(void *start, size_t count, uint32_t value)
+void GP_WritePixels_24BPP(void *start, size_t count, uint32_t value)
{
uint8_t *bytep = (uint8_t *) start;
@@ -406,7 +411,7 @@ void GP_WritePixels24bpp(void *start, size_t count, uint32_t value)
break;
}
- /*
+ /*
* Write as much of the line as possible as
* triplets of 32-bit numbers; hopefully the compiler can
* put some wide write instructions in.
@@ -448,11 +453,11 @@ void GP_WritePixels24bpp(void *start, size_t count, uint32_t value)
}
}
-void GP_WritePixels32bpp(void *start, size_t count, uint32_t value)
+void GP_WritePixels_32BPP(void *start, size_t count, uint32_t value)
{
/*
* Inspired by GNU libc's wmemset() (by Ulrich Drepper, licensed under LGPL).
- *
+ *
* Write the pixels in groups of four, allowing the compiler to use
* MMX/SSE/similar instructions if available. The last few pixels are
* copied normally one-by-one. (Speed gain is about 15% over a naive loop
diff --git a/libs/gfx/GP_HLine.c b/libs/gfx/GP_HLine.gen.c.t
similarity index 82%
rename from libs/gfx/GP_HLine.c
rename to libs/gfx/GP_HLine.gen.c.t
index 35e3e36..8fe9169 100644
--- a/libs/gfx/GP_HLine.c
+++ b/libs/gfx/GP_HLine.gen.c.t
@@ -23,18 +23,56 @@
* *
*****************************************************************************/
+%% extends "base.c.t"
+
+{% block descr %}Horizontal line drawing{% endblock %}
+
+%% block body
+
#include "core/GP_FnPerBpp.h"
#include "core/GP_WritePixel.h"
#include "core/GP_Transform.h"
-#include "algo/HLine.algo.h"
+/* #include "algo/HLine.algo.h" */
#include "gfx/GP_HLine.h"
#include "gfx/GP_VLine.h"
+%% for ps in pixelsizes
+
+void GP_HLine_Raw_{{ ps.suffix }}(GP_Context *context, int x0, int x1, int y,
+ GP_Pixel pixel)
+{
+ /* draw always from left to right, swap coords if necessary */
+ if (x0 > x1)
+ GP_SWAP(x0, x1);
+
+ /* return immediately if the line is completely out of surface */
+ if (y < 0 || y >= (int) context->h ||
+ x1 < 0 || x0 >= (int) context->w)
+ return;
+
+ /* clip the line against surface boundaries */
+ x0 = GP_MAX(x0, 0);
+ x1 = GP_MIN(x1, (int) context->w - 1);
+
+ size_t length = 1 + x1 - x0;
+ void *start = GP_PIXEL_ADDR(context, x0, y);
+
+%% if ps.needs_bit_endian()
+ GP_WritePixels_{{ ps.suffix }}(start, x0 % (8 / context->bpp), length, pixel);
+%% else
+ GP_WritePixels_{{ ps.suffix }}(start, length, pixel);
+%% endif
+
+}
+
+%% endfor
+
/* Generate drawing functions for various bit depths. */
//TODO: BIT ENDIANESS
+/*
DEF_HLINE_BU_FN(GP_HLine_Raw_1BPP_LE, GP_Context*, GP_Pixel, GP_PIXEL_ADDR, GP_WritePixels_1BPP_LE)
DEF_HLINE_BU_FN(GP_HLine_Raw_1BPP_BE, GP_Context*, GP_Pixel, GP_PIXEL_ADDR, GP_WritePixels1bpp)
DEF_HLINE_BU_FN(GP_HLine_Raw_2BPP_LE, GP_Context*, GP_Pixel, GP_PIXEL_ADDR, GP_WritePixels_2BPP_LE)
@@ -47,12 +85,13 @@ DEF_HLINE_FN(GP_HLine_Raw_8BPP, GP_Context *, GP_Pixel, GP_PIXEL_ADDR, GP_Write
DEF_HLINE_FN(GP_HLine_Raw_16BPP, GP_Context *, GP_Pixel, GP_PIXEL_ADDR, GP_WritePixels16bpp)
DEF_HLINE_FN(GP_HLine_Raw_24BPP, GP_Context *, GP_Pixel, GP_PIXEL_ADDR, GP_WritePixels24bpp)
DEF_HLINE_FN(GP_HLine_Raw_32BPP, GP_Context *, GP_Pixel, GP_PIXEL_ADDR, GP_WritePixels32bpp)
+*/
void GP_HLineXXY_Raw(GP_Context *context, GP_Coord x0, GP_Coord x1,
GP_Coord y, GP_Pixel pixel)
{
GP_CHECK_CONTEXT(context);
-
+
GP_FN_PER_BPP_CONTEXT(GP_HLine_Raw, context, context, x0, x1, y,
pixel);
}
@@ -70,7 +109,7 @@ void GP_HLineXXY(GP_Context *context, GP_Coord x0, GP_Coord x1, GP_Coord y,
GP_Pixel pixel)
{
GP_CHECK_CONTEXT(context);
-
+
if (context->axes_swap) {
GP_TRANSFORM_Y(context, x0);
GP_TRANSFORM_Y(context, x1);
@@ -92,3 +131,5 @@ void GP_HLineXYW(GP_Context *context, GP_Coord x, GP_Coord y, GP_Size w,
GP_HLineXXY(context, x, x + w - 1, y, pixel);
}
+
+%% endblock body
diff --git a/libs/gfx/Makefile b/libs/gfx/Makefile
index 145827b..d80e49a 100644
--- a/libs/gfx/Makefile
+++ b/libs/gfx/Makefile
@@ -1,6 +1,6 @@
TOPDIR=../..
CSOURCES=$(filter-out $(wildcard *.gen.c),$(wildcard *.c))
-GENSOURCES=GP_Line.gen.c GP_LineAA.gen.c GP_PutPixelAA.gen.c +GENSOURCES=GP_Line.gen.c GP_HLine.gen.c GP_LineAA.gen.c GP_PutPixelAA.gen.c GP_HLineAA.gen.c GP_VLineAA.gen.c GP_FillCircle.gen.c
LIBNAME=gfx
-----------------------------------------------------------------------
Summary of changes:
include/core/GP_WritePixel.h | 29 ++++++++----
libs/core/GP_WritePixel.c | 73 +++++++++++++++-------------
libs/gfx/{GP_HLine.c => GP_HLine.gen.c.t} | 47 +++++++++++++++++-
libs/gfx/Makefile | 2 +-
4 files changed, 104 insertions(+), 47 deletions(-)
rename libs/gfx/{GP_HLine.c => GP_HLine.gen.c.t} (82%)
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: 23a690342a49f0f96aad7ce26eb0d7290349d4f3
by bluebear 17 Dec '12
by bluebear 17 Dec '12
17 Dec '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 23a690342a49f0f96aad7ce26eb0d7290349d4f3 (commit)
from f80c7c799ea3cc54e9858863dc4a0e8461c6aeb8 (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/23a690342a49f0f96aad7ce26eb0d7290349…
commit 23a690342a49f0f96aad7ce26eb0d7290349d4f3
Author: Jiri BlueBear Dluhos <jiri.bluebear.dluhos(a)gmail.com>
Date: Mon Dec 17 23:53:04 2012 +0100
Use clipped putpixel in line drawing for now (slower but does not crash).
diff --git a/libs/gfx/GP_Line.gen.c.t b/libs/gfx/GP_Line.gen.c.t
index 42b9167..edc5382 100644
--- a/libs/gfx/GP_Line.gen.c.t
+++ b/libs/gfx/GP_Line.gen.c.t
@@ -51,8 +51,8 @@ void GP_Line_Raw_{{ ps.suffix }}(GP_Context *context, int x0, int y0,
/* special cases: vertical line, horizontal line, single point */
if (x0 == x1) {
if (y0 == y1) {
- GP_PutPixel_Raw_{{ ps.suffix }}(context, x0, y0,
- pixval);
+ GP_PutPixel_Raw_Clipped_{{ ps.suffix }}(context,
+ x0, y0, pixval);
return;
}
GP_VLine_Raw(context, x0, y0, y1, pixval);
@@ -93,9 +93,11 @@ void GP_Line_Raw_{{ ps.suffix }}(GP_Context *context, int x0, int y0,
for (x = x0; x <= x1; x++) {
if (steep)
- GP_PutPixel_Raw_{{ ps.suffix }}(context, y, x, pixval);
+ GP_PutPixel_Raw_Clipped_{{ ps.suffix }}(context, y, x,
+ pixval);
else
- GP_PutPixel_Raw_{{ ps.suffix }}(context, x, y, pixval);
+ GP_PutPixel_Raw_Clipped_{{ ps.suffix }}(context, x, y,
+ pixval);
error -= deltay;
if (error < 0) {
-----------------------------------------------------------------------
Summary of changes:
libs/gfx/GP_Line.gen.c.t | 10 ++++++----
1 files changed, 6 insertions(+), 4 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: f80c7c799ea3cc54e9858863dc4a0e8461c6aeb8
by bluebear 17 Dec '12
by bluebear 17 Dec '12
17 Dec '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 f80c7c799ea3cc54e9858863dc4a0e8461c6aeb8 (commit)
from 8aec3f568b4b7301f82a9ece1344a0aec93dc746 (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/f80c7c799ea3cc54e9858863dc4a0e8461c6…
commit f80c7c799ea3cc54e9858863dc4a0e8461c6aeb8
Author: Jiri BlueBear Dluhos <jiri.bluebear.dluhos(a)gmail.com>
Date: Mon Dec 17 17:16:54 2012 +0100
Templatized GP_Line().
diff --git a/include/gfx/GP_VLine.h b/include/gfx/GP_VLine.h
index f4c5d1e..a070f53 100644
--- a/include/gfx/GP_VLine.h
+++ b/include/gfx/GP_VLine.h
@@ -28,6 +28,41 @@
#include "core/GP_Context.h"
+/* Raw per BPP HLines */
+
+void GP_VLine_Raw_1BPP_LE(GP_Context *context, GP_Coord x0, GP_Coord x1,
+ GP_Coord y, GP_Pixel pixel);
+
+void GP_VLine_Raw_1BPP_BE(GP_Context *context, GP_Coord x0, GP_Coord x1,
+ GP_Coord y, GP_Pixel pixel);
+
+void GP_VLine_Raw_2BPP_LE(GP_Context *context, GP_Coord x0, GP_Coord x1,
+ GP_Coord y, GP_Pixel pixel);
+
+void GP_VLine_Raw_2BPP_BE(GP_Context *context, GP_Coord x0, GP_Coord x1,
+ GP_Coord y, GP_Pixel pixel);
+
+void GP_VLine_Raw_4BPP_LE(GP_Context *context, GP_Coord x0, GP_Coord x1,
+ GP_Coord y, GP_Pixel pixel);
+
+void GP_VLine_Raw_4BPP_BE(GP_Context *context, GP_Coord x0, GP_Coord x1,
+ GP_Coord y, GP_Pixel pixel);
+
+void GP_VLine_Raw_8BPP(GP_Context *context, GP_Coord x0, GP_Coord x1,
+ GP_Coord y, GP_Pixel pixel);
+
+void GP_VLine_Raw_18BPP_LE(GP_Context *context, GP_Coord x0, GP_Coord x1,
+ GP_Coord y, GP_Pixel pixel);
+
+void GP_VLine_Raw_16BPP(GP_Context *context, GP_Coord x0, GP_Coord x1,
+ GP_Coord y, GP_Pixel pixel);
+
+void GP_VLine_Raw_24BPP(GP_Context *context, GP_Coord x0, GP_Coord x1,
+ GP_Coord y, GP_Pixel pixel);
+
+void GP_VLine_Raw_32BPP(GP_Context *context, GP_Coord x0, GP_Coord x1,
+ GP_Coord y, GP_Pixel pixel);
+
void GP_VLineXYY(GP_Context *context, GP_Coord x, GP_Coord y0,
GP_Coord y1, GP_Pixel pixel);
diff --git a/libs/gfx/GP_Line.c b/libs/gfx/GP_Line.c
deleted file mode 100644
index 62db8a7..0000000
--- a/libs/gfx/GP_Line.c
+++ /dev/null
@@ -1,54 +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-2012 Cyril Hrubis <metan(a)ucw.cz> *
- * *
- *****************************************************************************/
-
-#include "core/GP_GetPutPixel.h"
-#include "core/GP_FnPerBpp.h"
-
-#include "gfx/GP_Line.h"
-
-#include "algo/Line.algo.h"
-
-/* Generate drawing functions for various bit depths. */
-GP_DEF_DRAW_FN_PER_BPP(GP_Line_Raw, DEF_LINE_FN)
-
-void GP_Line_Raw(GP_Context *context, GP_Coord x0, GP_Coord y0,
- GP_Coord x1, GP_Coord y1, GP_Pixel pixel)
-{
- GP_CHECK_CONTEXT(context);
-
- GP_FN_PER_BPP_CONTEXT(GP_Line_Raw, context, context, x0, y0, x1, y1,
- pixel);
-}
-
-void GP_Line(GP_Context *context, GP_Coord x0, GP_Coord y0,
- GP_Coord x1, GP_Coord y1, GP_Pixel pixel)
-{
- GP_CHECK_CONTEXT(context);
-
- GP_TRANSFORM_POINT(context, x0, y0);
- GP_TRANSFORM_POINT(context, x1, y1);
-
- GP_Line_Raw(context, x0, y0, x1, y1, pixel);
-}
diff --git a/libs/gfx/GP_Line.gen.c.t b/libs/gfx/GP_Line.gen.c.t
new file mode 100644
index 0000000..42b9167
--- /dev/null
+++ b/libs/gfx/GP_Line.gen.c.t
@@ -0,0 +1,130 @@
+/*****************************************************************************
+ * 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> *
+ * *
+ *****************************************************************************/
+
+%% extends "base.c.t"
+
+{% block descr %}Line drawing algorithm{% endblock %}
+
+%% block body
+
+#include "core/GP_Common.h"
+#include "core/GP_GetPutPixel.h"
+#include "core/GP_FnPerBpp.h"
+
+#include "gfx/GP_VLine.h"
+#include "gfx/GP_HLine.h"
+#include "gfx/GP_Line.h"
+
+/*
+ * The classical Bresenham line drawing algorithm.
+ * Please see http://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm
+ * for a nice and understandable description.
+ */
+
+%% for ps in pixelsizes
+
+void GP_Line_Raw_{{ ps.suffix }}(GP_Context *context, int x0, int y0,
+ int x1, int y1, GP_Pixel pixval)
+{
+ /* special cases: vertical line, horizontal line, single point */
+ if (x0 == x1) {
+ if (y0 == y1) {
+ GP_PutPixel_Raw_{{ ps.suffix }}(context, x0, y0,
+ pixval);
+ return;
+ }
+ GP_VLine_Raw(context, x0, y0, y1, pixval);
+ return;
+ }
+ if (y0 == y1) {
+ GP_HLine_Raw(context, x0, x1, y0, pixval);
+ return;
+ }
+
+ /*
+ * Which axis is longer? Swap the coordinates if necessary so
+ * that the X axis is always the longer one and Y is shorter.
+ */
+ int steep = abs(y1 - y0) / abs(x1 - x0);
+ if (steep) {
+ GP_SWAP(x0, y0);
+ GP_SWAP(x1, y1);
+ }
+ if (x0 > x1) {
+ GP_SWAP(x0, x1);
+ GP_SWAP(y0, y1);
+ }
+
+ /* iterate over the longer axis, calculate values on the shorter */
+ int deltax = x1 - x0;
+ int deltay = abs(y1 - y0);
+
+ /*
+ * start with error of 0.5 (multiplied by deltax for integer-only math),
+ * this reflects the fact that ideally, the coordinate should be
+ * in the middle of the pixel
+ */
+ int error = deltax / 2;
+
+ int y = y0, x;
+ int ystep = (y0 < y1) ? 1 : -1;
+ for (x = x0; x <= x1; x++) {
+
+ if (steep)
+ GP_PutPixel_Raw_{{ ps.suffix }}(context, y, x, pixval);
+ else
+ GP_PutPixel_Raw_{{ ps.suffix }}(context, x, y, pixval);
+
+ error -= deltay;
+ if (error < 0) {
+ y += ystep; /* next step on the shorter axis */
+ error += deltax;
+ }
+ }
+}
+
+%% endfor
+
+void GP_Line_Raw(GP_Context *context, GP_Coord x0, GP_Coord y0,
+ GP_Coord x1, GP_Coord y1, GP_Pixel pixel)
+{
+ GP_CHECK_CONTEXT(context);
+
+ GP_FN_PER_BPP_CONTEXT(GP_Line_Raw, context, context, x0, y0, x1, y1,
+ pixel);
+}
+
+void GP_Line(GP_Context *context, GP_Coord x0, GP_Coord y0,
+ GP_Coord x1, GP_Coord y1, GP_Pixel pixel)
+{
+ GP_CHECK_CONTEXT(context);
+
+ GP_TRANSFORM_POINT(context, x0, y0);
+ GP_TRANSFORM_POINT(context, x1, y1);
+
+ GP_Line_Raw(context, x0, y0, x1, y1, pixel);
+}
+
+%% endblock body
diff --git a/libs/gfx/Makefile b/libs/gfx/Makefile
index 0641888..145827b 100644
--- a/libs/gfx/Makefile
+++ b/libs/gfx/Makefile
@@ -1,7 +1,7 @@
TOPDIR=../..
CSOURCES=$(filter-out $(wildcard *.gen.c),$(wildcard *.c))
-GENSOURCES=GP_LineAA.gen.c GP_PutPixelAA.gen.c GP_HLineAA.gen.c - GP_VLineAA.gen.c GP_FillCircle.gen.c
+GENSOURCES=GP_Line.gen.c GP_LineAA.gen.c GP_PutPixelAA.gen.c + GP_HLineAA.gen.c GP_VLineAA.gen.c GP_FillCircle.gen.c
LIBNAME=gfx
include $(TOPDIR)/pre.mk
-----------------------------------------------------------------------
Summary of changes:
include/gfx/GP_VLine.h | 35 ++++++++++++
libs/gfx/GP_Line.c | 54 -------------------
libs/gfx/GP_Line.gen.c.t | 130 ++++++++++++++++++++++++++++++++++++++++++++++
libs/gfx/Makefile | 4 +-
4 files changed, 167 insertions(+), 56 deletions(-)
delete mode 100644 libs/gfx/GP_Line.c
create mode 100644 libs/gfx/GP_Line.gen.c.t
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: 8aec3f568b4b7301f82a9ece1344a0aec93dc746
by bluebear 17 Dec '12
by bluebear 17 Dec '12
17 Dec '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 8aec3f568b4b7301f82a9ece1344a0aec93dc746 (commit)
from 13f50596531c7c69961d1625a6be2550c3565634 (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/8aec3f568b4b7301f82a9ece1344a0aec93d…
commit 8aec3f568b4b7301f82a9ece1344a0aec93dc746
Author: Jiri BlueBear Dluhos <jiri.bluebear.dluhos(a)gmail.com>
Date: Mon Dec 17 02:25:58 2012 +0100
Finally understood how to handle horizontal lines.
diff --git a/libs/gfx/GP_Polygon.c b/libs/gfx/GP_Polygon.c
index 4bd0297..e76babe 100644
--- a/libs/gfx/GP_Polygon.c
+++ b/libs/gfx/GP_Polygon.c
@@ -41,20 +41,20 @@ typedef struct {
} GP_Point;
/* "almost equality" for float coordinates */
-#define GP_COORDS_ALMOST_EQUAL(a,b) (fabsf(a-b) < 0.00001f)
+#define GP_COORDS_ALMOST_EQUAL(a,b) (fabsf((a)-(b)) < 0.0001f)
/*
* Edge state. Every edge proceeds from READY to ACTIVE and then FINISHED.
- * Numeric values reflect sorting priority (ACTIVE < READY < FINISHED).
+ * HORIZONTAL is special (horizontal edges are handled separately).
+ * Numeric values reflect sorting priority (ACTIVE is foremost).
*/
+#define EDGE_HORIZONTAL 3
#define EDGE_FINISHED 2
#define EDGE_READY 1
#define EDGE_ACTIVE 0
/* Working record about an edge. */
struct GP_Edge {
- GP_Point start; /* starting point as specified by user */
- GP_Point end; /* ending point as specified by user */
int state; /* edge state */
float x; /* X coordinate of the working point */
int y; /* Y coordinate of the working point */
@@ -65,8 +65,15 @@ struct GP_Edge {
/* Initializes the edge structure. */
static void GP_InitEdge(struct GP_Edge *e, GP_Point start, GP_Point end)
{
- e->start = start;
- e->end = end;
+ /* horizontal edges are a special case */
+ if (start.y == end.y) {
+ e->dy = 0;
+ e->x = start.x;
+ e->y = start.y;
+ e->dxy = end.x - start.x;
+ e->state = EDGE_HORIZONTAL;
+ return;
+ }
/* initialize the working point to the top point of the edge */
if (start.y < end.y) {
@@ -77,17 +84,17 @@ static void GP_InitEdge(struct GP_Edge *e, GP_Point start, GP_Point end)
e->y = end.y;
}
- e->dy = GP_ABS(end.y - start.y) - 1;
+ e->dy = GP_ABS(end.y - start.y);
- if (e->dy < 0) {
+ e->dxy = (float)(end.x - start.x)/(end.y - start.y);
+ e->state = EDGE_READY;
- /* horizontal edge */
- e->dxy = (start.x < end.x) ? INFINITY : -INFINITY;
- e->state = EDGE_FINISHED; /* these are skipped */
- } else {
- e->dxy = (float)(end.x - start.x)/(end.y - start.y);
- e->state = EDGE_READY;
- }
+ /* Shorten each edge by one pixel at the bottom. This prevents
+ * every vertex point to be reported as two intersections.
+ * This also means causes all horizontal edges cut by one pixel,
+ * but we will fix this at the end by drawing them separately.
+ */
+ e->dy--;
}
/* Type of a callback function to be passed to qsort(). */
@@ -140,7 +147,7 @@ void GP_FillPolygon_Raw(GP_Context *context, unsigned int nvert,
if (nvert < 3)
return; /* not enough vertices */
-
+
GP_Point const *vert = (GP_Point const *) xy;
/* find first and last scanline */
@@ -149,7 +156,7 @@ void GP_FillPolygon_Raw(GP_Context *context, unsigned int nvert,
ymax = GP_MAX(ymax, vert[i].y);
ymin = GP_MIN(ymin, vert[i].y);
}
-
+
/* build a list of edges */
struct GP_Edge edges[nvert];
unsigned int nedges = 0; /* number of edges in list */
@@ -161,9 +168,9 @@ void GP_FillPolygon_Raw(GP_Context *context, unsigned int nvert,
*/
unsigned int nexti = (i+1) % nvert;
- GP_InitEdge(edges + nedges, vert[i], vert[nexti]);
-
- nedges++;
+ /* add new edge record */
+ e = edges + nedges++;
+ GP_InitEdge(e, vert[i], vert[nexti]);
}
if (nedges < 2)
@@ -172,7 +179,7 @@ void GP_FillPolygon_Raw(GP_Context *context, unsigned int nvert,
/* initially sort edges by Y, then X */
qsort(edges, nedges, sizeof(struct GP_Edge),
(GP_SortCallback) GP_CompareEdgesInitial);
-
+
/*
* for each scanline, compute intersections with all edges
* and draw a horizontal line segment between the intersections.
@@ -191,7 +198,7 @@ void GP_FillPolygon_Raw(GP_Context *context, unsigned int nvert,
}
qsort(edges, nedges, sizeof(struct GP_Edge),
(GP_SortCallback) GP_CompareEdgesRuntime);
-
+
/* record intersections with active edges */
ninter = 0;
for (i = 0; i < nedges; i++) {
@@ -200,7 +207,7 @@ void GP_FillPolygon_Raw(GP_Context *context, unsigned int nvert,
inter[ninter++] = e->x;
}
}
-
+
/* draw each even range between intersections */
for (i = 0; i < ninter; i += 2) {
float start = inter[i];
@@ -212,7 +219,7 @@ void GP_FillPolygon_Raw(GP_Context *context, unsigned int nvert,
float end = inter[i+1];
GP_HLine_Raw(context, start, end, y, pixel);
}
-
+
/* update active edges for next step */
for (i = 0; i < nedges; i++) {
e = edges + i;
@@ -226,6 +233,17 @@ void GP_FillPolygon_Raw(GP_Context *context, unsigned int nvert,
}
}
}
+
+ /* finishing touch: draw all horizontal edges that were skipped
+ * in the main loop
+ */
+ for (i = 0; i < nedges; i++) {
+ e = edges + i;
+ if (e->state == EDGE_HORIZONTAL) {
+ GP_HLine_Raw(context, e->x, e->x + e->dxy, e->y,
+ pixel);
+ }
+ }
}
void GP_FillPolygon(GP_Context *context, unsigned int vertex_count,
-----------------------------------------------------------------------
Summary of changes:
libs/gfx/GP_Polygon.c | 66 +++++++++++++++++++++++++++++++-----------------
1 files changed, 42 insertions(+), 24 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: 13f50596531c7c69961d1625a6be2550c3565634
by metan 15 Dec '12
by metan 15 Dec '12
15 Dec '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 13f50596531c7c69961d1625a6be2550c3565634 (commit)
from 561ae54e3e8468a4368622344e5a90187d15da48 (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/13f50596531c7c69961d1625a6be2550c356…
commit 13f50596531c7c69961d1625a6be2550c3565634
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Sat Dec 15 11:31:00 2012 +0100
tests: loaders: Add regression tests for PNG loader.
diff --git a/tests/loaders/Makefile b/tests/loaders/Makefile
index 9497586..d8c1fcb 100644
--- a/tests/loaders/Makefile
+++ b/tests/loaders/Makefile
@@ -3,7 +3,7 @@ include $(TOPDIR)/pre.mk
CSOURCES=$(shell echo *.c)
-APPS=loaders_suite
+APPS=loaders_suite PNG
include ../tests.mk
diff --git a/tests/loaders/PNG.c b/tests/loaders/PNG.c
new file mode 100644
index 0000000..ad9381e
--- /dev/null
+++ b/tests/loaders/PNG.c
@@ -0,0 +1,100 @@
+/*****************************************************************************
+ * 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 <string.h>
+#include <errno.h>
+#include <sys/stat.h>
+
+#include <core/GP_Context.h>
+#include <loaders/GP_Loaders.h>
+
+#include "tst_test.h"
+
+static int test_load_PNG(const char *path)
+{
+ GP_Context *img;
+
+ img = GP_LoadPNG(path, NULL);
+
+ if (img == NULL) {
+ switch (errno) {
+ case ENOSYS:
+ tst_msg("Not Implemented");
+ return TST_SKIPPED;
+ default:
+ tst_msg("Got %s", strerror(errno));
+ return TST_FAILED;
+ }
+ }
+
+ /*
+ * TODO: check correct data.
+ */
+
+ GP_ContextFree(img);
+
+ return TST_SUCCESS;
+}
+
+const struct tst_suite tst_suite = {
+ .suite_name = "PNG",
+ .tests = {
+ /* PNG loader tests */
+ {.name = "PNG 100x100 RGB",
+ .tst_fn = test_load_PNG,
+ .res_path = "data/png/valid/100x100-red.png",
+ .data = "100x100-red.png",
+ .flags = TST_TMPDIR | TST_CHECK_MALLOC},
+
+ {.name = "PNG 100x100 RGB 50% alpha",
+ .tst_fn = test_load_PNG,
+ .res_path = "data/png/valid/100x100-red-alpha.png",
+ .data = "100x100-red-alpha.png",
+ .flags = TST_TMPDIR | TST_CHECK_MALLOC},
+
+ {.name = "PNG 100x100 8 bit Grayscale",
+ .tst_fn = test_load_PNG,
+ .res_path = "data/png/valid/100x100-black-grayscale.png",
+ .data = "100x100-black-grayscale.png",
+ .flags = TST_TMPDIR | TST_CHECK_MALLOC},
+
+ {.name = "PNG 100x100 8 bit Grayscale + alpha",
+ .tst_fn = test_load_PNG,
+ .res_path = "data/png/valid/100x100-black-grayscale-alpha.png",
+ .data = "100x100-black-grayscale-alpha.png",
+ .flags = TST_TMPDIR | TST_CHECK_MALLOC},
+
+ {.name = "PNG 100x100 Palette + alpha",
+ .tst_fn = test_load_PNG,
+ .res_path = "data/png/valid/100x100-palette-alpha.png",
+ .data = "100x100-palette-alpha.png",
+ .flags = TST_TMPDIR | TST_CHECK_MALLOC},
+
+ {.name = "PNG 100x100 Palette",
+ .tst_fn = test_load_PNG,
+ .res_path = "data/png/valid/100x100-red-palette.png",
+ .data = "100x100-red-palette.png",
+ .flags = TST_TMPDIR | TST_CHECK_MALLOC},
+
+ {.name = NULL},
+ }
+};
diff --git a/tests/loaders/data/png/valid/100x100-black-grayscale-alpha.png b/tests/loaders/data/png/valid/100x100-black-grayscale-alpha.png
new file mode 100644
index 0000000..32db4da
Binary files /dev/null and b/tests/loaders/data/png/valid/100x100-black-grayscale-alpha.png differ
diff --git a/tests/loaders/data/png/valid/100x100-black-grayscale.png b/tests/loaders/data/png/valid/100x100-black-grayscale.png
new file mode 100644
index 0000000..61ae31f
Binary files /dev/null and b/tests/loaders/data/png/valid/100x100-black-grayscale.png differ
diff --git a/tests/loaders/data/png/valid/100x100-palette-alpha.png b/tests/loaders/data/png/valid/100x100-palette-alpha.png
new file mode 100644
index 0000000..409e9cf
Binary files /dev/null and b/tests/loaders/data/png/valid/100x100-palette-alpha.png differ
diff --git a/tests/loaders/data/png/valid/100x100-red-palette.png b/tests/loaders/data/png/valid/100x100-red-palette.png
new file mode 100644
index 0000000..c4bcd3b
Binary files /dev/null and b/tests/loaders/data/png/valid/100x100-red-palette.png differ
diff --git a/tests/loaders/loaders_suite.c b/tests/loaders/loaders_suite.c
index 3d9fed4..3802caa 100644
--- a/tests/loaders/loaders_suite.c
+++ b/tests/loaders/loaders_suite.c
@@ -560,41 +560,6 @@ static int test_load_BMP_8bpp_1x64000(void)
return test_load_BMP("8bpp-1x64000.bmp");
}
-static int test_load_PNG(const char *path)
-{
- GP_Context *img;
-
- img = GP_LoadPNG(path, NULL);
-
- if (img == NULL) {
- switch (errno) {
- case ENOSYS:
- tst_msg("Not Implemented");
- return TST_SKIPPED;
- default:
- tst_msg("Got %s", strerror(errno));
- return TST_FAILED;
- }
- }
-
- /*
- * TODO: check correct data.
- */
- GP_ContextFree(img);
-
- return TST_SUCCESS;
-}
-
-static int test_load_PNG_100x100(void)
-{
- return test_load_PNG("100x100-red.png");
-}
-
-static int test_load_PNG_100x100_alpha(void)
-{
- return test_load_PNG("100x100-red-alpha.png");
-}
-
static int test_load_JPEG(const char *path)
{
GP_Context *img;
@@ -719,16 +684,6 @@ const struct tst_suite tst_suite = {
.res_path = "data/bmp/bitmaps/valid/8bpp-1x64000.bmp",
.flags = TST_TMPDIR},
- /* PNG loader tests */
- {.name = "PNG 100x100", .tst_fn = test_load_PNG_100x100,
- .res_path = "data/png/valid/100x100-red.png",
- .flags = TST_TMPDIR},
-
- {.name = "PNG 100x100 50% alpha",
- .tst_fn = test_load_PNG_100x100_alpha,
- .res_path = "data/png/valid/100x100-red-alpha.png",
- .flags = TST_TMPDIR},
-
/* JPEG loader tests */
{.name = "JPEG 100x100", .tst_fn = test_load_JPEG_100x100,
.res_path = "data/jpeg/valid/100x100-red.jpeg",
diff --git a/tests/loaders/runtest.sh b/tests/loaders/runtest.sh
index 0c6d722..e92c0c4 100755
--- a/tests/loaders/runtest.sh
+++ b/tests/loaders/runtest.sh
@@ -10,3 +10,4 @@
export LIBC_FATAL_STDERR_=1
LD_PRELOAD=`pwd`/../framework/libtst_preload.so LD_LIBRARY_PATH=../../build/ ./loaders_suite "$@"
+LD_PRELOAD=`pwd`/../framework/libtst_preload.so LD_LIBRARY_PATH=../../build/ ./PNG "$@"
-----------------------------------------------------------------------
Summary of changes:
tests/loaders/Makefile | 2 +-
tests/loaders/PNG.c | 100 ++++++++++++++++++++
.../png/valid/100x100-black-grayscale-alpha.png | Bin 0 -> 271 bytes
.../data/png/valid/100x100-black-grayscale.png | Bin 0 -> 184 bytes
.../data/png/valid/100x100-palette-alpha.png | Bin 0 -> 212 bytes
.../loaders/data/png/valid/100x100-red-palette.png | Bin 0 -> 309 bytes
tests/loaders/loaders_suite.c | 45 ---------
tests/loaders/runtest.sh | 1 +
8 files changed, 102 insertions(+), 46 deletions(-)
create mode 100644 tests/loaders/PNG.c
create mode 100644 tests/loaders/data/png/valid/100x100-black-grayscale-alpha.png
create mode 100644 tests/loaders/data/png/valid/100x100-black-grayscale.png
create mode 100644 tests/loaders/data/png/valid/100x100-palette-alpha.png
create mode 100644 tests/loaders/data/png/valid/100x100-red-palette.png
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: 561ae54e3e8468a4368622344e5a90187d15da48
by metan 15 Dec '12
by metan 15 Dec '12
15 Dec '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 561ae54e3e8468a4368622344e5a90187d15da48 (commit)
from 47ecc1b6fbfe01c1b21089b596deb39955ebddfd (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/561ae54e3e8468a4368622344e5a90187d15…
commit 561ae54e3e8468a4368622344e5a90187d15da48
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Sat Dec 15 10:53:00 2012 +0100
pywrap: loaders.i: Add a few %newobject directives.
diff --git a/pylib/gfxprim/loaders/loaders.i b/pylib/gfxprim/loaders/loaders.i
index 9561176..7c9d903 100644
--- a/pylib/gfxprim/loaders/loaders.i
+++ b/pylib/gfxprim/loaders/loaders.i
@@ -12,6 +12,8 @@ ERROR_ON_NULL(GP_LoadImage);
ERROR_ON_NONZERO(GP_LoadMetaData);
ERROR_ON_NONZERO(GP_SaveImage);
+%newobject GP_LoadImage;
+
%include "GP_Loaders.h"
ERROR_ON_NONZERO(GP_OpenJPG);
@@ -21,18 +23,24 @@ ERROR_ON_NONZERO(GP_ReadJPGMetaData);
ERROR_ON_NONZERO(GP_LoadJPGMetaData);
ERROR_ON_NONZERO(GP_SaveJPG);
+%newobject GP_LoadJPG;
+
%include "GP_JPG.h"
ERROR_ON_NONZERO(GP_OpenBMP);
ERROR_ON_NULL(GP_ReadBMP);
ERROR_ON_NULL(GP_LoadBMP);
+%newobject GP_LoadBMP;
+
%include "GP_BMP.h"
ERROR_ON_NONZERO(GP_OpenGIF);
ERROR_ON_NULL(GP_ReadGIF);
ERROR_ON_NULL(GP_LoadGIF);
+%newobject GP_LoadGIF;
+
%include "GP_GIF.h"
ERROR_ON_NONZERO(GP_OpenPNG);
@@ -42,6 +50,8 @@ ERROR_ON_NONZERO(GP_ReadPNGMetaData);
ERROR_ON_NONZERO(GP_LoadPNGMetaData);
ERROR_ON_NONZERO(GP_SavePNG);
+%newobject GP_LoadPNG;
+
%include "GP_PNG.h"
ERROR_ON_NULL(GP_LoadPBM);
@@ -54,4 +64,3 @@ ERROR_ON_NONZERO(GP_SavePPM);
%include "GP_PBM.h"
%include "GP_PGM.h"
%include "GP_PPM.h"
-
-----------------------------------------------------------------------
Summary of changes:
pylib/gfxprim/loaders/loaders.i | 11 ++++++++++-
1 files changed, 10 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: 47ecc1b6fbfe01c1b21089b596deb39955ebddfd
by metan 14 Dec '12
by metan 14 Dec '12
14 Dec '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 47ecc1b6fbfe01c1b21089b596deb39955ebddfd (commit)
from a69e12cc1918ea0b302e668fbcc378e95e9bda7e (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/47ecc1b6fbfe01c1b21089b596deb39955eb…
commit 47ecc1b6fbfe01c1b21089b596deb39955ebddfd
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Fri Dec 14 23:23:53 2012 +0100
pywrap: Comment out the PyBuffer_FromMemory.
Now at least some of the python examples runs.
diff --git a/pylib/gfxprim/core/core.i b/pylib/gfxprim/core/core.i
index 6ddfc29..c679c4b 100644
--- a/pylib/gfxprim/core/core.i
+++ b/pylib/gfxprim/core/core.i
@@ -77,10 +77,12 @@ and self.thisown.") GP_Context;
$self->w, $self->h, $self->bpp, $self->free_pixels);
GP_ContextFree($self);
}
+ /*
PyObject *_hacky_hacky_pixels_buffer() {
GP_DEBUG(0, "Evil and dangerous _hacky_hacky_pixels_buffer() used!");
return PyBuffer_FromMemory($self->pixels, $self->bytes_per_row * $self->h);
}
+ */
};
/* Error handling */
-----------------------------------------------------------------------
Summary of changes:
pylib/gfxprim/core/core.i | 2 ++
1 files changed, 2 insertions(+), 0 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: a69e12cc1918ea0b302e668fbcc378e95e9bda7e
by metan 14 Dec '12
by metan 14 Dec '12
14 Dec '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 a69e12cc1918ea0b302e668fbcc378e95e9bda7e (commit)
via b3041644e08a6a9306cbd22b908d3fc4312b55d0 (commit)
via 81a4a805f6d839133ab4f7066d27ef5073b201e9 (commit)
from e33c83da1ded26f2e05184e4847c197d05ec146b (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/a69e12cc1918ea0b302e668fbcc378e95e9b…
commit a69e12cc1918ea0b302e668fbcc378e95e9bda7e
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Fri Dec 14 20:47:01 2012 +0100
loaders: GP_PNG.c: Fix crash on palette with alpha
diff --git a/libs/loaders/GP_PNG.c b/libs/loaders/GP_PNG.c
index 87d9eca..c963794 100644
--- a/libs/loaders/GP_PNG.c
+++ b/libs/loaders/GP_PNG.c
@@ -107,6 +107,7 @@ GP_Context *GP_ReadPNG(FILE *f, GP_ProgressCallback *callback)
GP_PixelType pixel_type = GP_PIXEL_UNKNOWN;
GP_Context *res;
int err;
+ double gamma;
png = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
@@ -138,12 +139,14 @@ GP_Context *GP_ReadPNG(FILE *f, GP_ProgressCallback *callback)
png_get_IHDR(png, png_info, &w, &h, &depth,
&color_type, &interlace_type, NULL, NULL);
- GP_DEBUG(2, "Have %s%s interlace %s PNG%s size %ux%u depth %i",
+ png_get_gAMA(png, png_info, &gamma);
+
+ GP_DEBUG(2, "Interlace=%s%s %s PNG%s size %ux%u depth %i gamma %.2lf",
interlace_type_name(interlace_type),
- color_type & PNG_COLOR_MASK_PALETTE ? " pallete " : "",
+ color_type & PNG_COLOR_MASK_PALETTE ? " pallete" : "",
color_type & PNG_COLOR_MASK_COLOR ? "color" : "gray",
color_type & PNG_COLOR_MASK_ALPHA ? " with alpha channel" : "",
- (unsigned int)w, (unsigned int)h, depth);
+ (unsigned int)w, (unsigned int)h, depth, gamma);
switch (color_type) {
case PNG_COLOR_TYPE_GRAY:
@@ -187,7 +190,16 @@ GP_Context *GP_ReadPNG(FILE *f, GP_ProgressCallback *callback)
//TODO: add palette matching to G2 G4 and G8
png_set_palette_to_rgb(png);
png_set_bgr(png);
- pixel_type = GP_PIXEL_RGB888;
+
+ png_read_update_info(png, png_info);
+
+ png_get_IHDR(png, png_info, &w, &h, &depth,
+ &color_type, NULL, NULL, NULL);
+
+ if (color_type & PNG_COLOR_MASK_ALPHA)
+ pixel_type = GP_PIXEL_UNKNOWN;
+ else
+ pixel_type = GP_PIXEL_RGB888;
break;
}
@@ -212,14 +224,13 @@ GP_Context *GP_ReadPNG(FILE *f, GP_ProgressCallback *callback)
/* start the actuall reading */
for (y = 0; y < h; y++) {
png_bytep row = GP_PIXEL_ADDR(res, 0, y);
- png_read_rows(png, &row, NULL, 1);
+ png_read_row(png, row, NULL);
if (GP_ProgressCallbackReport(callback, y, h, w)) {
GP_DEBUG(1, "Operation aborted");
err = ECANCELED;
goto err3;
}
-
}
png_destroy_read_struct(&png, &png_info, NULL);
http://repo.or.cz/w/gfxprim.git/commit/b3041644e08a6a9306cbd22b908d3fc4312b…
commit b3041644e08a6a9306cbd22b908d3fc4312b55d0
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Fri Dec 14 19:16:30 2012 +0100
backends: GP_X11.c: Make internal functions static.
diff --git a/libs/backends/GP_X11.c b/libs/backends/GP_X11.c
index d02b244..afe38fd 100644
--- a/libs/backends/GP_X11.c
+++ b/libs/backends/GP_X11.c
@@ -230,7 +230,8 @@ static int x11_set_attributes(struct GP_Backend *self,
return 0;
}
-void match_pixel_type(struct x11_priv *x11, enum GP_PixelType *pixel_type, int *depth)
+static void match_pixel_type(struct x11_priv *x11,
+ enum GP_PixelType *pixel_type, int *depth)
{
/*
* Eh, the XImage supports either 8, 16 or 32 bit pixels
@@ -437,9 +438,9 @@ static int resize_ximage(GP_Backend *self, int w, int h)
return 0;
}
-void create_window(struct x11_priv *x11, int x, int y,
- unsigned int *w, unsigned int *h,
- const char *caption, enum GP_BackendX11Flags flags)
+static void create_window(struct x11_priv *x11, int x, int y,
+ unsigned int *w, unsigned int *h,
+ const char *caption, enum GP_BackendX11Flags flags)
{
XSetWindowAttributes attrs;
unsigned long attr_mask = 0;
http://repo.or.cz/w/gfxprim.git/commit/81a4a805f6d839133ab4f7066d27ef5073b2…
commit 81a4a805f6d839133ab4f7066d27ef5073b201e9
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Fri Dec 14 19:13:35 2012 +0100
build: Edhance symbol detection script.
The script now works for backends and grabbers too.
diff --git a/build/check_symbols.sh b/build/check_symbols.sh
index 9625ff6..f4ccd32 100755
--- a/build/check_symbols.sh
+++ b/build/check_symbols.sh
@@ -3,7 +3,7 @@
# Purpose of this script is to check library exported symbols
#
-SYMBOLFILE=libGP_symbols.txt
+SYMTMPFILE=symbols.txt
function grep_sym
{
@@ -19,19 +19,42 @@ function find_symbol
find ../libs/ -name '*.o' | while read obj; do grep_sym "$obj" "$1"; done
}
-objdump --dynamic-syms libGP.so | awk 'NR > 4 { print }' | awk '$3 != "*UND*"' | awk '{print $NF}' > $SYMBOLFILE
+function get_symbols
+{
+ objdump --dynamic-syms "$1" | awk 'NR > 4 { print }' | awk '$3 != "*UND*"' | awk '{print $NF}' > "$2"
-#
-# Remove compiler and glibc symbols
-#
-sed -i '/^.init$/d' $SYMBOLFILE
-sed -i '/^__.*$/d' $SYMBOLFILE
-sed -i '/^_.*$/d' $SYMBOLFILE
+ #
+ # Remove compiler and glibc symbols
+ #
+ sed -i '/^.init$/d' "$2"
+ sed -i '/^__.*$/d' "$2"
+ sed -i '/^_.*$/d' "$2"
+}
-for i in `cat libGP_symbols.txt`; do
- if ! grep "$i" syms/*.txt 2>&1 > /dev/null; then
- find_symbol "$i"
- fi
-done
+function check_symbols
+{
+ local symfile=$1
+ shift
+
+ for i in `cat $symfile`; do
+ if ! grep $i $@ 2>&1 > /dev/null; then
+ find_symbol "$i"
+ fi
+ done
+}
+
+function do_check
+{
+ get_symbols "$1" $SYMTMPFILE
+ shift
+ check_symbols $SYMTMPFILE "$@"
+ rm $SYMTMPFILE
+}
+
+do_check libGP.so syms/Core_symbols.txt syms/Event_symbols.txt + syms/Filters_symbols.txt syms/GFX_symbols.txt + syms/Loaders_symbols.txt syms/Text_symbols.txt
+
+do_check libGP_backends.so syms/Backend_symbols.txt
-rm libGP_symbols.txt
+do_check libGP_grabbers.so syms/Grabbers_symbols.txt
diff --git a/build/syms/Backend_symbols.txt b/build/syms/Backend_symbols.txt
new file mode 100644
index 0000000..7eddbe5
--- /dev/null
+++ b/build/syms/Backend_symbols.txt
@@ -0,0 +1,10 @@
+GP_BackendInit
+GP_BackendLinuxFBInit
+GP_BackendVirtualInit
+GP_BackendX11Init
+GP_BackendSDLInit
+
+GP_ContextFromSurface
+
+GP_BackendResize
+GP_BackendUpdateRectXYXY
diff --git a/build/syms/Grabbers_symbols.txt b/build/syms/Grabbers_symbols.txt
new file mode 100644
index 0000000..1cf56e1
--- /dev/null
+++ b/build/syms/Grabbers_symbols.txt
@@ -0,0 +1 @@
+GP_GrabberV4L2Init
-----------------------------------------------------------------------
Summary of changes:
build/check_symbols.sh | 51 ++++++++++++++++++++++++++++----------
build/syms/Backend_symbols.txt | 10 +++++++
build/syms/Grabbers_symbols.txt | 1 +
libs/backends/GP_X11.c | 9 ++++---
libs/loaders/GP_PNG.c | 23 +++++++++++++----
5 files changed, 70 insertions(+), 24 deletions(-)
create mode 100644 build/syms/Backend_symbols.txt
create mode 100644 build/syms/Grabbers_symbols.txt
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