< prev index next >

src/java.desktop/share/native/libfreetype/src/smooth/ftsmooth.c

Print this page


   1 /****************************************************************************
   2  *
   3  * ftsmooth.c
   4  *
   5  *   Anti-aliasing renderer interface (body).
   6  *
   7  * Copyright (C) 2000-2019 by
   8  * David Turner, Robert Wilhelm, and Werner Lemberg.
   9  *
  10  * This file is part of the FreeType project, and may only be used,
  11  * modified, and distributed under the terms of the FreeType project
  12  * license, LICENSE.TXT.  By continuing to use, modify, or distribute
  13  * this file you indicate that you have read the license and
  14  * understand and accept it fully.
  15  *
  16  */
  17 
  18 
  19 #include <ft2build.h>
  20 #include FT_INTERNAL_DEBUG_H
  21 #include FT_INTERNAL_OBJECTS_H
  22 #include FT_OUTLINE_H
  23 #include "ftsmooth.h"
  24 #include "ftgrays.h"
  25 
  26 #include "ftsmerrs.h"
  27 


 138     /* check mode */
 139     if ( mode != required_mode )
 140     {
 141       error = FT_THROW( Cannot_Render_Glyph );
 142       goto Exit;
 143     }
 144 
 145     /* release old bitmap buffer */
 146     if ( slot->internal->flags & FT_GLYPH_OWN_BITMAP )
 147     {
 148       FT_FREE( bitmap->buffer );
 149       slot->internal->flags &= ~FT_GLYPH_OWN_BITMAP;
 150     }
 151 
 152     if ( ft_glyphslot_preset_bitmap( slot, mode, origin ) )
 153     {
 154       error = FT_THROW( Raster_Overflow );
 155       goto Exit;
 156     }
 157 



 158     /* allocate new one */
 159     if ( FT_ALLOC_MULT( bitmap->buffer, bitmap->rows, bitmap->pitch ) )
 160       goto Exit;
 161 
 162     slot->internal->flags |= FT_GLYPH_OWN_BITMAP;
 163 
 164     x_shift = 64 * -slot->bitmap_left;
 165     y_shift = 64 * -slot->bitmap_top;
 166     if ( bitmap->pixel_mode == FT_PIXEL_MODE_LCD_V )
 167       y_shift += 64 * (FT_Int)bitmap->rows / 3;
 168     else
 169       y_shift += 64 * (FT_Int)bitmap->rows;
 170 
 171     if ( origin )
 172     {
 173       x_shift += origin->x;
 174       y_shift += origin->y;
 175     }
 176 
 177     /* translate outline to render it into the bitmap */
 178     if ( x_shift || y_shift )
 179       FT_Outline_Translate( outline, x_shift, y_shift );
 180 
 181     /* set up parameters */
 182     params.target = bitmap;
 183     params.source = outline;
 184     params.flags  = FT_RASTER_FLAG_AA;
 185 
 186 #ifdef FT_CONFIG_OPTION_SUBPIXEL_RENDERING
 187 
 188     /* implode outline if needed */
 189     {
 190       FT_Vector*  points     = outline->points;
 191       FT_Vector*  points_end = points + outline->n_points;
 192       FT_Vector*  vec;
 193 
 194 
 195       if ( hmul )
 196         for ( vec = points; vec < points_end; vec++ )
 197           vec->x *= 3;
 198 
 199       if ( vmul )
 200         for ( vec = points; vec < points_end; vec++ )
 201           vec->y *= 3;
 202     }
 203 
 204     /* render outline into the bitmap */
 205     error = render->raster_render( render->raster, &params );
 206 
 207     /* deflate outline if needed */
 208     {
 209       FT_Vector*  points     = outline->points;
 210       FT_Vector*  points_end = points + outline->n_points;
 211       FT_Vector*  vec;
 212 
 213 
 214       if ( hmul )
 215         for ( vec = points; vec < points_end; vec++ )
 216           vec->x /= 3;
 217 
 218       if ( vmul )
 219         for ( vec = points; vec < points_end; vec++ )
 220           vec->y /= 3;
 221     }
 222 
 223     if ( error )
 224       goto Exit;
 225 
 226     /* finally apply filtering */
 227     if ( hmul || vmul )
 228     {
 229       FT_Byte*                 lcd_weights;
 230       FT_Bitmap_LcdFilterFunc  lcd_filter_func;


   1 /****************************************************************************
   2  *
   3  * ftsmooth.c
   4  *
   5  *   Anti-aliasing renderer interface (body).
   6  *
   7  * Copyright (C) 2000-2020 by
   8  * David Turner, Robert Wilhelm, and Werner Lemberg.
   9  *
  10  * This file is part of the FreeType project, and may only be used,
  11  * modified, and distributed under the terms of the FreeType project
  12  * license, LICENSE.TXT.  By continuing to use, modify, or distribute
  13  * this file you indicate that you have read the license and
  14  * understand and accept it fully.
  15  *
  16  */
  17 
  18 
  19 #include <ft2build.h>
  20 #include FT_INTERNAL_DEBUG_H
  21 #include FT_INTERNAL_OBJECTS_H
  22 #include FT_OUTLINE_H
  23 #include "ftsmooth.h"
  24 #include "ftgrays.h"
  25 
  26 #include "ftsmerrs.h"
  27 


 138     /* check mode */
 139     if ( mode != required_mode )
 140     {
 141       error = FT_THROW( Cannot_Render_Glyph );
 142       goto Exit;
 143     }
 144 
 145     /* release old bitmap buffer */
 146     if ( slot->internal->flags & FT_GLYPH_OWN_BITMAP )
 147     {
 148       FT_FREE( bitmap->buffer );
 149       slot->internal->flags &= ~FT_GLYPH_OWN_BITMAP;
 150     }
 151 
 152     if ( ft_glyphslot_preset_bitmap( slot, mode, origin ) )
 153     {
 154       error = FT_THROW( Raster_Overflow );
 155       goto Exit;
 156     }
 157 
 158     if ( !bitmap->rows || !bitmap->pitch )
 159       goto Exit;
 160 
 161     /* allocate new one */
 162     if ( FT_ALLOC_MULT( bitmap->buffer, bitmap->rows, bitmap->pitch ) )
 163       goto Exit;
 164 
 165     slot->internal->flags |= FT_GLYPH_OWN_BITMAP;
 166 
 167     x_shift = 64 * -slot->bitmap_left;
 168     y_shift = 64 * -slot->bitmap_top;
 169     if ( bitmap->pixel_mode == FT_PIXEL_MODE_LCD_V )
 170       y_shift += 64 * (FT_Int)bitmap->rows / 3;
 171     else
 172       y_shift += 64 * (FT_Int)bitmap->rows;
 173 
 174     if ( origin )
 175     {
 176       x_shift += origin->x;
 177       y_shift += origin->y;
 178     }
 179 
 180     /* translate outline to render it into the bitmap */
 181     if ( x_shift || y_shift )
 182       FT_Outline_Translate( outline, x_shift, y_shift );
 183 
 184     /* set up parameters */
 185     params.target = bitmap;
 186     params.source = outline;
 187     params.flags  = FT_RASTER_FLAG_AA;
 188 
 189 #ifdef FT_CONFIG_OPTION_SUBPIXEL_RENDERING
 190 
 191     /* implode outline if needed */
 192     {
 193       FT_Vector*  points     = outline->points;
 194       FT_Vector*  points_end = FT_OFFSET( points, outline->n_points );
 195       FT_Vector*  vec;
 196 
 197 
 198       if ( hmul )
 199         for ( vec = points; vec < points_end; vec++ )
 200           vec->x *= 3;
 201 
 202       if ( vmul )
 203         for ( vec = points; vec < points_end; vec++ )
 204           vec->y *= 3;
 205     }
 206 
 207     /* render outline into the bitmap */
 208     error = render->raster_render( render->raster, &params );
 209 
 210     /* deflate outline if needed */
 211     {
 212       FT_Vector*  points     = outline->points;
 213       FT_Vector*  points_end = FT_OFFSET( points, outline->n_points );
 214       FT_Vector*  vec;
 215 
 216 
 217       if ( hmul )
 218         for ( vec = points; vec < points_end; vec++ )
 219           vec->x /= 3;
 220 
 221       if ( vmul )
 222         for ( vec = points; vec < points_end; vec++ )
 223           vec->y /= 3;
 224     }
 225 
 226     if ( error )
 227       goto Exit;
 228 
 229     /* finally apply filtering */
 230     if ( hmul || vmul )
 231     {
 232       FT_Byte*                 lcd_weights;
 233       FT_Bitmap_LcdFilterFunc  lcd_filter_func;


< prev index next >