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 f9ab072d9aeefcd9888506fe0a9f30757c9e9a76 (commit) via dcb1062650a4926ced12a094a86d0a7590b5f67b (commit) via 0424a9f874f03edea2f10b52204ef3e6198126cd (commit) via 71f8dfeb78b75bc456ac761eaf74ea143548561a (commit) via 882c1204e0a05f9e82e8af79b2959569de0e5399 (commit) via 91e5cbbaa1e757faac1b3edd9144d749000de97a (commit) via c53b91525478de6a140d4355da7d62e6957d2727 (commit) from feff7abe0be63662f56d82aa080f3c7c8be9d194 (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/f9ab072d9aeefcd9888506fe0a9f30757c9e9...
commit f9ab072d9aeefcd9888506fe0a9f30757c9e9a76 Author: Cyril Hrubis metan@ucw.cz Date: Wed Apr 10 17:33:55 2013 +0200
core: Pixel: Add GP_PixelHasAlpha().
Signed-off-by: Cyril Hrubis metan@ucw.cz
diff --git a/include/core/GP_Pixel.h b/include/core/GP_Pixel.h index c9f0ab4..a60707f 100644 --- a/include/core/GP_Pixel.h +++ b/include/core/GP_Pixel.h @@ -186,4 +186,10 @@ GP_PixelType GP_PixelRGBLookup(uint32_t rsize, uint32_t roff, uint32_t asize, uint32_t aoff, uint8_t bits_per_pixel);
+/* + * Function to determine pixel attributes. + */ +int GP_PixelHasAlpha(GP_PixelType pixel_type); + + #endif /* CORE_GP_PIXEL_H */ diff --git a/libs/core/GP_Pixel.c b/libs/core/GP_Pixel.c index b14d5b0..b1ccad5 100644 --- a/libs/core/GP_Pixel.c +++ b/libs/core/GP_Pixel.c @@ -162,3 +162,16 @@ GP_PixelType GP_PixelRGBLookup(uint32_t rsize, uint32_t roff,
return GP_PIXEL_UNKNOWN; } + +int GP_PixelHasAlpha(GP_PixelType pixel_type) +{ + unsigned int i; + + GP_CHECK_VALID_PIXELTYPE(pixel_type); + + for (i = 0; i < GP_PixelTypes[pixel_type].numchannels; i++) + if (!strcmp(GP_PixelTypes[pixel_type].channels[i].name, "A")) + return 1; + + return 0; +}
http://repo.or.cz/w/gfxprim.git/commit/dcb1062650a4926ced12a094a86d0a7590b5f...
commit dcb1062650a4926ced12a094a86d0a7590b5f67b Author: Cyril Hrubis metan@ucw.cz Date: Wed Apr 10 17:32:17 2013 +0200
core: ContextConvert: Fill the allocated buffer.
Since alpha channel blits started to work, the image will be alpha blended with random mess in the allocated buffer. Fix it by filling the buffer with zeroes first which restores the previous behavior.
Signed-off-by: Cyril Hrubis metan@ucw.cz
diff --git a/libs/core/GP_Context.c b/libs/core/GP_Context.c index 633cb2e..a7855c7 100644 --- a/libs/core/GP_Context.c +++ b/libs/core/GP_Context.c @@ -213,9 +213,16 @@ GP_Context *GP_ContextConvertAlloc(const GP_Context *src, int h = GP_ContextH(src);
GP_Context *ret = GP_ContextAlloc(w, h, dst_pixel_type); - + if (ret == NULL) return NULL; + + /* + * Fill the buffer with zeroes, otherwise it will + * contain random data which will generate mess + * when converting image with alpha channel. + */ + memset(ret->pixels, 0, ret->bytes_per_row * ret->h);
GP_Blit(src, 0, 0, w, h, ret, 0, 0); @@ -228,6 +235,13 @@ GP_Context *GP_ContextConvert(const GP_Context *src, GP_Context *dst) int w = GP_ContextW(src); int h = GP_ContextH(src); + /* + * Fill the buffer with zeroes, otherwise it will + * contain random data which will generate mess + * when converting image with alpha channel. + */ + memset(dst->pixels, 0, dst->bytes_per_row * dst->h); + GP_Blit(src, 0, 0, w, h, dst, 0, 0);
return dst;
http://repo.or.cz/w/gfxprim.git/commit/0424a9f874f03edea2f10b52204ef3e619812...
commit 0424a9f874f03edea2f10b52204ef3e6198126cd Author: Cyril Hrubis metan@ucw.cz Date: Wed Apr 10 16:44:50 2013 +0200
core: Blit: Implement blit with alpha channel.
This is first version, more to come.
Signed-off-by: Cyril Hrubis metan@ucw.cz
diff --git a/include/core/GP_MixPixels2.gen.h.t b/include/core/GP_MixPixels2.gen.h.t new file mode 100644 index 0000000..5810a66 --- /dev/null +++ b/include/core/GP_MixPixels2.gen.h.t @@ -0,0 +1,83 @@ +/***************************************************************************** + * 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-2013 Cyril Hrubis metan@ucw.cz * + * * + *****************************************************************************/ + +%% extends "base.h.t" + +%%- block descr +Macros to mix two pixels. The source must have alpha channel. +%%- endblock + +%% block body + +#include "core/GP_GammaCorrection.h" +#include "core/GP_Pixel.h" + +//TODO: Fix blit where both source and destination have alpha channel + +%% for src in pixeltypes +%% if not src.is_unknown() and not src.is_palette() +%% for dst in pixeltypes +%% if not dst.is_unknown() and not dst.is_palette() +%% if src.is_alpha() + +static inline GP_Pixel GP_MixPixels_{{ src.name }}_{{ dst.name }}(GP_Pixel src, GP_Pixel dst) +{ + /* Extract the alpha channel */ + unsigned int alpha = GP_Pixel_GET_A_{{ src.name }}(src); + + /* Convert the pixel to RGB888, mix the values */ + GP_Pixel src_rgb = 0, dst_rgb = 0, res = 0; + + GP_Pixel_{{ src.name }}_TO_RGB888(src, src_rgb); + GP_Pixel_{{ dst.name }}_TO_RGB888(dst, dst_rgb); + + int sr, sg, sb; + int dr, dg, db; + + sr = GP_Pixel_GET_R_RGB888(src_rgb); + sg = GP_Pixel_GET_G_RGB888(src_rgb); + sb = GP_Pixel_GET_B_RGB888(src_rgb); + + dr = GP_Pixel_GET_R_RGB888(dst_rgb); + dg = GP_Pixel_GET_G_RGB888(dst_rgb); + db = GP_Pixel_GET_B_RGB888(dst_rgb); + +%% set a_max = 2 ** src.chans['A'][2] - 1 + + dr = (dr * ({{ a_max }} - alpha) + sr * alpha + {{ a_max // 2 }}) / {{ a_max }}; + dg = (dg * ({{ a_max }} - alpha) + sg * alpha + {{ a_max // 2 }}) / {{ a_max }}; + db = (db * ({{ a_max }} - alpha) + sb * alpha + {{ a_max // 2 }}) / {{ a_max }}; + + dst_rgb = GP_Pixel_CREATE_RGB888(dr, dg, db); + + GP_Pixel_RGB888_TO_{{ dst.name }}(dst_rgb, res); + + return res; +} + +%% endif +%% endif +%% endfor +%% endif +%% endfor + +%% endblock diff --git a/include/core/Makefile b/include/core/Makefile index 0dac795..6267d32 100644 --- a/include/core/Makefile +++ b/include/core/Makefile @@ -5,7 +5,7 @@ include $(TOPDIR)/pre.mk GENHEADERS=GP_Convert_Scale.gen.h GP_Pixel.gen.h GP_GetPutPixel.gen.h GP_Convert.gen.h GP_FnPerBpp.gen.h GP_MixPixels.gen.h GP_GammaCorrection.gen.h GP_GammaPixel.gen.h - GP_WritePixel.gen.h + GP_WritePixel.gen.h GP_MixPixels2.gen.h
include $(TOPDIR)/gen.mk include $(TOPDIR)/post.mk diff --git a/libs/core/GP_Blit.gen.c.t b/libs/core/GP_Blit.gen.c.t index ccb924a..0216cfc 100644 --- a/libs/core/GP_Blit.gen.c.t +++ b/libs/core/GP_Blit.gen.c.t @@ -13,6 +13,7 @@ #include "core/GP_Convert.h" #include "core/GP_Convert.gen.h" #include "core/GP_Convert_Scale.gen.h" +#include "core/GP_MixPixels2.gen.h"
/* * TODO: this is used for same pixel but different offset, could still be optimized @@ -97,10 +98,10 @@ static void blitXYXY_Raw_{{ ps.suffix }}(const GP_Context *src, * more than 50% and the size footprint for two for cycles is really small. */ %% for src in pixeltypes -%% if not src.is_unknown() and not src.is_palette() -%% for dst in pixeltypes -%% if not dst.is_unknown() and not dst.is_palette() -%% if dst.name != src.name +%% if not src.is_unknown() and not src.is_palette() +%% for dst in pixeltypes +%% if not dst.is_unknown() and not dst.is_palette() +%% if dst.name != src.name /* * Blits {{ src.name }} to {{ dst.name }} */ @@ -108,22 +109,32 @@ static void blitXYXY_Raw_{{ src.name }}_{{ dst.name }}(const GP_Context *src, GP_Coord x0, GP_Coord y0, GP_Coord x1, GP_Coord y1, GP_Context *dst, GP_Coord x2, GP_Coord y2) { - GP_Coord x, y; + GP_Coord x, y, dx, dy;
- for (y = y0; y <= y1; y++) + for (y = y0; y <= y1; y++) { for (x = x0; x <= x1; x++) { - GP_Pixel p1, p2 = 0; + dx = x2 + (x - x0); + dy = y2 + (y - y0); + + GP_Pixel p1, p2 = 0, p3 = 0; + p1 = GP_GetPixel_Raw_{{ src.pixelsize.suffix }}(src, x, y); +%% if src.is_alpha() + p2 = GP_GetPixel_Raw_{{ dst.pixelsize.suffix }}(dst, dx, dy); + p3 = GP_MixPixels_{{ src.name }}_{{ dst.name }}(p1, p2); +%% else GP_Pixel_{{ src.name }}_TO_RGB888(p1, p2); - GP_Pixel_RGB888_TO_{{ dst.name }}(p2, p1); - GP_PutPixel_Raw_{{ dst.pixelsize.suffix }}(dst, x2 + (x - x0), y2 + (y - y0), p1); + GP_Pixel_RGB888_TO_{{ dst.name }}(p2, p3); +%% endif + GP_PutPixel_Raw_{{ dst.pixelsize.suffix }}(dst, dx, dy, p3); } + } }
-%% endif -%% endif -%% endfor -%% endif +%% endif +%% endif +%% endfor +%% endif %% endfor
void GP_BlitXYXY_Raw_Fast(const GP_Context *src,
http://repo.or.cz/w/gfxprim.git/commit/71f8dfeb78b75bc456ac761eaf74ea1435485...
commit 71f8dfeb78b75bc456ac761eaf74ea143548561a Author: Cyril Hrubis metan@ucw.cz Date: Wed Apr 10 16:16:19 2013 +0200
demos: py_simple: Add demo for alpha channel blit.
Signed-off-by: Cyril Hrubis metan@ucw.cz
diff --git a/demos/py_simple/ball_blue.png b/demos/py_simple/ball_blue.png new file mode 100644 index 0000000..2d6c566 Binary files /dev/null and b/demos/py_simple/ball_blue.png differ diff --git a/demos/py_simple/ball_green.png b/demos/py_simple/ball_green.png new file mode 100644 index 0000000..6ed05b7 Binary files /dev/null and b/demos/py_simple/ball_green.png differ diff --git a/demos/py_simple/ball_red.png b/demos/py_simple/ball_red.png new file mode 100644 index 0000000..bf2bde9 Binary files /dev/null and b/demos/py_simple/ball_red.png differ diff --git a/demos/py_simple/blit.py b/demos/py_simple/blit.py new file mode 100755 index 0000000..14fa361 --- /dev/null +++ b/demos/py_simple/blit.py @@ -0,0 +1,90 @@ +#!/usr/bin/env python + +import sys +from time import sleep + +import gfxprim.core as core +import gfxprim.loaders as loaders +import gfxprim.backends as backends +import gfxprim.input as input + +class Ball: + def __init__(self, x, y, dx, dy, path, bg_img): + self.ball = loaders.Load(path) + assert(self.ball) + + self.x = x + self.y = y + self.dx = dx + self.dy = dy + + self.bg_img = bg_img + + def draw(self, bk): + self.ball.Blit(0, 0, bk.context, self.x, self.y, self.ball.w, self.ball.h) + + def move(self, bk): + old_x = self.x; + old_y = self.y; + + self.bg_img.Blit(old_x, old_y, bk.context, old_x, old_y, self.ball.w, self.ball.h) + + self.x += self.dx + self.y += self.dy + + if (self.x <= 0 or self.x >= self.bg_img.w - self.ball.w): + self.dx = -self.dx + + if (self.y <= 0 or self.y >= self.bg_img.h - self.ball.h): + self.dy = -self.dy + + self.ball.Blit(0, 0, bk.context, self.x, self.y, self.ball.w, self.ball.h) + bk.UpdateRect(min(old_x, self.x), min(self.y, old_y), + max(old_x, self.x) + self.ball.w - 1, + max(old_y, self.y) + self.ball.h - 1) + +def main(): + if len(sys.argv) != 2: + print("Takes an image as an argument") + sys.exit(1) + + # Load Backgroudn Image and ball sprite + bg = loaders.Load(sys.argv[1]) + assert(bg) + + ball1 = Ball(bg.w//2, bg.h//2, -3, -3, 'ball_red.png', bg) + ball2 = Ball(bg.w//2, bg.h//2, -2, 3, 'ball_green.png', bg) + ball3 = Ball(bg.w//2, bg.h//2, 2, -3, 'ball_blue.png', bg) + + # Create X11 window + bk = backends.BackendX11Init(None, 0, 0, bg.w, bg.h, sys.argv[1], 0) + assert(bk) + bg.Blit(0, 0, bk.context, 0, 0, bg.w, bg.h) + + bk.Flip() + + # Event loop + while True: + + while True: + ev = bk.PollEvent() + + if (ev is None): + break + + input.EventDump(ev) + + if (ev.type == input.EV_KEY and ev.val.val == input.KEY_ESC): + sys.exit(0) + elif (ev.type == input.EV_SYS): + if (ev.code == input.EV_SYS_QUIT): + sys.exit(0) + + sleep(0.005) + + ball1.move(bk); + ball2.move(bk); + ball3.move(bk); + +if __name__ == '__main__': + main()
http://repo.or.cz/w/gfxprim.git/commit/882c1204e0a05f9e82e8af79b2959569de0e5...
commit 882c1204e0a05f9e82e8af79b2959569de0e5399 Author: Cyril Hrubis metan@ucw.cz Date: Wed Apr 10 15:32:28 2013 +0200
doc: Slight update in the python backend docs.
Signed-off-by: Cyril Hrubis metan@ucw.cz
diff --git a/doc/backends_python.txt b/doc/backends_python.txt index 32d5d9f..48f5e01 100644 --- a/doc/backends_python.txt +++ b/doc/backends_python.txt @@ -91,8 +91,10 @@ import gfxprim.backends as backends bk.context.gfx.Fill(bk.context.RGBToPixel(0, 0, 0));
# If backend is buffered, changes are not propagated unless the screen is - # updated via Flip() or UpdateRect() + # updated via Flip() bk.Flip() + # or UpdateRect() + bk.UpdaterRect(x0, y0, x1, y1)
-------------------------------------------------------------------------------
http://repo.or.cz/w/gfxprim.git/commit/91e5cbbaa1e757faac1b3edd9144d749000de...
commit 91e5cbbaa1e757faac1b3edd9144d749000de97a Author: Cyril Hrubis metan@ucw.cz Date: Wed Apr 10 15:27:40 2013 +0200
pywrap: backends: Change UpdateRect API
The UpdateRect() now takes four numbers rather than array.
Signed-off-by: Cyril Hrubis metan@ucw.cz
diff --git a/pylib/gfxprim/backends/_extend_backend.py b/pylib/gfxprim/backends/_extend_backend.py index adaf96a..7ab8d07 100644 --- a/pylib/gfxprim/backends/_extend_backend.py +++ b/pylib/gfxprim/backends/_extend_backend.py @@ -20,9 +20,9 @@ def extend_backend(_backend): return c_backends.GP_BackendFlip(self)
@extend(_backend) - def UpdateRect(self, rect): + def UpdateRect(self, x0, y0, x1, y1): "Update a rectangle on a buffered backend." - return c_backends.GP_BackendUpdateRect(self, rect[0], rect[1], rect[2], rect[3]) + return c_backends.GP_BackendUpdateRect(self, x0, y0, x1, y1)
@extend(_backend) def Poll(self):
http://repo.or.cz/w/gfxprim.git/commit/c53b91525478de6a140d4355da7d62e6957d2...
commit c53b91525478de6a140d4355da7d62e6957d2727 Author: Cyril Hrubis metan@ucw.cz Date: Tue Apr 9 16:14:38 2013 +0200
core: tests: Test for invalid context pixel type.
Signed-off-by: Cyril Hrubis metan@ucw.cz
diff --git a/include/core/GP_Pixel.h b/include/core/GP_Pixel.h index c0b13f3..c9f0ab4 100644 --- a/include/core/GP_Pixel.h +++ b/include/core/GP_Pixel.h @@ -112,8 +112,10 @@ typedef struct GP_PixelTypeDescription { */ extern const GP_PixelTypeDescription const GP_PixelTypes[GP_PIXEL_MAX];
+#define GP_VALID_PIXELTYPE(type) (((type) > 0) && ((type) < GP_PIXEL_MAX)) + #define GP_CHECK_VALID_PIXELTYPE(type) - GP_CHECK(((type) > 0) && ((type) < GP_PIXEL_MAX), "Invalid PixelType %d", (type)) + GP_CHECK(GP_VALID_PIXELTYPE(type), "Invalid PixelType %d", (type))
/* * Convert pixel type to name. diff --git a/libs/core/GP_Context.c b/libs/core/GP_Context.c index 6279890..633cb2e 100644 --- a/libs/core/GP_Context.c +++ b/libs/core/GP_Context.c @@ -41,14 +41,16 @@ static uint32_t get_bpr(uint32_t bpp, uint32_t w)
GP_Context *GP_ContextAlloc(GP_Size w, GP_Size h, GP_PixelType type) { - GP_CHECK_VALID_PIXELTYPE(type); GP_Context *context; - uint32_t bpp = GP_PixelSize(type); - uint32_t bpr = get_bpr(bpp, w); + uint32_t bpp; + uint32_t bpr; void *pixels;
- GP_DEBUG(1, "Allocating context %u x %u - %s", - w, h, GP_PixelTypeName(type)); + if (!GP_VALID_PIXELTYPE(type)) { + GP_WARN("Invalid pixel type %u", type); + errno = EINVAL; + return NULL; + }
if (w <= 0 || h <= 0) { GP_WARN("Trying to allocate context with zero width and/or height"); @@ -56,6 +58,12 @@ GP_Context *GP_ContextAlloc(GP_Size w, GP_Size h, GP_PixelType type) return NULL; }
+ GP_DEBUG(1, "Allocating context %u x %u - %s", + w, h, GP_PixelTypeName(type)); + + bpp = GP_PixelSize(type); + bpr = get_bpr(bpp, w); + pixels = malloc(bpr * h); context = malloc(sizeof(GP_Context));
diff --git a/tests/core/Context.c b/tests/core/Context.c index fbabf17..5715717 100644 --- a/tests/core/Context.c +++ b/tests/core/Context.c @@ -243,6 +243,44 @@ static int context_zero_h(void) return TST_SUCCESS; }
+static int context_invalid_pixeltype1(void) +{ + GP_Context *c; + + c = GP_ContextAlloc(100, 100, -1); + + if (c != NULL) { + tst_msg("Context with invalid pixel type (-1) succesfully allocated"); + return TST_FAILED; + } + + if (errno != EINVAL) { + tst_msg("Expected errno set to EINVAL"); + return TST_FAILED; + } + + return TST_SUCCESS; +} + +static int context_invalid_pixeltype2(void) +{ + GP_Context *c; + + c = GP_ContextAlloc(100, 100, GP_PIXEL_MAX + 1000); + + if (c != NULL) { + tst_msg("Context with invalid pixel type (-1) succesfully allocated"); + return TST_FAILED; + } + + if (errno != EINVAL) { + tst_msg("Expected errno set to EINVAL"); + return TST_FAILED; + } + + return TST_SUCCESS; +} + const struct tst_suite tst_suite = { .suite_name = "Context Testsuite", .tests = { @@ -257,6 +295,10 @@ const struct tst_suite tst_suite = { .tst_fn = context_zero_w}, {.name = "Context Create h = 0", .tst_fn = context_zero_h}, + {.name = "Context Create pixel_type = -1", + .tst_fn = context_invalid_pixeltype1}, + {.name = "Context Create invalid pixel_type", + .tst_fn = context_invalid_pixeltype2}, {.name = NULL}, } };
-----------------------------------------------------------------------
Summary of changes: demos/py_simple/ball_blue.png | Bin 0 -> 1151 bytes demos/py_simple/ball_green.png | Bin 0 -> 1182 bytes demos/py_simple/ball_red.png | Bin 0 -> 1144 bytes demos/py_simple/blit.py | 90 ++++++++++++++++++++ doc/backends_python.txt | 4 +- .../core/GP_MixPixels2.gen.h.t | 82 ++++++++++-------- include/core/GP_Pixel.h | 10 ++- include/core/Makefile | 2 +- libs/core/GP_Blit.gen.c.t | 37 +++++--- libs/core/GP_Context.c | 34 ++++++-- libs/core/GP_Pixel.c | 13 +++ pylib/gfxprim/backends/_extend_backend.py | 4 +- tests/core/Context.c | 42 +++++++++ 13 files changed, 257 insertions(+), 61 deletions(-) create mode 100644 demos/py_simple/ball_blue.png create mode 100644 demos/py_simple/ball_green.png create mode 100644 demos/py_simple/ball_red.png create mode 100755 demos/py_simple/blit.py copy libs/gfx/GP_PutPixelAA.gen.c.t => include/core/GP_MixPixels2.gen.h.t (53%)
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.