Compare commits

...

4 Commits

Author SHA1 Message Date
Alexei Podtelezhnikov 1728230b6d * src/smooth/ftsmooth.c (ft_smooth_render_bgra): Restore contours. 2018-12-18 22:40:04 -05:00
Alexei Podtelezhnikov 953b3682b6 Color glyph framework and rendering (3/3).
* include/freetype/config/ftmodule.h, src/smooth/module.mk:
Register color renderer.
* include/freetype/freetype.h (FT_RENDER_MODE_BGRA): Introduce it.
* src/base/ftobjs.c (ft_glyphslot_preset_bitmap): Handle BGRA mode.
* src/smooth/ftsmooth.c (ft_smooth_render_bgra): Implement it.
(ft_smooth_bgra_renderer_class): Define it.
* src/smooth/ftsmooth.h: Declare it.
2018-12-11 23:22:15 -05:00
Alexei Podtelezhnikov 9569a5b2f2 Color glyph framework and rendering (2/3).
* include/freetype/freetype.h (FT_GlyphSlotRec): Rename reserved
pointer `other' into `color'.
* include/freetype/ftglyph.h (FT_OutlineGlyphRec): Add new field
`color'. Technically this breaks binary compatibility but this is
highly unlikely.
* src/base/ftglyph.c (ft_outline_glyph_{init,done,copy,prepare}):
Handle color and copy it between FT_Glyph and FT_GlyphSlot.

* src/base/ftobjs.c (ft_glyphslot_clear): s/other/color/.
* src/type42/t42objs.c (t42_glyphslot_clear): s/other/color/.
2018-12-11 23:17:36 -05:00
Alexei Podtelezhnikov aec5bdb43b Color glyph framework and rendering (1/3).
* include/freetype/fttypes.h (FT_Color): Move here...
* include/freetype/ftcolor.h (FT_Color): ...from here.
2018-12-11 23:15:49 -05:00
12 changed files with 258 additions and 43 deletions

View File

@ -1,3 +1,41 @@
2018-12-18 Alexei Podtelezhnikov <apodtele@gmail.com>
* src/smooth/ftsmooth.c (ft_smooth_render_bgra): Restore contours.
2018-12-11 Alexei Podtelezhnikov <apodtele@gmail.com>
Color glyph framework and rendering (3/3).
* include/freetype/config/ftmodule.h, src/smooth/module.mk:
Register color renderer.
* include/freetype/freetype.h (FT_RENDER_MODE_BGRA): Introduce it.
* src/base/ftobjs.c (ft_glyphslot_preset_bitmap): Handle BGRA mode.
* src/smooth/ftsmooth.c (ft_smooth_render_bgra): Implement it.
(ft_smooth_bgra_renderer_class): Define it.
* src/smooth/ftsmooth.h: Declare it.
2018-12-11 Alexei Podtelezhnikov <apodtele@gmail.com>
Color glyph framework and rendering (2/3).
* include/freetype/freetype.h (FT_GlyphSlotRec): Rename reserved
pointer `other' into `color'.
* include/freetype/ftglyph.h (FT_OutlineGlyphRec): Add new field
`color'. Technically this breaks binary compatibility but this is
highly unlikely.
* src/base/ftglyph.c (ft_outline_glyph_{init,done,copy,prepare}):
Handle color and copy it between FT_Glyph and FT_GlyphSlot.
* src/base/ftobjs.c (ft_glyphslot_clear): s/other/color/.
* src/type42/t42objs.c (t42_glyphslot_clear): s/other/color/.
2018-12-11 Alexei Podtelezhnikov <apodtele@gmail.com>
Color glyph framework and rendering (1/3).
* include/freetype/fttypes.h (FT_Color): Move here...
* include/freetype/ftcolor.h (FT_Color): ...from here.
2018-12-11 Werner Lemberg <wl@gnu.org>
* src/truetype/ttgload.c (TT_Hint_Glyph): Remove useless test.

View File

@ -27,6 +27,7 @@ FT_USE_MODULE( FT_Module_Class, sfnt_module_class )
FT_USE_MODULE( FT_Renderer_Class, ft_smooth_renderer_class )
FT_USE_MODULE( FT_Renderer_Class, ft_smooth_lcd_renderer_class )
FT_USE_MODULE( FT_Renderer_Class, ft_smooth_lcdv_renderer_class )
FT_USE_MODULE( FT_Renderer_Class, ft_smooth_bgra_renderer_class )
FT_USE_MODULE( FT_Driver_ClassRec, bdf_driver_class )
/* EOF */

View File

@ -1785,9 +1785,6 @@ FT_BEGIN_HEADER
* This is the length in bytes of the control data. Currently internal
* to FreeType.
*
* other ::
* Reserved.
*
* lsb_delta ::
* The difference between hinted and unhinted left side bearing while
* auto-hinting is active. Zero otherwise.
@ -1796,6 +1793,11 @@ FT_BEGIN_HEADER
* The difference between hinted and unhinted right side bearing while
* auto-hinting is active. Zero otherwise.
*
* color ::
* Supplemental pointer to the color array with elements corresponding
* to each outline contour. It is used with @FT_RENDER_MODE_RGBA,
* when consecutive contours of the same color are rendered as layers.
*
* @note:
* If @FT_Load_Glyph is called with default flags (see @FT_LOAD_DEFAULT)
* the glyph image is loaded in the glyph slot in its native format
@ -1904,7 +1906,7 @@ FT_BEGIN_HEADER
FT_Pos lsb_delta;
FT_Pos rsb_delta;
void* other;
FT_Color* color;
FT_Slot_Internal internal;
@ -3237,6 +3239,11 @@ FT_BEGIN_HEADER
* bitmaps that are 3~times the height of the original glyph outline in
* pixels and use the @FT_PIXEL_MODE_LCD_V mode.
*
* FT_RENDER_MODE_BGRA ::
* This mode is intended for rendering color layered glyphs. It
* produces 32-bit premultiplied color images using @FT_PIXEL_MODE_BGRA
* mode.
*
* @note:
* Should you define `FT_CONFIG_OPTION_SUBPIXEL_RENDERING` in your
* `ftoption.h`, which enables patented ClearType-style rendering, the
@ -3258,6 +3265,7 @@ FT_BEGIN_HEADER
FT_RENDER_MODE_MONO,
FT_RENDER_MODE_LCD,
FT_RENDER_MODE_LCD_V,
FT_RENDER_MODE_BGRA,
FT_RENDER_MODE_MAX

View File

@ -49,43 +49,6 @@ FT_BEGIN_HEADER
*/
/**************************************************************************
*
* @struct:
* FT_Color
*
* @description:
* This structure models a BGRA color value of a `CPAL` palette entry.
*
* The used color space is sRGB; the colors are not pre-multiplied, and
* alpha values must be explicitly set.
*
* @fields:
* blue ::
* Blue value.
*
* green ::
* Green value.
*
* red ::
* Red value.
*
* alpha ::
* Alpha value, giving the red, green, and blue color's opacity.
*
* @since:
* 2.10
*/
typedef struct FT_Color_
{
FT_Byte blue;
FT_Byte green;
FT_Byte red;
FT_Byte alpha;
} FT_Color;
/**************************************************************************
*
* @enum:

View File

@ -203,6 +203,10 @@ FT_BEGIN_HEADER
* outline ::
* A descriptor for the outline.
*
* color ::
* Supplemental pointer to the color array with elements corresponding
* to each outline contour.
*
* @note:
* You can typecast an @FT_Glyph to @FT_OutlineGlyph if you have
* `glyph->format == FT_GLYPH_FORMAT_OUTLINE`. This lets you access the
@ -219,6 +223,7 @@ FT_BEGIN_HEADER
{
FT_GlyphRec root;
FT_Outline outline;
FT_Color* color;
} FT_OutlineGlyphRec;

View File

@ -395,6 +395,43 @@ FT_BEGIN_HEADER
} FT_Matrix;
/**************************************************************************
*
* @struct:
* FT_Color
*
* @description:
* This structure models a BGRA color value.
*
* The used color space is sRGB; the colors are not pre-multiplied, and
* alpha values must be explicitly set.
*
* @fields:
* blue ::
* Blue value.
*
* green ::
* Green value.
*
* red ::
* Red value.
*
* alpha ::
* Alpha value, giving the red, green, and blue color's opacity.
*
* @since:
* 2.10
*/
typedef struct FT_Color_
{
FT_Byte blue;
FT_Byte green;
FT_Byte red;
FT_Byte alpha;
} FT_Color;
/**************************************************************************
*
* @struct:

View File

@ -182,6 +182,7 @@
goto Exit;
FT_Outline_Copy( source, target );
glyph->color = slot->color;
Exit:
return error;
@ -192,9 +193,13 @@
ft_outline_glyph_done( FT_Glyph outline_glyph )
{
FT_OutlineGlyph glyph = (FT_OutlineGlyph)outline_glyph;
FT_Memory memory = FT_GLYPH( glyph )->library->memory;
FT_Outline_Done( FT_GLYPH( glyph )->library, &glyph->outline );
if ( glyph->outline.flags & FT_OUTLINE_OWNER )
FT_FREE( glyph->color );
}
@ -213,7 +218,10 @@
source->outline.n_contours,
&target->outline );
if ( !error )
{
FT_Outline_Copy( &source->outline, &target->outline );
target->color = source->color;
}
return error;
}
@ -255,6 +263,7 @@
slot->format = FT_GLYPH_FORMAT_OUTLINE;
slot->outline = glyph->outline;
slot->color = glyph->color;
slot->outline.flags &= ~FT_OUTLINE_OWNER;
return FT_Err_Ok;

View File

@ -441,6 +441,10 @@
ft_lcd_padding( &cbox, slot, mode );
goto Adjust;
case FT_RENDER_MODE_BGRA:
pixel_mode = FT_PIXEL_MODE_BGRA;
goto Adjust;
case FT_RENDER_MODE_NORMAL:
case FT_RENDER_MODE_LIGHT:
default:
@ -469,6 +473,10 @@
pitch = FT_PAD_CEIL( width, 4 );
break;
case FT_PIXEL_MODE_BGRA:
pitch = 4 * width;
break;
case FT_PIXEL_MODE_LCD_V:
height *= 3;
/* fall through */
@ -551,7 +559,7 @@
slot->subglyphs = NULL;
slot->control_data = NULL;
slot->control_len = 0;
slot->other = NULL;
slot->color = NULL;
slot->format = FT_GLYPH_FORMAT_NONE;
slot->linearHoriAdvance = 0;

View File

@ -20,6 +20,7 @@
#include FT_INTERNAL_DEBUG_H
#include FT_INTERNAL_OBJECTS_H
#include FT_OUTLINE_H
#include FT_BITMAP_H
#include "ftsmooth.h"
#include "ftgrays.h"
@ -419,6 +420,120 @@
}
/* convert a slot image into a BGRA bitmap using supplemental color array */
static FT_Error
ft_smooth_render_bgra( FT_Renderer render,
FT_GlyphSlot slot,
FT_Render_Mode mode,
const FT_Vector* origin )
{
FT_Error error = FT_Err_Ok;
FT_Memory memory = render->root.memory;
FT_Outline outline = slot->outline; /* hard copy */
FT_Bitmap target;
FT_Vector target_offset, offset;
short i, j, c_done, p_done;
/* check glyph image format */
if ( slot->format != render->glyph_format )
return FT_THROW( Invalid_Argument );
/* check mode */
if ( mode != FT_RENDER_MODE_BGRA ||
slot->color == NULL )
return FT_THROW( Cannot_Render_Glyph );
/* release old bitmap buffer */
if ( slot->internal->flags & FT_GLYPH_OWN_BITMAP )
{
FT_FREE( slot->bitmap.buffer );
slot->internal->flags &= ~FT_GLYPH_OWN_BITMAP;
}
if ( ft_glyphslot_preset_bitmap( slot, mode, origin ) )
return FT_THROW( Raster_Overflow );
target = slot->bitmap;
target_offset.x = slot->bitmap_left * 64;
target_offset.y = slot->bitmap_top * 64;
/* allocate new one */
if ( FT_ALLOC_MULT( target.buffer, target.rows, target.pitch ) )
goto Exit;
c_done = 0;
p_done = 0;
for ( i = 0; i < outline.n_contours; i++ )
{
/* grow layer */
slot->outline.n_contours = i - c_done + 1;
slot->outline.n_points = outline.contours[i] - p_done + 1;
slot->outline.contours[i - c_done] = outline.contours[i] - p_done;
/* layer ends when color changes */
if ( i == outline.n_contours - 1 ||
slot->color[i + 1].red != slot->color[c_done].red ||
slot->color[i + 1].green != slot->color[c_done].green ||
slot->color[i + 1].blue != slot->color[c_done].blue ||
slot->color[i + 1].alpha != slot->color[c_done].alpha )
{
/* render layer */
error = ft_smooth_render( render,
slot,
FT_RENDER_MODE_NORMAL,
origin );
if ( error )
break;
/* blend layer */
offset.x = slot->bitmap_left * 64;
offset.y = slot->bitmap_top * 64;
error = FT_Bitmap_Blend( slot->library,
&slot->bitmap,
offset,
&target,
&target_offset,
slot->color[c_done] );
if ( error )
break;
/* restore contours */
for ( j = 0; j < slot->outline.n_contours; j++ )
slot->outline.contours[j] += p_done;
c_done += slot->outline.n_contours;
p_done += slot->outline.n_points;
/* start next layer */
slot->outline.contours = outline.contours + c_done;
slot->outline.points = outline.points + p_done;
slot->outline.tags = outline.tags + p_done;
slot->format = FT_GLYPH_FORMAT_OUTLINE;
}
}
/* restore pointers so that they can be freed */
slot->outline.contours = outline.contours;
slot->outline.points = outline.points;
slot->outline.tags = outline.tags;
if ( !error )
{
FT_FREE( slot->bitmap.buffer );
slot->bitmap = target;
slot->bitmap_left = target_offset.x >> 6;
slot->bitmap_top = target_offset.y >> 6;
slot->format = FT_GLYPH_FORMAT_BITMAP;
}
Exit:
return error;
}
FT_DEFINE_RENDERER(
ft_smooth_renderer_class,
@ -500,4 +615,31 @@
)
FT_DEFINE_RENDERER(
ft_smooth_bgra_renderer_class,
FT_MODULE_RENDERER,
sizeof ( FT_RendererRec ),
"smooth-bgra",
0x10000L,
0x20000L,
NULL, /* module specific interface */
(FT_Module_Constructor)ft_smooth_init, /* module_init */
(FT_Module_Destructor) NULL, /* module_done */
(FT_Module_Requester) NULL, /* get_interface */
FT_GLYPH_FORMAT_OUTLINE,
(FT_Renderer_RenderFunc) ft_smooth_render_bgra, /* render_glyph */
(FT_Renderer_TransformFunc)ft_smooth_transform, /* transform_glyph */
(FT_Renderer_GetCBoxFunc) ft_smooth_get_cbox, /* get_glyph_cbox */
(FT_Renderer_SetModeFunc) ft_smooth_set_mode, /* set_mode */
(FT_Raster_Funcs*)&ft_grays_raster /* raster_class */
)
/* END */

View File

@ -33,6 +33,8 @@ FT_BEGIN_HEADER
FT_DECLARE_RENDERER( ft_smooth_lcdv_renderer_class )
FT_DECLARE_RENDERER( ft_smooth_bgra_renderer_class )
FT_END_HEADER

View File

@ -22,6 +22,8 @@ $(OPEN_DRIVER) FT_Renderer_Class, ft_smooth_lcd_renderer_class $(CLOSE_DRIVER)
$(ECHO_DRIVER)smooth $(ECHO_DRIVER_DESC)anti-aliased bitmap renderer for LCDs$(ECHO_DRIVER_DONE)
$(OPEN_DRIVER) FT_Renderer_Class, ft_smooth_lcdv_renderer_class $(CLOSE_DRIVER)
$(ECHO_DRIVER)smooth $(ECHO_DRIVER_DESC)anti-aliased bitmap renderer for vertical LCDs$(ECHO_DRIVER_DONE)
$(OPEN_DRIVER) FT_Renderer_Class, ft_smooth_bgra_renderer_class $(CLOSE_DRIVER)
$(ECHO_DRIVER)smooth $(ECHO_DRIVER_DESC)color bitmap renderer for layered glyphs$(ECHO_DRIVER_DONE)
endef
# EOF

View File

@ -628,7 +628,7 @@
slot->subglyphs = NULL;
slot->control_data = NULL;
slot->control_len = 0;
slot->other = NULL;
slot->color = NULL;
slot->format = FT_GLYPH_FORMAT_NONE;
slot->linearHoriAdvance = 0;