apwfreetypelib

Check-in [a767fde976]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:splitting up of grayTWorker onto several derirvced classes.
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:a767fde976d8f1641d9e394bc3cd425498ae9303
User & Date: arnulf 2015-02-14 20:30:44
Context
2015-02-14
20:31
initial version. check-in: d7482c9d4b user: arnulf tags: trunk
20:30
splitting up of grayTWorker onto several derirvced classes. check-in: a767fde976 user: arnulf tags: trunk
18:22
fixes and added new Debug tags. check-in: 4621cff9f7 user: arnulf tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to aftraster/FTSmoothRendererClass.java.

359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
...
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394

  /* ==================== rasterReset ===================================== */
  @Override
  public FTError.ErrorTag rasterReset(FTRasterRec raster, byte[] raster_pool, int raster_pool_size) {
    FTError.ErrorTag error = FTError.ErrorTag.ERR_OK;
    grayTRasterRec traster = (grayTRasterRec)raster;

    traster.getWorker().gray_raster_reset(traster, raster_pool, raster_pool_size);
    traster.setBand_size(traster.getWorker().getBand_size());
    return error;
  }

  /* ==================== rasterSetMode ===================================== */
  @Override
  public FTError.ErrorTag rasterSetMode() {
................................................................................
  }

  /* ==================== rasterRender ===================================== */
  @Override
  public FTError.ErrorTag rasterRender(FTRasterRec raster, FTRasterParamsRec params) {
    grayTRasterRec traster = (grayTRasterRec)raster;

    return traster.getWorker().gray_raster_render(traster, params);
  }

  /* ==================== rasterDone ===================================== */
  @Override
  public FTError.ErrorTag rasterDone(FTRasterRec raster) {
    grayTRasterRec traster = (grayTRasterRec)raster;

    return traster.getWorker().gray_raster_done();
  }

}







|







 







|







|



359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
...
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394

  /* ==================== rasterReset ===================================== */
  @Override
  public FTError.ErrorTag rasterReset(FTRasterRec raster, byte[] raster_pool, int raster_pool_size) {
    FTError.ErrorTag error = FTError.ErrorTag.ERR_OK;
    grayTRasterRec traster = (grayTRasterRec)raster;

    traster.gray_raster_reset(traster.getWorker(), raster_pool, raster_pool_size);
    traster.setBand_size(traster.getWorker().getBand_size());
    return error;
  }

  /* ==================== rasterSetMode ===================================== */
  @Override
  public FTError.ErrorTag rasterSetMode() {
................................................................................
  }

  /* ==================== rasterRender ===================================== */
  @Override
  public FTError.ErrorTag rasterRender(FTRasterRec raster, FTRasterParamsRec params) {
    grayTRasterRec traster = (grayTRasterRec)raster;

    return traster.gray_raster_render(params);
  }

  /* ==================== rasterDone ===================================== */
  @Override
  public FTError.ErrorTag rasterDone(FTRasterRec raster) {
    grayTRasterRec traster = (grayTRasterRec)raster;

    return traster.gray_raster_done();
  }

}

Changes to aftraster/grayTRasterRec.java.

14
15
16
17
18
19
20




21
22
23
24
25
26
27
..
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
..
54
55
56
57
58
59
60


















































































































61
62
63
64
65
66
67
package org.apwtcl.apwfreetypelib.aftraster;

  /* ===================================================================== */
  /*    grayTRasterRec                                                     */
  /*                                                                       */
  /* ===================================================================== */





public class grayTRasterRec extends FTRasterRec {
  private static int oid = 0;

  private int id;
  private static String TAG = "grayTRasterRec";

  private int band_size = 0;
................................................................................
  /* ==================== grayTRasterRec ================================== */
  public grayTRasterRec() {
    oid++;
    id = oid;
    worker = new grayTWorkerRec();
  }
    
  /* ==================== grayTRaster ================================== */
  public grayTRasterRec(FTRasterRec raster_rec) {
    oid++;
    id = oid;
    this.buffer = raster_rec.buffer;
    this.buffer_size = raster_rec.buffer_size;
  }
    
................................................................................

  /* ==================== toDebugString ===================================== */
  public String toDebugString() {
    StringBuffer str = new StringBuffer(mySelf()+"\n");
    str.append("...band_size: "+band_size+'\n');
    return str.toString();
  }



















































































































  /* ==================== getBand_size ================================== */
  public int getBand_size() {
    return band_size;
  }

  /* ==================== setBand_size ================================== */







>
>
>
>







 







|







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
..
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
..
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
package org.apwtcl.apwfreetypelib.aftraster;

  /* ===================================================================== */
  /*    grayTRasterRec                                                     */
  /*                                                                       */
  /* ===================================================================== */

import org.apwtcl.apwfreetypelib.aftbase.FTBitmapRec;
import org.apwtcl.apwfreetypelib.aftbase.FTOutlineRec;
import org.apwtcl.apwfreetypelib.aftutil.FTError;

public class grayTRasterRec extends FTRasterRec {
  private static int oid = 0;

  private int id;
  private static String TAG = "grayTRasterRec";

  private int band_size = 0;
................................................................................
  /* ==================== grayTRasterRec ================================== */
  public grayTRasterRec() {
    oid++;
    id = oid;
    worker = new grayTWorkerRec();
  }
    
  /* ==================== grayTRasterRec ================================== */
  public grayTRasterRec(FTRasterRec raster_rec) {
    oid++;
    id = oid;
    this.buffer = raster_rec.buffer;
    this.buffer_size = raster_rec.buffer_size;
  }
    
................................................................................

  /* ==================== toDebugString ===================================== */
  public String toDebugString() {
    StringBuffer str = new StringBuffer(mySelf()+"\n");
    str.append("...band_size: "+band_size+'\n');
    return str.toString();
  }

  /* =====================================================================
 *    gray_raster_reset
 *
 * =====================================================================
 */
  public FTError.ErrorTag gray_raster_reset(grayTWorkerRec worker, byte[] pool_base, int pool_size) {
    FTError.ErrorTag error = FTError.ErrorTag.ERR_OK;

    Debug(0, DebugTag.DBG_RENDER, TAG, "gray_raster_reset");
    if (pool_base != null) {
      buffer = pool_base;
      buffer_size = pool_size;
//      band_size = (int)buffer_size / sizeof(TCell) * 8;
      band_size = buffer_size / 20;  // FIXME!!!
//      grayTWorkerRec worker =  new grayTWorkerRec();
      setWorker(worker);
      worker.setBand_size(band_size);
    } else {
      buffer = null;
      buffer_size = 0;
      setWorker(null);
    }
    return error;
  }

  /* =====================================================================
   *    gray_raster_render
   *
   * =====================================================================
   */
  public FTError.ErrorTag gray_raster_render(FTRasterParamsRec params) {
    Debug(0, DebugTag.DBG_RENDER, TAG, "gray_raster_render");
    FTOutlineRec outline = (FTOutlineRec)params.getSource();
    FTBitmapRec target_map = params.getTarget();

    if (buffer == null || buffer_size == 0) {
      return FTError.ErrorTag.RENDER_INVALID_ARGUMENT;
    }
    if (outline == null) {
      return FTError.ErrorTag.RENDER_INVALID_OUTLINE;
    }
      /* return immediately if the outline is empty */
    if (outline.getN_points() == 0 || outline.getN_contours() <= 0) {
      return FTError.ErrorTag.ERR_OK;
    }
    if (outline.getContours() == null || outline.getPoints()== null) {
      return FTError.ErrorTag.RENDER_INVALID_OUTLINE;
    }
    if (outline.getN_points() != outline.getContours()[outline.getN_contours() - 1] + 1) {
      return FTError.ErrorTag.RENDER_INVALID_OUTLINE;
    }
      /* if direct mode is not set, we must have a target bitmap */
    if ((params.getFlags() & FTRasterParamsRec.FT_RASTER_FLAG_DIRECT) == 0) {
      if (target_map == null) {
        return FTError.ErrorTag.RENDER_INVALID_ARGUMENT;
      }
        /* nothing to do */
      if (target_map.getWidth() == 0|| target_map.getRows() == 0) {
        return FTError.ErrorTag.ERR_OK;
      }
      if (target_map.getBuffer() == null) {
        return FTError.ErrorTag.RENDER_INVALID_ARGUMENT;
      }
    }
      /* this version does not support monochrome rendering */
    if ((params.getFlags() & FTRasterParamsRec.FT_RASTER_FLAG_AA) == 0) {
      return FTError.ErrorTag.RENDER_INVALID_MODE;
    }
      /* compute clipping box */
    if ((params.getFlags() & FTRasterParamsRec.FT_RASTER_FLAG_DIRECT) == 0) {
        /* compute clip box from target pixmap */
      worker.getClip_box().setxMin(0);
      worker.getClip_box().setyMin(0);
      worker.getClip_box().setxMax(target_map.getWidth());
      worker.getClip_box().setyMax(target_map.getRows());
    } else {
      if ((params.getFlags() & FTRasterParamsRec.FT_RASTER_FLAG_CLIP) != 0) {
        worker.setClip_box(params.getClip_box());
      } else {
        worker.getClip_box().setxMin(-32768);
        worker.getClip_box().setyMin(-32768);
        worker.getClip_box().setxMax(32767);
        worker.getClip_box().setyMax(32767);
      }
    }
    worker.gray_init_cells(buffer, buffer_size);
    worker.setOutline(outline);
    worker.setNum_cells(0);
    worker.setInvalid(true);
    worker.setNum_gray_spans(0);
    if ((params.getFlags() & FTRasterParamsRec.FT_RASTER_FLAG_DIRECT) != 0) {
//FIXME!!      worker.render_span(params.gray_spans);
      worker.setRender_span_data(params.getUser_data());
    } else {
      worker.setTarget(target_map);
      worker.setRender_span_data(worker);
    }
    return worker.gray_convert_glyph();
  }

  /* =====================================================================
   *    gray_raster_done
   *
   * =====================================================================
   */
  public FTError.ErrorTag gray_raster_done() {
    Debug(0, DebugTag.DBG_RENDER, TAG, "gray_raster_done");
    FTError.ErrorTag error = FTError.ErrorTag.ERR_OK;
    // nothing to do
    return error;
  }



  /* ==================== getBand_size ================================== */
  public int getBand_size() {
    return band_size;
  }

  /* ==================== setBand_size ================================== */

Changes to aftraster/grayTWorkerRec.java.

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
...
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
...
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
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
....
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
....
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
/* =====================================================================
 *  This Java implementation is derived from FreeType code
 *  Portions of this software are copyright (C) 2014 The FreeType
 *  Project (www.freetype.org).  All rights reserved.
 *
 *  Copyright (C) of the Java implementation 2014
 *  Arnulf Wiedemann: arnulf (at) wiedemann-pri (dot) de
 *
 *  See the file "license.terms" for information on usage and
 *  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 * =====================================================================
 */

package org.apwtcl.apwfreetypelib.aftraster;

  /* ===================================================================== */
  /*    grayTWorkerRec                                                     */
  /*                                                                       */
  /* ===================================================================== */

import android.util.Log;

import org.apwtcl.apwfreetypelib.aftbase.FTBBoxRec;
import org.apwtcl.apwfreetypelib.aftbase.FTBitmapRec;
import org.apwtcl.apwfreetypelib.aftbase.FTOutlineRec;
import org.apwtcl.apwfreetypelib.aftbase.Flags;
import org.apwtcl.apwfreetypelib.aftutil.FTCalc;
import org.apwtcl.apwfreetypelib.aftutil.FTDebug;
import org.apwtcl.apwfreetypelib.aftutil.FTError;
import org.apwtcl.apwfreetypelib.aftutil.FTTrace;
import org.apwtcl.apwfreetypelib.aftutil.FTVectorRec;
import org.apwtcl.apwfreetypelib.aftutil.RasterUtil;

public class grayTWorkerRec extends FTDebug {
  private static int oid = 0;

  private int id;
  private static String TAG = "grayTWorkerRec";
  private final static int MaxBezier = 32;

  private int ex;
  private int ey;
  private int min_ex;
  private int max_ex;
  private int min_ey;
  private int max_ey;
  private int count_ex;
  private int count_ey;
  private int area;
  private int cover;
  private boolean invalid;
  private TCellRec[] cells = null;
  private int max_cells;
  private int num_cells;
  private int cx;
  private int cy;
  private int x;
  private int y;
  private int last_ey;
  private FTVectorRec[] bez_stack = new FTVectorRec[MaxBezier * 3 + 1];
  private int[] lev_stack = new int[32];
  private FTOutlineRec outline;
  private FTBitmapRec target;
  private FTBBoxRec clip_box;
  private FTSpanRec[] gray_spans = new FTSpanRec[FTSpanRec.FT_MAX_GRAY_SPANS];
  private int num_gray_spans;
  private Object render_span_data;
  private int span_y;
  private int band_size;
  private int band_shoot;
  private byte[] buffer;
  private int buffer_size;
  private TCellRec[] ycells;
  private int ycount;

  /* ==================== grayTWorker ================================== */
  public grayTWorkerRec() {
    int i;

    oid++;
    id = oid;
    target = new FTBitmapRec();
    outline = new FTGrayOutlineClass();
    clip_box = new FTBBoxRec();
    for (i = 0; i < FTSpanRec.FT_MAX_GRAY_SPANS; i++) {
      gray_spans[i] = new FTSpanRec();
    }
    for (i = 0; i < MaxBezier * 3 + 1; i++) {
      bez_stack[i] = new FTVectorRec();
    }
  }
    
  /* ==================== mySelf ================================== */
  public String mySelf() {
    return TAG+"!"+id+"!";
  }
        
  /* ==================== toString ===================================== */
  public String toString() {
    return mySelf()+"!";
  }

  /* ==================== toDebugString ===================================== */
  public String toDebugString() {
    StringBuffer str = new StringBuffer(mySelf()+"\n");
    str.append("...ex: "+ex+'\n');
    str.append("...ey: "+ey+'\n');
    str.append("...min_ex: "+min_ex+'\n');
    str.append("...max_ex: "+max_ex+'\n');
    str.append("...min_ey: "+min_ey+'\n');
    str.append("...max_ey: "+max_ey+'\n');
    str.append("...count_ex: "+count_ex+'\n');
    str.append("...count_ey: "+count_ey+'\n');
    str.append("...area: "+area+'\n');
    str.append("...cover: "+cover+'\n');
    str.append("...invalid: "+invalid+'\n');
    str.append("...max_cells: "+max_cells+'\n');
    str.append("...num_cells: "+num_cells+'\n');
    str.append("...cx: "+cx+'\n');
    str.append("...cy: "+cy+'\n');
    str.append("...x: "+x+'\n');
    str.append("...y: "+y+'\n');
    str.append("...last_ey: "+last_ey+'\n');
    str.append("...num_gray_spans: "+num_gray_spans+'\n');
    str.append("...span_y: "+span_y+'\n');
    str.append("...band_size: "+band_size+'\n');
    str.append("...band_shoot: "+band_shoot+'\n');
    str.append("...buffer_size: "+buffer_size+'\n');
    str.append("...ycount: "+ycount+'\n');
    return str.toString();
  }

  /* =====================================================================
   *    gray_raster_reset
   *
   * =====================================================================
   */
  public FTError.ErrorTag gray_raster_reset(grayTRasterRec raster, byte[] pool_base, int pool_size) {
    FTError.ErrorTag error = FTError.ErrorTag.ERR_OK;

Debug(0, DebugTag.DBG_RENDER, TAG, "gray_raster_reset");
    if (pool_base != null) {
      buffer = pool_base;
      buffer_size = pool_size;
//        raster.band_size = (int)raster.buffer_size / sizeof(TCell) * 8;
      band_size = buffer_size / 20;  // FIXME!!!
//      grayTWorkerRec worker =  new grayTWorkerRec();
//      raster.setWorker(worker);
    } else {
      buffer = null;
      buffer_size = 0;
//      raster.setWorker(null);
    }
    return error;
  }

  /* =====================================================================
   *    gray_raster_render
   *
   * =====================================================================
   */
  public FTError.ErrorTag gray_raster_render(grayTRasterRec raster, FTRasterParamsRec params) {
Debug(0, DebugTag.DBG_RENDER, TAG, "gray_raster_render");
    FTOutlineRec outline = (FTOutlineRec)params.getSource();
    FTBitmapRec target_map = params.getTarget();

    if (buffer == null || buffer_size == 0) {
      return FTError.ErrorTag.RENDER_INVALID_ARGUMENT;
    }
    if (outline == null) {
      return FTError.ErrorTag.RENDER_INVALID_OUTLINE;
    }
      /* return immediately if the outline is empty */
    if (outline.getN_points() == 0 || outline.getN_contours() <= 0) {
      return FTError.ErrorTag.ERR_OK;
    }
    if (outline.getContours() == null || outline.getPoints()== null) {
      return FTError.ErrorTag.RENDER_INVALID_OUTLINE;
    }
    if (outline.getN_points() != outline.getContours()[outline.getN_contours() - 1] + 1) {
      return FTError.ErrorTag.RENDER_INVALID_OUTLINE;
    }
      /* if direct mode is not set, we must have a target bitmap */
    if ((params.getFlags() & FTRasterParamsRec.FT_RASTER_FLAG_DIRECT) == 0) {
      if (target_map == null) {
        return FTError.ErrorTag.RENDER_INVALID_ARGUMENT;
      }
        /* nothing to do */
      if (target_map.getWidth() == 0|| target_map.getRows() == 0) {
        return FTError.ErrorTag.ERR_OK;
      }
      if (target_map.getBuffer() == null) {
        return FTError.ErrorTag.RENDER_INVALID_ARGUMENT;
      }
    }
      /* this version does not support monochrome rendering */
    if ((params.getFlags() & FTRasterParamsRec.FT_RASTER_FLAG_AA) == 0) {
      return FTError.ErrorTag.RENDER_INVALID_MODE;
    }
      /* compute clipping box */
    if ((params.getFlags() & FTRasterParamsRec.FT_RASTER_FLAG_DIRECT) == 0) {
        /* compute clip box from target pixmap */
      clip_box.setxMin(0);
      clip_box.setyMin(0);
      clip_box.setxMax(target_map.getWidth());
      clip_box.setyMax(target_map.getRows());
    } else {
      if ((params.getFlags() & FTRasterParamsRec.FT_RASTER_FLAG_CLIP) != 0) {
        clip_box = params.getClip_box();
      } else {
        clip_box.setxMin(-32768);
        clip_box.setyMin(-32768);
        clip_box.setxMax(32767);
        clip_box.setyMax(32767);
      }
    }
    gray_init_cells(buffer, buffer_size);
    this.outline = outline;
    num_cells = 0;
    invalid = true;
    band_size = raster.getBand_size();
    num_gray_spans = 0;
    if ((params.getFlags() & FTRasterParamsRec.FT_RASTER_FLAG_DIRECT) != 0) {
//FIXME!!      worker.render_span(params.gray_spans);
      render_span_data = params.getUser_data();
    } else {
      target = target_map;
      render_span_data = this;
    }
    return gray_convert_glyph();
  }

  /* =====================================================================
   *    gray_raster_done
   *
   * =====================================================================
   */
  public FTError.ErrorTag gray_raster_done() {
Debug(0, DebugTag.DBG_RENDER, TAG, "gray_raster_done");
    FTError.ErrorTag error = FTError.ErrorTag.ERR_OK;
    // nothing to do
    return error;
  }

  /* =====================================================================
   *    gray_render_span
   *
   * =====================================================================
   */
  public void gray_render_span(int y, int count, FTSpanRec[] spans) {
    int spansIdx = 0;
    int pIdx;
    int qIdx;
    FTBitmapRec map = target;
Debug(0, DebugTag.DBG_RENDER, TAG, String.format("gray_render_span y: %d, count: %d", y, count));

    /* first of all, compute the scanline offset */
    pIdx = 0 - y * map.getPitch();
    if (map.getPitch() >= 0) {
      pIdx += ((map.getRows() - 1) * map.getPitch());
    }
    for (; count > 0; count--, spansIdx++) {
      byte coverage = spans[spansIdx].getCoverage();

      if (coverage != 0) {
          /* For small-spans it is faster to do it by ourselves than
           * calling `memset'.  This is mainly due to the cost of the
           * function call.
           */
        if (spans[spansIdx].getLen() >= 8) {
          int lgth = spans[spansIdx].getLen();
          int i;
          for (i = spans[spansIdx].getX(); i < spans[spansIdx].getX() + lgth; i++) {
            map.getBuffer()[i] = coverage;
          }
//            FT_MEM_SET(p + spans[spansIdx].x, (char)coverage, spans[spansIdx].len);
        } else {
//            char*  q = p + spans.x;
          qIdx = pIdx + spans[spansIdx].getX();

          switch (spans[spansIdx].getLen()) {
            case 7: map.getBuffer()[qIdx++] = coverage;
            case 6: map.getBuffer()[qIdx++] = coverage;
            case 5: map.getBuffer()[qIdx++] = coverage;
            case 4: map.getBuffer()[qIdx++] = coverage;
            case 3: map.getBuffer()[qIdx++] = coverage;
            case 2: map.getBuffer()[qIdx++] = coverage;
            case 1: map.getBuffer()[qIdx] = coverage;
            default:
              ;
          }
        }
      }
    }
  }

  /* =====================================================================
   *    gray_init_cells
   *
   * =====================================================================
   */
  public void gray_init_cells(byte[] buffer, int byte_size) {
Debug(0, DebugTag.DBG_RENDER, TAG, "+++ gray_init_cells");

    this.buffer = buffer;
    buffer_size = byte_size;
    ycells = new TCellRec[byte_size / 10];
    cells = null;
    max_cells = 0;
    num_cells = 0;
    area = 0;
    cover = 0;
    invalid = true;
  }

  /* =====================================================================
   *    gray_convert_glyph_inner
   *
   * =====================================================================
   */
  public FTError.ErrorTag gray_convert_glyph_inner() {
Debug(0, DebugTag.DBG_RENDER, TAG, "gray_convert_glyph_inner");
    FTError.ErrorTag error = FTError.ErrorTag.ERR_OK;

//      if (ft_setjmp(ras.jump_buffer) == 0) {
    error = outline.FTOutlineDecompose(this);
    gray_record_cell();
//      } else {
//        error = FT_THROW( Memory_Overflow );
//      }
    return error;
  }

  /* =====================================================================
   *    gray_hline
   *
   * =====================================================================
   */
  public void gray_hline(int x, int y, int area, int acount) {
Debug(0, DebugTag.DBG_RENDER, TAG, String.format("gray_hline: x: %d, y: %d, area: 0x%08x, acount: %d", x, y, area, acount));
    int coverage = 0;
    int spanIdx = 0;

      /* compute the coverage line's coverage, depending on the    */
      /* outline fill rule                                         */
      /*                                                           */
      /* the coverage percentage is area/(PIXEL_BITS*PIXEL_BITS*2) */
      /*                                                           */
    coverage = (area >> (FTGrayOutlineClass.PIXEL_BITS * 2 + 1 - 8));
                                                      /* use range 0..256 */
    if (coverage < 0) {
      coverage = -coverage;
    }
    if ((outline.getFlags() & Flags.Outline.EVEN_ODD_FILL.getVal()) != 0) {
      coverage &= 511;
      if (coverage > 256) {
        coverage = 512 - coverage;
      } else {
        if (coverage == 256) {
          coverage = 255;
        }
      }
    } else {
        /* normal non-zero winding rule */
      if (coverage >= 256) {
        coverage = 255;
      }
    }
    y += min_ey;
    x += min_ex;
      /* FT_Span.x is a 16-bit short, so limit our coordinates appropriately */
    if (x >= 32767) {
      x = 32767;
    }
      /* FT_Span.y is an integer, so limit our coordinates appropriately */
    if (y >= 0xFFFF) {
      y = 0xFFFF;
    }
Debug(0, DebugTag.DBG_RENDER, TAG, String.format("x: %d, y: %d, coverage: %x", x, y, coverage));
    if (coverage != 0) {
      int count;
      FTSpanRec span = null;

        /* see whether we can add this span to the current list */
      count = num_gray_spans;
      spanIdx = count - 1;
      if (count > 0) {
        span = gray_spans[count - 1];
      } else {
      }
      if (count > 0 && span_y == y && span.getX() + span.getLen() == x &&
          (span.getCoverage() & 0xFF) == coverage) {
        span.setLen(span.getLen() + acount);
        gray_spans[count - 1] = span;
        return;
      }
      if (span_y != y || count >= FTSpanRec.FT_MAX_GRAY_SPANS) {
        if (count > 0) {
          gray_render_span(span_y, count, gray_spans);
        }
        if (count > 0) {
          int  n;
          StringBuffer str = new StringBuffer();

          str.append(String.format("y = %3d ", span_y));
          for (n = 0; n < count; n++) {
            str.append(String.format("  [%d..%d]:0x%02x ",
                gray_spans[n].getX(), gray_spans[n].getX() + gray_spans[n].getLen() - 1, gray_spans[n].getCoverage()));
          }
          FTTrace.Trace(7, TAG, str.toString());
        }
        num_gray_spans = 0;
        span_y = y;
        count = 0;
        spanIdx = 0;
      } else {
        spanIdx++;
      }
        /* add a gray span to the current list */
      gray_spans[spanIdx].setX(x);
      gray_spans[spanIdx].setLen(acount);
      gray_spans[spanIdx].setCoverage((byte)coverage);
      num_gray_spans = num_gray_spans + 1;
    }
Debug(0, DebugTag.DBG_RENDER, TAG, "gray_hline END 2");
  }

  /* =====================================================================
   *    gray_sweep
   *
   * =====================================================================
   */
  public void gray_sweep(FTBitmapRec target) {
Debug(0, DebugTag.DBG_RENDER, TAG, "gray_sweep");
    int  yindex;

    if (num_cells == 0) {
      return;
    }
    num_gray_spans = 0;
    FTTrace.Trace(7, TAG, "gray_sweep: start "+ycount);
    for (yindex = 0; yindex < ycount; yindex++) {
      TCellRec cell = ycells[yindex];
      int cover = 0;
      int x = 0;

      for ( ; cell != null; cell = cell.getNext()) {
        int area;

Debug(0, DebugTag.DBG_RENDER, TAG, String.format("cell->next: %d", cell.getNext() == null ? -1 : cell.getNext().getSelf_idx()));
Debug(0, DebugTag.DBG_RENDER, TAG, String.format("gray_sweep 1: cell.x: %d x: %d,  yindex: %d, cover: %x", cell.getX(), x, yindex, cover));
        if (cell.getX() > x && cover != 0) {
          gray_hline(x, yindex, cover * (RasterUtil.ONE_PIXEL() * 2), cell.getX() - x );
        }
        cover += cell.getCover();
        area = cover * (RasterUtil.ONE_PIXEL() * 2) - cell.getArea();
        if (area != 0 && cell.getX() >= 0) {
          gray_hline(cell.getX(), yindex, area, 1 );
        }
        x = cell.getX() + 1;
      }
      if (cover != 0) {
        gray_hline(x, yindex, cover * (RasterUtil.ONE_PIXEL() * 2), count_ex - x);
      }
    }
    if (num_gray_spans > 0) {
      gray_render_span(span_y, num_gray_spans, gray_spans);
    }
    if (num_gray_spans > 0) {
      FTSpanRec span;
      int spanIdx = 0;
      int n;
      StringBuffer str = new StringBuffer("");

      str.append(String.format("y = %3d ", span_y));
      for (n = 0; n < num_gray_spans; n++, spanIdx++) {
        span = gray_spans[spanIdx];
        str.append(String.format("  [%d..%d]:0x%02x ",
            span.getX(), span.getX() + span.getLen() - 1, span.getCoverage() & 0xFF));
      }
      FTTrace.Trace(7, TAG, str.toString());
    }
    FTTrace.Trace(7, TAG, "gray_sweep: end");
  }

  /* =====================================================================
   *    gray_convert_glyph
   *
   * =====================================================================
   */
  public FTError.ErrorTag gray_convert_glyph() {
Debug(0, DebugTag.DBG_RENDER, TAG, "gray_convert_glyph");
    FTError.ErrorTag error = FTError.ErrorTag.ERR_OK;
    grayTBandRec[] bands = new grayTBandRec[40];
    int bandIdx = 0;
    int n;
    int i;
    int num_bands;
    int min;
................................................................................
    if (num_bands >= 39) {
      num_bands = 39;
    }
    band_shoot = 0;
    min = min_ey;
    max_y = max_ey;
    for (n = 0; n < num_bands; n++, min = max) {
Debug(0, DebugTag.DBG_RENDER, TAG, "num_bands: n: "+n+" "+num_bands);
      max = min + band_size;
      if (n == num_bands - 1 || max > max_y) {
        max = max_y;
      }
      bands[0].setMin(min);
      bands[0].setMax(max);
      bandIdx = 0;
................................................................................
    }
    if (band_shoot > 8 && band_size > 16) {
      band_size = band_size / 2;
    }
    return error;
  }

  /* =====================================================================
   *    gray_move_to
   *
   * =====================================================================
   */
  public FTError.ErrorTag gray_move_to(FTVectorRec to) {
    FTError.ErrorTag error = FTError.ErrorTag.ERR_OK;
    int x;
    int y;
Debug(0, DebugTag.DBG_RENDER, TAG, String.format("gray_move_to: to.x: %d, to.y: %d", to.getX(), to.getY()));

      /* record current cell, if any */
    gray_record_cell();
      /* start to a new position */
    x = RasterUtil.UPSCALE(to.getX());
    y = RasterUtil.UPSCALE(to.getY());
Debug(0, DebugTag.DBG_RENDER, TAG, String.format("gray_move_to2: x(UPSCALE): %d, y(UPSCALE): %d", x, y));
    gray_start_cell(RasterUtil.TRUNC(x), RasterUtil.TRUNC(y));
    this.x = x;
    this.y = y;
Debug(0, DebugTag.DBG_RENDER, TAG, String.format("gray_move_to end: worker.x: %d(%d)(%f), worker.y: %d(%d)(%f)", this.x, this.x/4, this.x/256.0, this.y, this.y/4, this.y/256.0));
    return error;
  }

  /* =====================================================================
   *    gray_line_to
   *
   * =====================================================================
   */
  public FTError.ErrorTag gray_line_to(FTVectorRec to) {
Debug(0, DebugTag.DBG_RENDER, TAG, String.format("gray_line_to: to.x: %d, to.y: %d", to.getX(), to.getY()));
    FTError.ErrorTag error = FTError.ErrorTag.ERR_OK;

Debug(0, DebugTag.DBG_RENDER, TAG, "gray_line_to call gray_render_line");
    gray_render_line(RasterUtil.UPSCALE(to.getX()), RasterUtil.UPSCALE(to.getY()));
Debug(0, DebugTag.DBG_RENDER, TAG, "gray_line_to after call gray_render_line");
    return error;
  }

  /* =====================================================================
   *    gray_conic_to
   *
   * =====================================================================
   */
  public FTError.ErrorTag gray_conic_to(FTVectorRec control, FTVectorRec to) {
Debug(0, DebugTag.DBG_RENDER, TAG, "gray_conic_to");
    FTError.ErrorTag error = FTError.ErrorTag.ERR_OK;

    gray_render_conic(control, to);
Debug(0, DebugTag.DBG_RENDER, TAG, "gray_conic_to end");
    return error;
  }

  /* =====================================================================
   *    gray_cubic_to
   *
   * =====================================================================
   */
  public FTError.ErrorTag gray_cubic_to(FTVectorRec control1, FTVectorRec control2, FTVectorRec to) {
Debug(0, DebugTag.DBG_RENDER, TAG, "gray_cubic_to");
    FTError.ErrorTag error = FTError.ErrorTag.ERR_OK;

    gray_render_cubic(control1, control2, to);
Debug(0, DebugTag.DBG_RENDER, TAG, "gray_cubic_to end");
    return error;
  }

  /* =====================================================================
   *    gray_find_cell
   *
   * =====================================================================
   */
  private TCellRec gray_find_cell() {
Debug(0, DebugTag.DBG_RENDER, TAG, String.format("  gray_find_cell: ras.ex: %d, ras.ey: %d, ras.count_ex: %d, ras.num_cells: %d", this.ex, this.ey, count_ex, num_cells));
    int pcellIdx;
    int cellIdx;
    TCellRec cell = null;
    TCellRec pcell = null;
    int x = ex;
    boolean useYcells = true;
    boolean isYcell = true;

    if (x > count_ex) {
      x = count_ex;
    }
    for(int j = 0; j < ycount; j++) {
      int a = ycells[j] == null ? -1 : ycells[j].getArea();
      int c = ycells[j] == null ? -1 : ycells[j].getCover();
      StringBuffer str = new StringBuffer("");
      str.append(String.format("ycells j: %2d\n\t\tidx: %2d, x: %2d, a: %06x, c: %06x", j,
          ycells[j] == null ? -1 : ycells[j].getSelf_idx(),
          ycells[j] == null ? -1 : ycells[j].getX(),
          a & 0xFFFFFF, c & 0xFFFFFF));
      cell = ycells[j];
      while( cell != null) {
        cell = cell.getNext();
        if (cell != null) {
          str.append(String.format("\n\t\tidx: %2d, x: %2d, a: %06x, c: %06x",
              cell.getSelf_idx(), cell.getX(), cell.getArea() & 0xFFFFFF, cell.getCover() & 0xFFFFFF));
        }
      }
      Debug(0, DebugTag.DBG_RENDER, TAG, str.toString());
    }

    pcellIdx = ey;
    cellIdx = -1;
    for (;;) {
      if (cellIdx == -1) {
        cell = ycells[pcellIdx];
      } else {
        cell = cell.getNext();
      }
      if (cell == null || cell.getX() > x) {
        break;
      }
      if (cell.getX() == x) {
        return cell;
      }
      if (!useYcells) {
        isYcell = false;
      }
      useYcells = false;
      cellIdx = cell.getSelf_idx();
    }
    if (num_cells >= max_cells) {
//FIXME!!        ft_longjmp( worker.jump_buffer, 1 );
      Log.e(TAG, "out of worker.cells: " + num_cells + "!" + max_cells);
    }
    cell = cells[num_cells];
    num_cells = num_cells + 1;
Debug(0, DebugTag.DBG_RENDER, TAG, String.format("new cell: x: %d, worker.ex: %d, worker.ey: %d", x, ex, ey));
    cell.setSelf_idx(num_cells - 1);
    cell.setX(x);
    cell.setArea(0);
    cell.setCover(0);
    if (useYcells) {
      cell.setNext(ycells[pcellIdx]);
//System.out.println(String.format("pcellIdx: %d",  pcellIdx));
      ycells[pcellIdx] = cell;
    } else {
      if (isYcell) {
        cell.setNext(ycells[pcellIdx].getNext());
Debug(0, DebugTag.DBG_RENDER, TAG, String.format("cellIdx. %d pcellIdx: %d",  cellIdx, pcellIdx));
        ycells[pcellIdx].setNext(cell);
Debug(0, DebugTag.DBG_RENDER, TAG, String.format("isYcell: cell idx: %d cell next idx: %d ", cell.getSelf_idx(), cell.getNext() == null ? -1 : cell.getNext().getSelf_idx()));
      } else {
        cell.setNext(cells[cellIdx].getNext());
Debug(0, DebugTag.DBG_RENDER, TAG, String.format("cellIdx. %d pcellIdx: %d",  cellIdx, pcellIdx));
        cells[cellIdx].setNext(cell);
      }
    }
    return cell;
  }

  /* =====================================================================
   *    gray_record_cell
   *
   * =====================================================================
   */
  public void gray_record_cell() {
Debug(0, DebugTag.DBG_RENDER, TAG, String.format("gray_record_cell: ras.invalid: %b, ras.area: %x, ras.cover: %x\n", invalid, area, cover));

    if (!invalid && (area | cover) != 0) {
      TCellRec cell = gray_find_cell();

      cell.setArea(cell.getArea() + area);
      cell.setCover(cell.getCover() + cover);
      Debug(0, DebugTag.DBG_RENDER, TAG, String.format("gray_record_cell2: cell.area: %x, cell.cover: %x worker.area: %x, worker.cover: %x\n", cell.getArea(), cell.getCover(), area, cover));
    }
  }

  /* =====================================================================
   *    gray_set_cell
   *
   * Move the cell pointer to a new position.  We set the `invalid'
   * flag to indicate that the cell isn't part of those we're interested
   * in during the render phase.  This means that:
   *
   * . the new vertical position must be within min_ey..max_ey-1.
   * . the new horizontal position must be strictly less than max_ex
   *
   * Note that if a cell is to the left of the clipping region, it is
   * actually set to the (min_ex-1) horizontal position.
   *
   * =====================================================================
   */
  private void gray_set_cell(int ex, int ey) {
Debug(0, DebugTag.DBG_RENDER, TAG, String.format("gray_set_cell: ex: %d, ey: %d, invalid: %b, worker.ex: %d, worker.ey: %d", ex, ey, invalid, this.ex, this.ey));
      /* All cells that are on the left of the clipping region go to the */
      /* min_ex - 1 horizontal position.                                 */
    ey -= min_ey;
    if (ex > max_ex) {
      ex = max_ex;
    }
    ex -= min_ex;
    if (ex < 0) {
      ex = -1;
    }
      /* are we moving to a different cell ? */
    if (ex != this.ex || ey != this.ey) {
        /* record the current one if it is valid */
      if (!invalid) {
        gray_record_cell();
Debug(0, DebugTag.DBG_RENDER, TAG, String.format("gray_set_cell after call gray_record_cell"));
      }
      area = 0;
      cover = 0;
    }
    this.ex = ex;
    this.ey = ey;
    invalid = (ey >= count_ey || ex >= count_ex);
Debug(0, DebugTag.DBG_RENDER, TAG, String.format("gray_set_cell2: invalid: %b, worker.area: %d, worker.cover: %d, worker.ex: %d, worker.ey: %d, worker.x: %d, worker.y: %d", invalid, area, cover, this.ex, this.ey, this.x, this.y));
Debug(0, DebugTag.DBG_RENDER, TAG, String.format("gray_set_cell end"));
  }

  /* =====================================================================
   *    gray_start_cell
   *
   * =====================================================================
   */
  private void gray_start_cell(int ex, int ey) {
Debug(0, DebugTag.DBG_RENDER, TAG, String.format("gray_start_cell: ex: %d, ey: %d, worker.max_ex: %d, worker.min_ex: %d", ex, ey, max_ex, min_ex));

    if (ex > max_ex) {
      ex = max_ex;
    }
    if (ex < min_ex) {
      ex = min_ex - 1;
    }
    area = 0;
    cover = 0;
    this.ex = ex - min_ex;
    this.ey = ey - min_ey;
    last_ey = RasterUtil.SUBPIXELS(ey);
    invalid = false;
Debug(0, DebugTag.DBG_RENDER, TAG, String.format("gray_start_cell2: worker.x: %d, worker.y: %d, worker.ex: %d, worker.ex: %d, worker.getlast_ey: %d", this.x, this.y, this.ex, this.ey, last_ey));
    gray_set_cell(ex, ey);
  }


  /* =====================================================================
   *    gray_render_scanline
   *
   * =====================================================================
   */
  private void gray_render_scanline(int ey, int x1, int y1, int x2, int y2) {
Debug(0, DebugTag.DBG_RENDER, TAG, String.format("gray_render_scanline0 x1: %d(%d)(%.2f) y1: %d(%d)(%.2f), x2: %d(%d)(%.2f), y2: %d(%d)(%.2f)", x1, x1/4, x1/256.0, y1, y1/4, y1/256.0, x2, x2/4, x2/256.0, y2, y2/4, y2/256.0));
Debug(0, DebugTag.DBG_RENDER, TAG, String.format("gray_render_scanline1 worker.area: 0x%08x, worker.cover: 0x%08x", area, cover));
    int ex1;
    int ex2;
    int fx1;
    int fx2;
    int delta;
    int mod;
    int p;
    int first;
    int dx;
    int incr;

    dx = x2 - x1;
    ex1 = RasterUtil.TRUNC(x1);
    ex2 = RasterUtil.TRUNC(x2);
    fx1 = x1 - RasterUtil.SUBPIXELS(ex1);
    fx2 = x2 - RasterUtil.SUBPIXELS(ex2);
      /* trivial case.  Happens often */
    if (y1 == y2) {
Debug(0, DebugTag.DBG_RENDER, TAG, String.format("call gray_set_cell ex2: %d, ey: %d", ex2, ey));
      gray_set_cell(ex2, ey);
      return;
    }
      /* everything is located in a single cell.  That is easy! */
      /*                                                        */
    if (ex1 == ex2) {
      delta = y2 - y1;
      area = area + ((fx1 + fx2) * delta);
      cover = cover + delta;
Debug(0, DebugTag.DBG_RENDER, TAG, String.format("gray_render_scanline return2: worker.area: 0x%08x, worker.cover: 0x%08x", area, cover));
Debug(0, DebugTag.DBG_RENDER, TAG, String.format("gray_render_scanline return2 ex1 == ex2: %d", ex2));
      return;
    }
      /* ok, we'll have to render a run of adjacent cells on the same */
      /* scanline...                                                  */
      /*                                                              */
    p = (RasterUtil.ONE_PIXEL() - fx1) * (y2 - y1);
    first = RasterUtil.ONE_PIXEL();
    incr = 1;
    if (dx < 0) {
      p = fx1 * (y2 - y1);
      first = 0;
      incr = -1;
      dx = -dx;
    }
    delta = (p / dx);
    mod   = (p % dx);
Debug(0, DebugTag.DBG_RENDER, TAG, String.format("delta: 0x%08x, p: 0x%08x, dx: 0x%08x, mod: 0x%08x", delta, p, dx, mod));
    if (mod < 0) {
      delta--;
      mod += dx;
    }
    area = area + ((fx1 + first) * delta);
    cover = cover + delta;
    ex1 += incr;
Debug(0, DebugTag.DBG_RENDER, TAG, String.format("call gray_set_cell2 ex1: %d, ey: %d", ex1, ey));
    gray_set_cell(ex1, ey);
    y1  += delta;
    if (ex1 != ex2) {
      int lift;
      int rem;

      p = RasterUtil.ONE_PIXEL() * (y2 - y1 + delta);
      lift = (p / dx);
      rem  = (p % dx);
      if (rem < 0) {
        lift--;
        rem += dx;
      }
      mod -= (int)dx;
      while (ex1 != ex2) {
Debug(0, DebugTag.DBG_RENDER, TAG, String.format("ex1: %d ex2: %d incr: %d", ex1, ex2, incr));
        delta = lift;
        mod  += rem;
        if (mod >= 0) {
          mod -= dx;
          delta++;
        }
        area = area + (RasterUtil.ONE_PIXEL() * delta);
        cover = cover + delta;
Debug(0, DebugTag.DBG_RENDER, TAG, String.format("gray_render_scanline3: worker.area: 0x%08x, worker.cover: 0x%08x", area, cover));
        y1 += delta;
        ex1 += incr;
        gray_set_cell(ex1, ey);
      }
    }
    delta = y2 - y1;
Debug(0, DebugTag.DBG_RENDER, TAG, String.format("return end delta: %d", delta));
    area = area  + ((fx2 + RasterUtil.ONE_PIXEL() - first) * delta);
    cover = cover + delta;
  }

  /* =====================================================================
   *    gray_render_line
   *
   * =====================================================================
   */
  private void gray_render_line(int to_x, int to_y) {
    int ey1;
    int ey2;
    int fy1;
    int fy2;
    int mod;
    int dx;
    int dy;
    int x;
    int x2;
    int p;
    int first;
    int delta;
    int rem;
    int lift;
    int incr;

Debug(0, DebugTag.DBG_RENDER, TAG, String.format("gray_render_line: to_x: %d, to_y: %d", to_x, to_y));
    ey1 = RasterUtil.TRUNC(last_ey);
    ey2 = RasterUtil.TRUNC(to_y);     /* if (ey2 >= ras.max_ey) ey2 = ras.max_ey-1; */
    fy1 = (this.y - last_ey);
    fy2 = (to_y - RasterUtil.SUBPIXELS(ey2));
    dx = to_x - this.x;
    dy = to_y - this.y;
      /* XXX: we should do something about the trivial case where dx == 0, */
      /*      as it happens very often!                                    */

      /* perform vertical clipping */
    {
      int min;
      int max;

      min = ey1;
      max = ey2;
      if (ey1 > ey2) {
        min = ey2;
        max = ey1;
      }
      if (min >= max_ey || max < min_ey) {
        this.x = to_x;
        this.y = to_y;
        last_ey = RasterUtil.SUBPIXELS(ey2);
Debug(0, DebugTag.DBG_RENDER, TAG, "gray_render_line return 1");
        return;
      }
    }
      /* everything is on a single scanline */
    if (ey1 == ey2) {
      gray_render_scanline(ey1, this.x, fy1, to_x, fy2);
      this.x = to_x;
      this.y = to_y;
      last_ey = RasterUtil.SUBPIXELS(ey2);
Debug(0, DebugTag.DBG_RENDER, TAG, "gray_render_line return 2");
      return;
    }
      /* vertical line - avoid calling gray_render_scanline */
    incr = 1;
    if (dx == 0) {
      int ex = RasterUtil.TRUNC(this.x);
      int two_fx = ((this.x - RasterUtil.SUBPIXELS(ex)) << 1);
      int area;

      first = RasterUtil.ONE_PIXEL();
      if (dy < 0) {
        first = 0;
        incr  = -1;
      }
      delta = first - fy1;
      this.area = this.area  + two_fx * delta;
      this.cover = this.cover + delta;
      ey1 += incr;
      gray_set_cell(ex, ey1);
      delta = (first + first - RasterUtil.ONE_PIXEL());
      area = two_fx * delta;
      while (ey1 != ey2) {
        this.area = this.area + area;
        this.cover = this.cover + delta;
        ey1 += incr;
Debug(0, DebugTag.DBG_RENDER, TAG, "gray_render_line call gray_set_cell while");
        gray_set_cell(ex, ey1);
      }
      delta = (fy2 - RasterUtil.ONE_PIXEL() + first);
      this.area = this.area + two_fx * delta;
      this.cover = this.cover + delta;
      this.x = to_x;
      this.y = to_y;
      last_ey = RasterUtil.SUBPIXELS(ey2);
Debug(0, DebugTag.DBG_RENDER, TAG, "gray_render_line return 3");
      return;
    }
      /* ok, we have to render several scanlines */
    p = (RasterUtil.ONE_PIXEL() - fy1) * dx;
    first = RasterUtil.ONE_PIXEL();
    incr = 1;
    if (dy < 0) {
      p = fy1 * dx;
      first = 0;
      incr = -1;
      dy = -dy;
    }
    delta = p / dy;
    mod = p % dy;
    if (mod < 0) {
      delta--;
      mod += dy;
    }
    x = this.x + delta;
Debug(0, DebugTag.DBG_RENDER, TAG, "gray_render_line call gray_render_scanline 1");
    gray_render_scanline(ey1, this.x, fy1, x, first);
    ey1 += incr;
    gray_set_cell(RasterUtil.TRUNC(x), ey1);
    if (ey1 != ey2) {
      p = RasterUtil.ONE_PIXEL() * dx;
      lift = (p / dy);
      rem = (p % dy);
      if (rem < 0) {
        lift--;
        rem += dy;
      }
      mod -= dy;
      while (ey1 != ey2) {
        delta = lift;
        mod += rem;
        if (mod >= 0) {
          mod -= dy;
          delta++;
        }
        x2 = x + delta;
Debug(0, DebugTag.DBG_RENDER, TAG, "gray_render_line call gray_render_scanline 2");
        gray_render_scanline(ey1, x, RasterUtil.ONE_PIXEL() - first, x2, first);
        x = x2;
        ey1 += incr;
        gray_set_cell(RasterUtil.TRUNC(x), ey1);
      }
    }
Debug(0, DebugTag.DBG_RENDER, TAG, "gray_render_line call gray_render_scanline 3");
    gray_render_scanline(ey1, x, RasterUtil.ONE_PIXEL() - first, to_x, fy2);
    this.x = to_x;
    this.y = to_y;
    last_ey = RasterUtil.SUBPIXELS(ey2);
Debug(0, DebugTag.DBG_RENDER, TAG, "gray_render_line end");
  }

  /* =====================================================================
   *    gray_split_conic
   *
   * =====================================================================
   */
  private void gray_split_conic(FTVectorRec[] base, int arcIdx) {
Debug(0, DebugTag.DBG_RENDER, TAG, "gray_split_conic");
    int a;
    int b;

    base[arcIdx + 4].setX(base[arcIdx + 2].getX());
    b = base[arcIdx + 1].getX();
    base[arcIdx + 3].setX((base[arcIdx + 2].getX() + b) / 2);
    a = base[arcIdx + 3].getX();
    base[arcIdx + 1].setX((base[arcIdx + 0].getX() + b) / 2);
    b = base[arcIdx + 1].getX();
    base[arcIdx + 2].setX((a + b) / 2);
    base[arcIdx + 4].setY(base[arcIdx + 2].getY());
    b = base[arcIdx + 1].getY();
    base[arcIdx + 3].setY((base[arcIdx + 2].getY() + b) / 2);
    a = base[arcIdx + 3].getY();
    base[arcIdx + 1].setY((base[arcIdx + 0].getY() + b) / 2);
    b = base[arcIdx + 1].getY();
    base[arcIdx + 2].setY((a + b) / 2);
  }

  /* =====================================================================
   *    gray_render_conic
   *
   * =====================================================================
   */
  private void gray_render_conic(FTVectorRec control, FTVectorRec to) {
    int dx;
    int dy;
    int min;
    int max;
    int y;
    int top;
    int level;
    int[] levels;
    FTVectorRec[] arc;
    int arcIdx = 0;
    boolean doDraw = false;

Debug(0, DebugTag.DBG_RENDER, TAG, "gray_render_conic");
    levels = lev_stack;
    arc = bez_stack;
    arc[arcIdx + 0].setX(RasterUtil.UPSCALE(to.getX()));
    arc[arcIdx + 0].setY(RasterUtil.UPSCALE(to.getY()));
    arc[arcIdx + 1].setX(RasterUtil.UPSCALE(control.getX()));
    arc[arcIdx + 1].setY(RasterUtil.UPSCALE(control.getY()));
    arc[arcIdx + 2].setX(this.x);
    arc[arcIdx + 2].setY(this.y);
    top = 0;
    dx = FTCalc.FT_ABS(arc[arcIdx + 2].getX() + arc[arcIdx].getX() - 2 * arc[arcIdx + 1].getX());
    dy = FTCalc.FT_ABS(arc[arcIdx + 2].getY() + arc[arcIdx].getY() - 2 * arc[arcIdx + 1].getY());
    if (dx < dy) {
      dx = dy;
    }
    if (dx < RasterUtil.ONE_PIXEL() / 4) {
      doDraw = true;
    }
    if (!doDraw) {
        /* short-cut the arc that crosses the current band */
      min = max = arc[arcIdx + 0].getY();
      y = arc[arcIdx + 1].getY();
      if (y < min) {
        min = y;
      }
      if (y > max) {
        max = y;
      }
      y = arc[arcIdx + 2].getY();
      if (y < min) {
        min = y;
      }
      if (y > max) {
        max = y;
      }
      if (RasterUtil.TRUNC(min) >= max_ey || RasterUtil.TRUNC(max) < min_ey) {
        doDraw = true;
      }
    }
    if (!doDraw) {
      level = 0;
      do {
        dx >>= 2;
        level++;
      } while (dx > RasterUtil.ONE_PIXEL() / 4);
      levels[0] = level;
    }
    do {
      if (!doDraw) {
        level = levels[top];
        if (level > 0) {
          gray_split_conic(arc, arcIdx);
          arcIdx += 2;
          top++;
          levels[top] = levels[top - 1] = level - 1;
Debug(0, DebugTag.DBG_RENDER, TAG, String.format("gray_render_conic !doDraw continue level: %d", level));
          continue;
        }
      }
      doDraw = false;
Debug(0, DebugTag.DBG_RENDER, TAG, String.format("gray_render_conic call gray_render_line top: %d", top));

      gray_render_line(arc[arcIdx + 0].getX(), arc[arcIdx + 0].getY());
Debug(0, DebugTag.DBG_RENDER, TAG, String.format("gray_render_conic call after gray_render_line top: %d", top));
      top--;
      arcIdx -= 2;
    } while ( top >= 0 );
Debug(0, DebugTag.DBG_RENDER, TAG, String.format("gray_render_conic end top: %d", top));
  }

  /* =====================================================================
   *    gray_split_cubic
   *
   * =====================================================================
   */
  private void gray_split_cubic(FTVectorRec[] base, int arcIdx) {
Debug(0, DebugTag.DBG_RENDER, TAG, "gray_split_cubic");
    int a;
    int b;
    int c;
    int d;

    base[arcIdx + 6].setX(base[arcIdx + 3].getX());
    c = base[arcIdx + 1].getX();
    d = base[arcIdx + 2].getX();
    a = (base[arcIdx + 0].getX() + c) / 2;
    base[arcIdx + 1].setX(a);
    b = (base[arcIdx + 3].getX() + d) / 2;
    base[arcIdx + 5].setX(b);
    c = (c + d) / 2;
    a = (a + c) / 2;
    base[arcIdx + 2].setX(a);
    b = (b + c) / 2;
    base[arcIdx + 4].setX(b);
    base[arcIdx + 3].setX((a + b) / 2);
    base[arcIdx + 6].setY(base[arcIdx + 3].getY());
    c = base[arcIdx + 1].getY();
    d = base[arcIdx + 2].getY();
    a = (base[arcIdx + 0].getY() + c) / 2;
    base[arcIdx + 1].setY(a);
    b = (base[arcIdx + 3].getY() + d) / 2;
    base[arcIdx + 5].setY(b);
    c = (c + d) / 2;
    a = (a + c) / 2;
    base[arcIdx + 2].setY(a);
    b = (b + c) / 2;
    base[arcIdx + 4].setY(b);
    base[arcIdx + 3].setY((a + b) / 2);
  }

  /* =====================================================================
   *    gray_render_cubic
   *
   * =====================================================================
   */
  private void gray_render_cubic(FTVectorRec control1, FTVectorRec control2, FTVectorRec to) {
    FTVectorRec[] arc;
    int arcIdx = 0;
    int min;
    int max;
    int y;
    boolean noSplit = false;

Debug(0, DebugTag.DBG_RENDER, TAG, "gray_render_cubic");
    arc = bez_stack;
    arc[arcIdx + 0].setX(RasterUtil.UPSCALE(to.getX()));
    arc[arcIdx + 0].setY(RasterUtil.UPSCALE(to.getY()));
    arc[arcIdx + 1].setX(RasterUtil.UPSCALE(control2.getX()));
    arc[arcIdx + 1].setY(RasterUtil.UPSCALE(control2.getY()));
    arc[arcIdx + 2].setX(RasterUtil.UPSCALE(control1.getX()));
    arc[arcIdx + 2].setY(RasterUtil.UPSCALE(control1.getY()));
    arc[arcIdx + 3].setX(this.x);
    arc[arcIdx + 3].setY(this.y);
      /* Short-cut the arc that crosses the current band. */
    min = max = arc[arcIdx + 0].getY();
    y = arc[arcIdx + 1].getY();
    if (y < min) {
      min = y;
    }
    if (y > max) {
      max = y;
    }
    y = arc[arcIdx + 2].getY();
    if (y < min) {
      min = y;
    }
    if (y > max) {
      max = y;
    }
    y = arc[arcIdx + 3].getY();
    if (y < min) {
      min = y;
    }
    if (y > max) {
      max = y;
    }
    if (RasterUtil.TRUNC(min) >= max_ey || RasterUtil.TRUNC(max) < min_ey) {
Debug(0, DebugTag.DBG_RENDER, TAG, String.format("gray_render_cubic call gray_render_line"));
      gray_render_line(arc[arcIdx].getX(), arc[arcIdx].getY());
      if (arc == bez_stack) {
        return;
      }
      arcIdx -= 3;
    }
    for (;;) {
        /* Decide whether to split or draw. See `Rapid Termination          */
        /* Evaluation for Recursive Subdivision of Bezier Curves' by Thomas */
        /* F. Hain, at                                                      */
        /* http://www.cis.southalabama.edu/~hain/general/Publications/Bezier/Camera-ready%20CISST02%202.pdf */

      noSplit = false;
      {
        int dx;
        int dy;
        int dx_;
        int dy_;
        int dx1;
        int dy1;
        int dx2;
        int dy2;
        int L;
        int s;
        int s_limit;

          /* dx and dy are x and y components of the P0-P3 chord vector. */
        dx = arc[arcIdx + 3].getX() - arc[arcIdx].getX();
        dy = arc[arcIdx + 3].getY() - arc[arcIdx].getY();
          /* L is an (under)estimate of the Euclidean distance P0-P3.       */
          /*                                                                */
          /* If dx >= dy, then r = sqrt(dx^2 + dy^2) can be overestimated   */
          /* with least maximum error by                                    */
          /*                                                                */
          /*   r_upperbound = dx + (sqrt(2) - 1) * dy  ,                    */
          /*                                                                */
          /* where sqrt(2) - 1 can be (over)estimated by 107/256, giving an */
          /* error of no more than 8.4%.                                    */
          /*                                                                */
          /* Similarly, some elementary calculus shows that r can be        */
          /* underestimated with least maximum error by                     */
          /*                                                                */
          /*   r_lowerbound = sqrt(2 + sqrt(2)) / 2 * dx                    */
          /*                  + sqrt(2 - sqrt(2)) / 2 * dy  .               */
          /*                                                                */
          /* 236/256 and 97/256 are (under)estimates of the two algebraic   */
          /* numbers, giving an error of no more than 8.1%.                 */
        dx_ = FTCalc.FT_ABS(dx);
        dy_ = FTCalc.FT_ABS(dy);
          /* This is the same as                     */
          /*                                         */
          /*   L = ( 236 * FT_MAX( dx_, dy_ )        */
          /*       + 97 * FT_MIN( dx_, dy_ ) ) >> 8; */
        L = (dx_ > dy_ ? 236 * dx_ +  97 * dy_ :  97 * dx_ + 236 * dy_) >> 8;
          /* Avoid possible arithmetic overflow below by splitting. */
        if (L > 32767) {
          gray_split_cubic(arc, arcIdx);
          arcIdx += 3;
          continue;
        }
          /* Max deviation may be as much as (s/L) * 3/4 (if Hain's v = 1). */
        s_limit = L * (RasterUtil.ONE_PIXEL() / 6);
          /* s is L * the perpendicular distance from P1 to the line P0-P3. */
        dx1 = arc[arcIdx + 1].getX() - arc[arcIdx].getX();
        dy1 = arc[arcIdx + 1].getY() - arc[arcIdx].getY();
        s = FTCalc.FT_ABS(dy * dx1 - dx * dy1);
        if (s > s_limit) {
          gray_split_cubic(arc, arcIdx);
          arcIdx += 3;
          continue;
        }
          /* s is L * the perpendicular distance from P2 to the line P0-P3. */
        dx2 = arc[arcIdx + 2].getX() - arc[arcIdx].getX();
        dy2 = arc[arcIdx + 2].getY() - arc[arcIdx].getY();
        s = FTCalc.FT_ABS(dy * dx2 - dx * dy2);
        if (s > s_limit) {
          gray_split_cubic(arc, arcIdx);
          arcIdx += 3;
          continue;
        }
          /* Split super curvy segments where the off points are so far
             from the chord that the angles P0-P1-P3 or P0-P2-P3 become
             acute as detected by appropriate dot products. */
        if (dx1 * (dx1 - dx) + dy1 * (dy1 - dy) > 0 ||
            dx2 * (dx2 - dx) + dy2 * (dy2 - dy) > 0) {
          gray_split_cubic(arc, arcIdx);
          arcIdx += 3;
          continue;
        }
          /* No reason to split. */
        noSplit = true;
      }
      if (! noSplit) {
        gray_split_cubic(arc, arcIdx);
        arcIdx += 3;
        continue;
      }
      Debug(0, DebugTag.DBG_RENDER, TAG, String.format("gray_render_cubic 2 call gray_render_line"));
      gray_render_line(arc[arcIdx + 0].getX(), arc[arcIdx + 0].getY());
      if (arc == bez_stack) {
        return;
      }
      arcIdx -= 3;
      bez_stack = arc;
    }
  }

  /* =====================================================================
   *    gray_compute_cbox
   *
   * =====================================================================
   */
  public void gray_compute_cbox() {
    FTVectorRec vec;
................................................................................
      max_ey = 0;
      return;
    }
    min_ex = outline.getPoints()[vecIdx].getX();
    max_ex = outline.getPoints()[vecIdx].getX();
    min_ey = outline.getPoints()[vecIdx].getY();
    max_ey = outline.getPoints()[vecIdx].getY();
Debug(0, DebugTag.DBG_RENDER, TAG, String.format("cbox01: %d %d %d %d", min_ex, min_ey, max_ex, max_ey));
    vecIdx++;
    for ( ; vecIdx < limit; vecIdx++) {
      vec = outline.getPoints()[vecIdx];
      int x = vec.getX();
      int y = vec.getY();

      if (x < min_ex) {
................................................................................
      }
      if (y < min_ey) {
        min_ey = y;
      }
      if (y > max_ey) {
        max_ey = y;
      }
Debug(0, DebugTag.DBG_RENDER, TAG, String.format("cbox11: %d %d", x, y));
Debug(0, DebugTag.DBG_RENDER, TAG, String.format("cbox12: %d %d %d %d", min_ex, min_ey, max_ex, max_ey));
    }
Debug(0, DebugTag.DBG_RENDER, TAG, String.format("cbox2: %d %d %d %d", min_ex, min_ey, max_ex, max_ey));
      /* truncate the bounding box to integer pixels */
    min_ex = min_ex >> 6;
    min_ey = min_ey >> 6;
    max_ex = (max_ex + 63) >> 6;
    max_ey = (max_ey + 63) >> 6;
    Debug(0, DebugTag.DBG_RENDER, TAG, String.format("gray_compute_cbox end: min_ex: %d min_ey: %d max_ex: %d max_ey: %d", min_ex, min_ey, max_ex, max_ey));
  }

  /* ==================== getEx ================================== */
  public int getEx() {
    return ex;
  }

  /* ==================== setEx ================================== */
  public void setEx(int ex) {
    this.ex = ex;
  }

  /* ==================== getEy ================================== */
  public int getEy() {
    return ey;
  }

  /* ==================== setEy ================================== */
  public void setEy(int ey) {
    this.ey = ey;
  }

  /* ==================== getMin_ex ================================== */
  public int getMin_ex() {
    return min_ex;
  }

  /* ==================== setMin_ex ================================== */
  public void setMin_ex(int min_ex) {
    this.min_ex = min_ex;
  }

  /* ==================== getMax_ex ================================== */
  public int getMax_ex() {
    return max_ex;
  }

  /* ==================== setMax_ex ================================== */
  public void setMax_ex(int max_ex) {
    this.max_ex = max_ex;
  }

  /* ==================== getMin_ey ================================== */
  public int getMin_ey() {
    return min_ey;
  }

  /* ==================== setMin_ey ================================== */
  public void setMin_ey(int min_ey) {
    this.min_ey = min_ey;
  }

  /* ==================== getMax_ey ================================== */
  public int getMax_ey() {
    return max_ey;
  }

  /* ==================== setMax_ey ================================== */
  public void setMax_ey(int max_ey) {
    this.max_ey = max_ey;
  }

  /* ==================== getCount_ex ================================== */
  public int getCount_ex() {
    return count_ex;
  }

  /* ==================== setCount_ex ================================== */
  public void setCount_ex(int count_ex) {
    this.count_ex = count_ex;
  }

  /* ==================== getCount_ey ================================== */
  public int getCount_ey() {
    return count_ey;
  }

  /* ==================== setCount_ey ================================== */
  public void setCount_ey(int count_ey) {
    this.count_ey = count_ey;
  }

  /* ==================== getArea ================================== */
  public int getArea() {
    return area;
  }

  /* ==================== setArea ================================== */
  public void setArea(int area) {
    this.area = area;
  }

  /* ==================== getCover ================================== */
  public int getCover() {
    return cover;
  }

  /* ==================== setCover ================================== */
  public void setCover(int cover) {
    this.cover = cover;
  }

  /* ==================== isInvalid ================================== */
  public boolean isInvalid() {
    return invalid;
  }

  /* ==================== setInvalid ================================== */
  public void setInvalid(boolean invalid) {
    this.invalid = invalid;
  }

  /* ==================== getCells ================================== */
  public TCellRec[] getCells() {
    return cells;
  }

  /* ==================== getCell ================================== */
  public TCellRec getCell(int idx) {
    return cells[idx];
  }

  /* ==================== setCells ================================== */
  public void setCells(TCellRec[] cells) {
    this.cells = cells;
  }

  /* ==================== setCell ================================== */
  public void setCell(int idx, TCellRec cell) {
    this.cells[idx] = cell;
  }

  /* ==================== getMax_cells ================================== */
  public int getMax_cells() {
    return max_cells;
  }

  /* ==================== setMax_cells ================================== */
  public void setMax_cells(int max_cells) {
    this.max_cells = max_cells;
  }

  /* ==================== getNum_cells ================================== */
  public int getNum_cells() {
    return num_cells;
  }

  /* ==================== setNum_cells ================================== */
  public void setNum_cells(int num_cells) {
    this.num_cells = num_cells;
  }

  /* ==================== getCx ================================== */
  public int getCx() {
    return cx;
  }

  /* ==================== setCx ================================== */
  public void setCx(int cx) {
    this.cx = cx;
  }

  /* ==================== getCy ================================== */
  public int getCy() {
    return cy;
  }

  /* ==================== setCy ================================== */
  public void setCy(int cy) {
    this.cy = cy;
  }

  /* ==================== getX ================================== */
  public int getX() {
    return x;
  }

  /* ==================== setX ================================== */
  public void setX(int x) {
    this.x = x;
  }

  /* ==================== getY ================================== */
  public int getY() {
    return y;
  }

  /* ==================== setY ================================== */
  public void setY(int y) {
    this.y = y;
  }

  /* ==================== getLast_ey ================================== */
  public int getLast_ey() {
    return last_ey;
  }

  /* ==================== setLast_ey ================================== */
  public void setLast_ey(int last_ey) {
    this.last_ey = last_ey;
  }

  /* ==================== getBez_stack ================================== */
  public FTVectorRec[] getBez_stack() {
    return bez_stack;
  }

  /* ==================== setBez_stack ================================== */
  public void setBez_stack(FTVectorRec[] bez_stack) {
    this.bez_stack = bez_stack;
  }

  /* ==================== getLev_stack ================================== */
  public int[] getLev_stack() {
    return lev_stack;
  }

  /* ==================== setLev_stack ================================== */
  public void setLev_stack(int[] lev_stack) {
    this.lev_stack = lev_stack;
  }

  /* ==================== getOutline ================================== */
  public FTOutlineRec getOutline() {
    return outline;
  }

  /* ==================== setOutline ================================== */
  public void setOutline(FTOutlineRec outline) {
    this.outline = outline;
  }

  /* ==================== getTarget ================================== */
  public FTBitmapRec getTarget() {
    return target;
  }

  /* ==================== setTarget ================================== */
  public void setTarget(FTBitmapRec target) {
    this.target = target;
  }

  /* ==================== getClip_box ================================== */
  public FTBBoxRec getClip_box() {
    return clip_box;
  }

  /* ==================== setClip_box ================================== */
  public void setClip_box(FTBBoxRec clip_box) {
    this.clip_box = clip_box;
  }

  /* ==================== getGray_spans ================================== */
  public FTSpanRec[] getGray_spans() {
    return gray_spans;
  }

  /* ==================== getGray_span ================================== */
  public FTSpanRec getGray_span(int idx) {
    return gray_spans[idx];
  }

  /* ==================== setGray_spans ================================== */
  public void setGray_spans(FTSpanRec[] gray_spans) {
    this.gray_spans = gray_spans;
  }

  /* ==================== setGray_span ================================== */
  public void setGray_span(int idx, FTSpanRec gray_span) {
    this.gray_spans[idx] = gray_span;
  }

  /* ==================== getNum_gray_spans ================================== */
  public int getNum_gray_spans() {
    return num_gray_spans;
  }

  /* ==================== setNum_gray_spans ================================== */
  public void setNum_gray_spans(int num_gray_spans) {
    this.num_gray_spans = num_gray_spans;
  }

  /* ==================== getRender_span_data ================================== */
  public Object getRender_span_data() {
    return render_span_data;
  }

  /* ==================== setRender_span_data ================================== */
  public void setRender_span_data(Object render_span_data) {
    this.render_span_data = render_span_data;
  }

  /* ==================== getSpan_y ================================== */
  public int getSpan_y() {
    return span_y;
  }

  /* ==================== setSpan_y ================================== */
  public void setSpan_y(int span_y) {
    this.span_y = span_y;
  }

  /* ==================== getBand_size ================================== */
  public int getBand_size() {
    return band_size;
  }

  /* ==================== setBand_size ================================== */
  public void setBand_size(int band_size) {
    this.band_size = band_size;
  }

  /* ==================== getBand_shoot ================================== */
  public int getBand_shoot() {
    return band_shoot;
  }

  /* ==================== setBand_shoot ================================== */
  public void setBand_shoot(int band_shoot) {
    this.band_shoot = band_shoot;
  }

  /* ==================== getBuffer ================================== */
  public Object getBuffer() {
    return buffer;
  }

  /* ==================== setBuffer ================================== */
  public void setBuffer(byte[] buffer) {
    this.buffer = buffer;
  }

  /* ==================== getBuffer_size ================================== */
  public int getBuffer_size() {
    return buffer_size;
  }

  /* ==================== setBuffer_size ================================== */
  public void setBuffer_size(int buffer_size) {
    this.buffer_size = buffer_size;
  }

  /* ==================== getYcells ================================== */
  public TCellRec[] getYcells() {
    return ycells;
  }

  /* ==================== getYcell ================================== */
  public TCellRec getYcell(int cell_idx) {
    if (cell_idx < 0) {
      Log.e(TAG, "bad cell_idx: "+cell_idx);
    }
    return ycells[cell_idx];
  }

  /* ==================== setYcells ================================== */
  public void setYcells(TCellRec[] ycells) {
    this.ycells = ycells;
  }

  /* ==================== setYcell ================================== */
  public void setYcell(int idx, TCellRec ycell) {
    this.ycells[idx] = ycell;
  }

  /* ==================== getYcount ================================== */
  public int getYcount() {
    return ycount;
  }

  /* ==================== setYcount ================================== */
  public void setYcount(int ycount) {
    this.ycount = ycount;
  }

}





|









<
<
<
<
<
<
<


<

<






|




<

<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|

<
|
<
<
<
<
<
<
<
|
<
<
<
<
<


|

|


|




|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<




<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<





|












<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<





|







 







|







 







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







 







|







 







|
|

|








<
<
<
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
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
...
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
...
216
217
218
219
220
221
222




























































































































































































































































































































































































































































































































































































































































































































































































































223
224
225
226
227
228
229
...
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
...
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275



276


















































































































































































































































































































































































/* =====================================================================
 *  This Java implementation is derived from FreeType code
 *  Portions of this software are copyright (C) 2014 The FreeType
 *  Project (www.freetype.org).  All rights reserved.
 *
 *  Copyright (C) of the Java implementation 2015
 *  Arnulf Wiedemann: arnulf (at) wiedemann-pri (dot) de
 *
 *  See the file "license.terms" for information on usage and
 *  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 * =====================================================================
 */

package org.apwtcl.apwfreetypelib.aftraster;








import org.apwtcl.apwfreetypelib.aftbase.FTBBoxRec;
import org.apwtcl.apwfreetypelib.aftbase.FTBitmapRec;

import org.apwtcl.apwfreetypelib.aftbase.Flags;

import org.apwtcl.apwfreetypelib.aftutil.FTDebug;
import org.apwtcl.apwfreetypelib.aftutil.FTError;
import org.apwtcl.apwfreetypelib.aftutil.FTTrace;
import org.apwtcl.apwfreetypelib.aftutil.FTVectorRec;
import org.apwtcl.apwfreetypelib.aftutil.RasterUtil;

public class grayTWorkerRec extends grayTWorkerSweepRec {
  private static int oid = 0;

  private int id;
  private static String TAG = "grayTWorkerRec";





































  /* ==================== grayTWorkerRec ================================== */
  public grayTWorkerRec() {

  }













  /* ==================== mySelf ================================== */
  public String mySelf() {
    return TAG + "!" + id + "!";
  }

  /* ==================== toString ===================================== */
  public String toString() {
    return mySelf() + "!";
  }

  /* ==================== toDebugString ===================================== */
  public String toDebugString() {
    StringBuffer str = new StringBuffer(mySelf() + "\n");
























    return str.toString();
  }

  /* =====================================================================























































































































































































   *    gray_convert_glyph_inner
   *
   * =====================================================================
   */
  public FTError.ErrorTag gray_convert_glyph_inner() {
    Debug(0, DebugTag.DBG_RENDER, TAG, "gray_convert_glyph_inner");
    FTError.ErrorTag error = FTError.ErrorTag.ERR_OK;

//      if (ft_setjmp(ras.jump_buffer) == 0) {
    error = outline.FTOutlineDecompose(this);
    gray_record_cell();
//      } else {
//        error = FT_THROW( Memory_Overflow );
//      }
    return error;
  }

  /* =====================================================================
























































































































































   *    gray_convert_glyph
   *
   * =====================================================================
   */
  public FTError.ErrorTag gray_convert_glyph() {
    Debug(0, DebugTag.DBG_RENDER, TAG, "gray_convert_glyph");
    FTError.ErrorTag error = FTError.ErrorTag.ERR_OK;
    grayTBandRec[] bands = new grayTBandRec[40];
    int bandIdx = 0;
    int n;
    int i;
    int num_bands;
    int min;
................................................................................
    if (num_bands >= 39) {
      num_bands = 39;
    }
    band_shoot = 0;
    min = min_ey;
    max_y = max_ey;
    for (n = 0; n < num_bands; n++, min = max) {
      Debug(0, DebugTag.DBG_RENDER, TAG, "num_bands: n: "+n+" "+num_bands);
      max = min + band_size;
      if (n == num_bands - 1 || max > max_y) {
        max = max_y;
      }
      bands[0].setMin(min);
      bands[0].setMax(max);
      bandIdx = 0;
................................................................................
    }
    if (band_shoot > 8 && band_size > 16) {
      band_size = band_size / 2;
    }
    return error;
  }





























































































































































































































































































































































































































































































































































































































































































































































































































  /* =====================================================================
   *    gray_compute_cbox
   *
   * =====================================================================
   */
  public void gray_compute_cbox() {
    FTVectorRec vec;
................................................................................
      max_ey = 0;
      return;
    }
    min_ex = outline.getPoints()[vecIdx].getX();
    max_ex = outline.getPoints()[vecIdx].getX();
    min_ey = outline.getPoints()[vecIdx].getY();
    max_ey = outline.getPoints()[vecIdx].getY();
    Debug(0, DebugTag.DBG_RENDER, TAG, String.format("cbox01: %d %d %d %d", min_ex, min_ey, max_ex, max_ey));
    vecIdx++;
    for ( ; vecIdx < limit; vecIdx++) {
      vec = outline.getPoints()[vecIdx];
      int x = vec.getX();
      int y = vec.getY();

      if (x < min_ex) {
................................................................................
      }
      if (y < min_ey) {
        min_ey = y;
      }
      if (y > max_ey) {
        max_ey = y;
      }
      Debug(0, DebugTag.DBG_RENDER, TAG, String.format("cbox11: %d %d", x, y));
      Debug(0, DebugTag.DBG_RENDER, TAG, String.format("cbox12: %d %d %d %d", min_ex, min_ey, max_ex, max_ey));
    }
    Debug(0, DebugTag.DBG_RENDER, TAG, String.format("cbox2: %d %d %d %d", min_ex, min_ey, max_ex, max_ey));
      /* truncate the bounding box to integer pixels */
    min_ex = min_ex >> 6;
    min_ey = min_ey >> 6;
    max_ex = (max_ex + 63) >> 6;
    max_ey = (max_ey + 63) >> 6;
    Debug(0, DebugTag.DBG_RENDER, TAG, String.format("gray_compute_cbox end: min_ex: %d min_ey: %d max_ex: %d max_ey: %d", min_ex, min_ey, max_ex, max_ey));
  }




}