summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSøren Sandmann Pedersen <ssp@redhat.com>2012-10-05 01:22:24 -0400
committerSøren Sandmann Pedersen <ssp@redhat.com>2012-10-05 01:22:24 -0400
commitc90d693c9742748bb89e140c628b3d3d2fd3e0bb (patch)
treef431b241c01d8c4a75847377ef5047bcea36dd66
parent1a505f4fdbc040da940e9c55c2cdefc5e1178a8d (diff)
more fimage
-rw-r--r--fimage.c139
1 files changed, 105 insertions, 34 deletions
diff --git a/fimage.c b/fimage.c
index 42247d3..33894d0 100644
--- a/fimage.c
+++ b/fimage.c
@@ -2,6 +2,11 @@
#include <pixman.h>
#include "fimage.h"
+/* TODO:
+ *
+ * rename to fragment_list?
+ */
+
struct fimage_t
{
pixman_bool_t broken;
@@ -18,29 +23,6 @@ static const fimage_t broken_fimage =
};
static fimage_t *
-fimage_new (fragment_t *fragment)
-{
- fimage_t *fimage;
-
- if (fragment_is_broken (fragment))
- return (fimage_t *)&broken_fimage;
-
- fimage = malloc (sizeof *fimage);
- if (!fimage)
- {
- fragment_free (fragment);
- return (fimage_t *)&broken_fimage;
- }
-
- fimage->broken = FALSE;
- fimage->n_allocated_fragments = 1;
- fimage->n_fragments = 1;
- fimage->fragments[0] = fragment;
-
- return fimage;
-}
-
-static fimage_t *
fimage_ensure_space (fimage_t *fimage, int n_more)
{
size_t required_fragments = fimage->n_fragments + n_more;
@@ -75,31 +57,71 @@ fimage_ensure_space (fimage_t *fimage, int n_more)
static fimage_t *
fimage_append_fragment (fimage_t *fimage, fragment_t *fragment)
{
- fimage = ensure_space (fimage, 1);
if (fimage->broken)
+ {
+ fragment_free (fragment);
+ return fimage;
+ }
+
+ if (fragment_is_broken (fragment))
+ {
+ fimage_free (fimage);
+ return (fimage_t *)&broken_fimage;
+ }
+
+ if (fragment_is_empty (fragment))
return fimage;
+ fimage = ensure_space (fimage, 1);
+ if (fimage->broken)
+ return fimage;
+
fimage->fragments[fimage->n_fragments++] = fragment;
return fimage;
}
+static fimage_t *
+fimage_new (void)
+{
+ fimage_t *fimage;
+
+ fimage = malloc (sizeof *fimage);
+ if (!fimage)
+ {
+ fragment_free (fragment);
+ return (fimage_t *)&broken_fimage;
+ }
+
+ fimage->broken = FALSE;
+ fimage->n_allocated_fragments = 1;
+ fimage->n_fragments = 0;
+
+ return fimage;
+}
+
+static fimage_t *
+make_image (fragment_t *fragment)
+{
+ return fimage_append_fragment (fimage_new(), fragment);
+}
+
fimage_t *
fimage_new_blank (int width, int height)
{
- return fimage_new (fragment_new_blank (width, height));
+ return make_image (fragment_new_blank (width, height));
}
fimage_t *
fimage_new_white (int width, int height)
{
- return fimage_new (fragment_new_white (width, height));
+ return make_image (fragment_new_white (width, height));
}
fimage_t *
fimage_new_traps (int width, int height,
int n_traps, pixman_trapezoid_t *traps)
{
- return fimage_new (fragment_new_traps (width, height, n_traps, traps));
+ return make_image (fragment_new_traps (width, height, n_traps, traps));
}
fimage_t *
@@ -108,7 +130,7 @@ fimage_new_glyphs (int width, int height,
int n_glyphs,
pixman_glyph_t *glyphs)
{
- return fimage_new (
+ return make_image (
fragment_new_glyphs (width, height, cache, n_glyphs, glyphs));
}
@@ -116,7 +138,7 @@ fimage_new_glyphs (int width, int height,
fimage_t *
fimage_new_image (int width, int height, pixman_image_t *image)
{
- return fimage_new (fragment_new_image (width, height, image));
+ return make_image (fragment_new_image (width, height, image));
}
@@ -125,21 +147,70 @@ fimage_t *
fimage_new_region (int width, int height,
pixman_region32_t *region)
{
- fragment1 = fragment_new_blank (width, height);
+ fragment_t *fragment1, *fragment2;
- fragment2 = fragment_new_region (region);
+ fragment1 = fragment_new_region (region);
- fragment1 = fragment_subtract (fragment1, fragment_2);
+ fragment2 = fragment_new_blank (width, height);
+ fragment2 = fragment_subtract (fragment1, fragment_2);
- image = fimage_new (fragment1);
- image = fimage_append_fragment (image, fragment2);
+ image = fimage_new ();
+ image = fimage_append (image, fragment1);
+ image = fimage_appned (image, fragment2);
return image;
}
+fimage_t *
+fimage_composite (fimage_t *fimage, pixman_op_t op, fimage_t *source)
+{
+ fragment_t *dfrag, *sfrag;
+ fimage_t *new_image;
+ int i, j;
+ int n;
+
+ if (fimage->broken || source->broken)
+ {
+ fimage_free (fimage);
+ return (fimage_t *)&broken_fimage;
+ }
+
+ new_image = fimage_new ();
+
+ for (i = 0; fimage->n_fragments; ++i)
+ {
+ for (j = 0; j < source->n_fragments; ++j)
+ {
+ fragment_t *new, *dfrag, *sfrag;
+
+ dfrag = fimage->fragments[i];
+ sfrag = source->fragments[j];
+
+ new = fragment_composite (dfrag, op, sfrag);
+
+ new_image = fimage_append_fragment (new_image, new);
+ new_image = fimage_append_fragment (new_image, dfrag);
+ }
+ }
+
+ fimage->n_fragments = 0;
+ fimage_free (fimage);
+
+ return new_image;
+}
+void
+fimage_paint (fimage_t *image, pixman_image_t *image)
+{
+ int i;
+ for (i = 0; i < image->n_fragments; ++i)
+ {
+ fragment_t *fragment = image->fragments[i];
+ fragment_apply (fragment, image);
+ }
+}
/*