summaryrefslogtreecommitdiff
path: root/riscos/bitmap.c
diff options
context:
space:
mode:
authorRichard Wilson <rjw@netsurf-browser.org>2004-10-04 23:54:42 +0000
committerRichard Wilson <rjw@netsurf-browser.org>2004-10-04 23:54:42 +0000
commit403f12872d55a71b04287ed828be0c63be19e856 (patch)
tree190dbf327b98bb49831dc609f6c13bd828ded377 /riscos/bitmap.c
parent7144ce65ebbc7b1cb77d1f6b678a6d2b3c6547d1 (diff)
downloadnetsurf-403f12872d55a71b04287ed828be0c63be19e856.tar.gz
netsurf-403f12872d55a71b04287ed828be0c63be19e856.tar.bz2
[project @ 2004-10-04 23:54:42 by rjw]
Moved GIF file reading to image/, optimisation of plotting for GIFs, JNGs, PNGs and JPEGs, initial work for toolbar customisation. Possibly some other things too. svn path=/import/netsurf/; revision=1301
Diffstat (limited to 'riscos/bitmap.c')
-rw-r--r--riscos/bitmap.c46
1 files changed, 42 insertions, 4 deletions
diff --git a/riscos/bitmap.c b/riscos/bitmap.c
index 892aed3b6..b758e82e7 100644
--- a/riscos/bitmap.c
+++ b/riscos/bitmap.c
@@ -39,8 +39,11 @@ struct bitmap *bitmap_create(int width, int height)
osspriteop_area *sprite_area;
osspriteop_header *sprite;
+ if ((width == 0) || (height == 0))
+ return NULL;
+
area_size = 16 + 44 + width * height * 4;
- bitmap = calloc(area_size, 1);
+ bitmap = calloc(sizeof(struct bitmap) + area_size, 1);
if (!bitmap)
return NULL;
@@ -54,7 +57,7 @@ struct bitmap *bitmap_create(int width, int height)
/* sprite control block */
sprite = (osspriteop_header *) (sprite_area + 1);
sprite->size = area_size - 16;
- memset(sprite->name, 0x00, 12);
+/* memset(sprite->name, 0x00, 12); */
strncpy(sprite->name, "bitmap", 12);
sprite->width = width - 1;
sprite->height = height - 1;
@@ -68,6 +71,40 @@ struct bitmap *bitmap_create(int width, int height)
/**
+ * Sets whether a bitmap should be plotted opaque
+ *
+ * \param bitmap a bitmap, as returned by bitmap_create()
+ * \param opaque whether the bitmap should be plotted opaque
+ */
+void bitmap_set_opaque(struct bitmap *bitmap, bool opaque)
+{
+ assert(bitmap);
+ bitmap->opaque = opaque;
+}
+
+
+/**
+ * Tests whether a bitmap has an opaque alpha channel
+ *
+ * \param bitmap a bitmap, as returned by bitmap_create()
+ * \return whether the bitmap is opaque
+ */
+bool bitmap_test_opaque(struct bitmap *bitmap)
+{
+ assert(bitmap);
+ char *sprite = bitmap_get_buffer(bitmap);
+ unsigned int width = bitmap_get_rowstride(bitmap);
+ osspriteop_header *sprite_header =
+ (osspriteop_header *) (&(bitmap->sprite_area) + 1);
+ unsigned int height = (sprite_header->height + 1);
+ unsigned int size = width * height;
+ for (unsigned int i = 3; i < size; i += 4)
+ if (sprite[i] != 0xff)
+ return false;
+ return true;
+}
+
+/**
* Return a pointer to the pixel data in a bitmap.
*
* \param bitmap a bitmap, as returned by bitmap_create()
@@ -80,7 +117,7 @@ struct bitmap *bitmap_create(int width, int height)
char *bitmap_get_buffer(struct bitmap *bitmap)
{
assert(bitmap);
- return ((char *) bitmap) + 16 + 44;
+ return ((char *) (&(bitmap->sprite_area))) + 16 + 44;
}
@@ -124,7 +161,8 @@ bool bitmap_redraw(struct content *c, int x, int y,
{
return image_redraw(&(c->bitmap->sprite_area), x, y, width, height,
c->width * 2, c->height * 2, background_colour,
- false, false, IMAGE_PLOT_TINCT_ALPHA);
+ false, false, ((c->bitmap->opaque) ?
+ IMAGE_PLOT_TINCT_OPAQUE : IMAGE_PLOT_TINCT_ALPHA));
}