1 /***************************************************************************/
5 /* The FreeType glyph rasterizer (body). */
7 /* Copyright 1996-2001, 2002, 2003, 2005, 2007, 2008, 2009 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 `ftimage.h' and `ftmisc.h' into the $(incdir) */
23 /* directory. Typically, you should do something like */
25 /* - copy `src/raster/ftraster.c' (this file) to your current directory */
27 /* - copy `include/freetype/ftimage.h' and `src/raster/ftmisc.h' */
28 /* to your current directory */
30 /* - compile `ftraster' with the _STANDALONE_ macro defined, as in */
32 /* cc -c -D_STANDALONE_ ftraster.c */
34 /* The renderer can be initialized with a call to */
35 /* `ft_standard_raster.raster_new'; a bitmap can be generated */
36 /* with a call to `ft_standard_raster.raster_render'. */
38 /* See the comments and documentation in the file `ftimage.h' for more */
39 /* details on how the raster works. */
41 /*************************************************************************/
44 /*************************************************************************/
46 /* This is a rewrite of the FreeType 1.x scan-line converter */
48 /*************************************************************************/
52 #define FT_CONFIG_STANDARD_LIBRARY_H <stdlib.h>
54 #include <string.h> /* for memset */
59 #else /* !_STANDALONE_ */
63 #include FT_INTERNAL_CALC_H /* for FT_MulDiv only */
67 #endif /* !_STANDALONE_ */
70 /*************************************************************************/
72 /* A simple technical note on how the raster works */
73 /* ----------------------------------------------- */
75 /* Converting an outline into a bitmap is achieved in several steps: */
77 /* 1 - Decomposing the outline into successive `profiles'. Each */
78 /* profile is simply an array of scanline intersections on a given */
79 /* dimension. A profile's main attributes are */
81 /* o its scanline position boundaries, i.e. `Ymin' and `Ymax' */
83 /* o an array of intersection coordinates for each scanline */
84 /* between `Ymin' and `Ymax' */
86 /* o a direction, indicating whether it was built going `up' or */
87 /* `down', as this is very important for filling rules */
89 /* o its drop-out mode */
91 /* 2 - Sweeping the target map's scanlines in order to compute segment */
92 /* `spans' which are then filled. Additionally, this pass */
93 /* performs drop-out control. */
95 /* The outline data is parsed during step 1 only. The profiles are */
96 /* built from the bottom of the render pool, used as a stack. The */
97 /* following graphics shows the profile list under construction: */
99 /* __________________________________________________________ _ _ */
101 /* | profile | coordinates for | profile | coordinates for |--> */
102 /* | 1 | profile 1 | 2 | profile 2 |--> */
103 /* |_________|_________________|_________|_________________|__ _ _ */
107 /* start of render pool top */
109 /* The top of the profile stack is kept in the `top' variable. */
111 /* As you can see, a profile record is pushed on top of the render */
112 /* pool, which is then followed by its coordinates/intersections. If */
113 /* a change of direction is detected in the outline, a new profile is */
114 /* generated until the end of the outline. */
116 /* Note that when all profiles have been generated, the function */
117 /* Finalize_Profile_Table() is used to record, for each profile, its */
118 /* bottom-most scanline as well as the scanline above its upmost */
119 /* boundary. These positions are called `y-turns' because they (sort */
120 /* of) correspond to local extrema. They are stored in a sorted list */
121 /* built from the top of the render pool as a downwards stack: */
123 /* _ _ _______________________________________ */
125 /* <--| sorted list of | */
126 /* <--| extrema scanlines | */
127 /* _ _ __________________|____________________| */
131 /* maxBuff sizeBuff = end of pool */
133 /* This list is later used during the sweep phase in order to */
134 /* optimize performance (see technical note on the sweep below). */
136 /* Of course, the raster detects whether the two stacks collide and */
137 /* handles the situation properly. */
139 /*************************************************************************/
142 /*************************************************************************/
143 /*************************************************************************/
145 /** CONFIGURATION MACROS **/
147 /*************************************************************************/
148 /*************************************************************************/
150 /* define DEBUG_RASTER if you want to compile a debugging version */
151 /* #define DEBUG_RASTER */
153 /* define FT_RASTER_OPTION_ANTI_ALIASING if you want to support */
154 /* 5-levels anti-aliasing */
155 /* #define FT_RASTER_OPTION_ANTI_ALIASING */
157 /* The size of the two-lines intermediate bitmap used */
158 /* for anti-aliasing, in bytes. */
159 #define RASTER_GRAY_LINES 2048
162 /*************************************************************************/
163 /*************************************************************************/
165 /** OTHER MACROS (do not change) **/
167 /*************************************************************************/
168 /*************************************************************************/
170 /*************************************************************************/
172 /* The macro FT_COMPONENT is used in trace mode. It is an implicit */
173 /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */
174 /* messages during execution. */
177 #define FT_COMPONENT trace_raster
183 /* This macro is used to indicate that a function parameter is unused. */
184 /* Its purpose is simply to reduce compiler warnings. Note also that */
185 /* simply defining it as `(void)x' doesn't avoid warnings with certain */
186 /* ANSI compilers (e.g. LCC). */
187 #define FT_UNUSED( x ) (x) = (x)
189 /* Disable the tracing mechanism for simplicity -- developers can */
190 /* activate it easily by redefining these two macros. */
192 #define FT_ERROR( x ) do { } while ( 0 ) /* nothing */
196 #define FT_TRACE( x ) do { } while ( 0 ) /* nothing */
197 #define FT_TRACE1( x ) do { } while ( 0 ) /* nothing */
198 #define FT_TRACE6( x ) do { } while ( 0 ) /* nothing */
201 #define Raster_Err_None 0
202 #define Raster_Err_Not_Ini -1
203 #define Raster_Err_Overflow -2
204 #define Raster_Err_Neg_Height -3
205 #define Raster_Err_Invalid -4
206 #define Raster_Err_Unsupported -5
208 #define ft_memset memset
210 #define FT_DEFINE_RASTER_FUNCS( class_, glyph_format_, raster_new_, \
211 raster_reset_, raster_set_mode_, \
212 raster_render_, raster_done_ ) \
213 const FT_Raster_Funcs class_ = \
223 #else /* !_STANDALONE_ */
226 #include FT_INTERNAL_OBJECTS_H
227 #include FT_INTERNAL_DEBUG_H /* for FT_TRACE() and FT_ERROR() */
229 #include "rasterrs.h"
231 #define Raster_Err_None Raster_Err_Ok
232 #define Raster_Err_Not_Ini Raster_Err_Raster_Uninitialized
233 #define Raster_Err_Overflow Raster_Err_Raster_Overflow
234 #define Raster_Err_Neg_Height Raster_Err_Raster_Negative_Height
235 #define Raster_Err_Invalid Raster_Err_Invalid_Outline
236 #define Raster_Err_Unsupported Raster_Err_Cannot_Render_Glyph
239 #endif /* !_STANDALONE_ */
243 #define FT_MEM_SET( d, s, c ) ft_memset( d, s, c )
247 #define FT_MEM_ZERO( dest, count ) FT_MEM_SET( dest, 0, count )
250 /* FMulDiv means `Fast MulDiv'; it is used in case where `b' is */
251 /* typically a small value and the result of a*b is known to fit into */
253 #define FMulDiv( a, b, c ) ( (a) * (b) / (c) )
255 /* On the other hand, SMulDiv means `Slow MulDiv', and is used typically */
256 /* for clipping computations. It simply uses the FT_MulDiv() function */
257 /* defined in `ftcalc.h'. */
258 #define SMulDiv FT_MulDiv
260 /* The rasterizer is a very general purpose component; please leave */
261 /* the following redefinitions there (you never know your target */
273 #define NULL (void*)0
285 #define MaxBezier 32 /* The maximum number of stacked Bezier curves. */
286 /* Setting this constant to more than 32 is a */
287 /* pure waste of space. */
289 #define Pixel_Bits 6 /* fractional bits of *input* coordinates */
292 /*************************************************************************/
293 /*************************************************************************/
295 /** SIMPLE TYPE DECLARATIONS **/
297 /*************************************************************************/
298 /*************************************************************************/
301 typedef unsigned int UInt
;
303 typedef unsigned short UShort
, *PUShort
;
304 typedef long Long
, *PLong
;
305 typedef unsigned long ULong
;
307 typedef unsigned char Byte
, *PByte
;
311 typedef union Alignment_
317 } Alignment
, *PAlignment
;
320 typedef struct TPoint_
328 /* values for the `flags' bit field */
330 #define Overshoot_Top 0x10
331 #define Overshoot_Bottom 0x20
334 /* States of each line, arc, and profile */
335 typedef enum TStates_
345 typedef struct TProfile_ TProfile
;
346 typedef TProfile
* PProfile
;
350 FT_F26Dot6 X
; /* current coordinate during sweep */
351 PProfile link
; /* link to next profile (various purposes) */
352 PLong offset
; /* start of profile's data in render pool */
353 unsigned flags
; /* Bit 0-2: drop-out mode */
354 /* Bit 3: profile orientation (up/down) */
355 /* Bit 4: is top profile? */
356 /* Bit 5: is bottom profile? */
357 long height
; /* profile's height in scanlines */
358 long start
; /* profile's starting scanline */
360 unsigned countL
; /* number of lines to step before this */
361 /* profile becomes drawable */
363 PProfile next
; /* next profile in same contour, used */
364 /* during drop-out control */
367 typedef PProfile TProfileList
;
368 typedef PProfile
* PProfileList
;
371 /* Simple record used to implement a stack of bands, required */
372 /* by the sub-banding mechanism */
373 typedef struct TBand_
375 Short y_min
; /* band's minimum */
376 Short y_max
; /* band's maximum */
381 #define AlignProfileSize \
382 ( ( sizeof ( TProfile ) + sizeof ( Alignment ) - 1 ) / sizeof ( long ) )
385 #ifdef FT_STATIC_RASTER
388 #define RAS_ARGS /* void */
389 #define RAS_ARG /* void */
391 #define RAS_VARS /* void */
392 #define RAS_VAR /* void */
394 #define FT_UNUSED_RASTER do { } while ( 0 )
397 #else /* !FT_STATIC_RASTER */
400 #define RAS_ARGS PWorker worker,
401 #define RAS_ARG PWorker worker
403 #define RAS_VARS worker,
404 #define RAS_VAR worker
406 #define FT_UNUSED_RASTER FT_UNUSED( worker )
409 #endif /* !FT_STATIC_RASTER */
412 typedef struct TWorker_ TWorker
, *PWorker
;
415 /* prototypes used for sweep function dispatch */
417 Function_Sweep_Init( RAS_ARGS Short
* min
,
421 Function_Sweep_Span( RAS_ARGS Short y
,
428 Function_Sweep_Step( RAS_ARG
);
431 /* NOTE: These operations are only valid on 2's complement processors */
433 #define FLOOR( x ) ( (x) & -ras.precision )
434 #define CEILING( x ) ( ( (x) + ras.precision - 1 ) & -ras.precision )
435 #define TRUNC( x ) ( (signed long)(x) >> ras.precision_bits )
436 #define FRAC( x ) ( (x) & ( ras.precision - 1 ) )
437 #define SCALED( x ) ( ( (x) << ras.scale_shift ) - ras.precision_half )
439 #define IS_BOTTOM_OVERSHOOT( x ) ( CEILING( x ) - x >= ras.precision_half )
440 #define IS_TOP_OVERSHOOT( x ) ( x - FLOOR( x ) >= ras.precision_half )
442 /* The most used variables are positioned at the top of the structure. */
443 /* Thus, their offset can be coded with less opcodes, resulting in a */
444 /* smaller executable. */
448 Int precision_bits
; /* precision related variables */
454 Int precision_jitter
;
456 Int scale_shift
; /* == precision_shift for bitmaps */
457 /* == precision_shift+1 for pixmaps */
459 PLong buff
; /* The profiles buffer */
460 PLong sizeBuff
; /* Render pool size */
461 PLong maxBuff
; /* Profiles buffer size */
462 PLong top
; /* Current cursor in buffer */
466 Int numTurns
; /* number of Y-turns in outline */
468 TPoint
* arc
; /* current Bezier arc pointer */
470 UShort bWidth
; /* target bitmap width */
471 PByte bTarget
; /* target bitmap buffer */
472 PByte gTarget
; /* target pixmap buffer */
477 UShort num_Profs
; /* current number of profiles */
479 Bool fresh
; /* signals a fresh new profile which */
480 /* `start' field must be completed */
481 Bool joint
; /* signals that the last arc ended */
482 /* exactly on a scanline. Allows */
483 /* removal of doublets */
484 PProfile cProfile
; /* current profile */
485 PProfile fProfile
; /* head of linked list of profiles */
486 PProfile gProfile
; /* contour's first profile in case */
489 TStates state
; /* rendering state */
491 FT_Bitmap target
; /* description of target bit/pixmap */
494 Long traceOfs
; /* current offset in target bitmap */
495 Long traceG
; /* current offset in target pixmap */
497 Short traceIncr
; /* sweep's increment in target bitmap */
499 Short gray_min_x
; /* current min x during gray rendering */
500 Short gray_max_x
; /* current max x during gray rendering */
502 /* dispatch variables */
504 Function_Sweep_Init
* Proc_Sweep_Init
;
505 Function_Sweep_Span
* Proc_Sweep_Span
;
506 Function_Sweep_Span
* Proc_Sweep_Drop
;
507 Function_Sweep_Step
* Proc_Sweep_Step
;
509 Byte dropOutControl
; /* current drop_out control method */
511 Bool second_pass
; /* indicates whether a horizontal pass */
512 /* should be performed to control */
513 /* drop-out accurately when calling */
514 /* Render_Glyph. Note that there is */
515 /* no horizontal pass during gray */
518 TPoint arcs
[3 * MaxBezier
+ 1]; /* The Bezier stack */
520 TBand band_stack
[16]; /* band stack used for sub-banding */
521 Int band_top
; /* band stack top */
523 #ifdef FT_RASTER_OPTION_ANTI_ALIASING
527 Byte gray_lines
[RASTER_GRAY_LINES
];
528 /* Intermediate table used to render the */
529 /* graylevels pixmaps. */
530 /* gray_lines is a buffer holding two */
531 /* monochrome scanlines */
533 Short gray_width
; /* width in bytes of one monochrome */
534 /* intermediate scanline of gray_lines. */
535 /* Each gray pixel takes 2 bits long there */
537 /* The gray_lines must hold 2 lines, thus with size */
538 /* in bytes of at least `gray_width*2'. */
540 #endif /* FT_RASTER_ANTI_ALIASING */
545 typedef struct TRaster_
556 #ifdef FT_STATIC_RASTER
558 static TWorker cur_ras
;
561 #else /* !FT_STATIC_RASTER */
563 #define ras (*worker)
565 #endif /* !FT_STATIC_RASTER */
568 #ifdef FT_RASTER_OPTION_ANTI_ALIASING
570 /* A lookup table used to quickly count set bits in four gray 2x2 */
571 /* cells. The values of the table have been produced with the */
572 /* following code: */
574 /* for ( i = 0; i < 256; i++ ) */
579 /* for ( c = 0; c < 4; c++ ) */
583 /* if ( j & 0x80 ) l++; */
584 /* if ( j & 0x40 ) l++; */
586 /* j = ( j << 2 ) & 0xFF; */
588 /* printf( "0x%04X", l ); */
592 static const short count_table
[256] =
594 0x0000, 0x0001, 0x0001, 0x0002, 0x0010, 0x0011, 0x0011, 0x0012,
595 0x0010, 0x0011, 0x0011, 0x0012, 0x0020, 0x0021, 0x0021, 0x0022,
596 0x0100, 0x0101, 0x0101, 0x0102, 0x0110, 0x0111, 0x0111, 0x0112,
597 0x0110, 0x0111, 0x0111, 0x0112, 0x0120, 0x0121, 0x0121, 0x0122,
598 0x0100, 0x0101, 0x0101, 0x0102, 0x0110, 0x0111, 0x0111, 0x0112,
599 0x0110, 0x0111, 0x0111, 0x0112, 0x0120, 0x0121, 0x0121, 0x0122,
600 0x0200, 0x0201, 0x0201, 0x0202, 0x0210, 0x0211, 0x0211, 0x0212,
601 0x0210, 0x0211, 0x0211, 0x0212, 0x0220, 0x0221, 0x0221, 0x0222,
602 0x1000, 0x1001, 0x1001, 0x1002, 0x1010, 0x1011, 0x1011, 0x1012,
603 0x1010, 0x1011, 0x1011, 0x1012, 0x1020, 0x1021, 0x1021, 0x1022,
604 0x1100, 0x1101, 0x1101, 0x1102, 0x1110, 0x1111, 0x1111, 0x1112,
605 0x1110, 0x1111, 0x1111, 0x1112, 0x1120, 0x1121, 0x1121, 0x1122,
606 0x1100, 0x1101, 0x1101, 0x1102, 0x1110, 0x1111, 0x1111, 0x1112,
607 0x1110, 0x1111, 0x1111, 0x1112, 0x1120, 0x1121, 0x1121, 0x1122,
608 0x1200, 0x1201, 0x1201, 0x1202, 0x1210, 0x1211, 0x1211, 0x1212,
609 0x1210, 0x1211, 0x1211, 0x1212, 0x1220, 0x1221, 0x1221, 0x1222,
610 0x1000, 0x1001, 0x1001, 0x1002, 0x1010, 0x1011, 0x1011, 0x1012,
611 0x1010, 0x1011, 0x1011, 0x1012, 0x1020, 0x1021, 0x1021, 0x1022,
612 0x1100, 0x1101, 0x1101, 0x1102, 0x1110, 0x1111, 0x1111, 0x1112,
613 0x1110, 0x1111, 0x1111, 0x1112, 0x1120, 0x1121, 0x1121, 0x1122,
614 0x1100, 0x1101, 0x1101, 0x1102, 0x1110, 0x1111, 0x1111, 0x1112,
615 0x1110, 0x1111, 0x1111, 0x1112, 0x1120, 0x1121, 0x1121, 0x1122,
616 0x1200, 0x1201, 0x1201, 0x1202, 0x1210, 0x1211, 0x1211, 0x1212,
617 0x1210, 0x1211, 0x1211, 0x1212, 0x1220, 0x1221, 0x1221, 0x1222,
618 0x2000, 0x2001, 0x2001, 0x2002, 0x2010, 0x2011, 0x2011, 0x2012,
619 0x2010, 0x2011, 0x2011, 0x2012, 0x2020, 0x2021, 0x2021, 0x2022,
620 0x2100, 0x2101, 0x2101, 0x2102, 0x2110, 0x2111, 0x2111, 0x2112,
621 0x2110, 0x2111, 0x2111, 0x2112, 0x2120, 0x2121, 0x2121, 0x2122,
622 0x2100, 0x2101, 0x2101, 0x2102, 0x2110, 0x2111, 0x2111, 0x2112,
623 0x2110, 0x2111, 0x2111, 0x2112, 0x2120, 0x2121, 0x2121, 0x2122,
624 0x2200, 0x2201, 0x2201, 0x2202, 0x2210, 0x2211, 0x2211, 0x2212,
625 0x2210, 0x2211, 0x2211, 0x2212, 0x2220, 0x2221, 0x2221, 0x2222
628 #endif /* FT_RASTER_OPTION_ANTI_ALIASING */
632 /*************************************************************************/
633 /*************************************************************************/
635 /** PROFILES COMPUTATION **/
637 /*************************************************************************/
638 /*************************************************************************/
641 /*************************************************************************/
644 /* Set_High_Precision */
647 /* Set precision variables according to param flag. */
650 /* High :: Set to True for high precision (typically for ppem < 18), */
651 /* false otherwise. */
654 Set_High_Precision( RAS_ARGS Int High
)
658 ras
.precision_bits
= 12;
659 ras
.precision_step
= 256;
660 ras
.precision_jitter
= 50;
664 ras
.precision_bits
= 6;
665 ras
.precision_step
= 32;
666 ras
.precision_jitter
= 2;
669 FT_TRACE6(( "Set_High_Precision(%s)\n", High
? "true" : "false" ));
671 ras
.precision
= 1 << ras
.precision_bits
;
672 ras
.precision_half
= ras
.precision
/ 2;
673 ras
.precision_shift
= ras
.precision_bits
- Pixel_Bits
;
674 ras
.precision_mask
= -ras
.precision
;
678 /*************************************************************************/
684 /* Create a new profile in the render pool. */
687 /* aState :: The state/orientation of the new profile. */
689 /* overshoot :: Whether the profile's unrounded start position */
690 /* differs by at least a half pixel. */
693 /* SUCCESS on success. FAILURE in case of overflow or of incoherent */
697 New_Profile( RAS_ARGS TStates aState
,
702 ras
.cProfile
= (PProfile
)ras
.top
;
703 ras
.fProfile
= ras
.cProfile
;
704 ras
.top
+= AlignProfileSize
;
707 if ( ras
.top
>= ras
.maxBuff
)
709 ras
.error
= Raster_Err_Overflow
;
713 ras
.cProfile
->flags
= 0;
714 ras
.cProfile
->start
= 0;
715 ras
.cProfile
->height
= 0;
716 ras
.cProfile
->offset
= ras
.top
;
717 ras
.cProfile
->link
= (PProfile
)0;
718 ras
.cProfile
->next
= (PProfile
)0;
719 ras
.cProfile
->flags
= ras
.dropOutControl
;
723 case Ascending_State
:
724 ras
.cProfile
->flags
|= Flow_Up
;
726 ras
.cProfile
->flags
|= Overshoot_Bottom
;
728 FT_TRACE6(( "New ascending profile = %lx\n", (long)ras
.cProfile
));
731 case Descending_State
:
733 ras
.cProfile
->flags
|= Overshoot_Top
;
734 FT_TRACE6(( "New descending profile = %lx\n", (long)ras
.cProfile
));
738 FT_ERROR(( "New_Profile: invalid profile direction\n" ));
739 ras
.error
= Raster_Err_Invalid
;
744 ras
.gProfile
= ras
.cProfile
;
754 /*************************************************************************/
760 /* Finalize the current profile. */
763 /* overshoot :: Whether the profile's unrounded end position differs */
764 /* by at least a half pixel. */
767 /* SUCCESS on success. FAILURE in case of overflow or incoherency. */
770 End_Profile( RAS_ARGS Bool overshoot
)
776 h
= (Long
)( ras
.top
- ras
.cProfile
->offset
);
780 FT_ERROR(( "End_Profile: negative height encountered\n" ));
781 ras
.error
= Raster_Err_Neg_Height
;
787 FT_TRACE6(( "Ending profile %lx, start = %ld, height = %ld\n",
788 (long)ras
.cProfile
, ras
.cProfile
->start
, h
));
790 ras
.cProfile
->height
= h
;
793 if ( ras
.cProfile
->flags
& Flow_Up
)
794 ras
.cProfile
->flags
|= Overshoot_Top
;
796 ras
.cProfile
->flags
|= Overshoot_Bottom
;
799 oldProfile
= ras
.cProfile
;
800 ras
.cProfile
= (PProfile
)ras
.top
;
802 ras
.top
+= AlignProfileSize
;
804 ras
.cProfile
->height
= 0;
805 ras
.cProfile
->offset
= ras
.top
;
807 oldProfile
->next
= ras
.cProfile
;
811 if ( ras
.top
>= ras
.maxBuff
)
813 FT_TRACE1(( "overflow in End_Profile\n" ));
814 ras
.error
= Raster_Err_Overflow
;
824 /*************************************************************************/
830 /* Insert a salient into the sorted list placed on top of the render */
834 /* New y scanline position. */
837 /* SUCCESS on success. FAILURE in case of overflow. */
840 Insert_Y_Turn( RAS_ARGS Int y
)
846 n
= ras
.numTurns
- 1;
847 y_turns
= ras
.sizeBuff
- ras
.numTurns
;
849 /* look for first y value that is <= */
850 while ( n
>= 0 && y
< y_turns
[n
] )
853 /* if it is <, simply insert it, ignore if == */
854 if ( n
>= 0 && y
> y_turns
[n
] )
857 y2
= (Int
)y_turns
[n
];
866 if ( ras
.maxBuff
<= ras
.top
)
868 ras
.error
= Raster_Err_Overflow
;
872 ras
.sizeBuff
[-ras
.numTurns
] = y
;
879 /*************************************************************************/
882 /* Finalize_Profile_Table */
885 /* Adjust all links in the profiles list. */
888 /* SUCCESS on success. FAILURE in case of overflow. */
891 Finalize_Profile_Table( RAS_ARG
)
906 p
->link
= (PProfile
)( p
->offset
+ p
->height
);
910 if ( p
->flags
& Flow_Up
)
912 bottom
= (Int
)p
->start
;
913 top
= (Int
)( p
->start
+ p
->height
- 1 );
917 bottom
= (Int
)( p
->start
- p
->height
+ 1 );
920 p
->offset
+= p
->height
- 1;
923 if ( Insert_Y_Turn( RAS_VARS bottom
) ||
924 Insert_Y_Turn( RAS_VARS top
+ 1 ) )
938 /*************************************************************************/
944 /* Subdivide one conic Bezier into two joint sub-arcs in the Bezier */
948 /* None (subdivided Bezier is taken from the top of the stack). */
951 /* This routine is the `beef' of this component. It is _the_ inner */
952 /* loop that should be optimized to hell to get the best performance. */
955 Split_Conic( TPoint
* base
)
960 base
[4].x
= base
[2].x
;
962 a
= base
[3].x
= ( base
[2].x
+ b
) / 2;
963 b
= base
[1].x
= ( base
[0].x
+ b
) / 2;
964 base
[2].x
= ( a
+ b
) / 2;
966 base
[4].y
= base
[2].y
;
968 a
= base
[3].y
= ( base
[2].y
+ b
) / 2;
969 b
= base
[1].y
= ( base
[0].y
+ b
) / 2;
970 base
[2].y
= ( a
+ b
) / 2;
972 /* hand optimized. gcc doesn't seem to be too good at common */
973 /* expression substitution and instruction scheduling ;-) */
977 /*************************************************************************/
983 /* Subdivide a third-order Bezier arc into two joint sub-arcs in the */
987 /* This routine is the `beef' of the component. It is one of _the_ */
988 /* inner loops that should be optimized like hell to get the best */
992 Split_Cubic( TPoint
* base
)
997 base
[6].x
= base
[3].x
;
1000 base
[1].x
= a
= ( base
[0].x
+ c
+ 1 ) >> 1;
1001 base
[5].x
= b
= ( base
[3].x
+ d
+ 1 ) >> 1;
1002 c
= ( c
+ d
+ 1 ) >> 1;
1003 base
[2].x
= a
= ( a
+ c
+ 1 ) >> 1;
1004 base
[4].x
= b
= ( b
+ c
+ 1 ) >> 1;
1005 base
[3].x
= ( a
+ b
+ 1 ) >> 1;
1007 base
[6].y
= base
[3].y
;
1010 base
[1].y
= a
= ( base
[0].y
+ c
+ 1 ) >> 1;
1011 base
[5].y
= b
= ( base
[3].y
+ d
+ 1 ) >> 1;
1012 c
= ( c
+ d
+ 1 ) >> 1;
1013 base
[2].y
= a
= ( a
+ c
+ 1 ) >> 1;
1014 base
[4].y
= b
= ( b
+ c
+ 1 ) >> 1;
1015 base
[3].y
= ( a
+ b
+ 1 ) >> 1;
1019 /*************************************************************************/
1025 /* Compute the x-coordinates of an ascending line segment and store */
1026 /* them in the render pool. */
1029 /* x1 :: The x-coordinate of the segment's start point. */
1031 /* y1 :: The y-coordinate of the segment's start point. */
1033 /* x2 :: The x-coordinate of the segment's end point. */
1035 /* y2 :: The y-coordinate of the segment's end point. */
1037 /* miny :: A lower vertical clipping bound value. */
1039 /* maxy :: An upper vertical clipping bound value. */
1042 /* SUCCESS on success, FAILURE on render pool overflow. */
1045 Line_Up( RAS_ARGS Long x1
,
1053 Int e1
, e2
, f1
, f2
, size
; /* XXX: is `Short' sufficient? */
1062 if ( Dy
<= 0 || y2
< miny
|| y1
> maxy
)
1067 /* Take care: miny-y1 can be a very large value; we use */
1068 /* a slow MulDiv function to avoid clipping bugs */
1069 x1
+= SMulDiv( Dx
, miny
- y1
, Dy
);
1070 e1
= (Int
)TRUNC( miny
);
1075 e1
= (Int
)TRUNC( y1
);
1076 f1
= (Int
)FRAC( y1
);
1081 /* x2 += FMulDiv( Dx, maxy - y2, Dy ); UNNECESSARY */
1082 e2
= (Int
)TRUNC( maxy
);
1087 e2
= (Int
)TRUNC( y2
);
1088 f2
= (Int
)FRAC( y2
);
1097 x1
+= FMulDiv( Dx
, ras
.precision
- f1
, Dy
);
1108 ras
.joint
= (char)( f2
== 0 );
1112 ras
.cProfile
->start
= e1
;
1117 if ( ras
.top
+ size
>= ras
.maxBuff
)
1119 ras
.error
= Raster_Err_Overflow
;
1125 Ix
= ( ras
.precision
* Dx
) / Dy
;
1126 Rx
= ( ras
.precision
* Dx
) % Dy
;
1131 Ix
= -( ( ras
.precision
* -Dx
) / Dy
);
1132 Rx
= ( ras
.precision
* -Dx
) % Dy
;
1158 /*************************************************************************/
1164 /* Compute the x-coordinates of an descending line segment and store */
1165 /* them in the render pool. */
1168 /* x1 :: The x-coordinate of the segment's start point. */
1170 /* y1 :: The y-coordinate of the segment's start point. */
1172 /* x2 :: The x-coordinate of the segment's end point. */
1174 /* y2 :: The y-coordinate of the segment's end point. */
1176 /* miny :: A lower vertical clipping bound value. */
1178 /* maxy :: An upper vertical clipping bound value. */
1181 /* SUCCESS on success, FAILURE on render pool overflow. */
1184 Line_Down( RAS_ARGS Long x1
,
1196 result
= Line_Up( RAS_VARS x1
, -y1
, x2
, -y2
, -maxy
, -miny
);
1198 if ( fresh
&& !ras
.fresh
)
1199 ras
.cProfile
->start
= -ras
.cProfile
->start
;
1205 /* A function type describing the functions used to split Bezier arcs */
1206 typedef void (*TSplitter
)( TPoint
* base
);
1209 /*************************************************************************/
1215 /* Compute the x-coordinates of an ascending Bezier arc and store */
1216 /* them in the render pool. */
1219 /* degree :: The degree of the Bezier arc (either 2 or 3). */
1221 /* splitter :: The function to split Bezier arcs. */
1223 /* miny :: A lower vertical clipping bound value. */
1225 /* maxy :: An upper vertical clipping bound value. */
1228 /* SUCCESS on success, FAILURE on render pool overflow. */
1231 Bezier_Up( RAS_ARGS Int degree
,
1236 Long y1
, y2
, e
, e2
, e0
;
1250 if ( y2
< miny
|| y1
> maxy
)
1265 f1
= (Short
)( FRAC( y1
) );
1276 *top
++ = arc
[degree
].x
;
1284 ras
.cProfile
->start
= TRUNC( e0
);
1291 if ( ( top
+ TRUNC( e2
- e
) + 1 ) >= ras
.maxBuff
)
1294 ras
.error
= Raster_Err_Overflow
;
1300 while ( arc
>= start_arc
&& e
<= e2
)
1309 if ( y2
- y1
>= ras
.precision_step
)
1316 *top
++ = arc
[degree
].x
+ FMulDiv( arc
[0].x
- arc
[degree
].x
,
1342 /*************************************************************************/
1348 /* Compute the x-coordinates of an descending Bezier arc and store */
1349 /* them in the render pool. */
1352 /* degree :: The degree of the Bezier arc (either 2 or 3). */
1354 /* splitter :: The function to split Bezier arcs. */
1356 /* miny :: A lower vertical clipping bound value. */
1358 /* maxy :: An upper vertical clipping bound value. */
1361 /* SUCCESS on success, FAILURE on render pool overflow. */
1364 Bezier_Down( RAS_ARGS Int degree
,
1369 TPoint
* arc
= ras
.arc
;
1373 arc
[0].y
= -arc
[0].y
;
1374 arc
[1].y
= -arc
[1].y
;
1375 arc
[2].y
= -arc
[2].y
;
1377 arc
[3].y
= -arc
[3].y
;
1381 result
= Bezier_Up( RAS_VARS degree
, splitter
, -maxy
, -miny
);
1383 if ( fresh
&& !ras
.fresh
)
1384 ras
.cProfile
->start
= -ras
.cProfile
->start
;
1386 arc
[0].y
= -arc
[0].y
;
1391 /*************************************************************************/
1397 /* Inject a new line segment and adjust the Profiles list. */
1400 /* x :: The x-coordinate of the segment's end point (its start point */
1401 /* is stored in `lastX'). */
1403 /* y :: The y-coordinate of the segment's end point (its start point */
1404 /* is stored in `lastY'). */
1407 /* SUCCESS on success, FAILURE on render pool overflow or incorrect */
1411 Line_To( RAS_ARGS Long x
,
1414 /* First, detect a change of direction */
1416 switch ( ras
.state
)
1419 if ( y
> ras
.lastY
)
1421 if ( New_Profile( RAS_VARS Ascending_State
,
1422 IS_BOTTOM_OVERSHOOT( ras
.lastY
) ) )
1427 if ( y
< ras
.lastY
)
1428 if ( New_Profile( RAS_VARS Descending_State
,
1429 IS_TOP_OVERSHOOT( ras
.lastY
) ) )
1434 case Ascending_State
:
1435 if ( y
< ras
.lastY
)
1437 if ( End_Profile( RAS_VARS
IS_TOP_OVERSHOOT( ras
.lastY
) ) ||
1438 New_Profile( RAS_VARS Descending_State
,
1439 IS_TOP_OVERSHOOT( ras
.lastY
) ) )
1444 case Descending_State
:
1445 if ( y
> ras
.lastY
)
1447 if ( End_Profile( RAS_VARS
IS_BOTTOM_OVERSHOOT( ras
.lastY
) ) ||
1448 New_Profile( RAS_VARS Ascending_State
,
1449 IS_BOTTOM_OVERSHOOT( ras
.lastY
) ) )
1458 /* Then compute the lines */
1460 switch ( ras
.state
)
1462 case Ascending_State
:
1463 if ( Line_Up( RAS_VARS ras
.lastX
, ras
.lastY
,
1464 x
, y
, ras
.minY
, ras
.maxY
) )
1468 case Descending_State
:
1469 if ( Line_Down( RAS_VARS ras
.lastX
, ras
.lastY
,
1470 x
, y
, ras
.minY
, ras
.maxY
) )
1485 /*************************************************************************/
1491 /* Inject a new conic arc and adjust the profile list. */
1494 /* cx :: The x-coordinate of the arc's new control point. */
1496 /* cy :: The y-coordinate of the arc's new control point. */
1498 /* x :: The x-coordinate of the arc's end point (its start point is */
1499 /* stored in `lastX'). */
1501 /* y :: The y-coordinate of the arc's end point (its start point is */
1502 /* stored in `lastY'). */
1505 /* SUCCESS on success, FAILURE on render pool overflow or incorrect */
1509 Conic_To( RAS_ARGS Long cx
,
1514 Long y1
, y2
, y3
, x3
, ymin
, ymax
;
1519 ras
.arc
[2].x
= ras
.lastX
;
1520 ras
.arc
[2].y
= ras
.lastY
;
1533 /* first, categorize the Bezier arc */
1546 if ( y2
< ymin
|| y2
> ymax
)
1548 /* this arc has no given direction, split it! */
1549 Split_Conic( ras
.arc
);
1552 else if ( y1
== y3
)
1554 /* this arc is flat, ignore it and pop it from the Bezier stack */
1559 /* the arc is y-monotonous, either ascending or descending */
1560 /* detect a change of direction */
1561 state_bez
= y1
< y3
? Ascending_State
: Descending_State
;
1562 if ( ras
.state
!= state_bez
)
1564 Bool o
= state_bez
== Ascending_State
? IS_BOTTOM_OVERSHOOT( y1
)
1565 : IS_TOP_OVERSHOOT( y1
);
1568 /* finalize current profile if any */
1569 if ( ras
.state
!= Unknown_State
&&
1570 End_Profile( RAS_VARS o
) )
1573 /* create a new profile */
1574 if ( New_Profile( RAS_VARS state_bez
, o
) )
1578 /* now call the appropriate routine */
1579 if ( state_bez
== Ascending_State
)
1581 if ( Bezier_Up( RAS_VARS
2, Split_Conic
, ras
.minY
, ras
.maxY
) )
1585 if ( Bezier_Down( RAS_VARS
2, Split_Conic
, ras
.minY
, ras
.maxY
) )
1589 } while ( ras
.arc
>= ras
.arcs
);
1601 /*************************************************************************/
1607 /* Inject a new cubic arc and adjust the profile list. */
1610 /* cx1 :: The x-coordinate of the arc's first new control point. */
1612 /* cy1 :: The y-coordinate of the arc's first new control point. */
1614 /* cx2 :: The x-coordinate of the arc's second new control point. */
1616 /* cy2 :: The y-coordinate of the arc's second new control point. */
1618 /* x :: The x-coordinate of the arc's end point (its start point is */
1619 /* stored in `lastX'). */
1621 /* y :: The y-coordinate of the arc's end point (its start point is */
1622 /* stored in `lastY'). */
1625 /* SUCCESS on success, FAILURE on render pool overflow or incorrect */
1629 Cubic_To( RAS_ARGS Long cx1
,
1636 Long y1
, y2
, y3
, y4
, x4
, ymin1
, ymax1
, ymin2
, ymax2
;
1641 ras
.arc
[3].x
= ras
.lastX
;
1642 ras
.arc
[3].y
= ras
.lastY
;
1658 /* first, categorize the Bezier arc */
1682 if ( ymin2
< ymin1
|| ymax2
> ymax1
)
1684 /* this arc has no given direction, split it! */
1685 Split_Cubic( ras
.arc
);
1688 else if ( y1
== y4
)
1690 /* this arc is flat, ignore it and pop it from the Bezier stack */
1695 state_bez
= ( y1
<= y4
) ? Ascending_State
: Descending_State
;
1697 /* detect a change of direction */
1698 if ( ras
.state
!= state_bez
)
1700 Bool o
= state_bez
== Ascending_State
? IS_BOTTOM_OVERSHOOT( y1
)
1701 : IS_TOP_OVERSHOOT( y1
);
1704 /* finalize current profile if any */
1705 if ( ras
.state
!= Unknown_State
&&
1706 End_Profile( RAS_VARS o
) )
1709 if ( New_Profile( RAS_VARS state_bez
, o
) )
1713 /* compute intersections */
1714 if ( state_bez
== Ascending_State
)
1716 if ( Bezier_Up( RAS_VARS
3, Split_Cubic
, ras
.minY
, ras
.maxY
) )
1720 if ( Bezier_Down( RAS_VARS
3, Split_Cubic
, ras
.minY
, ras
.maxY
) )
1724 } while ( ras
.arc
>= ras
.arcs
);
1737 #define SWAP_( x, y ) do \
1747 /*************************************************************************/
1750 /* Decompose_Curve */
1753 /* Scan the outline arrays in order to emit individual segments and */
1754 /* Beziers by calling Line_To() and Bezier_To(). It handles all */
1755 /* weird cases, like when the first point is off the curve, or when */
1756 /* there are simply no `on' points in the contour! */
1759 /* first :: The index of the first point in the contour. */
1761 /* last :: The index of the last point in the contour. */
1763 /* flipped :: If set, flip the direction of the curve. */
1766 /* SUCCESS on success, FAILURE on error. */
1769 Decompose_Curve( RAS_ARGS UShort first
,
1774 FT_Vector v_control
;
1782 unsigned tag
; /* current point's state */
1785 points
= ras
.outline
.points
;
1786 limit
= points
+ last
;
1788 v_start
.x
= SCALED( points
[first
].x
);
1789 v_start
.y
= SCALED( points
[first
].y
);
1790 v_last
.x
= SCALED( points
[last
].x
);
1791 v_last
.y
= SCALED( points
[last
].y
);
1795 SWAP_( v_start
.x
, v_start
.y
);
1796 SWAP_( v_last
.x
, v_last
.y
);
1799 v_control
= v_start
;
1801 point
= points
+ first
;
1802 tags
= ras
.outline
.tags
+ first
;
1804 /* set scan mode if necessary */
1805 if ( tags
[0] & FT_CURVE_TAG_HAS_SCANMODE
)
1806 ras
.dropOutControl
= (Byte
)tags
[0] >> 5;
1808 tag
= FT_CURVE_TAG( tags
[0] );
1810 /* A contour cannot start with a cubic control point! */
1811 if ( tag
== FT_CURVE_TAG_CUBIC
)
1812 goto Invalid_Outline
;
1814 /* check first point to determine origin */
1815 if ( tag
== FT_CURVE_TAG_CONIC
)
1817 /* first point is conic control. Yes, this happens. */
1818 if ( FT_CURVE_TAG( ras
.outline
.tags
[last
] ) == FT_CURVE_TAG_ON
)
1820 /* start at last point if it is on the curve */
1826 /* if both first and last points are conic, */
1827 /* start at their middle and record its position */
1829 v_start
.x
= ( v_start
.x
+ v_last
.x
) / 2;
1830 v_start
.y
= ( v_start
.y
+ v_last
.y
) / 2;
1838 ras
.lastX
= v_start
.x
;
1839 ras
.lastY
= v_start
.y
;
1841 while ( point
< limit
)
1846 tag
= FT_CURVE_TAG( tags
[0] );
1850 case FT_CURVE_TAG_ON
: /* emit a single line_to */
1855 x
= SCALED( point
->x
);
1856 y
= SCALED( point
->y
);
1860 if ( Line_To( RAS_VARS x
, y
) )
1865 case FT_CURVE_TAG_CONIC
: /* consume conic arcs */
1866 v_control
.x
= SCALED( point
[0].x
);
1867 v_control
.y
= SCALED( point
[0].y
);
1870 SWAP_( v_control
.x
, v_control
.y
);
1873 if ( point
< limit
)
1881 tag
= FT_CURVE_TAG( tags
[0] );
1883 x
= SCALED( point
[0].x
);
1884 y
= SCALED( point
[0].y
);
1889 if ( tag
== FT_CURVE_TAG_ON
)
1891 if ( Conic_To( RAS_VARS v_control
.x
, v_control
.y
, x
, y
) )
1896 if ( tag
!= FT_CURVE_TAG_CONIC
)
1897 goto Invalid_Outline
;
1899 v_middle
.x
= ( v_control
.x
+ x
) / 2;
1900 v_middle
.y
= ( v_control
.y
+ y
) / 2;
1902 if ( Conic_To( RAS_VARS v_control
.x
, v_control
.y
,
1903 v_middle
.x
, v_middle
.y
) )
1912 if ( Conic_To( RAS_VARS v_control
.x
, v_control
.y
,
1913 v_start
.x
, v_start
.y
) )
1918 default: /* FT_CURVE_TAG_CUBIC */
1920 Long x1
, y1
, x2
, y2
, x3
, y3
;
1923 if ( point
+ 1 > limit
||
1924 FT_CURVE_TAG( tags
[1] ) != FT_CURVE_TAG_CUBIC
)
1925 goto Invalid_Outline
;
1930 x1
= SCALED( point
[-2].x
);
1931 y1
= SCALED( point
[-2].y
);
1932 x2
= SCALED( point
[-1].x
);
1933 y2
= SCALED( point
[-1].y
);
1934 x3
= SCALED( point
[ 0].x
);
1935 y3
= SCALED( point
[ 0].y
);
1944 if ( point
<= limit
)
1946 if ( Cubic_To( RAS_VARS x1
, y1
, x2
, y2
, x3
, y3
) )
1951 if ( Cubic_To( RAS_VARS x1
, y1
, x2
, y2
, v_start
.x
, v_start
.y
) )
1958 /* close the contour with a line segment */
1959 if ( Line_To( RAS_VARS v_start
.x
, v_start
.y
) )
1966 ras
.error
= Raster_Err_Invalid
;
1973 /*************************************************************************/
1979 /* Convert a glyph into a series of segments and arcs and make a */
1980 /* profiles list with them. */
1983 /* flipped :: If set, flip the direction of curve. */
1986 /* SUCCESS on success, FAILURE if any error was encountered during */
1990 Convert_Glyph( RAS_ARGS
int flipped
)
1995 PProfile lastProfile
;
1998 ras
.fProfile
= NULL
;
2002 ras
.maxBuff
= ras
.sizeBuff
- AlignProfileSize
;
2006 ras
.cProfile
= (PProfile
)ras
.top
;
2007 ras
.cProfile
->offset
= ras
.top
;
2012 for ( i
= 0; i
< ras
.outline
.n_contours
; i
++ )
2017 ras
.state
= Unknown_State
;
2018 ras
.gProfile
= NULL
;
2020 if ( Decompose_Curve( RAS_VARS (unsigned short)start
,
2021 ras
.outline
.contours
[i
],
2025 start
= ras
.outline
.contours
[i
] + 1;
2027 /* we must now check whether the extreme arcs join or not */
2028 if ( FRAC( ras
.lastY
) == 0 &&
2029 ras
.lastY
>= ras
.minY
&&
2030 ras
.lastY
<= ras
.maxY
)
2031 if ( ras
.gProfile
&&
2032 ( ras
.gProfile
->flags
& Flow_Up
) ==
2033 ( ras
.cProfile
->flags
& Flow_Up
) )
2035 /* Note that ras.gProfile can be nil if the contour was too small */
2038 lastProfile
= ras
.cProfile
;
2039 if ( ras
.cProfile
->flags
& Flow_Up
)
2040 o
= IS_TOP_OVERSHOOT( ras
.lastY
);
2042 o
= IS_BOTTOM_OVERSHOOT( ras
.lastY
);
2043 if ( End_Profile( RAS_VARS o
) )
2046 /* close the `next profile in contour' linked list */
2048 lastProfile
->next
= ras
.gProfile
;
2051 if ( Finalize_Profile_Table( RAS_VAR
) )
2054 return (Bool
)( ras
.top
< ras
.maxBuff
? SUCCESS
: FAILURE
);
2058 /*************************************************************************/
2059 /*************************************************************************/
2061 /** SCAN-LINE SWEEPS AND DRAWING **/
2063 /*************************************************************************/
2064 /*************************************************************************/
2067 /*************************************************************************/
2071 /* Initializes an empty linked list. */
2074 Init_Linked( TProfileList
* l
)
2080 /*************************************************************************/
2084 /* Inserts a new profile in a linked list. */
2087 InsNew( PProfileList list
,
2090 PProfile
*old
, current
;
2100 if ( x
< current
->X
)
2102 old
= ¤t
->link
;
2106 profile
->link
= current
;
2111 /*************************************************************************/
2115 /* Removes an old profile from a linked list. */
2118 DelOld( PProfileList list
,
2121 PProfile
*old
, current
;
2129 if ( current
== profile
)
2131 *old
= current
->link
;
2135 old
= ¤t
->link
;
2139 /* we should never get there, unless the profile was not part of */
2144 /*************************************************************************/
2148 /* Sorts a trace list. In 95%, the list is already sorted. We need */
2149 /* an algorithm which is fast in this case. Bubble sort is enough */
2153 Sort( PProfileList list
)
2155 PProfile
*old
, current
, next
;
2158 /* First, set the new X coordinate of each profile */
2162 current
->X
= *current
->offset
;
2163 current
->offset
+= current
->flags
& Flow_Up
? 1 : -1;
2165 current
= current
->link
;
2168 /* Then sort them */
2175 next
= current
->link
;
2179 if ( current
->X
<= next
->X
)
2181 old
= ¤t
->link
;
2190 current
->link
= next
->link
;
2191 next
->link
= current
;
2197 next
= current
->link
;
2202 /*************************************************************************/
2204 /* Vertical Sweep Procedure Set */
2206 /* These four routines are used during the vertical black/white sweep */
2207 /* phase by the generic Draw_Sweep() function. */
2209 /*************************************************************************/
2212 Vertical_Sweep_Init( RAS_ARGS Short
* min
,
2215 Long pitch
= ras
.target
.pitch
;
2220 ras
.traceIncr
= (Short
)-pitch
;
2221 ras
.traceOfs
= -*min
* pitch
;
2223 ras
.traceOfs
+= ( ras
.target
.rows
- 1 ) * pitch
;
2231 Vertical_Sweep_Span( RAS_ARGS Short y
,
2247 /* Drop-out control */
2249 e1
= TRUNC( CEILING( x1
) );
2251 if ( x2
- x1
- ras
.precision
<= ras
.precision_jitter
)
2254 e2
= TRUNC( FLOOR( x2
) );
2256 if ( e2
>= 0 && e1
< ras
.bWidth
)
2260 if ( e2
>= ras
.bWidth
)
2261 e2
= ras
.bWidth
- 1;
2263 c1
= (Short
)( e1
>> 3 );
2264 c2
= (Short
)( e2
>> 3 );
2266 f1
= (Byte
) ( 0xFF >> ( e1
& 7 ) );
2267 f2
= (Byte
) ~( 0x7F >> ( e2
& 7 ) );
2269 if ( ras
.gray_min_x
> c1
)
2270 ras
.gray_min_x
= (short)c1
;
2271 if ( ras
.gray_max_x
< c2
)
2272 ras
.gray_max_x
= (short)c2
;
2274 target
= ras
.bTarget
+ ras
.traceOfs
+ c1
;
2281 /* memset() is slower than the following code on many platforms. */
2282 /* This is due to the fact that, in the vast majority of cases, */
2283 /* the span length in bytes is relatively small. */
2293 *target
|= ( f1
& f2
);
2299 Vertical_Sweep_Drop( RAS_ARGS Short y
,
2309 /* Drop-out control */
2315 /* +-------------+---------------------+------------+ */
2319 /* pixel contour contour pixel */
2322 /* drop-out mode scan conversion rules (as defined in OpenType) */
2323 /* --------------------------------------------------------------- */
2327 /* 3 same as mode 2 */
2330 /* 6, 7 same as mode 2 */
2338 Int dropOutControl
= left
->flags
& 7;
2341 if ( e1
== e2
+ ras
.precision
)
2343 switch ( dropOutControl
)
2345 case 0: /* simple drop-outs including stubs */
2349 case 4: /* smart drop-outs including stubs */
2350 pxl
= FLOOR( ( x1
+ x2
- 1 ) / 2 + ras
.precision_half
);
2353 case 1: /* simple drop-outs excluding stubs */
2354 case 5: /* smart drop-outs excluding stubs */
2356 /* Drop-out Control Rules #4 and #6 */
2358 /* The specification neither provides an exact definition */
2359 /* of a `stub' nor gives exact rules to exclude them. */
2361 /* Here the constraints we use to recognize a stub. */
2365 /* - P_Left and P_Right are in the same contour */
2366 /* - P_Right is the successor of P_Left in that contour */
2367 /* - y is the top of P_Left and P_Right */
2371 /* - P_Left and P_Right are in the same contour */
2372 /* - P_Left is the successor of P_Right in that contour */
2373 /* - y is the bottom of P_Left */
2375 /* We draw a stub if the following constraints are met. */
2377 /* - for an upper or lower stub, there is top or bottom */
2378 /* overshoot, respectively */
2379 /* - the covered interval is greater or equal to a half */
2382 /* upper stub test */
2383 if ( left
->next
== right
&&
2384 left
->height
<= 0 &&
2385 !( left
->flags
& Overshoot_Top
&&
2386 x2
- x1
>= ras
.precision_half
) )
2389 /* lower stub test */
2390 if ( right
->next
== left
&&
2392 !( left
->flags
& Overshoot_Bottom
&&
2393 x2
- x1
>= ras
.precision_half
) )
2396 if ( dropOutControl
== 1 )
2399 pxl
= FLOOR( ( x1
+ x2
- 1 ) / 2 + ras
.precision_half
);
2402 default: /* modes 2, 3, 6, 7 */
2403 return; /* no drop-out control */
2406 /* check that the other pixel isn't set */
2407 e1
= pxl
== e1
? e2
: e1
;
2411 c1
= (Short
)( e1
>> 3 );
2412 f1
= (Short
)( e1
& 7 );
2414 if ( e1
>= 0 && e1
< ras
.bWidth
&&
2415 ras
.bTarget
[ras
.traceOfs
+ c1
] & ( 0x80 >> f1
) )
2424 if ( e1
>= 0 && e1
< ras
.bWidth
)
2426 c1
= (Short
)( e1
>> 3 );
2427 f1
= (Short
)( e1
& 7 );
2429 if ( ras
.gray_min_x
> c1
)
2430 ras
.gray_min_x
= c1
;
2431 if ( ras
.gray_max_x
< c1
)
2432 ras
.gray_max_x
= c1
;
2434 ras
.bTarget
[ras
.traceOfs
+ c1
] |= (char)( 0x80 >> f1
);
2440 Vertical_Sweep_Step( RAS_ARG
)
2442 ras
.traceOfs
+= ras
.traceIncr
;
2446 /***********************************************************************/
2448 /* Horizontal Sweep Procedure Set */
2450 /* These four routines are used during the horizontal black/white */
2451 /* sweep phase by the generic Draw_Sweep() function. */
2453 /***********************************************************************/
2456 Horizontal_Sweep_Init( RAS_ARGS Short
* min
,
2459 /* nothing, really */
2467 Horizontal_Sweep_Span( RAS_ARGS Short y
,
2481 if ( x2
- x1
< ras
.precision
)
2488 bits
= ras
.bTarget
+ ( y
>> 3 );
2489 f1
= (Byte
)( 0x80 >> ( y
& 7 ) );
2493 if ( e1
>= 0 && e1
< ras
.target
.rows
)
2498 p
= bits
- e1
*ras
.target
.pitch
;
2499 if ( ras
.target
.pitch
> 0 )
2500 p
+= ( ras
.target
.rows
- 1 ) * ras
.target
.pitch
;
2510 Horizontal_Sweep_Drop( RAS_ARGS Short y
,
2521 /* During the horizontal sweep, we only take care of drop-outs */
2523 /* e1 + <-- pixel center */
2525 /* x1 ---+--> <-- contour */
2528 /* x2 <--+--- <-- contour */
2531 /* e2 + <-- pixel center */
2539 Int dropOutControl
= left
->flags
& 7;
2542 if ( e1
== e2
+ ras
.precision
)
2544 switch ( dropOutControl
)
2546 case 0: /* simple drop-outs including stubs */
2550 case 4: /* smart drop-outs including stubs */
2551 pxl
= FLOOR( ( x1
+ x2
- 1 ) / 2 + ras
.precision_half
);
2554 case 1: /* simple drop-outs excluding stubs */
2555 case 5: /* smart drop-outs excluding stubs */
2556 /* see Vertical_Sweep_Drop for details */
2558 /* rightmost stub test */
2559 if ( left
->next
== right
&&
2560 left
->height
<= 0 &&
2561 !( left
->flags
& Overshoot_Top
&&
2562 x2
- x1
>= ras
.precision_half
) )
2565 /* leftmost stub test */
2566 if ( right
->next
== left
&&
2568 !( left
->flags
& Overshoot_Bottom
&&
2569 x2
- x1
>= ras
.precision_half
) )
2572 if ( dropOutControl
== 1 )
2575 pxl
= FLOOR( ( x1
+ x2
- 1 ) / 2 + ras
.precision_half
);
2578 default: /* modes 2, 3, 6, 7 */
2579 return; /* no drop-out control */
2582 /* check that the other pixel isn't set */
2583 e1
= pxl
== e1
? e2
: e1
;
2587 bits
= ras
.bTarget
+ ( y
>> 3 );
2588 f1
= (Byte
)( 0x80 >> ( y
& 7 ) );
2590 bits
-= e1
* ras
.target
.pitch
;
2591 if ( ras
.target
.pitch
> 0 )
2592 bits
+= ( ras
.target
.rows
- 1 ) * ras
.target
.pitch
;
2595 e1
< ras
.target
.rows
&&
2603 bits
= ras
.bTarget
+ ( y
>> 3 );
2604 f1
= (Byte
)( 0x80 >> ( y
& 7 ) );
2608 if ( e1
>= 0 && e1
< ras
.target
.rows
)
2610 bits
-= e1
* ras
.target
.pitch
;
2611 if ( ras
.target
.pitch
> 0 )
2612 bits
+= ( ras
.target
.rows
- 1 ) * ras
.target
.pitch
;
2620 Horizontal_Sweep_Step( RAS_ARG
)
2622 /* Nothing, really */
2627 #ifdef FT_RASTER_OPTION_ANTI_ALIASING
2630 /*************************************************************************/
2632 /* Vertical Gray Sweep Procedure Set */
2634 /* These two routines are used during the vertical gray-levels sweep */
2635 /* phase by the generic Draw_Sweep() function. */
2639 /* - The target pixmap's width *must* be a multiple of 4. */
2641 /* - You have to use the function Vertical_Sweep_Span() for the gray */
2644 /*************************************************************************/
2647 Vertical_Gray_Sweep_Init( RAS_ARGS Short
* min
,
2650 Long pitch
, byte_len
;
2654 *max
= ( *max
+ 3 ) & -2;
2657 pitch
= ras
.target
.pitch
;
2659 ras
.traceIncr
= (Short
)byte_len
;
2660 ras
.traceG
= ( *min
/ 2 ) * byte_len
;
2664 ras
.traceG
+= ( ras
.target
.rows
- 1 ) * pitch
;
2665 byte_len
= -byte_len
;
2668 ras
.gray_min_x
= (Short
)byte_len
;
2669 ras
.gray_max_x
= -(Short
)byte_len
;
2674 Vertical_Gray_Sweep_Step( RAS_ARG
)
2677 PByte pix
, bit
, bit2
;
2678 short* count
= (short*)count_table
;
2682 ras
.traceOfs
+= ras
.gray_width
;
2684 if ( ras
.traceOfs
> ras
.gray_width
)
2686 pix
= ras
.gTarget
+ ras
.traceG
+ ras
.gray_min_x
* 4;
2689 if ( ras
.gray_max_x
>= 0 )
2691 Long last_pixel
= ras
.target
.width
- 1;
2692 Int last_cell
= last_pixel
>> 2;
2693 Int last_bit
= last_pixel
& 3;
2697 if ( ras
.gray_max_x
>= last_cell
&& last_bit
!= 3 )
2699 ras
.gray_max_x
= last_cell
- 1;
2703 if ( ras
.gray_min_x
< 0 )
2706 bit
= ras
.bTarget
+ ras
.gray_min_x
;
2707 bit2
= bit
+ ras
.gray_width
;
2709 c1
= ras
.gray_max_x
- ras
.gray_min_x
;
2713 c2
= count
[*bit
] + count
[*bit2
];
2717 pix
[0] = grays
[(c2
>> 12) & 0x000F];
2718 pix
[1] = grays
[(c2
>> 8 ) & 0x000F];
2719 pix
[2] = grays
[(c2
>> 4 ) & 0x000F];
2720 pix
[3] = grays
[ c2
& 0x000F];
2734 c2
= count
[*bit
] + count
[*bit2
];
2740 pix
[2] = grays
[(c2
>> 4 ) & 0x000F];
2742 pix
[1] = grays
[(c2
>> 8 ) & 0x000F];
2744 pix
[0] = grays
[(c2
>> 12) & 0x000F];
2754 ras
.traceG
+= ras
.traceIncr
;
2756 ras
.gray_min_x
= 32000;
2757 ras
.gray_max_x
= -32000;
2763 Horizontal_Gray_Sweep_Span( RAS_ARGS Short y
,
2769 /* nothing, really */
2780 Horizontal_Gray_Sweep_Drop( RAS_ARGS Short y
,
2791 /* During the horizontal sweep, we only take care of drop-outs */
2798 Int dropOutControl
= left
->flags
& 7;
2801 if ( e1
== e2
+ ras
.precision
)
2803 switch ( dropOutControl
)
2805 case 0: /* simple drop-outs including stubs */
2809 case 4: /* smart drop-outs including stubs */
2810 e1
= FLOOR( ( x1
+ x2
- 1 ) / 2 + ras
.precision_half
);
2813 case 1: /* simple drop-outs excluding stubs */
2814 case 5: /* smart drop-outs excluding stubs */
2815 /* see Vertical_Sweep_Drop for details */
2817 /* rightmost stub test */
2818 if ( left
->next
== right
&& left
->height
<= 0 )
2821 /* leftmost stub test */
2822 if ( right
->next
== left
&& left
->start
== y
)
2825 if ( dropOutControl
== 1 )
2828 e1
= FLOOR( ( x1
+ x2
- 1 ) / 2 + ras
.precision_half
);
2832 default: /* modes 2, 3, 6, 7 */
2833 return; /* no drop-out control */
2842 if ( x2
- x1
>= ras
.precision_half
)
2843 color
= ras
.grays
[2];
2845 color
= ras
.grays
[1];
2847 e1
= TRUNC( e1
) / 2;
2848 if ( e1
< ras
.target
.rows
)
2850 pixel
= ras
.gTarget
- e1
* ras
.target
.pitch
+ y
/ 2;
2851 if ( ras
.target
.pitch
> 0 )
2852 pixel
+= ( ras
.target
.rows
- 1 ) * ras
.target
.pitch
;
2854 if ( pixel
[0] == ras
.grays
[0] )
2861 #endif /* FT_RASTER_OPTION_ANTI_ALIASING */
2864 /*************************************************************************/
2866 /* Generic Sweep Drawing routine */
2868 /*************************************************************************/
2871 Draw_Sweep( RAS_ARG
)
2873 Short y
, y_change
, y_height
;
2875 PProfile P
, Q
, P_Left
, P_Right
;
2877 Short min_Y
, max_Y
, top
, bottom
, dropouts
;
2879 Long x1
, x2
, xs
, e1
, e2
;
2881 TProfileList waiting
;
2882 TProfileList draw_left
, draw_right
;
2885 /* initialize empty linked lists */
2887 Init_Linked( &waiting
);
2889 Init_Linked( &draw_left
);
2890 Init_Linked( &draw_right
);
2892 /* first, compute min and max Y */
2895 max_Y
= (Short
)TRUNC( ras
.minY
);
2896 min_Y
= (Short
)TRUNC( ras
.maxY
);
2902 bottom
= (Short
)P
->start
;
2903 top
= (Short
)( P
->start
+ P
->height
- 1 );
2905 if ( min_Y
> bottom
)
2911 InsNew( &waiting
, P
);
2916 /* check the Y-turns */
2917 if ( ras
.numTurns
== 0 )
2919 ras
.error
= Raster_Err_Invalid
;
2923 /* now initialize the sweep */
2925 ras
.Proc_Sweep_Init( RAS_VARS
&min_Y
, &max_Y
);
2927 /* then compute the distance of each profile from min_Y */
2933 P
->countL
= (UShort
)( P
->start
- min_Y
);
2942 if ( ras
.numTurns
> 0 &&
2943 ras
.sizeBuff
[-ras
.numTurns
] == min_Y
)
2946 while ( ras
.numTurns
> 0 )
2948 /* check waiting list for new activations */
2955 P
->countL
-= y_height
;
2956 if ( P
->countL
== 0 )
2958 DelOld( &waiting
, P
);
2960 if ( P
->flags
& Flow_Up
)
2961 InsNew( &draw_left
, P
);
2963 InsNew( &draw_right
, P
);
2969 /* sort the drawing lists */
2972 Sort( &draw_right
);
2974 y_change
= (Short
)ras
.sizeBuff
[-ras
.numTurns
--];
2975 y_height
= (Short
)( y_change
- y
);
2977 while ( y
< y_change
)
2984 P_Right
= draw_right
;
3001 if ( x2
- x1
<= ras
.precision
&&
3002 e1
!= x1
&& e2
!= x2
)
3004 if ( e1
> e2
|| e2
== e1
+ ras
.precision
)
3006 Int dropOutControl
= P_Left
->flags
& 7;
3009 if ( dropOutControl
!= 2 )
3011 /* a drop-out was detected */
3016 /* mark profile for drop-out processing */
3025 ras
.Proc_Sweep_Span( RAS_VARS y
, x1
, x2
, P_Left
, P_Right
);
3029 P_Left
= P_Left
->link
;
3030 P_Right
= P_Right
->link
;
3033 /* handle drop-outs _after_ the span drawing -- */
3034 /* drop-out processing has been moved out of the loop */
3035 /* for performance tuning */
3041 ras
.Proc_Sweep_Step( RAS_VAR
);
3048 Sort( &draw_right
);
3052 /* now finalize the profiles that need it */
3058 if ( P
->height
== 0 )
3059 DelOld( &draw_left
, P
);
3067 if ( P
->height
== 0 )
3068 DelOld( &draw_right
, P
);
3073 /* for gray-scaling, flush the bitmap scanline cache */
3074 while ( y
<= max_Y
)
3076 ras
.Proc_Sweep_Step( RAS_VAR
);
3085 P_Right
= draw_right
;
3089 if ( P_Left
->countL
)
3093 dropouts
--; /* -- this is useful when debugging only */
3095 ras
.Proc_Sweep_Drop( RAS_VARS y
,
3102 P_Left
= P_Left
->link
;
3103 P_Right
= P_Right
->link
;
3110 /*************************************************************************/
3113 /* Render_Single_Pass */
3116 /* Perform one sweep with sub-banding. */
3119 /* flipped :: If set, flip the direction of the outline. */
3122 /* Renderer error code. */
3125 Render_Single_Pass( RAS_ARGS Bool flipped
)
3130 while ( ras
.band_top
>= 0 )
3132 ras
.maxY
= (Long
)ras
.band_stack
[ras
.band_top
].y_max
* ras
.precision
;
3133 ras
.minY
= (Long
)ras
.band_stack
[ras
.band_top
].y_min
* ras
.precision
;
3137 ras
.error
= Raster_Err_None
;
3139 if ( Convert_Glyph( RAS_VARS flipped
) )
3141 if ( ras
.error
!= Raster_Err_Overflow
)
3144 ras
.error
= Raster_Err_None
;
3149 ClearBand( RAS_VARS
TRUNC( ras
.minY
), TRUNC( ras
.maxY
) );
3152 i
= ras
.band_stack
[ras
.band_top
].y_min
;
3153 j
= ras
.band_stack
[ras
.band_top
].y_max
;
3155 k
= (Short
)( ( i
+ j
) / 2 );
3157 if ( ras
.band_top
>= 7 || k
< i
)
3160 ras
.error
= Raster_Err_Invalid
;
3165 ras
.band_stack
[ras
.band_top
+ 1].y_min
= k
;
3166 ras
.band_stack
[ras
.band_top
+ 1].y_max
= j
;
3168 ras
.band_stack
[ras
.band_top
].y_max
= (Short
)( k
- 1 );
3175 if ( Draw_Sweep( RAS_VAR
) )
3185 /*************************************************************************/
3191 /* Render a glyph in a bitmap. Sub-banding if needed. */
3194 /* FreeType error code. 0 means success. */
3196 FT_LOCAL_DEF( FT_Error
)
3197 Render_Glyph( RAS_ARG
)
3202 Set_High_Precision( RAS_VARS ras
.outline
.flags
&
3203 FT_OUTLINE_HIGH_PRECISION
);
3204 ras
.scale_shift
= ras
.precision_shift
;
3206 if ( ras
.outline
.flags
& FT_OUTLINE_IGNORE_DROPOUTS
)
3207 ras
.dropOutControl
= 2;
3210 if ( ras
.outline
.flags
& FT_OUTLINE_SMART_DROPOUTS
)
3211 ras
.dropOutControl
= 4;
3213 ras
.dropOutControl
= 0;
3215 if ( !( ras
.outline
.flags
& FT_OUTLINE_INCLUDE_STUBS
) )
3216 ras
.dropOutControl
+= 1;
3219 ras
.second_pass
= (FT_Byte
)( !( ras
.outline
.flags
&
3220 FT_OUTLINE_SINGLE_PASS
) );
3222 /* Vertical Sweep */
3223 ras
.Proc_Sweep_Init
= Vertical_Sweep_Init
;
3224 ras
.Proc_Sweep_Span
= Vertical_Sweep_Span
;
3225 ras
.Proc_Sweep_Drop
= Vertical_Sweep_Drop
;
3226 ras
.Proc_Sweep_Step
= Vertical_Sweep_Step
;
3229 ras
.band_stack
[0].y_min
= 0;
3230 ras
.band_stack
[0].y_max
= (short)( ras
.target
.rows
- 1 );
3232 ras
.bWidth
= (unsigned short)ras
.target
.width
;
3233 ras
.bTarget
= (Byte
*)ras
.target
.buffer
;
3235 if ( ( error
= Render_Single_Pass( RAS_VARS
0 ) ) != 0 )
3238 /* Horizontal Sweep */
3239 if ( ras
.second_pass
&& ras
.dropOutControl
!= 2 )
3241 ras
.Proc_Sweep_Init
= Horizontal_Sweep_Init
;
3242 ras
.Proc_Sweep_Span
= Horizontal_Sweep_Span
;
3243 ras
.Proc_Sweep_Drop
= Horizontal_Sweep_Drop
;
3244 ras
.Proc_Sweep_Step
= Horizontal_Sweep_Step
;
3247 ras
.band_stack
[0].y_min
= 0;
3248 ras
.band_stack
[0].y_max
= (short)( ras
.target
.width
- 1 );
3250 if ( ( error
= Render_Single_Pass( RAS_VARS
1 ) ) != 0 )
3254 return Raster_Err_None
;
3258 #ifdef FT_RASTER_OPTION_ANTI_ALIASING
3260 /*************************************************************************/
3263 /* Render_Gray_Glyph */
3266 /* Render a glyph with grayscaling. Sub-banding if needed. */
3269 /* FreeType error code. 0 means success. */
3271 FT_LOCAL_DEF( FT_Error
)
3272 Render_Gray_Glyph( RAS_ARG
)
3278 Set_High_Precision( RAS_VARS ras
.outline
.flags
&
3279 FT_OUTLINE_HIGH_PRECISION
);
3280 ras
.scale_shift
= ras
.precision_shift
+ 1;
3282 if ( ras
.outline
.flags
& FT_OUTLINE_IGNORE_DROPOUTS
)
3283 ras
.dropOutControl
= 2;
3286 if ( ras
.outline
.flags
& FT_OUTLINE_SMART_DROPOUTS
)
3287 ras
.dropOutControl
= 4;
3289 ras
.dropOutControl
= 0;
3291 if ( !( ras
.outline
.flags
& FT_OUTLINE_INCLUDE_STUBS
) )
3292 ras
.dropOutControl
+= 1;
3295 ras
.second_pass
= !( ras
.outline
.flags
& FT_OUTLINE_SINGLE_PASS
);
3297 /* Vertical Sweep */
3300 ras
.band_stack
[0].y_min
= 0;
3301 ras
.band_stack
[0].y_max
= 2 * ras
.target
.rows
- 1;
3303 ras
.bWidth
= ras
.gray_width
;
3304 pixel_width
= 2 * ( ( ras
.target
.width
+ 3 ) >> 2 );
3306 if ( ras
.bWidth
> pixel_width
)
3307 ras
.bWidth
= pixel_width
;
3309 ras
.bWidth
= ras
.bWidth
* 8;
3310 ras
.bTarget
= (Byte
*)ras
.gray_lines
;
3311 ras
.gTarget
= (Byte
*)ras
.target
.buffer
;
3313 ras
.Proc_Sweep_Init
= Vertical_Gray_Sweep_Init
;
3314 ras
.Proc_Sweep_Span
= Vertical_Sweep_Span
;
3315 ras
.Proc_Sweep_Drop
= Vertical_Sweep_Drop
;
3316 ras
.Proc_Sweep_Step
= Vertical_Gray_Sweep_Step
;
3318 error
= Render_Single_Pass( RAS_VARS
0 );
3322 /* Horizontal Sweep */
3323 if ( ras
.second_pass
&& ras
.dropOutControl
!= 2 )
3325 ras
.Proc_Sweep_Init
= Horizontal_Sweep_Init
;
3326 ras
.Proc_Sweep_Span
= Horizontal_Gray_Sweep_Span
;
3327 ras
.Proc_Sweep_Drop
= Horizontal_Gray_Sweep_Drop
;
3328 ras
.Proc_Sweep_Step
= Horizontal_Sweep_Step
;
3331 ras
.band_stack
[0].y_min
= 0;
3332 ras
.band_stack
[0].y_max
= ras
.target
.width
* 2 - 1;
3334 error
= Render_Single_Pass( RAS_VARS
1 );
3339 return Raster_Err_None
;
3342 #else /* !FT_RASTER_OPTION_ANTI_ALIASING */
3344 FT_LOCAL_DEF( FT_Error
)
3345 Render_Gray_Glyph( RAS_ARG
)
3349 return Raster_Err_Unsupported
;
3352 #endif /* !FT_RASTER_OPTION_ANTI_ALIASING */
3356 ft_black_init( PRaster raster
)
3358 #ifdef FT_RASTER_OPTION_ANTI_ALIASING
3362 /* set default 5-levels gray palette */
3363 for ( n
= 0; n
< 5; n
++ )
3364 raster
->grays
[n
] = n
* 255 / 4;
3366 raster
->gray_width
= RASTER_GRAY_LINES
/ 2;
3368 FT_UNUSED( raster
);
3373 /**** RASTER OBJECT CREATION: In standalone mode, we simply use *****/
3374 /**** a static object. *****/
3381 ft_black_new( void* memory
,
3382 FT_Raster
*araster
)
3384 static TRaster the_raster
;
3387 *araster
= (FT_Raster
)&the_raster
;
3388 FT_MEM_ZERO( &the_raster
, sizeof ( the_raster
) );
3389 ft_black_init( &the_raster
);
3396 ft_black_done( FT_Raster raster
)
3399 FT_UNUSED( raster
);
3403 #else /* _STANDALONE_ */
3407 ft_black_new( FT_Memory memory
,
3415 if ( !FT_NEW( raster
) )
3417 raster
->memory
= memory
;
3418 ft_black_init( raster
);
3428 ft_black_done( PRaster raster
)
3430 FT_Memory memory
= (FT_Memory
)raster
->memory
;
3435 #endif /* _STANDALONE_ */
3439 ft_black_reset( PRaster raster
,
3445 if ( pool_base
&& pool_size
>= (long)sizeof(TWorker
) + 2048 )
3447 PWorker worker
= (PWorker
)pool_base
;
3450 raster
->buffer
= pool_base
+ ( (sizeof ( *worker
) + 7 ) & ~7 );
3451 raster
->buffer_size
= ( ( pool_base
+ pool_size
) -
3452 (char*)raster
->buffer
) / sizeof ( Long
);
3453 raster
->worker
= worker
;
3457 raster
->buffer
= NULL
;
3458 raster
->buffer_size
= 0;
3459 raster
->worker
= NULL
;
3466 ft_black_set_mode( PRaster raster
,
3468 const char* palette
)
3470 #ifdef FT_RASTER_OPTION_ANTI_ALIASING
3472 if ( mode
== FT_MAKE_TAG( 'p', 'a', 'l', '5' ) )
3474 /* set 5-levels gray palette */
3475 raster
->grays
[0] = palette
[0];
3476 raster
->grays
[1] = palette
[1];
3477 raster
->grays
[2] = palette
[2];
3478 raster
->grays
[3] = palette
[3];
3479 raster
->grays
[4] = palette
[4];
3484 FT_UNUSED( raster
);
3486 FT_UNUSED( palette
);
3493 ft_black_render( PRaster raster
,
3494 const FT_Raster_Params
* params
)
3496 const FT_Outline
* outline
= (const FT_Outline
*)params
->source
;
3497 const FT_Bitmap
* target_map
= params
->target
;
3501 if ( !raster
|| !raster
->buffer
|| !raster
->buffer_size
)
3502 return Raster_Err_Not_Ini
;
3505 return Raster_Err_Invalid
;
3507 /* return immediately if the outline is empty */
3508 if ( outline
->n_points
== 0 || outline
->n_contours
<= 0 )
3509 return Raster_Err_None
;
3511 if ( !outline
->contours
|| !outline
->points
)
3512 return Raster_Err_Invalid
;
3514 if ( outline
->n_points
!=
3515 outline
->contours
[outline
->n_contours
- 1] + 1 )
3516 return Raster_Err_Invalid
;
3518 worker
= raster
->worker
;
3520 /* this version of the raster does not support direct rendering, sorry */
3521 if ( params
->flags
& FT_RASTER_FLAG_DIRECT
)
3522 return Raster_Err_Unsupported
;
3525 return Raster_Err_Invalid
;
3528 if ( !target_map
->width
|| !target_map
->rows
)
3529 return Raster_Err_None
;
3531 if ( !target_map
->buffer
)
3532 return Raster_Err_Invalid
;
3534 ras
.outline
= *outline
;
3535 ras
.target
= *target_map
;
3537 worker
->buff
= (PLong
) raster
->buffer
;
3538 worker
->sizeBuff
= worker
->buff
+
3539 raster
->buffer_size
/ sizeof ( Long
);
3540 #ifdef FT_RASTER_OPTION_ANTI_ALIASING
3541 worker
->grays
= raster
->grays
;
3542 worker
->gray_width
= raster
->gray_width
;
3544 FT_MEM_ZERO( worker
->gray_lines
, worker
->gray_width
* 2 );
3547 return ( params
->flags
& FT_RASTER_FLAG_AA
)
3548 ? Render_Gray_Glyph( RAS_VAR
)
3549 : Render_Glyph( RAS_VAR
);
3553 FT_DEFINE_RASTER_FUNCS( ft_standard_raster
,
3554 FT_GLYPH_FORMAT_OUTLINE
,
3555 (FT_Raster_New_Func
) ft_black_new
,
3556 (FT_Raster_Reset_Func
) ft_black_reset
,
3557 (FT_Raster_Set_Mode_Func
)ft_black_set_mode
,
3558 (FT_Raster_Render_Func
) ft_black_render
,
3559 (FT_Raster_Done_Func
) ft_black_done