Split pixel images into pixman-bits-image.c
authorSøren Sandmann Pedersen <sandmann@redhat.com>
Sun, 3 May 2009 01:14:36 +0000 (21:14 -0400)
committerSøren Sandmann Pedersen <sandmann@redhat.com>
Sat, 16 May 2009 19:12:35 +0000 (15:12 -0400)
pixman/Makefile.am
pixman/pixman-bits-image.c [new file with mode: 0644]
pixman/pixman-image.c
pixman/pixman-private.h

index 4a0cba0..cca662e 100644 (file)
@@ -21,6 +21,7 @@ libpixman_1_la_SOURCES =              \
        pixman-conical-gradient.c       \
        pixman-linear-gradient.c        \
        pixman-radial-gradient.c        \
+       pixman-bits-image.c             \
        pixman-transformed.c            \
        pixman-transformed-accessors.c  \
        pixman-utils.c                  \
diff --git a/pixman/pixman-bits-image.c b/pixman/pixman-bits-image.c
new file mode 100644 (file)
index 0000000..7df159f
--- /dev/null
@@ -0,0 +1,118 @@
+/*
+ * Copyright © 2000 SuSE, Inc.
+ * Copyright © 2007 Red Hat, Inc.
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of SuSE not be used in advertising or
+ * publicity pertaining to distribution of the software without specific,
+ * written prior permission.  SuSE makes no representations about the
+ * suitability of this software for any purpose.  It is provided "as is"
+ * without express or implied warranty.
+ *
+ * SuSE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL SuSE
+ * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
+ * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <config.h>
+#include <stdlib.h>
+#include "pixman-private.h"
+
+static uint32_t *
+create_bits (pixman_format_code_t format,
+            int                  width,
+            int                  height,
+            int                 *rowstride_bytes)
+{
+    int stride;
+    int buf_size;
+    int bpp;
+
+    /* what follows is a long-winded way, avoiding any possibility of integer
+     * overflows, of saying:
+     * stride = ((width * bpp + FB_MASK) >> FB_SHIFT) * sizeof (uint32_t);
+     */
+
+    bpp = PIXMAN_FORMAT_BPP (format);
+    if (pixman_multiply_overflows_int (width, bpp))
+       return NULL;
+
+    stride = width * bpp;
+    if (pixman_addition_overflows_int (stride, FB_MASK))
+       return NULL;
+
+    stride += FB_MASK;
+    stride >>= FB_SHIFT;
+
+#if FB_SHIFT < 2
+    if (pixman_multiply_overflows_int (stride, sizeof (uint32_t)))
+       return NULL;
+#endif
+    stride *= sizeof (uint32_t);
+
+    if (pixman_multiply_overflows_int (height, stride))
+       return NULL;
+
+    buf_size = height * stride;
+
+    if (rowstride_bytes)
+       *rowstride_bytes = stride;
+
+    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_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);
+
+    if (!bits && width && height)
+    {
+       free_me = bits = create_bits (format, width, height, &rowstride_bytes);
+       if (!bits)
+           return NULL;
+    }
+
+    image = _pixman_image_allocate();
+
+    if (!image) {
+       if (free_me)
+           free (free_me);
+       return NULL;
+    }
+    
+    image->type = BITS;
+    image->bits.format = format;
+    image->bits.width = width;
+    image->bits.height = height;
+    image->bits.bits = bits;
+    image->bits.free_me = free_me;
+
+    image->bits.rowstride = rowstride_bytes / (int) sizeof (uint32_t); /* we store it in number
+                                                                 * of uint32_t's
+                                                                 */
+    image->bits.indexed = NULL;
+
+    pixman_region32_fini (&image->common.full_region);
+    pixman_region32_init_rect (&image->common.full_region, 0, 0,
+                              image->bits.width, image->bits.height);
+
+    _pixman_image_reset_clip_region (image);
+    return image;
+}
index 970ca53..1ee7529 100644 (file)
@@ -299,51 +299,8 @@ pixman_image_unref (pixman_image_t *image)
 
 /* Constructors */
 
-static uint32_t *
-create_bits (pixman_format_code_t format,
-            int                  width,
-            int                  height,
-            int                 *rowstride_bytes)
-{
-    int stride;
-    int buf_size;
-    int bpp;
-
-    /* what follows is a long-winded way, avoiding any possibility of integer
-     * overflows, of saying:
-     * stride = ((width * bpp + FB_MASK) >> FB_SHIFT) * sizeof (uint32_t);
-     */
-
-    bpp = PIXMAN_FORMAT_BPP (format);
-    if (pixman_multiply_overflows_int (width, bpp))
-       return NULL;
-
-    stride = width * bpp;
-    if (pixman_addition_overflows_int (stride, FB_MASK))
-       return NULL;
-
-    stride += FB_MASK;
-    stride >>= FB_SHIFT;
-
-#if FB_SHIFT < 2
-    if (pixman_multiply_overflows_int (stride, sizeof (uint32_t)))
-       return NULL;
-#endif
-    stride *= sizeof (uint32_t);
-
-    if (pixman_multiply_overflows_int (height, stride))
-       return NULL;
-
-    buf_size = height * stride;
-
-    if (rowstride_bytes)
-       *rowstride_bytes = stride;
-
-    return calloc (buf_size, 1);
-}
-
-static void
-reset_clip_region (pixman_image_t *image)
+void
+_pixman_image_reset_clip_region (pixman_image_t *image)
 {
     pixman_region32_fini (&image->common.clip_region);
 
@@ -358,56 +315,6 @@ reset_clip_region (pixman_image_t *image)
     }
 }
 
-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;
-    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);
-
-    if (!bits && width && height)
-    {
-       free_me = bits = create_bits (format, width, height, &rowstride_bytes);
-       if (!bits)
-           return NULL;
-    }
-
-    image = _pixman_image_allocate();
-
-    if (!image) {
-       if (free_me)
-           free (free_me);
-       return NULL;
-    }
-    
-    image->type = BITS;
-    image->bits.format = format;
-    image->bits.width = width;
-    image->bits.height = height;
-    image->bits.bits = bits;
-    image->bits.free_me = free_me;
-
-    image->bits.rowstride = rowstride_bytes / (int) sizeof (uint32_t); /* we store it in number
-                                                                 * of uint32_t's
-                                                                 */
-    image->bits.indexed = NULL;
-
-    pixman_region32_fini (&image->common.full_region);
-    pixman_region32_init_rect (&image->common.full_region, 0, 0,
-                              image->bits.width, image->bits.height);
-
-    reset_clip_region (image);
-    return image;
-}
-
 PIXMAN_EXPORT pixman_bool_t
 pixman_image_set_clip_region32 (pixman_image_t *image,
                                pixman_region32_t *region)
@@ -420,7 +327,7 @@ pixman_image_set_clip_region32 (pixman_image_t *image,
     }
     else
     {
-       reset_clip_region (image);
+       _pixman_image_reset_clip_region (image);
 
        return TRUE;
     }
@@ -439,7 +346,7 @@ pixman_image_set_clip_region (pixman_image_t    *image,
     }
     else
     {
-       reset_clip_region (image);
+       _pixman_image_reset_clip_region (image);
 
        return TRUE;
     }
index be120ff..1bde4b9 100644 (file)
@@ -308,6 +308,9 @@ pixman_bool_t
 _pixman_init_gradient (gradient_t     *gradient,
                       const pixman_gradient_stop_t *stops,
                       int             n_stops);
+void
+_pixman_image_reset_clip_region (pixman_image_t *image);
+
 struct point
 {
     int16_t x, y;