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 bdecc49ad74d5d50032ba686e53eb98c5bec913e (commit) via f2727c95f0c8d87bb9ad90c581e36c3acfa55b91 (commit) from ce1f7e60318bc537190107fef5834338da94706d (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/bdecc49ad74d5d50032ba686e53eb98c5bec9...
commit bdecc49ad74d5d50032ba686e53eb98c5bec913e Author: Cyril Hrubis metan@ucw.cz Date: Sun Aug 28 11:19:33 2011 +0200
Added experimental subcontext support.
* Works only for byte aligned pixels. * Clipping is broken on some primitives.
diff --git a/include/core/GP_Context.h b/include/core/GP_Context.h index 4c620b8..e5f62bf 100644 --- a/include/core/GP_Context.h +++ b/include/core/GP_Context.h @@ -50,6 +50,7 @@ typedef struct GP_Context { uint8_t x_swap:1; /* swap direction on x */ uint8_t y_swap:1; /* swap direction on y */ uint8_t bit_endian:1; /* GP_BIT_ENDIAN */ + uint8_t free_pixels:1; /* If set pixels are freed on GP_ContextFree */ } GP_Context;
/* Returns the pixel type used by the context. */ @@ -88,7 +89,7 @@ static inline GP_PixelType GP_GetContextPixelType(const GP_Context *context) /* * Allocate context. */ -GP_Context *GP_ContextAlloc(uint32_t w, uint32_t h, GP_PixelType type); +GP_Context *GP_ContextAlloc(GP_Size w, GP_Size h, GP_PixelType type);
/* * If passed the pixels are copied to newly created context, otherwise @@ -102,6 +103,12 @@ GP_Context *GP_ContextAlloc(uint32_t w, uint32_t h, GP_PixelType type); GP_Context *GP_ContextCopy(GP_Context *context, int flag);
/* + * Create subcontext. + */ +GP_Context *GP_ContextSubContext(GP_Context *context, GP_Coord x, GP_Coord y, + GP_Size w, GP_Size h); + +/* * Converts context to different pixel type. * * This is naive implementation that doesn't do any ditherings or error diff --git a/libs/core/GP_Context.c b/libs/core/GP_Context.c index af6ef26..fffabba 100644 --- a/libs/core/GP_Context.c +++ b/libs/core/GP_Context.c @@ -63,12 +63,14 @@ GP_Context *GP_ContextCopy(GP_Context *context, int flag) new->axes_swap = context->axes_swap; new->y_swap = context->y_swap; new->x_swap = context->x_swap; + + new->free_pixels = 1;
return new; }
-GP_Context *GP_ContextAlloc(uint32_t w, uint32_t h, GP_PixelType type) +GP_Context *GP_ContextAlloc(GP_Size w, GP_Size h, GP_PixelType type) { GP_Context *context = malloc(sizeof(GP_Context)); uint32_t bpp = GP_PixelSize(type); @@ -96,6 +98,8 @@ GP_Context *GP_ContextAlloc(uint32_t w, uint32_t h, GP_PixelType type) context->axes_swap = 0; context->y_swap = 0; context->x_swap = 0; + + context->free_pixels = 1;
return context; } @@ -114,10 +118,47 @@ GP_Context *GP_ContextConvert(const GP_Context *context, GP_PixelType res_type)
void GP_ContextFree(GP_Context *context) { - free(context->pixels); + if (context == NULL) + return; + + if (context->free_pixels) + free(context->pixels); + free(context); }
+GP_Context *GP_ContextSubContext(GP_Context *context, GP_Coord x, GP_Coord y, + GP_Size w, GP_Size h) +{ + GP_CHECK(context, "NULL context"); + GP_CHECK(context->w >= x + w, "Subcontext w out of original context."); + GP_CHECK(context->h >= y + h, "Subcontext h out of original context."); + + GP_Context *ret = malloc(sizeof(GP_Context)); + + if (ret == NULL) + return NULL; + + ret->bpp = context->bpp; + ret->bytes_per_row = context->bytes_per_row; + + ret->w = w; + ret->h = h; + + ret->pixel_type = context->pixel_type; + + /* rotation and mirroring */ + ret->axes_swap = context->axes_swap; + ret->y_swap = context->y_swap; + ret->x_swap = context->x_swap; + + ret->pixels = GP_PIXEL_ADDR(context, x, y); + + ret->free_pixels = 0; + + return ret; +} + GP_RetCode GP_ContextDump(GP_Context *context, const char *path) { FILE *f = fopen(path, "w"); diff --git a/tests/SDL/Makefile b/tests/SDL/Makefile index 22292e5..d99fdb9 100644 --- a/tests/SDL/Makefile +++ b/tests/SDL/Makefile @@ -6,7 +6,7 @@ INCLUDE=core gfx SDL backends LDLIBS+=-lGP -L$(TOPDIR)/build/ -lGP_SDL -lSDL
APPS=pixeltest fileview fonttest linetest randomshapetest shapetest sierpinsky- symbolstest textaligntest trianglefps input blittest + symbolstest textaligntest trianglefps input blittest subcontext
include $(TOPDIR)/include.mk include $(TOPDIR)/app.mk diff --git a/tests/SDL/subcontext.c b/tests/SDL/subcontext.c new file mode 100644 index 0000000..963e8e8 --- /dev/null +++ b/tests/SDL/subcontext.c @@ -0,0 +1,277 @@ +/***************************************************************************** + * 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-2011 Cyril Hrubis metan@ucw.cz * + * * + *****************************************************************************/ + +#include <stdio.h> +#include <stdlib.h> +#include <math.h> +#include <SDL/SDL.h> + +#include "GP.h" +#include "GP_SDL.h" + +static GP_Pixel black, white, gray, red, green; + +SDL_Surface *display = NULL; +GP_Context context, *sub_context; + +SDL_TimerID timer; + +SDL_UserEvent timer_event; + +static int pause_flag = 0; +static int draw_flag = 0; + +Uint32 timer_callback(__attribute__((unused)) Uint32 interval, + __attribute__((unused)) void *param) +{ + timer_event.type = SDL_USEREVENT; + SDL_PushEvent((SDL_Event *) &timer_event); + return 10; +} + +static void draw_line(GP_Context *dest, GP_Coord x, GP_Coord y, + GP_Size w, GP_Size h, GP_Color col) +{ + GP_Coord x1, x2, y1, y2; + + x1 = random() % w + x; + y1 = random() % h + y; + x2 = random() % w + x; + y2 = random() % h + y; + + GP_Line(dest, x1, y1, x2, y2, col); +} + +static void draw_triangle(GP_Context *dest, GP_Coord x, GP_Coord y, + GP_Size w, GP_Size h, GP_Color col, int flag) +{ + GP_Coord x1, x2, x3, y1, y2, y3; + + x1 = random() % w + x; + y1 = random() % h + y; + x2 = random() % w + x; + y2 = random() % h + y; + x3 = random() % w + x; + y3 = random() % h + y; + + if (flag) + GP_FillTriangle(dest, x1, y1, x2, y2, x3, y3, col); + else + GP_Triangle(dest, x1, y1, x2, y2, x3, y3, col); +} + +static void draw_rect(GP_Context *dest, GP_Coord x, GP_Coord y, + GP_Size w, GP_Size h, GP_Color col, int flag) +{ + GP_Coord x1, x2, y1, y2; + + x1 = random() % w + x; + y1 = random() % h + y; + x2 = random() % w + x; + y2 = random() % h + y; + + if (flag) + GP_FillRect(dest, x1, y1, x2, y2, col); + else + GP_Rect(dest, x1, y1, x2, y2, col); +} + +static void draw_circle(GP_Context *dest, GP_Coord x, GP_Coord y, + GP_Size w, GP_Size h, GP_Color col, int flag) +{ + GP_Coord x1, y1, r; + + r = random() % 150; + + x1 = random() % (w - 2*r) + x + r; + y1 = random() % (h - 2*r) + y + r; + + if (flag) + GP_FillCircle(dest, x1, y1, r, col); + else + GP_Circle(dest, x1, y1, r, col); +} + +#define TEXT "Lorem Ipsum Dolor Sit Amet" + +static void draw_text(GP_Context *dest, GP_Coord x, GP_Coord y, + GP_Size w, GP_Size h, GP_Color col) +{ + GP_Coord x1, y1; + GP_Size tw, th; + + tw = GP_TextWidth(NULL, TEXT); + th = GP_TextHeight(NULL); + + x1 = random() % (w - tw) + x; + y1 = random() % (h - th) + y; + + GP_Text(dest, NULL, x1, y1, GP_ALIGN_RIGHT|GP_VALIGN_BOTTOM, TEXT, col); +} + +void redraw_screen(void) +{ + if (pause_flag) + return; + + SDL_LockSurface(display); + + uint8_t v = random() % 128 + 50; + GP_Color col = GP_RGBToContextPixel(v, v, 255, sub_context); + + /* frame around subcontext */ + GP_Rect(&context, 99, 99, context.w - 100, context.h - 100, white); + + switch (draw_flag) { + case 0: + draw_line(sub_context, -100, -100, sub_context->w + 200, sub_context->h + 200, col); + break; + case 1: + draw_triangle(sub_context, -100, -100, sub_context->w + 200, sub_context->h + 200, col, 0); + break; + case 2: + draw_triangle(sub_context, -100, -100, sub_context->w + 200, sub_context->h + 200, col, 1); + break; + case 3: + draw_rect(sub_context, -100, -100, sub_context->w + 200, sub_context->h + 200, col, 0); + break; + case 4: + draw_rect(sub_context, -100, -100, sub_context->w + 200, sub_context->h + 200, col, 1); + break; + case 5: + draw_circle(sub_context, -100, -100, sub_context->w + 200, sub_context->h + 200, col, 0); + break; + case 6: + draw_circle(sub_context, -100, -100, sub_context->w + 200, sub_context->h + 200, col, 1); + break; + case 7: + draw_text(sub_context, -100, -100, sub_context->w + 200, sub_context->h + 200, col); + break; + } + + SDL_Flip(display); + + SDL_UnlockSurface(display); +} + +void clear_screen(void) +{ + GP_Fill(&context, black); + GP_Fill(sub_context, gray); +} + +void event_loop(void) +{ + SDL_Event event; + + while (SDL_WaitEvent(&event) > 0) { + + switch (event.type) { + + case SDL_USEREVENT: + redraw_screen(); + break; + case SDL_KEYDOWN: + switch (event.key.keysym.sym) { + case SDLK_p: + pause_flag = !pause_flag; + break; + case SDLK_SPACE: + draw_flag = (draw_flag + 1) % 8; + clear_screen(); + break; + case SDLK_ESCAPE: + return; + + default: + break; + } + break; + case SDL_QUIT: + return; + default: + break; + } + } +} + +int main(int argc, char *argv[]) +{ + /* Bits per pixel to be set for the display surface. */ + int display_bpp = 0; + + int i; + for (i = 1; i < argc; i++) { + if (strcmp(argv[i], "-16") == 0) { + display_bpp = 16; + } + else if (strcmp(argv[i], "-24") == 0) { + display_bpp = 24; + } + else if (strcmp(argv[i], "-32") == 0) { + display_bpp = 32; + } + } + + GP_SetDebugLevel(10); + + if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) != 0) { + fprintf(stderr, "Could not initialize SDL: %sn", SDL_GetError()); + return 1; + } + + display = SDL_SetVideoMode(640, 480, display_bpp, SDL_SWSURFACE); + if (display == NULL) { + fprintf(stderr, "Could not open display: %sn", SDL_GetError()); + goto fail; + } + + GP_SDL_ContextFromSurface(&context, display); + + black = GP_ColorToPixel(&context, GP_COL_BLACK); + white = GP_ColorToPixel(&context, GP_COL_WHITE); + gray = GP_ColorToPixel(&context, GP_COL_GRAY_DARK); + red = GP_ColorToPixel(&context, GP_COL_RED); + green = GP_ColorToPixel(&context, GP_COL_GREEN); + + sub_context = GP_ContextSubContext(&context, 100, 100, 440, 280); + GP_Fill(sub_context, gray); + + timer = SDL_AddTimer(60, timer_callback, NULL); + if (timer == 0) { + fprintf(stderr, "Could not set up timer: %sn", SDL_GetError()); + goto fail; + } + + event_loop(); + + SDL_Quit(); + return 0; + +fail: + SDL_Quit(); + return 1; +} +
http://repo.or.cz/w/gfxprim.git/commit/f2727c95f0c8d87bb9ad90c581e36c3acfa55...
commit f2727c95f0c8d87bb9ad90c581e36c3acfa55b91 Author: Cyril Hrubis metan@ucw.cz Date: Sun Aug 28 11:18:49 2011 +0200
Made the TextMetric use default style.
diff --git a/libs/text/GP_Text.c b/libs/text/GP_Text.c index 073561d..65f025c 100644 --- a/libs/text/GP_Text.c +++ b/libs/text/GP_Text.c @@ -29,7 +29,7 @@ #include "core/GP_DefFnPerBpp.h" #include "GP_Text.h"
-static GP_TextStyle DefaultStyle = GP_DEFAULT_TEXT_STYLE; +GP_TextStyle GP_DefaultStyle = GP_DEFAULT_TEXT_STYLE;
/* Generate drawing functions for various bit depths. */ GP_DEF_FILL_FN_PER_BPP(GP_Text_Raw, DEF_TEXT_FN) @@ -44,7 +44,7 @@ GP_RetCode GP_Text_Raw(GP_Context *context, const GP_TextStyle *style, return GP_ENULLPTR;
if (style == NULL) - style = &DefaultStyle; + style = &GP_DefaultStyle; GP_CHECK_TEXT_STYLE(style);
@@ -100,7 +100,7 @@ GP_RetCode GP_Text(GP_Context *context, const GP_TextStyle *style, return GP_ENULLPTR;
if (style == NULL) - style = &DefaultStyle; + style = &GP_DefaultStyle; GP_CHECK_TEXT_STYLE(style);
@@ -152,7 +152,7 @@ GP_RetCode GP_BoxCenteredText_Raw(GP_Context *context, const GP_TextStyle *style return GP_ENULLPTR;
if (style == NULL) - style = &DefaultStyle; + style = &GP_DefaultStyle; GP_CHECK_TEXT_STYLE(style);
@@ -176,7 +176,7 @@ GP_RetCode GP_BoxCenteredText(GP_Context *context, const GP_TextStyle *style, return GP_ENULLPTR;
if (style == NULL) - style = &DefaultStyle; + style = &GP_DefaultStyle; GP_CHECK_TEXT_STYLE(style);
diff --git a/libs/text/GP_TextMetric.c b/libs/text/GP_TextMetric.c index cac94cf..d22acc9 100644 --- a/libs/text/GP_TextMetric.c +++ b/libs/text/GP_TextMetric.c @@ -19,13 +19,15 @@ * Copyright (C) 2009-2010 Jiri "BlueBear" Dluhos * * jiri.bluebear.dluhos@gmail.com * * * - * Copyright (C) 2009-2010 Cyril Hrubis metan@ucw.cz * + * Copyright (C) 2009-2011 Cyril Hrubis metan@ucw.cz * * * *****************************************************************************/
#include "core/GP_Common.h" #include "GP_TextMetric.h"
+extern GP_TextStyle GP_DefaultStyle; + static unsigned int SpaceWidth(const GP_TextStyle *style) { //TODO: Does space change with pixel_yspace? @@ -59,11 +61,15 @@ static unsigned int MaxCharsWidth(const GP_TextStyle *style, const char *str)
unsigned int GP_TextWidth(const GP_TextStyle *style, const char *str) { - GP_CHECK_TEXT_STYLE(style); GP_CHECK(str, "NULL string specified"); unsigned int i, len = 0; - unsigned int space = SpaceWidth(style); + unsigned int space; + + if (style == NULL) + style = &GP_DefaultStyle; + + space = SpaceWidth(style);
if (str[0] == '0') return 0; @@ -76,11 +82,14 @@ unsigned int GP_TextWidth(const GP_TextStyle *style, const char *str)
unsigned int GP_TextMaxWidth(const GP_TextStyle *style, unsigned int len) { - GP_CHECK_TEXT_STYLE(style); - unsigned int space_width = SpaceWidth(style); - unsigned int char_width = style->font->max_bounding_width - * (style->pixel_xmul + style->pixel_xspace); + unsigned int char_width; + + if (style == NULL) + style = &GP_DefaultStyle; + + char_width = style->font->max_bounding_width + * (style->pixel_xmul + style->pixel_xspace);
if (len == 0) return 0; @@ -91,12 +100,16 @@ unsigned int GP_TextMaxWidth(const GP_TextStyle *style, unsigned int len) unsigned int GP_TextMaxStrWidth(const GP_TextStyle *style, const char *str, unsigned int len) { - GP_CHECK_TEXT_STYLE(style); GP_CHECK(str, "NULL string specified");
- unsigned int space_width = SpaceWidth(style); + unsigned int space_width; unsigned int char_width; + if (style == NULL) + style = &GP_DefaultStyle; + + space_width = SpaceWidth(style); + if (len == 0) return 0;
@@ -107,7 +120,8 @@ unsigned int GP_TextMaxStrWidth(const GP_TextStyle *style, const char *str,
unsigned int GP_TextHeight(const GP_TextStyle *style) { - GP_CHECK_TEXT_STYLE(style); + if (style == NULL) + style = &GP_DefaultStyle;
return style->font->height * style->pixel_ymul + (style->font->height - 1) * style->pixel_yspace; @@ -115,17 +129,25 @@ unsigned int GP_TextHeight(const GP_TextStyle *style)
unsigned int GP_TextAscent(const GP_TextStyle *style) { - GP_CHECK_TEXT_STYLE(style); + unsigned int h; + + if (style == NULL) + style = &GP_DefaultStyle;
- unsigned int h = style->font->height - style->font->baseline; + h = style->font->height - style->font->baseline; + return h * style->pixel_ymul + (h - 1) * style->pixel_yspace; }
unsigned int GP_TextDescent(const GP_TextStyle *style) { - GP_CHECK_TEXT_STYLE(style); + unsigned int h; + + if (style == NULL) + style = &GP_DefaultStyle;
- unsigned int h = style->font->baseline; + h = style->font->baseline; + return h * style->pixel_ymul + (h - 1) * style->pixel_yspace; }
-----------------------------------------------------------------------
Summary of changes: include/core/GP_Context.h | 9 ++- libs/core/GP_Context.c | 45 ++++++++- libs/text/GP_Text.c | 10 +- libs/text/GP_TextMetric.c | 50 ++++++--- tests/SDL/Makefile | 2 +- tests/SDL/{blittest.c => subcontext.c} | 186 +++++++++++++++++++++---------- 6 files changed, 219 insertions(+), 83 deletions(-) copy tests/SDL/{blittest.c => subcontext.c} (53%)
repo.or.cz automatic notification. Contact project admin jiri.bluebear.dluhos@gmail.com if you want to unsubscribe, or site admin admin@repo.or.cz if you receive no reply.