diff options
author | Andrea Canciani <ranma42@gmail.com> | 2010-11-03 07:55:27 +0100 |
---|---|---|
committer | Andrea Canciani <ranma42@gmail.com> | 2010-12-20 12:21:56 +0100 |
commit | c9915e3b98bd81fa461f3f8934b1d39da4a94352 (patch) | |
tree | c5a4dd6968d2afb30ca7a018a392c25fe206e0dd | |
parent | d1f9a87b2752ca6abd998b6c4739e145c846f970 (diff) |
colorspace
-rw-r--r-- | pixman/Makefile.am | 1 | ||||
-rw-r--r-- | pixman/pixman-color-space.c | 138 | ||||
-rw-r--r-- | pixman/pixman-private.h | 12 | ||||
-rw-r--r-- | pixman/pixman.h | 15 |
4 files changed, 166 insertions, 0 deletions
diff --git a/pixman/Makefile.am b/pixman/Makefile.am index 8043804..969e293 100644 --- a/pixman/Makefile.am +++ b/pixman/Makefile.am @@ -6,6 +6,7 @@ libpixman_1_la_SOURCES = \ pixman-accessor.h \ pixman-access.c \ pixman-access-accessors.c \ + pixman-color-space.c \ pixman-cpu.c \ pixman-gradient-walker.c \ pixman-region16.c \ diff --git a/pixman/pixman-color-space.c b/pixman/pixman-color-space.c new file mode 100644 index 0000000..5cbd453 --- /dev/null +++ b/pixman/pixman-color-space.c @@ -0,0 +1,138 @@ +/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include <stdlib.h> +#include <assert.h> + +#include "pixman-private.h" + + +const pixman_color_space_t _pixman_color_space_device_gray = { + PIXMAN_REFERENCE_COUNT_INVALID, + 1 +}; + +const pixman_color_space_t _pixman_color_space_device_rgb = { + PIXMAN_REFERENCE_COUNT_INVALID, + 3 +}; + +const pixman_color_space_t _pixman_color_space_device_cmyk = { + PIXMAN_REFERENCE_COUNT_INVALID, + 4 +}; + +static void +_pixman_color_space_init (pixman_color_space_t *color_space, + void *profile_data, + unsigned long profile_len) +{ + color_space->ref_count = 0; + color_space->profile_data = profile_data; + color_space->profile_len = profile_len; +} + +PIXMAN_EXPORT pixman_color_space_t * +pixman_color_space_create_icc (const void *profile, unsigned long profile_len) +{ + pixman_color_space_t *color_space; + + color_space = malloc (sizeof (pixman_color_space_t) + profile_len); + if (color_space == NULL) + return NULL; + + memcpy (color_space + 1, profile, profile_len); + + _pixman_color_space_init (color_space, color_space + 1, profile_len); + + color_space->ref_count = 1; + + return color_space; +} + +/** + * pixman_color_space_ref: + * @color_space: a #pixman_color_space_t + * + * Increases the reference count on @color_space by one. This prevents + * @color_space from being destroyed until a matching call to + * pixman_color_space_unref() is made. + * + * Return value: the referenced #pixman_color_space_t. + **/ +PIXMAN_EXPORT pixman_color_space_t * +pixman_color_space_ref (pixman_color_space_t *color_space) +{ + if (color_space == NULL || + simpleops_atomic_int_get (&color_space->ref_count) == PIXMAN_REFERENCE_COUNT_INVALID) + return color_space; + + simpleops_atomic_int_inc_and_get (&color_space->ref_count); + + return color_space; +} + +/** + * pixman_color_space_unref: + * @color_space: a #pixman_color_space_t + * + * Decreases the reference count on @color_space by one. If the result is + * zero, then @color_space and all associated resources are freed. See + * pixman_color_space_ref(). + **/ +PIXMAN_EXPORT pixman_bool_t +pixman_color_space_unref (pixman_color_space_t *color_space) +{ + if (color_space == NULL || + simpleops_atomic_int_get (&color_space->ref_count) == PIXMAN_REFERENCE_COUNT_INVALID) + return FALSE; + + if (! simpleops_atomic_int_dec_and_test (&color_space->ref_count)) + return FALSE; + + free (color_space); + + return TRUE; +} + +/** + * pixman_color_space_get_num_components: + * @color_space: a #pixman_color_space_t + * + * Returns the number of components of @color_space. + * + * Return value: the number of components of @color_space. If the + * object is NULL, 0 will be returned. + **/ +PIXMAN_EXPORT unsigned int +pixman_color_space_get_num_components (const pixman_color_space_t *color_space) +{ + if (color_space == NULL) + return 0; + + return color_space->n_components; +} + +pixman_color_space_t * +_pixman_color_space_from_pixman_format (pixman_format_code_t pixman_format) +{ + switch (PIXMAN_FORMAT_TYPE (pixman_format)) { + case PIXMAN_TYPE_ARGB: + case PIXMAN_TYPE_ABGR: + case PIXMAN_TYPE_BGRA: + return (pixman_color_space_t *) &_pixman_color_space_device_rgb; + + case PIXMAN_TYPE_A: + return NULL; + + case PIXMAN_TYPE_GRAY: + return (pixman_color_space_t *) &_pixman_color_space_device_gray; + + default: + assert (0); + return NULL; + } +} diff --git a/pixman/pixman-private.h b/pixman/pixman-private.h index 7e03043..3fdfe2e 100644 --- a/pixman/pixman-private.h +++ b/pixman/pixman-private.h @@ -18,6 +18,18 @@ #include "pixman-compiler.h" #include "simpleops/atomic/simpleops-atomic.h" +#define PIXMAN_REFERENCE_COUNT_INVALID -1 + +#define MAX_COMPONENTS 16 + +struct pixman_color_space { + int32_t ref_count; + unsigned int n_components; + void *profile_data; + unsigned long profile_len; + /* mime data? */ +}; + /* * Images */ diff --git a/pixman/pixman.h b/pixman/pixman.h index 8fdb12c..08e0c4e 100644 --- a/pixman/pixman.h +++ b/pixman/pixman.h @@ -184,6 +184,7 @@ struct pixman_transform /* forward declaration (sorry) */ struct pixman_box16; typedef union pixman_image pixman_image_t; +typedef struct pixman_color_space pixman_color_space_t; void pixman_transform_init_identity (struct pixman_transform *matrix); pixman_bool_t pixman_transform_point_3d (const struct pixman_transform *transform, @@ -952,6 +953,20 @@ void pixman_rasterize_trapezoid (pixman_image_t *image, int x_off, int y_off); + +pixman_color_space_t * +pixman_color_space_create_icc (const void *profile, unsigned long profile_len); + +pixman_color_space_t * +pixman_color_space_ref (pixman_color_space_t *color_space); + +pixman_bool_t +pixman_color_space_unref (pixman_color_space_t *color_space); + +unsigned int +pixman_color_space_get_num_components (const pixman_color_space_t *color_space); + + PIXMAN_END_DECLS #endif /* PIXMAN_H__ */ |