* src/smooth/ftgrays: "setjmp/longjmp" is now used for rollback (i.e. when memory pool overflow occurs), function names are now all prefixed with "gray_", and a new type (TArea) is defined to store area value in each cell (using "int" was too small on 16-bit systems)..
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956
diff --git a/ChangeLog b/ChangeLog
index 1e4ecaa..9b7748b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2001-10-07 David Turner <david@freetype.org>
+
+ * src/smooth/ftgrays: "setjmp/longjmp" is now used for rollback (i.e.
+ when memory pool overflow occurs), function names are now all prefixed
+ with "gray_", and a new type (TArea) is defined to store area value in
+ each cell (using "int" was too small on 16-bit systems)..
+
2001-09-20 Detlef Würkner <TetiSoft@apg.lahn.de>
* builds/amiga/*: Added port to Amiga with the SAS/C compiler.
diff --git a/src/smooth/ftgrays.c b/src/smooth/ftgrays.c
index 1997570..41dcb89 100644
--- a/src/smooth/ftgrays.c
+++ b/src/smooth/ftgrays.c
@@ -4,7 +4,7 @@
/* */
/* A new `perfect' anti-aliasing renderer (body). */
/* */
-/* Copyright 2000-2001 by */
+/* Copyright 2000 by */
/* David Turner, Robert Wilhelm, and Werner Lemberg. */
/* */
/* This file is part of the FreeType project, and may only be used, */
@@ -32,8 +32,8 @@
/* cc -c -D_STANDALONE_ ftgrays.c */
/* */
/* The renderer can be initialized with a call to */
- /* `ft_grays_raster.grays_raster_new'; an anti-aliased bitmap can be */
- /* generated with a call to `ft_grays_raster.grays_raster_render'. */
+ /* `ft_gray_raster.gray_raster_new'; an anti-aliased bitmap can be */
+ /* generated with a call to `ft_gray_raster.gray_raster_render'. */
/* */
/* See the comments and documentation in the file `ftimage.h' for */
/* more details on how the raster works. */
@@ -82,7 +82,7 @@
#include <string.h> /* for memcpy() */
-
+#include <setjmp.h>
/*************************************************************************/
/* */
@@ -94,6 +94,8 @@
#define FT_COMPONENT trace_aaraster
+#define ErrRaster_MemoryOverflow -4
+
#ifdef _STANDALONE_
@@ -199,9 +201,35 @@
/* */
/* TYPE DEFINITIONS */
/* */
+
+ /* don't change the following types to FT_Int or FT_Pos, since we might */
+ /* need to define them to "float" or "double" when experimenting with */
+ /* new algorithms.. */
+
typedef int TScan; /* integer scanline/pixel coordinate */
typedef long TPos; /* sub-pixel coordinate */
+ /* determine the type used to store cell areas. This normally takes at */
+ /* least PIXEL_BYTES*2 + 1, on 16-bit systems, we need to use 'longs' */
+ /* instead of 'ints'.. otherwise bad things happen.. */
+
+#if PIXEL_BITS <= 7
+
+ typedef int TArea;
+
+#else /* PIXEL_BITS >= 8 */
+
+ /* approximately determine the size of integers using an ANSI-C header */
+# include <limits.h>
+# if UINT_MAX == 0xFFFFU
+ typedef long TArea;
+# else
+ typedef int TArea;
+# endif
+
+#endif /* PIXEL_BITS >= 8 */
+
+
/* maximal number of gray spans in a call to the span callback */
#define FT_MAX_GRAY_SPANS 32
@@ -224,7 +252,7 @@
TScan x;
TScan y;
int cover;
- int area;
+ TArea area;
} TCell, *PCell;
@@ -240,7 +268,7 @@
TScan min_ex, max_ex;
TScan min_ey, max_ey;
- int area;
+ TArea area;
int cover;
int invalid;
@@ -264,12 +292,13 @@
void* render_span_data;
int span_y;
- int band_size;
- int band_shoot;
- int conic_level;
- int cubic_level;
+ int band_size;
+ int band_shoot;
+ int conic_level;
+ int cubic_level;
- void* memory;
+ void* memory;
+ jmp_buf jump_buffer;
} TRaster, *PRaster;
@@ -279,8 +308,8 @@
/* Initialize the cells table. */
/* */
static void
- init_cells( RAS_ARG_ void* buffer,
- long byte_size )
+ gray_init_cells( RAS_ARG_ void* buffer,
+ long byte_size )
{
ras.cells = (PCell)buffer;
ras.max_cells = byte_size / sizeof ( TCell );
@@ -296,10 +325,11 @@
/* Compute the outline bounding box. */
/* */
static void
- compute_cbox( RAS_ARG_ FT_Outline* outline )
+ gray_compute_cbox( RAS_ARG )
{
- FT_Vector* vec = outline->points;
- FT_Vector* limit = vec + outline->n_points;
+ FT_Outline* outline = &ras.outline;
+ FT_Vector* vec = outline->points;
+ FT_Vector* limit = vec + outline->n_points;
if ( outline->n_points <= 0 )
@@ -338,8 +368,8 @@
/* */
/* Record the current cell in the table. */
/* */
- static int
- record_cell( RAS_ARG )
+ static void
+ gray_record_cell( RAS_ARG )
{
PCell cell;
@@ -347,7 +377,7 @@
if ( !ras.invalid && ( ras.area | ras.cover ) )
{
if ( ras.num_cells >= ras.max_cells )
- return 1;
+ longjmp( ras.jump_buffer, 1 );
cell = ras.cells + ras.num_cells++;
cell->x = ras.ex - ras.min_ex;
@@ -355,8 +385,6 @@
cell->area = ras.area;
cell->cover = ras.cover;
}
-
- return 0;
}
@@ -364,9 +392,9 @@
/* */
/* Set the current cell to a new position. */
/* */
- static int
- set_cell( RAS_ARG_ TScan ex,
- TScan ey )
+ static void
+ gray_set_cell( RAS_ARG_ TScan ex,
+ TScan ey )
{
int invalid, record, clean;
@@ -402,8 +430,8 @@
/* record the previous cell if needed (i.e., if we changed the cell */
/* position, of changed the `invalid' flag) */
- if ( ( ras.invalid != invalid || record ) && record_cell( RAS_VAR ) )
- return 1;
+ if ( ras.invalid != invalid || record )
+ gray_record_cell( RAS_VAR );
if ( clean )
{
@@ -414,7 +442,6 @@
ras.invalid = invalid;
ras.ex = ex;
ras.ey = ey;
- return 0;
}
@@ -423,8 +450,8 @@
/* Start a new contour at a given cell. */
/* */
static void
- start_cell( RAS_ARG_ TScan ex,
- TScan ey )
+ gray_start_cell( RAS_ARG_ TScan ex,
+ TScan ey )
{
if ( ex < ras.min_ex )
ex = ras.min_ex - 1;
@@ -436,7 +463,7 @@
ras.last_ey = SUBPIXELS( ey );
ras.invalid = 0;
- (void)set_cell( RAS_VAR_ ex, ey );
+ gray_set_cell( RAS_VAR_ ex, ey );
}
@@ -444,12 +471,12 @@
/* */
/* Render a scanline as one or more cells. */
/* */
- static int
- render_scanline( RAS_ARG_ TScan ey,
- TPos x1,
- TScan y1,
- TPos x2,
- TScan y2 )
+ static void
+ gray_render_scanline( RAS_ARG_ TScan ey,
+ TPos x1,
+ TScan y1,
+ TPos x2,
+ TScan y2 )
{
TScan ex1, ex2, fx1, fx2, delta;
long p, first, dx;
@@ -465,16 +492,19 @@
/* trivial case. Happens often */
if ( y1 == y2 )
- return set_cell( RAS_VAR_ ex2, ey );
+ {
+ gray_set_cell( RAS_VAR_ ex2, ey );
+ return;
+ }
/* everything is located in a single cell. That is easy! */
/* */
if ( ex1 == ex2 )
{
delta = y2 - y1;
- ras.area += ( fx1 + fx2 ) * delta;
+ ras.area += (TArea)( fx1 + fx2 ) * delta;
ras.cover += delta;
- return 0;
+ return;
}
/* ok, we'll have to render a run of adjacent cells on the same */
@@ -500,12 +530,11 @@
mod += dx;
}
- ras.area += ( fx1 + first ) * delta;
+ ras.area += (TArea)( fx1 + first ) * delta;
ras.cover += delta;
ex1 += incr;
- if ( set_cell( RAS_VAR_ ex1, ey ) )
- goto Error;
+ gray_set_cell( RAS_VAR_ ex1, ey );
y1 += delta;
if ( ex1 != ex2 )
@@ -531,23 +560,17 @@
delta++;
}
- ras.area += ONE_PIXEL * delta;
+ ras.area += (TArea)ONE_PIXEL * delta;
ras.cover += delta;
y1 += delta;
ex1 += incr;
- if ( set_cell( RAS_VAR_ ex1, ey ) )
- goto Error;
+ gray_set_cell( RAS_VAR_ ex1, ey );
}
}
delta = y2 - y1;
- ras.area += ( fx2 + ONE_PIXEL - first ) * delta;
+ ras.area += (TArea)( fx2 + ONE_PIXEL - first ) * delta;
ras.cover += delta;
-
- return 0;
-
- Error:
- return 1;
}
@@ -555,9 +578,9 @@
/* */
/* Render a given line as a series of scanlines. */
/* */
- static int
- render_line( RAS_ARG_ TPos to_x,
- TPos to_y )
+ static void
+ gray_render_line( RAS_ARG_ TPos to_x,
+ TPos to_y )
{
TScan ey1, ey2, fy1, fy2;
TPos dx, dy, x, x2;
@@ -594,8 +617,7 @@
/* everything is on a single scanline */
if ( ey1 == ey2 )
{
- if ( render_scanline( RAS_VAR_ ey1, ras.x, fy1, to_x, fy2 ) )
- goto Error;
+ gray_render_scanline( RAS_VAR_ ey1, ras.x, fy1, to_x, fy2 );
goto End;
}
@@ -621,12 +643,10 @@
}
x = ras.x + delta;
- if ( render_scanline( RAS_VAR_ ey1, ras.x, fy1, x, first ) )
- goto Error;
+ gray_render_scanline( RAS_VAR_ ey1, ras.x, fy1, x, first );
ey1 += incr;
- if ( set_cell( RAS_VAR_ TRUNC( x ), ey1 ) )
- goto Error;
+ gray_set_cell( RAS_VAR_ TRUNC( x ), ey1 );
if ( ey1 != ey2 )
{
@@ -651,34 +671,25 @@
}
x2 = x + delta;
- if ( render_scanline( RAS_VAR_ ey1,
- x, ONE_PIXEL - first, x2, first ) )
- goto Error;
+ gray_render_scanline( RAS_VAR_ ey1, x, ONE_PIXEL - first, x2, first );
x = x2;
+
ey1 += incr;
- if ( set_cell( RAS_VAR_ TRUNC( x ), ey1 ) )
- goto Error;
+ gray_set_cell( RAS_VAR_ TRUNC( x ), ey1 );
}
}
- if ( render_scanline( RAS_VAR_ ey1,
- x, ONE_PIXEL - first, to_x, fy2 ) )
- goto Error;
+ gray_render_scanline( RAS_VAR_ ey1, x, ONE_PIXEL - first, to_x, fy2 );
End:
ras.x = to_x;
ras.y = to_y;
ras.last_ey = SUBPIXELS( ey2 );
-
- return 0;
-
- Error:
- return 1;
}
static void
- split_conic( FT_Vector* base )
+ gray_split_conic( FT_Vector* base )
{
TPos a, b;
@@ -697,9 +708,9 @@
}
- static int
- render_conic( RAS_ARG_ FT_Vector* control,
- FT_Vector* to )
+ static void
+ gray_render_conic( RAS_ARG_ FT_Vector* control,
+ FT_Vector* to )
{
TPos dx, dy;
int top, level;
@@ -728,7 +739,7 @@
if ( level <= 1 )
{
/* we compute the mid-point directly in order to avoid */
- /* calling split_conic() */
+ /* calling gray_split_conic() */
TPos to_x, to_y, mid_x, mid_y;
@@ -737,8 +748,9 @@
mid_x = ( ras.x + to_x + 2 * UPSCALE( control->x ) ) / 4;
mid_y = ( ras.y + to_y + 2 * UPSCALE( control->y ) ) / 4;
- return render_line( RAS_VAR_ mid_x, mid_y ) ||
- render_line( RAS_VAR_ to_x, to_y );
+ gray_render_line( RAS_VAR_ mid_x, mid_y );
+ gray_render_line( RAS_VAR_ to_x, to_y );
+ return;
}
arc = ras.bez_stack;
@@ -775,7 +787,7 @@
if ( TRUNC( min ) >= ras.max_ey || TRUNC( max ) < 0 )
goto Draw;
- split_conic( arc );
+ gray_split_conic( arc );
arc += 2;
top++;
levels[top] = levels[top - 1] = level - 1;
@@ -792,20 +804,19 @@
mid_x = ( ras.x + to_x + 2 * arc[1].x ) / 4;
mid_y = ( ras.y + to_y + 2 * arc[1].y ) / 4;
- if ( render_line( RAS_VAR_ mid_x, mid_y ) ||
- render_line( RAS_VAR_ to_x, to_y ) )
- return 1;
+ gray_render_line( RAS_VAR_ mid_x, mid_y );
+ gray_render_line( RAS_VAR_ to_x, to_y );
top--;
arc -= 2;
}
}
- return 0;
+ return;
}
static void
- split_cubic( FT_Vector* base )
+ gray_split_cubic( FT_Vector* base )
{
TPos a, b, c, d;
@@ -832,10 +843,10 @@
}
- static int
- render_cubic( RAS_ARG_ FT_Vector* control1,
- FT_Vector* control2,
- FT_Vector* to )
+ static void
+ gray_render_cubic( RAS_ARG_ FT_Vector* control1,
+ FT_Vector* control2,
+ FT_Vector* to )
{
TPos dx, dy, da, db;
int top, level;
@@ -885,8 +896,9 @@
mid_y = ( ras.y + to_y +
3 * UPSCALE( control1->y + control2->y ) ) / 8;
- return render_line( RAS_VAR_ mid_x, mid_y ) ||
- render_line( RAS_VAR_ to_x, to_y );
+ gray_render_line( RAS_VAR_ mid_x, mid_y );
+ gray_render_line( RAS_VAR_ to_x, to_y );
+ return;
}
arc = ras.bez_stack;
@@ -924,7 +936,7 @@
if ( y > max ) max = y;
if ( TRUNC( min ) >= ras.max_ey || TRUNC( max ) < 0 )
goto Draw;
- split_cubic( arc );
+ gray_split_cubic( arc );
arc += 3;
top ++;
levels[top] = levels[top - 1] = level - 1;
@@ -941,14 +953,13 @@
mid_x = ( ras.x + to_x + 3 * ( arc[1].x + arc[2].x ) ) / 8;
mid_y = ( ras.y + to_y + 3 * ( arc[1].y + arc[2].y ) ) / 8;
- if ( render_line( RAS_VAR_ mid_x, mid_y ) ||
- render_line( RAS_VAR_ to_x, to_y ) )
- return 1;
+ gray_render_line( RAS_VAR_ mid_x, mid_y );
+ gray_render_line( RAS_VAR_ to_x, to_y );
top --;
arc -= 3;
}
}
- return 0;
+ return;
}
@@ -979,8 +990,8 @@
/* a simple shell sort algorithm that works directly on our */
/* cells table */
static void
- shell_sort ( PCell cells,
- int count )
+ gray_shell_sort ( PCell cells,
+ int count )
{
PCell i, j, limit = cells + count;
TCell temp;
@@ -1025,8 +1036,8 @@
/* through a normal insertion sort */
static void
- quick_sort( PCell cells,
- int count )
+ gray_quick_sort( PCell cells,
+ int count )
{
PCell stack[40]; /* should be enough ;-) */
PCell* top; /* top of stack */
@@ -1125,8 +1136,8 @@
#ifdef DEBUG_SORT
static int
- check_sort( PCell cells,
- int count )
+ gray_check_sort( PCell cells,
+ int count )
{
PCell p, q;
@@ -1145,19 +1156,21 @@
static int
- Move_To( FT_Vector* to,
- FT_Raster raster )
+ gray_move_to( FT_Vector* to,
+ FT_Raster raster )
{
TPos x, y;
/* record current cell, if any */
- record_cell( (PRaster)raster );
+ gray_record_cell( (PRaster)raster );
/* start to a new position */
x = UPSCALE( to->x );
y = UPSCALE( to->y );
- start_cell( (PRaster)raster, TRUNC( x ), TRUNC( y ) );
+
+ gray_start_cell( (PRaster)raster, TRUNC( x ), TRUNC( y ) );
+
((PRaster)raster)->x = x;
((PRaster)raster)->y = y;
return 0;
@@ -1165,38 +1178,41 @@
static int
- Line_To( FT_Vector* to,
- FT_Raster raster )
+ gray_line_to( FT_Vector* to,
+ FT_Raster raster )
{
- return render_line( (PRaster)raster,
- UPSCALE( to->x ), UPSCALE( to->y ) );
+ gray_render_line( (PRaster)raster,
+ UPSCALE( to->x ), UPSCALE( to->y ) );
+ return 0;
}
static int
- Conic_To( FT_Vector* control,
- FT_Vector* to,
- FT_Raster raster )
+ gray_conic_to( FT_Vector* control,
+ FT_Vector* to,
+ FT_Raster raster )
{
- return render_conic( (PRaster)raster, control, to );
+ gray_render_conic( (PRaster)raster, control, to );
+ return 0;
}
static int
- Cubic_To( FT_Vector* control1,
- FT_Vector* control2,
- FT_Vector* to,
- FT_Raster raster )
+ gray_cubic_to( FT_Vector* control1,
+ FT_Vector* control2,
+ FT_Vector* to,
+ FT_Raster raster )
{
- return render_cubic( (PRaster)raster, control1, control2, to );
+ gray_render_cubic( (PRaster)raster, control1, control2, to );
+ return 0;
}
static void
- grays_render_span( int y,
- int count,
- FT_Span* spans,
- PRaster raster )
+ gray_render_span( int y,
+ int count,
+ FT_Span* spans,
+ PRaster raster )
{
unsigned char* p;
FT_Bitmap* map = &raster->target;
@@ -1229,7 +1245,7 @@
#include <stdio.h>
static void
- dump_cells( RAS_ARG )
+ gray_dump_cells( RAS_ARG )
{
PCell cell, limit;
int y = -1;
@@ -1255,10 +1271,10 @@
static void
- grays_hline( RAS_ARG_ TScan x,
- TScan y,
- TPos area,
- int acount )
+ gray_hline( RAS_ARG_ TScan x,
+ TScan y,
+ TPos area,
+ int acount )
{
FT_Span* span;
int count;
@@ -1355,16 +1371,17 @@
static void
- grays_sweep( RAS_ARG_ FT_Bitmap* target )
+ gray_sweep( RAS_ARG_ FT_Bitmap* target )
{
- TScan x, y, cover, area;
+ TScan x, y, cover;
+ TArea area;
PCell start, cur, limit;
FT_UNUSED( target );
if ( ras.num_cells == 0 )
return;
-
+
cur = ras.cells;
limit = cur + ras.num_cells;
@@ -1396,7 +1413,7 @@
/* individual gray pixel there */
if ( area && x >= 0 )
{
- grays_hline( RAS_VAR_ x, y, cover * ( ONE_PIXEL * 2 ) - area, 1 );
+ gray_hline( RAS_VAR_ x, y, cover * ( ONE_PIXEL * 2 ) - area, 1 );
x++;
}
@@ -1407,14 +1424,14 @@
{
/* draw a gray span between the start cell and the current one */
if ( cur->x > x )
- grays_hline( RAS_VAR_ x, y,
+ gray_hline( RAS_VAR_ x, y,
cover * ( ONE_PIXEL * 2 ), cur->x - x );
}
else
{
/* draw a gray span until the end of the clipping region */
if ( cover && x < ras.max_ex - ras.min_ex )
- grays_hline( RAS_VAR_ x, y,
+ gray_hline( RAS_VAR_ x, y,
cover * ( ONE_PIXEL * 2 ),
ras.max_ex - x - ras.min_ex );
cover = 0;
@@ -1481,13 +1498,17 @@
/* <Return> */
/* Error code. 0 means sucess. */
/* */
- static int
- FT_Outline_Decompose( FT_Outline* outline,
- const FT_Outline_Funcs* interface,
- void* user )
+ static
+ int FT_Outline_Decompose( FT_Outline* outline,
+ const FT_Outline_Funcs* interface,
+ void* user )
{
#undef SCALED
-#define SCALED( x ) ( ( (x) << shift ) - delta )
+#if 0
+# define SCALED( x ) ( ( (x) << shift ) - delta )
+#else
+# define SCALED( x) (x)
+#endif
FT_Vector v_last;
FT_Vector v_control;
@@ -1502,8 +1523,10 @@
int error;
char tag; /* current point's state */
+#if 0
int shift = interface->shift;
FT_Pos delta = interface->delta;
+#endif
first = 0;
@@ -1692,19 +1715,38 @@
static int
- grays_convert_glyph( RAS_ARG_ FT_Outline* outline )
+ gray_convert_glyph_inner( RAS_ARG )
{
static
const FT_Outline_Funcs interface =
{
- (FT_Outline_MoveTo_Func) Move_To,
- (FT_Outline_LineTo_Func) Line_To,
- (FT_Outline_ConicTo_Func)Conic_To,
- (FT_Outline_CubicTo_Func)Cubic_To,
+ (FT_Outline_MoveTo_Func) gray_move_to,
+ (FT_Outline_LineTo_Func) gray_line_to,
+ (FT_Outline_ConicTo_Func) gray_conic_to,
+ (FT_Outline_CubicTo_Func) gray_cubic_to,
0,
0
};
+ volatile int error = 0;
+
+ if ( setjmp( ras.jump_buffer ) == 0 )
+ {
+ error = FT_Outline_Decompose( &ras.outline, &interface, &ras );
+ gray_record_cell( RAS_VAR );
+ }
+ else
+ {
+ error = ErrRaster_MemoryOverflow;
+ }
+
+ return error;
+ }
+
+
+ static int
+ gray_convert_glyph( RAS_ARG )
+ {
TBand bands[40], *band;
int n, num_bands;
TPos min, max, max_y;
@@ -1712,11 +1754,11 @@
/* Set up state in the raster object */
- compute_cbox( RAS_VAR_ outline );
+ gray_compute_cbox( RAS_VAR );
/* clip to target bitmap, exit if nothing to do */
clip = &ras.clip_box;
-
+
if ( ras.max_ex <= clip->xMin || ras.min_ex >= clip->xMax ||
ras.max_ey <= clip->yMin || ras.min_ey >= clip->yMax )
return 0;
@@ -1728,7 +1770,7 @@
if ( ras.max_ey > clip->yMax ) ras.max_ey = clip->yMax;
/* simple heuristic used to speed-up the bezier decomposition -- see */
- /* the code in render_conic() and render_cubic() for more details */
+ /* the code in gray_render_conic() and gray_render_cubic() for more details */
ras.conic_level = 32;
ras.cubic_level = 16;
@@ -1776,26 +1818,32 @@
ras.min_ey = band->min;
ras.max_ey = band->max;
+#if 1
+ error = gray_convert_glyph_inner( RAS_VAR );
+#else
error = FT_Outline_Decompose( outline, &interface, &ras ) ||
- record_cell( RAS_VAR );
+ gray_record_cell( RAS_VAR );
+#endif
if ( !error )
{
#ifdef SHELL_SORT
- shell_sort( ras.cells, ras.num_cells );
+ gray_shell_sort( ras.cells, ras.num_cells );
#else
- quick_sort( ras.cells, ras.num_cells );
+ gray_quick_sort( ras.cells, ras.num_cells );
#endif
#ifdef DEBUG_GRAYS
- check_sort( ras.cells, ras.num_cells );
- dump_cells( RAS_VAR );
+ gray_check_sort( ras.cells, ras.num_cells );
+ gray_dump_cells( RAS_VAR );
#endif
- grays_sweep( RAS_VAR_ &ras.target );
+ gray_sweep( RAS_VAR_ &ras.target );
band--;
continue;
}
+ else if ( error != ErrRaster_MemoryOverflow )
+ return 1;
/* render pool overflow, we will reduce the render band by half */
bottom = band->min;
@@ -1831,8 +1879,8 @@
extern int
- grays_raster_render( PRaster raster,
- FT_Raster_Params* params )
+ gray_raster_render( PRaster raster,
+ FT_Raster_Params* params )
{
FT_Outline* outline = (FT_Outline*)params->source;
FT_Bitmap* target_map = params->target;
@@ -1889,7 +1937,7 @@
if ( target_map )
ras.target = *target_map;
- ras.render_span = (FT_Raster_Span_Func)grays_render_span;
+ ras.render_span = (FT_Raster_Span_Func)gray_render_span;
ras.render_span_data = &ras;
if ( params->flags & ft_raster_flag_direct )
@@ -1898,7 +1946,7 @@
ras.render_span_data = params->user;
}
- return grays_convert_glyph( (PRaster)raster, outline );
+ return gray_convert_glyph( (PRaster)raster );
}
@@ -1908,8 +1956,8 @@
#ifdef _STANDALONE_
static int
- grays_raster_new( void* memory,
- FT_Raster* araster )
+ gray_raster_new( void* memory,
+ FT_Raster* araster )
{
static TRaster the_raster;
@@ -1924,7 +1972,7 @@
static void
- grays_raster_done( FT_Raster raster )
+ gray_raster_done( FT_Raster raster )
{
/* nothing */
FT_UNUSED( raster );
@@ -1933,8 +1981,8 @@
#else /* _STANDALONE_ */
static int
- grays_raster_new( FT_Memory memory,
- FT_Raster* araster )
+ gray_raster_new( FT_Memory memory,
+ FT_Raster* araster )
{
FT_Error error;
PRaster raster;
@@ -1952,7 +2000,7 @@
static void
- grays_raster_done( FT_Raster raster )
+ gray_raster_done( FT_Raster raster )
{
FT_Memory memory = (FT_Memory)((PRaster)raster)->memory;
@@ -1964,15 +2012,15 @@
static void
- grays_raster_reset( FT_Raster raster,
- const char* pool_base,
- long pool_size )
+ gray_raster_reset( FT_Raster raster,
+ const char* pool_base,
+ long pool_size )
{
PRaster rast = (PRaster)raster;
if ( raster && pool_base && pool_size >= 4096 )
- init_cells( rast, (char*)pool_base, pool_size );
+ gray_init_cells( rast, (char*)pool_base, pool_size );
rast->band_size = ( pool_size / sizeof ( TCell ) ) / 8;
}
@@ -1982,11 +2030,11 @@
{
ft_glyph_format_outline,
- (FT_Raster_New_Func) grays_raster_new,
- (FT_Raster_Reset_Func) grays_raster_reset,
- (FT_Raster_Set_Mode_Func)0,
- (FT_Raster_Render_Func) grays_raster_render,
- (FT_Raster_Done_Func) grays_raster_done
+ (FT_Raster_New_Func) gray_raster_new,
+ (FT_Raster_Reset_Func) gray_raster_reset,
+ (FT_Raster_Set_Mode_Func) 0,
+ (FT_Raster_Render_Func) gray_raster_render,
+ (FT_Raster_Done_Func) gray_raster_done
};