From 32b937c63052f6686b1d818744f172c8658d4be2 Mon Sep 17 00:00:00 2001 From: Cyril Hrubis Date: Fri, 16 Jan 2015 16:44:18 +0100 Subject: [PATCH] core: Get rid of GP_Color. Special thanks to coccinelle and spatch for making this easy job. :) Signed-off-by: Cyril Hrubis --- build/syms/Core_symbols.txt | 5 -- demos/c_simple/SDL_glue.c | 4 +- demos/c_simple/backend_example.c | 4 +- demos/c_simple/backend_timers_example.c | 2 +- demos/c_simple/blittest.c | 4 +- demos/c_simple/fileview.c | 12 +-- demos/c_simple/fonttest.c | 12 +-- demos/c_simple/input_example.c | 8 +- demos/c_simple/koch.c | 8 +- demos/c_simple/linetest.c | 4 +- demos/c_simple/randomshapetest.c | 4 +- demos/c_simple/shapetest.c | 14 ++-- demos/c_simple/textaligntest.c | 14 ++-- demos/c_simple/virtual_backend_example.c | 10 +-- demos/c_simple/x11_windows.c | 4 +- demos/particle/particle_demo.c | 4 +- demos/spiv/spiv.c | 4 +- demos/spiv/spiv_help.c | 4 +- demos/ttf2img/ttf2img.c | 4 +- doc/basic_types.txt | 110 +++++-------------------- doc/convert.txt | 2 - doc/core_python.txt | 9 +-- include/core/GP_Color.h | 124 ---------------------------- include/core/GP_Core.h | 3 - libs/core/GP_Color.c | 135 ------------------------------- pylib/gfxprim/core/core.i | 6 +- 26 files changed, 83 insertions(+), 431 deletions(-) rewrite doc/basic_types.txt (77%) delete mode 100644 include/core/GP_Color.h delete mode 100644 libs/core/GP_Color.c diff --git a/build/syms/Core_symbols.txt b/build/syms/Core_symbols.txt index 902dbdbd..47acec59 100644 --- a/build/syms/Core_symbols.txt +++ b/build/syms/Core_symbols.txt @@ -28,8 +28,6 @@ GP_SetDebugHandler GP_PrintAbortInfo -GP_ColorToPixel -GP_ColorLoadPixels GP_RGBA8888ToPixel GP_PixelRGBMatch GP_PixelTypeByName @@ -63,9 +61,6 @@ GP_PutPixel GP_GetPixel GP_PixelRGBLookup GP_PixelToRGB888 -GP_ColorNameToPixel -GP_ColorNameToColor -GP_ColorToColorName GP_PixelToRGBA8888 GP_Fill diff --git a/demos/c_simple/SDL_glue.c b/demos/c_simple/SDL_glue.c index a6131594..8e9e2162 100644 --- a/demos/c_simple/SDL_glue.c +++ b/demos/c_simple/SDL_glue.c @@ -102,8 +102,8 @@ int main(void) GP_ContextFromSDLSurface(&context, display); - black_pixel = GP_ColorToContextPixel(GP_COL_BLACK, &context); - darkgray_pixel = GP_ColorToContextPixel(GP_COL_GRAY_DARK, &context); + black_pixel = GP_RGBToContextPixel(0x00, 0x00, 0x00, &context); + darkgray_pixel = GP_RGBToContextPixel(0x7f, 0x7f, 0x7f, &context); redraw_screen(); SDL_Flip(display); diff --git a/demos/c_simple/backend_example.c b/demos/c_simple/backend_example.c index 651ffffd..5e87ff18 100644 --- a/demos/c_simple/backend_example.c +++ b/demos/c_simple/backend_example.c @@ -34,8 +34,8 @@ static void redraw(GP_Backend *self) GP_Context *context = self->context; GP_Pixel white_pixel, black_pixel; - black_pixel = GP_ColorToContextPixel(GP_COL_BLACK, context); - white_pixel = GP_ColorToContextPixel(GP_COL_WHITE, context); + black_pixel = GP_RGBToContextPixel(0x00, 0x00, 0x00, context); + white_pixel = GP_RGBToContextPixel(0xff, 0xff, 0xff, context); GP_Fill(context, black_pixel); GP_Line(context, 0, 0, context->w - 1, context->h - 1, white_pixel); diff --git a/demos/c_simple/backend_timers_example.c b/demos/c_simple/backend_timers_example.c index 8d860e56..7b7aae2a 100644 --- a/demos/c_simple/backend_timers_example.c +++ b/demos/c_simple/backend_timers_example.c @@ -32,7 +32,7 @@ static void redraw(GP_Backend *self) { GP_Context *context = self->context; - GP_Pixel black_pixel = GP_ColorToContextPixel(GP_COL_BLACK, context); + GP_Pixel black_pixel = GP_RGBToContextPixel(0x00, 0x00, 0x00, context); GP_Fill(context, black_pixel); diff --git a/demos/c_simple/blittest.c b/demos/c_simple/blittest.c index c6cd2758..ecdb39a2 100644 --- a/demos/c_simple/blittest.c +++ b/demos/c_simple/blittest.c @@ -174,8 +174,8 @@ int main(void) win->context->pixel_type); change_bitmap(); - black = GP_ColorToContextPixel(GP_COL_BLACK, win->context); - white = GP_ColorToContextPixel(GP_COL_WHITE, win->context); + black = GP_RGBToContextPixel(0x00, 0x00, 0x00, win->context); + white = GP_RGBToContextPixel(0xff, 0xff, 0xff, win->context); GP_Fill(win->context, black); GP_BackendFlip(win); diff --git a/demos/c_simple/fileview.c b/demos/c_simple/fileview.c index 2d06dae0..972514bd 100644 --- a/demos/c_simple/fileview.c +++ b/demos/c_simple/fileview.c @@ -263,12 +263,12 @@ int main(int argc, char *argv[]) win = backend->context; - white_pixel = GP_ColorToContextPixel(GP_COL_WHITE, win); - gray_pixel = GP_ColorToContextPixel(GP_COL_GRAY_LIGHT, win); - dark_gray_pixel = GP_ColorToContextPixel(GP_COL_GRAY_DARK, win); - black_pixel = GP_ColorToContextPixel(GP_COL_BLACK, win); - red_pixel = GP_ColorToContextPixel(GP_COL_RED, win); - blue_pixel = GP_ColorToContextPixel(GP_COL_BLUE, win); + white_pixel = GP_RGBToContextPixel(0xff, 0xff, 0xff, win); + gray_pixel = GP_RGBToContextPixel(0xbe, 0xbe, 0xbe, win); + dark_gray_pixel = GP_RGBToContextPixel(0x7f, 0x7f, 0x7f, win); + black_pixel = GP_RGBToContextPixel(0x00, 0x00, 0x00, win); + red_pixel = GP_RGBToContextPixel(0xff, 0x00, 0x00, win); + blue_pixel = GP_RGBToContextPixel(0x00, 0x00, 0xff, win); redraw_screen(); GP_BackendFlip(backend); diff --git a/demos/c_simple/fonttest.c b/demos/c_simple/fonttest.c index 4e33020e..9a3aff1a 100644 --- a/demos/c_simple/fonttest.c +++ b/demos/c_simple/fonttest.c @@ -277,12 +277,12 @@ int main(int argc, char *argv[]) return 1; } - white_pixel = GP_ColorToContextPixel(GP_COL_WHITE, win->context); - gray_pixel = GP_ColorToContextPixel(GP_COL_GRAY_LIGHT, win->context); - dark_gray_pixel = GP_ColorToContextPixel(GP_COL_GRAY_DARK, win->context); - black_pixel = GP_ColorToContextPixel(GP_COL_BLACK, win->context); - red_pixel = GP_ColorToContextPixel(GP_COL_RED, win->context); - blue_pixel = GP_ColorToContextPixel(GP_COL_BLUE, win->context); + white_pixel = GP_RGBToContextPixel(0xff, 0xff, 0xff, win->context); + gray_pixel = GP_RGBToContextPixel(0xbe, 0xbe, 0xbe, win->context); + dark_gray_pixel = GP_RGBToContextPixel(0x7f, 0x7f, 0x7f, win->context); + black_pixel = GP_RGBToContextPixel(0x00, 0x00, 0x00, win->context); + red_pixel = GP_RGBToContextPixel(0xff, 0x00, 0x00, win->context); + blue_pixel = GP_RGBToContextPixel(0x00, 0x00, 0xff, win->context); redraw_screen(); GP_BackendFlip(win); diff --git a/demos/c_simple/input_example.c b/demos/c_simple/input_example.c index 3b94ce36..3a294d23 100644 --- a/demos/c_simple/input_example.c +++ b/demos/c_simple/input_example.c @@ -150,10 +150,10 @@ int main(int argc, char *argv[]) win = backend->context; - red = GP_ColorToContextPixel(GP_COL_RED, win); - green = GP_ColorToContextPixel(GP_COL_GREEN, win); - white = GP_ColorToContextPixel(GP_COL_WHITE, win); - black = GP_ColorToContextPixel(GP_COL_BLACK, win); + red = GP_RGBToContextPixel(0xff, 0x00, 0x00, win); + green = GP_RGBToContextPixel(0x00, 0xff, 0x00, win); + white = GP_RGBToContextPixel(0xff, 0xff, 0xff, win); + black = GP_RGBToContextPixel(0x00, 0x00, 0x00, win); GP_Fill(win, black); GP_BackendFlip(backend); diff --git a/demos/c_simple/koch.c b/demos/c_simple/koch.c index 335815d8..5bb15385 100644 --- a/demos/c_simple/koch.c +++ b/demos/c_simple/koch.c @@ -138,10 +138,10 @@ int main(void) context = backend->context; - black = GP_ColorToContextPixel(GP_COL_BLACK, context); - blue = GP_ColorToContextPixel(GP_COL_BLUE, context); - gray = GP_ColorToContextPixel(GP_COL_GRAY_LIGHT, context); - red = GP_ColorToContextPixel(GP_COL_RED, context); + black = GP_RGBToContextPixel(0x00, 0x00, 0x00, context); + blue = GP_RGBToContextPixel(0x00, 0x00, 0xff, context); + gray = GP_RGBToContextPixel(0xbe, 0xbe, 0xbe, context); + red = GP_RGBToContextPixel(0xff, 0x00, 0x00, context); iter = 0; draw(context->w/2, context->h/2, l, iter); diff --git a/demos/c_simple/linetest.c b/demos/c_simple/linetest.c index 1df6e6e0..19a0244d 100644 --- a/demos/c_simple/linetest.c +++ b/demos/c_simple/linetest.c @@ -135,8 +135,8 @@ int main(int argc, char *argv[]) return 1; } - white = GP_ColorToContextPixel(GP_COL_WHITE, win->context); - black = GP_ColorToContextPixel(GP_COL_BLACK, win->context); + white = GP_RGBToContextPixel(0xff, 0xff, 0xff, win->context); + black = GP_RGBToContextPixel(0x00, 0x00, 0x00, win->context); redraw_screen(); diff --git a/demos/c_simple/randomshapetest.c b/demos/c_simple/randomshapetest.c index f3dbaa1f..e5f4e5d8 100644 --- a/demos/c_simple/randomshapetest.c +++ b/demos/c_simple/randomshapetest.c @@ -268,8 +268,8 @@ int main(void) return 1; } - white = GP_ColorToContextPixel(GP_COL_WHITE, win->context); - black = GP_ColorToContextPixel(GP_COL_BLACK, win->context); + white = GP_RGBToContextPixel(0xff, 0xff, 0xff, win->context); + black = GP_RGBToContextPixel(0x00, 0x00, 0x00, win->context); for (;;) { GP_BackendPoll(win); diff --git a/demos/c_simple/shapetest.c b/demos/c_simple/shapetest.c index db329388..b114fd8f 100644 --- a/demos/c_simple/shapetest.c +++ b/demos/c_simple/shapetest.c @@ -505,13 +505,13 @@ int main(int argc, char *argv[]) center_y = win->h / 2; /* Load colors compatible with the display */ - black = GP_ColorToContextPixel(GP_COL_BLACK, win); - white = GP_ColorToContextPixel(GP_COL_WHITE, win); - yellow = GP_ColorToContextPixel(GP_COL_YELLOW, win); - green = GP_ColorToContextPixel(GP_COL_GREEN, win); - red = GP_ColorToContextPixel(GP_COL_RED, win); - gray = GP_ColorToContextPixel(GP_COL_GRAY_LIGHT, win); - darkgray = GP_ColorToContextPixel(GP_COL_GRAY_DARK, win); + black = GP_RGBToContextPixel(0x00, 0x00, 0x00, win); + white = GP_RGBToContextPixel(0xff, 0xff, 0xff, win); + yellow = GP_RGBToContextPixel(0xff, 0xff, 0x00, win); + green = GP_RGBToContextPixel(0x00, 0xff, 0x00, win); + red = GP_RGBToContextPixel(0xff, 0x00, 0x00, win); + gray = GP_RGBToContextPixel(0xbe, 0xbe, 0xbe, win); + darkgray = GP_RGBToContextPixel(0x7f, 0x7f, 0x7f, win); print_instructions(); redraw_screen(); diff --git a/demos/c_simple/textaligntest.c b/demos/c_simple/textaligntest.c index 70b2fd23..5e2fbd69 100644 --- a/demos/c_simple/textaligntest.c +++ b/demos/c_simple/textaligntest.c @@ -181,13 +181,13 @@ int main(int argc, char *argv[]) return 1; } - black_pixel = GP_ColorToContextPixel(GP_COL_BLACK, win->context); - red_pixel = GP_ColorToContextPixel(GP_COL_RED, win->context); - blue_pixel = GP_ColorToContextPixel(GP_COL_BLUE, win->context); - green_pixel = GP_ColorToContextPixel(GP_COL_GREEN, win->context); - yellow_pixel = GP_ColorToContextPixel(GP_COL_YELLOW, win->context); - white_pixel = GP_ColorToContextPixel(GP_COL_WHITE, win->context); - darkgray_pixel = GP_ColorToContextPixel(GP_COL_GRAY_DARK, win->context); + black_pixel = GP_RGBToContextPixel(0x00, 0x00, 0x00, win->context); + red_pixel = GP_RGBToContextPixel(0xff, 0x00, 0x00, win->context); + blue_pixel = GP_RGBToContextPixel(0x00, 0x00, 0xff, win->context); + green_pixel = GP_RGBToContextPixel(0x00, 0xff, 0x00, win->context); + yellow_pixel = GP_RGBToContextPixel(0xff, 0xff, 0x00, win->context); + white_pixel = GP_RGBToContextPixel(0xff, 0xff, 0xff, win->context); + darkgray_pixel = GP_RGBToContextPixel(0x7f, 0x7f, 0x7f, win->context); redraw_screen(); GP_BackendFlip(win); diff --git a/demos/c_simple/virtual_backend_example.c b/demos/c_simple/virtual_backend_example.c index 925a3d6a..5ef5a8ef 100644 --- a/demos/c_simple/virtual_backend_example.c +++ b/demos/c_simple/virtual_backend_example.c @@ -93,11 +93,11 @@ int main(int argc, char *argv[]) context = backend->context; /* Now draw some testing patters */ - black_pixel = GP_ColorToContextPixel(GP_COL_BLACK, context); - white_pixel = GP_ColorToContextPixel(GP_COL_WHITE, context); - red_pixel = GP_ColorToContextPixel(GP_COL_RED, context); - blue_pixel = GP_ColorToContextPixel(GP_COL_BLUE, context); - green_pixel = GP_ColorToContextPixel(GP_COL_GREEN, context); + black_pixel = GP_RGBToContextPixel(0x00, 0x00, 0x00, context); + white_pixel = GP_RGBToContextPixel(0xff, 0xff, 0xff, context); + red_pixel = GP_RGBToContextPixel(0xff, 0x00, 0x00, context); + blue_pixel = GP_RGBToContextPixel(0x00, 0x00, 0xff, context); + green_pixel = GP_RGBToContextPixel(0x00, 0xff, 0x00, context); GP_Fill(context, white_pixel); diff --git a/demos/c_simple/x11_windows.c b/demos/c_simple/x11_windows.c index fa52cc20..1c5b2d07 100644 --- a/demos/c_simple/x11_windows.c +++ b/demos/c_simple/x11_windows.c @@ -33,8 +33,8 @@ static void redraw(struct GP_Context *context) { GP_Pixel white_pixel, black_pixel; - black_pixel = GP_ColorToContextPixel(GP_COL_BLACK, context); - white_pixel = GP_ColorToContextPixel(GP_COL_WHITE, context); + black_pixel = GP_RGBToContextPixel(0x00, 0x00, 0x00, context); + white_pixel = GP_RGBToContextPixel(0xff, 0xff, 0xff, context); GP_Fill(context, black_pixel); GP_Line(context, 0, 0, context->w - 1, context->h - 1, white_pixel); diff --git a/demos/particle/particle_demo.c b/demos/particle/particle_demo.c index 2b902a0a..46fafe29 100644 --- a/demos/particle/particle_demo.c +++ b/demos/particle/particle_demo.c @@ -90,8 +90,8 @@ int main(int argc, char *argv[]) context = backend->context; - black_pixel = GP_ColorToContextPixel(GP_COL_BLACK, context); - white_pixel = GP_ColorToContextPixel(GP_COL_WHITE, context); + black_pixel = GP_RGBToContextPixel(0x00, 0x00, 0x00, context); + white_pixel = GP_RGBToContextPixel(0xff, 0xff, 0xff, context); GP_Fill(context, black_pixel); GP_BackendFlip(backend); diff --git a/demos/spiv/spiv.c b/demos/spiv/spiv.c index 40a5687b..75af202b 100644 --- a/demos/spiv/spiv.c +++ b/demos/spiv/spiv.c @@ -818,8 +818,8 @@ int main(int argc, char *argv[]) context = backend->context; - black_pixel = GP_ColorToContextPixel(GP_COL_BLACK, context); - white_pixel = GP_ColorToContextPixel(GP_COL_WHITE, context); + black_pixel = GP_RGBToContextPixel(0x00, 0x00, 0x00, context); + white_pixel = GP_RGBToContextPixel(0xff, 0xff, 0xff, context); gray_pixel = GP_RGBToContextPixel(0x33, 0x33, 0x33, context); GP_Fill(context, black_pixel); diff --git a/demos/spiv/spiv_help.c b/demos/spiv/spiv_help.c index ef1f0c58..2d7eac94 100644 --- a/demos/spiv/spiv_help.c +++ b/demos/spiv/spiv_help.c @@ -235,8 +235,8 @@ static int last_line; static int redraw_help(GP_Backend *backend, unsigned int loff, GP_Coord xoff) { GP_Context *c = backend->context; - GP_Pixel black = GP_ColorToContextPixel(GP_COL_BLACK, c); - GP_Pixel white = GP_ColorToContextPixel(GP_COL_WHITE, c); + GP_Pixel black = GP_RGBToContextPixel(0x00, 0x00, 0x00, c); + GP_Pixel white = GP_RGBToContextPixel(0xff, 0xff, 0xff, c); int i; int spacing = GP_TextHeight(config.style)/10 + 2; diff --git a/demos/ttf2img/ttf2img.c b/demos/ttf2img/ttf2img.c index 9bc45588..deaa37a4 100644 --- a/demos/ttf2img/ttf2img.c +++ b/demos/ttf2img/ttf2img.c @@ -76,8 +76,8 @@ int main(int argc, char *argv[]) GP_Context *context = GP_ContextAlloc(img_w, img_h, GP_PIXEL_RGB888); - GP_Pixel black_pixel = GP_ColorToContextPixel(GP_COL_BLACK, context); - GP_Pixel white_pixel = GP_ColorToContextPixel(GP_COL_WHITE, context); + GP_Pixel black_pixel = GP_RGBToContextPixel(0x00, 0x00, 0x00, context); + GP_Pixel white_pixel = GP_RGBToContextPixel(0xff, 0xff, 0xff, context); GP_Fill(context, white_pixel); diff --git a/doc/basic_types.txt b/doc/basic_types.txt dissimilarity index 77% index 11ff214b..3b6c6fda 100644 --- a/doc/basic_types.txt +++ b/doc/basic_types.txt @@ -1,91 +1,19 @@ -Basic types ------------ -Coordinates and Size and Length -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -Most of the drawing functions use typedefed 'GP_Coord' and 'GP_Size' integer -types for parameters. - -The 'GP_Coord' is signed integer which is used for coordinates and the -'GP_Size' is unsigned integer type used for object size, length and so. - -Pixel -~~~~~ - -Pixel value in 'GFXprim' is an integer big enough to hold the actual pixel -values. The default typedef for 'GP_Pixel' is set to 32 bit integer, which may -be changed at compile time to support colors with more than 10 bits per -channel. The 'GP_Pixel' is thus used as opaque value big enough to hold any -supported pixel value. - -[[Color]] -Color -~~~~~ - -The 'GP_Color' enumeration holds symbolic constants for basic colors. - -A 'GP_Color' can be converted into a 'GP_Pixel' for a given 'GP_PixelType'. -Symbolic values can also be converted to/from strings (color name in English). - -The 'GP_Color' enum is defined as follows: - -[source,c] --------------------------------------------------------------------------------- -typedef enum GP_Color { - GP_COL_INVALID = -1, - - /* full-intensity RGB and CMYK */ - GP_COL_BLACK, - GP_COL_RED, - GP_COL_GREEN, - GP_COL_BLUE, - GP_COL_YELLOW, - GP_COL_CYAN, - GP_COL_MAGENTA, - - /* various common mixes */ - GP_COL_BROWN, - GP_COL_ORANGE, - GP_COL_GRAY_DARK, /* exactly half RGB values of white */ - GP_COL_GRAY_LIGHT, - GP_COL_PURPLE, - - GP_COL_WHITE, /* full-intensity white */ - GP_COL_MAX, -} GP_Color; --------------------------------------------------------------------------------- - -[source,c] --------------------------------------------------------------------------------- -#include -/* or */ -#include - -GP_Pixel GP_ColorToPixel(GP_Color color, GP_PixelType pixel_type); -GP_Pixel GP_ColorToContextPixel(GP_Color color, GP_Context *context); - -GP_Color GP_ColorNameToColor(const char *color_name); -const char *GP_ColorToColorName(GP_Color color); - -bool GP_ColorNameToPixel(const char *color_name, GP_PixelType pixel_type, - GP_Pixel *pixel); -bool GP_ColorNameToContextPixel(const char *color_name, GP_Context *context, - GP_Pixel *pixel); --------------------------------------------------------------------------------- - -Functions for conversion between colors, pixels and color names. The last two -returns true if color with such name was found. - -[source,c] --------------------------------------------------------------------------------- -#include -/* or */ -#include - -void GP_ColorLoadPixels(GP_Pixel pixels[], GP_PixelType pixel_type); -void GP_ColorLoadContextPixels(GP_Pixel pixels[], GP_Context *context); --------------------------------------------------------------------------------- - -Loads array of 'GP_Pixel' of size 'GP_COL_MAX', the array is then used with -the GP_Color enum as 'pixels[GP_COL_BLACK]'. - +Basic types +----------- +Coordinates and Size and Length +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Most of the drawing functions use typedefed 'GP_Coord' and 'GP_Size' integer +types for parameters. + +The 'GP_Coord' is signed integer which is used for coordinates and the +'GP_Size' is unsigned integer type used for object size, length and so. + +Pixel +~~~~~ + +Pixel value in 'GFXprim' is an integer big enough to hold the actual pixel +values. The default typedef for 'GP_Pixel' is set to 32 bit integer, which may +be changed at compile time to support colors with more than 10 bits per +channel. The 'GP_Pixel' is thus used as opaque value big enough to hold any +supported pixel value. diff --git a/doc/convert.txt b/doc/convert.txt index 91918051..f11f932a 100644 --- a/doc/convert.txt +++ b/doc/convert.txt @@ -3,8 +3,6 @@ Pixel Conversions This page describes RGB tripplet to pixels conversions. -See also link:basic_types.html#Color[colors]. - [source,c] ------------------------------------------------------------------------------- #include diff --git a/doc/core_python.txt b/doc/core_python.txt index 487b903c..108c8594 100644 --- a/doc/core_python.txt +++ b/doc/core_python.txt @@ -101,15 +101,13 @@ Blit is clipped. TIP: See link:example_py_showimage.html[example Blit usage]. -[[Colors_and_Pixels]] -Colors and Pixels -~~~~~~~~~~~~~~~~~ +[[Pixels]] +Pixels +~~~~~~ Pixel in GFXprim is a number large enough to store a pixel value. Pixel is passed as a parameter to all drawing functions. -Color is a more abstract representation for example RGB triplet. - There are several functions to create a pixel value for a particular pixel type from color. @@ -128,7 +126,6 @@ import gfxprim.core as core These functions creates a pixel suitable for drawing into a bitmap with particular pixel type. - [source,python] ------------------------------------------------------------------------------- import gfxprim.core as core diff --git a/include/core/GP_Color.h b/include/core/GP_Color.h deleted file mode 100644 index de87e6a6..00000000 --- a/include/core/GP_Color.h +++ /dev/null @@ -1,124 +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 * - * * - * * - * Copyright (C) 2009-2011 Cyril Hrubis * - * * - *****************************************************************************/ - - /* - - Color is enumeration of color names which may be converted into pixel values - in desired pixel format. - - */ - -#ifndef GP_COLOR_H -#define GP_COLOR_H - -#include "GP_Context.h" -#include "GP_Pixel.h" - -/* - * Enumeration of color constants. - */ -typedef enum GP_Color { - GP_COL_INVALID = -1, - GP_COL_BLACK, - GP_COL_RED, - GP_COL_GREEN, - GP_COL_BLUE, - GP_COL_YELLOW, - GP_COL_CYAN, - GP_COL_MAGENTA, - GP_COL_BROWN, - GP_COL_ORANGE, - GP_COL_GRAY_DARK, - GP_COL_GRAY_LIGHT, - GP_COL_PURPLE, - GP_COL_WHITE, - GP_COL_MAX, -} GP_Color; - -/* - * Converts GP_Color to GP_Pixel. - */ -GP_Pixel GP_ColorToPixel(GP_Color color, GP_PixelType pixel_type); - -/* - * Converts GP_Color to GP_Pixel. - */ -static inline GP_Pixel GP_ColorToContextPixel(GP_Color color, - GP_Context *context) -{ - return GP_ColorToPixel(color, context->pixel_type); -} - -/* - * Converts Color name (eg. string) to GP_Color. - */ -GP_Color GP_ColorNameToColor(const char *color_name); - -/* - * Converts GP_Color to color name. - * - * If color is not valid NULL is returned. - */ -const char *GP_ColorToColorName(GP_Color color); - -/* - * Converts Color name to Pixel. - * - * Returns true if conversion was successful false otherwise. - */ -bool GP_ColorNameToPixel(const char *color_name, GP_PixelType pixel_type, - GP_Pixel *pixel); - -/* - * Converts Color name to Pixel. - * - * Returns true if conversion was successful false otherwise. - */ -static inline bool GP_ColorNameToContextPixel(const char *color_name, - GP_Context *context, - GP_Pixel *pixel) -{ - return GP_ColorNameToPixel(color_name, context->pixel_type, pixel); -} - -/* - * Loads all colors into array of GP_Pixel of size GP_COL_MAX. - * - * The colors are then used as pixels[GP_COL_XXX]; - */ -void GP_ColorLoadPixels(GP_Pixel pixels[], GP_PixelType pixel_type); - -/* - * Loads all colors into array of GP_Pixel of size GP_COL_MAX. - * - * The colors are then used as pixels[GP_COL_XXX]; - */ -static inline void GP_ColorLoadContextPixels(GP_Pixel pixels[], - GP_Context *context) -{ - GP_ColorLoadPixels(pixels, context->pixel_type); -} - -#endif /* GP_COLOR_H */ diff --git a/include/core/GP_Core.h b/include/core/GP_Core.h index b9f1b6ac..bef68345 100644 --- a/include/core/GP_Core.h +++ b/include/core/GP_Core.h @@ -65,9 +65,6 @@ /* Debug and debug level */ #include "core/GP_Debug.h" -/* Color */ -#include "core/GP_Color.h" - /* Progress callback */ #include "core/GP_ProgressCallback.h" diff --git a/libs/core/GP_Color.c b/libs/core/GP_Color.c deleted file mode 100644 index 2c42d4a1..00000000 --- a/libs/core/GP_Color.c +++ /dev/null @@ -1,135 +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 * - * * - * * - * Copyright (C) 2009-2011 Cyril Hrubis * - * * - *****************************************************************************/ - -#include -#include - -#include "GP_Convert.h" - -#include "GP_Color.h" - - -static char *color_names[] = { - "Black", - "Red", - "Green", - "Blue", - "Yellow", - "Cyan", - "Magenta", - "Brown", - "Orange", - "DarkGray", - "LightGray", - "Purple", - "White" -}; - -static uint8_t rgb888_colors[][3] = { - {0x00, 0x00, 0x00}, /* Black */ - {0xff, 0x00, 0x00}, /* Red */ - {0x00, 0xff, 0x00}, /* Green */ - {0x00, 0x00, 0xff}, /* Blue */ - {0xff, 0xff, 0x00}, /* Yellow */ - {0x00, 0xff, 0xff}, /* Cyan */ - {0xff, 0x00, 0xff}, /* Magenta */ - {0xa5, 0x2a, 0x2a}, /* Brown */ - {0xff, 0xa5, 0x00}, /* Orange */ - {0x7f, 0x7f, 0x7f}, /* DarkGray */ - {0xbe, 0xbe, 0xbe}, /* LightGray */ - {0xa0, 0x20, 0xf0}, /* Purple */ - {0xff, 0xff, 0xff}, /* White */ -}; - -/* 3-2-3 RGB palette */ -static uint8_t p8_colors[] = { - 0x00, /* Black */ - 0xe0, /* Red */ - 0x1c, /* Green */ - 0x03, /* Blue */ - 0xfc, /* Yellow */ - 0x1f, /* Cyan */ - 0xe7, /* Magenta */ - 0x88, /* Brown */ - 0xf0, /* Orange */ - 0x49, /* DarkGray */ - 0x92, /* LightGray */ - 0x8a, /* Purple */ - 0xff, /* White */ -}; - -GP_Pixel GP_ColorToPixel(GP_Color color, GP_PixelType pixel_type) -{ - GP_ASSERT(color < GP_COL_MAX); - GP_ASSERT(color >= 0); - - if (pixel_type == GP_PIXEL_P8) - return p8_colors[color]; - - return GP_RGBToPixel(rgb888_colors[color][0], - rgb888_colors[color][1], - rgb888_colors[color][2], - pixel_type); -} - -GP_Color GP_ColorNameToColor(const char *color_name) -{ - unsigned int i; - - for (i = 0; i < GP_COL_MAX; i++) - if (!strcasecmp(color_name, color_names[i])) - return i; - - return -1; -} - -const char *GP_ColorToColorName(GP_Color color) -{ - if (color < 0 || color >= GP_COL_MAX) - return NULL; - - return color_names[color]; -} - -bool GP_ColorNameToPixel(const char *color_name, GP_PixelType pixel_type, - GP_Pixel *pixel) -{ - GP_Color color = GP_ColorNameToColor(color_name); - - if (color == GP_COL_INVALID) - return false; - - *pixel = GP_ColorToPixel(color, pixel_type); - - return true; -} - -void GP_ColorLoadPixels(GP_Pixel pixels[], GP_PixelType pixel_type) -{ - unsigned int i; - - for (i = 0; i < GP_COL_MAX; i++) - pixels[i] = GP_ColorToPixel(i, pixel_type); -} diff --git a/pylib/gfxprim/core/core.i b/pylib/gfxprim/core/core.i index ff0c0629..b0aff173 100644 --- a/pylib/gfxprim/core/core.i +++ b/pylib/gfxprim/core/core.i @@ -28,12 +28,8 @@ %include "GP_Debug.h" /* - * Color and pixel types + * Pixel types */ - -ERROR_ON_NULL(GP_ColorToColorName); - -%include "GP_Color.h" %include "GP_Pixel.h" %include "GP_Pixel.gen.h" /* Includes enum GP_PixelType definition */ %include "GP_Convert.h" -- 2.11.4.GIT