1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
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
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
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
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
|
/*
WARNING: This file was generated by dkct.
Changes you make here will be lost if dkct is run again!
You should modify the original source and run dkct on it.
Original source: dk3bm.ctr
*/
/*
Copyright (C) 2011-2017, Dirk Krause
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above opyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the author nor the names of contributors may be used
to endorse or promote products derived from this software without specific
prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/** @file dk3bm.c The dk3bm module.
*/
#line 106 "dk3bm.ctr"
#include "dk3all.h"
#include "dk3bif.h"
#include "dk3bifa.h"
#include "dk3bmeps.h"
#include "dk3bmeo.h"
#include "dk3bmj.h"
#include "dk3pdf.h"
#include "dk3bm.h"
#if DK3_USE_WX
#include <wxbmeps.h>
#endif
#line 124 "dk3bm.ctr"
/** Don't debug the module.
*/
#define DK3BM_DEBUG 0
/** File name suffixes for output files.
*/
dkChar const * const dk3bm_output_suffixes[] = {
dkT(".ps"),
dkT(".eps"),
dkT(".pdf"),
dkT(".bb")
};
/** Everything between 72-epsilon and 72+epsilon is seen as 72 dpi.
Some file formats store the resolution in pixels per meter as
integer numbers.
If 72.0 is scaled from one inch to a meter and rounded to
integer, the rounding error maximum is one. If one dot per meter
(the probable rounding error) is converted back to dot per inch
the result is 0.254.
*/
static double const dk3bm_epsilon = 0.254;
/** Keywords used by the module.
*/
static char const * const dk3bm_c8_kw[] = {
/* 0 */ "\n",
/* 1 */ " ",
/* 2 */ "{\n",
/* 3 */ "} exec\n",
/* 4 */ "gsave\n",
/* 5 */ "grestore\n",
/* 6 */ "showpage\n",
/* 7 */ "13 dict begin\n",
/* 8 */ "end\n",
/* 9 */ "%lg %lg translate\n",
/* 10 */ "%d rotate\n",
/* 11 */ "%lg %lg scale\n",
/* 12 */ "%ld %ld scale\n",
/* 13 */ "%!PS-Adobe-2.0",
/* 14 */ "%!PS-Adobe-3.0",
/* 15 */ " EPSF-2.0",
/* 16 */ " EPSF-3.0",
/* 17 */ "<<\n",
/* 18 */ ">>\nimage\n",
/* 19 */ "/ImageType 1\n",
/* 20 */ "/DeviceRGB setcolorspace\n",
/* 21 */ "/DeviceGray setcolorspace\n",
/* 22 */ "/fa currentfile /ASCII85Decode filter def\n",
/* 23 */ "fa flushfile fa closefile\n",
/* 24 */ "/fb fa /RunLengthDecode filter def\n",
/* 25 */ "fb closefile\n",
/* 26 */ "/fb fa /FlateDecode filter def\n",
/* 27 */ "/fb fa << >> /DCTDecode filter def\n",
/* 28 */ "/Width %ld\n",
/* 29 */ "/Height %ld\n",
/* 30 */ "/ImageMatrix [%ld 0 0 -%ld 0 %ld]\n",
/* 31 */ "%%%%BoundingBox: 0 0 %ld %ld\n",
/* 32 */ "%%LanguageLevel: 2\n",
/* 33 */ "%%LanguageLevel: 3\n",
/* 34 */ "/BitsPerComponent %u\n",
/* 35 */ "/MultipleDataSources true\n",
/* 36 */ "/MultipleDataSources false\n",
/* 37 */ "/DataSource fb\n",
/* 38 */ "/DataSource fa\n",
/* 39 */ "/DataSource [\n",
/* 40 */ "{ fb sr readstring pop }\n",
/* 41 */ "{ fb sg readstring pop }\n",
/* 42 */ "{ fb sb readstring pop }\n",
/* 43 */ "]\n",
/* 44 */ "/Decode [0 1]\n",
/* 45 */ "/Decode [0 1 0 1 0 1]\n",
/* 46 */ "/Interpolate true\n",
/* 47 */ "/Interpolate false\n",
/* 48 */ "/sr %ld string def\n",
/* 49 */ "/sg %ld string def\n",
/* 50 */ "/sb %ld string def\n",
/* 51 */ "%%Creator: bmeps3\n",
/* 52 */ "%%Title: ",
/* 53 */ "%%%%Pages: %u\n",
/* 54 */ "%%PageOrder: Ascend\n",
/* 55 */ "%%DocumentData: Clean7Bit\n",
/* 56 */ "%%EndComments\n",
/* 57 */ "%%BeginProlog\n",
/* 58 */ "%%EndProlog\n",
/* 59 */ "%%BeginSetup\n",
/* 60 */ "%%EndSetup\n",
/* 61 */ "%%Trailer\n",
/* 62 */ "%%EOF\n",
/* 63 */ "%%%%Page: %u %u\n",
/* 64 */ "%%BeginFeature: *PageSize BmepsPage\n",
/* 65 */ "%%EndFeature\n",
/* 66 */ "<< /PageSize [%ld %ld] /ImagingBBox null >> setpagedevice\n",
/* 67 */ "%%BeginFeature: *Duplex DuplexNoTumble\n",
/* 68 */ "<< /Duplex true /Tumble false >> setpagedevice\n",
/* 69 */ "%%BeginFeature: *Duplex DuplexTumble\n",
/* 70 */ "<< /Duplex true /Tumble true >> setpagedevice\n",
/* 71 */ "0 setgray\nnewpath\n",
/* 72 */ "%lg %lg moveto\n",
/* 73 */ "%lg %lg lineto\n",
/* 74 */ "closepath\nfill\n",
/* 75 */ "0.8 setgray\nnewpath\n",
/* 76 */ "1 setgray\nnewpath\n",
/* 77 */ "%lg setlinewidth\n",
/* 78 */ "newpath\n",
/* 79 */ "stroke\n",
/* 80 */ "/fb fa <<\n",
/* 81 */ ">> /FlateDecode filter def\n",
/* 82 */ "/Predictor %d\n",
/* 83 */ "/Columns %ld\n",
/* 84 */ "/Colors 3\n",
/* 85 */ "/Colors 1\n",
/* 86 */ "/DeviceCMYK setcolorspace\n",
/* 87 */ "/Decode [0 1 0 1 0 1 0 1]\n",
/* 88 */ "/Decode [1 0 1 0 1 0 1 0]\n",
};
/** Convert long to double.
@param l Long value to convert.
@return Conversion result.
*/
static
double
dk3bm_l_to_d(long l)
{
return ((double)l);
}
/** Correct output buffer.
If LC_NUMERIC has a wrong setting it might produce
a comma instead of a decimal dot for floating point numbers.
The PS and PDF language specification always requires a dot,
independent of the users language setting.
@param s Buffer start address.
*/
static
void
dk3bm_correct_output_buffer(char *s)
{
char *ptr; /* Temporary pointer to traverse string. */
#line 278 "dk3bm.ctr"
if(s) {
ptr = s;
while(*ptr) {
if(*ptr == ',') { *ptr = '.'; }
ptr++;
}
}
#line 285 "dk3bm.ctr"
}
/** Write PS header for document.
@param job Conversion job.
@param pages Number of pages in the print job.
*/
static
void
dk3bm_ps_document_header(dk3_bm_conversion_job_t *job, size_t pages)
{
char fnb[DK3_MAX_PATH]; /* Buffer used to construct output. */
char outputbuffer[256]; /* Another buffer for output. */
dkChar const *ptr; /* Used to traverse file name. */
dkChar const *nb; /* Short file name. */
int ie; /* Input encoding. */
#line 303 "dk3bm.ctr"
fputs(dk3bm_c8_kw[((job->opt)->psl == 3) ? 14 : 13], job->dfile);
if((job->opt)->dr == DK3_BMEPS_DRIVER_EPS) {
fputs(dk3bm_c8_kw[((job->opt)->psl == 3) ? 16 : 15], job->dfile);
}
fputs(dk3bm_c8_kw[0], job->dfile);
#line 308 "dk3bm.ctr"
fprintf(job->dfile, dk3bm_c8_kw[31], job->x_size, job->y_size);
fputs(dk3bm_c8_kw[((job->opt)->psl == 3) ? 33 : 32], job->dfile);
if((job->opt)->dsc) {
fputs(dk3bm_c8_kw[51], job->dfile);
ptr = job->sfn;
if(ptr) {
nb = NULL;
while(*ptr) {
if((*ptr == dkT('\\')) || (*ptr == dkT('/'))) {
nb = ptr;
}
ptr++;
}
if(nb) {
nb++;
} else {
nb = job->sfn;
}
ie = dk3app_get_encoding((job->opt)->app);
if(dk3str_to_c8p_app(fnb,sizeof(fnb),nb,ie,(job->opt)->app)) {
fputs(dk3bm_c8_kw[52], job->dfile);
fputc('(', job->dfile);
fputs(fnb, job->dfile);
fputc(')', job->dfile);
fputs(dk3bm_c8_kw[0], job->dfile);
}
}
sprintf(fnb, dk3bm_c8_kw[53], (unsigned)pages);
fputs(fnb, job->dfile);
for(ie = 54; ie <= 59; ie++) {
fputs(dk3bm_c8_kw[ie], job->dfile);
}
switch((job->opt)->dr) {
case DK3_BMEPS_DRIVER_PS: {
switch((job->opt)->mode) {
case DK3_BMEPS_MODE_DOCUMENT: {
fputs(dk3bm_c8_kw[64], job->dfile);
sprintf(outputbuffer, dk3bm_c8_kw[66], job->x_size, job->y_size);
fputs(outputbuffer, job->dfile);
fputs(dk3bm_c8_kw[65], job->dfile);
if((job->opt)->duplex) {
if((job->opt)->tumble) {
fputs(dk3bm_c8_kw[69], job->dfile);
fputs(dk3bm_c8_kw[70], job->dfile);
fputs(dk3bm_c8_kw[65], job->dfile);
} else {
fputs(dk3bm_c8_kw[67], job->dfile);
fputs(dk3bm_c8_kw[68], job->dfile);
fputs(dk3bm_c8_kw[65], job->dfile);
}
}
} break;
}
} break;
}
fputs(dk3bm_c8_kw[60], job->dfile);
} else {
if((job->opt)->duplex) {
if((job->opt)->tumble) {
fputs(dk3bm_c8_kw[70], job->dfile);
} else {
fputs(dk3bm_c8_kw[68], job->dfile);
}
}
}
#line 373 "dk3bm.ctr"
}
/** Produce footer for PS print job.
@param job Conversion job.
*/
static
void
dk3bm_ps_document_footer(dk3_bm_conversion_job_t *job)
{
#line 385 "dk3bm.ctr"
if((job->opt)->dsc) {
fputs(dk3bm_c8_kw[61], job->dfile);
fputs(dk3bm_c8_kw[62], job->dfile);
}
switch((job->opt)->dr) {
case DK3_BMEPS_DRIVER_PS: {
switch((job->opt)->mode) {
case DK3_BMEPS_MODE_DOCUMENT: {
fputc(0x04, job->dfile);
} break;
}
} break;
}
#line 398 "dk3bm.ctr"
}
/** Copy DCT encoded data directly from input to output.
@param of Output filter.
@param dctin Input file containing DCT-encoded data.
@param job Conversion job.
@return 1 on success, 0 on error.
*/
static
int
dk3bm_copy_dct_data(
dk3_of_t *of,
FILE *dctin,
dk3_bm_conversion_job_t *job
)
{
char bu[4096]; /* Buffer for data read from file. */
size_t rb; /* Number of bytes read. */
int back = 1;
int cc; /* Flag: Can continue. */
#line 421 "dk3bm.ctr"
cc = 1;
while(cc) {
cc = 0;
rb = dk3sf_fread_app((void *)bu, 1, sizeof(bu), dctin, (job->opt)->app);
if(rb > 0) {
cc = 1;
if(!dk3of_write_bytes(of, (unsigned char *)bu, rb)) {
back = 0;
cc = 0;
/* ERROR: Failed to write data! */
dk3bmj_log_1(
(job->opt)->app, DK3_LL_ERROR, job->msg, 58, DK3_BMJ_LOG_BOTH, job
);
}
}
}
#line 437 "dk3bm.ctr"
return back;
}
/** Write flate filter definition with predictor.
@param job Conversion job.
*/
static
void
dk3bm_define_flate_with_predictor(dk3_bm_conversion_job_t *job)
{
char outputbuffer[256]; /* Buffer to construct output. */
int i = 0; /* Predictor ID in PS and PDF. */
#line 452 "dk3bm.ctr"
fputs(dk3bm_c8_kw[80], job->dfile);
/* Predictor Columns Colors BitsPerComponent */
switch((job->opt)->pred) {
case DK3_COMPRESSION_PREDICTOR_TIFF: {
i = 2;
} break;
case DK3_COMPRESSION_PREDICTOR_PNG_SUB: {
i = 11;
} break;
case DK3_COMPRESSION_PREDICTOR_PNG_UP: {
i = 12;
} break;
case DK3_COMPRESSION_PREDICTOR_PNG_AVERAGE: {
i = 13;
} break;
case DK3_COMPRESSION_PREDICTOR_PNG_PAETH: {
i = 14;
} break;
}
sprintf(outputbuffer, dk3bm_c8_kw[82], i);
fputs(outputbuffer, job->dfile);
sprintf(outputbuffer, dk3bm_c8_kw[83], dk3bif_get_width(job->bif));
fputs(outputbuffer, job->dfile);
sprintf(outputbuffer, dk3bm_c8_kw[34], job->bpc);
fputs(outputbuffer, job->dfile);
if(job->procedure == DK3_BMEPS_RGB_FLATE) {
fputs(dk3bm_c8_kw[84], job->dfile);
} else {
fputs(dk3bm_c8_kw[85], job->dfile);
}
fputs(dk3bm_c8_kw[81], job->dfile);
#line 483 "dk3bm.ctr"
}
/** Write one unsigned character.
@param of Output filter.
@param v Value to write to output.
*/
static
void
dk3bm_write_uc(dk3_of_t *of, dk3_bif_pixel_t v)
{
unsigned char ucv; /* Byte to write. */
#line 497 "dk3bm.ctr"
ucv = (unsigned char)v;
dk3of_write_bytes(of, &ucv, 1);
#line 499 "dk3bm.ctr"
}
/** Produce PS for image or object.
The following components of job must be set:
x_size, y_size, x_translate, y_translate, x_0, x_1, y_0, y_1,
x_scale, y_scale, do_translate, do_rotate, do_float_scale.
@param job Conversion job.
@return 1 on success, 0 on error.
*/
static
int
dk3bm_job_produce_img_job_real_ps(dk3_bm_conversion_job_t *job)
{
char outputbuffer[256]; /* Buffer to prepare output. */
FILE *dctin; /* Input file containing DCT data. */
dk3_stream_t *os; /* Output stream. */
dk3_of_t *of; /* Output filter. */
long bitsperline; /* Bits per line. */
long bytesperline; /* Bytes per line. */
dk3_bif_coord_t w; /* Image width. */
dk3_bif_coord_t h; /* Image height. */
dk3_bif_coord_t x; /* Current x. */
dk3_bif_coord_t y; /* Current y. */
dk3_bif_pixel_t v; /* Current point value. */
dk3_bif_pixel_t pl; /* Left pixel. */
dk3_bif_pixel_t pu; /* Upper pixel. */
dk3_bif_pixel_t plu; /* Left upper pixel. */
size_t nbits; /* Number of bits per component. */
int back = 0;
int analysis_type = 0; /* Analysis to perform. */
int use_dct = 0; /* Flag: DCT used. */
int me = 0; /* Flag: Math error. */
int alphain = 0; /* Flag: Alpha channel. */
#if TRACE_DEBUG || VERSION_BEFORE_20150821
int colorin = 0; /* Flag: Color image. */
#endif
#if DK3_USE_WX
int minpb; /* Original min progress bar value. */
int maxpb; /* Original max progress bar value. */
int pbmin; /* Min progress bar value. */
int pbmax; /* Max progress bar value. */
#endif
#line 544 "dk3bm.ctr"
#if DK3_USE_WX
minpb = job->minpb;
maxpb = job->maxpb;
#endif
if(job->dfile) {
#line 549 "dk3bm.ctr"
alphain = 0;
switch(dk3bif_get_color_space(job->bif)) {
case DK3_COLOR_SPACE_GRAY_ALPHA:
case DK3_COLOR_SPACE_RGBA:
{
alphain = 1;
#line 555 "dk3bm.ctr"
} break;
}
#if VERSION_BEFORE_20150821
/* Already initialized to 0 */
colorin = 0;
#endif
switch(dk3bif_get_color_space(job->bif)) {
case DK3_COLOR_SPACE_GRAY:
case DK3_COLOR_SPACE_GRAY_ALPHA: {
} break;
default: {
/* Static code analysis: Dead assignment */
/* Variable used when tracing, not in normaly build */
#if VERSION_BEFORE_20150821
colorin = 1;
#line 570 "dk3bm.ctr"
#endif
} break;
}
/*
Conversion defaults.
*/
w = dk3bif_get_width(job->bif);
h = dk3bif_get_height(job->bif);
job->procedure = DK3_BMEPS_GRAY_UNCOMPRESSED;
job->bpc = 8;
/*
Decisions about compression, bpc, colors.
*/
analysis_type = 0;
switch(dk3bif_get_type(job->bif)) {
case DK3_BIF_IMAGE_TYPE_JPEG: {
#line 586 "dk3bm.ctr"
if((job->opt)->dct) {
#line 587 "dk3bm.ctr"
switch(dk3bif_get_bits_per_pixel(job->bif)) {
case 8: case 4: case 2: case 1: {
#line 589 "dk3bm.ctr"
switch(dk3bif_jpeg_get_num_components(job->bif)) {
case 1: {
#line 591 "dk3bm.ctr"
job->procedure = DK3_BMEPS_GRAY_DCT;
job->bpc = dk3bif_get_bits_per_pixel(job->bif);
use_dct = 1;
} break;
case 3: {
#line 596 "dk3bm.ctr"
job->procedure = DK3_BMEPS_RGB_DCT;
job->bpc = dk3bif_get_bits_per_pixel(job->bif);
use_dct = 1;
} break;
case 4: {
#line 601 "dk3bm.ctr"
job->procedure = DK3_BMEPS_CMYK_DCT;
job->bpc = dk3bif_get_bits_per_pixel(job->bif);
use_dct = 1;
} break;
default: {
#line 606 "dk3bm.ctr"
} break;
}
} break;
}
}
} break;
}
if(!(use_dct)) {
if((job->opt)->color) {
switch(dk3bif_get_color_space(job->bif)) {
case DK3_COLOR_SPACE_GRAY:
case DK3_COLOR_SPACE_GRAY_ALPHA: {
} break;
default: {
analysis_type |= DK3_BIF_ANALYSIS_COLOR;
} break;
}
}
if((job->opt)->rbpc) {
analysis_type |= DK3_BIF_ANALYSIS_BITS;
}
if(alphain) {
analysis_type |= DK3_BIF_ANALYSIS_ALPHA;
}
/* PROGRESS: Analyzing image. */
dk3app_log_1((job->opt)->app, DK3_LL_PROGRESS, job->msg, 48);
if(analysis_type) {
#if DK3_USE_WX
dk3bif_analyze_progress(
job->bif, analysis_type, job->pComm, minpb, ((maxpb + minpb)/2)
);
#else
dk3bif_analyze(job->bif, analysis_type);
#endif
}
nbits = dk3bif_get_bits_per_pixel(job->bif);
if((job->opt)->rbpc) { nbits = dk3bif_real_bits_per_pixel(job->bif); }
#if 0
/* 2014-03-22
New algorithms for bits per component detection and reduction.
*/
job->bpc = 1;
if(nbits > 1) {
job->bpc = 2;
if(nbits > 2) {
job->bpc = 4;
if(nbits > 4) {
job->bpc = 8;
if(nbits > 8) {
job->bpc = 12;
}
}
}
}
#else
switch (nbits) {
case 1: { job->bpc = 1; } break;
case 2: { job->bpc = 2; } break;
case 4: { job->bpc = 4; } break;
case 12: { job->bpc = 12; } break;
default: { job->bpc = 8; } break;
}
#endif
/* 2014-03-23
The dk3bifa module generate debug output.
*/
#if 0
/* DEBUG: Analysis results. */
{
dkChar numbuf[128];
dkChar const *msgpart[3];
int convres;
msgpart[0] = (job->msg)[51];
msgpart[1] = (job->msg)[(colorin) ? 49 : 50];
dk3app_log_msg((job->opt)->app, DK3_LL_DEBUG, msgpart, 2);
msgpart[0] = (job->msg)[52];
msgpart[1] = (job->msg)[(dk3bif_real_color(job->bif)) ? 49 : 50];
dk3app_log_msg((job->opt)->app, DK3_LL_DEBUG, msgpart, 2);
msgpart[0] = (job->msg)[53];
msgpart[1] = (job->msg)[(alphain) ? 49 : 50];
dk3app_log_msg((job->opt)->app, DK3_LL_DEBUG, msgpart, 2);
msgpart[0] = (job->msg)[54];
msgpart[1] = (job->msg)[(dk3bif_real_alpha(job->bif)) ? 49 : 50];
dk3app_log_msg((job->opt)->app, DK3_LL_DEBUG, msgpart, 2);
#if VERSION_BEFORE_20140716
dk3sf_sprintf3(numbuf,dkT("%u"),(unsigned)dk3bif_get_bits_per_pixel(job->bif));
msgpart[0] = (job->msg)[55];
msgpart[1] = numbuf;
dk3app_log_msg((job->opt)->app, DK3_LL_DEBUG, msgpart, 2);
dk3sf_sprintf3(numbuf,dkT("%u"),(unsigned)dk3bif_real_bits_per_pixel(job->bif));
msgpart[0] = (job->msg)[56];
msgpart[1] = numbuf;
dk3app_log_msg((job->opt)->app, DK3_LL_DEBUG, msgpart, 2);
dk3sf_sprintf3(numbuf,dkT("%u"),(unsigned)(job->bpc));
msgpart[0] = (job->msg)[57];
msgpart[1] = numbuf;
dk3app_log_msg((job->opt)->app, DK3_LL_DEBUG, msgpart, 2);
#else
convres = dk3ma_um_to_string(
numbuf, DK3_SIZEOF(numbuf,dkChar),
(dk3_um_t)dk3bif_get_bits_per_pixel(job->bif)
);
if (0 != convres) {
msgpart[0] = (job->msg)[55];
msgpart[1] = numbuf;
dk3app_log_msg((job->opt)->app, DK3_LL_DEBUG, msgpart, 2);
}
convres = dk3ma_um_to_string(
numbuf, DK3_SIZEOF(numbuf,dkChar),
(dk3_um_t)dk3bif_real_bits_per_pixel(job->bif)
);
if (0 != convres) {
msgpart[0] = (job->msg)[56];
msgpart[1] = numbuf;
dk3app_log_msg((job->opt)->app, DK3_LL_DEBUG, msgpart, 2);
}
convres = dk3ma_um_to_string(
numbuf, DK3_SIZEOF(numbuf,dkChar), (dk3_um_t)(job->bpc)
);
if (0 != convres) {
msgpart[0] = (job->msg)[57];
msgpart[1] = numbuf;
dk3app_log_msg((job->opt)->app, DK3_LL_DEBUG, msgpart, 2);
}
#endif
}
#endif
#if VERSION_BEFORE_20150821
if(analysis_type & DK3_BIF_ANALYSIS_COLOR) {
colorin = dk3bif_real_color(job->bif);
}
#endif
if(analysis_type & DK3_BIF_ANALYSIS_ALPHA) {
alphain = dk3bif_real_alpha(job->bif);
}
switch(dk3bif_get_color_space(job->bif)) {
case DK3_COLOR_SPACE_GRAY:
case DK3_COLOR_SPACE_GRAY_ALPHA: {
job->procedure = DK3_BMEPS_GRAY_RUNLENGTH;
if((job->opt)->psl >= 3) {
job->procedure = DK3_BMEPS_GRAY_FLATE;
if((job->opt)->pred > DK3_COMPRESSION_PREDICTOR_TIFF) {
job->bpc = 8;
}
}
} break;
default: {
if(dk3bif_real_color(job->bif)) {
job->procedure = DK3_BMEPS_RGB_UNCOMPRESSED;
if((job->opt)->psl >= 3) {
job->procedure = DK3_BMEPS_RGB_FLATE;
if((job->opt)->pred > DK3_COMPRESSION_PREDICTOR_TIFF) {
job->bpc = 8;
}
} else {
bitsperline = dk3ma_l_mul_ok((long)(job->bpc), w, &me);
if(me == 0) {
bytesperline = bitsperline / 8L;
if(bitsperline % 8L) { bytesperline++; }
if(bytesperline < 16384L) {
job->procedure = DK3_BMEPS_RGB_RUNLENGTH;
}
}
}
} else {
job->procedure = DK3_BMEPS_GRAY_RUNLENGTH;
if((job->opt)->psl >= 3) {
job->procedure = DK3_BMEPS_GRAY_FLATE;
if((job->opt)->pred > DK3_COMPRESSION_PREDICTOR_TIFF) {
job->bpc = 8;
}
}
}
} break;
}
}
dk3app_log_1((job->opt)->app, DK3_LL_PROGRESS, job->msg, 76);
#if DK3BM_DEBUG
job->procedure = DK3_BMEPS_RGB_UNCOMPRESSED;
#endif
#if DK3_USE_WX
#line 789 "dk3bm.ctr"
dk3bmj_progress(job->pComm, ((maxpb + minpb)/2));
job->minpb = ((maxpb + minpb) / 2);
pbmin = job->minpb;
pbmax = job->maxpb;
#endif
/*
File header.
*/
if(job->do_header_footer) {
dk3bm_ps_document_header(job, 1);
}
/*
Image.
*/
if((job->opt)->dsc) {
sprintf(
outputbuffer, dk3bm_c8_kw[63],
(unsigned)(job->currentPage),
(unsigned)(job->currentPage)
);
fputs(outputbuffer, job->dfile);
}
fputs(dk3bm_c8_kw[2], job->dfile); /* { */
fputs(dk3bm_c8_kw[4], job->dfile); /* gsave */
/*
Translate, rotate, scale.
*/
if(job->do_translate) {
sprintf(
outputbuffer, dk3bm_c8_kw[9], job->x_translate, job->y_translate
);
dk3bm_correct_output_buffer(outputbuffer);
fputs(outputbuffer, job->dfile);
}
if(job->do_rotate) {
sprintf(outputbuffer, dk3bm_c8_kw[10], (90 * job->do_rotate));
fputs(outputbuffer, job->dfile);
}
if(job->do_float_scale) {
sprintf(
outputbuffer,
dk3bm_c8_kw[11],
job->x_scale, job->y_scale
);
dk3bm_correct_output_buffer(outputbuffer);
} else {
sprintf(outputbuffer, dk3bm_c8_kw[12], w, h);
}
fputs(outputbuffer, job->dfile);
fputs(dk3bm_c8_kw[7], job->dfile); /* 13 dict begin */
/*
Color space, definitions for data source(s).
*/
switch(job->procedure) {
case DK3_BMEPS_GRAY_UNCOMPRESSED: {
fputs(dk3bm_c8_kw[21], job->dfile);
fputs(dk3bm_c8_kw[22], job->dfile);
} break;
case DK3_BMEPS_RGB_UNCOMPRESSED: {
fputs(dk3bm_c8_kw[20], job->dfile);
fputs(dk3bm_c8_kw[22], job->dfile);
} break;
case DK3_BMEPS_GRAY_RUNLENGTH: {
fputs(dk3bm_c8_kw[21], job->dfile);
fputs(dk3bm_c8_kw[22], job->dfile);
fputs(dk3bm_c8_kw[24], job->dfile);
} break;
case DK3_BMEPS_RGB_RUNLENGTH: {
fputs(dk3bm_c8_kw[20], job->dfile);
fputs(dk3bm_c8_kw[22], job->dfile);
fputs(dk3bm_c8_kw[24], job->dfile);
bitsperline = w * (long)(job->bpc);
bytesperline = bitsperline / 8L;
if(bitsperline % 8L) { bytesperline++; }
fprintf(job->dfile, dk3bm_c8_kw[48], bytesperline);
fprintf(job->dfile, dk3bm_c8_kw[49], bytesperline);
fprintf(job->dfile, dk3bm_c8_kw[50], bytesperline);
} break;
case DK3_BMEPS_GRAY_DCT: {
fputs(dk3bm_c8_kw[21], job->dfile);
fputs(dk3bm_c8_kw[22], job->dfile);
fputs(dk3bm_c8_kw[27], job->dfile);
} break;
case DK3_BMEPS_RGB_DCT: {
fputs(dk3bm_c8_kw[20], job->dfile);
fputs(dk3bm_c8_kw[22], job->dfile);
fputs(dk3bm_c8_kw[27], job->dfile);
} break;
case DK3_BMEPS_CMYK_DCT: {
fputs(dk3bm_c8_kw[86], job->dfile);
fputs(dk3bm_c8_kw[22], job->dfile);
fputs(dk3bm_c8_kw[27], job->dfile);
} break;
case DK3_BMEPS_GRAY_FLATE: {
fputs(dk3bm_c8_kw[21], job->dfile);
fputs(dk3bm_c8_kw[22], job->dfile);
if((job->opt)->pred) {
dk3bm_define_flate_with_predictor(job);
} else {
fputs(dk3bm_c8_kw[26], job->dfile);
}
} break;
case DK3_BMEPS_RGB_FLATE: {
fputs(dk3bm_c8_kw[20], job->dfile);
fputs(dk3bm_c8_kw[22], job->dfile);
if((job->opt)->pred) {
dk3bm_define_flate_with_predictor(job);
} else {
fputs(dk3bm_c8_kw[26], job->dfile);
}
} break;
}
fputs(dk3bm_c8_kw[17], job->dfile); /* << */
/*
Image dictionary contents.
*/
fputs(dk3bm_c8_kw[19], job->dfile); /* /ImageType 1 */
sprintf(outputbuffer, dk3bm_c8_kw[28], w);
fputs(outputbuffer, job->dfile); /* /Width ... */
sprintf(outputbuffer, dk3bm_c8_kw[29], h);
fputs(outputbuffer, job->dfile); /* /Height ... */
sprintf(outputbuffer, dk3bm_c8_kw[30], w, h, h);
fputs(outputbuffer, job->dfile); /* /ImageMatrix ... */
sprintf(outputbuffer, dk3bm_c8_kw[34], (unsigned)(job->bpc));
fputs(outputbuffer, job->dfile); /* /BitsPerComponent ... */
/* /Interpolate ... */
switch(job->procedure) {
case DK3_BMEPS_GRAY_UNCOMPRESSED: {
fputs(dk3bm_c8_kw[38], job->dfile);
fputs(dk3bm_c8_kw[44], job->dfile);
fputs(dk3bm_c8_kw[((job->opt)->ip) ? 46 : 47], job->dfile);
} break;
case DK3_BMEPS_RGB_UNCOMPRESSED: {
fputs(dk3bm_c8_kw[36], job->dfile);
fputs(dk3bm_c8_kw[38], job->dfile);
fputs(dk3bm_c8_kw[45], job->dfile);
fputs(dk3bm_c8_kw[((job->opt)->ip) ? 46 : 47], job->dfile);
} break;
case DK3_BMEPS_GRAY_RUNLENGTH: {
fputs(dk3bm_c8_kw[37], job->dfile);
fputs(dk3bm_c8_kw[44], job->dfile);
fputs(dk3bm_c8_kw[((job->opt)->ip) ? 46 : 47], job->dfile);
} break;
case DK3_BMEPS_RGB_RUNLENGTH: {
fputs(dk3bm_c8_kw[35], job->dfile);
fputs(dk3bm_c8_kw[39], job->dfile);
fputs(dk3bm_c8_kw[40], job->dfile);
fputs(dk3bm_c8_kw[41], job->dfile);
fputs(dk3bm_c8_kw[42], job->dfile);
fputs(dk3bm_c8_kw[43], job->dfile);
fputs(dk3bm_c8_kw[45], job->dfile);
fputs(dk3bm_c8_kw[((job->opt)->ip) ? 46 : 47], job->dfile);
} break;
case DK3_BMEPS_GRAY_DCT: {
fputs(dk3bm_c8_kw[37], job->dfile);
fputs(dk3bm_c8_kw[44], job->dfile);
if((job->opt)->ip) {
if((job->opt)->jip) {
fputs(dk3bm_c8_kw[46], job->dfile);
}
}
} break;
case DK3_BMEPS_RGB_DCT: {
fputs(dk3bm_c8_kw[36], job->dfile);
fputs(dk3bm_c8_kw[37], job->dfile);
fputs(dk3bm_c8_kw[45], job->dfile);
if((job->opt)->ip) {
if((job->opt)->jip) {
fputs(dk3bm_c8_kw[46], job->dfile);
}
}
} break;
case DK3_BMEPS_CMYK_DCT: {
fputs(dk3bm_c8_kw[36], job->dfile);
fputs(dk3bm_c8_kw[37], job->dfile);
if(dk3bif_jpeg_get_found_adobe_marker(job->bif)) {
fputs(dk3bm_c8_kw[88], job->dfile);
} else {
fputs(dk3bm_c8_kw[87], job->dfile);
}
if((job->opt)->ip) {
if((job->opt)->jip) {
fputs(dk3bm_c8_kw[46], job->dfile);
}
}
} break;
case DK3_BMEPS_GRAY_FLATE: {
fputs(dk3bm_c8_kw[37], job->dfile);
fputs(dk3bm_c8_kw[44], job->dfile);
fputs(dk3bm_c8_kw[((job->opt)->ip) ? 46 : 47], job->dfile);
} break;
case DK3_BMEPS_RGB_FLATE: {
fputs(dk3bm_c8_kw[36], job->dfile);
fputs(dk3bm_c8_kw[37], job->dfile);
fputs(dk3bm_c8_kw[45], job->dfile);
fputs(dk3bm_c8_kw[((job->opt)->ip) ? 46 : 47], job->dfile);
} break;
}
fputs(dk3bm_c8_kw[18], job->dfile); /* >> image */
/*
Close data streams.
*/
switch(job->procedure) {
case DK3_BMEPS_GRAY_UNCOMPRESSED: {
fputs(dk3bm_c8_kw[23], job->dfile);
} break;
case DK3_BMEPS_RGB_UNCOMPRESSED: {
fputs(dk3bm_c8_kw[23], job->dfile);
} break;
case DK3_BMEPS_GRAY_RUNLENGTH: {
fputs(dk3bm_c8_kw[25], job->dfile);
fputs(dk3bm_c8_kw[23], job->dfile);
} break;
case DK3_BMEPS_RGB_RUNLENGTH: {
fputs(dk3bm_c8_kw[25], job->dfile);
fputs(dk3bm_c8_kw[23], job->dfile);
} break;
case DK3_BMEPS_GRAY_DCT: {
fputs(dk3bm_c8_kw[25], job->dfile);
fputs(dk3bm_c8_kw[23], job->dfile);
} break;
case DK3_BMEPS_RGB_DCT: {
fputs(dk3bm_c8_kw[25], job->dfile);
fputs(dk3bm_c8_kw[23], job->dfile);
} break;
case DK3_BMEPS_CMYK_DCT: {
fputs(dk3bm_c8_kw[25], job->dfile);
fputs(dk3bm_c8_kw[23], job->dfile);
} break;
case DK3_BMEPS_GRAY_FLATE: {
fputs(dk3bm_c8_kw[25], job->dfile);
fputs(dk3bm_c8_kw[23], job->dfile);
} break;
case DK3_BMEPS_RGB_FLATE: {
fputs(dk3bm_c8_kw[25], job->dfile);
fputs(dk3bm_c8_kw[23], job->dfile);
} break;
}
fputs(dk3bm_c8_kw[8], job->dfile); /* end */
fputs(dk3bm_c8_kw[5], job->dfile); /* grestore */
switch((job->opt)->mode) {
case DK3_BMEPS_MODE_IMAGE:
case DK3_BMEPS_MODE_DOCUMENT: {
if((job->opt)->dr == DK3_BMEPS_DRIVER_PS) {
fputs(dk3bm_c8_kw[6], job->dfile); /* showpage */
}
} break;
}
fputs(dk3bm_c8_kw[3], job->dfile); /* } exec */
/*
Write compress/encoded image data.
*/
os = dk3stream_open_file_app(
job->dfile, DK3_STREAM_FLAG_WRITE, (job->opt)->app
);
if(os) {
of = dk3of_open_app(os, (job->opt)->app);
if(of) {
dk3of_set_finalize(of, 1);
if(dk3of_add_cell(of, DK3_OF_CELL_TYPE_A85)) {
switch(job->procedure) {
case DK3_BMEPS_GRAY_UNCOMPRESSED: {
dk3bif_set_bits_per_pixel(job->bif, job->bpc);
if(dk3of_start_chunk(of)) {
if(job->bpc == 8) {
if(alphain) {
for(y = 0L; y < h; y++) {
for(x = 0L; x < w; x++) {
v = dk3bif_get_mixed_gray(job->bif, x, y);
dk3bm_write_uc(of, v);
}
#if DK3_USE_WX
dk3bmj_lines_progress(job->pComm,pbmin,pbmax,h,y);
#endif
}
} else {
for(y = 0L; y < h; y++) {
for(x = 0L; x < w; x++) {
v = dk3bif_get_gray(job->bif, x, y);
dk3bm_write_uc(of, v);
}
#if DK3_USE_WX
dk3bmj_lines_progress(job->pComm,pbmin,pbmax,h,y);
#endif
}
}
} else {
if(alphain) {
for(y = 0L; y < h; y++) {
for(x = 0L; x < w; x++) {
v = dk3bif_get_mixed_gray(job->bif, x, y);
dk3of_write_bits(of, v, job->bpc);
}
dk3of_flush_bits(of);
#if DK3_USE_WX
dk3bmj_lines_progress(job->pComm,pbmin,pbmax,h,y);
#endif
}
} else {
for(y = 0L; y < h; y++) {
for(x = 0L; x < w; x++) {
v = dk3bif_get_gray(job->bif, x, y);
dk3of_write_bits(of, v, job->bpc);
}
dk3of_flush_bits(of);
#if DK3_USE_WX
dk3bmj_lines_progress(job->pComm,pbmin,pbmax,h,y);
#endif
}
}
}
back = dk3of_end_chunk(of);
} else {
/* ERROR: Failed to start encoded chunk! */
dk3bmj_log_1(
(job->opt)->app, DK3_LL_ERROR, job->msg, 59,
DK3_BMJ_LOG_BOTH, job
);
}
} break;
case DK3_BMEPS_RGB_UNCOMPRESSED: {
dk3bif_set_bits_per_pixel(job->bif, job->bpc);
if(dk3of_start_chunk(of)) {
if(job->bpc == 8) {
if(alphain) {
for(y = 0L; y < h; y++) {
for(x = 0L; x < w; x++) {
v = dk3bif_get_mixed_red(job->bif, x, y);
dk3bm_write_uc(of, v);
v = dk3bif_get_mixed_green(job->bif, x, y);
dk3bm_write_uc(of, v);
v = dk3bif_get_mixed_blue(job->bif, x, y);
dk3bm_write_uc(of, v);
}
#if DK3_USE_WX
dk3bmj_lines_progress(job->pComm,pbmin,pbmax,h,y);
#endif
}
} else {
for(y = 0L; y < h; y++) {
for(x = 0L; x < w; x++) {
v = dk3bif_get_red(job->bif, x, y);
dk3bm_write_uc(of, v);
v = dk3bif_get_green(job->bif, x, y);
dk3bm_write_uc(of, v);
v = dk3bif_get_blue(job->bif, x, y);
dk3bm_write_uc(of, v);
}
#if DK3_USE_WX
dk3bmj_lines_progress(job->pComm,pbmin,pbmax,h,y);
#endif
}
}
} else {
if(alphain) {
for(y = 0L; y < h; y++) {
for(x = 0L; x < w; x++) {
v = dk3bif_get_mixed_red(job->bif, x, y);
dk3of_write_bits(of, v, job->bpc);
v = dk3bif_get_mixed_green(job->bif, x, y);
dk3of_write_bits(of, v, job->bpc);
v = dk3bif_get_mixed_blue(job->bif, x, y);
dk3of_write_bits(of, v, job->bpc);
}
dk3of_flush_bits(of);
#if DK3_USE_WX
dk3bmj_lines_progress(job->pComm,pbmin,pbmax,h,y);
#endif
}
} else {
for(y = 0L; y < h; y++) {
for(x = 0L; x < w; x++) {
v = dk3bif_get_red(job->bif, x, y);
dk3of_write_bits(of, v, job->bpc);
v = dk3bif_get_green(job->bif, x, y);
dk3of_write_bits(of, v, job->bpc);
v = dk3bif_get_blue(job->bif, x, y);
dk3of_write_bits(of, v, job->bpc);
}
dk3of_flush_bits(of);
#if DK3_USE_WX
dk3bmj_lines_progress(job->pComm,pbmin,pbmax,h,y);
#endif
}
}
}
back = dk3of_end_chunk(of);
} else {
/* ERROR: Failed to start encoded chunk! */
dk3bmj_log_1(
(job->opt)->app, DK3_LL_ERROR, job->msg, 59,
DK3_BMJ_LOG_BOTH, job
);
}
} break;
case DK3_BMEPS_GRAY_RUNLENGTH: {
dk3bif_set_bits_per_pixel(job->bif, job->bpc);
if(dk3of_add_cell(of, DK3_OF_CELL_TYPE_RUN_LENGTH)) {
if(dk3of_start_chunk(of)) {
if(job->bpc == 8) {
if(alphain) {
for(y = 0UL; y < h; y++) {
for(x = 0UL; x < w; x++) {
v = dk3bif_get_mixed_gray(job->bif, x, y);
dk3bm_write_uc(of, v);
}
#if DK3_USE_WX
dk3bmj_lines_progress(job->pComm,pbmin,pbmax,h,y);
#endif
}
} else {
for(y = 0UL; y < h; y++) {
for(x = 0UL; x < w; x++) {
v = dk3bif_get_gray(job->bif, x, y);
dk3bm_write_uc(of, v);
}
#if DK3_USE_WX
dk3bmj_lines_progress(job->pComm,pbmin,pbmax,h,y);
#endif
}
}
} else {
if(alphain) {
for(y = 0UL; y < h; y++) {
for(x = 0UL; x < w; x++) {
v = dk3bif_get_mixed_gray(job->bif, x, y);
dk3of_write_bits(of, v, job->bpc);
}
dk3of_flush_bits(of);
#if DK3_USE_WX
dk3bmj_lines_progress(job->pComm,pbmin,pbmax,h,y);
#endif
}
} else {
for(y = 0UL; y < h; y++) {
for(x = 0UL; x < w; x++) {
v = dk3bif_get_gray(job->bif, x, y);
dk3of_write_bits(of, v, job->bpc);
}
dk3of_flush_bits(of);
#if DK3_USE_WX
dk3bmj_lines_progress(job->pComm,pbmin,pbmax,h,y);
#endif
}
}
}
back = dk3of_end_chunk(of);
} else {
/* ERROR: Failed to start encoded chunk! */
dk3bmj_log_1(
(job->opt)->app, DK3_LL_ERROR, job->msg, 59,
DK3_BMJ_LOG_BOTH, job
);
}
} else {
/* ERROR: Failed to add run-length cell! */
dk3bmj_log_1(
(job->opt)->app, DK3_LL_ERROR, job->msg, 59,
DK3_BMJ_LOG_BOTH, job
);
}
} break;
case DK3_BMEPS_RGB_RUNLENGTH: {
dk3bif_set_bits_per_pixel(job->bif, job->bpc);
if(dk3of_add_cell(of, DK3_OF_CELL_TYPE_RUN_LENGTH)) {
if(dk3of_start_chunk(of)) {
if(job->bpc == 8) {
if(alphain) {
for(y = 0UL; y < h; y++) {
for(x = 0UL; x < w; x++) {
v = dk3bif_get_mixed_red(job->bif, x, y);
dk3bm_write_uc(of, v);
}
for(x = 0UL; x < w; x++) {
v = dk3bif_get_mixed_green(job->bif, x, y);
dk3bm_write_uc(of, v);
}
for(x = 0UL; x < w; x++) {
v = dk3bif_get_mixed_blue(job->bif, x, y);
dk3bm_write_uc(of, v);
}
#if DK3_USE_WX
dk3bmj_lines_progress(job->pComm,pbmin,pbmax,h,y);
#endif
}
} else {
for(y = 0UL; y < h; y++) {
for(x = 0UL; x < w; x++) {
v = dk3bif_get_red(job->bif, x, y);
dk3bm_write_uc(of, v);
}
for(x = 0UL; x < w; x++) {
v = dk3bif_get_green(job->bif, x, y);
dk3bm_write_uc(of, v);
}
for(x = 0UL; x < w; x++) {
v = dk3bif_get_blue(job->bif, x, y);
dk3bm_write_uc(of, v);
}
#if DK3_USE_WX
dk3bmj_lines_progress(job->pComm,pbmin,pbmax,h,y);
#endif
}
}
} else {
if(alphain) {
for(y = 0UL; y < h; y++) {
for(x = 0UL; x < w; x++) {
v = dk3bif_get_mixed_red(job->bif, x, y);
dk3of_write_bits(of, v, job->bpc);
}
dk3of_flush_bits(of);
for(x = 0UL; x < w; x++) {
v = dk3bif_get_mixed_green(job->bif, x, y);
dk3of_write_bits(of, v, job->bpc);
}
dk3of_flush_bits(of);
for(x = 0UL; x < w; x++) {
v = dk3bif_get_mixed_blue(job->bif, x, y);
dk3of_write_bits(of, v, job->bpc);
}
dk3of_flush_bits(of);
#if DK3_USE_WX
dk3bmj_lines_progress(job->pComm,pbmin,pbmax,h,y);
#endif
}
} else {
for(y = 0UL; y < h; y++) {
for(x = 0UL; x < w; x++) {
v = dk3bif_get_red(job->bif, x, y);
dk3of_write_bits(of, v, job->bpc);
}
dk3of_flush_bits(of);
for(x = 0UL; x < w; x++) {
v = dk3bif_get_green(job->bif, x, y);
dk3of_write_bits(of, v, job->bpc);
}
dk3of_flush_bits(of);
for(x = 0UL; x < w; x++) {
v = dk3bif_get_blue(job->bif, x, y);
dk3of_write_bits(of, v, job->bpc);
}
dk3of_flush_bits(of);
#if DK3_USE_WX
dk3bmj_lines_progress(job->pComm,pbmin,pbmax,h,y);
#endif
}
}
}
back = dk3of_end_chunk(of);
} else {
/* ERROR: Failed to start encoded chunk! */
dk3bmj_log_1(
(job->opt)->app, DK3_LL_ERROR, job->msg, 59,
DK3_BMJ_LOG_BOTH, job
);
}
} else {
/* ERROR: Failed to add run-length cell! */
dk3bmj_log_1(
(job->opt)->app, DK3_LL_ERROR, job->msg, 59,
DK3_BMJ_LOG_BOTH, job
);
}
} break;
case DK3_BMEPS_GRAY_DCT:
case DK3_BMEPS_RGB_DCT:
case DK3_BMEPS_CMYK_DCT: {
dctin = dk3bif_get_file(job->bif);
if(dctin) {
rewind(dctin);
if(dk3of_start_chunk(of)) {
back = dk3bm_copy_dct_data(of, dctin, job);
if(back) {
back = dk3of_end_chunk(of);
} else {
(void)dk3of_end_chunk(of);
}
} else {
/* ERROR: Failed to start encoded chunk! */
dk3bmj_log_1(
(job->opt)->app, DK3_LL_ERROR, job->msg, 59,
DK3_BMJ_LOG_BOTH, job
);
}
} else {
/* BUG: No input file! */
}
} break;
case DK3_BMEPS_GRAY_FLATE: {
dk3bif_set_bits_per_pixel(job->bif, job->bpc);
if(dk3of_add_cell(of, DK3_OF_CELL_TYPE_FLATE)) {
if(dk3of_start_chunk(of)) {
if(job->bpc == 8) {
if(alphain) {
#line 1384 "dk3bm.ctr"
switch((job->opt)->pred) {
case DK3_COMPRESSION_PREDICTOR_TIFF: {
for(y = 0UL; y < h; y++) {
pl = 0;
for(x = 0UL; x < w; x++) {
v = dk3bif_get_mixed_gray(job->bif, x, y);
dk3bm_write_uc(of, (v - pl));
pl = v;
}
#if DK3_USE_WX
dk3bmj_lines_progress(job->pComm,pbmin,pbmax,h,y);
#endif
}
} break;
case DK3_COMPRESSION_PREDICTOR_PNG_SUB: {
for(y = 0UL; y < h; y++) {
pl = 0;
dk3bm_write_uc(of, 1);
for(x = 0UL; x < w; x++) {
v = dk3bif_get_mixed_gray(job->bif, x, y);
dk3bm_write_uc(of, (v - pl));
pl = v;
}
#if DK3_USE_WX
dk3bmj_lines_progress(job->pComm,pbmin,pbmax,h,y);
#endif
}
} break;
case DK3_COMPRESSION_PREDICTOR_PNG_UP: {
for(y = 0UL; y < h; y++) {
dk3bm_write_uc(of, 2);
for(x = 0UL; x < w; x++) {
#line 1416 "dk3bm.ctr"
v = dk3bif_get_mixed_gray(job->bif, x, y);
pu = dk3bif_get_mixed_gray(job->bif, x, (y - 1L));
#line 1419 "dk3bm.ctr"
v = v - pu;
#line 1420 "dk3bm.ctr"
dk3bm_write_uc(of, v);
}
#if DK3_USE_WX
dk3bmj_lines_progress(job->pComm,pbmin,pbmax,h,y);
#endif
}
} break;
case DK3_COMPRESSION_PREDICTOR_PNG_AVERAGE: {
for(y = 0UL; y < h; y++) {
dk3bm_write_uc(of, 3);
for(x = 0UL; x < w; x++) {
v = dk3bif_get_mixed_gray(job->bif, x, y);
pl = dk3bif_get_mixed_gray(job->bif, (x - 1L), y);
pu = dk3bif_get_mixed_gray(job->bif, x, (y - 1L));
pl = dk3bif_average(pl, pu);
pl &= 0x00FFU;
v = v - pl;
dk3bm_write_uc(of, v);
}
#if DK3_USE_WX
dk3bmj_lines_progress(job->pComm,pbmin,pbmax,h,y);
#endif
}
} break;
case DK3_COMPRESSION_PREDICTOR_PNG_PAETH: {
for(y = 0UL; y < h; y++) {
dk3bm_write_uc(of, 4);
for(x = 0UL; x < w; x++) {
v = dk3bif_get_mixed_gray(job->bif, x, y);
pl = dk3bif_get_mixed_gray(job->bif, (x - 1L), y);
pu = dk3bif_get_mixed_gray(job->bif, x, (y - 1L));
plu = dk3bif_get_mixed_gray(
job->bif, (x - 1L), (y - 1L)
);
pl = dk3bif_paeth(pl, pu, plu);
v = v - pl;
dk3bm_write_uc(of, v);
}
#if DK3_USE_WX
dk3bmj_lines_progress(job->pComm,pbmin,pbmax,h,y);
#endif
}
} break;
default: {
for(y = 0UL; y < h; y++) {
for(x = 0UL; x < w; x++) {
v = dk3bif_get_mixed_gray(job->bif, x, y);
dk3bm_write_uc(of, v);
}
#if DK3_USE_WX
dk3bmj_lines_progress(job->pComm,pbmin,pbmax,h,y);
#endif
}
} break;
}
} else {
switch((job->opt)->pred) {
case DK3_COMPRESSION_PREDICTOR_TIFF: {
for(y = 0UL; y < h; y++) {
pl = 0;
for(x = 0UL; x < w; x++) {
v = dk3bif_get_gray(job->bif, x, y);
dk3bm_write_uc(of, (v - pl));
pl = v;
}
#if DK3_USE_WX
dk3bmj_lines_progress(job->pComm,pbmin,pbmax,h,y);
#endif
}
} break;
case DK3_COMPRESSION_PREDICTOR_PNG_SUB: {
for(y = 0UL; y < h; y++) {
dk3bm_write_uc(of, 1);
pl = 0;
for(x = 0UL; x < w; x++) {
v = dk3bif_get_gray(job->bif, x, y);
dk3bm_write_uc(of, (v - pl));
pl = v;
}
#if DK3_USE_WX
dk3bmj_lines_progress(job->pComm,pbmin,pbmax,h,y);
#endif
}
} break;
case DK3_COMPRESSION_PREDICTOR_PNG_UP: {
for(y = 0UL; y < h; y++) {
dk3bm_write_uc(of, 2);
for(x = 0UL; x < w; x++) {
v = dk3bif_get_gray(job->bif, x, y);
pu = dk3bif_get_gray(job->bif, x, (y - 1L));
dk3bm_write_uc(of, (v - pu));
}
#if DK3_USE_WX
dk3bmj_lines_progress(job->pComm,pbmin,pbmax,h,y);
#endif
}
} break;
case DK3_COMPRESSION_PREDICTOR_PNG_AVERAGE: {
for(y = 0UL; y < h; y++) {
dk3bm_write_uc(of, 3);
for(x = 0UL; x < w; x++) {
v = dk3bif_get_gray(job->bif, x, y);
pl = dk3bif_get_gray(job->bif, (x - 1L), y);
pu = dk3bif_get_gray(job->bif, x, (y - 1L));
pl = dk3bif_average(pl, pu);
pl &= 0x00FFU;
v = v - pl;
dk3bm_write_uc(of, v);
}
#if DK3_USE_WX
dk3bmj_lines_progress(job->pComm,pbmin,pbmax,h,y);
#endif
}
} break;
case DK3_COMPRESSION_PREDICTOR_PNG_PAETH: {
for(y = 0UL; y < h; y++) {
dk3bm_write_uc(of, 4);
for(x = 0UL; x < w; x++) {
v = dk3bif_get_gray(job->bif, x, y);
pl = dk3bif_get_gray(job->bif, (x - 1L), y);
pu = dk3bif_get_gray(job->bif, x, (y - 1L));
plu = dk3bif_get_gray(
job->bif, (x - 1L), (y - 1L)
);
pl = dk3bif_paeth(pl, pu, plu);
v = v - pl;
dk3bm_write_uc(of, v);
}
#if DK3_USE_WX
dk3bmj_lines_progress(job->pComm,pbmin,pbmax,h,y);
#endif
}
} break;
default: {
for(y = 0UL; y < h; y++) {
for(x = 0UL; x < w; x++) {
v = dk3bif_get_gray(job->bif, x, y);
dk3bm_write_uc(of, v);
}
#if DK3_USE_WX
dk3bmj_lines_progress(job->pComm,pbmin,pbmax,h,y);
#endif
}
} break;
}
}
} else {
if(alphain) {
switch((job->opt)->pred) {
case DK3_COMPRESSION_PREDICTOR_TIFF: {
for(y = 0UL; y < h; y++) {
pl = 0;
for(x = 0UL; x < w; x++) {
v = dk3bif_get_mixed_gray(job->bif, x, y);
dk3of_write_bits(of, (v - pl), job->bpc);
pl = v;
}
dk3of_flush_bits(of);
#if DK3_USE_WX
dk3bmj_lines_progress(job->pComm,pbmin,pbmax,h,y);
#endif
}
} break;
default: {
for(y = 0UL; y < h; y++) {
for(x = 0UL; x < w; x++) {
v = dk3bif_get_mixed_gray(job->bif, x, y);
dk3of_write_bits(of, v, job->bpc);
}
dk3of_flush_bits(of);
#if DK3_USE_WX
dk3bmj_lines_progress(job->pComm,pbmin,pbmax,h,y);
#endif
}
} break;
}
} else {
switch((job->opt)->pred) {
case DK3_COMPRESSION_PREDICTOR_TIFF: {
for(y = 0UL; y < h; y++) {
pl = 0;
for(x = 0UL; x < w; x++) {
v = dk3bif_get_gray(job->bif, x, y);
dk3of_write_bits(of, (v - pl), job->bpc);
pl = v;
}
dk3of_flush_bits(of);
#if DK3_USE_WX
dk3bmj_lines_progress(job->pComm,pbmin,pbmax,h,y);
#endif
}
} break;
default: {
for(y = 0UL; y < h; y++) {
for(x = 0UL; x < w; x++) {
v = dk3bif_get_gray(job->bif, x, y);
dk3of_write_bits(of, v, job->bpc);
}
dk3of_flush_bits(of);
#if DK3_USE_WX
dk3bmj_lines_progress(job->pComm,pbmin,pbmax,h,y);
#endif
}
} break;
}
}
}
back = dk3of_end_chunk(of);
} else {
/* ERROR: Failed to start encoded chunk! */
dk3bmj_log_1(
(job->opt)->app, DK3_LL_ERROR, job->msg, 59,
DK3_BMJ_LOG_BOTH, job
);
}
} else {
/* ERROR: Failed to add run-length cell! */
dk3bmj_log_1(
(job->opt)->app, DK3_LL_ERROR, job->msg, 59,
DK3_BMJ_LOG_BOTH, job
);
}
} break;
case DK3_BMEPS_RGB_FLATE: {
dk3bif_set_bits_per_pixel(job->bif, job->bpc);
if(dk3of_add_cell(of, DK3_OF_CELL_TYPE_FLATE)) {
if(dk3of_start_chunk(of)) {
if(job->bpc == 8) {
if(alphain) {
switch((job->opt)->pred) {
case DK3_COMPRESSION_PREDICTOR_TIFF: {
for(y = 0UL; y < h; y++) {
pl = 0; /* r */
pu = 0; /* g */
plu = 0; /* b */
for(x = 0UL; x < w; x++) {
v = dk3bif_get_mixed_red(job->bif, x, y);
dk3bm_write_uc(of, (v - pl));
pl = v;
v = dk3bif_get_mixed_green(job->bif, x, y);
dk3bm_write_uc(of, (v - pu));
pu = v;
v = dk3bif_get_mixed_blue(job->bif, x, y);
dk3bm_write_uc(of, (v - plu));
plu = v;
}
#if DK3_USE_WX
dk3bmj_lines_progress(job->pComm,pbmin,pbmax,h,y);
#endif
}
} break;
case DK3_COMPRESSION_PREDICTOR_PNG_SUB: {
for(y = 0UL; y < h; y++) {
pl = 0; /* r */
pu = 0; /* g */
plu = 0; /* b */
dk3bm_write_uc(of, 1);
for(x = 0UL; x < w; x++) {
v = dk3bif_get_mixed_red(job->bif, x, y);
dk3bm_write_uc(of, (v - pl));
pl = v;
v = dk3bif_get_mixed_green(job->bif, x, y);
dk3bm_write_uc(of, (v - pu));
pu = v;
v = dk3bif_get_mixed_blue(job->bif, x, y);
dk3bm_write_uc(of, (v - plu));
plu = v;
}
#if DK3_USE_WX
dk3bmj_lines_progress(job->pComm,pbmin,pbmax,h,y);
#endif
}
} break;
case DK3_COMPRESSION_PREDICTOR_PNG_UP: {
for(y = 0UL; y < h; y++) {
dk3bm_write_uc(of, 2);
for(x = 0UL; x < w; x++) {
v = dk3bif_get_mixed_red(job->bif, x, y);
pu = dk3bif_get_mixed_red(job->bif, x, (y - 1L));
dk3bm_write_uc(of, (v - pu));
v = dk3bif_get_mixed_green(job->bif, x, y);
pu = dk3bif_get_mixed_green(job->bif, x, (y - 1L));
dk3bm_write_uc(of, (v - pu));
v = dk3bif_get_mixed_blue(job->bif, x, y);
pu = dk3bif_get_mixed_blue(job->bif, x, (y - 1L));
dk3bm_write_uc(of, (v - pu));
}
#if DK3_USE_WX
dk3bmj_lines_progress(job->pComm,pbmin,pbmax,h,y);
#endif
}
} break;
case DK3_COMPRESSION_PREDICTOR_PNG_AVERAGE: {
for(y = 0UL; y < h; y++) {
dk3bm_write_uc(of, 3);
for(x = 0UL; x < w; x++) {
v = dk3bif_get_mixed_red(job->bif, x, y);
pl = dk3bif_get_mixed_red(job->bif, (x - 1L), y);
pu = dk3bif_get_mixed_red(job->bif, x, (y - 1L));
pu = dk3bif_average(pl, pu);
dk3bm_write_uc(of, (v - pu));
v = dk3bif_get_mixed_green(job->bif, x, y);
pl = dk3bif_get_mixed_green(job->bif, (x - 1L), y);
pu = dk3bif_get_mixed_green(job->bif, x, (y - 1L));
pu = dk3bif_average(pl, pu);
dk3bm_write_uc(of, (v - pu));
v = dk3bif_get_mixed_blue(job->bif, x, y);
pl = dk3bif_get_mixed_blue(job->bif, (x - 1L), y);
pu = dk3bif_get_mixed_blue(job->bif, x, (y - 1L));
pu = dk3bif_average(pl, pu);
dk3bm_write_uc(of, (v - pu));
}
#if DK3_USE_WX
dk3bmj_lines_progress(job->pComm,pbmin,pbmax,h,y);
#endif
}
} break;
case DK3_COMPRESSION_PREDICTOR_PNG_PAETH: {
for(y = 0UL; y < h; y++) {
dk3bm_write_uc(of, 3);
for(x = 0UL; x < w; x++) {
v = dk3bif_get_mixed_red(job->bif, x, y);
pl = dk3bif_get_mixed_red(job->bif, (x - 1L), y);
pu = dk3bif_get_mixed_red(job->bif, x, (y - 1L));
plu = dk3bif_get_mixed_red(job->bif, (x - 1L), (y - 1L));
pu = dk3bif_paeth(pl, pu, plu);
dk3bm_write_uc(of, (v - pu));
v = dk3bif_get_mixed_green(job->bif, x, y);
pl = dk3bif_get_mixed_green(job->bif, (x - 1L), y);
pu = dk3bif_get_mixed_green(job->bif, x, (y - 1L));
plu = dk3bif_get_mixed_green(job->bif, (x - 1L), (y - 1L));
pu = dk3bif_paeth(pl, pu, plu);
dk3bm_write_uc(of, (v - pu));
v = dk3bif_get_mixed_blue(job->bif, x, y);
pl = dk3bif_get_mixed_blue(job->bif, (x - 1L), y);
pu = dk3bif_get_mixed_blue(job->bif, x, (y - 1L));
plu = dk3bif_get_mixed_blue(job->bif, (x - 1L), (y - 1L));
pu = dk3bif_paeth(pl, pu, plu);
dk3bm_write_uc(of, (v - pu));
}
#if DK3_USE_WX
dk3bmj_lines_progress(job->pComm,pbmin,pbmax,h,y);
#endif
}
} break;
default: {
for(y = 0UL; y < h; y++) {
for(x = 0UL; x < w; x++) {
v = dk3bif_get_mixed_red(job->bif, x, y);
dk3bm_write_uc(of, v);
v = dk3bif_get_mixed_green(job->bif, x, y);
dk3bm_write_uc(of, v);
v = dk3bif_get_mixed_blue(job->bif, x, y);
dk3bm_write_uc(of, v);
}
#if DK3_USE_WX
dk3bmj_lines_progress(job->pComm,pbmin,pbmax,h,y);
#endif
}
} break;
}
} else {
switch((job->opt)->pred) {
case DK3_COMPRESSION_PREDICTOR_TIFF: {
for(y = 0UL; y < h; y++) {
pl = 0; /* r */
pu = 0; /* g */
plu = 0; /* b */
for(x = 0UL; x < w; x++) {
v = dk3bif_get_red(job->bif, x, y);
dk3bm_write_uc(of, (v - pl));
pl = v;
v = dk3bif_get_green(job->bif, x, y);
dk3bm_write_uc(of, (v - pu));
pu = v;
v = dk3bif_get_blue(job->bif, x, y);
dk3bm_write_uc(of, (v - plu));
plu = v;
}
#if DK3_USE_WX
dk3bmj_lines_progress(job->pComm,pbmin,pbmax,h,y);
#endif
}
} break;
case DK3_COMPRESSION_PREDICTOR_PNG_SUB: {
for(y = 0UL; y < h; y++) {
pl = 0; /* r */
pu = 0; /* g */
plu = 0; /* b */
dk3bm_write_uc(of, 1);
for(x = 0UL; x < w; x++) {
v = dk3bif_get_red(job->bif, x, y);
dk3bm_write_uc(of, (v - pl));
pl = v;
v = dk3bif_get_green(job->bif, x, y);
dk3bm_write_uc(of, (v - pu));
pu = v;
v = dk3bif_get_blue(job->bif, x, y);
dk3bm_write_uc(of, (v - plu));
plu = v;
}
#if DK3_USE_WX
dk3bmj_lines_progress(job->pComm,pbmin,pbmax,h,y);
#endif
}
} break;
case DK3_COMPRESSION_PREDICTOR_PNG_UP: {
for(y = 0UL; y < h; y++) {
dk3bm_write_uc(of, 2);
for(x = 0UL; x < w; x++) {
v = dk3bif_get_red(job->bif, x, y);
pu = dk3bif_get_red(job->bif, x, (y - 1L));
dk3bm_write_uc(of, (v - pu));
v = dk3bif_get_green(job->bif, x, y);
pu = dk3bif_get_green(job->bif, x, (y - 1L));
dk3bm_write_uc(of, (v - pu));
v = dk3bif_get_blue(job->bif, x, y);
pu = dk3bif_get_blue(job->bif, x, (y - 1L));
dk3bm_write_uc(of, (v - pu));
}
#if DK3_USE_WX
dk3bmj_lines_progress(job->pComm,pbmin,pbmax,h,y);
#endif
}
} break;
case DK3_COMPRESSION_PREDICTOR_PNG_AVERAGE: {
for(y = 0UL; y < h; y++) {
dk3bm_write_uc(of, 3);
for(x = 0UL; x < w; x++) {
v = dk3bif_get_red(job->bif, x, y);
pl = dk3bif_get_red(job->bif, (x - 1L), y);
pu = dk3bif_get_red(job->bif, x, (y - 1L));
pu = dk3bif_average(pl, pu);
dk3bm_write_uc(of, (v - pu));
v = dk3bif_get_green(job->bif, x, y);
pl = dk3bif_get_green(job->bif, (x - 1L), y);
pu = dk3bif_get_green(job->bif, x, (y - 1L));
pu = dk3bif_average(pl, pu);
dk3bm_write_uc(of, (v - pu));
v = dk3bif_get_blue(job->bif, x, y);
pl = dk3bif_get_blue(job->bif, (x - 1L), y);
pu = dk3bif_get_blue(job->bif, x, (y - 1L));
pu = dk3bif_average(pl, pu);
dk3bm_write_uc(of, (v - pu));
}
#if DK3_USE_WX
dk3bmj_lines_progress(job->pComm,pbmin,pbmax,h,y);
#endif
}
} break;
case DK3_COMPRESSION_PREDICTOR_PNG_PAETH: {
for(y = 0UL; y < h; y++) {
dk3bm_write_uc(of, 3);
for(x = 0UL; x < w; x++) {
v = dk3bif_get_red(job->bif, x, y);
pl = dk3bif_get_red(job->bif, (x - 1L), y);
pu = dk3bif_get_red(job->bif, x, (y - 1L));
plu = dk3bif_get_red(job->bif, (x - 1L), (y - 1L));
pu = dk3bif_paeth(pl, pu, plu);
dk3bm_write_uc(of, (v - pu));
v = dk3bif_get_green(job->bif, x, y);
pl = dk3bif_get_green(job->bif, (x - 1L), y);
pu = dk3bif_get_green(job->bif, x, (y - 1L));
plu = dk3bif_get_green(job->bif, (x - 1L), (y - 1L));
pu = dk3bif_paeth(pl, pu, plu);
dk3bm_write_uc(of, (v - pu));
v = dk3bif_get_blue(job->bif, x, y);
pl = dk3bif_get_blue(job->bif, (x - 1L), y);
pu = dk3bif_get_blue(job->bif, x, (y - 1L));
plu = dk3bif_get_blue(job->bif, (x - 1L), (y - 1L));
pu = dk3bif_paeth(pl, pu, plu);
dk3bm_write_uc(of, (v - pu));
}
#if DK3_USE_WX
dk3bmj_lines_progress(job->pComm,pbmin,pbmax,h,y);
#endif
}
} break;
default : {
for(y = 0UL; y < h; y++) {
for(x = 0UL; x < w; x++) {
v = dk3bif_get_red(job->bif, x, y);
dk3bm_write_uc(of, v);
v = dk3bif_get_green(job->bif, x, y);
dk3bm_write_uc(of, v);
v = dk3bif_get_blue(job->bif, x, y);
dk3bm_write_uc(of, v);
}
#if DK3_USE_WX
dk3bmj_lines_progress(job->pComm,pbmin,pbmax,h,y);
#endif
}
} break;
}
}
} else {
if(alphain) {
switch((job->opt)->pred) {
case DK3_COMPRESSION_PREDICTOR_TIFF: {
for(y = 0UL; y < h; y++) {
pl = 0; pu = 0; plu = 0;
for(x = 0UL; x < w; x++) {
v = dk3bif_get_mixed_red(job->bif, x, y);
dk3of_write_bits(of, (v - pl), job->bpc);
pl = v;
v = dk3bif_get_mixed_green(job->bif, x, y);
dk3of_write_bits(of, (v - pu), job->bpc);
pu = v;
v = dk3bif_get_mixed_blue(job->bif, x, y);
dk3of_write_bits(of, (v - plu), job->bpc);
plu = v;
}
dk3of_flush_bits(of);
#if DK3_USE_WX
dk3bmj_lines_progress(job->pComm,pbmin,pbmax,h,y);
#endif
}
} break;
default: {
for(y = 0UL; y < h; y++) {
for(x = 0UL; x < w; x++) {
v = dk3bif_get_mixed_red(job->bif, x, y);
dk3of_write_bits(of, v, job->bpc);
v = dk3bif_get_mixed_green(job->bif, x, y);
dk3of_write_bits(of, v, job->bpc);
v = dk3bif_get_mixed_blue(job->bif, x, y);
dk3of_write_bits(of, v, job->bpc);
}
dk3of_flush_bits(of);
#if DK3_USE_WX
dk3bmj_lines_progress(job->pComm,pbmin,pbmax,h,y);
#endif
}
} break;
}
} else {
switch((job->opt)->pred) {
case DK3_COMPRESSION_PREDICTOR_TIFF: {
for(y = 0UL; y < h; y++) {
pl = 0; pu = 0; plu = 0;
for(x = 0UL; x < w; x++) {
v = dk3bif_get_red(job->bif, x, y);
dk3of_write_bits(of, (v - pl), job->bpc);
pl = v;
v = dk3bif_get_green(job->bif, x, y);
dk3of_write_bits(of, (v - pu), job->bpc);
pu = v;
v = dk3bif_get_blue(job->bif, x, y);
dk3of_write_bits(of, (v - plu), job->bpc);
plu = v;
}
dk3of_flush_bits(of);
#if DK3_USE_WX
dk3bmj_lines_progress(job->pComm,pbmin,pbmax,h,y);
#endif
}
} break;
default: {
for(y = 0UL; y < h; y++) {
for(x = 0UL; x < w; x++) {
v = dk3bif_get_red(job->bif, x, y);
dk3of_write_bits(of, v, job->bpc);
v = dk3bif_get_green(job->bif, x, y);
dk3of_write_bits(of, v, job->bpc);
v = dk3bif_get_blue(job->bif, x, y);
dk3of_write_bits(of, v, job->bpc);
}
dk3of_flush_bits(of);
#if DK3_USE_WX
dk3bmj_lines_progress(job->pComm,pbmin,pbmax,h,y);
#endif
}
} break;
}
}
}
back = dk3of_end_chunk(of);
} else {
/* ERROR: Failed to start encoded chunk! */
dk3bmj_log_1(
(job->opt)->app, DK3_LL_ERROR, job->msg, 59,
DK3_BMJ_LOG_BOTH, job
);
}
} else {
/* ERROR: Failed to add run-length cell! */
dk3bmj_log_1(
(job->opt)->app, DK3_LL_ERROR, job->msg, 59,
DK3_BMJ_LOG_BOTH, job
);
}
} break;
}
} else {
/* ERROR: Failed to add filter cell! */
dk3bmj_log_1(
(job->opt)->app, DK3_LL_ERROR, job->msg, 59,
DK3_BMJ_LOG_BOTH, job
);
}
dk3of_close(of);
} else {
/* ERROR: Failed to create output filter! */
dk3bmj_log_1(
(job->opt)->app, DK3_LL_ERROR, job->msg, 59, DK3_BMJ_LOG_BOTH, job
);
}
dk3stream_close(os);
} else {
/* ERROR: Failed to create output stream! */
dk3bmj_log_1(
(job->opt)->app, DK3_LL_ERROR, job->msg, 59, DK3_BMJ_LOG_BOTH, job
);
}
/*
File footer.
*/
if(job->do_header_footer) {
dk3bm_ps_document_footer(job);
}
} else {
#line 2041 "dk3bm.ctr"
/* BUG: No output file! */
}
#if DK3_USE_WX
job->minpb = minpb;
job->maxpb = maxpb;
#endif
#line 2048 "dk3bm.ctr"
return back;
}
int
dk3bm_find_transformation(
dk3_coordinates_transformation_t *dst,
dk3_bb_t *outbb,
int drawdir,
double imw,
double imh,
double xres,
double yres,
int *ec
)
{
double w = 0.0; /* Image width. */
double h = 0.0; /* Image height. */
double sx = 0.0; /* X scale factor. */
double sy = 0.0; /* Y scale factor. */
#if VERSION_BEFORE_20150821
double sf = 0.0; /* Scale factor. */
#endif
double xmin = 0.0; /* Minimum X. */
double xmax = 0.0; /* Maximum X. */
double ymin = 0.0; /* Minimum Y. */
double ymax = 0.0; /* Maximum Y. */
double xused = 0.0; /* Used X range. */
double yused = 0.0; /* Used Y range. */
double xborder = 0.0; /* X border. */
double yborder = 0.0; /* Y border. */
int mec = 0; /* Mathematical error code. */
int back = 0;
#line 2083 "dk3bm.ctr"
if((dst) && (outbb)) {
back = 1;
w = imw;
#line 2086 "dk3bm.ctr"
h = imh;
#line 2087 "dk3bm.ctr"
if((xres > 0.0) && (yres > 0.0)) {
w = dk3ma_d_div_ok(w, xres, &mec);
#line 2089 "dk3bm.ctr"
h = dk3ma_d_div_ok(h, yres, &mec);
#line 2090 "dk3bm.ctr"
}
#if VERSION_BEFORE_20150821
sx = sy = sf = 0.0;
#endif
switch(drawdir) {
case DK3_IMAGE_ORIGIN_LEFT_BOTTOM:
case DK3_IMAGE_ORIGIN_RIGHT_TOP:
case DK3_IMAGE_ORIGIN_LEFT_TOP_FLIPPED:
case DK3_IMAGE_ORIGIN_RIGHT_BOTTOM_FLIPPED:
{
sx = dk3ma_d_div_ok(
dk3ma_d_sub_ok(outbb->xmax, outbb->xmin, ec),
h,
ec
);
sy = dk3ma_d_div_ok(
dk3ma_d_sub_ok(outbb->ymax, outbb->ymin, ec),
w,
ec
);
if(sx < sy) { /* Entire X range used. */
xmin = outbb->xmin;
xmax = outbb->xmax;
xused = dk3ma_d_sub_ok(xmax, xmin, ec);
#if VERSION_BEFORE_20150821
xborder = 0.0;
#endif
yused = dk3ma_d_mul_ok(sx, w, ec);
yborder = 0.5 * dk3ma_d_sub_ok(
dk3ma_d_sub_ok(outbb->ymax, outbb->ymin, ec),
yused,
ec
);
if(yborder < 0.0) { yborder = 0.0; }
ymin = dk3ma_d_add_ok(outbb->ymin, yborder, ec);
ymax = dk3ma_d_add_ok(ymin, yused, ec);
} else { /* Entire Y range used. */
ymin = outbb->ymin;
ymax = outbb->ymax;
yused = dk3ma_d_sub_ok(ymax, ymin, ec);
#if VERSION_BEFORE_20150821
yborder = 0.0;
#endif
xused = dk3ma_d_mul_ok(sy, h, ec);
xborder = 0.5 * dk3ma_d_sub_ok(
dk3ma_d_sub_ok(outbb->xmax, outbb->xmin, ec),
xused,
ec
);
if(xborder < 0.0) { xborder = 0.0; }
xmin = dk3ma_d_add_ok(outbb->xmin, xborder, ec);
xmax = dk3ma_d_add_ok(xmin, xused, ec);
}
} break;
default: {
sx = dk3ma_d_div_ok(
dk3ma_d_sub_ok(outbb->xmax, outbb->xmin, ec),
w,
ec
);
sy = dk3ma_d_div_ok(
dk3ma_d_sub_ok(outbb->ymax, outbb->ymin, ec),
h,
ec
);
if(sx < sy) { /* Entire X range used. */
xmin = outbb->xmin;
xmax = outbb->xmax;
xused = dk3ma_d_sub_ok(xmax, xmin, ec);
#if VERSION_BEFORE_20150821
xborder = 0.0;
#endif
yused = dk3ma_d_mul_ok(sx, h, ec);
yborder = 0.5 * dk3ma_d_sub_ok(
dk3ma_d_sub_ok(outbb->ymax, outbb->ymin, ec),
yused,
ec
);
if(yborder < 0.0) { yborder = 0.0; }
ymin = dk3ma_d_add_ok(outbb->ymin, yborder, ec);
ymax = dk3ma_d_add_ok(ymin, yused, ec);
} else { /* Entire Y range used. */
ymin = outbb->ymin;
ymax = outbb->ymax;
yused = dk3ma_d_sub_ok(ymax, ymin, ec);
#if VERSION_BEFORE_20150821
yborder = 0.0;
#endif
xused = dk3ma_d_mul_ok(sy, w, ec);
xborder = 0.5 * dk3ma_d_sub_ok(
dk3ma_d_sub_ok(outbb->xmax, outbb->xmin, ec),
xused,
ec
);
if(xborder < 0.0) { xborder = 0.0; }
xmin = dk3ma_d_add_ok(outbb->xmin, xborder, ec);
xmax = dk3ma_d_add_ok(xmin, xused, ec);
}
} break;
}
dst->x_scale = xused;
dst->y_scale = yused;
#line 2193 "dk3bm.ctr"
#line 2194 "dk3bm.ctr"
#line 2195 "dk3bm.ctr"
#line 2196 "dk3bm.ctr"
#line 2197 "dk3bm.ctr"
#line 2198 "dk3bm.ctr"
dst->rot = 0;
switch(drawdir) {
case DK3_IMAGE_ORIGIN_LEFT_BOTTOM: { /* 1 */
dst->x_translate = xmax;
dst->y_translate = ymin;
dst->rot = 1;
dst->x_scale = yused;
dst->y_scale = xused;
} break;
case DK3_IMAGE_ORIGIN_RIGHT_TOP: { /* 2 */
dst->x_translate = xmin;
dst->y_translate = ymax;
dst->rot = 3;
dst->x_scale = yused;
dst->y_scale = xused;
} break;
case DK3_IMAGE_ORIGIN_RIGHT_BOTTOM: { /* 3 */
dst->x_translate = xmax;
dst->y_translate = ymax;
dst->rot = 2;
} break;
case DK3_IMAGE_ORIGIN_LEFT_TOP_FLIPPED: { /* 4 */
dst->x_translate = xmax;
dst->y_translate = ymax;
dst->rot = 1;
dst->x_scale = yused;
dst->y_scale = xused;
dst->x_scale = -1.0 * (dst->x_scale);
} break;
case DK3_IMAGE_ORIGIN_LEFT_BOTTOM_FLIPPED: { /* 5 */
dst->x_translate = xmin;
dst->y_translate = ymax;
dst->y_scale = -1.0 * (dst->y_scale);
} break;
case DK3_IMAGE_ORIGIN_RIGHT_TOP_FLIPPED: { /* 6 */
dst->x_translate = xmax;
dst->y_translate = ymin;
dst->x_scale = -1.0 * (dst->x_scale);
} break;
case DK3_IMAGE_ORIGIN_RIGHT_BOTTOM_FLIPPED: { /* 7 */
dst->x_translate = xmin;
dst->y_translate = ymin;
dst->rot = 3;
dst->x_scale = yused;
dst->y_scale = xused;
dst->x_scale = -1.0 * (dst->x_scale);
} break;
default: { /* left top */
dst->x_translate = xmin;
dst->y_translate = ymin;
dst->rot = 0;
} break;
}
#line 2252 "dk3bm.ctr"
#line 2253 "dk3bm.ctr"
#line 2254 "dk3bm.ctr"
#line 2255 "dk3bm.ctr"
#line 2256 "dk3bm.ctr"
}
if(mec) {
if(ec) { *ec = mec; }
}
#line 2260 "dk3bm.ctr"
return back;
}
int
dk3bm_find_bif_transformation(
dk3_coordinates_transformation_t *dst,
dk3_bif_t *bif,
dk3_bb_t *outbb,
int drawdir,
int *ec
)
{
double w;
double h;
double xres;
double yres;
dk3_bif_coord_t imw;
dk3_bif_coord_t imh;
int back = 0;
#line 2282 "dk3bm.ctr"
if((dst) && (bif) && (outbb)) {
imw = dk3bif_get_width(bif);
imh = dk3bif_get_height(bif);
w = (double)imw;
h = (double)imh;
xres = dk3bif_get_xres(bif);
yres = dk3bif_get_yres(bif);
back = dk3bm_find_transformation(dst, outbb, drawdir, w, h, xres, yres, ec);
}
#line 2291 "dk3bm.ctr"
return back;
}
int
dk3bm_ps_place_object(
FILE *dfile,
dk3_bb_t *outbb,
int drawdir,
char const *sfn,
dk3_app_t *app,
int pslevel,
int *ec
)
{
dk3_coordinates_transformation_t trans;
dk3_bm_eps_options_t bmeo;
dk3_bm_conversion_job_t job;
int back = 0;
#line 2312 "dk3bm.ctr"
if((dfile) && (outbb) && (sfn) && (app)) {
dk3bmj_init(&job, app);
dk3bmeo_init(&bmeo);
#line 2315 "dk3bm.ctr"
job.opt = &bmeo;
job.sfn = NULL;
job.dfile = dfile;
job.do_header_footer = 0;
bmeo.app = app;
bmeo.ima.ia.xl = outbb->xmin;
bmeo.ima.ia.xr = outbb->xmax;
bmeo.ima.ia.yb = outbb->ymin;
bmeo.ima.ia.yt = outbb->ymax;
#if VERSION_BEFORE_20140902
bmeo.mode =
bmeo.szmode =
bmeo.dr = DK3_BMEPS_DRIVER_EPS;
#else
bmeo.mode = DK3_BMEPS_MODE_OBJECT;
bmeo.szmode = DK3_BMEPS_SIZE_1_1;
#line 2331 "dk3bm.ctr"
bmeo.dr = DK3_BMEPS_DRIVER_EPS;
#endif
bmeo.io = drawdir;
bmeo.psl = pslevel;
job.bif = dk3bif_open_c8_filename_app(sfn,DK3_BIF_IMAGE_TYPE_UNKNOWN,app);
if(job.bif) {
#line 2337 "dk3bm.ctr"
job.biftype = dk3bif_get_type(job.bif);
/* job.procedure = */
#line 2339 "dk3bm.ctr"
/* job->x_size */
/* job->y_size */
/* job->x_0 */
/* job->x_1 */
/* job->y_0 */
/* job->y_1 */
/* job->procedure */
/* job->bpc */
/* job->nPages */
/* job->currentPage */
if(dk3bm_find_bif_transformation(&trans, job.bif, outbb, drawdir, ec)) {
/* FIG2LAT */
#line 2351 "dk3bm.ctr"
job.x_translate = trans.x_translate;
job.y_translate = trans.y_translate;
job.x_scale = trans.x_scale;
job.y_scale = trans.y_scale;
job.do_rotate = trans.rot;
job.do_translate = 1;
job.do_float_scale = 1;
#line 2358 "dk3bm.ctr"
if(dk3bif_read_data(job.bif)) {
back = dk3bm_job_produce_img_job_real_ps(&job);
} else {
/* ##### ERROR: Failed to read image data! */
}
} else {
/* ##### ERROR: Failed to calculate transformation data */
}
dk3bif_close(job.bif);
} else {
#line 2368 "dk3bm.ctr"
/* ##### ERROR: Failed to open image */
}
} else {
#line 2371 "dk3bm.ctr"
}
#line 2372 "dk3bm.ctr"
return back;
}
/** Paper size check function.
@param ps Paper size to check.
@return 1 on success, 0 on error (borders larger than paper).
*/
static
int
dk3bm_check_paper_size(dk3_paper_size_t *ps)
{
int back = 0;
#line 2387 "dk3bm.ctr"
if(ps->w > (ps->i + ps->o)) {
if(ps->h > (ps->t + ps->b)) {
back = 1;
}
}
#line 2392 "dk3bm.ctr"
return back;
}
/** Produce PS draft for image or object.
The x_0, x_1, y_0 and y_1 values must be set.
@param job Conversion job.
@return 1 on succes, 0 on error.
*/
static
int
dk3bm_job_produce_img_job_draft_ps(dk3_bm_conversion_job_t *job)
{
char outputbuffer[256]; /* Conversion buffer for numbers. */
double dx; /* Stripe width. */
double dy; /* Stripe width backup. */
int back = 0;
#line 2411 "dk3bm.ctr"
dk3bm_ps_document_header(job, job->nPages);
fputs(dk3bm_c8_kw[4], job->dfile);
fputs(dk3bm_c8_kw[21], job->dfile);
fputs(dk3bm_c8_kw[71], job->dfile);
sprintf(outputbuffer, dk3bm_c8_kw[72], job->x_0, job->y_0);
dk3bm_correct_output_buffer(outputbuffer);
fputs(outputbuffer, job->dfile);
sprintf(outputbuffer, dk3bm_c8_kw[73], job->x_1, job->y_0);
dk3bm_correct_output_buffer(outputbuffer);
fputs(outputbuffer, job->dfile);
sprintf(outputbuffer, dk3bm_c8_kw[73], job->x_1, job->y_1);
dk3bm_correct_output_buffer(outputbuffer);
fputs(outputbuffer, job->dfile);
sprintf(outputbuffer, dk3bm_c8_kw[73], job->x_0, job->y_1);
dk3bm_correct_output_buffer(outputbuffer);
fputs(outputbuffer, job->dfile);
fputs(dk3bm_c8_kw[74], job->dfile);
dx = 0.01 * (job->x_1 - job->x_0);
dy = 0.01 * (job->y_1 - job->y_0);
if(dy < dx) dx = dy;
if(dx > 2.8) dx = 2.8;
fputs(dk3bm_c8_kw[75], job->dfile);
sprintf(outputbuffer, dk3bm_c8_kw[72], job->x_0+dx, job->y_0+dx);
dk3bm_correct_output_buffer(outputbuffer);
fputs(outputbuffer, job->dfile);
sprintf(outputbuffer, dk3bm_c8_kw[73], job->x_1-dx, job->y_0+dx);
dk3bm_correct_output_buffer(outputbuffer);
fputs(outputbuffer, job->dfile);
sprintf(outputbuffer, dk3bm_c8_kw[73], job->x_1-dx, job->y_1-dx);
dk3bm_correct_output_buffer(outputbuffer);
fputs(outputbuffer, job->dfile);
sprintf(outputbuffer, dk3bm_c8_kw[73], job->x_0+dx, job->y_1-dx);
dk3bm_correct_output_buffer(outputbuffer);
fputs(outputbuffer, job->dfile);
fputs(dk3bm_c8_kw[74], job->dfile);
dx = 10.0 * dx;
fputs(dk3bm_c8_kw[76], job->dfile);
sprintf(outputbuffer, dk3bm_c8_kw[72], job->x_0+dx, job->y_0+dx);
dk3bm_correct_output_buffer(outputbuffer);
fputs(outputbuffer, job->dfile);
sprintf(outputbuffer, dk3bm_c8_kw[73], job->x_1-dx, job->y_0+dx);
dk3bm_correct_output_buffer(outputbuffer);
fputs(outputbuffer, job->dfile);
sprintf(outputbuffer, dk3bm_c8_kw[73], job->x_1-dx, job->y_1-dx);
dk3bm_correct_output_buffer(outputbuffer);
fputs(outputbuffer, job->dfile);
sprintf(outputbuffer, dk3bm_c8_kw[73], job->x_0+dx, job->y_1-dx);
dk3bm_correct_output_buffer(outputbuffer);
fputs(outputbuffer, job->dfile);
fputs(dk3bm_c8_kw[74], job->dfile);
sprintf(outputbuffer, dk3bm_c8_kw[77], 0.9 * dx);
dk3bm_correct_output_buffer(outputbuffer);
fputs(outputbuffer, job->dfile);
fputs(dk3bm_c8_kw[75], job->dfile);
sprintf(outputbuffer, dk3bm_c8_kw[72], job->x_0+dx, job->y_0+dx);
dk3bm_correct_output_buffer(outputbuffer);
fputs(outputbuffer, job->dfile);
sprintf(outputbuffer, dk3bm_c8_kw[73], job->x_1-dx, job->y_1-dx);
dk3bm_correct_output_buffer(outputbuffer);
fputs(outputbuffer, job->dfile);
fputs(dk3bm_c8_kw[79], job->dfile);
fputs(dk3bm_c8_kw[78], job->dfile);
sprintf(outputbuffer, dk3bm_c8_kw[72], job->x_0+dx, job->y_1-dx);
dk3bm_correct_output_buffer(outputbuffer);
fputs(outputbuffer, job->dfile);
sprintf(outputbuffer, dk3bm_c8_kw[73], job->x_1-dx, job->y_0+dx);
dk3bm_correct_output_buffer(outputbuffer);
fputs(outputbuffer, job->dfile);
fputs(dk3bm_c8_kw[79], job->dfile);
fputs(dk3bm_c8_kw[5], job->dfile);
switch((job->opt)->mode) {
case DK3_BMEPS_MODE_IMAGE:
case DK3_BMEPS_MODE_DOCUMENT: {
if((job->opt)->dr == DK3_BMEPS_DRIVER_PS) {
fputs(dk3bm_c8_kw[6], job->dfile); /* showpage */
}
} break;
}
dk3bm_ps_document_footer(job);
#line 2491 "dk3bm.ctr"
return back;
}
/** Do the real work when producing a PS document.
@param job Job structure.
@return 1 on success, 0 on error.
*/
static
int
dk3bm_job_produce_doc_real_ps(dk3_bm_conversion_job_t *job)
{
double dmaxwidth = 0.0; /* Max width PS points. */
double dmaxheight = 0.0; /* Max height PS points. */
double xres; /* X res current frame. */
double yres; /* Y res current frame. */
double deltax; /* Real x width. */
double deltay; /* Real y width. */
double sx; /* Scale factor x. */
double sy; /* Scale factor y. */
dk3_bif_coord_t maxwidth = 0L; /* Max width pixels. */
dk3_bif_coord_t maxheight = 0L; /* Max height pixels. */
dk3_bif_coord_t w; /* Current frame width. */
dk3_bif_coord_t h; /* Current frame height. */
size_t nFrames; /* Number of frames. */
size_t cf; /* Current frame. */
int me = 0; /* Math error. */
int workmode = 0; /* Transformation mode. */
int back = 1;
int must_rotate = 0; /* Flag: Must rotate. */
#if DK3_USE_WX
int minpb; /* Original min progress bar value. */
int maxpb; /* Original max progress bar value. */
#endif
#line 2527 "dk3bm.ctr"
#if DK3_USE_WX
minpb = job->minpb;
maxpb = job->maxpb;
#endif
switch((job->opt)->szmode) {
case DK3_BMEPS_SIZE_1_1: {
#line 2533 "dk3bm.ctr"
workmode = 0;
} break;
case DK3_BMEPS_SIZE_CHUNK: case DK3_BMEPS_SIZE_SPECIFIED: {
workmode = 1;
#line 2537 "dk3bm.ctr"
} break;
case DK3_BMEPS_SIZE_PAPER: {
#line 2539 "dk3bm.ctr"
workmode = 2;
if(!dk3bm_check_paper_size(&(((job->opt)->ima).ps))) {
back = 0;
/* ERROR: Incorrect paper size setup! */
dk3bmj_log_1(
(job->opt)->app, DK3_LL_ERROR, job->msg, 62, DK3_BMJ_LOG_BOTH, job
);
}
} break;
}
if(back) {
nFrames = dk3bif_number_of_frames(job->bif);
for(cf = 0; cf < nFrames; cf++) {
dk3bif_set_frame(job->bif, cf);
job->currentPage = cf + 1;
w = dk3bif_get_width(job->bif);
h = dk3bif_get_height(job->bif);
if(w > maxwidth) { maxwidth = w; }
if(h > maxheight) { maxheight = h; }
if(workmode == 1) {
switch((job->opt)->szmode) {
case DK3_BMEPS_SIZE_SPECIFIED: {
#line 2561 "dk3bm.ctr"
xres = yres = (job->opt)->resolution;
} break;
default: {
#line 2564 "dk3bm.ctr"
xres = dk3bif_get_xres(job->bif);
yres = dk3bif_get_yres(job->bif);
} break;
}
if(xres <= 0.0) { xres = 72.0; }
if(yres <= 0.0) { yres = 72.0; }
if(fabs(xres - 72.0) > dk3bm_epsilon) {
deltax = dk3ma_d_mul_ok(
72.0,
dk3ma_d_div_ok(dk3bm_l_to_d(w), xres, &me),
&me
);
} else {
deltax = dk3bm_l_to_d(w);
}
if(fabs(yres - 72.0) > dk3bm_epsilon) {
deltay = dk3ma_d_mul_ok(
72.0,
dk3ma_d_div_ok(dk3bm_l_to_d(h), yres, &me),
&me
);
} else {
deltay = dk3bm_l_to_d(h);
}
if(deltax > dmaxwidth) { dmaxwidth = deltax; }
if(deltay > dmaxheight) { dmaxheight = deltay; }
}
}
switch(workmode) {
case 0: {
job->x_size = maxwidth;
job->y_size = maxheight;
} break;
case 1: {
dmaxwidth = ceil(dmaxwidth);
dmaxheight = ceil(dmaxheight);
job->x_size = dk3ma_d_to_l_ok(dmaxwidth, &me);
job->y_size = dk3ma_d_to_l_ok(dmaxheight, &me);
} break;
case 2: {
job->x_size = dk3ma_d_to_l_ok(floor(((job->opt)->ima).ps.w), &me);
job->y_size = dk3ma_d_to_l_ok(floor(((job->opt)->ima).ps.h), &me);
} break;
}
/*
Produce output.
*/
if(back) {
job->nPages = nFrames;
dk3bm_ps_document_header(job, job->nPages);
job->do_header_footer = 0;
for(cf = 0; cf < nFrames; cf++) {
#if DK3_USE_WX
job->minpb = minpb + (int)cf * (maxpb - minpb) / (int)nFrames;
job->maxpb = minpb + (1 + (int)cf) * (maxpb - minpb) / (int)nFrames;
if(job->minpb < minpb) { job->minpb = minpb; }
if(job->maxpb > maxpb) { job->maxpb = maxpb; }
#endif
dk3bif_set_frame(job->bif, cf);
w = dk3bif_get_width(job->bif);
h = dk3bif_get_height(job->bif);
job->currentPage = cf + 1;
job->x_translate = 0.0;
job->y_translate = 0.0;
job->x_0 = 0.0;
job->y_0 = 0.0;
job->x_1 = 0.0;
job->y_1 = 0.0;
job->x_scale = 1.0;
job->y_scale = 1.0;
job->do_translate = 0;
job->do_float_scale = 0;
job->do_rotate = 0;
must_rotate = 0;
switch(workmode) {
case 0: {
if(w < maxwidth) {
job->x_translate = 0.5 * dk3bm_l_to_d(maxwidth - w);
job->do_translate = 1;
}
if(h < maxheight) {
job->y_translate = 0.5 * dk3bm_l_to_d(maxheight - h);
job->do_translate = 1;
}
if(job->do_translate) {
job->x_scale = dk3bm_l_to_d(w);
job->y_scale = dk3bm_l_to_d(h);
job->do_float_scale = 1;
}
} break;
case 1: {
job->do_float_scale = 1;
job->do_translate = 1;
switch((job->opt)->szmode) {
case DK3_BMEPS_SIZE_SPECIFIED: {
#line 2659 "dk3bm.ctr"
xres = yres = (job->opt)->resolution;
} break;
default: {
#line 2662 "dk3bm.ctr"
xres = dk3bif_get_xres(job->bif);
yres = dk3bif_get_yres(job->bif);
} break;
}
if(xres <= 0.0) { xres = 72.0; }
if(yres <= 0.0) { yres = 72.0; }
if(fabs(xres - 72.0) > dk3bm_epsilon) {
deltax = dk3ma_d_mul_ok(
72.0,
dk3ma_d_div_ok(dk3bm_l_to_d(w), xres, &me),
&me
);
} else {
deltax = dk3bm_l_to_d(w);
}
if(fabs(yres - 72.0) > dk3bm_epsilon) {
deltay = dk3ma_d_mul_ok(
72.0,
dk3ma_d_div_ok(dk3bm_l_to_d(h), yres, &me),
&me
);
} else {
deltay = dk3bm_l_to_d(h);
}
job->x_scale = deltax;
job->y_scale = deltay;
job->x_translate = 0.5 * (dmaxwidth - deltax);
job->y_translate = 0.5 * (dmaxheight - deltay);
} break;
case 2: {
job->do_float_scale = 1;
job->do_translate = 1;
if((job->opt)->duplex) {
if((job->opt)->tumble) {
if((job->currentPage) % 2) {
job->y_0 = ((job->opt)->ima).ps.b;
job->y_1 = ((job->opt)->ima).ps.h - ((job->opt)->ima).ps.t;
} else {
job->y_0 = ((job->opt)->ima).ps.t;
job->y_1 = ((job->opt)->ima).ps.h - ((job->opt)->ima).ps.b;
}
job->x_0 = ((job->opt)->ima).ps.i;
job->x_1 = ((job->opt)->ima).ps.w - ((job->opt)->ima).ps.o;
} else {
if((job->currentPage) % 2) {
job->x_0 = ((job->opt)->ima).ps.i;
job->x_1 = ((job->opt)->ima).ps.w - ((job->opt)->ima).ps.o;
} else {
job->x_0 = ((job->opt)->ima).ps.o;
job->x_1 = ((job->opt)->ima).ps.w - ((job->opt)->ima).ps.i;
}
job->y_0 = ((job->opt)->ima).ps.b;
job->y_1 = ((job->opt)->ima).ps.h - ((job->opt)->ima).ps.t;
}
} else {
job->x_0 = ((job->opt)->ima).ps.i;
job->x_1 = ((job->opt)->ima).ps.w - ((job->opt)->ima).ps.o;
job->y_0 = ((job->opt)->ima).ps.b;
job->y_1 = ((job->opt)->ima).ps.h - ((job->opt)->ima).ps.t;
}
xres = dk3bif_get_xres(job->bif);
yres = dk3bif_get_yres(job->bif);
if(xres <= 0.0) xres = 72.0;
if(yres <= 0.0) yres = 72.0;
if(fabs(xres - 72.0) > dk3bm_epsilon) {
deltax = dk3ma_d_mul_ok(
72.0,
dk3ma_d_div_ok(dk3bm_l_to_d(w), xres, &me),
&me
);
} else {
deltax = dk3bm_l_to_d(w);
}
if(fabs(yres - 72.0) > dk3bm_epsilon) {
deltay = dk3ma_d_mul_ok(
72.0,
dk3ma_d_div_ok(dk3bm_l_to_d(h), yres, &me),
&me
);
} else {
deltay = dk3bm_l_to_d(h);
}
if((job->y_1 - job->y_0) > (job->x_1 - job->x_0)) {
if(deltax > deltay) {
must_rotate = 1;
}
} else {
if((job->y_1 - job->y_0) < (job->x_1 - job->x_0)) {
if(deltax > deltay) {
must_rotate = 1;
}
}
}
if(must_rotate) {
job->do_rotate = 1;
sx = dk3ma_d_div_ok((job->y_1 - job->y_0), deltax, &me);
sy = dk3ma_d_div_ok((job->x_1 - job->x_0), deltay, &me);
if(sx < sy) {
job->x_scale = job->y_1 - job->y_0;
job->y_scale = dk3ma_d_mul_ok(sx, deltay, &me);
job->x_translate = job->x_1 - 0.5 * (job->x_1 - job->x_0 - job->y_scale);
job->y_translate = job->y_0;
} else {
job->y_scale = job->x_1 - job->x_0;
job->x_scale = dk3ma_d_mul_ok(sy, deltax, &me);
job->x_translate = job->x_1;
job->y_translate = job->y_0 + 0.5 * (job->y_1 - job->y_0 - job->x_scale);
}
} else {
sx = dk3ma_d_div_ok((job->x_1 - job->x_0), deltax, &me);
sy = dk3ma_d_div_ok((job->y_1 - job->y_0), deltay, &me);
if(sx < sy) {
job->x_scale = job->x_1 - job->x_0;
job->y_scale = dk3ma_d_mul_ok(sx, deltay, &me);
job->x_translate = job->x_0;
job->y_translate = job->y_0 + 0.5 * (job->y_1 - job->y_0 - job->y_scale);
} else {
job->y_scale = job->y_1 - job->y_0;
job->x_scale = dk3ma_d_mul_ok(sy, deltax, &me);
job->y_translate = job->y_0;
job->x_translate = job->x_0 + 0.5 * (job->x_1 - job->x_0 - job->x_scale);
}
}
#line 2786 "dk3bm.ctr"
#line 2787 "dk3bm.ctr"
#line 2788 "dk3bm.ctr"
#line 2789 "dk3bm.ctr"
#line 2790 "dk3bm.ctr"
} break;
}
/*
Output current frame.
*/
if(back) {
if(!dk3bm_job_produce_img_job_real_ps(job)) {
back = 0;
}
}
#if DK3_USE_WX
dk3bmj_progress(job->pComm, job->maxpb);
#endif
}
dk3bm_ps_document_footer(job);
}
}
#if DK3_USE_WX
job->minpb = minpb;
job->maxpb = maxpb;
#endif
#line 2812 "dk3bm.ctr"
return back;
}
/** Produce PS document.
@param job Conversion job.
@return 1 on success, 0 on error.
*/
static
int
dk3bm_job_produce_doc_ps(dk3_bm_conversion_job_t *job)
{
int back = 0;
#if DK3_USE_WX
int min; /* Original min progress bar value. */
int max; /* Original max progress bar value. */
#endif
/* PROGRESS: Reading image. */
#line 2832 "dk3bm.ctr"
dk3app_log_1((job->opt)->app, DK3_LL_PROGRESS, job->msg, 47);
#if DK3_USE_WX
min = job->minpb;
max = job->maxpb;
#endif
if(dk3bif_read_data(job->bif)) {
#line 2838 "dk3bm.ctr"
#if DK3_USE_WX
#line 2840 "dk3bm.ctr"
dk3bmj_progress(job->pComm, job->minpb + (job->maxpb - job->minpb)/3);
job->minpb = job->minpb + ((job->maxpb - job->minpb)/3);
#endif
if(job->dfile) {
back = dk3bm_job_produce_doc_real_ps(job);
} else {
job->dfile = dk3sf_fopen_app(
job->dfn,
dk3app_not_localized(24),
(job->opt)->app
);
if(job->dfile) {
back = dk3bm_job_produce_doc_real_ps(job);
if(!dk3sf_fclose_fn_app(job->dfile, job->dfn, (job->opt)->app)) {
back = 0;
}
job->dfile = NULL;
} else {
/* ERROR: Failed to open output file! */
dk3bmj_log_i3(
(job->opt)->app, DK3_LL_ERROR, 77, 78, job->dfn, DK3_BMJ_LOG_JOB, job
);
}
}
} else {
#line 2865 "dk3bm.ctr"
/* ERROR: Failed to read image data! */
dk3bmj_log_1(
(job->opt)->app, DK3_LL_ERROR, job->msg, 61, DK3_BMJ_LOG_BOTH, job
);
}
#if DK3_USE_WX
job->minpb = min;
job->maxpb = max;
#endif
#line 2875 "dk3bm.ctr"
return back;
}
/** Produce PS image or object.
@param job Conversion job.
@return 1 on success, 0 on error.
*/
static
int
dk3bm_job_produce_img_obj_ps(dk3_bm_conversion_job_t *job)
{
double w; /* Image width used. */
double h; /* Image height used. */
double xr = 0.0; /* X resolution. */
double yr = 0.0; /* Y resolution. */
int back = 1;
int ur = 0; /* Flag: Use resolution. */
int ec = 0; /* Math error code. */
#line 2896 "dk3bm.ctr"
/*
Prepare for size 1:1.
*/
job->x_size = dk3bif_get_width(job->bif);
job->y_size = dk3bif_get_height(job->bif);
job->x_1 = dk3bm_l_to_d(job->x_size);
job->y_1 = dk3bm_l_to_d(job->y_size);
#line 2904 "dk3bm.ctr"
/*
Attempt to use other size/resolution if required.
*/
switch((job->opt)->szmode) {
case DK3_BMEPS_SIZE_CHUNK: {
#line 2909 "dk3bm.ctr"
xr = dk3bif_get_xres(job->bif);
yr = dk3bif_get_yres(job->bif);
#line 2911 "dk3bm.ctr"
if((xr > 0.0) && (yr > 0.0)) {
#line 2913 "dk3bm.ctr"
if(fabs(xr - 72.0) > dk3bm_epsilon) {
ur = 1;
}
#line 2917 "dk3bm.ctr"
if(fabs(yr - 72.0) > dk3bm_epsilon) {
ur = 1;
}
}
} break;
case DK3_BMEPS_SIZE_SPECIFIED: {
#line 2923 "dk3bm.ctr"
if((job->opt)->resolution > 0.0) {
#line 2925 "dk3bm.ctr"
if(fabs((job->opt)->resolution - 72.0) > dk3bm_epsilon) {
xr = yr = (job->opt)->resolution;
#line 2927 "dk3bm.ctr"
ur = 1;
}
}
} break;
}
/*
If we have to use a resolution, calculate dimensions.
*/
if(ur) {
#line 2936 "dk3bm.ctr"
w = dk3bm_l_to_d(job->x_size);
#line 2937 "dk3bm.ctr"
h = dk3bm_l_to_d(job->y_size);
#line 2938 "dk3bm.ctr"
w = dk3ma_d_mul_ok(72.0, dk3ma_d_div_ok(w, xr, &ec), &ec);
h = dk3ma_d_mul_ok(72.0, dk3ma_d_div_ok(h, yr, &ec), &ec);
job->x_1 = ceil(w);
#line 2941 "dk3bm.ctr"
job->y_1 = ceil(h);
job->x_size = dk3ma_d_to_l_ok(job->x_1, &ec);
job->y_size = dk3ma_d_to_l_ok(job->y_1, &ec);
#line 2945 "dk3bm.ctr"
job->x_translate = 0.5 * (job->x_1 - w);
job->y_translate = 0.5 * (job->y_1 - h);
if(job->x_translate < 0.0) { job->x_translate = 0.0; }
if(job->y_translate < 0.0) { job->y_translate = 0.0; }
job->do_translate = 1;
job->x_0 = job->x_translate;
job->y_0 = job->y_translate;
job->x_1 = job->x_0 + w;
job->y_1 = job->y_0 + h;
if(job->x_1 > dk3bm_l_to_d(job->x_size)) {
job->x_1 = dk3bm_l_to_d(job->x_size);
}
if(job->y_1 > dk3bm_l_to_d(job->y_size)) {
job->y_1 = dk3bm_l_to_d(job->y_size);
}
job->x_scale = w;
job->y_scale = h;
job->do_float_scale = 1;
#line 2964 "dk3bm.ctr"
#line 2965 "dk3bm.ctr"
#line 2966 "dk3bm.ctr"
#line 2967 "dk3bm.ctr"
#line 2968 "dk3bm.ctr"
#line 2969 "dk3bm.ctr"
#line 2970 "dk3bm.ctr"
#line 2971 "dk3bm.ctr"
#line 2972 "dk3bm.ctr"
#line 2973 "dk3bm.ctr"
if(ec) {
#line 2974 "dk3bm.ctr"
back = 0;
dk3bmj_log_i1(
(job->opt)->app, DK3_LL_ERROR, 260, DK3_BMJ_LOG_BOTH, job
);
}
}
/*
If no error yet, go on.
*/
if(back) {
if((job->opt)->draft) {
#line 2985 "dk3bm.ctr"
if(job->dfile) {
#line 2986 "dk3bm.ctr"
back = dk3bm_job_produce_img_job_draft_ps(job);
} else {
#line 2988 "dk3bm.ctr"
job->dfile = dk3sf_fopen_app(
job->dfn,
dk3app_not_localized(24),
(job->opt)->app
);
if(job->dfile) {
#line 2994 "dk3bm.ctr"
back = dk3bm_job_produce_img_job_draft_ps(job);
if(!dk3sf_fclose_fn_app(job->dfile, job->dfn, (job->opt)->app)) {
back = 0;
}
job->dfile = NULL;
} else {
#line 3000 "dk3bm.ctr"
back = 0;
/* ERROR: Failed to open output file! */
dk3bmj_log_i3(
(job->opt)->app, DK3_LL_ERROR, 77, 78, job->dfn,
DK3_BMJ_LOG_JOB, job
);
}
}
} else {
#line 3009 "dk3bm.ctr"
/* PROGRESS: Reading image. */
dk3app_log_1((job->opt)->app, DK3_LL_PROGRESS, job->msg, 47);
if(dk3bif_read_data(job->bif)) {
#line 3012 "dk3bm.ctr"
#if DK3_USE_WX
#line 3014 "dk3bm.ctr"
dk3bmj_progress(job->pComm, job->minpb + (job->maxpb - job->minpb)/3);
job->minpb = job->minpb + ((job->maxpb - job->minpb)/3);
#endif
if(job->dfile) {
#line 3018 "dk3bm.ctr"
back = dk3bm_job_produce_img_job_real_ps(job);
} else {
#line 3020 "dk3bm.ctr"
job->dfile = dk3sf_fopen_app(
job->dfn,
dk3app_not_localized(24),
(job->opt)->app
);
if(job->dfile) {
#line 3026 "dk3bm.ctr"
back = dk3bm_job_produce_img_job_real_ps(job);
if(!dk3sf_fclose_fn_app(job->dfile, job->dfn, (job->opt)->app)) {
back = 0;
}
job->dfile = NULL;
} else {
#line 3032 "dk3bm.ctr"
back = 0;
/* ERROR: Failed to open output file! */
dk3bmj_log_i3(
(job->opt)->app, DK3_LL_ERROR, 77, 78, job->dfn,
DK3_BMJ_LOG_JOB, job
);
}
}
} else {
#line 3041 "dk3bm.ctr"
back = 0;
/* ERROR: Failed to read image data! */
dk3bmj_log_1(
(job->opt)->app, DK3_LL_ERROR, job->msg, 61, DK3_BMJ_LOG_BOTH, job
);
}
}
}
#line 3049 "dk3bm.ctr"
return back;
}
/** Produce PS/EPS output.
@param job Job structure.
@return 1 on success, 0 on error.
*/
static
int
dk3bm_job_produce_ps(dk3_bm_conversion_job_t *job)
{
int back = 0;
#line 3064 "dk3bm.ctr"
switch((job->opt)->mode) {
case DK3_BMEPS_MODE_DOCUMENT: {
#line 3066 "dk3bm.ctr"
back = dk3bm_job_produce_doc_ps(job);
} break;
default: {
#line 3069 "dk3bm.ctr"
back = dk3bm_job_produce_img_obj_ps(job);
} break;
}
#line 3072 "dk3bm.ctr"
return back;
}
/** Add one image frame as output page.
@param job Conversion job.
@param pageno Page number of frame to add.
@return 1 on success, 0 on error.
*/
static
int
dk3bm_job_add_pdf_frame(dk3_bm_conversion_job_t *job, size_t pageno)
{
dk3_bif_coord_t w; /* Image width. */
dk3_bif_coord_t h; /* Image height. */
double xres = 0.0; /* X resolution. */
double yres = 0.0; /* Y resolution. */
double dw; /* Image width on paper. */
double dh; /* Image height on paper. */
double px0; /* Left x (paper). */
double px1; /* Right x (paper). */
double py0; /* Lower y (paper). */
double py1; /* Upper y (paper). */
double width; /* Paper width. */
double height; /* Paper height. */
double sx; /* Scale factor for x direction. */
double sy; /* Scale factor for y direction. */
long mbx0; /* Left x (media box). */
long mbx1; /* Right x (media box). */
long mby0; /* Lower y (media box). */
long mby1; /* Upper y (media box). */
int workmode; /* Transformation mode. */
int back = 1;
int me = 0; /* Flag: Math error. */
#line 3108 "dk3bm.ctr"
/*
Re-initialize (we probably have to handle multiple frames in one job.
*/
job->x_translate = 0.0;
job->y_translate = 0.0;
job->x_scale = 1.0;
job->y_scale = 1.0;
job->x_0 = 0.0;
job->x_1 = 0.0;
job->y_0 = 0.0;
job->y_1 = 0.0;
job->x_size = 0L;
job->y_size = 0L;
job->bpc = 8;
job->do_translate = 0;
job->do_rotate = 0;
job->do_float_scale = 0;
job->procedure = 0;
workmode = 0;
mbx0 = mbx1 = mby0 = mby1 = 0L;
/*
Process image width, height and resolution.
*/
w = dk3bif_get_width(job->bif);
h = dk3bif_get_height(job->bif);
switch((job->opt)->szmode) {
case DK3_BMEPS_SIZE_CHUNK: {
#line 3135 "dk3bm.ctr"
xres = dk3bif_get_xres(job->bif);
yres = dk3bif_get_yres(job->bif);
if(xres > 0.0) {
if(yres > 0.0) {
if((fabs(xres - 72.0) > dk3bm_epsilon)
|| (fabs(yres - 72.0) > dk3bm_epsilon))
{
workmode = 1;
}
}
}
} break;
case DK3_BMEPS_SIZE_SPECIFIED: {
#line 3148 "dk3bm.ctr"
xres = yres = (job->opt)->resolution;
if(xres > 0.0) {
if(fabs(xres - 72.0) > dk3bm_epsilon) {
workmode = 1;
}
}
} break;
case DK3_BMEPS_SIZE_PAPER: {
#line 3156 "dk3bm.ctr"
workmode = 2;
xres = dk3bif_get_xres(job->bif);
yres = dk3bif_get_yres(job->bif);
if(xres <= 0.0) { xres = 72.0; }
if(yres <= 0.0) { yres = 72.0; }
if(fabs(xres - 72.0) <= dk3bm_epsilon) {
xres = 72.0;
}
if(fabs(yres - 72.0) <= dk3bm_epsilon) {
yres = 72.0;
}
} break;
default: {
#line 3169 "dk3bm.ctr"
workmode = 0;
} break;
}
switch(workmode) {
case 2: {
dw = dk3ma_d_mul_ok(
72.0,
dk3ma_d_div_ok(dk3bm_l_to_d(w), xres, &me),
&me
);
dh = dk3ma_d_mul_ok(
72.0,
dk3ma_d_div_ok(dk3bm_l_to_d(h), yres, &me),
&me
);
#line 3184 "dk3bm.ctr"
if(dk3bm_check_paper_size(&(((job->opt)->ima).ps))) {
width = floor(((job->opt)->ima).ps.w);
height = floor(((job->opt)->ima).ps.h);
#line 3188 "dk3bm.ctr"
#line 3189 "dk3bm.ctr"
mbx1 = dk3ma_d_to_l_ok(width, &me);
mby1 = dk3ma_d_to_l_ok(height, &me);
if((job->opt)->duplex) {
if((job->opt)->tumble) {
if(pageno % 2) { /* Rueckseite */
px0 = ((job->opt)->ima).ps.i;
px1 = width - ((job->opt)->ima).ps.o;
py0 = ((job->opt)->ima).ps.t;
py1 = height - ((job->opt)->ima).ps.b;
} else { /* Vorderseite */
px0 = ((job->opt)->ima).ps.i;
px1 = width - ((job->opt)->ima).ps.o;
py0 = ((job->opt)->ima).ps.b;
py1 = height - ((job->opt)->ima).ps.t;
}
} else {
if(pageno % 2) { /* Rueckseite */
px0 = ((job->opt)->ima).ps.o;
px1 = width - ((job->opt)->ima).ps.i;
py0 = ((job->opt)->ima).ps.b;
py1 = height - ((job->opt)->ima).ps.t;
} else { /* Vorderseite */
px0 = ((job->opt)->ima).ps.i;
px1 = width - ((job->opt)->ima).ps.o;
py0 = ((job->opt)->ima).ps.b;
py1 = height - ((job->opt)->ima).ps.t;
}
}
} else {
px0 = ((job->opt)->ima).ps.i;
px1 = width - ((job->opt)->ima).ps.o;
py0 = ((job->opt)->ima).ps.b;
py1 = height - ((job->opt)->ima).ps.t;
}
if((px1 > px0) && (py1 > py0)) {
if((py1 - py0) > (px1 - px0)) {
#line 3225 "dk3bm.ctr"
if(dw > dh) {
#line 3226 "dk3bm.ctr"
job->do_rotate = 1;
} else {
#line 3228 "dk3bm.ctr"
}
} else {
#line 3230 "dk3bm.ctr"
if((py1 - py0) < (px1 - px0)) {
#line 3231 "dk3bm.ctr"
if(dh > dw) {
#line 3232 "dk3bm.ctr"
job->do_rotate = 1;
} else {
}
}
}
#line 3238 "dk3bm.ctr"
#line 3239 "dk3bm.ctr"
#line 3240 "dk3bm.ctr"
#line 3241 "dk3bm.ctr"
if(job->do_rotate) {
#line 3242 "dk3bm.ctr"
sx = dk3ma_d_div_ok((py1 - py0), dw, &me);
sy = dk3ma_d_div_ok((px1 - px0), dh, &me);
if(sx > sy) {
#line 3245 "dk3bm.ctr"
job->y_scale = (px1 - px0);
job->x_scale = sy * dw;
job->x_translate = px1;
job->y_translate = py0 + 0.5 * (py1 - py0 - job->x_scale);
if(job->y_translate < py0) { job->y_translate = py0; }
} else {
#line 3251 "dk3bm.ctr"
job->x_scale = (py1 - py0);
job->y_scale = sx * dh;
job->x_translate = px1 - 0.5 * (px1 - px0 - job->y_scale);
if(job->x_translate > px1) { job->x_translate = px1; }
job->y_translate = py0;
}
} else {
#line 3258 "dk3bm.ctr"
sx = dk3ma_d_div_ok((px1 - px0), dw, &me);
sy = dk3ma_d_div_ok((py1 - py0), dh, &me);
if(sx > sy) {
#line 3261 "dk3bm.ctr"
job->y_scale = py1 - py0;
job->x_scale = sy * dw;
job->x_translate = px0 + 0.5 * (px1 - px0 - job->x_scale);
if(job->x_translate < px0) { job->x_translate = px0; }
job->y_translate = py0;
} else {
#line 3267 "dk3bm.ctr"
job->x_scale = px1 - px0;
job->y_scale = sx * dh;
job->y_translate = py0 + 0.5 * (py1 - py0 - job->y_scale);
if(job->y_translate < py0) { job->y_translate = py0; }
job->x_translate = px0;
}
}
job->do_translate = 1;
job->do_float_scale = 1;
} else {
#line 3277 "dk3bm.ctr"
back = 0;
/* ERROR Page setup incorrect */
dk3bmj_log_i1(
(job->opt)->app, DK3_LL_ERROR, 259,
DK3_BMJ_LOG_BOTH, job
);
}
} else {
back = 0;
}
#line 3288 "dk3bm.ctr"
#line 3289 "dk3bm.ctr"
#line 3290 "dk3bm.ctr"
#line 3291 "dk3bm.ctr"
#line 3292 "dk3bm.ctr"
} break;
case 1: {
dw = dk3ma_d_mul_ok(
72.0,
dk3ma_d_div_ok(dk3bm_l_to_d(w), xres, &me),
&me
);
dh = dk3ma_d_mul_ok(
72.0,
dk3ma_d_div_ok(dk3bm_l_to_d(h), yres, &me),
&me
);
job->x_scale = dw;
job->y_scale = dh;
job->x_size = dk3ma_d_to_l_ok(ceil(dw), &me);
job->y_size = dk3ma_d_to_l_ok(ceil(dh), &me);
job->do_float_scale = 1;
job->x_translate = 0.5 * dk3ma_d_sub_ok(job->x_size, dw, &me);
job->y_translate = 0.5 * dk3ma_d_sub_ok(job->y_size, dh, &me);
if(job->x_translate < 0.0) { job->x_translate = 0.0; }
if(job->y_translate < 0.0) { job->y_translate = 0.0; }
job->do_translate = 1;
mbx1 = dk3ma_d_to_l_ok(job->x_size, &me);
mby1 = dk3ma_d_to_l_ok(job->y_size, &me);
} break;
default: {
#line 3318 "dk3bm.ctr"
mbx0 = 0L; mby0 = 0L; mbx1 = w; mby1 = h;
job->x_size = w; job->y_size = h;
} break;
}
dk3pdf_set_next_mediabox(job->pdf, mbx0, mbx1, mby0, mby1);
if(me) {
#line 3324 "dk3bm.ctr"
back = 0;
}
if(back == 1) {
#line 3327 "dk3bm.ctr"
if(dk3pdf_open_page(job->pdf)) {
#line 3328 "dk3bm.ctr"
if(job->do_translate) {
dk3pdf_translate_double(job->pdf, job->x_translate, job->y_translate);
}
if(job->do_rotate) {
dk3pdf_rotate_int(job->pdf, 90);
}
if(job->do_float_scale) {
dk3pdf_scale_double(job->pdf, job->x_scale, job->y_scale);
} else {
dk3pdf_scale_long(job->pdf, mbx1, mby1);
}
if(dk3pdf_add_image_progress(
job->pdf, job->bif, job->opt, job->pComm, job->minpb, job->maxpb
)
)
{
back = 1;
#line 3345 "dk3bm.ctr"
} else {
back = 0;
#line 3347 "dk3bm.ctr"
dk3bmj_log_1(
(job->opt)->app, DK3_LL_ERROR, job->msg, 73,
DK3_BMJ_LOG_BOTH, job
);
}
dk3pdf_close_page(job->pdf);
} else {
#line 3354 "dk3bm.ctr"
dk3bmj_log_1(
(job->opt)->app, DK3_LL_ERROR, job->msg, 71,
DK3_BMJ_LOG_JOB, job
);
}
} else {
back = 0;
/* ERROR: Math error! */
dk3bmj_log_i1(
(job->opt)->app, DK3_LL_ERROR, 260,
DK3_BMJ_LOG_BOTH, job
);
}
#line 3367 "dk3bm.ctr"
return back;
}
/** Produce PDF output.
@param job Job structure.
@return 1 on success, 0 on error.
*/
static
int
dk3bm_job_produce_file_pdf(dk3_bm_conversion_job_t *job)
{
size_t nFrames; /* Number of frames. */
size_t i; /* Current frame index. */
int back = 0;
#if DK3_USE_WX
int min; /* Original min progress bar value. */
int max; /* Original max progress bar value. */
int xmax; /* Intermediate progress bar value. */
#endif
#line 3389 "dk3bm.ctr"
#if DK3_USE_WX
min = job->minpb;
max = job->maxpb;
job->maxpb = xmax = min + ((14 * (max - min)) / 15);
#endif
job->pdf = dk3pdf_open_app((job->opt)->app);
if(job->pdf) {
back = 1;
#line 3398 "dk3bm.ctr"
switch((job->opt)->mode) {
case DK3_BMEPS_MODE_DOCUMENT: {
#line 3400 "dk3bm.ctr"
nFrames = dk3bif_number_of_frames(job->bif);
for(i = 0; i < nFrames; i++) {
#if DK3_USE_WX
job->minpb = min + ((((int)i) * (xmax - min)) / (int)nFrames);
job->maxpb = min + (((((int)i) + 1) * (xmax - min)) / (int)nFrames);
#endif
if(dk3bif_set_frame(job->bif, i)) {
if(!dk3bm_job_add_pdf_frame(job, i)) {
back = 0;
}
} else {
back = 0;
/* ERROR: Failed to set frame! */
dk3bmj_log_i1(
(job->opt)->app, DK3_LL_ERROR, 261, DK3_BMJ_LOG_BOTH, job
);
}
#if DK3_USE_WX
#line 3419 "dk3bm.ctr"
dk3bmj_progress(job->pComm, job->maxpb);
#endif
}
} break;
default: {
#line 3424 "dk3bm.ctr"
if(!dk3bm_job_add_pdf_frame(job, 0)) {
back = 0;
}
} break;
}
#if DK3_USE_WX
#line 3431 "dk3bm.ctr"
dk3bmj_progress(job->pComm, job->maxpb);
job->minpb = job->maxpb;
job->maxpb = max;
#endif
if(!dk3pdf_write_file_progress(
job->pdf, job->dfile, job->pComm, job->minpb, job->maxpb)
)
{
back = 0;
dk3bmj_log_1(
(job->opt)->app, DK3_LL_ERROR, job->msg, 72,
DK3_BMJ_LOG_JOB, job
);
}
dk3pdf_close(job->pdf); job->pdf = NULL;
} else {
/* ERROR: Failed to create PDF job! */
dk3bmj_log_i1(
(job->opt)->app, DK3_LL_ERROR, 9,
DK3_BMJ_LOG_JOB, job
);
}
#if DK3_USE_WX
job->minpb = min;
job->maxpb = max;
#endif
#line 3458 "dk3bm.ctr"
return back;
}
/** Produce draft PDF output.
@param job Job structure.
@return 1 on success, 0 on error.
*/
static
int
dk3bm_job_draft_pdf(dk3_bm_conversion_job_t *job)
{
dk3_pdf_t *pdf; /* PDF writer structure. */
double x0; /* Left border. */
double x1; /* Right border. */
double y0; /* Lower border. */
double y1; /* Upper border. */
double xres = -1.0; /* X resolution. */
double yres = -1.0; /* Y resolution. */
double w; /* Width, using resolution. */
double h; /* Height, using resolution. */
double dx; /* X delta. */
double dy; /* Y delta. */
long mbx0; /* Media box x0. */
long mbx1; /* Media box x1. */
long mby0; /* Media box y0. */
long mby1; /* Media box y1. */
int me = 0; /* Flag: Math error. */
int workmode = 0; /* Work mode. */
int do_rotate = 0; /* Flag: Rotate. */
int back = 1;
#line 3491 "dk3bm.ctr"
mbx0 = mby0 = 0L;
mbx1 = dk3bif_get_width(job->bif);
mby1 = dk3bif_get_height(job->bif);
x0 = 0.0;
y0 = 0.0;
x1 = dk3bm_l_to_d(mbx1);
y1 = dk3bm_l_to_d(mby1);
switch((job->opt)->szmode) {
case DK3_BMEPS_SIZE_CHUNK: {
#line 3500 "dk3bm.ctr"
xres = dk3bif_get_xres(job->bif);
yres = dk3bif_get_yres(job->bif);
if((xres > 0.0) || (yres > 0.0)) {
if(xres <= 0.0) { xres = 72.0; }
if(yres <= 0.0) { yres = 72.0; }
if(fabs(xres - 72.0) > dk3bm_epsilon) {
workmode = 1;
}
if(fabs(yres - 72.0) > dk3bm_epsilon) {
workmode = 1;
}
}
} break;
case DK3_BMEPS_SIZE_SPECIFIED: {
#line 3514 "dk3bm.ctr"
xres = yres = (job->opt)->resolution;
if(xres > 0.0) {
if(fabs(xres - 72.0) > dk3bm_epsilon) {
workmode = 1;
}
}
} break;
case DK3_BMEPS_SIZE_PAPER: {
#line 3522 "dk3bm.ctr"
workmode = 2;
xres = dk3bif_get_xres(job->bif);
yres = dk3bif_get_yres(job->bif);
if(xres <= 0.0) { xres = 72.0; }
if(yres <= 0.0) { yres = 72.0; }
if(fabs(xres - 72.0) <= dk3bm_epsilon) { xres = 72.0; }
if(fabs(yres - 72.0) <= dk3bm_epsilon) { yres = 72.0; }
} break;
}
switch(workmode) {
case 2: { /* Fit to page */
w = dk3ma_d_div_ok(dk3bm_l_to_d(mbx1), xres, &me);
#line 3534 "dk3bm.ctr"
h = dk3ma_d_div_ok(dk3bm_l_to_d(mby1), yres, &me);
#line 3535 "dk3bm.ctr"
mbx1 = dk3ma_d_to_l_ok(floor(((job->opt)->ima).ps.w), &me);
mby1 = dk3ma_d_to_l_ok(floor(((job->opt)->ima).ps.h), &me);
#line 3538 "dk3bm.ctr"
x0 = ((job->opt)->ima).ps.i;
y0 = ((job->opt)->ima).ps.b;
x1 = dk3ma_d_sub_ok(((job->opt)->ima).ps.w, ((job->opt)->ima).ps.o, &me);
y1 = dk3ma_d_sub_ok(((job->opt)->ima).ps.h, ((job->opt)->ima).ps.t, &me);
#line 3543 "dk3bm.ctr"
if((x1 > x0) && (y1 > y0)) {
#line 3544 "dk3bm.ctr"
if((x1 - x0) > (y1 - y0)) {
if(h > w) {
#line 3546 "dk3bm.ctr"
do_rotate = 1;
}
} else {
if((x1 - x0) < (y1 - y0)) {
if(h < w) {
#line 3551 "dk3bm.ctr"
do_rotate = 1;
}
}
}
if(do_rotate) {
#line 3556 "dk3bm.ctr"
dx = dk3ma_d_div_ok((x1 - x0), h, &me);
dy = dk3ma_d_div_ok((y1 - y0), w, &me);
if(dx > dy) {
w = dk3ma_d_mul_ok(dy, h, &me);
dx = dk3ma_d_add_ok(
x0,
0.5 * dk3ma_d_sub_ok((x1 - x0), w, &me),
&me
);
dy = dk3ma_d_add_ok(dx, w, &me);
if(dx >= x0) { x0 = dx; }
if(dy <= x1) { x1 = dy; }
} else {
h = dk3ma_d_mul_ok(dx, w, &me);
dx = dk3ma_d_add_ok(
y0,
0.5 * dk3ma_d_sub_ok((y1 - y0), h, &me),
&me
);
dy = dk3ma_d_add_ok(dx, h, &me);
if(dx >= y0) { y0 = dx; }
if(dy <= y1) { y1 = dy; }
}
} else {
#line 3580 "dk3bm.ctr"
dx = dk3ma_d_div_ok((x1 - x0), w, &me);
dy = dk3ma_d_div_ok((y1 - y0), h, &me);
if(dx > dy) {
#line 3583 "dk3bm.ctr"
w = dk3ma_d_mul_ok(dy, w, &me);
dx = dk3ma_d_add_ok(
x0,
0.5 * dk3ma_d_sub_ok((x1 - x0), w, &me),
&me
);
dy = dk3ma_d_add_ok(dx, w, &me);
if(dx >= x0) { x0 = dx; }
if(dy <= x1) { x1 = dy; }
} else {
#line 3593 "dk3bm.ctr"
h = dk3ma_d_mul_ok(dx, h, &me);
dx = dk3ma_d_add_ok(
y0,
0.5 * dk3ma_d_sub_ok((y1 - y0), h, &me),
&me
);
dy = dk3ma_d_add_ok(dx, h, &me);
if(dx >= y0) { y0 = dx; }
if(dy <= y1) { y1 = dy; }
}
}
#line 3604 "dk3bm.ctr"
} else {
back = 0;
/* ERROR: Incorrect page setup. */
dk3bmj_log_i1(
(job->opt)->app, DK3_LL_ERROR, 259, DK3_BMJ_LOG_BOTH, job
);
}
} break;
case 1: { /* Use resolution */
w = dk3ma_d_div_ok(dk3bm_l_to_d(mbx1), xres, &me);
h = dk3ma_d_div_ok(dk3bm_l_to_d(mby1), yres, &me);
w = dk3ma_d_mul_ok(72.0, w, &me);
h = dk3ma_d_mul_ok(72.0, h, &me);
x1 = ceil(w);
y1 = ceil(h);
mbx1 = dk3ma_d_to_l_ok(x1, &me);
mby1 = dk3ma_d_to_l_ok(y1, &me);
x0 = 0.5 * dk3ma_d_sub_ok(x1, w, &me);
y0 = 0.5 * dk3ma_d_sub_ok(y1, h, &me);
x1 = dk3ma_d_add_ok(x0, w, &me);
y1 = dk3ma_d_add_ok(y0, h, &me);
if(x0 < 0.0) { x0 = 0.0; }
if(y0 < 0.0) { y0 = 0.0; }
if(x1 > dk3bm_l_to_d(mbx1)) { x1 = dk3bm_l_to_d(mbx1); }
if(y1 > dk3bm_l_to_d(mby1)) { y1 = dk3bm_l_to_d(mby1); }
} break;
default: { /* 1:1 */
/* Nothing to do, everything is initialized. */
} break;
}
if(me) {
back = 0;
/* ERROR: Math error occured! */
dk3bmj_log_i1(
(job->opt)->app, DK3_LL_ERROR, 260, DK3_BMJ_LOG_BOTH, job
);
}
if(back) {
back = 0;
/* Here we have all information prepared to produce the draft. */
pdf = dk3pdf_open_app((job->opt)->app);
if(pdf) {
dk3pdf_set_next_mediabox(pdf, mbx0, mbx1, mby0, mby1);
if(dk3pdf_open_page(pdf)) {
back = 1;
dx = 0.01 * (x1 - x0);
dy = 0.01 * (y1 - y0);
if(dy < dx) dx = dy;
if(dx > 2.8) dx = 2.8;
dk3pdf_set_nonstroking_gray(pdf, 0.0);
dk3pdf_newpath_moveto(pdf, x0, y0);
dk3pdf_lineto(pdf, x1, y0);
dk3pdf_lineto(pdf, x1, y1);
dk3pdf_lineto(pdf, x0, y1);
dk3pdf_closepath(pdf);
dk3pdf_fill_nz(pdf);
dk3pdf_set_nonstroking_gray(pdf, 0.8);
dk3pdf_newpath_moveto(pdf, (x0 + dx), (y0 + dx));
dk3pdf_lineto(pdf, (x1 - dx), (y0 + dx));
dk3pdf_lineto(pdf, (x1 - dx), (y1 - dx));
dk3pdf_lineto(pdf, (x0 + dx), (y1 - dx));
dk3pdf_closepath(pdf);
dk3pdf_fill_nz(pdf);
dk3pdf_set_nonstroking_gray(pdf, 1.0);
#if VERSION_BEFORE_20150821
dy = dx;
#endif
dx = 10.0 * dx;
dk3pdf_newpath_moveto(pdf, (x0 + dx), (y0 + dx));
dk3pdf_lineto(pdf, (x1 - dx), (y0 + dx));
dk3pdf_lineto(pdf, (x1 - dx), (y1 - dx));
dk3pdf_lineto(pdf, (x0 + dx), (y1 - dx));
dk3pdf_closepath(pdf);
dk3pdf_fill_nz(pdf);
dk3pdf_set_linewidth(pdf, dx);
dk3pdf_set_linecap(pdf, DK3_LINECAP_ROUND);
dk3pdf_set_stroking_gray(pdf, 0.8);
dk3pdf_newpath_moveto(pdf, (x0 + dx), (y0 + dx));
dk3pdf_lineto(pdf, (x1 - dx), (y1 - dx));
dk3pdf_stroke(pdf);
dk3pdf_newpath_moveto(pdf, (x0 + dx), (y1 - dx));
dk3pdf_lineto(pdf, (x1 - dx), (y0 + dx));
dk3pdf_stroke(pdf);
dk3pdf_close_page(pdf);
} else {
dk3bmj_log_1(
(job->opt)->app, DK3_LL_ERROR, job->msg, 71,
DK3_BMJ_LOG_JOB, job
);
}
dk3pdf_write_file(pdf, job->dfile);
dk3pdf_close(pdf);
} else {
/* ERROR: Failed to create PDF writer */
dk3bmj_log_i1(
(job->opt)->app, DK3_LL_ERROR, 9,
DK3_BMJ_LOG_JOB, job
);
}
}
#line 3705 "dk3bm.ctr"
return back;
}
/** Produce PDF output.
@param job Job structure.
@return 1 on success, 0 on error.
*/
static
int
dk3bm_job_produce_pdf(dk3_bm_conversion_job_t *job)
{
int back = 0;
#if DK3_USE_WX
int min; /* Original min progress bar value. */
int max; /* Original max progress bar value. */
#endif
#line 3724 "dk3bm.ctr"
#if DK3_USE_WX
min = job->minpb;
max = job->maxpb;
job->minpb = min + ((max - min) / 4);
#endif
if((job->opt)->draft) {
if(job->dfile) {
back = dk3bm_job_draft_pdf(job);
} else {
job->dfile = dk3sf_fopen_app(
job->dfn,
dk3app_not_localized(53),
(job->opt)->app
);
if(job->dfile) {
back = dk3bm_job_draft_pdf(job);
if(!dk3sf_fclose_fn_app(job->dfile, job->dfn, (job->opt)->app)) {
back = 0;
}
job->dfile = NULL;
} else {
/* ERROR: Failed to open output file! */
dk3bmj_log_i3(
(job->opt)->app, DK3_LL_ERROR, 77, 78, job->dfn,
DK3_BMJ_LOG_JOB, job
);
}
}
} else {
if(dk3bif_read_data(job->bif)) {
#if DK3_USE_WX
if((job->pComm) && (job->maxpb > job->minpb)) {
#line 3757 "dk3bm.ctr"
dk3bmj_progress(job->pComm, job->minpb);
}
#endif
if(job->dfile) {
back = dk3bm_job_produce_file_pdf(job);
} else {
job->dfile = dk3sf_fopen_app(
job->dfn,
dk3app_not_localized(53),
(job->opt)->app
);
if(job->dfile) {
back = dk3bm_job_produce_file_pdf(job);
if(!dk3sf_fclose_fn_app(job->dfile, job->dfn, (job->opt)->app)) {
back = 0;
}
job->dfile = NULL;
} else {
/* ERROR: Failed to open output file! */
dk3bmj_log_i3(
(job->opt)->app, DK3_LL_ERROR, 77, 78, job->dfn,
DK3_BMJ_LOG_JOB, job
);
}
}
} else {
/* ERROR: Failed to read image data! */
dk3bmj_log_1(
(job->opt)->app, DK3_LL_ERROR, job->msg, 61, DK3_BMJ_LOG_BOTH, job
);
}
}
#if DK3_USE_WX
job->minpb = min;
job->maxpb = max;
#endif
#line 3794 "dk3bm.ctr"
return back;
}
/** Produce bounding box output.
@param job Job structure.
*/
static
void
dk3bm_produce_bb(dk3_bm_conversion_job_t *job)
{
dk3_bif_coord_t w; /* Image width. */
dk3_bif_coord_t h; /* Image height. */
#line 3809 "dk3bm.ctr"
w = dk3bif_get_width(job->bif);
h = dk3bif_get_height(job->bif);
fprintf(job->dfile, dk3bm_c8_kw[31], w, h);
#line 3813 "dk3bm.ctr"
}
/** Produce bounding box output.
@param job Job structure.
@return 1 on success, 0 on error.
*/
static
int
dk3bm_job_produce_bb(dk3_bm_conversion_job_t *job)
{
int back = 0;
if(job->dfile) {
dk3bm_produce_bb(job);
back = 1;
} else {
job->dfile = dk3sf_fopen_app(
job->dfn,
dk3app_not_localized(24),
(job->opt)->app
);
if(job->dfile) {
dk3bm_produce_bb(job);
back = 1;
if(!dk3sf_fclose_fn_app(job->dfile, job->dfn, (job->opt)->app)) {
back = 0;
}
job->dfile = NULL;
} else {
dk3bmj_log_i3(
(job->opt)->app, DK3_LL_ERROR, 77, 78, job->dfn,
DK3_BMJ_LOG_JOB, job
);
}
}
return back;
}
/** Run a conversion job for either the opened file or the named file.
@param job Conversion job.
@return 1 on success, 0 on error.
*/
static
int
dk3bm_job_from_program_with_output(dk3_bm_conversion_job_t *job)
{
int back = 0;
#line 3864 "dk3bm.ctr"
job->bif = dk3bif_open_filename_app(job->sfn, job->biftype, (job->opt)->app);
if(job->bif) {
switch((job->opt)->dr) {
case DK3_BMEPS_DRIVER_PS: {
back = dk3bm_job_produce_ps(job);
} break;
case DK3_BMEPS_DRIVER_EPS: {
back = dk3bm_job_produce_ps(job);
} break;
case DK3_BMEPS_DRIVER_PDF: {
back = dk3bm_job_produce_pdf(job);
} break;
default: {
back = dk3bm_job_produce_bb(job);
} break;
}
dk3bif_close(job->bif);
} else {
dk3bmj_log_3(
(job->opt)->app, DK3_LL_ERROR, job->msg, 69, 70, job->sfn, DK3_BMJ_LOG_BOTH, job
);
}
#line 3887 "dk3bm.ctr"
return back;
}
/** Construct an output file name and run.
@param job Conversion job.
@return 1 on success, 0 on error.
*/
static
int
dk3bm_job_from_program_construct_name(dk3_bm_conversion_job_t *job)
{
dkChar fno[DK3_MAX_PATH]; /* Output file name buffer. */
dkChar *sptr; /* Pointer to file name suffix. */
dkChar const *ns; /* New suffix. */
int back = 0;
#line 3906 "dk3bm.ctr"
dk3str_cpy_not_overlapped(fno, job->sfn);
sptr = dk3str_get_suffix(fno);
if(sptr) { *sptr = dkT('\0'); }
ns = dk3bm_output_suffixes[0];
switch((job->opt)->dr) {
case DK3_BMEPS_DRIVER_EPS: {
ns = dk3bm_output_suffixes[1];
} break;
case DK3_BMEPS_DRIVER_PDF: {
ns = dk3bm_output_suffixes[2];
} break;
case DK3_BMEPS_DRIVER_BB: {
ns = dk3bm_output_suffixes[3];
} break;
}
if((dk3str_len(ns) + dk3str_len(fno)) < DK3_SIZEOF(fno,dkChar)) {
dk3str_cat(fno, ns);
#line 3923 "dk3bm.ctr"
job->dfn = fno;
back = dk3bm_job_from_program_with_output(job);
} else {
/* ERROR: File name too long! */
dk3bmj_log_i3(
(job->opt)->app, DK3_LL_ERROR, 65, 66, job->sfn, DK3_BMJ_LOG_BOTH, job
);
}
#line 3931 "dk3bm.ctr"
return back;
}
int
dk3bm_process_file_name(
dk3_bm_eps_options_t *opt,
dkChar const *sfn,
int biftype,
int min,
int max,
void *comm
)
{
dk3_bm_eps_options_t bmeo; /* Conversion options. */
dk3_bm_conversion_job_t job; /* Conversion job. */
#if DK3_ON_WINDOWS
int oldmode; /* Original stdout file mode. */
#endif
int back = 0;
#line 3953 "dk3bm.ctr"
if((opt) && (sfn)) {
#line 3954 "dk3bm.ctr"
if(opt->app) {
#line 3955 "dk3bm.ctr"
dk3bmj_init(&job, opt->app);
dk3mem_cpy((void *)(&bmeo), (void *)opt, sizeof(dk3_bm_eps_options_t));
job.opt = &bmeo;
#line 3958 "dk3bm.ctr"
job.sfn = sfn;
job.biftype = biftype;
#if DK3_USE_WX
job.pComm = comm;
job.minpb = min;
job.maxpb = max;
#endif
if(dk3bmeo_check(&bmeo, 0, opt->app, &job)) {
#line 3966 "dk3bm.ctr"
if(opt->to_stdout) {
#line 3967 "dk3bm.ctr"
job.dfile = stdout;
switch(opt->dr) {
case DK3_BMEPS_DRIVER_PDF: {
#line 3970 "dk3bm.ctr"
#if DK3_ON_WINDOWS
oldmode = _setmode(_fileno(stdout), _O_BINARY);
#endif
back = dk3bm_job_from_program_with_output(&job);
#if DK3_ON_WINDOWS
_setmode(_fileno(stdout), oldmode);
#endif
} break;
default: {
#line 3979 "dk3bm.ctr"
back = dk3bm_job_from_program_with_output(&job);
} break;
}
} else {
#line 3983 "dk3bm.ctr"
job.dfile = NULL;
back = dk3bm_job_from_program_construct_name(&job);
}
} else {
#line 3987 "dk3bm.ctr"
/* ERROR: Inconsistent options, reported by dk3bmeo_check(). */
dk3bmj_log_1(
opt->app, DK3_LL_ERROR, job.msg, 68, DK3_BMJ_LOG_JOB, &job
);
}
} else {
#line 3993 "dk3bm.ctr"
/* ERROR: Application structure not set! */
}
}
#if DK3_USE_WX
if((comm) && (max > min)) {
#line 3999 "dk3bm.ctr"
dk3bmj_progress(comm, max);
}
#endif
#line 4003 "dk3bm.ctr"
return back;
}
|