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, generate has been updated via 8c9174cab63f49a6239b64579244425a384520c1 (commit) via 661f7dd456af5304f88364a49f445b0dd03bdf5c (commit) via 1230c9066f4c5ac5d38991896e6795ae5f0d0c0e (commit) via 04b22f1283e5c809494415d1c35593ee3858884f (commit) from 63b5c2d57786aff8babac4c17c5fc5996c33cd4a (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/8c9174cab63f49a6239b64579244425a38452...
commit 8c9174cab63f49a6239b64579244425a384520c1 Author: Cyril Hrubis metan@ucw.cz Date: Fri Sep 30 21:03:16 2011 +0200
Added new filter to grinder.
diff --git a/demos/grinder/grinder.c b/demos/grinder/grinder.c index 365b45d..78d33d7 100644 --- a/demos/grinder/grinder.c +++ b/demos/grinder/grinder.c @@ -246,14 +246,8 @@ static GP_RetCode bright(GP_Context **c, const char *params) return GP_EINVAL; }
- GP_Context *res = GP_FilterBrightness(*c, bright); + GP_FilterBrightness_Raw(*c, *c, bright);
- if (res == NULL) - return GP_EINVAL; - - GP_ContextFree(*c); - *c = res; - return GP_ESUCCESS; }
@@ -276,16 +270,27 @@ static GP_RetCode contrast(GP_Context **c, const char *params) return GP_EINVAL; }
- GP_Context *res = GP_FilterContrast(*c, mul); + GP_FilterContrast_Raw(*c, *c, mul);
- if (res == NULL) + return GP_ESUCCESS; +} + +/* invert */ + +static struct param invert_params[] = { + {NULL, 0, NULL, NULL, NULL} +}; + +static GP_RetCode invert(GP_Context **c, const char *params) +{ + if (param_parse(params, invert_params, "invert", param_err)) return GP_EINVAL;
- GP_ContextFree(*c); - *c = res; - + GP_FilterInvert_Raw(*c, *c); + return GP_ESUCCESS; } + /* filters */
struct filter { @@ -301,6 +306,7 @@ static struct filter filter_table[] = { {"rotate", "rotate image", rotate_params, rotate}, {"bright", "alter image brightness", bright_params, bright}, {"contrast", "alter image contrast", contrast_params, contrast}, + {"invert", "inverts image", invert_params, invert}, {NULL, NULL, NULL, NULL} };
http://repo.or.cz/w/gfxprim.git/commit/661f7dd456af5304f88364a49f445b0dd03bd...
commit 661f7dd456af5304f88364a49f445b0dd03bdf5c Author: Cyril Hrubis metan@ucw.cz Date: Fri Sep 30 21:02:32 2011 +0200
Created template for point pixel filters.
diff --git a/include/filters/GP_Filters.h b/include/filters/GP_Filters.h index bbeb3eb..4c1304d 100644 --- a/include/filters/GP_Filters.h +++ b/include/filters/GP_Filters.h @@ -35,7 +35,7 @@ /* Image rotations (90 180 270 grads) and mirroring */ #include "filters/GP_Rotate.h"
-#include "filters/GP_Linear.h" +#include "filters/GP_Point.h"
/* Image down and up scaling */ #include "filters/GP_Scale.h" diff --git a/include/filters/GP_Linear.h b/include/filters/GP_Point.h similarity index 87% rename from include/filters/GP_Linear.h rename to include/filters/GP_Point.h index 43b757c..8ef935b 100644 --- a/include/filters/GP_Linear.h +++ b/include/filters/GP_Point.h @@ -22,17 +22,17 @@
/*
- Standart point and linear filters. + Point filters, these works on individual pixels.
*/
-#ifndef GP_LINEAR_H -#define GP_LINEAR_H +#ifndef GP_POINT_H +#define GP_POINT_H
#include <GP_Context.h>
/* - * Brightness (point) filter. + * Brightness filter. */ void GP_FilterBrightness_Raw(const GP_Context *src, GP_Context *res, int32_t inc); @@ -40,11 +40,18 @@ void GP_FilterBrightness_Raw(const GP_Context *src, GP_Context *res, GP_Context *GP_FilterBrightness(const GP_Context *src, int32_t inc);
/* - * Contrast (point) filter. + * Contrast filter. */ GP_Context *GP_FilterContrast_Raw(const GP_Context *src, GP_Context *res, float mul);
GP_Context *GP_FilterContrast(const GP_Context *src, float mul);
-#endif /* GP_LINEAR_H */ +/* + * Invert filter. + */ +GP_Context *GP_FilterInvert_Raw(const GP_Context *src, GP_Context *res); + +GP_Context *GP_FilterInvert(const GP_Context *src); + +#endif /* GP_POINT_H */ diff --git a/libs/filters/GP_Brightness.gen.c.t b/libs/filters/GP_Brightness.gen.c.t index b73fb9a..8262dc1 100644 --- a/libs/filters/GP_Brightness.gen.c.t +++ b/libs/filters/GP_Brightness.gen.c.t @@ -1,4 +1,4 @@ -%% extends "base.c.t" +%% extends "filter.point.c.t"
%% block descr Brightness filters -- Increments all color channels by a fixed value. @@ -9,83 +9,16 @@ Brightness filters -- Increments all color channels by a fixed value. #include <GP_Pixel.h> #include <GP_GetPutPixel.h>
-/* - * Simple brightness operations for one channel bitmaps - */ -%% for ps in pixelsizes -%% if ps.size <= 8 and ps.size > 1 -void GP_FilterBrightness_{{ ps.suffix }}(const GP_Context *src, GP_Context *res, int32_t inc) -{ - uint32_t x, y; +%% call(ps) filter_per_pixel_size('Brightness', 'int32_t inc') +pix = pix + inc; +{{ filter_clamp_val('pix', ps.size) }} +%% endcall
- for (y = 0; y < src->h; y++) - for (x = 0; x < src->w; x++) { - int32_t pix = GP_GetPixel_Raw_{{ ps.suffix }}(src, x, y) + inc; - - if (pix < 0) - pix = 0; - - if (pix > {{ 2 ** ps.size - 1 }}) - pix = {{ 2 ** ps.size - 1}}; - - GP_PutPixel_Raw_{{ ps.suffix }}(res, x, y, pix); - } -} - -%% endif -%% endfor - -/* - * Brightness filters for pixel types with more than one channels - */ -%% for pt in pixeltypes -%% if not pt.is_unknown() and len(pt.chanslist) > 1 -void GP_FilterBrightness_{{ pt.name }}(const GP_Context *src, GP_Context *res, int32_t inc) -{ - uint32_t x, y; - - for (y = 0; y < src->h; y++) - for (x = 0; x < src->w; x++) { - GP_Pixel pix = GP_GetPixel_Raw_{{ pt.pixelsize.suffix }}(src, x, y); - %% for c in pt.chanslist - int32_t {{ c[0] }} = GP_Pixel_GET_{{ c[0] }}_{{ pt.name }}(pix) + inc; - %% endfor - - %% for c in pt.chanslist - if ({{ c[0] }} < 0) - {{ c[0] }} = 0; - - if ({{ c[0] }} > {{ 2 ** c[2] - 1 }}) - {{ c[0] }} = 255; - - %% endfor - pix = GP_Pixel_CREATE_{{ pt.name }}({{ pt.chanslist[0][0] }}{% for c in pt.chanslist[1:] %}, {{ c[0] }}{% endfor %}); - - GP_PutPixel_Raw_{{ pt.pixelsize.suffix }}(res, x, y, pix); - } -} - -%% endif -%% endfor - -void GP_FilterBrightness_Raw(const GP_Context *src, GP_Context *res, int32_t inc) -{ - switch (src->pixel_type) { - %% for pt in pixeltypes - case GP_PIXEL_{{ pt.name }}: - %% if pt.is_unknown() or pt.pixelsize.size < 2 - return; - %% elif len(pt.chanslist) == 1: - GP_FilterBrightness_{{ pt.pixelsize.suffix }}(src, res, inc); - %% else - GP_FilterBrightness_{{ pt.name }}(src, res, inc); - %% endif - break; - %% endfor - default: - break; - } -} +%% call(chan) filter_per_pixel_type('Brightness', 'int32_t inc') +{{ chan[0] }} = {{ chan[0] }} + inc; +{{ filter_clamp_val(chan[0], chan[2]) }} +%% endcall
+{{ filter_functions('Brightness', 'int32_t inc', 'inc') }}
%% endblock body diff --git a/libs/filters/GP_Contrast.gen.c.t b/libs/filters/GP_Contrast.gen.c.t index 6ce18ba..5a78363 100644 --- a/libs/filters/GP_Contrast.gen.c.t +++ b/libs/filters/GP_Contrast.gen.c.t @@ -1,4 +1,4 @@ -%% extends "base.c.t" +%% extends "filter.point.c.t"
%% block descr Contrast filters -- Multiply all color channels by a fixed value. @@ -9,83 +9,16 @@ Contrast filters -- Multiply all color channels by a fixed value. #include <GP_Pixel.h> #include <GP_GetPutPixel.h>
-/* - * Simple brightness operations for one channel bitmaps - */ -%% for ps in pixelsizes -%% if ps.size <= 8 and ps.size > 1 -void GP_FilterContrast_{{ ps.suffix }}(const GP_Context *src, GP_Context *res, float mul) -{ - uint32_t x, y; +%% call(ps) filter_per_pixel_size('Contrast', 'float mul') +pix = 1.00 * pix * mul; +{{ filter_clamp_val('pix', ps.size) }} +%% endcall
- for (y = 0; y < src->h; y++) - for (x = 0; x < src->w; x++) { - int32_t pix = GP_GetPixel_Raw_{{ ps.suffix }}(src, x, y) * mul + 0.5; - - if (pix < 0) - pix = 0; - - if (pix > {{ 2 ** ps.size - 1 }}) - pix = {{ 2 ** ps.size - 1}}; - - GP_PutPixel_Raw_{{ ps.suffix }}(res, x, y, pix); - } -} - -%% endif -%% endfor - -/* - * Brightness filters for pixel types with more than one channels - */ -%% for pt in pixeltypes -%% if not pt.is_unknown() and len(pt.chanslist) > 1 -void GP_FilterContrast_{{ pt.name }}(const GP_Context *src, GP_Context *res, float mul) -{ - uint32_t x, y; - - for (y = 0; y < src->h; y++) - for (x = 0; x < src->w; x++) { - GP_Pixel pix = GP_GetPixel_Raw_{{ pt.pixelsize.suffix }}(src, x, y); - %% for c in pt.chanslist - int32_t {{ c[0] }} = GP_Pixel_GET_{{ c[0] }}_{{ pt.name }}(pix) * mul + 0.5; - %% endfor - - %% for c in pt.chanslist - if ({{ c[0] }} < 0) - {{ c[0] }} = 0; - - if ({{ c[0] }} > {{ 2 ** c[2] - 1 }}) - {{ c[0] }} = 255; - - %% endfor - pix = GP_Pixel_CREATE_{{ pt.name }}({{ pt.chanslist[0][0] }}{% for c in pt.chanslist[1:] %}, {{ c[0] }}{% endfor %}); - - GP_PutPixel_Raw_{{ pt.pixelsize.suffix }}(res, x, y, pix); - } -} - -%% endif -%% endfor - -void GP_FilterContrast_Raw(const GP_Context *src, GP_Context *res, float mul) -{ - switch (src->pixel_type) { - %% for pt in pixeltypes - case GP_PIXEL_{{ pt.name }}: - %% if pt.is_unknown() or pt.pixelsize.size < 2 - return; - %% elif len(pt.chanslist) == 1: - GP_FilterContrast_{{ pt.pixelsize.suffix }}(src, res, mul); - %% else - GP_FilterContrast_{{ pt.name }}(src, res, mul); - %% endif - break; - %% endfor - default: - break; - } -} +%% call(chan) filter_per_pixel_type('Contrast', 'float mul') +{{ chan[0] }} = mul * {{ chan[0] }} + 0.5; +{{ filter_clamp_val(chan[0], chan[2]) }} +%% endcall
+{{ filter_functions('Contrast', 'float mul', 'mul') }}
%% endblock body diff --git a/libs/filters/GP_Invert.gen.c.t b/libs/filters/GP_Invert.gen.c.t new file mode 100644 index 0000000..f641fcf --- /dev/null +++ b/libs/filters/GP_Invert.gen.c.t @@ -0,0 +1,22 @@ +%% extends "filter.point.c.t" + +%% block descr +Invert filters -- Invert image +%% endblock + +%% block body +#include <GP_Context.h> +#include <GP_Pixel.h> +#include <GP_GetPutPixel.h> + +%% call(ps) filter_per_pixel_size('Invert') +pix = {{ 2 ** ps.size - 1 }} - pix; +%% endcall + +%% call(chan) filter_per_pixel_type('Invert') +{{ chan[0] }} = {{ 2 ** chan[2] - 1 }} - {{ chan[0] }}; +%% endcall + +{{ filter_functions('Invert') }} + +%% endblock body diff --git a/libs/filters/GP_Linear.c b/libs/filters/GP_Linear.c deleted file mode 100644 index beed134..0000000 --- a/libs/filters/GP_Linear.c +++ /dev/null @@ -1,60 +0,0 @@ -/***************************************************************************** - * This file is part of gfxprim library. * - * * - * Gfxprim is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Lesser General Public * - * License as published by the Free Software Foundation; either * - * version 2.1 of the License, or (at your option) any later version. * - * * - * Gfxprim is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * - * Lesser General Public License for more details. * - * * - * You should have received a copy of the GNU Lesser General Public * - * License along with gfxprim; if not, write to the Free Software * - * Foundation, Inc., 51 Franklin Street, Fifth Floor, * - * Boston, MA 02110-1301 USA * - * * - * Copyright (C) 2009-2011 Cyril Hrubis metan@ucw.cz * - * * - *****************************************************************************/ - -#include <GP_Context.h> -#include <GP_GetPutPixel.h> - -#include <GP_Debug.h> - -#include "GP_Linear.h" - -GP_Context *GP_FilterBrightness(const GP_Context *src, int32_t inc) -{ - GP_Context *res; - - GP_DEBUG(1, "Running Brightness filter with inc=%i", (int)inc); - - res = GP_ContextCopy(src, 0); - - if (res == NULL) - return NULL; - - GP_FilterBrightness_Raw(src, res, inc); - - return res; -} - -GP_Context *GP_FilterContrast(const GP_Context *src, float mul) -{ - GP_Context *res; - - GP_DEBUG(1, "Running Contrast filter with mul=%2.2f", mul); - - res = GP_ContextCopy(src, 0); - - if (res == NULL) - return NULL; - - GP_FilterContrast_Raw(src, res, mul); - - return res; -} diff --git a/libs/filters/Makefile b/libs/filters/Makefile index 0708ef6..bd5ed37 100644 --- a/libs/filters/Makefile +++ b/libs/filters/Makefile @@ -1,5 +1,5 @@ TOPDIR=../.. -GENSOURCES=GP_Brightness.gen.c GP_Contrast.gen.c +GENSOURCES=GP_Brightness.gen.c GP_Contrast.gen.c GP_Invert.gen.c GENHEADERS= CSOURCES=$(filter-out $(wildcard *.gen.c),$(wildcard *.c)) LIBNAME=filters @@ -8,3 +8,5 @@ INCLUDE=core include $(TOPDIR)/gen.mk include $(TOPDIR)/include.mk include $(TOPDIR)/lib.mk + +$(GENSOURCES): $(TOPDIR)/pylib/templates/filter.point.c.t diff --git a/pylib/templates/filter.point.c.t b/pylib/templates/filter.point.c.t new file mode 100644 index 0000000..93461d9 --- /dev/null +++ b/pylib/templates/filter.point.c.t @@ -0,0 +1,109 @@ +%% extends "base.c.t" + +%% macro maybe_opts(opts) +%% if opts +,{{ opts }} +%% endif +%% endmacro + +/* + * Filter per pixel size, used for one channel images. + */ +%% macro filter_per_pixel_size(name, opts="") +%% for ps in pixelsizes +%% if ps.size <= 8 and ps.size > 1 +void GP_Filter{{ name }}_{{ ps.suffix }}(const GP_Context *src, GP_Context *res{{ maybe_opts(opts) }}) +{ + uint32_t x, y; + + for (y = 0; y < src->h; y++) { + for (x = 0; x < src->w; x++) { + int32_t pix = GP_GetPixel_Raw_{{ ps.suffix }}(src, x, y); + {{ caller(ps) }} + GP_PutPixel_Raw_{{ ps.suffix }}(res, x, y, pix); + } + } +} +%% endif +%% endfor +%% endmacro + +/* + * Filter per pixel type, used for images with more than one channel per pixel + */ +%% macro filter_per_pixel_type(name, opts="") +%% for pt in pixeltypes +%% if not pt.is_unknown() and len(pt.chanslist) > 1 +void GP_Filter{{ name }}_{{ pt.name }}(const GP_Context *src, GP_Context *res{{ maybe_opts(opts) }}) +{ + uint32_t x, y; + + for (y = 0; y < src->h; y++) + for (x = 0; x < src->w; x++) { + GP_Pixel pix = GP_GetPixel_Raw_{{ pt.pixelsize.suffix }}(src, x, y); + %% for c in pt.chanslist + int32_t {{ c[0] }} = GP_Pixel_GET_{{ c[0] }}_{{ pt.name }}(pix); + %% endfor + + %% for c in pt.chanslist + {{ caller(c) }} + %% endfor + + pix = GP_Pixel_CREATE_{{ pt.name }}({{ pt.chanslist[0][0] }}{% for c in pt.chanslist[1:] %}, {{ c[0] }}{% endfor %}); + + GP_PutPixel_Raw_{{ pt.pixelsize.suffix }}(res, x, y, pix); + } +} +%% endif +%% endfor +%% endmacro + +/* + * Value clamping macro + */ +%% macro filter_clamp_val(var, size) + if ({{ var }} < 0) + {{ var }} = 0; + + if ({{ var }} > {{ 2 ** size - 1}}) + {{ var }} = {{ 2 ** size - 1}}; +%% endmacro + +/* + * Switch per pixel sizes or pixel types. + */ +%% macro filter_functions(name, opts="", params="") +void GP_Filter{{ name }}_Raw(const GP_Context *src, GP_Context *res{{ maybe_opts(opts) }}) +{ + switch (src->pixel_type) { + %% for pt in pixeltypes + case GP_PIXEL_{{ pt.name }}: + %% if pt.is_unknown() or pt.pixelsize.size < 2 + return; + %% elif len(pt.chanslist) == 1: + GP_Filter{{ name }}_{{ pt.pixelsize.suffix }}(src, res{{ maybe_opts(params) }}); + %% else + GP_Filter{{ name }}_{{ pt.name }}(src, res{{ maybe_opts(params) }}); + %% endif + break; + %% endfor + default: + break; + } +} + +GP_Context *GP_Filter{{ name }}(const GP_Context *src{{ maybe_opts(opts) }}) +{ + GP_Context *res; + + res = GP_ContextCopy(src, 0); + + if (res == NULL) + return NULL; + + GP_Filter{{ name }}_Raw(src, res{{ maybe_opts(params) }}); + + return res; +} +%% endmacro +
http://repo.or.cz/w/gfxprim.git/commit/1230c9066f4c5ac5d38991896e6795ae5f0d0...
commit 1230c9066f4c5ac5d38991896e6795ae5f0d0c0e Author: Cyril Hrubis metan@ucw.cz Date: Fri Sep 30 19:10:30 2011 +0200
More work on grinder.
* added invalid parameter detection
* added contrast filter
diff --git a/demos/grinder/grinder.c b/demos/grinder/grinder.c index 3d099b2..365b45d 100644 --- a/demos/grinder/grinder.c +++ b/demos/grinder/grinder.c @@ -31,6 +31,14 @@
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", + (char*)priv, val); + return 1; + } + + /* just regular error */ fprintf(stderr, "ERROR: %s: invalid %s parameter %s = '%s'", (char *)priv, param_type_name(self->type), self->name, val); @@ -65,7 +73,7 @@ static const char *resize_algs[] = { };
static int resize_check_ratio(const struct param *self __attribute__((unused)), - void *val) + void *val, int count __attribute__((unused))) { float f = *((float*)val);
@@ -126,7 +134,7 @@ static const char *scale_algs[] = { };
static int scale_check_size(const struct param *self __attribute__((unused)), - void *val) + void *val, int count __attribute__((unused))) { int i = *((int*)val);
@@ -222,7 +230,7 @@ static GP_RetCode rotate(GP_Context **c, const char *params) /* brightness filter */
static struct param bright_params[] = { - {"val", PARAM_INT, "brightness increment", NULL, NULL}, + {"inc", PARAM_INT, "brightness increment", NULL, NULL}, {NULL, 0, NULL, NULL, NULL} };
@@ -249,6 +257,35 @@ static GP_RetCode bright(GP_Context **c, const char *params) return GP_ESUCCESS; }
+/* contrast */ + +static struct param contrast_params[] = { + {"mul", PARAM_FLOAT, "contrast (1.5 = +50%, 0.5 = -50%)", NULL, NULL}, + {NULL, 0, NULL, NULL, NULL} +}; + +static GP_RetCode contrast(GP_Context **c, const char *params) +{ + float mul = 0; + + if (param_parse(params, contrast_params, "contrast", param_err, &mul)) + return GP_EINVAL; + + if (mul <= 0) { + print_error("contrast: mul parameter must be >= 0"); + return GP_EINVAL; + } + + GP_Context *res = GP_FilterContrast(*c, mul); + + if (res == NULL) + return GP_EINVAL; + + GP_ContextFree(*c); + *c = res; + + return GP_ESUCCESS; +} /* filters */
struct filter { @@ -259,10 +296,11 @@ struct filter { };
static struct filter filter_table[] = { - {"resize", "resize image by given ratio", resize_params, resize}, - {"scale", "scale image to given width and height", scale_params, scale}, - {"rotate", "rotate image", rotate_params, rotate}, - {"bright", "alter image brightness", bright_params, bright}, + {"resize", "resize image by given ratio", resize_params, resize}, + {"scale", "scale image to given width and height", scale_params, scale}, + {"rotate", "rotate image", rotate_params, rotate}, + {"bright", "alter image brightness", bright_params, bright}, + {"contrast", "alter image contrast", contrast_params, contrast}, {NULL, NULL, NULL, NULL} };
@@ -341,7 +379,7 @@ static void apply_filters(GP_Context **src)
static const char *app_help = { " n" - " <-= Bitmap Grinder =-> n" + " <<<<<<<<<< Bitmap Grinder >>>>>>>>>>> n" " n" " +-+-----+ n" " / | +-+| .11. n" @@ -350,6 +388,7 @@ static const char *app_help = { " O=+ +-+-----+ .10110101. n" " .010101. n" " .1. n" + " n" " Program options n" " =============== n" " n" @@ -357,6 +396,16 @@ static const char *app_help = { "-v int - sets gfxprim verbosity level n" "-f params - apply filter, multiple filters may be usedn" " n" + " Example usage n" + " ============= n" + " n" + " grider -f resize:ratio=1.5 -f contrast:mul=1.2 in.pngn" + " n" + " * will resize image 1.5 times and increases contrast n" + " by 20%. The result is, just for now, saved to n" + " out_X.ppm where X is number which is increased for n" + " each image given as parameter. n" + " n" " List of filters n" " =============== n" }; diff --git a/demos/grinder/params.c b/demos/grinder/params.c index 827d3e9..d2dbfb9 100644 --- a/demos/grinder/params.c +++ b/demos/grinder/params.c @@ -215,9 +215,12 @@ int set_enum(int *res, char *val, const char *enums[]) return 1; }
-#define CALL_ERR_CALLBACK(error, p, value, private) do { - if (error != NULL) - error(p, value, private); +#define CALL_ERR_CALLBACK(error, p, value, private) do { + int error_ret; + + if (error != NULL) + if ((error_ret = error(p, value, private))) + return error_ret; } while (0)
int param_parse(const char *params, const struct param *param_desc, void *priv, @@ -242,6 +245,9 @@ int param_parse(const char *params, const struct param *param_desc, void *priv,
char *names[n]; char *values[n]; + int flags[n]; + + memset(flags, 0, sizeof(flags));
split_params(par, names); split_values(names, values, n); @@ -258,7 +264,9 @@ int param_parse(const char *params, const struct param *param_desc, void *priv, CALL_ERR_CALLBACK(err, ¶m_desc[i], "", priv); goto err; } - + + flags[pos]++; + switch (param_desc[i].type) { case PARAM_BOOL: @@ -291,7 +299,7 @@ int param_parse(const char *params, const struct param *param_desc, void *priv, }
if (param_desc[i].check != NULL) - if ((ret = param_desc[i].check(¶m_desc[i], arg))) { + if ((ret = param_desc[i].check(¶m_desc[i], arg, flags[i]))) { CALL_ERR_CALLBACK(err, ¶m_desc[i], values[pos], priv); goto err; @@ -300,6 +308,20 @@ int param_parse(const char *params, const struct param *param_desc, void *priv, } }
+ for (i = 0; i < n; i++) { + switch (flags[i]) { + /* unknown parameter passed */ + case 0: + CALL_ERR_CALLBACK(err, NULL, names[i], priv); + break; + case 1: + break; + /* parameter redefined */ + default: + break; + } + } + ret = 0; err: va_end(va); diff --git a/demos/grinder/params.h b/demos/grinder/params.h index e633c00..f726282 100644 --- a/demos/grinder/params.h +++ b/demos/grinder/params.h @@ -37,7 +37,8 @@ struct param { const char *desc; const char **enum_table;
- int (*check)(const struct param *self, void *val); + /* called after parameter is set */ + int (*check)(const struct param *self, void *val, int count); };
const char *param_type_name(enum param_type type);
http://repo.or.cz/w/gfxprim.git/commit/04b22f1283e5c809494415d1c35593ee38588...
commit 04b22f1283e5c809494415d1c35593ee3858884f Author: Cyril Hrubis metan@ucw.cz Date: Fri Sep 30 19:09:19 2011 +0200
Creates simple contrast filter.
* which wastly duplicates the code in brightness filter (we may create some python glue code for filter creation).
diff --git a/include/filters/GP_Linear.h b/include/filters/GP_Linear.h index 5465882..43b757c 100644 --- a/include/filters/GP_Linear.h +++ b/include/filters/GP_Linear.h @@ -22,6 +22,7 @@
/*
+ Standart point and linear filters.
*/
@@ -30,6 +31,20 @@
#include <GP_Context.h>
+/* + * Brightness (point) filter. + */ +void GP_FilterBrightness_Raw(const GP_Context *src, GP_Context *res, + int32_t inc); + GP_Context *GP_FilterBrightness(const GP_Context *src, int32_t inc);
+/* + * Contrast (point) filter. + */ +GP_Context *GP_FilterContrast_Raw(const GP_Context *src, GP_Context *res, + float mul); + +GP_Context *GP_FilterContrast(const GP_Context *src, float mul); + #endif /* GP_LINEAR_H */ diff --git a/libs/filters/GP_Contrast.gen.c.t b/libs/filters/GP_Contrast.gen.c.t new file mode 100644 index 0000000..6ce18ba --- /dev/null +++ b/libs/filters/GP_Contrast.gen.c.t @@ -0,0 +1,91 @@ +%% extends "base.c.t" + +%% block descr +Contrast filters -- Multiply all color channels by a fixed value. +%% endblock + +%% block body +#include <GP_Context.h> +#include <GP_Pixel.h> +#include <GP_GetPutPixel.h> + +/* + * Simple brightness operations for one channel bitmaps + */ +%% for ps in pixelsizes +%% if ps.size <= 8 and ps.size > 1 +void GP_FilterContrast_{{ ps.suffix }}(const GP_Context *src, GP_Context *res, float mul) +{ + uint32_t x, y; + + for (y = 0; y < src->h; y++) + for (x = 0; x < src->w; x++) { + int32_t pix = GP_GetPixel_Raw_{{ ps.suffix }}(src, x, y) * mul + 0.5; + + if (pix < 0) + pix = 0; + + if (pix > {{ 2 ** ps.size - 1 }}) + pix = {{ 2 ** ps.size - 1}}; + + GP_PutPixel_Raw_{{ ps.suffix }}(res, x, y, pix); + } +} + +%% endif +%% endfor + +/* + * Brightness filters for pixel types with more than one channels + */ +%% for pt in pixeltypes +%% if not pt.is_unknown() and len(pt.chanslist) > 1 +void GP_FilterContrast_{{ pt.name }}(const GP_Context *src, GP_Context *res, float mul) +{ + uint32_t x, y; + + for (y = 0; y < src->h; y++) + for (x = 0; x < src->w; x++) { + GP_Pixel pix = GP_GetPixel_Raw_{{ pt.pixelsize.suffix }}(src, x, y); + %% for c in pt.chanslist + int32_t {{ c[0] }} = GP_Pixel_GET_{{ c[0] }}_{{ pt.name }}(pix) * mul + 0.5; + %% endfor + + %% for c in pt.chanslist + if ({{ c[0] }} < 0) + {{ c[0] }} = 0; + + if ({{ c[0] }} > {{ 2 ** c[2] - 1 }}) + {{ c[0] }} = 255; + + %% endfor + pix = GP_Pixel_CREATE_{{ pt.name }}({{ pt.chanslist[0][0] }}{% for c in pt.chanslist[1:] %}, {{ c[0] }}{% endfor %}); + + GP_PutPixel_Raw_{{ pt.pixelsize.suffix }}(res, x, y, pix); + } +} + +%% endif +%% endfor + +void GP_FilterContrast_Raw(const GP_Context *src, GP_Context *res, float mul) +{ + switch (src->pixel_type) { + %% for pt in pixeltypes + case GP_PIXEL_{{ pt.name }}: + %% if pt.is_unknown() or pt.pixelsize.size < 2 + return; + %% elif len(pt.chanslist) == 1: + GP_FilterContrast_{{ pt.pixelsize.suffix }}(src, res, mul); + %% else + GP_FilterContrast_{{ pt.name }}(src, res, mul); + %% endif + break; + %% endfor + default: + break; + } +} + + +%% endblock body diff --git a/libs/filters/GP_Linear.c b/libs/filters/GP_Linear.c index 50ec525..beed134 100644 --- a/libs/filters/GP_Linear.c +++ b/libs/filters/GP_Linear.c @@ -27,11 +27,13 @@
#include "GP_Linear.h"
-void GP_FilterBrightness_Raw(const GP_Context *src, GP_Context *res, int32_t inc); - GP_Context *GP_FilterBrightness(const GP_Context *src, int32_t inc) { - GP_Context *res = GP_ContextCopy(src, 0); + GP_Context *res; + + GP_DEBUG(1, "Running Brightness filter with inc=%i", (int)inc); + + res = GP_ContextCopy(src, 0);
if (res == NULL) return NULL; @@ -40,3 +42,19 @@ GP_Context *GP_FilterBrightness(const GP_Context *src, int32_t inc)
return res; } + +GP_Context *GP_FilterContrast(const GP_Context *src, float mul) +{ + GP_Context *res; + + GP_DEBUG(1, "Running Contrast filter with mul=%2.2f", mul); + + res = GP_ContextCopy(src, 0); + + if (res == NULL) + return NULL; + + GP_FilterContrast_Raw(src, res, mul); + + return res; +} diff --git a/libs/filters/Makefile b/libs/filters/Makefile index 6f48556..0708ef6 100644 --- a/libs/filters/Makefile +++ b/libs/filters/Makefile @@ -1,5 +1,5 @@ TOPDIR=../.. -GENSOURCES=GP_Brightness.gen.c +GENSOURCES=GP_Brightness.gen.c GP_Contrast.gen.c GENHEADERS= CSOURCES=$(filter-out $(wildcard *.gen.c),$(wildcard *.c)) LIBNAME=filters
-----------------------------------------------------------------------
Summary of changes: demos/grinder/grinder.c | 81 ++++++++++++--- demos/grinder/params.c | 32 +++++- demos/grinder/params.h | 3 +- include/filters/GP_Filters.h | 2 +- include/filters/GP_Linear.h | 35 ------ .../GP_Linear.c => include/filters/GP_Point.h | 39 +++++-- libs/filters/GP_Brightness.gen.c.t | 87 ++-------------- libs/filters/GP_Contrast.gen.c.t | 24 +++++ libs/filters/GP_Invert.gen.c.t | 22 ++++ libs/filters/Makefile | 4 +- pylib/templates/filter.point.c.t | 109 ++++++++++++++++++++ 11 files changed, 293 insertions(+), 145 deletions(-) delete mode 100644 include/filters/GP_Linear.h rename libs/filters/GP_Linear.c => include/filters/GP_Point.h (76%) create mode 100644 libs/filters/GP_Contrast.gen.c.t create mode 100644 libs/filters/GP_Invert.gen.c.t create mode 100644 pylib/templates/filter.point.c.t
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.