/** * Determine if a content is opaque * * \param c Content to retrieve opacity from * \return false if the content is not opaque or information is not * known else true. */ bool content__get_opaque(struct content *c) { bool opaque = false; if ((c != NULL) && (c->handler != NULL) && (c->handler->type != NULL) && (c->handler->type() == CONTENT_IMAGE) && (c->handler->get_internal != NULL) ) { struct bitmap *bitmap = NULL; bitmap = c->handler->get_internal(c, NULL); if (bitmap != NULL) { opaque = bitmap_get_opaque(bitmap); } } return opaque; }
static bool framebuffer_plot_bitmap(int x, int y, int width, int height, struct bitmap *bitmap, colour bg, bitmap_flags_t flags) { int xf,yf; nsfb_bbox_t loc; nsfb_bbox_t clipbox; bool repeat_x = (flags & BITMAPF_REPEAT_X); bool repeat_y = (flags & BITMAPF_REPEAT_Y); int bmwidth; int bmheight; unsigned char *bmptr; nsfb_t *bm = (nsfb_t *)bitmap; /* x and y define coordinate of top left of of the initial explicitly * placed tile. The width and height are the image scaling and the * bounding box defines the extent of the repeat (which may go in all * four directions from the initial tile). */ if (!(repeat_x || repeat_y)) { /* Not repeating at all, so just plot it */ loc.x0 = x; loc.y0 = y; loc.x1 = loc.x0 + width; loc.y1 = loc.y0 + height; return nsfb_plot_copy(bm, NULL, nsfb, &loc); } nsfb_plot_get_clip(nsfb, &clipbox); nsfb_get_geometry(bm, &bmwidth, &bmheight, NULL); nsfb_get_buffer(bm, &bmptr, NULL); /* Optimise tiled plots of 1x1 bitmaps by replacing with a flat fill * of the area. Can only be done when image is fully opaque. */ if ((bmwidth == 1) && (bmheight == 1)) { if ((*(nsfb_colour_t *)bmptr & 0xff000000) != 0) { return nsfb_plot_rectangle_fill(nsfb, &clipbox, *(nsfb_colour_t *)bmptr); } } /* Optimise tiled plots of bitmaps scaled to 1x1 by replacing with * a flat fill of the area. Can only be done when image is fully * opaque. */ if ((width == 1) && (height == 1)) { if (bitmap_get_opaque(bm)) { /** TODO: Currently using top left pixel. Maybe centre * pixel or average value would be better. */ return nsfb_plot_rectangle_fill(nsfb, &clipbox, *(nsfb_colour_t *)bmptr); } } /* get left most tile position */ if (repeat_x) for (; x > clipbox.x0; x -= width); /* get top most tile position */ if (repeat_y) for (; y > clipbox.y0; y -= height); /* tile down and across to extents */ for (xf = x; xf < clipbox.x1; xf += width) { for (yf = y; yf < clipbox.y1; yf += height) { loc.x0 = xf; loc.y0 = yf; loc.x1 = loc.x0 + width; loc.y1 = loc.y0 + height; nsfb_plot_copy(bm, NULL, nsfb, &loc); if (!repeat_y) break; } if (!repeat_x) break; } return true; }
static bool framebuffer_plot_bitmap(int x, int y, int width, int height, struct bitmap *bitmap, colour bg, bitmap_flags_t flags) { nsfb_bbox_t loc; nsfb_bbox_t clipbox; bool repeat_x = (flags & BITMAPF_REPEAT_X); bool repeat_y = (flags & BITMAPF_REPEAT_Y); int bmwidth; int bmheight; int bmstride; enum nsfb_format_e bmformat; unsigned char *bmptr; nsfb_t *bm = (nsfb_t *)bitmap; /* x and y define coordinate of top left of of the initial explicitly * placed tile. The width and height are the image scaling and the * bounding box defines the extent of the repeat (which may go in all * four directions from the initial tile). */ if (!(repeat_x || repeat_y)) { /* Not repeating at all, so just plot it */ loc.x0 = x; loc.y0 = y; loc.x1 = loc.x0 + width; loc.y1 = loc.y0 + height; return nsfb_plot_copy(bm, NULL, nsfb, &loc); } nsfb_plot_get_clip(nsfb, &clipbox); nsfb_get_geometry(bm, &bmwidth, &bmheight, &bmformat); nsfb_get_buffer(bm, &bmptr, &bmstride); /* Optimise tiled plots of 1x1 bitmaps by replacing with a flat fill * of the area. Can only be done when image is fully opaque. */ if ((bmwidth == 1) && (bmheight == 1)) { if ((*(nsfb_colour_t *)bmptr & 0xff000000) != 0) { return nsfb_plot_rectangle_fill(nsfb, &clipbox, *(nsfb_colour_t *)bmptr); } } /* Optimise tiled plots of bitmaps scaled to 1x1 by replacing with * a flat fill of the area. Can only be done when image is fully * opaque. */ if ((width == 1) && (height == 1)) { if (bitmap_get_opaque(bm)) { /** TODO: Currently using top left pixel. Maybe centre * pixel or average value would be better. */ return nsfb_plot_rectangle_fill(nsfb, &clipbox, *(nsfb_colour_t *)bmptr); } } /* get left most tile position */ if (repeat_x) for (; x > clipbox.x0; x -= width); /* get top most tile position */ if (repeat_y) for (; y > clipbox.y0; y -= height); /* set up top left tile location */ loc.x0 = x; loc.y0 = y; loc.x1 = loc.x0 + width; loc.y1 = loc.y0 + height; /* plot tiling across and down to extents */ nsfb_plot_bitmap_tiles(nsfb, &loc, repeat_x ? ((clipbox.x1 - x) + width - 1) / width : 1, repeat_y ? ((clipbox.y1 - y) + height - 1) / height : 1, (nsfb_colour_t *)bmptr, bmwidth, bmheight, bmstride * 8 / 32, bmformat == NSFB_FMT_ABGR8888); return true; }