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 2d34007fde18efe7a66079b899a16eae0bfd2dbc (commit) from f7289bd299e2a2414ab8b69f692f6e36f701a2e3 (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/2d34007fde18efe7a66079b899a16eae0bfd2...
commit 2d34007fde18efe7a66079b899a16eae0bfd2dbc Author: Cyril Hrubis metan@ucw.cz Date: Sun Jul 17 20:25:45 2011 +0200
Changed GP_Color api.
* GP_Color is now enum * Color Name is string
diff --git a/include/core/GP_Color.h b/include/core/GP_Color.h index 1fddae9..8bda861 100644 --- a/include/core/GP_Color.h +++ b/include/core/GP_Color.h @@ -23,13 +23,20 @@ * * *****************************************************************************/
+ /* + + Color. + + */ + #ifndef GP_COLOR_H #define GP_COLOR_H
#include "GP_Context.h" #include "GP_Pixel.h"
-typedef enum GP_ColorName { +typedef enum GP_Color { + GP_COL_INVALID = -1, GP_COL_BLACK, GP_COL_RED, GP_COL_GREEN, @@ -42,8 +49,23 @@ typedef enum GP_ColorName { GP_COL_PURPLE, GP_COL_WHITE, GP_COL_MAX, -} GP_ColorName; +} GP_Color; + +/* + * Converts Color to Pixel + */ +GP_Pixel GP_ColorToPixel(GP_Context *context, GP_Color col); + +/* + * Converts Color name to Color. + */ +GP_Color GP_ColorNameToColor(const char *color_name); + +const char *GP_ColorToColorName(GP_Color col);
-GP_Pixel GP_ColorNameToPixel(GP_Context *context, GP_ColorName name); +/* + * Converts Color name to Pixel. + */ +GP_Pixel GP_ColorNameToPixel(GP_Context *context, const char *color_name);
#endif /* GP_COLOR_H */ diff --git a/libs/core/GP_Color.c b/libs/core/GP_Color.c index 19906e3..b6981d9 100644 --- a/libs/core/GP_Color.c +++ b/libs/core/GP_Color.c @@ -28,40 +28,71 @@ #include "GP_Color.h"
#include <stdint.h> +#include <string.h>
static char *color_names[] = { - "black ", - "red ", - "green ", - "blue ", - "yellow ", - "brown ", - "orange ", - "gray dark ", - "gray light", - "purple ", - "white " + "Black", + "Red", + "Green", + "Blue", + "Yellow", + "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 */ - {0xa5, 0x2a, 0x2a}, /* brown */ - {0xff, 0xa5, 0x00}, /* orange */ - {0x7f, 0x7f, 0x7f}, /* gray dark */ - {0xbe, 0xbe, 0xbe}, /* gray light */ - {0xa0, 0x20, 0xf0}, /* purple */ - {0xff, 0xff, 0xff}, /* white */ + {0x00, 0x00, 0x00}, /* Black */ + {0xff, 0x00, 0x00}, /* Red */ + {0x00, 0xff, 0x00}, /* Green */ + {0x00, 0x00, 0xff}, /* Blue */ + {0xff, 0xff, 0x00}, /* Yellow */ + {0xa5, 0x2a, 0x2a}, /* Brown */ + {0xff, 0xa5, 0x00}, /* Orange */ + {0x7f, 0x7f, 0x7f}, /* DarkGray */ + {0xbe, 0xbe, 0xbe}, /* LigthGray */ + {0xa0, 0x20, 0xf0}, /* Purple */ + {0xff, 0xff, 0xff}, /* White */ };
-GP_Pixel GP_ColorNameToPixel(GP_Context *context, GP_ColorName name) +GP_Pixel GP_ColorToPixel(GP_Context *context, GP_Color col) { - GP_ASSERT(name < GP_COL_MAX); + GP_ASSERT(col < GP_COL_MAX); + GP_ASSERT(col >= 0);
- return GP_RGBToPixel(rgb888_colors[name][0], - rgb888_colors[name][1], - rgb888_colors[name][2], context->pixel_type); + return GP_RGBToPixel(rgb888_colors[col][0], + rgb888_colors[col][1], + rgb888_colors[col][2], context->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 col) +{ + if (col < 0 || col >= GP_COL_MAX) + return NULL; + + return color_names[col]; +} + +GP_Pixel GP_ColorNameToPixel(GP_Context *context, const char *color_name) +{ + GP_Color col = GP_ColorNameToColor(color_name); + + if (col < 0) + return 0; + + return GP_ColorToPixel(context, col); } diff --git a/tests/SDL/fileview.c b/tests/SDL/fileview.c index d7eead9..4bbe940 100644 --- a/tests/SDL/fileview.c +++ b/tests/SDL/fileview.c @@ -237,12 +237,12 @@ int main(int argc, char *argv[]) GP_SDL_ContextFromSurface(&context, display);
/* Load colors suitable for the display */ - white_pixel = GP_ColorNameToPixel(&context, GP_COL_WHITE); - gray_pixel = GP_ColorNameToPixel(&context, GP_COL_GRAY_LIGHT); - dark_gray_pixel = GP_ColorNameToPixel(&context, GP_COL_GRAY_DARK); - black_pixel = GP_ColorNameToPixel(&context, GP_COL_BLACK); - red_pixel = GP_ColorNameToPixel(&context, GP_COL_RED); - blue_pixel = GP_ColorNameToPixel(&context, GP_COL_BLUE); + white_pixel = GP_ColorToPixel(&context, GP_COL_WHITE); + gray_pixel = GP_ColorToPixel(&context, GP_COL_GRAY_LIGHT); + dark_gray_pixel = GP_ColorToPixel(&context, GP_COL_GRAY_DARK); + black_pixel = GP_ColorToPixel(&context, GP_COL_BLACK); + red_pixel = GP_ColorToPixel(&context, GP_COL_RED); + blue_pixel = GP_ColorToPixel(&context, GP_COL_BLUE);
redraw_screen(); SDL_Flip(display); diff --git a/tests/SDL/fonttest.c b/tests/SDL/fonttest.c index 788f652..91f42fc 100644 --- a/tests/SDL/fonttest.c +++ b/tests/SDL/fonttest.c @@ -231,12 +231,12 @@ int main(int argc, char *argv[]) GP_SDL_ContextFromSurface(&context, display);
/* Load colors suitable for the display */ - white_pixel = GP_ColorNameToPixel(&context, GP_COL_WHITE); - gray_pixel = GP_ColorNameToPixel(&context, GP_COL_GRAY_LIGHT); - dark_gray_pixel = GP_ColorNameToPixel(&context, GP_COL_GRAY_DARK); - black_pixel = GP_ColorNameToPixel(&context, GP_COL_BLACK); - red_pixel = GP_ColorNameToPixel(&context, GP_COL_RED); - blue_pixel = GP_ColorNameToPixel(&context, GP_COL_BLUE); + white_pixel = GP_ColorToPixel(&context, GP_COL_WHITE); + gray_pixel = GP_ColorToPixel(&context, GP_COL_GRAY_LIGHT); + dark_gray_pixel = GP_ColorToPixel(&context, GP_COL_GRAY_DARK); + black_pixel = GP_ColorToPixel(&context, GP_COL_BLACK); + red_pixel = GP_ColorToPixel(&context, GP_COL_RED); + blue_pixel = GP_ColorToPixel(&context, GP_COL_BLUE);
redraw_screen(); SDL_Flip(display); diff --git a/tests/SDL/linetest.c b/tests/SDL/linetest.c index 7012804..245b1ce 100644 --- a/tests/SDL/linetest.c +++ b/tests/SDL/linetest.c @@ -124,8 +124,8 @@ int main(int argc, char **argv) GP_SDL_ContextFromSurface(&context, display);
/* Load colors in display format */ - black = GP_ColorNameToPixel(&context, GP_COL_BLACK); - white = GP_ColorNameToPixel(&context, GP_COL_WHITE); + black = GP_ColorToPixel(&context, GP_COL_BLACK); + white = GP_ColorToPixel(&context, GP_COL_WHITE);
/* Set up the refresh timer */ timer = SDL_AddTimer(30, timer_callback, NULL); diff --git a/tests/SDL/pixeltest.c b/tests/SDL/pixeltest.c index 5ea47a1..467a17b 100644 --- a/tests/SDL/pixeltest.c +++ b/tests/SDL/pixeltest.c @@ -156,10 +156,10 @@ int main(int argc, char **argv) GP_SDL_ContextFromSurface(&context, display);
/* Load pixel values compatible with the display. */ - red_pixel = GP_ColorNameToPixel(&context, GP_COL_RED); - green_pixel = GP_ColorNameToPixel(&context, GP_COL_GREEN); - blue_pixel = GP_ColorNameToPixel(&context, GP_COL_BLUE); - white_pixel = GP_ColorNameToPixel(&context, GP_COL_WHITE); + red_pixel = GP_ColorToPixel(&context, GP_COL_RED); + green_pixel = GP_ColorToPixel(&context, GP_COL_GREEN); + blue_pixel = GP_ColorToPixel(&context, GP_COL_BLUE); + white_pixel = GP_ColorToPixel(&context, GP_COL_WHITE);
/* Set up the refresh timer */ timer = SDL_AddTimer(30, timer_callback, NULL); diff --git a/tests/SDL/randomshapetest.c b/tests/SDL/randomshapetest.c index 61c9f6f..592d466 100644 --- a/tests/SDL/randomshapetest.c +++ b/tests/SDL/randomshapetest.c @@ -89,13 +89,11 @@ void draw_random_circle(GP_Pixel pixel) random_point(display, &x, &y); int r = random() % 50;
- if (fill_flag) { + if (fill_flag) GP_FillCircle(&context, x, y, r, pixel); - }
- if (outline_flag) { + if (outline_flag) GP_Circle(&context, x, y, r, white); - } }
void draw_random_ellipse(GP_Pixel pixel) @@ -105,13 +103,11 @@ void draw_random_ellipse(GP_Pixel pixel) int rx = random() % 50; int ry = random() % 50;
- if (fill_flag) { + if (fill_flag) GP_FillEllipse(&context, x, y, rx, ry, pixel); - }
- if (outline_flag) { + if (outline_flag) GP_Ellipse(&context, x, y, rx, ry, white); - } }
void draw_random_triangle(GP_Pixel pixel) @@ -121,13 +117,11 @@ void draw_random_triangle(GP_Pixel pixel) random_point(display, &x1, &y1); random_point(display, &x2, &y2);
- if (fill_flag) { + if (fill_flag) GP_FillTriangle(&context, x0, y0, x1, y1, x2, y2, pixel); - }
- if (outline_flag) { + if (outline_flag) GP_Triangle(&context, x0, y0, x1, y1, x2, y2, white); - } }
void draw_random_rectangle(GP_Pixel pixel) @@ -136,13 +130,11 @@ void draw_random_rectangle(GP_Pixel pixel) random_point(display, &x0, &y0); random_point(display, &x1, &y1);
- if (fill_flag) { + if (fill_flag) GP_FillRect(&context, x0, y0, x1, y1, pixel); - }
- if (outline_flag) { + if (outline_flag) GP_Rect(&context, x0, y0, x1, y1, white); - } }
void draw_random_tetragon(GP_Pixel pixel) @@ -153,13 +145,11 @@ void draw_random_tetragon(GP_Pixel pixel) random_point(display, &x2, &y2); random_point(display, &x3, &y3);
- if (fill_flag) { + if (fill_flag) GP_FillTetragon(&context, x0, y0, x1, y1, x2, y2, x3, y3, pixel); - }
- if (outline_flag) { + if (outline_flag) GP_Tetragon(&context, x0, y0, x1, y1, x2, y2, x3, y3, pixel); - } }
void clear_screen(void) @@ -178,7 +168,8 @@ void redraw_screen(void)
/* Pick a random color for drawing. */ GP_Pixel pixel; - pixel = GP_RGBToPixel(&context, random() % 256, random() % 256, random() % 256); + pixel = GP_RGBToPixel(random() % 256, random() % 256, + random() % 256, context.pixel_type);
switch (shape) { case SHAPE_CIRCLE: @@ -309,8 +300,8 @@ int main(int argc, char *argv[])
GP_SDL_ContextFromSurface(&context, display);
- white = GP_ColorNameToPixel(&context, GP_COL_WHITE); - black = GP_ColorNameToPixel(&context, GP_COL_BLACK); + white = GP_ColorToPixel(&context, GP_COL_WHITE); + black = GP_ColorToPixel(&context, GP_COL_BLACK);
/* Set up the refresh timer */ timer = SDL_AddTimer(60, timer_callback, NULL); diff --git a/tests/SDL/shapetest.c b/tests/SDL/shapetest.c index 44f04cf..f91d94e 100644 --- a/tests/SDL/shapetest.c +++ b/tests/SDL/shapetest.c @@ -136,9 +136,8 @@ void draw_testing_triangle(int x, int y, int xradius, int yradius) if (outline == 1) GP_TTriangle(&context, x0, y0, x1, y1, x2, y2, yellow);
- if (fill) { + if (fill) GP_TFillTriangle(&context, x0, y0, x1, y1, x2, y2, red); - }
if (outline == 2) GP_TTriangle(&context, x0, y0, x1, y1, x2, y2, white); @@ -284,17 +283,16 @@ void event_loop(void) break; case SDLK_f: fill = !fill; - if (!fill && !outline) { + if (!fill && !outline) outline = 1; - } break;
case SDLK_o: outline++; - if (outline == 3) { outline = 0; } - if (!fill && outline == 0) { + if (outline == 3) + outline = 0; + if (!fill && outline == 0) fill = 1; - } break;
case SDLK_a: @@ -463,13 +461,13 @@ int main(int argc, char ** argv) GP_SDL_ContextFromSurface(&context, display);
/* Load colors compatible with the display */ - black = GP_ColorNameToPixel(&context, GP_COL_BLACK); - white = GP_ColorNameToPixel(&context, GP_COL_WHITE); - yellow = GP_ColorNameToPixel(&context, GP_COL_YELLOW); - green = GP_ColorNameToPixel(&context, GP_COL_GREEN); - red = GP_ColorNameToPixel(&context, GP_COL_RED); - gray = GP_ColorNameToPixel(&context, GP_COL_GRAY_LIGHT); - darkgray = GP_ColorNameToPixel(&context, GP_COL_GRAY_DARK); + black = GP_ColorToPixel(&context, GP_COL_BLACK); + white = GP_ColorToPixel(&context, GP_COL_WHITE); + yellow = GP_ColorToPixel(&context, GP_COL_YELLOW); + green = GP_ColorToPixel(&context, GP_COL_GREEN); + red = GP_ColorToPixel(&context, GP_COL_RED); + gray = GP_ColorToPixel(&context, GP_COL_GRAY_LIGHT); + darkgray = GP_ColorToPixel(&context, GP_COL_GRAY_DARK);
/* Set up the refresh timer */ timer = SDL_AddTimer(60, timer_callback, NULL); diff --git a/tests/SDL/sierpinsky.c b/tests/SDL/sierpinsky.c index 333107f..b2e6dd8 100644 --- a/tests/SDL/sierpinsky.c +++ b/tests/SDL/sierpinsky.c @@ -55,7 +55,7 @@ static void sierpinsky(double x1, double y1, double x4, double y4, int iter) { double x2, y2, x3, y3, x5, y5; GP_Pixel pixel; - pixel = GP_RGBToPixel(context, 0, 0, 255-16*iter); + pixel = GP_RGBToPixel(0, 0, 255-16*iter, context->pixel_type); if (iter <= 0) { if (draw_edge) @@ -162,10 +162,10 @@ int main(void) display = SDL_GetVideoSurface(); context = GP_GetBackendVideoContext();
- black = GP_ColorNameToPixel(context, GP_COL_BLACK); - blue = GP_ColorNameToPixel(context, GP_COL_BLUE); - gray = GP_ColorNameToPixel(context, GP_COL_GRAY_LIGHT); - red = GP_ColorNameToPixel(context, GP_COL_RED); + black = GP_ColorToPixel(context, GP_COL_BLACK); + blue = GP_ColorToPixel(context, GP_COL_BLUE); + gray = GP_ColorToPixel(context, GP_COL_GRAY_LIGHT); + red = GP_ColorToPixel(context, GP_COL_RED);
iter = 0; draw(display->w/2, display->h/2, l, iter); diff --git a/tests/SDL/symbolstest.c b/tests/SDL/symbolstest.c index 532c13a..e7fd0a3 100644 --- a/tests/SDL/symbolstest.c +++ b/tests/SDL/symbolstest.c @@ -172,7 +172,7 @@ int main(int argc, char *argv[])
GP_SDL_ContextFromSurface(&context, display);
- black = GP_ColorNameToPixel(&context, GP_COL_BLACK); + black = GP_ColorToPixel(&context, GP_COL_BLACK); /* Set up the refresh timer */ timer = SDL_AddTimer(60, timer_callback, NULL); diff --git a/tests/SDL/textaligntest.c b/tests/SDL/textaligntest.c index 348eab7..f7872ac 100644 --- a/tests/SDL/textaligntest.c +++ b/tests/SDL/textaligntest.c @@ -159,9 +159,9 @@ int main(void) GP_SDL_ContextFromSurface(&context, display);
/* Load colors suitable for the display */ - black_pixel = GP_ColorNameToPixel(&context, GP_COL_BLACK); - red_pixel = GP_ColorNameToPixel(&context, GP_COL_RED); - blue_pixel = GP_ColorNameToPixel(&context, GP_COL_BLUE); + black_pixel = GP_ColorToPixel(&context, GP_COL_BLACK); + red_pixel = GP_ColorToPixel(&context, GP_COL_RED); + blue_pixel = GP_ColorToPixel(&context, GP_COL_BLUE);
redraw_screen(); SDL_Flip(display); diff --git a/tests/SDL/trianglefps.c b/tests/SDL/trianglefps.c index 17c0604..cf163bf 100644 --- a/tests/SDL/trianglefps.c +++ b/tests/SDL/trianglefps.c @@ -159,8 +159,8 @@ int main(int argc, char ** argv)
GP_SDL_ContextFromSurface(&context, display);
- white = GP_ColorNameToPixel(&context, GP_COL_WHITE); - black = GP_ColorNameToPixel(&context, GP_COL_BLACK); + white = GP_ColorToPixel(&context, GP_COL_WHITE); + black = GP_ColorToPixel(&context, GP_COL_BLACK);
/* Set up the timer */ timer = SDL_AddTimer(1000, timer_callback, NULL);
-----------------------------------------------------------------------
Summary of changes: include/core/GP_Color.h | 28 +++++++++++++-- libs/core/GP_Color.c | 85 +++++++++++++++++++++++++++++-------------- tests/SDL/fileview.c | 12 +++--- tests/SDL/fonttest.c | 12 +++--- tests/SDL/linetest.c | 4 +- tests/SDL/pixeltest.c | 8 ++-- tests/SDL/randomshapetest.c | 37 +++++++------------ tests/SDL/shapetest.c | 26 ++++++------- tests/SDL/sierpinsky.c | 10 +++--- tests/SDL/symbolstest.c | 2 +- tests/SDL/textaligntest.c | 6 ++-- tests/SDL/trianglefps.c | 4 +- 12 files changed, 138 insertions(+), 96 deletions(-)
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.