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 generate updated: 7765fb749d234f875480769baba4b8c3c4919a0d
by metan 01 Oct '11
by metan 01 Oct '11
01 Oct '11
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 7765fb749d234f875480769baba4b8c3c4919a0d (commit)
from 8c9174cab63f49a6239b64579244425a384520c1 (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/7765fb749d234f875480769baba4b8c3c491…
commit 7765fb749d234f875480769baba4b8c3c4919a0d
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Fri Sep 30 23:56:28 2011 +0200
Some bicubic parameters fine tuning.
The artifact on the image border seems solved now.
diff --git a/libs/filters/GP_Scale.c b/libs/filters/GP_Scale.c
index e0ff64b..88c14a9 100644
--- a/libs/filters/GP_Scale.c
+++ b/libs/filters/GP_Scale.c
@@ -104,10 +104,10 @@ GP_Context *GP_Scale_BiCubic(GP_Context *src, GP_Size w, GP_Size h)
1.00 * w / src->w, 1.00 * h / src->h);
for (i = 0; i < w; i++) {
- float x = (1.00 * i / w) * src->w + 0.5;
+ float x = (1.00 * i / w) * (src->w - 4.5) + 2.5;
v4f cvx;
int xi = x - 1;
-
+
cvx.f[0] = cubic(x - xi);
cvx.f[1] = cubic(x - xi - 1);
cvx.f[2] = cubic(x - xi - 2);
@@ -155,7 +155,7 @@ GP_Context *GP_Scale_BiCubic(GP_Context *src, GP_Size w, GP_Size h)
/* now interpolate column for new image */
for (j = 0; j < h; j++) {
- float y = (1.00 * j / h) * src->h + 0.5;
+ float y = (1.00 * j / h) * (src->h - 4.5) + 2.5;
v4f cvy, rv, gv, bv;
float r, g, b;
int yi = y - 1;
-----------------------------------------------------------------------
Summary of changes:
libs/filters/GP_Scale.c | 6 +++---
1 files changed, 3 insertions(+), 3 deletions(-)
repo.or.cz automatic notification. Contact project admin jiri.bluebear.dluhos(a)gmail.com
if you want to unsubscribe, or site admin admin(a)repo.or.cz if you receive
no reply.
--
gfxprim.git ("A simple 2D graphics library with emphasis on correctness and well-defined operation.")
1
0
[repo.or.cz] gfxprim.git branch generate updated: 8c9174cab63f49a6239b64579244425a384520c1
by metan 30 Sep '11
by metan 30 Sep '11
30 Sep '11
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/8c9174cab63f49a6239b64579244425a3845…
commit 8c9174cab63f49a6239b64579244425a384520c1
Author: Cyril Hrubis <metan(a)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/661f7dd456af5304f88364a49f445b0dd03b…
commit 661f7dd456af5304f88364a49f445b0dd03bdf5c
Author: Cyril Hrubis <metan(a)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(a)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/1230c9066f4c5ac5d38991896e6795ae5f0d…
commit 1230c9066f4c5ac5d38991896e6795ae5f0d0c0e
Author: Cyril Hrubis <metan(a)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/04b22f1283e5c809494415d1c35593ee3858…
commit 04b22f1283e5c809494415d1c35593ee3858884f
Author: Cyril Hrubis <metan(a)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(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 generate updated: 63b5c2d57786aff8babac4c17c5fc5996c33cd4a
by metan 29 Sep '11
by metan 29 Sep '11
29 Sep '11
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 63b5c2d57786aff8babac4c17c5fc5996c33cd4a (commit)
from 36c8c982d2d3a3f672a293664a04e7a0491a6a97 (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/63b5c2d57786aff8babac4c17c5fc5996c33…
commit 63b5c2d57786aff8babac4c17c5fc5996c33cd4a
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Thu Sep 29 02:19:56 2011 +0200
Help is autogenerated from parameter descriptions.
diff --git a/demos/grinder/grinder.c b/demos/grinder/grinder.c
index a4ef8c5..3d099b2 100644
--- a/demos/grinder/grinder.c
+++ b/demos/grinder/grinder.c
@@ -76,9 +76,9 @@ static int resize_check_ratio(const struct param *self __attribute__((unused)),
}
static struct param resize_params[] = {
- {"alg", PARAM_ENUM, resize_algs, NULL},
- {"ratio", PARAM_FLOAT, NULL, resize_check_ratio},
- {NULL, 0, NULL, NULL}
+ {"alg", PARAM_ENUM, "algorithm to be used", resize_algs, NULL},
+ {"ratio", PARAM_FLOAT, "scale ratio", NULL, resize_check_ratio},
+ {NULL, 0, NULL, NULL, NULL}
};
static GP_RetCode resize(GP_Context **c, const char *params)
@@ -137,10 +137,10 @@ static int scale_check_size(const struct param *self __attribute__((unused)),
}
static struct param scale_params[] = {
- {"alg", PARAM_ENUM, scale_algs, NULL},
- {"w", PARAM_INT, NULL, scale_check_size},
- {"h", PARAM_INT, NULL, scale_check_size},
- {NULL, 0, NULL, NULL}
+ {"alg", PARAM_ENUM, "algorithm to be used", scale_algs, NULL},
+ {"w", PARAM_INT, "new width", NULL, scale_check_size},
+ {"h", PARAM_INT, "new height", NULL, scale_check_size},
+ {NULL, 0, NULL, NULL, NULL}
};
static GP_RetCode scale(GP_Context **c, const char *params)
@@ -187,8 +187,8 @@ static const char *rotate_rots[] = {
};
static struct param rotate_params[] = {
- {"rot", PARAM_ENUM, rotate_rots, NULL},
- {NULL, 0, NULL, NULL}
+ {"rot", PARAM_ENUM, "image rotation", rotate_rots, NULL},
+ {NULL, 0, NULL, NULL, NULL}
};
static GP_RetCode rotate(GP_Context **c, const char *params)
@@ -222,8 +222,8 @@ static GP_RetCode rotate(GP_Context **c, const char *params)
/* brightness filter */
static struct param bright_params[] = {
- {"val", PARAM_INT, NULL, NULL},
- {NULL, 0, NULL, NULL}
+ {"val", PARAM_INT, "brightness increment", NULL, NULL},
+ {NULL, 0, NULL, NULL, NULL}
};
static GP_RetCode bright(GP_Context **c, const char *params)
@@ -252,17 +252,18 @@ static GP_RetCode bright(GP_Context **c, const char *params)
/* filters */
struct filter {
- char *name;
- char *param_help;
+ const char *name;
+ const char *desc;
+ struct param *param_desc;
GP_RetCode (*apply)(GP_Context **c, const char *params);
};
static struct filter filter_table[] = {
- {"resize", "alg=nn|cubic:ratio=float", resize},
- {"scale", "alg=nn|cubic:w=int:h=int", scale},
- {"rotate", "rot=90|180|270", rotate},
- {"bright", "val=int", bright},
- {NULL, NULL, NULL}
+ {"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},
+ {NULL, NULL, NULL, NULL}
};
static struct filter *get_filter(const char *name)
@@ -277,13 +278,24 @@ static struct filter *get_filter(const char *name)
return NULL;
}
-static void print_filter_help(const char *prefix)
+static void print_filter_help(void)
{
- unsigned int i;
+ unsigned int i, j;
for (i = 0; filter_table[i].name != NULL; i++) {
- printf("%s%s : %sn", prefix, filter_table[i].name,
- filter_table[i].param_help);
+ printf("%sn", filter_table[i].name);
+
+ j = strlen(filter_table[i].name);
+
+ while (j--)
+ putchar('-');
+ putchar('n');
+
+ printf("* %sn", filter_table[i].desc);
+ putchar('n');
+
+ param_describe(filter_table[i].param_desc, " ");
+ putchar('n');
}
}
@@ -328,19 +340,31 @@ static void apply_filters(GP_Context **src)
}
static const char *app_help = {
- " <- Bitmap Grinder -> n"
" n"
- "-h : prints this help n"
- "-v int : sets gfxprim verbosity level n"
- "-f params : apply filter, multiple filters may be usedn"
+ " <-= Bitmap Grinder =-> n"
+ " n"
+ " +-+-----+ n"
+ " / | +-+| .11. n"
+ " +-{ D| |010101011. n"
+ " | \ | +-.0100101. n"
+ " O=+ +-+-----+ .10110101. n"
+ " .010101. n"
+ " .1. n"
+ " Program options n"
+ " =============== n"
+ " n"
+ "-h - prints this help n"
+ "-v int - sets gfxprim verbosity level n"
+ "-f params - apply filter, multiple filters may be usedn"
" n"
" List of filters n"
+ " =============== n"
};
static void print_help(void)
{
puts(app_help);
- print_filter_help(" ");
+ print_filter_help();
}
int main(int argc, char *argv[])
diff --git a/demos/grinder/params.c b/demos/grinder/params.c
index 1c02b7d..827d3e9 100644
--- a/demos/grinder/params.c
+++ b/demos/grinder/params.c
@@ -45,6 +45,58 @@ const char *param_type_name(enum param_type type)
return param_type_names[type];
}
+static const char *param_type_names_padd[] = {
+ "bool ",
+ "integer",
+ "float ",
+ "string ",
+ "enum ",
+};
+
+static void padd(unsigned int n)
+{
+ while (n--)
+ putchar(' ');
+}
+
+
+static void print_enum(const char *enum_table[])
+{
+ unsigned int i;
+
+ printf(" = [");
+
+ for (i = 0; enum_table[i] != NULL; i++)
+ if (enum_table[i+1] == NULL)
+ printf("%s]", enum_table[i]);
+ else
+ printf("%s | ", enum_table[i]);
+}
+
+void param_describe(const struct param *param_desc, const char *prefix)
+{
+ unsigned int i, len = 0, l;
+
+ for (i = 0; param_desc[i].name != NULL; i++) {
+ l = strlen(param_desc[i].name);
+
+ if (l > len)
+ len = l;
+ }
+
+ for (i = 0; param_desc[i].name != NULL; i++) {
+ printf("%s%s", prefix, param_desc[i].name);
+ padd(len - strlen(param_desc[i].name));
+ printf(" : %s", param_type_names_padd[param_desc[i].type]);
+ printf(" - %s", param_desc[i].desc);
+
+ if (param_desc[i].type == PARAM_ENUM)
+ print_enum(param_desc[i].enum_table);
+
+ printf("n");
+ }
+}
+
static unsigned int count_params(const char *params)
{
unsigned int ret = 1, i;
diff --git a/demos/grinder/params.h b/demos/grinder/params.h
index 3efea7d..e633c00 100644
--- a/demos/grinder/params.h
+++ b/demos/grinder/params.h
@@ -34,6 +34,7 @@ enum param_type {
struct param {
const char *name;
enum param_type type;
+ const char *desc;
const char **enum_table;
int (*check)(const struct param *self, void *val);
@@ -41,6 +42,8 @@ struct param {
const char *param_type_name(enum param_type type);
+void param_describe(const struct param *param_desc, const char *prefix);
+
int param_parse(const char *params, const struct param *param_desc, void *priv,
int (*err)(const struct param *self, const char *val, void *priv), ...);
-----------------------------------------------------------------------
Summary of changes:
demos/grinder/grinder.c | 78 ++++++++++++++++++++++++++++++----------------
demos/grinder/params.c | 52 +++++++++++++++++++++++++++++++
demos/grinder/params.h | 3 ++
3 files changed, 106 insertions(+), 27 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 generate updated: 36c8c982d2d3a3f672a293664a04e7a0491a6a97
by metan 28 Sep '11
by metan 28 Sep '11
28 Sep '11
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 36c8c982d2d3a3f672a293664a04e7a0491a6a97 (commit)
from a26eff704d1d896d04efccb273cab42593b9efde (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/36c8c982d2d3a3f672a293664a04e7a0491a…
commit 36c8c982d2d3a3f672a293664a04e7a0491a6a97
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Thu Sep 29 01:14:00 2011 +0200
grinder: far better parameter checks and error messages.
diff --git a/demos/grinder/grinder.c b/demos/grinder/grinder.c
index 73c2d4b..a4ef8c5 100644
--- a/demos/grinder/grinder.c
+++ b/demos/grinder/grinder.c
@@ -29,6 +29,33 @@
#include "params.h"
+static int param_err(const struct param *self, const char *val, void *priv)
+{
+ fprintf(stderr, "ERROR: %s: invalid %s parameter %s = '%s'",
+ (char *)priv, param_type_name(self->type), self->name, val);
+
+ if (self->type == PARAM_ENUM) {
+ unsigned int i;
+
+ fprintf(stderr, " is not in [");
+
+ for (i = 0; self->enum_table[i] != NULL; i++)
+ if (self->enum_table[i+1] == NULL)
+ fprintf(stderr, "'%s']", self->enum_table[i]);
+ else
+ fprintf(stderr, "'%s' | ", self->enum_table[i]);
+ }
+
+ fprintf(stderr, "n");
+
+ return 1;
+}
+
+static void print_error(const char *error)
+{
+ fprintf(stderr, "ERROR: %sn", error);
+}
+
/* resize filter */
static const char *resize_algs[] = {
@@ -37,10 +64,21 @@ static const char *resize_algs[] = {
NULL
};
+static int resize_check_ratio(const struct param *self __attribute__((unused)),
+ void *val)
+{
+ float f = *((float*)val);
+
+ if (f <= 0)
+ return -1;
+
+ return 0;
+}
+
static struct param resize_params[] = {
{"alg", PARAM_ENUM, resize_algs, NULL},
- {"ratio", PARAM_FLOAT, NULL, NULL},
- {NULL, 0, NULL, NULL}
+ {"ratio", PARAM_FLOAT, NULL, resize_check_ratio},
+ {NULL, 0, NULL, NULL}
};
static GP_RetCode resize(GP_Context **c, const char *params)
@@ -48,10 +86,14 @@ static GP_RetCode resize(GP_Context **c, const char *params)
int alg = 1;
float ratio = -1;
- param_parse(params, resize_params, &alg, &ratio);
+ if (param_parse(params, resize_params, "resize", param_err,
+ &alg, &ratio))
+ return GP_EINVAL;
- if (ratio == -1)
+ if (ratio == -1) {
+ print_error("resize: ratio parameter is missing");
return GP_EINVAL;
+ }
GP_Size w = ratio * (*c)->w;
GP_Size h = ratio * (*c)->h;
@@ -107,10 +149,14 @@ static GP_RetCode scale(GP_Context **c, const char *params)
int w = -1;
int h = -1;
- param_parse(params, scale_params, &alg, &w, &h);
+ if (param_parse(params, scale_params, "scale", param_err,
+ &alg, &w, &h))
+ return GP_EINVAL;
- if (w == -1 || h == -1)
+ if (w == -1 || h == -1) {
+ print_error("scale: w and/or h missing");
return GP_EINVAL;
+ }
GP_Context *res = NULL;
@@ -149,10 +195,13 @@ static GP_RetCode rotate(GP_Context **c, const char *params)
{
int rot = -1;
- param_parse(params, rotate_params, &rot);
+ if (param_parse(params, rotate_params, "rotate", param_err, &rot))
+ return GP_EINVAL;
- if (rot == -1)
+ if (rot == -1) {
+ print_error("rotate: rot parameter is missing");
return GP_EINVAL;
+ }
switch (rot) {
case 0:
@@ -160,6 +209,7 @@ static GP_RetCode rotate(GP_Context **c, const char *params)
break;
case 1:
GP_MirrorV(*c);
+ GP_MirrorH(*c);
break;
case 2:
GP_RotateCCW(*c);
@@ -180,7 +230,13 @@ static GP_RetCode bright(GP_Context **c, const char *params)
{
int bright = 0;
- param_parse(params, bright_params, &bright);
+ if (param_parse(params, bright_params, "bright", param_err, &bright))
+ return GP_EINVAL;
+
+ if (bright == 0) {
+ print_error("bright: bright parameter is zero or missing");
+ return GP_EINVAL;
+ }
GP_Context *res = GP_FilterBrightness(*c, bright);
diff --git a/demos/grinder/params.c b/demos/grinder/params.c
index 405c8bd..1c02b7d 100644
--- a/demos/grinder/params.c
+++ b/demos/grinder/params.c
@@ -25,9 +25,26 @@
#include <ctype.h>
#include <stdlib.h>
#include <stdarg.h>
+#include <errno.h>
#include "params.h"
+static const char *param_type_names[] = {
+ "bool",
+ "integer",
+ "float",
+ "string",
+ "enum",
+};
+
+const char *param_type_name(enum param_type type)
+{
+ if (type > PARAM_ENUM)
+ return NULL;
+
+ return param_type_names[type];
+}
+
static unsigned int count_params(const char *params)
{
unsigned int ret = 1, i;
@@ -97,16 +114,38 @@ int param_pos(char *names[], const char *name, unsigned int start, unsigned int
int set_int(int *res, char *val)
{
- //TODO: error checks
- *res = atoi(val);
+ long l;
+ char *end;
+
+ errno = 0;
+ l = strtol(val, &end, 0);
+
+ if (*end != '0')
+ return 1;
+
+ if (errno != 0)
+ return 1;
+
+ *res = l;
return 0;
}
int set_float(float *res, char *val)
{
- //TODO: error checks
- *res = atof(val);
+ char *end;
+ float f;
+
+ errno = 0;
+ f = strtof(val, &end);
+
+ if (*end != '0')
+ return 1;
+
+ if (errno != 0)
+ return 1;
+
+ *res = f;
return 0;
}
@@ -124,11 +163,23 @@ int set_enum(int *res, char *val, const char *enums[])
return 1;
}
-int param_parse(const char *params, const struct param *param_desc, ...)
+#define CALL_ERR_CALLBACK(error, p, value, private) do { + if (error != NULL) + error(p, value, private); +} while (0)
+
+int param_parse(const char *params, const struct param *param_desc, void *priv,
+ int (*err)(const struct param *self, const char *val, void *priv), ...)
{
- char *par = strdup(params);
+ char *par;
unsigned int n, i;
va_list va;
+ int ret;
+
+ if (params == NULL || *params == '0')
+ return 0;
+
+ par = strdup(params);
if (par == NULL) {
fprintf(stderr, "Malloc failed :(n");
@@ -143,43 +194,63 @@ int param_parse(const char *params, const struct param *param_desc, ...)
split_params(par, names);
split_values(names, values, n);
- va_start(va, param_desc);
+ va_start(va, err);
for (i = 0; param_desc[i].name != NULL; i++) {
void *arg = va_arg(va, void*);
- int pos = 0, ret;
+ int pos = 0;
while ((pos = param_pos(names, param_desc[i].name, pos, n)) >= 0) {
+
+ if (values[pos] == NULL || *values[pos] == '0') {
+ CALL_ERR_CALLBACK(err, ¶m_desc[i], "", priv);
+ goto err;
+ }
+
switch (param_desc[i].type) {
case PARAM_BOOL:
break;
case PARAM_INT:
- if ((ret = set_int(arg, values[pos])))
- return ret;
+ if ((ret = set_int(arg, values[pos]))) {
+ CALL_ERR_CALLBACK(err, ¶m_desc[i],
+ values[pos], priv);
+ goto err;
+ }
break;
case PARAM_FLOAT:
- if ((ret = set_float(arg, values[pos])))
- return ret;
+ if ((ret = set_float(arg, values[pos]))) {
+ CALL_ERR_CALLBACK(err, ¶m_desc[i],
+ values[pos], priv);
+ goto err;
+ }
break;
case PARAM_STR:
break;
case PARAM_ENUM:
if ((ret = set_enum(arg, values[pos],
- param_desc[i].enum_table)))
- return ret;
+ param_desc[i].enum_table))) {
+ CALL_ERR_CALLBACK(err, ¶m_desc[i],
+ values[pos], priv);
+ goto err;
+ }
break;
}
if (param_desc[i].check != NULL)
- param_desc[i].check(¶m_desc[i], arg);
+ if ((ret = param_desc[i].check(¶m_desc[i], arg))) {
+ CALL_ERR_CALLBACK(err, ¶m_desc[i],
+ values[pos], priv);
+ goto err;
+ }
pos++;
}
}
+ ret = 0;
+err:
va_end(va);
free(par);
-
- return 0;
+ return ret;
}
diff --git a/demos/grinder/params.h b/demos/grinder/params.h
index f397bb7..3efea7d 100644
--- a/demos/grinder/params.h
+++ b/demos/grinder/params.h
@@ -39,6 +39,9 @@ struct param {
int (*check)(const struct param *self, void *val);
};
-int param_parse(const char *params, const struct param *param_desc, ...);
+const char *param_type_name(enum param_type type);
+
+int param_parse(const char *params, const struct param *param_desc, void *priv,
+ int (*err)(const struct param *self, const char *val, void *priv), ...);
#endif /* PARAMS_H */
-----------------------------------------------------------------------
Summary of changes:
demos/grinder/grinder.c | 74 +++++++++++++++++++++++++++++----
demos/grinder/params.c | 105 +++++++++++++++++++++++++++++++++++++++--------
demos/grinder/params.h | 5 ++-
3 files changed, 157 insertions(+), 27 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 generate updated: a26eff704d1d896d04efccb273cab42593b9efde
by metan 28 Sep '11
by metan 28 Sep '11
28 Sep '11
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 a26eff704d1d896d04efccb273cab42593b9efde (commit)
from 8bed60585798f64bb79328f012a738f44746cc81 (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/a26eff704d1d896d04efccb273cab42593b9…
commit a26eff704d1d896d04efccb273cab42593b9efde
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Wed Sep 28 23:30:03 2011 +0200
Added grinder demo on gfxprim bitmap filters.
diff --git a/Makefile b/Makefile
index fac8f9b..5c4d45f 100644
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,5 @@
TOPDIR=.
-SUBDIRS=libs tests pylib
+SUBDIRS=libs tests pylib demos
include include.mk
#
diff --git a/demos/Makefile b/demos/Makefile
new file mode 100644
index 0000000..571580a
--- /dev/null
+++ b/demos/Makefile
@@ -0,0 +1,3 @@
+TOPDIR=..
+SUBDIRS=grinder
+include $(TOPDIR)/include.mk
diff --git a/demos/grinder/Makefile b/demos/grinder/Makefile
new file mode 100644
index 0000000..7cf1e72
--- /dev/null
+++ b/demos/grinder/Makefile
@@ -0,0 +1,13 @@
+TOPDIR=../..
+
+CSOURCES=$(shell echo *.c)
+
+INCLUDE=core gfx SDL backends
+LDLIBS+=-lGP -L$(TOPDIR)/build/ -lpng
+
+APPS=grinder
+
+grinder: params.o
+
+include $(TOPDIR)/include.mk
+include $(TOPDIR)/app.mk
diff --git a/demos/grinder/README b/demos/grinder/README
new file mode 100644
index 0000000..749485f
--- /dev/null
+++ b/demos/grinder/README
@@ -0,0 +1,12 @@
+BITMAP GRINDER
+~~~~~~~~~~~~~~
+
+Simple utility to load image, apply gfxprim filters and save result.
+
+The usage is:
+
+grinder -f filter_name:filter_params... -f filter_name:filter_params... -f filter_name:filter_params... image1 image2 ...
+
+Which will apply pipeline of filters to each image and store results to out_X.ppm
+
+see grinder -h for list of filters and options
diff --git a/demos/grinder/grinder.c b/demos/grinder/grinder.c
new file mode 100644
index 0000000..73c2d4b
--- /dev/null
+++ b/demos/grinder/grinder.c
@@ -0,0 +1,343 @@
+/*****************************************************************************
+ * 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(a)ucw.cz> *
+ * *
+ *****************************************************************************/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+
+#include "GP.h"
+
+#include "params.h"
+
+/* resize filter */
+
+static const char *resize_algs[] = {
+ "nn",
+ "cubic",
+ NULL
+};
+
+static struct param resize_params[] = {
+ {"alg", PARAM_ENUM, resize_algs, NULL},
+ {"ratio", PARAM_FLOAT, NULL, NULL},
+ {NULL, 0, NULL, NULL}
+};
+
+static GP_RetCode resize(GP_Context **c, const char *params)
+{
+ int alg = 1;
+ float ratio = -1;
+
+ param_parse(params, resize_params, &alg, &ratio);
+
+ if (ratio == -1)
+ return GP_EINVAL;
+
+ GP_Size w = ratio * (*c)->w;
+ GP_Size h = ratio * (*c)->h;
+ GP_Context *res = NULL;
+
+ switch (alg) {
+ case 0:
+ res = GP_Scale_NN(*c, w, h);
+ break;
+ case 1:
+ res = GP_Scale_BiCubic(*c, w, h);
+ break;
+ }
+
+ if (res == NULL)
+ return GP_EINVAL;
+
+ GP_ContextFree(*c);
+ *c = res;
+
+ return GP_ESUCCESS;
+}
+
+/* scale filter */
+
+static const char *scale_algs[] = {
+ "nn",
+ "cubic",
+ NULL
+};
+
+static int scale_check_size(const struct param *self __attribute__((unused)),
+ void *val)
+{
+ int i = *((int*)val);
+
+ if (i <= 0)
+ return 1;
+
+ return 0;
+}
+
+static struct param scale_params[] = {
+ {"alg", PARAM_ENUM, scale_algs, NULL},
+ {"w", PARAM_INT, NULL, scale_check_size},
+ {"h", PARAM_INT, NULL, scale_check_size},
+ {NULL, 0, NULL, NULL}
+};
+
+static GP_RetCode scale(GP_Context **c, const char *params)
+{
+ int alg = 1;
+ int w = -1;
+ int h = -1;
+
+ param_parse(params, scale_params, &alg, &w, &h);
+
+ if (w == -1 || h == -1)
+ return GP_EINVAL;
+
+ GP_Context *res = NULL;
+
+ switch (alg) {
+ case 0:
+ res = GP_Scale_NN(*c, w, h);
+ break;
+ case 1:
+ res = GP_Scale_BiCubic(*c, w, h);
+ break;
+ }
+
+ if (res == NULL)
+ return GP_EINVAL;
+
+ GP_ContextFree(*c);
+ *c = res;
+
+ return GP_ESUCCESS;
+}
+
+/* rotate filter */
+
+static const char *rotate_rots[] = {
+ "90",
+ "180",
+ "270",
+};
+
+static struct param rotate_params[] = {
+ {"rot", PARAM_ENUM, rotate_rots, NULL},
+ {NULL, 0, NULL, NULL}
+};
+
+static GP_RetCode rotate(GP_Context **c, const char *params)
+{
+ int rot = -1;
+
+ param_parse(params, rotate_params, &rot);
+
+ if (rot == -1)
+ return GP_EINVAL;
+
+ switch (rot) {
+ case 0:
+ GP_RotateCW(*c);
+ break;
+ case 1:
+ GP_MirrorV(*c);
+ break;
+ case 2:
+ GP_RotateCCW(*c);
+ break;
+ }
+
+ return GP_ESUCCESS;
+}
+
+/* brightness filter */
+
+static struct param bright_params[] = {
+ {"val", PARAM_INT, NULL, NULL},
+ {NULL, 0, NULL, NULL}
+};
+
+static GP_RetCode bright(GP_Context **c, const char *params)
+{
+ int bright = 0;
+
+ param_parse(params, bright_params, &bright);
+
+ GP_Context *res = GP_FilterBrightness(*c, bright);
+
+ if (res == NULL)
+ return GP_EINVAL;
+
+ GP_ContextFree(*c);
+ *c = res;
+
+ return GP_ESUCCESS;
+}
+
+/* filters */
+
+struct filter {
+ char *name;
+ char *param_help;
+ GP_RetCode (*apply)(GP_Context **c, const char *params);
+};
+
+static struct filter filter_table[] = {
+ {"resize", "alg=nn|cubic:ratio=float", resize},
+ {"scale", "alg=nn|cubic:w=int:h=int", scale},
+ {"rotate", "rot=90|180|270", rotate},
+ {"bright", "val=int", bright},
+ {NULL, NULL, NULL}
+};
+
+static struct filter *get_filter(const char *name)
+{
+ unsigned int i;
+
+ for (i = 0; filter_table[i].name != NULL; i++) {
+ if (!strcasecmp(filter_table[i].name, name))
+ return &filter_table[i];
+ }
+
+ return NULL;
+}
+
+static void print_filter_help(const char *prefix)
+{
+ unsigned int i;
+
+ for (i = 0; filter_table[i].name != NULL; i++) {
+ printf("%s%s : %sn", prefix, filter_table[i].name,
+ filter_table[i].param_help);
+ }
+}
+
+/* application */
+
+#define FILTERS_MAX 255
+
+static const char *filter_params[FILTERS_MAX];
+static const struct filter *filters[FILTERS_MAX];
+static unsigned int filter_cnt = 0;
+
+static void add_filter(char *params)
+{
+ if (filter_cnt >= FILTERS_MAX) {
+ fprintf(stderr, "Maximal number of filters exceeded (%u), "
+ "increase and recompile.", FILTERS_MAX);
+ exit(1);
+ }
+
+ const char *name = strsep(¶ms, ":");
+
+ filters[filter_cnt] = get_filter(name);
+
+ if (filters[filter_cnt] == NULL) {
+ fprintf(stderr, "Invalid filter name '%s'n", name);
+ exit(1);
+ }
+
+ filter_params[filter_cnt++] = params;
+}
+
+static void apply_filters(GP_Context **src)
+{
+ unsigned int i;
+ GP_RetCode ret;
+
+ for (i = 0; i < filter_cnt; i++)
+ if ((ret = filters[i]->apply(src, filter_params[i]))) {
+ fprintf(stderr, "Error: %sn", GP_RetCodeName(ret));
+ exit(1);
+ }
+}
+
+static const char *app_help = {
+ " <- Bitmap Grinder -> n"
+ " n"
+ "-h : prints this help n"
+ "-v int : sets gfxprim verbosity level n"
+ "-f params : apply filter, multiple filters may be usedn"
+ " n"
+ " List of filters n"
+};
+
+static void print_help(void)
+{
+ puts(app_help);
+ print_filter_help(" ");
+}
+
+int main(int argc, char *argv[])
+{
+ GP_Context *bitmap;
+ GP_RetCode ret;
+ int opt, i;
+
+ while ((opt = getopt(argc, argv, "f:hv:")) != -1) {
+ switch (opt) {
+ case 'h':
+ print_help();
+ return 0;
+ break;
+ case 'v':
+ GP_SetDebugLevel(atoi(optarg));
+ break;
+ case 'f':
+ add_filter(optarg);
+ break;
+ default:
+ print_help();
+ return 1;
+ }
+ }
+
+ if (optind >= argc) {
+ fprintf(stderr, "Expected bitmap filenamesn");
+ print_help();
+ return 1;
+ }
+
+ for (i = optind; i < argc; i++) {
+ char buf[255];
+
+ snprintf(buf, sizeof(buf), "out_%i.ppm", i - optind + 1);
+ fprintf(stderr, "Processing '%s' -> '%s'n", argv[i], buf);
+
+ if ((ret = GP_LoadImage(argv[i], &bitmap))) {
+ fprintf(stderr, "Failed to load bitmap: %sn",
+ GP_RetCodeName(ret));
+ return 1;
+ }
+
+ apply_filters(&bitmap);
+
+
+ if ((ret = GP_SavePPM(buf, bitmap, "b"))) {
+ fprintf(stderr, "Failed to load bitmap: %sn", GP_RetCodeName(ret));
+ return 1;
+ }
+
+ }
+
+ return 0;
+}
diff --git a/demos/grinder/params.c b/demos/grinder/params.c
new file mode 100644
index 0000000..405c8bd
--- /dev/null
+++ b/demos/grinder/params.c
@@ -0,0 +1,185 @@
+/*****************************************************************************
+ * 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(a)ucw.cz> *
+ * *
+ *****************************************************************************/
+
+#include <stdio.h>
+#include <string.h>
+#include <ctype.h>
+#include <stdlib.h>
+#include <stdarg.h>
+
+#include "params.h"
+
+static unsigned int count_params(const char *params)
+{
+ unsigned int ret = 1, i;
+ char prev = ':';
+
+ for (i = 0; params[i] != '0'; i++) {
+
+ if (params[i] == ':' && prev != ':')
+ ret++;
+
+ prev = params[i];
+ }
+
+ return ret;
+}
+
+static void split_params(char *params, char **names)
+{
+ unsigned int i, n = 0;
+ char prev = ':';
+
+ for (i = 0; params[i] != '0'; i++) {
+
+ if (params[i] != ':' && prev == ':')
+ names[n++] = ¶ms[i];
+
+ prev = params[i];
+
+ if (params[i] == ':')
+ params[i] = '0';
+ }
+}
+
+static void do_split(char *param, char **value)
+{
+ unsigned int i;
+
+ *value = NULL;
+
+ for (i = 0; param[i] != '0'; i++) {
+
+ if (param[i] == '=' || isspace(param[i])) {
+ param[i] = '0';
+ *value = ¶m[i+1];
+ }
+ }
+}
+
+static void split_values(char **names, char **values, unsigned int n)
+{
+ unsigned int i;
+
+ for (i = 0; i < n; i++)
+ do_split(names[i], &values[i]);
+}
+
+int param_pos(char *names[], const char *name, unsigned int start, unsigned int n)
+{
+ unsigned int i;
+
+ for (i = start; i < n; i++)
+ if (!strcasecmp(names[i], name))
+ return i;
+
+ return -1;
+}
+
+int set_int(int *res, char *val)
+{
+ //TODO: error checks
+ *res = atoi(val);
+
+ return 0;
+}
+
+int set_float(float *res, char *val)
+{
+ //TODO: error checks
+ *res = atof(val);
+
+ return 0;
+}
+
+int set_enum(int *res, char *val, const char *enums[])
+{
+ unsigned int i;
+
+ for (i = 0; enums[i] != NULL; i++)
+ if (!strcasecmp(enums[i], val)) {
+ *res = i;
+ return 0;
+ }
+
+ return 1;
+}
+
+int param_parse(const char *params, const struct param *param_desc, ...)
+{
+ char *par = strdup(params);
+ unsigned int n, i;
+ va_list va;
+
+ if (par == NULL) {
+ fprintf(stderr, "Malloc failed :(n");
+ return 1;
+ }
+
+ n = count_params(params);
+
+ char *names[n];
+ char *values[n];
+
+ split_params(par, names);
+ split_values(names, values, n);
+
+ va_start(va, param_desc);
+
+ for (i = 0; param_desc[i].name != NULL; i++) {
+ void *arg = va_arg(va, void*);
+ int pos = 0, ret;
+
+ while ((pos = param_pos(names, param_desc[i].name, pos, n)) >= 0) {
+ switch (param_desc[i].type) {
+ case PARAM_BOOL:
+
+ break;
+ case PARAM_INT:
+ if ((ret = set_int(arg, values[pos])))
+ return ret;
+ break;
+ case PARAM_FLOAT:
+ if ((ret = set_float(arg, values[pos])))
+ return ret;
+ break;
+ case PARAM_STR:
+
+ break;
+ case PARAM_ENUM:
+ if ((ret = set_enum(arg, values[pos],
+ param_desc[i].enum_table)))
+ return ret;
+ break;
+ }
+
+ if (param_desc[i].check != NULL)
+ param_desc[i].check(¶m_desc[i], arg);
+ pos++;
+ }
+ }
+
+ va_end(va);
+ free(par);
+
+ return 0;
+}
diff --git a/demos/grinder/params.h b/demos/grinder/params.h
new file mode 100644
index 0000000..f397bb7
--- /dev/null
+++ b/demos/grinder/params.h
@@ -0,0 +1,44 @@
+/*****************************************************************************
+ * 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(a)ucw.cz> *
+ * *
+ *****************************************************************************/
+
+#ifndef PARAMS_H
+#define PARAMS_H
+
+enum param_type {
+ PARAM_BOOL,
+ PARAM_INT,
+ PARAM_FLOAT,
+ PARAM_STR,
+ PARAM_ENUM,
+};
+
+struct param {
+ const char *name;
+ enum param_type type;
+ const char **enum_table;
+
+ int (*check)(const struct param *self, void *val);
+};
+
+int param_parse(const char *params, const struct param *param_desc, ...);
+
+#endif /* PARAMS_H */
diff --git a/demos/grinder/runtest.sh b/demos/grinder/runtest.sh
new file mode 100755
index 0000000..73c9f61
--- /dev/null
+++ b/demos/grinder/runtest.sh
@@ -0,0 +1,10 @@
+#!/bin/bash
+#
+# Run dynamically linked test.
+#
+
+PROG="$1"
+shift
+
+echo "LD_LIBRARY_PATH=../../build/ ./$PROG $@"
+LD_LIBRARY_PATH=../../build/ ./$PROG $@
-----------------------------------------------------------------------
Summary of changes:
Makefile | 2 +-
{tests => demos}/Makefile | 2 +-
demos/grinder/Makefile | 13 +
demos/grinder/README | 12 +
demos/grinder/grinder.c | 343 ++++++++++++++++++++
demos/grinder/params.c | 185 +++++++++++
.../filters/GP_Linear.h => demos/grinder/params.h | 25 +-
{tests/SDL => demos/grinder}/runtest.sh | 0
8 files changed, 572 insertions(+), 10 deletions(-)
copy {tests => demos}/Makefile (53%)
create mode 100644 demos/grinder/Makefile
create mode 100644 demos/grinder/README
create mode 100644 demos/grinder/grinder.c
create mode 100644 demos/grinder/params.c
copy include/filters/GP_Linear.h => demos/grinder/params.h (82%)
copy {tests/SDL => demos/grinder}/runtest.sh (100%)
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 generate updated: 8bed60585798f64bb79328f012a738f44746cc81
by metan 28 Sep '11
by metan 28 Sep '11
28 Sep '11
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 8bed60585798f64bb79328f012a738f44746cc81 (commit)
from 688e786f9814c87a37a3dbb6d2d7e94b8d392674 (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/8bed60585798f64bb79328f012a738f44746…
commit 8bed60585798f64bb79328f012a738f44746cc81
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Wed Sep 28 18:55:44 2011 +0200
Some more cleanup and moving things back and forth.
diff --git a/include/filters/GP_Filters.h b/include/filters/GP_Filters.h
index 4575497..bbeb3eb 100644
--- a/include/filters/GP_Filters.h
+++ b/include/filters/GP_Filters.h
@@ -32,8 +32,12 @@
#ifndef GP_FILTERS_H
#define GP_FILTERS_H
-#include "GP_Rotate.h"
-#include "GP_Linear.h"
-#include "GP_Resize.h"
+/* Image rotations (90 180 270 grads) and mirroring */
+#include "filters/GP_Rotate.h"
+
+#include "filters/GP_Linear.h"
+
+/* Image down and up scaling */
+#include "filters/GP_Scale.h"
#endif /* GP_FILTERS_H */
diff --git a/include/filters/GP_Resize.h b/include/filters/GP_Scale.h
similarity index 75%
rename from include/filters/GP_Resize.h
rename to include/filters/GP_Scale.h
index c475645..06414c2 100644
--- a/include/filters/GP_Resize.h
+++ b/include/filters/GP_Scale.h
@@ -26,13 +26,27 @@
*/
-#ifndef GP_RESIZE_H
-#define GP_RESIZE_H
+#ifndef GP_SCALE_H
+#define GP_SCALE_H
#include "core/GP_Context.h"
-GP_Context *GP_ScaleDown(GP_Context *src);
+/*
+ * Nearest neighbour
+ *
+ * Faster than others, but produces pixelated images. Works however well for
+ * images with sharp edges mostly consisting of big once color parts (eg
+ * doesn't blurr the result on upscaling).
+ */
+GP_Context *GP_Scale_NN(GP_Context *src, GP_Size w, GP_Size h);
+
+/*
+ * Bicubic Scaling
+ *
+ * Works well for upscaling. Not so good for downscaling big images to small
+ * ones (looses too much information).
+ */
+GP_Context *GP_Scale_BiCubic(GP_Context *src, GP_Size w, GP_Size h);
-GP_Context *GP_Scale(GP_Context *src, GP_Size w, GP_Size h);
-#endif /* GP_RESIZE_H */
+#endif /* GP_SCALE_H */
diff --git a/libs/filters/GP_ScaleDown.c b/libs/filters/GP_Scale.c
similarity index 88%
rename from libs/filters/GP_ScaleDown.c
rename to libs/filters/GP_Scale.c
index 35210cc..e0ff64b 100644
--- a/libs/filters/GP_ScaleDown.c
+++ b/libs/filters/GP_Scale.c
@@ -25,27 +25,33 @@
#include <GP_Debug.h>
-#include <GP_Resize.h>
+#include <GP_Scale.h>
-GP_Context *GP_ScaleDown(GP_Context *src)
+
+GP_Context *GP_Scale_NN(GP_Context *src, GP_Size w, GP_Size h)
{
- uint32_t w, h, x, y;
GP_Context *dst;
if (src->pixel_type != GP_PIXEL_RGB888)
return NULL;
- w = src->w/2;
- h = src->h/2;
-
dst = GP_ContextAlloc(w, h, GP_PIXEL_RGB888);
if (dst == NULL)
return NULL;
- for (y = 0; y < h; y++)
- for (x = 0; x < w; x++) {
- GP_Pixel pix = GP_GetPixel_Raw_24BPP(src, 2*x, 2*y);
+ GP_DEBUG(1, "Scaling image %ux%u -> %ux%u %2.2f %2.2f",
+ src->w, src->h, w, h,
+ 1.00 * w / src->w, 1.00 * h / src->h);
+
+ GP_Coord x, y;
+
+ for (y = 0; y < (int)h; y++)
+ for (x = 0; x < (int)w; x++) {
+ GP_Coord xi = (1.00 * x / w) * src->w;
+ GP_Coord yi = (1.00 * y / h) * src->h;
+
+ GP_Pixel pix = GP_GetPixel_Raw_24BPP(src, xi, yi);
GP_PutPixel_Raw_24BPP(dst, x, y, pix);
}
@@ -79,7 +85,7 @@ typedef union v4f {
#define MUL_V4SF(a, b) ((union v4f)((a).v * (b).v))
#define SUM_V4SF(a) ((a).f[0] + (a).f[1] + (a).f[2] + (a).f[3])
-GP_Context *GP_Scale(GP_Context *src, GP_Size w, GP_Size h)
+GP_Context *GP_Scale_BiCubic(GP_Context *src, GP_Size w, GP_Size h)
{
GP_Context *dst;
float col_r[src->h], col_g[src->h], col_b[src->h];
@@ -93,6 +99,10 @@ GP_Context *GP_Scale(GP_Context *src, GP_Size w, GP_Size h)
if (dst == NULL)
return NULL;
+ GP_DEBUG(1, "Scaling image %ux%u -> %ux%u %2.2f %2.2f",
+ src->w, src->h, w, h,
+ 1.00 * w / src->w, 1.00 * h / src->h);
+
for (i = 0; i < w; i++) {
float x = (1.00 * i / w) * src->w + 0.5;
v4f cvx;
diff --git a/libs/loaders/GP_PPM.c b/libs/loaders/GP_PPM.c
index de6877e..106e78d 100644
--- a/libs/loaders/GP_PPM.c
+++ b/libs/loaders/GP_PPM.c
@@ -144,6 +144,8 @@ GP_RetCode GP_SavePPM(const char *res_path, GP_Context *src, char *fmt)
/* binary */
case 'b':
hfmt = '6';
+ GP_DEBUG(1, "Writing binary PPM %ux%u '%s'",
+ src->w, src->h, res_path);
break;
default:
return GP_ENOIMPL;
diff --git a/tests/SDL/scale_test.c b/tests/SDL/scale_test.c
index 4bfc0e8..aa026b9 100644
--- a/tests/SDL/scale_test.c
+++ b/tests/SDL/scale_test.c
@@ -45,7 +45,7 @@ int main(int argc, char *argv[])
w = atoi(argv[2]);
h = atoi(argv[3]);
- bitmap = GP_Scale(bitmap, w, h);
+ bitmap = GP_Scale_BiCubic(bitmap, w, h);
if ((ret = GP_SavePPM("out.ppm", bitmap, "b"))) {
fprintf(stderr, "Failed to load bitmap: %sn", GP_RetCodeName(ret));
-----------------------------------------------------------------------
Summary of changes:
include/filters/GP_Filters.h | 10 ++++++--
include/filters/{GP_Resize.h => GP_Scale.h} | 24 +++++++++++++++++----
libs/filters/{GP_ScaleDown.c => GP_Scale.c} | 30 ++++++++++++++++++---------
libs/loaders/GP_PPM.c | 2 +
tests/SDL/scale_test.c | 2 +-
5 files changed, 49 insertions(+), 19 deletions(-)
rename include/filters/{GP_Resize.h => GP_Scale.h} (75%)
rename libs/filters/{GP_ScaleDown.c => GP_Scale.c} (88%)
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 generate updated: 688e786f9814c87a37a3dbb6d2d7e94b8d392674
by metan 28 Sep '11
by metan 28 Sep '11
28 Sep '11
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 688e786f9814c87a37a3dbb6d2d7e94b8d392674 (commit)
from 18183ede44829436ce42ce740974c63fe5f92ac6 (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/688e786f9814c87a37a3dbb6d2d7e94b8d39…
commit 688e786f9814c87a37a3dbb6d2d7e94b8d392674
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Wed Sep 28 17:52:55 2011 +0200
Fix some headers.
diff --git a/include/GP.h b/include/GP.h
index 2d72546..7310ddc 100644
--- a/include/GP.h
+++ b/include/GP.h
@@ -44,4 +44,7 @@
/* bitmap loaders */
#include "loaders/GP_Loaders.h"
+/* bitmap filters */
+#include "filters/GP_Filters.h"
+
#endif /* GP_H */
diff --git a/include/core/GP_Blit.h b/include/core/GP_Blit.h
index fc2c6a7..3c9ec54 100644
--- a/include/core/GP_Blit.h
+++ b/include/core/GP_Blit.h
@@ -17,6 +17,7 @@
* Boston, MA 02110-1301 USA *
* *
* Copyright (C) 2011 Tomas Gavenciak <gavento(a)ucw.cz> *
+ * Copyright (C) 2011 Cyril Hrubis <metan(a)ucw.cz> *
* *
*****************************************************************************/
@@ -26,8 +27,9 @@
/* Generated header */
#include "GP_Blit.gen.h"
-void GP_Blit(const GP_Context *c1, int x1, int y1, int w, int h,
- GP_Context *c2, int x2, int y2);
+void GP_Blit(const GP_Context *c1, GP_Coord x1, GP_Coord y1,
+ GP_Size w, GP_Size h, GP_Context *c2, GP_Coord x2, GP_Coord y2);
+
/*
* Very naive blit, no optimalizations whatsoever - keep it that way.
diff --git a/include/core/GP_Core.h b/include/core/GP_Core.h
index 705ceb3..b080db7 100644
--- a/include/core/GP_Core.h
+++ b/include/core/GP_Core.h
@@ -50,6 +50,9 @@
/* Individual pixel access */
#include "core/GP_GetPutPixel.h"
+/* blitting */
+#include "core/GP_Blit.h"
+
/* Debug and debug level */
#include "core/GP_Debug.h"
diff --git a/include/filters/GP_Filters.h b/include/filters/GP_Filters.h
index b09b5d2..4575497 100644
--- a/include/filters/GP_Filters.h
+++ b/include/filters/GP_Filters.h
@@ -32,8 +32,8 @@
#ifndef GP_FILTERS_H
#define GP_FILTERS_H
-
#include "GP_Rotate.h"
+#include "GP_Linear.h"
#include "GP_Resize.h"
#endif /* GP_FILTERS_H */
diff --git a/include/filters/GP_Resize.h b/include/filters/GP_Resize.h
index 4a0f9b6..c475645 100644
--- a/include/filters/GP_Resize.h
+++ b/include/filters/GP_Resize.h
@@ -33,4 +33,6 @@
GP_Context *GP_ScaleDown(GP_Context *src);
+GP_Context *GP_Scale(GP_Context *src, GP_Size w, GP_Size h);
+
#endif /* GP_RESIZE_H */
diff --git a/libs/SDL/GP_SDL_Context.c b/libs/SDL/GP_SDL_Context.c
index 3378d3b..f0a0747 100644
--- a/libs/SDL/GP_SDL_Context.c
+++ b/libs/SDL/GP_SDL_Context.c
@@ -23,7 +23,7 @@
* *
*****************************************************************************/
-#include "GP.h"
+#include "GP_Core.h"
#include "GP_SDL.h"
GP_RetCode GP_SDL_ContextFromSurface(GP_Context *context, SDL_Surface *surf)
diff --git a/libs/SDL/Makefile b/libs/SDL/Makefile
index 6d06e7c..5ce0549 100644
--- a/libs/SDL/Makefile
+++ b/libs/SDL/Makefile
@@ -1,5 +1,6 @@
TOPDIR=../..
CSOURCES=$(shell ls *.c)
+INCLUDE=core
LIBNAME=SDL
BUILDLIB=yes
include $(TOPDIR)/include.mk
diff --git a/libs/core/GP_Blit.c b/libs/core/GP_Blit.c
index 11ed746..ced7d54 100644
--- a/libs/core/GP_Blit.c
+++ b/libs/core/GP_Blit.c
@@ -17,6 +17,7 @@
* Boston, MA 02110-1301 USA *
* *
* Copyright (C) 2011 Tomas Gavenciak <gavento(a)ucw.cz> *
+ * Copyright (C) 2011 Cyril Hrubis <metan(a)ucw.cz> *
* *
*****************************************************************************/
@@ -26,14 +27,12 @@
#include "GP_Convert.h"
#include "GP_Blit.h"
-/*
-void GP_Blit(const GP_Context *c1, int x1, int y1, int w, int h,
- GP_Context *c2, int x2, int y2)
+void GP_Blit(const GP_Context *c1, GP_Coord x1, GP_Coord y1,
+ GP_Size w, GP_Size h, GP_Context *c2, GP_Coord x2, GP_Coord y2)
{
// Ultimate TODO: effective processing
GP_Blit_Naive(c1, x1, y1, w, h, c2, x2, y2);
}
-*/
// TODO(gavento, czech) Plan:
// GP_Blit_Naive - Zadne rotovani a tak, jen Get/PutPixel a konverze A->RGBA8888->B
diff --git a/tests/SDL/blittest.c b/tests/SDL/blittest.c
index 1f77533..a62d381 100644
--- a/tests/SDL/blittest.c
+++ b/tests/SDL/blittest.c
@@ -86,7 +86,7 @@ void redraw_screen(void)
SDL_LockSurface(display);
GP_Text(&context, NULL, 20, 20, GP_ALIGN_RIGHT|GP_VALIGN_BOTTOM, text_buf, white);
- GP_Blit_Naive(bitmap, 0, 0, bitmap->w, bitmap->h, &context, bitmap_x, bitmap_y);
+ GP_Blit(bitmap, 0, 0, bitmap->w, bitmap->h, &context, bitmap_x, bitmap_y);
SDL_UpdateRect(display, bitmap_x, bitmap_y, bitmap->w, bitmap->h);
SDL_UpdateRect(display, 20, 20, 300, 50);
diff --git a/tests/SDL/showimage.c b/tests/SDL/showimage.c
index 937296d..b043b72 100644
--- a/tests/SDL/showimage.c
+++ b/tests/SDL/showimage.c
@@ -54,7 +54,7 @@ void event_loop(void)
printf("brightness = %i %ux%un", brightness, res->w, res->h);
- GP_Blit_Naive(res, 0, 0, res->w, res->h, &context, 0, 0);
+ GP_Blit(res, 0, 0, res->w, res->h, &context, 0, 0);
SDL_Flip(display);
GP_ContextFree(res);
break;
@@ -112,7 +112,7 @@ int main(int argc, char *argv[])
GP_SDL_ContextFromSurface(&context, display);
- GP_Blit_Naive(bitmap, 0, 0, bitmap->w, bitmap->h, &context, 0, 0);
+ GP_Blit(bitmap, 0, 0, bitmap->w, bitmap->h, &context, 0, 0);
SDL_Flip(display);
event_loop();
-----------------------------------------------------------------------
Summary of changes:
include/GP.h | 3 +++
include/core/GP_Blit.h | 6 ++++--
include/core/GP_Core.h | 3 +++
include/filters/GP_Filters.h | 2 +-
include/filters/GP_Resize.h | 2 ++
libs/SDL/GP_SDL_Context.c | 2 +-
libs/SDL/Makefile | 1 +
libs/core/GP_Blit.c | 7 +++----
tests/SDL/blittest.c | 2 +-
tests/SDL/showimage.c | 4 ++--
10 files changed, 21 insertions(+), 11 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 generate updated: 18183ede44829436ce42ce740974c63fe5f92ac6
by metan 28 Sep '11
by metan 28 Sep '11
28 Sep '11
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 18183ede44829436ce42ce740974c63fe5f92ac6 (commit)
from 76d600658de2a46ded4ba41e6f16802eef40a794 (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/18183ede44829436ce42ce740974c63fe5f9…
commit 18183ede44829436ce42ce740974c63fe5f92ac6
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Wed Sep 28 17:36:25 2011 +0200
Get rid of -std=gnu9 as it breaks clang.
diff --git a/config.mk b/config.mk
index 226cc5e..b37929d 100644
--- a/config.mk
+++ b/config.mk
@@ -1,4 +1,4 @@
-CFLAGS+=-W -Wall -Wextra -fPIC -O2 -std=gnu99
+CFLAGS+=-W -Wall -Wextra -fPIC -O2
CFLAGS+=-I$(TOPDIR)/include/
LDLIBS+=-ldl
diff --git a/libs/core/GP_Blit.c b/libs/core/GP_Blit.c
index a43c16f..11ed746 100644
--- a/libs/core/GP_Blit.c
+++ b/libs/core/GP_Blit.c
@@ -64,8 +64,10 @@ void GP_Blit_Naive(const GP_Context *c1, GP_Coord x1, GP_Coord y1, GP_Size w, GP
GP_CHECK(x2 + w <= GP_ContextW(c2));
GP_CHECK(y2 + h <= GP_ContextH(c2));
- for (GP_Size i = 0; i < w; i++)
- for (GP_Size j = 0; j < h; j++) {
+ GP_Size i, j;
+
+ for (i = 0; i < w; i++)
+ for (j = 0; j < h; j++) {
GP_Pixel p = GP_GetPixel(c1, x1 + i, y1 + j);
if (c1->pixel_type != c2->pixel_type)
p = GP_ConvertContextPixel(p, c1, c2);
diff --git a/libs/core/GP_Blit.gen.c.t b/libs/core/GP_Blit.gen.c.t
index cccf961..2491b0b 100644
--- a/libs/core/GP_Blit.gen.c.t
+++ b/libs/core/GP_Blit.gen.c.t
@@ -28,7 +28,9 @@ void GP_Blit_{{ ps.suffix }}(const GP_Context *c1, GP_Coord x1, GP_Coord y1, GP_
%% if not ps.needs_bit_endian()
/* General case - memcpy() each horizontal line */
- for (GP_Size i = 0; i < h; i++)
+ GP_Size i;
+
+ for (i = 0; i < h; i++)
memcpy(GP_PIXEL_ADDR_{{ ps.suffix }}(c2, x2, y2 + i),
GP_PIXEL_ADDR_{{ ps.suffix }}(c1, x2, y2 + i),
{{ ps.size/8 }} * w);
@@ -48,7 +50,10 @@ void GP_Blit_{{ ps.suffix }}(const GP_Context *c1, GP_Coord x1, GP_Coord y1, GP_
uint8_t *p2 = (uint8_t *) GP_PIXEL_ADDR_{{ ps.suffix }}(c2, x2, y2);
uint8_t *end_p1 = (uint8_t *) GP_PIXEL_ADDR_{{ ps.suffix }}(c1, x1 + w - 1, y1);
uint8_t *end_p2 = (uint8_t *) GP_PIXEL_ADDR_{{ ps.suffix }}(c2, x2 + w - 1, y2);
- for (GP_Size i = 0; i < h; i++) {
+
+ GP_Size i;
+
+ for (i = 0; i < h; i++) {
if (al1 != 0)
GP_SET_BITS(al1, 8-al1, *p2, GP_GET_BITS(al1, 8-al1, *p1));
memcpy(p2+(al1!=0), p1+(al1!=0), copy_size);
diff --git a/libs/filters/GP_ScaleDown.c b/libs/filters/GP_ScaleDown.c
index f4bcf70..35210cc 100644
--- a/libs/filters/GP_ScaleDown.c
+++ b/libs/filters/GP_ScaleDown.c
@@ -55,7 +55,7 @@ GP_Context *GP_ScaleDown(GP_Context *src)
#define A 0.5
-float cubic(float x)
+static float cubic(float x)
{
if (x < 0)
x = -x;
-----------------------------------------------------------------------
Summary of changes:
config.mk | 2 +-
libs/core/GP_Blit.c | 6 ++++--
libs/core/GP_Blit.gen.c.t | 9 +++++++--
libs/filters/GP_ScaleDown.c | 2 +-
4 files changed, 13 insertions(+), 6 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 generate updated: 76d600658de2a46ded4ba41e6f16802eef40a794
by metan 28 Sep '11
by metan 28 Sep '11
28 Sep '11
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 76d600658de2a46ded4ba41e6f16802eef40a794 (commit)
from dc66cb62d3bed90a28854b0b566af6f45daf0b94 (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/76d600658de2a46ded4ba41e6f16802eef40…
commit 76d600658de2a46ded4ba41e6f16802eef40a794
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Wed Sep 28 14:12:30 2011 +0200
Count the coeficients before we round the coordinate.
- Behaves better at the bitmap borders
diff --git a/config.mk b/config.mk
index 962c414..226cc5e 100644
--- a/config.mk
+++ b/config.mk
@@ -1,4 +1,4 @@
-CFLAGS+=-W -Wall -Wextra -fPIC -ggdb -O2 -std=gnu99
+CFLAGS+=-W -Wall -Wextra -fPIC -O2 -std=gnu99
CFLAGS+=-I$(TOPDIR)/include/
LDLIBS+=-ldl
diff --git a/libs/filters/GP_ScaleDown.c b/libs/filters/GP_ScaleDown.c
index 0d49950..f4bcf70 100644
--- a/libs/filters/GP_ScaleDown.c
+++ b/libs/filters/GP_ScaleDown.c
@@ -97,17 +97,17 @@ GP_Context *GP_Scale(GP_Context *src, GP_Size w, GP_Size h)
float x = (1.00 * i / w) * src->w + 0.5;
v4f cvx;
int xi = x - 1;
-
- if (xi < 0)
- xi = 0;
-
- if (xi > (int)src->w - 4)
- xi = src->w - 4;
cvx.f[0] = cubic(x - xi);
cvx.f[1] = cubic(x - xi - 1);
cvx.f[2] = cubic(x - xi - 2);
cvx.f[3] = cubic(x - xi - 3);
+
+ if (xi < 0)
+ xi = 0;
+
+ if (xi > (int)src->w - 4)
+ xi = src->w - 4;
/* Generate interpolated column */
for (j = 0; j < src->h; j++) {
@@ -149,6 +149,11 @@ GP_Context *GP_Scale(GP_Context *src, GP_Size w, GP_Size h)
v4f cvy, rv, gv, bv;
float r, g, b;
int yi = y - 1;
+
+ cvy.f[0] = cubic(y - yi);
+ cvy.f[1] = cubic(y - yi - 1);
+ cvy.f[2] = cubic(y - yi - 2);
+ cvy.f[3] = cubic(y - yi - 3);
if (yi < 0)
yi = 0;
@@ -171,11 +176,6 @@ GP_Context *GP_Scale(GP_Context *src, GP_Size w, GP_Size h)
bv.f[2] = col_b[yi + 2];
bv.f[3] = col_b[yi + 3];
- cvy.f[0] = cubic(y - yi);
- cvy.f[1] = cubic(y - yi - 1);
- cvy.f[2] = cubic(y - yi - 2);
- cvy.f[3] = cubic(y - yi - 3);
-
rv = MUL_V4SF(rv, cvy);
gv = MUL_V4SF(gv, cvy);
bv = MUL_V4SF(bv, cvy);
-----------------------------------------------------------------------
Summary of changes:
config.mk | 2 +-
libs/filters/GP_ScaleDown.c | 22 +++++++++++-----------
2 files changed, 12 insertions(+), 12 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 generate updated: dc66cb62d3bed90a28854b0b566af6f45daf0b94
by metan 28 Sep '11
by metan 28 Sep '11
28 Sep '11
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 dc66cb62d3bed90a28854b0b566af6f45daf0b94 (commit)
from 78f907f5c2ec5e07373ddfc04774c9a78639a44d (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/dc66cb62d3bed90a28854b0b566af6f45daf…
commit dc66cb62d3bed90a28854b0b566af6f45daf0b94
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Wed Sep 28 13:28:24 2011 +0200
Moved the cubic coeficient generation out of main loop.
diff --git a/libs/filters/GP_ScaleDown.c b/libs/filters/GP_ScaleDown.c
index 90ba812..0d49950 100644
--- a/libs/filters/GP_ScaleDown.c
+++ b/libs/filters/GP_ScaleDown.c
@@ -84,7 +84,6 @@ GP_Context *GP_Scale(GP_Context *src, GP_Size w, GP_Size h)
GP_Context *dst;
float col_r[src->h], col_g[src->h], col_b[src->h];
uint32_t i, j;
- int idx;
if (src->pixel_type != GP_PIXEL_RGB888)
return NULL;
@@ -96,24 +95,29 @@ GP_Context *GP_Scale(GP_Context *src, GP_Size w, GP_Size h)
for (i = 0; i < w; i++) {
float x = (1.00 * i / w) * src->w + 0.5;
+ v4f cvx;
+ int xi = x - 1;
+
+ if (xi < 0)
+ xi = 0;
+
+ if (xi > (int)src->w - 4)
+ xi = src->w - 4;
+
+ cvx.f[0] = cubic(x - xi);
+ cvx.f[1] = cubic(x - xi - 1);
+ cvx.f[2] = cubic(x - xi - 2);
+ cvx.f[3] = cubic(x - xi - 3);
/* Generate interpolated column */
for (j = 0; j < src->h; j++) {
- v4f cv, rv, gv, bv;
+ v4f rv, gv, bv;
GP_Pixel pix[4];
- idx = x - 1;
-
- if (idx < 0)
- idx = 0;
-
- if (idx > (int)src->w - 4)
- idx = src->w - 4;
-
- pix[0] = GP_GetPixel_Raw_24BPP(src, idx, j);
- pix[1] = GP_GetPixel_Raw_24BPP(src, idx + 1, j);
- pix[2] = GP_GetPixel_Raw_24BPP(src, idx + 2, j);
- pix[3] = GP_GetPixel_Raw_24BPP(src, idx + 3, j);
+ pix[0] = GP_GetPixel_Raw_24BPP(src, xi, j);
+ pix[1] = GP_GetPixel_Raw_24BPP(src, xi + 1, j);
+ pix[2] = GP_GetPixel_Raw_24BPP(src, xi + 2, j);
+ pix[3] = GP_GetPixel_Raw_24BPP(src, xi + 3, j);
rv.f[0] = GP_Pixel_GET_R_RGB888(pix[0]);
rv.f[1] = GP_Pixel_GET_R_RGB888(pix[1]);
@@ -130,14 +134,9 @@ GP_Context *GP_Scale(GP_Context *src, GP_Size w, GP_Size h)
bv.f[2] = GP_Pixel_GET_B_RGB888(pix[2]);
bv.f[3] = GP_Pixel_GET_B_RGB888(pix[3]);
- cv.f[0] = cubic(x - idx);
- cv.f[1] = cubic(x - idx - 1);
- cv.f[2] = cubic(x - idx - 2);
- cv.f[3] = cubic(x - idx - 3);
-
- rv = MUL_V4SF(rv, cv);
- gv = MUL_V4SF(gv, cv);
- bv = MUL_V4SF(bv, cv);
+ rv = MUL_V4SF(rv, cvx);
+ gv = MUL_V4SF(gv, cvx);
+ bv = MUL_V4SF(bv, cvx);
col_r[j] = SUM_V4SF(rv);
col_g[j] = SUM_V4SF(gv);
@@ -147,40 +146,39 @@ GP_Context *GP_Scale(GP_Context *src, GP_Size w, GP_Size h)
/* now interpolate column for new image */
for (j = 0; j < h; j++) {
float y = (1.00 * j / h) * src->h + 0.5;
- v4f cv, rv, gv, bv;
+ v4f cvy, rv, gv, bv;
float r, g, b;
-
- idx = y - 1;
+ int yi = y - 1;
- if (idx < 0)
- idx = 0;
+ if (yi < 0)
+ yi = 0;
- if (idx > (int)src->h - 4)
- idx = src->h - 4;
+ if (yi > (int)src->h - 4)
+ yi = src->h - 4;
- rv.f[0] = col_r[idx];
- rv.f[1] = col_r[idx + 1];
- rv.f[2] = col_r[idx + 2];
- rv.f[3] = col_r[idx + 3];
+ rv.f[0] = col_r[yi];
+ rv.f[1] = col_r[yi + 1];
+ rv.f[2] = col_r[yi + 2];
+ rv.f[3] = col_r[yi + 3];
- gv.f[0] = col_g[idx];
- gv.f[1] = col_g[idx + 1];
- gv.f[2] = col_g[idx + 2];
- gv.f[3] = col_g[idx + 3];
+ gv.f[0] = col_g[yi];
+ gv.f[1] = col_g[yi + 1];
+ gv.f[2] = col_g[yi + 2];
+ gv.f[3] = col_g[yi + 3];
- bv.f[0] = col_b[idx];
- bv.f[1] = col_b[idx + 1];
- bv.f[2] = col_b[idx + 2];
- bv.f[3] = col_b[idx + 3];
+ bv.f[0] = col_b[yi];
+ bv.f[1] = col_b[yi + 1];
+ bv.f[2] = col_b[yi + 2];
+ bv.f[3] = col_b[yi + 3];
- cv.f[0] = cubic(y - idx);
- cv.f[1] = cubic(y - idx - 1);
- cv.f[2] = cubic(y - idx - 2);
- cv.f[3] = cubic(y - idx - 3);
-
- rv = MUL_V4SF(rv, cv);
- gv = MUL_V4SF(gv, cv);
- bv = MUL_V4SF(bv, cv);
+ cvy.f[0] = cubic(y - yi);
+ cvy.f[1] = cubic(y - yi - 1);
+ cvy.f[2] = cubic(y - yi - 2);
+ cvy.f[3] = cubic(y - yi - 3);
+
+ rv = MUL_V4SF(rv, cvy);
+ gv = MUL_V4SF(gv, cvy);
+ bv = MUL_V4SF(bv, cvy);
r = SUM_V4SF(rv);
g = SUM_V4SF(gv);
-----------------------------------------------------------------------
Summary of changes:
libs/filters/GP_ScaleDown.c | 96 +++++++++++++++++++++----------------------
1 files changed, 47 insertions(+), 49 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