Gfxprim
Threads by month
- ----- 2026 -----
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
October 2011
- 2 participants
- 44 discussions
[repo.or.cz] gfxprim.git branch generate updated: 9be6758838682bf96a52cf189f94b81f18441e80
by metan 31 Oct '11
by metan 31 Oct '11
31 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 9be6758838682bf96a52cf189f94b81f18441e80 (commit)
via 5309636e9487a4547fe4fe1f4bf798c0174ab575 (commit)
from aa8f80b7334e88d72171f325bb37cfc4b2245d0e (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/9be6758838682bf96a52cf189f94b81f1844…
commit 9be6758838682bf96a52cf189f94b81f18441e80
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Mon Oct 31 15:15:31 2011 +0100
More docs for filters.
diff --git a/doc/filters.txt b/doc/filters.txt
index 0f54e7a..d806786 100644
--- a/doc/filters.txt
+++ b/doc/filters.txt
@@ -84,9 +84,48 @@ void GP_FilterFoo_Raw(const GP_Context *src, GP_Context *dst,
GP_ProgressCallback *callback);
-------------------------------------------------------------------------------
-Rotation and Symmetries
+Point operation filters
~~~~~~~~~~~~~~~~~~~~~~~
+Point operations are filters that works with pixels as with independent values
+(the value of destination pixel depends only on the pixel on the same
+coodrdinates in source image). All of these filters works 'in-place' and the
+result has always the same size as the source.
+
+[source,c]
+-------------------------------------------------------------------------------
+#include <GP_Filters.h>
+
+GP_Context *GP_FilterBrightness(const GP_Context *src, GP_Context *dst,
+ int32_t inc, GP_ProgressCallback *callback);
+-------------------------------------------------------------------------------
+
+Brightness filter, increments all pixel channels by a fixed value.
+
+[source,c]
+-------------------------------------------------------------------------------
+#include <GP_Filters.h>
+
+GP_Context *GP_FilterContrast(const GP_Context *src, GP_Context *dst,
+ float mul, GP_ProgressCallback *callback);
+-------------------------------------------------------------------------------
+
+Constrast filter, multiplies all pixel channels by a fixed value.
+
+[source,c]
+-------------------------------------------------------------------------------
+#include <GP_Filters.h>
+
+GP_Context *GP_FilterInvert(const GP_Context *src, GP_Context *dst,
+ GP_ProgressCallback *callback);
+-------------------------------------------------------------------------------
+
+Inverts the image, for each channel the result value is computed as "chan_max
+- val".
+
+Rotation and Symmetry filters
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
[source,c]
-------------------------------------------------------------------------------
#include <GP_Filters.h>
@@ -200,3 +239,49 @@ Works 'in-place'.
'TODO:' this filter is implemented for RGB888 only.
+
+Interpolation filters
+~~~~~~~~~~~~~~~~~~~~~
+
+[source,c]
+-------------------------------------------------------------------------------
+#include <GP_Filters.h>
+
+typedef enum GP_InterpolationType {
+ GP_INTERP_NN, /* Nearest Neighbour */
+ GP_INTERP_CUBIC, /* Bicubic */
+} GP_InterpolationType;
+
+GP_Context *GP_FilterResize(const GP_Context *src, GP_Context *dst,
+ GP_InterpolationType type,
+ GP_Size w, GP_Size h,
+ GP_ProgressCallback *callback);
+-------------------------------------------------------------------------------
+
+Interpolate (resize) the context.
+
+Doesn't work 'in-place' (this is quite impossible as the size of the bitmap is
+changed by the filter).
+
+If the filter destination is non 'NULL' and the 'w' and 'h' is smaller than the
+destination size the source image is interpolated into subcontext of
+destination defined by 'w' and 'h'.
+
+'TODO:' this filter is implemented for RGB888 only.
+
+Nearest Neighbour Interpolation
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+Fast, but produces "pixelated" images may however work better for images with
+sharp edges mostly consisting of big one colour regions (eg. doesn't blur the
+result on upscaling).
+
+Bicubic Interpolation
+^^^^^^^^^^^^^^^^^^^^^
+
+Works well as is on image upscaling. To get decent result on downscaling
+low-pass filter (gaussian blur) must be used on original image before actuall
+downscaling. To do this reasonably fast we could cheat a little first resize
+big images a little without the low-past filter, then apply low-pass filter and
+finally downscale it to desired size.
+
http://repo.or.cz/w/gfxprim.git/commit/5309636e9487a4547fe4fe1f4bf798c0174a…
commit 5309636e9487a4547fe4fe1f4bf798c0174ab575
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Mon Oct 31 15:06:55 2011 +0100
Fixed the point filters API.
diff --git a/demos/grinder/grinder.c b/demos/grinder/grinder.c
index 3582c38..51c362b 100644
--- a/demos/grinder/grinder.c
+++ b/demos/grinder/grinder.c
@@ -279,7 +279,7 @@ static GP_RetCode bright(GP_Context **c, const char *params)
return GP_EINVAL;
}
- GP_FilterBrightness_Raw(*c, *c, bright);
+ GP_FilterBrightness(*c, *c, bright, progress_callback);
return GP_ESUCCESS;
}
@@ -303,7 +303,7 @@ static GP_RetCode contrast(GP_Context **c, const char *params)
return GP_EINVAL;
}
- GP_FilterContrast_Raw(*c, *c, mul);
+ GP_FilterContrast(*c, *c, mul, progress_callback);
return GP_ESUCCESS;
}
@@ -319,7 +319,7 @@ static GP_RetCode invert(GP_Context **c, const char *params)
if (param_parse(params, invert_params, "invert", param_err))
return GP_EINVAL;
- GP_FilterInvert_Raw(*c, *c);
+ GP_FilterInvert(*c, *c, progress_callback);
return GP_ESUCCESS;
}
diff --git a/include/SDL/GP_SDL.h b/include/SDL/GP_SDL.h
index a5967c2..d01bd1e 100644
--- a/include/SDL/GP_SDL.h
+++ b/include/SDL/GP_SDL.h
@@ -19,7 +19,7 @@
* Copyright (C) 2009-2010 Jiri "BlueBear" Dluhos *
* <jiri.bluebear.dluhos(a)gmail.com> *
* *
- * Copyright (C) 2009-2010 Cyril Hrubis <metan(a)ucw.cz> *
+ * Copyright (C) 2009-2011 Cyril Hrubis <metan(a)ucw.cz> *
* *
*****************************************************************************/
@@ -28,7 +28,6 @@
#include <SDL/SDL.h>
-#include "GP.h"
#include "GP_SDL_Context.h"
#include "GP_SDL_VideoInit.h"
diff --git a/include/filters/GP_Filter.h b/include/filters/GP_Filter.h
index cc9918d..20d323c 100644
--- a/include/filters/GP_Filter.h
+++ b/include/filters/GP_Filter.h
@@ -26,8 +26,8 @@
*/
-#ifndef GP_FILTER_H
-#define GP_FILTER_H
+#ifndef GP_FILTERS_FILTER_H
+#define GP_FILTERS_FILTER_H
#include "core/GP_Context.h"
@@ -55,4 +55,4 @@ static inline void GP_ProgressCallbackDone(GP_ProgressCallback *callback)
GP_ProgressCallbackReport(callback, 100);
}
-#endif /* GP_FILTER_H */
+#endif /* FILTERS_GP_FILTER_H */
diff --git a/include/filters/GP_Point.h b/include/filters/GP_Point.h
index b5e7d50..c5b53a8 100644
--- a/include/filters/GP_Point.h
+++ b/include/filters/GP_Point.h
@@ -26,32 +26,42 @@
*/
-#ifndef GP_POINT_H
-#define GP_POINT_H
+#ifndef FILTERS_GP_POINT_H
+#define FILTERS_GP_POINT_H
-#include "core/GP_Context.h"
+#include "GP_Filter.h"
/*
* Brightness filter.
+ *
+ * Increments each pixel channel by a given value.
*/
-void GP_FilterBrightness_Raw(const GP_Context *src, GP_Context *res,
- int32_t inc);
+void GP_FilterBrightness_Raw(const GP_Context *src, GP_Context *dst,
+ int32_t inc, GP_ProgressCallback *callback);
-GP_Context *GP_FilterBrightness(const GP_Context *src, int32_t inc);
+GP_Context *GP_FilterBrightness(const GP_Context *src, GP_Context *dst,
+ int32_t inc, GP_ProgressCallback *callback);
/*
* Contrast filter.
+ *
+ * Multiplies each pixel channel by a given value.
*/
-GP_Context *GP_FilterContrast_Raw(const GP_Context *src, GP_Context *res,
- float mul);
+GP_Context *GP_FilterContrast_Raw(const GP_Context *src, GP_Context *dst,
+ float mul, GP_ProgressCallback *callback);
-GP_Context *GP_FilterContrast(const GP_Context *src, float mul);
+GP_Context *GP_FilterContrast(const GP_Context *src, GP_Context *dst,
+ float mul, GP_ProgressCallback *callback);
/*
* Invert filter.
+ *
+ * Inverts each pixel channel (eg. val = max - val)
*/
-GP_Context *GP_FilterInvert_Raw(const GP_Context *src, GP_Context *res);
+GP_Context *GP_FilterInvert_Raw(const GP_Context *src, GP_Context *dst,
+ GP_ProgressCallback *callback);
-GP_Context *GP_FilterInvert(const GP_Context *src);
+GP_Context *GP_FilterInvert(const GP_Context *src, GP_Context *dst,
+ GP_ProgressCallback *callback);
-#endif /* GP_POINT_H */
+#endif /* FILTERS_GP_POINT_H */
diff --git a/pylib/templates/filter.point.c.t b/pylib/templates/filter.point.c.t
index 271418c..4c3bdaa 100644
--- a/pylib/templates/filter.point.c.t
+++ b/pylib/templates/filter.point.c.t
@@ -3,10 +3,11 @@
{% macro maybe_opts(opts) %}{% if opts %}, {{ opts }}{% endif %}{% endmacro %}
%% macro filter_include()
-#include <GP_Context.h>
-#include <GP_Pixel.h>
-#include <GP_GetPutPixel.h>
-#include <GP_Debug.h>
+#include "core/GP_Context.h"
+#include "core/GP_Pixel.h"
+#include "core/GP_GetPutPixel.h"
+#include "core/GP_Debug.h"
+#include "GP_Filter.h"
%% endmacro
/*
@@ -15,7 +16,8 @@
%% 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) }})
+void GP_Filter{{ name }}_{{ ps.suffix }}(const GP_Context *src, GP_Context *dst{{ maybe_opts(opts) }},
+ GP_ProgressCallback *callback)
{
uint32_t x, y;
@@ -23,9 +25,14 @@ void GP_Filter{{ name }}_{{ ps.suffix }}(const GP_Context *src, GP_Context *res{
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);
+ GP_PutPixel_Raw_{{ ps.suffix }}(dst, x, y, pix);
}
+
+ if (callback != NULL && y % 100 == 0)
+ GP_ProgressCallbackReport(callback, 100.00 * y/src->h);
}
+
+ GP_ProgressCallbackDone(callback);
}
%% endif
%% endfor
@@ -37,11 +44,12 @@ void GP_Filter{{ name }}_{{ ps.suffix }}(const GP_Context *src, GP_Context *res{
%% 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) }})
+void GP_Filter{{ name }}_{{ pt.name }}(const GP_Context *src, GP_Context *dst{{ maybe_opts(opts) }},
+ GP_ProgressCallback *callback)
{
uint32_t x, y;
- for (y = 0; y < src->h; 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
@@ -54,8 +62,14 @@ void GP_Filter{{ name }}_{{ pt.name }}(const GP_Context *src, GP_Context *res{{
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);
+ GP_PutPixel_Raw_{{ pt.pixelsize.suffix }}(dst, x, y, pix);
}
+
+ if (callback != NULL && y % 100 == 0)
+ GP_ProgressCallbackReport(callback, 100.00 * y/src->h);
+ }
+
+ GP_ProgressCallbackDone(callback);
}
%% endif
@@ -77,7 +91,8 @@ void GP_Filter{{ name }}_{{ pt.name }}(const GP_Context *src, GP_Context *res{{
* Switch per pixel sizes or pixel types.
*/
%% macro filter_functions(name, opts="", params="", fmt="")
-void GP_Filter{{ name }}_Raw(const GP_Context *src, GP_Context *res{{ maybe_opts(opts) }})
+void GP_Filter{{ name }}_Raw(const GP_Context *src, GP_Context *dst{{ maybe_opts(opts) }},
+ GP_ProgressCallback *callback)
{
GP_DEBUG(1, "Running filter {{ name }} {{ fmt }}"{{ maybe_opts(params) }});
@@ -87,9 +102,9 @@ void GP_Filter{{ name }}_Raw(const GP_Context *src, GP_Context *res{{ maybe_opts
%% 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) }});
+ GP_Filter{{ name }}_{{ pt.pixelsize.suffix }}(src, dst{{ maybe_opts(params) }}, callback);
%% else
- GP_Filter{{ name }}_{{ pt.name }}(src, res{{ maybe_opts(params) }});
+ GP_Filter{{ name }}_{{ pt.name }}(src, dst{{ maybe_opts(params) }}, callback);
%% endif
break;
%% endfor
@@ -98,18 +113,25 @@ void GP_Filter{{ name }}_Raw(const GP_Context *src, GP_Context *res{{ maybe_opts
}
}
-GP_Context *GP_Filter{{ name }}(const GP_Context *src{{ maybe_opts(opts) }})
+GP_Context *GP_Filter{{ name }}(const GP_Context *src, GP_Context *dst{{ maybe_opts(opts) }},
+ GP_ProgressCallback *callback)
{
- GP_Context *res;
- res = GP_ContextCopy(src, 0);
+ if (dst == NULL) {
+ dst = GP_ContextCopy(src, 0);
- if (res == NULL)
- return NULL;
+ if (dst == NULL)
+ return NULL;
+ } else {
+ GP_ASSERT(src->pixel_type == dst->pixel_type,
+ "The src and dst pixel types must match");
+ GP_ASSERT(src->w <= dst->w && src->h <= dst->h,
+ "Destination is not big enough");
+ }
- GP_Filter{{ name }}_Raw(src, res{{ maybe_opts(params) }});
+ GP_Filter{{ name }}_Raw(src, dst{{ maybe_opts(params) }}, callback);
- return res;
+ return dst;
}
%% endmacro
diff --git a/tests/SDL/showimage.c b/tests/SDL/showimage.c
index b043b72..134f8f9 100644
--- a/tests/SDL/showimage.c
+++ b/tests/SDL/showimage.c
@@ -50,7 +50,7 @@ void event_loop(void)
case SDLK_DOWN:
brightness-=1;
- res = GP_FilterBrightness(bitmap, brightness);
+ res = GP_FilterBrightness(bitmap, NULL, brightness, NULL);
printf("brightness = %i %ux%un", brightness, res->w, res->h);
-----------------------------------------------------------------------
Summary of changes:
demos/grinder/grinder.c | 6 +-
doc/filters.txt | 87 +++++++++++++++++++++++++++++++++++++-
include/SDL/GP_SDL.h | 3 +-
include/filters/GP_Filter.h | 6 +-
include/filters/GP_Point.h | 34 ++++++++++-----
pylib/templates/filter.point.c.t | 60 ++++++++++++++++++--------
tests/SDL/showimage.c | 2 +-
7 files changed, 157 insertions(+), 41 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: aa8f80b7334e88d72171f325bb37cfc4b2245d0e
by metan 31 Oct '11
by metan 31 Oct '11
31 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 aa8f80b7334e88d72171f325bb37cfc4b2245d0e (commit)
via 473d31d4feafd632b9cd7c668fb7548a6855ce03 (commit)
via 8c0a1d4f59d6c69dfbffa2817236b6b18d7f261b (commit)
from 4061392c7024e648dc2bcfde720ce11e0f70dedb (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/aa8f80b7334e88d72171f325bb37cfc4b224…
commit aa8f80b7334e88d72171f325bb37cfc4b2245d0e
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Mon Oct 31 14:22:24 2011 +0100
Fixed the interpolation filters api.
diff --git a/demos/fbshow/fbshow.c b/demos/fbshow/fbshow.c
index 76dcb99..ffa2c6a 100644
--- a/demos/fbshow/fbshow.c
+++ b/demos/fbshow/fbshow.c
@@ -48,7 +48,7 @@ static GP_Context *image_to_display(GP_Context *img, uint32_t w, uint32_t h)
{
float rat = calc_img_size(img->w, img->h, w, h);
- return GP_FilterResize(img, NULL, GP_INTERP_CUBIC, img->w * rat, img->h * rat);
+ return GP_FilterResize(img, NULL, GP_INTERP_CUBIC, img->w * rat, img->h * rat, NULL);
}
static int show_image(GP_Framebuffer *fb, const char *img_path, int clear)
diff --git a/demos/grinder/grinder.c b/demos/grinder/grinder.c
index 27d8ded..3582c38 100644
--- a/demos/grinder/grinder.c
+++ b/demos/grinder/grinder.c
@@ -117,7 +117,7 @@ static GP_RetCode resize(GP_Context **c, const char *params)
GP_Size h = ratio * (*c)->h;
GP_Context *res = NULL;
- res = GP_FilterResize(*c, progress_callback, alg, w, h);
+ res = GP_FilterResize(*c, NULL, alg, w, h, progress_callback);
if (res == NULL)
return GP_EINVAL;
@@ -177,7 +177,7 @@ static GP_RetCode scale(GP_Context **c, const char *params)
GP_Context *res = NULL;
- res = GP_FilterResize(*c, progress_callback, alg, w, h);
+ res = GP_FilterResize(*c, NULL, alg, w, h, progress_callback);
if (res == NULL)
return GP_EINVAL;
diff --git a/include/filters/GP_Filters.h b/include/filters/GP_Filters.h
index 90f63b3..8e2d84d 100644
--- a/include/filters/GP_Filters.h
+++ b/include/filters/GP_Filters.h
@@ -38,10 +38,10 @@
/* Point filters, brightness, contrast ... */
#include "filters/GP_Point.h"
-/* Linear convolution base filters (mostly blurs) */
+/* Linear convolution based filters (mostly blurs) */
#include "filters/GP_Linear.h"
-/* Image scaling */
+/* Image scaling (resampling) */
#include "filters/GP_Resize.h"
#endif /* GP_FILTERS_H */
diff --git a/include/filters/GP_Linear.h b/include/filters/GP_Linear.h
index ae028fc..3c0d1e9 100644
--- a/include/filters/GP_Linear.h
+++ b/include/filters/GP_Linear.h
@@ -63,7 +63,8 @@ GP_Context *GP_FilterGaussianBlur(const GP_Context *src, GP_Context *dst,
/*
* Linear convolution.
*
- * The kernel is array of kw * kh floats and is indexed as two directional array.
+ * The kernel is array of kw * kh floats and is indexed as two directional
+ * array.
*
* To define 3x3 average filter
*
diff --git a/include/filters/GP_Resize.h b/include/filters/GP_Resize.h
index 05f80c7..63a6143 100644
--- a/include/filters/GP_Resize.h
+++ b/include/filters/GP_Resize.h
@@ -41,8 +41,8 @@
*/
-#ifndef GP_RESIZE_H
-#define GP_RESIZE_H
+#ifndef FILTERS_GP_RESIZE_H
+#define FILTERS_GP_RESIZE_H
#include "GP_Filter.h"
@@ -51,11 +51,26 @@ typedef enum GP_InterpolationType {
GP_INTERP_CUBIC, /* Bicubic */
} GP_InterpolationType;
-void GP_FilterResize_Raw(GP_Context *src, GP_Context *res,
- GP_ProgressCallback *callback,
- GP_InterpolationType type);
+/*
+ * Just interpolate the source context into destination context.
+ */
+void GP_FilterResize_Raw(const GP_Context *src, GP_Context *dst,
+ GP_InterpolationType type,
+ GP_ProgressCallback *callback);
-GP_Context *GP_FilterResize(GP_Context *src, GP_ProgressCallback *callback,
- GP_InterpolationType type, GP_Size w, GP_Size h);
+/*
+ * If destination is non NULL, the w and h are used to create subcontext from
+ * destination which is then used to interpolate the image to.
+ *
+ * Otherwise if destination is NULL, the context of size w and h is allocated
+ * and returned.
+ *
+ * In both cases the pointer to destination or NULL in case of failure is
+ * returned.
+ */
+GP_Context *GP_FilterResize(const GP_Context *src, GP_Context *dst,
+ GP_InterpolationType type,
+ GP_Size w, GP_Size h,
+ GP_ProgressCallback *callback);
-#endif /* GP_RESIZE_H */
+#endif /* FILTERS_GP_RESIZE_H */
diff --git a/libs/filters/GP_Resize.c b/libs/filters/GP_Resize.c
index 192d5f5..eb42478 100644
--- a/libs/filters/GP_Resize.c
+++ b/libs/filters/GP_Resize.c
@@ -27,27 +27,27 @@
#include <GP_Resize.h>
-void GP_FilterInterpolate_NN(GP_Context *src, GP_Context *res,
+void GP_FilterInterpolate_NN(const GP_Context *src, GP_Context *dst,
GP_ProgressCallback *callback)
{
GP_Coord x, y;
GP_DEBUG(1, "Scaling image %ux%u -> %ux%u %2.2f %2.2f",
- src->w, src->h, res->w, res->h,
- 1.00 * res->w / src->w, 1.00 * res->h / src->h);
+ src->w, src->h, dst->w, dst->h,
+ 1.00 * dst->w / src->w, 1.00 * dst->h / src->h);
- for (y = 0; y < (GP_Coord)res->h; y++) {
- for (x = 0; x < (GP_Coord)res->w; x++) {
- GP_Coord xi = (1.00 * x / res->w) * src->w;
- GP_Coord yi = (1.00 * y / res->h) * src->h;
+ for (y = 0; y < (GP_Coord)dst->h; y++) {
+ for (x = 0; x < (GP_Coord)dst->w; x++) {
+ GP_Coord xi = (1.00 * x / dst->w) * src->w;
+ GP_Coord yi = (1.00 * y / dst->h) * src->h;
GP_Pixel pix = GP_GetPixel_Raw_24BPP(src, xi, yi);
- GP_PutPixel_Raw_24BPP(res, x, y, pix);
+ GP_PutPixel_Raw_24BPP(dst, x, y, pix);
}
if (callback != NULL && y % 100 == 0)
- GP_ProgressCallbackReport(callback, 100.00 * y/res->h);
+ GP_ProgressCallbackReport(callback, 100.00 * y/dst->h);
}
GP_ProgressCallbackDone(callback);
@@ -79,18 +79,18 @@ 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])
-void GP_FilterInterpolate_Cubic(GP_Context *src, GP_Context *res,
+void GP_FilterInterpolate_Cubic(const GP_Context *src, GP_Context *dst,
GP_ProgressCallback *callback)
{
float col_r[src->h], col_g[src->h], col_b[src->h];
uint32_t i, j;
GP_DEBUG(1, "Scaling image %ux%u -> %ux%u %2.2f %2.2f",
- src->w, src->h, res->w, res->h,
- 1.00 * res->w / src->w, 1.00 * res->h / src->h);
+ src->w, src->h, dst->w, dst->h,
+ 1.00 * dst->w / src->w, 1.00 * dst->h / src->h);
- for (i = 0; i < res->w; i++) {
- float x = (1.00 * i / res->w) * (src->w - 4.5) + 2.5;
+ for (i = 0; i < dst->w; i++) {
+ float x = (1.00 * i / dst->w) * (src->w - 4.5) + 2.5;
v4f cvx;
int xi = x - 1;
@@ -140,8 +140,8 @@ void GP_FilterInterpolate_Cubic(GP_Context *src, GP_Context *res,
}
/* now interpolate column for new image */
- for (j = 0; j < res->h; j++) {
- float y = (1.00 * j / res->h) * (src->h - 4.5) + 2.5;
+ for (j = 0; j < dst->h; j++) {
+ float y = (1.00 * j / dst->h) * (src->h - 4.5) + 2.5;
v4f cvy, rv, gv, bv;
float r, g, b;
int yi = y - 1;
@@ -199,46 +199,58 @@ void GP_FilterInterpolate_Cubic(GP_Context *src, GP_Context *res,
b = 0;
GP_Pixel pix = GP_Pixel_CREATE_RGB888((uint8_t)r, (uint8_t)g, (uint8_t)b);
- GP_PutPixel_Raw_24BPP(res, i, j, pix);
+ GP_PutPixel_Raw_24BPP(dst, i, j, pix);
}
if (callback != NULL && i % 100 == 0)
- GP_ProgressCallbackReport(callback, 100.00 * i/res->w);
+ GP_ProgressCallbackReport(callback, 100.00 * i/dst->w);
}
GP_ProgressCallbackDone(callback);
}
-void GP_FilterResize_Raw(GP_Context *src, GP_Context *res,
- GP_ProgressCallback *callback,
- GP_InterpolationType type)
+void GP_FilterResize_Raw(const GP_Context *src, GP_Context *dst,
+ GP_InterpolationType type,
+ GP_ProgressCallback *callback)
{
switch (type) {
case GP_INTERP_NN:
- GP_FilterInterpolate_NN(src, res, callback);
+ GP_FilterInterpolate_NN(src, dst, callback);
break;
case GP_INTERP_CUBIC:
- GP_FilterInterpolate_Cubic(src, res, callback);
+ GP_FilterInterpolate_Cubic(src, dst, callback);
break;
}
}
-GP_Context *GP_FilterResize(GP_Context *src, GP_ProgressCallback *callback,
- GP_InterpolationType type, GP_Size w, GP_Size h)
+GP_Context *GP_FilterResize(const GP_Context *src, GP_Context *dst,
+ GP_InterpolationType type,
+ GP_Size w, GP_Size h,
+ GP_ProgressCallback *callback)
{
- GP_Context *res;
-
+ GP_Context sub, *res;
+
+ /* TODO: Templatize */
if (src->pixel_type != GP_PIXEL_RGB888)
return NULL;
-
- res = GP_ContextAlloc(w, h, GP_PIXEL_RGB888);
-
- if (res == NULL) {
- GP_DEBUG(1, "Malloc failed :(");
- return NULL;
+
+ if (dst == NULL) {
+ dst = GP_ContextAlloc(w, h, src->pixel_type);
+
+ if (dst == NULL)
+ return NULL;
+
+ res = dst;
+ } else {
+ GP_ASSERT(src->pixel_type == dst->pixel_type,
+ "The src and dst pixel types must match");
+ /*
+ * The size of w and h is asserted in subcontext initalization
+ */
+ res = GP_ContextSubContext(dst, &sub, 0, 0, w, h);
}
- GP_FilterResize_Raw(src, res, callback, type);
+ GP_FilterResize_Raw(src, res, type, callback);
- return res;
+ return dst;
}
http://repo.or.cz/w/gfxprim.git/commit/473d31d4feafd632b9cd7c668fb7548a6855…
commit 473d31d4feafd632b9cd7c668fb7548a6855ce03
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Mon Oct 31 14:05:32 2011 +0100
Remove the redundant linker flags.
diff --git a/demos/fbshow/Makefile b/demos/fbshow/Makefile
index 2ca7439..0a8147c 100644
--- a/demos/fbshow/Makefile
+++ b/demos/fbshow/Makefile
@@ -3,7 +3,7 @@ TOPDIR=../..
CSOURCES=$(shell echo *.c)
INCLUDE=
-LDLIBS+=-lGP -L$(TOPDIR)/build/ -lpng
+LDLIBS+=-lGP -L$(TOPDIR)/build/
APPS=fbshow
diff --git a/demos/grinder/Makefile b/demos/grinder/Makefile
index 7cf1e72..a984bd9 100644
--- a/demos/grinder/Makefile
+++ b/demos/grinder/Makefile
@@ -3,7 +3,7 @@ TOPDIR=../..
CSOURCES=$(shell echo *.c)
INCLUDE=core gfx SDL backends
-LDLIBS+=-lGP -L$(TOPDIR)/build/ -lpng
+LDLIBS+=-lGP -L$(TOPDIR)/build/
APPS=grinder
diff --git a/tests/SDL/Makefile b/tests/SDL/Makefile
index 8c02ba1..123889b 100644
--- a/tests/SDL/Makefile
+++ b/tests/SDL/Makefile
@@ -3,7 +3,7 @@ TOPDIR=../..
CSOURCES=$(shell echo *.c)
INCLUDE=core gfx SDL backends
-LDLIBS+=-lGP -L$(TOPDIR)/build/ -lGP_SDL -lSDL -lpng
+LDLIBS+=-lGP -L$(TOPDIR)/build/ -lGP_SDL -lSDL
APPS=pixeltest fileview fonttest linetest randomshapetest shapetest sierpinsky symbolstest textaligntest trianglefps input blittest subcontext showimage
http://repo.or.cz/w/gfxprim.git/commit/8c0a1d4f59d6c69dfbffa2817236b6b18d7f…
commit 8c0a1d4f59d6c69dfbffa2817236b6b18d7f261b
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Mon Oct 31 13:57:09 2011 +0100
Allow GP_ContextSubContext() to inialized given buffer.
diff --git a/include/core/GP_Context.h b/include/core/GP_Context.h
index 80794d9..ef2940e 100644
--- a/include/core/GP_Context.h
+++ b/include/core/GP_Context.h
@@ -104,9 +104,15 @@ GP_Context *GP_ContextCopy(const GP_Context *src, int flag);
/*
* Create subcontext.
+ *
+ * If pointer to subcontext is NULL, new context is allocated
+ * otherwise context pointed by subcontext pointer is initalized.
+ *
+ * The free_pixels flag is set to 0 upon subcontext initalization so the
+ * GP_ContextFree() would not call free() upon the subcontext->pixels pointer.
*/
-GP_Context *GP_ContextSubContext(GP_Context *context, GP_Coord x, GP_Coord y,
- GP_Size w, GP_Size h);
+GP_Context *GP_ContextSubContext(GP_Context *context, GP_Context *subcontext,
+ GP_Coord x, GP_Coord y, GP_Size w, GP_Size h);
/*
* Converts context to different pixel type.
diff --git a/libs/core/GP_Context.c b/libs/core/GP_Context.c
index 83c9f73..67aca4f 100644
--- a/libs/core/GP_Context.c
+++ b/libs/core/GP_Context.c
@@ -127,17 +127,21 @@ void GP_ContextFree(GP_Context *context)
free(context);
}
-GP_Context *GP_ContextSubContext(GP_Context *context, GP_Coord x, GP_Coord y,
- GP_Size w, GP_Size h)
+GP_Context *GP_ContextSubContext(GP_Context *context, GP_Context *subcontext,
+ GP_Coord x, GP_Coord y, GP_Size w, GP_Size h)
{
GP_CHECK(context, "NULL context");
GP_CHECK(context->w >= x + w, "Subcontext w out of original context.");
GP_CHECK(context->h >= y + h, "Subcontext h out of original context.");
+
+ GP_Context *ret = subcontext;
- GP_Context *ret = malloc(sizeof(GP_Context));
+ if (ret == NULL) {
+ GP_Context *ret = malloc(sizeof(GP_Context));
- if (ret == NULL)
- return NULL;
+ if (ret == NULL)
+ return NULL;
+ }
ret->bpp = context->bpp;
ret->bytes_per_row = context->bytes_per_row;
diff --git a/tests/SDL/subcontext.c b/tests/SDL/subcontext.c
index bbdfeae..25db7fb 100644
--- a/tests/SDL/subcontext.c
+++ b/tests/SDL/subcontext.c
@@ -260,7 +260,7 @@ int main(int argc, char *argv[])
white = GP_ColorToContextPixel(GP_COL_WHITE, &context);
gray = GP_ColorToContextPixel(GP_COL_GRAY_DARK, &context);
- sub_context = GP_ContextSubContext(&context, 100, 100, 440, 280);
+ sub_context = GP_ContextSubContext(&context, NULL, 100, 100, 440, 280);
GP_Fill(sub_context, gray);
timer = SDL_AddTimer(60, timer_callback, NULL);
-----------------------------------------------------------------------
Summary of changes:
demos/fbshow/Makefile | 2 +-
demos/fbshow/fbshow.c | 2 +-
demos/grinder/Makefile | 2 +-
demos/grinder/grinder.c | 4 +-
include/core/GP_Context.h | 10 ++++-
include/filters/GP_Filters.h | 4 +-
include/filters/GP_Linear.h | 3 +-
include/filters/GP_Resize.h | 31 ++++++++++++----
libs/core/GP_Context.c | 14 +++++---
libs/filters/GP_Resize.c | 82 ++++++++++++++++++++++++------------------
tests/SDL/Makefile | 2 +-
tests/SDL/subcontext.c | 2 +-
12 files changed, 98 insertions(+), 60 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: 4061392c7024e648dc2bcfde720ce11e0f70dedb
by metan 31 Oct '11
by metan 31 Oct '11
31 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 4061392c7024e648dc2bcfde720ce11e0f70dedb (commit)
via f7f55767a6e8855d5e70a7220a5c9c1511251de5 (commit)
from a47b50d43100a1e3314a818f5bcdf37bf560d8d0 (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/4061392c7024e648dc2bcfde720ce11e0f70…
commit 4061392c7024e648dc2bcfde720ce11e0f70dedb
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Mon Oct 31 13:42:26 2011 +0100
Update filters docs, more to come.
diff --git a/doc/filters.txt b/doc/filters.txt
index d741abb..0f54e7a 100644
--- a/doc/filters.txt
+++ b/doc/filters.txt
@@ -1,44 +1,202 @@
Context filters
---------------
-Pixel filters for 'GP_Context'. The context filter is basially an function that modifies context somehow (may even allocate new context to store result).
+Pixel filters for 'GP_Context'.
-Rotation
-~~~~~~~~
+The context filter is basially an function that operates on context pixels.
+The result may be stored into a new bitmap or placed to bitmap passed as
+argument or, in some cases, the filter could be used 'in place' so the result
+is stored into the same context as the one passed as filter source.
+
+Progress Callback
+~~~~~~~~~~~~~~~~~
+
+Progress callback is a structure that stores user-defined callback function,
+pointer to store location of user data and percentage.
+
+[source,c]
+-------------------------------------------------------------------------------
+typdedef struct GP_ProgressCallback {
+ float percentage;
+ void (*callback)(struct GP_ProgressCallback *self);
+ void *priv;
+} GP_ProgressCallback;
+-------------------------------------------------------------------------------
+
+If non 'NULL' progress callback structure is passed to a filter function, the
+callback function is periodically called and the percentage is updated.
+
+The callback is, if supported, the last parameter of the filter function.
+
+Common filter API
+~~~~~~~~~~~~~~~~~
+
+The filters have, for your convinience unified API.
+
+* Each filter returns pointer to destination context or 'NULL' on failure
+* The first two arguments are source and destination
+* The last argument is progress callback
+
+Each filter function could be used in two modes.
+
+By passing non 'NULL' argument as filter destination user requests result to
+be stored into the destination context. The context must have correct pixel
+type and the context size must be big enough to store the result.
+
+For filters that works 'in-place' (which is explicitly said for each filter)
+the source and the destination could be the same context. Note that this is
+not expected to work if you do several overlaping subcontextes and pass these
+as arguments.
+
+When 'NULL' is passed as destination new context for storing the result is
+allocated and returned.
+
+The return value is either pointer to destination context or 'NULL' either
+when malloc(2) has failed or if the filter is not implemented for such
+pixel_type, parameters, etc...
+
+[source,c]
+-------------------------------------------------------------------------------
+/*
+ * Filter common api.
+ */
+GP_Context *GP_FilterFoo(const GP_Context *src, GP_Context *dst,
+ foo params ...,
+ GP_ProgressCallback *callback);
+-------------------------------------------------------------------------------
+
+
+Filters also exists in _Raw variant (that just takes source context,
+destination context, filters parameters and progress callback). These filter
+APIs are used for internal implementation and shouldn't be called by user as
+the destination is expected to be crafted exactly for storing the filter
+result and there are 'NO' sanity checks in place.
+
+'You could use these at your own risk'
+
+[source,c]
+-------------------------------------------------------------------------------
+/*
+ * Raw filter common api.
+ */
+void GP_FilterFoo_Raw(const GP_Context *src, GP_Context *dst,
+ foo params ...,
+ GP_ProgressCallback *callback);
+-------------------------------------------------------------------------------
+
+Rotation and Symmetries
+~~~~~~~~~~~~~~~~~~~~~~~
+
+[source,c]
+-------------------------------------------------------------------------------
+#include <GP_Filters.h>
+
+GP_Context *GP_FilterMirrorH(const GP_Context *src, GP_Context *dst,
+ GP_ProgressCallback *callback);
+-------------------------------------------------------------------------------
+
+Mirrors context horizontally.
+
+Works 'in-place'.
+
+The destination has to have the same pixel type and the destination size must
+be at least as big as source.
[source,c]
-------------------------------------------------------------------------------
#include <GP_Filters.h>
-GP_RetCode GP_MirrorH(GP_Context *context);
+GP_Context *GP_FilterMirrorV(const GP_Context *src, GP_Context *dst,
+ GP_ProgressCallback *callback);
-------------------------------------------------------------------------------
-Mirrors context pixels horizontaly and updates the context metadata.
+Mirrors context vertically.
+
+Works 'in-place'.
+
+the destination has to have the same pixel type and the destination size must
+be at least as big as source.
[source,c]
-------------------------------------------------------------------------------
#include <GP_Filters.h>
-GP_RetCode GP_MirrorV(GP_Context *context);
+GP_Context *GP_FilterRotate90(const GP_Context *src, GP_Context *dst,
+ GP_ProgressCallback *callback);
-------------------------------------------------------------------------------
-Mirrors context pixels verticaly and updates the context metadata.
+Rotate context by 90 degrees.
+
+Doesn't work 'in-place' (yet).
+
+The destinatoin has to have the same pixel type and destination size must be
+big enough to fit rotated context (eg. W and H are swapped).
[source,c]
-------------------------------------------------------------------------------
#include <GP_Filters.h>
-GP_RetCode GP_RotateCW(GP_Context *context);
+GP_Context *GP_FilterRotate180(const GP_Context *src, GP_Context *dst,
+ GP_ProgressCallback *callback);
-------------------------------------------------------------------------------
-Rotates context clock wise and updates the context metadata.
+Rotate context by 180 degrees.
+
+Doesn't work 'in-place' (yet).
+
+the destination has to have the same pixel type and the destination size must
+be at least as big as source.
[source,c]
-------------------------------------------------------------------------------
#include <GP_Filters.h>
-GP_RetCode GP_RotateCCW(GP_Context *context);
+GP_Context *GP_FilterRotate270(const GP_Context *src, GP_Context *dst,
+ GP_ProgressCallback *callback);
-------------------------------------------------------------------------------
-Rotates context counter clock wise and updates the context metadata.
+Rotate context by 270 degrees.
+
+Doesn't work 'in-place' (yet).
+
+The destinatoin has to have the same pixel type and destination size must be
+big enough to fit rotated context (eg. W and H are swapped).
+
+[source,c]
+-------------------------------------------------------------------------------
+typedef enum GP_FilterSymmetries {
+ GP_ROTATE_90,
+ GP_ROTATE_CW = GP_ROTATE_90,
+ GP_ROTATE_180,
+ GP_ROTATE_270,
+ GP_ROTATE_CCW = GP_ROTATE_270,
+ GP_MIRROR_H,
+ GP_MIRROR_V,
+} GP_FilterSymmetries;
+
+GP_Context *GP_FilterSymmetry(const GP_Context *src, GP_Context *dst,
+ GP_FilterSymmetries symmetry,
+ GP_ProgressCallback *callback);
+-------------------------------------------------------------------------------
+
+Catch all function for symmetry filters.
+
+
+Linear filters
+~~~~~~~~~~~~~~
+
+[source,c]
+-------------------------------------------------------------------------------
+#include <GP_Filters.h>
+
+GP_Context *GP_FilterGaussianBlur(const GP_Context *src, GP_Context *dst,
+ float sigma_x, float sigma_y,
+ GP_ProgressCallback *callback);
+-------------------------------------------------------------------------------
+
+Gaussian blur filter.
+
+Works 'in-place'.
+
+'TODO:' this filter is implemented for RGB888 only.
http://repo.or.cz/w/gfxprim.git/commit/f7f55767a6e8855d5e70a7220a5c9c151125…
commit f7f55767a6e8855d5e70a7220a5c9c1511251de5
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Mon Oct 31 13:41:20 2011 +0100
Remove unused accessor.
diff --git a/include/core/GP_Context.h b/include/core/GP_Context.h
index 00138df..80794d9 100644
--- a/include/core/GP_Context.h
+++ b/include/core/GP_Context.h
@@ -23,8 +23,8 @@
* *
*****************************************************************************/
-#ifndef GP_CONTEXT_H
-#define GP_CONTEXT_H
+#ifndef CORE_GP_CONTEXT_H
+#define CORE_GP_CONTEXT_H
#include <stdint.h>
#include <unistd.h>
@@ -59,12 +59,6 @@ typedef struct GP_Context {
uint8_t free_pixels:1; /* If set pixels are freed on GP_ContextFree */
} GP_Context;
-/* Returns the pixel type used by the context. */
-static inline GP_PixelType GP_GetContextPixelType(const GP_Context *context)
-{
- return context->pixel_type;
-}
-
/* Determines the address of a pixel within the context's image.
* Rows and columns are specified in the image's orientation
* (i.e. they might not be XY if the image is rotated).
@@ -157,4 +151,4 @@ static inline uint32_t GP_ContextH(const GP_Context *context)
return context->h;
}
-#endif /* GP_CONTEXT_H */
+#endif /* CORE_GP_CONTEXT_H */
-----------------------------------------------------------------------
Summary of changes:
doc/filters.txt | 180 ++++++++++++++++++++++++++++++++++++++++++---
include/core/GP_Context.h | 12 +--
2 files changed, 172 insertions(+), 20 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: a47b50d43100a1e3314a818f5bcdf37bf560d8d0
by metan 31 Oct '11
by metan 31 Oct '11
31 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 a47b50d43100a1e3314a818f5bcdf37bf560d8d0 (commit)
via e62510c49073237e02238eede6c52f04ef9acac3 (commit)
from 71f1574977b03a901b7381fb3aca1c6d0c3ed33d (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/a47b50d43100a1e3314a818f5bcdf37bf560…
commit a47b50d43100a1e3314a818f5bcdf37bf560d8d0
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Mon Oct 31 12:17:36 2011 +0100
The 18BPP needs an offset.
diff --git a/include/core/GP_WritePixel.h b/include/core/GP_WritePixel.h
index 9295835..26d072c 100644
--- a/include/core/GP_WritePixel.h
+++ b/include/core/GP_WritePixel.h
@@ -40,10 +40,10 @@
void GP_WritePixels1bpp(uint8_t *start, uint8_t off, size_t cnt, uint8_t val);
void GP_WritePixels2bpp(uint8_t *start, uint8_t off, size_t cnt, uint8_t val);
void GP_WritePixels4bpp(uint8_t *start, uint8_t off, size_t cnt, uint8_t val);
+void GP_WritePixels18bpp(void *start, uint8_t off, size_t count, uint32_t value);
void GP_WritePixels8bpp(void *start, size_t count, uint8_t value);
void GP_WritePixels16bpp(void *start, size_t count, uint16_t value);
-void GP_WritePixels18bpp(void *start, size_t count, uint32_t value);
void GP_WritePixels24bpp(void *start, size_t count, uint32_t value);
void GP_WritePixels32bpp(void *start, size_t count, uint32_t value);
diff --git a/libs/core/GP_WritePixel.c b/libs/core/GP_WritePixel.c
index 5638ca5..c35b7ec 100644
--- a/libs/core/GP_WritePixel.c
+++ b/libs/core/GP_WritePixel.c
@@ -162,7 +162,7 @@ void GP_WritePixels16bpp(void *start, size_t count, uint16_t value)
}
}
-void GP_WritePixels18bpp(void *start, size_t count, uint32_t value)
+void GP_WritePixels18bpp(void *start, uint8_t off, size_t count, uint32_t value)
{
#warning TODO
}
diff --git a/libs/gfx/GP_HLine.c b/libs/gfx/GP_HLine.c
index c249f49..38200d5 100644
--- a/libs/gfx/GP_HLine.c
+++ b/libs/gfx/GP_HLine.c
@@ -36,10 +36,10 @@ DEF_HLINE_BU_FN(GP_HLine_Raw_2BPP_LE, GP_Context*, GP_Pixel, GP_PIXEL_ADDR, GP_W
DEF_HLINE_BU_FN(GP_HLine_Raw_2BPP_BE, GP_Context*, GP_Pixel, GP_PIXEL_ADDR, GP_WritePixels2bpp)
DEF_HLINE_BU_FN(GP_HLine_Raw_4BPP_LE, GP_Context*, GP_Pixel, GP_PIXEL_ADDR, GP_WritePixels4bpp)
DEF_HLINE_BU_FN(GP_HLine_Raw_4BPP_BE, GP_Context*, GP_Pixel, GP_PIXEL_ADDR, GP_WritePixels4bpp)
+DEF_HLINE_BU_FN(GP_HLine_Raw_18BPP_LE, GP_Context *, GP_Pixel, GP_PIXEL_ADDR, GP_WritePixels18bpp)
DEF_HLINE_FN(GP_HLine_Raw_8BPP, GP_Context *, GP_Pixel, GP_PIXEL_ADDR, GP_WritePixels8bpp)
DEF_HLINE_FN(GP_HLine_Raw_16BPP, GP_Context *, GP_Pixel, GP_PIXEL_ADDR, GP_WritePixels16bpp)
-DEF_HLINE_FN(GP_HLine_Raw_18BPP_LE, GP_Context *, GP_Pixel, GP_PIXEL_ADDR, GP_WritePixels18bpp)
DEF_HLINE_FN(GP_HLine_Raw_24BPP, GP_Context *, GP_Pixel, GP_PIXEL_ADDR, GP_WritePixels24bpp)
DEF_HLINE_FN(GP_HLine_Raw_32BPP, GP_Context *, GP_Pixel, GP_PIXEL_ADDR, GP_WritePixels32bpp)
http://repo.or.cz/w/gfxprim.git/commit/e62510c49073237e02238eede6c52f04ef9a…
commit e62510c49073237e02238eede6c52f04ef9acac3
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Mon Oct 31 12:16:38 2011 +0100
More work on unifying the filter API.
diff --git a/demos/grinder/grinder.c b/demos/grinder/grinder.c
index beb69e2..27d8ded 100644
--- a/demos/grinder/grinder.c
+++ b/demos/grinder/grinder.c
@@ -350,7 +350,7 @@ static GP_RetCode blur(GP_Context **c, const char *params)
return GP_EINVAL;
}
- GP_FilterGaussianBlur_Raw(*c, *c, progress_callback, sigma_x, sigma_y);
+ GP_FilterGaussianBlur_Raw(*c, *c, sigma_x, sigma_y, progress_callback);
return GP_ESUCCESS;
}
diff --git a/include/filters/GP_Linear.h b/include/filters/GP_Linear.h
index 3194cb8..ae028fc 100644
--- a/include/filters/GP_Linear.h
+++ b/include/filters/GP_Linear.h
@@ -26,8 +26,8 @@
*/
-#ifndef GP_LINEAR_H
-#define GP_LINEAR_H
+#ifndef FILTERS_GP_LINEAR_H
+#define FILTERS_GP_LINEAR_H
#include "GP_Filter.h"
@@ -44,13 +44,21 @@
*
* GP_FilterGaussianBlur_Raw(context, context, ...);
*/
-void GP_FilterGaussianBlur_Raw(GP_Context *src, GP_Context *res,
- GP_ProgressCallback *callback,
- float sigma_x, float sigma_y);
-
-GP_Context *GP_FilterGaussianBlur(GP_Context *src,
- GP_ProgressCallback *callback,
- float sigma_x, float sigma_y);
+void GP_FilterGaussianBlur_Raw(const GP_Context *src, GP_Context *dst,
+ float sigma_x, float sigma_y,
+ GP_ProgressCallback *callback);
+/*
+ * Gaussian blur.
+ *
+ * If dst is NULL, new bitmap is allocated.
+ *
+ * This variant could work in-place.
+ *
+ * Returns pointer to destination bitmap or NULL if allocation failed.
+ */
+GP_Context *GP_FilterGaussianBlur(const GP_Context *src, GP_Context *dst,
+ float sigma_x, float sigma_y,
+ GP_ProgressCallback *callback);
/*
* Linear convolution.
@@ -69,24 +77,26 @@ GP_Context *GP_FilterGaussianBlur(GP_Context *src,
*
* This function works also in-place.
*/
-void GP_FilterLinearConvolution_Raw(const GP_Context *src, GP_Context *res,
- GP_ProgressCallback *callback,
- float kernel[], uint32_t kw, uint32_t kh);
+void GP_FilterLinearConvolution_Raw(const GP_Context *src, GP_Context *dst,
+ float kernel[], uint32_t kw, uint32_t kh,
+ GP_ProgressCallback *callback);
/*
* Special cases for convolution only in horizontal/vertical direction.
*
* These are about 10-30% faster than the generic implementation (depending on
* the kernel size, bigger kernel == more savings).
- *
+ *
+ * These are two are a base for bilinear filters.
+ *
* Both works also in-place.
*/
-void GP_FilterHLinearConvolution_Raw(const GP_Context *src, GP_Context *res,
- GP_ProgressCallback *callback,
- float kernel[], uint32_t kw);
+void GP_FilterHLinearConvolution_Raw(const GP_Context *src, GP_Context *dst,
+ float kernel[], uint32_t kw,
+ GP_ProgressCallback *callback);
-void GP_FilterVLinearConvolution_Raw(const GP_Context *src, GP_Context *res,
- GP_ProgressCallback *callback,
- float kernel[], uint32_t kh);
+void GP_FilterVLinearConvolution_Raw(const GP_Context *src, GP_Context *dst,
+ float kernel[], uint32_t kh,
+ GP_ProgressCallback *callback);
-#endif /* GP_LINEAR_H */
+#endif /* FILTERS_GP_LINEAR_H */
diff --git a/libs/filters/GP_Linear.c b/libs/filters/GP_Linear.c
index 8f7c2a3..b0148c9 100644
--- a/libs/filters/GP_Linear.c
+++ b/libs/filters/GP_Linear.c
@@ -59,9 +59,9 @@ static void gaussian_callback_2(GP_ProgressCallback *self)
GP_ProgressCallbackReport(self->priv, self->percentage/2 + 50);
}
-void GP_FilterGaussianBlur_Raw(GP_Context *src, GP_Context *res,
- GP_ProgressCallback *callback,
- float sigma_x, float sigma_y)
+void GP_FilterGaussianBlur_Raw(const GP_Context *src, GP_Context *dst,
+ float sigma_x, float sigma_y,
+ GP_ProgressCallback *callback)
{
unsigned int size_x = gaussian_kernel_size(sigma_x);
unsigned int size_y = gaussian_kernel_size(sigma_y);
@@ -84,8 +84,8 @@ void GP_FilterGaussianBlur_Raw(GP_Context *src, GP_Context *res,
float kernel_x[size_x];
gaussian_kernel_init(sigma_x, kernel_x);
- GP_FilterHLinearConvolution_Raw(src, res, new_callback,
- kernel_x, size_x);
+ GP_FilterHLinearConvolution_Raw(src, dst, kernel_x, size_x,
+ new_callback);
}
if (new_callback != NULL)
@@ -96,37 +96,41 @@ void GP_FilterGaussianBlur_Raw(GP_Context *src, GP_Context *res,
float kernel_y[size_y];
gaussian_kernel_init(sigma_y, kernel_y);
- GP_FilterVLinearConvolution_Raw(res, res, new_callback,
- kernel_y, size_y);
+ GP_FilterVLinearConvolution_Raw(dst, dst, kernel_y, size_y,
+ new_callback);
}
GP_ProgressCallbackDone(callback);
}
-GP_Context *GP_FilterGaussianBlur(GP_Context *src,
- GP_ProgressCallback *callback,
- float sigma_x, float sigma_y)
+GP_Context *GP_FilterGaussianBlur(const GP_Context *src, GP_Context *dst,
+ float sigma_x, float sigma_y,
+ GP_ProgressCallback *callback)
{
- GP_Context *res;
-
+ /* TODO: templatetize */
if (src->pixel_type != GP_PIXEL_RGB888)
return NULL;
-
- res = GP_ContextCopy(src, 0);
-
- if (res == NULL) {
- GP_DEBUG(1, "Malloc failed :(");
- return NULL;
+
+ if (dst == NULL) {
+ dst = GP_ContextCopy(src, 0);
+
+ if (dst == NULL)
+ return NULL;
+ } else {
+ GP_ASSERT(src->pixel_type == dst->pixel_type,
+ "The src and dst pixel types must match");
+ GP_ASSERT(src->w <= dst->w && src->h <= dst->h,
+ "Destination is not big enough");
}
- GP_FilterGaussianBlur_Raw(src, res, callback, sigma_x, sigma_y);
+ GP_FilterGaussianBlur_Raw(src, dst, sigma_x, sigma_y, callback);
- return res;
+ return dst;
}
-void GP_FilterHLinearConvolution_Raw(const GP_Context *src, GP_Context *res,
- GP_ProgressCallback *callback,
- float kernel[], uint32_t kw)
+void GP_FilterHLinearConvolution_Raw(const GP_Context *src, GP_Context *dst,
+ float kernel[], uint32_t kw,
+ GP_ProgressCallback *callback)
{
float kernel_sum = 0;
GP_Coord x, y;
@@ -140,7 +144,7 @@ void GP_FilterHLinearConvolution_Raw(const GP_Context *src, GP_Context *res,
kernel_sum += kernel[i];
/* do linear convolution */
- for (y = 0; y < (GP_Coord)res->h; y++) {
+ for (y = 0; y < (GP_Coord)dst->h; y++) {
GP_Pixel pix;
uint32_t R[kw], G[kw], B[kw];
@@ -160,7 +164,7 @@ void GP_FilterHLinearConvolution_Raw(const GP_Context *src, GP_Context *res,
int idx = kw - 1;
- for (x = 0; x < (GP_Coord)res->w; x++) {
+ for (x = 0; x < (GP_Coord)dst->w; x++) {
float r = 0, g = 0, b = 0;
int cx = x + kw/2;
@@ -209,7 +213,7 @@ void GP_FilterHLinearConvolution_Raw(const GP_Context *src, GP_Context *res,
pix = GP_Pixel_CREATE_RGB888((uint32_t)r, (uint32_t)g, (uint32_t)b);
- GP_PutPixel_Raw_24BPP(res, x, y, pix);
+ GP_PutPixel_Raw_24BPP(dst, x, y, pix);
idx++;
@@ -218,7 +222,7 @@ void GP_FilterHLinearConvolution_Raw(const GP_Context *src, GP_Context *res,
}
if (callback != NULL && y % 100 == 0)
- GP_ProgressCallbackReport(callback, 100.00 * y/res->h);
+ GP_ProgressCallbackReport(callback, 100.00 * y/dst->h);
}
GP_ProgressCallbackDone(callback);
@@ -229,9 +233,9 @@ void GP_FilterHLinearConvolution_Raw(const GP_Context *src, GP_Context *res,
*
* Can be used in-place.
*/
-void GP_FilterVLinearConvolution_Raw(const GP_Context *src, GP_Context *res,
- GP_ProgressCallback *callback,
- float kernel[], uint32_t kh)
+void GP_FilterVLinearConvolution_Raw(const GP_Context *src, GP_Context *dst,
+ float kernel[], uint32_t kh,
+ GP_ProgressCallback *callback)
{
float kernel_sum = 0;
GP_Coord x, y;
@@ -245,7 +249,7 @@ void GP_FilterVLinearConvolution_Raw(const GP_Context *src, GP_Context *res,
kernel_sum += kernel[i];
/* do linear convolution */
- for (x = 0; x < (GP_Coord)res->w; x++) {
+ for (x = 0; x < (GP_Coord)dst->w; x++) {
GP_Pixel pix;
uint32_t R[kh], G[kh], B[kh];
@@ -265,7 +269,7 @@ void GP_FilterVLinearConvolution_Raw(const GP_Context *src, GP_Context *res,
int idx = kh - 1;
- for (y = 0; y < (GP_Coord)res->h; y++) {
+ for (y = 0; y < (GP_Coord)dst->h; y++) {
float r = 0, g = 0, b = 0;
int cy = y + kh/2;
@@ -314,7 +318,7 @@ void GP_FilterVLinearConvolution_Raw(const GP_Context *src, GP_Context *res,
pix = GP_Pixel_CREATE_RGB888((uint32_t)r, (uint32_t)g, (uint32_t)b);
- GP_PutPixel_Raw_24BPP(res, x, y, pix);
+ GP_PutPixel_Raw_24BPP(dst, x, y, pix);
idx++;
@@ -323,7 +327,7 @@ void GP_FilterVLinearConvolution_Raw(const GP_Context *src, GP_Context *res,
}
if (callback != NULL && x % 100 == 0)
- GP_ProgressCallbackReport(callback, 100.00 * x/res->w);
+ GP_ProgressCallbackReport(callback, 100.00 * x/dst->w);
}
GP_ProgressCallbackDone(callback);
@@ -335,9 +339,9 @@ void GP_FilterVLinearConvolution_Raw(const GP_Context *src, GP_Context *res,
*
* Can be used in-place.
*/
-void GP_FilterLinearConvolution_Raw(const GP_Context *src, GP_Context *res,
- GP_ProgressCallback *callback,
- float kernel[], uint32_t kw, uint32_t kh)
+void GP_FilterLinearConvolution_Raw(const GP_Context *src, GP_Context *dst,
+ float kernel[], uint32_t kw, uint32_t kh,
+ GP_ProgressCallback *callback)
{
float kernel_sum = 0;
GP_Coord x, y;
@@ -351,7 +355,7 @@ void GP_FilterLinearConvolution_Raw(const GP_Context *src, GP_Context *res,
kernel_sum += kernel[i];
/* do linear convolution */
- for (y = 0; y < (GP_Coord)res->h; y++) {
+ for (y = 0; y < (GP_Coord)dst->h; y++) {
GP_Pixel pix;
uint32_t R[kw][kh], G[kw][kh], B[kw][kh];
@@ -380,7 +384,7 @@ void GP_FilterLinearConvolution_Raw(const GP_Context *src, GP_Context *res,
int idx = kw - 1;
- for (x = 0; x < (GP_Coord)res->w; x++) {
+ for (x = 0; x < (GP_Coord)dst->w; x++) {
float r = 0, g = 0, b = 0;
for (j = 0; j < kh; j++) {
@@ -440,7 +444,7 @@ void GP_FilterLinearConvolution_Raw(const GP_Context *src, GP_Context *res,
pix = GP_Pixel_CREATE_RGB888((uint32_t)r, (uint32_t)g, (uint32_t)b);
- GP_PutPixel_Raw_24BPP(res, x, y, pix);
+ GP_PutPixel_Raw_24BPP(dst, x, y, pix);
idx++;
@@ -449,7 +453,7 @@ void GP_FilterLinearConvolution_Raw(const GP_Context *src, GP_Context *res,
}
if (callback != NULL && y % 100 == 0)
- GP_ProgressCallbackReport(callback, 100.00 * y/res->h);
+ GP_ProgressCallbackReport(callback, 100.00 * y/dst->h);
}
GP_ProgressCallbackDone(callback);
-----------------------------------------------------------------------
Summary of changes:
demos/grinder/grinder.c | 2 +-
include/core/GP_WritePixel.h | 2 +-
include/filters/GP_Linear.h | 50 ++++++++++++++----------
libs/core/GP_WritePixel.c | 2 +-
libs/filters/GP_Linear.c | 86 ++++++++++++++++++++++--------------------
libs/gfx/GP_HLine.c | 2 +-
6 files changed, 79 insertions(+), 65 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: 71f1574977b03a901b7381fb3aca1c6d0c3ed33d
by metan 30 Oct '11
by metan 30 Oct '11
30 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 71f1574977b03a901b7381fb3aca1c6d0c3ed33d (commit)
from b964f56ae4fe0a0a48f16fc18a8daec953acb3cc (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/71f1574977b03a901b7381fb3aca1c6d0c3e…
commit 71f1574977b03a901b7381fb3aca1c6d0c3ed33d
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Sun Oct 30 17:48:04 2011 +0100
Proved myself wrong, we need to read last two bytes.
Still haven't tried the code, just proved, while
riding the train, that sometimes we need to get
last two bytes.
diff --git a/include/core/GP_GetSetBits.h b/include/core/GP_GetSetBits.h
index bd55fe2..d724828 100644
--- a/include/core/GP_GetSetBits.h
+++ b/include/core/GP_GetSetBits.h
@@ -27,8 +27,8 @@
*/
-#ifndef GP_GET_SET_BITS_H
-#define GP_GET_SET_BITS_H
+#ifndef CORE_GP_GET_SET_BITS_H
+#define CORE_GP_GET_SET_BITS_H
/*
* Helper macros to read/write parts of words
@@ -122,6 +122,7 @@
#define GP_SET_BITS3_ALIGNED(offset, len, dest, val) do { uint32_t v; v = ((uint8_t *)dest)[0]; + v |= ((uint8_t *)dest)[1]<<8; v |= ((uint8_t *)dest)[2]<<16; GP_SET_BITS(offset, len, v, val); @@ -134,6 +135,7 @@
#define GP_SET_BITS4_ALIGNED(offset, len, dest, val) do { uint32_t v; v = ((uint8_t *)dest)[0]; + v |= ((uint8_t *)dest)[2]<<16; v |= ((uint8_t *)dest)[3]<<24; GP_SET_BITS(offset, len, v, val); @@ -145,4 +147,4 @@
} while (0)
-#endif /* GP_GET_SET_BITS_H */
+#endif /* CORE_GP_GET_SET_BITS_H */
-----------------------------------------------------------------------
Summary of changes:
include/core/GP_GetSetBits.h | 8 +++++---
1 files changed, 5 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: b964f56ae4fe0a0a48f16fc18a8daec953acb3cc
by metan 30 Oct '11
by metan 30 Oct '11
30 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 b964f56ae4fe0a0a48f16fc18a8daec953acb3cc (commit)
from 3037f6a8d06bf7262dbaf15395affd4e241fad1d (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/b964f56ae4fe0a0a48f16fc18a8daec953ac…
commit b964f56ae4fe0a0a48f16fc18a8daec953acb3cc
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Sun Oct 30 17:41:16 2011 +0100
Changed the filter API (hopefully this is final version).
diff --git a/demos/grinder/grinder.c b/demos/grinder/grinder.c
index f372bf5..beb69e2 100644
--- a/demos/grinder/grinder.c
+++ b/demos/grinder/grinder.c
@@ -217,13 +217,13 @@ static GP_RetCode rotate(GP_Context **c, const char *params)
switch (rot) {
case 0:
- res = GP_FilterRotate90(*c, progress_callback);
+ res = GP_FilterRotate90(*c, NULL, progress_callback);
break;
case 1:
- res = GP_FilterRotate180(*c, progress_callback);
+ res = GP_FilterRotate180(*c, NULL, progress_callback);
break;
case 2:
- res = GP_FilterRotate270(*c, progress_callback);
+ res = GP_FilterRotate270(*c, NULL, progress_callback);
break;
}
diff --git a/include/filters/GP_Rotate.h b/include/filters/GP_Rotate.h
index daa8287..245e3c2 100644
--- a/include/filters/GP_Rotate.h
+++ b/include/filters/GP_Rotate.h
@@ -40,7 +40,14 @@
void GP_FilterMirrorH_Raw(const GP_Context *src, GP_Context *dst,
GP_ProgressCallback *callback);
-GP_Context *GP_FilterMirrorH(const GP_Context *src,
+/*
+ * Mirrors bitmap horizontally.
+ *
+ * If dst is NULL, new bitmap is allocated.
+ *
+ * Returns pointer to destination bitmap or NULL if allocation failed.
+ */
+GP_Context *GP_FilterMirrorH(const GP_Context *src, GP_Context *dst,
GP_ProgressCallback *callback);
/*
@@ -51,14 +58,21 @@ GP_Context *GP_FilterMirrorH(const GP_Context *src,
void GP_FilterMirrorV_Raw(const GP_Context *src, GP_Context *dst,
GP_ProgressCallback *callback);
-GP_Context *GP_FilterMirrorV(const GP_Context *src,
+/*
+ * Mirrors bitmap vertically.
+ *
+ * If dst is NULL, new bitmap is allocated.
+ *
+ * Returns pointer to destination bitmap or NULL if allocation failed.
+ */
+GP_Context *GP_FilterMirrorV(const GP_Context *src, GP_Context *dst,
GP_ProgressCallback *callback);
/*
* Rotate context by 90, 180 and 270.
*
* Doesn't work 'in place'. The contexts must have equal pixel_type size must
- * match the rotated size size (is equal for 180 and swapped for 90 and 270).
+ * match the rotated size (is equal for 180 and swapped for 90 and 270).
*/
void GP_FilterRotate90_Raw(const GP_Context *src, GP_Context *dst,
GP_ProgressCallback *callback);
@@ -69,7 +83,30 @@ void GP_FilterRotate180_Raw(const GP_Context *src, GP_Context *dst,
void GP_FilterRotate270_Raw(const GP_Context *src, GP_Context *dst,
GP_ProgressCallback *callback);
-typedef enum GP_FilterRotation {
+/*
+ * Rotate the context by 90, 180, 270.
+ *
+ * If dst is NULL, new bitmap is allocated.
+ *
+ * Returns pointer to destination bitmap or NULL if allocation failed.
+ */
+GP_Context *GP_FilterRotate90(const GP_Context *src, GP_Context *dst,
+ GP_ProgressCallback *callback);
+
+GP_Context *GP_FilterRotate180(const GP_Context *src, GP_Context *dst,
+ GP_ProgressCallback *callback);
+
+GP_Context *GP_FilterRotate270(const GP_Context *src, GP_Context *dst,
+ GP_ProgressCallback *callback);
+
+/*
+ * Calls a symmetry filter on bitmap.
+ *
+ * If dst is NULL, new bitmap is allocated.
+ *
+ * Returns pointer to destination bitmap or NULL if allocation failed.
+ */
+typedef enum GP_FilterSymmetries {
GP_ROTATE_90,
GP_ROTATE_CW = GP_ROTATE_90,
GP_ROTATE_180,
@@ -77,32 +114,10 @@ typedef enum GP_FilterRotation {
GP_ROTATE_CCW = GP_ROTATE_270,
GP_MIRROR_H,
GP_MIRROR_V,
-} GP_FilterRotation;
-
-void GP_FilterRotate_Raw(const GP_Context *src, GP_Context *dst,
- GP_FilterRotation rotation,
- GP_ProgressCallback *callback);
-
-GP_Context *GP_FilterRotate(const GP_Context *context,
- GP_FilterRotation rotation,
- GP_ProgressCallback *callback);
+} GP_FilterSymmetries;
-static inline GP_Context *GP_FilterRotate90(const GP_Context *src,
- GP_ProgressCallback *callback)
-{
- return GP_FilterRotate(src, GP_ROTATE_90, callback);
-}
-
-static inline GP_Context *GP_FilterRotate180(const GP_Context *src,
- GP_ProgressCallback *callback)
-{
- return GP_FilterRotate(src, GP_ROTATE_180, callback);
-}
-
-static inline GP_Context *GP_FilterRotate270(const GP_Context *src,
- GP_ProgressCallback *callback)
-{
- return GP_FilterRotate(src, GP_ROTATE_270, callback);
-}
+GP_Context *GP_FilterSymmetry(const GP_Context *src, GP_Context *dst,
+ GP_FilterSymmetries symmetry,
+ GP_ProgressCallback *callback);
#endif /* FILTERS_GP_ROTATE_H */
diff --git a/libs/filters/GP_Rotate.c b/libs/filters/GP_Rotate.c
index ea7ae0a..73987e7 100644
--- a/libs/filters/GP_Rotate.c
+++ b/libs/filters/GP_Rotate.c
@@ -53,8 +53,49 @@ void GP_FilterMirrorH_Raw(const GP_Context *src, GP_Context *dst,
GP_ProgressCallbackDone(callback);
}
+GP_Context *GP_FilterMirrorH(const GP_Context *src, GP_Context *dst,
+ GP_ProgressCallback *callback)
+{
+ if (dst == NULL) {
+ dst = GP_ContextCopy(src, 0);
+
+ if (dst == NULL)
+ return NULL;
+ } else {
+ GP_ASSERT(src->pixel_type == dst->pixel_type,
+ "The src and dst pixel types must match");
+ GP_ASSERT(src->w <= dst->w && src->h <= dst->h,
+ "Destination is not big enough");
+ }
+
+ GP_FilterMirrorH_Raw(src, dst, callback);
+
+ return dst;
+}
+
+
+GP_Context *GP_FilterMirrorV(const GP_Context *src, GP_Context *dst,
+ GP_ProgressCallback *callback)
+{
+ if (dst == NULL) {
+ dst = GP_ContextCopy(src, 0);
+
+ if (dst == NULL)
+ return NULL;
+ } else {
+ GP_ASSERT(src->pixel_type == dst->pixel_type,
+ "The src and dst pixel types must match");
+ GP_ASSERT(src->w <= dst->w && src->h <= dst->h,
+ "Destination is not big enough");
+ }
+
+ GP_FilterMirrorV_Raw(src, dst, callback);
+
+ return dst;
+}
+
void GP_FilterRotate180_Raw(const GP_Context *src, GP_Context *dst,
- GP_ProgressCallback *callback)
+ GP_ProgressCallback *callback)
{
#warning FIXME: Callbacks, faster algorighm?
@@ -62,53 +103,82 @@ void GP_FilterRotate180_Raw(const GP_Context *src, GP_Context *dst,
GP_FilterMirrorH_Raw(dst, dst, callback);
}
-void GP_FilterRotate_Raw(const GP_Context *src, GP_Context *dst,
- GP_FilterRotation rotation,
- GP_ProgressCallback *callback)
+GP_Context *GP_FilterRotate90(const GP_Context *src, GP_Context *dst,
+ GP_ProgressCallback *callback)
{
- switch (rotation) {
- case GP_ROTATE_90:
- GP_FilterRotate90_Raw(src, dst, callback);
- break;
- case GP_ROTATE_180:
- GP_FilterRotate180_Raw(src, dst, callback);
- break;
- case GP_ROTATE_270:
- GP_FilterRotate270_Raw(src, dst, callback);
- break;
- case GP_MIRROR_H:
- GP_FilterMirrorH_Raw(src, dst, callback);
- break;
- case GP_MIRROR_V:
- GP_FilterMirrorV_Raw(src, dst, callback);
- break;
+ if (dst == NULL) {
+ dst = GP_ContextAlloc(src->h, src->w, src->pixel_type);
+
+ if (dst == NULL)
+ return NULL;
+ } else {
+ GP_ASSERT(src->pixel_type == dst->pixel_type,
+ "The src and dst pixel types must match");
+ GP_ASSERT(src->w <= dst->h && src->h <= dst->w,
+ "Destination is not big enough");
}
+
+ GP_FilterRotate90_Raw(src, dst, callback);
+
+ return dst;
}
-GP_Context *GP_FilterRotate(const GP_Context *context,
- GP_FilterRotation rotation,
- GP_ProgressCallback *callback)
+GP_Context *GP_FilterRotate180(const GP_Context *src, GP_Context *dst,
+ GP_ProgressCallback *callback)
{
- GP_Size w = context->w;
- GP_Size h = context->h;
-
- switch (rotation) {
- case GP_ROTATE_90:
- case GP_ROTATE_270:
- GP_SWAP(w, h);
- break;
- default:
- break;
+ if (dst == NULL) {
+ dst = GP_ContextCopy(src, 0);
+
+ if (dst == NULL)
+ return NULL;
+ } else {
+ GP_ASSERT(src->pixel_type == dst->pixel_type,
+ "The src and dst pixel types must match");
+ GP_ASSERT(src->w <= dst->w && src->h <= dst->h,
+ "Destination is not big enough");
}
- GP_Context *ret = GP_ContextAlloc(w, h, context->pixel_type);
+ GP_FilterRotate180_Raw(src, dst, callback);
+
+ return dst;
+}
- if (unlikely(ret == NULL)) {
- GP_DEBUG(1, "Malloc failed :(");
- return NULL;
+GP_Context *GP_FilterRotate270(const GP_Context *src, GP_Context *dst,
+ GP_ProgressCallback *callback)
+{
+ if (dst == NULL) {
+ dst = GP_ContextAlloc(src->h, src->w, src->pixel_type);
+
+ if (dst == NULL)
+ return NULL;
+ } else {
+ GP_ASSERT(src->pixel_type == dst->pixel_type,
+ "The src and dst pixel types must match");
+ GP_ASSERT(src->w <= dst->h && src->h <= dst->w,
+ "Destination is not big enough");
}
- GP_FilterRotate_Raw(context, ret, rotation, callback);
+ GP_FilterRotate270_Raw(src, dst, callback);
+
+ return dst;
+}
+
+GP_Context *GP_FilterSymmetry(const GP_Context *src, GP_Context *dst,
+ GP_FilterSymmetries symmetry,
+ GP_ProgressCallback *callback)
+{
+ switch (symmetry) {
+ case GP_ROTATE_90:
+ return GP_FilterRotate90(src, dst, callback);
+ case GP_ROTATE_180:
+ return GP_FilterRotate180(src, dst, callback);
+ case GP_ROTATE_270:
+ return GP_FilterRotate270(src, dst, callback);
+ case GP_MIRROR_H:
+ return GP_FilterMirrorH(src, dst, callback);
+ case GP_MIRROR_V:
+ return GP_FilterMirrorV(src, dst, callback);
+ }
- return ret;
+ return NULL;
}
-----------------------------------------------------------------------
Summary of changes:
demos/grinder/grinder.c | 6 +-
include/filters/GP_Rotate.h | 75 +++++++++++++---------
libs/filters/GP_Rotate.c | 148 +++++++++++++++++++++++++++++++-----------
3 files changed, 157 insertions(+), 72 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: 3037f6a8d06bf7262dbaf15395affd4e241fad1d
by metan 27 Oct '11
by metan 27 Oct '11
27 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 3037f6a8d06bf7262dbaf15395affd4e241fad1d (commit)
via a8f1ba07c9863cdda6b55a7b82fb35fbe55758a9 (commit)
via bcaa19c8129a6bcaac8a3640979e91135c016846 (commit)
via 828d02ecb1948597d7f7b83e86f15e7bb7ca9164 (commit)
from 7d1c1b2c4aeef95941109cbdc5707eff6ad0a36f (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/3037f6a8d06bf7262dbaf15395affd4e241f…
commit 3037f6a8d06bf7262dbaf15395affd4e241fad1d
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Thu Oct 27 23:07:13 2011 +0200
Rewrote rotate and mirror filters.
diff --git a/demos/grinder/grinder.c b/demos/grinder/grinder.c
index 26d6d0d..f372bf5 100644
--- a/demos/grinder/grinder.c
+++ b/demos/grinder/grinder.c
@@ -213,18 +213,49 @@ static GP_RetCode rotate(GP_Context **c, const char *params)
return GP_EINVAL;
}
+ GP_Context *res = NULL;
+
switch (rot) {
case 0:
- GP_RotateCW(*c);
+ res = GP_FilterRotate90(*c, progress_callback);
break;
case 1:
- GP_MirrorV(*c);
- GP_MirrorH(*c);
+ res = GP_FilterRotate180(*c, progress_callback);
break;
case 2:
- GP_RotateCCW(*c);
+ res = GP_FilterRotate270(*c, progress_callback);
break;
}
+
+ if (res == NULL)
+ return GP_ENOMEM;
+
+ GP_ContextFree(*c);
+ *c = res;
+
+ return GP_ESUCCESS;
+}
+
+/* mirror filter */
+
+static struct param mirror_params[] = {
+ {"vert", PARAM_BOOL, "mirror vertically", NULL, NULL},
+ {"horiz", PARAM_BOOL, "mirror horizontally", NULL, NULL},
+ {NULL, 0, NULL, NULL, NULL}
+};
+
+static GP_RetCode mirror(GP_Context **c, const char *params)
+{
+ int vert = 0, horiz = 0;
+
+ if (param_parse(params, mirror_params, "mirror", param_err, &vert, &horiz))
+ return GP_EINVAL;
+
+ if (vert)
+ GP_FilterMirrorV_Raw(*c, *c, progress_callback);
+
+ if (horiz)
+ GP_FilterMirrorH_Raw(*c, *c, progress_callback);
return GP_ESUCCESS;
}
@@ -334,9 +365,10 @@ 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},
+ {"mirror", "mirror vertically/horizontally", mirror_params, mirror},
+ {"scale", "scale image to given width and height", scale_params, scale},
+ {"resize", "resize image by given ratio", resize_params, resize},
{"bright", "alter image brightness", bright_params, bright},
{"contrast", "alter image contrast", contrast_params, contrast},
{"invert", "inverts image", invert_params, invert},
diff --git a/demos/grinder/params.c b/demos/grinder/params.c
index d2dbfb9..17aebb9 100644
--- a/demos/grinder/params.c
+++ b/demos/grinder/params.c
@@ -183,6 +183,39 @@ int set_int(int *res, char *val)
return 0;
}
+static char *bool_false[] = {
+ "No",
+ "False",
+ "Off",
+ NULL
+};
+
+static char *bool_true[] = {
+ "Yes",
+ "True",
+ "On",
+ NULL
+};
+
+int set_bool(int *res, char *val)
+{
+ unsigned int i;
+
+ for (i = 0; bool_false[i] != NULL; i++)
+ if (!strcasecmp(val, bool_false[i])) {
+ *res = 0;
+ return 0;
+ }
+
+ for (i = 0; bool_true[i] != NULL; i++)
+ if (!strcasecmp(val, bool_true[i])) {
+ *res = 1;
+ return 0;
+ }
+
+ return 1;
+}
+
int set_float(float *res, char *val)
{
char *end;
@@ -269,7 +302,11 @@ int param_parse(const char *params, const struct param *param_desc, void *priv,
switch (param_desc[i].type) {
case PARAM_BOOL:
-
+ if ((ret = set_bool(arg, values[pos]))) {
+ CALL_ERR_CALLBACK(err, ¶m_desc[i],
+ values[pos], priv);
+ goto err;
+ }
break;
case PARAM_INT:
if ((ret = set_int(arg, values[pos]))) {
diff --git a/include/filters/GP_Rotate.h b/include/filters/GP_Rotate.h
index e73b0fe..daa8287 100644
--- a/include/filters/GP_Rotate.h
+++ b/include/filters/GP_Rotate.h
@@ -16,42 +16,93 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, *
* Boston, MA 02110-1301 USA *
* *
- * Copyright (C) 2009-2010 Jiri "BlueBear" Dluhos *
- * <jiri.bluebear.dluhos(a)gmail.com> *
- * *
- * Copyright (C) 2009-2010 Cyril Hrubis <metan(a)ucw.cz> *
+ * Copyright (C) 2009-2011 Cyril Hrubis <metan(a)ucw.cz> *
* *
*****************************************************************************/
/*
- GP_Context in place rotations.
+ GP_Context rotations and mirroring.
*/
-#ifndef GP_ROTATE_H
-#define GP_ROTATE_H
+#ifndef FILTERS_GP_ROTATE_H
+#define FILTERS_GP_ROTATE_H
#include "core/GP_Context.h"
+#include "GP_Filter.h"
/*
* Mirror horizontally.
+ *
+ * Works 'in place'. The contexts must have equal pixel_type and size.
*/
-GP_RetCode GP_MirrorH(GP_Context *context);
+void GP_FilterMirrorH_Raw(const GP_Context *src, GP_Context *dst,
+ GP_ProgressCallback *callback);
+
+GP_Context *GP_FilterMirrorH(const GP_Context *src,
+ GP_ProgressCallback *callback);
/*
* Mirror vertically
+ *
+ * Works 'in place'. The contexts must have equal pixel_type and size.
*/
-GP_RetCode GP_MirrorV(GP_Context *context);
+void GP_FilterMirrorV_Raw(const GP_Context *src, GP_Context *dst,
+ GP_ProgressCallback *callback);
-/*
- * Rotate clockwise.
- */
-GP_RetCode GP_RotateCW(GP_Context *context);
+GP_Context *GP_FilterMirrorV(const GP_Context *src,
+ GP_ProgressCallback *callback);
/*
- * Rotate counter clockwise.
+ * Rotate context by 90, 180 and 270.
+ *
+ * Doesn't work 'in place'. The contexts must have equal pixel_type size must
+ * match the rotated size size (is equal for 180 and swapped for 90 and 270).
*/
-GP_RetCode GP_RotateCCW(GP_Context *context);
+void GP_FilterRotate90_Raw(const GP_Context *src, GP_Context *dst,
+ GP_ProgressCallback *callback);
+
+void GP_FilterRotate180_Raw(const GP_Context *src, GP_Context *dst,
+ GP_ProgressCallback *callback);
+
+void GP_FilterRotate270_Raw(const GP_Context *src, GP_Context *dst,
+ GP_ProgressCallback *callback);
+
+typedef enum GP_FilterRotation {
+ GP_ROTATE_90,
+ GP_ROTATE_CW = GP_ROTATE_90,
+ GP_ROTATE_180,
+ GP_ROTATE_270,
+ GP_ROTATE_CCW = GP_ROTATE_270,
+ GP_MIRROR_H,
+ GP_MIRROR_V,
+} GP_FilterRotation;
+
+void GP_FilterRotate_Raw(const GP_Context *src, GP_Context *dst,
+ GP_FilterRotation rotation,
+ GP_ProgressCallback *callback);
+
+GP_Context *GP_FilterRotate(const GP_Context *context,
+ GP_FilterRotation rotation,
+ GP_ProgressCallback *callback);
+
+static inline GP_Context *GP_FilterRotate90(const GP_Context *src,
+ GP_ProgressCallback *callback)
+{
+ return GP_FilterRotate(src, GP_ROTATE_90, callback);
+}
+
+static inline GP_Context *GP_FilterRotate180(const GP_Context *src,
+ GP_ProgressCallback *callback)
+{
+ return GP_FilterRotate(src, GP_ROTATE_180, callback);
+}
+
+static inline GP_Context *GP_FilterRotate270(const GP_Context *src,
+ GP_ProgressCallback *callback)
+{
+ return GP_FilterRotate(src, GP_ROTATE_270, callback);
+}
-#endif /* GP_ROTATE_H */
+#endif /* FILTERS_GP_ROTATE_H */
diff --git a/libs/filters/GP_MirrorV.gen.c.t b/libs/filters/GP_MirrorV.gen.c.t
new file mode 100644
index 0000000..c696349
--- /dev/null
+++ b/libs/filters/GP_MirrorV.gen.c.t
@@ -0,0 +1,44 @@
+%% extends "base.c.t"
+
+%% block descr
+Vertical Mirror alogorithm
+%% endblock
+
+%% block body
+
+#include "core/GP_GetPutPixel.h"
+#include "core/GP_Debug.h"
+#include "GP_Rotate.h"
+
+%% for ps in pixelsizes
+void GP_MirrorV_Raw_{{ ps.suffix }}(const GP_Context *src, GP_Context *dst,
+ GP_ProgressCallback *callback)
+{
+ uint32_t x, y;
+ GP_Pixel tmp;
+
+ GP_DEBUG(1, "Mirroring image vertically %ux%u", src->w, src->h);
+
+ for (x = 0; x < src->w/2; x++) {
+ uint32_t xm = src->w - x - 1;
+ for (y = 0; y < src->h; y++) {
+ tmp = GP_GetPixel_Raw_{{ ps.suffix }}(src, x, y);
+ GP_PutPixel_Raw_{{ ps.suffix }}(dst, x, y, GP_GetPixel_Raw_{{ ps.suffix }}(src, xm, y));
+ GP_PutPixel_Raw_{{ ps.suffix }}(dst, xm, y, tmp);
+ }
+
+ if (callback != NULL && x % 100 == 0)
+ GP_ProgressCallbackReport(callback, 200.00 * x / src->w);
+ }
+
+ GP_ProgressCallbackDone(callback);
+}
+
+%% endfor
+
+void GP_FilterMirrorV_Raw(const GP_Context *src, GP_Context *dst,
+ GP_ProgressCallback *callback)
+{
+ GP_FN_PER_BPP_CONTEXT(GP_MirrorV_Raw, src, src, dst, callback);
+}
+%% endblock body
diff --git a/libs/filters/GP_Rotate.c b/libs/filters/GP_Rotate.c
index 513b969..ea7ae0a 100644
--- a/libs/filters/GP_Rotate.c
+++ b/libs/filters/GP_Rotate.c
@@ -16,10 +16,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, *
* Boston, MA 02110-1301 USA *
* *
- * Copyright (C) 2009-2010 Jiri "BlueBear" Dluhos *
- * <jiri.bluebear.dluhos(a)gmail.com> *
- * *
- * Copyright (C) 2009-2010 Cyril Hrubis <metan(a)ucw.cz> *
+ * Copyright (C) 2009-2011 Cyril Hrubis <metan(a)ucw.cz> *
* *
*****************************************************************************/
@@ -30,66 +27,88 @@
#include <string.h>
-#include "algo/GP_MirrorV.algo.h"
-
-GP_RetCode GP_MirrorH(GP_Context *context)
+void GP_FilterMirrorH_Raw(const GP_Context *src, GP_Context *dst,
+ GP_ProgressCallback *callback)
{
- uint32_t bpr = context->bytes_per_row;
+ uint32_t bpr = src->bytes_per_row;
uint8_t buf[bpr];
uint32_t y;
- if (context == NULL)
- return GP_ENULLPTR;
+ GP_DEBUG(1, "Mirroring image horizontally %ux%u", src->w, src->h);
- for (y = 0; y < context->h/2; y++) {
- uint8_t *l1 = context->pixels + bpr * y;
- uint8_t *l2 = context->pixels + bpr * (context->h - y - 1);
+ #warning FIXME: non byte aligned pixels
+
+ for (y = 0; y < src->h/2; y++) {
+ uint8_t *l1 = dst->pixels + bpr * y;
+ uint8_t *l2 = dst->pixels + bpr * (src->h - y - 1);
memcpy(buf, l1, bpr);
memcpy(l1, l2, bpr);
memcpy(l2, buf, bpr);
+
+ if (callback != NULL && y % 100 == 0)
+ GP_ProgressCallbackReport(callback, 200.00 * y / src->h);
}
- return GP_ESUCCESS;
+ GP_ProgressCallbackDone(callback);
}
-/* Generate mirror functions per BPP */
-GP_DEF_FFN_PER_BPP(GP_MirrorV, DEF_MIRRORV_FN)
-
-GP_RetCode GP_MirrorV(GP_Context *context)
+void GP_FilterRotate180_Raw(const GP_Context *src, GP_Context *dst,
+ GP_ProgressCallback *callback)
{
- if (context == NULL)
- return GP_ENULLPTR;
+ #warning FIXME: Callbacks, faster algorighm?
- GP_FN_PER_BPP_CONTEXT(GP_MirrorV, context, context);
-
- return GP_ESUCCESS;
+ GP_FilterMirrorV_Raw(src, dst, NULL);
+ GP_FilterMirrorH_Raw(dst, dst, callback);
}
-#include "algo/GP_Rotate.algo.h"
-
-/* Generate Rotate functions per BPP */
-GP_DEF_FFN_PER_BPP(GP_RotateCW, DEF_ROTATECW_FN)
-
-GP_RetCode GP_RotateCW(GP_Context *context)
+void GP_FilterRotate_Raw(const GP_Context *src, GP_Context *dst,
+ GP_FilterRotation rotation,
+ GP_ProgressCallback *callback)
{
- if (context == NULL)
- return GP_ENULLPTR;
-
- GP_FN_RET_PER_BPP_CONTEXT(GP_RotateCW, context, context);
-
- return GP_ENOIMPL;
+ switch (rotation) {
+ case GP_ROTATE_90:
+ GP_FilterRotate90_Raw(src, dst, callback);
+ break;
+ case GP_ROTATE_180:
+ GP_FilterRotate180_Raw(src, dst, callback);
+ break;
+ case GP_ROTATE_270:
+ GP_FilterRotate270_Raw(src, dst, callback);
+ break;
+ case GP_MIRROR_H:
+ GP_FilterMirrorH_Raw(src, dst, callback);
+ break;
+ case GP_MIRROR_V:
+ GP_FilterMirrorV_Raw(src, dst, callback);
+ break;
+ }
}
-/* Generate Rotate functions per BPP */
-GP_DEF_FFN_PER_BPP(GP_RotateCCW, DEF_ROTATECCW_FN)
-
-GP_RetCode GP_RotateCCW(GP_Context *context)
+GP_Context *GP_FilterRotate(const GP_Context *context,
+ GP_FilterRotation rotation,
+ GP_ProgressCallback *callback)
{
- if (context == NULL)
- return GP_ENULLPTR;
+ GP_Size w = context->w;
+ GP_Size h = context->h;
+
+ switch (rotation) {
+ case GP_ROTATE_90:
+ case GP_ROTATE_270:
+ GP_SWAP(w, h);
+ break;
+ default:
+ break;
+ }
+
+ GP_Context *ret = GP_ContextAlloc(w, h, context->pixel_type);
+
+ if (unlikely(ret == NULL)) {
+ GP_DEBUG(1, "Malloc failed :(");
+ return NULL;
+ }
- GP_FN_RET_PER_BPP_CONTEXT(GP_RotateCCW, context, context);
+ GP_FilterRotate_Raw(context, ret, rotation, callback);
- return GP_ENOIMPL;
+ return ret;
}
diff --git a/libs/filters/GP_Rotate.gen.c.t b/libs/filters/GP_Rotate.gen.c.t
new file mode 100644
index 0000000..9ef7bd9
--- /dev/null
+++ b/libs/filters/GP_Rotate.gen.c.t
@@ -0,0 +1,71 @@
+%% extends "base.c.t"
+
+%% block descr
+Vertical Mirror alogorithm
+%% endblock
+
+%% block body
+
+#include "core/GP_Debug.h"
+#include "core/GP_GetPutPixel.h"
+#include "GP_Rotate.h"
+
+%% for ps in pixelsizes
+void GP_FilterRotate90_Raw_{{ ps.suffix }}(const GP_Context *src, GP_Context *dst,
+ GP_ProgressCallback *callback)
+{
+ uint32_t x, y;
+
+ GP_DEBUG(1, "Rotating image by 90 %ux%u", src->w, src->h);
+
+ for (x = 0; x < src->w; x++) {
+ for (y = 0; y < src->h; y++) {
+ uint32_t yr = src->h - y - 1;
+ GP_PutPixel_Raw_{{ ps.suffix }}(dst, yr, x, GP_GetPixel_Raw_{{ ps.suffix }}(src, x, y));
+ }
+
+ if (callback != NULL && x % 100 == 0)
+ GP_ProgressCallbackReport(callback, 100.00 * x / src->w);
+ }
+
+ GP_ProgressCallbackDone(callback);
+}
+
+%% endfor
+
+void GP_FilterRotate90_Raw(const GP_Context *src, GP_Context *dst,
+ GP_ProgressCallback *callback)
+{
+ GP_FN_PER_BPP_CONTEXT(GP_FilterRotate90_Raw, src, src, dst, callback);
+}
+
+%% for ps in pixelsizes
+void GP_FilterRotate270_Raw_{{ ps.suffix }}(const GP_Context *src, GP_Context *dst,
+ GP_ProgressCallback *callback)
+{
+ uint32_t x, y;
+
+ GP_DEBUG(1, "Rotating image by 270 %ux%u", src->w, src->h);
+
+ for (x = 0; x < src->w; x++) {
+ for (y = 0; y < src->h; y++) {
+ uint32_t xr = src->w - x - 1;
+ GP_PutPixel_Raw_{{ ps.suffix }}(dst, y, xr, GP_GetPixel_Raw_{{ ps.suffix }}(src, x, y));
+ }
+
+ if (callback != NULL && x % 100 == 0)
+ GP_ProgressCallbackReport(callback, 100.00 * x / src->w);
+ }
+
+ GP_ProgressCallbackDone(callback);
+}
+
+%% endfor
+
+void GP_FilterRotate270_Raw(const GP_Context *src, GP_Context *dst,
+ GP_ProgressCallback *callback)
+{
+ GP_FN_PER_BPP_CONTEXT(GP_FilterRotate270_Raw, src, src, dst, callback);
+}
+
+%% endblock body
diff --git a/libs/filters/Makefile b/libs/filters/Makefile
index bd5ed37..8133fb0 100644
--- a/libs/filters/Makefile
+++ b/libs/filters/Makefile
@@ -1,5 +1,6 @@
TOPDIR=../..
-GENSOURCES=GP_Brightness.gen.c GP_Contrast.gen.c GP_Invert.gen.c
+GENSOURCES=GP_Brightness.gen.c GP_Contrast.gen.c GP_Invert.gen.c+ GP_MirrorV.gen.c GP_Rotate.gen.c
GENHEADERS=
CSOURCES=$(filter-out $(wildcard *.gen.c),$(wildcard *.c))
LIBNAME=filters
diff --git a/libs/filters/algo/GP_MirrorV.algo.h b/libs/filters/algo/GP_MirrorV.algo.h
deleted file mode 100644
index 6555700..0000000
--- a/libs/filters/algo/GP_MirrorV.algo.h
+++ /dev/null
@@ -1,42 +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 Jiri "BlueBear" Dluhos *
- * <jiri.bluebear.dluhos(a)gmail.com> *
- * *
- * Copyright (C) 2009-2011 Cyril Hrubis <metan(a)ucw.cz> *
- * *
- *****************************************************************************/
-
-
-#define DEF_MIRRORV_FN(FN_NAME, CONTEXT_T, PIXEL_T, PUTPIXEL, GETPIXEL) -void FN_NAME(CONTEXT_T context) -{ - uint32_t x, y; - PIXEL_T tmp; -- for (x = 0; x < context->w/2; x++) { - uint32_t xm = context->w - x - 1; - for (y = 0; y < context->h; y++) { - tmp = GETPIXEL(context, x, y); -- PUTPIXEL(context, x, y, GETPIXEL(context, xm, y)); - PUTPIXEL(context, xm, y, tmp); - } - } -}
diff --git a/libs/filters/algo/GP_Rotate.algo.h b/libs/filters/algo/GP_Rotate.algo.h
deleted file mode 100644
index bc7528d..0000000
--- a/libs/filters/algo/GP_Rotate.algo.h
+++ /dev/null
@@ -1,83 +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 Jiri "BlueBear" Dluhos *
- * <jiri.bluebear.dluhos(a)gmail.com> *
- * *
- * Copyright (C) 2009-2011 Cyril Hrubis <metan(a)ucw.cz> *
- * *
- *****************************************************************************/
-
-#include "core/GP_Common.h"
-#include "core/GP_Context.h"
-
-#define DEF_ROTATECW_FN(FN_NAME, CONTEXT_T, PIXEL_T, PUTPIXEL, GETPIXEL) -GP_RetCode FN_NAME(CONTEXT_T context) -{ - uint32_t x, y; - CONTEXT_T tmp; -- tmp = GP_ContextCopy(context, GP_COPY_WITH_PIXELS); -- if (tmp == NULL) - return GP_ENOMEM; -- GP_SWAP(context->w, context->h); -- context->bytes_per_row = GP_CALC_ROW_SIZE(context->pixel_type, - context->w); -- for (x = 0; x < tmp->w; x++) { - for (y = 0; y < tmp->h; y++) { - uint32_t yr = tmp->h - y - 1; - PUTPIXEL(context, yr, x, GETPIXEL(tmp, x, y)); - } - } -- GP_ContextFree(tmp); -- return GP_ESUCCESS; -}
-
-#define DEF_ROTATECCW_FN(FN_NAME, CONTEXT_T, PIXEL_T, PUTPIXEL, GETPIXEL) -GP_RetCode FN_NAME(CONTEXT_T context) -{ - uint32_t x, y; - CONTEXT_T tmp; -- tmp = GP_ContextCopy(context, GP_COPY_WITH_PIXELS); -- if (tmp == NULL) - return GP_ENOMEM; -- GP_SWAP(context->w, context->h); -- context->bytes_per_row = GP_CALC_ROW_SIZE(context->pixel_type, - context->w); -- for (x = 0; x < tmp->w; x++) { - for (y = 0; y < tmp->h; y++) { - uint32_t xr = tmp->w - x - 1; - PUTPIXEL(context, y, xr, GETPIXEL(tmp, x, y)); - } - } -- GP_ContextFree(tmp); -- return GP_ESUCCESS; -}
http://repo.or.cz/w/gfxprim.git/commit/a8f1ba07c9863cdda6b55a7b82fb35fbe557…
commit a8f1ba07c9863cdda6b55a7b82fb35fbe55758a9
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Thu Oct 27 21:06:31 2011 +0200
Add missing linker flag.
diff --git a/tests/drivers/Makefile b/tests/drivers/Makefile
index 664900d..28ea051 100644
--- a/tests/drivers/Makefile
+++ b/tests/drivers/Makefile
@@ -1,4 +1,4 @@
-LDFLAGS=-L../../build/ -lGP -lpng -ldl
+LDFLAGS=-L../../build/ -lGP -lpng -ldl -ljpeg
INCLUDE=-I../../include
# Some warnings are triggered only with -O2
# thuss added here
http://repo.or.cz/w/gfxprim.git/commit/bcaa19c8129a6bcaac8a3640979e91135c01…
commit bcaa19c8129a6bcaac8a3640979e91135c016846
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Thu Oct 27 16:40:09 2011 +0000
Add context offset.
This is first step for subcontexes for
non byte alignes pixel types.
diff --git a/include/core/GP_Context.h b/include/core/GP_Context.h
index 6bc244c..00138df 100644
--- a/include/core/GP_Context.h
+++ b/include/core/GP_Context.h
@@ -36,10 +36,16 @@
/* This structure holds all information needed for drawing into an image. */
typedef struct GP_Context {
uint8_t *pixels; /* pointer to image pixels */
- uint8_t bpp; /* values: 1, 2, 4, 8, 16, 24, 32 */
+ uint8_t bpp; /* pixel length in bits */
uint32_t bytes_per_row;
uint32_t w; /* width in pixels */
uint32_t h; /* height in pixels */
+ /*
+ * Row bit offset. The offset is ignored for byte aligned pixels.
+ * Basically it's used for non aligned pixels with combination
+ * with subcontextes.
+ */
+ uint8_t offset;
GP_PixelType pixel_type; /* hardware pixel format */
diff --git a/include/core/GP_GetPutPixel.h b/include/core/GP_GetPutPixel.h
index 599da1d..0cd7661 100644
--- a/include/core/GP_GetPutPixel.h
+++ b/include/core/GP_GetPutPixel.h
@@ -67,4 +67,9 @@ static inline void GP_PutPixel_Raw(GP_Context *context, int x, int y,
context, x, y, p);
}
+/*
+ * Returns pixel offset.
+ */
+uint8_t GP_PixelAddrOffset(GP_Coord x, GP_PixelType pixel_type);
+
#endif /* CORE_GP_GETPUTPIXEL_H */
diff --git a/libs/core/GP_Context.c b/libs/core/GP_Context.c
index 0ce6342..83c9f73 100644
--- a/libs/core/GP_Context.c
+++ b/libs/core/GP_Context.c
@@ -52,6 +52,7 @@ GP_Context *GP_ContextCopy(const GP_Context *src, int flag)
new->bpp = src->bpp;
new->bytes_per_row = src->bytes_per_row;
+ new->offset = 0;
new->w = src->w;
new->h = src->h;
@@ -66,7 +67,6 @@ GP_Context *GP_ContextCopy(const GP_Context *src, int flag)
new->free_pixels = 1;
return new;
-
}
GP_Context *GP_ContextAlloc(GP_Size w, GP_Size h, GP_PixelType type)
@@ -87,6 +87,7 @@ GP_Context *GP_ContextAlloc(GP_Size w, GP_Size h, GP_PixelType type)
context->pixels = pixels;
context->bpp = bpp;
context->bytes_per_row = bpr;
+ context->offset = 0;
context->w = w;
context->h = h;
@@ -140,6 +141,8 @@ GP_Context *GP_ContextSubContext(GP_Context *context, GP_Coord x, GP_Coord y,
ret->bpp = context->bpp;
ret->bytes_per_row = context->bytes_per_row;
+ ret->offset = (context->offset +
+ GP_PixelAddrOffset(x, context->pixel_type)) % 8;
ret->w = w;
ret->h = h;
@@ -169,7 +172,7 @@ GP_RetCode GP_ContextDump(GP_Context *context, const char *path)
for (y = 0; y < context->h; y++) {
for (x = 0; x < context->bytes_per_row; x++)
fprintf(f, "0x%02x ", ((uint8_t *)context->pixels)
- [y * context->bytes_per_row + x]);
+ [y * context->bytes_per_row + x]);
fprintf(f, "n");
}
diff --git a/libs/core/GP_GetPutPixel.c b/libs/core/GP_GetPutPixel.c
index 774be54..6550275 100644
--- a/libs/core/GP_GetPutPixel.c
+++ b/libs/core/GP_GetPutPixel.c
@@ -37,3 +37,10 @@ void GP_PutPixel(GP_Context *context, int x, int y, GP_Pixel p)
if (!GP_PIXEL_IS_CLIPPED(context, x, y))
GP_PutPixel_Raw(context, x, y, p);
}
+
+uint8_t GP_PixelAddrOffset(GP_Coord x, GP_PixelType pixel_type)
+{
+ GP_FN_RET_PER_BPP_PIXELTYPE(GP_PIXEL_ADDR_OFFSET, pixel_type, x);
+
+ return 0;
+}
diff --git a/libs/core/GP_Pixel.c b/libs/core/GP_Pixel.c
index 98dc0d0..bedaf14 100644
--- a/libs/core/GP_Pixel.c
+++ b/libs/core/GP_Pixel.c
@@ -28,8 +28,8 @@
#include "GP_Debug.h"
#include "GP_Pixel.h"
-static const GP_PixelTypeChannel *get_channel(const GP_PixelTypeDescription *desc,
- const char *name)
+static const GP_PixelTypeChannel *
+get_channel(const GP_PixelTypeDescription *desc, const char *name)
{
unsigned int i;
@@ -115,8 +115,9 @@ GP_PixelType GP_PixelRGBLookup(uint32_t rsize, uint32_t roff,
{
unsigned int i;
- GP_DEBUG(1, "Looking up Pixel R %08x %08x G %08x %08x B %08x %08x size %u",
- rsize, roff, gsize, goff, bsize, boff, bits_per_pixel);
+ GP_DEBUG(1, "Looking up Pixel R %08x %08x G %08x %08x B %08x %08x "
+ "size %u", rsize, roff, gsize, goff, bsize, boff,
+ bits_per_pixel);
for (i = 0; i < GP_PIXEL_MAX; i++) {
const GP_PixelTypeChannel *r, *g, *b, *a;
http://repo.or.cz/w/gfxprim.git/commit/828d02ecb1948597d7f7b83e86f15e7bb7ca…
commit 828d02ecb1948597d7f7b83e86f15e7bb7ca9164
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Thu Oct 27 16:02:32 2011 +0000
Remove (hopefuly) last function with T prefix.
diff --git a/include/core/GP_GetPutPixel.h b/include/core/GP_GetPutPixel.h
index 9d9b7be..599da1d 100644
--- a/include/core/GP_GetPutPixel.h
+++ b/include/core/GP_GetPutPixel.h
@@ -57,13 +57,6 @@ static inline GP_Pixel GP_GetPixel_Raw(const GP_Context *context, int x, int y)
*/
void GP_PutPixel(GP_Context *context, int x, int y, GP_Pixel p);
-//TODO: This is the same as GP_PutPixel
-static inline void GP_TPutPixel(GP_Context *context, GP_Coord x, GP_Coord y,
- GP_Pixel p)
-{
- GP_PutPixel(context, x, y, p);
-}
-
/*
* Version of PutPixel without transformations nor border checking.
*/
-----------------------------------------------------------------------
Summary of changes:
demos/grinder/grinder.c | 44 +++++++++++++--
demos/grinder/params.c | 39 +++++++++++++-
include/core/GP_Context.h | 8 ++-
include/core/GP_GetPutPixel.h | 12 ++--
include/filters/GP_Rotate.h | 83 ++++++++++++++++++++++-----
libs/core/GP_Context.c | 7 ++-
libs/core/GP_GetPutPixel.c | 7 ++
libs/core/GP_Pixel.c | 9 ++-
libs/filters/GP_MirrorV.gen.c.t | 44 +++++++++++++++
libs/filters/GP_Rotate.c | 105 ++++++++++++++++++++--------------
libs/filters/GP_Rotate.gen.c.t | 71 +++++++++++++++++++++++
libs/filters/Makefile | 3 +-
libs/filters/algo/GP_MirrorV.algo.h | 42 --------------
libs/filters/algo/GP_Rotate.algo.h | 83 ---------------------------
tests/drivers/Makefile | 2 +-
15 files changed, 352 insertions(+), 207 deletions(-)
create mode 100644 libs/filters/GP_MirrorV.gen.c.t
create mode 100644 libs/filters/GP_Rotate.gen.c.t
delete mode 100644 libs/filters/algo/GP_MirrorV.algo.h
delete mode 100644 libs/filters/algo/GP_Rotate.algo.h
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: 7d1c1b2c4aeef95941109cbdc5707eff6ad0a36f
by metan 25 Oct '11
by metan 25 Oct '11
25 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 7d1c1b2c4aeef95941109cbdc5707eff6ad0a36f (commit)
from c8554f3ed96486d4ef20838b260c369f61c61b3c (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/7d1c1b2c4aeef95941109cbdc5707eff6ad0…
commit 7d1c1b2c4aeef95941109cbdc5707eff6ad0a36f
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Tue Oct 25 16:08:45 2011 +0000
fbshow: fix timeval reinitalization.
diff --git a/demos/fbshow/fbshow.c b/demos/fbshow/fbshow.c
index e6c6212..76dcb99 100644
--- a/demos/fbshow/fbshow.c
+++ b/demos/fbshow/fbshow.c
@@ -143,13 +143,16 @@ int main(int argc, char *argv[])
FD_ZERO(&rfds);
FD_SET(drv->fd, &rfds);
struct timeval tv = {.tv_sec = sleep_sec, .tv_usec = 0};
+ struct timeval *tvp = sleep_sec ? &tv : NULL;
for (;;) {
int ret;
if (drv != NULL) {
- ret = select(drv->fd + 1, &rfds, NULL, NULL, &tv);
-
+ ret = select(drv->fd + 1, &rfds, NULL, NULL, tvp);
+
+ tv.tv_sec = sleep_sec;
+
switch (ret) {
case -1:
GP_FramebufferExit(fb);
-----------------------------------------------------------------------
Summary of changes:
demos/fbshow/fbshow.c | 7 +++++--
1 files changed, 5 insertions(+), 2 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: c8554f3ed96486d4ef20838b260c369f61c61b3c
by metan 25 Oct '11
by metan 25 Oct '11
25 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 c8554f3ed96486d4ef20838b260c369f61c61b3c (commit)
from 298530749895f3e6eb2805c4cb422e217e85586a (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/c8554f3ed96486d4ef20838b260c369f61c6…
commit c8554f3ed96486d4ef20838b260c369f61c61b3c
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Tue Oct 25 19:40:48 2011 +0200
Loaders: Added experimental JPEG support.
diff --git a/app.mk b/app.mk
index 4c90884..9b31c14 100644
--- a/app.mk
+++ b/app.mk
@@ -2,6 +2,8 @@ ifndef APPS
$(error APPS not defined, fix your library Makefile)
endif
+LDFLAGS+=-lpng -ljpeg
+
all: $(APPS)
CLEAN+=$(APPS)
diff --git a/include/loaders/GP_Loaders.h b/include/loaders/GP_JPG.h
similarity index 74%
copy from include/loaders/GP_Loaders.h
copy to include/loaders/GP_JPG.h
index a245e9a..bef6e10 100644
--- a/include/loaders/GP_Loaders.h
+++ b/include/loaders/GP_JPG.h
@@ -16,33 +16,36 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, *
* Boston, MA 02110-1301 USA *
* *
- * Copyright (C) 2009-2010 Jiri "BlueBear" Dluhos *
- * <jiri.bluebear.dluhos(a)gmail.com> *
- * *
* Copyright (C) 2009-2011 Cyril Hrubis <metan(a)ucw.cz> *
* *
*****************************************************************************/
/*
-
- Core include file for loaders API.
+
+ JPG support using jpeg library.
*/
-#ifndef GP_LOADERS_H
-#define GP_LOADERS_H
+#ifndef GP_JPG_H
+#define GP_JPG_H
#include "core/GP_Context.h"
-#include "GP_PBM.h"
-#include "GP_PGM.h"
-#include "GP_PPM.h"
+/*
+ * Opens up file and checks signature. Upon successful return the file
+ * possition would be set to eight bytes (exactly after the PNG signature).
+ */
+GP_RetCode GP_OpenJPG(const char *src_path, FILE **f);
-#include "GP_PNG.h"
+/*
+ * Reads PNG from an open FILE. Expects the file possition set after the eight
+ * bytes PNG signature.
+ */
+GP_RetCode GP_ReadJPG(FILE *f, GP_Context **res);
/*
- * Tries to load image accordingly to extension.
+ * Loads a PNG file into GP_Context. The Context is newly allocated.
*/
-GP_RetCode GP_LoadImage(const char *src_path, GP_Context **res);
+GP_RetCode GP_LoadJPG(const char *src_path, GP_Context **res);
-#endif /* GP_LOADERS_H */
+#endif /* GP_JPG_H */
diff --git a/include/loaders/GP_Loaders.h b/include/loaders/GP_Loaders.h
index a245e9a..e3ff703 100644
--- a/include/loaders/GP_Loaders.h
+++ b/include/loaders/GP_Loaders.h
@@ -40,6 +40,8 @@
#include "GP_PNG.h"
+#include "GP_JPG.h"
+
/*
* Tries to load image accordingly to extension.
*/
diff --git a/libs/loaders/GP_JPG.c b/libs/loaders/GP_JPG.c
new file mode 100644
index 0000000..69ddd55
--- /dev/null
+++ b/libs/loaders/GP_JPG.c
@@ -0,0 +1,182 @@
+/*****************************************************************************
+ * 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> *
+ * *
+ *****************************************************************************/
+
+/*
+
+ JPG image support using jpeg library.
+
+ */
+
+#include <stdint.h>
+#include <inttypes.h>
+
+#include <errno.h>
+#include <string.h>
+#include <stdio.h>
+#include <setjmp.h>
+
+#include <jpeglib.h>
+
+#include <GP_Context.h>
+#include <GP_Debug.h>
+
+GP_RetCode GP_OpenJPG(const char *src_path, FILE **f)
+{
+ *f = fopen(src_path, "rb");
+
+ if (*f == NULL) {
+ GP_DEBUG(1, "Failed to open '%s' : %s",
+ src_path, strerror(errno));
+ return GP_EBADFILE;
+ }
+
+ //TODO: check signature and rewind the stream
+
+ return GP_ESUCCESS;
+}
+
+struct my_jpg_err {
+ struct jpeg_error_mgr error_mgr;
+
+ jmp_buf setjmp_buf;
+};
+
+static void my_error_exit(j_common_ptr cinfo)
+{
+ struct my_jpg_err *my_err = (struct my_jpg_err*) cinfo->err;
+
+ GP_DEBUG(1, "ERROR reading jpeg file");
+
+ longjmp(my_err->setjmp_buf, 1);
+}
+
+static const char *get_colorspace(J_COLOR_SPACE color_space)
+{
+ switch (color_space) {
+ case JCS_GRAYSCALE:
+ return "Grayscale";
+ case JCS_RGB:
+ return "RGB";
+ case JCS_YCbCr:
+ return "YCbCr";
+ case JCS_CMYK:
+ return "CMYK";
+ case JCS_YCCK:
+ return "YCCK";
+ default:
+ return "Unknown";
+ };
+}
+
+GP_RetCode GP_ReadJPG(FILE *f, GP_Context **res)
+{
+ struct jpeg_decompress_struct cinfo;
+ struct my_jpg_err my_err;
+ GP_Context *ret = NULL;
+
+ cinfo.err = jpeg_std_error(&my_err.error_mgr);
+ my_err.error_mgr.error_exit = my_error_exit;
+
+ if (setjmp(my_err.setjmp_buf)) {
+ jpeg_destroy_decompress(&cinfo);
+ GP_ContextFree(ret);
+ fclose(f);
+ return GP_EBADFILE;
+ }
+
+ jpeg_create_decompress(&cinfo);
+ jpeg_stdio_src(&cinfo, f);
+
+ jpeg_read_header(&cinfo, TRUE);
+
+ GP_DEBUG(1, "Have %s JPEG size %ux%u %i channels",
+ get_colorspace(cinfo.jpeg_color_space),
+ cinfo.image_width, cinfo.image_height,
+ cinfo.num_components);
+
+ GP_Pixel pixel_type;
+
+ switch (cinfo.out_color_space) {
+ case JCS_GRAYSCALE:
+ pixel_type = GP_PIXEL_G8;
+ break;
+ case JCS_RGB:
+ pixel_type = GP_PIXEL_RGB888;
+ break;
+ default:
+ pixel_type = GP_PIXEL_UNKNOWN;
+ }
+
+ if (pixel_type == GP_PIXEL_UNKNOWN) {
+ GP_DEBUG(1, "Can't handle %s JPEG output format",
+ get_colorspace(cinfo.out_color_space));
+ jpeg_destroy_decompress(&cinfo);
+ fclose(f);
+ return GP_EBADFILE;
+ }
+
+ ret = GP_ContextAlloc(cinfo.image_width, cinfo.image_height,
+ pixel_type);
+
+ if (ret == NULL) {
+ GP_DEBUG(1, "Malloc failed :(");
+ jpeg_destroy_decompress(&cinfo);
+ fclose(f);
+ return GP_ENOMEM;
+ }
+
+ jpeg_start_decompress(&cinfo);
+
+ while (cinfo.output_scanline < cinfo.output_height) {
+ uint32_t y = cinfo.output_scanline;
+
+ JSAMPROW addr = (void*)GP_PIXEL_ADDR(ret, 0, y);
+ jpeg_read_scanlines(&cinfo, &addr, 1);
+
+ //TODO: fixme bigendian?
+ /* fix the pixel, as we want in fact BGR */
+ uint32_t i;
+
+ for (i = 0; i < ret->w; i++) {
+ uint8_t *pix = GP_PIXEL_ADDR(ret, i, y);
+ GP_SWAP(pix[0], pix[2]);
+ }
+ }
+
+ jpeg_finish_decompress(&cinfo);
+ jpeg_destroy_decompress(&cinfo);
+ fclose(f);
+ *res = ret;
+
+ return GP_ESUCCESS;
+}
+
+GP_RetCode GP_LoadJPG(const char *src_path, GP_Context **res)
+{
+ FILE *f;
+ GP_RetCode ret;
+
+ if ((ret = GP_OpenJPG(src_path, &f)))
+ return ret;
+
+ return GP_ReadJPG(f, res);
+}
diff --git a/libs/loaders/GP_Loaders.c b/libs/loaders/GP_Loaders.c
index 63f1da5..8f69d03 100644
--- a/libs/loaders/GP_Loaders.c
+++ b/libs/loaders/GP_Loaders.c
@@ -56,6 +56,20 @@ GP_RetCode GP_LoadImage(const char *src_path, GP_Context **res)
src_path[len - 3] == 'P')
ret = GP_LoadPNG(src_path, res);
break;
+ case 'p':
+ case 'P':
+ if (src_path[len - 3] == 'j' ||
+ src_path[len - 3] == 'J')
+ ret = GP_LoadJPG(src_path, res);
+ break;
+ case 'e':
+ case 'E':
+ if ((src_path[len - 3] == 'p' ||
+ src_path[len - 3] == 'P') &&
+ (src_path[len - 4] == 'j' ||
+ src_path[len - 4] == 'J'))
+ ret = GP_LoadJPG(src_path, res);
+ break;
}
break;
/* PPM, PGM, PBM, PNM */
-----------------------------------------------------------------------
Summary of changes:
app.mk | 2 +
include/loaders/{GP_PNG.h => GP_JPG.h} | 14 ++--
include/loaders/GP_Loaders.h | 2 +
libs/loaders/GP_JPG.c | 182 ++++++++++++++++++++++++++++++++
libs/loaders/GP_Loaders.c | 14 +++
5 files changed, 207 insertions(+), 7 deletions(-)
copy include/loaders/{GP_PNG.h => GP_JPG.h} (88%)
create mode 100644 libs/loaders/GP_JPG.c
repo.or.cz automatic notification. Contact project admin jiri.bluebear.dluhos(a)gmail.com
if you want to unsubscribe, or site admin admin(a)repo.or.cz if you receive
no reply.
--
gfxprim.git ("A simple 2D graphics library with emphasis on correctness and well-defined operation.")
1
0
[repo.or.cz] gfxprim.git branch generate updated: 298530749895f3e6eb2805c4cb422e217e85586a
by metan 25 Oct '11
by metan 25 Oct '11
25 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 298530749895f3e6eb2805c4cb422e217e85586a (commit)
via 4bf88545a7e86d3a925a83e19ba7c92920a14cb5 (commit)
via 48642159e541d480d808e876239566e8b1077de5 (commit)
from 859d22427003b1d4be3f536075d48a847bcd2c8a (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/298530749895f3e6eb2805c4cb422e217e85…
commit 298530749895f3e6eb2805c4cb422e217e85586a
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Tue Oct 25 12:51:00 2011 +0000
Fix merge.
diff --git a/demos/fbshow/fbshow.c b/demos/fbshow/fbshow.c
index 12d4626..e6c6212 100644
--- a/demos/fbshow/fbshow.c
+++ b/demos/fbshow/fbshow.c
@@ -48,7 +48,7 @@ static GP_Context *image_to_display(GP_Context *img, uint32_t w, uint32_t h)
{
float rat = calc_img_size(img->w, img->h, w, h);
- return GP_FilterResize(img, NULL, GP_INTER_CUBIC, img->w * rat, img->h * rat);
+ return GP_FilterResize(img, NULL, GP_INTERP_CUBIC, img->w * rat, img->h * rat);
}
static int show_image(GP_Framebuffer *fb, const char *img_path, int clear)
http://repo.or.cz/w/gfxprim.git/commit/4bf88545a7e86d3a925a83e19ba7c92920a1…
commit 4bf88545a7e86d3a925a83e19ba7c92920a14cb5
Merge: 4864215 859d224
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Tue Oct 25 12:31:24 2011 +0000
Merge branch 'generate' of git://repo.or.cz/gfxprim into generate
http://repo.or.cz/w/gfxprim.git/commit/48642159e541d480d808e876239566e8b107…
commit 48642159e541d480d808e876239566e8b1077de5
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Mon Oct 24 17:56:37 2011 +0200
Base for framebuffer image viewer.
diff --git a/demos/Makefile b/demos/Makefile
index 571580a..eddfa9f 100644
--- a/demos/Makefile
+++ b/demos/Makefile
@@ -1,3 +1,3 @@
TOPDIR=..
-SUBDIRS=grinder
+SUBDIRS=grinder fbshow
include $(TOPDIR)/include.mk
diff --git a/demos/fbshow/Makefile b/demos/fbshow/Makefile
new file mode 100644
index 0000000..2ca7439
--- /dev/null
+++ b/demos/fbshow/Makefile
@@ -0,0 +1,11 @@
+TOPDIR=../..
+
+CSOURCES=$(shell echo *.c)
+
+INCLUDE=
+LDLIBS+=-lGP -L$(TOPDIR)/build/ -lpng
+
+APPS=fbshow
+
+include $(TOPDIR)/include.mk
+include $(TOPDIR)/app.mk
diff --git a/demos/fbshow/fbshow.c b/demos/fbshow/fbshow.c
new file mode 100644
index 0000000..12d4626
--- /dev/null
+++ b/demos/fbshow/fbshow.c
@@ -0,0 +1,214 @@
+/*****************************************************************************
+ * 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> *
+ * *
+ *****************************************************************************/
+
+ /*
+
+ Simple framebuffer image viewer.
+
+ */
+
+#include <unistd.h>
+
+#include <GP.h>
+#include <backends/GP_Framebuffer.h>
+#include <input/GP_InputDriverLinux.h>
+
+static GP_Pixel black_pixel;
+static GP_Pixel white_pixel;
+
+static float calc_img_size(uint32_t img_w, uint32_t img_h,
+ uint32_t src_w, uint32_t src_h)
+{
+ float w_rat = 1.00 * src_w / img_w;
+ float h_rat = 1.00 * src_h / img_h;
+
+ return GP_MIN(w_rat, h_rat);
+}
+
+static GP_Context *image_to_display(GP_Context *img, uint32_t w, uint32_t h)
+{
+ float rat = calc_img_size(img->w, img->h, w, h);
+
+ return GP_FilterResize(img, NULL, GP_INTER_CUBIC, img->w * rat, img->h * rat);
+}
+
+static int show_image(GP_Framebuffer *fb, const char *img_path, int clear)
+{
+ GP_Context *img;
+
+ if (clear) {
+ char buf[100];
+ snprintf(buf, sizeof(buf), "Loading '%s'", img_path);
+ GP_Fill(&fb->context, black_pixel);
+ GP_BoxCenteredText(&fb->context, NULL, 0, 0,
+ fb->context.w, fb->context.h,
+ buf, white_pixel);
+ }
+
+ if (GP_LoadImage(img_path, &img) == 0) {
+ GP_Context *img2 = image_to_display(img, fb->context.w, fb->context.h);
+
+ GP_ContextFree(img);
+
+ if (img2 == NULL)
+ return 1;
+
+ uint32_t cx = (fb->context.w - img2->w)/2;
+ uint32_t cy = (fb->context.h - img2->h)/2;
+
+ GP_Fill(&fb->context, black_pixel);
+
+ GP_Blit(img2, 0, 0, img2->w, img2->h, &fb->context, cx, cy);
+
+ GP_ContextFree(img2);
+ }
+
+ return 0;
+}
+
+int main(int argc, char *argv[])
+{
+ GP_Framebuffer *fb;
+ GP_InputDriverLinux *drv = NULL;
+ char *input_dev = NULL;
+ int sleep_sec = 0;
+
+ int opt;
+
+ while ((opt = getopt(argc, argv, "i:s:")) != -1) {
+ switch (opt) {
+ case 'i':
+ input_dev = optarg;
+ break;
+ case 's':
+ sleep_sec = atoi(optarg);
+ break;
+ default:
+ fprintf(stderr, "Invalid paramter '%c'n", opt);
+ }
+ }
+
+ GP_SetDebugLevel(10);
+
+ if (input_dev == NULL) {
+ sleep_sec = 1;
+ } else {
+ drv = GP_InputDriverLinuxOpen(input_dev);
+
+ if (drv == NULL) {
+ fprintf(stderr, "Failed to initalize input device '%s'n",
+ input_dev);
+ return 1;
+ }
+ }
+
+ fb = GP_FramebufferInit("/dev/fb0");
+
+ if (fb == NULL) {
+ fprintf(stderr, "Failed to initalize framebuffern");
+ return 1;
+ }
+
+ GP_EventSetScreenSize(fb->context.w, fb->context.h);
+
+ black_pixel = GP_ColorToContextPixel(GP_COL_BLACK, &fb->context);
+ white_pixel = GP_ColorToContextPixel(GP_COL_WHITE, &fb->context);
+
+ int argf = optind;
+ int argn = argf;
+
+ show_image(fb, argv[argf], 1);
+
+ /* Initalize select */
+ fd_set rfds;
+ FD_ZERO(&rfds);
+ FD_SET(drv->fd, &rfds);
+ struct timeval tv = {.tv_sec = sleep_sec, .tv_usec = 0};
+
+ for (;;) {
+ int ret;
+
+ if (drv != NULL) {
+ ret = select(drv->fd + 1, &rfds, NULL, NULL, &tv);
+
+ switch (ret) {
+ case -1:
+ GP_FramebufferExit(fb);
+ return 0;
+ break;
+ case 0:
+ argn++;
+ if (argn >= argc)
+ argn = argf;
+
+ show_image(fb, argv[argn], 0);
+ break;
+ default:
+ while (GP_InputDriverLinuxRead(drv));
+ }
+
+ FD_SET(drv->fd, &rfds);
+ } else {
+ sleep(sleep_sec);
+
+ argn++;
+ if (argn >= argc)
+ argn = argf;
+
+ show_image(fb, argv[argn], 0);
+ }
+
+ /* Read and parse events */
+ GP_Event ev;
+
+ while (GP_EventGet(&ev)) {
+
+ GP_EventDump(&ev);
+
+ switch (ev.type) {
+ case GP_EV_KEY:
+ if (ev.code != GP_EV_KEY_DOWN)
+ continue;
+
+ switch (ev.val.key.key) {
+ case GP_KEY_ENTER:
+ GP_FramebufferExit(fb);
+ return 0;
+ break;
+ case GP_KEY_ESC:
+ case GP_KEY_SPACE:
+ case GP_KEY_Q:
+ argn++;
+ if (argn >= argc)
+ argn = argf;
+ show_image(fb, argv[argn], 1);
+ break;
+ }
+ break;
+ }
+ }
+ }
+
+ GP_FramebufferExit(fb);
+
+ return 0;
+}
diff --git a/demos/fbshow/runtest.sh b/demos/fbshow/runtest.sh
new file mode 100755
index 0000000..163c76c
--- /dev/null
+++ b/demos/fbshow/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:
demos/Makefile | 2 +-
demos/{grinder => fbshow}/Makefile | 6 +-
demos/fbshow/fbshow.c | 214 ++++++++++++++++++++++++++++++++
{tests/SDL => demos/fbshow}/runtest.sh | 2 +-
4 files changed, 218 insertions(+), 6 deletions(-)
copy demos/{grinder => fbshow}/Makefile (68%)
create mode 100644 demos/fbshow/fbshow.c
copy {tests/SDL => demos/fbshow}/runtest.sh (72%)
repo.or.cz automatic notification. Contact project admin jiri.bluebear.dluhos(a)gmail.com
if you want to unsubscribe, or site admin admin(a)repo.or.cz if you receive
no reply.
--
gfxprim.git ("A simple 2D graphics library with emphasis on correctness and well-defined operation.")
1
0