ReactOS 0.4.16-dev-334-g4d9f67c
ftbitmap.c File Reference
#include <ft2build.h>
Include dependency graph for ftbitmap.c:

Go to the source code of this file.

Functions

 FT_Bitmap_Init (FT_Bitmap *abitmap)
 
 FT_Bitmap_New (FT_Bitmap *abitmap)
 
 FT_Bitmap_Copy (FT_Library library, const FT_Bitmap *source, FT_Bitmap *target)
 
static FT_Error ft_bitmap_assure_buffer (FT_Memory memory, FT_Bitmap *bitmap, FT_UInt xpixels, FT_UInt ypixels)
 
 FT_Bitmap_Embolden (FT_Library library, FT_Bitmap *bitmap, FT_Pos xStrength, FT_Pos yStrength)
 
static FT_Byte ft_gray_for_premultiplied_srgb_bgra (const FT_Byte *bgra)
 
 FT_Bitmap_Convert (FT_Library library, const FT_Bitmap *source, FT_Bitmap *target, FT_Int alignment)
 
 FT_GlyphSlot_Own_Bitmap (FT_GlyphSlot slot)
 
 FT_Bitmap_Done (FT_Library library, FT_Bitmap *bitmap)
 

Variables

static const FT_Bitmap null_bitmap = { 0, 0, 0, 0, 0, 0, 0, 0 }
 

Function Documentation

◆ ft_bitmap_assure_buffer()

static FT_Error ft_bitmap_assure_buffer ( FT_Memory  memory,
FT_Bitmap bitmap,
FT_UInt  xpixels,
FT_UInt  ypixels 
)
static

Definition at line 150 of file ftbitmap.c.

154 {
156 unsigned int pitch;
157 unsigned int new_pitch;
158 FT_UInt bpp;
160 unsigned char* buffer = NULL;
161
162
163 width = bitmap->width;
164 height = bitmap->rows;
165 pitch = (unsigned int)FT_ABS( bitmap->pitch );
166
167 switch ( bitmap->pixel_mode )
168 {
170 bpp = 1;
171 new_pitch = ( width + xpixels + 7 ) >> 3;
172 break;
174 bpp = 2;
175 new_pitch = ( width + xpixels + 3 ) >> 2;
176 break;
178 bpp = 4;
179 new_pitch = ( width + xpixels + 1 ) >> 1;
180 break;
184 bpp = 8;
185 new_pitch = width + xpixels;
186 break;
187 default:
188 return FT_THROW( Invalid_Glyph_Format );
189 }
190
191 /* if no need to allocate memory */
192 if ( ypixels == 0 && new_pitch <= pitch )
193 {
194 /* zero the padding */
195 FT_UInt bit_width = pitch * 8;
196 FT_UInt bit_last = ( width + xpixels ) * bpp;
197
198
199 if ( bit_last < bit_width )
200 {
201 FT_Byte* line = bitmap->buffer + ( bit_last >> 3 );
202 FT_Byte* end = bitmap->buffer + pitch;
203 FT_UInt shift = bit_last & 7;
204 FT_UInt mask = 0xFF00U >> shift;
206
207
208 for ( ; count > 0; count--, line += pitch, end += pitch )
209 {
210 FT_Byte* write = line;
211
212
213 if ( shift > 0 )
214 {
215 write[0] = (FT_Byte)( write[0] & mask );
216 write++;
217 }
218 if ( write < end )
220 }
221 }
222
223 return FT_Err_Ok;
224 }
225
226 /* otherwise allocate new buffer */
227 if ( FT_QALLOC_MULT( buffer, bitmap->rows + ypixels, new_pitch ) )
228 return error;
229
230 /* new rows get added at the top of the bitmap, */
231 /* thus take care of the flow direction */
232 if ( bitmap->pitch > 0 )
233 {
234 FT_UInt len = ( width * bpp + 7 ) >> 3;
235
236 unsigned char* in = bitmap->buffer;
237 unsigned char* out = buffer;
238
239 unsigned char* limit = bitmap->buffer + pitch * bitmap->rows;
240 unsigned int delta = new_pitch - pitch;
241
242
243 FT_MEM_ZERO( out, new_pitch * ypixels );
244 out += new_pitch * ypixels;
245
246 while ( in < limit )
247 {
248 FT_MEM_COPY( out, in, len );
249 in += pitch;
250 out += pitch;
251
252 FT_MEM_ZERO( out, delta );
253 out += delta;
254 }
255 }
256 else
257 {
258 FT_UInt len = ( width * bpp + 7 ) >> 3;
259
260 unsigned char* in = bitmap->buffer;
261 unsigned char* out = buffer;
262
263 unsigned char* limit = bitmap->buffer + pitch * bitmap->rows;
264 unsigned int delta = new_pitch - pitch;
265
266
267 while ( in < limit )
268 {
269 FT_MEM_COPY( out, in, len );
270 in += pitch;
271 out += pitch;
272
273 FT_MEM_ZERO( out, delta );
274 out += delta;
275 }
276
277 FT_MEM_ZERO( out, new_pitch * ypixels );
278 }
279
280 FT_FREE( bitmap->buffer );
281 bitmap->buffer = buffer;
282
283 /* set pitch only, width and height are left untouched */
284 if ( bitmap->pitch < 0 )
285 bitmap->pitch = -(int)new_pitch;
286 else
287 bitmap->pitch = (int)new_pitch;
288
289 return FT_Err_Ok;
290 }
#define write
Definition: acwin.h:97
#define NULL
Definition: types.h:112
DWORD bpp
Definition: surface.c:185
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31
return FT_Err_Ok
Definition: ftbbox.c:511
#define FT_THROW(e)
Definition: ftdebug.h:213
@ FT_PIXEL_MODE_GRAY2
Definition: ftimage.h:185
@ FT_PIXEL_MODE_LCD_V
Definition: ftimage.h:188
@ FT_PIXEL_MODE_MONO
Definition: ftimage.h:183
@ FT_PIXEL_MODE_GRAY
Definition: ftimage.h:184
@ FT_PIXEL_MODE_LCD
Definition: ftimage.h:187
@ FT_PIXEL_MODE_GRAY4
Definition: ftimage.h:186
#define FT_QALLOC_MULT(ptr, count, item_size)
Definition: ftmemory.h:322
#define FT_FREE(ptr)
Definition: ftmemory.h:329
#define FT_MEM_COPY(dest, source, count)
Definition: ftmemory.h:228
#define FT_MEM_ZERO(dest, count)
Definition: ftmemory.h:235
#define FT_ABS(a)
Definition: ftobjs.h:74
unsigned char FT_Byte
Definition: fttypes.h:154
int FT_Error
Definition: fttypes.h:300
unsigned int FT_UInt
Definition: fttypes.h:231
GLuint GLuint end
Definition: gl.h:1545
GLuint GLuint GLsizei count
Definition: gl.h:1545
GLint GLint GLsizei GLsizei height
Definition: gl.h:1546
GLint GLint GLsizei width
Definition: gl.h:1546
GLuint buffer
Definition: glext.h:5915
GLenum GLint GLuint mask
Definition: glext.h:6028
GLint limit
Definition: glext.h:10326
GLuint in
Definition: glext.h:9616
GLenum GLsizei len
Definition: glext.h:6722
#define error(str)
Definition: mkdosfs.c:1605
#define shift
Definition: input.c:1755
static FILE * out
Definition: regtests2xml.c:44
Definition: uimain.c:89
uint32 width
Definition: uimain.c:91
Definition: parser.c:49

Referenced by FT_Bitmap_Embolden().

◆ FT_Bitmap_Convert()

FT_Bitmap_Convert ( FT_Library  library,
const FT_Bitmap source,
FT_Bitmap target,
FT_Int  alignment 
)

Definition at line 504 of file ftbitmap.c.

508 {
511
512 FT_Byte* s;
513 FT_Byte* t;
514
515
516 if ( !library )
517 return FT_THROW( Invalid_Library_Handle );
518
519 if ( !source || !target )
520 return FT_THROW( Invalid_Argument );
521
523
524 switch ( source->pixel_mode )
525 {
533 {
534 FT_Int pad, old_target_pitch, target_pitch;
535 FT_ULong old_size;
536
537
538 old_target_pitch = target->pitch;
539 if ( old_target_pitch < 0 )
540 old_target_pitch = -old_target_pitch;
541
542 old_size = target->rows * (FT_UInt)old_target_pitch;
543
544 target->pixel_mode = FT_PIXEL_MODE_GRAY;
545 target->rows = source->rows;
546 target->width = source->width;
547
548 pad = 0;
549 if ( alignment > 0 )
550 {
551 pad = (FT_Int)source->width % alignment;
552 if ( pad != 0 )
553 pad = alignment - pad;
554 }
555
556 target_pitch = (FT_Int)source->width + pad;
557
558 if ( target_pitch > 0 &&
559 (FT_ULong)target->rows > FT_ULONG_MAX / (FT_ULong)target_pitch )
560 return FT_THROW( Invalid_Argument );
561
562 if ( FT_QREALLOC( target->buffer,
563 old_size, target->rows * (FT_UInt)target_pitch ) )
564 return error;
565
566 target->pitch = target->pitch < 0 ? -target_pitch : target_pitch;
567 }
568 break;
569
570 default:
571 error = FT_THROW( Invalid_Argument );
572 }
573
574 s = source->buffer;
575 t = target->buffer;
576
577 /* take care of bitmap flow */
578 if ( source->pitch < 0 )
579 s -= source->pitch * (FT_Int)( source->rows - 1 );
580 if ( target->pitch < 0 )
581 t -= target->pitch * (FT_Int)( target->rows - 1 );
582
583 switch ( source->pixel_mode )
584 {
586 {
587 FT_UInt i;
588
589
590 target->num_grays = 2;
591
592 for ( i = source->rows; i > 0; i-- )
593 {
594 FT_Byte* ss = s;
595 FT_Byte* tt = t;
596 FT_UInt j;
597
598
599 /* get the full bytes */
600 for ( j = source->width >> 3; j > 0; j-- )
601 {
602 FT_Int val = ss[0]; /* avoid a byte->int cast on each line */
603
604#ifdef __REACTOS__
605 tt[0] = (FT_Byte)( ( val & 0x80 ) ? 0xff : 0);
606 tt[1] = (FT_Byte)( ( val & 0x40 ) ? 0xff : 0);
607 tt[2] = (FT_Byte)( ( val & 0x20 ) ? 0xff : 0);
608 tt[3] = (FT_Byte)( ( val & 0x10 ) ? 0xff : 0);
609 tt[4] = (FT_Byte)( ( val & 0x08 ) ? 0xff : 0);
610 tt[5] = (FT_Byte)( ( val & 0x04 ) ? 0xff : 0);
611 tt[6] = (FT_Byte)( ( val & 0x02 ) ? 0xff : 0);
612 tt[7] = (FT_Byte)( ( val & 0x01 ) ? 0xff : 0);
613#else
614 tt[0] = (FT_Byte)( ( val & 0x80 ) >> 7 );
615 tt[1] = (FT_Byte)( ( val & 0x40 ) >> 6 );
616 tt[2] = (FT_Byte)( ( val & 0x20 ) >> 5 );
617 tt[3] = (FT_Byte)( ( val & 0x10 ) >> 4 );
618 tt[4] = (FT_Byte)( ( val & 0x08 ) >> 3 );
619 tt[5] = (FT_Byte)( ( val & 0x04 ) >> 2 );
620 tt[6] = (FT_Byte)( ( val & 0x02 ) >> 1 );
621 tt[7] = (FT_Byte)( val & 0x01 );
622#endif
623
624 tt += 8;
625 ss += 1;
626 }
627
628 /* get remaining pixels (if any) */
629 j = source->width & 7;
630 if ( j > 0 )
631 {
632 FT_Int val = *ss;
633
634
635 for ( ; j > 0; j-- )
636 {
637#ifdef __REACTOS__
638 tt[0] = (FT_Byte)( ( val & 0x80 ) ? 0xff : 0);
639#else
640 tt[0] = (FT_Byte)( ( val & 0x80 ) >> 7);
641#endif
642 val <<= 1;
643 tt += 1;
644 }
645 }
646
647 s += source->pitch;
648 t += target->pitch;
649 }
650 }
651 break;
652
653
657 {
658 FT_UInt width = source->width;
659 FT_UInt i;
660
661
662 target->num_grays = 256;
663
664 for ( i = source->rows; i > 0; i-- )
665 {
666 FT_ARRAY_COPY( t, s, width );
667
668 s += source->pitch;
669 t += target->pitch;
670 }
671 }
672 break;
673
674
676 {
677 FT_UInt i;
678
679
680 target->num_grays = 4;
681
682 for ( i = source->rows; i > 0; i-- )
683 {
684 FT_Byte* ss = s;
685 FT_Byte* tt = t;
686 FT_UInt j;
687
688
689 /* get the full bytes */
690 for ( j = source->width >> 2; j > 0; j-- )
691 {
692 FT_Int val = ss[0];
693
694
695 tt[0] = (FT_Byte)( ( val & 0xC0 ) >> 6 );
696 tt[1] = (FT_Byte)( ( val & 0x30 ) >> 4 );
697 tt[2] = (FT_Byte)( ( val & 0x0C ) >> 2 );
698 tt[3] = (FT_Byte)( ( val & 0x03 ) );
699
700 ss += 1;
701 tt += 4;
702 }
703
704 j = source->width & 3;
705 if ( j > 0 )
706 {
707 FT_Int val = ss[0];
708
709
710 for ( ; j > 0; j-- )
711 {
712 tt[0] = (FT_Byte)( ( val & 0xC0 ) >> 6 );
713 val <<= 2;
714 tt += 1;
715 }
716 }
717
718 s += source->pitch;
719 t += target->pitch;
720 }
721 }
722 break;
723
724
726 {
727 FT_UInt i;
728
729
730 target->num_grays = 16;
731
732 for ( i = source->rows; i > 0; i-- )
733 {
734 FT_Byte* ss = s;
735 FT_Byte* tt = t;
736 FT_UInt j;
737
738
739 /* get the full bytes */
740 for ( j = source->width >> 1; j > 0; j-- )
741 {
742 FT_Int val = ss[0];
743
744
745 tt[0] = (FT_Byte)( ( val & 0xF0 ) >> 4 );
746 tt[1] = (FT_Byte)( ( val & 0x0F ) );
747
748 ss += 1;
749 tt += 2;
750 }
751
752 if ( source->width & 1 )
753 tt[0] = (FT_Byte)( ( ss[0] & 0xF0 ) >> 4 );
754
755 s += source->pitch;
756 t += target->pitch;
757 }
758 }
759 break;
760
761
763 {
764 FT_UInt i;
765
766
767 target->num_grays = 256;
768
769 for ( i = source->rows; i > 0; i-- )
770 {
771 FT_Byte* ss = s;
772 FT_Byte* tt = t;
773 FT_UInt j;
774
775
776 for ( j = source->width; j > 0; j-- )
777 {
779
780 ss += 4;
781 tt += 1;
782 }
783
784 s += source->pitch;
785 t += target->pitch;
786 }
787 }
788 break;
789
790 default:
791 ;
792 }
793
794 return error;
795 }
FT_Library library
Definition: cffdrivr.c:654
static FT_Byte ft_gray_for_premultiplied_srgb_bgra(const FT_Byte *bgra)
Definition: ftbitmap.c:456
@ FT_PIXEL_MODE_BGRA
Definition: ftimage.h:189
#define FT_QREALLOC(ptr, cursz, newsz)
Definition: ftmemory.h:319
#define FT_ARRAY_COPY(dest, source, count)
Definition: ftmemory.h:244
#define FT_ULONG_MAX
Definition: ftstdlib.h:68
typedefFT_BEGIN_HEADER struct FT_MemoryRec_ * FT_Memory
Definition: ftsystem.h:66
unsigned long FT_ULong
Definition: fttypes.h:253
signed int FT_Int
Definition: fttypes.h:220
GLdouble s
Definition: gl.h:2039
GLdouble GLdouble t
Definition: gl.h:2047
GLuint GLfloat * val
Definition: glext.h:7180
GLenum target
Definition: glext.h:7315
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
Definition: glfuncs.h:250
#define ss
Definition: i386-dis.c:441
if(dx< 0)
Definition: linetemp.h:194
static char memory[1024 *256]
Definition: process.c:116
FT_Memory memory
Definition: ftobjs.h:918

Referenced by FT_Bitmap_Embolden(), FT_Render_Glyph_Internal(), and IntGetBitmapGlyphWithCache().

◆ FT_Bitmap_Copy()

FT_Bitmap_Copy ( FT_Library  library,
const FT_Bitmap source,
FT_Bitmap target 
)

Definition at line 54 of file ftbitmap.c.

57 {
60
61 FT_Int pitch;
63
64 FT_Int source_pitch_sign, target_pitch_sign;
65
66
67 if ( !library )
68 return FT_THROW( Invalid_Library_Handle );
69
70 if ( !source || !target )
71 return FT_THROW( Invalid_Argument );
72
73 if ( source == target )
74 return FT_Err_Ok;
75
76 source_pitch_sign = source->pitch < 0 ? -1 : 1;
77 target_pitch_sign = target->pitch < 0 ? -1 : 1;
78
79 if ( !source->buffer )
80 {
81 *target = *source;
82 if ( source_pitch_sign != target_pitch_sign )
83 target->pitch = -target->pitch;
84
85 return FT_Err_Ok;
86 }
87
89 pitch = source->pitch;
90
91 if ( pitch < 0 )
92 pitch = -pitch;
93 size = (FT_ULong)pitch * source->rows;
94
95 if ( target->buffer )
96 {
97 FT_Int target_pitch = target->pitch;
98 FT_ULong target_size;
99
100
101 if ( target_pitch < 0 )
102 target_pitch = -target_pitch;
103 target_size = (FT_ULong)target_pitch * target->rows;
104
105 if ( target_size != size )
106 (void)FT_QREALLOC( target->buffer, target_size, size );
107 }
108 else
109 (void)FT_QALLOC( target->buffer, size );
110
111 if ( !error )
112 {
113 unsigned char *p;
114
115
116 p = target->buffer;
117 *target = *source;
118 target->buffer = p;
119
120 if ( source_pitch_sign == target_pitch_sign )
121 FT_MEM_COPY( target->buffer, source->buffer, size );
122 else
123 {
124 /* take care of bitmap flow */
125 FT_UInt i;
126 FT_Byte* s = source->buffer;
127 FT_Byte* t = target->buffer;
128
129
130 t += (FT_ULong)pitch * ( target->rows - 1 );
131
132 for ( i = target->rows; i > 0; i-- )
133 {
134 FT_ARRAY_COPY( t, s, pitch );
135
136 s += pitch;
137 t -= pitch;
138 }
139 }
140 }
141
142 return error;
143 }
#define FT_QALLOC(ptr, size)
Definition: ftmemory.h:316
GLsizeiptr size
Definition: glext.h:5919
GLfloat GLfloat p
Definition: glext.h:8902

Referenced by ft_bitmap_glyph_copy(), ft_bitmap_glyph_init(), and FT_GlyphSlot_Own_Bitmap().

◆ FT_Bitmap_Done()

FT_Bitmap_Done ( FT_Library  library,
FT_Bitmap bitmap 
)

Definition at line 826 of file ftbitmap.c.

828 {
830
831
832 if ( !library )
833 return FT_THROW( Invalid_Library_Handle );
834
835 if ( !bitmap )
836 return FT_THROW( Invalid_Argument );
837
839
840 FT_FREE( bitmap->buffer );
842
843 return FT_Err_Ok;
844 }
static const FT_Bitmap null_bitmap
Definition: ftbitmap.c:28

Referenced by FT_Bitmap_Embolden(), ft_bitmap_glyph_done(), FT_Render_Glyph_Internal(), and IntGetBitmapGlyphWithCache().

◆ FT_Bitmap_Embolden()

FT_Bitmap_Embolden ( FT_Library  library,
FT_Bitmap bitmap,
FT_Pos  xStrength,
FT_Pos  yStrength 
)

Definition at line 296 of file ftbitmap.c.

300 {
302 unsigned char* p;
303 FT_Int i, x, pitch;
304 FT_UInt y;
305 FT_Int xstr, ystr;
306
307
308 if ( !library )
309 return FT_THROW( Invalid_Library_Handle );
310
311 if ( !bitmap || !bitmap->buffer )
312 return FT_THROW( Invalid_Argument );
313
314 if ( ( ( FT_PIX_ROUND( xStrength ) >> 6 ) > FT_INT_MAX ) ||
315 ( ( FT_PIX_ROUND( yStrength ) >> 6 ) > FT_INT_MAX ) )
316 return FT_THROW( Invalid_Argument );
317
318 xstr = (FT_Int)FT_PIX_ROUND( xStrength ) >> 6;
319 ystr = (FT_Int)FT_PIX_ROUND( yStrength ) >> 6;
320
321 if ( xstr == 0 && ystr == 0 )
322 return FT_Err_Ok;
323 else if ( xstr < 0 || ystr < 0 )
324 return FT_THROW( Invalid_Argument );
325
326 switch ( bitmap->pixel_mode )
327 {
330 {
331 FT_Bitmap tmp;
332
333
334 /* convert to 8bpp */
335 FT_Bitmap_Init( &tmp );
336 error = FT_Bitmap_Convert( library, bitmap, &tmp, 1 );
337 if ( error )
338 return error;
339
341 *bitmap = tmp;
342 }
343 break;
344
346 if ( xstr > 8 )
347 xstr = 8;
348 break;
349
351 xstr *= 3;
352 break;
353
355 ystr *= 3;
356 break;
357
359 /* We don't embolden color glyphs. */
360 return FT_Err_Ok;
361 }
362
364 (FT_UInt)xstr, (FT_UInt)ystr );
365 if ( error )
366 return error;
367
368 /* take care of bitmap flow */
369 pitch = bitmap->pitch;
370 if ( pitch > 0 )
371 p = bitmap->buffer + pitch * ystr;
372 else
373 {
374 pitch = -pitch;
375 p = bitmap->buffer + (FT_UInt)pitch * ( bitmap->rows - 1 );
376 }
377
378 /* for each row */
379 for ( y = 0; y < bitmap->rows; y++ )
380 {
381 /*
382 * Horizontally:
383 *
384 * From the last pixel on, make each pixel or'ed with the
385 * `xstr' pixels before it.
386 */
387 for ( x = pitch - 1; x >= 0; x-- )
388 {
389 unsigned char tmp;
390
391
392 tmp = p[x];
393 for ( i = 1; i <= xstr; i++ )
394 {
395 if ( bitmap->pixel_mode == FT_PIXEL_MODE_MONO )
396 {
397 p[x] |= tmp >> i;
398
399 /* the maximum value of 8 for `xstr' comes from here */
400 if ( x > 0 )
401 p[x] |= p[x - 1] << ( 8 - i );
402
403#if 0
404 if ( p[x] == 0xFF )
405 break;
406#endif
407 }
408 else
409 {
410 if ( x - i >= 0 )
411 {
412 if ( p[x] + p[x - i] > bitmap->num_grays - 1 )
413 {
414 p[x] = (unsigned char)( bitmap->num_grays - 1 );
415 break;
416 }
417 else
418 {
419 p[x] = (unsigned char)( p[x] + p[x - i] );
420 if ( p[x] == bitmap->num_grays - 1 )
421 break;
422 }
423 }
424 else
425 break;
426 }
427 }
428 }
429
430 /*
431 * Vertically:
432 *
433 * Make the above `ystr' rows or'ed with it.
434 */
435 for ( x = 1; x <= ystr; x++ )
436 {
437 unsigned char* q;
438
439
440 q = p - bitmap->pitch * x;
441 for ( i = 0; i < pitch; i++ )
442 q[i] |= p[i];
443 }
444
445 p += bitmap->pitch;
446 }
447
448 bitmap->width += (FT_UInt)xstr;
449 bitmap->rows += (FT_UInt)ystr;
450
451 return FT_Err_Ok;
452 }
unsigned char
Definition: typeof.h:29
FT_Bitmap_Convert(FT_Library library, const FT_Bitmap *source, FT_Bitmap *target, FT_Int alignment)
Definition: ftbitmap.c:504
FT_Bitmap_Done(FT_Library library, FT_Bitmap *bitmap)
Definition: ftbitmap.c:826
FT_Bitmap_Init(FT_Bitmap *abitmap)
Definition: ftbitmap.c:34
static FT_Error ft_bitmap_assure_buffer(FT_Memory memory, FT_Bitmap *bitmap, FT_UInt xpixels, FT_UInt ypixels)
Definition: ftbitmap.c:150
#define FT_PIX_ROUND(x)
Definition: ftobjs.h:93
#define FT_INT_MAX
Definition: ftstdlib.h:63
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
GLint GLint GLint GLint GLint GLint y
Definition: gl.h:1548
GLdouble GLdouble GLdouble GLdouble q
Definition: gl.h:2063

Referenced by FT_GlyphSlot_Embolden().

◆ FT_Bitmap_Init()

FT_Bitmap_Init ( FT_Bitmap abitmap)

Definition at line 34 of file ftbitmap.c.

35 {
36 if ( abitmap )
37 *abitmap = null_bitmap;
38 }

Referenced by FT_Bitmap_Embolden(), ft_bitmap_glyph_init(), FT_GlyphSlot_Own_Bitmap(), and FT_Render_Glyph_Internal().

◆ FT_Bitmap_New()

FT_Bitmap_New ( FT_Bitmap abitmap)

Definition at line 44 of file ftbitmap.c.

45 {
46 if ( abitmap )
47 *abitmap = null_bitmap;
48 }

Referenced by IntGetBitmapGlyphWithCache().

◆ FT_GlyphSlot_Own_Bitmap()

FT_GlyphSlot_Own_Bitmap ( FT_GlyphSlot  slot)

Definition at line 801 of file ftbitmap.c.

802 {
803 if ( slot && slot->format == FT_GLYPH_FORMAT_BITMAP &&
804 !( slot->internal->flags & FT_GLYPH_OWN_BITMAP ) )
805 {
808
809
811 error = FT_Bitmap_Copy( slot->library, &slot->bitmap, &bitmap );
812 if ( error )
813 return error;
814
815 slot->bitmap = bitmap;
816 slot->internal->flags |= FT_GLYPH_OWN_BITMAP;
817 }
818
819 return FT_Err_Ok;
820 }
FT_Bitmap_Copy(FT_Library library, const FT_Bitmap *source, FT_Bitmap *target)
Definition: ftbitmap.c:54
#define FT_GLYPH_OWN_BITMAP
Definition: ftobjs.h:463
Definition: vfat.h:185

Referenced by FT_GlyphSlot_Embolden().

◆ ft_gray_for_premultiplied_srgb_bgra()

static FT_Byte ft_gray_for_premultiplied_srgb_bgra ( const FT_Byte bgra)
static

Definition at line 456 of file ftbitmap.c.

457 {
458 FT_UInt a = bgra[3];
459 FT_UInt l;
460
461
462 /* Short-circuit transparent color to avoid division by zero. */
463 if ( !a )
464 return 0;
465
466 /*
467 * Luminosity for sRGB is defined using ~0.2126,0.7152,0.0722
468 * coefficients for RGB channels *on the linear colors*.
469 * A gamma of 2.2 is fair to assume. And then, we need to
470 * undo the premultiplication too.
471 *
472 * https://accessibility.kde.org/hsl-adjusted.php
473 *
474 * We do the computation with integers only, applying a gamma of 2.0.
475 * We guarantee 32-bit arithmetic to avoid overflow but the resulting
476 * luminosity fits into 16 bits.
477 *
478 */
479
480 l = ( 4732UL /* 0.0722 * 65536 */ * bgra[0] * bgra[0] +
481 46871UL /* 0.7152 * 65536 */ * bgra[1] * bgra[1] +
482 13933UL /* 0.2126 * 65536 */ * bgra[2] * bgra[2] ) >> 16;
483
484 /*
485 * Final transparency can be determined as follows.
486 *
487 * - If alpha is zero, we want 0.
488 * - If alpha is zero and luminosity is zero, we want 255.
489 * - If alpha is zero and luminosity is one, we want 0.
490 *
491 * So the formula is a * (1 - l) = a - l * a.
492 *
493 * We still need to undo premultiplication by dividing l by a*a.
494 *
495 */
496
497 return (FT_Byte)( a - l / a );
498 }
r l[0]
Definition: byte_order.h:168
GLboolean GLboolean GLboolean GLboolean a
Definition: glext.h:6204
#define a
Definition: ke_i.h:78

Referenced by FT_Bitmap_Convert().

Variable Documentation

◆ null_bitmap

const FT_Bitmap null_bitmap = { 0, 0, 0, 0, 0, 0, 0, 0 }
static

Definition at line 28 of file ftbitmap.c.

Referenced by FT_Bitmap_Done(), FT_Bitmap_Init(), and FT_Bitmap_New().