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 7d798834242fb298acd49b2c444843eaad852a93 (commit) from b7f10b82d579dfb7878335336b0d016f5343f793 (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/7d798834242fb298acd49b2c444843eaad852...
commit 7d798834242fb298acd49b2c444843eaad852a93 Author: Cyril Hrubis metan@ucw.cz Date: Sat Jul 9 22:44:00 2011 +0200
Started to fix surrounding library code.
Started to fix the library code to play well with generated code. BEWARE UNTESTED.
diff --git a/include/core/GP_Pixel.h b/include/core/GP_Pixel.h index 7250179..6282bf1 100644 --- a/include/core/GP_Pixel.h +++ b/include/core/GP_Pixel.h @@ -41,7 +41,7 @@ struct GP_Context; /* * GP_PixelType is typedef enum of PixelTypes, * - * each named GP_PIXEL_<TYPENAME>, such as GP_PIXEL_GRB888 + * each named GP_PIXEL_<TYPENAME>, such as GP_PIXEL_RGB888 * see the beginning of GP_Pixel.gen.h for a complete list * * The type always contains GP_PIXEL_UNKNOWN = 0 and @@ -52,8 +52,8 @@ struct GP_Context; /* * GP_Pixel is just uint32_t */ - typedef uint32_t GP_Pixel; +#define GP_PIXEL_BITS 32
/* Generated header */ #include "GP_Pixel.gen.h" @@ -123,8 +123,8 @@ extern const GP_PixelTypeDescription const GP_PixelTypes[];
static inline const char *GP_PixelTypeName(GP_PixelType type) { - GP_CHECK(type < GP_PIXEL_MAX); - return GP_PixelTypes[type].name; + GP_CHECK(type < GP_PIXEL_MAX); + return GP_PixelTypes[type].name; }
/* @@ -133,15 +133,16 @@ static inline const char *GP_PixelTypeName(GP_PixelType type)
static inline uint32_t GP_PixelSize(GP_PixelType type) { - GP_CHECK(type < GP_PIXEL_MAX); - return GP_PixelTypes[type].size; + GP_CHECK(type < GP_PIXEL_MAX); + return GP_PixelTypes[type].size; }
/* * Print a human-readable representation of a pixel value to a string. * Arguments as for snprintf(). */ -static inline void GP_PixelSNPrint(char *buf, size_t len, GP_Pixel pixel, GP_PixelType type) +static inline void GP_PixelSNPrint(char *buf, size_t len, GP_Pixel pixel, + GP_PixelType type) { GP_FN_PER_PIXELTYPE(GP_PixelSNPrint, type, buf, len, pixel); } @@ -156,4 +157,13 @@ static inline void GP_PixelPrint(GP_Pixel pixel, GP_PixelType type) printf("%s", buf); }
+/* + * Match pixel type to known pixel types. + * + * Returns either valid PixelType or GP_PIXEL_UNKNOWN + */ +GP_PixelType GP_PixelRGBMatch(GP_Pixel rmask, GP_Pixel gmask, + GP_Pixel bmask, GP_Pixel amask); + + #endif /* GP_PIXEL_H */ diff --git a/libs/SDL/GP_SDL_Context.c b/libs/SDL/GP_SDL_Context.c index 487476b..021b6e6 100644 --- a/libs/SDL/GP_SDL_Context.c +++ b/libs/SDL/GP_SDL_Context.c @@ -26,91 +26,22 @@ #include "GP.h" #include "GP_SDL.h"
-/* Checks whether pixel color component masks in the given surface are equal - * to specified. Returns nonzero if they match, zero otherwise. - */ -static int check_pixel_masks(SDL_Surface *surf, unsigned int rmask, - unsigned int gmask, unsigned int bmask, unsigned int amask) -{ - return (surf->format->Rmask == rmask - && surf->format->Gmask == gmask - && surf->format->Bmask == bmask - && surf->format->Ashift == amask); -} - -/* Detects the pixel type of the SDL surface. - * Returns the pixel type, or GP_PIXEL_UNKNOWN if the type was not recognized. - */ -static enum GP_PixelType find_surface_pixel_type(SDL_Surface *surf) -{ - switch (surf->format->BytesPerPixel) { - case 1: - if (check_pixel_masks(surf, 0, 0, 0, 0)) { - return GP_PIXEL_PAL8; - } - break; - case 2: - if (check_pixel_masks(surf, 0x7c00, 0x03e0, 0x001f, 0)) { - return GP_PIXEL_RGB555; - } - if (check_pixel_masks(surf, 0xf800, 0x07e0, 0x001f, 0)) { - return GP_PIXEL_RGB565; - } - break; - case 3: - if (check_pixel_masks(surf, 0xff0000, 0xff00, 0xff, 0)) { - return GP_PIXEL_RGB888; - } - if (check_pixel_masks(surf, 0xff, 0xff00, 0xff0000, 0)) { - return GP_PIXEL_BGR888; - } - break; - case 4: - if (check_pixel_masks(surf, 0xff0000, 0xff00, 0xff, 0)) { - return GP_PIXEL_XRGB8888; - } - if (check_pixel_masks(surf, 0xff, 0xff00, 0xff0000, 0)) { - return GP_PIXEL_XBGR8888; - } - if (check_pixel_masks(surf, 0xff000000, 0xff0000, 0xff00, 0)) { - return GP_PIXEL_RGBX8888; - } - if (check_pixel_masks(surf, 0xff00, 0xff0000, 0xff000000, 0)) { - return GP_PIXEL_BGRX8888; - } - if (check_pixel_masks(surf, 0xff0000, 0xff00, 0xff, 0xff000000)) { - return GP_PIXEL_ARGB8888; - } - if (check_pixel_masks(surf, 0xff, 0xff00, 0xff0000, 0xff000000)) { - return GP_PIXEL_ABGR8888; - } - if (check_pixel_masks(surf, 0xff000000, 0xff0000, 0xff00, 0xff)) { - return GP_PIXEL_RGBA8888; - } - if (check_pixel_masks(surf, 0xff00, 0xff0000, 0xff000000, 0xff)) { - return GP_PIXEL_BGRA8888; - } - break; - - } - return GP_PIXEL_UNKNOWN; - -} - GP_RetCode GP_SDL_ContextFromSurface(GP_Context *context, SDL_Surface *surf) { - if (surf == NULL || surf->pixels == NULL || context == NULL) { + if (surf == NULL || surf->pixels == NULL || context == NULL) return GP_ENULLPTR; - }
/* sanity checks on the SDL surface */ - if (surf->format->BytesPerPixel == 0 || surf->format->BytesPerPixel > 4) { + if (surf->format->BytesPerPixel == 0 || surf->format->BytesPerPixel > 4) return GP_ENOIMPL; - } - enum GP_PixelType pixeltype = find_surface_pixel_type(surf); - if (pixeltype == GP_PIXEL_UNKNOWN) { + + enum GP_PixelType pixeltype = GP_PixelRGBMatch(surf->format->Rmask, + surf->format->Gmask, + surf->format->Bmask, + surf->format->Ashift); + + if (pixeltype == GP_PIXEL_UNKNOWN) return GP_ENOIMPL; - }
/* basic structure and size */ context->pixels = surf->pixels; diff --git a/libs/backends/GP_Backend_SDL.c b/libs/backends/GP_Backend_SDL.c index 2cf4fe4..aac4a32 100644 --- a/libs/backends/GP_Backend_SDL.c +++ b/libs/backends/GP_Backend_SDL.c @@ -45,78 +45,6 @@ static int (*dyn_SDL_WaitEvent)(SDL_Event *); /* User callbacks. */ static void (*GP_SDL_update_video_callback)(void) = NULL;
-/* - * Checks whether pixel color component masks in the given surface are equal - * to specified. Returns nonzero if they match, zero otherwise. - */ -static int GP_SDL_CheckPixelMasks(SDL_Surface *surf, unsigned int rmask, - unsigned int gmask, unsigned int bmask, unsigned int amask) -{ - return (surf->format->Rmask == rmask - && surf->format->Gmask == gmask - && surf->format->Bmask == bmask - && surf->format->Ashift == amask); -} - -/* - * Detects the pixel type of the SDL surface. - * Returns the pixel type, or GP_PIXEL_UNKNOWN if the type was not recognized. - */ -static enum GP_PixelType GP_SDL_FindSurfacePixelType(SDL_Surface *surf) -{ - switch (surf->format->BytesPerPixel) { - case 1: - if (GP_SDL_CheckPixelMasks(surf, 0, 0, 0, 0)) { - return GP_PIXEL_PAL8; - } - break; - case 2: - if (GP_SDL_CheckPixelMasks(surf, 0x7c00, 0x03e0, 0x001f, 0)) { - return GP_PIXEL_RGB555; - } - if (GP_SDL_CheckPixelMasks(surf, 0xf800, 0x07e0, 0x001f, 0)) { - return GP_PIXEL_RGB565; - } - break; - case 3: - if (GP_SDL_CheckPixelMasks(surf, 0xff0000, 0xff00, 0xff, 0)) { - return GP_PIXEL_RGB888; - } - if (GP_SDL_CheckPixelMasks(surf, 0xff, 0xff00, 0xff0000, 0)) { - return GP_PIXEL_BGR888; - } - break; - case 4: - if (GP_SDL_CheckPixelMasks(surf, 0xff0000, 0xff00, 0xff, 0)) { - return GP_PIXEL_XRGB8888; - } - if (GP_SDL_CheckPixelMasks(surf, 0xff, 0xff00, 0xff0000, 0)) { - return GP_PIXEL_XBGR8888; - } - if (GP_SDL_CheckPixelMasks(surf, 0xff000000, 0xff0000, 0xff00, 0)) { - return GP_PIXEL_RGBX8888; - } - if (GP_SDL_CheckPixelMasks(surf, 0xff00, 0xff0000, 0xff000000, 0)) { - return GP_PIXEL_BGRX8888; - } - if (GP_SDL_CheckPixelMasks(surf, 0xff0000, 0xff00, 0xff, 0xff000000)) { - return GP_PIXEL_ARGB8888; - } - if (GP_SDL_CheckPixelMasks(surf, 0xff, 0xff00, 0xff0000, 0xff000000)) { - return GP_PIXEL_ABGR8888; - } - if (GP_SDL_CheckPixelMasks(surf, 0xff000000, 0xff0000, 0xff00, 0xff)) { - return GP_PIXEL_RGBA8888; - } - if (GP_SDL_CheckPixelMasks(surf, 0xff00, 0xff0000, 0xff000000, 0xff)) { - return GP_PIXEL_BGRA8888; - } - break; - - } - return GP_PIXEL_UNKNOWN; -} - inline GP_RetCode GP_SDL_ContextFromSurface( GP_Context *context, SDL_Surface *surf) { @@ -124,13 +52,16 @@ inline GP_RetCode GP_SDL_ContextFromSurface( GP_CHECK(surf, "surface is NULL");
/* sanity checks on the SDL surface */ - if (surf->format->BytesPerPixel == 0 || surf->format->BytesPerPixel > 4) { + if (surf->format->BytesPerPixel == 0 || surf->format->BytesPerPixel > 4) return GP_ENOIMPL; - } - enum GP_PixelType pixeltype = GP_SDL_FindSurfacePixelType(surf); - if (pixeltype == GP_PIXEL_UNKNOWN) { + + enum GP_PixelType pixeltype = GP_PixelRGBMatch(surf->format->Rmask, + surf->format->Gmask, + surf->format->Bmask, + surf->format->Ashift); + + if (pixeltype == GP_PIXEL_UNKNOWN) return GP_ENOIMPL; - }
/* basic structure and size */ context->pixels = surf->pixels; diff --git a/libs/core/GP_Pixel.c b/libs/core/GP_Pixel.c new file mode 100644 index 0000000..d6553b1 --- /dev/null +++ b/libs/core/GP_Pixel.c @@ -0,0 +1,78 @@ +/***************************************************************************** + * 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-2010 Jiri "BlueBear" Dluhos * + * jiri.bluebear.dluhos@gmail.com * + * * + * Copyright (C) 2009-2010 Cyril Hrubis metan@ucw.cz * + * * + *****************************************************************************/ + +#include <string.h> + +#include "GP_Pixel.h" + +static const GP_PixelTypeChannel *get_channel(const GP_PixelTypeDescription *desc, + const char *name) +{ + unsigned int i; + + for (i = 0; i < desc->numchannels; i++) + if (!strcmp(desc->channels[i].name, name)) + return &desc->channels[i]; + + return NULL; +} + +static int match(const GP_PixelTypeChannel *channel, GP_Pixel mask) +{ + if (channel == NULL) + return !mask; + + GP_Pixel chmask = ~0; + + chmask >>= (GP_PIXEL_BITS - channel->size); + chmask <<= channel->offset; + + return (chmask == mask); +} + +GP_PixelType GP_PixelRGBMatch(GP_Pixel rmask, GP_Pixel gmask, + GP_Pixel bmask, GP_Pixel amask) +{ + unsigned int i; + + for (i = 0; i < GP_PIXEL_MAX; i++) { + int res; + + const GP_PixelTypeChannel *r, *g, *b, *a; + + r = get_channel(&GP_PixelTypes[i], "R"); + g = get_channel(&GP_PixelTypes[i], "G"); + b = get_channel(&GP_PixelTypes[i], "B"); + a = get_channel(&GP_PixelTypes[i], "A"); + + res = match(r, rmask) && match(g, gmask) && + match(b, bmask) && match(a, amask); + + if (res) + return GP_PixelTypes[i].type; + } + + return GP_PIXEL_UNKNOWN; +} diff --git a/libs/loaders/Makefile b/libs/loaders/Makefile index 1e88e78..e753f5c 100644 --- a/libs/loaders/Makefile +++ b/libs/loaders/Makefile @@ -1,5 +1,5 @@ TOPDIR=../.. -CSOURCES=$(shell ls *.c) +#CSOURCES=$(shell ls *.c) LIBNAME=loaders include $(TOPDIR)/include.mk include $(TOPDIR)/lib.mk diff --git a/pylib/gfxprim/generators/core/make_GP_Convert.py b/pylib/gfxprim/generators/core/make_GP_Convert.py index dfd23dd..03b682c 100644 --- a/pylib/gfxprim/generators/core/make_GP_Convert.py +++ b/pylib/gfxprim/generators/core/make_GP_Convert.py @@ -20,7 +20,7 @@ def core_GP_Pixel_Scale_gen(h): h.rhead( "/* helper macros to transfer s1-bit value to s2-bit valuen" " * NOTE: efficient and accurate for both up- and downscaling,n" - " * WARNING: GP_SCALE_VAL requires constants numebrs as first two parametersn" + " * WARNING: GP_SCALE_VAL requires constants numbers as first two parametersn" " */n" "#define GP_SCALE_VAL(s1, s2, val) ( GP_SCALE_VAL_##s1##_##s2(val) )nn"
-----------------------------------------------------------------------
Summary of changes: include/core/GP_Pixel.h | 24 ++++-- libs/SDL/GP_SDL_Context.c | 87 ++------------------- libs/backends/GP_Backend_SDL.c | 85 ++------------------- libs/{backends/GP_Backend.c => core/GP_Pixel.c} | 79 +++++++++----------- libs/loaders/Makefile | 2 +- pylib/gfxprim/generators/core/make_GP_Convert.py | 2 +- 6 files changed, 71 insertions(+), 208 deletions(-) copy libs/{backends/GP_Backend.c => core/GP_Pixel.c} (64%)
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.