Alexei Podtelezhnikov pushed to branch bitmap_convert at FreeType / FreeType
Commits:
-
468eaf19
by Alexei Podtelezhnikov at 2022-09-21T16:57:34+00:00
2 changed files:
Changes:
... | ... | @@ -47,14 +47,6 @@ FT_BEGIN_HEADER |
47 | 47 | * @description:
|
48 | 48 | * This section contains functions for handling @FT_Bitmap objects,
|
49 | 49 | * automatically adjusting the target's bitmap buffer size as needed.
|
50 | - *
|
|
51 | - * Note that none of the functions changes the bitmap's 'flow' (as
|
|
52 | - * indicated by the sign of the `pitch` field in @FT_Bitmap).
|
|
53 | - *
|
|
54 | - * To set the flow, assign an appropriate positive or negative value to
|
|
55 | - * the `pitch` field of the target @FT_Bitmap object after calling
|
|
56 | - * @FT_Bitmap_Init but before calling any of the other functions
|
|
57 | - * described here.
|
|
58 | 50 | */
|
59 | 51 | |
60 | 52 | |
... | ... | @@ -105,8 +97,14 @@ FT_BEGIN_HEADER |
105 | 97 | * FreeType error code. 0~means success.
|
106 | 98 | *
|
107 | 99 | * @note:
|
108 | - * `source->buffer` and `target->buffer` must neither be equal nor
|
|
109 | - * overlap.
|
|
100 | + * This function reallocates the memory in the target bitmap, which has
|
|
101 | + * to be valid, either initialized by @FT_Bitmap_Init or reused multiple
|
|
102 | + * times. `source->buffer` and `target->buffer` must neither be equal
|
|
103 | + * nor overlap. Use @FT_Bitmap_Done to finally remove the bitmap object.
|
|
104 | + *
|
|
105 | + * The source and target bitmaps can have different flows if their
|
|
106 | + * pitches are set to opposite signs before calling this function.
|
|
107 | + * Otherwise, the flow is preserved.
|
|
110 | 108 | */
|
111 | 109 | FT_EXPORT( FT_Error )
|
112 | 110 | FT_Bitmap_Copy( FT_Library library,
|
... | ... | @@ -67,8 +67,7 @@ |
67 | 67 | FT_Memory memory;
|
68 | 68 | FT_Error error = FT_Err_Ok;
|
69 | 69 | FT_Int pitch;
|
70 | - |
|
71 | - FT_Int source_pitch_sign, target_pitch_sign;
|
|
70 | + FT_Int flip;
|
|
72 | 71 | |
73 | 72 | |
74 | 73 | if ( !library )
|
... | ... | @@ -80,15 +79,15 @@ |
80 | 79 | if ( source == target )
|
81 | 80 | return FT_Err_Ok;
|
82 | 81 | |
83 | - source_pitch_sign = source->pitch < 0 ? -1 : 1;
|
|
84 | - target_pitch_sign = target->pitch < 0 ? -1 : 1;
|
|
82 | + flip = ( source->pitch < 0 && target->pitch > 0 ) ||
|
|
83 | + ( source->pitch > 0 && target->pitch < 0 );
|
|
85 | 84 | |
86 | 85 | memory = library->memory;
|
87 | 86 | FT_FREE( target->buffer );
|
88 | 87 | |
89 | 88 | *target = *source;
|
90 | 89 | |
91 | - if ( source_pitch_sign != target_pitch_sign )
|
|
90 | + if ( flip )
|
|
92 | 91 | target->pitch = -target->pitch;
|
93 | 92 | |
94 | 93 | if ( !source->buffer )
|
... | ... | @@ -102,10 +101,7 @@ |
102 | 101 | |
103 | 102 | if ( !error )
|
104 | 103 | {
|
105 | - if ( source_pitch_sign == target_pitch_sign )
|
|
106 | - FT_MEM_COPY( target->buffer, source->buffer,
|
|
107 | - (FT_Long)source->rows * pitch );
|
|
108 | - else
|
|
104 | + if ( flip )
|
|
109 | 105 | {
|
110 | 106 | /* take care of bitmap flow */
|
111 | 107 | FT_UInt i;
|
... | ... | @@ -123,6 +119,9 @@ |
123 | 119 | t -= pitch;
|
124 | 120 | }
|
125 | 121 | }
|
122 | + else
|
|
123 | + FT_MEM_COPY( target->buffer, source->buffer,
|
|
124 | + (FT_Long)source->rows * pitch );
|
|
126 | 125 | }
|
127 | 126 | |
128 | 127 | return error;
|