diff options
Diffstat (limited to 'framebuffer')
-rw-r--r-- | framebuffer/fb_32bpp_plotters.c | 98 | ||||
-rw-r--r-- | framebuffer/fb_font.h | 2 | ||||
-rw-r--r-- | framebuffer/fb_font_freetype.c | 4 |
3 files changed, 90 insertions, 14 deletions
diff --git a/framebuffer/fb_32bpp_plotters.c b/framebuffer/fb_32bpp_plotters.c index c5bf45968..11268d40a 100644 --- a/framebuffer/fb_32bpp_plotters.c +++ b/framebuffer/fb_32bpp_plotters.c @@ -38,6 +38,13 @@ fb_32bpp_get_xy_loc(int x, int y) (x << 2)); } +static inline colour fb_32bpp_to_colour(uint32_t pixel) +{ + return ((pixel & 0xFF) << 16) | + ((pixel & 0xFF00)) | + ((pixel & 0xFF0000) >> 16); +} + #define SIGN(x) ((x<0) ? -1 : ((x>0) ? 1 : 0)) static bool fb_32bpp_line(int x0, int y0, int x1, int y1, int width, @@ -182,7 +189,7 @@ static bool fb_32bpp_clg(colour c) static bool -fb_32bpp_draw_ft_bitmap(FT_Bitmap *bp, int x, int y, colour c) +fb_32bpp_draw_ft_monobitmap(FT_Bitmap *bp, int x, int y, colour c) { int height = bp->rows; int width = bp->width; @@ -252,6 +259,66 @@ fb_32bpp_draw_ft_bitmap(FT_Bitmap *bp, int x, int y, colour c) return true; } +static bool +fb_32bpp_draw_ft_bitmap(FT_Bitmap *bp, int x, int y, colour c) +{ + uint32_t *pvideo; + uint8_t *pixel = (uint8_t *)bp->buffer; + colour abpixel; /* alphablended pixel */ + int xloop, yloop; + int x0,y0,x1,y1; + int xoff, yoff; /* x and y offset into image */ + int height = bp->rows; + int width = bp->width; + uint32_t fgcol; + + /* The part of the scaled image actually displayed is cropped to the + * current context. + */ + x0 = x; + y0 = y; + x1 = x + width; + y1 = y + height; + + if (!fb_plotters_clip_rect_ctx(&x0, &y0, &x1, &y1)) + return true; + + if (height > (y1 - y0)) + height = (y1 - y0); + + if (width > (x1 - x0)) + width = (x1 - x0); + + xoff = x0 - x; + yoff = y0 - y; + + /* plot the image */ + pvideo = fb_32bpp_get_xy_loc(x0, y0); + + fgcol = c & 0xFFFFFF; + + for (yloop = 0; yloop < height; yloop++) { + for (xloop = 0; xloop < width; xloop++) { + abpixel = (pixel[((yoff + yloop) * bp->pitch) + xloop + xoff] << 24) | fgcol; + if ((abpixel & 0xFF000000) != 0) { + /* pixel is not transparent */ + if ((abpixel & 0xFF000000) != 0xFF) { + abpixel = fb_plotters_ablend(abpixel, + fb_32bpp_to_colour(*(pvideo + xloop))); + } + + *(pvideo + xloop) = ((abpixel & 0xFF) << 16) | + ((abpixel & 0xFF00)) | + ((abpixel & 0xFF0000) >> 16); + + } + } + pvideo += (framebuffer->linelen >> 2); + } + + return true; +} + static bool fb_32bpp_text(int x, int y, const struct css_style *style, const char *text, size_t length, colour bg, colour c) { @@ -266,17 +333,26 @@ static bool fb_32bpp_text(int x, int y, const struct css_style *style, nxtchr = utf8_next(text, length, nxtchr); glyph_index = FT_Get_Char_Index(face, ucs4); - error = FT_Load_Glyph(face, glyph_index, FT_LOAD_RENDER | - FT_LOAD_MONOCHROME | - FT_LOAD_FORCE_AUTOHINT); + error = FT_Load_Glyph(face, + glyph_index, + FT_LOAD_RENDER | + FT_LOAD_FORCE_AUTOHINT | + ft_load_type); if (error) continue; /* now, draw to our target surface */ - fb_32bpp_draw_ft_bitmap( &face->glyph->bitmap, - x + face->glyph->bitmap_left, - y - face->glyph->bitmap_top, - c); + if (face->glyph->bitmap.pixel_mode == FT_PIXEL_MODE_MONO) { + fb_32bpp_draw_ft_monobitmap( &face->glyph->bitmap, + x + face->glyph->bitmap_left, + y - face->glyph->bitmap_top, + c); + } else { + fb_32bpp_draw_ft_bitmap( &face->glyph->bitmap, + x + face->glyph->bitmap_left, + y - face->glyph->bitmap_top, + c); + } x += face->glyph->advance.x >> 6; @@ -384,12 +460,6 @@ static inline colour ablend(colour pixel) return pixel; } -static inline colour fb_32bpp_to_colour(uint32_t pixel) -{ - return ((pixel & 0xFF) << 16) | - ((pixel & 0xFF00)) | - ((pixel & 0xFF0000) >> 16); -} static bool fb_32bpp_bitmap(int x, int y, int width, int height, struct bitmap *bitmap, colour bg, diff --git a/framebuffer/fb_font.h b/framebuffer/fb_font.h index 2e453d465..cd32e5193 100644 --- a/framebuffer/fb_font.h +++ b/framebuffer/fb_font.h @@ -29,6 +29,8 @@ bool fb_font_finalise(void); FT_Face fb_get_face(const struct css_style *style); +extern int ft_load_type; + #else #include "utils/utf8.h" diff --git a/framebuffer/fb_font_freetype.c b/framebuffer/fb_font_freetype.c index 36130fa55..3469ba5b6 100644 --- a/framebuffer/fb_font_freetype.c +++ b/framebuffer/fb_font_freetype.c @@ -32,6 +32,7 @@ static FT_Library library; static FT_Face face_sans_serif; +int ft_load_type; utf8_convert_ret utf8_to_local_encoding(const char *string, size_t len, @@ -68,6 +69,9 @@ bool fb_font_init(void) return false; } + /* set the default render mode */ + // ft_load_type = FT_LOAD_MONOCHROME; + ft_load_type = 0; return true; } |