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 abf38d0ef10e4cd84391950b1595cfc60dcf3181 (commit) via 80c8f8ccda4b63c85fa784cb2ebfa61181a818a4 (commit) via 06fa397a908dd96877573db3df61274cd493eed4 (commit) via 21749e191eb8863acaa33bc32d2959f89cc97d88 (commit) via 4b24345dd60ebbc38dccca753476ebf32cb72df0 (commit) via 47c5f5f4b32da3d004ffa2c037857c8323ea1a1f (commit) via c4ac868f69649ea94eab4a650b49ca25dcd2c490 (commit) via 51e969cd103ec6546ec91af744157338d352896c (commit) via f11293be8118c9707b268f55ba49dc6ea8b111ff (commit) via 6aa9b93dc730b452effb253df5a051bc791692ef (commit) via 93c34cab6ae326bf2ff21a69c973a3922ca9ece7 (commit) via 628bf75875173555777a15ce6a7fe7e91cd328b8 (commit) via cfd3858ce9e6a269b8903bd312e52259c48e318c (commit) from fb094cd7f8086ddb9e59b91224c5fef9702136fa (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/abf38d0ef10e4cd84391950b1595cfc60dcf3...
commit abf38d0ef10e4cd84391950b1595cfc60dcf3181 Author: Tomas Gavenciak gavento@ucw.cz Date: Sun Jun 12 01:27:18 2011 +0200
Add blit color conversion, use GP_Coord and GP_Size in blits
diff --git a/libs/core/GP_Blit.c b/include/core/GP_Blit.h similarity index 55% copy from libs/core/GP_Blit.c copy to include/core/GP_Blit.h index 29e90e8..fc2c6a7 100644 --- a/libs/core/GP_Blit.c +++ b/include/core/GP_Blit.h @@ -20,57 +20,29 @@ * * *****************************************************************************/
-#include "GP_Pixel.h" -#include "GP_Pixel_Access.h" -#include "GP_Context.h" +#ifndef CORE_GP_BLIT_H +#define CORE_GP_BLIT_H
-/* -void GP_Blit(const GP_Context *c1, int x1, int y1, int w, int h, - GP_Context *c2, int x2, int y2) -{ - // Ultimate TODO: effective processing - GP_Blit_Naive(c1, x1, y1, w, h, c2, x2, y2); -} -*/ +/* Generated header */ +#include "GP_Blit.gen.h"
-// TODO(gavento, czech) Plan: -// GP_Blit_Naive - Zadne rotovani a tak, jen Get/PutPixel a konverze A->RGBA8888->B -// GP_Blit_Simple - S rotovanim, makrovy Get/PutPixel, mozna optimalizace na radky, chytrejsi konverze (ale porad univ.) -// GP_Blit_Simple_xBPP - S rotovanim, makrovy Get/PutPixel -// GP_Blit_xBPP - Optimalizovane, muze volat GP_Blit_Simple_xBPP pro divne pripady -// GP_Blit - Vola GP_Blit_xBPP (stejny typ) nebo GP_Blit_Simple (jine typy), pripadne optimalizovat - -/* -void GP_Blit_Naive(const GP_Context *c1, int x1, int y1, int w, int h, - GP_Context *c2, int x2, int y2) -{ - GP_TRANSFORM_BLIT(c1, x1, y1, w, h, c2, x2, y2); - // TODO: Cipping? - GP_Blit_Naive_Raw(c1, x1, y1, w, h, c2, x2, y2); -} -*/ +void GP_Blit(const GP_Context *c1, int x1, int y1, int w, int h, + GP_Context *c2, int x2, int y2);
/* * Very naive blit, no optimalizations whatsoever - keep it that way. * Used as a reference for testing and such. Aaand ultimate fallback. + * GP_CHECKS for clipping and size (for testing) */ -void GP_Blit_Naive(const GP_Context *c1, int x1, int y1, int w, int h, - GP_Context *c2, int x2, int y2) -{ - GP_CHECK(x1 >= 0); - GP_CHECK(y1 >= 0); - GP_CHECK(w >= 0); - GP_CHECK(h >= 0); - GP_CHECK(x1 + w <= GP_ContextW(c1)); - GP_CHECK(y1 + h <= GP_ContextH(c1)); - GP_CHECK(x2 >= 0); - GP_CHECK(y2 >= 0); - GP_CHECK(x2 + w <= GP_ContextW(c2)); - GP_CHECK(y2 + h <= GP_ContextH(c2)); +void GP_Blit_Naive(const GP_Context *c1, GP_Coord x1, GP_Coord y1, GP_Size w, GP_Size h, + GP_Context *c2, GP_Coord x2, GP_Coord y2);
- for (int i = 0; i < w; i++) - for (int j = 0; j < h; j++) { - GP_Pixel p = GP_GetPixel(c1, x1 + i, y1 + j); - GP_PutPixel(c2, x2 + i, y2 + j, p); - } -} +/* + * Similar in purpose to GP_Blit_Naive, but operates on raw coordinates. + * Does no range checking. + */ +/* +void GP_Blit_Naive_Raw(const GP_Context *c1, int x1, int y1, int w, int h, + GP_Context *c2, int x2, int y2); +*/ +#endif // CORE_GP_BLIT_H diff --git a/libs/core/GP_Blit.c b/libs/core/GP_Blit.c index 29e90e8..76c7a2c 100644 --- a/libs/core/GP_Blit.c +++ b/libs/core/GP_Blit.c @@ -21,8 +21,9 @@ *****************************************************************************/
#include "GP_Pixel.h" -#include "GP_Pixel_Access.h" +#include "GP_GetPutPixel.h" #include "GP_Context.h" +#include "GP_Blit.h"
/* void GP_Blit(const GP_Context *c1, int x1, int y1, int w, int h, @@ -50,12 +51,8 @@ void GP_Blit_Naive(const GP_Context *c1, int x1, int y1, int w, int h, } */
-/* - * Very naive blit, no optimalizations whatsoever - keep it that way. - * Used as a reference for testing and such. Aaand ultimate fallback. - */ -void GP_Blit_Naive(const GP_Context *c1, int x1, int y1, int w, int h, - GP_Context *c2, int x2, int y2) +void GP_Blit_Naive(const GP_Context *c1, GP_Coord x1, GP_Coord y1, GP_Size w, GP_Size h, + GP_Context *c2, GP_Coord x2, GP_Coord y2) { GP_CHECK(x1 >= 0); GP_CHECK(y1 >= 0); @@ -71,6 +68,8 @@ void GP_Blit_Naive(const GP_Context *c1, int x1, int y1, int w, int h, for (int i = 0; i < w; i++) for (int j = 0; j < h; j++) { GP_Pixel p = GP_GetPixel(c1, x1 + i, y1 + j); + if (c1->pixel_type != c2->pixel_type) + p = GP_GP_ConvertContextPixel(p, c1, c2); GP_PutPixel(c2, x2 + i, y2 + j, p); } } diff --git a/pylib/gfxprim/generators/core/gen_blit.py b/pylib/gfxprim/generators/core/gen_blit.py index 819f29f..78be0f8 100644 --- a/pylib/gfxprim/generators/core/gen_blit.py +++ b/pylib/gfxprim/generators/core/gen_blit.py @@ -18,14 +18,14 @@ def gen_blit_same_t(size, size_suffix, header, code): "n/*** Blit preserving type, variant for {{ size_suffix }} ***n" " * Assumes the contexts to be of the right types and sizesn" " * Ignores transformations and clipping */nn" - "void GP_Blit_{{ size_suffix }}(const GP_Context *c1, int x1, int y1, int w, int h,n" - " GP_Context *c2, int x2, int y2);n", + "void GP_Blit_{{ size_suffix }}(const GP_Context *c1, GP_Coord x1, GP_Coord y1, GP_Size w, GP_Size h,n" + " GP_Context *c2, GP_Coord x2, GP_Coord y2);n", size=size, size_suffix=size_suffix)
code.rbody( "n/*** Blit preservimg type, variant for {{ size_suffix }} ***/n" - "void GP_Blit_{{ size_suffix }}(const GP_Context *c1, int x1, int y1, int w, int h,n" - " GP_Context *c2, int x2, int y2)n" + "void GP_Blit_{{ size_suffix }}(const GP_Context *c1, GP_Coord x1, GP_Coord y1, GP_Size w, GP_Size h,n" + " GP_Context *c2, GP_Coord x2, GP_Coord y2)n" "{n" " if (unlikely(w == 0 || h == 0)) return;nn" " /* Special case - copy whole line-block with one memcpy() */n" @@ -38,7 +38,7 @@ def gen_blit_same_t(size, size_suffix, header, code): " }nn" "{% if size>=8 %}" " /* General case - memcpy() each horizontal line */n" - " for (int i=0; i<h; i++)n" + " for (GP_Size i = 0; i < h; i++)n" " memcpy(GP_PIXEL_ADDR_{{ size_suffix }}(c2, x2, y2 + i), n" " GP_PIXEL_ADDR_{{ size_suffix }}(c1, x2, y2 + i),n" " {{ size/8 }} * w);n" @@ -57,7 +57,7 @@ def gen_blit_same_t(size, size_suffix, header, code): " uint8_t *p2 = GP_PIXEL_ADDR_{{ size_suffix }}(c2, x2, y2);n" " uint8_t *end_p1 = GP_PIXEL_ADDR_{{ size_suffix }}(c1, x1 + w - 1, y1);n" " uint8_t *end_p2 = GP_PIXEL_ADDR_{{ size_suffix }}(c2, x2 + w - 1, y2);n" - " for (int i = 0; i < h; i++) {n" + " for (GP_Size i = 0; i < h; i++) {n" " if (al1 != 0)n" " GP_SET_BITS(al1, 8-al1, *p2, GP_GET_BITS(al1, 8-al1, *p1));n" " memcpy(p2+(al1!=0), p1+(al1!=0), copy_size);n" @@ -73,19 +73,3 @@ def gen_blit_same_t(size, size_suffix, header, code): "{% endif %}" "}n", size=size, size_suffix=size_suffix)
- -def gen_blit_t(f1, f2, header, code): - "Generate a macro GP_Blit_T1_T2 blitting a rectangle" - "Does not (yet) convert between PAL formats and RGBVA" - allowed_chansets = [ set(list(s)) for s in ['RGB', 'RGBA', 'V', 'VA'] ] - if f1!=f2: - assert(set(f1.chans.keys()) in allowed_chansets) - assert(set(f2.chans.keys()) in allowed_chansets) - - header.rbody( - "n/*** Blit line {{ f1.name }} -> {{ f2.name }} ***n" - " * Assumes the contexts to be of the right types and sizes */nn" - "void GP_Blit_{{ f1.name }}_{{ f2.name }}(const GP_Context *c1, int x1, int y2, int w, int h,n" - " GP_Context *c2, int x2, int y2);n", - f1=f1, f2=f2) - diff --git a/pylib/gfxprim/generators/core/make_GP_Blit.py b/pylib/gfxprim/generators/core/make_GP_Blit.py index 702d2ba..03057b0 100644 --- a/pylib/gfxprim/generators/core/make_GP_Blit.py +++ b/pylib/gfxprim/generators/core/make_GP_Blit.py @@ -21,7 +21,7 @@ def core_GP_Blit_gen(h, c): '#include "GP_Pixel.h"n' '#include "GP.h"n' '#include "GP_Context.h"n' - '#include "GP_Blit.gen.h"n' + '#include "GP_Blit.h"n' )
for bpp in bitsizes:
http://repo.or.cz/w/gfxprim.git/commit/80c8f8ccda4b63c85fa784cb2ebfa61181a81...
commit 80c8f8ccda4b63c85fa784cb2ebfa61181a818a4 Author: Tomas Gavenciak gavento@ucw.cz Date: Sun Jun 12 01:25:24 2011 +0200
Add GP_Size (unsigned int) type
diff --git a/include/core/GP_Context.h b/include/core/GP_Context.h index da344f3..ce85f65 100644 --- a/include/core/GP_Context.h +++ b/include/core/GP_Context.h @@ -35,6 +35,7 @@ /* Integer type for coordinates: x, y, width, height, ... * Should be signed to hold negative values as well. */ typedef int GP_Coord; +typedef unsigned int GP_Size;
/* This structure holds all information needed for drawing into an image. */ typedef struct GP_Context {
http://repo.or.cz/w/gfxprim.git/commit/06fa397a908dd96877573db3df61274cd493e...
commit 06fa397a908dd96877573db3df61274cd493eed4 Author: Tomas Gavenciak gavento@ucw.cz Date: Sun Jun 12 01:09:05 2011 +0200
Extend value scaling to all values 1..8
Requred by RGB565 etc.
diff --git a/pylib/gfxprim/generators/core/make_GP_Convert.py b/pylib/gfxprim/generators/core/make_GP_Convert.py index 8ef43ed..291b383 100644 --- a/pylib/gfxprim/generators/core/make_GP_Convert.py +++ b/pylib/gfxprim/generators/core/make_GP_Convert.py @@ -23,7 +23,7 @@ def core_GP_Pixel_Scale_gen(h): " */n" "#define GP_SCALE_VAL(s1, s2, val) ( GP_SCALE_VAL_##s1##_##s2(val) )nn"
- "{% for s1 in [1, 2, 4, 8] %}{% for s2 in [1, 2, 4, 8] %}" + "{% for s1 in range(1,9) %}{% for s2 in range(1,9) %}" "{% if s2>s1 %}" "#define GP_SCALE_VAL_{{s1}}_{{s2}}(val) ((val) * {{ multcoef(s1, s2) }})n" "{% else %}"
http://repo.or.cz/w/gfxprim.git/commit/21749e191eb8863acaa33bc32d2959f89cc97...
commit 21749e191eb8863acaa33bc32d2959f89cc97d88 Author: Tomas Gavenciak gavento@ucw.cz Date: Sun Jun 12 01:00:16 2011 +0200
Move scaling code generation from Pixel to Convert
diff --git a/include/core/GP_Convert.h b/include/core/GP_Convert.h index c1c44ef..dff93e6 100644 --- a/include/core/GP_Convert.h +++ b/include/core/GP_Convert.h @@ -26,8 +26,9 @@ #include "GP_Common.h" #include "GP_Context.h"
-/* Generated header */ +/* Generated headers */ #include "GP_Convert.gen.h" +#include "GP_Convert_Scale.gen.h"
/* * Generated function to convert RGB888 to any type. diff --git a/include/core/GP_Pixel.h b/include/core/GP_Pixel.h index 7ac0fb7..ec78c04 100644 --- a/include/core/GP_Pixel.h +++ b/include/core/GP_Pixel.h @@ -54,9 +54,8 @@ struct GP_Context;
typedef uint32_t GP_Pixel;
-/* Generated headers */ +/* Generated header */ #include "GP_Pixel.gen.h" -#include "GP_Pixel_Scale.gen.h"
/* * Information about ordering of pixels in byte for 1, 2 and 4 bpp diff --git a/libs/core/Makefile b/libs/core/Makefile index bce6f9d..5bcadca 100644 --- a/libs/core/Makefile +++ b/libs/core/Makefile @@ -1,6 +1,6 @@ TOPDIR=../.. GENSOURCES=GP_Pixel.gen.c GP_Blit.gen.c GP_Convert.gen.c -GENHEADERS=GP_Pixel_Scale.gen.h GP_Blit.gen.h GP_Pixel.gen.h GP_GetPutPixel.gen.h GP_Convert.gen.h +GENHEADERS=GP_Convert_Scale.gen.h GP_Blit.gen.h GP_Pixel.gen.h GP_GetPutPixel.gen.h GP_Convert.gen.h CSOURCES=$(filter-out $(wildcard *.gen.c),$(wildcard *.c)) LIBNAME=core CFLAGS+=-Wno-overflow diff --git a/pylib/gfxprim/generators/core/make_GP_Convert.py b/pylib/gfxprim/generators/core/make_GP_Convert.py index 1800a2c..8ef43ed 100644 --- a/pylib/gfxprim/generators/core/make_GP_Convert.py +++ b/pylib/gfxprim/generators/core/make_GP_Convert.py @@ -3,6 +3,7 @@ # Script generating: # # GP_Convert.gen.c, GP_Convert.gen.h +# GP_Convert_Scale.gen.h # # 2011 - Tomas Gavenciak gavento@ucw.cz # @@ -11,11 +12,29 @@ from gfxprim.generators.generator import * from gfxprim.generators.pixeltype import * from gfxprim.generators.core.gen_convert import *
+@generator(CHeaderGenerator(name = 'GP_Convert_Scale.gen.h'), + descr = 'Fast value scaling macros', + authors = ["2011 - Tomas Gavenciak gavento@ucw.cz"]) +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" + " */n" + "#define GP_SCALE_VAL(s1, s2, val) ( GP_SCALE_VAL_##s1##_##s2(val) )nn" + + "{% for s1 in [1, 2, 4, 8] %}{% for s2 in [1, 2, 4, 8] %}" + "{% if s2>s1 %}" + "#define GP_SCALE_VAL_{{s1}}_{{s2}}(val) ((val) * {{ multcoef(s1, s2) }})n" + "{% else %}" + "#define GP_SCALE_VAL_{{s1}}_{{s2}}(val) ((val) >> {{ s1 - s2 }})n" + "{% endif %}" + "{% endfor %}{% endfor %}", multcoef = lambda s1,s2: hex(sum([1<<i*s1 for i in range(s2/s1)])) + )
@generator(CHeaderGenerator(name = 'GP_Convert.gen.h'), CSourceGenerator(name = 'GP_Convert.gen.c'), - descr = 'Convert PixelType values macros and functionsn' - 'Do not include directly, use GP_Convert.h', + descr = 'Convert PixelType values macros and functions', authors = ["2011 - Tomas Gavenciak gavento@ucw.cz"]) def core_GP_Convert_gen_h(h, c): h.rhead('#include "GP_Common.h"n'); diff --git a/pylib/gfxprim/generators/core/make_GP_Pixel.py b/pylib/gfxprim/generators/core/make_GP_Pixel.py index fc99657..05cc28e 100644 --- a/pylib/gfxprim/generators/core/make_GP_Pixel.py +++ b/pylib/gfxprim/generators/core/make_GP_Pixel.py @@ -3,7 +3,6 @@ # Script generating: # # GP_Pixel.gen.c, GP_Pixel.gen.h -# GP_Pixel_Scale.gen.h # GP_Pixel_Access.gen.h # # 2011 - Tomas Gavenciak gavento@ucw.cz @@ -14,26 +13,6 @@ from gfxprim.generators.pixeltype import * from gfxprim.generators.core.gen_pixeltype import * from gfxprim.generators.core.gen_getputpixel import *
-@generator(CHeaderGenerator(name = 'GP_Pixel_Scale.gen.h'), - descr = 'Fast value scaling macrosnDo not include directly, use GP_Pixel.h', - authors = ["2011 - Tomas Gavenciak gavento@ucw.cz"]) -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" - " */n" - "#define GP_SCALE_VAL(s1, s2, val) ( GP_SCALE_VAL_##s1##_##s2(val) )nn" - - "{% for s1 in [1, 2, 4, 8] %}{% for s2 in [1, 2, 4, 8] %}" - "{% if s2>s1 %}" - "#define GP_SCALE_VAL_{{s1}}_{{s2}}(val) ((val) * {{ multcoef(s1, s2) }})n" - "{% else %}" - "#define GP_SCALE_VAL_{{s1}}_{{s2}}(val) ((val) >> {{ s1 - s2 }})n" - "{% endif %}" - "{% endfor %}{% endfor %}", multcoef = lambda s1,s2: hex(sum([1<<i*s1 for i in range(s2/s1)])) - ) - @generator(CHeaderGenerator(name='GP_Pixel.gen.h'), CSourceGenerator(name='GP_Pixel.gen.c'), descr = 'Pixel type definitions and functionsnDo not include directly, use GP_Pixel.h',
http://repo.or.cz/w/gfxprim.git/commit/4b24345dd60ebbc38dccca753476ebf32cb72...
commit 4b24345dd60ebbc38dccca753476ebf32cb72df0 Author: Tomas Gavenciak gavento@ucw.cz Date: Sun Jun 12 00:56:36 2011 +0200
Write up more conversion code, almost complete
diff --git a/include/core/GP_Convert.h b/include/core/GP_Convert.h index bf1580b..c1c44ef 100644 --- a/include/core/GP_Convert.h +++ b/include/core/GP_Convert.h @@ -26,13 +26,40 @@ #include "GP_Common.h" #include "GP_Context.h"
+/* Generated header */ +#include "GP_Convert.gen.h" + +/* + * Generated function to convert RGB888 to any type. + * Does not work with palette types. + */ +GP_Pixel GP_RGB888ToPixel(GP_Pixel pixel, GP_PixelType type); + +/* + * Generated function to convert RGBA8888 to any type. + * Does not work with palette types. + */ +GP_Pixel GP_RGBA8888ToPixel(GP_Pixel pixel, GP_PixelType type); + +/* + * Generated function to convert to RGB888 from any type. + * Does not work with palette types. + */ +GP_Pixel GP_PixelToRGB888(GP_Pixel pixel, GP_PixelType type); + +/* + * Generated function to convert to RGBA8888 from any type. + * Does not work with palette types. + */ +GP_Pixel GP_PixelToRGBA8888(GP_Pixel pixel, GP_PixelType type); + /* * Converts a color specified by its R, G, B components to a specified type. */ static inline GP_Pixel GP_RGBToPixel(uint8_t r, uint8_t g, uint8_t b, GP_PixelType type) { GP_Pixel p = GP_Pixel_CREATE_RGB888(r, g, b); - return GP_RGB888ToType(p, type); + return GP_RGB888ToPixel(p, type); }
/* @@ -41,7 +68,7 @@ static inline GP_Pixel GP_RGBToPixel(uint8_t r, uint8_t g, uint8_t b, GP_PixelTy static inline GP_Pixel GP_RGBAToPixel(uint8_t r, uint8_t g, uint8_t b, uint8_t a, GP_PixelType type) { GP_Pixel p = GP_Pixel_CREATE_RGBA8888(r, g, b, a); - return GP_RGBA8888ToType(p, type); + return GP_RGBA8888ToPixel(p, type); }
/* @@ -55,27 +82,29 @@ static inline GP_Pixel GP_RGBToContextPixel(uint8_t r, uint8_t g, uint8_t b, }
/* - * Generated function to convert RGB888 to any type. - * Does not work with palette types. - */ -GP_Pixel GP_RGB888ToPixel(GP_Pixel pixel, GP_PixelType type); - -/* - * Generated function to convert RGBA8888 to any type. - * Does not work with palette types. + * Converts a color specified by its R, G, B, A components to a pixel value + * compatible with the specified context. */ -GP_Pixel GP_RGBA8888ToPixel(GP_Pixel pixel, GP_PixelType type); +static inline GP_Pixel GP_RGBAToContextPixel(uint8_t r, uint8_t g, uint8_t b, uint8_t a, const GP_Context *context) +{ + return GP_RGBAToPixel(r, g, b, a, context->pixel_type); +}
/* - * Generated function to convert to RGB888 from any type. - * Does not work with palette types. + * Convert between any pixel types (excl. palette types) via RGBA8888 */ -GP_Pixel GP_PixelToRGB888(GP_Pixel pixel, GP_PixelType type); - +static inline GP_Pixel GP_ConvertPixel(GP_Pixel pixel, GP_PixelType from, GP_PixelType to) +{ + return GP_RGBA8888ToPixel(GP_PixelToRGBA8888(from, pixel), to); +} + /* - * Generated function to convert to RGBA8888 from any type. - * Does not work with palette types. + * Convert between pixel types of given contexts (excl. palette types) via RGBA8888. + * */ -GP_Pixel GP_PixelToRGBA8888(GP_Pixel pixel, GP_PixelType type); +static inline GP_Pixel GP_ConvertContextPixel(GP_Pixel pixel, const GP_Context *from, const GP_Context *to) +{ + return GP_RGBA8888ToPixel(GP_PixelToRGBA8888(from->pixel_type, pixel), to->pixel_type); +}
#endif /* CORE_GP_CONVERT_H */ diff --git a/pylib/gfxprim/generators/core/gen_convert.py b/pylib/gfxprim/generators/core/gen_convert.py index a136649..84c2b69 100644 --- a/pylib/gfxprim/generators/core/gen_convert.py +++ b/pylib/gfxprim/generators/core/gen_convert.py @@ -28,10 +28,10 @@ def gen_fixedtype_to_type(fixedtype, header, code): "{% endif %}" "{% endfor %}" " default:n" - " GP_ABORT("Unknown PixelType %ld", type);n" + " GP_ABORT("Unknown PixelType %ud", type);n" " }n" " return p;n" - "}n", f=fixedtype, types=pixeltypes.values()) + "}nn", f=fixedtype, types=pixeltypes.values())
def gen_type_to_fixedtype(fixedtype, header, code): "Generate functions converting to a fixed PixelType from any other" @@ -57,10 +57,10 @@ def gen_type_to_fixedtype(fixedtype, header, code): "{% endif %}" "{% endfor %}" " default:n" - " GP_ABORT("Unknown PixelType %ld", type);n" + " GP_ABORT("Unknown PixelType %u", type);n" " }n" " return p;n" - "}n", f=fixedtype, types=pixeltypes.values()) + "}nn", f=fixedtype, types=pixeltypes.values())
def gen_convert_to(f1, f2, header, code): "Generate a macro converting from f1 to f2" @@ -80,25 +80,25 @@ def gen_convert_to(f1, f2, header, code):
# case 1: just copy a channel "{%- if c2[0] in f1.chans.keys() %}{% set c1 = f1.chans[c2[0]] %}" - " /* {{ c2[0] }}:={{ c1[0] }} */ GP_SET_BITS({{c2[1]}}+o2, " - " GP_SCALE_VAL_{{c1[2]}}_{{c2[2]}}(GP_GET_BITS({{c1[1]}}+o1, {{c1[2]}}, p1)), p2); " + " /* {{ c2[0] }}:={{ c1[0] }} */ GP_SET_BITS({{c2[1]}}+o2, {{c2[2]}}, p2, " + " GP_SCALE_VAL_{{c1[2]}}_{{c2[2]}}(GP_GET_BITS({{c1[1]}}+o1, {{c1[2]}}, p1))); "
# case 2: set A to full opacity (not present in source) "{% elif c2[0]=='A' %}" - " /* A:={{ hmask(c2[2]) }} */GP_SET_BITS({{c2[1]}}+o2, {{ hmask(c2[2]) }}, p2); " + " /* A:={{ hmask(c2[2]) }} */GP_SET_BITS({{c2[1]}}+o2, {{c2[2]}}, p2, {{ hmask(c2[2]) }}); "
# case 3: calculate V as average of RGB "{% elif c2[0]=='V' and set('RGB').issubset(set(f1.chans.keys())) %}" - " /* V:=RGB_avg */ GP_SET_BITS({{c2[1]}}+o2, ( " + " /* V:=RGB_avg */ GP_SET_BITS({{c2[1]}}+o2, {{c2[2]}}, p2, ( " "{% for c1 in [f1.chans['R'], f1.chans['G'], f1.chans['B']] %}" - " /* {{c1[0]}} */ GP_SCALE_VAL_{{c1[2]}}_{{c2[2]}}(GP_GET_BITS({{c1[1]}}+o1, {{c1[2]}}, p1), p2) + " + " /* {{c1[0]}} */ GP_SCALE_VAL_{{c1[2]}}_{{c2[2]}}(GP_GET_BITS({{c1[1]}}+o1, {{c1[2]}}, p1)) + " "{% endfor %}" " 0)/3); "
#- case 4: set each RGB to V "{% elif c2[0] in 'RGB' and 'V' in f1.chans.keys() %}{% set c1 = f1.chans['V'] %}" - " /* {{ c2[0] }}:=V */ GP_SET_BITS({{c2[1]}}+o2, " - " GP_SCALE_VAL_{{c1[2]}}_{{c2[2]}}(GP_GET_BITS({{c1[1]}}+o1, {{c1[2]}}, p1)), p2); " + " /* {{ c2[0] }}:=V */ GP_SET_BITS({{c2[1]}}+o2, {{c2[2]}}, p2, " + " GP_SCALE_VAL_{{c1[2]}}_{{c2[2]}}(GP_GET_BITS({{c1[1]}}+o1, {{c1[2]}}, p1))); "
# invalid mapping (there should be none, but who knows ...) "{% else %} {{ raise(Error('channel conversion' +f1.name+ ' to ' +f2.name+ ' not supported')) }}" @@ -111,6 +111,6 @@ def gen_convert_to(f1, f2, header, code): # add version without offsets "/* a version without offsets */n" "#define GP_Pixel_{{ f1.name }}_TO_{{ f2.name }}(p1, p2) " - "(GP_Pixel_{{ f1.name }}_TO_{{ f2.name }}_OFFSET(p1, 0, p2, 0))n", + "GP_Pixel_{{ f1.name }}_TO_{{ f2.name }}_OFFSET(p1, 0, p2, 0)n", f1=f1, f2=f2, hmask=hmask, set=set)
diff --git a/pylib/gfxprim/generators/core/make_GP_Convert.py b/pylib/gfxprim/generators/core/make_GP_Convert.py index e8c7360..1800a2c 100644 --- a/pylib/gfxprim/generators/core/make_GP_Convert.py +++ b/pylib/gfxprim/generators/core/make_GP_Convert.py @@ -22,8 +22,7 @@ def core_GP_Convert_gen_h(h, c): h.rhead('#include "GP_Context.h"n'); h.rhead('#include "GP_Pixel.h"nn');
- h.rhead('#include "GP_Common.h"n'); - c.rhead('#include "GP_Pixel.h"nn'); + c.rhead('#include "GP_Convert.h"nn');
## two base types for conversions for bt in [pixeltypes['RGB888'], pixeltypes['RGBA8888']]:
http://repo.or.cz/w/gfxprim.git/commit/47c5f5f4b32da3d004ffa2c037857c8323ea1...
commit 47c5f5f4b32da3d004ffa2c037857c8323ea1a1f Author: Tomas Gavenciak gavento@ucw.cz Date: Sun Jun 12 00:54:55 2011 +0200
Rename pixel_access -> getputpixel in gener. libs as well
diff --git a/pylib/gfxprim/generators/core/gen_pixel_access.py b/pylib/gfxprim/generators/core/gen_getputpixel.py similarity index 100% rename from pylib/gfxprim/generators/core/gen_pixel_access.py rename to pylib/gfxprim/generators/core/gen_getputpixel.py diff --git a/pylib/gfxprim/generators/core/make_GP_Pixel.py b/pylib/gfxprim/generators/core/make_GP_Pixel.py index 0ade754..fc99657 100644 --- a/pylib/gfxprim/generators/core/make_GP_Pixel.py +++ b/pylib/gfxprim/generators/core/make_GP_Pixel.py @@ -12,7 +12,7 @@ from gfxprim.generators.generator import * from gfxprim.generators.pixeltype import * from gfxprim.generators.core.gen_pixeltype import * -from gfxprim.generators.core.gen_pixel_access import * +from gfxprim.generators.core.gen_getputpixel import *
@generator(CHeaderGenerator(name = 'GP_Pixel_Scale.gen.h'), descr = 'Fast value scaling macrosnDo not include directly, use GP_Pixel.h',
http://repo.or.cz/w/gfxprim.git/commit/c4ac868f69649ea94eab4a650b49ca25dcd2c...
commit c4ac868f69649ea94eab4a650b49ca25dcd2c490 Author: Tomas Gavenciak gavento@ucw.cz Date: Sun Jun 12 00:20:00 2011 +0200
Fixed Makefile (gen files), disable overflow warning
diff --git a/libs/core/Makefile b/libs/core/Makefile index c3692df..bce6f9d 100644 --- a/libs/core/Makefile +++ b/libs/core/Makefile @@ -1,8 +1,9 @@ TOPDIR=../.. -GENSOURCES=GP_Pixel.gen.c GP_Blit.gen.c GP_Convert.gen.c GP_Convert.gen.h -GENHEADERS=GP_Pixel_Scale.gen.h GP_Blit.gen.h GP_Pixel.gen.h GP_GetPutPixel.gen.h +GENSOURCES=GP_Pixel.gen.c GP_Blit.gen.c GP_Convert.gen.c +GENHEADERS=GP_Pixel_Scale.gen.h GP_Blit.gen.h GP_Pixel.gen.h GP_GetPutPixel.gen.h GP_Convert.gen.h CSOURCES=$(filter-out $(wildcard *.gen.c),$(wildcard *.c)) LIBNAME=core +CFLAGS+=-Wno-overflow
include $(TOPDIR)/gen.mk include $(TOPDIR)/include.mk
http://repo.or.cz/w/gfxprim.git/commit/51e969cd103ec6546ec91af744157338d3528...
commit 51e969cd103ec6546ec91af744157338d352896c Author: Tomas Gavenciak gavento@ucw.cz Date: Sun Jun 12 00:15:09 2011 +0200
Remove annoying readout in pixeltype loading
replaced by warning in case nothing is loaded
diff --git a/pylib/gfxprim/generators/pixeltype.py b/pylib/gfxprim/generators/pixeltype.py index e43ffce..92586ab 100644 --- a/pylib/gfxprim/generators/pixeltype.py +++ b/pylib/gfxprim/generators/pixeltype.py @@ -104,11 +104,7 @@ def load_pixeltypes(defs_file = None): if not defs_file: path = os.path.dirname(os.path.abspath(__file__)) defs_file = os.path.join(path, '..', '..', 'pixeltypes.py') - sys.stderr.write("Opening PixelType defs file '" + defs_file + "'n") - l1 = len(pixeltypes) execfile(defs_file) - l2 = len(pixeltypes) - sys.stderr.write("Read %d PixelTypes, now %d totaln" % (l2 - l1, l2))
def __init__(): "Initialize PixelType UNKNOWN.n" @@ -116,6 +112,9 @@ def __init__(): if 0 not in pixeltypes: PixelType("UNKNOWN", 0, [], bit_endian=bit_endians[0], number=0) load_pixeltypes() + # check if some types were loaded + if len(pixeltypes) <= 1: + sys.stderr.write("WARNING: no PixelTypes were loaded.")
__init__()
http://repo.or.cz/w/gfxprim.git/commit/f11293be8118c9707b268f55ba49dc6ea8b11...
commit f11293be8118c9707b268f55ba49dc6ea8b111ff Author: Tomas Gavenciak gavento@ucw.cz Date: Sun Jun 12 00:00:41 2011 +0200
Implemented various PixelType conversions
diff --git a/include/core/GP_Convert.h b/include/core/GP_Convert.h new file mode 100644 index 0000000..bf1580b --- /dev/null +++ b/include/core/GP_Convert.h @@ -0,0 +1,81 @@ +/***************************************************************************** + * 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) 2011 Tomas Gavenciak gavento@ucw.cz * + * * + *****************************************************************************/ + +#ifndef CORE_GP_CONVERT_H +#define CORE_GP_CONVERT_H + +#include "GP_Common.h" +#include "GP_Context.h" + +/* + * Converts a color specified by its R, G, B components to a specified type. + */ +static inline GP_Pixel GP_RGBToPixel(uint8_t r, uint8_t g, uint8_t b, GP_PixelType type) +{ + GP_Pixel p = GP_Pixel_CREATE_RGB888(r, g, b); + return GP_RGB888ToType(p, type); +} + +/* + * Converts a color specified by its R, G, B, A components to a specified type. + */ +static inline GP_Pixel GP_RGBAToPixel(uint8_t r, uint8_t g, uint8_t b, uint8_t a, GP_PixelType type) +{ + GP_Pixel p = GP_Pixel_CREATE_RGBA8888(r, g, b, a); + return GP_RGBA8888ToType(p, type); +} + +/* + * Converts a color specified by its R, G, B components to a pixel value + * compatible with the specified context. + */ +static inline GP_Pixel GP_RGBToContextPixel(uint8_t r, uint8_t g, uint8_t b, + const GP_Context *context) +{ + return GP_RGBToPixel(r, g, b, context->pixel_type); +} + +/* + * Generated function to convert RGB888 to any type. + * Does not work with palette types. + */ +GP_Pixel GP_RGB888ToPixel(GP_Pixel pixel, GP_PixelType type); + +/* + * Generated function to convert RGBA8888 to any type. + * Does not work with palette types. + */ +GP_Pixel GP_RGBA8888ToPixel(GP_Pixel pixel, GP_PixelType type); + +/* + * Generated function to convert to RGB888 from any type. + * Does not work with palette types. + */ +GP_Pixel GP_PixelToRGB888(GP_Pixel pixel, GP_PixelType type); + +/* + * Generated function to convert to RGBA8888 from any type. + * Does not work with palette types. + */ +GP_Pixel GP_PixelToRGBA8888(GP_Pixel pixel, GP_PixelType type); + +#endif /* CORE_GP_CONVERT_H */ diff --git a/include/core/GP_Pixel.h b/include/core/GP_Pixel.h index a1469e8..7ac0fb7 100644 --- a/include/core/GP_Pixel.h +++ b/include/core/GP_Pixel.h @@ -21,6 +21,8 @@ * * * Copyright (C) 2009-2010 Cyril Hrubis metan@ucw.cz * * * + * Copyright (C) 2011 Tomas Gavenciak gavento@ucw.cz * + * * *****************************************************************************/
#ifndef GP_PIXEL_H @@ -135,38 +137,4 @@ static inline uint32_t GP_PixelSize(GP_PixelType type) return GP_PixelTypes[type].size; }
- -/* Below -- TODO sync with new pixel type */ - -/* - * Returns GP_PixelType to GP_ColorType mapping. - */ -//GP_ColorType GP_PixelTypeToColorType(GP_PixelType type); - -/* - * Converts a color to the specified pixel type. - */ -//GP_RetCode GP_ColorToPixelType(GP_PixelType pixel_type, GP_Color color, GP_Pixel *pixel); - -/* - * Converts a color to a pixel value suitable for the specified context. - */ -//GP_RetCode GP_ColorToPixel(struct GP_Context *context, GP_Color color, GP_Pixel *pixel); - -/* - * - */ -//GP_RetCode GP_ColorNameToPixel(struct GP_Context *context, GP_ColorName name, GP_Pixel *pixel); - -/* - * Converts a color name to the specified pixel type. - */ -//GP_RetCode GP_ColorNameToPixelType(GP_PixelType pixel_type, GP_ColorName name, GP_Pixel *pixel); - -/* - * Converts a color specified by its R, G, B components to a pixel value - * compatible with the specified context. - */ -GP_RetCode GP_RGBToPixel(struct GP_Context *context, uint8_t r, uint8_t g, uint8_t b, GP_Pixel *pixel); - #endif /* GP_PIXEL_H */ diff --git a/libs/core/Makefile b/libs/core/Makefile index 9ed6c65..c3692df 100644 --- a/libs/core/Makefile +++ b/libs/core/Makefile @@ -1,5 +1,5 @@ TOPDIR=../.. -GENSOURCES=GP_Pixel.gen.c GP_Blit.gen.c +GENSOURCES=GP_Pixel.gen.c GP_Blit.gen.c GP_Convert.gen.c GP_Convert.gen.h GENHEADERS=GP_Pixel_Scale.gen.h GP_Blit.gen.h GP_Pixel.gen.h GP_GetPutPixel.gen.h CSOURCES=$(filter-out $(wildcard *.gen.c),$(wildcard *.c)) LIBNAME=core diff --git a/pylib/gfxprim/generators/core/gen_convert.py b/pylib/gfxprim/generators/core/gen_convert.py new file mode 100644 index 0000000..a136649 --- /dev/null +++ b/pylib/gfxprim/generators/core/gen_convert.py @@ -0,0 +1,116 @@ +# Module generating C source and headers for various PixelType conversions +# 2011 - Tomas Gavenciak gavento@ucw.cz + +from gfxprim.generators.pixeltype import pixeltypes, channels +from gfxprim.generators.utils import hmask + +def gen_fixedtype_to_type(fixedtype, header, code): + "Generate functions converting a fixed PixelType to any other" + "Does not work on palette types at all (yet)" + code.rbody( + "GP_Pixel GP_{{ f.name }}ToPixel(GP_Pixel pixel, GP_PixelType type)n" + "{n" + " GP_Pixel p = 0;n" + " switch(type) {n" + "{% for tf in types %}" + "{% if tf.number == 0 %}" + " case GP_PIXEL_UNKNOWN:n" + " GP_ABORT("Cannot convert to GP_PIXEL_UNKNOWN");n" + " break;n" + "{% elif tf.is_palette() %}" + " case GP_PIXEL_{{ tf.name }}:n" + " GP_ABORT("Cannot convert to palette type {{ tf.name }}");n" + " break;n" + "{% else %}" + " case GP_PIXEL_{{ tf.name }}:n" + " GP_Pixel_{{ f.name }}_TO_{{ tf.name }}(pixel, p);n" + " break;n" + "{% endif %}" + "{% endfor %}" + " default:n" + " GP_ABORT("Unknown PixelType %ld", type);n" + " }n" + " return p;n" + "}n", f=fixedtype, types=pixeltypes.values()) + +def gen_type_to_fixedtype(fixedtype, header, code): + "Generate functions converting to a fixed PixelType from any other" + "Does not work on palette types at all (yet)" + code.rbody( + "GP_Pixel GP_PixelTo{{ f.name }}(GP_Pixel pixel, GP_PixelType type)n" + "{n" + " GP_Pixel p = 0;n" + " switch(type) {n" + "{% for sf in types %}" + "{% if sf.number == 0 %}" + " case GP_PIXEL_UNKNOWN:n" + " GP_ABORT("Cannot convert from GP_PIXEL_UNKNOWN");n" + " break;n" + "{% elif sf.is_palette() %}" + " case GP_PIXEL_{{ sf.name }}:n" + " GP_ABORT("Cannot convert from palette type {{ sf.name }} (yet)");n" + " break;n" + "{% else %}" + " case GP_PIXEL_{{ sf.name }}:n" + " GP_Pixel_{{ sf.name }}_TO_{{ f.name }}(pixel, p);n" + " break;n" + "{% endif %}" + "{% endfor %}" + " default:n" + " GP_ABORT("Unknown PixelType %ld", type);n" + " }n" + " return p;n" + "}n", f=fixedtype, types=pixeltypes.values()) + +def gen_convert_to(f1, f2, header, code): + "Generate a macro converting from f1 to f2" + "This function supports only RGBVA types (no palettes" + allowed_chansets = [ set(list(s)) for s in ['RGB', 'RGBA', 'V', 'VA'] ] + assert(set(f1.chans.keys()) in allowed_chansets) + assert(set(f2.chans.keys()) in allowed_chansets) + + header.rbody( + "n/*** {{ f1.name }} -> {{ f2.name }} ***n" + " * macro storing p1 ({{ f1.name }} at bit-offset o1) in p2 ({{ f2.name }} at bit-offset o2),n" + " * the relevant part of p2 is assumed to be clear (zero) */nn" + "#define GP_Pixel_{{ f1.name }}_TO_{{ f2.name }}_OFFSET(p1, o1, p2, o2) do { " + + ## set each of <TARGET> channels + "{% for c2 in f2.chanslist %}" + + # case 1: just copy a channel + "{%- if c2[0] in f1.chans.keys() %}{% set c1 = f1.chans[c2[0]] %}" + " /* {{ c2[0] }}:={{ c1[0] }} */ GP_SET_BITS({{c2[1]}}+o2, " + " GP_SCALE_VAL_{{c1[2]}}_{{c2[2]}}(GP_GET_BITS({{c1[1]}}+o1, {{c1[2]}}, p1)), p2); " + + # case 2: set A to full opacity (not present in source) + "{% elif c2[0]=='A' %}" + " /* A:={{ hmask(c2[2]) }} */GP_SET_BITS({{c2[1]}}+o2, {{ hmask(c2[2]) }}, p2); " + + # case 3: calculate V as average of RGB + "{% elif c2[0]=='V' and set('RGB').issubset(set(f1.chans.keys())) %}" + " /* V:=RGB_avg */ GP_SET_BITS({{c2[1]}}+o2, ( " + "{% for c1 in [f1.chans['R'], f1.chans['G'], f1.chans['B']] %}" + " /* {{c1[0]}} */ GP_SCALE_VAL_{{c1[2]}}_{{c2[2]}}(GP_GET_BITS({{c1[1]}}+o1, {{c1[2]}}, p1), p2) + " + "{% endfor %}" + " 0)/3); " + + #- case 4: set each RGB to V + "{% elif c2[0] in 'RGB' and 'V' in f1.chans.keys() %}{% set c1 = f1.chans['V'] %}" + " /* {{ c2[0] }}:=V */ GP_SET_BITS({{c2[1]}}+o2, " + " GP_SCALE_VAL_{{c1[2]}}_{{c2[2]}}(GP_GET_BITS({{c1[1]}}+o1, {{c1[2]}}, p1)), p2); " + + # invalid mapping (there should be none, but who knows ...) + "{% else %} {{ raise(Error('channel conversion' +f1.name+ ' to ' +f2.name+ ' not supported')) }}" + + # end of the loop + "{% endif %}" + "{% endfor %}" + "} while (0)nn" + + # add version without offsets + "/* a version without offsets */n" + "#define GP_Pixel_{{ f1.name }}_TO_{{ f2.name }}(p1, p2) " + "(GP_Pixel_{{ f1.name }}_TO_{{ f2.name }}_OFFSET(p1, 0, p2, 0))n", + f1=f1, f2=f2, hmask=hmask, set=set) + diff --git a/pylib/gfxprim/generators/core/gen_pixeltype.py b/pylib/gfxprim/generators/core/gen_pixeltype.py index ea3ae20..ba25a20 100644 --- a/pylib/gfxprim/generators/core/gen_pixeltype.py +++ b/pylib/gfxprim/generators/core/gen_pixeltype.py @@ -1,12 +1,6 @@ # Module generating C source and headers for various PixelTypes # 2011 - Tomas Gavenciak gavento@ucw.cz
-""" -The functions gen_* generate both source and header. -Such functions accept (and then extend) two list of strins. -These should be later joined with "" or " ". -""" - from gfxprim.generators.pixeltype import pixeltypes, channels from gfxprim.generators.utils import j2render as r, hmask
@@ -89,60 +83,19 @@ def gen_get_chs(ptype, header, code): header.rbody( "/* macros to get channels of pixel type {{ f.name }} */n" "{% for c in f.chanslist %}" - "#define GP_Pixel_GET_{{ c[0] }}_{{ f.name }}(p) (GP_GET_BITS({{ c[1] }}, {{ c[2] }}, (p)))n" + "#define GP_Pixel_GET_{{ c[0] }}_{{ f.name }}(p) (GP_GET_BITS({{ c[1] }}, {{ c[2] }}, (p)))n" "{% endfor %}", f=ptype)
-def gen_convert_to(f1, f2, header, code): - "Generate a macro converting from f1 to f2" - "This function supports only RGBVA types (no palettes" - allowed_chansets = [ set(list(s)) for s in ['RGB', 'RGBA', 'V', 'VA'] ] - assert(set(f1.chans.keys()) in allowed_chansets) - assert(set(f2.chans.keys()) in allowed_chansets) - +def gen_create(ptype, header, code): + "Generate GP_Pixel_CREATE_<TYPE> macros" header.rbody( - "n/*** {{ f1.name }} -> {{ f2.name }} ***n" - " * macro storing p1 ({{ f1.name }} at bit-offset o1) in p2 ({{ f2.name }} at bit-offset o2),n" - " * the relevant part of p2 is assumed to be clear (zero) */nn" - "#define GP_Pixel_{{ f1.name }}_TO_{{ f2.name }}_OFFSET(p1, o1, p2, o2) do { " - - ## set each of <TARGET> channels - "{% for c2 in f2.chanslist %}" - - # case 1: just copy a channel - "{%- if c2[0] in f1.chans.keys() %}{% set c1 = f1.chans[c2[0]] %}" - " /* {{ c2[0] }}:={{ c1[0] }} */ GP_SET_BITS({{c2[1]}}+o2, " - " GP_SCALE_VAL_{{c1[2]}}_{{c2[2]}}(GP_GET_BITS({{c1[1]}}+o1, {{c1[2]}}, p1)), p2); " - - # case 2: set A to full opacity (not present in source) - "{% elif c2[0]=='A' %}" - " /* A:={{ hmask(c2[2]) }} */GP_SET_BITS({{c2[1]}}+o2, {{ hmask(c2[2]) }}, p2); " - - # case 3: calculate V as average of RGB - "{% elif c2[0]=='V' and set('RGB').issubset(set(f1.chans.keys())) %}" - " /* V:=RGB_avg */ GP_SET_BITS({{c2[1]}}+o2, ( " - "{% for c1 in [f1.chans['R'], f1.chans['G'], f1.chans['B']] %}" - " /* {{c1[0]}} */ GP_SCALE_VAL_{{c1[2]}}_{{c2[2]}}(GP_GET_BITS({{c1[1]}}+o1, {{c1[2]}}, p1), p2) + " - "{% endfor %}" - " 0)/3); " - - #- case 4: set each RGB to V - "{% elif c2[0] in 'RGB' and 'V' in f1.chans.keys() %}{% set c1 = f1.chans['V'] %}" - " /* {{ c2[0] }}:=V */ GP_SET_BITS({{c2[1]}}+o2, " - " GP_SCALE_VAL_{{c1[2]}}_{{c2[2]}}(GP_GET_BITS({{c1[1]}}+o1, {{c1[2]}}, p1)), p2); " - - # invalid mapping (there should be none, but who knows ...) - "{% else %} {{ raise(Error('channel conversion' +f1.name+ ' to ' +f2.name+ ' not supported')) }}" - - # end of the loop - "{% endif %}" - "{% endfor %}" - "} while (0)nn" - - # add version without offsets - "/* a version without offsets */n" - "#define GP_Pixel_{{ f1.name }}_TO_{{ f2.name }}(p1, p2) " - "(GP_Pixel_{{ f1.name }}_TO_{{ f2.name }}_OFFSET(p1, 0, p2, 0))n", - f1=f1, f2=f2, hmask=hmask, set=set) + "/* macros to create GP_Pixel of pixel type {{ f.name }} directly from given values.n" + " * The values are NOT clipped to actual value ranges.*/n" + "#define GP_Pixel_CREATE_{{ f.name }}({{ args }}) (0 " + "{% for c in f.chanslist %}" + " + (({{ c[0] }}) << {{ c[1] }}) " + "{% endfor %}" + " )n", f=ptype, args=', '.join([c[0] for c in ptype.chanslist]))
def gen_get_pixel_addr(ptype, header, code): "Generate GP_PIXEL_ADDR_<TYPE> and _OFFSET_<TYPE> macros" diff --git a/pylib/gfxprim/generators/core/make_GP_Convert.py b/pylib/gfxprim/generators/core/make_GP_Convert.py new file mode 100644 index 0000000..e8c7360 --- /dev/null +++ b/pylib/gfxprim/generators/core/make_GP_Convert.py @@ -0,0 +1,41 @@ +#!/usr/bin/python +# +# Script generating: +# +# GP_Convert.gen.c, GP_Convert.gen.h +# +# 2011 - Tomas Gavenciak gavento@ucw.cz +# + +from gfxprim.generators.generator import * +from gfxprim.generators.pixeltype import * +from gfxprim.generators.core.gen_convert import * + + +@generator(CHeaderGenerator(name = 'GP_Convert.gen.h'), + CSourceGenerator(name = 'GP_Convert.gen.c'), + descr = 'Convert PixelType values macros and functionsn' + 'Do not include directly, use GP_Convert.h', + authors = ["2011 - Tomas Gavenciak gavento@ucw.cz"]) +def core_GP_Convert_gen_h(h, c): + h.rhead('#include "GP_Common.h"n'); + h.rhead('#include "GP_Context.h"n'); + h.rhead('#include "GP_Pixel.h"nn'); + + h.rhead('#include "GP_Common.h"n'); + c.rhead('#include "GP_Pixel.h"nn'); + + ## two base types for conversions + for bt in [pixeltypes['RGB888'], pixeltypes['RGBA8888']]: + gen_fixedtype_to_type(bt, h, c) + gen_type_to_fixedtype(bt, h, c) + ## Conversion macros + for t in pixeltypes.values(): + if not t.is_palette() and t.number != 0: + gen_convert_to(t, bt, h, c) + gen_convert_to(bt, t, h, c) + + ## Just experimental conversion macros + gen_convert_to(pixeltypes['RGB565'], pixeltypes['RGBA8888'], h, c) + gen_convert_to(pixeltypes['RGBA8888'], pixeltypes['V2'], h, c) + gen_convert_to(pixeltypes['VA12'], pixeltypes['RGBA8888'], h, c) diff --git a/pylib/gfxprim/generators/core/make_GP_Pixel.py b/pylib/gfxprim/generators/core/make_GP_Pixel.py index 21cb252..0ade754 100644 --- a/pylib/gfxprim/generators/core/make_GP_Pixel.py +++ b/pylib/gfxprim/generators/core/make_GP_Pixel.py @@ -60,11 +60,7 @@ def core_GP_Pixel_gen(h, c): gen_print(t, h, c) gen_get_chs(t, h, c) gen_get_pixel_addr(t, h, c) - - ## Conversion macros - gen_convert_to(pixeltypes['RGB565'], pixeltypes['RGBA8888'], h, c) - gen_convert_to(pixeltypes['RGBA8888'], pixeltypes['V2'], h, c) - gen_convert_to(pixeltypes['VA12'], pixeltypes['RGBA8888'], h, c) + gen_create(t, h, c)
@generator(CHeaderGenerator(name = 'GP_GetPutPixel.gen.h'), diff --git a/pylib/gfxprim/generators/pixeltype.py b/pylib/gfxprim/generators/pixeltype.py index 384930d..e43ffce 100644 --- a/pylib/gfxprim/generators/pixeltype.py +++ b/pylib/gfxprim/generators/pixeltype.py @@ -91,6 +91,9 @@ class PixelType(object): def __str__(self): return "<PixelType " + self.name + ">"
+ def is_palette(self): + return ('P' in self.chans) + def load_pixeltypes(defs_file = None): "Initialize pixeltypes by loading the defs file.n" "Looks for the file by parameter, env['PIXELTYPE_DEFS'] and " diff --git a/pylib/gfxprim/generators/utils.py b/pylib/gfxprim/generators/utils.py index 3ddc7ad..fe5abb4 100644 --- a/pylib/gfxprim/generators/utils.py +++ b/pylib/gfxprim/generators/utils.py @@ -19,6 +19,7 @@ def load_generators(): import gfxprim.generators.make_collected_tests import gfxprim.generators.core.make_GP_Pixel import gfxprim.generators.core.make_GP_Blit + import gfxprim.generators.core.make_GP_Convert pass
def generate_file(fname):
http://repo.or.cz/w/gfxprim.git/commit/6aa9b93dc730b452effb253df5a051bc79169...
commit 6aa9b93dc730b452effb253df5a051bc791692ef Author: Tomas Gavenciak gavento@ucw.cz Date: Sat Jun 11 22:37:20 2011 +0200
More pruning old code
diff --git a/libs/core/GP_Pixel.c b/libs/core/GP_Pixel.c deleted file mode 100644 index eedd94a..0000000 --- a/libs/core/GP_Pixel.c +++ /dev/null @@ -1,235 +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-2010 Jiri "BlueBear" Dluhos * - * jiri.bluebear.dluhos@gmail.com * - * * - * Copyright (C) 2009-2010 Cyril Hrubis metan@ucw.cz * - * * - *****************************************************************************/ - -#include "GP_Core.h" - -/////// removed by gavento -// struct PixelTypeInfo { -// const char *type_name; /* human-readable name */ -// GP_ColorType color_type; /* color type used for this pixel type */ -// unsigned int bits; /* how many bits the pixel occupies */ -// }; -// -// /* This table shows relations of pixel types to color types, their names -// * and bits per pixel. -// */ -// static struct PixelTypeInfo pixel_type_infos[] = { -// { "Unknown pixel type", GP_NOCOLOR, 0 }, -// { "Palette 4bit", GP_PAL4, 4 }, -// { "Palette 8bit", GP_PAL8, 8 }, -// { "Grayscale 1bit", GP_G1, 1 }, -// { "Grayscale 2bits", GP_G2, 2 }, -// { "Grayscale 4bits", GP_G4, 4 }, -// { "Grayscale 8bits", GP_G8, 8 }, -// { "RGB 555", GP_RGB555, 16 }, -// { "BGR 555", GP_RGB555, 16 }, -// { "RGB 565", GP_RGB565, 16 }, -// { "BGR 565", GP_RGB565, 16 }, -// { "RGB 888", GP_RGB888, 24 }, -// { "BGR 888", GP_RGB888, 24 }, -// { "XRGB 8888", GP_RGB888, 32 }, -// { "RGBX 8888", GP_RGB888, 32 }, -// { "XBGR 8888", GP_RGB888, 32 }, -// { "BGRX 8888", GP_RGB888, 32 }, -// { "ARGB 8888", GP_RGBA8888, 32 }, -// { "RGBA 8888", GP_RGBA8888, 32 }, -// { "ABGR 8888", GP_RGBA8888, 32 }, -// { "BGRA 8888", GP_RGBA8888, 32 } -// }; -// -// GP_ColorType GP_PixelTypeToColorType(GP_PixelType type) -// { -// if (type >= GP_PIXEL_MAX) -// return GP_COLMAX; -// -// return pixel_type_infos[type].color_type; -// } -// -// #define CHECK_RET(ret) if (ret != GP_ESUCCESS && ret != GP_EUNPRECISE) return ret; -// -// GP_RetCode GP_ColorToPixelType(GP_PixelType pixel_type, GP_Color color, GP_Pixel *pixel) -// { -// if (pixel == NULL) -// return GP_ENULLPTR; -// -// GP_RetCode ret; -// -// switch (pixel_type) { -// case GP_PIXEL_PAL4: -// ret = GP_ColorConvert(&color, GP_PAL4); -// CHECK_RET(ret); -// *pixel = color.pal4.index; -// return ret; -// break; -// case GP_PIXEL_PAL8: -// ret = GP_ColorConvert(&color, GP_PAL8); -// CHECK_RET(ret); -// *pixel = color.pal8.index; -// return ret; -// break; -// case GP_PIXEL_G1: -// ret = GP_ColorConvert(&color, GP_G1); -// CHECK_RET(ret); -// *pixel = color.g1.gray; -// return ret; -// break; -// case GP_PIXEL_G2: -// ret = GP_ColorConvert(&color, GP_G2); -// CHECK_RET(ret); -// *pixel = color.g2.gray; -// return ret; -// break; -// case GP_PIXEL_G4: -// ret = GP_ColorConvert(&color, GP_G4); -// CHECK_RET(ret); -// *pixel = color.g4.gray; -// return ret; -// break; -// case GP_PIXEL_G8: -// ret = GP_ColorConvert(&color, GP_G8); -// CHECK_RET(ret); -// *pixel = color.g8.gray; -// return ret; -// break; -// case GP_PIXEL_RGB565: -// ret = GP_ColorConvert(&color, GP_RGB565); -// CHECK_RET(ret); -// *pixel = color.rgb565.red << 0x0b | -// color.rgb565.green << 0x05 | -// color.rgb565.blue; -// case GP_PIXEL_RGB888: -// case GP_PIXEL_XRGB8888: -// ret = GP_ColorConvert(&color, GP_RGB888); -// CHECK_RET(ret); -// *pixel = color.rgb888.red << 0x10 | -// color.rgb888.green << 0x08 | -// color.rgb888.blue; -// return ret; -// break; -// case GP_PIXEL_BGR888: -// case GP_PIXEL_XBGR8888: -// ret = GP_ColorConvert(&color, GP_RGB888); -// CHECK_RET(ret); -// *pixel = color.rgb888.red | -// color.rgb888.green << 0x08 | -// color.rgb888.blue << 0x10; -// return ret; -// break; -// case GP_PIXEL_RGBX8888: -// ret = GP_ColorConvert(&color, GP_RGB888); -// CHECK_RET(ret); -// *pixel = color.rgb888.red << 0x18 | -// color.rgb888.green << 0x10 | -// color.rgb888.blue << 0x8; -// return ret; -// break; -// case GP_PIXEL_BGRX8888: -// ret = GP_ColorConvert(&color, GP_RGB888); -// CHECK_RET(ret); -// *pixel = color.rgb888.red << 0x08 | -// color.rgb888.green << 0x10 | -// color.rgb888.blue << 0x18; -// return ret; -// break; -// case GP_PIXEL_ARGB8888: -// ret = GP_ColorConvert(&color, GP_RGBA8888); -// CHECK_RET(ret); -// *pixel = color.rgba8888.red << 0x10 | -// color.rgba8888.green << 0x08 | -// color.rgba8888.blue | -// color.rgba8888.alpha << 0x18; -// return ret; -// break; -// case GP_PIXEL_RGBA8888: -// ret = GP_ColorConvert(&color, GP_RGBA8888); -// CHECK_RET(ret); -// *pixel = color.rgba8888.red << 0x18 | -// color.rgba8888.green << 0x10 | -// color.rgba8888.blue << 0x08 | -// color.rgba8888.alpha; -// return ret; -// break; -// case GP_PIXEL_ABGR8888: -// ret = GP_ColorConvert(&color, GP_RGBA8888); -// CHECK_RET(ret); -// *pixel = color.rgba8888.red | -// color.rgba8888.green << 0x08 | -// color.rgba8888.blue << 0x10 | -// color.rgba8888.alpha << 0x18; -// return ret; -// break; -// case GP_PIXEL_BGRA8888: -// ret = GP_ColorConvert(&color, GP_RGBA8888); -// CHECK_RET(ret); -// *pixel = color.rgba8888.red << 0x08 | -// color.rgba8888.green << 0x10 | -// color.rgba8888.blue << 0x18 | -// color.rgba8888.alpha; -// return ret; -// break; -// case GP_PIXEL_MAX: -// break; -// } -// -// if (pixel_type >= GP_PIXEL_MAX) -// return GP_EINVAL; -// else -// return GP_ENOIMPL; -// } -// -// GP_RetCode GP_ColorToPixel(GP_Context *context, GP_Color color, GP_Pixel *pixel) -// { -// if (context == NULL || pixel == NULL) -// return GP_ENULLPTR; -// -// return GP_ColorToPixelType(context->pixel_type, color, pixel); -// } -// -// GP_RetCode GP_ColorNameToPixel(GP_Context *context, GP_ColorName name, GP_Pixel *pixel) -// { -// if (context == NULL || pixel == NULL) -// return GP_ENULLPTR; -// -// GP_Color color = GP_COLNAME_PACK(name); -// return GP_ColorToPixelType(context->pixel_type, color, pixel); -// } -// -// GP_RetCode GP_ColorNameToPixelType(GP_PixelType pixel_type, GP_ColorName name, GP_Pixel *pixel) -// { -// if (pixel == NULL) -// return GP_ENULLPTR; -// -// GP_Color color = GP_COLNAME_PACK(name); -// return GP_ColorToPixelType(pixel_type, color, pixel); -// } -// -// GP_RetCode GP_RGBToPixel(GP_Context *context, uint8_t r, uint8_t g, uint8_t b, GP_Pixel *pixel) -// { -// if (pixel == NULL) -// return GP_ENULLPTR; -// -// GP_Color color = GP_RGB888_PACK(r, g, b); -// return GP_ColorToPixelType(context->pixel_type, color, pixel); -// }
http://repo.or.cz/w/gfxprim.git/commit/93c34cab6ae326bf2ff21a69c973a3922ca9e...
commit 93c34cab6ae326bf2ff21a69c973a3922ca9ece7 Author: Tomas Gavenciak gavento@ucw.cz Date: Sat Jun 11 22:29:58 2011 +0200
Rename GP_Pixel_Access to GP_GetPutPixel
diff --git a/include/core/GP_Core.h b/include/core/GP_Core.h index a00f1d7..6d45291 100644 --- a/include/core/GP_Core.h +++ b/include/core/GP_Core.h @@ -45,6 +45,6 @@ #include "core/GP_Pixel.h"
/* Individual pixel access */ -#include "core/GP_Pixel_Access.h" +#include "core/GP_GetPutPixel.h"
#endif /* GP_CORE_H */ diff --git a/include/core/GP_Pixel_Access.h b/include/core/GP_GetPutPixel.h similarity index 95% rename from include/core/GP_Pixel_Access.h rename to include/core/GP_GetPutPixel.h index 331d7eb..102bf9a 100644 --- a/include/core/GP_Pixel_Access.h +++ b/include/core/GP_GetPutPixel.h @@ -20,8 +20,8 @@ * * *****************************************************************************/
-#ifndef GP_PIXEL_ACCESS_H -#define GP_PIXEL_ACCESS_H +#ifndef CORE_GP_GETPUTPIXEL_H +#define CORE_GP_GETPUTPIXEL_H
#include "GP_Context.h" #include "GP_FnPerBpp.h" @@ -30,7 +30,7 @@ /* * Generated header */ -#include "GP_Pixel_Access.gen.h" +#include "GP_GetPutPixel.gen.h"
/* * GetPixel with context transformations and clipping. @@ -62,4 +62,4 @@ static inline void GP_PutPixel_Raw(GP_Context *context, int x, int y, GP_Pixel p context, x, y, p); }
-#endif /* GP_PIXEL_ACCESS_H */ +#endif /* CORE_GP_GETPUTPIXEL_H */ diff --git a/include/gfx/GP_Gfx.h b/include/gfx/GP_Gfx.h index 2f42cb1..aa578b4 100644 --- a/include/gfx/GP_Gfx.h +++ b/include/gfx/GP_Gfx.h @@ -37,7 +37,7 @@ #include "core/GP_Transform.h" #include "core/GP_Context.h" #include "core/GP_WritePixel.h" -#include "core/GP_Pixel_Access.h" +#include "core/GP_GetPutPixel.h" #include "core/GP_Color.h"
/* public drawing API */ diff --git a/libs/core/GP_Pixel_Access.c b/libs/core/GP_GetPutPixel.c similarity index 98% rename from libs/core/GP_Pixel_Access.c rename to libs/core/GP_GetPutPixel.c index f2b8924..fe37216 100644 --- a/libs/core/GP_Pixel_Access.c +++ b/libs/core/GP_GetPutPixel.c @@ -20,7 +20,7 @@ * * *****************************************************************************/
-#include "GP_Pixel_Access.h" +#include "GP_GetPutPixel.h" #include "GP_Transform.h"
GP_Pixel GP_GetPixel(GP_Context *context, int x, int y) diff --git a/libs/core/Makefile b/libs/core/Makefile index 3808736..9ed6c65 100644 --- a/libs/core/Makefile +++ b/libs/core/Makefile @@ -1,6 +1,6 @@ TOPDIR=../.. GENSOURCES=GP_Pixel.gen.c GP_Blit.gen.c -GENHEADERS=GP_Pixel_Scale.gen.h GP_Blit.gen.h GP_Pixel.gen.h GP_Pixel_Access.gen.h +GENHEADERS=GP_Pixel_Scale.gen.h GP_Blit.gen.h GP_Pixel.gen.h GP_GetPutPixel.gen.h CSOURCES=$(filter-out $(wildcard *.gen.c),$(wildcard *.c)) LIBNAME=core
diff --git a/pylib/gfxprim/generators/core/make_GP_Pixel.py b/pylib/gfxprim/generators/core/make_GP_Pixel.py index 0a1ff3b..21cb252 100644 --- a/pylib/gfxprim/generators/core/make_GP_Pixel.py +++ b/pylib/gfxprim/generators/core/make_GP_Pixel.py @@ -67,8 +67,8 @@ def core_GP_Pixel_gen(h, c): gen_convert_to(pixeltypes['VA12'], pixeltypes['RGBA8888'], h, c)
-@generator(CHeaderGenerator(name = 'GP_Pixel_Access.gen.h'), - descr = 'Access pixel bytes, Put and GetPixelnDo not include directly, use GP_Pixel.h', +@generator(CHeaderGenerator(name = 'GP_GetPutPixel.gen.h'), + descr = 'Access pixel bytes, Get and PutPixelnDo not include directly, use GP_Pixel.h', authors = ["2011 - Tomas Gavenciak gavento@ucw.cz"]) def core_GP_Pixel_Scale_gen(h): h.rhead('#include "GP_Common.h"nn');
http://repo.or.cz/w/gfxprim.git/commit/628bf75875173555777a15ce6a7fe7e91cd32...
commit 628bf75875173555777a15ce6a7fe7e91cd328b8 Author: Tomas Gavenciak gavento@ucw.cz Date: Sat Jun 11 22:13:05 2011 +0200
Added basic common pixeltypes to be generated
diff --git a/pylib/pixeltypes.py b/pylib/pixeltypes.py index 7f77336..4762255 100644 --- a/pylib/pixeltypes.py +++ b/pylib/pixeltypes.py @@ -14,6 +14,9 @@ # a complete recompilation is required after any change. #
+# +# Standard RGB types +#
PixelType(name='RGBx8888', size=32, chanslist=[ ('R', 0, 8), @@ -28,20 +31,56 @@ PixelType(name='RGBA8888', size=32, chanslist=[ ('A', 24, 8)])
+PixelType(name='RGB888', size=24, chanslist=[ + ('R', 0, 8), + ('G', 8, 8), + ('B', 16, 8)]) + + PixelType(name='RGB565', size=16, chanslist=[ ('R', 0, 5), ('G', 5, 6), ('B', 11, 5)])
+# +# Palette types +# + +PixelType(name='P2', size=2, bit_endian='LE', chanslist=[ + ('P', 0, 2)]) + + +PixelType(name='P4', size=4, bit_endian='LE', chanslist=[ + ('P', 0, 4)])
-PixelType(name='V8', size=8, chanslist=[ - ('V', 0, 8)]) + +PixelType(name='P8', size=8, bit_endian='LE', chanslist=[ + ('P', 0, 8)]) + +# +# Gray-only pixel types +# + +PixelType(name='V1', size=1, bit_endian='LE', chanslist=[ + ('V', 0, 1)])
PixelType(name='V2', size=2, bit_endian='LE', chanslist=[ ('V', 0, 2)])
+PixelType(name='V4', size=4, bit_endian='LE', chanslist=[ + ('V', 0, 4)]) + + +PixelType(name='V8', size=8, bit_endian='LE', chanslist=[ + ('V', 0, 8)]) + + +# +# Experiments +# + PixelType(name='VA12', size=4, bit_endian='BE', chanslist=[ ('A', 1, 2), ('V', 3, 1)])
http://repo.or.cz/w/gfxprim.git/commit/cfd3858ce9e6a269b8903bd312e52259c48e3...
commit cfd3858ce9e6a269b8903bd312e52259c48e318c Author: Tomas Gavenciak gavento@ucw.cz Date: Sat Jun 11 22:11:23 2011 +0200
Drastic color/palette code pruning
Palettes to be reimplemented (did not work as such with gen. code anyway) Color as (type, color) pair may be re-added much later
diff --git a/include/core/GP_Color.h b/include/core/GP_Color.h index 8f11b03..3f13f95 100644 --- a/include/core/GP_Color.h +++ b/include/core/GP_Color.h @@ -26,101 +26,6 @@ #ifndef GP_COLOR_H #define GP_COLOR_H
-#include <stdint.h> - -#include "GP_RetCode.h" - -#define GP_COLNAME_PACK(n) {.name = {GP_COLNAME, n}} -#define GP_PALINDEX_PACK(palette, index) {.pal = {GP_PALETTE, index, palette}} -#define GP_PAL4_PACK(index) {.pal4 = {GP_PAL4, index}} -#define GP_PAL8_PACK(index) {.pal8 = {GP_PAL8, index}} -#define GP_G1_PACK(g) {.g1 = {GP_G1, g}} -#define GP_G2_PACK(g) {.g2 = {GP_G2, g}} -#define GP_G4_PACK(g) {.g4 = {GP_G4, g}} -#define GP_G8_PACK(g) {.g8 = {GP_G8, g}} -#define GP_RGB555_PACK(r, g, b) {.rgb555 = {GP_RGB555, r, g, b}} -#define GP_RGB565_PACK(r, g, b) {.rgb565 = {GP_RGB565, r, g, b}} -#define GP_RGB666_PACK(r, g, b) {.rgb666 = {GP_RGB666, r, g, b}} -#define GP_RGB888_PACK(r, g, b) {.rgb888 = {GP_RGB888, r, g, b}} -#define GP_RGBA8888_PACK(r, g, b, a) {.rgba8888 = {GP_RGBA8888, r, g, b, a}} - -#define GP_COLNAME_FILL(col, n) do { - (col)->name.type = GP_COLNAME; - (col)->name.name = n; -} while (0) - -#define GP_PALINDEX_FILL(col, p, i) do { - (col)->pal.type = GP_PALETTE; - (col)->pal.index = i; - (col)->pal.palette = p; -} while (0) - -#define GP_PAL4_FILL(col, i) do { - (col)->pal4.type = GP_PAL4; - (col)->pal4.index = i; -} while (0) - -#define GP_PAL8_FILL(col, i) do { - (col)->pal8.type = GP_PAL8; - (col)->pal8.index = i; -} while (0) - -#define GP_G1_FILL(col, g) do { - (col)->g1.type = GP_G1; - (col)->g1.gray = g; -} while (0) - -#define GP_G2_FILL(col, g) do { - (col)->g2.type = GP_G2; - (col)->g2.gray = g; -} while (0) - -#define GP_G4_FILL(col, g) do { - (col)->g4.type = GP_G4; - (col)->g4.gray = g; -} while (0) - -#define GP_G8_FILL(col, g) do { - (col)->g8.type = GP_G8; - (col)->g8.gray = g; -} while (0) - -#define GP_RGB555_FILL(col, r, g, b) do {- (col)->rgb555.type = GP_RGB555; - (col)->rgb555.red = r; - (col)->rgb555.green = g; - (col)->rgb555.blue = b; -} while (0) - -#define GP_RGB565_FILL(col, r, g, b) do {- (col)->rgb565.type = GP_RGB565; - (col)->rgb565.red = r; - (col)->rgb565.green = g; - (col)->rgb565.blue = b; -} while (0) - -#define GP_RGB666_FILL(col, r, g, b) do {- (col)->rgb666.type = GP_RGB666; - (col)->rgb666.red = r; - (col)->rgb666.green = g; - (col)->rgb666.blue = b; -} while (0) - -#define GP_RGB888_FILL(col, r, g, b) do {- (col)->rgb888.type = GP_RGB888; - (col)->rgb888.red = r; - (col)->rgb888.green = g; - (col)->rgb888.blue = b; -} while (0) - -#define GP_RGBA8888_FILL(col, r, g, b, a) do {- (col)->rgba8888.type = GP_RGBA8888; - (col)->rgba8888.red = r; - (col)->rgba8888.green = g; - (col)->rgba8888.blue = b; - (col)->rgba8888.alpha = a; -} while (0) - typedef enum GP_ColorName { GP_COL_BLACK, GP_COL_RED, @@ -136,131 +41,4 @@ typedef enum GP_ColorName { GP_COL_MAX, } GP_ColorName;
-typedef enum GP_ColorType { - GP_NOCOLOR = 0, - GP_COLNAME, - GP_PALETTE, - GP_PAL4, - GP_PAL8, - GP_G1, - GP_G2, - GP_G4, - GP_G8, - GP_RGB555, - GP_RGB565, - GP_RGB666, - GP_RGB888, - GP_RGBA8888, - GP_COLMAX, -} GP_ColorType; - -struct GP_ColName { - enum GP_ColorType type; - enum GP_ColorName name; -}; - -struct GP_ColPal { - enum GP_ColorType type; - uint16_t index; - union GP_Palette *palette; -}; - -struct GP_ColPal4 { - enum GP_ColorType type; - uint8_t index:4; -}; - -struct GP_ColPal8 { - enum GP_ColorType type; - uint8_t index; -}; - -struct GP_ColRGB888 { - enum GP_ColorType type; - uint8_t red; - uint8_t green; - uint8_t blue; -}; - -struct GP_ColG1 { - enum GP_ColorType type; - uint8_t gray:1; -}; - -struct GP_ColG2 { - enum GP_ColorType type; - uint8_t gray:2; -}; - -struct GP_ColG4 { - enum GP_ColorType type; - uint8_t gray:4; -}; - -struct GP_ColG8 { - enum GP_ColorType type; - uint8_t gray; -}; - -struct GP_ColRGBA8888 { - enum GP_ColorType type; - uint8_t red; - uint8_t green; - uint8_t blue; - uint8_t alpha; -}; - -struct GP_ColRGB555 { - enum GP_ColorType type; - uint16_t red:5; - uint16_t green:5; - uint16_t blue:5; -}; - -struct GP_ColRGB565 { - enum GP_ColorType type; - uint16_t red:5; - uint16_t green:6; - uint16_t blue:5; -}; - -struct GP_ColRGB666 { - enum GP_ColorType type; - uint32_t red:6; - uint32_t green:6; - uint32_t blue:6; -}; - -typedef union GP_Color { - enum GP_ColorType type; - struct GP_ColName name; - struct GP_ColPal pal; - struct GP_ColPal4 pal4; - struct GP_ColPal8 pal8; - struct GP_ColG1 g1; - struct GP_ColG2 g2; - struct GP_ColG4 g4; - struct GP_ColG8 g8; - struct GP_ColRGB888 rgb888; - struct GP_ColRGB555 rgb555; - struct GP_ColRGB565 rgb565; - struct GP_ColRGB666 rgb666; - struct GP_ColRGBA8888 rgba8888; -} GP_Color; - -/* - * Convers color pointed by *color to type. - */ -enum GP_RetCode GP_ColorConvert(GP_Color *color, GP_ColorType type); - -/* - * Returns color type name. - */ -const char *GP_ColorTypeName(GP_ColorType type); - -/* - * Print color into stdout in human-readable format. - */ -void GP_ColorPrint(GP_Color *color); - #endif /* GP_COLOR_H */ diff --git a/include/core/GP_Palette.h b/include/core/GP_Palette.h deleted file mode 100644 index 69f1854..0000000 --- a/include/core/GP_Palette.h +++ /dev/null @@ -1,75 +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-2010 Jiri "BlueBear" Dluhos * - * jiri.bluebear.dluhos@gmail.com * - * * - * Copyright (C) 2009-2010 Cyril Hrubis metan@ucw.cz * - * * - *****************************************************************************/ - -#ifndef GP_PALETTE_H -#define GP_PALETTE_H - -#include <stdint.h> - -#include "GP_RetCode.h" -#include "GP_Color.h" - -/* - * Usage: - * - * struct GP_RGB888 pal_cols[] = { - * {0xff, 0x00, 0xff}, - * ... - * }; - * - * GP_Palette my_palette = GP_PAL_RGB888_PACK(pal_cols); - */ -#define GP_PAL_RGB888_PACK(cols) {.rgb888 = {GP_RGB888, - sizeof (cols) / sizeof (struct GP_RGB888),- cols}} - -struct GP_RGB888 { - uint8_t red; - uint8_t green; - uint8_t blue; -}; - -struct GP_PalRGB888 { - enum GP_ColorType type; - uint16_t size; - struct GP_RGB888 *colors; -}; - -typedef union GP_Palette { - enum GP_ColorType type; - struct GP_PalRGB888 rgb888; -} GP_Palette; - -/* - * Converts palette color to direct color. - */ -enum GP_RetCode GP_PaletteColorToColor(GP_Color *color); - -/* - * Print palette into stdout in human-readable format. - */ -void GP_PalettePrint(GP_Palette *palette); - -#endif /* GP_PALETTE_H */ diff --git a/libs/core/GP_Color.c b/libs/core/GP_Color.c index b2e7a0a..e6f2c53 100644 --- a/libs/core/GP_Color.c +++ b/libs/core/GP_Color.c @@ -23,10 +23,7 @@ * * *****************************************************************************/
-#include <stdio.h> - -#include "GP_Palette.h" -#include "GP_Color.h" +#include <stdint.h>
static char *color_names[] = { "black ", @@ -56,799 +53,3 @@ static uint8_t rgb888_colors[][3] = { {0xff, 0xff, 0xff}, /* white */ };
-static const char *color_type_names[] = { - "Invalid color" - "ColorName", - "Index to In Memory Palette", - "HW Palete 4bit", - "HW Palete 8bit", - "Grayscale 1bit", - "Grayscale 2bit", - "Grayscale 4bit", - "Grayscale 8bit", - "RGB 555", - "RGB 565", - "RGB 666", - "RGB 888", - "RGBA 8888", -}; - -static enum GP_RetCode conv_from_name(GP_Color *color, GP_ColorType type) -{ - enum GP_ColorName i = color->name.name; - - if (i >= GP_COL_MAX) - return GP_EINVAL; - - switch (type) { - case GP_NOCOLOR: - return GP_EINVAL; - break; - case GP_PAL4: - case GP_PAL8: - return GP_EINVAL; - break; - case GP_G1: - break; - case GP_G2: - break; - case GP_G4: - GP_G4_FILL(color, ((rgb888_colors[i][0] + - rgb888_colors[i][1] + - rgb888_colors[i][2])/3)>>4); - return GP_EUNPRECISE; - break; - case GP_G8: - GP_G8_FILL(color, (rgb888_colors[i][0] + - rgb888_colors[i][1] + - rgb888_colors[i][2])/3); - return GP_EUNPRECISE; - break; - case GP_RGB555: - GP_RGB555_FILL(color, rgb888_colors[i][0]>>3, - rgb888_colors[i][1]>>3, - rgb888_colors[i][2]>>3); - return GP_ESUCCESS; - break; - case GP_RGB565: - GP_RGB565_FILL(color, rgb888_colors[i][0]>>3, - rgb888_colors[i][1]>>2, - rgb888_colors[i][2]>>3); - return GP_ESUCCESS; - break; - case GP_RGB666: - GP_RGB666_FILL(color, rgb888_colors[i][0]>>2, - rgb888_colors[i][1]>>2, - rgb888_colors[i][2]>>2); - return GP_ESUCCESS; - break; - case GP_RGB888: - GP_RGB888_FILL(color, rgb888_colors[i][0], - rgb888_colors[i][1], - rgb888_colors[i][2]); - return GP_ESUCCESS; - break; - case GP_RGBA8888: - GP_RGBA8888_FILL(color, rgb888_colors[i][0], - rgb888_colors[i][1], - rgb888_colors[i][2], 0xff); - return GP_ESUCCESS; - break; - case GP_COLNAME: - case GP_COLMAX: - case GP_PALETTE: - break; - } - - if (type >= GP_COLMAX) - return GP_EINVAL; - else - return GP_ENOIMPL; -} - -const char *GP_ColorTypeName(GP_ColorType type) -{ - if (type >= GP_COLMAX) - return "UNKNOWN"; - - return color_type_names[type]; -} - -static enum GP_RetCode conv_from_g1(GP_Color *color, GP_ColorType type) -{ - struct GP_ColG1 *col = &color->g1; - - switch (type) { - case GP_NOCOLOR: - return GP_EINVAL; - break; - case GP_PAL4: - case GP_PAL8: - return GP_EINVAL; - break; - case GP_G1: - return GP_ESUCCESS; - break; - case GP_G2: - GP_G2_FILL(color, col->gray * 0x03); - return GP_ESUCCESS; - break; - case GP_G4: - GP_G4_FILL(color, col->gray * 0x0f); - return GP_ESUCCESS; - break; - case GP_G8: - GP_G8_FILL(color, col->gray * 0xff); - return GP_ESUCCESS; - break; - case GP_RGB555: - GP_RGB555_FILL(color, col->gray * 0x1f, - col->gray * 0x1f, - col->gray * 0x1f); - return GP_ESUCCESS; - break; - case GP_RGB565: - GP_RGB565_FILL(color, col->gray * 0x1f, - col->gray * 0x3f, - col->gray * 0x1f); - return GP_ESUCCESS; - break; - case GP_RGB666: - GP_RGB666_FILL(color, col->gray * 0x3f, - col->gray * 0x3f, - col->gray * 0x3f); - return GP_ESUCCESS; - break; - case GP_RGB888: - GP_RGB888_FILL(color, col->gray * 0xff, - col->gray * 0xff, - col->gray * 0xff); - return GP_ESUCCESS; - break; - case GP_RGBA8888: - GP_RGBA8888_FILL(color, col->gray * 0xff, - col->gray * 0xff, - col->gray * 0xff, 0xff); - return GP_ESUCCESS; - break; - case GP_COLMAX: - case GP_COLNAME: - case GP_PALETTE: - break; - } - - if (type >= GP_COLMAX) - return GP_EINVAL; - else - return GP_ENOIMPL; -} - -static enum GP_RetCode conv_from_g2(GP_Color *color, GP_ColorType type) -{ - struct GP_ColG2 *col = &color->g2; - - switch (type) { - case GP_NOCOLOR: - return GP_EINVAL; - break; - case GP_PAL4: - case GP_PAL8: - return GP_EINVAL; - break; - case GP_G1: - GP_G1_FILL(color, col->gray>>2); - return GP_EUNPRECISE; - break; - case GP_G2: - return GP_ESUCCESS; - break; - case GP_G4: - GP_G4_FILL(color, col->gray * 0x0f / 0x03); - return GP_ESUCCESS; - break; - case GP_G8: - GP_G8_FILL(color, col->gray * 0xff / 0x03); - return GP_ESUCCESS; - break; - case GP_RGB555: - GP_RGB555_FILL(color, col->gray * 0x1f / 0x03, - col->gray * 0x1f / 0x03, - col->gray * 0x1f / 0x03); - return GP_ESUCCESS; - break; - case GP_RGB565: - GP_RGB565_FILL(color, col->gray * 0x1f / 0x03, - col->gray * 0x3f / 0x03, - col->gray * 0x1f / 0x03); - return GP_ESUCCESS; - break; - case GP_RGB666: - GP_RGB666_FILL(color, col->gray * 0x3f / 0x03, - col->gray * 0x3f / 0x03, - col->gray * 0x3f / 0x03); - return GP_ESUCCESS; - break; - case GP_RGB888: - GP_RGB888_FILL(color, col->gray * 0xff / 0x03, - col->gray * 0xff / 0x03, - col->gray * 0xff / 0x03); - return GP_ESUCCESS; - break; - case GP_RGBA8888: - GP_RGBA8888_FILL(color, col->gray * 0xff / 0x03, - col->gray * 0xff / 0x03, - col->gray * 0xff / 0x03, 0xff); - return GP_ESUCCESS; - break; - case GP_COLMAX: - case GP_COLNAME: - case GP_PALETTE: - break; - } - - if (type >= GP_COLMAX) - return GP_EINVAL; - else - return GP_ENOIMPL; -} - -static enum GP_RetCode conv_from_g4(GP_Color *color, GP_ColorType type) -{ - struct GP_ColG4 *col = &color->g4; - - switch (type) { - case GP_NOCOLOR: - return GP_EINVAL; - break; - case GP_PAL4: - case GP_PAL8: - return GP_EINVAL; - break; - case GP_G1: - GP_G1_FILL(color, col->gray>>3); - return GP_EUNPRECISE; - break; - case GP_G2: - GP_G2_FILL(color, col->gray>>2); - return GP_EUNPRECISE; - break; - case GP_G4: - return GP_ESUCCESS; - break; - case GP_G8: - GP_G8_FILL(color, col->gray * 0xff / 0x0f); - return GP_ESUCCESS; - break; - case GP_RGB555: - GP_RGB555_FILL(color, col->gray * 0x1f / 0x0f, - col->gray * 0x1f / 0x0f, - col->gray * 0x1f / 0x0f); - return GP_ESUCCESS; - break; - case GP_RGB565: - GP_RGB565_FILL(color, col->gray * 0x1f / 0x0f, - col->gray * 0x3f / 0x0f, - col->gray * 0x1f / 0x0f); - return GP_ESUCCESS; - break; - case GP_RGB666: - GP_RGB666_FILL(color, col->gray * 0x3f / 0x0f, - col->gray * 0x3f / 0x0f, - col->gray * 0x3f / 0x0f); - return GP_ESUCCESS; - break; - case GP_RGB888: - GP_RGB888_FILL(color, col->gray * 0xff / 0x0f, - col->gray * 0xff / 0x0f, - col->gray * 0xff / 0x0f); - return GP_ESUCCESS; - break; - case GP_RGBA8888: - GP_RGBA8888_FILL(color, col->gray * 0xff / 0x0f, - col->gray * 0xff / 0x0f, - col->gray * 0xff / 0x0f, 0xff); - return GP_ESUCCESS; - break; - case GP_COLMAX: - case GP_COLNAME: - case GP_PALETTE: - break; - } - - if (type >= GP_COLMAX) - return GP_EINVAL; - else - return GP_ENOIMPL; -} - -static enum GP_RetCode conv_from_g8(GP_Color *color, GP_ColorType type) -{ - struct GP_ColG8 *col = &color->g8; - - switch (type) { - case GP_NOCOLOR: - return GP_EINVAL; - break; - case GP_PAL4: - case GP_PAL8: - return GP_EINVAL; - break; - case GP_G1: - GP_G1_FILL(color, col->gray / 8); - return GP_EUNPRECISE; - break; - case GP_G2: - GP_G2_FILL(color, col->gray / 4); - return GP_EUNPRECISE; - break; - case GP_G4: - GP_G4_FILL(color, col->gray / 2); - return GP_EUNPRECISE; - break; - case GP_G8: - return GP_ESUCCESS; - break; - case GP_RGB555: - GP_RGB555_FILL(color, col->gray * 0x1f / 0xff, - col->gray * 0x1f / 0xff, - col->gray * 0x1f / 0xff); - return GP_ESUCCESS; - break; - case GP_RGB565: - GP_RGB565_FILL(color, col->gray * 0x1f / 0xff, - col->gray * 0x3f / 0xff, - col->gray * 0x1f / 0xff); - return GP_ESUCCESS; - break; - case GP_RGB666: - GP_RGB666_FILL(color, col->gray * 0x3f / 0xff, - col->gray * 0x3f / 0xff, - col->gray * 0x3f / 0xff); - return GP_ESUCCESS; - break; - case GP_RGB888: - GP_RGB888_FILL(color, col->gray, - col->gray, - col->gray); - return GP_ESUCCESS; - break; - case GP_RGBA8888: - GP_RGBA8888_FILL(color, col->gray, - col->gray, - col->gray, 0xff); - return GP_ESUCCESS; - break; - case GP_COLMAX: - case GP_COLNAME: - case GP_PALETTE: - break; - } - - if (type >= GP_COLMAX) - return GP_EINVAL; - else - return GP_ENOIMPL; -} - -static enum GP_RetCode conv_from_rgb555(GP_Color *color, GP_ColorType type) -{ - struct GP_ColRGB555 *col = &color->rgb555; - uint8_t val; - - switch (type) { - case GP_NOCOLOR: - return GP_EINVAL; - break; - case GP_PAL4: - case GP_PAL8: - return GP_EINVAL; - break; - case GP_G1: - val = ((col->red + col->green + col->blue) / 3)>>4; - GP_G1_FILL(color, val); - return GP_EUNPRECISE; - break; - case GP_G2: - val = ((col->red + col->green + col->blue) / 3)>>3; - GP_G2_FILL(color, val); - return GP_EUNPRECISE; - break; - case GP_G4: - val = ((col->red + col->green + col->blue) / 3)>>2; - GP_G4_FILL(color, val); - return GP_EUNPRECISE; - break; - case GP_G8: - val = (0xff * (col->red + col->green + col->blue)) / - (3 * 0x1f); - GP_G8_FILL(color, val); - return GP_EUNPRECISE; - break; - case GP_RGB555: - return GP_ESUCCESS; - break; - case GP_RGB565: - GP_RGB565_FILL(color, col->red, col->green << 1, - col->blue); - return GP_ESUCCESS; - break; - case GP_RGB666: - GP_RGB666_FILL(color, 0x3f * col->red / 0x1f, - 0x3f * col->green / 0x1f, - 0x3f * col->blue / 0x1f); - return GP_ESUCCESS; - break; - case GP_RGB888: - GP_RGB888_FILL(color, 0xff * col->red / 0x1f, - 0xff * col->green / 0x1f, - 0xff * col->blue / 0x1f); - return GP_ESUCCESS; - break; - case GP_RGBA8888: - GP_RGBA8888_FILL(color, 0xff * col->red / 0x1f, - 0xff * col->green / 0x1f, - 0xff * col->blue / 0x1f, 0xff); - return GP_ESUCCESS; - break; - case GP_COLMAX: - case GP_COLNAME: - case GP_PALETTE: - break; - } - - if (type >= GP_COLMAX) - return GP_EINVAL; - else - return GP_ENOIMPL; -} - -static enum GP_RetCode conv_from_rgb888(GP_Color *color, GP_ColorType type) -{ - struct GP_ColRGB888 *col = &color->rgb888; - uint8_t val; - - switch (type) { - case GP_NOCOLOR: - return GP_EINVAL; - break; - case GP_PAL4: - case GP_PAL8: - return GP_EINVAL; - break; - case GP_G1: - val = ((col->red + col->green + col->blue)/3)>>7; - GP_G1_FILL(color, val); - return GP_EUNPRECISE; - break; - case GP_G2: - val = ((col->red + col->green + col->blue)/3)>>6; - GP_G2_FILL(color, val); - return GP_EUNPRECISE; - break; - case GP_G4: - val = ((col->red + col->green + col->blue)/3)>>4; - GP_G4_FILL(color, val); - return GP_EUNPRECISE; - break; - case GP_G8: - val = ((col->red + col->green + col->blue)/3); - GP_G8_FILL(color, val); - return GP_EUNPRECISE; - break; - case GP_RGB555: - GP_RGB555_FILL(color, col->red>>3, - col->green>>3, - col->blue>>3); - return GP_EUNPRECISE; - break; - case GP_RGB565: - GP_RGB565_FILL(color, col->red>>3, col->green>>2, - col->blue>>3); - return GP_EUNPRECISE; - break; - case GP_RGB666: - GP_RGB666_FILL(color, col->red>>2, col->green>>2, - col->blue>>2); - return GP_EUNPRECISE; - break; - case GP_RGB888: - return GP_ESUCCESS; - break; - case GP_RGBA8888: - GP_RGBA8888_FILL(color, col->red, col->green, - col->blue, 0xff); - return GP_ESUCCESS; - break; - - case GP_COLMAX: - case GP_COLNAME: - case GP_PALETTE: - break; - } - - if (type >= GP_COLMAX) - return GP_EINVAL; - else - return GP_ENOIMPL; -} - -static enum GP_RetCode conv_from_rgba8888(GP_Color *color, GP_ColorType type) -{ - struct GP_ColRGBA8888 *col = &color->rgba8888; - uint8_t val; - - switch (type) { - case GP_NOCOLOR: - return GP_EINVAL; - break; - case GP_PAL4: - case GP_PAL8: - return GP_EINVAL; - break; - case GP_G1: - val = ((col->red + col->green + col->blue)/3)>>7; - GP_G1_FILL(color, val); - return GP_EUNPRECISE; - break; - case GP_G2: - val = ((col->red + col->green + col->blue)/3)>>6; - GP_G2_FILL(color, val); - return GP_EUNPRECISE; - break; - case GP_G4: - val = ((col->red + col->green + col->blue)/3)>>4; - GP_G4_FILL(color, val); - return GP_EUNPRECISE; - break; - case GP_G8: - val = ((col->red + col->green + col->blue)/3); - GP_G8_FILL(color, val); - return GP_EUNPRECISE; - break; - case GP_RGB555: - GP_RGB555_FILL(color, col->red>>3, - col->green>>3, - col->blue>>3); - return GP_EUNPRECISE; - break; - case GP_RGB888: - GP_RGB888_FILL(color, col->red, - col->green, - col->blue); - return GP_EUNPRECISE; - break; - case GP_RGBA8888: - return GP_ESUCCESS; - break; - case GP_COLMAX: - case GP_COLNAME: - case GP_PALETTE: - break; - } - - if (type >= GP_COLMAX) - return GP_EINVAL; - else - return GP_ENOIMPL; -} - -static enum GP_RetCode color_convert(GP_Color *color, GP_ColorType type) -{ - switch (color->type) { - case GP_NOCOLOR: - return GP_EINVAL; - break; - case GP_PAL4: - case GP_PAL8: - return GP_EINVAL; - break; - case GP_COLNAME: - return conv_from_name(color, type); - break; - case GP_G1: - return conv_from_g1(color, type); - break; - case GP_G2: - return conv_from_g2(color, type); - break; - case GP_G4: - return conv_from_g4(color, type); - break; - case GP_G8: - return conv_from_g8(color, type); - break; - case GP_RGB888: - return conv_from_rgb888(color, type); - break; - case GP_RGBA8888: - return conv_from_rgba8888(color, type); - break; - case GP_RGB555: - return conv_from_rgb555(color, type); - break; - case GP_COLMAX: - case GP_PALETTE: - break; - } - - if (color->type >= GP_COLMAX) - return GP_EINVAL; - else - return GP_ENOIMPL; -} - -GP_RetCode GP_ColorConvert(GP_Color *color, GP_ColorType type) -{ - if (!color) - return GP_ENULLPTR; - - /* nothing to do */ - if (color->type == type) - return GP_ESUCCESS; - - GP_RetCode ret; - - /* convert palette color to color */ - if (color->type == GP_PALETTE) { - ret = GP_PaletteColorToColor(color); - - if (ret != GP_ESUCCESS) - return ret; - } - - /* convert color */ - return color_convert(color, type); -} - -static void print_name(struct GP_ColName *color) -{ - printf(" TYPE NAMEn"); - - if (color->name > GP_COL_MAX) { - printf("COLNAME invalidn"); - return; - } - - printf("COLNAME %sn", color_names[color->name]); -} - -static void print_palette(struct GP_ColPal *color) -{ - printf("Palette index %04un", color->index); - GP_PalettePrint(color->palette); -} - -static void print_pal4(struct GP_ColPal4 *color) -{ - printf("HW Palette index 0x%01u", color->index); -} - -static void print_pal8(struct GP_ColPal8 *color) -{ - printf("HW Palette index 0x%02u", color->index); -} - -static void print_g1(struct GP_ColG1 *color) -{ - printf(" TYPE Gn"); - printf(" G1 0x%xn", color->gray); -} - -static void print_g2(struct GP_ColG2 *color) -{ - printf(" TYPE Gn"); - printf(" G2 0x%xn", color->gray); -} - -static void print_g4(struct GP_ColG4 *color) -{ - printf(" TYPE Gn"); - printf(" G4 0x%02xn", color->gray); -} - -static void print_g8(struct GP_ColG8 *color) -{ - printf(" TYPE Gn"); - printf(" G8 0x%02xn", color->gray); -} - -static void print_rgb555(struct GP_ColRGB555 *color) -{ - printf(" TYPE R G Bn"); - printf("RGB555 0x%02x 0x%02x 0x%02xn", color->red, - color->green, - color->blue); -} - -static void print_rgb565(struct GP_ColRGB565 *color) -{ - printf(" TYPE R G Bn"); - printf("RGB565 0x%02x 0x%02x 0x%02xn", color->red, - color->green, - color->blue); -} - -static void print_rgb666(struct GP_ColRGB666 *color) -{ - printf(" TYPE R G Bn"); - printf("RGB666 0x%02x 0x%02x 0x%02xn", color->red, - color->green, - color->blue); -} -static void print_rgb888(struct GP_ColRGB888 *color) -{ - printf(" TYPE R G Bn"); - printf("RGB888 0x%02x 0x%02x 0x%02xn", color->red, - color->green, - color->blue); -} - -static void print_rgba8888(struct GP_ColRGBA8888 *color) -{ - printf(" TYPE R G B An"); - printf("RGBA8888 0x%02x 0x%02x 0x%02x 0x%02xn", color->red, - color->green, - color->blue, - color->alpha); -} - -void GP_ColorPrint(GP_Color *color) -{ - switch (color->type) { - case GP_COLNAME: - print_name(&color->name); - return; - break; - case GP_PALETTE: - print_palette(&color->pal); - return; - break; - case GP_PAL4: - print_pal4(&color->pal4); - return; - break; - case GP_PAL8: - print_pal8(&color->pal8); - break; - case GP_G1: - print_g1(&color->g1); - return; - break; - case GP_G2: - print_g2(&color->g2); - return; - break; - case GP_G4: - print_g4(&color->g4); - return; - break; - case GP_G8: - print_g8(&color->g8); - return; - break; - case GP_RGB555: - print_rgb555(&color->rgb555); - return; - break; - case GP_RGB565: - print_rgb565(&color->rgb565); - return; - break; - case GP_RGB666: - print_rgb666(&color->rgb666); - return; - break; - case GP_RGB888: - print_rgb888(&color->rgb888); - return; - break; - case GP_RGBA8888: - print_rgba8888(&color->rgba8888); - return; - break; - case GP_COLMAX: - break; - } - - printf("Invalid color type (%u)n", color->type); -} diff --git a/libs/core/GP_Palette.c b/libs/core/GP_Palette.c deleted file mode 100644 index 01224f8..0000000 --- a/libs/core/GP_Palette.c +++ /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-2010 Jiri "BlueBear" Dluhos * - * jiri.bluebear.dluhos@gmail.com * - * * - * Copyright (C) 2009-2010 Cyril Hrubis metan@ucw.cz * - * * - *****************************************************************************/ - -#include <stdio.h> - -#include "GP_Color.h" -#include "GP_Palette.h" - -enum GP_RetCode GP_PaletteColorToColor(GP_Color *color) -{ - struct GP_ColPal *pal; - GP_Palette *palette; - uint16_t index; - - if (color->type != GP_PALETTE) - return GP_EINVAL; - - pal = &color->pal; - palette = pal->palette; - index = pal->index; - - switch (pal->palette->type) { - case GP_RGB888: - if (index >= palette->rgb888.size) - return GP_EINVAL; - - GP_RGB888_FILL(color, palette->rgb888.colors[index].red, - palette->rgb888.colors[index].green, - palette->rgb888.colors[index].blue); - return GP_ESUCCESS; - break; - default: - return GP_ENOIMPL; - } -} - -static void print_rgb888(struct GP_PalRGB888 *palette) -{ - uint16_t i; - - printf("palette format rgb888 (size = %u)n", palette->size); - printf(" NR R G Bn"); - - for (i = 0; i < palette->size; i++) { - printf("%04u: 0x%.2x 0x%.2x 0x%.2xn", i, - palette->colors[i].red, - palette->colors[i].green, - palette->colors[i].blue); - } -} - -void GP_PalettePrint(GP_Palette *palette) -{ - switch (palette->type) { - case GP_RGB888: - print_rgb888(&palette->rgb888); - break; - default: - break; - } -}
-----------------------------------------------------------------------
Summary of changes: .../GP_Pixel_Access.c => include/core/GP_Blit.h | 39 +- include/core/GP_Color.h | 222 ------ include/core/GP_Context.h | 1 + include/core/GP_Convert.h | 111 +++ include/core/GP_Core.h | 2 +- .../core/{GP_Pixel_Access.h => GP_GetPutPixel.h} | 8 +- include/core/GP_Palette.h | 75 -- include/core/GP_Pixel.h | 39 +- include/gfx/GP_Gfx.h | 2 +- libs/core/GP_Blit.c | 13 +- libs/core/GP_Color.c | 801 +------------------- libs/core/{GP_Pixel_Access.c => GP_GetPutPixel.c} | 2 +- libs/core/GP_Palette.c | 83 -- libs/core/GP_Pixel.c | 235 ------ libs/core/Makefile | 5 +- pylib/gfxprim/generators/core/gen_blit.py | 28 +- pylib/gfxprim/generators/core/gen_convert.py | 116 +++ .../{gen_pixel_access.py => gen_getputpixel.py} | 0 pylib/gfxprim/generators/core/gen_pixeltype.py | 67 +-- pylib/gfxprim/generators/core/make_GP_Blit.py | 2 +- pylib/gfxprim/generators/core/make_GP_Convert.py | 59 ++ pylib/gfxprim/generators/core/make_GP_Pixel.py | 33 +- pylib/gfxprim/generators/pixeltype.py | 10 +- pylib/gfxprim/generators/utils.py | 1 + pylib/pixeltypes.py | 43 +- 25 files changed, 400 insertions(+), 1597 deletions(-) copy libs/core/GP_Pixel_Access.c => include/core/GP_Blit.h (66%) create mode 100644 include/core/GP_Convert.h rename include/core/{GP_Pixel_Access.h => GP_GetPutPixel.h} (95%) delete mode 100644 include/core/GP_Palette.h rename libs/core/{GP_Pixel_Access.c => GP_GetPutPixel.c} (98%) delete mode 100644 libs/core/GP_Palette.c delete mode 100644 libs/core/GP_Pixel.c create mode 100644 pylib/gfxprim/generators/core/gen_convert.py rename pylib/gfxprim/generators/core/{gen_pixel_access.py => gen_getputpixel.py} (100%) create mode 100644 pylib/gfxprim/generators/core/make_GP_Convert.py
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.