summaryrefslogtreecommitdiff
path: root/pixman/pixman-bits-image.c
diff options
context:
space:
mode:
authorTaekyun Kim <tkq.kim@samsung.com>2011-09-22 16:20:03 +0900
committerTaekyun Kim <tkq.kim@samsung.com>2011-10-10 12:18:14 +0900
commit7272e2fcd2ff8e546cef19929cd370ae2f946135 (patch)
tree7adc46772269501c621dc0246ac53412788890e3 /pixman/pixman-bits-image.c
parent4dcf1b0107334857e1f0bb203c34efed1146535c (diff)
init/fini functions for pixman_image_t
pixman_image_t itself can be on stack or heap. So segregating init/fini from create/unref can be useful when we want to use pixman_image_t on stack or other memory.
Diffstat (limited to 'pixman/pixman-bits-image.c')
-rw-r--r--pixman/pixman-bits-image.c74
1 files changed, 46 insertions, 28 deletions
diff --git a/pixman/pixman-bits-image.c b/pixman/pixman-bits-image.c
index f382c65..99c0dfe 100644
--- a/pixman/pixman-bits-image.c
+++ b/pixman/pixman-bits-image.c
@@ -1437,40 +1437,30 @@ create_bits (pixman_format_code_t format,
return calloc (buf_size, 1);
}
-PIXMAN_EXPORT pixman_image_t *
-pixman_image_create_bits (pixman_format_code_t format,
- int width,
- int height,
- uint32_t * bits,
- int rowstride_bytes)
+pixman_bool_t
+_pixman_bits_image_init (pixman_image_t * image,
+ pixman_format_code_t format,
+ int width,
+ int height,
+ uint32_t * bits,
+ int rowstride)
{
- pixman_image_t *image;
uint32_t *free_me = NULL;
- /* must be a whole number of uint32_t's
- */
- return_val_if_fail (
- bits == NULL || (rowstride_bytes % sizeof (uint32_t)) == 0, NULL);
-
- return_val_if_fail (PIXMAN_FORMAT_BPP (format) >= PIXMAN_FORMAT_DEPTH (format), NULL);
-
if (!bits && width && height)
{
- free_me = bits = create_bits (format, width, height, &rowstride_bytes);
- if (!bits)
- return NULL;
- }
+ int rowstride_bytes;
- image = _pixman_image_allocate ();
+ free_me = bits = create_bits (format, width, height, &rowstride_bytes);
- if (!image)
- {
- if (free_me)
- free (free_me);
+ if (!bits)
+ return FALSE;
- return NULL;
+ rowstride = rowstride_bytes / (int) sizeof (uint32_t);
}
+ _pixman_image_init (image);
+
image->type = BITS;
image->bits.format = format;
image->bits.width = width;
@@ -1479,15 +1469,43 @@ pixman_image_create_bits (pixman_format_code_t format,
image->bits.free_me = free_me;
image->bits.read_func = NULL;
image->bits.write_func = NULL;
-
- /* The rowstride is stored in number of uint32_t */
- image->bits.rowstride = rowstride_bytes / (int) sizeof (uint32_t);
-
+ image->bits.rowstride = rowstride;
image->bits.indexed = NULL;
image->common.property_changed = bits_image_property_changed;
_pixman_image_reset_clip_region (image);
+ return TRUE;
+}
+
+PIXMAN_EXPORT pixman_image_t *
+pixman_image_create_bits (pixman_format_code_t format,
+ int width,
+ int height,
+ uint32_t * bits,
+ int rowstride_bytes)
+{
+ pixman_image_t *image;
+
+ /* must be a whole number of uint32_t's
+ */
+ return_val_if_fail (
+ bits == NULL || (rowstride_bytes % sizeof (uint32_t)) == 0, NULL);
+
+ return_val_if_fail (PIXMAN_FORMAT_BPP (format) >= PIXMAN_FORMAT_DEPTH (format), NULL);
+
+ image = _pixman_image_allocate ();
+
+ if (!image)
+ return NULL;
+
+ if (!_pixman_bits_image_init (image, format, width, height, bits,
+ rowstride_bytes / (int) sizeof (uint32_t)))
+ {
+ free (image);
+ return NULL;
+ }
+
return image;
}