diff options
-rw-r--r-- | navit/font/freetype/font_freetype.c | 232 | ||||
-rw-r--r-- | navit/font/freetype/font_freetype.h | 20 | ||||
-rw-r--r-- | navit/graphics/gd/graphics_gd.c | 4 | ||||
-rw-r--r-- | navit/graphics/gtk_drawing_area/graphics_gtk_drawing_area.c | 4 | ||||
-rw-r--r-- | navit/graphics/opengl/graphics_opengl.c | 5 | ||||
-rw-r--r-- | navit/graphics/qt_qpainter/graphics_qt_qpainter.cpp | 4 | ||||
-rw-r--r-- | navit/graphics/sdl/graphics_sdl.c | 6 |
7 files changed, 61 insertions, 214 deletions
diff --git a/navit/font/freetype/font_freetype.c b/navit/font/freetype/font_freetype.c index ede39c06c..f41eff314 100644 --- a/navit/font/freetype/font_freetype.c +++ b/navit/font/freetype/font_freetype.c @@ -535,34 +535,19 @@ font_freetype_font_new(struct graphics_priv *gr, /** Implementation of font_freetype_methods.get_shadow. */ static int font_freetype_glyph_get_shadow(struct font_freetype_glyph *g, - unsigned char *data, int depth, int stride, struct color *foreground, struct color *background) + unsigned char *data, int stride, struct color *foreground, struct color *background) { - int mask0, mask1, mask2, x, y, w = g->w, h = g->h; + int x, y, w = g->w, h = g->h; unsigned int bg, fg; unsigned char *pm, *psp,*ps,*psn; - switch (depth) { - case 1: - fg=0xff; - bg=0x00; - break; - case 8: - fg=foreground->a>>COL_SHIFT; - bg=background->a>>COL_SHIFT; - break; - case 24: - case 32: - fg=((foreground->a>>COL_SHIFT)<<24)| - ((foreground->r>>COL_SHIFT)<<16)| - ((foreground->g>>COL_SHIFT)<<8)| - ((foreground->b>>COL_SHIFT)<<0); - bg=((background->a>>COL_SHIFT)<<24)| - ((background->r>>COL_SHIFT)<<16)| - ((background->g>>COL_SHIFT)<<8)| - ((background->b>>COL_SHIFT)<<0); - break; - default: - return 0; - } + fg=((foreground->a>>COL_SHIFT)<<24)| + ((foreground->r>>COL_SHIFT)<<16)| + ((foreground->g>>COL_SHIFT)<<8)| + ((foreground->b>>COL_SHIFT)<<0); + bg=((background->a>>COL_SHIFT)<<24)| + ((background->r>>COL_SHIFT)<<16)| + ((background->g>>COL_SHIFT)<<8)| + ((background->b>>COL_SHIFT)<<0); for (y = 0; y < h+2; y++) { if (stride) { ps = data + stride * y; @@ -570,25 +555,8 @@ font_freetype_glyph_get_shadow(struct font_freetype_glyph *g, unsigned char **dataptr=(unsigned char **)data; ps = dataptr[y]; } - switch (depth) { - case 1: - memset(ps, bg, (w+9)/2); - break; - case 8: - memset(ps, bg, w+2); - break; - case 24: - for (x = 0 ; x < w+2 ; x++) { - ps[x*3]=bg>>16; - ps[x*3+1]=bg>>8; - ps[x*3+2]=bg; - } - break; - case 32: - for (x = 0 ; x < w+2 ; x++) - ((unsigned int *)ps)[x]=bg; - break; - } + for (x = 0 ; x < w+2 ; x++) + ((unsigned int *)ps)[x]=bg; } for (y = 0; y < h; y++) { pm = g->pixmap + y * w; @@ -602,94 +570,18 @@ font_freetype_glyph_get_shadow(struct font_freetype_glyph *g, ps = dataptr[y+1]; psn = dataptr[y+2]; } - switch (depth) { - case 1: - mask0 = 0x4000; - mask1 = 0xe000; - mask2 = 0x4000; - for (x = 0; x < w; x++) { - if (*pm) { - psp[0] |= (mask0 >> 8); - if (mask0 & 0xff) - psp[1] |= mask0; - ps[0] |= (mask1 >> 8); - if (mask1 & 0xff) - ps[1] |= mask1; - psn[0] |= (mask2 >> 8); - if (mask2 & 0xff) - psn[1] |= mask2; - } - mask0 >>= 1; - mask1 >>= 1; - mask2 >>= 1; - if (! - ((mask0 >> 8) | (mask1 >> 8) | - (mask2 >> 8))) { - mask0 <<= 8; - mask1 <<= 8; - mask2 <<= 8; - psp++; - ps++; - psn++; - } - pm++; - } - break; - case 8: - for (x = 0; x < w; x++) { - if (*pm) { - psp[1] = fg; - ps[0] = fg; - ps[1] = fg; - ps[2] = fg; - psn[1] = fg; - } - psp++; - ps++; - psn++; - pm++; + for (x = 0; x < w; x++) { + if (*pm) { + ((unsigned int *)psp)[1]=fg; + ((unsigned int *)ps)[0]=fg; + ((unsigned int *)ps)[1]=fg; + ((unsigned int *)ps)[2]=fg; + ((unsigned int *)psn)[1]=fg; } - break; - case 24: - for (x = 0; x < w; x++) { - if (*pm) { - psp[3]=fg>>16; - psp[4]=fg>>8; - psp[5]=fg; - ps[0]=fg>>16; - ps[1]=fg>>8; - ps[2]=fg; - ps[3]=fg>>16; - ps[4]=fg>>8; - ps[5]=fg; - ps[6]=fg>>16; - ps[7]=fg>>8; - ps[8]=fg; - psn[3]=fg>>16; - psn[4]=fg>>8; - psn[5]=fg; - } - psp+=3; - ps+=3; - psn+=3; - pm++; - } - break; - case 32: - for (x = 0; x < w; x++) { - if (*pm) { - ((unsigned int *)psp)[1]=fg; - ((unsigned int *)ps)[0]=fg; - ((unsigned int *)ps)[1]=fg; - ((unsigned int *)ps)[2]=fg; - ((unsigned int *)psn)[1]=fg; - } - psp+=4; - ps+=4; - psn+=4; - pm++; - } - break; + psp+=4; + ps+=4; + psn+=4; + pm++; } } return 1; @@ -698,25 +590,15 @@ font_freetype_glyph_get_shadow(struct font_freetype_glyph *g, /** Implementation of font_freetype_methods.get_glyph. */ static int font_freetype_glyph_get_glyph(struct font_freetype_glyph *g, - unsigned char *data, int depth, int stride, struct color *fg, struct color *bg, struct color *transparent) + unsigned char *data, int stride, struct color *fg, struct color *bg, struct color *transparent) { int x, y, w = g->w, h = g->h; unsigned int tr; unsigned char v,vi,*pm, *ps; - switch (depth) { - case 8: - tr=transparent->a>>COL_SHIFT; - break; - case 24: - case 32: - tr=((transparent->a>>COL_SHIFT)<<24)| - ((transparent->r>>COL_SHIFT)<<16)| - ((transparent->g>>COL_SHIFT)<<8)| - ((transparent->b>>COL_SHIFT)<<0); - break; - default: - return 0; - } + tr=((transparent->a>>COL_SHIFT)<<24)| + ((transparent->r>>COL_SHIFT)<<16)| + ((transparent->g>>COL_SHIFT)<<8)| + ((transparent->b>>COL_SHIFT)<<0); for (y = 0; y < h; y++) { pm = g->pixmap + y * w; if (stride) { @@ -725,51 +607,19 @@ font_freetype_glyph_get_glyph(struct font_freetype_glyph *g, unsigned char **dataptr=(unsigned char **)data; ps = dataptr[y]; } - switch (depth) { - case 8: - for (x = 0; x < w; x++) { - v=*pm; - if (v) - *ps=fg->a; - else - *ps=tr; - ps++; - pm++; - } - break; - case 24: - for (x = 0; x < w; x++) { - v=*pm; - if (v) { - vi=255-v; - ps[0]=(((fg->r*v+bg->r*vi)/255)>>COL_SHIFT); - ps[1]=(((fg->g*v+bg->g*vi)/255)>>COL_SHIFT); - ps[2]=(((fg->b*v+bg->b*vi)/255)>>COL_SHIFT); - } else { - ps[0]=tr >> 16; - ps[1]=tr >> 8; - ps[2]=tr; - } - ps+=3; - pm++; - } - break; - case 32: - for (x = 0; x < w; x++) { - v=*pm; - if (v) { - vi=255-v; - ((unsigned int *)ps)[0]= - ((((fg->a*v+bg->a*vi)/255)>>COL_SHIFT)<<24)| - ((((fg->r*v+bg->r*vi)/255)>>COL_SHIFT)<<16)| - ((((fg->g*v+bg->g*vi)/255)>>COL_SHIFT)<<8)| - ((((fg->b*v+bg->b*vi)/255)>>COL_SHIFT)<<0); - } else - ((unsigned int *)ps)[0]=tr; - ps+=4; - pm++; - } - break; + for (x = 0; x < w; x++) { + v=*pm; + if (v) { + vi=255-v; + ((unsigned int *)ps)[0]= + ((((fg->a*v+bg->a*vi)/255)>>COL_SHIFT)<<24)| + ((((fg->r*v+bg->r*vi)/255)>>COL_SHIFT)<<16)| + ((((fg->g*v+bg->g*vi)/255)>>COL_SHIFT)<<8)| + ((((fg->b*v+bg->b*vi)/255)>>COL_SHIFT)<<0); + } else + ((unsigned int *)ps)[0]=tr; + ps+=4; + pm++; } } return 1; diff --git a/navit/font/freetype/font_freetype.h b/navit/font/freetype/font_freetype.h index d09dec59d..e4ef58bb9 100644 --- a/navit/font/freetype/font_freetype.h +++ b/navit/font/freetype/font_freetype.h @@ -63,39 +63,37 @@ struct font_freetype_methods { /** * @brief Get glyph "shadow", a glyph bitmap to be used as background. * - * This method returns a glyph shadow, a bitmap with the glyph, where individual glyphs have been - * "fattened" by expanding them by one pixel on each side. + * This method returns a glyph shadow, a bitmap with the glyph, where the glyph has been + * "fattened" by expanding it by one pixel on each side. * In Navit, the shadow is used as the background behind the glyph bitmaps (returned by * font_freetype_methods.get_glyph() ), to make the text easier to read. * * @param g glyph to render, usually created via font_freetype_methods.text_new() - * @param data buffer for result image bitmap. Size must be at least (stride * (g->h+2)). - * @param depth bit depth for result bitmap + * @param data buffer for result image bitmap. Size must be at least (4 * stride * (g->h+2)). * @param stride see font_freetype_methods.get_glyph(). Minimum: g->w+2. * @param foreground color for rendering the "shadow" * @param background color for rest of the bitmap (typically set to transparent) * @returns 0 if depth is invalid, 1 otherwise */ int (*get_shadow) (struct font_freetype_glyph * glyph, - unsigned char *data, int depth, int stride, struct color *fg, struct color *tr); + unsigned char *data, int stride, struct color *fg, struct color *tr); /** * @brief Get a glyph bitmap. * * This method returns a bitmap for rendering the supplied glyph. * * @param g glyph to render, usually obtained from a struct font_freetype_text created via font_freetype_methods.text_new() - * @param data buffer for result image bitmap. Size must be at least (stride * g->h). - * @param depth bit depth for result bitmap + * @param data buffer for result image bitmap. Size must be at least (4 * stride * g->h). * @param stride stride (bytes per data row) for result bitmap; must be at least g->w, but may include padding. * Special case: * If set to 0, 'data' is interpreted as an array of pointers to image data rows (i.e. unsigned char**). - * @param fg color for rendering the glyphs (depth 8 only uses alpha channel) - * @param bg color to alpha blend with fg for semi-transparent glyph pixels (only for depth 24 & 32) - * @param transparent color for background pixels (depth 8 only uses alpha channel) + * @param fg color for rendering the glyph + * @param bg color to alpha blend with fg for semi-transparent glyph pixels + * @param transparent color for background pixels * @returns 0 if depth is invalid, 1 otherwise */ int (*get_glyph) (struct font_freetype_glyph * glyph, - unsigned char *data, int depth, int stride, + unsigned char *data, int stride, struct color * fg, struct color * bg, struct color *tr); }; diff --git a/navit/graphics/gd/graphics_gd.c b/navit/graphics/gd/graphics_gd.c index b4991f30a..47868d622 100644 --- a/navit/graphics/gd/graphics_gd.c +++ b/navit/graphics/gd/graphics_gd.c @@ -430,7 +430,7 @@ draw_text(struct graphics_priv *gr, struct graphics_gc_priv *fg, struct graphics h=g->h; if (w && h) { im=gdImageCreateTrueColor(w+2, h+2); - gr->freetype_methods.get_shadow(g,(unsigned char *)(im->tpixels),32,0,&bgc,&transparent); + gr->freetype_methods.get_shadow(g,(unsigned char *)(im->tpixels),0,&bgc,&transparent); gdImageCopy(gr->im, im, ((x+g->x)>>6)-1, ((y+g->y)>>6)-1, 0, 0, w+2, h+2); gdImageDestroy(im); } @@ -450,7 +450,7 @@ draw_text(struct graphics_priv *gr, struct graphics_gc_priv *fg, struct graphics h=g->h; if (w && h) { im=gdImageCreateTrueColor(w, h); - gr->freetype_methods.get_glyph(g,(unsigned char *)(im->tpixels),32,0,&fgc,&bgc,&transparent); + gr->freetype_methods.get_glyph(g,(unsigned char *)(im->tpixels),0,&fgc,&bgc,&transparent); gdImageCopy(gr->im, im, (x+g->x)>>6, (y+g->y)>>6, 0, 0, w, h); gdImageDestroy(im); } diff --git a/navit/graphics/gtk_drawing_area/graphics_gtk_drawing_area.c b/navit/graphics/gtk_drawing_area/graphics_gtk_drawing_area.c index 332673529..665d306e3 100644 --- a/navit/graphics/gtk_drawing_area/graphics_gtk_drawing_area.c +++ b/navit/graphics/gtk_drawing_area/graphics_gtk_drawing_area.c @@ -366,7 +366,7 @@ display_text_draw(struct font_freetype_text *text, struct graphics_priv *gr, str unsigned char *shadow; stride=cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, g->w+2); shadow=g_malloc(stride*(g->h+2)); - gr->freetype_methods.get_shadow(g, shadow, 32, stride, &bg->c, &transparent); + gr->freetype_methods.get_shadow(g, shadow, stride, &bg->c, &transparent); draw_rgb_image_buffer(gr->cairo, g->w+2, g->h+2, ((x+g->x)>>6)-1, ((y+g->y)>>6)-1, stride, shadow); g_free(shadow); } @@ -384,7 +384,7 @@ display_text_draw(struct font_freetype_text *text, struct graphics_priv *gr, str unsigned char *glyph; stride=cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, g->w); glyph=g_malloc(stride*g->h); - gr->freetype_methods.get_glyph(g, glyph, 32, stride, &fg->c, bg?&bg->c:&transparent, &transparent); + gr->freetype_methods.get_glyph(g, glyph, stride, &fg->c, bg?&bg->c:&transparent, &transparent); draw_rgb_image_buffer(gr->cairo, g->w, g->h, (x+g->x)>>6, (y+g->y)>>6, stride, glyph); g_free(glyph); } diff --git a/navit/graphics/opengl/graphics_opengl.c b/navit/graphics/opengl/graphics_opengl.c index 742dcae51..b6e0fb41a 100644 --- a/navit/graphics/opengl/graphics_opengl.c +++ b/navit/graphics/opengl/graphics_opengl.c @@ -921,7 +921,7 @@ display_text_draw(struct font_freetype_text *text, if (color) { shadow = g_malloc(stride * (g->h + 2)); gr->freetype_methods.get_shadow(g, shadow, - 32, stride, + stride, &white, &transparent); #ifdef USE_OPENGLES @@ -961,7 +961,6 @@ display_text_draw(struct font_freetype_text *text, g_malloc(stride * g->h * 4); gr->freetype_methods.get_glyph(g, glyph, - 32, stride * 4, &black, @@ -989,7 +988,7 @@ display_text_draw(struct font_freetype_text *text, stride *= 4; glyph = g_malloc(stride * g->h); gr->freetype_methods.get_glyph(g, glyph, - 32, stride, + stride, &black, &white, &transparent); diff --git a/navit/graphics/qt_qpainter/graphics_qt_qpainter.cpp b/navit/graphics/qt_qpainter/graphics_qt_qpainter.cpp index 20ac0c296..714f0753e 100644 --- a/navit/graphics/qt_qpainter/graphics_qt_qpainter.cpp +++ b/navit/graphics/qt_qpainter/graphics_qt_qpainter.cpp @@ -420,7 +420,7 @@ static void draw_text(struct graphics_priv *gr, struct graphics_gc_priv *fg, str unsigned char *data; QImage img(g->w+2, g->h+2, QImage::Format_ARGB32_Premultiplied); data=img.bits(); - gr->freetype_methods.get_shadow(g,(unsigned char *)data,32,img.bytesPerLine(),bgc,&transparent); + gr->freetype_methods.get_shadow(g,(unsigned char *)data,img.bytesPerLine(),bgc,&transparent); painter->drawImage(((x+g->x)>>6)-1, ((y+g->y)>>6)-1, img); } @@ -439,7 +439,7 @@ static void draw_text(struct graphics_priv *gr, struct graphics_gc_priv *fg, str unsigned char *data; QImage img(g->w, g->h, QImage::Format_ARGB32_Premultiplied); data=img.bits(); - gr->freetype_methods.get_glyph(g,(unsigned char *)data,32,img.bytesPerLine(),fgc,bgc,&transparent); + gr->freetype_methods.get_glyph(g,(unsigned char *)data,img.bytesPerLine(),fgc,bgc,&transparent); painter->drawImage((x+g->x)>>6, (y+g->y)>>6, img); } x+=g->dx; diff --git a/navit/graphics/sdl/graphics_sdl.c b/navit/graphics/sdl/graphics_sdl.c index b01af5c3f..e5d9f7872 100644 --- a/navit/graphics/sdl/graphics_sdl.c +++ b/navit/graphics/sdl/graphics_sdl.c @@ -650,7 +650,7 @@ display_text_draw(struct font_freetype_text *text, stride = (g->w + 2) * 4; if (color) { resize_ft_buffer(stride * (g->h + 2)); - gr->freetype_methods.get_shadow(g, ft_buffer, 32, stride, &white, &transparent); + gr->freetype_methods.get_shadow(g, ft_buffer, stride, &white, &transparent); SDL_Surface *glyph_surface = SDL_CreateRGBSurfaceFrom(ft_buffer, g->w + 2, g->h + 2, @@ -684,7 +684,7 @@ display_text_draw(struct font_freetype_text *text, stride = g->w; if (bg) { resize_ft_buffer(stride * g->h * 4); - gr->freetype_methods.get_glyph(g, ft_buffer, 32, + gr->freetype_methods.get_glyph(g, ft_buffer, stride * 4, &black, &white, &transparent); SDL_Surface *glyph_surface = @@ -704,7 +704,7 @@ display_text_draw(struct font_freetype_text *text, } stride *= 4; resize_ft_buffer(stride * g->h); - gr->freetype_methods.get_glyph(g, ft_buffer, 32, stride, + gr->freetype_methods.get_glyph(g, ft_buffer, stride, &black, &white, &transparent); int ii, jj; |