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: 14d0a7da4df6fac46b50da3afd0ab8fe35653e6f
by metan 31 Jul '12
by metan 31 Jul '12
31 Jul '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 14d0a7da4df6fac46b50da3afd0ab8fe35653e6f (commit)
via 4e3436903e82cb8d907c20f466f74861a1d4f8d0 (commit)
from 3bb0c27b1b845641f8e8d69a28244b2ecc028d08 (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/14d0a7da4df6fac46b50da3afd0ab8fe3565…
commit 14d0a7da4df6fac46b50da3afd0ab8fe35653e6f
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Tue Jul 31 23:24:42 2012 +0200
demos: rename sierpinsky to koch (the name was wrong to begin with).
diff --git a/demos/c_simple/Makefile b/demos/c_simple/Makefile
index cefd2bb..ec6ac66 100644
--- a/demos/c_simple/Makefile
+++ b/demos/c_simple/Makefile
@@ -8,7 +8,7 @@ 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 sierpinsky
+ v4l2_show v4l2_grab convolution weighted_median shapetest koch
v4l2_show: LDLIBS+=-lGP_grabbers
v4l2_grab: LDLIBS+=-lGP_grabbers
diff --git a/demos/c_simple/sierpinsky.c b/demos/c_simple/koch.c
similarity index 98%
rename from demos/c_simple/sierpinsky.c
rename to demos/c_simple/koch.c
index db52a04..6668cb0 100644
--- a/demos/c_simple/sierpinsky.c
+++ b/demos/c_simple/koch.c
@@ -128,7 +128,7 @@ int main(void)
{
const char *backend_opts = "X11";
- backend = GP_BackendInit(backend_opts, "Shapetest", stderr);
+ backend = GP_BackendInit(backend_opts, "Koch", stderr);
if (backend == NULL) {
fprintf(stderr, "Failed to initalize backend '%s'n",
http://repo.or.cz/w/gfxprim.git/commit/4e3436903e82cb8d907c20f466f74861a1d4…
commit 4e3436903e82cb8d907c20f466f74861a1d4f8d0
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Tue Jul 31 23:22:40 2012 +0200
demos: Port sierpinsky from SDL to GFXprim backends.
diff --git a/demos/c_simple/Makefile b/demos/c_simple/Makefile
index 32adf69..cefd2bb 100644
--- a/demos/c_simple/Makefile
+++ b/demos/c_simple/Makefile
@@ -8,7 +8,7 @@ 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
+ v4l2_show v4l2_grab convolution weighted_median shapetest sierpinsky
v4l2_show: LDLIBS+=-lGP_grabbers
v4l2_grab: LDLIBS+=-lGP_grabbers
diff --git a/demos/c_simple/shapetest.c b/demos/c_simple/shapetest.c
index 3f50d5a..ef33b04 100644
--- a/demos/c_simple/shapetest.c
+++ b/demos/c_simple/shapetest.c
@@ -434,8 +434,6 @@ int main(int argc, char ** argv)
// GP_SetDebugLevel(10);
- backend_opts = "SDL:320x240";
-
backend = GP_BackendInit(backend_opts, "Shapetest", stderr);
if (backend == NULL) {
diff --git a/tests/SDL/sierpinsky.c b/demos/c_simple/sierpinsky.c
similarity index 72%
rename from tests/SDL/sierpinsky.c
rename to demos/c_simple/sierpinsky.c
index 5d1e0f9..db52a04 100644
--- a/tests/SDL/sierpinsky.c
+++ b/demos/c_simple/sierpinsky.c
@@ -19,7 +19,7 @@
* Copyright (C) 2009-2010 Jiri "BlueBear" Dluhos *
* <jiri.bluebear.dluhos(a)gmail.com> *
* *
- * Copyright (C) 2009-2011 Cyril Hrubis <metan(a)ucw.cz> *
+ * Copyright (C) 2009-2012 Cyril Hrubis <metan(a)ucw.cz> *
* *
*****************************************************************************/
@@ -29,27 +29,21 @@
*/
-#include "GP_SDL.h"
-
-#include <SDL/SDL.h>
#include <math.h>
-#define TIMER_TICK 50
+#include <GP.h>
+
+#define TIMER_TICK 10000
#define DISPLAY_W 640
#define DISPLAY_H 480
#define sqr(x) ((x)*(x))
#define sgn(x) ((x)>0 ? 1 : -1)
-SDL_Surface *display;
-GP_Context *context, ctx;
-
-SDL_TimerID timer;
-
-int iter, l, way = 1;
+static GP_Backend *backend;
+static GP_Context *context;
-GP_Pixel black, blue, gray, red;
-
-int draw_edge = 1;
+static int iter, l, way = 1, draw_edge = 1;
+static GP_Pixel black, blue, gray, red;
static void sierpinsky(double x1, double y1, double x4, double y4, int iter)
{
@@ -109,92 +103,80 @@ static void draw(int x, int y, int l, int iter)
sierpinsky(x2, y2, x3, y3, iter/60%6);
sierpinsky(x3, y3, x1, y1, iter/60%6);
- SDL_Flip(display);
+ GP_BackendFlip(backend);
}
-int paused = 0;
+static int paused = 0;
-Uint32 timer_callback(Uint32 interval __attribute__ ((unused)),
- void *ptr __attribute__ ((unused)))
+void redraw(void)
{
if (paused)
- return TIMER_TICK;
+ return;
iter += 2 * way;
- if (iter + 2 * way > 350)
+ if (iter > 350)
way *= -1;
- if (iter < 2 * way)
- way *= 1;
-
- draw(display->w/2, display->h/2, l, iter);
+ if (iter < 0)
+ way *= -1;
- return TIMER_TICK;
+ draw(context->w/2, context->h/2, l, iter);
}
int main(void)
{
- SDL_Event ev;
-
- if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) != 0)
- return -1;
-
- display = SDL_SetVideoMode(DISPLAY_W, DISPLAY_H, 0, SDL_SWSURFACE | SDL_RESIZABLE | SDL_DOUBLEBUF);
+ const char *backend_opts = "X11";
+
+ backend = GP_BackendInit(backend_opts, "Shapetest", stderr);
- if (display == NULL) {
- SDL_Quit();
- return -1;
+ if (backend == NULL) {
+ fprintf(stderr, "Failed to initalize backend '%s'n",
+ backend_opts);
+ return 1;
}
-
- GP_SDL_ContextFromSurface(&ctx, display);
-
- context = &ctx;
-
+
+ context = backend->context;
+
black = GP_ColorToContextPixel(GP_COL_BLACK, context);
blue = GP_ColorToContextPixel(GP_COL_BLUE, context);
gray = GP_ColorToContextPixel(GP_COL_GRAY_LIGHT, context);
red = GP_ColorToContextPixel(GP_COL_RED, context);
-
+
iter = 0;
- draw(display->w/2, display->h/2, l, iter);
+ draw(context->w/2, context->h/2, l, iter);
- timer = SDL_AddTimer(0, timer_callback, NULL);
+ for (;;) {
+ GP_Event ev;
- if (timer == 0) {
- SDL_Quit();
- return -1;
- }
-
- while (SDL_WaitEvent(&ev) > 0) {
- switch (ev.type) {
- case SDL_KEYDOWN:
- switch(ev.key.keysym.sym) {
- case SDLK_p:
- paused = !paused;
- break;
- case SDLK_e:
- draw_edge = !draw_edge;
- break;
- case SDLK_ESCAPE:
- SDL_Quit();
- return 0;
- break;
- default:
- break;
+ redraw();
+
+ GP_BackendPoll(backend);
+
+ while (GP_EventGet(&ev)) {
+ GP_EventDump(&ev);
+
+ switch (ev.type) {
+ case GP_EV_KEY:
+ if (ev.code != GP_EV_KEY_DOWN)
+ continue;
+
+ switch (ev.val.key.key) {
+ case GP_KEY_P:
+ paused = !paused;
+ break;
+ case GP_KEY_E:
+ draw_edge = !draw_edge;
+ break;
+ case GP_KEY_ESC:
+ GP_BackendExit(backend);
+ return 0;
+ break;
}
- break;
- case SDL_QUIT:
- SDL_Quit();
- return 0;
- break;
- default:
- break;
+ }
}
+ usleep(TIMER_TICK);
}
-
- SDL_Quit();
-
+
return 0;
}
-
diff --git a/tests/SDL/Makefile b/tests/SDL/Makefile
index 26cfa60..228df9e 100644
--- a/tests/SDL/Makefile
+++ b/tests/SDL/Makefile
@@ -7,7 +7,7 @@ LDLIBS+=-lGP -L$(TOPDIR)/build/ -lGP_SDL -lSDL
ifeq ($(HAVE_LIBSDL),yes)
CSOURCES=$(shell echo *.c)
-APPS=pixeltest fileview fonttest linetest randomshapetest sierpinsky+APPS=pixeltest fileview fonttest linetest randomshapetest symbolstest textaligntest trianglefps input blittest subcontext showimage aatest mixpixeltest
endif
-----------------------------------------------------------------------
Summary of changes:
demos/c_simple/Makefile | 2 +-
tests/SDL/sierpinsky.c => demos/c_simple/koch.c | 130 ++++++++++-------------
demos/c_simple/shapetest.c | 2 -
tests/SDL/Makefile | 2 +-
4 files changed, 58 insertions(+), 78 deletions(-)
rename tests/SDL/sierpinsky.c => demos/c_simple/koch.c (72%)
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: 3bb0c27b1b845641f8e8d69a28244b2ecc028d08
by metan 31 Jul '12
by metan 31 Jul '12
31 Jul '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 3bb0c27b1b845641f8e8d69a28244b2ecc028d08 (commit)
via 40d352f0bb0706b29175f0dde15b33183b0868d3 (commit)
via 6cd5c9a311e704e0c23fff2fdbe73ff9b60a40d4 (commit)
via b1270316b77d3b03e3c43db35f20e69807e3f02c (commit)
via aa0e161ecd926eadbfc894db7568b468c617b648 (commit)
via 11febf3f119c7d728b7a14b912d0ad216c855545 (commit)
via ed4194a59b8b1d8d28d32e51d85863e2db559c17 (commit)
from 2cc8f1085bcceb34939008770bf988597a1d0d5f (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/3bb0c27b1b845641f8e8d69a28244b2ecc02…
commit 3bb0c27b1b845641f8e8d69a28244b2ecc028d08
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Tue Jul 31 22:51:03 2012 +0200
demos: Port shapetest from SDL to GFXprim backends.
diff --git a/demos/c_simple/Makefile b/demos/c_simple/Makefile
index 0a311ea..32adf69 100644
--- a/demos/c_simple/Makefile
+++ b/demos/c_simple/Makefile
@@ -8,7 +8,7 @@ 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
+ v4l2_show v4l2_grab convolution weighted_median shapetest
v4l2_show: LDLIBS+=-lGP_grabbers
v4l2_grab: LDLIBS+=-lGP_grabbers
diff --git a/tests/SDL/shapetest.c b/demos/c_simple/shapetest.c
similarity index 54%
rename from tests/SDL/shapetest.c
rename to demos/c_simple/shapetest.c
index 0bbc4c4..3f50d5a 100644
--- a/tests/SDL/shapetest.c
+++ b/demos/c_simple/shapetest.c
@@ -19,34 +19,17 @@
* Copyright (C) 2009-2010 Jiri "BlueBear" Dluhos *
* <jiri.bluebear.dluhos(a)gmail.com> *
* *
- * Copyright (C) 2009-2011 Cyril Hrubis <metan(a)ucw.cz> *
+ * Copyright (C) 2009-2012 Cyril Hrubis <metan(a)ucw.cz> *
* *
*****************************************************************************/
#include <stdio.h>
#include <stdlib.h>
-#include <SDL/SDL.h>
-#include "GP.h"
-#include "GP_SDL.h"
+#include <GP.h>
-/* The surface used as a display (in fact it is a software surface). */
-SDL_Surface *display = NULL;
-GP_Context context;
-
-/* Timer used for refreshing the display */
-SDL_TimerID timer;
-
-/* An event used for signaling that the timer was triggered. */
-SDL_UserEvent timer_event;
-
-Uint32 timer_callback(__attribute__((unused)) Uint32 interval,
- __attribute__((unused)) void * param)
-{
- timer_event.type = SDL_USEREVENT;
- SDL_PushEvent((SDL_Event *) &timer_event);
- return 60;
-}
+static GP_Context *win;
+static GP_Backend *backend;
/* Basic colors in display-specific format. */
static GP_Pixel black, white, yellow, green, red, gray, darkgray;
@@ -79,19 +62,9 @@ static int shape = SHAPE_FIRST;
/* Variants in coordinates, if applicable */
static int variant = 1;
-/* Increments added to radii in every timeframe (0 = no change). */
-static int xradius_add = 0;
-static int yradius_add = 0;
-
-#define DISPLAY_W 640
-#define DISPLAY_H 480
-
-static int display_w = DISPLAY_W;
-static int display_h = DISPLAY_H;
-
/* center of drawing */
-static int center_x = DISPLAY_W/2;
-static int center_y = DISPLAY_H/2;
+static int center_x;
+static int center_y;
void draw_testing_triangle(int x, int y, int xradius, int yradius)
{
@@ -135,61 +108,61 @@ void draw_testing_triangle(int x, int y, int xradius, int yradius)
/* draw the three vertices green; they should never be visible
* because the red triangle should cover them; if they are visible,
* it means we don't draw to the end */
- GP_PutPixel(&context, x0, y0, green);
- GP_PutPixel(&context, x1, y1, green);
- GP_PutPixel(&context, x2, y2, green);
+ GP_PutPixel(win, x0, y0, green);
+ GP_PutPixel(win, x1, y1, green);
+ GP_PutPixel(win, x2, y2, green);
if (outline == 1)
- GP_Triangle(&context, x0, y0, x1, y1, x2, y2, yellow);
+ GP_Triangle(win, x0, y0, x1, y1, x2, y2, yellow);
if (fill)
- GP_FillTriangle(&context, x0, y0, x1, y1, x2, y2, red);
+ GP_FillTriangle(win, x0, y0, x1, y1, x2, y2, red);
if (outline == 2)
- GP_Triangle(&context, x0, y0, x1, y1, x2, y2, white);
+ GP_Triangle(win, x0, y0, x1, y1, x2, y2, white);
}
void draw_testing_circle(int x, int y, int xradius,
__attribute__((unused)) int yradius)
{
if (outline == 1)
- GP_Circle(&context, x, y, xradius, yellow);
+ GP_Circle(win, x, y, xradius, yellow);
if (fill)
- GP_FillCircle(&context, x, y, xradius, red);
+ GP_FillCircle(win, x, y, xradius, red);
if (outline == 2)
- GP_Circle(&context, x, y, xradius, white);
+ GP_Circle(win, x, y, xradius, white);
}
void draw_testing_ring(int x, int y, int xradius,
__attribute__((unused)) int yradius)
{
if (outline == 1)
- GP_Ring(&context, x, y, xradius, yradius, yellow);
+ GP_Ring(win, x, y, xradius, yradius, yellow);
if (fill)
- GP_FillRing(&context, x, y, xradius, yradius, red);
+ GP_FillRing(win, x, y, xradius, yradius, red);
if (outline == 2)
- GP_Ring(&context, x, y, xradius, yradius, white);
+ GP_Ring(win, x, y, xradius, yradius, white);
}
void draw_testing_ellipse(int x, int y, int xradius, int yradius)
{
if (outline == 1)
- GP_Ellipse(&context, x, y, xradius, yradius, yellow);
+ GP_Ellipse(win, x, y, xradius, yradius, yellow);
if (fill)
- GP_FillEllipse(&context, x, y, xradius, yradius, red);
+ GP_FillEllipse(win, x, y, xradius, yradius, red);
if (outline == 2)
- GP_Ellipse(&context, x, y, xradius, yradius, white);
+ GP_Ellipse(win, x, y, xradius, yradius, white);
}
void draw_testing_arc(int x, int y, int xradius, int yradius)
{
- GP_ArcSegment(&context, x, y, xradius, yradius, -1,
+ GP_ArcSegment(win, x, y, xradius, yradius, -1,
M_PI - M_PI/8.0, M_PI/4.0, red);
}
@@ -199,13 +172,13 @@ void draw_testing_rectangle(int x, int y, int xradius, int yradius)
int x1 = x + xradius, y1 = y + yradius;
if (outline == 1)
- GP_Rect(&context, x0, y0, x1, y1, yellow);
+ GP_Rect(win, x0, y0, x1, y1, yellow);
if (fill)
- GP_FillRect(&context, x0, y0, x1, y1, red);
+ GP_FillRect(win, x0, y0, x1, y1, red);
if (outline == 2)
- GP_Rect(&context, x0, y0, x1, y1, white);
+ GP_Rect(win, x0, y0, x1, y1, white);
}
void draw_testing_tetragon(int x, int y, int xradius, int yradius)
@@ -216,13 +189,13 @@ void draw_testing_tetragon(int x, int y, int xradius, int yradius)
int x3 = x, y3 = y + yradius;
if (outline == 1)
- GP_Tetragon(&context, x0, y0, x1, y1, x2, y2, x3, y3, yellow);
+ GP_Tetragon(win, x0, y0, x1, y1, x2, y2, x3, y3, yellow);
if (fill)
- GP_FillTetragon(&context, x0, y0, x1, y1, x2, y2, x3, y3, red);
+ GP_FillTetragon(win, x0, y0, x1, y1, x2, y2, x3, y3, red);
if (outline == 2)
- GP_Tetragon(&context, x0, y0, x1, y1, x2, y2, x3, y3, white);
+ GP_Tetragon(win, x0, y0, x1, y1, x2, y2, x3, y3, white);
}
void redraw_screen(void)
@@ -237,17 +210,16 @@ void redraw_screen(void)
.pixel_yspace = 1,
};
- SDL_LockSurface(display);
- GP_Fill(&context, black);
+ GP_Fill(win, black);
/* axes */
if (show_axes) {
- GP_HLine(&context, 0, display_w, center_y, gray);
- GP_HLine(&context, 0, display_w, center_y-yradius, darkgray);
- GP_HLine(&context, 0, display_w, center_y+yradius, darkgray);
- GP_VLine(&context, center_x, 0, display_h, gray);
- GP_VLine(&context, center_x-xradius, 0, display_h, darkgray);
- GP_VLine(&context, center_x+xradius, 0, display_h, darkgray);
+ GP_HLine(win, 0, win->w, center_y, gray);
+ GP_HLine(win, 0, win->w, center_y-yradius, darkgray);
+ GP_HLine(win, 0, win->w, center_y+yradius, darkgray);
+ GP_VLine(win, center_x, 0, win->h, gray);
+ GP_VLine(win, center_x-xradius, 0, win->h, darkgray);
+ GP_VLine(win, center_x+xradius, 0, win->h, darkgray);
}
/* the shape */
@@ -283,183 +255,156 @@ void redraw_screen(void)
break;
}
- GP_Text(&context, &style, 16, 16, GP_ALIGN_RIGHT|GP_VALIGN_BELOW,
+ GP_Text(win, &style, 16, 16, GP_ALIGN_RIGHT|GP_VALIGN_BELOW,
white, black, title);
- SDL_UnlockSurface(display);
+ GP_BackendFlip(backend);
}
-void event_loop(void)
+static void xradius_add(int xradius_add)
{
- static bool shift_pressed = false;
- static int xcenter_add = 0;
- static int ycenter_add = 0;
- SDL_Event event;
-
- while (SDL_WaitEvent(&event) > 0) {
-
- switch (event.type) {
- case SDL_USEREVENT:
+ if (xradius + xradius_add > 1 &&
+ xradius + xradius_add < (int)win->w)
+ xradius += xradius_add;
+}
+
- if (xradius + xradius_add > 1 &&
- xradius + xradius_add < display_w)
- xradius += xradius_add;
-
- if (yradius + yradius_add > 1 &&
- yradius + yradius_add < display_h)
- yradius += yradius_add;
+static void yradius_add(int yradius_add)
+{
+ if (yradius + yradius_add > 1 &&
+ yradius + yradius_add < (int)win->h)
+ yradius += yradius_add;
+}
- if (center_x + xcenter_add > 1 &&
- center_x + xcenter_add < display_w/2)
- center_x += xcenter_add;
+static void xcenter_add(int xcenter_add)
+{
+ if (center_x + xcenter_add > 1 &&
+ center_x + xcenter_add < (int)win->w/2)
+ center_x += xcenter_add;
+}
- if (center_y + ycenter_add > 1 &&
- center_y + ycenter_add < display_h/2)
- center_y += ycenter_add;
+static void ycenter_add(int ycenter_add)
+{
+ if (center_y + ycenter_add > 1 &&
+ center_y + ycenter_add < (int)win->h/2)
+ center_y += ycenter_add;
+}
- redraw_screen();
- SDL_Flip(display);
- break;
+void event_loop(void)
+{
+ int shift_pressed;
- case SDL_KEYDOWN:
- switch (event.key.keysym.sym) {
- case SDLK_LSHIFT:
- case SDLK_RSHIFT:
- shift_pressed = true;
- break;
- case SDLK_x:
- context.x_swap = !context.x_swap;
+ GP_Event ev;
+
+ while (GP_EventGet(&ev)) {
+ GP_EventDump(&ev);
+
+ shift_pressed = GP_EventGetKey(&ev, GP_KEY_LEFT_SHIFT) ||
+ GP_EventGetKey(&ev, GP_KEY_RIGHT_SHIFT);
+
+ switch (ev.type) {
+ case GP_EV_KEY:
+ if (ev.code != GP_EV_KEY_DOWN)
+ continue;
+
+ switch (ev.val.key.key) {
+ case GP_KEY_X:
+ win->x_swap = !win->x_swap;
break;
- case SDLK_y:
- context.y_swap = !context.y_swap;
+ case GP_KEY_Y:
+ win->y_swap = !win->y_swap;
break;
- case SDLK_r:
- context.axes_swap = !context.axes_swap;
- GP_SWAP(display_w, display_h);
+ case GP_KEY_R:
+ win->axes_swap = !win->axes_swap;
+ GP_SWAP(win->w, win->h);
break;
- case SDLK_f:
+ case GP_KEY_F:
fill = !fill;
if (!fill && !outline)
outline = 1;
- break;
-
- case SDLK_o:
+ break;
+ case GP_KEY_O:
outline++;
if (outline == 3)
outline = 0;
if (!fill && outline == 0)
fill = 1;
- break;
-
- case SDLK_a:
+ break;
+ case GP_KEY_A:
show_axes = !show_axes;
- break;
-
- case SDLK_ESCAPE:
- return;
-
- case SDLK_LEFT:
+ break;
+ case GP_KEY_LEFT:
if (shift_pressed)
- xcenter_add = -1;
+ xcenter_add(-1);
else
- xradius_add = -1;
- break;
-
- case SDLK_RIGHT:
+ xradius_add(-1);
+ break;
+ case GP_KEY_RIGHT:
if (shift_pressed)
- xcenter_add = 1;
+ xcenter_add(1);
else
- xradius_add = 1;
- break;
-
- case SDLK_UP:
+ xradius_add(1);
+ break;
+ case GP_KEY_UP:
if (shift_pressed)
- ycenter_add = -1;
+ ycenter_add(-1);
else
- yradius_add = 1;
- break;
-
- case SDLK_DOWN:
+ yradius_add(1);
+ break;
+ case GP_KEY_DOWN:
if (shift_pressed)
- ycenter_add = 1;
+ ycenter_add(1);
else
- yradius_add = -1;
- break;
-
- case SDLK_PAGEUP:
- xradius_add = 1;
- yradius_add = 1;
- break;
-
- case SDLK_PAGEDOWN:
- xradius_add = -1;
- yradius_add = -1;
- break;
-
- case SDLK_1:
- variant = 1;
- break;
-
- case SDLK_2:
- variant = 2;
- break;
-
- case SDLK_3:
- variant = 3;
- break;
-
- case SDLK_4:
- variant = 4;
- break;
-
- case SDLK_SPACE:
+ yradius_add(-1);
+ break;
+ case GP_KEY_SPACE:
shape++;
if (shape > SHAPE_LAST)
shape = SHAPE_FIRST;
- break;
-
- case SDLK_EQUALS:
+ break;
+ case GP_KEY_EQUAL:
if (xradius > yradius)
yradius = xradius;
else
xradius = yradius;
- break;
-
- default:
- break;
- }
break;
- case SDL_KEYUP:
- switch (event.key.keysym.sym) {
- case SDLK_LSHIFT:
- case SDLK_RSHIFT:
- shift_pressed = false;
+ case GP_KEY_1:
+ variant = 1;
+ break;
+ case GP_KEY_2:
+ variant = 2;
+ break;
+ case GP_KEY_3:
+ variant = 3;
+ break;
+ case GP_KEY_4:
+ variant = 4;
+ break;
+ case GP_KEY_PAGE_UP:
+ xradius_add(1);
+ yradius_add(1);
+ break;
+ case GP_KEY_PAGE_DOWN:
+ xradius_add(-1);
+ yradius_add(-1);
+ break;
+ case GP_KEY_ESC:
+ GP_BackendExit(backend);
+ exit(0);
+ break;
+ }
+ break;
+ case GP_EV_SYS:
+ switch(ev.code) {
+ case GP_EV_SYS_QUIT:
+ GP_BackendExit(backend);
+ exit(1);
break;
- /* Stop incrementing as soon as the key is released. */
- case SDLK_LEFT:
- case SDLK_RIGHT:
- xradius_add = 0;
- xcenter_add = 0;
- break;
- case SDLK_UP:
- case SDLK_DOWN:
- yradius_add = 0;
- ycenter_add = 0;
- break;
-
- case SDLK_PAGEUP:
- case SDLK_PAGEDOWN:
- xradius_add = 0;
- yradius_add = 0;
- break;
-
- default:
- break;
}
break;
- case SDL_QUIT:
- return;
}
+
+ redraw_screen();
}
}
@@ -485,62 +430,40 @@ void print_instructions(void)
int main(int argc, char ** argv)
{
- int display_bpp = 0;
-
- int i;
- for (i = 1; i < argc; i++) {
- if (strcmp(argv[i], "-16") == 0) {
- display_bpp = 16;
- } else if (strcmp(argv[i], "-24") == 0) {
- display_bpp = 24;
- }
- }
+ const char *backend_opts = "X11";
- GP_SetDebugLevel(10);
+// GP_SetDebugLevel(10);
- /* Initialize SDL */
- if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) != 0) {
- fprintf(stderr, "Could not initialize SDL: %sn", SDL_GetError());
- return 1;
- }
+ backend_opts = "SDL:320x240";
- /* Create a window with a software back surface */
- display = SDL_SetVideoMode(display_w, display_h, display_bpp, SDL_SWSURFACE);
- if (display == NULL) {
- fprintf(stderr, "Could not open display: %sn", SDL_GetError());
- goto fail;
- }
+ backend = GP_BackendInit(backend_opts, "Shapetest", stderr);
- /* Set up a clipping rectangle to exercise clipping */
- SDL_Rect clip_rect = {10, 10, display_w - 10, display_h - 10};
- SDL_SetClipRect(display, &clip_rect);
+ if (backend == NULL) {
+ fprintf(stderr, "Failed to initalize backend '%s'n",
+ backend_opts);
+ return 1;
+ }
+
+ win = backend->context;
- GP_SDL_ContextFromSurface(&context, display);
+ center_x = win->w / 2;
+ center_y = win->h / 2;
/* Load colors compatible with the display */
- black = GP_ColorToContextPixel(GP_COL_BLACK, &context);
- white = GP_ColorToContextPixel(GP_COL_WHITE, &context);
- yellow = GP_ColorToContextPixel(GP_COL_YELLOW, &context);
- green = GP_ColorToContextPixel(GP_COL_GREEN, &context);
- red = GP_ColorToContextPixel(GP_COL_RED, &context);
- gray = GP_ColorToContextPixel(GP_COL_GRAY_LIGHT, &context);
- darkgray = GP_ColorToContextPixel(GP_COL_GRAY_DARK, &context);
-
- /* Set up the refresh timer */
- timer = SDL_AddTimer(60, timer_callback, NULL);
- if (timer == 0) {
- fprintf(stderr, "Could not set up timer: %sn", SDL_GetError());
- goto fail;
- }
+ black = GP_ColorToContextPixel(GP_COL_BLACK, win);
+ white = GP_ColorToContextPixel(GP_COL_WHITE, win);
+ yellow = GP_ColorToContextPixel(GP_COL_YELLOW, win);
+ green = GP_ColorToContextPixel(GP_COL_GREEN, win);
+ red = GP_ColorToContextPixel(GP_COL_RED, win);
+ gray = GP_ColorToContextPixel(GP_COL_GRAY_LIGHT, win);
+ darkgray = GP_ColorToContextPixel(GP_COL_GRAY_DARK, win);
print_instructions();
+
+ redraw_screen();
- event_loop();
- SDL_Quit();
- return 0;
-
-fail:
- SDL_Quit();
- return 1;
+ for (;;) {
+ GP_BackendWait(backend);
+ event_loop();
+ }
}
-
diff --git a/tests/SDL/Makefile b/tests/SDL/Makefile
index 436b8b3..26cfa60 100644
--- a/tests/SDL/Makefile
+++ b/tests/SDL/Makefile
@@ -7,7 +7,7 @@ LDLIBS+=-lGP -L$(TOPDIR)/build/ -lGP_SDL -lSDL
ifeq ($(HAVE_LIBSDL),yes)
CSOURCES=$(shell echo *.c)
-APPS=pixeltest fileview fonttest linetest randomshapetest shapetest sierpinsky+APPS=pixeltest fileview fonttest linetest randomshapetest sierpinsky symbolstest textaligntest trianglefps input blittest subcontext showimage aatest mixpixeltest
endif
http://repo.or.cz/w/gfxprim.git/commit/40d352f0bb0706b29175f0dde15b33183b08…
commit 40d352f0bb0706b29175f0dde15b33183b0868d3
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Tue Jul 31 22:36:30 2012 +0200
backends: SDL: Make use of GP_WARN().
diff --git a/libs/backends/GP_SDL.c b/libs/backends/GP_SDL.c
index a391b2e..2602a2d 100644
--- a/libs/backends/GP_SDL.c
+++ b/libs/backends/GP_SDL.c
@@ -101,12 +101,12 @@ int context_from_surface(GP_Context *context, SDL_Surface *surf)
{
/* sanity checks on the SDL surface */
if (surf->format->BytesPerPixel == 0) {
- GP_DEBUG(1, "ERROR: Surface->BytesPerPixel == 0");
+ GP_WARN("Surface->BytesPerPixel == 0");
return 1;
}
if (surf->format->BytesPerPixel > 4) {
- GP_DEBUG(1, "ERROR: Surface->BytesPerPixel > 4");
+ GP_WARN("Surface->BytesPerPixel > 4");
return 1;
}
@@ -182,7 +182,7 @@ GP_Backend *GP_BackendSDLInit(GP_Size w, GP_Size h, uint8_t bpp, uint8_t flags,
return &backend;
if (SDL_Init(SDL_INIT_VIDEO)) {
- GP_DEBUG(1, "ERROR: SDL_Init: %s", SDL_GetError());
+ GP_WARN("SDL_Init: %s", SDL_GetError());
return NULL;
}
@@ -198,7 +198,7 @@ GP_Backend *GP_BackendSDLInit(GP_Size w, GP_Size h, uint8_t bpp, uint8_t flags,
SDL_WM_SetCaption(caption, caption);
if (sdl_surface == NULL) {
- GP_DEBUG(1, "ERROR: SDL_SetVideoMode: %s", SDL_GetError());
+ GP_WARN("SDL_SetVideoMode: %s", SDL_GetError());
SDL_Quit();
return NULL;
}
@@ -206,7 +206,7 @@ GP_Backend *GP_BackendSDLInit(GP_Size w, GP_Size h, uint8_t bpp, uint8_t flags,
mutex = SDL_CreateMutex();
if (context_from_surface(&context, sdl_surface)) {
- GP_DEBUG(1, "ERROR: Failed to match pixel_type");
+ GP_WARN("Failed to match pixel_type");
SDL_Quit();
return NULL;
}
@@ -229,7 +229,7 @@ GP_Backend *GP_BackendSDLInit(GP_Size w __attribute__((unused)),
uint8_t flags __attribute__((unused)),
const char *caption __attribute__((unused)))
{
- GP_DEBUG(0, "FATAL: SDL support not compiled in.");
+ GP_WARN("SDL support not compiled in.");
return NULL;
}
http://repo.or.cz/w/gfxprim.git/commit/6cd5c9a311e704e0c23fff2fdbe73ff9b60a…
commit 6cd5c9a311e704e0c23fff2fdbe73ff9b60a40d4
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Tue Jul 31 22:34:34 2012 +0200
backends: SDL: Enable key repeat by default.
diff --git a/libs/backends/GP_SDL.c b/libs/backends/GP_SDL.c
index 0f8a600..a391b2e 100644
--- a/libs/backends/GP_SDL.c
+++ b/libs/backends/GP_SDL.c
@@ -210,7 +210,10 @@ GP_Backend *GP_BackendSDLInit(GP_Size w, GP_Size h, uint8_t bpp, uint8_t flags,
SDL_Quit();
return NULL;
}
-
+
+ SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY,
+ SDL_DEFAULT_REPEAT_INTERVAL);
+
backend.context = &context;
return &backend;
http://repo.or.cz/w/gfxprim.git/commit/b1270316b77d3b03e3c43db35f20e69807e3…
commit b1270316b77d3b03e3c43db35f20e69807e3f02c
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Tue Jul 31 22:33:18 2012 +0200
backends: SDL: simplify init code.
* This just shuffles some code
* No functional changes are done
diff --git a/libs/backends/GP_SDL.c b/libs/backends/GP_SDL.c
index d487dd6..0f8a600 100644
--- a/libs/backends/GP_SDL.c
+++ b/libs/backends/GP_SDL.c
@@ -177,41 +177,42 @@ static void sdl_exit(struct GP_Backend *self __attribute__((unused)))
GP_Backend *GP_BackendSDLInit(GP_Size w, GP_Size h, uint8_t bpp, uint8_t flags,
const char *caption)
{
- /* SDL not yet initalized */
- if (backend.context == NULL) {
- if (SDL_Init(SDL_INIT_VIDEO)) {
- GP_DEBUG(1, "ERROR: SDL_Init: %s", SDL_GetError());
- return NULL;
- }
+ /* SDL was already initalized */
+ if (backend.context != NULL)
+ return &backend;
- if (flags & GP_SDL_FULLSCREEN)
- sdl_flags |= SDL_FULLSCREEN;
-
- if (flags & GP_SDL_RESIZABLE)
- sdl_flags |= SDL_RESIZABLE;
+ if (SDL_Init(SDL_INIT_VIDEO)) {
+ GP_DEBUG(1, "ERROR: SDL_Init: %s", SDL_GetError());
+ return NULL;
+ }
- sdl_surface = SDL_SetVideoMode(w, h, bpp, sdl_flags);
+ if (flags & GP_SDL_FULLSCREEN)
+ sdl_flags |= SDL_FULLSCREEN;
- if (caption != NULL)
- SDL_WM_SetCaption(caption, caption);
+ if (flags & GP_SDL_RESIZABLE)
+ sdl_flags |= SDL_RESIZABLE;
- if (sdl_surface == NULL) {
- GP_DEBUG(1, "ERROR: SDL_SetVideoMode: %s", SDL_GetError());
- SDL_Quit();
- return NULL;
- }
+ sdl_surface = SDL_SetVideoMode(w, h, bpp, sdl_flags);
- mutex = SDL_CreateMutex();
+ if (caption != NULL)
+ SDL_WM_SetCaption(caption, caption);
- if (context_from_surface(&context, sdl_surface)) {
- GP_DEBUG(1, "ERROR: Failed to match pixel_type");
- SDL_Quit();
- return NULL;
- }
-
- backend.context = &context;
+ if (sdl_surface == NULL) {
+ GP_DEBUG(1, "ERROR: SDL_SetVideoMode: %s", SDL_GetError());
+ SDL_Quit();
+ return NULL;
}
+ mutex = SDL_CreateMutex();
+
+ if (context_from_surface(&context, sdl_surface)) {
+ GP_DEBUG(1, "ERROR: Failed to match pixel_type");
+ SDL_Quit();
+ return NULL;
+ }
+
+ backend.context = &context;
+
return &backend;
}
http://repo.or.cz/w/gfxprim.git/commit/aa0e161ecd926eadbfc894db7568b468c617…
commit aa0e161ecd926eadbfc894db7568b468c617b648
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Tue Jul 31 22:24:07 2012 +0200
demos: Fix the backend includes.
diff --git a/demos/c_simple/backend_example.c b/demos/c_simple/backend_example.c
index 3f5c199..063da75 100644
--- a/demos/c_simple/backend_example.c
+++ b/demos/c_simple/backend_example.c
@@ -27,7 +27,6 @@
*/
#include <GP.h>
-#include <backends/GP_Backends.h>
int main(int argc, char *argv[])
{
diff --git a/demos/c_simple/showimage.c b/demos/c_simple/showimage.c
index 9abbb6d..9b1741b 100644
--- a/demos/c_simple/showimage.c
+++ b/demos/c_simple/showimage.c
@@ -30,8 +30,7 @@
#include <errno.h>
#include <string.h>
-#include "GP.h"
-#include "backends/GP_X11.h"
+#include <GP.h>
int main(int argc, char *argv[])
{
diff --git a/demos/c_simple/v4l2_show.c b/demos/c_simple/v4l2_show.c
index 681f30a..c7f5cbb 100644
--- a/demos/c_simple/v4l2_show.c
+++ b/demos/c_simple/v4l2_show.c
@@ -30,7 +30,6 @@
#include <string.h>
#include <GP.h>
-#include <backends/GP_X11.h>
int main(int argc, char *argv[])
{
diff --git a/demos/c_simple/virtual_backend_example.c b/demos/c_simple/virtual_backend_example.c
index 523a826..448c72c 100644
--- a/demos/c_simple/virtual_backend_example.c
+++ b/demos/c_simple/virtual_backend_example.c
@@ -30,7 +30,6 @@
*/
#include <GP.h>
-#include <backends/GP_Backends.h>
int main(int argc, char *argv[])
{
http://repo.or.cz/w/gfxprim.git/commit/11febf3f119c7d728b7a14b912d0ad216c85…
commit 11febf3f119c7d728b7a14b912d0ad216c855545
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Tue Jul 31 22:12:56 2012 +0200
include: Fix GP_Backend.h vs GP_Backends.h include.
This fixes miscompilations on 64 bit hardware.
diff --git a/include/GP.h b/include/GP.h
index 4b622e6..eb1ad7c 100644
--- a/include/GP.h
+++ b/include/GP.h
@@ -36,7 +36,7 @@
#include "text/GP_Text.h"
/* backends */
-#include "backends/GP_Backend.h"
+#include "backends/GP_Backends.h"
/* input and events */
#include "input/GP_Input.h"
http://repo.or.cz/w/gfxprim.git/commit/ed4194a59b8b1d8d28d32e51d85863e2db55…
commit ed4194a59b8b1d8d28d32e51d85863e2db559c17
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Tue Jul 31 19:11:57 2012 +0200
demos: spiv: make use of the mouse wheel.
diff --git a/demos/spiv/spiv.c b/demos/spiv/spiv.c
index aad96a9..a569429 100644
--- a/demos/spiv/spiv.c
+++ b/demos/spiv/spiv.c
@@ -680,9 +680,20 @@ int main(int argc, char *argv[])
while (GP_EventGet(&ev)) {
- // GP_EventDump(&ev);
+ GP_EventDump(&ev);
switch (ev.type) {
+ case GP_EV_REL:
+ switch (ev.code) {
+ case GP_EV_REL_WHEEL:
+ if (ev.val.val > 0)
+ goto next;
+
+ if (ev.val.val < 0)
+ goto prev;
+ break;
+ }
+ break;
case GP_EV_KEY:
if (ev.code != GP_EV_KEY_DOWN)
continue;
@@ -775,6 +786,7 @@ int main(int argc, char *argv[])
params.show_progress_once = 1;
show_image(¶ms, argv[argn]);
break;
+ next:
case GP_KEY_RIGHT:
case GP_KEY_UP:
case GP_KEY_SPACE:
@@ -785,6 +797,7 @@ int main(int argc, char *argv[])
params.show_progress_once = 1;
show_image(¶ms, argv[argn]);
break;
+ prev:
case GP_KEY_BACKSPACE:
case GP_KEY_LEFT:
case GP_KEY_DOWN:
-----------------------------------------------------------------------
Summary of changes:
demos/c_simple/Makefile | 2 +-
demos/c_simple/backend_example.c | 1 -
{tests/SDL => demos/c_simple}/shapetest.c | 415 ++++++++++++-----------------
demos/c_simple/showimage.c | 3 +-
demos/c_simple/v4l2_show.c | 1 -
demos/c_simple/virtual_backend_example.c | 1 -
demos/spiv/spiv.c | 15 +-
include/GP.h | 2 +-
libs/backends/GP_SDL.c | 62 +++--
tests/SDL/Makefile | 2 +-
10 files changed, 220 insertions(+), 284 deletions(-)
rename {tests/SDL => demos/c_simple}/shapetest.c (54%)
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: 2cc8f1085bcceb34939008770bf988597a1d0d5f
by metan 31 Jul '12
by metan 31 Jul '12
31 Jul '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 2cc8f1085bcceb34939008770bf988597a1d0d5f (commit)
from d2feca863b6d28d6b7a494ce16621c434d53aa41 (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/2cc8f1085bcceb34939008770bf988597a1d…
commit 2cc8f1085bcceb34939008770bf988597a1d0d5f
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Tue Jul 31 19:02:36 2012 +0200
input: Map mouse wheel in X11 and SDL.
diff --git a/include/input/GP_Event.h b/include/input/GP_Event.h
index 962c71c..71eef60 100644
--- a/include/input/GP_Event.h
+++ b/include/input/GP_Event.h
@@ -214,7 +214,7 @@ enum GP_EventKeyValue {
enum GP_EventRelCode {
GP_EV_REL_POS = 0,
- GP_EV_REL_WHEEL = 1,
+ GP_EV_REL_WHEEL = 8,
};
enum GP_EventAbsCode {
diff --git a/libs/input/GP_InputDriverSDL.c b/libs/input/GP_InputDriverSDL.c
index b954127..207cfca 100644
--- a/libs/input/GP_InputDriverSDL.c
+++ b/libs/input/GP_InputDriverSDL.c
@@ -24,6 +24,8 @@
#ifdef HAVE_LIBSDL
+#include "core/GP_Debug.h"
+
#include "GP_Event.h"
#include "GP_InputDriverSDL.h"
@@ -108,7 +110,18 @@ void GP_InputDriverSDLEventPut(SDL_Event *ev)
case 3:
key = GP_BTN_RIGHT;
break;
+ /* Mouse wheel */
+ case 4:
+ if (ev->type == SDL_MOUSEBUTTONDOWN)
+ GP_EventPush(GP_EV_REL, GP_EV_REL_WHEEL, 1, NULL);
+ return;
+ case 5:
+ if (ev->type == SDL_MOUSEBUTTONDOWN)
+ GP_EventPush(GP_EV_REL, GP_EV_REL_WHEEL, -1, NULL);
+ return;
default:
+ GP_DEBUG(0, "Unmapped SDL Mouse button %02x",
+ ev->button.button);
return;
}
diff --git a/libs/input/GP_InputDriverX11.c b/libs/input/GP_InputDriverX11.c
index 3de0734..656c232 100644
--- a/libs/input/GP_InputDriverX11.c
+++ b/libs/input/GP_InputDriverX11.c
@@ -81,6 +81,15 @@ void GP_InputDriverX11EventPut(XEvent *ev)
case 3:
key = GP_BTN_RIGHT;
break;
+ /* Mouse wheel */
+ case 4:
+ if (press)
+ GP_EventPush(GP_EV_REL, GP_EV_REL_WHEEL, 1, NULL);
+ return;
+ case 5:
+ if (press)
+ GP_EventPush(GP_EV_REL, GP_EV_REL_WHEEL, -1, NULL);
+ return;
}
if (key == 0) {
-----------------------------------------------------------------------
Summary of changes:
include/input/GP_Event.h | 2 +-
libs/input/GP_InputDriverSDL.c | 13 +++++++++++++
libs/input/GP_InputDriverX11.c | 9 +++++++++
3 files changed, 23 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: d2feca863b6d28d6b7a494ce16621c434d53aa41
by metan 27 Jul '12
by metan 27 Jul '12
27 Jul '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 d2feca863b6d28d6b7a494ce16621c434d53aa41 (commit)
via f5eccc5a040a1f2423a399d3bc8ee0161899f2bc (commit)
via d72f3d729af93136c09cc881ede6449826c87889 (commit)
via 7de86b4f90000c336361314916ba2b1bc631bba5 (commit)
from 18ebb6623592780a57e7eea4f2e646c9a4c8dd99 (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/d2feca863b6d28d6b7a494ce16621c434d53…
commit d2feca863b6d28d6b7a494ce16621c434d53aa41
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Fri Jul 27 19:25:02 2012 +0200
demos: grinder: Fix the wrong invalid output error.
diff --git a/demos/grinder/grinder.c b/demos/grinder/grinder.c
index ec1f812..fbf0e21 100644
--- a/demos/grinder/grinder.c
+++ b/demos/grinder/grinder.c
@@ -654,6 +654,8 @@ static GP_RetCode sigma_mean(GP_Context **c, const char *params)
if (rad_x < 0 || rad_y < 0)
return GP_EINVAL;
+ (*c)->gamma = GP_GammaAcquire((*c)->pixel_type, 1.2);
+
GP_Context *ret = GP_FilterSigmaAlloc(*c, rad_x, rad_y, min, sigma, progress_callback);
if (ret == NULL)
@@ -946,9 +948,10 @@ static void check_fmt(const char *fmt)
for (i = 0; out_fmts[i] != NULL; i++)
if (!strcmp(out_fmts[i], fmt))
- break;
+ return;
fprintf(stderr, "Invalid output format '%s'n", fmt);
+ exit(1);
}
static void save_by_fmt(struct GP_Context *bitmap, const char *name, const char *fmt)
http://repo.or.cz/w/gfxprim.git/commit/f5eccc5a040a1f2423a399d3bc8ee0161899…
commit f5eccc5a040a1f2423a399d3bc8ee0161899f2bc
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Fri Jul 27 18:52:41 2012 +0200
pywrap: Update filters pywrap.i
diff --git a/pylib/gfxprim/filters/filters.i b/pylib/gfxprim/filters/filters.i
index caecd35..d2d9618 100644
--- a/pylib/gfxprim/filters/filters.i
+++ b/pylib/gfxprim/filters/filters.i
@@ -60,3 +60,7 @@
%newobject GP_FilterMedianAlloc;
%newobject GP_FilterMedianExAlloc;
%include "GP_Median.h"
+
+%newobject GP_FilterSigmaAlloc;
+%newobject GP_FilterSigmaExAlloc;
+%include "GP_Sigma.h"
http://repo.or.cz/w/gfxprim.git/commit/d72f3d729af93136c09cc881ede6449826c8…
commit d72f3d729af93136c09cc881ede6449826c87889
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Fri Jul 27 18:51:23 2012 +0200
demos: grinder: Add more filters.
diff --git a/demos/grinder/grinder.c b/demos/grinder/grinder.c
index f001ff6..ec1f812 100644
--- a/demos/grinder/grinder.c
+++ b/demos/grinder/grinder.c
@@ -47,13 +47,13 @@ static int param_err(const struct param *self, const char *val, void *priv)
{
/* invalid parameter name */
if (self == NULL) {
- fprintf(stderr, "ERROR: %s: invalid parameter '%s'n",
+ fprintf(stderr, "ERROR: %s: Unknown parameter name '%s'n",
(char*)priv, val);
return 1;
}
/* just regular error */
- fprintf(stderr, "ERROR: %s: invalid %s parameter %s = '%s'",
+ fprintf(stderr, "ERROR: %s: Invalid %s parameter value %s = '%s'",
(char *)priv, param_type_name(self->type), self->name, val);
if (self->type == PARAM_ENUM) {
@@ -626,6 +626,69 @@ static GP_RetCode median(GP_Context **c, const char *params)
return GP_ESUCCESS;
}
+/* sigma mean filter */
+
+static struct param sigma_mean_params[] = {
+ {"radius", PARAM_INT, "median radius for both x and y", NULL, NULL},
+ {"min", PARAM_INT, "minimal number of pixels to use for the mean", NULL, NULL},
+ {"sigma", PARAM_FLOAT, "sigma scaled to [0,1] interval", NULL, NULL},
+ {"radius_x", PARAM_INT, "median radius for x", NULL, NULL},
+ {"radius_y", PARAM_INT, "median radius for y", NULL, NULL},
+ {NULL, 0, NULL, NULL, NULL}
+};
+
+static GP_RetCode sigma_mean(GP_Context **c, const char *params)
+{
+ int rad = -1, rad_x, rad_y, min = 0;
+ float sigma = 0.1;
+
+ if (param_parse(params, sigma_mean_params, "sigma", param_err,
+ &rad, &min, &sigma, &rad_x, &rad_y))
+ return GP_EINVAL;
+
+ if (rad != -1) {
+ rad_x = rad;
+ rad_y = rad;
+ }
+
+ if (rad_x < 0 || rad_y < 0)
+ return GP_EINVAL;
+
+ GP_Context *ret = GP_FilterSigmaAlloc(*c, rad_x, rad_y, min, sigma, progress_callback);
+
+ if (ret == NULL)
+ return GP_ENOMEM;
+
+ GP_ContextFree(*c);
+ *c = ret;
+
+ return GP_ESUCCESS;
+}
+
+/* laplacian edge sharpening filter */
+
+static struct param sharpen_params[] = {
+ {"weight", PARAM_FLOAT, "sharpening weight from [0,1] interval", NULL, NULL},
+ {NULL, 0, NULL, NULL, NULL}
+};
+
+static GP_RetCode sharpen(GP_Context **c, const char *params)
+{
+ float weight = 0.1;
+
+ if (param_parse(params, sharpen_params, "sigma", param_err, &weight))
+ return GP_EINVAL;
+
+ GP_Context *ret = GP_FilterEdgeSharpeningAlloc(*c, weight, progress_callback);
+
+ if (ret == NULL)
+ return GP_ENOMEM;
+
+ GP_ContextFree(*c);
+ *c = ret;
+
+ return GP_ESUCCESS;
+}
/* arithmetics */
@@ -739,6 +802,8 @@ static struct filter filter_table[] = {
{"arithmetic", "arithmetic operation", arithmetic_params, arithmetic},
{"histogram", "save histogram into image file", histogram_params, histogram},
{"median", "median filter", median_params, median},
+ {"sigma", "sigma (mean) filter", sigma_mean_params, sigma_mean},
+ {"sharpen", "laplacian edge sharpening", sharpen_params, sharpen},
{"jpg", "save jpg image", save_jpg_params, save_jpg},
{"png", "save png image", save_png_params, save_png},
{NULL, NULL, NULL, NULL}
http://repo.or.cz/w/gfxprim.git/commit/7de86b4f90000c336361314916ba2b1bc631…
commit 7de86b4f90000c336361314916ba2b1bc631bba5
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Fri Jul 27 18:51:00 2012 +0200
filtes: Add Sigma Mean filter.
diff --git a/include/filters/GP_Filters.h b/include/filters/GP_Filters.h
index 451ec8c..e685ec3 100644
--- a/include/filters/GP_Filters.h
+++ b/include/filters/GP_Filters.h
@@ -68,7 +68,10 @@
/* Median filter */
#include "filters/GP_Median.h"
-/* Median filter */
+/* Weighted Median filter */
#include "filters/GP_WeightedMedian.h"
+/* Sigma Mean filter */
+#include "filters/GP_Sigma.h"
+
#endif /* GP_FILTERS_H */
diff --git a/include/filters/GP_Sigma.h b/include/filters/GP_Sigma.h
new file mode 100644
index 0000000..1660e5b
--- /dev/null
+++ b/include/filters/GP_Sigma.h
@@ -0,0 +1,77 @@
+/*****************************************************************************
+ * 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> *
+ * *
+ *****************************************************************************/
+
+ /*
+
+ Sigma Lee filter.
+
+ The xrad and yrad denotes radius the filter works on. The number of neighbor
+ pixels is exactly 2 * rad + 1 for both directions.
+
+ The sigma denotes maximal symetric difference of pixels scaled to [0,1]
+ interval. Greater sigma causes results to be closer to mean linear filter.
+
+ The min parameter defines minimial number of pixels that must be in the two
+ sigma iterval, if there is a less pixels in this interval the new pixel
+ value is computed as mean of the surrounding pixels (not including the
+ center one).
+
+ */
+
+#ifndef GP_FILTERS_SIGMA_H
+#define GP_FILTERS_SIGMA_H
+
+#include "GP_Filter.h"
+
+int GP_FilterSigmaEx(const GP_Context *src,
+ GP_Coord x_src, GP_Coord y_src,
+ GP_Size w_src, GP_Size h_src,
+ GP_Context *dst,
+ GP_Coord x_dst, GP_Coord y_dst,
+ int xrad, int yrad, int min, float sigma,
+ GP_ProgressCallback *callback);
+
+GP_Context *GP_FilterSigmaExAlloc(const GP_Context *src,
+ GP_Coord x_src, GP_Coord y_src,
+ GP_Size w_src, GP_Size h_src,
+ int xrad, int yrad, int min, float sigma,
+ GP_ProgressCallback *callback);
+
+static inline int GP_FilterSigma(const GP_Context *src,
+ GP_Context *dst,
+ int xrad, int yrad, int min, float sigma,
+ GP_ProgressCallback *callback)
+{
+ return GP_FilterSigmaEx(src, 0, 0, src->w, src->h,
+ dst, 0, 0, xrad, yrad, min, sigma, callback);
+}
+
+static inline GP_Context *GP_FilterSigmaAlloc(const GP_Context *src,
+ int xrad, int yrad,
+ int min, float sigma,
+ GP_ProgressCallback *callback)
+{
+ return GP_FilterSigmaExAlloc(src, 0, 0, src->w, src->h,
+ xrad, yrad, min, sigma, callback);
+}
+
+#endif /* GP_FILTERS_SIGMA_H */
diff --git a/libs/filters/GP_Sigma.c b/libs/filters/GP_Sigma.c
new file mode 100644
index 0000000..876e21d
--- /dev/null
+++ b/libs/filters/GP_Sigma.c
@@ -0,0 +1,249 @@
+/*****************************************************************************
+ * 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_Context.h"
+#include "core/GP_GetPutPixel.h"
+#include "core/GP_TempAlloc.h"
+#include "core/GP_Clamp.h"
+#include "core/GP_Common.h"
+
+#include "core/GP_Debug.h"
+
+#include "GP_Sigma.h"
+
+#include <string.h>
+
+static int GP_FilterSigma_Raw(const GP_Context *src,
+ GP_Coord x_src, GP_Coord y_src,
+ GP_Size w_src, GP_Size h_src,
+ GP_Context *dst,
+ GP_Coord x_dst, GP_Coord y_dst,
+ int xrad, int yrad, int min, float sigma,
+ GP_ProgressCallback *callback)
+{
+ int x, y;
+ unsigned int x1, y1;
+
+ GP_CHECK(src->pixel_type == GP_PIXEL_RGB888);
+
+ GP_DEBUG(1, "Sigma Mean filter size %ux%u xrad=%u yrad=%u sigma=%.2f",
+ w_src, h_src, xrad, yrad, sigma);
+
+ unsigned int R_sigma = 255 * sigma;
+ unsigned int G_sigma = 255 * sigma;
+ unsigned int B_sigma = 255 * sigma;
+
+ unsigned int xdiam = 2 * xrad + 1;
+ unsigned int ydiam = 2 * yrad + 1;
+
+ unsigned int w = w_src + xdiam;
+ unsigned int size = w * ydiam;
+
+ GP_TempAllocCreate(temp, 3 * size * sizeof(unsigned int));
+
+ unsigned int *R = GP_TempAllocGet(temp, size * sizeof(unsigned int));
+ unsigned int *G = GP_TempAllocGet(temp, size * sizeof(unsigned int));
+ unsigned int *B = GP_TempAllocGet(temp, size * sizeof(unsigned int));
+
+ /* prefil the sampled array */
+ for (x = 0; x < (int)w; x++) {
+ int xi = GP_CLAMP(x_src + x - xrad, 0, (int)src->w - 1);
+
+ for (y = 0; y < ydiam; y++) {
+ int yi = GP_CLAMP(y_src + y - yrad, 0, (int)src->h - 1);
+
+ GP_Pixel pix = GP_GetPixel_Raw_24BPP(src, xi, yi);
+
+ R[y * w + x] = GP_Pixel_GET_R_RGB888(pix);
+ G[y * w + x] = GP_Pixel_GET_G_RGB888(pix);
+ B[y * w + x] = GP_Pixel_GET_B_RGB888(pix);
+ }
+ }
+
+ unsigned int R_sum;
+ unsigned int G_sum;
+ unsigned int B_sum;
+
+ unsigned int R_ssum;
+ unsigned int G_ssum;
+ unsigned int B_ssum;
+
+ unsigned int R_cnt;
+ unsigned int G_cnt;
+ unsigned int B_cnt;
+
+ unsigned int cnt = xdiam * ydiam - 1;
+
+ /* center pixel ypsilon in the buffer */
+ unsigned int yc = yrad;
+ /* last sampled ypsilon in the buffer */
+ unsigned int yl = 0;
+
+ /* Apply the sigma mean filter */
+ for (y = 0; y < (int)h_src; y++) {
+ for (x = 0; x < (int)w_src; x++) {
+ /* Get center pixel */
+ unsigned int R_center = R[yc * w + x + xrad];
+ unsigned int G_center = G[yc * w + x + xrad];
+ unsigned int B_center = B[yc * w + x + xrad];
+
+ /* Reset sum counters */
+ R_sum = 0;
+ G_sum = 0;
+ B_sum = 0;
+
+ R_ssum = 0;
+ G_ssum = 0;
+ B_ssum = 0;
+
+ R_cnt = 0;
+ G_cnt = 0;
+ B_cnt = 0;
+
+ for (x1 = 0; x1 < xdiam; x1++) {
+ for (y1 = 0; y1 < ydiam; y1++) {
+ unsigned int R_cur = R[y1 * w + x + x1];
+ unsigned int G_cur = G[y1 * w + x + x1];
+ unsigned int B_cur = B[y1 * w + x + x1];
+
+ R_sum += R_cur;
+ G_sum += G_cur;
+ B_sum += B_cur;
+
+ if (abs(R_cur - R_center) < R_sigma) {
+ R_ssum += R_cur;
+ R_cnt++;
+ }
+
+ if (abs(G_cur - G_center) < G_sigma) {
+ G_ssum += G_cur;
+ G_cnt++;
+ }
+
+ if (abs(B_cur - B_center) < B_sigma) {
+ B_ssum += B_cur;
+ B_cnt++;
+ }
+ }
+ }
+
+ R_sum -= R_center;
+ G_sum -= G_center;
+ B_sum -= B_center;
+
+ unsigned int r;
+ unsigned int g;
+ unsigned int b;
+
+ if (R_cnt >= min)
+ r = R_ssum / R_cnt;
+ else
+ r = R_sum / cnt;
+
+ if (G_cnt >= min)
+ g = G_ssum / G_cnt;
+ else
+ g = G_sum / cnt;
+
+ if (B_cnt >= min)
+ b = B_ssum / B_cnt;
+ else
+ b = B_sum / cnt;
+
+ GP_PutPixel_Raw_24BPP(dst, x_dst + x, y_dst + y,
+ GP_Pixel_CREATE_RGB888(r, g, b));
+ }
+
+ int yi = GP_CLAMP(y_src + y + yrad + 1, 0, (int)src->h - 1);
+
+ for (x = 0; x < (int)w; x++) {
+ int xi = GP_CLAMP(x_src + x - xrad, 0, (int)src->w - 1);
+
+ GP_Pixel pix = GP_GetPixel_Raw_24BPP(src, xi, yi);
+
+ R[yl * w + x] = GP_Pixel_GET_R_RGB888(pix);
+ G[yl * w + x] = GP_Pixel_GET_G_RGB888(pix);
+ B[yl * w + x] = GP_Pixel_GET_B_RGB888(pix);
+
+ }
+
+ yc = (yc+1) % ydiam;
+ yl = (yl+1) % ydiam;
+
+ if (GP_ProgressCallbackReport(callback, y, h_src, w_src)) {
+ GP_TempAllocFree(temp);
+ return 1;
+ }
+ }
+
+ GP_TempAllocFree(temp);
+ GP_ProgressCallbackDone(callback);
+
+ return 0;
+}
+
+int GP_FilterSigmaEx(const GP_Context *src,
+ GP_Coord x_src, GP_Coord y_src,
+ GP_Size w_src, GP_Size h_src,
+ GP_Context *dst,
+ GP_Coord x_dst, GP_Coord y_dst,
+ int xrad, int yrad, int min, float sigma,
+ GP_ProgressCallback *callback)
+{
+ GP_CHECK(src->pixel_type == dst->pixel_type);
+
+ /* Check that destination is large enough */
+ GP_CHECK(x_dst + (GP_Coord)w_src <= (GP_Coord)dst->w);
+ GP_CHECK(y_dst + (GP_Coord)h_src <= (GP_Coord)dst->h);
+
+ GP_CHECK(xrad >= 0 && yrad >= 0);
+
+ return GP_FilterSigma_Raw(src, x_src, y_src, w_src, h_src,
+ dst, x_dst, y_dst, xrad, yrad, min, sigma,
+ callback);
+}
+
+GP_Context *GP_FilterSigmaExAlloc(const GP_Context *src,
+ GP_Coord x_src, GP_Coord y_src,
+ GP_Size w_src, GP_Size h_src,
+ int xrad, int yrad, int min, float sigma,
+ GP_ProgressCallback *callback)
+{
+ int ret;
+
+ GP_CHECK(xrad >= 0 && yrad >= 0);
+
+ GP_Context *dst = GP_ContextAlloc(w_src, h_src, src->pixel_type);
+
+ if (dst == NULL)
+ return NULL;
+
+ ret = GP_FilterSigma_Raw(src, x_src, y_src, w_src, h_src,
+ dst, 0, 0, xrad, yrad, min, sigma, callback);
+
+ if (ret) {
+ GP_ContextFree(dst);
+ return NULL;
+ }
+
+ return dst;
+}
-----------------------------------------------------------------------
Summary of changes:
demos/grinder/grinder.c | 74 ++++++++-
include/filters/GP_Filters.h | 5 +-
include/filters/{GP_Median.h => GP_Sigma.h} | 51 +++---
libs/filters/GP_Sigma.c | 249 +++++++++++++++++++++++++++
pylib/gfxprim/filters/filters.i | 4 +
5 files changed, 357 insertions(+), 26 deletions(-)
copy include/filters/{GP_Median.h => GP_Sigma.h} (58%)
create mode 100644 libs/filters/GP_Sigma.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: 18ebb6623592780a57e7eea4f2e646c9a4c8dd99
by metan 25 Jul '12
by metan 25 Jul '12
25 Jul '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 18ebb6623592780a57e7eea4f2e646c9a4c8dd99 (commit)
via 335644c07618c8cd0a56559c47be572e896c0356 (commit)
via 127badb9b2c793efcf9e67f9cf2e7ac940fdf5aa (commit)
via f4a0bc10531fb0f7ab0330bc0f9b71cb84231bcb (commit)
from f945311372cbe2b60435593398c7de612c492c75 (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/18ebb6623592780a57e7eea4f2e646c9a4c8…
commit 18ebb6623592780a57e7eea4f2e646c9a4c8dd99
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Wed Jul 25 23:13:10 2012 +0200
build: Remove unused -ldl.
diff --git a/app.mk b/app.mk
index c743505..556f9fd 100644
--- a/app.mk
+++ b/app.mk
@@ -1,4 +1,4 @@
-LDLIBS+=-lm -ldl
+LDLIBS+=-lm
ALL+=$(APPS)
CLEAN+=$(APPS)
http://repo.or.cz/w/gfxprim.git/commit/335644c07618c8cd0a56559c47be572e896c…
commit 335644c07618c8cd0a56559c47be572e896c0356
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Wed Jul 25 22:49:13 2012 +0200
demos: Fix demos LDLIBS and LDFLAGS.
diff --git a/demos/c_simple/Makefile b/demos/c_simple/Makefile
index 68cf89e..0a311ea 100644
--- a/demos/c_simple/Makefile
+++ b/demos/c_simple/Makefile
@@ -3,7 +3,8 @@ TOPDIR=../..
CSOURCES=$(shell echo *.c)
INCLUDE=
-LDLIBS+=-lGP -lGP_backends -lSDL -L$(TOPDIR)/build/
+LDFLAGS+=-L$(TOPDIR)/build/
+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 showimagediff --git a/demos/grinder/Makefile b/demos/grinder/Makefile
index 56117e6..2ea815c 100644
--- a/demos/grinder/Makefile
+++ b/demos/grinder/Makefile
@@ -2,8 +2,9 @@ TOPDIR=../..
CSOURCES=$(shell echo *.c)
-INCLUDE=core gfx SDL
-LDLIBS+=-lGP -L$(TOPDIR)/build/
+INCLUDE=core gfx
+LDFLAGS+=-L$(TOPDIR)/build/
+LDLIBS+=-lrt `$(TOPDIR)/gfxprim-config --libs --libs-backends`
APPS=grinder
diff --git a/demos/particle/Makefile b/demos/particle/Makefile
index 17cd059..6204f93 100644
--- a/demos/particle/Makefile
+++ b/demos/particle/Makefile
@@ -3,7 +3,8 @@ TOPDIR=../..
CSOURCES=$(shell echo *.c)
INCLUDE=
-LDLIBS+=-lGP -lGP_backends -lSDL -L$(TOPDIR)/build/
+LDFLAGS+=-L$(TOPDIR)/build/
+LDLIBS+=-lrt `$(TOPDIR)/gfxprim-config --libs --libs-backends`
APPS=particle_demo
diff --git a/demos/spiv/Makefile b/demos/spiv/Makefile
index 431e6ce..f533179 100644
--- a/demos/spiv/Makefile
+++ b/demos/spiv/Makefile
@@ -3,9 +3,8 @@ TOPDIR=../..
CSOURCES=$(shell echo *.c)
INCLUDE=
-CFLAGS+=-pthread
-LDFLAGS+=-pthread -lrt
-LDLIBS+=-lGP -lGP_backends -lSDL -L$(TOPDIR)/build/
+LDFLAGS+=-L$(TOPDIR)/build/
+LDLIBS+=-lrt `$(TOPDIR)/gfxprim-config --libs --libs-backends`
APPS=spiv
http://repo.or.cz/w/gfxprim.git/commit/127badb9b2c793efcf9e67f9cf2e7ac940fd…
commit 127badb9b2c793efcf9e67f9cf2e7ac940fdf5aa
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Wed Jul 25 22:38:11 2012 +0200
input: Fix Xlib less build.
diff --git a/libs/input/GP_InputDriverX11.c b/libs/input/GP_InputDriverX11.c
index bab3b2a..3de0734 100644
--- a/libs/input/GP_InputDriverX11.c
+++ b/libs/input/GP_InputDriverX11.c
@@ -24,10 +24,11 @@
#include "core/GP_Debug.h"
#include "GP_Event.h"
-#include "GP_InputDriverX11.h"
#ifdef HAVE_LIBX11
+#include "GP_InputDriverX11.h"
+
/* X11 keycodes */
static uint16_t keycode_table[] = {
GP_KEY_ESC, GP_KEY_1, GP_KEY_2, GP_KEY_3,
http://repo.or.cz/w/gfxprim.git/commit/f4a0bc10531fb0f7ab0330bc0f9b71cb8423…
commit f4a0bc10531fb0f7ab0330bc0f9b71cb84231bcb
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Wed Jul 25 22:32:31 2012 +0200
text: Fix FreeType less build.
diff --git a/libs/text/GP_FreeType.c b/libs/text/GP_FreeType.c
index b454d89..29b3977 100644
--- a/libs/text/GP_FreeType.c
+++ b/libs/text/GP_FreeType.c
@@ -20,12 +20,15 @@
* *
*****************************************************************************/
+#include "../../config.h"
+#include "core/GP_Debug.h"
+#include "text/GP_Font.h"
+
+#ifdef HAVE_FREETYPE
+
#include <ft2build.h>
#include FT_FREETYPE_H
-#include "core/GP_Debug.h"
-#include "GP_Font.h"
-
GP_FontFace *GP_FontFaceLoad(const char *path, uint32_t width, uint32_t height)
{
FT_Library library;
@@ -199,3 +202,18 @@ err1:
//TODO FREETYPE CLEANUP
return NULL;
}
+
+#else
+
+GP_FontFace *GP_FontFaceLoad(const char *path, uint32_t width, uint32_t height)
+{
+ (void)path;
+ (void)width;
+ (void)height;
+
+ GP_WARN("FreeType support not compiled in.");
+
+ return NULL;
+}
+
+#endif /* HAVE_FREETYPE */
diff --git a/libs/text/Makefile b/libs/text/Makefile
index 48c746f..ed33ab7 100644
--- a/libs/text/Makefile
+++ b/libs/text/Makefile
@@ -1,12 +1,16 @@
TOPDIR=../..
+include $(TOPDIR)/pre.mk
+include $(TOPDIR)/config.mk
+
GENSOURCES=GP_Text.gen.c
CSOURCES=$(filter-out $(wildcard *.gen.c),$(wildcard *.c))
LIBNAME=text
-include $(TOPDIR)/pre.mk
include $(TOPDIR)/gen.mk
include $(TOPDIR)/lib.mk
include $(TOPDIR)/post.mk
+ifeq ($(HAVE_FREETYPE),yes)
GP_FreeType.dep: CFLAGS+=`freetype-config --cflags`
GP_FreeType.o: CFLAGS+=`freetype-config --cflags`
+endif
-----------------------------------------------------------------------
Summary of changes:
app.mk | 2 +-
demos/c_simple/Makefile | 3 ++-
demos/grinder/Makefile | 5 +++--
demos/particle/Makefile | 3 ++-
demos/spiv/Makefile | 5 ++---
libs/input/GP_InputDriverX11.c | 3 ++-
libs/text/GP_FreeType.c | 24 +++++++++++++++++++++---
libs/text/Makefile | 6 +++++-
8 files changed, 38 insertions(+), 13 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: f945311372cbe2b60435593398c7de612c492c75
by metan 25 Jul '12
by metan 25 Jul '12
25 Jul '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 f945311372cbe2b60435593398c7de612c492c75 (commit)
via 21a67077f7274a807f784cebe146de9d9766c62b (commit)
via 23962459d2101ec72e59cc66007264cbd860a215 (commit)
from c790f88c116700214c4bd14a8d350f302ba12993 (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/f945311372cbe2b60435593398c7de612c49…
commit f945311372cbe2b60435593398c7de612c492c75
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Wed Jul 25 16:53:43 2012 +0200
filters: Add simple weighted median filter.
diff --git a/demos/c_simple/Makefile b/demos/c_simple/Makefile
index bfff75b..68cf89e 100644
--- a/demos/c_simple/Makefile
+++ b/demos/c_simple/Makefile
@@ -7,7 +7,7 @@ LDLIBS+=-lGP -lGP_backends -lSDL -L$(TOPDIR)/build/
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
+ v4l2_show v4l2_grab convolution weighted_median
v4l2_show: LDLIBS+=-lGP_grabbers
v4l2_grab: LDLIBS+=-lGP_grabbers
diff --git a/demos/c_simple/weighted_median.c b/demos/c_simple/weighted_median.c
new file mode 100644
index 0000000..fbbd8c5
--- /dev/null
+++ b/demos/c_simple/weighted_median.c
@@ -0,0 +1,159 @@
+/*****************************************************************************
+ * 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> *
+ * *
+ *****************************************************************************/
+
+ /*
+
+ Convolution filter example.
+
+ */
+
+#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 1;
+ }
+
+ 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");
+
+ unsigned int circle[] = {
+ 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0,
+ 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0,
+ 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0,
+ 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0,
+ 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0,
+ 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0,
+ 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0,
+ };
+
+ unsigned int calpen[] = {
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ };
+
+ unsigned int cross[] = {
+ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
+ 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0,
+ 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0,
+ 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0,
+ 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0,
+ 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0,
+ 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0,
+ 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0,
+ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
+ };
+
+ unsigned int crazy[] = {
+ 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0,
+ 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1,
+ 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1,
+ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
+ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
+ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
+ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
+ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
+ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
+ 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1,
+ 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1,
+ 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0,
+ };
+
+ GP_MedianWeights weights = {
+ .w = 11,
+ .h = 11,
+ .weights = circle,
+ };
+
+ priv.op = "Weighted Median";
+
+ GP_Context *res = GP_FilterWeightedMedianAlloc(img, &weights, &callback);
+
+ printf("n");
+
+ priv.op = "Saving";
+ priv.name = "out.png";
+
+ if (GP_SavePNG(res, "out.png", &callback)) {
+ fprintf(stderr, "Failed to save image: %s", strerror(errno));
+ return 1;
+ }
+
+ printf("n");
+
+ return 0;
+}
diff --git a/include/filters/GP_Filters.h b/include/filters/GP_Filters.h
index a6a6f92..451ec8c 100644
--- a/include/filters/GP_Filters.h
+++ b/include/filters/GP_Filters.h
@@ -68,4 +68,7 @@
/* Median filter */
#include "filters/GP_Median.h"
+/* Median filter */
+#include "filters/GP_WeightedMedian.h"
+
#endif /* GP_FILTERS_H */
diff --git a/include/filters/GP_WeightedMedian.h b/include/filters/GP_WeightedMedian.h
new file mode 100644
index 0000000..8219abd
--- /dev/null
+++ b/include/filters/GP_WeightedMedian.h
@@ -0,0 +1,70 @@
+/*****************************************************************************
+ * 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> *
+ * *
+ *****************************************************************************/
+
+ /*
+
+
+ */
+
+#ifndef GP_FILTERS_WEIGHTED_MEDIAN_H
+#define GP_FILTERS_WEIGHTED_MEDIAN_H
+
+#include "GP_Filter.h"
+
+typedef struct GP_MedianWeights {
+ unsigned int w;
+ unsigned int h;
+ unsigned int *weights;
+} GP_MedianWeights;
+
+int GP_FilterWeightedMedianEx(const GP_Context *src,
+ GP_Coord x_src, GP_Coord y_src,
+ GP_Size w_src, GP_Size h_src,
+ GP_Context *dst,
+ GP_Coord x_dst, GP_Coord y_dst,
+ GP_MedianWeights *weights,
+ GP_ProgressCallback *callback);
+
+GP_Context *GP_FilterWeightedMedianExAlloc(const GP_Context *src,
+ GP_Coord x_src, GP_Coord y_src,
+ GP_Size w_src, GP_Size h_src,
+ GP_MedianWeights *weights,
+ GP_ProgressCallback *callback);
+
+static inline int GP_FilterWeightedMedian(const GP_Context *src,
+ GP_Context *dst,
+ GP_MedianWeights *weights,
+ GP_ProgressCallback *callback)
+{
+ return GP_FilterWeightedMedianEx(src, 0, 0, src->w, src->h,
+ dst, 0, 0, weights, callback);
+}
+
+static inline GP_Context *GP_FilterWeightedMedianAlloc(const GP_Context *src,
+ GP_MedianWeights *weights,
+ GP_ProgressCallback *callback)
+{
+ return GP_FilterWeightedMedianExAlloc(src, 0, 0, src->w, src->h,
+ weights, callback);
+}
+
+#endif /* GP_FILTERS_MEDIAN_H */
diff --git a/libs/filters/GP_WeightedMedian.c b/libs/filters/GP_WeightedMedian.c
new file mode 100644
index 0000000..a34193d
--- /dev/null
+++ b/libs/filters/GP_WeightedMedian.c
@@ -0,0 +1,221 @@
+/*****************************************************************************
+ * 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_Context.h"
+#include "core/GP_GetPutPixel.h"
+#include "core/GP_TempAlloc.h"
+#include "core/GP_Clamp.h"
+
+#include "core/GP_Debug.h"
+
+#include "GP_WeightedMedian.h"
+
+#include <string.h>
+
+static unsigned int sum_weights(GP_MedianWeights *weights)
+{
+ unsigned int i;
+ unsigned int sum = 0;
+
+ for (i = 0; i < weights->w * weights->h; i++)
+ sum += weights->weights[i];
+
+ return sum;
+}
+
+static inline void hist_add(unsigned int *hist, unsigned int val,
+ unsigned int count)
+{
+ hist[val] += count;
+}
+
+static inline unsigned int hist_med(unsigned int *hist, unsigned int size,
+ unsigned int threshold)
+{
+ unsigned int i;
+ unsigned int acc = 0;
+
+ for (i = 0; i < size; i++) {
+ acc += hist[i];
+ if (acc >= threshold)
+ return i;
+ }
+
+ GP_BUG("Threshold not reached");
+ return 0;
+}
+
+static inline void hist_clear(unsigned int *hist, unsigned int size)
+{
+ memset(hist, 0, sizeof(unsigned int) * size);
+}
+
+static inline unsigned int get_weight(GP_MedianWeights *weights,
+ unsigned int x, unsigned int y)
+{
+ return weights->weights[y * weights->w + x];
+}
+
+static int GP_FilterWeightedMedian_Raw(const GP_Context *src,
+ GP_Coord x_src, GP_Coord y_src,
+ GP_Size w_src, GP_Size h_src,
+ GP_Context *dst,
+ GP_Coord x_dst, GP_Coord y_dst,
+ GP_MedianWeights *weights,
+ GP_ProgressCallback *callback)
+{
+ int x, y, sum = sum_weights(weights);
+ unsigned int x1, y1;
+
+ GP_CHECK(src->pixel_type == GP_PIXEL_RGB888);
+
+ GP_DEBUG(1, "Weighted Median filter size %ux%u xmed=%u ymed=%u sum=%u",
+ w_src, h_src, weights->w, weights->h, sum);
+
+ unsigned int w = w_src + weights->w;
+ unsigned int size = w * weights->h;
+
+ GP_TempAllocCreate(temp, 3 * size * sizeof(unsigned int));
+
+ unsigned int *R = GP_TempAllocGet(temp, size * sizeof(unsigned int));
+ unsigned int *G = GP_TempAllocGet(temp, size * sizeof(unsigned int));
+ unsigned int *B = GP_TempAllocGet(temp, size * sizeof(unsigned int));
+
+ /* prefil the sampled array */
+ for (x = 0; x < (int)w; x++) {
+ int xi = GP_CLAMP(x_src + x - (int)weights->w/2, 0, (int)src->w - 1);
+
+ for (y = 0; y < (int)weights->h; y++) {
+ int yi = GP_CLAMP(y_src + y - (int)weights->h, 0, (int)src->h - 1);
+
+ GP_Pixel pix = GP_GetPixel_Raw_24BPP(src, xi, yi);
+
+ R[y * w + x] = GP_Pixel_GET_R_RGB888(pix);
+ G[y * w + x] = GP_Pixel_GET_G_RGB888(pix);
+ B[y * w + x] = GP_Pixel_GET_B_RGB888(pix);
+ }
+ }
+
+ unsigned int hist_R[256];
+ unsigned int hist_G[256];
+ unsigned int hist_B[256];
+
+ hist_clear(hist_R, 256);
+ hist_clear(hist_G, 256);
+ hist_clear(hist_B, 256);
+
+ /* Apply the weighted median filter */
+ for (y = 0; y < (int)h_src; y++) {
+ for (x = 0; x < (int)w_src; x++) {
+ /* compute weighted histogram and then median */
+ for (x1 = 0; x1 < weights->w; x1++) {
+ for (y1 = 0; y1 < weights->h; y1++) {
+ unsigned int weight = get_weight(weights, x1, y1);
+ hist_add(hist_R, R[y1 * w + x + x1], weight);
+ hist_add(hist_G, G[y1 * w + x + x1], weight);
+ hist_add(hist_B, B[y1 * w + x + x1], weight);
+ }
+ }
+
+ unsigned int r = hist_med(hist_R, 256, sum/2);
+ unsigned int g = hist_med(hist_G, 256, sum/2);
+ unsigned int b = hist_med(hist_B, 256, sum/2);
+
+ GP_PutPixel_Raw_24BPP(dst, x_dst + x, y_dst + y,
+ GP_Pixel_CREATE_RGB888(r, g, b));
+
+ hist_clear(hist_R, 256);
+ hist_clear(hist_G, 256);
+ hist_clear(hist_B, 256);
+ }
+
+ for (x = 0; x < (int)w; x++) {
+ int xi = GP_CLAMP(x_src + x - (int)weights->w/2, 0, (int)src->w - 1);
+
+ for (y1 = 0; y1 < weights->h; y1++) {
+ int yi = GP_CLAMP(y_src + y + (int)y1 - (int)weights->h/2, 0, (int)src->h - 1);
+
+ GP_Pixel pix = GP_GetPixel_Raw_24BPP(src, xi, yi);
+
+ R[y1 * w + x] = GP_Pixel_GET_R_RGB888(pix);
+ G[y1 * w + x] = GP_Pixel_GET_G_RGB888(pix);
+ B[y1 * w + x] = GP_Pixel_GET_B_RGB888(pix);
+ }
+ }
+
+ if (GP_ProgressCallbackReport(callback, y, h_src, w_src)) {
+ GP_TempAllocFree(temp);
+ return 1;
+ }
+ }
+
+ GP_TempAllocFree(temp);
+ GP_ProgressCallbackDone(callback);
+
+ return 0;
+}
+
+int GP_FilterWeightedMedianEx(const GP_Context *src,
+ GP_Coord x_src, GP_Coord y_src,
+ GP_Size w_src, GP_Size h_src,
+ GP_Context *dst,
+ GP_Coord x_dst, GP_Coord y_dst,
+ GP_MedianWeights *weights,
+ GP_ProgressCallback *callback)
+{
+ GP_CHECK(src->pixel_type == dst->pixel_type);
+
+ /* Check that destination is large enough */
+ GP_CHECK(x_dst + (GP_Coord)w_src <= (GP_Coord)dst->w);
+ GP_CHECK(y_dst + (GP_Coord)h_src <= (GP_Coord)dst->h);
+
+ //GP_CHECK(xmed >= 0 && ymed >= 0);
+
+ return GP_FilterWeightedMedian_Raw(src, x_src, y_src, w_src, h_src,
+ dst, x_dst, y_dst, weights, callback);
+}
+
+GP_Context *GP_FilterWeightedMedianExAlloc(const GP_Context *src,
+ GP_Coord x_src, GP_Coord y_src,
+ GP_Size w_src, GP_Size h_src,
+ GP_MedianWeights *weights,
+ GP_ProgressCallback *callback)
+{
+ int ret;
+
+ //GP_CHECK(xmed >= 0 && ymed >= 0);
+
+ GP_Context *dst = GP_ContextAlloc(w_src, h_src, src->pixel_type);
+
+ if (dst == NULL)
+ return NULL;
+
+ ret = GP_FilterWeightedMedian_Raw(src, x_src, y_src, w_src, h_src,
+ dst, 0, 0, weights, callback);
+
+ if (ret) {
+ GP_ContextFree(dst);
+ return NULL;
+ }
+
+ return dst;
+}
http://repo.or.cz/w/gfxprim.git/commit/21a67077f7274a807f784cebe146de9d9766…
commit 21a67077f7274a807f784cebe146de9d9766c62b
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Wed Jul 25 16:41:29 2012 +0200
doc: Fix median filter docs.
diff --git a/doc/images/median/lenna_med_3_3.png b/doc/images/median/lenna_med_3_3.png
index abbc202..b1263d7 100644
Binary files a/doc/images/median/lenna_med_3_3.png and b/doc/images/median/lenna_med_3_3.png differ
diff --git a/doc/images/median/lenna_med_5_5.png b/doc/images/median/lenna_med_5_5.png
index f205d49..3a70498 100644
Binary files a/doc/images/median/lenna_med_5_5.png and b/doc/images/median/lenna_med_5_5.png differ
diff --git a/doc/images/median/lenna_med_7_7.png b/doc/images/median/lenna_med_7_7.png
index 5b11b19..15a5395 100644
Binary files a/doc/images/median/lenna_med_7_7.png and b/doc/images/median/lenna_med_7_7.png differ
diff --git a/doc/images/median/lenna_med_9_9.png b/doc/images/median/lenna_med_9_9.png
index f068dbb..94a62f1 100644
Binary files a/doc/images/median/lenna_med_9_9.png and b/doc/images/median/lenna_med_9_9.png differ
diff --git a/doc/images/median/lenna_small_med_3_3.png b/doc/images/median/lenna_small_med_3_3.png
index eef311d..c8703bc 100644
Binary files a/doc/images/median/lenna_small_med_3_3.png and b/doc/images/median/lenna_small_med_3_3.png differ
diff --git a/doc/images/median/lenna_small_med_5_5.png b/doc/images/median/lenna_small_med_5_5.png
index fca6ab4..8dbb616 100644
Binary files a/doc/images/median/lenna_small_med_5_5.png and b/doc/images/median/lenna_small_med_5_5.png differ
diff --git a/doc/images/median/lenna_small_med_7_7.png b/doc/images/median/lenna_small_med_7_7.png
index 8ba3aab..e06ddf5 100644
Binary files a/doc/images/median/lenna_small_med_7_7.png and b/doc/images/median/lenna_small_med_7_7.png differ
diff --git a/doc/images/median/lenna_small_med_9_9.png b/doc/images/median/lenna_small_med_9_9.png
index 0eec833..2fa7997 100644
Binary files a/doc/images/median/lenna_small_med_9_9.png and b/doc/images/median/lenna_small_med_9_9.png differ
http://repo.or.cz/w/gfxprim.git/commit/23962459d2101ec72e59cc66007264cbd860…
commit 23962459d2101ec72e59cc66007264cbd860a215
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Wed Jul 25 16:37:53 2012 +0200
filters: Median fix the trigger value.
diff --git a/libs/filters/GP_Median.c b/libs/filters/GP_Median.c
index 88dd92c..e6dca7d 100644
--- a/libs/filters/GP_Median.c
+++ b/libs/filters/GP_Median.c
@@ -148,7 +148,7 @@ static inline unsigned int hist8_median(struct hist8u *h, struct hist8 *row,
if (acc >= trigger) {
acc -= h->coarse[i];
-
+
/* update fine on position i */
hist8_update(h, i, row, x, xmed);
@@ -174,6 +174,7 @@ static int GP_FilterMedian_Raw(const GP_Context *src,
GP_ProgressCallback *callback)
{
int i, x, y;
+ unsigned int trigger = ((2*xmed+1)*(2*ymed+1))/2;
//TODO
GP_CHECK(src->pixel_type == GP_PIXEL_RGB888);
@@ -229,9 +230,9 @@ static int GP_FilterMedian_Raw(const GP_Context *src,
/* Generate row */
for (x = 0; x < (int)w_src; x++) {
- int r = hist8_median(XR, R, x, xmed, (xmed + ymed + 1));
- int g = hist8_median(XG, G, x, xmed, (xmed + ymed + 1));
- int b = hist8_median(XB, B, x, xmed, (xmed + ymed + 1));
+ int r = hist8_median(XR, R, x, xmed, trigger);
+ int g = hist8_median(XG, G, x, xmed, trigger);
+ int b = hist8_median(XB, B, x, xmed, trigger);
GP_PutPixel_Raw_24BPP(dst, x_dst + x, y_dst + y,
GP_Pixel_CREATE_RGB888(r, g, b));
-----------------------------------------------------------------------
Summary of changes:
demos/c_simple/Makefile | 2 +-
.../c_simple/{convolution.c => weighted_median.c} | 80 ++++++--
doc/images/median/lenna_med_3_3.png | Bin 331859 -> 337110 bytes
doc/images/median/lenna_med_5_5.png | Bin 275419 -> 289966 bytes
doc/images/median/lenna_med_7_7.png | Bin 241894 -> 259580 bytes
doc/images/median/lenna_med_9_9.png | Bin 218719 -> 239185 bytes
doc/images/median/lenna_small_med_3_3.png | Bin 89004 -> 90434 bytes
doc/images/median/lenna_small_med_5_5.png | Bin 74908 -> 78931 bytes
doc/images/median/lenna_small_med_7_7.png | Bin 66044 -> 72126 bytes
doc/images/median/lenna_small_med_9_9.png | Bin 59615 -> 67725 bytes
include/filters/GP_Filters.h | 3 +
.../filters/{GP_Median.h => GP_WeightedMedian.h} | 62 +++---
libs/filters/GP_Median.c | 9 +-
libs/filters/GP_WeightedMedian.c | 221 ++++++++++++++++++++
14 files changed, 323 insertions(+), 54 deletions(-)
copy demos/c_simple/{convolution.c => weighted_median.c} (59%)
copy include/filters/{GP_Median.h => GP_WeightedMedian.h} (50%)
create mode 100644 libs/filters/GP_WeightedMedian.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: c790f88c116700214c4bd14a8d350f302ba12993
by metan 22 Jul '12
by metan 22 Jul '12
22 Jul '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 c790f88c116700214c4bd14a8d350f302ba12993 (commit)
from 62f5963ad7a384999f52b96a18f5c253cde5290c (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/c790f88c116700214c4bd14a8d350f302ba1…
commit c790f88c116700214c4bd14a8d350f302ba12993
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Sun Jul 22 12:53:12 2012 +0200
doc: Add median filter docs.
diff --git a/doc/filters.txt b/doc/filters.txt
index 68d7180..d15b3aa 100644
--- a/doc/filters.txt
+++ b/doc/filters.txt
@@ -1068,3 +1068,60 @@ image:images/dither/lenna_RGB333_HP_small.png[
"3-bit RGB Hilbert-Peano",
link="images/dither/lenna_RGB333_HP.png"]
+Median
+~~~~~~
+
+[source,c]
+-------------------------------------------------------------------------------
+#include <filters/GP_Median.h>
+/* or */
+#include <GP.h>
+
+int GP_FilterMedianEx(const GP_Context *src,
+ GP_Coord x_src, GP_Coord y_src,
+ GP_Size w_src, GP_Size h_src,
+ GP_Context *dst,
+ GP_Coord x_dst, GP_Coord y_dst,
+ int xmed, int ymed,
+ GP_ProgressCallback *callback);
+
+GP_Context *GP_FilterMedianExAlloc(const GP_Context *src,
+ GP_Coord x_src, GP_Coord y_src,
+ GP_Size w_src, GP_Size h_src,
+ int xmed, int ymed,
+ GP_ProgressCallback *callback);
+
+int GP_FilterMedian(const GP_Context *src,
+ GP_Context *dst,
+ int xmed, int ymed,
+ GP_ProgressCallback *callback);
+
+GP_Context *GP_FilterMedianAlloc(const GP_Context *src,
+ int xmed, int ymed,
+ GP_ProgressCallback *callback);
+-------------------------------------------------------------------------------
+
+Constant time median filters (the computational complexity is independent of
+radius size).
+
+The xmed and ymed are radius values for x and y. The algorithm uses xmed
+respectively ymed pixel neighbors from each side so the result is median of
+rectangle of 2 * xmed + 1 x 2 * ymed + 1 pixels.
+
+.Original Image; Median 3x3, 5x5, 7x7, 9x9
+image:images/dither/lenna_small.png[
+ "Original Image",
+ link="images/dither/lenna.png"]
+image:images/median/lenna_small_med_3_3.png[
+ "Median 3x3",
+ link="images/median/lenna_med_3_3.png"]
+image:images/median/lenna_small_med_5_5.png[
+ "Median 5x5",
+ link="images/median/lenna_med_5_5.png"]
+image:images/median/lenna_small_med_7_7.png[
+ "Median 7x7",
+ link="images/median/lenna_med_7_7.png"]
+image:images/median/lenna_small_med_9_9.png[
+ "Median 9x9",
+ link="images/median/lenna_med_9_9.png"]
+
diff --git a/doc/images/median/lenna_med_3_3.png b/doc/images/median/lenna_med_3_3.png
new file mode 100644
index 0000000..abbc202
Binary files /dev/null and b/doc/images/median/lenna_med_3_3.png differ
diff --git a/doc/images/median/lenna_med_5_5.png b/doc/images/median/lenna_med_5_5.png
new file mode 100644
index 0000000..f205d49
Binary files /dev/null and b/doc/images/median/lenna_med_5_5.png differ
diff --git a/doc/images/median/lenna_med_7_7.png b/doc/images/median/lenna_med_7_7.png
new file mode 100644
index 0000000..5b11b19
Binary files /dev/null and b/doc/images/median/lenna_med_7_7.png differ
diff --git a/doc/images/median/lenna_med_9_9.png b/doc/images/median/lenna_med_9_9.png
new file mode 100644
index 0000000..f068dbb
Binary files /dev/null and b/doc/images/median/lenna_med_9_9.png differ
diff --git a/doc/images/median/lenna_small_med_3_3.png b/doc/images/median/lenna_small_med_3_3.png
new file mode 100644
index 0000000..eef311d
Binary files /dev/null and b/doc/images/median/lenna_small_med_3_3.png differ
diff --git a/doc/images/median/lenna_small_med_5_5.png b/doc/images/median/lenna_small_med_5_5.png
new file mode 100644
index 0000000..fca6ab4
Binary files /dev/null and b/doc/images/median/lenna_small_med_5_5.png differ
diff --git a/doc/images/median/lenna_small_med_7_7.png b/doc/images/median/lenna_small_med_7_7.png
new file mode 100644
index 0000000..8ba3aab
Binary files /dev/null and b/doc/images/median/lenna_small_med_7_7.png differ
diff --git a/doc/images/median/lenna_small_med_9_9.png b/doc/images/median/lenna_small_med_9_9.png
new file mode 100644
index 0000000..0eec833
Binary files /dev/null and b/doc/images/median/lenna_small_med_9_9.png differ
diff --git a/include/filters/GP_Median.h b/include/filters/GP_Median.h
index 891ae70..0547793 100644
--- a/include/filters/GP_Median.h
+++ b/include/filters/GP_Median.h
@@ -22,12 +22,12 @@
/*
- Constant time Median Filter (the computational complexity is independend of
+ Constant time Median Filter (the computational complexity is independent of
radius).
The xmed and ymed are radius values for x and y. The algorithm uses xmed
- respectively ymed pixel neighbours from each side so the result is median
- of rectangle of 2 * xmed + 1 x 2 * ymed + 1 pixels.
+ respectively ymed pixel neighbors from each side so the result is median of
+ rectangle of 2 * xmed + 1 x 2 * ymed + 1 pixels.
*/
-----------------------------------------------------------------------
Summary of changes:
doc/filters.txt | 57 +++++++++++++++++++++++++++++
doc/images/median/lenna_med_3_3.png | Bin 0 -> 331859 bytes
doc/images/median/lenna_med_5_5.png | Bin 0 -> 275419 bytes
doc/images/median/lenna_med_7_7.png | Bin 0 -> 241894 bytes
doc/images/median/lenna_med_9_9.png | Bin 0 -> 218719 bytes
doc/images/median/lenna_small_med_3_3.png | Bin 0 -> 89004 bytes
doc/images/median/lenna_small_med_5_5.png | Bin 0 -> 74908 bytes
doc/images/median/lenna_small_med_7_7.png | Bin 0 -> 66044 bytes
doc/images/median/lenna_small_med_9_9.png | Bin 0 -> 59615 bytes
include/filters/GP_Median.h | 6 ++--
10 files changed, 60 insertions(+), 3 deletions(-)
create mode 100644 doc/images/median/lenna_med_3_3.png
create mode 100644 doc/images/median/lenna_med_5_5.png
create mode 100644 doc/images/median/lenna_med_7_7.png
create mode 100644 doc/images/median/lenna_med_9_9.png
create mode 100644 doc/images/median/lenna_small_med_3_3.png
create mode 100644 doc/images/median/lenna_small_med_5_5.png
create mode 100644 doc/images/median/lenna_small_med_7_7.png
create mode 100644 doc/images/median/lenna_small_med_9_9.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: 62f5963ad7a384999f52b96a18f5c253cde5290c
by metan 21 Jul '12
by metan 21 Jul '12
21 Jul '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 62f5963ad7a384999f52b96a18f5c253cde5290c (commit)
from c5df8a737efa84871a78e5ee6a165cbaaa6ed90f (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/62f5963ad7a384999f52b96a18f5c253cde5…
commit 62f5963ad7a384999f52b96a18f5c253cde5290c
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Sat Jul 21 23:14:56 2012 +0200
filters: Median: clean up allocated memory correctly.
diff --git a/libs/filters/GP_Median.c b/libs/filters/GP_Median.c
index 974e140..88dd92c 100644
--- a/libs/filters/GP_Median.c
+++ b/libs/filters/GP_Median.c
@@ -175,6 +175,9 @@ static int GP_FilterMedian_Raw(const GP_Context *src,
{
int i, x, y;
+ //TODO
+ GP_CHECK(src->pixel_type == GP_PIXEL_RGB888);
+
GP_DEBUG(1, "Median filter size %ux%u xmed=%u ymed=%u",
w_src, h_src, 2 * xmed + 1, 2 * ymed + 1);
@@ -182,15 +185,19 @@ static int GP_FilterMedian_Raw(const GP_Context *src,
unsigned int size = (w_src + 2 * xmed + 1);
/* Create and initalize arrays for row of histograms */
- GP_TempAllocCreate(temp, 3 * sizeof(struct hist8) * size);
+ GP_TempAllocCreate(temp, 3 * sizeof(struct hist8) * size + 3 * sizeof(struct hist8u));
struct hist8 *R = GP_TempAllocGet(temp, sizeof(struct hist8) * size);
struct hist8 *G = GP_TempAllocGet(temp, sizeof(struct hist8) * size);
struct hist8 *B = GP_TempAllocGet(temp, sizeof(struct hist8) * size);
- memset(R, 0, sizeof(*R));
- memset(G, 0, sizeof(*G));
- memset(B, 0, sizeof(*B));
+ memset(R, 0, sizeof(*R) * size);
+ memset(G, 0, sizeof(*G) * size);
+ memset(B, 0, sizeof(*B) * size);
+
+ struct hist8u *XR = GP_TempAllocGet(temp, sizeof(struct hist8u));
+ struct hist8u *XG = GP_TempAllocGet(temp, sizeof(struct hist8u));
+ struct hist8u *XB = GP_TempAllocGet(temp, sizeof(struct hist8u));
/* Prefill row of histograms */
for (x = 0; x < (int)w_src + 2*xmed; x++) {
@@ -209,9 +216,6 @@ static int GP_FilterMedian_Raw(const GP_Context *src,
/* Apply the median filter */
for (y = 0; y < (int)h_src; y++) {
- struct hist8u xR, xG, xB;
- struct hist8u *XR = &xR, *XG = &xG, *XB = &xB;
-
memset(XR, 0, sizeof(*XR));
memset(XG, 0, sizeof(*XG));
memset(XB, 0, sizeof(*XB));
-----------------------------------------------------------------------
Summary of changes:
libs/filters/GP_Median.c | 18 +++++++++++-------
1 files changed, 11 insertions(+), 7 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: c5df8a737efa84871a78e5ee6a165cbaaa6ed90f
by metan 21 Jul '12
by metan 21 Jul '12
21 Jul '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 c5df8a737efa84871a78e5ee6a165cbaaa6ed90f (commit)
from fd39fe5069250bef3b5cea2b317b914cf702395d (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/c5df8a737efa84871a78e5ee6a165cbaaa6e…
commit c5df8a737efa84871a78e5ee6a165cbaaa6ed90f
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Sat Jul 21 22:34:10 2012 +0200
filters: Median: implemented lazy median computation
The filter runs twice as fast.
diff --git a/libs/filters/GP_Median.c b/libs/filters/GP_Median.c
index 92a4419..974e140 100644
--- a/libs/filters/GP_Median.c
+++ b/libs/filters/GP_Median.c
@@ -36,6 +36,12 @@ struct hist8 {
unsigned int fine[16][16];
};
+struct hist8u {
+ unsigned int coarse[16];
+ unsigned int fine[16][16];
+ unsigned int lx[16];
+};
+
static inline void hist8_inc(struct hist8 *h, unsigned int x, unsigned int val)
{
h[x].coarse[val>>4]++;
@@ -48,7 +54,19 @@ static inline void hist8_dec(struct hist8 *h, unsigned int x, unsigned int val)
h[x].fine[val>>4][val&0x0f]--;
}
-static inline void hist8_add(struct hist8 *out, struct hist8 *in, unsigned int x)
+static inline void hist8_add(struct hist8u *out, struct hist8 *in, unsigned int x)
+{
+ int i;
+
+ for (i = 0; i < 16; i += 4) {
+ out->coarse[i + 0] += in[x].coarse[i + 0];
+ out->coarse[i + 1] += in[x].coarse[i + 1];
+ out->coarse[i + 2] += in[x].coarse[i + 2];
+ out->coarse[i + 3] += in[x].coarse[i + 3];
+ }
+}
+
+static inline void hist8_add_fine(struct hist8u *out, struct hist8 *in, unsigned int x)
{
int i, j;
@@ -59,34 +77,68 @@ static inline void hist8_add(struct hist8 *out, struct hist8 *in, unsigned int x
out->coarse[i + 3] += in[x].coarse[i + 3];
for (j = 0; j < 16; j++) {
- out->fine[i][j] += in[x].fine[i][j];
- out->fine[i+1][j] += in[x].fine[i+1][j];
- out->fine[i+2][j] += in[x].fine[i+2][j];
- out->fine[i+3][j] += in[x].fine[i+3][j];
+ out->fine[i + 0][j] += in[x].fine[i + 0][j];
+ out->fine[i + 1][j] += in[x].fine[i + 1][j];
+ out->fine[i + 2][j] += in[x].fine[i + 2][j];
+ out->fine[i + 3][j] += in[x].fine[i + 3][j];
}
}
}
-static inline void hist8_sub(struct hist8 *out, struct hist8 *in, unsigned int x)
+static inline void hist8_sub(struct hist8u *out, struct hist8 *in, unsigned int x)
{
- int i, j;
+ int i;
for (i = 0; i < 16; i += 4) {
out->coarse[i + 0] -= in[x].coarse[i + 0];
out->coarse[i + 1] -= in[x].coarse[i + 1];
out->coarse[i + 2] -= in[x].coarse[i + 2];
out->coarse[i + 3] -= in[x].coarse[i + 3];
-
+ }
+}
+
+/*
+ * Updates only one specified fine part of the histogram.
+ *
+ * The structure hist8u remebers when was particular fine row updated so we either
+ * generate it from scatch or update depending on the number of needed operations.
+ */
+static inline void hist8_update(struct hist8u *h, unsigned int i,
+ struct hist8 *row, unsigned int x, unsigned int xmed)
+{
+ unsigned int j, k;
+ unsigned int lx = h->lx[i];
+ unsigned int dx = x - lx;
+
+ if (dx > 2*xmed) {
+ /* if last update was long ago clear it and load again */
+ for (j = 0; j < 16; j+=4) {
+ h->fine[i][j + 0] = 0;
+ h->fine[i][j + 1] = 0;
+ h->fine[i][j + 2] = 0;
+ h->fine[i][j + 3] = 0;
+ }
+
+ for (j = 0; j < 16; j++)
+ for (k = 0; k <= 2*xmed; k++)
+ h->fine[i][j + 0] += row[x + k].fine[i][j + 0];
+ } else {
+ /* update only missing bits */
for (j = 0; j < 16; j++) {
- out->fine[i][j] -= in[x].fine[i][j];
- out->fine[i+1][j] -= in[x].fine[i+1][j];
- out->fine[i+2][j] -= in[x].fine[i+2][j];
- out->fine[i+3][j] -= in[x].fine[i+3][j];
+ for (k = 0; k < dx; k++) {
+ h->fine[i][j] -= row[lx + k].fine[i][j];
+ h->fine[i][j] += row[lx + k + 2*xmed + 1].fine[i][j];
+ }
}
+
}
+
+ h->lx[i] = x;
}
-static inline unsigned int hist8_median(struct hist8 *h, struct hist8 *row, unsigned int x, unsigned int trigger)
+
+static inline unsigned int hist8_median(struct hist8u *h, struct hist8 *row,
+ unsigned int x, int xmed, unsigned int trigger)
{
unsigned int i, j;
unsigned int acc = 0;
@@ -96,7 +148,10 @@ static inline unsigned int hist8_median(struct hist8 *h, struct hist8 *row, unsi
if (acc >= trigger) {
acc -= h->coarse[i];
-
+
+ /* update fine on position i */
+ hist8_update(h, i, row, x, xmed);
+
for (j = 0; j < 16; j++) {
acc += h->fine[i][j];
@@ -154,8 +209,8 @@ static int GP_FilterMedian_Raw(const GP_Context *src,
/* Apply the median filter */
for (y = 0; y < (int)h_src; y++) {
- struct hist8 xR, xG, xB;
- struct hist8 *XR = &xR, *XG = &xG, *XB = &xB;
+ struct hist8u xR, xG, xB;
+ struct hist8u *XR = &xR, *XG = &xG, *XB = &xB;
memset(XR, 0, sizeof(*XR));
memset(XG, 0, sizeof(*XG));
@@ -163,16 +218,16 @@ static int GP_FilterMedian_Raw(const GP_Context *src,
/* Compute first histogram */
for (i = 0; i <= 2*xmed; i++) {
- hist8_add(XR, R, i);
- hist8_add(XG, G, i);
- hist8_add(XB, B, i);
+ hist8_add_fine(XR, R, i);
+ hist8_add_fine(XG, G, i);
+ hist8_add_fine(XB, B, i);
}
/* Generate row */
for (x = 0; x < (int)w_src; x++) {
- int r = hist8_median(XR, R, x, (xmed + ymed + 1));
- int g = hist8_median(XG, G, x, (xmed + ymed + 1));
- int b = hist8_median(XB, B, x, (xmed + ymed + 1));
+ int r = hist8_median(XR, R, x, xmed, (xmed + ymed + 1));
+ int g = hist8_median(XG, G, x, xmed, (xmed + ymed + 1));
+ int b = hist8_median(XB, B, x, xmed, (xmed + ymed + 1));
GP_PutPixel_Raw_24BPP(dst, x_dst + x, y_dst + y,
GP_Pixel_CREATE_RGB888(r, g, b));
-----------------------------------------------------------------------
Summary of changes:
libs/filters/GP_Median.c | 99 +++++++++++++++++++++++++++++++++++----------
1 files changed, 77 insertions(+), 22 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: fd39fe5069250bef3b5cea2b317b914cf702395d
by metan 21 Jul '12
by metan 21 Jul '12
21 Jul '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 fd39fe5069250bef3b5cea2b317b914cf702395d (commit)
from eaa73f8e7eea739d3d14c830622c455acd6717c6 (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/fd39fe5069250bef3b5cea2b317b914cf702…
commit fd39fe5069250bef3b5cea2b317b914cf702395d
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Sat Jul 21 21:30:54 2012 +0200
filters: Rewrite Median filter, prepare for speedup.
diff --git a/libs/filters/GP_Median.c b/libs/filters/GP_Median.c
index db58806..92a4419 100644
--- a/libs/filters/GP_Median.c
+++ b/libs/filters/GP_Median.c
@@ -31,47 +31,81 @@
#include <string.h>
-static inline void hist_inc(unsigned int *h, unsigned int x, unsigned int val)
+struct hist8 {
+ unsigned int coarse[16];
+ unsigned int fine[16][16];
+};
+
+static inline void hist8_inc(struct hist8 *h, unsigned int x, unsigned int val)
{
- h[256 * x + val]++;
+ h[x].coarse[val>>4]++;
+ h[x].fine[val>>4][val&0x0f]++;
}
-static inline void hist_dec(unsigned int *h, unsigned int x, unsigned int val)
+static inline void hist8_dec(struct hist8 *h, unsigned int x, unsigned int val)
{
- h[256 * x + val]--;
+ h[x].coarse[val>>4]--;
+ h[x].fine[val>>4][val&0x0f]--;
}
-static inline void hist_sub(unsigned int *a, unsigned int *b, unsigned int x)
+static inline void hist8_add(struct hist8 *out, struct hist8 *in, unsigned int x)
{
- int j;
+ int i, j;
+
+ for (i = 0; i < 16; i += 4) {
+ out->coarse[i + 0] += in[x].coarse[i + 0];
+ out->coarse[i + 1] += in[x].coarse[i + 1];
+ out->coarse[i + 2] += in[x].coarse[i + 2];
+ out->coarse[i + 3] += in[x].coarse[i + 3];
- for (j = 0; j < 256; j++)
- a[j] -= b[256 * x + j];
+ for (j = 0; j < 16; j++) {
+ out->fine[i][j] += in[x].fine[i][j];
+ out->fine[i+1][j] += in[x].fine[i+1][j];
+ out->fine[i+2][j] += in[x].fine[i+2][j];
+ out->fine[i+3][j] += in[x].fine[i+3][j];
+ }
+ }
}
-static inline void hist_add(unsigned int *a, unsigned int *b, unsigned int x)
+static inline void hist8_sub(struct hist8 *out, struct hist8 *in, unsigned int x)
{
- int j;
-
- for (j = 0; j < 256; j++)
- a[j] += b[256 * x + j];
-}
+ int i, j;
-#define HIST_INC hist_inc
-#define HIST_DEC hist_dec
+ for (i = 0; i < 16; i += 4) {
+ out->coarse[i + 0] -= in[x].coarse[i + 0];
+ out->coarse[i + 1] -= in[x].coarse[i + 1];
+ out->coarse[i + 2] -= in[x].coarse[i + 2];
+ out->coarse[i + 3] -= in[x].coarse[i + 3];
+
+ for (j = 0; j < 16; j++) {
+ out->fine[i][j] -= in[x].fine[i][j];
+ out->fine[i+1][j] -= in[x].fine[i+1][j];
+ out->fine[i+2][j] -= in[x].fine[i+2][j];
+ out->fine[i+3][j] -= in[x].fine[i+3][j];
+ }
+ }
+}
-static inline unsigned int hist_median(unsigned int *hist, unsigned int len,
- unsigned int trigger)
+static inline unsigned int hist8_median(struct hist8 *h, struct hist8 *row, unsigned int x, unsigned int trigger)
{
- unsigned int i;
+ unsigned int i, j;
unsigned int acc = 0;
- for (i = 0; i < len; i++) {
- acc += hist[i];
- if (acc >= trigger)
- return i;
+ for (i = 0; i < 16; i++) {
+ acc += h->coarse[i];
+
+ if (acc >= trigger) {
+ acc -= h->coarse[i];
+
+ for (j = 0; j < 16; j++) {
+ acc += h->fine[i][j];
+
+ if (acc >= trigger)
+ return (i<<4) | j;
+ }
+ }
}
-
+
GP_BUG("Trigger not reached");
return 0;
}
@@ -90,18 +124,18 @@ static int GP_FilterMedian_Raw(const GP_Context *src,
w_src, h_src, 2 * xmed + 1, 2 * ymed + 1);
/* The buffer is w + 2*xmed + 1 size because we read the last value but we don't use it */
- unsigned int size = (w_src + 2 * xmed + 1) * sizeof(int);
+ unsigned int size = (w_src + 2 * xmed + 1);
/* Create and initalize arrays for row of histograms */
- GP_TempAllocCreate(temp, 3 * 256 * size);
+ GP_TempAllocCreate(temp, 3 * sizeof(struct hist8) * size);
- unsigned int *R = GP_TempAllocGet(temp, 256 * size);
- unsigned int *G = GP_TempAllocGet(temp, 256 * size);
- unsigned int *B = GP_TempAllocGet(temp, 256 * size);
+ struct hist8 *R = GP_TempAllocGet(temp, sizeof(struct hist8) * size);
+ struct hist8 *G = GP_TempAllocGet(temp, sizeof(struct hist8) * size);
+ struct hist8 *B = GP_TempAllocGet(temp, sizeof(struct hist8) * size);
- memset(R, 0, 256 * size);
- memset(G, 0, 256 * size);
- memset(B, 0, 256 * size);
+ memset(R, 0, sizeof(*R));
+ memset(G, 0, sizeof(*G));
+ memset(B, 0, sizeof(*B));
/* Prefill row of histograms */
for (x = 0; x < (int)w_src + 2*xmed; x++) {
@@ -112,44 +146,45 @@ static int GP_FilterMedian_Raw(const GP_Context *src,
GP_Pixel pix = GP_GetPixel_Raw_24BPP(src, xi, yi);
- HIST_INC(R, x, GP_Pixel_GET_R_RGB888(pix));
- HIST_INC(G, x, GP_Pixel_GET_G_RGB888(pix));
- HIST_INC(B, x, GP_Pixel_GET_B_RGB888(pix));
+ hist8_inc(R, x, GP_Pixel_GET_R_RGB888(pix));
+ hist8_inc(G, x, GP_Pixel_GET_G_RGB888(pix));
+ hist8_inc(B, x, GP_Pixel_GET_B_RGB888(pix));
}
}
/* Apply the median filter */
for (y = 0; y < (int)h_src; y++) {
- unsigned int XR[256], XG[256], XB[256];
-
- memset(XR, 0, sizeof(XR));
- memset(XG, 0, sizeof(XG));
- memset(XB, 0, sizeof(XB));
+ struct hist8 xR, xG, xB;
+ struct hist8 *XR = &xR, *XG = &xG, *XB = &xB;
+ memset(XR, 0, sizeof(*XR));
+ memset(XG, 0, sizeof(*XG));
+ memset(XB, 0, sizeof(*XB));
+
/* Compute first histogram */
for (i = 0; i <= 2*xmed; i++) {
- hist_add(XR, R, i);
- hist_add(XG, G, i);
- hist_add(XB, B, i);
+ hist8_add(XR, R, i);
+ hist8_add(XG, G, i);
+ hist8_add(XB, B, i);
}
-
+
/* Generate row */
for (x = 0; x < (int)w_src; x++) {
- int r = hist_median(XR, 256, (xmed + ymed + 1));
- int g = hist_median(XG, 256, (xmed + ymed + 1));
- int b = hist_median(XB, 256, (xmed + ymed + 1));
+ int r = hist8_median(XR, R, x, (xmed + ymed + 1));
+ int g = hist8_median(XG, G, x, (xmed + ymed + 1));
+ int b = hist8_median(XB, B, x, (xmed + ymed + 1));
GP_PutPixel_Raw_24BPP(dst, x_dst + x, y_dst + y,
GP_Pixel_CREATE_RGB888(r, g, b));
/* Recompute histograms */
- hist_sub(XR, R, x);
- hist_sub(XG, G, x);
- hist_sub(XB, B, x);
+ hist8_sub(XR, R, x);
+ hist8_sub(XG, G, x);
+ hist8_sub(XB, B, x);
- hist_add(XR, R, (x + 2 * xmed + 1));
- hist_add(XG, G, (x + 2 * xmed + 1));
- hist_add(XB, B, (x + 2 * xmed + 1));
+ hist8_add(XR, R, (x + 2 * xmed + 1));
+ hist8_add(XG, G, (x + 2 * xmed + 1));
+ hist8_add(XB, B, (x + 2 * xmed + 1));
}
/* Recompute histograms, remove y - ymed pixel add y + ymed + 1 */
@@ -159,17 +194,17 @@ static int GP_FilterMedian_Raw(const GP_Context *src,
GP_Pixel pix = GP_GetPixel_Raw_24BPP(src, xi, yi);
- HIST_DEC(R, x, GP_Pixel_GET_R_RGB888(pix));
- HIST_DEC(G, x, GP_Pixel_GET_G_RGB888(pix));
- HIST_DEC(B, x, GP_Pixel_GET_B_RGB888(pix));
+ hist8_dec(R, x, GP_Pixel_GET_R_RGB888(pix));
+ hist8_dec(G, x, GP_Pixel_GET_G_RGB888(pix));
+ hist8_dec(B, x, GP_Pixel_GET_B_RGB888(pix));
yi = GP_MIN(y_src + y + ymed + 1, (int)src->h - 1);
pix = GP_GetPixel_Raw_24BPP(src, xi, yi);
- HIST_INC(R, x, GP_Pixel_GET_R_RGB888(pix));
- HIST_INC(G, x, GP_Pixel_GET_G_RGB888(pix));
- HIST_INC(B, x, GP_Pixel_GET_B_RGB888(pix));
+ hist8_inc(R, x, GP_Pixel_GET_R_RGB888(pix));
+ hist8_inc(G, x, GP_Pixel_GET_G_RGB888(pix));
+ hist8_inc(B, x, GP_Pixel_GET_B_RGB888(pix));
}
if (GP_ProgressCallbackReport(callback, y, h_src, w_src)) {
-----------------------------------------------------------------------
Summary of changes:
libs/filters/GP_Median.c | 153 ++++++++++++++++++++++++++++------------------
1 files changed, 94 insertions(+), 59 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