[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[freetype2-demos] master b786a43: [graph] Fix color management bugs incl
From: |
Alexei Podtelezhnikov |
Subject: |
[freetype2-demos] master b786a43: [graph] Fix color management bugs including `ftmulti'. |
Date: |
Thu, 4 Jun 2020 23:40:55 -0400 (EDT) |
branch: master
commit b786a4313ca0cae72e35fbec531bac9ac0ceca08
Author: Alexei Podtelezhnikov <apodtele@gmail.com>
Commit: Alexei Podtelezhnikov <apodtele@gmail.com>
[graph] Fix color management bugs including `ftmulti'.
* graph/gblblit.c (grSetTargetPenBrush): New function to manage color
and other parameters required for direct rendering.
(grBlitGlyphToSurface): Use it here to decode color only.
* src/ftcommon.h (FTDemo_Sketch_Glyph_Color): Use it here in full.
* graph/graph.h: Update docs.
---
ChangeLog | 10 ++++++
graph/gblblit.c | 102 ++++++++++++++++++++++++++++++++++++--------------------
graph/graph.h | 23 +++++++++++++
src/ftcommon.c | 30 +----------------
4 files changed, 100 insertions(+), 65 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index f4ed6c9..4f48686 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2020-06-04 Alexei Podtelezhnikov <apodtele@gmail.com>
+
+ [graph] Fix color management bugs including `ftmulti'.
+
+ * graph/gblblit.c (grSetTargetPenBrush): New function to manage color
+ and other parameters required for direct rendering.
+ (grBlitGlyphToSurface): Use it here to decode color only.
+ * src/ftcommon.h (FTDemo_Sketch_Glyph_Color): Use it here in full.
+ * graph/graph.h: Update docs.
+
2020-06-01 Alexei Podtelezhnikov <apodtele@gmail.com>
[ftgrid,ftstring,ftview] Avoid uninitialized `event.type'.
diff --git a/graph/gblblit.c b/graph/gblblit.c
index b5e30f7..a03821a 100644
--- a/graph/gblblit.c
+++ b/graph/gblblit.c
@@ -61,6 +61,8 @@
#define GRGB_TO_GRAY8(r,g,b) ( (unsigned char)( ( 2*(r) + 7*(g) + (b) ) / 10
) )
+#define GGRAY8_TO_RGB24(p) GRGB_PACK(p,p,p)
+
#define GRGB24_TO_GRAY8(p) ( (unsigned char)( ( 2*( ((p) >> 16) & 0xFF ) +
\
7*( ((p) >> 8) & 0xFF ) +
\
( ((p)) & 0xFF ) )
/ 10 ) )
@@ -345,6 +347,67 @@ gblender_blit_init( GBlenderBlit blit,
}
+GBLENDER_APIDEF( void )
+grSetTargetGamma( grBitmap* target,
+ double gamma )
+{
+ grSurface* surface = (grSurface*)target;
+
+
+ gblender_init( surface->gblender, gamma );
+}
+
+
+GBLENDER_APIDEF( void )
+grSetTargetPenBrush( grBitmap* target,
+ int x,
+ int y,
+ grColor color )
+{
+ grSurface* surface = (grSurface*)target;
+
+
+ surface->origin = target->buffer;
+ if ( target->pitch < 0 )
+ surface->origin += ( y - target->rows ) * target->pitch;
+ else
+ surface->origin += ( y - 1 ) * target->pitch;
+
+ switch ( target->mode )
+ {
+ case gr_pixel_mode_gray:
+ surface->origin += x;
+ surface->gray_spans = _gblender_spans_gray8;
+ surface->gcolor = GGRAY8_TO_RGB24( color.value );
+ break;
+ case gr_pixel_mode_rgb565:
+ surface->origin += x * 2;
+ surface->gray_spans = _gblender_spans_rgb565;
+ surface->gcolor = GRGB565_TO_RGB24( color.value );
+ break;
+ case gr_pixel_mode_rgb24:
+ surface->origin += x * 3;
+ surface->gray_spans = _gblender_spans_rgb24;
+ surface->gcolor = GRGB_PACK( color.chroma[0],
+ color.chroma[1],
+ color.chroma[2] );
+ break;
+ case gr_pixel_mode_rgb32:
+ surface->origin += x * 4;
+ surface->gray_spans = _gblender_spans_rgb32;
+ surface->gcolor = GRGB_PACK( color.chroma[0],
+ color.chroma[1],
+ color.chroma[2] );
+ break;
+ default:
+ (void)_gblender_spans_bgr565; /* unused */
+ surface->origin = NULL;
+ surface->gray_spans = (grSpanFunc)NULL;
+ surface->gcolor = 0;
+ }
+}
+
+
GBLENDER_APIDEF( int )
grBlitGlyphToSurface( grSurface* surface,
grBitmap* glyph,
@@ -353,7 +416,6 @@ grBlitGlyphToSurface( grSurface* surface,
grColor color )
{
GBlenderBlitRec gblit[1];
- GBlenderPixel gcolor;
/* check arguments */
@@ -377,41 +439,9 @@ grBlitGlyphToSurface( grSurface* surface,
return -1;
}
- gcolor = ((GBlenderPixel)color.chroma[0] << 16) |
- ((GBlenderPixel)color.chroma[1] << 8 ) |
- ((GBlenderPixel)color.chroma[2] ) ;
+ /* this is not a direct mode but we need to decode color */
+ grSetTargetPenBrush( (grBitmap*)surface, 0, 0, color );
- gblender_blit_run( gblit, gcolor );
+ gblender_blit_run( gblit, surface->gcolor );
return 1;
}
-
-
-GBLENDER_APIDEF( void )
-grSetTargetGamma( grBitmap* target,
- double gamma )
-{
- grSurface* surface = (grSurface*)target;
-
-
- gblender_init( surface->gblender, gamma );
-
- /* not related to gamma but needs to be set */
- switch ( target->mode )
- {
- case gr_pixel_mode_gray:
- surface->gray_spans = _gblender_spans_gray8;
- break;
- case gr_pixel_mode_rgb32:
- surface->gray_spans = _gblender_spans_rgb32;
- break;
- case gr_pixel_mode_rgb24:
- surface->gray_spans = _gblender_spans_rgb24;
- break;
- case gr_pixel_mode_rgb565:
- surface->gray_spans = _gblender_spans_rgb565;
- break;
- default:
- (void)_gblender_spans_bgr565; /* unused */
- surface->gray_spans = (grSpanFunc)0;
- }
-}
diff --git a/graph/graph.h b/graph/graph.h
index 357bfb1..ce681a3 100644
--- a/graph/graph.h
+++ b/graph/graph.h
@@ -667,6 +667,7 @@
* blit glyphs
*
* <Input>
+ * target :: handle to target bitmap/surface
* gamma :: gamma value. <= 0 to select sRGB transfer function
*
**********************************************************************/
@@ -674,6 +675,28 @@
extern
void grSetTargetGamma( grBitmap* target, double gamma_value );
+
+ /**********************************************************************
+ *
+ * <Function>
+ * grSetTargetPenBrush
+ *
+ * <Description>
+ * set the pen position and brush color as required for direct mode.
+ *
+ * <Input>
+ * target :: handle to target bitmap/surface
+ * x, y :: pen position
+ * color :: color as defined by grFindColor
+ *
+ **********************************************************************/
+
+ extern
+ void grSetTargetPenBrush( grBitmap* target,
+ int x,
+ int y,
+ grColor color );
+
/* */
#endif /* GRAPH_H_ */
diff --git a/src/ftcommon.c b/src/ftcommon.c
index 8f01264..48c0d9b 100644
--- a/src/ftcommon.c
+++ b/src/ftcommon.c
@@ -1771,7 +1771,6 @@
{
grSurface* surface = (grSurface*)display->surface;
grBitmap* target = display->bitmap;
- unsigned char* origin;
FT_Outline* outline;
FT_Raster_Params params;
@@ -1779,35 +1778,8 @@
if ( glyph->format != FT_GLYPH_FORMAT_OUTLINE )
return FT_Err_Ok;
- origin = target->buffer;
- if ( target->pitch < 0 )
- origin += ( y - target->rows ) * target->pitch;
- else
- origin += ( y - 1 ) * target->pitch;
-
- switch ( target->mode )
- {
- case gr_pixel_mode_gray:
- origin += x;
- break;
- case gr_pixel_mode_rgb565:
- origin += x * 2;
- break;
- case gr_pixel_mode_rgb24:
- origin += x * 3;
- break;
- case gr_pixel_mode_rgb32:
- origin += x * 4;
- break;
- default:
- fprintf( stderr, "Unsupported target\n" );
- return FT_Err_Ok;
- }
+ grSetTargetPenBrush( target, x, y, color );
- surface->origin = origin;
- surface->gcolor = ((GBlenderPixel)color.chroma[0] << 16) |
- ((GBlenderPixel)color.chroma[1] << 8 ) |
- ((GBlenderPixel)color.chroma[2] ) ;
outline = &((FT_OutlineGlyph)glyph)->outline;
params.source = outline;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [freetype2-demos] master b786a43: [graph] Fix color management bugs including `ftmulti'.,
Alexei Podtelezhnikov <=