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 bcb2459351a67a9e7e5eabaf1fe081cc1aa724bd (commit) via 42be3cae59405f7867c489e4be12f85c40e4a54e (commit) via dbcb0965a2d31e572ab897d23ca4cbc14377fc02 (commit) via 5df856f5af17bd0922b99fc21c1236f01f3d2f27 (commit) via 5261b44a10e5bcf3d7abd86d97076161449b2ef4 (commit) via e1e008bfb7e62140b69da17b0a6b30eed15de653 (commit) via 4fddc1754f1d4f739c318adb305041595efbfa1f (commit) via 79adf5cfb66ddd38140c64f8015be735bad2a985 (commit) via ca0579cff49cfb79bcc2382c4508a8c5aef6f04e (commit) via d082267d9e82e53500d0989dbc158a1725cc68b4 (commit) via 6a75eaa20c6561c387c324b8013e1ff04517b33b (commit) via 382a79d9e517a63ab444030f0003c045c3c55d17 (commit) from f5c3fdd85dc385b05af7f41ede836a6074fb4c3c (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/bcb2459351a67a9e7e5eabaf1fe081cc1aa72...
commit bcb2459351a67a9e7e5eabaf1fe081cc1aa724bd Author: Cyril Hrubis metan@ucw.cz Date: Tue Jun 12 21:00:55 2012 +0200
build: Add gfxprim-config into the .gitignore
diff --git a/.gitignore b/.gitignore index 7d18a2b..7007e36 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ *.a config.h config.gen.mk +gfxprim-config
http://repo.or.cz/w/gfxprim.git/commit/42be3cae59405f7867c489e4be12f85c40e4a...
commit 42be3cae59405f7867c489e4be12f85c40e4a54e Author: Cyril Hrubis metan@ucw.cz Date: Tue Jun 12 18:49:05 2012 +0200
core: Slight cleanup in GP_Context.
The most notable changes are:
* Split the subcontext API into two functions
* Split the ContextConvert API into two functions
* Added inline helpers for rotation flags handling
* Added GP_ContextPrintInfo() function
+ Various cleanups and fixups.
diff --git a/demos/spiv/spiv.c b/demos/spiv/spiv.c index 72d8595..11d24bf 100644 --- a/demos/spiv/spiv.c +++ b/demos/spiv/spiv.c @@ -154,7 +154,8 @@ GP_Context *load_image(struct loader_params *params, int elevate) /* Workaround */ if (img->pixel_type != GP_PIXEL_RGB888) { - GP_Context *tmp = GP_ContextConvert(img, GP_PIXEL_RGB888); + GP_Context *tmp; + tmp = GP_ContextConvertAlloc(img, GP_PIXEL_RGB888); GP_ContextFree(img); img = tmp; } @@ -307,7 +308,7 @@ static void *image_loader(void *ptr) if (dithering) { callback.priv = "Dithering"; - GP_ContextSubContext(context, &sub_display, cx, cy, img->w, img->h); + GP_SubContext(context, &sub_display, cx, cy, img->w, img->h); // GP_FilterFloydSteinberg_RGB888(ret, &sub_display, NULL); GP_FilterHilbertPeano_RGB888(img, &sub_display, NULL); } else { diff --git a/doc/context.txt b/doc/context.txt index 809f995..f92473c 100644 --- a/doc/context.txt +++ b/doc/context.txt @@ -1,7 +1,7 @@ Drawing Context ---------------
-The 'GP_Context' structure describes a bitmap in memory. It contains all +The 'GP_Context' structure describes an 'in memory' memory. It contains all metadata needed for drawing into a bitmap.
Data Structure @@ -22,7 +22,7 @@ typedef struct GP_Context { */ uint8_t offset;
- GP_PixelType pixel_type; /* pixel format enum */ + enum GP_PixelType pixel_type; /* pixel format */
uint8_t axes_swap:1; /* swap axes */ uint8_t x_swap:1; /* mirror x */ @@ -42,8 +42,8 @@ Rotation
The orientation flags affects the gfx and text drawing functions and blits. If some of the flags is changed the origin and direction of the drawing is -changed. Note that the image pixels are not affected by this at all only the -coordinates passed to drawing functions are transformed accordingly. +changed accordingly. Note that the image pixels are not affected by this at +all only the coordinates passed to drawing functions are transformed.
If you don't need this functionality just don't touch the flags the as overhead of these transformations is not measurable. @@ -81,12 +81,28 @@ GP_RETRANSFORM_POINT(context, x, y) /* * Rotate context flags clock wise. */ -void GP_ContextFlagsRotateCW(GP_Context *context); +void GP_ContextRotateCW(GP_Context *context);
/* * Rotate context flags counter clock wise. */ -void GP_ContextFlagsRotateCCW(GP_Context *context); +void GP_ContextRotateCCW(GP_Context *context); + +/* + * Retruns 1 if rotation flags are equal. + */ +int GP_ContextRotationEqual(const GP_Context *c1, const GP_Context *c2); + +/* + * Sets context rotation flags. + */ +void GP_ContextSetRotation(GP_Context *dst, int axes_swap, + int x_swap, int y_swap); + +/* + * Copies rotation flags. + */ +void GP_ContextCopyRotation(const GP_Context *src, GP_Context *dst);
/* * Returns context width and height taking the rotation flags into the account. @@ -104,8 +120,8 @@ Basic context functions /* or */ #include <GP.h>
-void GP_ContextInit(GP_Context *context, GP_Size w, GP_Size h, - GP_PixelType type, void *pixels); +GP_Context *GP_ContextInit(GP_Context *context, GP_Size w, GP_Size h, + GP_PixelType type, void *pixels); -------------------------------------------------------------------------------
Initialize given context accordingly to parameters, the rest of context @@ -116,6 +132,9 @@ bytes per row are computed from the given pixel type and size. The 'pixels' pointer can be 'NULL' and can be changed later manually (the call will *not* try to allocate the pixel memory automatically).
+The function returns a pointer to the initialized context (i.e. the same +pointer you passed as second argument). + [source,c] ------------------------------------------------------------------------------- #include <core/GP_Context.h> @@ -138,13 +157,34 @@ appropriate size; the initial contents of the bitmap are undefined. /* or */ #include <GP.h>
-GP_Context *GP_ContextCopy(const GP_Context *src, int flag); +enum GP_ContextCopyFlags { + /* + * Copy bitmap pixels too. If not set pixels are uninitialized. + */ + GP_COPY_WITH_PIXELS = 0x01, + /* + * Copy image rotation flags. If not set flags are set to (0, 0, 0). + */ + GP_COPY_WITH_ROTATION = 0x02, +}; + +GP_Context *GP_ContextCopy(const GP_Context *src, int flags); -------------------------------------------------------------------------------
The 'GP_ContextCopy()' allocates and initializes a copy of the context passed -as argument. If 'flag' is set, the bitmap contents ('src->pixels') -are also copied; otherwise the copy will have the same dimensions but -undefined contents. +as arguments. + +The call returns pointer to newly allocated context or in case of 'malloc()' +failure NULL. + +If 'GP_COPY_WITH_PIXELS' is set, the bitmap contents ('src->pixels') are also +copied; otherwise the copy will have the same dimensions but undefined +contents. + +If 'GP_COPY_WITH_ROTATION' is set rotation flags are copied; otherwise rotation +flags are set to zero. + +The 'free_pixels' flag for the resulting context is set.
[source,c] ------------------------------------------------------------------------------- @@ -163,10 +203,16 @@ Subcontext
A subcontext is a context that refers to a rectangular area within another context. Subcontexts can be used as any other context (including creating -another subcontexts). +another subcontexts). Generally the subcontexts behave exactly as any other +contexts with one exception, if you create several overlapping subcontexts the +results may be unexpected.
-Calling 'GP_ContextFree()' on a subcontext is safe; the bitmap is not freed as -it belongs to another context; it will be freed with the hosting context. +Calling 'GP_ContextFree()' on a allocated subcontext is safe; the bitmap is not +freed as it belongs to another context; it will be freed with the hosting +context (i.e. the 'free_pixels' flag is not set when creating subcontext). On +the other hand, the subcontext doesn't hold a reference to the original +context, so once the parent context is freed the subcontext pixel pointer is +not valid anymore.
[source,c] ------------------------------------------------------------------------------- @@ -174,18 +220,23 @@ it belongs to another context; it will be freed with the hosting context. /* or */ #include <GP.h>
-GP_Context *GP_ContextSubContext(GP_Context *context, GP_Context *subcontext, - GP_Coord x, GP_Coord y, GP_Size w, GP_Size h); +GP_Context *GP_SubContext(const GP_Context *context, GP_Context *subcontext, + GP_Coord x, GP_Coord y, GP_Size w, GP_Size h); + +GP_Context *GP_SubContextAlloc(const GP_Context *context, + GP_Coord x, GP_Coord y, GP_Size w, GP_Size h); -------------------------------------------------------------------------------
Creates subcontext of a context. The rectangular area must fit into the context.
-If subcontext pointer is 'NULL', the context structure is allocated; otherwise -the metadata are filled into the context structure pointed by subcontext -pointer. +The 'GP_SubContext()' function initializes the passed pointer as a subcontext +of a context and returns pointer to initialized subcontext (i.e. the same +pointer you passed as the subcontext parameter).
-In both cases, the call returns either a pointer to the new subcontext, -or NULL on failure (when there is not enough memory). +The 'GP_SubContextAlloc()' function allocates 'GP_Context' structure and +initializes it as a subcontext. This function may return NULL in case of +'malloc()' failure and the newly created context should be later freed with +'GP_ContextFree()'.
Conversions ~~~~~~~~~~~ @@ -196,13 +247,30 @@ Conversions /* or */ #include <GP.h>
-GP_Context *GP_ContextConvert(const GP_Context *src, GP_Context *dst, - GP_PixelType dst_pixel_type); +GP_Context *GP_ContextConvertAlloc(const GP_Context *src, + GP_PixelType dst_pixel_type); + +GP_Context *GP_ContextConvert(const GP_Context *src, GP_Context *dst); + -------------------------------------------------------------------------------
-Provides basic context conversion functionality. A newly allocated context is -returned. +Converts a context to different pixel type. + +This is naive implementation that only multiplies/divides the pixel values. + +To get a better result use dithering filters instead. + +Misc +~~~~
-This function does no error distribution, it only multiplies or rounds the pixel -values. If you need something better use Floyd Steinberg dithering instead. +[source,c] +------------------------------------------------------------------------------- +#include <core/GP_Context.h> +/* or */ +#include <GP.h> + +void GP_ContextPrintInfo(const GP_Context *self); +-------------------------------------------------------------------------------
+This function prints the content of 'GP_Context' structure, in a readable +format, into the stdout. diff --git a/include/core/GP_Context.h b/include/core/GP_Context.h index 494199a..feed975 100644 --- a/include/core/GP_Context.h +++ b/include/core/GP_Context.h @@ -36,7 +36,7 @@ /* This structure holds all information needed for drawing into an image. */ typedef struct GP_Context { uint8_t *pixels; /* pointer to image pixels */ - uint8_t bpp; /* pixel length in bits */ + uint8_t bpp; /* pixel size in bits */ uint32_t bytes_per_row; uint32_t w; /* width in pixels */ uint32_t h; /* height in pixels */ @@ -47,14 +47,15 @@ typedef struct GP_Context { */ uint8_t offset;
- GP_PixelType pixel_type; /* hardware pixel format */ + enum GP_PixelType pixel_type; /* pixel format */
- /* image orientation. Most common is landscape (0, 0, 0), + /* + * Image orientation. Most common is landscape (0, 0, 0), * portrait with normal topleft corner is (1, 0, 0). */ uint8_t axes_swap:1; /* swap axes so that x is y and y is x */ - uint8_t x_swap:1; /* swap direction on x */ - uint8_t y_swap:1; /* swap direction on y */ + 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; @@ -87,54 +88,70 @@ typedef struct GP_Context { || (y) < 0 || y >= (typeof(y)) context->h) /* - * Check for exactly same rotation flags. + * Allocate context. + * + * The context consists of two parts, the GP_Context structure and pixels array. + * + * The rotation flags are set to (0, 0, 0). */ -#define GP_CONTEXT_ROTATION_EQUAL(c1, c2) - ((c1)->axes_swap == (c2)->axes_swap && - (c1)->x_swap == (c2)->x_swap && - (c1)->y_swap == (c2)->y_swap) +GP_Context *GP_ContextAlloc(GP_Size w, GP_Size h, GP_PixelType type);
/* - * Allocate context. + * Free context. + * + * If context->free_pixels, also free pixel data. */ -GP_Context *GP_ContextAlloc(GP_Size w, GP_Size h, GP_PixelType type); +void GP_ContextFree(GP_Context *context);
/* * Initalize context, pixels pointer is not dereferenced so it's safe to pass * NULL there and allocate it later with size context->bpr * context->h. + * + * The returned pointer is the pointer you passed as first argument. */ -void GP_ContextInit(GP_Context *context, GP_Size w, GP_Size h, - GP_PixelType type, void *pixels); +GP_Context *GP_ContextInit(GP_Context *context, GP_Size w, GP_Size h, + GP_PixelType type, void *pixels);
/* - * Resizes context->pixels array and changes metadata to match. + * Resizes context->pixels array and changes metadata to match the new size. + * + * Returns non-zero on failure (malloc() has failed). * - * Returns non-zero on failure (remalloc() has failed). + * This call only resizes the pixel array. The pixel values, after resizing, + * are __UNINITALIZED__ use resampling filters to resize image data. */ int GP_ContextResize(GP_Context *context, GP_Size w, GP_Size h);
+enum GP_ContextCopyFlags { + /* + * Copy bitmap pixels too. If not set pixels are uninitalized. + */ + GP_COPY_WITH_PIXELS = 0x01, + /* + * Copy image rotation flags. If not set flags are set to (0, 0, 0). + */ + GP_COPY_WITH_ROTATION = 0x02, +}; + /* - * If passed the pixels are copied to newly created context, otherwise - * the pixels are allocated but uninitalized. + * Allocates a contex with exactly same values as source context. */ -#define GP_COPY_WITH_PIXELS 1 +GP_Context *GP_ContextCopy(const GP_Context *src, int flags);
/* - * Copy context. + * Initalize subcontext. The returned pointer points to passed subcontext. */ -GP_Context *GP_ContextCopy(const GP_Context *src, int flag); +GP_Context *GP_SubContext(const GP_Context *context, GP_Context *subcontext, + GP_Coord x, GP_Coord y, GP_Size w, GP_Size h);
/* - * Create subcontext. + * Allocate and initalize subcontext. * - * If pointer to subcontext is NULL, new context is allocated - * otherwise context pointed by subcontext pointer is initalized. - * * The free_pixels flag is set to 0 upon subcontext initalization so the * GP_ContextFree() would not call free() upon the subcontext->pixels pointer. */ -GP_Context *GP_ContextSubContext(GP_Context *context, GP_Context *subcontext, - GP_Coord x, GP_Coord y, GP_Size w, GP_Size h); +GP_Context *GP_SubContextAlloc(const GP_Context *context, + GP_Coord x, GP_Coord y, GP_Size w, GP_Size h);
/* * Converts context to a different pixel type. @@ -143,30 +160,64 @@ GP_Context *GP_ContextSubContext(GP_Context *context, GP_Context *subcontext, * This is naive implementation that doesn't do any ditherings or error * diffusions. */ -GP_Context *GP_ContextConvert(const GP_Context *src, - GP_PixelType dst_pixel_type); +GP_Context *GP_ContextConvertAlloc(const GP_Context *src, + GP_PixelType dst_pixel_type);
/* - * Prints context information into stdout. + * Converts context to a different pixel type. + * + * This is naive implementation that doesn't do any ditherings or error + * diffusions. */ -void GP_ContextInfoPrint(const GP_Context *self); +GP_Context *GP_ContextConvert(const GP_Context *src, GP_Context *dst);
/* - * Free context. - * - * If context->free_pixels, also free pixel data. + * Prints context information into stdout. */ -void GP_ContextFree(GP_Context *context); +void GP_ContextPrintInfo(const GP_Context *self);
/* * Rotates context flags clock wise. */ -void GP_ContextFlagsRotateCW(GP_Context *context); +void GP_ContextRotateCW(GP_Context *context);
/* * Rotates context flags counter clock wise. */ -void GP_ContextFlagsRotateCCW(GP_Context *context); +void GP_ContextRotateCCW(GP_Context *context); + +/* + * Retruns 1 if rotation flags are equal. + */ +static inline int GP_ContextRotationEqual(const GP_Context *c1, + const GP_Context *c2) +{ + return c1->axes_swap == c2->axes_swap && + c1->x_swap == c2->x_swap && + c1->y_swap == c2->y_swap; +} + +/* + * Sets rotation flags. + */ +static inline void GP_ContextSetRotation(GP_Context *dst, int axes_swap, + int x_swap, int y_swap) +{ + dst->axes_swap = axes_swap; + dst->x_swap = x_swap; + dst->y_swap = y_swap; +} + +/* + * Copies rotation flags. + */ +static inline void GP_ContextCopyRotation(const GP_Context *src, + GP_Context *dst) +{ + dst->axes_swap = src->axes_swap; + dst->x_swap = src->x_swap; + dst->y_swap = src->y_swap; +}
/* * Returns context width and height taking the rotation flags into a account. diff --git a/libs/core/GP_Blit.c b/libs/core/GP_Blit.c index eadfe1d..58e818a 100644 --- a/libs/core/GP_Blit.c +++ b/libs/core/GP_Blit.c @@ -77,7 +77,7 @@ void GP_BlitXYXY(const GP_Context *src, GP_CHECK(x2 + (x1 - x0) < (GP_Coord)GP_ContextW(dst)); GP_CHECK(y2 + (y1 - y0) < (GP_Coord)GP_ContextH(dst));
- if (GP_CONTEXT_ROTATION_EQUAL(src, dst)) + if (GP_ContextRotationEqual(src, dst)) GP_BlitXYXY_Raw_Fast(src, x0, y0, x1, y1, dst, x2, y2); else GP_BlitXYXY_Fast(src, x0, y0, x1, y1, dst, x2, y2); @@ -138,7 +138,7 @@ void GP_BlitXYXY_Clipped(const GP_Context *src, x0, y0, x1, y1, GP_ContextW(src), GP_ContextH(src), x2, y2, GP_ContextW(dst), GP_ContextH(dst));
- if (GP_CONTEXT_ROTATION_EQUAL(src, dst)) + if (GP_ContextRotationEqual(src, dst)) GP_BlitXYXY_Raw_Fast(src, x0, y0, x1, y1, dst, x2, y2); else GP_BlitXYXY_Fast(src, x0, y0, x1, y1, dst, x2, y2); diff --git a/libs/core/GP_Context.c b/libs/core/GP_Context.c index c7b2d89..3cf3ecf 100644 --- a/libs/core/GP_Context.c +++ b/libs/core/GP_Context.c @@ -19,57 +19,19 @@ * Copyright (C) 2009-2011 Jiri "BlueBear" Dluhos * * jiri.bluebear.dluhos@gmail.com * * * - * Copyright (C) 2009-2011 Cyril Hrubis metan@ucw.cz * + * Copyright (C) 2009-2012 Cyril Hrubis metan@ucw.cz * * * *****************************************************************************/
-#include "GP_Core.h" +#include "GP_Debug.h" +#include "GP_Transform.h" +#include "GP_Pixel.h" +#include "GP_GetPutPixel.h" +#include "GP_Context.h" #include "GP_Blit.h"
#include <string.h>
-GP_Context *GP_ContextCopy(const GP_Context *src, int flag) -{ - GP_Context *new; - uint8_t *pixels; - - if (src == NULL) - return NULL; - - new = malloc(sizeof(GP_Context)); - pixels = malloc(src->bytes_per_row * src->h); - - if (pixels == NULL || new == NULL) { - free(pixels); - free(new); - return NULL; - } - - new->pixels = pixels; - - if (flag) - memcpy(pixels, src->pixels, src->bytes_per_row * src->h); - - new->bpp = src->bpp; - new->bytes_per_row = src->bytes_per_row; - new->offset = 0; - - new->w = src->w; - new->h = src->h; - - new->pixel_type = src->pixel_type; - new->bit_endian = src->bit_endian; - - /* rotation and mirroring */ - new->axes_swap = src->axes_swap; - new->y_swap = src->y_swap; - new->x_swap = src->x_swap; - - new->free_pixels = 1; - - return new; -} - static uint32_t get_bpr(uint32_t bpp, uint32_t w) { return (bpp * w) / 8 + !!((bpp * w) % 8); @@ -78,16 +40,18 @@ static uint32_t get_bpr(uint32_t bpp, uint32_t w) GP_Context *GP_ContextAlloc(GP_Size w, GP_Size h, GP_PixelType type) { GP_CHECK_VALID_PIXELTYPE(type); - GP_Context *context = malloc(sizeof(GP_Context)); + GP_Context *context; uint32_t bpp = GP_PixelSize(type); uint32_t bpr = get_bpr(bpp, w); void *pixels;
pixels = malloc(bpr * h); + context = malloc(sizeof(GP_Context));
if (pixels == NULL || context == NULL) { free(pixels); free(context); + GP_WARN("Malloc failed :("); return NULL; }
@@ -100,19 +64,55 @@ GP_Context *GP_ContextAlloc(GP_Size w, GP_Size h, GP_PixelType type) context->h = h;
context->pixel_type = type; - #warning Hmm, bit endianity... Why isn't this settled by different pixel types? + #warning Hmm, bit endianity... Why is not this settled by different pixel types? context->bit_endian = 0; /* rotation and mirroring */ - context->axes_swap = 0; - context->y_swap = 0; - context->x_swap = 0; - + GP_ContextSetRotation(context, 0, 0, 0); + context->free_pixels = 1;
return context; }
+void GP_ContextFree(GP_Context *context) +{ + GP_DEBUG(1, "Freeing context (%p)", context); + + if (context == NULL) + return; + + if (context->free_pixels) + free(context->pixels); + + free(context); +} + +GP_Context *GP_ContextInit(GP_Context *context, GP_Size w, GP_Size h, + GP_PixelType type, void *pixels) +{ + uint32_t bpp = GP_PixelSize(type); + uint32_t bpr = get_bpr(bpp, w); + + context->pixels = pixels; + context->bpp = bpp; + context->bytes_per_row = bpr; + context->offset = 0; + + context->w = w; + context->h = h; + + context->pixel_type = type; + context->bit_endian = 0; + + /* rotation and mirroring */ + GP_ContextSetRotation(context, 0, 0, 0); + + context->free_pixels = 0; + + return context; +} + int GP_ContextResize(GP_Context *context, GP_Size w, GP_Size h) { uint32_t bpr = get_bpr(context->bpp, w); @@ -131,57 +131,92 @@ int GP_ContextResize(GP_Context *context, GP_Size w, GP_Size h) return 0; }
-void GP_ContextInit(GP_Context *context, GP_Size w, GP_Size h, - GP_PixelType type, void *pixels) +GP_Context *GP_ContextCopy(const GP_Context *src, int flags) { - uint32_t bpp = GP_PixelSize(type); - uint32_t bpr = get_bpr(bpp, w); + GP_Context *new; + uint8_t *pixels;
- context->pixels = pixels; - context->bpp = bpp; - context->bytes_per_row = bpr; - context->offset = 0; + if (src == NULL) + return NULL;
- context->w = w; - context->h = h; + new = malloc(sizeof(GP_Context)); + pixels = malloc(src->bytes_per_row * src->h);
- context->pixel_type = type; - context->bit_endian = 0; + if (pixels == NULL || new == NULL) { + free(pixels); + free(new); + GP_WARN("Malloc failed :("); + return NULL; + }
- /* rotation and mirroring */ - context->axes_swap = 0; - context->y_swap = 0; - context->x_swap = 0; + new->pixels = pixels; + + if (flags & GP_COPY_WITH_PIXELS) + memcpy(pixels, src->pixels, src->bytes_per_row * src->h); + + new->bpp = src->bpp; + new->bytes_per_row = src->bytes_per_row; + new->offset = 0; + + new->w = src->w; + new->h = src->h; + + new->pixel_type = src->pixel_type; + new->bit_endian = src->bit_endian; + + if (flags & GP_COPY_WITH_ROTATION) + GP_ContextCopyRotation(src, new); + else + GP_ContextSetRotation(new, 0, 0, 0); - context->free_pixels = 0; + new->free_pixels = 1; + + return new; }
-GP_Context *GP_ContextConvert(const GP_Context *src, - GP_PixelType dst_pixel_type) + +GP_Context *GP_ContextConvertAlloc(const GP_Context *src, + GP_PixelType dst_pixel_type) { int w = GP_ContextW(src); int h = GP_ContextH(src); + GP_Context *ret = GP_ContextAlloc(w, h, dst_pixel_type); + if (ret == NULL) return NULL;
GP_Blit(src, 0, 0, w, h, ret, 0, 0); + return ret; }
-void GP_ContextFree(GP_Context *context) +GP_Context *GP_ContextConvert(const GP_Context *src, GP_Context *dst) { - if (context == NULL) - return; + //TODO: Asserts + int w = GP_ContextW(src); + int h = GP_ContextH(src); + + GP_Blit(src, 0, 0, w, h, dst, 0, 0);
- if (context->free_pixels) - free(context->pixels); + return dst; +}
- free(context); +GP_Context *GP_SubContextAlloc(const GP_Context *context, + GP_Coord x, GP_Coord y, GP_Size w, GP_Size h) +{ + GP_Context *res = malloc(sizeof(GP_Context)); + + if (res == NULL) { + GP_WARN("Malloc failed :("); + return NULL; + } + + return GP_SubContext(context, res, x, y, w, h); }
-GP_Context *GP_ContextSubContext(GP_Context *context, GP_Context *subcontext, - GP_Coord x, GP_Coord y, GP_Size w, GP_Size h) +GP_Context *GP_SubContext(const GP_Context *context, GP_Context *subcontext, + GP_Coord x, GP_Coord y, GP_Size w, GP_Size h) { GP_CHECK(context, "NULL context");
@@ -190,46 +225,36 @@ GP_Context *GP_ContextSubContext(GP_Context *context, GP_Context *subcontext, 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 = subcontext; - - if (ret == NULL) { - ret = malloc(sizeof(GP_Context)); + subcontext->bpp = context->bpp; + subcontext->bytes_per_row = context->bytes_per_row; + subcontext->offset = (context->offset + + GP_PixelAddrOffset(x, context->pixel_type)) % 8;
- if (ret == NULL) - return NULL; - } - - ret->bpp = context->bpp; - ret->bytes_per_row = context->bytes_per_row; - ret->offset = (context->offset + - GP_PixelAddrOffset(x, context->pixel_type)) % 8; + subcontext->w = w; + subcontext->h = h;
- ret->w = w; - ret->h = h; - - ret->pixel_type = context->pixel_type; - ret->bit_endian = context->bit_endian; + subcontext->pixel_type = context->pixel_type; + subcontext->bit_endian = context->bit_endian;
/* rotation and mirroring */ - ret->axes_swap = context->axes_swap; - ret->y_swap = context->y_swap; - ret->x_swap = context->x_swap; + GP_ContextCopyRotation(context, subcontext);
- ret->pixels = GP_PIXEL_ADDR(context, x, y); + subcontext->pixels = GP_PIXEL_ADDR(context, x, y);
- ret->free_pixels = 0; + subcontext->free_pixels = 0;
- return ret; + return subcontext; }
-void GP_ContextInfoPrint(const GP_Context *self) +void GP_ContextPrintInfo(const GP_Context *self) { printf("Context infon"); printf("------------n"); printf("Sizet%ux%un", self->w, self->h); printf("BPPt%un", self->bpp); printf("BPRt%un", self->bytes_per_row); - printf("Pixelt%sn", GP_PixelTypeName(self->pixel_type)); + printf("Pixelt%s (%u)n", GP_PixelTypeName(self->pixel_type), + self->pixel_type); printf("Offsett%u (only unaligned pixel types)n", self->offset); printf("Flagstaxes_swap=%u x_swap=%u y_swap=%u free_pixels=%un", self->axes_swap, self->x_swap, self->y_swap, self->free_pixels); @@ -258,7 +283,7 @@ void GP_ContextInfoPrint(const GP_Context *self) * 0 1 0 * */ -void GP_ContextFlagsRotateCW(GP_Context *context) +void GP_ContextRotateCW(GP_Context *context) { context->axes_swap = !context->axes_swap;
@@ -280,7 +305,7 @@ void GP_ContextFlagsRotateCW(GP_Context *context) context->y_swap = 0; }
-void GP_ContextFlagsRotateCCW(GP_Context *context) +void GP_ContextRotateCCW(GP_Context *context) { context->axes_swap = !context->axes_swap;
diff --git a/libs/filters/GP_Resize.c b/libs/filters/GP_Resize.c index 76d1621..81db9ed 100644 --- a/libs/filters/GP_Resize.c +++ b/libs/filters/GP_Resize.c @@ -702,7 +702,7 @@ GP_Context *GP_FilterResize(const GP_Context *src, GP_Context *dst, /* * The size of w and h is asserted in subcontext initalization */ - res = GP_ContextSubContext(dst, &sub, 0, 0, w, h); + res = GP_SubContext(dst, &sub, 0, 0, w, h); }
/* diff --git a/pylib/gfxprim/core/core.i b/pylib/gfxprim/core/core.i index 86b0233..bfd4649 100644 --- a/pylib/gfxprim/core/core.i +++ b/pylib/gfxprim/core/core.i @@ -91,14 +91,14 @@ and self.thisown.") GP_Context; ERROR_ON_NONZERO(GP_ContextResize); ERROR_ON_NULL(GP_ContextAlloc); ERROR_ON_NULL(GP_ContextCopy); -ERROR_ON_NULL(GP_ContextSubContext); -ERROR_ON_NULL(GP_ContextConvert); +ERROR_ON_NULL(GP_ContextConvertAlloc); +ERROR_ON_NULL(GP_SubContextAlloc);
/* Indicate new wrapper-owned GP_Context */ %newobject GP_ContextAlloc; %newobject GP_ContextCopy; -%newobject GP_ContextSubContext; -%newobject GP_ContextConvert; +%newobject GP_ContextConvertAlloc; +%newobject GP_SubContextAlloc;
%include "GP_Context.h"
diff --git a/tests/SDL/blittest.c b/tests/SDL/blittest.c index 2d09436..c23776c 100644 --- a/tests/SDL/blittest.c +++ b/tests/SDL/blittest.c @@ -212,7 +212,7 @@ int main(int argc, char *argv[])
GP_SDL_ContextFromSurface(&context, display); - bitmap_conv = GP_ContextConvert(bitmap_raw, context.pixel_type); + bitmap_conv = GP_ContextConvertAlloc(bitmap_raw, context.pixel_type); change_bitmap();
black = GP_ColorToContextPixel(GP_COL_BLACK, &context); diff --git a/tests/SDL/subcontext.c b/tests/SDL/subcontext.c index 5147ddf..a9348e6 100644 --- a/tests/SDL/subcontext.c +++ b/tests/SDL/subcontext.c @@ -260,7 +260,7 @@ int main(int argc, char *argv[]) white = GP_ColorToContextPixel(GP_COL_WHITE, &context); gray = GP_ColorToContextPixel(GP_COL_GRAY_DARK, &context);
- sub_context = GP_ContextSubContext(&context, NULL, 100, 100, 440, 280); + sub_context = GP_SubContextAlloc(&context, 100, 100, 440, 280); GP_Fill(sub_context, gray);
timer = SDL_AddTimer(60, timer_callback, NULL);
http://repo.or.cz/w/gfxprim.git/commit/dbcb0965a2d31e572ab897d23ca4cbc14377f...
commit dbcb0965a2d31e572ab897d23ca4cbc14377fc02 Author: Cyril Hrubis metan@ucw.cz Date: Tue Jun 12 15:22:06 2012 +0200
core: Add GP_ContextInfoPrint().
diff --git a/include/core/GP_Context.h b/include/core/GP_Context.h index 5057481..494199a 100644 --- a/include/core/GP_Context.h +++ b/include/core/GP_Context.h @@ -147,6 +147,11 @@ GP_Context *GP_ContextConvert(const GP_Context *src, GP_PixelType dst_pixel_type);
/* + * Prints context information into stdout. + */ +void GP_ContextInfoPrint(const GP_Context *self); + +/* * Free context. * * If context->free_pixels, also free pixel data. diff --git a/libs/core/GP_Context.c b/libs/core/GP_Context.c index 3226c1c..c7b2d89 100644 --- a/libs/core/GP_Context.c +++ b/libs/core/GP_Context.c @@ -222,6 +222,19 @@ GP_Context *GP_ContextSubContext(GP_Context *context, GP_Context *subcontext, return ret; }
+void GP_ContextInfoPrint(const GP_Context *self) +{ + printf("Context infon"); + printf("------------n"); + printf("Sizet%ux%un", self->w, self->h); + printf("BPPt%un", self->bpp); + printf("BPRt%un", self->bytes_per_row); + printf("Pixelt%sn", GP_PixelTypeName(self->pixel_type)); + printf("Offsett%u (only unaligned pixel types)n", self->offset); + printf("Flagstaxes_swap=%u x_swap=%u y_swap=%u free_pixels=%un", + self->axes_swap, self->x_swap, self->y_swap, self->free_pixels); +} + /* * The context rotations consists of two cyclic permutation groups that are * mirrored.
http://repo.or.cz/w/gfxprim.git/commit/5df856f5af17bd0922b99fc21c1236f01f3d2...
commit 5df856f5af17bd0922b99fc21c1236f01f3d2f27 Author: Cyril Hrubis metan@ucw.cz Date: Tue Jun 12 15:06:28 2012 +0200
core: Remove GP_ContextDump().
diff --git a/include/core/GP_Context.h b/include/core/GP_Context.h index 141fa76..5057481 100644 --- a/include/core/GP_Context.h +++ b/include/core/GP_Context.h @@ -154,11 +154,6 @@ GP_Context *GP_ContextConvert(const GP_Context *src, void GP_ContextFree(GP_Context *context);
/* - * Dump context into file - */ -GP_RetCode GP_ContextDump(GP_Context *context, const char *path); - -/* * Rotates context flags clock wise. */ void GP_ContextFlagsRotateCW(GP_Context *context); diff --git a/libs/core/GP_Context.c b/libs/core/GP_Context.c index 967edcb..3226c1c 100644 --- a/libs/core/GP_Context.c +++ b/libs/core/GP_Context.c @@ -222,25 +222,6 @@ GP_Context *GP_ContextSubContext(GP_Context *context, GP_Context *subcontext, return ret; }
-GP_RetCode GP_ContextDump(GP_Context *context, const char *path) -{ - FILE *f = fopen(path, "w"); - uint32_t x, y; - - if (f == NULL) - return GP_EBADFILE; - - for (y = 0; y < context->h; y++) { - for (x = 0; x < context->bytes_per_row; x++) - fprintf(f, "0x%02x ", ((uint8_t *)context->pixels) - [y * context->bytes_per_row + x]); - fprintf(f, "n"); - } - - fclose(f); - return GP_ESUCCESS; -} - /* * The context rotations consists of two cyclic permutation groups that are * mirrored.
http://repo.or.cz/w/gfxprim.git/commit/5261b44a10e5bcf3d7abd86d97076161449b2...
commit 5261b44a10e5bcf3d7abd86d97076161449b2ef4 Merge: e1e008b f5c3fdd Author: Cyril Hrubis metan@ucw.cz Date: Tue Jun 12 13:34:42 2012 +0200
Merge ssh://repo.or.cz/srv/git/gfxprim
http://repo.or.cz/w/gfxprim.git/commit/e1e008bfb7e62140b69da17b0a6b30eed15de...
commit e1e008bfb7e62140b69da17b0a6b30eed15de653 Merge: 4fddc17 46fc9fc Author: Cyril Hrubis metan@ucw.cz Date: Sat Jun 9 00:31:11 2012 +0200
Merge ssh://repo.or.cz/srv/git/gfxprim
http://repo.or.cz/w/gfxprim.git/commit/4fddc1754f1d4f739c318adb305041595efbf...
commit 4fddc1754f1d4f739c318adb305041595efbfa1f Merge: 79adf5c 9dc7c88 Author: Cyril Hrubis metan@ucw.cz Date: Mon May 28 21:17:03 2012 +0200
Merge ssh://repo.or.cz/srv/git/gfxprim
http://repo.or.cz/w/gfxprim.git/commit/79adf5cfb66ddd38140c64f8015be735bad2a...
commit 79adf5cfb66ddd38140c64f8015be735bad2a985 Merge: ca0579c 60acd49 Author: Cyril Hrubis metan@ucw.cz Date: Mon May 21 00:56:44 2012 +0200
Merge ssh://repo.or.cz/srv/git/gfxprim
http://repo.or.cz/w/gfxprim.git/commit/ca0579cff49cfb79bcc2382c4508a8c5aef6f...
commit ca0579cff49cfb79bcc2382c4508a8c5aef6f04e Merge: d082267 3447cc0 Author: Cyril Hrubis metan@ucw.cz Date: Sun Apr 29 20:37:59 2012 +0200
Merge ssh://repo.or.cz/srv/git/gfxprim
http://repo.or.cz/w/gfxprim.git/commit/d082267d9e82e53500d0989dbc158a1725cc6...
commit d082267d9e82e53500d0989dbc158a1725cc68b4 Merge: 6a75eaa b4f2a25 Author: Cyril Hrubis metan@ucw.cz Date: Tue Apr 17 21:12:21 2012 +0200
Merge ssh://repo.or.cz/srv/git/gfxprim
http://repo.or.cz/w/gfxprim.git/commit/6a75eaa20c6561c387c324b8013e1ff04517b...
commit 6a75eaa20c6561c387c324b8013e1ff04517b33b Merge: 382a79d 4f696f6 Author: Cyril Hrubis metan@ucw.cz Date: Mon Apr 16 21:32:08 2012 +0200
Merge ssh://repo.or.cz/srv/git/gfxprim
http://repo.or.cz/w/gfxprim.git/commit/382a79d9e517a63ab444030f0003c045c3c55...
commit 382a79d9e517a63ab444030f0003c045c3c55d17 Author: Cyril Hrubis metan@ucw.cz Date: Sat Mar 3 23:48:31 2012 +0100
core: Add info to the existing call.
diff --git a/include/core/GP_Context.h b/include/core/GP_Context.h index a6b76df..affb8d5 100644 --- a/include/core/GP_Context.h +++ b/include/core/GP_Context.h @@ -100,7 +100,8 @@ typedef struct GP_Context { GP_Context *GP_ContextAlloc(GP_Size w, GP_Size h, GP_PixelType type);
/* - * Initalize context. + * Initalize context, pixels pointer is not dereferenced so it's safe to pass + * NULL there and allocate it later with size context->bpr * context->h. */ void GP_ContextInit(GP_Context *context, GP_Size w, GP_Size h, GP_PixelType type, void *pixels);
-----------------------------------------------------------------------
Summary of changes: .gitignore | 1 + demos/spiv/spiv.c | 5 +- doc/context.txt | 124 +++++++++++++++++----- include/core/GP_Context.h | 126 ++++++++++++++++------- libs/core/GP_Blit.c | 4 +- libs/core/GP_Context.c | 255 ++++++++++++++++++++++++--------------------- libs/filters/GP_Resize.c | 2 +- pylib/gfxprim/core/core.i | 8 +- tests/SDL/blittest.c | 2 +- tests/SDL/subcontext.c | 2 +- 10 files changed, 335 insertions(+), 194 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.