1 /****************************************************************************
5 * FreeType utility functions for bitmaps (body).
7 * Copyright (C) 2004-2020 by
8 * David Turner, Robert Wilhelm, and Werner Lemberg.
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.
19 #include <freetype/internal/ftdebug.h>
21 #include <freetype/ftbitmap.h>
22 #include <freetype/ftimage.h>
23 #include <freetype/internal/ftobjs.h>
26 /**************************************************************************
28 * The macro FT_COMPONENT is used in trace mode. It is an implicit
29 * parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log
30 * messages during execution.
33 #define FT_COMPONENT bitmap
37 const FT_Bitmap null_bitmap = { 0, 0, 0, NULL, 0, 0, 0, NULL };
40 /* documentation is in ftbitmap.h */
43 FT_Bitmap_Init( FT_Bitmap *abitmap )
46 *abitmap = null_bitmap;
50 /* deprecated function name; retained for ABI compatibility */
53 FT_Bitmap_New( FT_Bitmap *abitmap )
56 *abitmap = null_bitmap;
60 /* documentation is in ftbitmap.h */
62 FT_EXPORT_DEF( FT_Error )
63 FT_Bitmap_Copy( FT_Library library,
64 const FT_Bitmap *source,
68 FT_Error error = FT_Err_Ok;
73 FT_Int source_pitch_sign, target_pitch_sign;
77 return FT_THROW( Invalid_Library_Handle );
79 if ( !source || !target )
80 return FT_THROW( Invalid_Argument );
82 if ( source == target )
85 source_pitch_sign = source->pitch < 0 ? -1 : 1;
86 target_pitch_sign = target->pitch < 0 ? -1 : 1;
88 if ( !source->buffer )
91 if ( source_pitch_sign != target_pitch_sign )
92 target->pitch = -target->pitch;
97 memory = library->memory;
98 pitch = source->pitch;
102 size = (FT_ULong)pitch * source->rows;
104 if ( target->buffer )
106 FT_Int target_pitch = target->pitch;
107 FT_ULong target_size;
110 if ( target_pitch < 0 )
111 target_pitch = -target_pitch;
112 target_size = (FT_ULong)target_pitch * target->rows;
114 if ( target_size != size )
115 (void)FT_QREALLOC( target->buffer, target_size, size );
118 (void)FT_QALLOC( target->buffer, size );
129 if ( source_pitch_sign == target_pitch_sign )
130 FT_MEM_COPY( target->buffer, source->buffer, size );
133 /* take care of bitmap flow */
135 FT_Byte* s = source->buffer;
136 FT_Byte* t = target->buffer;
139 t += (FT_ULong)pitch * ( target->rows - 1 );
141 for ( i = target->rows; i > 0; i-- )
143 FT_ARRAY_COPY( t, s, pitch );
155 /* Enlarge `bitmap' horizontally and vertically by `xpixels' */
156 /* and `ypixels', respectively. */
159 ft_bitmap_assure_buffer( FT_Memory memory,
166 unsigned int new_pitch;
168 FT_UInt width, height;
169 unsigned char* buffer = NULL;
172 width = bitmap->width;
173 height = bitmap->rows;
174 pitch = (unsigned int)FT_ABS( bitmap->pitch );
176 switch ( bitmap->pixel_mode )
178 case FT_PIXEL_MODE_MONO:
180 new_pitch = ( width + xpixels + 7 ) >> 3;
182 case FT_PIXEL_MODE_GRAY2:
184 new_pitch = ( width + xpixels + 3 ) >> 2;
186 case FT_PIXEL_MODE_GRAY4:
188 new_pitch = ( width + xpixels + 1 ) >> 1;
190 case FT_PIXEL_MODE_GRAY:
191 case FT_PIXEL_MODE_LCD:
192 case FT_PIXEL_MODE_LCD_V:
194 new_pitch = width + xpixels;
197 return FT_THROW( Invalid_Glyph_Format );
200 /* if no need to allocate memory */
201 if ( ypixels == 0 && new_pitch <= pitch )
203 /* zero the padding */
204 FT_UInt bit_width = pitch * 8;
205 FT_UInt bit_last = ( width + xpixels ) * bpp;
208 if ( bit_last < bit_width )
210 FT_Byte* line = bitmap->buffer + ( bit_last >> 3 );
211 FT_Byte* end = bitmap->buffer + pitch;
212 FT_UInt shift = bit_last & 7;
213 FT_UInt mask = 0xFF00U >> shift;
214 FT_UInt count = height;
217 for ( ; count > 0; count--, line += pitch, end += pitch )
219 FT_Byte* write = line;
224 write[0] = (FT_Byte)( write[0] & mask );
228 FT_MEM_ZERO( write, end - write );
235 /* otherwise allocate new buffer */
236 if ( FT_QALLOC_MULT( buffer, bitmap->rows + ypixels, new_pitch ) )
239 /* new rows get added at the top of the bitmap, */
240 /* thus take care of the flow direction */
241 if ( bitmap->pitch > 0 )
243 FT_UInt len = ( width * bpp + 7 ) >> 3;
245 unsigned char* in = bitmap->buffer;
246 unsigned char* out = buffer;
248 unsigned char* limit = bitmap->buffer + pitch * bitmap->rows;
249 unsigned int delta = new_pitch - len;
252 FT_MEM_ZERO( out, new_pitch * ypixels );
253 out += new_pitch * ypixels;
257 FT_MEM_COPY( out, in, len );
261 /* we use FT_QALLOC_MULT, which doesn't zero out the buffer; */
262 /* consequently, we have to manually zero out the remaining bytes */
263 FT_MEM_ZERO( out, delta );
269 FT_UInt len = ( width * bpp + 7 ) >> 3;
271 unsigned char* in = bitmap->buffer;
272 unsigned char* out = buffer;
274 unsigned char* limit = bitmap->buffer + pitch * bitmap->rows;
275 unsigned int delta = new_pitch - len;
280 FT_MEM_COPY( out, in, len );
284 FT_MEM_ZERO( out, delta );
288 FT_MEM_ZERO( out, new_pitch * ypixels );
291 FT_FREE( bitmap->buffer );
292 bitmap->buffer = buffer;
294 /* set pitch only, width and height are left untouched */
295 if ( bitmap->pitch < 0 )
296 bitmap->pitch = -(int)new_pitch;
298 bitmap->pitch = (int)new_pitch;
304 /* documentation is in ftbitmap.h */
306 FT_EXPORT_DEF( FT_Error )
307 FT_Bitmap_Embolden( FT_Library library,
320 return FT_THROW( Invalid_Library_Handle );
322 if ( !bitmap || !bitmap->buffer )
323 return FT_THROW( Invalid_Argument );
325 if ( ( ( FT_PIX_ROUND( xStrength ) >> 6 ) > FT_INT_MAX ) ||
326 ( ( FT_PIX_ROUND( yStrength ) >> 6 ) > FT_INT_MAX ) )
327 return FT_THROW( Invalid_Argument );
329 xstr = (FT_Int)FT_PIX_ROUND( xStrength ) >> 6;
330 ystr = (FT_Int)FT_PIX_ROUND( yStrength ) >> 6;
332 if ( xstr == 0 && ystr == 0 )
334 else if ( xstr < 0 || ystr < 0 )
335 return FT_THROW( Invalid_Argument );
337 switch ( bitmap->pixel_mode )
339 case FT_PIXEL_MODE_GRAY2:
340 case FT_PIXEL_MODE_GRAY4:
345 /* convert to 8bpp */
346 FT_Bitmap_Init( &tmp );
347 error = FT_Bitmap_Convert( library, bitmap, &tmp, 1 );
351 FT_Bitmap_Done( library, bitmap );
356 case FT_PIXEL_MODE_MONO:
361 case FT_PIXEL_MODE_LCD:
365 case FT_PIXEL_MODE_LCD_V:
369 case FT_PIXEL_MODE_BGRA:
370 /* We don't embolden color glyphs. */
374 error = ft_bitmap_assure_buffer( library->memory, bitmap,
375 (FT_UInt)xstr, (FT_UInt)ystr );
379 /* take care of bitmap flow */
380 pitch = bitmap->pitch;
382 p = bitmap->buffer + pitch * ystr;
386 p = bitmap->buffer + (FT_UInt)pitch * ( bitmap->rows - 1 );
390 for ( y = 0; y < bitmap->rows; y++ )
395 * From the last pixel on, make each pixel or'ed with the
396 * `xstr' pixels before it.
398 for ( x = pitch - 1; x >= 0; x-- )
404 for ( i = 1; i <= xstr; i++ )
406 if ( bitmap->pixel_mode == FT_PIXEL_MODE_MONO )
410 /* the maximum value of 8 for `xstr' comes from here */
412 p[x] |= p[x - 1] << ( 8 - i );
423 if ( p[x] + p[x - i] > bitmap->num_grays - 1 )
425 p[x] = (unsigned char)( bitmap->num_grays - 1 );
430 p[x] = (unsigned char)( p[x] + p[x - i] );
431 if ( p[x] == bitmap->num_grays - 1 )
444 * Make the above `ystr' rows or'ed with it.
446 for ( x = 1; x <= ystr; x++ )
451 q = p - bitmap->pitch * x;
452 for ( i = 0; i < pitch; i++ )
459 bitmap->width += (FT_UInt)xstr;
460 bitmap->rows += (FT_UInt)ystr;
467 ft_gray_for_premultiplied_srgb_bgra( const FT_Byte* bgra )
473 /* Short-circuit transparent color to avoid division by zero. */
478 * Luminosity for sRGB is defined using ~0.2126,0.7152,0.0722
479 * coefficients for RGB channels *on the linear colors*.
480 * A gamma of 2.2 is fair to assume. And then, we need to
481 * undo the premultiplication too.
483 * https://accessibility.kde.org/hsl-adjusted.php
485 * We do the computation with integers only, applying a gamma of 2.0.
486 * We guarantee 32-bit arithmetic to avoid overflow but the resulting
487 * luminosity fits into 16 bits.
491 l = ( 4732UL /* 0.0722 * 65536 */ * bgra[0] * bgra[0] +
492 46871UL /* 0.7152 * 65536 */ * bgra[1] * bgra[1] +
493 13933UL /* 0.2126 * 65536 */ * bgra[2] * bgra[2] ) >> 16;
496 * Final transparency can be determined as follows.
498 * - If alpha is zero, we want 0.
499 * - If alpha is zero and luminosity is zero, we want 255.
500 * - If alpha is zero and luminosity is one, we want 0.
502 * So the formula is a * (1 - l) = a - l * a.
504 * We still need to undo premultiplication by dividing l by a*a.
508 return (FT_Byte)( a - l / a );
512 /* documentation is in ftbitmap.h */
514 FT_EXPORT_DEF( FT_Error )
515 FT_Bitmap_Convert( FT_Library library,
516 const FT_Bitmap *source,
520 FT_Error error = FT_Err_Ok;
528 return FT_THROW( Invalid_Library_Handle );
530 if ( !source || !target )
531 return FT_THROW( Invalid_Argument );
533 memory = library->memory;
535 switch ( source->pixel_mode )
537 case FT_PIXEL_MODE_MONO:
538 case FT_PIXEL_MODE_GRAY:
539 case FT_PIXEL_MODE_GRAY2:
540 case FT_PIXEL_MODE_GRAY4:
541 case FT_PIXEL_MODE_LCD:
542 case FT_PIXEL_MODE_LCD_V:
543 case FT_PIXEL_MODE_BGRA:
545 FT_Int pad, old_target_pitch, target_pitch;
549 old_target_pitch = target->pitch;
550 if ( old_target_pitch < 0 )
551 old_target_pitch = -old_target_pitch;
553 old_size = target->rows * (FT_UInt)old_target_pitch;
555 target->pixel_mode = FT_PIXEL_MODE_GRAY;
556 target->rows = source->rows;
557 target->width = source->width;
562 pad = (FT_Int)source->width % alignment;
564 pad = alignment - pad;
567 target_pitch = (FT_Int)source->width + pad;
569 if ( target_pitch > 0 &&
570 (FT_ULong)target->rows > FT_ULONG_MAX / (FT_ULong)target_pitch )
571 return FT_THROW( Invalid_Argument );
573 if ( FT_QREALLOC( target->buffer,
574 old_size, target->rows * (FT_UInt)target_pitch ) )
577 target->pitch = target->pitch < 0 ? -target_pitch : target_pitch;
582 error = FT_THROW( Invalid_Argument );
588 /* take care of bitmap flow */
589 if ( source->pitch < 0 )
590 s -= source->pitch * (FT_Int)( source->rows - 1 );
591 if ( target->pitch < 0 )
592 t -= target->pitch * (FT_Int)( target->rows - 1 );
594 switch ( source->pixel_mode )
596 case FT_PIXEL_MODE_MONO:
601 target->num_grays = 2;
603 for ( i = source->rows; i > 0; i-- )
610 /* get the full bytes */
611 for ( j = source->width >> 3; j > 0; j-- )
613 FT_Int val = ss[0]; /* avoid a byte->int cast on each line */
616 tt[0] = (FT_Byte)( ( val & 0x80 ) >> 7 );
617 tt[1] = (FT_Byte)( ( val & 0x40 ) >> 6 );
618 tt[2] = (FT_Byte)( ( val & 0x20 ) >> 5 );
619 tt[3] = (FT_Byte)( ( val & 0x10 ) >> 4 );
620 tt[4] = (FT_Byte)( ( val & 0x08 ) >> 3 );
621 tt[5] = (FT_Byte)( ( val & 0x04 ) >> 2 );
622 tt[6] = (FT_Byte)( ( val & 0x02 ) >> 1 );
623 tt[7] = (FT_Byte)( val & 0x01 );
629 /* get remaining pixels (if any) */
630 j = source->width & 7;
638 tt[0] = (FT_Byte)( ( val & 0x80 ) >> 7);
651 case FT_PIXEL_MODE_GRAY:
652 case FT_PIXEL_MODE_LCD:
653 case FT_PIXEL_MODE_LCD_V:
655 FT_UInt width = source->width;
659 target->num_grays = 256;
661 for ( i = source->rows; i > 0; i-- )
663 FT_ARRAY_COPY( t, s, width );
672 case FT_PIXEL_MODE_GRAY2:
677 target->num_grays = 4;
679 for ( i = source->rows; i > 0; i-- )
686 /* get the full bytes */
687 for ( j = source->width >> 2; j > 0; j-- )
692 tt[0] = (FT_Byte)( ( val & 0xC0 ) >> 6 );
693 tt[1] = (FT_Byte)( ( val & 0x30 ) >> 4 );
694 tt[2] = (FT_Byte)( ( val & 0x0C ) >> 2 );
695 tt[3] = (FT_Byte)( ( val & 0x03 ) );
701 j = source->width & 3;
709 tt[0] = (FT_Byte)( ( val & 0xC0 ) >> 6 );
722 case FT_PIXEL_MODE_GRAY4:
727 target->num_grays = 16;
729 for ( i = source->rows; i > 0; i-- )
736 /* get the full bytes */
737 for ( j = source->width >> 1; j > 0; j-- )
742 tt[0] = (FT_Byte)( ( val & 0xF0 ) >> 4 );
743 tt[1] = (FT_Byte)( ( val & 0x0F ) );
749 if ( source->width & 1 )
750 tt[0] = (FT_Byte)( ( ss[0] & 0xF0 ) >> 4 );
759 case FT_PIXEL_MODE_BGRA:
764 target->num_grays = 256;
766 for ( i = source->rows; i > 0; i-- )
773 for ( j = source->width; j > 0; j-- )
775 tt[0] = ft_gray_for_premultiplied_srgb_bgra( ss );
795 /* documentation is in ftbitmap.h */
797 FT_EXPORT_DEF( FT_Error )
798 FT_Bitmap_Blend( FT_Library library,
799 const FT_Bitmap* source_,
800 const FT_Vector source_offset_,
802 FT_Vector *atarget_offset,
805 FT_Error error = FT_Err_Ok;
808 FT_Bitmap source_bitmap;
809 const FT_Bitmap* source;
811 FT_Vector source_offset;
812 FT_Vector target_offset;
814 FT_Bool free_source_bitmap = 0;
815 FT_Bool free_target_bitmap_on_error = 0;
817 FT_Pos source_llx, source_lly, source_urx, source_ury;
818 FT_Pos target_llx, target_lly, target_urx, target_ury;
819 FT_Pos final_llx, final_lly, final_urx, final_ury;
821 unsigned int final_rows, final_width;
825 if ( !library || !target || !source_ || !atarget_offset )
826 return FT_THROW( Invalid_Argument );
828 memory = library->memory;
830 if ( !( target->pixel_mode == FT_PIXEL_MODE_NONE ||
831 ( target->pixel_mode == FT_PIXEL_MODE_BGRA &&
833 return FT_THROW( Invalid_Argument );
835 if ( source_->pixel_mode == FT_PIXEL_MODE_NONE )
836 return FT_Err_Ok; /* nothing to do */
838 /* pitches must have the same sign */
839 if ( target->pixel_mode == FT_PIXEL_MODE_BGRA &&
840 ( source_->pitch ^ target->pitch ) < 0 )
841 return FT_THROW( Invalid_Argument );
843 if ( !( source_->width && source_->rows ) )
844 return FT_Err_Ok; /* nothing to do */
846 /* assure integer pixel offsets */
847 source_offset.x = FT_PIX_FLOOR( source_offset_.x );
848 source_offset.y = FT_PIX_FLOOR( source_offset_.y );
849 target_offset.x = FT_PIX_FLOOR( atarget_offset->x );
850 target_offset.y = FT_PIX_FLOOR( atarget_offset->y );
852 /* get source bitmap dimensions */
853 source_llx = source_offset.x;
854 if ( FT_LONG_MIN + (FT_Pos)( source_->rows << 6 ) + 64 > source_offset.y )
857 "FT_Bitmap_Blend: y coordinate overflow in source bitmap\n" ));
858 return FT_THROW( Invalid_Argument );
860 source_lly = source_offset.y - ( source_->rows << 6 );
862 if ( FT_LONG_MAX - (FT_Pos)( source_->width << 6 ) - 64 < source_llx )
865 "FT_Bitmap_Blend: x coordinate overflow in source bitmap\n" ));
866 return FT_THROW( Invalid_Argument );
868 source_urx = source_llx + ( source_->width << 6 );
869 source_ury = source_offset.y;
871 /* get target bitmap dimensions */
872 if ( target->width && target->rows )
874 target_llx = target_offset.x;
875 if ( FT_LONG_MIN + (FT_Pos)( target->rows << 6 ) > target_offset.y )
878 "FT_Bitmap_Blend: y coordinate overflow in target bitmap\n" ));
879 return FT_THROW( Invalid_Argument );
881 target_lly = target_offset.y - ( target->rows << 6 );
883 if ( FT_LONG_MAX - (FT_Pos)( target->width << 6 ) < target_llx )
886 "FT_Bitmap_Blend: x coordinate overflow in target bitmap\n" ));
887 return FT_THROW( Invalid_Argument );
889 target_urx = target_llx + ( target->width << 6 );
890 target_ury = target_offset.y;
894 target_llx = FT_LONG_MAX;
895 target_lly = FT_LONG_MAX;
896 target_urx = FT_LONG_MIN;
897 target_ury = FT_LONG_MIN;
900 /* compute final bitmap dimensions */
901 final_llx = FT_MIN( source_llx, target_llx );
902 final_lly = FT_MIN( source_lly, target_lly );
903 final_urx = FT_MAX( source_urx, target_urx );
904 final_ury = FT_MAX( source_ury, target_ury );
906 final_width = ( final_urx - final_llx ) >> 6;
907 final_rows = ( final_ury - final_lly ) >> 6;
909 #ifdef FT_DEBUG_LEVEL_TRACE
910 FT_TRACE5(( "FT_Bitmap_Blend:\n"
911 " source bitmap: (%ld, %ld) -- (%ld, %ld); %d x %d\n",
912 source_llx / 64, source_lly / 64,
913 source_urx / 64, source_ury / 64,
914 source_->width, source_->rows ));
916 if ( target->width && target->rows )
917 FT_TRACE5(( " target bitmap: (%ld, %ld) -- (%ld, %ld); %d x %d\n",
918 target_llx / 64, target_lly / 64,
919 target_urx / 64, target_ury / 64,
920 target->width, target->rows ));
922 FT_TRACE5(( " target bitmap: empty\n" ));
924 if ( final_width && final_rows )
925 FT_TRACE5(( " final bitmap: (%ld, %ld) -- (%ld, %ld); %d x %d\n",
926 final_llx / 64, final_lly / 64,
927 final_urx / 64, final_ury / 64,
928 final_width, final_rows ));
930 FT_TRACE5(( " final bitmap: empty\n" ));
931 #endif /* FT_DEBUG_LEVEL_TRACE */
933 if ( !( final_width && final_rows ) )
934 return FT_Err_Ok; /* nothing to do */
936 /* for blending, set offset vector of final bitmap */
937 /* temporarily to (0,0) */
938 source_llx -= final_llx;
939 source_lly -= final_lly;
941 if ( target->width && target->rows )
943 target_llx -= final_llx;
944 target_lly -= final_lly;
947 /* set up target bitmap */
948 if ( target->pixel_mode == FT_PIXEL_MODE_NONE )
950 /* create new empty bitmap */
951 target->width = final_width;
952 target->rows = final_rows;
953 target->pixel_mode = FT_PIXEL_MODE_BGRA;
954 target->pitch = (int)final_width * 4;
955 target->num_grays = 256;
957 if ( FT_LONG_MAX / target->pitch < (int)target->rows )
959 FT_TRACE5(( "FT_Blend_Bitmap: target bitmap too large (%d x %d)\n",
960 final_width, final_rows ));
961 return FT_THROW( Invalid_Argument );
964 if ( FT_ALLOC( target->buffer, target->pitch * (int)target->rows ) )
967 free_target_bitmap_on_error = 1;
969 else if ( target->width != final_width ||
970 target->rows != final_rows )
972 /* adjust old bitmap to enlarged size */
973 int pitch, new_pitch;
975 unsigned char* buffer = NULL;
978 pitch = target->pitch;
983 new_pitch = (int)final_width * 4;
985 if ( FT_LONG_MAX / new_pitch < (int)final_rows )
987 FT_TRACE5(( "FT_Blend_Bitmap: target bitmap too large (%d x %d)\n",
988 final_width, final_rows ));
989 return FT_THROW( Invalid_Argument );
992 /* TODO: provide an in-buffer solution for large bitmaps */
993 /* to avoid allocation of a new buffer */
994 if ( FT_ALLOC( buffer, new_pitch * (int)final_rows ) )
997 /* copy data to new buffer */
1001 /* the bitmap flow is from top to bottom, */
1002 /* but y is measured from bottom to top */
1003 if ( target->pitch < 0 )
1013 ( final_rows - y - target->rows ) * new_pitch +
1015 unsigned char* limit_p =
1016 p + pitch * (int)target->rows;
1019 while ( p < limit_p )
1021 FT_MEM_COPY( q, p, pitch );
1028 FT_FREE( target->buffer );
1030 target->width = final_width;
1031 target->rows = final_rows;
1033 if ( target->pitch < 0 )
1034 target->pitch = -new_pitch;
1036 target->pitch = new_pitch;
1038 target->buffer = buffer;
1041 /* adjust source bitmap if necessary */
1042 if ( source_->pixel_mode != FT_PIXEL_MODE_GRAY )
1044 FT_Bitmap_Init( &source_bitmap );
1045 error = FT_Bitmap_Convert( library, source_, &source_bitmap, 1 );
1049 source = &source_bitmap;
1050 free_source_bitmap = 1;
1055 /* do blending; the code below returns pre-multiplied channels, */
1056 /* similar to what FreeType gets from `CBDT' tables */
1057 x = source_llx >> 6;
1058 y = source_lly >> 6;
1060 /* the bitmap flow is from top to bottom, */
1061 /* but y is measured from bottom to top */
1062 if ( target->pitch < 0 )
1072 ( target->rows - y - source->rows ) * target->pitch +
1074 unsigned char* limit_p =
1075 p + source->pitch * (int)source->rows;
1078 while ( p < limit_p )
1080 unsigned char* r = p;
1081 unsigned char* s = q;
1082 unsigned char* limit_r = r + source->width;
1085 while ( r < limit_r )
1088 int fa = color.alpha * aa / 255;
1090 int fb = color.blue * fa / 255;
1091 int fg = color.green * fa / 255;
1092 int fr = color.red * fa / 255;
1102 *s++ = (unsigned char)( bb * ba2 / 255 + fb );
1103 *s++ = (unsigned char)( bg * ba2 / 255 + fg );
1104 *s++ = (unsigned char)( br * ba2 / 255 + fr );
1105 *s++ = (unsigned char)( ba * ba2 / 255 + fa );
1113 atarget_offset->x = final_llx;
1114 atarget_offset->y = final_lly + ( final_rows << 6 );
1117 if ( error && free_target_bitmap_on_error )
1118 FT_Bitmap_Done( library, target );
1120 if ( free_source_bitmap )
1121 FT_Bitmap_Done( library, &source_bitmap );
1127 /* documentation is in ftbitmap.h */
1129 FT_EXPORT_DEF( FT_Error )
1130 FT_GlyphSlot_Own_Bitmap( FT_GlyphSlot slot )
1132 if ( slot && slot->format == FT_GLYPH_FORMAT_BITMAP &&
1133 !( slot->internal->flags & FT_GLYPH_OWN_BITMAP ) )
1139 FT_Bitmap_Init( &bitmap );
1140 error = FT_Bitmap_Copy( slot->library, &slot->bitmap, &bitmap );
1144 slot->bitmap = bitmap;
1145 slot->internal->flags |= FT_GLYPH_OWN_BITMAP;
1152 /* documentation is in ftbitmap.h */
1154 FT_EXPORT_DEF( FT_Error )
1155 FT_Bitmap_Done( FT_Library library,
1162 return FT_THROW( Invalid_Library_Handle );
1165 return FT_THROW( Invalid_Argument );
1167 memory = library->memory;
1169 FT_FREE( bitmap->buffer );
1170 *bitmap = null_bitmap;