From 8bdb8b1d93bbbffafe111b4fc4dac0df9bbb6fe5 Mon Sep 17 00:00:00 2001 From: Soren Sandmann Pedersen Date: Wed, 9 May 2007 09:47:33 -0400 Subject: [PATCH] Export pixman_gradient_stop; get rid of *error argument from init functions. Add return_if_fail macros to pixman-private.h --- pixman/pixman-compose.c | 4 +- pixman/pixman-image.c | 156 +++++++++++++++++++----------------------------- pixman/pixman-private.h | 52 ++++++++++++---- pixman/pixman.h | 32 +++++----- test/composite-test.c | 9 ++- 5 files changed, 120 insertions(+), 133 deletions(-) diff --git a/pixman/pixman-compose.c b/pixman/pixman-compose.c index 3ab418a..cd6308e 100644 --- a/pixman/pixman-compose.c +++ b/pixman/pixman-compose.c @@ -3153,7 +3153,7 @@ typedef struct int32_t right_x; int32_t stepper; - gradient_stop_t *stops; + pixman_gradient_stop_t *stops; int num_stops; unsigned int spread; @@ -3186,7 +3186,7 @@ _gradient_walker_reset (GradientWalker *walker, int32_t x, left_x, right_x; pixman_color_t *left_c, *right_c; int n, count = walker->num_stops; - gradient_stop_t * stops = walker->stops; + pixman_gradient_stop_t * stops = walker->stops; static const pixman_color_t transparent_black = { 0, 0, 0, 0 }; diff --git a/pixman/pixman-image.c b/pixman/pixman-image.c index 72115b2..3b441b5 100644 --- a/pixman/pixman-image.c +++ b/pixman/pixman-image.c @@ -22,6 +22,7 @@ #include #include +#include #include "pixman.h" #include "pixman-private.h" @@ -52,53 +53,28 @@ init_source_image (source_image_t *image) image->class = SOURCE_IMAGE_CLASS_UNKNOWN; } -static void +static pixman_bool_t init_gradient (gradient_t *gradient, - int stop_count, - pixman_fixed_t *stop_points, - pixman_color_t *stop_colors, - int *error) + const pixman_gradient_stop_t *stops, + int n_stops) { - int i; - pixman_fixed_t dpos; - - if (stop_count <= 0) - { - *error = PIXMAN_BAD_VALUE; - return; - } + return_val_if_fail (n_stops > 0, FALSE); init_source_image (&gradient->common); - - dpos = -1; - for (i = 0; i < stop_count; ++i) - { - if (stop_points[i] < dpos || stop_points[i] > (1<<16)) - { - *error = PIXMAN_BAD_VALUE; - return; - } - dpos = stop_points[i]; - } - gradient->stops = malloc (stop_count * sizeof (gradient_stop_t)); + gradient->stops = malloc (n_stops * sizeof (pixman_gradient_stop_t)); if (!gradient->stops) - { - *error = PIXMAN_BAD_ALLOC; - return; - } + return FALSE; - gradient->n_stops = stop_count; - - for (i = 0; i < stop_count; ++i) - { - gradient->stops[i].x = stop_points[i]; - gradient->stops[i].color = stop_colors[i]; - } + memcpy (gradient->stops, stops, n_stops * sizeof (pixman_gradient_stop_t)); + + gradient->n_stops = n_stops; gradient->stop_range = 0xffff; gradient->color_table = NULL; gradient->color_table_size = 0; + + return TRUE; } static uint32_t @@ -145,27 +121,26 @@ pixman_image_create_solid_fill (pixman_color_t *color, pixman_image_t * pixman_image_create_linear_gradient (pixman_point_fixed_t *p1, pixman_point_fixed_t *p2, - int n_stops, - pixman_fixed_t *stops, - pixman_color_t *colors, - int *error) + const pixman_gradient_stop_t *stops, + int n_stops) { - pixman_image_t *image = allocate_image(); - linear_gradient_t *linear = &image->linear; + pixman_image_t *image; + linear_gradient_t *linear; + return_val_if_fail (n_stops < 2, NULL); + + image = allocate_image(); + if (!image) - { - *error = PIXMAN_BAD_ALLOC; return NULL; - } + + linear = &image->linear; - if (n_stops < 2) + if (!init_gradient (&linear->common, stops, n_stops)) { - *error = PIXMAN_BAD_VALUE; - return NULL; + free (image); + return NULL; } - - init_gradient (&linear->common, n_stops, stops, colors, error); linear->p1 = *p1; linear->p2 = *p2; @@ -181,28 +156,27 @@ pixman_image_create_radial_gradient (pixman_point_fixed_t *inner, pixman_point_fixed_t *outer, pixman_fixed_t inner_radius, pixman_fixed_t outer_radius, - int n_stops, - pixman_fixed_t *stops, - pixman_color_t *colors, - int *error) + const pixman_gradient_stop_t *stops, + int n_stops) { - pixman_image_t *image = allocate_image(); - radial_gradient_t *radial = &image->radial; + pixman_image_t *image; + radial_gradient_t *radial; + + return_val_if_fail (n_stops < 2, NULL); + + image = allocate_image(); if (!image) - { - *error = PIXMAN_BAD_ALLOC; return NULL; - } - - if (n_stops < 2) + + radial = &image->radial; + + if (!init_gradient (&radial->common, stops, n_stops)) { - *error = PIXMAN_BAD_VALUE; + free (image); return NULL; } - init_gradient (&radial->common, n_stops, stops, colors, error); - image->type = RADIAL; radial->c1.x = inner->x; @@ -211,12 +185,12 @@ pixman_image_create_radial_gradient (pixman_point_fixed_t *inner, radial->c2.x = outer->x; radial->c2.y = outer->y; radial->c2.radius = outer_radius; - radial->cdx = (radial->c2.x - radial->c1.x) / 65536.; - radial->cdy = (radial->c2.y - radial->c1.y) / 65536.; - radial->dr = (radial->c2.radius - radial->c1.radius) / 65536.; - radial->A = ( radial->cdx * radial->cdx - + radial->cdy * radial->cdy - - radial->dr * radial->dr); + radial->cdx = pixman_fixed_to_double (radial->c2.x - radial->c1.x); + radial->cdy = pixman_fixed_to_double (radial->c2.y - radial->c1.y); + radial->dr = pixman_fixed_to_double (radial->c2.radius - radial->c1.radius); + radial->A = (radial->cdx * radial->cdx + + radial->cdy * radial->cdy + - radial->dr * radial->dr); return image; } @@ -224,28 +198,23 @@ pixman_image_create_radial_gradient (pixman_point_fixed_t *inner, pixman_image_t * pixman_image_create_conical_gradient (pixman_point_fixed_t *center, pixman_fixed_t angle, - int n_stops, - pixman_fixed_t *stops, - pixman_color_t *colors, - int *error) + const pixman_gradient_stop_t *stops, + int n_stops) { pixman_image_t *image = allocate_image(); - conical_gradient_t *conical = &image->conical; + conical_gradient_t *conical; if (!image) - { - *error = PIXMAN_BAD_ALLOC; return NULL; - } + + conical = &image->conical; - if (n_stops < 2) + if (!init_gradient (&conical->common, stops, n_stops)) { - *error = PIXMAN_BAD_VALUE; + free (image); return NULL; } - init_gradient (&conical->common, n_stops, stops, colors, error); - image->type = CONICAL; conical->center = *center; conical->angle = angle; @@ -254,27 +223,22 @@ pixman_image_create_conical_gradient (pixman_point_fixed_t *center, } pixman_image_t * -pixman_image_create_bits (pixman_format_code_t format, - int width, - int height, +pixman_image_create_bits (pixman_format_code_t format, + int width, + int height, uint32_t *bits, - int rowstride, - int *error) + int rowstride) { - pixman_image_t *image = allocate_image(); + pixman_image_t *image; + + return_val_if_fail ((rowstride & 0x3) == 0, NULL); /* must be a multiple of 4 */ + + image = allocate_image(); if (!image) - { - *error = PIXMAN_BAD_ALLOC; return NULL; - } init_common (&image->common); - - if (rowstride & 0x3) - { - /* we should probably spew some warning here */ - } image->type = BITS; image->bits.format = format; diff --git a/pixman/pixman-private.h b/pixman/pixman-private.h index f63b2b7..87b9965 100644 --- a/pixman/pixman-private.h +++ b/pixman/pixman-private.h @@ -8,6 +8,39 @@ #define TRUE 1 #endif +#define DEBUG 1 + +#if DEBUG + +#define return_if_fail(expr) { \ + do \ + { \ + if (!(expr)) \ + { \ + fprintf(stderr, "In %s: %s failed\n", __FUNCTION__, #expr); \ + return; \ + } \ + } \ + while (0) + +#define return_val_if_fail(expr, retval) \ + do \ + { \ + if (!(expr)) \ + { \ + fprintf(stderr, "In %s: %s failed\n", __FUNCTION__, #expr); \ + return (retval); \ + } \ + } \ + while (0) + +#else + +#define return_if_fail(expr) +#define return_val_if_fail(expr, retval) + +#endif + typedef struct image_common image_common_t; typedef struct source_image source_image_t; typedef struct solid_fill solid_fill_t; @@ -18,7 +51,6 @@ typedef struct vertical_gradient vertical_gradient_t; typedef struct conical_gradient conical_gradient_t; typedef struct radial_gradient radial_gradient_t; typedef struct bits_image bits_image_t; -typedef struct gradient_stop gradient_stop_t; typedef struct circle circle_t; typedef struct point point_t; @@ -93,12 +125,6 @@ struct image_common pixman_bool_t component_alpha; }; -struct gradient_stop -{ - pixman_fixed_t x; - pixman_color_t color; -}; - struct source_image { image_common_t common; @@ -113,12 +139,12 @@ struct solid_fill struct gradient { - source_image_t common; - int n_stops; - gradient_stop_t * stops; - int stop_range; - uint32_t * color_table; - int color_table_size; + source_image_t common; + int n_stops; + pixman_gradient_stop_t * stops; + int stop_range; + uint32_t * color_table; + int color_table_size; }; struct linear_gradient diff --git a/pixman/pixman.h b/pixman/pixman.h index 5f5cba0..1a2dc5c 100644 --- a/pixman/pixman.h +++ b/pixman/pixman.h @@ -272,9 +272,14 @@ const pixman_box16_t * pixman_region_rectangles (pixman_region16_t *region, /* * Images */ -typedef union pixman_image pixman_image_t; -typedef struct pixman_indexed pixman_indexed_t; +typedef union pixman_image pixman_image_t; +typedef struct pixman_indexed pixman_indexed_t; +typedef struct pixman_gradient_stop pixman_gradient_stop_t; +struct pixman_gradient_stop { + pixman_fixed_t x; + pixman_color_t color; +}; #define PIXMAN_MAX_INDEXED 256 /* XXX depth must be <= 8 */ @@ -378,31 +383,24 @@ typedef enum { pixman_image_t *pixman_image_create_solid_fill (pixman_color_t *color, int *error); pixman_image_t *pixman_image_create_linear_gradient (pixman_point_fixed_t *p1, - pixman_point_fixed_t *p2, - int n_stops, - pixman_fixed_t *stops, - pixman_color_t *colors, - int *error); + pixman_point_fixed_t *p2, + const pixman_gradient_stop_t *stops, + int n_stops); pixman_image_t *pixman_image_create_radial_gradient (pixman_point_fixed_t *inner, pixman_point_fixed_t *outer, pixman_fixed_t inner_radius, pixman_fixed_t outer_radius, - int n_stops, - pixman_fixed_t *stops, - pixman_color_t *colors, - int *error); + const pixman_gradient_stop_t *stops, + int n_stops); pixman_image_t *pixman_image_create_conical_gradient (pixman_point_fixed_t *center, pixman_fixed_t angle, - int n_stops, - pixman_fixed_t *stops, - pixman_color_t *colors, - int *error); + const pixman_gradient_stop_t *stops, + int n_stops); pixman_image_t *pixman_image_create_bits (pixman_format_code_t format, int width, int height, uint32_t *bits, - int rowstride_bytes, - int *error); + int rowstride_bytes); /* Destructor */ void pixman_image_destroy (pixman_image_t *image); diff --git a/test/composite-test.c b/test/composite-test.c index 2aecd54..0dd8f8e 100644 --- a/test/composite-test.c +++ b/test/composite-test.c @@ -9,7 +9,6 @@ main () uint32_t *dest = malloc (10 * 10 * 4); pixman_image_t *src_img; pixman_image_t *dest_img; - uint32_t real; int i; @@ -22,12 +21,12 @@ main () src_img = pixman_image_create_bits (PIXMAN_a8r8g8b8, 10, 10, src, - 10 * 4, NULL); + 10 * 4); dest_img = pixman_image_create_bits (PIXMAN_a8r8g8b8, - 10, 10, - dest, - 10 * 4, NULL); + 10, 10, + dest, + 10 * 4); pixman_image_composite (PIXMAN_OP_OVER, src_img, NULL, dest_img, 0, 0, 0, 0, 0, 0, 10, 10); -- 2.7.4