1 /***************************************************************************/
5 /* A new `perfect' anti-aliasing renderer (body). */
7 /* Copyright 2000-2003, 2005-2014 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. */
16 /***************************************************************************/
18 /*************************************************************************/
20 /* This file can be compiled without the rest of the FreeType engine, by */
21 /* defining the _STANDALONE_ macro when compiling it. You also need to */
22 /* put the files `ftgrays.h' and `ftimage.h' into the current */
23 /* compilation directory. Typically, you could do something like */
25 /* - copy `src/smooth/ftgrays.c' (this file) to your current directory */
27 /* - copy `include/ftimage.h' and `src/smooth/ftgrays.h' to the same */
30 /* - compile `ftgrays' with the _STANDALONE_ macro defined, as in */
32 /* cc -c -D_STANDALONE_ ftgrays.c */
34 /* The renderer can be initialized with a call to */
35 /* `ft_gray_raster.raster_new'; an anti-aliased bitmap can be generated */
36 /* with a call to `ft_gray_raster.raster_render'. */
38 /* See the comments and documentation in the file `ftimage.h' for more */
39 /* details on how the raster works. */
41 /*************************************************************************/
43 /*************************************************************************/
45 /* This is a new anti-aliasing scan-converter for FreeType 2. The */
46 /* algorithm used here is _very_ different from the one in the standard */
47 /* `ftraster' module. Actually, `ftgrays' computes the _exact_ */
48 /* coverage of the outline on each pixel cell. */
50 /* It is based on ideas that I initially found in Raph Levien's */
51 /* excellent LibArt graphics library (see http://www.levien.com/libart */
52 /* for more information, though the web pages do not tell anything */
53 /* about the renderer; you'll have to dive into the source code to */
54 /* understand how it works). */
56 /* Note, however, that this is a _very_ different implementation */
57 /* compared to Raph's. Coverage information is stored in a very */
58 /* different way, and I don't use sorted vector paths. Also, it doesn't */
59 /* use floating point values. */
61 /* This renderer has the following advantages: */
63 /* - It doesn't need an intermediate bitmap. Instead, one can supply a */
64 /* callback function that will be called by the renderer to draw gray */
65 /* spans on any target surface. You can thus do direct composition on */
66 /* any kind of bitmap, provided that you give the renderer the right */
69 /* - A perfect anti-aliaser, i.e., it computes the _exact_ coverage on */
70 /* each pixel cell. */
72 /* - It performs a single pass on the outline (the `standard' FT2 */
73 /* renderer makes two passes). */
75 /* - It can easily be modified to render to _any_ number of gray levels */
78 /* - For small (< 20) pixel sizes, it is faster than the standard */
81 /*************************************************************************/
84 /*************************************************************************/
86 /* The macro FT_COMPONENT is used in trace mode. It is an implicit */
87 /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */
88 /* messages during execution. */
91 #define FT_COMPONENT trace_smooth
97 /* Auxiliary macros for token concatenation. */
98 #define FT_ERR_XCAT( x, y ) x ## y
99 #define FT_ERR_CAT( x, y ) FT_ERR_XCAT( x, y )
102 /* define this to dump debugging information */
103 /* #define FT_DEBUG_LEVEL_TRACE */
106 #ifdef FT_DEBUG_LEVEL_TRACE
115 #define FT_UINT_MAX UINT_MAX
116 #define FT_INT_MAX INT_MAX
118 #define ft_memset memset
120 #define ft_setjmp setjmp
121 #define ft_longjmp longjmp
122 #define ft_jmp_buf jmp_buf
124 typedef ptrdiff_t FT_PtrDist
;
127 #define ErrRaster_Invalid_Mode -2
128 #define ErrRaster_Invalid_Outline -1
129 #define ErrRaster_Invalid_Argument -3
130 #define ErrRaster_Memory_Overflow -4
132 #define FT_BEGIN_HEADER
133 #define FT_END_HEADER
139 /* This macro is used to indicate that a function parameter is unused. */
140 /* Its purpose is simply to reduce compiler warnings. Note also that */
141 /* simply defining it as `(void)x' doesn't avoid warnings with certain */
142 /* ANSI compilers (e.g. LCC). */
143 #define FT_UNUSED( x ) (x) = (x)
146 /* we only use level 5 & 7 tracing messages; cf. ftdebug.h */
148 #ifdef FT_DEBUG_LEVEL_TRACE
151 FT_Message( const char* fmt
,
158 vfprintf( stderr
, fmt
, ap
);
163 /* empty function useful for setting a breakpoint to catch errors */
177 /* we don't handle tracing levels in stand-alone mode; */
179 #define FT_TRACE5( varformat ) FT_Message varformat
182 #define FT_TRACE7( varformat ) FT_Message varformat
185 #define FT_ERROR( varformat ) FT_Message varformat
188 #define FT_THROW( e ) \
189 ( FT_Throw( FT_ERR_CAT( ErrRaster, e ), \
192 FT_ERR_CAT( ErrRaster, e ) )
194 #else /* !FT_DEBUG_LEVEL_TRACE */
196 #define FT_TRACE5( x ) do { } while ( 0 ) /* nothing */
197 #define FT_TRACE7( x ) do { } while ( 0 ) /* nothing */
198 #define FT_ERROR( x ) do { } while ( 0 ) /* nothing */
199 #define FT_THROW( e ) FT_ERR_CAT( ErrRaster_, e )
202 #endif /* !FT_DEBUG_LEVEL_TRACE */
205 #define FT_DEFINE_OUTLINE_FUNCS( class_, \
206 move_to_, line_to_, \
207 conic_to_, cubic_to_, \
209 static const FT_Outline_Funcs class_ = \
219 #define FT_DEFINE_RASTER_FUNCS( class_, glyph_format_, \
220 raster_new_, raster_reset_, \
221 raster_set_mode_, raster_render_, \
223 const FT_Raster_Funcs class_ = \
234 #else /* !_STANDALONE_ */
237 #include <ft2build.h>
239 #include FT_INTERNAL_OBJECTS_H
240 #include FT_INTERNAL_DEBUG_H
241 #include FT_OUTLINE_H
243 #include "ftsmerrs.h"
247 #define Smooth_Err_Invalid_Mode Smooth_Err_Cannot_Render_Glyph
248 #define Smooth_Err_Memory_Overflow Smooth_Err_Out_Of_Memory
249 #define ErrRaster_Memory_Overflow Smooth_Err_Out_Of_Memory
252 #endif /* !_STANDALONE_ */
256 #define FT_MEM_SET( d, s, c ) ft_memset( d, s, c )
260 #define FT_MEM_ZERO( dest, count ) FT_MEM_SET( dest, 0, count )
263 /* as usual, for the speed hungry :-) */
270 #ifndef FT_STATIC_RASTER
272 #define RAS_ARG gray_PWorker worker
273 #define RAS_ARG_ gray_PWorker worker,
275 #define RAS_VAR worker
276 #define RAS_VAR_ worker,
278 #else /* FT_STATIC_RASTER */
280 #define RAS_ARG /* empty */
281 #define RAS_ARG_ /* empty */
282 #define RAS_VAR /* empty */
283 #define RAS_VAR_ /* empty */
285 #endif /* FT_STATIC_RASTER */
288 /* must be at least 6 bits! */
296 #define ONE_PIXEL ( 1L << PIXEL_BITS )
297 #define PIXEL_MASK ( -1L << PIXEL_BITS )
298 #define TRUNC( x ) ( (TCoord)( (x) >> PIXEL_BITS ) )
299 #define SUBPIXELS( x ) ( (TPos)(x) << PIXEL_BITS )
300 #define FLOOR( x ) ( (x) & -ONE_PIXEL )
301 #define CEILING( x ) ( ( (x) + ONE_PIXEL - 1 ) & -ONE_PIXEL )
302 #define ROUND( x ) ( ( (x) + ONE_PIXEL / 2 ) & -ONE_PIXEL )
305 #define UPSCALE( x ) ( (x) << ( PIXEL_BITS - 6 ) )
306 #define DOWNSCALE( x ) ( (x) >> ( PIXEL_BITS - 6 ) )
308 #define UPSCALE( x ) ( (x) >> ( 6 - PIXEL_BITS ) )
309 #define DOWNSCALE( x ) ( (x) << ( 6 - PIXEL_BITS ) )
313 /* Compute `dividend / divisor' and return both its quotient and */
314 /* remainder, cast to a specific type. This macro also ensures that */
315 /* the remainder is always positive. */
316 #define FT_DIV_MOD( type, dividend, divisor, quotient, remainder ) \
318 (quotient) = (type)( (dividend) / (divisor) ); \
319 (remainder) = (type)( (dividend) % (divisor) ); \
320 if ( (remainder) < 0 ) \
323 (remainder) += (type)(divisor); \
328 /* Work around a bug specific to GCC which make the compiler fail to */
329 /* optimize a division and modulo operation on the same parameters */
330 /* into a single call to `__aeabi_idivmod'. See */
332 /* http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43721 */
334 #define FT_DIV_MOD( type, dividend, divisor, quotient, remainder ) \
336 (quotient) = (type)( (dividend) / (divisor) ); \
337 (remainder) = (type)( (dividend) - (quotient) * (divisor) ); \
338 if ( (remainder) < 0 ) \
341 (remainder) += (type)(divisor); \
347 /*************************************************************************/
349 /* TYPE DEFINITIONS */
352 /* don't change the following types to FT_Int or FT_Pos, since we might */
353 /* need to define them to "float" or "double" when experimenting with */
356 typedef long TCoord
; /* integer scanline/pixel coordinate */
357 typedef long TPos
; /* sub-pixel coordinate */
359 /* determine the type used to store cell areas. This normally takes at */
360 /* least PIXEL_BITS*2 + 1 bits. On 16-bit systems, we need to use */
361 /* `long' instead of `int', otherwise bad things happen */
367 #else /* PIXEL_BITS >= 8 */
369 /* approximately determine the size of integers using an ANSI-C header */
370 #if FT_UINT_MAX == 0xFFFFU
376 #endif /* PIXEL_BITS >= 8 */
379 /* maximum number of gray spans in a call to the span callback */
380 #define FT_MAX_GRAY_SPANS 32
383 typedef struct TCell_
* PCell
;
385 typedef struct TCell_
387 TPos x
; /* same with gray_TWorker.ex */
388 TCoord cover
; /* same with gray_TWorker.cover */
395 #if defined( _MSC_VER ) /* Visual C++ (and Intel C++) */
396 /* We disable the warning `structure was padded due to */
397 /* __declspec(align())' in order to compile cleanly with */
398 /* the maximum level of warnings. */
399 #pragma warning( push )
400 #pragma warning( disable : 4324 )
401 #endif /* _MSC_VER */
403 typedef struct gray_TWorker_
408 TPos count_ex
, count_ey
;
415 FT_PtrDist max_cells
;
416 FT_PtrDist num_cells
;
423 FT_Vector bez_stack
[32 * 3 + 1];
430 FT_Span gray_spans
[FT_MAX_GRAY_SPANS
];
433 FT_Raster_Span_Func render_span
;
434 void* render_span_data
;
440 ft_jmp_buf jump_buffer
;
448 } gray_TWorker
, *gray_PWorker
;
450 #if defined( _MSC_VER )
451 #pragma warning( pop )
455 #ifndef FT_STATIC_RASTER
456 #define ras (*worker)
458 static gray_TWorker ras
;
462 typedef struct gray_TRaster_
470 } gray_TRaster
, *gray_PRaster
;
474 /*************************************************************************/
476 /* Initialize the cells table. */
479 gray_init_cells( RAS_ARG_
void* buffer
,
483 ras
.buffer_size
= byte_size
;
485 ras
.ycells
= (PCell
*) buffer
;
495 /*************************************************************************/
497 /* Compute the outline bounding box. */
500 gray_compute_cbox( RAS_ARG
)
502 FT_Outline
* outline
= &ras
.outline
;
503 FT_Vector
* vec
= outline
->points
;
504 FT_Vector
* limit
= vec
+ outline
->n_points
;
507 if ( outline
->n_points
<= 0 )
509 ras
.min_ex
= ras
.max_ex
= 0;
510 ras
.min_ey
= ras
.max_ey
= 0;
514 ras
.min_ex
= ras
.max_ex
= vec
->x
;
515 ras
.min_ey
= ras
.max_ey
= vec
->y
;
519 for ( ; vec
< limit
; vec
++ )
525 if ( x
< ras
.min_ex
) ras
.min_ex
= x
;
526 if ( x
> ras
.max_ex
) ras
.max_ex
= x
;
527 if ( y
< ras
.min_ey
) ras
.min_ey
= y
;
528 if ( y
> ras
.max_ey
) ras
.max_ey
= y
;
531 /* truncate the bounding box to integer pixels */
532 ras
.min_ex
= ras
.min_ex
>> 6;
533 ras
.min_ey
= ras
.min_ey
>> 6;
534 ras
.max_ex
= ( ras
.max_ex
+ 63 ) >> 6;
535 ras
.max_ey
= ( ras
.max_ey
+ 63 ) >> 6;
539 /*************************************************************************/
541 /* Record the current cell in the table. */
544 gray_find_cell( RAS_ARG
)
550 if ( x
> ras
.count_ex
)
553 pcell
= &ras
.ycells
[ras
.ey
];
557 if ( cell
== NULL
|| cell
->x
> x
)
566 if ( ras
.num_cells
>= ras
.max_cells
)
567 ft_longjmp( ras
.jump_buffer
, 1 );
569 cell
= ras
.cells
+ ras
.num_cells
++;
583 gray_record_cell( RAS_ARG
)
585 if ( ras
.area
| ras
.cover
)
587 PCell cell
= gray_find_cell( RAS_VAR
);
590 cell
->area
+= ras
.area
;
591 cell
->cover
+= ras
.cover
;
596 /*************************************************************************/
598 /* Set the current cell to a new position. */
601 gray_set_cell( RAS_ARG_ TCoord ex
,
604 /* Move the cell pointer to a new position. We set the `invalid' */
605 /* flag to indicate that the cell isn't part of those we're interested */
606 /* in during the render phase. This means that: */
608 /* . the new vertical position must be within min_ey..max_ey-1. */
609 /* . the new horizontal position must be strictly less than max_ex */
611 /* Note that if a cell is to the left of the clipping region, it is */
612 /* actually set to the (min_ex-1) horizontal position. */
614 /* All cells that are on the left of the clipping region go to the */
615 /* min_ex - 1 horizontal position. */
618 if ( ex
> ras
.max_ex
)
625 /* are we moving to a different cell ? */
626 if ( ex
!= ras
.ex
|| ey
!= ras
.ey
)
628 /* record the current one if it is valid */
630 gray_record_cell( RAS_VAR
);
638 ras
.invalid
= ( (unsigned)ey
>= (unsigned)ras
.count_ey
||
639 ex
>= ras
.count_ex
);
643 /*************************************************************************/
645 /* Start a new contour at a given cell. */
648 gray_start_cell( RAS_ARG_ TCoord ex
,
651 if ( ex
> ras
.max_ex
)
652 ex
= (TCoord
)( ras
.max_ex
);
654 if ( ex
< ras
.min_ex
)
655 ex
= (TCoord
)( ras
.min_ex
- 1 );
659 ras
.ex
= ex
- ras
.min_ex
;
660 ras
.ey
= ey
- ras
.min_ey
;
661 ras
.last_ey
= SUBPIXELS( ey
);
664 gray_set_cell( RAS_VAR_ ex
, ey
);
668 /*************************************************************************/
670 /* Render a scanline as one or more cells. */
673 gray_render_scanline( RAS_ARG_ TCoord ey
,
679 TCoord ex1
, ex2
, fx1
, fx2
, delta
, mod
;
688 fx1
= (TCoord
)( x1
- SUBPIXELS( ex1
) );
689 fx2
= (TCoord
)( x2
- SUBPIXELS( ex2
) );
691 /* trivial case. Happens often */
694 gray_set_cell( RAS_VAR_ ex2
, ey
);
698 /* everything is located in a single cell. That is easy! */
703 ras
.area
+= (TArea
)(( fx1
+ fx2
) * delta
);
708 /* ok, we'll have to render a run of adjacent cells on the same */
711 p
= ( ONE_PIXEL
- fx1
) * ( y2
- y1
);
717 p
= fx1
* ( y2
- y1
);
723 FT_DIV_MOD( TCoord
, p
, dx
, delta
, mod
);
725 ras
.area
+= (TArea
)(( fx1
+ first
) * delta
);
729 gray_set_cell( RAS_VAR_ ex1
, ey
);
737 p
= ONE_PIXEL
* ( y2
- y1
+ delta
);
738 FT_DIV_MOD( TCoord
, p
, dx
, lift
, rem
);
752 ras
.area
+= (TArea
)(ONE_PIXEL
* delta
);
756 gray_set_cell( RAS_VAR_ ex1
, ey
);
761 ras
.area
+= (TArea
)(( fx2
+ ONE_PIXEL
- first
) * delta
);
766 /*************************************************************************/
768 /* Render a given line as a series of scanlines. */
771 gray_render_line( RAS_ARG_ TPos to_x
,
774 TCoord ey1
, ey2
, fy1
, fy2
, mod
;
777 int delta
, rem
, lift
, incr
;
780 ey1
= TRUNC( ras
.last_ey
);
781 ey2
= TRUNC( to_y
); /* if (ey2 >= ras.max_ey) ey2 = ras.max_ey-1; */
782 fy1
= (TCoord
)( ras
.y
- ras
.last_ey
);
783 fy2
= (TCoord
)( to_y
- SUBPIXELS( ey2
) );
788 /* perform vertical clipping */
800 if ( min
>= ras
.max_ey
|| max
< ras
.min_ey
)
804 /* everything is on a single scanline */
807 gray_render_scanline( RAS_VAR_ ey1
, ras
.x
, fy1
, to_x
, fy2
);
811 /* vertical line - avoid calling gray_render_scanline */
816 TCoord ex
= TRUNC( ras
.x
);
817 TCoord two_fx
= (TCoord
)( ( ras
.x
- SUBPIXELS( ex
) ) << 1 );
828 delta
= (int)( first
- fy1
);
829 ras
.area
+= (TArea
)two_fx
* delta
;
833 gray_set_cell( RAS_VAR_ ex
, ey1
);
835 delta
= (int)( first
+ first
- ONE_PIXEL
);
836 area
= (TArea
)two_fx
* delta
;
843 gray_set_cell( RAS_VAR_ ex
, ey1
);
846 delta
= (int)( fy2
- ONE_PIXEL
+ first
);
847 ras
.area
+= (TArea
)two_fx
* delta
;
853 /* ok, we have to render several scanlines */
854 p
= ( ONE_PIXEL
- fy1
) * dx
;
866 FT_DIV_MOD( int, p
, dy
, delta
, mod
);
869 gray_render_scanline( RAS_VAR_ ey1
, ras
.x
, fy1
, x
, (TCoord
)first
);
872 gray_set_cell( RAS_VAR_
TRUNC( x
), ey1
);
877 FT_DIV_MOD( int, p
, dy
, lift
, rem
);
891 gray_render_scanline( RAS_VAR_ ey1
, x
,
892 (TCoord
)( ONE_PIXEL
- first
), x2
,
897 gray_set_cell( RAS_VAR_
TRUNC( x
), ey1
);
901 gray_render_scanline( RAS_VAR_ ey1
, x
,
902 (TCoord
)( ONE_PIXEL
- first
), to_x
,
908 ras
.last_ey
= SUBPIXELS( ey2
);
913 gray_split_conic( FT_Vector
* base
)
918 base
[4].x
= base
[2].x
;
920 a
= base
[3].x
= ( base
[2].x
+ b
) / 2;
921 b
= base
[1].x
= ( base
[0].x
+ b
) / 2;
922 base
[2].x
= ( a
+ b
) / 2;
924 base
[4].y
= base
[2].y
;
926 a
= base
[3].y
= ( base
[2].y
+ b
) / 2;
927 b
= base
[1].y
= ( base
[0].y
+ b
) / 2;
928 base
[2].y
= ( a
+ b
) / 2;
933 gray_render_conic( RAS_ARG_
const FT_Vector
* control
,
934 const FT_Vector
* to
)
943 levels
= ras
.lev_stack
;
946 arc
[0].x
= UPSCALE( to
->x
);
947 arc
[0].y
= UPSCALE( to
->y
);
948 arc
[1].x
= UPSCALE( control
->x
);
949 arc
[1].y
= UPSCALE( control
->y
);
954 dx
= FT_ABS( arc
[2].x
+ arc
[0].x
- 2 * arc
[1].x
);
955 dy
= FT_ABS( arc
[2].y
+ arc
[0].y
- 2 * arc
[1].y
);
959 if ( dx
< ONE_PIXEL
/ 4 )
962 /* short-cut the arc that crosses the current band */
963 min
= max
= arc
[0].y
;
966 if ( y
< min
) min
= y
;
967 if ( y
> max
) max
= y
;
970 if ( y
< min
) min
= y
;
971 if ( y
> max
) max
= y
;
973 if ( TRUNC( min
) >= ras
.max_ey
|| TRUNC( max
) < ras
.min_ey
)
981 } while ( dx
> ONE_PIXEL
/ 4 );
990 gray_split_conic( arc
);
993 levels
[top
] = levels
[top
- 1] = level
- 1;
998 gray_render_line( RAS_VAR_ arc
[0].x
, arc
[0].y
);
1002 } while ( top
>= 0 );
1007 gray_split_cubic( FT_Vector
* base
)
1012 base
[6].x
= base
[3].x
;
1015 base
[1].x
= a
= ( base
[0].x
+ c
) / 2;
1016 base
[5].x
= b
= ( base
[3].x
+ d
) / 2;
1018 base
[2].x
= a
= ( a
+ c
) / 2;
1019 base
[4].x
= b
= ( b
+ c
) / 2;
1020 base
[3].x
= ( a
+ b
) / 2;
1022 base
[6].y
= base
[3].y
;
1025 base
[1].y
= a
= ( base
[0].y
+ c
) / 2;
1026 base
[5].y
= b
= ( base
[3].y
+ d
) / 2;
1028 base
[2].y
= a
= ( a
+ c
) / 2;
1029 base
[4].y
= b
= ( b
+ c
) / 2;
1030 base
[3].y
= ( a
+ b
) / 2;
1035 gray_render_cubic( RAS_ARG_
const FT_Vector
* control1
,
1036 const FT_Vector
* control2
,
1037 const FT_Vector
* to
)
1043 arc
= ras
.bez_stack
;
1044 arc
[0].x
= UPSCALE( to
->x
);
1045 arc
[0].y
= UPSCALE( to
->y
);
1046 arc
[1].x
= UPSCALE( control2
->x
);
1047 arc
[1].y
= UPSCALE( control2
->y
);
1048 arc
[2].x
= UPSCALE( control1
->x
);
1049 arc
[2].y
= UPSCALE( control1
->y
);
1053 /* Short-cut the arc that crosses the current band. */
1054 min
= max
= arc
[0].y
;
1074 if ( TRUNC( min
) >= ras
.max_ey
|| TRUNC( max
) < ras
.min_ey
)
1079 /* Decide whether to split or draw. See `Rapid Termination */
1080 /* Evaluation for Recursive Subdivision of Bezier Curves' by Thomas */
1082 /* http://www.cis.southalabama.edu/~hain/general/Publications/Bezier/Camera-ready%20CISST02%202.pdf */
1085 TPos dx
, dy
, dx_
, dy_
;
1086 TPos dx1
, dy1
, dx2
, dy2
;
1090 /* dx and dy are x and y components of the P0-P3 chord vector. */
1091 dx
= arc
[3].x
- arc
[0].x
;
1092 dy
= arc
[3].y
- arc
[0].y
;
1094 /* L is an (under)estimate of the Euclidean distance P0-P3. */
1096 /* If dx >= dy, then r = sqrt(dx^2 + dy^2) can be overestimated */
1097 /* with least maximum error by */
1099 /* r_upperbound = dx + (sqrt(2) - 1) * dy , */
1101 /* where sqrt(2) - 1 can be (over)estimated by 107/256, giving an */
1102 /* error of no more than 8.4%. */
1104 /* Similarly, some elementary calculus shows that r can be */
1105 /* underestimated with least maximum error by */
1107 /* r_lowerbound = sqrt(2 + sqrt(2)) / 2 * dx */
1108 /* + sqrt(2 - sqrt(2)) / 2 * dy . */
1110 /* 236/256 and 97/256 are (under)estimates of the two algebraic */
1111 /* numbers, giving an error of no more than 8.1%. */
1116 /* This is the same as */
1118 /* L = ( 236 * FT_MAX( dx_, dy_ ) */
1119 /* + 97 * FT_MIN( dx_, dy_ ) ) >> 8; */
1120 L
= ( dx_
> dy_
? 236 * dx_
+ 97 * dy_
1121 : 97 * dx_
+ 236 * dy_
) >> 8;
1123 /* Avoid possible arithmetic overflow below by splitting. */
1127 /* Max deviation may be as much as (s/L) * 3/4 (if Hain's v = 1). */
1128 s_limit
= L
* (TPos
)( ONE_PIXEL
/ 6 );
1130 /* s is L * the perpendicular distance from P1 to the line P0-P3. */
1131 dx1
= arc
[1].x
- arc
[0].x
;
1132 dy1
= arc
[1].y
- arc
[0].y
;
1133 s
= FT_ABS( dy
* dx1
- dx
* dy1
);
1138 /* s is L * the perpendicular distance from P2 to the line P0-P3. */
1139 dx2
= arc
[2].x
- arc
[0].x
;
1140 dy2
= arc
[2].y
- arc
[0].y
;
1141 s
= FT_ABS( dy
* dx2
- dx
* dy2
);
1146 /* Split super curvy segments where the off points are so far
1147 from the chord that the angles P0-P1-P3 or P0-P2-P3 become
1148 acute as detected by appropriate dot products. */
1149 if ( dx1
* ( dx1
- dx
) + dy1
* ( dy1
- dy
) > 0 ||
1150 dx2
* ( dx2
- dx
) + dy2
* ( dy2
- dy
) > 0 )
1153 /* No reason to split. */
1158 gray_split_cubic( arc
);
1163 gray_render_line( RAS_VAR_ arc
[0].x
, arc
[0].y
);
1165 if ( arc
== ras
.bez_stack
)
1174 gray_move_to( const FT_Vector
* to
,
1175 gray_PWorker worker
)
1180 /* record current cell, if any */
1182 gray_record_cell( RAS_VAR
);
1184 /* start to a new position */
1185 x
= UPSCALE( to
->x
);
1186 y
= UPSCALE( to
->y
);
1188 gray_start_cell( RAS_VAR_
TRUNC( x
), TRUNC( y
) );
1197 gray_line_to( const FT_Vector
* to
,
1198 gray_PWorker worker
)
1200 gray_render_line( RAS_VAR_
UPSCALE( to
->x
), UPSCALE( to
->y
) );
1206 gray_conic_to( const FT_Vector
* control
,
1207 const FT_Vector
* to
,
1208 gray_PWorker worker
)
1210 gray_render_conic( RAS_VAR_ control
, to
);
1216 gray_cubic_to( const FT_Vector
* control1
,
1217 const FT_Vector
* control2
,
1218 const FT_Vector
* to
,
1219 gray_PWorker worker
)
1221 gray_render_cubic( RAS_VAR_ control1
, control2
, to
);
1227 gray_render_span( int y
,
1229 const FT_Span
* spans
,
1230 gray_PWorker worker
)
1233 FT_Bitmap
* map
= &worker
->target
;
1236 /* first of all, compute the scanline offset */
1237 p
= (unsigned char*)map
->buffer
- y
* map
->pitch
;
1238 if ( map
->pitch
>= 0 )
1239 p
+= (unsigned)( ( map
->rows
- 1 ) * map
->pitch
);
1241 for ( ; count
> 0; count
--, spans
++ )
1243 unsigned char coverage
= spans
->coverage
;
1248 /* For small-spans it is faster to do it by ourselves than
1249 * calling `memset'. This is mainly due to the cost of the
1252 if ( spans
->len
>= 8 )
1253 FT_MEM_SET( p
+ spans
->x
, (unsigned char)coverage
, spans
->len
);
1256 unsigned char* q
= p
+ spans
->x
;
1259 switch ( spans
->len
)
1261 case 7: *q
++ = (unsigned char)coverage
;
1262 case 6: *q
++ = (unsigned char)coverage
;
1263 case 5: *q
++ = (unsigned char)coverage
;
1264 case 4: *q
++ = (unsigned char)coverage
;
1265 case 3: *q
++ = (unsigned char)coverage
;
1266 case 2: *q
++ = (unsigned char)coverage
;
1267 case 1: *q
= (unsigned char)coverage
;
1278 gray_hline( RAS_ARG_ TCoord x
,
1286 /* compute the coverage line's coverage, depending on the */
1287 /* outline fill rule */
1289 /* the coverage percentage is area/(PIXEL_BITS*PIXEL_BITS*2) */
1291 coverage
= (int)( area
>> ( PIXEL_BITS
* 2 + 1 - 8 ) );
1292 /* use range 0..256 */
1294 coverage
= -coverage
;
1296 if ( ras
.outline
.flags
& FT_OUTLINE_EVEN_ODD_FILL
)
1300 if ( coverage
> 256 )
1301 coverage
= 512 - coverage
;
1302 else if ( coverage
== 256 )
1307 /* normal non-zero winding rule */
1308 if ( coverage
>= 256 )
1312 y
+= (TCoord
)ras
.min_ey
;
1313 x
+= (TCoord
)ras
.min_ex
;
1315 /* FT_Span.x is a 16-bit short, so limit our coordinates appropriately */
1319 /* FT_Span.y is an integer, so limit our coordinates appropriately */
1320 if ( y
>= FT_INT_MAX
)
1329 /* see whether we can add this span to the current list */
1330 count
= ras
.num_gray_spans
;
1331 span
= ras
.gray_spans
+ count
- 1;
1334 (int)span
->x
+ span
->len
== (int)x
&&
1335 span
->coverage
== coverage
)
1337 span
->len
= (unsigned short)( span
->len
+ acount
);
1341 if ( ras
.span_y
!= y
|| count
>= FT_MAX_GRAY_SPANS
)
1343 if ( ras
.render_span
&& count
> 0 )
1344 ras
.render_span( ras
.span_y
, count
, ras
.gray_spans
,
1345 ras
.render_span_data
);
1347 #ifdef FT_DEBUG_LEVEL_TRACE
1354 FT_TRACE7(( "y = %3d ", ras
.span_y
));
1355 span
= ras
.gray_spans
;
1356 for ( n
= 0; n
< count
; n
++, span
++ )
1357 FT_TRACE7(( "[%d..%d]:%02x ",
1358 span
->x
, span
->x
+ span
->len
- 1, span
->coverage
));
1359 FT_TRACE7(( "\n" ));
1362 #endif /* FT_DEBUG_LEVEL_TRACE */
1364 ras
.num_gray_spans
= 0;
1365 ras
.span_y
= (int)y
;
1367 span
= ras
.gray_spans
;
1372 /* add a gray span to the current list */
1374 span
->len
= (unsigned short)acount
;
1375 span
->coverage
= (unsigned char)coverage
;
1377 ras
.num_gray_spans
++;
1382 #ifdef FT_DEBUG_LEVEL_TRACE
1384 /* to be called while in the debugger -- */
1385 /* this function causes a compiler warning since it is unused otherwise */
1387 gray_dump_cells( RAS_ARG
)
1392 for ( yindex
= 0; yindex
< ras
.ycount
; yindex
++ )
1397 printf( "%3d:", yindex
);
1399 for ( cell
= ras
.ycells
[yindex
]; cell
!= NULL
; cell
= cell
->next
)
1400 printf( " (%3ld, c:%4ld, a:%6d)", cell
->x
, cell
->cover
, cell
->area
);
1405 #endif /* FT_DEBUG_LEVEL_TRACE */
1409 gray_sweep( RAS_ARG_
const FT_Bitmap
* target
)
1413 FT_UNUSED( target
);
1416 if ( ras
.num_cells
== 0 )
1419 ras
.num_gray_spans
= 0;
1421 FT_TRACE7(( "gray_sweep: start\n" ));
1423 for ( yindex
= 0; yindex
< ras
.ycount
; yindex
++ )
1425 PCell cell
= ras
.ycells
[yindex
];
1430 for ( ; cell
!= NULL
; cell
= cell
->next
)
1435 if ( cell
->x
> x
&& cover
!= 0 )
1436 gray_hline( RAS_VAR_ x
, yindex
, cover
* ( ONE_PIXEL
* 2 ),
1439 cover
+= cell
->cover
;
1440 area
= cover
* ( ONE_PIXEL
* 2 ) - cell
->area
;
1442 if ( area
!= 0 && cell
->x
>= 0 )
1443 gray_hline( RAS_VAR_ cell
->x
, yindex
, area
, 1 );
1449 gray_hline( RAS_VAR_ x
, yindex
, cover
* ( ONE_PIXEL
* 2 ),
1453 if ( ras
.render_span
&& ras
.num_gray_spans
> 0 )
1454 ras
.render_span( ras
.span_y
, ras
.num_gray_spans
,
1455 ras
.gray_spans
, ras
.render_span_data
);
1457 #ifdef FT_DEBUG_LEVEL_TRACE
1459 if ( ras
.num_gray_spans
> 0 )
1465 FT_TRACE7(( "y = %3d ", ras
.span_y
));
1466 span
= ras
.gray_spans
;
1467 for ( n
= 0; n
< ras
.num_gray_spans
; n
++, span
++ )
1468 FT_TRACE7(( "[%d..%d]:%02x ",
1469 span
->x
, span
->x
+ span
->len
- 1, span
->coverage
));
1470 FT_TRACE7(( "\n" ));
1473 FT_TRACE7(( "gray_sweep: end\n" ));
1475 #endif /* FT_DEBUG_LEVEL_TRACE */
1482 /*************************************************************************/
1484 /* The following function should only compile in stand-alone mode, */
1485 /* i.e., when building this component without the rest of FreeType. */
1487 /*************************************************************************/
1489 /*************************************************************************/
1492 /* FT_Outline_Decompose */
1495 /* Walk over an outline's structure to decompose it into individual */
1496 /* segments and Bézier arcs. This function is also able to emit */
1497 /* `move to' and `close to' operations to indicate the start and end */
1498 /* of new contours in the outline. */
1501 /* outline :: A pointer to the source target. */
1503 /* func_interface :: A table of `emitters', i.e., function pointers */
1504 /* called during decomposition to indicate path */
1508 /* user :: A typeless pointer which is passed to each */
1509 /* emitter during the decomposition. It can be */
1510 /* used to store the state during the */
1511 /* decomposition. */
1514 /* Error code. 0 means success. */
1517 FT_Outline_Decompose( const FT_Outline
* outline
,
1518 const FT_Outline_Funcs
* func_interface
,
1522 #define SCALED( x ) ( ( (x) << shift ) - delta )
1525 FT_Vector v_control
;
1534 int n
; /* index of contour in outline */
1535 int first
; /* index of first point in contour */
1536 char tag
; /* current point's state */
1542 if ( !outline
|| !func_interface
)
1543 return FT_THROW( Invalid_Argument
);
1545 shift
= func_interface
->shift
;
1546 delta
= func_interface
->delta
;
1549 for ( n
= 0; n
< outline
->n_contours
; n
++ )
1551 int last
; /* index of last point in contour */
1554 FT_TRACE5(( "FT_Outline_Decompose: Outline %d\n", n
));
1556 last
= outline
->contours
[n
];
1558 goto Invalid_Outline
;
1559 limit
= outline
->points
+ last
;
1561 v_start
= outline
->points
[first
];
1562 v_start
.x
= SCALED( v_start
.x
);
1563 v_start
.y
= SCALED( v_start
.y
);
1565 v_last
= outline
->points
[last
];
1566 v_last
.x
= SCALED( v_last
.x
);
1567 v_last
.y
= SCALED( v_last
.y
);
1569 v_control
= v_start
;
1571 point
= outline
->points
+ first
;
1572 tags
= outline
->tags
+ first
;
1573 tag
= FT_CURVE_TAG( tags
[0] );
1575 /* A contour cannot start with a cubic control point! */
1576 if ( tag
== FT_CURVE_TAG_CUBIC
)
1577 goto Invalid_Outline
;
1579 /* check first point to determine origin */
1580 if ( tag
== FT_CURVE_TAG_CONIC
)
1582 /* first point is conic control. Yes, this happens. */
1583 if ( FT_CURVE_TAG( outline
->tags
[last
] ) == FT_CURVE_TAG_ON
)
1585 /* start at last point if it is on the curve */
1591 /* if both first and last points are conic, */
1592 /* start at their middle and record its position */
1594 v_start
.x
= ( v_start
.x
+ v_last
.x
) / 2;
1595 v_start
.y
= ( v_start
.y
+ v_last
.y
) / 2;
1603 FT_TRACE5(( " move to (%.2f, %.2f)\n",
1604 v_start
.x
/ 64.0, v_start
.y
/ 64.0 ));
1605 error
= func_interface
->move_to( &v_start
, user
);
1609 while ( point
< limit
)
1614 tag
= FT_CURVE_TAG( tags
[0] );
1617 case FT_CURVE_TAG_ON
: /* emit a single line_to */
1622 vec
.x
= SCALED( point
->x
);
1623 vec
.y
= SCALED( point
->y
);
1625 FT_TRACE5(( " line to (%.2f, %.2f)\n",
1626 vec
.x
/ 64.0, vec
.y
/ 64.0 ));
1627 error
= func_interface
->line_to( &vec
, user
);
1633 case FT_CURVE_TAG_CONIC
: /* consume conic arcs */
1634 v_control
.x
= SCALED( point
->x
);
1635 v_control
.y
= SCALED( point
->y
);
1638 if ( point
< limit
)
1646 tag
= FT_CURVE_TAG( tags
[0] );
1648 vec
.x
= SCALED( point
->x
);
1649 vec
.y
= SCALED( point
->y
);
1651 if ( tag
== FT_CURVE_TAG_ON
)
1653 FT_TRACE5(( " conic to (%.2f, %.2f)"
1654 " with control (%.2f, %.2f)\n",
1655 vec
.x
/ 64.0, vec
.y
/ 64.0,
1656 v_control
.x
/ 64.0, v_control
.y
/ 64.0 ));
1657 error
= func_interface
->conic_to( &v_control
, &vec
, user
);
1663 if ( tag
!= FT_CURVE_TAG_CONIC
)
1664 goto Invalid_Outline
;
1666 v_middle
.x
= ( v_control
.x
+ vec
.x
) / 2;
1667 v_middle
.y
= ( v_control
.y
+ vec
.y
) / 2;
1669 FT_TRACE5(( " conic to (%.2f, %.2f)"
1670 " with control (%.2f, %.2f)\n",
1671 v_middle
.x
/ 64.0, v_middle
.y
/ 64.0,
1672 v_control
.x
/ 64.0, v_control
.y
/ 64.0 ));
1673 error
= func_interface
->conic_to( &v_control
, &v_middle
, user
);
1681 FT_TRACE5(( " conic to (%.2f, %.2f)"
1682 " with control (%.2f, %.2f)\n",
1683 v_start
.x
/ 64.0, v_start
.y
/ 64.0,
1684 v_control
.x
/ 64.0, v_control
.y
/ 64.0 ));
1685 error
= func_interface
->conic_to( &v_control
, &v_start
, user
);
1688 default: /* FT_CURVE_TAG_CUBIC */
1690 FT_Vector vec1
, vec2
;
1693 if ( point
+ 1 > limit
||
1694 FT_CURVE_TAG( tags
[1] ) != FT_CURVE_TAG_CUBIC
)
1695 goto Invalid_Outline
;
1700 vec1
.x
= SCALED( point
[-2].x
);
1701 vec1
.y
= SCALED( point
[-2].y
);
1703 vec2
.x
= SCALED( point
[-1].x
);
1704 vec2
.y
= SCALED( point
[-1].y
);
1706 if ( point
<= limit
)
1711 vec
.x
= SCALED( point
->x
);
1712 vec
.y
= SCALED( point
->y
);
1714 FT_TRACE5(( " cubic to (%.2f, %.2f)"
1715 " with controls (%.2f, %.2f) and (%.2f, %.2f)\n",
1716 vec
.x
/ 64.0, vec
.y
/ 64.0,
1717 vec1
.x
/ 64.0, vec1
.y
/ 64.0,
1718 vec2
.x
/ 64.0, vec2
.y
/ 64.0 ));
1719 error
= func_interface
->cubic_to( &vec1
, &vec2
, &vec
, user
);
1725 FT_TRACE5(( " cubic to (%.2f, %.2f)"
1726 " with controls (%.2f, %.2f) and (%.2f, %.2f)\n",
1727 v_start
.x
/ 64.0, v_start
.y
/ 64.0,
1728 vec1
.x
/ 64.0, vec1
.y
/ 64.0,
1729 vec2
.x
/ 64.0, vec2
.y
/ 64.0 ));
1730 error
= func_interface
->cubic_to( &vec1
, &vec2
, &v_start
, user
);
1736 /* close the contour with a line segment */
1737 FT_TRACE5(( " line to (%.2f, %.2f)\n",
1738 v_start
.x
/ 64.0, v_start
.y
/ 64.0 ));
1739 error
= func_interface
->line_to( &v_start
, user
);
1748 FT_TRACE5(( "FT_Outline_Decompose: Done\n", n
));
1752 FT_TRACE5(( "FT_Outline_Decompose: Error %d\n", error
));
1756 return FT_THROW( Invalid_Outline
);
1759 #endif /* _STANDALONE_ */
1762 typedef struct gray_TBand_
1768 FT_DEFINE_OUTLINE_FUNCS(func_interface
,
1769 (FT_Outline_MoveTo_Func
) gray_move_to
,
1770 (FT_Outline_LineTo_Func
) gray_line_to
,
1771 (FT_Outline_ConicTo_Func
)gray_conic_to
,
1772 (FT_Outline_CubicTo_Func
)gray_cubic_to
,
1778 gray_convert_glyph_inner( RAS_ARG
)
1781 volatile int error
= 0;
1783 #ifdef FT_CONFIG_OPTION_PIC
1784 FT_Outline_Funcs func_interface
;
1785 Init_Class_func_interface(&func_interface
);
1788 if ( ft_setjmp( ras
.jump_buffer
) == 0 )
1790 error
= FT_Outline_Decompose( &ras
.outline
, &func_interface
, &ras
);
1792 gray_record_cell( RAS_VAR
);
1795 error
= FT_THROW( Memory_Overflow
);
1802 gray_convert_glyph( RAS_ARG
)
1804 gray_TBand bands
[40];
1805 gray_TBand
* volatile band
;
1806 int volatile n
, num_bands
;
1807 TPos
volatile min
, max
, max_y
;
1811 /* Set up state in the raster object */
1812 gray_compute_cbox( RAS_VAR
);
1814 /* clip to target bitmap, exit if nothing to do */
1815 clip
= &ras
.clip_box
;
1817 if ( ras
.max_ex
<= clip
->xMin
|| ras
.min_ex
>= clip
->xMax
||
1818 ras
.max_ey
<= clip
->yMin
|| ras
.min_ey
>= clip
->yMax
)
1821 if ( ras
.min_ex
< clip
->xMin
) ras
.min_ex
= clip
->xMin
;
1822 if ( ras
.min_ey
< clip
->yMin
) ras
.min_ey
= clip
->yMin
;
1824 if ( ras
.max_ex
> clip
->xMax
) ras
.max_ex
= clip
->xMax
;
1825 if ( ras
.max_ey
> clip
->yMax
) ras
.max_ey
= clip
->yMax
;
1827 ras
.count_ex
= ras
.max_ex
- ras
.min_ex
;
1828 ras
.count_ey
= ras
.max_ey
- ras
.min_ey
;
1830 /* set up vertical bands */
1831 num_bands
= (int)( ( ras
.max_ey
- ras
.min_ey
) / ras
.band_size
);
1832 if ( num_bands
== 0 )
1834 if ( num_bands
>= 39 )
1842 for ( n
= 0; n
< num_bands
; n
++, min
= max
)
1844 max
= min
+ ras
.band_size
;
1845 if ( n
== num_bands
- 1 || max
> max_y
)
1852 while ( band
>= bands
)
1854 TPos bottom
, top
, middle
;
1860 long cell_start
, cell_end
, cell_mod
;
1863 ras
.ycells
= (PCell
*)ras
.buffer
;
1864 ras
.ycount
= band
->max
- band
->min
;
1866 cell_start
= sizeof ( PCell
) * ras
.ycount
;
1867 cell_mod
= cell_start
% sizeof ( TCell
);
1869 cell_start
+= sizeof ( TCell
) - cell_mod
;
1871 cell_end
= ras
.buffer_size
;
1872 cell_end
-= cell_end
% sizeof ( TCell
);
1874 cells_max
= (PCell
)( (char*)ras
.buffer
+ cell_end
);
1875 ras
.cells
= (PCell
)( (char*)ras
.buffer
+ cell_start
);
1876 if ( ras
.cells
>= cells_max
)
1879 ras
.max_cells
= cells_max
- ras
.cells
;
1880 if ( ras
.max_cells
< 2 )
1883 for ( yindex
= 0; yindex
< ras
.ycount
; yindex
++ )
1884 ras
.ycells
[yindex
] = NULL
;
1889 ras
.min_ey
= band
->min
;
1890 ras
.max_ey
= band
->max
;
1891 ras
.count_ey
= band
->max
- band
->min
;
1893 error
= gray_convert_glyph_inner( RAS_VAR
);
1897 gray_sweep( RAS_VAR_
&ras
.target
);
1901 else if ( error
!= ErrRaster_Memory_Overflow
)
1905 /* render pool overflow; we will reduce the render band by half */
1908 middle
= bottom
+ ( ( top
- bottom
) >> 1 );
1910 /* This is too complex for a single scanline; there must */
1911 /* be some problems. */
1912 if ( middle
== bottom
)
1914 #ifdef FT_DEBUG_LEVEL_TRACE
1915 FT_TRACE7(( "gray_convert_glyph: rotten glyph\n" ));
1920 if ( bottom
-top
>= ras
.band_size
)
1923 band
[1].min
= bottom
;
1924 band
[1].max
= middle
;
1925 band
[0].min
= middle
;
1931 if ( ras
.band_shoot
> 8 && ras
.band_size
> 16 )
1932 ras
.band_size
= ras
.band_size
/ 2;
1939 gray_raster_render( gray_PRaster raster
,
1940 const FT_Raster_Params
* params
)
1942 const FT_Outline
* outline
= (const FT_Outline
*)params
->source
;
1943 const FT_Bitmap
* target_map
= params
->target
;
1944 gray_PWorker worker
;
1947 if ( !raster
|| !raster
->buffer
|| !raster
->buffer_size
)
1948 return FT_THROW( Invalid_Argument
);
1951 return FT_THROW( Invalid_Outline
);
1953 /* return immediately if the outline is empty */
1954 if ( outline
->n_points
== 0 || outline
->n_contours
<= 0 )
1957 if ( !outline
->contours
|| !outline
->points
)
1958 return FT_THROW( Invalid_Outline
);
1960 if ( outline
->n_points
!=
1961 outline
->contours
[outline
->n_contours
- 1] + 1 )
1962 return FT_THROW( Invalid_Outline
);
1964 worker
= raster
->worker
;
1966 /* if direct mode is not set, we must have a target bitmap */
1967 if ( !( params
->flags
& FT_RASTER_FLAG_DIRECT
) )
1970 return FT_THROW( Invalid_Argument
);
1973 if ( !target_map
->width
|| !target_map
->rows
)
1976 if ( !target_map
->buffer
)
1977 return FT_THROW( Invalid_Argument
);
1980 /* this version does not support monochrome rendering */
1981 if ( !( params
->flags
& FT_RASTER_FLAG_AA
) )
1982 return FT_THROW( Invalid_Mode
);
1984 /* compute clipping box */
1985 if ( !( params
->flags
& FT_RASTER_FLAG_DIRECT
) )
1987 /* compute clip box from target pixmap */
1988 ras
.clip_box
.xMin
= 0;
1989 ras
.clip_box
.yMin
= 0;
1990 ras
.clip_box
.xMax
= target_map
->width
;
1991 ras
.clip_box
.yMax
= target_map
->rows
;
1993 else if ( params
->flags
& FT_RASTER_FLAG_CLIP
)
1994 ras
.clip_box
= params
->clip_box
;
1997 ras
.clip_box
.xMin
= -32768L;
1998 ras
.clip_box
.yMin
= -32768L;
1999 ras
.clip_box
.xMax
= 32767L;
2000 ras
.clip_box
.yMax
= 32767L;
2003 gray_init_cells( RAS_VAR_ raster
->buffer
, raster
->buffer_size
);
2005 ras
.outline
= *outline
;
2008 ras
.band_size
= raster
->band_size
;
2009 ras
.num_gray_spans
= 0;
2011 if ( params
->flags
& FT_RASTER_FLAG_DIRECT
)
2013 ras
.render_span
= (FT_Raster_Span_Func
)params
->gray_spans
;
2014 ras
.render_span_data
= params
->user
;
2018 ras
.target
= *target_map
;
2019 ras
.render_span
= (FT_Raster_Span_Func
)gray_render_span
;
2020 ras
.render_span_data
= &ras
;
2023 return gray_convert_glyph( RAS_VAR
);
2027 /**** RASTER OBJECT CREATION: In stand-alone mode, we simply use *****/
2028 /**** a static object. *****/
2033 gray_raster_new( void* memory
,
2034 FT_Raster
* araster
)
2036 static gray_TRaster the_raster
;
2038 FT_UNUSED( memory
);
2041 *araster
= (FT_Raster
)&the_raster
;
2042 FT_MEM_ZERO( &the_raster
, sizeof ( the_raster
) );
2049 gray_raster_done( FT_Raster raster
)
2052 FT_UNUSED( raster
);
2055 #else /* !_STANDALONE_ */
2058 gray_raster_new( FT_Memory memory
,
2059 FT_Raster
* araster
)
2062 gray_PRaster raster
= NULL
;
2066 if ( !FT_ALLOC( raster
, sizeof ( gray_TRaster
) ) )
2068 raster
->memory
= memory
;
2069 *araster
= (FT_Raster
)raster
;
2077 gray_raster_done( FT_Raster raster
)
2079 FT_Memory memory
= (FT_Memory
)((gray_PRaster
)raster
)->memory
;
2085 #endif /* !_STANDALONE_ */
2089 gray_raster_reset( FT_Raster raster
,
2093 gray_PRaster rast
= (gray_PRaster
)raster
;
2098 if ( pool_base
&& pool_size
>= (long)sizeof ( gray_TWorker
) + 2048 )
2100 gray_PWorker worker
= (gray_PWorker
)pool_base
;
2103 rast
->worker
= worker
;
2104 rast
->buffer
= pool_base
+
2105 ( ( sizeof ( gray_TWorker
) +
2106 sizeof ( TCell
) - 1 ) &
2107 ~( sizeof ( TCell
) - 1 ) );
2108 rast
->buffer_size
= (long)( ( pool_base
+ pool_size
) -
2109 (char*)rast
->buffer
) &
2110 ~( sizeof ( TCell
) - 1 );
2111 rast
->band_size
= (int)( rast
->buffer_size
/
2112 ( sizeof ( TCell
) * 8 ) );
2116 rast
->buffer
= NULL
;
2117 rast
->buffer_size
= 0;
2118 rast
->worker
= NULL
;
2124 FT_DEFINE_RASTER_FUNCS(ft_grays_raster
,
2125 FT_GLYPH_FORMAT_OUTLINE
,
2127 (FT_Raster_New_Func
) gray_raster_new
,
2128 (FT_Raster_Reset_Func
) gray_raster_reset
,
2129 (FT_Raster_Set_Mode_Func
)0,
2130 (FT_Raster_Render_Func
) gray_raster_render
,
2131 (FT_Raster_Done_Func
) gray_raster_done
2138 /* Local Variables: */