OLD | NEW |
1 /***************************************************************************/ | 1 /***************************************************************************/ |
2 /* */ | 2 /* */ |
3 /* ftraster.c */ | 3 /* ftraster.c */ |
4 /* */ | 4 /* */ |
5 /* The FreeType glyph rasterizer (body). */ | 5 /* The FreeType glyph rasterizer (body). */ |
6 /* */ | 6 /* */ |
7 /* Copyright 1996-2001, 2002, 2003, 2005, 2007, 2008, 2009, 2010, 2011 by */ | 7 /* Copyright 1996-2003, 2005, 2007-2012 by */ |
8 /* David Turner, Robert Wilhelm, and Werner Lemberg. */ | 8 /* David Turner, Robert Wilhelm, and Werner Lemberg. */ |
9 /* */ | 9 /* */ |
10 /* This file is part of the FreeType project, and may only be used, */ | 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 */ | 11 /* modified, and distributed under the terms of the FreeType project */ |
12 /* license, LICENSE.TXT. By continuing to use, modify, or distribute */ | 12 /* license, LICENSE.TXT. By continuing to use, modify, or distribute */ |
13 /* this file you indicate that you have read the license and */ | 13 /* this file you indicate that you have read the license and */ |
14 /* understand and accept it fully. */ | 14 /* understand and accept it fully. */ |
15 /* */ | 15 /* */ |
16 /***************************************************************************/ | 16 /***************************************************************************/ |
17 | 17 |
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
362 PProfile next; /* next profile in same contour, used */ | 362 PProfile next; /* next profile in same contour, used */ |
363 /* during drop-out control */ | 363 /* during drop-out control */ |
364 }; | 364 }; |
365 | 365 |
366 typedef PProfile TProfileList; | 366 typedef PProfile TProfileList; |
367 typedef PProfile* PProfileList; | 367 typedef PProfile* PProfileList; |
368 | 368 |
369 | 369 |
370 /* Simple record used to implement a stack of bands, required */ | 370 /* Simple record used to implement a stack of bands, required */ |
371 /* by the sub-banding mechanism */ | 371 /* by the sub-banding mechanism */ |
372 typedef struct TBand_ | 372 typedef struct black_TBand_ |
373 { | 373 { |
374 Short y_min; /* band's minimum */ | 374 Short y_min; /* band's minimum */ |
375 Short y_max; /* band's maximum */ | 375 Short y_max; /* band's maximum */ |
376 | 376 |
377 } TBand; | 377 } black_TBand; |
378 | 378 |
379 | 379 |
380 #define AlignProfileSize \ | 380 #define AlignProfileSize \ |
381 ( ( sizeof ( TProfile ) + sizeof ( Alignment ) - 1 ) / sizeof ( long ) ) | 381 ( ( sizeof ( TProfile ) + sizeof ( Alignment ) - 1 ) / sizeof ( long ) ) |
382 | 382 |
383 | 383 |
| 384 #undef RAS_ARG |
| 385 #undef RAS_ARGS |
| 386 #undef RAS_VAR |
| 387 #undef RAS_VARS |
| 388 |
384 #ifdef FT_STATIC_RASTER | 389 #ifdef FT_STATIC_RASTER |
385 | 390 |
386 | 391 |
387 #define RAS_ARGS /* void */ | 392 #define RAS_ARGS /* void */ |
388 #define RAS_ARG /* void */ | 393 #define RAS_ARG /* void */ |
389 | 394 |
390 #define RAS_VARS /* void */ | 395 #define RAS_VARS /* void */ |
391 #define RAS_VAR /* void */ | 396 #define RAS_VAR /* void */ |
392 | 397 |
393 #define FT_UNUSED_RASTER do { } while ( 0 ) | 398 #define FT_UNUSED_RASTER do { } while ( 0 ) |
394 | 399 |
395 | 400 |
396 #else /* !FT_STATIC_RASTER */ | 401 #else /* !FT_STATIC_RASTER */ |
397 | 402 |
398 | 403 |
399 #define RAS_ARGS PWorker worker, | 404 #define RAS_ARGS black_PWorker worker, |
400 #define RAS_ARG PWorker worker | 405 #define RAS_ARG black_PWorker worker |
401 | 406 |
402 #define RAS_VARS worker, | 407 #define RAS_VARS worker, |
403 #define RAS_VAR worker | 408 #define RAS_VAR worker |
404 | 409 |
405 #define FT_UNUSED_RASTER FT_UNUSED( worker ) | 410 #define FT_UNUSED_RASTER FT_UNUSED( worker ) |
406 | 411 |
407 | 412 |
408 #endif /* !FT_STATIC_RASTER */ | 413 #endif /* !FT_STATIC_RASTER */ |
409 | 414 |
410 | 415 |
411 typedef struct TWorker_ TWorker, *PWorker; | 416 typedef struct black_TWorker_ black_TWorker, *black_PWorker; |
412 | 417 |
413 | 418 |
414 /* prototypes used for sweep function dispatch */ | 419 /* prototypes used for sweep function dispatch */ |
415 typedef void | 420 typedef void |
416 Function_Sweep_Init( RAS_ARGS Short* min, | 421 Function_Sweep_Init( RAS_ARGS Short* min, |
417 Short* max ); | 422 Short* max ); |
418 | 423 |
419 typedef void | 424 typedef void |
420 Function_Sweep_Span( RAS_ARGS Short y, | 425 Function_Sweep_Span( RAS_ARGS Short y, |
421 FT_F26Dot6 x1, | 426 FT_F26Dot6 x1, |
422 FT_F26Dot6 x2, | 427 FT_F26Dot6 x2, |
423 PProfile left, | 428 PProfile left, |
424 PProfile right ); | 429 PProfile right ); |
425 | 430 |
426 typedef void | 431 typedef void |
427 Function_Sweep_Step( RAS_ARG ); | 432 Function_Sweep_Step( RAS_ARG ); |
428 | 433 |
429 | 434 |
430 /* NOTE: These operations are only valid on 2's complement processors */ | 435 /* NOTE: These operations are only valid on 2's complement processors */ |
| 436 #undef FLOOR |
| 437 #undef CEILING |
| 438 #undef TRUNC |
| 439 #undef SCALED |
431 | 440 |
432 #define FLOOR( x ) ( (x) & -ras.precision ) | 441 #define FLOOR( x ) ( (x) & -ras.precision ) |
433 #define CEILING( x ) ( ( (x) + ras.precision - 1 ) & -ras.precision ) | 442 #define CEILING( x ) ( ( (x) + ras.precision - 1 ) & -ras.precision ) |
434 #define TRUNC( x ) ( (signed long)(x) >> ras.precision_bits ) | 443 #define TRUNC( x ) ( (signed long)(x) >> ras.precision_bits ) |
435 #define FRAC( x ) ( (x) & ( ras.precision - 1 ) ) | 444 #define FRAC( x ) ( (x) & ( ras.precision - 1 ) ) |
436 #define SCALED( x ) ( ( (x) << ras.scale_shift ) - ras.precision_half ) | 445 #define SCALED( x ) ( ( (x) << ras.scale_shift ) - ras.precision_half ) |
437 | 446 |
438 #define IS_BOTTOM_OVERSHOOT( x ) ( CEILING( x ) - x >= ras.precision_half ) | 447 #define IS_BOTTOM_OVERSHOOT( x ) ( CEILING( x ) - x >= ras.precision_half ) |
439 #define IS_TOP_OVERSHOOT( x ) ( x - FLOOR( x ) >= ras.precision_half ) | 448 #define IS_TOP_OVERSHOOT( x ) ( x - FLOOR( x ) >= ras.precision_half ) |
440 | 449 |
441 /* The most used variables are positioned at the top of the structure. */ | 450 /* The most used variables are positioned at the top of the structure. */ |
442 /* Thus, their offset can be coded with less opcodes, resulting in a */ | 451 /* Thus, their offset can be coded with less opcodes, resulting in a */ |
443 /* smaller executable. */ | 452 /* smaller executable. */ |
444 | 453 |
445 struct TWorker_ | 454 struct black_TWorker_ |
446 { | 455 { |
447 Int precision_bits; /* precision related variables */ | 456 Int precision_bits; /* precision related variables */ |
448 Int precision; | 457 Int precision; |
449 Int precision_half; | 458 Int precision_half; |
450 Int precision_shift; | 459 Int precision_shift; |
451 Int precision_step; | 460 Int precision_step; |
452 Int precision_jitter; | 461 Int precision_jitter; |
453 | 462 |
454 Int scale_shift; /* == precision_shift for bitmaps */ | 463 Int scale_shift; /* == precision_shift for bitmaps */ |
455 /* == precision_shift+1 for pixmaps */ | 464 /* == precision_shift+1 for pixmaps */ |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
508 | 517 |
509 Bool second_pass; /* indicates whether a horizontal pass */ | 518 Bool second_pass; /* indicates whether a horizontal pass */ |
510 /* should be performed to control */ | 519 /* should be performed to control */ |
511 /* drop-out accurately when calling */ | 520 /* drop-out accurately when calling */ |
512 /* Render_Glyph. Note that there is */ | 521 /* Render_Glyph. Note that there is */ |
513 /* no horizontal pass during gray */ | 522 /* no horizontal pass during gray */ |
514 /* rendering. */ | 523 /* rendering. */ |
515 | 524 |
516 TPoint arcs[3 * MaxBezier + 1]; /* The Bezier stack */ | 525 TPoint arcs[3 * MaxBezier + 1]; /* The Bezier stack */ |
517 | 526 |
518 TBand band_stack[16]; /* band stack used for sub-banding */ | 527 black_TBand band_stack[16]; /* band stack used for sub-banding */ |
519 Int band_top; /* band stack top */ | 528 Int band_top; /* band stack top */ |
520 | 529 |
521 #ifdef FT_RASTER_OPTION_ANTI_ALIASING | 530 #ifdef FT_RASTER_OPTION_ANTI_ALIASING |
522 | 531 |
523 Byte* grays; | 532 Byte* grays; |
524 | 533 |
525 Byte gray_lines[RASTER_GRAY_LINES]; | 534 Byte gray_lines[RASTER_GRAY_LINES]; |
526 /* Intermediate table used to render the */ | 535 /* Intermediate table used to render the */ |
527 /* graylevels pixmaps. */ | 536 /* graylevels pixmaps. */ |
528 /* gray_lines is a buffer holding two */ | 537 /* gray_lines is a buffer holding two */ |
529 /* monochrome scanlines */ | 538 /* monochrome scanlines */ |
530 | 539 |
531 Short gray_width; /* width in bytes of one monochrome */ | 540 Short gray_width; /* width in bytes of one monochrome */ |
532 /* intermediate scanline of gray_lines. */ | 541 /* intermediate scanline of gray_lines. */ |
533 /* Each gray pixel takes 2 bits long there */ | 542 /* Each gray pixel takes 2 bits long there */ |
534 | 543 |
535 /* The gray_lines must hold 2 lines, thus with size */ | 544 /* The gray_lines must hold 2 lines, thus with size */ |
536 /* in bytes of at least `gray_width*2'. */ | 545 /* in bytes of at least `gray_width*2'. */ |
537 | 546 |
538 #endif /* FT_RASTER_ANTI_ALIASING */ | 547 #endif /* FT_RASTER_ANTI_ALIASING */ |
539 | 548 |
540 }; | 549 }; |
541 | 550 |
542 | 551 |
543 typedef struct TRaster_ | 552 typedef struct black_TRaster_ |
544 { | 553 { |
545 char* buffer; | 554 char* buffer; |
546 long buffer_size; | 555 long buffer_size; |
547 void* memory; | 556 void* memory; |
548 PWorker worker; | 557 black_PWorker worker; |
549 Byte grays[5]; | 558 Byte grays[5]; |
550 Short gray_width; | 559 Short gray_width; |
551 | 560 |
552 } TRaster, *PRaster; | 561 } black_TRaster, *black_PRaster; |
553 | 562 |
554 #ifdef FT_STATIC_RASTER | 563 #ifdef FT_STATIC_RASTER |
555 | 564 |
556 static TWorker cur_ras; | 565 static black_TWorker cur_ras; |
557 #define ras cur_ras | 566 #define ras cur_ras |
558 | 567 |
559 #else /* !FT_STATIC_RASTER */ | 568 #else /* !FT_STATIC_RASTER */ |
560 | 569 |
561 #define ras (*worker) | 570 #define ras (*worker) |
562 | 571 |
563 #endif /* !FT_STATIC_RASTER */ | 572 #endif /* !FT_STATIC_RASTER */ |
564 | 573 |
565 | 574 |
566 #ifdef FT_RASTER_OPTION_ANTI_ALIASING | 575 #ifdef FT_RASTER_OPTION_ANTI_ALIASING |
(...skipping 2817 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3384 { | 3393 { |
3385 FT_UNUSED_RASTER; | 3394 FT_UNUSED_RASTER; |
3386 | 3395 |
3387 return Raster_Err_Unsupported; | 3396 return Raster_Err_Unsupported; |
3388 } | 3397 } |
3389 | 3398 |
3390 #endif /* !FT_RASTER_OPTION_ANTI_ALIASING */ | 3399 #endif /* !FT_RASTER_OPTION_ANTI_ALIASING */ |
3391 | 3400 |
3392 | 3401 |
3393 static void | 3402 static void |
3394 ft_black_init( PRaster raster ) | 3403 ft_black_init( black_PRaster raster ) |
3395 { | 3404 { |
3396 #ifdef FT_RASTER_OPTION_ANTI_ALIASING | 3405 #ifdef FT_RASTER_OPTION_ANTI_ALIASING |
3397 FT_UInt n; | 3406 FT_UInt n; |
3398 | 3407 |
3399 | 3408 |
3400 /* set default 5-levels gray palette */ | 3409 /* set default 5-levels gray palette */ |
3401 for ( n = 0; n < 5; n++ ) | 3410 for ( n = 0; n < 5; n++ ) |
3402 raster->grays[n] = n * 255 / 4; | 3411 raster->grays[n] = n * 255 / 4; |
3403 | 3412 |
3404 raster->gray_width = RASTER_GRAY_LINES / 2; | 3413 raster->gray_width = RASTER_GRAY_LINES / 2; |
3405 #else | 3414 #else |
3406 FT_UNUSED( raster ); | 3415 FT_UNUSED( raster ); |
3407 #endif | 3416 #endif |
3408 } | 3417 } |
3409 | 3418 |
3410 | 3419 |
3411 /**** RASTER OBJECT CREATION: In standalone mode, we simply use *****/ | 3420 /**** RASTER OBJECT CREATION: In standalone mode, we simply use *****/ |
3412 /**** a static object. *****/ | 3421 /**** a static object. *****/ |
3413 | 3422 |
3414 | 3423 |
3415 #ifdef _STANDALONE_ | 3424 #ifdef _STANDALONE_ |
3416 | 3425 |
3417 | 3426 |
3418 static int | 3427 static int |
3419 ft_black_new( void* memory, | 3428 ft_black_new( void* memory, |
3420 FT_Raster *araster ) | 3429 FT_Raster *araster ) |
3421 { | 3430 { |
3422 static TRaster the_raster; | 3431 static black_TRaster the_raster; |
3423 FT_UNUSED( memory ); | 3432 FT_UNUSED( memory ); |
3424 | 3433 |
3425 | 3434 |
3426 *araster = (FT_Raster)&the_raster; | 3435 *araster = (FT_Raster)&the_raster; |
3427 FT_MEM_ZERO( &the_raster, sizeof ( the_raster ) ); | 3436 FT_MEM_ZERO( &the_raster, sizeof ( the_raster ) ); |
3428 ft_black_init( &the_raster ); | 3437 ft_black_init( &the_raster ); |
3429 | 3438 |
3430 return 0; | 3439 return 0; |
3431 } | 3440 } |
3432 | 3441 |
3433 | 3442 |
3434 static void | 3443 static void |
3435 ft_black_done( FT_Raster raster ) | 3444 ft_black_done( FT_Raster raster ) |
3436 { | 3445 { |
3437 /* nothing */ | 3446 /* nothing */ |
3438 FT_UNUSED( raster ); | 3447 FT_UNUSED( raster ); |
3439 } | 3448 } |
3440 | 3449 |
3441 | 3450 |
3442 #else /* !_STANDALONE_ */ | 3451 #else /* !_STANDALONE_ */ |
3443 | 3452 |
3444 | 3453 |
3445 static int | 3454 static int |
3446 ft_black_new( FT_Memory memory, | 3455 ft_black_new( FT_Memory memory, |
3447 PRaster *araster ) | 3456 black_PRaster *araster ) |
3448 { | 3457 { |
3449 FT_Error error; | 3458 FT_Error error; |
3450 PRaster raster = NULL; | 3459 black_PRaster raster = NULL; |
3451 | 3460 |
3452 | 3461 |
3453 *araster = 0; | 3462 *araster = 0; |
3454 if ( !FT_NEW( raster ) ) | 3463 if ( !FT_NEW( raster ) ) |
3455 { | 3464 { |
3456 raster->memory = memory; | 3465 raster->memory = memory; |
3457 ft_black_init( raster ); | 3466 ft_black_init( raster ); |
3458 | 3467 |
3459 *araster = raster; | 3468 *araster = raster; |
3460 } | 3469 } |
3461 | 3470 |
3462 return error; | 3471 return error; |
3463 } | 3472 } |
3464 | 3473 |
3465 | 3474 |
3466 static void | 3475 static void |
3467 ft_black_done( PRaster raster ) | 3476 ft_black_done( black_PRaster raster ) |
3468 { | 3477 { |
3469 FT_Memory memory = (FT_Memory)raster->memory; | 3478 FT_Memory memory = (FT_Memory)raster->memory; |
| 3479 |
| 3480 |
3470 FT_FREE( raster ); | 3481 FT_FREE( raster ); |
3471 } | 3482 } |
3472 | 3483 |
3473 | 3484 |
3474 #endif /* !_STANDALONE_ */ | 3485 #endif /* !_STANDALONE_ */ |
3475 | 3486 |
3476 | 3487 |
3477 static void | 3488 static void |
3478 ft_black_reset( PRaster raster, | 3489 ft_black_reset( black_PRaster raster, |
3479 char* pool_base, | 3490 char* pool_base, |
3480 long pool_size ) | 3491 long pool_size ) |
3481 { | 3492 { |
3482 if ( raster ) | 3493 if ( raster ) |
3483 { | 3494 { |
3484 if ( pool_base && pool_size >= (long)sizeof(TWorker) + 2048 ) | 3495 if ( pool_base && pool_size >= (long)sizeof ( black_TWorker ) + 2048 ) |
3485 { | 3496 { |
3486 PWorker worker = (PWorker)pool_base; | 3497 black_PWorker worker = (black_PWorker)pool_base; |
3487 | 3498 |
3488 | 3499 |
3489 raster->buffer = pool_base + ( ( sizeof ( *worker ) + 7 ) & ~7 ); | 3500 raster->buffer = pool_base + ( ( sizeof ( *worker ) + 7 ) & ~7 ); |
3490 raster->buffer_size = pool_base + pool_size - (char*)raster->buffer; | 3501 raster->buffer_size = pool_base + pool_size - (char*)raster->buffer; |
3491 raster->worker = worker; | 3502 raster->worker = worker; |
3492 } | 3503 } |
3493 else | 3504 else |
3494 { | 3505 { |
3495 raster->buffer = NULL; | 3506 raster->buffer = NULL; |
3496 raster->buffer_size = 0; | 3507 raster->buffer_size = 0; |
3497 raster->worker = NULL; | 3508 raster->worker = NULL; |
3498 } | 3509 } |
3499 } | 3510 } |
3500 } | 3511 } |
3501 | 3512 |
3502 | 3513 |
3503 static void | 3514 static void |
3504 ft_black_set_mode( PRaster raster, | 3515 ft_black_set_mode( black_PRaster raster, |
3505 unsigned long mode, | 3516 unsigned long mode, |
3506 const char* palette ) | 3517 const char* palette ) |
3507 { | 3518 { |
3508 #ifdef FT_RASTER_OPTION_ANTI_ALIASING | 3519 #ifdef FT_RASTER_OPTION_ANTI_ALIASING |
3509 | 3520 |
3510 if ( mode == FT_MAKE_TAG( 'p', 'a', 'l', '5' ) ) | 3521 if ( mode == FT_MAKE_TAG( 'p', 'a', 'l', '5' ) ) |
3511 { | 3522 { |
3512 /* set 5-levels gray palette */ | 3523 /* set 5-levels gray palette */ |
3513 raster->grays[0] = palette[0]; | 3524 raster->grays[0] = palette[0]; |
3514 raster->grays[1] = palette[1]; | 3525 raster->grays[1] = palette[1]; |
3515 raster->grays[2] = palette[2]; | 3526 raster->grays[2] = palette[2]; |
3516 raster->grays[3] = palette[3]; | 3527 raster->grays[3] = palette[3]; |
3517 raster->grays[4] = palette[4]; | 3528 raster->grays[4] = palette[4]; |
3518 } | 3529 } |
3519 | 3530 |
3520 #else | 3531 #else |
3521 | 3532 |
3522 FT_UNUSED( raster ); | 3533 FT_UNUSED( raster ); |
3523 FT_UNUSED( mode ); | 3534 FT_UNUSED( mode ); |
3524 FT_UNUSED( palette ); | 3535 FT_UNUSED( palette ); |
3525 | 3536 |
3526 #endif | 3537 #endif |
3527 } | 3538 } |
3528 | 3539 |
3529 | 3540 |
3530 static int | 3541 static int |
3531 ft_black_render( PRaster raster, | 3542 ft_black_render( black_PRaster raster, |
3532 const FT_Raster_Params* params ) | 3543 const FT_Raster_Params* params ) |
3533 { | 3544 { |
3534 const FT_Outline* outline = (const FT_Outline*)params->source; | 3545 const FT_Outline* outline = (const FT_Outline*)params->source; |
3535 const FT_Bitmap* target_map = params->target; | 3546 const FT_Bitmap* target_map = params->target; |
3536 PWorker worker; | 3547 black_PWorker worker; |
3537 | 3548 |
3538 | 3549 |
3539 if ( !raster || !raster->buffer || !raster->buffer_size ) | 3550 if ( !raster || !raster->buffer || !raster->buffer_size ) |
3540 return Raster_Err_Not_Ini; | 3551 return Raster_Err_Not_Ini; |
3541 | 3552 |
3542 if ( !outline ) | 3553 if ( !outline ) |
3543 return Raster_Err_Invalid; | 3554 return Raster_Err_Invalid; |
3544 | 3555 |
3545 /* return immediately if the outline is empty */ | 3556 /* return immediately if the outline is empty */ |
3546 if ( outline->n_points == 0 || outline->n_contours <= 0 ) | 3557 if ( outline->n_points == 0 || outline->n_contours <= 0 ) |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3592 FT_GLYPH_FORMAT_OUTLINE, | 3603 FT_GLYPH_FORMAT_OUTLINE, |
3593 (FT_Raster_New_Func) ft_black_new, | 3604 (FT_Raster_New_Func) ft_black_new, |
3594 (FT_Raster_Reset_Func) ft_black_reset, | 3605 (FT_Raster_Reset_Func) ft_black_reset, |
3595 (FT_Raster_Set_Mode_Func)ft_black_set_mode, | 3606 (FT_Raster_Set_Mode_Func)ft_black_set_mode, |
3596 (FT_Raster_Render_Func) ft_black_render, | 3607 (FT_Raster_Render_Func) ft_black_render, |
3597 (FT_Raster_Done_Func) ft_black_done | 3608 (FT_Raster_Done_Func) ft_black_done |
3598 ) | 3609 ) |
3599 | 3610 |
3600 | 3611 |
3601 /* END */ | 3612 /* END */ |
OLD | NEW |