diff options
Diffstat (limited to 'freetype/src/sfnt/pngshim.c')
-rw-r--r-- | freetype/src/sfnt/pngshim.c | 57 |
1 files changed, 45 insertions, 12 deletions
diff --git a/freetype/src/sfnt/pngshim.c b/freetype/src/sfnt/pngshim.c index 408f879c3..878de1fef 100644 --- a/freetype/src/sfnt/pngshim.c +++ b/freetype/src/sfnt/pngshim.c @@ -122,7 +122,7 @@ error_callback( png_structp png, png_const_charp error_msg ) { - FT_Error* error = png_get_error_ptr( png ); + FT_Error* error = (FT_Error*)png_get_error_ptr( png ); FT_UNUSED( error_msg ); @@ -159,7 +159,7 @@ if ( FT_FRAME_ENTER( length ) ) { - FT_Error* e = png_get_error_ptr( png ); + FT_Error* e = (FT_Error*)png_get_error_ptr( png ); *e = FT_THROW( Invalid_Stream_Read ); @@ -174,16 +174,18 @@ } - static FT_Error - Load_SBit_Png( FT_Bitmap* map, + FT_LOCAL_DEF( FT_Error ) + Load_SBit_Png( FT_GlyphSlot slot, FT_Int x_offset, FT_Int y_offset, FT_Int pix_bits, TT_SBit_Metrics metrics, FT_Memory memory, FT_Byte* data, - FT_UInt png_len ) + FT_UInt png_len, + FT_Bool populate_map_and_metrics ) { + FT_Bitmap *map = &slot->bitmap; FT_Error error = FT_Err_Ok; FT_StreamRec stream; @@ -193,12 +195,21 @@ int bitdepth, color_type, interlace; FT_Int i; - png_byte* *rows; + png_byte* *rows = NULL; /* pacify compiler */ - if ( x_offset < 0 || x_offset + metrics->width > map->width || - y_offset < 0 || y_offset + metrics->height > map->rows || - pix_bits != 32 || map->pixel_mode != FT_PIXEL_MODE_BGRA ) + if ( x_offset < 0 || + y_offset < 0 ) + { + error = FT_THROW( Invalid_Argument ); + goto Exit; + } + + if ( !populate_map_and_metrics && + ( x_offset + metrics->width > map->width || + y_offset + metrics->height > map->rows || + pix_bits != 32 || + map->pixel_mode != FT_PIXEL_MODE_BGRA ) ) { error = FT_THROW( Invalid_Argument ); goto Exit; @@ -238,11 +249,33 @@ &bitdepth, &color_type, &interlace, NULL, NULL ); - if ( error != FT_Err_Ok || - (FT_Int)imgWidth != metrics->width || - (FT_Int)imgHeight != metrics->height ) + if ( error || + ( !populate_map_and_metrics && + ( (FT_Int)imgWidth != metrics->width || + (FT_Int)imgHeight != metrics->height ) ) ) goto DestroyExit; + if ( populate_map_and_metrics ) + { + FT_Long size; + + + metrics->width = (FT_Int)imgWidth; + metrics->height = (FT_Int)imgHeight; + + map->width = metrics->width; + map->rows = metrics->height; + map->pixel_mode = FT_PIXEL_MODE_BGRA; + map->pitch = map->width * 4; + map->num_grays = 256; + + size = map->rows * map->pitch; + + error = ft_glyphslot_alloc_bitmap( slot, size ); + if ( error ) + goto DestroyExit; + } + /* convert palette/gray image to rgb */ if ( color_type == PNG_COLOR_TYPE_PALETTE ) png_set_palette_to_rgb( png ); |