#include <stdlib.h>
#include <stdio.h>
+#include <string.h>
#include "pixman.h"
#include "pixman-private.h"
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
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;
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;
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;
}
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;
}
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;
#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;
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;
pixman_bool_t component_alpha;
};
-struct gradient_stop
-{
- pixman_fixed_t x;
- pixman_color_t color;
-};
-
struct source_image
{
image_common_t common;
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
/*
* 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 */
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);