* Sync up to trunk HEAD (r62502).
[reactos.git] / lib / 3rdparty / freetype / src / sfnt / pngshim.c
index 408f879..878de1f 100644 (file)
   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 );
 
 
     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 );
   }
 
 
-  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;
 
 
     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;
                   &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 );