bitmap opaque handling

svn path=/trunk/netsurf/; revision=6777
This commit is contained in:
Vincent Sanders 2009-03-11 21:28:34 +00:00
parent 305ab859ad
commit cdc47ee52c
4 changed files with 43 additions and 34 deletions

View File

@ -542,41 +542,30 @@ static bool fb_32bpp_bitmap(int x, int y, int width, int height,
/* plot the image */
pvideo = fb_32bpp_get_xy_loc(x0, y0);
for (yloop = yoff; yloop < height; yloop += bitmap->width) {
#if 1
for (xloop = 0; xloop < width; xloop++) {
abpixel = pixel[yloop + xloop + xoff];
if ((abpixel & 0xFF000000) != 0) {
if ((abpixel & 0xFF000000) != 0xFF000000) {
abpixel = fb_plotters_ablend(abpixel,
fb_32bpp_to_colour(*(pvideo + xloop)));
}
if (bitmap->opaque) {
for (yloop = yoff; yloop < height; yloop += bitmap->width) {
for (xloop = 0; xloop < width; xloop++) {
abpixel = pixel[yloop + xloop + xoff];
*(pvideo + xloop) = fb_colour_to_pixel(abpixel);
}
pvideo += (framebuffer->linelen >> 2);
}
#else
uint32_t *pvid = pvideo;
colour *pix = &pixel[yloop + xoff];
colour *epix = pix + width;
do {
colour *spix = pix;
while (pix < epix && !((abpixel = *pix) & 0xFF000000U)) pix++;
if (pix < epix) {
pvid += pix++ - spix;
do {
} else {
for (yloop = yoff; yloop < height; yloop += bitmap->width) {
for (xloop = 0; xloop < width; xloop++) {
abpixel = pixel[yloop + xloop + xoff];
if ((abpixel & 0xFF000000) != 0) {
if ((abpixel & 0xFF000000) != 0xFF000000) {
abpixel = fb_plotters_ablend(abpixel,
fb_32bpp_to_colour(*pvid));
abpixel = fb_plotters_ablend(abpixel,
fb_32bpp_to_colour(*(pvideo + xloop)));
}
*pvid++ = fb_colour_to_pixel(abpixel);
} while (pix < epix && ((abpixel = *pix++) & 0xFF000000U));
}
} while (pix < epix);
#endif
pvideo += (framebuffer->linelen >> 2);
}
*(pvideo + xloop) = fb_colour_to_pixel(abpixel);
}
}
pvideo += (framebuffer->linelen >> 2);
}
}
return true;
}

View File

@ -46,6 +46,7 @@ void *bitmap_create(int width, int height, unsigned int state)
if (bitmap->pixdata != NULL) {
bitmap->width = width;
bitmap->height = height;
bitmap->opaque = false;
} else {
free(bitmap);
bitmap=NULL;
@ -164,11 +165,15 @@ void bitmap_set_suspendable(void *bitmap, void *private_word,
*/
void bitmap_set_opaque(void *bitmap, bool opaque)
{
struct bitmap *bm = bitmap;
if (bitmap == NULL) {
LOG(("NULL bitmap!"));
return;
}
/* todo: set bitmap as opaque */
LOG(("setting bitmap %p to %s", bm, opaque?"opaque":"transparent"));
bm->opaque = opaque;
}
@ -180,13 +185,24 @@ void bitmap_set_opaque(void *bitmap, bool opaque)
*/
bool bitmap_test_opaque(void *bitmap)
{
int tst;
struct bitmap *bm = bitmap;
if (bitmap == NULL) {
LOG(("NULL bitmap!"));
return false;
}
/* todo: test if bitmap as opaque */
return false;
tst = bm->width * bm->height;
while (tst-- > 0) {
if (bm->pixdata[(tst << 2) + 3] != 0xff) {
LOG(("bitmap %p has transparency",bm));
return false;
}
}
LOG(("bitmap %p is opaque", bm));
return true;
}
@ -197,13 +213,14 @@ bool bitmap_test_opaque(void *bitmap)
*/
bool bitmap_get_opaque(void *bitmap)
{
struct bitmap *bm = bitmap;
if (bitmap == NULL) {
LOG(("NULL bitmap!"));
return false;
}
/* todo: get whether bitmap is opaque */
return false;
return bm->opaque;
}
int bitmap_get_width(void *bitmap)

View File

@ -23,6 +23,8 @@ struct bitmap {
int width;
int height;
uint8_t *pixdata;
bool opaque;
/* The following two are only used for cursors */
int hot_x;
int hot_y;

View File

@ -172,6 +172,7 @@ main(int argc, char **argv)
fprintf(f, " *\n * Do not edit this file directly.\n */\n\n");
fprintf(f, "#include <sys/types.h>\n\n");
fprintf(f, "#include <stdint.h>\n\n");
fprintf(f, "#include <stdbool.h>\n\n");
fprintf(f, "#include \"framebuffer/fb_bitmap.h\"\n\n");
fprintf(f, "static uint8_t %s_pixdata[] = {\n", argv[3]);