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 c7be9d64e221992b3205a65b1007653b408ba574 (commit) via 85ff7a0aeccbddfdd69611f6dd3128162aff6996 (commit) via e086670095af025857270b996b7a5d2deec42820 (commit) via 7dc5026aa07022e0b17da3b5fd173eaa900ec3b2 (commit) via dff4c0ec8bdcc90fab43fe7cc627d8d164cde641 (commit) from faaba1897920ea54344ca36ec8c6633d0a6ebf1d (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/c7be9d64e221992b3205a65b1007653b408ba...
commit c7be9d64e221992b3205a65b1007653b408ba574 Author: Cyril Hrubis metan@ucw.cz Date: Thu Aug 2 16:05:56 2012 +0200
filters: Add gaussian additive noise filter.
diff --git a/demos/grinder/grinder.c b/demos/grinder/grinder.c index 648e950..5434e65 100644 --- a/demos/grinder/grinder.c +++ b/demos/grinder/grinder.c @@ -692,6 +692,27 @@ static int sharpen(GP_Context **c, const char *params) return 0; }
+/* gaussian additive noise filter */ + +static struct param gauss_noise_params[] = { + {"sigma", PARAM_FLOAT, "sigma: amount of noise between [0,1]", NULL, NULL}, + {"mu", PARAM_FLOAT, "mu: offset of noise between [0,1]", NULL, NULL}, + {NULL, 0, NULL, NULL, NULL} +}; + +static int gauss_noise(GP_Context **c, const char *params) +{ + float sigma = 0.1; + float mu = 0; + + if (param_parse(params, gauss_noise_params, "gaussian noise", param_err, &sigma, &mu)) + return EINVAL; + + GP_FilterGaussianNoiseAdd(*c, *c, sigma, mu, progress_callback); + + return 0; +} + /* arithmetics */
static const char *arithmetic_ops[] = { @@ -806,6 +827,7 @@ static struct filter filter_table[] = { {"median", "median filter", median_params, median}, {"sigma", "sigma (mean) filter", sigma_mean_params, sigma_mean}, {"sharpen", "laplacian edge sharpening", sharpen_params, sharpen}, + {"gauss_noise", "additive gaussian (normaly distributed) noise", gauss_noise_params, gauss_noise}, {"jpg", "save jpg image", save_jpg_params, save_jpg}, {"png", "save png image", save_png_params, save_png}, {NULL, NULL, NULL, NULL} diff --git a/include/filters/GP_Filters.h b/include/filters/GP_Filters.h index e685ec3..cd06035 100644 --- a/include/filters/GP_Filters.h +++ b/include/filters/GP_Filters.h @@ -74,4 +74,7 @@ /* Sigma Mean filter */ #include "filters/GP_Sigma.h"
+/* Gaussian noise filter */ +#include "filters/GP_GaussianNoise.h" + #endif /* GP_FILTERS_H */ diff --git a/include/filters/GP_GaussianNoise.h b/include/filters/GP_GaussianNoise.h new file mode 100644 index 0000000..59d9d35 --- /dev/null +++ b/include/filters/GP_GaussianNoise.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@ucw.cz * + * * + *****************************************************************************/ + + /* + + Additive Gaussian noise filters. + + The sigma and mu parameters define the noise parameters. The sigma defines + amount of randomness, the mu defines offset. Both are defined as a ratio of + the particular channel size. + + */ + +#ifndef GP_FILTERS_GAUSSIAN_NOISE_H +#define GP_FILTERS_GAUSSIAN_NOISE_H + +#include "GP_Filter.h" + +int GP_FilterGaussianNoiseAddEx(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, + float sigma, float mu, + GP_ProgressCallback *callback); + +GP_Context *GP_FilterGaussianNoiseAddExAlloc(const GP_Context *src, + GP_Coord x_src, GP_Coord y_src, + GP_Size w_src, GP_Size h_src, + float sigma, float mu, + GP_ProgressCallback *callback); + +static inline int GP_FilterGaussianNoiseAdd(const GP_Context *src, + GP_Context *dst, + float sigma, float mu, + GP_ProgressCallback *callback) +{ + return GP_FilterGaussianNoiseAddEx(src, 0, 0, src->w, src->h, + dst, 0, 0, sigma, mu, callback); +} + +static inline GP_Context * +GP_FilterGaussianNoiseAddAlloc(const GP_Context *src, + float sigma, float mu, + GP_ProgressCallback *callback) +{ + return GP_FilterGaussianNoiseAddExAlloc(src, 0, 0, src->w, src->h, + sigma, mu, callback); +} + +#endif /* GP_FILTERS_GAUSSIAN_NOISE_H */ diff --git a/include/filters/GP_Filters.h b/include/filters/GP_Rand.h similarity index 55% copy from include/filters/GP_Filters.h copy to include/filters/GP_Rand.h index e685ec3..0fc7e18 100644 --- a/include/filters/GP_Filters.h +++ b/include/filters/GP_Rand.h @@ -16,62 +16,25 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, * * Boston, MA 02110-1301 USA * * * - * Copyright (C) 2009-2010 Jiri "BlueBear" Dluhos * - * jiri.bluebear.dluhos@gmail.com * - * * - * Copyright (C) 2009-2011 Cyril Hrubis metan@ucw.cz * + * Copyright (C) 2009-2012 Cyril Hrubis metan@ucw.cz * * * *****************************************************************************/
/*
- GP_Context filters. + Functions to generate random numbers.
*/
-#ifndef GP_FILTERS_H -#define GP_FILTERS_H - -/* Filter per channel parameter passing interface */ -#include "filters/GP_FilterParam.h" - -/* Point filters, brightness, contrast ... */ -#include "filters/GP_Point.h" - -/* Addition, difference, min, max ... */ -#include "filters/GP_Arithmetic.h" - -/* Histograms, ... */ -#include "filters/GP_Stats.h" - -/* Image rotations (90 180 270 grads) and mirroring */ -#include "filters/GP_Rotate.h" - -/* Linear convolution Raw API */ -#include "filters/GP_Linear.h" - -/* Convolution filters */ -#include "filters/GP_Convolution.h" +#ifndef FILTERS_GP_RAND_H +#define FILTERS_GP_RAND_H
-/* Blur filters */ -#include "filters/GP_Blur.h" - -/* Image scaling (resampling) */ -#include "filters/GP_Resize.h" - -/* Bitmap dithering */ -#include "filters/GP_Dither.h" - -/* Laplace based filters */ -#include "filters/GP_Laplace.h" - -/* Median filter */ -#include "filters/GP_Median.h" - -/* Weighted Median filter */ -#include "filters/GP_WeightedMedian.h" - -/* Sigma Mean filter */ -#include "filters/GP_Sigma.h" +/* + * Fills the array with size integers with Normal (Gaussian) distribution + * defined by sigma and mu parameters. + * + * The size _MUST_ be odd. + */ +void GP_NormInt(int *arr, unsigned int size, int sigma, int mu);
-#endif /* GP_FILTERS_H */ +#endif /* FILTERS_GP_RAND_H */ diff --git a/libs/filters/GP_GaussianNoise.gen.c.t b/libs/filters/GP_GaussianNoise.gen.c.t new file mode 100644 index 0000000..1d8c8a6 --- /dev/null +++ b/libs/filters/GP_GaussianNoise.gen.c.t @@ -0,0 +1,149 @@ +%% extends "filter.c.t" + +{% block descr %}Gaussian Noise{% endblock %} + +%% block body + +#include "core/GP_Context.h" +#include "core/GP_GetPutPixel.h" +#include "core/GP_TempAlloc.h" +//#include "core/GP_Gamma.h" +#include "core/GP_Clamp.h" +#include "core/GP_Debug.h" + +#include "GP_Rand.h" +#include "GP_GaussianNoise.h" + +%% for pt in pixeltypes +%% if not pt.is_unknown() and not pt.is_palette() +static int GP_FilterGaussianNoiseAdd_{{ pt.name }}_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, + float sigma, float mu, + GP_ProgressCallback *callback) +{ + GP_DEBUG(1, "Additive Gaussian noise filter %ux%u sigma=%f mu=%f", + w_src, h_src, sigma, mu); + + %% for c in pt.chanslist + int sigma_{{ c[0] }} = {{ 2 ** c[2] - 1 }} * sigma; + int mu_{{ c[0] }} = {{ 2 ** c[2] - 1 }} * mu; + %% endfor + + unsigned int size = w_src + w_src%2; + + /* Create temporary buffers */ + GP_TempAllocCreate(temp, sizeof(int) * size * {{ len(pt.chanslist) }}); + + %% for c in pt.chanslist + int *{{ c[0] }} = GP_TempAllocGet(temp, size * sizeof(int)); + %% endfor + + /* Apply the additive noise filter */ + unsigned int x, y; + + for (y = 0; y < h_src; y++) { + %% for c in pt.chanslist + GP_NormInt({{ c[0] }}, size, sigma_{{ c[0] }}, mu_{{ c[0] }}); + %% endfor + + for (x = 0; x < w_src; x++) { + GP_Pixel pix = GP_GetPixel_Raw_{{ pt.pixelsize.suffix }}(src, x + x_src, y + y_src); + + %% for c in pt.chanslist + {{ c[0] }}[x] += GP_Pixel_GET_{{ c[0] }}_{{ pt.name }}(pix); + {{ c[0] }}[x] = GP_CLAMP({{ c[0] }}[x], 0, {{ 2 ** c[2] - 1 }}); + %% endfor + + pix = GP_Pixel_CREATE_{{ pt.name }}({{ expand_chanslist(pt, "", "[x]") }}); + GP_PutPixel_Raw_{{ pt.pixelsize.suffix }}(dst, x + x_dst, y + y_dst, pix); + } + + if (GP_ProgressCallbackReport(callback, y, h_src, w_src)) { + GP_TempAllocFree(temp); + return 1; + } + } + + GP_TempAllocFree(temp); + GP_ProgressCallbackDone(callback); + + return 0; +} + +%% endif +%% endfor + +int GP_FilterGaussianNoiseAdd_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, + float sigma, float mu, + GP_ProgressCallback *callback) +{ + switch (src->pixel_type) { + %% for pt in pixeltypes + %% if not pt.is_unknown() and not pt.is_palette() + case GP_PIXEL_{{ pt.name }}: + return GP_FilterGaussianNoiseAdd_{{ pt.name }}_Raw(src, x_src, + y_src, w_src, h_src, dst, x_dst, y_dst, + sigma, mu, callback); + break; + %% endif + %% endfor + default: + return -1; + } +} + +int GP_FilterGaussianNoiseAddEx(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, + float sigma, float mu, + 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); + + /* Source is large enough */ + GP_CHECK(x_src + w_src <= src->w); + GP_CHECK(y_src + h_src <= src->h); + + return GP_FilterGaussianNoiseAdd_Raw(src, x_src, y_src, w_src, h_src, + dst, x_dst, y_dst, + sigma, mu, callback); +} + +GP_Context *GP_FilterGaussianNoiseAddExAlloc(const GP_Context *src, + GP_Coord x_src, GP_Coord y_src, + GP_Size w_src, GP_Size h_src, + float sigma, float mu, + GP_ProgressCallback *callback) +{ + int ret; + + GP_Context *dst = GP_ContextAlloc(w_src, h_src, src->pixel_type); + + if (dst == NULL) + return NULL; + + ret = GP_FilterGaussianNoiseAdd_Raw(src, x_src, y_src, w_src, h_src, + dst, 0, 0, sigma, mu, callback); + + if (ret) { + GP_ContextFree(dst); + return NULL; + } + + return dst; +} + +%% endblock body diff --git a/include/filters/GP_Filters.h b/libs/filters/GP_Rand.c similarity index 55% copy from include/filters/GP_Filters.h copy to libs/filters/GP_Rand.c index e685ec3..f571585 100644 --- a/include/filters/GP_Filters.h +++ b/libs/filters/GP_Rand.c @@ -16,62 +16,37 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, * * Boston, MA 02110-1301 USA * * * - * Copyright (C) 2009-2010 Jiri "BlueBear" Dluhos * - * jiri.bluebear.dluhos@gmail.com * - * * - * Copyright (C) 2009-2011 Cyril Hrubis metan@ucw.cz * + * Copyright (C) 2009-2012 Cyril Hrubis metan@ucw.cz * * * *****************************************************************************/
-/* - - GP_Context filters. - - */ - -#ifndef GP_FILTERS_H -#define GP_FILTERS_H - -/* Filter per channel parameter passing interface */ -#include "filters/GP_FilterParam.h" - -/* Point filters, brightness, contrast ... */ -#include "filters/GP_Point.h" - -/* Addition, difference, min, max ... */ -#include "filters/GP_Arithmetic.h" - -/* Histograms, ... */ -#include "filters/GP_Stats.h" - -/* Image rotations (90 180 270 grads) and mirroring */ -#include "filters/GP_Rotate.h" - -/* Linear convolution Raw API */ -#include "filters/GP_Linear.h" +#include <math.h>
-/* Convolution filters */ -#include "filters/GP_Convolution.h" +#include "core/GP_Common.h"
-/* Blur filters */ -#include "filters/GP_Blur.h" +#include "GP_Rand.h"
-/* Image scaling (resampling) */ -#include "filters/GP_Resize.h" +void GP_NormInt(int *arr, unsigned int size, int sigma, int mu) +{ + unsigned int i = 0; + float a, b, rsq;
-/* Bitmap dithering */ -#include "filters/GP_Dither.h" + GP_ASSERT(size%2 == 0);
-/* Laplace based filters */ -#include "filters/GP_Laplace.h" + while (i < size) { + /* Sample two point inside of the unit circle */ + do { + a = (float)random() / (RAND_MAX/2) - 1; + b = (float)random() / (RAND_MAX/2) - 1;
-/* Median filter */ -#include "filters/GP_Median.h" + rsq = a * a + b * b;
-/* Weighted Median filter */ -#include "filters/GP_WeightedMedian.h" + } while (rsq >= 1 || rsq == 0);
-/* Sigma Mean filter */ -#include "filters/GP_Sigma.h" + /* Polar form of the Box-Muller transformation */ + float mul = sqrtf(-2.0 * logf(rsq)/rsq);
-#endif /* GP_FILTERS_H */ + arr[i++] = mu + sigma * a * mul; + arr[i++] = mu + sigma * b * mul; + } +} diff --git a/libs/filters/Makefile b/libs/filters/Makefile index c9661e6..cedc55a 100644 --- a/libs/filters/Makefile +++ b/libs/filters/Makefile @@ -3,7 +3,7 @@ TOPDIR=../.. STATS_FILTERS=GP_Histogram.gen.c
POINT_FILTERS=GP_Contrast.gen.c GP_Brightness.gen.c GP_Invert.gen.c- GP_Point.gen.c GP_Noise.gen.c + GP_Point.gen.c GP_Noise.gen.c GP_GaussianNoise.gen.c
ARITHMETIC_FILTERS=GP_Difference.gen.c GP_Addition.gen.c GP_Min.gen.c GP_Max.gen.c GP_Multiply.gen.c
http://repo.or.cz/w/gfxprim.git/commit/85ff7a0aeccbddfdd69611f6dd3128162aff6...
commit 85ff7a0aeccbddfdd69611f6dd3128162aff6996 Author: Cyril Hrubis metan@ucw.cz Date: Thu Aug 2 14:47:34 2012 +0200
demos: c_simple: Ported input test from SDL.
diff --git a/demos/c_simple/Makefile b/demos/c_simple/Makefile index ec6ac66..99af986 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 koch + v4l2_show v4l2_grab convolution weighted_median shapetest koch input
v4l2_show: LDLIBS+=-lGP_grabbers v4l2_grab: LDLIBS+=-lGP_grabbers diff --git a/tests/SDL/input.c b/demos/c_simple/input.c similarity index 54% rename from tests/SDL/input.c rename to demos/c_simple/input.c index c2b1cde..6a083e2 100644 --- a/tests/SDL/input.c +++ b/demos/c_simple/input.c @@ -19,32 +19,20 @@ * Copyright (C) 2009-2010 Jiri "BlueBear" Dluhos * * jiri.bluebear.dluhos@gmail.com * * * - * Copyright (C) 2009-2011 Cyril Hrubis metan@ucw.cz * + * Copyright (C) 2009-2012 Cyril Hrubis metan@ucw.cz * * * *****************************************************************************/
#include <stdio.h> #include <stdlib.h> -#include <SDL/SDL.h> +#include <unistd.h>
#include "GP.h" -#include "GP_SDL.h"
-SDL_Surface *display = NULL; -GP_Context context; +static GP_Context *win; +static GP_Backend *backend;
-SDL_TimerID timer; -SDL_UserEvent timer_event; - -GP_Pixel black_pixel, red_pixel, green_pixel, white_pixel; - -Uint32 timer_callback(__attribute__((unused)) Uint32 interval, - __attribute__((unused)) void *param) -{ - timer_event.type = SDL_USEREVENT; - SDL_PushEvent((SDL_Event *) &timer_event); - return 30; -} +static GP_Pixel red, green, white, black;
static void draw_event(GP_Event *ev) { @@ -55,20 +43,19 @@ static void draw_event(GP_Event *ev) int align = GP_ALIGN_RIGHT|GP_VALIGN_BOTTOM;
- GP_TextClear(&context, NULL, 20, 20, align, black_pixel, size); - size = GP_Print(&context, NULL, 20, 20, align, - white_pixel, black_pixel, "Key=%s", + GP_TextClear(win, NULL, 20, 20, align, black, size); + size = GP_Print(win, NULL, 20, 20, align, + white, black, "Key=%s", GP_EventKeyName(ev->val.key.key)); - SDL_Flip(display); + + GP_BackendFlip(backend); }
static void event_loop(void) { - SDL_Event event; - - while (SDL_WaitEvent(&event) > 0) { - GP_InputDriverSDLEventPut(&event); - + for (;;) { + GP_BackendWait(backend); + while (GP_EventQueued()) { GP_Event ev;
@@ -81,17 +68,17 @@ static void event_loop(void)
switch (ev.val.key.key) { case GP_KEY_ESC: - SDL_Quit(); + GP_BackendExit(backend); exit(0); break; case GP_BTN_LEFT: - GP_HLineXXY(&context, ev.cursor_x - 3, + GP_HLineXXY(win, ev.cursor_x - 3, ev.cursor_x + 3, - ev.cursor_y, red_pixel); - GP_VLineXYY(&context, ev.cursor_x, + ev.cursor_y, red); + GP_VLineXYY(win, ev.cursor_x, ev.cursor_y - 3, - ev.cursor_y + 3, red_pixel); - SDL_Flip(display); + ev.cursor_y + 3, red); + GP_BackendFlip(backend); break; default: break; @@ -102,18 +89,17 @@ static void event_loop(void) static int size = 0; case GP_EV_REL_POS: if (GP_EventGetKey(&ev, GP_BTN_LEFT)) { - GP_PutPixel(&context, ev.cursor_x, - ev.cursor_y, green_pixel); - SDL_Flip(display); + GP_PutPixel(win, ev.cursor_x, + ev.cursor_y, green); } int align = GP_ALIGN_RIGHT|GP_VALIGN_BOTTOM;
- GP_TextClear(&context, NULL, 20, 40, align, - black_pixel, size); - size = GP_Print(&context, NULL, 20, 40, align, - white_pixel, black_pixel, "X=%3u Y=%3u", + GP_TextClear(win, NULL, 20, 40, align, + black, size); + size = GP_Print(win, NULL, 20, 40, align, + white, black, "X=%3u Y=%3u", ev.cursor_x, ev.cursor_y); - SDL_Flip(display); + GP_BackendFlip(backend); break; } break; @@ -124,49 +110,48 @@ static void event_loop(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"; + int opt; + + while ((opt = getopt(argc, argv, "b:h")) != -1) { + switch (opt) { + case 'b': + backend_opts = optarg; + break; + case 'h': + GP_BackendInit(NULL, NULL, stderr); + return 0; + break; + default: + fprintf(stderr, "Invalid paramter '%c'n", opt); + return 1; } }
- /* Initialize SDL */ - if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) != 0) { - fprintf(stderr, "Could not initialize SDL: %sn", SDL_GetError()); - return 1; - } +// GP_SetDebugLevel(10);
- display = SDL_SetVideoMode(480, 640, display_bpp, SDL_SWSURFACE); - if (display == NULL) { - fprintf(stderr, "Could not open display: %sn", SDL_GetError()); - goto fail; + backend = GP_BackendInit(backend_opts, "Input Test", stderr); + + if (backend == NULL) { + fprintf(stderr, "Failed to initalize backend '%s'n", + backend_opts); + return 1; } + + win = backend->context;
- GP_EventSetScreenSize(480, 640); + red = GP_ColorToContextPixel(GP_COL_RED, win); + green = GP_ColorToContextPixel(GP_COL_GREEN, win); + white = GP_ColorToContextPixel(GP_COL_WHITE, win); + black = GP_ColorToContextPixel(GP_COL_BLACK, win);
- GP_SDL_ContextFromSurface(&context, display); + GP_Fill(win, black); + GP_BackendFlip(backend);
- red_pixel = GP_ColorToContextPixel(GP_COL_RED, &context); - green_pixel = GP_ColorToContextPixel(GP_COL_GREEN, &context); - white_pixel = GP_ColorToContextPixel(GP_COL_WHITE, &context); - black_pixel = GP_ColorToContextPixel(GP_COL_BLACK, &context); + GP_EventSetScreenSize(win->w, win->h);
- timer = SDL_AddTimer(30, timer_callback, NULL); - if (timer == 0) { - fprintf(stderr, "Could not set up timer: %sn", SDL_GetError()); - goto fail; + for (;;) { + GP_BackendWait(backend); + event_loop(); } - - event_loop(); - SDL_Quit(); - return 0; - -fail: - SDL_Quit(); - return 1; } diff --git a/tests/SDL/Makefile b/tests/SDL/Makefile index 228df9e..4455172 100644 --- a/tests/SDL/Makefile +++ b/tests/SDL/Makefile @@ -8,7 +8,7 @@ ifeq ($(HAVE_LIBSDL),yes) CSOURCES=$(shell echo *.c)
APPS=pixeltest fileview fonttest linetest randomshapetest- symbolstest textaligntest trianglefps input blittest subcontext showimage+ symbolstest textaligntest trianglefps blittest subcontext showimage aatest mixpixeltest endif
http://repo.or.cz/w/gfxprim.git/commit/e086670095af025857270b996b7a5d2deec42...
commit e086670095af025857270b996b7a5d2deec42820 Author: Cyril Hrubis metan@ucw.cz Date: Thu Aug 2 14:25:44 2012 +0200
demos: grinder: Get rid of GP_RetCode.
diff --git a/demos/grinder/grinder.c b/demos/grinder/grinder.c index fbf0e21..648e950 100644 --- a/demos/grinder/grinder.c +++ b/demos/grinder/grinder.c @@ -106,18 +106,18 @@ static struct param resize_params[] = { {NULL, 0, NULL, NULL, NULL} };
-static GP_RetCode resize(GP_Context **c, const char *params) +static int resize(GP_Context **c, const char *params) { int alg = 1; float ratio = -1;
if (param_parse(params, resize_params, "resize", param_err, &alg, &ratio)) - return GP_EINVAL; + return EINVAL;
if (ratio == -1) { print_error("resize: ratio parameter is missing"); - return GP_EINVAL; + return EINVAL; }
GP_Size w = ratio * (*c)->w; @@ -127,12 +127,12 @@ static GP_RetCode resize(GP_Context **c, const char *params) res = GP_FilterResize(*c, NULL, alg, w, h, progress_callback); if (res == NULL) - return GP_EINVAL; + return EINVAL;
GP_ContextFree(*c); *c = res;
- return GP_ESUCCESS; + return 0; }
/* scale filter */ @@ -164,7 +164,7 @@ static struct param scale_params[] = { {NULL, 0, NULL, NULL, NULL} };
-static GP_RetCode scale(GP_Context **c, const char *params) +static int scale(GP_Context **c, const char *params) { int alg = 1; int w = -1; @@ -172,11 +172,11 @@ static GP_RetCode scale(GP_Context **c, const char *params)
if (param_parse(params, scale_params, "scale", param_err, &alg, &w, &h)) - return GP_EINVAL; + return EINVAL;
if (w == -1 && h == -1) { print_error("scale: w and/or h missing"); - return GP_EINVAL; + return EINVAL; }
if (w == -1) @@ -190,12 +190,12 @@ static GP_RetCode scale(GP_Context **c, const char *params) res = GP_FilterResize(*c, NULL, alg, w, h, progress_callback);
if (res == NULL) - return GP_EINVAL; + return EINVAL;
GP_ContextFree(*c); *c = res;
- return GP_ESUCCESS; + return 0; }
/* rotate filter */ @@ -211,16 +211,16 @@ static struct param rotate_params[] = { {NULL, 0, NULL, NULL, NULL} };
-static GP_RetCode rotate(GP_Context **c, const char *params) +static int rotate(GP_Context **c, const char *params) { int rot = -1;
if (param_parse(params, rotate_params, "rotate", param_err, &rot)) - return GP_EINVAL; + return EINVAL;
if (rot == -1) { print_error("rotate: rot parameter is missing"); - return GP_EINVAL; + return EINVAL; }
GP_Context *res = NULL; @@ -243,7 +243,7 @@ static GP_RetCode rotate(GP_Context **c, const char *params) GP_ContextFree(*c); *c = res;
- return GP_ESUCCESS; + return 0; }
/* mirror filter */ @@ -254,12 +254,12 @@ static struct param mirror_params[] = { {NULL, 0, NULL, NULL, NULL} };
-static GP_RetCode mirror(GP_Context **c, const char *params) +static int mirror(GP_Context **c, const char *params) { int vert = 0, horiz = 0;
if (param_parse(params, mirror_params, "mirror", param_err, &vert, &horiz)) - return GP_EINVAL; + return EINVAL;
if (vert) GP_FilterMirrorV(*c, *c, progress_callback); @@ -267,7 +267,7 @@ static GP_RetCode mirror(GP_Context **c, const char *params) if (horiz) GP_FilterMirrorH(*c, *c, progress_callback);
- return GP_ESUCCESS; + return 0; }
/* brightness filter */ @@ -278,17 +278,17 @@ static struct param bright_params[] = { {NULL, 0, NULL, NULL, NULL} };
-static GP_RetCode bright(GP_Context **c, const char *params) +static int bright(GP_Context **c, const char *params) { int bright = 0; char *chann = NULL;
if (param_parse(params, bright_params, "bright", param_err, &bright, &chann)) - return GP_EINVAL; + return EINVAL;
if (bright == 0) { print_error("bright: bright parameter is zero or missing"); - return GP_EINVAL; + return EINVAL; }
GP_FILTER_PARAMS((*c)->pixel_type, filter_params); @@ -300,7 +300,7 @@ static GP_RetCode bright(GP_Context **c, const char *params) if (param == NULL) { print_error("bright: Invalid channel name"); - return GP_EINVAL; + return EINVAL; }
GP_FilterParamSetIntAll(filter_params, 0); @@ -309,7 +309,7 @@ static GP_RetCode bright(GP_Context **c, const char *params)
GP_FilterBrightness(*c, *c, filter_params, progress_callback);
- return GP_ESUCCESS; + return 0; }
/* contrast */ @@ -320,17 +320,17 @@ static struct param contrast_params[] = { {NULL, 0, NULL, NULL, NULL} };
-static GP_RetCode contrast(GP_Context **c, const char *params) +static int contrast(GP_Context **c, const char *params) { float mul = 0; char *chann = NULL;
if (param_parse(params, contrast_params, "contrast", param_err, &mul, &chann)) - return GP_EINVAL; + return EINVAL;
if (mul <= 0) { print_error("contrast: mul parameter must be >= 0"); - return GP_EINVAL; + return EINVAL; } GP_FILTER_PARAMS((*c)->pixel_type, filter_params); @@ -342,7 +342,7 @@ static GP_RetCode contrast(GP_Context **c, const char *params) if (param == NULL) { print_error("contrast: Invalid channel name"); - return GP_EINVAL; + return EINVAL; }
GP_FilterParamSetFloatAll(filter_params, 1); @@ -351,7 +351,7 @@ static GP_RetCode contrast(GP_Context **c, const char *params)
GP_FilterContrast(*c, *c, filter_params, progress_callback);
- return GP_ESUCCESS; + return 0; }
/* noise */ @@ -360,12 +360,12 @@ static struct param noise_params[] = { {NULL, 0, NULL, NULL, NULL} };
-static GP_RetCode noise(GP_Context **c, const char *params) +static int noise(GP_Context **c, const char *params) { float rat;
if (param_parse(params, noise_params, "noise", param_err, &rat)) - return GP_EINVAL; + return EINVAL;
GP_FILTER_PARAMS((*c)->pixel_type, filter_params); @@ -373,7 +373,7 @@ static GP_RetCode noise(GP_Context **c, const char *params)
GP_FilterNoise(*c, *c, filter_params, progress_callback);
- return GP_ESUCCESS; + return 0; }
/* invert */ @@ -382,14 +382,14 @@ static struct param invert_params[] = { {NULL, 0, NULL, NULL, NULL} };
-static GP_RetCode invert(GP_Context **c, const char *params) +static int invert(GP_Context **c, const char *params) { if (param_parse(params, invert_params, "invert", param_err)) - return GP_EINVAL; + return EINVAL;
GP_FilterInvert(*c, *c, progress_callback);
- return GP_ESUCCESS; + return 0; }
/* blur */ @@ -401,7 +401,7 @@ static struct param blur_params[] = { {NULL, 0, NULL, NULL, NULL} };
-static GP_RetCode blur(GP_Context **c, const char *params) +static int blur(GP_Context **c, const char *params) { float sigma = 0; float sigma_x = 0; @@ -417,12 +417,12 @@ static GP_RetCode blur(GP_Context **c, const char *params)
if (sigma_x <= 0 && sigma_y <= 0) { print_error("blur: at least one of sigma_x and sigma_y must be >= 0"); - return GP_EINVAL; + return EINVAL; }
GP_FilterGaussianBlur(*c, *c, sigma_x, sigma_y, progress_callback);
- return GP_ESUCCESS; + return 0; }
/* dithering */ @@ -454,16 +454,16 @@ static struct param dither_params[] = { {NULL, 0, NULL, NULL, NULL} };
-static GP_RetCode dither(GP_Context **c, const char *params) +static int dither(GP_Context **c, const char *params) { int fmt = -1;
if (param_parse(params, dither_params, "dither", param_err, &fmt)) - return GP_EINVAL; + return EINVAL; if (fmt == -1) { print_error("dither: invalid format or format param missing"); - return GP_EINVAL; + return EINVAL; }
GP_Context *bw; @@ -476,7 +476,7 @@ static GP_RetCode dither(GP_Context **c, const char *params)
GP_ContextFree(bw);
- return GP_ESUCCESS; + return 0; }
/* jpg save filter */ @@ -486,21 +486,21 @@ static struct param save_jpg_params[] = { {NULL, 0, NULL, NULL, NULL} };
-static GP_RetCode save_jpg(GP_Context **c, const char *params) +static int save_jpg(GP_Context **c, const char *params) { char *file = NULL;
if (param_parse(params, save_jpg_params, "jpg", param_err, &file)) - return GP_EINVAL; + return EINVAL; if (file == NULL) { print_error("jpg: filename missing"); - return GP_EINVAL; + return EINVAL; }
GP_SaveJPG(*c, file, progress_callback);
- return GP_ESUCCESS; + return 0; }
/* png save filter */ @@ -510,21 +510,21 @@ static struct param save_png_params[] = { {NULL, 0, NULL, NULL, NULL} };
-static GP_RetCode save_png(GP_Context **c, const char *params) +static int save_png(GP_Context **c, const char *params) { char *file = NULL;
if (param_parse(params, save_png_params, "png", param_err, &file)) - return GP_EINVAL; + return EINVAL; if (file == NULL) { print_error("png: filename missing"); - return GP_EINVAL; + return EINVAL; }
GP_SavePNG(*c, file, progress_callback);
- return GP_ESUCCESS; + return 0; }
/* noise filter */ @@ -559,13 +559,13 @@ static uint32_t no_op(uint32_t val) return val; }
-static GP_RetCode add_noise(GP_Context **c, const char *params) +static int add_noise(GP_Context **c, const char *params) { float percents = 0; char *chann = NULL;
if (param_parse(params, add_noise_params, "add_noise", param_err, &percents, &chann)) - return GP_EINVAL; + return EINVAL; GP_FILTER_PARAMS((*c)->pixel_type, priv); GP_FilterParamSetFloatAll(priv, percents/100); @@ -578,7 +578,7 @@ static GP_RetCode add_noise(GP_Context **c, const char *params) if (param == NULL) { print_error("add_noise: Invalid channel name"); - return GP_EINVAL; + return EINVAL; }
@@ -588,7 +588,7 @@ static GP_RetCode add_noise(GP_Context **c, const char *params)
GP_FilterPoint(*c, *c, op_callbacks, priv, progress_callback);
- return GP_ESUCCESS; + return 0; }
/* median filter */ @@ -600,12 +600,12 @@ static struct param median_params[] = { {NULL, 0, NULL, NULL, NULL} };
-static GP_RetCode median(GP_Context **c, const char *params) +static int median(GP_Context **c, const char *params) { int rad = -1, rad_x, rad_y;
if (param_parse(params, median_params, "median", param_err, &rad, &rad_x, &rad_y)) - return GP_EINVAL; + return EINVAL; if (rad != -1) { rad_x = rad; @@ -613,17 +613,17 @@ static GP_RetCode median(GP_Context **c, const char *params) }
if (rad_x < 0 || rad_y < 0) - return GP_EINVAL; + return EINVAL;
GP_Context *ret = GP_FilterMedianAlloc(*c, rad_x, rad_y, progress_callback);
if (ret == NULL) - return GP_ENOMEM; + return ENOMEM;
GP_ContextFree(*c); *c = ret;
- return GP_ESUCCESS; + return 0; }
/* sigma mean filter */ @@ -637,14 +637,14 @@ static struct param sigma_mean_params[] = { {NULL, 0, NULL, NULL, NULL} };
-static GP_RetCode sigma_mean(GP_Context **c, const char *params) +static int 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; + return EINVAL; if (rad != -1) { rad_x = rad; @@ -652,19 +652,19 @@ static GP_RetCode sigma_mean(GP_Context **c, const char *params) }
if (rad_x < 0 || rad_y < 0) - return GP_EINVAL; + return 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) - return GP_ENOMEM; + return ENOMEM;
GP_ContextFree(*c); *c = ret;
- return GP_ESUCCESS; + return 0; }
/* laplacian edge sharpening filter */ @@ -674,22 +674,22 @@ static struct param sharpen_params[] = { {NULL, 0, NULL, NULL, NULL} };
-static GP_RetCode sharpen(GP_Context **c, const char *params) +static int sharpen(GP_Context **c, const char *params) { float weight = 0.1;
if (param_parse(params, sharpen_params, "sigma", param_err, &weight)) - return GP_EINVAL; + return EINVAL; GP_Context *ret = GP_FilterEdgeSharpeningAlloc(*c, weight, progress_callback);
if (ret == NULL) - return GP_ENOMEM; + return ENOMEM;
GP_ContextFree(*c); *c = ret;
- return GP_ESUCCESS; + return 0; }
/* arithmetics */ @@ -709,24 +709,24 @@ static struct param arithmetic_params[] = { {NULL, 0, NULL, NULL, NULL} };
-static GP_RetCode arithmetic(GP_Context **c, const char *params) +static int arithmetic(GP_Context **c, const char *params) { char *file = NULL; int op = -1;
if (param_parse(params, arithmetic_params, "arithmetic", param_err, &file, &op)) - return GP_EINVAL; + return EINVAL; if (file == NULL) { print_error("arithmetic: Filename missing"); - return GP_EINVAL; + return EINVAL; }
GP_Context *img, *res = NULL;
if ((img = GP_LoadImage(file, progress_callback)) == NULL) { print_error("arithmetic: Invalid image."); - return GP_EINVAL; + return EINVAL; }
switch (op) { @@ -748,13 +748,13 @@ static GP_RetCode arithmetic(GP_Context **c, const char *params) }
if (res == NULL) - return GP_EINVAL; + return ENOMEM;
GP_ContextFree(*c);
*c = res;
- return GP_ESUCCESS; + return 0; }
/* histogram */ @@ -764,20 +764,20 @@ static struct param histogram_params[] = { {NULL, 0, NULL, NULL, NULL} };
-static GP_RetCode histogram(GP_Context **c, const char *params) +static int histogram(GP_Context **c, const char *params) { char *file = "histogram.png";
if (param_parse(params, histogram_params, "histogram", param_err, &file)) - return GP_EINVAL; + return EINVAL; if (file == NULL) { print_error("histogram: Filename missing"); - return GP_EINVAL; + return EINVAL; }
histogram_to_png(*c, file); - return GP_ESUCCESS; + return 0; }
/* filters */ @@ -786,7 +786,7 @@ struct filter { const char *name; const char *desc; struct param *param_desc; - GP_RetCode (*apply)(GP_Context **c, const char *params); + int (*apply)(GP_Context **c, const char *params); };
static struct filter filter_table[] = { @@ -875,7 +875,7 @@ static void add_filter(char *params) static void apply_filters(GP_Context **src) { unsigned int i; - GP_RetCode ret; + int ret;
for (i = 0; i < filter_cnt; i++) { char buf[255]; @@ -885,7 +885,7 @@ static void apply_filters(GP_Context **src) progress_prefix = buf;
if ((ret = filters[i]->apply(src, filter_params[i]))) { - fprintf(stderr, "Error: %sn", GP_RetCodeName(ret)); + fprintf(stderr, "Error: %sn", strerror(ret)); exit(1); } @@ -956,7 +956,7 @@ static void check_fmt(const char *fmt)
static void save_by_fmt(struct GP_Context *bitmap, const char *name, const char *fmt) { - GP_RetCode ret; + int ret;
progress_prefix = "Saving Image";
@@ -968,7 +968,8 @@ static void save_by_fmt(struct GP_Context *bitmap, const char *name, const char ret = GP_SavePNG(bitmap, name, progress_callback); if (ret) { - fprintf(stderr, "Failed to save bitmap: %sn", GP_RetCodeName(ret)); + fprintf(stderr, "Failed to save bitmap: %sn", + strerror(errno)); exit(1); }
http://repo.or.cz/w/gfxprim.git/commit/7dc5026aa07022e0b17da3b5fd173eaa900ec...
commit 7dc5026aa07022e0b17da3b5fd173eaa900ec3b2 Author: Cyril Hrubis metan@ucw.cz Date: Thu Aug 2 14:10:04 2012 +0200
doc: Add debug env variable docs.
diff --git a/doc/debug.txt b/doc/debug.txt index c86e8a9..3f1cc69 100644 --- a/doc/debug.txt +++ b/doc/debug.txt @@ -27,6 +27,9 @@ or destroyed or when particular algorithm has been started. Setting debug level to value higher than 1 would expose even more verbose messages the current maximum used by debug messages is 4.
+The debug level may also be set by setting the 'GP_DEBUG' environment +variable. In such case the debug level is set accordingly to its value when +first debug message is about to be printed.
[source,c] ------------------------------------------------------------------------------- diff --git a/doc/environment_variables.txt b/doc/environment_variables.txt index c120528..71e3b91 100644 --- a/doc/environment_variables.txt +++ b/doc/environment_variables.txt @@ -21,3 +21,10 @@ bellow: | >=2 | Use N threads unless the image buffer is too small. |=============================================================================
+GP_DEBUG +~~~~~~~~ + +The 'GP_DEBUG' environment variable may be used to set library debug level. +The variable and its value is used only once a the time first debug message is +about to be printed. +
http://repo.or.cz/w/gfxprim.git/commit/dff4c0ec8bdcc90fab43fe7cc627d8d164cde...
commit dff4c0ec8bdcc90fab43fe7cc627d8d164cde641 Author: Cyril Hrubis metan@ucw.cz Date: Thu Aug 2 13:53:04 2012 +0200
core: debug: Add debug level env variable.
Add support for setting debug level from GP_DEBUG environment variable. The environment variable is used exactly once at a time first debug message is about to be printed.
diff --git a/libs/core/GP_Debug.c b/libs/core/GP_Debug.c index ecef216..9332828 100644 --- a/libs/core/GP_Debug.c +++ b/libs/core/GP_Debug.c @@ -25,6 +25,7 @@ #include "GP_Debug.h"
static unsigned int debug_level = GP_DEFAULT_DEBUG_LEVEL; +static int env_used = 0;
void GP_SetDebugLevel(unsigned int level) { @@ -44,6 +45,24 @@ void GP_DebugPrint(int level, const char *file, const char *function, int line, if (level > (int)debug_level) return;
+ if (!env_used) { + char *level = getenv("GP_DEBUG"); + + env_used = 1; + + if (level != NULL) { + int new_level = atoi(level); + + if (new_level >= 0) { + debug_level = new_level; + + GP_DEBUG(1, "Using debug level GP_DEBUG=%i " + "from enviroment variable", + debug_level); + } + } + } + for (i = 1; i < level; i++) fputc(' ', stderr);
-----------------------------------------------------------------------
Summary of changes: demos/c_simple/Makefile | 2 +- {tests/SDL => demos/c_simple}/input.c | 135 +++++++-------- demos/grinder/grinder.c | 185 +++++++++++--------- doc/debug.txt | 3 + doc/environment_variables.txt | 7 + include/filters/GP_Filters.h | 3 + include/filters/GP_GaussianNoise.h | 70 ++++++++ .../GP_InputDriverX11.h => filters/GP_Rand.h} | 17 +- libs/core/GP_Debug.c | 19 ++ libs/filters/GP_GaussianNoise.gen.c.t | 149 ++++++++++++++++ .../loaders_example.c => libs/filters/GP_Rand.c | 47 ++--- libs/filters/Makefile | 2 +- tests/SDL/Makefile | 2 +- 13 files changed, 446 insertions(+), 195 deletions(-) rename {tests/SDL => demos/c_simple}/input.c (54%) create mode 100644 include/filters/GP_GaussianNoise.h copy include/{input/GP_InputDriverX11.h => filters/GP_Rand.h} (83%) create mode 100644 libs/filters/GP_GaussianNoise.gen.c.t copy demos/c_simple/loaders_example.c => libs/filters/GP_Rand.c (73%)
repo.or.cz automatic notification. Contact project admin jiri.bluebear.dluhos@gmail.com if you want to unsubscribe, or site admin admin@repo.or.cz if you receive no reply.