diff options
author | Vincent Sanders <vince@netsurf-browser.org> | 2009-04-08 21:39:21 +0000 |
---|---|---|
committer | Vincent Sanders <vince@netsurf-browser.org> | 2009-04-08 21:39:21 +0000 |
commit | 762784c01baec27dffcf1437b2427a45d82a59de (patch) | |
tree | bc3231dbb7166448d16785c6d543808d8f4ee8a8 | |
parent | 08bf9ed1ac868954feefdc812204fd6a4d4767e7 (diff) | |
download | libnsfb-762784c01baec27dffcf1437b2427a45d82a59de.tar.gz libnsfb-762784c01baec27dffcf1437b2427a45d82a59de.tar.bz2 |
add font glyph plotting support
svn path=/trunk/libnsfb/; revision=7068
-rw-r--r-- | include/libnsfb_plot.h | 11 | ||||
-rw-r--r-- | include/nsfb_plot.h | 15 | ||||
-rw-r--r-- | src/32bpp_plotters.c | 113 | ||||
-rw-r--r-- | src/plot.c | 17 | ||||
-rw-r--r-- | test/plottest.c | 70 |
5 files changed, 222 insertions, 4 deletions
diff --git a/include/libnsfb_plot.h b/include/libnsfb_plot.h index 64aa729..2b19b52 100644 --- a/include/libnsfb_plot.h +++ b/include/libnsfb_plot.h @@ -69,4 +69,13 @@ bool nsfb_plot_copy(nsfb_t *nsfb, int srcx, int srcy, int width, int height, int /** Plot bitmap. */ -bool nsfb_plot_bitmap(nsfb_t *nsfb, nsfb_bbox_t *loc, nsfb_colour_t *pixel, int bmp_width, int bmp_height, int bmp_stride, bool alpha); +bool nsfb_plot_bitmap(nsfb_t *nsfb, nsfb_bbox_t *loc, const nsfb_colour_t *pixel, int bmp_width, int bmp_height, int bmp_stride, bool alpha); + +/** Plot an 8 bit glyph. + */ +bool nsfb_plot_glyph8(nsfb_t *nsfb, nsfb_bbox_t *loc, const uint8_t *pixel, int pitch, nsfb_colour_t c); + + +/** Plot an 1 bit glyph. + */ +bool nsfb_plot_glyph1(nsfb_t *nsfb, nsfb_bbox_t *loc, const uint8_t *pixel, int pitch, nsfb_colour_t c); diff --git a/include/nsfb_plot.h b/include/nsfb_plot.h index 2dbd22a..02da331 100644 --- a/include/nsfb_plot.h +++ b/include/nsfb_plot.h @@ -60,7 +60,7 @@ typedef bool (nsfb_plotfn_ellipse_fill_t)(nsfb_t *nsfb, nsfb_bbox_t *ellipse, ns /** Plot bitmap */ -typedef bool (nsfb_plotfn_bitmap_t)(nsfb_t *nsfb, nsfb_bbox_t *loc, nsfb_colour_t *pixel, int bmp_width, int bmp_height, int bmp_stride, bool alpha); +typedef bool (nsfb_plotfn_bitmap_t)(nsfb_t *nsfb, nsfb_bbox_t *loc, const nsfb_colour_t *pixel, int bmp_width, int bmp_height, int bmp_stride, bool alpha); /** Copy an area of screen @@ -69,6 +69,17 @@ typedef bool (nsfb_plotfn_bitmap_t)(nsfb_t *nsfb, nsfb_bbox_t *loc, nsfb_colour */ typedef bool (nsfb_plotfn_copy_t)(nsfb_t *nsfb, int srcx, int srcy, int width, int height, int dstx, int dsty); + +/** Plot an 8 bit glyph. + */ +typedef bool (nsfb_plotfn_glyph8_t)(nsfb_t *nsfb, nsfb_bbox_t *loc, const uint8_t *pixel, int pitch, nsfb_colour_t c); + + +/** Plot an 1 bit glyph. + */ +typedef bool (nsfb_plotfn_glyph1_t)(nsfb_t *nsfb, nsfb_bbox_t *loc, const uint8_t *pixel, int pitch, nsfb_colour_t c); + + /** plotter function table. */ typedef struct nsfb_plotter_fns_s { nsfb_plotfn_clg_t *clg; @@ -83,6 +94,8 @@ typedef struct nsfb_plotter_fns_s { nsfb_plotfn_bitmap_t *bitmap; nsfb_plotfn_point_t *point; nsfb_plotfn_copy_t *copy; + nsfb_plotfn_glyph8_t *glyph8; + nsfb_plotfn_glyph1_t *glyph1; } nsfb_plotter_fns_t; diff --git a/src/32bpp_plotters.c b/src/32bpp_plotters.c index eb6d162..c52faad 100644 --- a/src/32bpp_plotters.c +++ b/src/32bpp_plotters.c @@ -225,10 +225,119 @@ static bool point(nsfb_t *nsfb, int x, int y, nsfb_colour_t c) return true; } +static bool +glyph1(nsfb_t *nsfb, + nsfb_bbox_t *loc, + const uint8_t *pixel, + int pitch, + nsfb_colour_t c) +{ + uint32_t *pvideo; + int xloop, yloop; + int xoff, yoff; /* x and y offset into image */ + int x = loc->x0; + int y = loc->y0; + int width = loc->x1 - loc->x0; + int height = loc->y1 - loc->y0; + uint32_t fgcol; + const uint8_t *fntd; + uint8_t row; + + if (!nsfb_plot_clip_ctx(nsfb, loc)) + return true; + + if (height > (loc->y1 - loc->y0)) + height = (loc->y1 - loc->y0); + + if (width > (loc->x1 - loc->x0)) + width = (loc->x1 - loc->x0); + + xoff = loc->x0 - x; + yoff = loc->y0 - y; + + /* plot the image */ + pvideo = get_xy_loc(nsfb, loc->x0, loc->y0); + + fgcol = colour_to_pixel(c); + + for (yloop = yoff; yloop < height; yloop++) { + fntd = pixel + (yloop * (pitch>>3)) + (xoff>>3); + row = (*fntd++) << (xoff & 3); + for (xloop = xoff; xloop < width ; xloop++) { + if (((xloop % 8) == 0) && (xloop != 0)) { + row = *fntd++; + } + + if ((row & 0x80) != 0) { + *(pvideo + xloop) = fgcol; + } + row = row << 1; + + } + + pvideo += (nsfb->linelen >> 2); + } + + return true; +} + +static bool +glyph8(nsfb_t *nsfb, + nsfb_bbox_t *loc, + const uint8_t *pixel, + int pitch, + nsfb_colour_t c) +{ + uint32_t *pvideo; + nsfb_colour_t abpixel; /* alphablended pixel */ + int xloop, yloop; + int xoff, yoff; /* x and y offset into image */ + int x = loc->x0; + int y = loc->y0; + int width = loc->x1 - loc->x0; + int height = loc->y1 - loc->y0; + uint32_t fgcol; + + if (!nsfb_plot_clip_ctx(nsfb, loc)) + return true; + + if (height > (loc->y1 - loc->y0)) + height = (loc->y1 - loc->y0); + + if (width > (loc->x1 - loc->x0)) + width = (loc->x1 - loc->x0); + + xoff = loc->x0 - x; + yoff = loc->y0 - y; + + /* plot the image */ + pvideo = get_xy_loc(nsfb, loc->x0, loc->y0); + + fgcol = c & 0xFFFFFF; + + for (yloop = 0; yloop < height; yloop++) { + for (xloop = 0; xloop < width; xloop++) { + abpixel = (pixel[((yoff + yloop) * pitch) + xloop + xoff] << 24) | fgcol; + if ((abpixel & 0xFF000000) != 0) { + /* pixel is not transparent */ + if ((abpixel & 0xFF000000) != 0xFF000000) { + abpixel = nsfb_plot_ablend(abpixel, + pixel_to_colour(*(pvideo + xloop))); + } + + *(pvideo + xloop) = colour_to_pixel(abpixel); + } + } + pvideo += (nsfb->linelen >> 2); + } + + return true; +} + static bool bitmap(nsfb_t *nsfb, nsfb_bbox_t *loc, - nsfb_colour_t *pixel, + const nsfb_colour_t *pixel, int bmp_width, int bmp_height, int bmp_stride, @@ -311,6 +420,8 @@ const nsfb_plotter_fns_t _nsfb_32bpp_plotters = { .fill = fill, .point = point, .bitmap = bitmap, + .glyph8 = glyph8, + .glyph1 = glyph1, }; /* @@ -108,7 +108,22 @@ bool nsfb_plot_copy(nsfb_t *nsfb, int srcx, int srcy, int width, int height, int return nsfb->plotter_fns->copy(nsfb, srcx, srcy, width, height, dstx, dsty); } -bool nsfb_plot_bitmap(nsfb_t *nsfb, nsfb_bbox_t *loc, nsfb_colour_t *pixel, int bmp_width, int bmp_height, int bmp_stride, bool alpha) +bool nsfb_plot_bitmap(nsfb_t *nsfb, nsfb_bbox_t *loc, const nsfb_colour_t *pixel, int bmp_width, int bmp_height, int bmp_stride, bool alpha) { return nsfb->plotter_fns->bitmap(nsfb, loc, pixel, bmp_width, bmp_height, bmp_stride, alpha); } + +/** Plot an 8 bit glyph. + */ +bool nsfb_plot_glyph8(nsfb_t *nsfb, nsfb_bbox_t *loc, const uint8_t *pixel, int pitch, nsfb_colour_t c) +{ + return nsfb->plotter_fns->glyph8(nsfb, loc, pixel, pitch, c); +} + + +/** Plot an 1 bit glyph. + */ +bool nsfb_plot_glyph1(nsfb_t *nsfb, nsfb_bbox_t *loc, const uint8_t *pixel, int pitch, nsfb_colour_t c) +{ + return nsfb->plotter_fns->glyph1(nsfb, loc, pixel, pitch, c); +} diff --git a/test/plottest.c b/test/plottest.c index 992fdd9..f2008fa 100644 --- a/test/plottest.c +++ b/test/plottest.c @@ -14,6 +14,56 @@ extern const struct { unsigned char pixel_data[132 * 135 * 4 + 1]; } nsglobe; +const struct { + unsigned int w; + unsigned int h; + unsigned char data[16]; +} Mglyph1 = { + 8, 16, { + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0xc6, /* 11000110 */ + 0xee, /* 11101110 */ + 0xfe, /* 11111110 */ + 0xfe, /* 11111110 */ + 0xd6, /* 11010110 */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0xc6, /* 11000110 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + 0x00, /* 00000000 */ + } +}; + +const struct { + unsigned int w; + unsigned int h; + unsigned char data[16 * 8]; +} Mglyph8 = { + 8, 16, { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 00000000 */ + 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x44, 0x00, /* 00000000 */ + 0xaa, 0xff, 0x00, 0x00, 0x00, 0xff, 0xaa, 0x00, /* 11000110 */ + 0xaa, 0xff, 0xff, 0x00, 0xff, 0xff, 0xaa, 0x00, /* 11101110 */ + 0xaa, 0xff, 0xff, 0xff, 0xff, 0xff, 0xaa, 0x00, /* 11111110 */ + 0xaa, 0xff, 0xff, 0xff, 0xff, 0xff, 0xaa, 0x00, /* 11111110 */ + 0xaa, 0xff, 0x00, 0x00, 0x00, 0xff, 0xaa, 0x00, /* 11010110 */ + 0xaa, 0xff, 0x00, 0x00, 0x00, 0xff, 0xaa, 0x00, /* 11000110 */ + 0xaa, 0xff, 0x00, 0x00, 0x00, 0xff, 0xaa, 0x00, /* 11000110 */ + 0xaa, 0xff, 0x00, 0x00, 0x00, 0xff, 0xaa, 0x00, /* 11000110 */ + 0xaa, 0xff, 0x00, 0x00, 0x00, 0xff, 0xaa, 0x00, /* 11000110 */ + 0xaa, 0xff, 0x00, 0x00, 0x00, 0xff, 0xaa, 0x00, /* 11000110 */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 00000000 */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 00000000 */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 00000000 */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 00000000 */ + } +}; + int main(int argc, char **argv) { nsfb_t *nsfb; @@ -147,6 +197,26 @@ int main(int argc, char **argv) nsfb_plot_bitmap(nsfb, &box3, (nsfb_colour_t *)nsglobe.pixel_data, nsglobe.width, nsglobe.height, nsglobe.width, true); + /* test glyph plotting */ + for (loop = 100; loop < 200; loop+= Mglyph1.w) { + box3.x0 = loop; + box3.y0 = 20; + box3.x1 = box3.x0 + Mglyph8.w; + box3.y1 = box3.y0 + Mglyph8.h; + + nsfb_plot_glyph1(nsfb, &box3, Mglyph1.data, Mglyph1.w, 0xff000000); + } + + /* test glyph plotting */ + for (loop = 100; loop < 200; loop+= Mglyph8.w) { + box3.x0 = loop; + box3.y0 = 50; + box3.x1 = box3.x0 + Mglyph8.w; + box3.y1 = box3.y0 + Mglyph8.h; + + nsfb_plot_glyph8(nsfb, &box3, Mglyph8.data, Mglyph8.w, 0xff000000); + } + nsfb_release(nsfb, &box); /* random rectangles in clipped area*/ |