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, master has been updated via 9f1c5605ccc309bc66b098c26590a3a1e35025b2 (commit) from 0850c45f543489686dc6a2984cf104ed2e89b4aa (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/9f1c5605ccc309bc66b098c26590a3a1e3502...
commit 9f1c5605ccc309bc66b098c26590a3a1e35025b2 Author: Cyril Hrubis metan@ucw.cz Date: Tue Jan 3 19:43:28 2012 +0100
gfx: Working on Anti Aliased rectangles
Nearly done
* special cases not yet hanlded
* corners are not drawn correctly
diff --git a/include/core/GP_FixedPoint.h b/include/core/GP_FixedPoint.h new file mode 100644 index 0000000..baf4ed4 --- /dev/null +++ b/include/core/GP_FixedPoint.h @@ -0,0 +1,104 @@ +/***************************************************************************** + * 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-2012 Cyril Hrubis metan@ucw.cz * + * * + *****************************************************************************/ + +/* + + Macros for fixed point arithmetic. + + We use 8 bits for fractional part for coordinates and sizes for Anti Aliased + primitives. + + */ + +#ifndef CORE_GP_FIXED_POINT_H +#define CORE_GP_FIXED_POINT_H + +#include <stdint.h> + +typedef uint8_t GP_FP_Frac; + +/* + * Number of bits used for fractional part. + */ +#define GP_FP_FRAC_BITS 8 + +/* + * One + */ +#define GP_FP_1 (1<<GP_FP_FRAC_BITS) + +/* + * One Half + */ +#define GP_FP_1_2 ((1<<(GP_FP_FRAC_BITS - 1)) + +/* + * Fraction part bitmask. + */ +#define GP_FP_FRAC_MASK ((1<<GP_FP_FRAC_BITS)-1) + +/* + * Addition. + */ +#define GP_FP_ADD(a, b) ((a)+(b)) + +/* + * Substraction. + */ +#define GP_FP_SUB(a, b) ((a)-(b)) + +/* + * Floor. + */ +#define GP_FP_FLOOR(a) ((a)>>GP_FP_FRAC_BITS) + +/* + * Ceilling. + */ +#define GP_FP_CEIL(a) (((a)>>GP_FP_FRAC_BITS) + !!(GP_FP_FRAC(a))) + +/* + * Rounding. + */ +#define GP_FP_ROUND(a) (((a) + GP_FP_1_2))>>GP_FP_FRAC_BITS + +/* + * Integer part. + */ +#define GP_FP_INT(a) GP_FP_FLOOR(a) + +/* + * Fractional part. + */ +#define GP_FP_FRAC(a) ((a) & GP_FP_FRAC_MASK) + +/* + * Returns an float. + */ +#define GP_FP_TO_FLOAT(a) (((float)(a))/((float)GP_FP_1)) + +/* + * Returns fixed point from integer. + */ +#define GP_FP_FROM_INT(a) ((a)<<GP_FP_FRAC_BITS) + +#endif /* CORE_GP_FIXED_POINT_H */ diff --git a/include/core/GP_Transform.h b/include/core/GP_Transform.h index 9ea5eec..cc6e8b4 100644 --- a/include/core/GP_Transform.h +++ b/include/core/GP_Transform.h @@ -19,26 +19,41 @@ * Copyright (C) 2009-2010 Jiri "BlueBear" Dluhos * * jiri.bluebear.dluhos@gmail.com * * * - * Copyright (C) 2009-2010 Cyril Hrubis metan@ucw.cz * + * Copyright (C) 2009-2012 Cyril Hrubis metan@ucw.cz * * * * Copyright (C) 2011 Tomas Gavenciak gavento@ucw.cz * * * *****************************************************************************/
-#ifndef GP_TRANSFORM_H -#define GP_TRANSFORM_H +#ifndef CORE_GP_TRANSFORM_H +#define CORE_GP_TRANSFORM_H + +#include "GP_FixedPoint.h"
/* * Flip a coordinate within context according to context transformation. */ -#define GP_TRANSFORM_X(context, x) do { - if ((context)->x_swap) - x = (context)->w - x - 1; +#define GP_TRANSFORM_X(context, x) do { + if ((context)->x_swap) + x = (context)->w - x - 1; +} while (0) + +#define GP_TRANSFORM_Y(context, y) do { + if ((context)->y_swap) + y = (context)->h - y - 1; } while (0)
-#define GP_TRANSFORM_Y(context, y) do { - if ((context)->y_swap) - y = (context)->h - y - 1; +/* + * Fixed point variants. + */ +#define GP_TRANSFORM_X_FP(context, x) do { + if ((context)->x_swap) + x = GP_FP_FROM_INT((context)->w - 1) - x; +} while (0) + +#define GP_TRANSFORM_Y_FP(context, y) do { + if ((context)->y_swap) + y = GP_FP_FROM_INT((context)->h - 1) - y; } while (0)
/* @@ -59,6 +74,12 @@ GP_TRANSFORM_Y(context, y); } while (0)
+#define GP_TRANSFORM_POINT_FP(context, x, y) do { + GP_TRANSFORM_SWAP(context, x, y); + GP_TRANSFORM_X_FP(context, x); + GP_TRANSFORM_Y_FP(context, y); +} while (0) + /* * Transform "user"-coordinates to "real"-coordinates of a rectangle corner * according to context transformation. Corner with min-coordinates is @@ -68,12 +89,23 @@ #define GP_TRANSFORM_RECT(context, x, y, w, h) do { GP_TRANSFORM_SWAP(context, x, y); GP_TRANSFORM_SWAP(context, w, h); - if ((context)->x_swap) { + + if ((context)->x_swap) x = (context)->w - x - w; - } - if ((context)->y_swap) { + + if ((context)->y_swap) y = (context)->h - y - h; - } +} while (0) + +#define GP_TRANSFORM_RECT_FP(context, x, y, w, h) do { + GP_TRANSFORM_SWAP(context, x, y); + GP_TRANSFORM_SWAP(context, w, h); + + if ((context)->x_swap) + x = GP_FP_FROM_INT((context)->w) - x - w; + + if ((context)->y_swap) + y = GP_FP_FROM_INT((context)->h) - y - h; } while (0)
/* @@ -98,4 +130,4 @@ GP_TRANSFORM_SWAP(context, x, y); } while (0)
-#endif /* GP_TRANSFORM_H */ +#endif /* CORE_GP_TRANSFORM_H */ diff --git a/libs/gfx/GP_RectAA.c b/libs/gfx/GP_RectAA.c index 0939a7f..4225fd0 100644 --- a/libs/gfx/GP_RectAA.c +++ b/libs/gfx/GP_RectAA.c @@ -23,6 +23,7 @@ #include "core/GP_Transform.h" #include "core/GP_GetPutPixel.h" #include "core/GP_MixPixels.h" +#include "core/GP_FixedPoint.h" #include "core/GP_GammaCorrection.h" #include "GP_Rect.h" #include "GP_RectAA.h" @@ -38,62 +39,79 @@ void GP_FillRectXYXY_AA_Raw(GP_Context *context, GP_Coord x0, GP_Coord y0, if (y0 > y1) GP_SWAP(y0, y1);
- /* Draw the full part of the rect */ - GP_FillRect(context, x0>>8, y0>>8, x1>>8, y1>>8, pixel); + GP_Size w = x1 - x0; + GP_Size h = y1 - y0; + + printf("W = %f, H = %f, X = %f, Y = %fn", + GP_FP_TO_FLOAT(w), GP_FP_TO_FLOAT(h), + GP_FP_TO_FLOAT(x0), GP_FP_TO_FLOAT(y0)); + + /* This are integer coordinates of the "inner" rectangle */ + GP_Coord xi0 = GP_FP_CEIL(x0); + GP_Coord yi0 = GP_FP_CEIL(y0); + GP_Coord xi1 = GP_FP_FLOOR(x1); + GP_Coord yi1 = GP_FP_FLOOR(y1); + + if (xi1 >= xi0 && yi1 >= yi0) + GP_FillRect(context, xi0, yi0, xi1, yi1, pixel); + printf("%i %i %i %in", xi0, yi0, yi1, yi1); + /* Draw the "frame" around */ GP_Coord i;
uint8_t u_perc; uint8_t d_perc; - d_perc = GP_GammaToLinear(x0%8); - u_perc = GP_GammaToLinear(x1%8); + u_perc = GP_GammaToLinear(GP_FP_1 - GP_FP_FRAC(y0)); + d_perc = GP_GammaToLinear(GP_FP_FRAC(y1));
- for (i = x0>>8; i <= x1>>8; i++) { - GP_Pixel u = GP_GetPixel(context, i, (y0>>8) - 1); - GP_Pixel d = GP_GetPixel(context, i, (y1>>8) + 1); + for (i = GP_FP_CEIL(x0); i <= GP_FP_FLOOR(x1); i++) { + GP_Pixel u = GP_GetPixel(context, i, GP_FP_FLOOR(y0)); + GP_Pixel d = GP_GetPixel(context, i, GP_FP_CEIL(y1)); u = GP_MixPixels(pixel, u, u_perc, context->pixel_type); d = GP_MixPixels(pixel, d, d_perc, context->pixel_type); - GP_PutPixel(context, i, (y0>>8) - 1, u); - GP_PutPixel(context, i, (y1>>8) + 1, d); + GP_PutPixel(context, i, GP_FP_FLOOR(y0), u); + GP_PutPixel(context, i, GP_FP_CEIL(y1), d); } + + u_perc = GP_GammaToLinear(GP_FP_1 - GP_FP_FRAC(x0)); + d_perc = GP_GammaToLinear(GP_FP_FRAC(x1)); - d_perc = GP_GammaToLinear(y0%8); - u_perc = GP_GammaToLinear(y1%8); - - for (i = y0>>8; i <= y1>>8; i++) { - GP_Pixel u = GP_GetPixel(context, (x0>>8) - 1, i); - GP_Pixel d = GP_GetPixel(context, (x1>>8) + 1, i); + for (i = GP_FP_CEIL(y0); i <= GP_FP_FLOOR(y1); i++) { + GP_Pixel u = GP_GetPixel(context, GP_FP_FLOOR(x0), i); + GP_Pixel d = GP_GetPixel(context, GP_FP_CEIL(x1), i); u = GP_MixPixels(pixel, u, u_perc, context->pixel_type); d = GP_MixPixels(pixel, d, d_perc, context->pixel_type); - GP_PutPixel(context, (x0>>8) - 1, i, u); - GP_PutPixel(context, (x1>>8) + 1, i, d); + GP_PutPixel(context, GP_FP_FLOOR(x0), i, u); + GP_PutPixel(context, GP_FP_CEIL(x1), i, d); }
+ return; + uint8_t perc; GP_Pixel p;
- perc = GP_GammaToLinear((x0%8+y0%8)/2); - p = GP_GetPixel(context, (x0>>8) - 1, (y0>>8) - 1); + perc = GP_GammaToLinear((GP_FP_FRAC(x0) + GP_FP_FRAC(y0) + 1)/2); + p = GP_GetPixel(context, GP_FP_FLOOR(x0), GP_FP_FLOOR(y0)); p = GP_MixPixels(pixel, p, perc, context->pixel_type); - GP_PutPixel(context, (x0>>8) - 1, (y0>>8) - 1, p); + GP_PutPixel(context, GP_FP_FLOOR(x0), GP_FP_FLOOR(y0), p);
- perc = GP_GammaToLinear((x1%8+y0%8)/2); + perc = GP_GammaToLinear((GP_FP_FRAC(x1) + GP_FP_FRAC(y0) + 1)/2); p = GP_GetPixel(context, (x1>>8) + 1, (y0>>8) - 1); p = GP_MixPixels(pixel, p, perc, context->pixel_type); GP_PutPixel(context, (x1>>8) + 1, (y0>>8) - 1, p);
- perc = GP_GammaToLinear((x0%8+y1%8)/2); + perc = GP_GammaToLinear((GP_FP_FRAC(x0) + GP_FP_FRAC(y1) + 1)/2); p = GP_GetPixel(context, (x0>>8) - 1, (y1>>8) + 1); p = GP_MixPixels(pixel, p, perc, context->pixel_type); GP_PutPixel(context, (x0>>8) - 1, (y1>>8) + 1, p); - perc = GP_GammaToLinear((x1%8+y1%8)/2); + perc = GP_GammaToLinear((GP_FP_FRAC(x1) + GP_FP_FRAC(y1) + 1)/2); p = GP_GetPixel(context, (x1>>8) + 1, (y1>>8) + 1); p = GP_MixPixels(pixel, p, perc, context->pixel_type); GP_PutPixel(context, (x1>>8) + 1, (y1>>8) + 1, p); @@ -105,7 +123,8 @@ void GP_FillRectXYWH_AA_Raw(GP_Context *context, GP_Coord x, GP_Coord y, if (w == 0 || h == 0) return;
- GP_FillRectXYXY_AA_Raw(context, x, y, x + w - 1, y + h - 1, pixel); + GP_FillRectXYXY_AA_Raw(context, x, y, + x + w - GP_FP_1, y + h - GP_FP_1, pixel); }
void GP_FillRectXYXY_AA(GP_Context *context, GP_Coord x0, GP_Coord y0, @@ -113,8 +132,8 @@ void GP_FillRectXYXY_AA(GP_Context *context, GP_Coord x0, GP_Coord y0, { GP_CHECK_CONTEXT(context); - GP_TRANSFORM_POINT(context, x0, y0); - GP_TRANSFORM_POINT(context, x1, y1); + GP_TRANSFORM_POINT_FP(context, x0, y0); + GP_TRANSFORM_POINT_FP(context, x1, y1);
GP_FillRect_AA_Raw(context, x0, y0, x1, y1, pixel); } @@ -125,5 +144,6 @@ void GP_FillRectXYWH_AA(GP_Context *context, GP_Coord x, GP_Coord y, if (w == 0 || h == 0) return;
- GP_FillRectXYXY_AA(context, x, y, x + w - 1, y + h - 1, pixel); + GP_FillRectXYXY_AA(context, x, y, + x + w - GP_FP_1, y + h - GP_FP_1, pixel); } diff --git a/tests/SDL/Makefile b/tests/SDL/Makefile index 123889b..8520abb 100644 --- a/tests/SDL/Makefile +++ b/tests/SDL/Makefile @@ -6,7 +6,8 @@ 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 subcontext showimage + symbolstest textaligntest trianglefps input blittest subcontext showimage+ aatest
include $(TOPDIR)/include.mk include $(TOPDIR)/app.mk diff --git a/tests/SDL/aatest.c b/tests/SDL/aatest.c new file mode 100644 index 0000000..247c553 --- /dev/null +++ b/tests/SDL/aatest.c @@ -0,0 +1,165 @@ +/***************************************************************************** + * 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-2012 Cyril Hrubis metan@ucw.cz * + * * + *****************************************************************************/ + +#include <stdio.h> +#include <stdlib.h> +#include <SDL/SDL.h> + +#include "GP.h" +#include "GP_SDL.h" + +SDL_Surface *display = NULL; +GP_Context context; + +static GP_Coord x = 10<<8; +static GP_Coord y = 10<<8; + +SDL_UserEvent timer_event; + +GP_Pixel red_pixel, green_pixel, blue_pixel, white_pixel; + +static void draw(void) +{ + GP_Context *ctx = &context; + + GP_Fill(ctx, white_pixel); + + GP_Coord i; + + for (i = 0; i < 24; i++) { + GP_FillRect_AA(ctx, x, y + ((10*i)<<8), + x + (60<<8), y + ((10*i)<<8) + 64*i + 64, 0); + + GP_FillRect_AA(ctx, x + (80<<8), y + ((10*i)<<8) + 64, + x + (140<<8), y + ((10*i)<<8) + 64*i + 128, 0); + + GP_FillRect_AA(ctx, x + (160<<8), y + ((10*i)<<8) + 128, + x + (220<<8), y + ((10*i)<<8) + 64*i + 192, 0); + + GP_FillRect_AA(ctx, x + (240<<8), y + ((10*i)<<8) + 192, + x + (300<<8), y + ((10*i)<<8) + 64*i + 256, 0); + printf("--------------------------------------------------------n"); + } + + SDL_Flip(display); +} + +void event_loop(void) +{ + SDL_Event event; + + while (SDL_WaitEvent(&event) > 0) { + switch (event.type) { + case SDL_KEYDOWN: + switch (event.key.keysym.sym) { + case SDLK_DOWN: + y += 64; + draw(); + break; + case SDLK_UP: + y -= 64; + draw(); + break; + case SDLK_LEFT: + x -= 64; + draw(); + break; + case SDLK_RIGHT: + x += 64; + draw(); + break; + case SDLK_x: + context.x_swap = !context.x_swap; + draw(); + break; + case SDLK_y: + context.y_swap = !context.y_swap; + draw(); + break; + case SDLK_r: + context.axes_swap = !context.axes_swap; + draw(); + break; + case SDLK_ESCAPE: + case SDLK_q: + return; + default: + break; + } + break; + case SDL_QUIT: + return; + } + } +} + +int main(int argc, char **argv) +{ + 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; + } + } + + if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) != 0) { + fprintf(stderr, "Could not initialize SDL: %sn", SDL_GetError()); + return 1; + } + + display = SDL_SetVideoMode(320, 240, display_bpp, SDL_SWSURFACE); + if (display == NULL) { + fprintf(stderr, "Could not open display: %sn", SDL_GetError()); + goto fail; + } + + + printf("Display surface properties:n"); + printf(" width: %4d, height: %4d, pitch: %4dn", + display->w, display->h, display->pitch); + printf(" bits per pixel: %2d, bytes per pixel: %2dn", + display->format->BitsPerPixel, display->format->BytesPerPixel); + + GP_SDL_ContextFromSurface(&context, display); + + red_pixel = GP_ColorToContextPixel(GP_COL_RED, &context); + green_pixel = GP_ColorToContextPixel(GP_COL_GREEN, &context); + blue_pixel = GP_ColorToContextPixel(GP_COL_BLUE, &context); + white_pixel = GP_ColorToContextPixel(GP_COL_WHITE, &context); + + draw(); + + event_loop(); + SDL_Quit(); + return 0; + +fail: + SDL_Quit(); + return 1; +}
-----------------------------------------------------------------------
Summary of changes: .../core/{GP_GammaCorrection.h => GP_FixedPoint.h} | 83 +++++++++++-- include/core/GP_Transform.h | 60 +++++++-- libs/gfx/GP_RectAA.c | 74 +++++++---- tests/SDL/Makefile | 3 +- tests/SDL/{pixeltest.c => aatest.c} | 126 ++++++++++---------- 5 files changed, 226 insertions(+), 120 deletions(-) copy include/core/{GP_GammaCorrection.h => GP_FixedPoint.h} (58%) copy tests/SDL/{pixeltest.c => aatest.c} (66%)
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.