This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project gfxprim.git.
The branch, master has been updated via 9c29fb0086bf7531c018827337848b9ba5681242 (commit) via 03d643e6b7770cdf34ba62046985b595cc7827cf (commit) from f841e08588f0113c8a6800a55ab3735ea7691188 (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/9c29fb0086bf7531c018827337848b9ba5681...
commit 9c29fb0086bf7531c018827337848b9ba5681242 Author: Cyril Hrubis metan@ucw.cz Date: Sun Nov 13 20:53:25 2011 +0100
filters: Experimental Floyd Steinberg.
diff --git a/demos/grinder/grinder.c b/demos/grinder/grinder.c index fd6ccce..2f8596a 100644 --- a/demos/grinder/grinder.c +++ b/demos/grinder/grinder.c @@ -359,6 +359,28 @@ static GP_RetCode blur(GP_Context **c, const char *params) return GP_ESUCCESS; }
+/* dithering */ + +static struct param dither_params[] = { + {NULL, 0, NULL, NULL, NULL} +}; + +static GP_RetCode dither(GP_Context **c, const char *params) +{ + if (param_parse(params, dither_params, "dither", param_err)) + return GP_EINVAL; + + GP_Context *bw = GP_FilterFloydSteinberg(*c, NULL, progress_callback); + + //TODO: so far we convert the context back to RGB888 + //(so we can do further work with it) + GP_ContextConvert(bw, *c, (*c)->pixel_type); + + GP_ContextFree(bw); + + return GP_ESUCCESS; +} + /* filters */
struct filter { @@ -377,6 +399,7 @@ static struct filter filter_table[] = { {"contrast", "alter image contrast", contrast_params, contrast}, {"invert", "inverts image", invert_params, invert}, {"blur", "gaussian blur", blur_params, blur}, + {"dither", "dithers bitmap", dither_params, dither}, {NULL, NULL, NULL, NULL} };
diff --git a/include/filters/GP_Filters.h b/include/filters/GP_Dither.h similarity index 72% copy from include/filters/GP_Filters.h copy to include/filters/GP_Dither.h index 8e2d84d..37fac43 100644 --- a/include/filters/GP_Filters.h +++ b/include/filters/GP_Dither.h @@ -16,32 +16,25 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, * * Boston, MA 02110-1301 USA * * * - * Copyright (C) 2009-2010 Jiri "BlueBear" Dluhos * - * jiri.bluebear.dluhos@gmail.com * - * * * Copyright (C) 2009-2011 Cyril Hrubis metan@ucw.cz * * * *****************************************************************************/
/*
- GP_Context filters. + Dithering algorithms.
*/
-#ifndef GP_FILTERS_H -#define GP_FILTERS_H - -/* Image rotations (90 180 270 grads) and mirroring */ -#include "filters/GP_Rotate.h" - -/* Point filters, brightness, contrast ... */ -#include "filters/GP_Point.h" +#ifndef FILTERS_GP_DITHER_H +#define FILTERS_GP_DITHER_H
-/* Linear convolution based filters (mostly blurs) */ -#include "filters/GP_Linear.h" +#include "GP_Filter.h"
-/* Image scaling (resampling) */ -#include "filters/GP_Resize.h" +/* + * Experimental Floyd Steinberg that coverts any pixel type to G1 + */ +GP_Context *GP_FilterFloydSteinberg(const GP_Context *src, GP_Context *dst, + GP_ProgressCallback *callback);
-#endif /* GP_FILTERS_H */ +#endif /* FILTERS_GP_DITHER_H */ diff --git a/include/filters/GP_Filters.h b/include/filters/GP_Filters.h index 8e2d84d..4a38cb6 100644 --- a/include/filters/GP_Filters.h +++ b/include/filters/GP_Filters.h @@ -44,4 +44,7 @@ /* Image scaling (resampling) */ #include "filters/GP_Resize.h"
+/* Bitmap dithering */ +#include "filters/GP_Dither.h" + #endif /* GP_FILTERS_H */ diff --git a/libs/filters/GP_Dither.c b/libs/filters/GP_Dither.c new file mode 100644 index 0000000..ffe7354 --- /dev/null +++ b/libs/filters/GP_Dither.c @@ -0,0 +1,116 @@ +/***************************************************************************** + * This file is part of gfxprim library. * + * * + * Gfxprim is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Lesser General Public * + * License as published by the Free Software Foundation; either * + * version 2.1 of the License, or (at your option) any later version. * + * * + * Gfxprim is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with gfxprim; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, * + * Boston, MA 02110-1301 USA * + * * + * Copyright (C) 2009-2011 Cyril Hrubis metan@ucw.cz * + * * + *****************************************************************************/ + +#include "core/GP_Core.h" +#include "core/GP_FnPerBpp.h" + +#include "GP_Dither.h" + +#include <string.h> + +static void print_err(float *d, int size) +{ + int i; + + printf("["); + + for (i = 0; i < size; i++) + printf("%2.2f, ", d[i]); + + printf("]n"); +} + +/* + * Experimental Floyd Steinberg XXX -> G1 + */ +int GP_FilterFloydSteinberg_Raw(const GP_Context *src, GP_Context *dst, + GP_ProgressCallback *callback) +{ + float errors[2][src->w]; + + GP_DEBUG(1, "Floyd Steiberg %ux%u", src->w, src->h); + + GP_Coord x, y; + + memset(errors[0], 0, src->w * sizeof(float)); + memset(errors[1], 0, src->w * sizeof(float)); + + for (y = 0; y < src->h; y++) { + for (x = 0; x < src->w; x++) { + GP_Pixel pix = GP_GetPixel(src, x, y); + float val = GP_ConvertPixel(pix, src->pixel_type, GP_PIXEL_G8); + + val += errors[y%2][x]; + + float err; + + if (val > 127) { + err = val - 255; + GP_PutPixel_Raw_1BPP_LE(dst, x, y, 1); + } else { + err = val - 0; + GP_PutPixel_Raw_1BPP_LE(dst, x, y, 0); + } + + if (x + 1 < src->w) + errors[y%2][x+1] += 7 * err / 16; + + if (x > 1) + errors[!(y%2)][x-1] += 3 * err / 16; + + errors[!(y%2)][x] += 5 * err / 16; + + if (x + 1 < src->w) + errors[!(y%2)][x+1] += err / 16; + } + + memset(errors[y%2], 0, src->w * sizeof(float)); + // if (GP_ProgressCallbackReport(callback, 2 * y, src->h, src->w)) + // return 1; + } + +// GP_ProgressCallbackDone(callback); + return 0; +} + +GP_Context *GP_FilterFloydSteinberg(const GP_Context *src, GP_Context *dst, + GP_ProgressCallback *callback) +{ + GP_Context *ret = dst; + + if (ret == NULL) { + ret = GP_ContextAlloc(src->w, src->h, GP_PIXEL_G1); + + if (ret == NULL) { + GP_DEBUG(1, "Malloc failed :("); + return NULL; + } + } + + if (GP_FilterFloydSteinberg_Raw(src, ret, callback)) { + if (dst == NULL) + free(ret); + return NULL; + } + + return ret; +}
http://repo.or.cz/w/gfxprim.git/commit/03d643e6b7770cdf34ba62046985b595cc782...
commit 03d643e6b7770cdf34ba62046985b595cc7827cf Author: Cyril Hrubis metan@ucw.cz Date: Sun Nov 13 20:11:11 2011 +0100
core: Added asserts for context conversions.
diff --git a/libs/core/GP_Context.c b/libs/core/GP_Context.c index f1efa61..23ae77b 100644 --- a/libs/core/GP_Context.c +++ b/libs/core/GP_Context.c @@ -117,6 +117,11 @@ GP_Context *GP_ContextConvert(const GP_Context *src, GP_Context *dst,
if (ret == NULL) return NULL; + } else { + GP_ASSERT(dst->pixel_type == dst_pixel_type, + "Destination pixel type doesn't match"); + GP_ASSERT(src->w <= dst->w && src->h <= dst->h, + "Destination is not big enough"); }
GP_Blit_Naive(src, 0, 0, src->w, src->h, ret, 0, 0);
-----------------------------------------------------------------------
Summary of changes: demos/grinder/grinder.c | 23 ++++ .../GP_InputDriverSDL.h => filters/GP_Dither.h} | 15 ++- include/filters/GP_Filters.h | 3 + libs/core/GP_Context.c | 5 + libs/filters/GP_Dither.c | 116 ++++++++++++++++++++ 5 files changed, 155 insertions(+), 7 deletions(-) copy include/{input/GP_InputDriverSDL.h => filters/GP_Dither.h} (82%) create mode 100644 libs/filters/GP_Dither.c
repo.or.cz automatic notification. Contact project admin jiri.bluebear.dluhos@gmail.com if you want to unsubscribe, or site admin admin@repo.or.cz if you receive no reply.