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 0543a967e4953d105ccbb8ca1bd7fd2915a4a298 (commit) via a078ba651d736964efa6f71b9d0e4728bee803d6 (commit) from 4df6d59aba3f76c23c9f9155721db580f3b6cff1 (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/0543a967e4953d105ccbb8ca1bd7fd2915a4a...
commit 0543a967e4953d105ccbb8ca1bd7fd2915a4a298 Author: Cyril Hrubis metan@ucw.cz Date: Wed Sep 21 23:19:16 2011 +0200
Added simple brightness filter.
diff --git a/include/filters/GP_Linear.h b/include/filters/GP_Linear.h new file mode 100644 index 0000000..5465882 --- /dev/null +++ b/include/filters/GP_Linear.h @@ -0,0 +1,35 @@ +/***************************************************************************** + * 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 * + * * + *****************************************************************************/ + +/* + + + */ + +#ifndef GP_LINEAR_H +#define GP_LINEAR_H + +#include <GP_Context.h> + +GP_Context *GP_FilterBrightness(const GP_Context *src, int32_t inc); + +#endif /* GP_LINEAR_H */ diff --git a/libs/filters/GP_Brightness.gen.c.t b/libs/filters/GP_Brightness.gen.c.t new file mode 100644 index 0000000..b73fb9a --- /dev/null +++ b/libs/filters/GP_Brightness.gen.c.t @@ -0,0 +1,91 @@ +%% extends "base.c.t" + +%% block descr +Brightness filters -- Increments all color channels by a fixed value. +%% endblock + +%% block body +#include <GP_Context.h> +#include <GP_Pixel.h> +#include <GP_GetPutPixel.h> + +/* + * Simple brightness operations for one channel bitmaps + */ +%% for ps in pixelsizes +%% if ps.size <= 8 and ps.size > 1 +void GP_FilterBrightness_{{ ps.suffix }}(const GP_Context *src, GP_Context *res, int32_t inc) +{ + uint32_t x, y; + + for (y = 0; y < src->h; y++) + for (x = 0; x < src->w; x++) { + int32_t pix = GP_GetPixel_Raw_{{ ps.suffix }}(src, x, y) + inc; + + if (pix < 0) + pix = 0; + + if (pix > {{ 2 ** ps.size - 1 }}) + pix = {{ 2 ** ps.size - 1}}; + + GP_PutPixel_Raw_{{ ps.suffix }}(res, x, y, pix); + } +} + +%% endif +%% endfor + +/* + * Brightness filters for pixel types with more than one channels + */ +%% for pt in pixeltypes +%% if not pt.is_unknown() and len(pt.chanslist) > 1 +void GP_FilterBrightness_{{ pt.name }}(const GP_Context *src, GP_Context *res, int32_t inc) +{ + uint32_t x, y; + + for (y = 0; y < src->h; y++) + for (x = 0; x < src->w; x++) { + GP_Pixel pix = GP_GetPixel_Raw_{{ pt.pixelsize.suffix }}(src, x, y); + %% for c in pt.chanslist + int32_t {{ c[0] }} = GP_Pixel_GET_{{ c[0] }}_{{ pt.name }}(pix) + inc; + %% endfor + + %% for c in pt.chanslist + if ({{ c[0] }} < 0) + {{ c[0] }} = 0; + + if ({{ c[0] }} > {{ 2 ** c[2] - 1 }}) + {{ c[0] }} = 255; + + %% endfor + pix = GP_Pixel_CREATE_{{ pt.name }}({{ pt.chanslist[0][0] }}{% for c in pt.chanslist[1:] %}, {{ c[0] }}{% endfor %}); + + GP_PutPixel_Raw_{{ pt.pixelsize.suffix }}(res, x, y, pix); + } +} + +%% endif +%% endfor + +void GP_FilterBrightness_Raw(const GP_Context *src, GP_Context *res, int32_t inc) +{ + switch (src->pixel_type) { + %% for pt in pixeltypes + case GP_PIXEL_{{ pt.name }}: + %% if pt.is_unknown() or pt.pixelsize.size < 2 + return; + %% elif len(pt.chanslist) == 1: + GP_FilterBrightness_{{ pt.pixelsize.suffix }}(src, res, inc); + %% else + GP_FilterBrightness_{{ pt.name }}(src, res, inc); + %% endif + break; + %% endfor + default: + break; + } +} + + +%% endblock body diff --git a/libs/filters/GP_Linear.c b/libs/filters/GP_Linear.c new file mode 100644 index 0000000..50ec525 --- /dev/null +++ b/libs/filters/GP_Linear.c @@ -0,0 +1,42 @@ +/***************************************************************************** + * This file is part of gfxprim library. * + * * + * Gfxprim is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Lesser General Public * + * License as published by the Free Software Foundation; either * + * version 2.1 of the License, or (at your option) any later version. * + * * + * Gfxprim is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with gfxprim; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, * + * Boston, MA 02110-1301 USA * + * * + * Copyright (C) 2009-2011 Cyril Hrubis metan@ucw.cz * + * * + *****************************************************************************/ + +#include <GP_Context.h> +#include <GP_GetPutPixel.h> + +#include <GP_Debug.h> + +#include "GP_Linear.h" + +void GP_FilterBrightness_Raw(const GP_Context *src, GP_Context *res, int32_t inc); + +GP_Context *GP_FilterBrightness(const GP_Context *src, int32_t inc) +{ + GP_Context *res = GP_ContextCopy(src, 0); + + if (res == NULL) + return NULL; + + GP_FilterBrightness_Raw(src, res, inc); + + return res; +} diff --git a/libs/filters/Makefile b/libs/filters/Makefile index 9e5120a..6f48556 100644 --- a/libs/filters/Makefile +++ b/libs/filters/Makefile @@ -1,6 +1,10 @@ TOPDIR=../.. -CSOURCES=$(shell ls *.c) +GENSOURCES=GP_Brightness.gen.c +GENHEADERS= +CSOURCES=$(filter-out $(wildcard *.gen.c),$(wildcard *.c)) LIBNAME=filters INCLUDE=core + +include $(TOPDIR)/gen.mk include $(TOPDIR)/include.mk include $(TOPDIR)/lib.mk diff --git a/tests/SDL/showimage.c b/tests/SDL/showimage.c index 1e0b356..9ef23f1 100644 --- a/tests/SDL/showimage.c +++ b/tests/SDL/showimage.c @@ -30,9 +30,12 @@ SDL_Surface *display = NULL; GP_Context context, *bitmap;
+int brightness = 0; + void event_loop(void) { SDL_Event event; + GP_Context *res;
while (SDL_WaitEvent(&event) > 0) {
@@ -42,6 +45,19 @@ void event_loop(void) switch (event.key.keysym.sym) { case SDLK_ESCAPE: return; + case SDLK_UP: + brightness+=2; + case SDLK_DOWN: + brightness-=1; + + res = GP_FilterBrightness(bitmap, brightness); + + printf("brightness = %i %ux%un", brightness, res->w, res->h); + + GP_Blit_Naive(res, 0, 0, res->w, res->h, &context, 0, 0); + SDL_Flip(display); + GP_ContextFree(res); + break; default: break; } diff --git a/tests/SDL/subcontext.c b/tests/SDL/subcontext.c index cbe110e..b8f68c4 100644 --- a/tests/SDL/subcontext.c +++ b/tests/SDL/subcontext.c @@ -139,7 +139,11 @@ void redraw_screen(void) SDL_LockSurface(display);
uint8_t v = random() % 128 + 50; - GP_Color col = GP_RGBToContextPixel(v, v, 255, sub_context); + GP_Color col; + if (sub_context->pixel_type == GP_PIXEL_P8) + col = random() % 256; + else + col = GP_RGBToContextPixel(v, v, 255, sub_context); /* frame around subcontext */ GP_Rect(&context, 99, 99, context.w - 100, context.h - 100, white); @@ -224,7 +228,9 @@ int main(int argc, char *argv[])
int i; for (i = 1; i < argc; i++) { - if (strcmp(argv[i], "-16") == 0) { + if (strcmp(argv[i], "-8") == 0) { + display_bpp = 8; + } else if (strcmp(argv[i], "-16") == 0) { display_bpp = 16; } else if (strcmp(argv[i], "-24") == 0) {
http://repo.or.cz/w/gfxprim.git/commit/a078ba651d736964efa6f71b9d0e4728bee80...
commit a078ba651d736964efa6f71b9d0e4728bee803d6 Author: Cyril Hrubis metan@ucw.cz Date: Wed Sep 21 17:25:54 2011 +0200
Small GP_ContextCopy() fixup.
diff --git a/include/core/GP_Context.h b/include/core/GP_Context.h index bd53482..b4d5ce6 100644 --- a/include/core/GP_Context.h +++ b/include/core/GP_Context.h @@ -100,7 +100,7 @@ GP_Context *GP_ContextAlloc(GP_Size w, GP_Size h, GP_PixelType type); /* * Copy context. */ -GP_Context *GP_ContextCopy(GP_Context *context, int flag); +GP_Context *GP_ContextCopy(const GP_Context *src, int flag);
/* * Create subcontext. diff --git a/libs/core/GP_Context.c b/libs/core/GP_Context.c index fffabba..0ce6342 100644 --- a/libs/core/GP_Context.c +++ b/libs/core/GP_Context.c @@ -28,41 +28,40 @@
#include <string.h>
-GP_Context *GP_ContextCopy(GP_Context *context, int flag) +GP_Context *GP_ContextCopy(const GP_Context *src, int flag) { GP_Context *new; uint8_t *pixels;
- if (context == NULL) + if (src == NULL) return NULL;
new = malloc(sizeof(GP_Context)); - pixels = malloc(context->bytes_per_row * context->h); + pixels = malloc(src->bytes_per_row * src->h);
- if (pixels == NULL || context == NULL) { + if (pixels == NULL || new == NULL) { free(pixels); - free(context); + free(new); return NULL; }
new->pixels = pixels;
if (flag) - memcpy(pixels, context->pixels, - context->bytes_per_row * context->h); + memcpy(pixels, src->pixels, src->bytes_per_row * src->h);
- new->bpp = context->bpp; - new->bytes_per_row = context->bytes_per_row; + new->bpp = src->bpp; + new->bytes_per_row = src->bytes_per_row;
- new->w = context->w; - new->h = context->h; + new->w = src->w; + new->h = src->h;
- new->pixel_type = context->pixel_type; + new->pixel_type = src->pixel_type;
/* rotation and mirroring */ - new->axes_swap = context->axes_swap; - new->y_swap = context->y_swap; - new->x_swap = context->x_swap; + new->axes_swap = src->axes_swap; + new->y_swap = src->y_swap; + new->x_swap = src->x_swap; new->free_pixels = 1;
-----------------------------------------------------------------------
Summary of changes: include/core/GP_Context.h | 2 +- include/filters/{GP_Resize.h => GP_Linear.h} | 11 ++-- libs/core/GP_Context.c | 29 ++++---- libs/filters/GP_Brightness.gen.c.t | 91 +++++++++++++++++++++++++ libs/{core/GP_Debug.c => filters/GP_Linear.c} | 23 ++++-- libs/filters/Makefile | 6 ++- tests/SDL/showimage.c | 16 +++++ tests/SDL/subcontext.c | 10 ++- 8 files changed, 155 insertions(+), 33 deletions(-) copy include/filters/{GP_Resize.h => GP_Linear.h} (91%) create mode 100644 libs/filters/GP_Brightness.gen.c.t copy libs/{core/GP_Debug.c => filters/GP_Linear.c} (81%)
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.