94#define QT_FT_COMPONENT trace_smooth
98#define QT_FT_ERR_XCAT( x, y ) x ## y
101#define QT_FT_BEGIN_STMNT do {
102#define QT_FT_END_STMNT } while ( 0
)
104#define QT_FT_MAX( a, b ) ( (a) > (b) ? (a) : (b) )
105#define QT_FT_ABS( a ) ( (a) < 0
? -(a) : (a) )
109
110
111
112
113#define QT_FT_HYPOT( x, y )
116 x > y ? x + ( 3
* y >> 3
)
117 : y + ( 3
* x >> 3
) )
119#define ErrRaster_MemoryOverflow -4
122# include <vxWorksCommon.h>
128#define QT_FT_UINT_MAX UINT_MAX
130#define qt_ft_memset memset
132#define qt_ft_setjmp setjmp
133#define qt_ft_longjmp longjmp
134#define qt_ft_jmp_buf jmp_buf
139#define ErrRaster_Invalid_Mode -2
140#define ErrRaster_Invalid_Outline -1
141#define ErrRaster_Invalid_Argument -3
142#define ErrRaster_Memory_Overflow -4
143#define ErrRaster_OutOfMemory -6
145#define QT_FT_BEGIN_HEADER
146#define QT_FT_END_HEADER
148#include <private/qrasterdefs_p.h>
149#include <private/qgrayraster_p.h>
151#include <qcompilerdetection.h>
152#include <qtconfigmacros.h>
158#define QT_FT_UNUSED( x ) (void) x
160#define QT_FT_TRACE5( x ) do { } while ( 0
)
161#define QT_FT_TRACE7( x ) do { } while ( 0
)
162#define QT_FT_ERROR( x ) do { } while ( 0
)
169#ifndef QT_FT_MEM_ZERO
174#define RAS_ARG PWorker worker
175#define RAS_ARG_ PWorker worker,
177#define RAS_VAR worker
178#define RAS_VAR_ worker,
193#define UPSCALE( x ) ( (x) >> ( 6
- PIXEL_BITS ) )
194#define DOWNSCALE( x ) ( (x) * ( 64
>> PIXEL_BITS ) )
200#define QT_FT_DIV_MOD( type, dividend, divisor, quotient, remainder ) QT_FT_BEGIN_STMNT
202 (quotient) = (type)( (dividend) / (divisor) );
203 (remainder) = (type)( (dividend) % (divisor) );
204 if ( (remainder) < 0
)
207 (remainder) += (type)(divisor);
213#define QT_FT_UDIVPREP( b )
214 long b ## _r = (long)( ULONG_MAX >> PIXEL_BITS ) / ( b )
215#define QT_FT_UDIV( a, b )
216 ( ( (unsigned long)( a ) * (unsigned long)( b ## _r ) ) >>
234#define QT_FT_MAX_GRAY_SPANS 256
337 QT_FT_Outline* outline = &
ras.outline;
338 QT_FT_Vector* vec = outline->points;
339 QT_FT_Vector* limit = vec + outline->n_points;
342 if ( outline->n_points <= 0 )
354 for ( ; vec < limit; vec++ )
392 if ( cell == NULL || cell->x > x )
515 TCoord ex1, ex2, fx1, fx2, first, dy, delta, mod;
587 }
while ( ex1 != ex2 );
607 TCoord ey1, ey2, fy1, fy2, first, delta, mod;
608 TPos p, dx, dy, x, x2;
654 area = (
TArea)two_fx * delta;
658 ey1 = (max_ey1 > ey2) ? max_ey1 : ey2;
684 while ( ey1 < ey2 && ey1 < max_ey1)
698 delta = (
int)( fy2 -
ONE_PIXEL + first );
756 }
while ( ey1 != ey2 );
776 gray_render_line( RAS_ARG_ TPos to_x,
779 TPos dx, dy, fx1, fy1, fx2, fy2;
780 TCoord ex1, ex2, ey1, ey2;
783 ex1 = TRUNC( ras.x );
785 ey1 = TRUNC( ras.y );
789 if ( ( ey1 >= ras.max_ey && ey2 >= ras.max_ey ) ||
790 ( ey1 < ras.min_ey && ey2 < ras.min_ey ) )
796 fx1 = FRACT( ras.x );
797 fy1 = FRACT( ras.y );
799 if ( ex1 == ex2 && ey1 == ey2 )
804 gray_set_cell( RAS_VAR_ ex1, ey1 );
812 ras.cover += ( fy2 - fy1 );
813 ras.area += ( fy2 - fy1 ) * fx1 * 2;
816 gray_set_cell( RAS_VAR_ ex1, ey1 );
817 }
while ( ey1 != ey2 );
822 ras.cover += ( fy2 - fy1 );
823 ras.area += ( fy2 - fy1 ) * fx1 * 2;
826 gray_set_cell( RAS_VAR_ ex1, ey1 );
827 }
while ( ey1 != ey2 );
831 TArea prod = dx * fy1 - dy * fx1;
832 QT_FT_UDIVPREP( dx );
833 QT_FT_UDIVPREP( dy );
842 prod - dx * ONE_PIXEL > 0 )
845 fy2 = (TPos)QT_FT_UDIV( -prod, -dx );
846 prod -= dy * ONE_PIXEL;
847 ras.cover += ( fy2 - fy1 );
848 ras.area += ( fy2 - fy1 ) * ( fx1 + fx2 );
853 else if ( prod - dx * ONE_PIXEL <= 0 &&
854 prod - dx * ONE_PIXEL + dy * ONE_PIXEL > 0 )
856 prod -= dx * ONE_PIXEL;
857 fx2 = (TPos)QT_FT_UDIV( -prod, dy );
859 ras.cover += ( fy2 - fy1 );
860 ras.area += ( fy2 - fy1 ) * ( fx1 + fx2 );
865 else if ( prod - dx * ONE_PIXEL + dy * ONE_PIXEL <= 0 &&
866 prod + dy * ONE_PIXEL >= 0 )
868 prod += dy * ONE_PIXEL;
870 fy2 = (TPos)QT_FT_UDIV( prod, dx );
871 ras.cover += ( fy2 - fy1 );
872 ras.area += ( fy2 - fy1 ) * ( fx1 + fx2 );
878
880 fx2 = (TPos)QT_FT_UDIV( prod, -dy );
882 prod += dx * ONE_PIXEL;
883 ras.cover += ( fy2 - fy1 );
884 ras.area += ( fy2 - fy1 ) * ( fx1 + fx2 );
890 gray_set_cell( RAS_VAR_ ex1, ey1 );
891 }
while ( ex1 != ex2 || ey1 != ey2 );
897 ras.cover += ( fy2 - fy1 );
898 ras.area += ( fy2 - fy1 ) * ( fx1 + fx2 );
913 base[4].x = base[2].x;
915 a = base[3].x = ( base[2].x + b ) / 2;
916 b = base[1].x = ( base[0].x + b ) / 2;
917 base[2].x = ( a + b ) / 2;
919 base[4].y = base[2].y;
921 a = base[3].y = ( base[2].y + b ) / 2;
922 b = base[1].y = ( base[0].y + b ) / 2;
923 base[2].y = ( a + b ) / 2;
929 const QT_FT_Vector* to )
931 QT_FT_Vector bez_stack[16 * 2 + 1];
932 QT_FT_Vector* arc = bez_stack;
939 arc[1].x =
UPSCALE( control->x );
940 arc[1].y =
UPSCALE( control->y );
957 dx =
QT_FT_ABS( arc[2].x + arc[0].x - 2 * arc[1].x );
958 dy =
QT_FT_ABS( arc[2].y + arc[0].y - 2 * arc[1].y );
978 while ( ( draw & split ) == 0 )
980 gray_split_conic( arc );
985 gray_render_line(
RAS_VAR_ arc[0].x, arc[0].y );
998 base[6].x = base[3].x;
1001 base[1].x = a = ( base[0].x + c ) / 2;
1002 base[5].x = b = ( base[3].x + d ) / 2;
1004 base[2].x = a = ( a + c ) / 2;
1005 base[4].x = b = ( b + c ) / 2;
1006 base[3].x = ( a + b ) / 2;
1008 base[6].y = base[3].y;
1011 base[1].y = a = ( base[0].y + c ) / 2;
1012 base[5].y = b = ( base[3].y + d ) / 2;
1014 base[2].y = a = ( a + c ) / 2;
1015 base[4].y = b = ( b + c ) / 2;
1016 base[3].y = ( a + b ) / 2;
1022 const QT_FT_Vector* control2,
1023 const QT_FT_Vector* to )
1025 QT_FT_Vector bez_stack[16 * 3 + 1];
1026 QT_FT_Vector* arc = bez_stack;
1027 TPos dx, dy, dx_, dy_;
1028 TPos dx1, dy1, dx2, dy2;
1034 arc[1].x =
UPSCALE( control2->x );
1035 arc[1].y =
UPSCALE( control2->y );
1036 arc[2].x =
UPSCALE( control1->x );
1037 arc[2].y =
UPSCALE( control1->y );
1065 dx = dx_ = arc[3].x - arc[0].x;
1066 dy = dy_ = arc[3].y - arc[0].y;
1071 if ( L >= (1 << 23) )
1078 dx1 = arc[1].x - arc[0].x;
1079 dy1 = arc[1].y - arc[0].y;
1086 dx2 = arc[2].x - arc[0].x;
1087 dy2 = arc[2].y - arc[0].y;
1094
1095
1096 if ( dx1 * ( dx1 - dx ) + dy1 * ( dy1 - dy ) > 0 ||
1097 dx2 * ( dx2 - dx ) + dy2 * ( dy2 - dy ) > 0 )
1100 gray_render_line(
RAS_VAR_ arc[0].x, arc[0].y );
1102 if ( arc == bez_stack )
1109 gray_split_cubic( arc );
1140 const QT_FT_Span* spans,
1144 QT_FT_Bitmap* map = &worker->target;
1146 for ( ; count > 0; count--, spans++ )
1148 unsigned char coverage = spans->coverage;
1151 p = (
unsigned char*)map->buffer - spans->y * map->pitch;
1152 if ( map->pitch >= 0 )
1153 p += ( map->rows - 1 ) * (
unsigned int)map->pitch;
1158 unsigned char* q = p + spans->x;
1162
1163
1164
1165 switch ( spans->len )
1197 coverage = (
int)( area >> (
PIXEL_BITS * 2 + 1 - 8 ) );
1200 coverage = -coverage;
1202 if (
ras.outline.flags & QT_FT_OUTLINE_EVEN_ODD_FILL )
1206 if ( coverage > 256 )
1207 coverage = 512 - coverage;
1208 else if ( coverage == 256 )
1214 if ( coverage >= 256 )
1222 if ( x >= (1 << 23) )
1226 if ( y >= (1 << 23) )
1238 span =
ras.gray_spans + count - 1;
1241 span->x + span->len == x &&
1242 span->coverage == coverage )
1244 span->len = span->len + acount;
1254 ras.gray_spans + skip,
1269 fprintf( stderr,
"y=%3d ", y );
1270 span = ras.gray_spans;
1271 for ( n = 0; n < count; n++, span++ )
1272 fprintf( stderr,
"[%d..%d]:%02x ",
1273 span->x, span->x + span->len - 1, span->coverage );
1274 fprintf( stderr,
"\n" );
1281 span =
ras.gray_spans;
1290 span->coverage = (
unsigned char)coverage;
1300 gray_dump_cells( RAS_ARG )
1305 for ( yindex = 0; yindex < ras.ycount; yindex++ )
1310 printf(
"%3d:", yindex );
1312 for ( cell = ras.ycells[yindex]; cell != NULL; cell = cell->next )
1313 printf(
" (%3d, c:%4d, a:%6d)", cell->x, cell->cover, cell->area );
1334 for ( yindex = 0; yindex <
ras.ycount; yindex++ )
1341 for ( ; cell != NULL; cell = cell
->next )
1346 if ( cell
->x > x && cover != 0 )
1353 if ( area != 0 && cell
->x >= 0 )
1401#define SCALED( x ) (x)
1403 QT_FT_Vector v_last;
1404 QT_FT_Vector v_control;
1405 QT_FT_Vector v_start;
1407 QT_FT_Vector* point;
1408 QT_FT_Vector* limit;
1421 for ( n = 0; n < outline->n_contours; n++ )
1426 last = outline->contours[n];
1428 goto Invalid_Outline;
1429 limit = outline->points + last;
1431 v_start = outline->points[first];
1432 v_start.x =
SCALED( v_start.x );
1433 v_start.y =
SCALED( v_start.y );
1435 v_last = outline->points[last];
1436 v_last.x =
SCALED( v_last.x );
1437 v_last.y =
SCALED( v_last.y );
1439 v_control = v_start;
1441 point = outline->points + first;
1442 tags = outline->tags + first;
1443 tag = QT_FT_CURVE_TAG( tags[0] );
1446 if ( tag == QT_FT_CURVE_TAG_CUBIC )
1447 goto Invalid_Outline;
1450 if ( tag == QT_FT_CURVE_TAG_CONIC )
1453 if ( QT_FT_CURVE_TAG( outline->tags[last] ) == QT_FT_CURVE_TAG_ON )
1464 v_start.x = ( v_start.x + v_last.x ) / 2;
1465 v_start.y = ( v_start.y + v_last.y ) / 2;
1474 v_start.x / 64.0, v_start.y / 64.0 ));
1475 error = gray_move_to( &v_start, user );
1479 while ( point < limit )
1484 tag = QT_FT_CURVE_TAG( tags[0] );
1487 case QT_FT_CURVE_TAG_ON:
1492 vec.x =
SCALED( point->x );
1493 vec.y =
SCALED( point->y );
1496 vec.x / 64.0, vec.y / 64.0 ));
1501 case QT_FT_CURVE_TAG_CONIC:
1503 v_control.x =
SCALED( point->x );
1504 v_control.y =
SCALED( point->y );
1507 if ( point < limit )
1510 QT_FT_Vector v_middle;
1515 tag = QT_FT_CURVE_TAG( tags[0] );
1517 vec.x =
SCALED( point->x );
1518 vec.y =
SCALED( point->y );
1520 if ( tag == QT_FT_CURVE_TAG_ON )
1523 " with control (%.2f, %.2f)\n",
1524 vec.x / 64.0, vec.y / 64.0,
1525 v_control.x / 64.0, v_control.y / 64.0 ));
1526 gray_render_conic(user, &v_control, &vec);
1530 if ( tag != QT_FT_CURVE_TAG_CONIC )
1531 goto Invalid_Outline;
1533 v_middle.x = ( v_control.x + vec.x ) / 2;
1534 v_middle.y = ( v_control.y + vec.y ) / 2;
1537 " with control (%.2f, %.2f)\n",
1538 v_middle.x / 64.0, v_middle.y / 64.0,
1539 v_control.x / 64.0, v_control.y / 64.0 ));
1540 gray_render_conic(user, &v_control, &v_middle);
1547 " with control (%.2f, %.2f)\n",
1548 v_start.x / 64.0, v_start.y / 64.0,
1549 v_control.x / 64.0, v_control.y / 64.0 ));
1550 gray_render_conic(user, &v_control, &v_start);
1556 QT_FT_Vector vec1, vec2;
1559 if ( point + 1 > limit ||
1560 QT_FT_CURVE_TAG( tags[1] ) != QT_FT_CURVE_TAG_CUBIC )
1561 goto Invalid_Outline;
1566 vec1.x =
SCALED( point[-2].x );
1567 vec1.y =
SCALED( point[-2].y );
1569 vec2.x =
SCALED( point[-1].x );
1570 vec2.y =
SCALED( point[-1].y );
1572 if ( point <= limit )
1577 vec.x =
SCALED( point->x );
1578 vec.y =
SCALED( point->y );
1581 " with controls (%.2f, %.2f) and (%.2f, %.2f)\n",
1582 vec.x / 64.0, vec.y / 64.0,
1583 vec1.x / 64.0, vec1.y / 64.0,
1584 vec2.x / 64.0, vec2.y / 64.0 ));
1585 gray_render_cubic(user, &vec1, &vec2, &vec);
1590 " with controls (%.2f, %.2f) and (%.2f, %.2f)\n",
1591 v_start.x / 64.0, v_start.y / 64.0,
1592 vec1.x / 64.0, vec1.y / 64.0,
1593 vec2.x / 64.0, vec2.y / 64.0 ));
1594 gray_render_cubic(user, &vec1, &vec2, &v_start);
1602 v_start.x / 64.0, v_start.y / 64.0 ));
1613 QT_FT_TRACE5((
"FT_Outline_Decompose: Error %d\n", error ));
1629 volatile int error = 0;
1633 error = QT_FT_Outline_Decompose( &
ras.outline, &
ras );
1650 TBand*
volatile band;
1651 int volatile n, num_bands;
1652 TPos volatile min, max, max_y;
1662 clip = &
ras.clip_box;
1679 if ( num_bands == 0 )
1681 if ( num_bands >= 39 )
1689 for ( n = 0; n < num_bands; n++, min = max )
1692 if ( n == num_bands - 1 || max > max_y )
1699 while ( band >= bands )
1701 TPos bottom, top, middle;
1707 int cell_start, cell_end, cell_mod;
1714 cell_mod = cell_start %
sizeof ( TCell );
1716 cell_start +=
sizeof ( TCell ) - cell_mod;
1719 cell_end -= cell_end %
sizeof( TCell );
1730 for ( yindex = 0; yindex <
ras.ycount; yindex++ )
1731 ras.ycells[yindex] = NULL;
1755 middle = bottom + ( ( top - bottom ) >> 1 );
1759 if ( middle == bottom )
1762 fprintf( stderr,
"Rotten glyph!\n" );
1770 band[1]
.min = bottom;
1771 band[1]
.max = middle;
1772 band[0]
.min = middle;
1782 ras.gray_spans + skip,
1797 const QT_FT_Raster_Params* params )
1799 const QT_FT_Outline* outline = (
const QT_FT_Outline*)params->source;
1800 const QT_FT_Bitmap* target_map = params->target;
1804 if ( !raster || !raster->buffer || !raster->buffer_size )
1811 raster->worker->skip_spans = params->skip_spans;
1816 if (raster->buffer_allocated_size < MINIMUM_POOL_SIZE )
1823 if ( outline->n_points == 0 || outline->n_contours <= 0 )
1826 if ( !outline->contours || !outline->points )
1829 if ( outline->n_points !=
1830 outline->contours[outline->n_contours - 1] + 1 )
1833 worker = raster->worker;
1836 if ( ( params->flags & QT_FT_RASTER_FLAG_DIRECT ) == 0 )
1842 if ( !target_map->width || !target_map->rows )
1845 if ( !target_map->buffer )
1850 if ( !( params->flags & QT_FT_RASTER_FLAG_AA ) )
1854 if ( ( params->flags & QT_FT_RASTER_FLAG_DIRECT ) == 0 )
1857 ras.clip_box.xMin = 0;
1858 ras.clip_box.yMin = 0;
1859 ras.clip_box.xMax = target_map->width;
1860 ras.clip_box.yMax = target_map->rows;
1862 else if ( params->flags & QT_FT_RASTER_FLAG_CLIP )
1864 ras.clip_box = params->clip_box;
1868 ras.clip_box.xMin = -(1 << 23);
1869 ras.clip_box.yMin = -(1 << 23);
1870 ras.clip_box.xMax = (1 << 23) - 1;
1871 ras.clip_box.yMax = (1 << 23) - 1;
1874 gray_init_cells( worker, raster->buffer, raster->buffer_size );
1876 ras.outline = *outline;
1882 ras.target = *target_map;
1884 ras.render_span = (QT_FT_Raster_Span_Func)gray_render_span;
1887 if ( params->flags & QT_FT_RASTER_FLAG_DIRECT )
1889 ras.render_span = (QT_FT_Raster_Span_Func)params->gray_spans;
1903 *araster = malloc(
sizeof(TRaster));
1926 PRaster rast = (PRaster)raster;
1930 if ( pool_base && ( pool_size >= MINIMUM_POOL_SIZE ) )
1932 PWorker worker = (PWorker)pool_base;
1937 ( (
sizeof ( TWorker ) +
sizeof ( TCell ) - 1 ) &
1938 ~(
sizeof ( TCell ) - 1 ) );
1941 ~(
sizeof ( TCell ) - 1 );
1943 (
sizeof ( TCell ) * 8 ) );
1945 else if ( pool_base)
1949 rast->worker = NULL;
1954 rast->buffer = NULL;
1956 rast->worker = NULL;
1964 QT_FT_GLYPH_FORMAT_OUTLINE,
1966 (QT_FT_Raster_New_Func) gray_raster_new,
1967 (QT_FT_Raster_Reset_Func) gray_raster_reset,
1968 (QT_FT_Raster_Set_Mode_Func)0,
1969 (QT_FT_Raster_Render_Func) gray_raster_render,
1970 (QT_FT_Raster_Done_Func) gray_raster_done
#define QT_FT_MAX_GRAY_SPANS
static int gray_move_to(const QT_FT_Vector *to, PWorker worker)
static void gray_record_cell(RAS_ARG)
#define QT_FT_MEM_ZERO(dest, count)
#define ErrRaster_Memory_Overflow
static PCell gray_find_cell(RAS_ARG)
static void gray_raster_done(QT_FT_Raster raster)
static void gray_render_line(RAS_ARG_ TPos to_x, TPos to_y)
static int gray_convert_glyph_inner(RAS_ARG)
static void gray_start_cell(RAS_ARG_ TCoord ex, TCoord ey)
static void gray_split_conic(QT_FT_Vector *base)
#define ErrRaster_Invalid_Argument
static int gray_raster_new(QT_FT_Raster *araster)
static int QT_FT_Outline_Decompose(const QT_FT_Outline *outline, void *user)
#define QT_FT_DIV_MOD(type, dividend, divisor, quotient, remainder)
#define QT_FT_HYPOT(x, y)
static void gray_render_cubic(RAS_ARG_ const QT_FT_Vector *control1, const QT_FT_Vector *control2, const QT_FT_Vector *to)
static int gray_convert_glyph(RAS_ARG)
#define QT_FT_ERR_XCAT(x, y)
static int gray_raster_render(QT_FT_Raster raster, const QT_FT_Raster_Params *params)
#define ErrRaster_Invalid_Mode
static void gray_raster_reset(QT_FT_Raster raster, char *pool_base, long pool_size)
static void gray_compute_cbox(RAS_ARG)
static void gray_set_cell(RAS_ARG_ TCoord ex, TCoord ey)
#define ErrRaster_OutOfMemory
#define QT_FT_ERR_CAT(x, y)
#define QT_FT_MEM_SET(d, s, c)
static void gray_init_cells(RAS_ARG_ void *buffer, long byte_size)
static void gray_render_conic(RAS_ARG_ const QT_FT_Vector *control, const QT_FT_Vector *to)
static void gray_sweep(RAS_ARG_ const QT_FT_Bitmap *target)
static void gray_render_scanline(RAS_ARG_ TCoord ey, TPos x1, TCoord y1, TPos x2, TCoord y2)
static void gray_render_span(int count, const QT_FT_Span *spans, PWorker worker)
#define ErrRaster_Invalid_Outline
static void gray_split_cubic(QT_FT_Vector *base)
static void gray_hline(RAS_ARG_ TCoord x, TCoord y, TPos area, int acount)
#define QT_MANGLE_NAMESPACE(name)
long buffer_allocated_size
qt_ft_jmp_buf jump_buffer
QT_FT_Raster_Span_Func render_span
QT_FT_Span gray_spans[QT_FT_MAX_GRAY_SPANS]