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
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695
5696
5697
5698
5699
5700
5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722
5723
5724
5725
5726
5727
5728
5729
5730
5731
5732
5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
5772
5773
5774
5775
5776
5777
5778
5779
5780
5781
5782
5783
5784
5785
5786
5787
5788
5789
5790
5791
5792
5793
5794
5795
5796
5797
5798
5799
5800
5801
5802
5803
5804
5805
5806
5807
5808
5809
5810
5811
5812
5813
5814
5815
5816
5817
5818
5819
5820
5821
5822
5823
5824
5825
5826
5827
5828
5829
5830
5831
5832
5833
5834
5835
5836
5837
5838
5839
5840
5841
5842
5843
5844
5845
5846
5847
5848
5849
5850
5851
5852
5853
5854
5855
5856
5857
5858
5859
5860
5861
5862
5863
5864
5865
5866
5867
5868
5869
5870
5871
5872
5873
5874
5875
5876
5877
5878
5879
5880
5881
5882
5883
5884
5885
5886
5887
5888
5889
5890
5891
5892
5893
5894
5895
5896
5897
5898
5899
5900
5901
5902
5903
5904
5905
5906
5907
5908
5909
5910
5911
5912
5913
5914
5915
5916
5917
5918
5919
5920
5921
5922
5923
5924
5925
5926
5927
5928
5929
5930
5931
5932
5933
5934
5935
5936
5937
5938
5939
5940
5941
5942
5943
5944
5945
5946
5947
5948
5949
5950
5951
5952
5953
5954
5955
5956
5957
5958
5959
5960
5961
5962
5963
5964
5965
5966
5967
5968
5969
5970
5971
5972
5973
5974
5975
5976
5977
5978
5979
5980
5981
5982
5983
5984
5985
5986
5987
5988
5989
5990
5991
5992
5993
5994
5995
5996
5997
5998
5999
6000
6001
6002
6003
6004
6005
6006
6007
6008
6009
6010
6011
6012
6013
6014
6015
6016
6017
6018
6019
6020
6021
6022
6023
6024
6025
6026
6027
6028
6029
6030
6031
6032
6033
6034
6035
6036
6037
6038
6039
6040
6041
6042
6043
6044
6045
6046
6047
6048
6049
6050
6051
6052
6053
6054
6055
6056
6057
6058
6059
6060
6061
6062
6063
6064
6065
6066
6067
6068
6069
6070
6071
6072
6073
6074
6075
6076
6077
6078
6079
6080
6081
6082
6083
6084
6085
6086
6087
6088
6089
6090
6091
6092
6093
6094
6095
6096
6097
6098
6099
6100
6101
6102
6103
6104
6105
6106
6107
6108
6109
6110
6111
6112
6113
6114
6115
6116
6117
6118
6119
6120
6121
6122
6123
6124
6125
6126
6127
6128
6129
6130
6131
6132
6133
6134
6135
6136
6137
6138
6139
6140
6141
6142
6143
6144
6145
6146
6147
6148
6149
6150
6151
6152
6153
6154
6155
6156
6157
6158
6159
6160
6161
6162
6163
6164
6165
6166
6167
6168
6169
6170
6171
6172
6173
6174
6175
6176
6177
6178
6179
6180
6181
6182
6183
6184
6185
6186
6187
6188
6189
6190
6191
6192
6193
6194
6195
6196
6197
6198
6199
6200
6201
6202
6203
6204
6205
6206
6207
6208
6209
6210
6211
6212
6213
6214
6215
6216
6217
6218
6219
6220
6221
6222
6223
6224
6225
6226
6227
6228
6229
6230
6231
6232
6233
6234
6235
6236
6237
6238
6239
6240
6241
6242
6243
6244
6245
6246
6247
6248
6249
6250
6251
6252
6253
6254
6255
6256
6257
6258
6259
6260
6261
6262
6263
6264
6265
6266
6267
6268
6269
6270
6271
6272
6273
6274
6275
6276
6277
6278
6279
6280
6281
6282
6283
6284
6285
6286
6287
6288
6289
6290
6291
6292
6293
6294
6295
6296
6297
6298
6299
6300
6301
6302
6303
6304
6305
6306
6307
6308
6309
6310
6311
6312
6313
6314
6315
6316
6317
6318
6319
6320
6321
6322
6323
6324
6325
6326
6327
6328
6329
6330
6331
6332
6333
6334
6335
6336
6337
6338
6339
6340
6341
6342
6343
6344
6345
6346
6347
6348
6349
6350
6351
6352
6353
6354
6355
6356
6357
6358
6359
6360
6361
6362
6363
6364
6365
6366
6367
6368
6369
6370
6371
6372
6373
6374
6375
6376
6377
6378
6379
6380
6381
6382
6383
6384
6385
6386
6387
6388
6389
6390
6391
6392
6393
6394
6395
6396
6397
6398
6399
6400
6401
6402
6403
6404
6405
6406
6407
6408
6409
6410
6411
6412
6413
6414
6415
6416
6417
6418
6419
6420
6421
6422
6423
6424
6425
6426
6427
6428
6429
6430
6431
6432
6433
6434
6435
6436
6437
6438
6439
6440
6441
6442
6443
6444
6445
6446
6447
6448
6449
6450
6451
6452
6453
6454
6455
6456
6457
6458
6459
6460
6461
6462
6463
6464
6465
6466
6467
6468
6469
6470
6471
6472
6473
6474
6475
6476
6477
6478
6479
6480
6481
6482
6483
6484
6485
6486
6487
6488
6489
6490
6491
6492
6493
6494
6495
6496
6497
6498
6499
6500
6501
6502
6503
6504
6505
6506
6507
6508
6509
6510
6511
6512
6513
6514
6515
6516
6517
6518
6519
6520
6521
6522
6523
6524
6525
6526
6527
6528
6529
6530
6531
6532
6533
6534
6535
6536
6537
6538
6539
6540
6541
6542
6543
6544
6545
6546
6547
6548
6549
6550
6551
6552
6553
6554
6555
6556
6557
6558
6559
6560
6561
6562
6563
6564
6565
6566
6567
6568
6569
6570
6571
6572
6573
6574
6575
6576
6577
6578
6579
6580
6581
6582
6583
6584
6585
6586
6587
6588
6589
6590
6591
6592
6593
6594
6595
6596
6597
6598
6599
6600
6601
6602
6603
6604
6605
6606
6607
6608
6609
6610
6611
6612
6613
6614
6615
6616
6617
6618
6619
6620
6621
6622
6623
6624
6625
6626
6627
6628
6629
6630
6631
6632
6633
6634
6635
6636
6637
6638
6639
6640
6641
6642
6643
6644
6645
6646
6647
6648
6649
6650
6651
6652
6653
6654
6655
6656
6657
6658
6659
6660
6661
6662
6663
6664
6665
6666
6667
6668
6669
6670
6671
6672
6673
6674
6675
6676
6677
6678
6679
6680
6681
6682
6683
6684
6685
6686
6687
6688
6689
6690
6691
6692
6693
6694
6695
6696
6697
6698
6699
6700
6701
6702
6703
6704
6705
6706
6707
6708
6709
6710
6711
6712
6713
6714
6715
6716
6717
6718
6719
6720
6721
6722
6723
6724
6725
6726
6727
6728
6729
6730
6731
6732
6733
6734
6735
6736
6737
6738
6739
6740
6741
6742
6743
6744
6745
6746
6747
6748
6749
6750
6751
6752
6753
6754
6755
6756
6757
6758
6759
6760
6761
6762
6763
6764
6765
6766
6767
6768
6769
6770
6771
6772
6773
6774
6775
6776
6777
6778
6779
6780
6781
6782
6783
6784
6785
6786
6787
6788
6789
6790
6791
6792
6793
6794
6795
6796
6797
6798
6799
6800
6801
6802
6803
6804
6805
6806
6807
6808
6809
6810
6811
6812
6813
6814
6815
6816
6817
6818
6819
6820
6821
6822
6823
6824
6825
6826
6827
6828
6829
6830
6831
6832
6833
6834
6835
6836
6837
6838
6839
6840
6841
6842
6843
6844
6845
6846
6847
6848
6849
6850
6851
6852
6853
6854
6855
6856
6857
6858
6859
6860
6861
6862
6863
6864
6865
6866
6867
6868
6869
6870
6871
6872
6873
6874
6875
6876
6877
6878
6879
6880
6881
6882
6883
6884
6885
6886
6887
6888
6889
6890
6891
6892
6893
6894
6895
6896
6897
6898
6899
6900
6901
6902
6903
6904
6905
6906
6907
6908
6909
6910
6911
6912
6913
6914
6915
6916
6917
6918
6919
6920
6921
6922
6923
6924
6925
6926
6927
6928
6929
6930
6931
6932
6933
6934
6935
6936
6937
6938
6939
6940
6941
6942
6943
6944
6945
6946
6947
6948
6949
6950
6951
6952
6953
6954
6955
6956
6957
6958
6959
6960
6961
6962
6963
6964
6965
6966
6967
6968
6969
6970
6971
6972
6973
6974
6975
6976
6977
6978
6979
6980
6981
6982
6983
6984
6985
6986
6987
6988
6989
6990
6991
6992
6993
6994
6995
6996
6997
6998
6999
7000
7001
7002
7003
7004
7005
7006
7007
7008
7009
7010
7011
7012
7013
7014
7015
7016
7017
7018
7019
7020
7021
7022
7023
7024
7025
7026
7027
7028
7029
7030
7031
7032
7033
7034
7035
7036
7037
7038
7039
7040
7041
7042
7043
7044
7045
7046
7047
7048
7049
7050
7051
7052
7053
7054
7055
7056
7057
7058
7059
7060
7061
7062
7063
7064
7065
7066
7067
7068
7069
7070
7071
7072
7073
7074
7075
7076
7077
7078
7079
7080
7081
7082
7083
7084
7085
7086
7087
7088
7089
7090
7091
7092
7093
7094
7095
7096
7097
7098
7099
7100
7101
7102
7103
7104
7105
7106
7107
7108
7109
7110
7111
7112
7113
7114
7115
7116
7117
7118
7119
7120
7121
7122
7123
7124
7125
7126
7127
7128
7129
7130
7131
7132
7133
7134
7135
7136
7137
7138
7139
7140
7141
7142
7143
7144
7145
7146
7147
7148
7149
7150
7151
7152
7153
7154
7155
7156
7157
7158
7159
7160
7161
7162
7163
7164
7165
7166
7167
7168
7169
7170
7171
7172
7173
7174
7175
7176
7177
7178
7179
7180
7181
7182
7183
7184
7185
7186
7187
7188
7189
7190
7191
7192
7193
7194
7195
7196
7197
7198
7199
7200
7201
7202
7203
7204
7205
7206
7207
7208
7209
7210
7211
7212
7213
7214
7215
7216
7217
7218
7219
7220
7221
7222
7223
7224
7225
7226
7227
7228
7229
7230
7231
7232
7233
7234
7235
7236
7237
7238
7239
7240
7241
7242
7243
7244
7245
7246
7247
7248
7249
7250
7251
7252
7253
7254
7255
7256
7257
7258
7259
7260
7261
7262
7263
7264
7265
7266
7267
7268
7269
7270
7271
7272
7273
7274
7275
7276
7277
7278
7279
7280
7281
7282
7283
7284
7285
7286
7287
7288
7289
7290
7291
7292
7293
7294
7295
7296
7297
7298
7299
7300
7301
7302
7303
7304
7305
7306
7307
7308
7309
7310
7311
7312
7313
7314
7315
7316
7317
7318
7319
7320
7321
7322
7323
7324
7325
7326
7327
7328
7329
7330
7331
7332
7333
7334
7335
7336
7337
7338
7339
7340
7341
7342
7343
7344
7345
7346
7347
7348
7349
7350
7351
7352
7353
7354
7355
7356
7357
7358
7359
7360
7361
7362
7363
7364
7365
7366
7367
7368
7369
7370
7371
7372
7373
7374
7375
7376
7377
7378
7379
7380
7381
7382
7383
7384
7385
7386
7387
7388
7389
7390
7391
7392
7393
7394
7395
7396
7397
7398
7399
7400
7401
7402
7403
7404
7405
7406
7407
7408
7409
7410
7411
7412
7413
7414
7415
7416
7417
7418
7419
7420
7421
7422
7423
7424
7425
7426
7427
7428
7429
7430
7431
7432
7433
7434
7435
7436
7437
7438
7439
7440
7441
7442
7443
7444
7445
7446
7447
7448
7449
7450
7451
7452
7453
7454
7455
7456
7457
7458
7459
7460
7461
7462
7463
7464
7465
7466
7467
7468
7469
7470
7471
7472
7473
7474
7475
7476
7477
7478
7479
7480
7481
7482
7483
7484
7485
7486
7487
7488
7489
7490
7491
7492
7493
7494
7495
7496
7497
7498
7499
7500
7501
7502
7503
7504
7505
7506
7507
7508
7509
7510
7511
7512
7513
7514
7515
7516
7517
7518
7519
7520
7521
7522
7523
7524
7525
7526
7527
7528
7529
7530
7531
7532
7533
7534
7535
7536
7537
7538
7539
7540
7541
7542
7543
7544
7545
7546
7547
7548
7549
7550
7551
7552
7553
7554
7555
7556
7557
7558
7559
7560
7561
7562
7563
7564
7565
7566
7567
7568
7569
7570
7571
7572
7573
7574
7575
7576
7577
7578
7579
7580
7581
7582
7583
7584
7585
7586
7587
7588
7589
7590
7591
7592
7593
7594
7595
7596
7597
7598
7599
7600
7601
7602
7603
7604
7605
7606
7607
7608
7609
7610
7611
7612
7613
7614
7615
7616
7617
7618
7619
7620
7621
7622
7623
7624
7625
7626
7627
7628
7629
7630
7631
7632
7633
7634
7635
7636
7637
7638
7639
7640
7641
7642
7643
7644
7645
7646
7647
7648
7649
7650
7651
7652
7653
7654
7655
7656
7657
7658
7659
7660
7661
7662
7663
7664
7665
7666
7667
7668
7669
7670
7671
7672
7673
7674
7675
7676
7677
7678
7679
7680
7681
7682
7683
7684
7685
7686
7687
7688
7689
7690
7691
7692
7693
7694
7695
7696
7697
7698
7699
7700
7701
7702
7703
7704
7705
7706
7707
7708
7709
7710
7711
7712
7713
7714
7715
7716
7717
7718
7719
7720
7721
7722
7723
7724
7725
7726
7727
7728
7729
7730
7731
7732
7733
7734
7735
7736
7737
7738
7739
7740
7741
7742
7743
7744
7745
7746
7747
7748
7749
7750
7751
7752
7753
7754
7755
7756
7757
7758
7759
7760
7761
7762
7763
7764
7765
7766
7767
7768
7769
7770
7771
7772
7773
7774
7775
7776
7777
7778
7779
7780
7781
7782
7783
7784
7785
7786
7787
7788
7789
7790
7791
7792
7793
7794
7795
7796
7797
7798
7799
7800
7801
7802
7803
7804
7805
7806
7807
7808
7809
7810
7811
7812
7813
7814
7815
7816
7817
7818
7819
7820
7821
7822
7823
7824
7825
7826
7827
7828
7829
7830
7831
7832
7833
7834
7835
7836
7837
7838
7839
7840
7841
7842
7843
7844
7845
7846
7847
7848
7849
7850
7851
7852
7853
7854
7855
7856
7857
7858
7859
7860
7861
7862
7863
7864
7865
7866
7867
7868
7869
7870
7871
7872
7873
7874
7875
7876
7877
7878
7879
7880
7881
7882
7883
7884
7885
7886
7887
7888
7889
7890
7891
7892
7893
7894
7895
7896
7897
7898
7899
7900
7901
7902
7903
7904
7905
7906
7907
7908
7909
7910
7911
7912
7913
7914
7915
7916
7917
7918
7919
7920
7921
7922
7923
7924
7925
7926
7927
7928
7929
7930
7931
7932
7933
7934
7935
7936
7937
7938
7939
7940
7941
7942
7943
7944
7945
7946
7947
7948
7949
7950
7951
7952
7953
7954
7955
7956
7957
7958
7959
7960
7961
7962
7963
7964
7965
7966
7967
7968
7969
7970
7971
7972
7973
7974
7975
7976
7977
7978
7979
7980
7981
7982
7983
7984
7985
7986
7987
7988
7989
7990
7991
7992
7993
7994
7995
7996
7997
7998
7999
8000
8001
8002
8003
8004
8005
8006
8007
8008
8009
8010
8011
8012
8013
8014
8015
8016
8017
8018
8019
8020
8021
8022
8023
8024
8025
8026
8027
8028
8029
8030
8031
8032
8033
8034
8035
8036
8037
8038
8039
8040
8041
8042
8043
8044
8045
8046
8047
8048
8049
8050
8051
8052
8053
8054
8055
8056
8057
8058
8059
8060
8061
8062
8063
8064
8065
8066
8067
8068
8069
8070
8071
8072
8073
8074
8075
8076
8077
8078
8079
8080
8081
8082
8083
8084
8085
8086
8087
8088
8089
8090
8091
8092
8093
8094
8095
8096
8097
8098
8099
8100
8101
8102
8103
8104
8105
8106
8107
8108
8109
8110
8111
8112
8113
8114
8115
8116
8117
8118
8119
8120
8121
8122
8123
8124
8125
8126
8127
8128
8129
8130
8131
8132
8133
8134
8135
8136
8137
8138
8139
8140
8141
8142
8143
8144
8145
8146
8147
8148
8149
8150
8151
8152
8153
8154
8155
8156
8157
8158
8159
8160
8161
8162
8163
8164
8165
8166
8167
8168
8169
8170
8171
8172
8173
8174
8175
8176
8177
8178
8179
8180
8181
8182
8183
8184
8185
8186
8187
8188
8189
8190
8191
8192
8193
8194
8195
8196
8197
8198
8199
8200
8201
8202
8203
8204
8205
8206
8207
8208
8209
8210
8211
8212
8213
8214
8215
8216
8217
8218
8219
8220
8221
8222
8223
8224
8225
8226
8227
8228
8229
8230
8231
8232
8233
8234
8235
8236
8237
8238
8239
8240
8241
8242
8243
8244
8245
8246
8247
8248
8249
8250
8251
8252
8253
8254
8255
8256
8257
8258
8259
8260
8261
8262
8263
8264
8265
8266
8267
8268
8269
8270
8271
8272
8273
8274
8275
8276
8277
8278
8279
8280
8281
8282
8283
8284
8285
8286
8287
8288
8289
8290
8291
8292
8293
8294
8295
8296
8297
8298
8299
8300
8301
8302
8303
8304
8305
8306
8307
8308
8309
8310
8311
8312
8313
8314
8315
8316
8317
8318
8319
8320
8321
8322
8323
8324
8325
8326
8327
8328
8329
8330
8331
8332
8333
8334
8335
8336
8337
8338
8339
8340
8341
8342
8343
8344
8345
8346
8347
8348
8349
8350
8351
8352
8353
8354
8355
8356
8357
8358
8359
8360
8361
8362
8363
8364
8365
8366
8367
8368
8369
8370
8371
8372
8373
8374
8375
8376
8377
8378
8379
8380
8381
8382
8383
8384
8385
8386
8387
8388
8389
8390
8391
8392
8393
8394
8395
8396
8397
8398
8399
8400
8401
8402
8403
8404
8405
8406
8407
8408
8409
8410
8411
8412
8413
8414
8415
8416
8417
8418
8419
8420
8421
8422
8423
8424
8425
8426
8427
8428
8429
8430
8431
8432
8433
8434
8435
8436
8437
8438
8439
8440
8441
8442
8443
8444
8445
8446
8447
8448
8449
8450
8451
8452
8453
8454
8455
8456
8457
8458
8459
8460
8461
8462
8463
8464
8465
8466
8467
8468
8469
8470
8471
8472
8473
8474
8475
8476
8477
8478
8479
8480
8481
8482
8483
8484
8485
8486
8487
8488
8489
8490
8491
8492
8493
8494
8495
8496
8497
8498
8499
8500
8501
8502
8503
8504
8505
8506
8507
8508
8509
8510
8511
8512
8513
8514
8515
8516
8517
8518
8519
8520
8521
8522
8523
8524
8525
8526
8527
8528
8529
8530
8531
8532
8533
8534
8535
8536
8537
8538
8539
8540
8541
8542
8543
8544
8545
8546
8547
8548
8549
8550
8551
8552
8553
8554
8555
8556
8557
8558
8559
8560
8561
8562
8563
8564
8565
8566
8567
8568
8569
8570
8571
8572
8573
8574
8575
8576
8577
8578
8579
8580
8581
8582
8583
8584
8585
8586
8587
8588
8589
8590
8591
8592
8593
8594
8595
8596
8597
8598
8599
8600
8601
8602
8603
8604
8605
8606
8607
8608
8609
8610
8611
8612
8613
8614
8615
8616
8617
8618
8619
8620
8621
8622
8623
8624
8625
8626
8627
8628
8629
8630
8631
8632
8633
8634
8635
8636
8637
8638
8639
8640
8641
8642
8643
8644
8645
8646
8647
8648
8649
8650
8651
8652
8653
8654
8655
8656
8657
8658
8659
8660
8661
8662
8663
8664
8665
8666
8667
8668
8669
8670
8671
8672
8673
8674
8675
8676
8677
8678
8679
8680
8681
8682
8683
8684
8685
8686
8687
8688
8689
8690
8691
8692
8693
8694
8695
8696
8697
8698
8699
8700
8701
8702
8703
8704
8705
8706
8707
8708
8709
8710
8711
8712
8713
8714
8715
8716
8717
8718
8719
8720
8721
8722
8723
8724
8725
8726
8727
8728
8729
8730
8731
8732
8733
8734
8735
8736
8737
8738
8739
8740
8741
8742
8743
8744
8745
8746
8747
8748
8749
8750
8751
8752
8753
8754
8755
8756
8757
8758
8759
8760
8761
8762
8763
8764
8765
8766
8767
8768
8769
8770
8771
8772
8773
8774
8775
8776
8777
8778
8779
8780
8781
8782
8783
8784
8785
8786
8787
8788
8789
8790
8791
8792
8793
8794
8795
8796
8797
8798
8799
8800
8801
8802
8803
8804
8805
8806
8807
8808
8809
8810
8811
8812
8813
8814
8815
8816
8817
8818
8819
8820
8821
8822
8823
8824
8825
8826
8827
8828
8829
8830
8831
8832
8833
8834
8835
8836
8837
8838
8839
8840
8841
8842
8843
8844
8845
8846
8847
8848
8849
8850
8851
8852
8853
8854
8855
8856
8857
8858
8859
8860
8861
8862
8863
8864
8865
8866
8867
8868
8869
8870
8871
8872
8873
8874
8875
8876
8877
8878
8879
8880
8881
8882
8883
8884
8885
8886
8887
8888
8889
8890
8891
8892
8893
8894
8895
8896
8897
8898
8899
8900
8901
8902
8903
8904
8905
8906
8907
8908
8909
8910
8911
8912
8913
8914
8915
8916
8917
8918
8919
8920
8921
8922
8923
8924
8925
8926
8927
8928
8929
8930
8931
8932
8933
8934
8935
8936
8937
8938
8939
8940
8941
8942
8943
8944
8945
8946
8947
8948
8949
8950
8951
8952
8953
8954
8955
8956
8957
8958
8959
8960
8961
8962
8963
8964
8965
8966
8967
8968
8969
8970
8971
8972
8973
8974
8975
8976
8977
8978
8979
8980
8981
8982
8983
8984
8985
8986
8987
8988
8989
8990
8991
8992
8993
8994
8995
8996
8997
8998
8999
9000
9001
9002
9003
9004
9005
9006
9007
9008
9009
9010
9011
9012
9013
9014
9015
9016
9017
9018
9019
9020
9021
9022
9023
9024
9025
9026
9027
9028
9029
9030
9031
9032
9033
9034
9035
9036
9037
9038
9039
9040
9041
9042
9043
9044
9045
9046
9047
9048
9049
9050
9051
9052
9053
9054
9055
9056
9057
9058
9059
9060
9061
9062
9063
9064
9065
9066
9067
9068
9069
9070
9071
9072
9073
9074
9075
9076
9077
9078
9079
9080
9081
9082
9083
9084
9085
9086
9087
9088
9089
9090
9091
9092
9093
9094
9095
9096
9097
9098
9099
9100
9101
9102
9103
9104
9105
9106
9107
9108
9109
9110
9111
9112
9113
9114
9115
9116
9117
9118
9119
9120
9121
9122
9123
9124
9125
9126
9127
9128
9129
9130
9131
9132
9133
9134
9135
9136
9137
9138
9139
9140
9141
9142
9143
9144
9145
9146
9147
9148
9149
9150
9151
9152
9153
9154
9155
9156
9157
9158
9159
9160
9161
9162
9163
9164
9165
9166
9167
9168
9169
9170
9171
9172
9173
9174
9175
9176
9177
9178
9179
9180
9181
9182
9183
9184
9185
9186
9187
9188
9189
9190
9191
9192
9193
9194
9195
9196
9197
9198
9199
9200
9201
9202
9203
9204
9205
9206
9207
9208
9209
9210
9211
9212
9213
9214
9215
9216
9217
9218
9219
9220
9221
9222
9223
9224
9225
9226
9227
9228
9229
9230
9231
9232
9233
9234
9235
9236
9237
9238
9239
9240
9241
9242
9243
9244
9245
9246
9247
9248
9249
9250
9251
9252
9253
9254
9255
9256
9257
9258
9259
9260
9261
9262
9263
9264
9265
9266
9267
9268
9269
9270
9271
9272
9273
9274
9275
9276
9277
9278
9279
9280
9281
9282
9283
9284
9285
9286
9287
9288
9289
9290
9291
9292
9293
9294
9295
9296
9297
9298
9299
9300
9301
9302
9303
9304
9305
9306
9307
9308
9309
9310
9311
9312
9313
9314
9315
9316
9317
9318
9319
9320
9321
9322
9323
9324
9325
9326
9327
9328
9329
9330
9331
9332
9333
9334
9335
9336
9337
9338
9339
9340
9341
9342
9343
9344
9345
9346
9347
9348
9349
9350
9351
9352
9353
9354
9355
9356
9357
9358
9359
9360
9361
9362
9363
9364
9365
9366
9367
9368
9369
9370
9371
9372
9373
9374
9375
9376
9377
9378
9379
9380
9381
9382
9383
9384
9385
9386
9387
9388
9389
9390
9391
9392
9393
9394
9395
9396
9397
9398
9399
9400
9401
9402
9403
9404
9405
9406
9407
9408
9409
9410
9411
9412
9413
9414
9415
9416
9417
9418
9419
9420
9421
9422
9423
9424
9425
9426
9427
9428
9429
9430
9431
9432
9433
9434
9435
9436
9437
9438
9439
9440
9441
9442
9443
9444
9445
9446
9447
9448
9449
9450
9451
9452
9453
9454
9455
9456
9457
9458
9459
9460
9461
9462
9463
9464
9465
9466
9467
9468
9469
9470
9471
9472
9473
9474
9475
9476
9477
9478
9479
9480
9481
9482
9483
9484
9485
9486
9487
9488
9489
9490
9491
9492
9493
9494
9495
9496
9497
9498
9499
9500
9501
9502
9503
9504
9505
9506
9507
9508
9509
9510
9511
9512
9513
9514
9515
9516
9517
9518
9519
9520
9521
9522
9523
9524
9525
9526
9527
9528
9529
9530
9531
9532
9533
9534
9535
9536
9537
9538
9539
9540
9541
9542
9543
9544
9545
9546
9547
9548
9549
9550
9551
9552
9553
9554
9555
9556
9557
9558
9559
9560
9561
9562
9563
9564
9565
9566
9567
9568
9569
9570
9571
9572
9573
9574
9575
9576
9577
9578
9579
9580
9581
9582
9583
9584
9585
9586
9587
9588
9589
9590
9591
9592
9593
9594
9595
9596
9597
9598
9599
9600
9601
9602
9603
9604
9605
9606
9607
9608
9609
9610
9611
9612
9613
9614
9615
9616
9617
9618
9619
9620
9621
9622
9623
9624
9625
9626
9627
9628
9629
9630
9631
9632
9633
9634
9635
9636
9637
9638
9639
9640
9641
9642
9643
9644
9645
9646
9647
9648
9649
9650
9651
9652
9653
9654
9655
9656
9657
9658
9659
9660
9661
9662
9663
9664
9665
9666
9667
9668
9669
9670
9671
9672
9673
9674
9675
9676
9677
9678
9679
9680
9681
9682
9683
9684
9685
9686
9687
9688
9689
9690
9691
9692
9693
9694
9695
9696
9697
9698
9699
9700
9701
9702
9703
9704
9705
9706
9707
9708
9709
9710
9711
9712
9713
9714
9715
9716
9717
9718
9719
9720
9721
9722
9723
9724
9725
9726
9727
9728
9729
9730
9731
9732
9733
9734
9735
9736
9737
9738
9739
9740
9741
9742
9743
9744
9745
9746
9747
9748
9749
9750
9751
9752
9753
9754
9755
9756
9757
9758
9759
9760
9761
9762
9763
9764
9765
9766
9767
9768
9769
9770
9771
9772
9773
9774
9775
9776
9777
9778
9779
9780
9781
9782
9783
9784
9785
9786
9787
9788
9789
9790
9791
9792
9793
9794
9795
9796
9797
9798
9799
9800
9801
9802
9803
9804
9805
9806
9807
9808
9809
9810
9811
9812
9813
9814
9815
9816
9817
9818
9819
9820
9821
9822
9823
9824
9825
9826
9827
9828
9829
9830
9831
9832
9833
9834
9835
9836
9837
9838
9839
9840
9841
9842
9843
9844
9845
9846
9847
9848
9849
9850
9851
9852
9853
9854
9855
9856
9857
9858
9859
9860
9861
9862
9863
9864
9865
9866
9867
9868
9869
9870
9871
9872
9873
9874
9875
9876
9877
9878
9879
9880
9881
9882
9883
9884
9885
9886
9887
9888
9889
9890
9891
9892
9893
9894
9895
9896
9897
9898
9899
9900
9901
9902
9903
9904
9905
9906
9907
9908
9909
9910
9911
9912
9913
9914
9915
9916
9917
9918
9919
9920
9921
9922
9923
9924
9925
9926
9927
9928
9929
9930
9931
9932
9933
9934
9935
9936
9937
9938
9939
9940
9941
9942
9943
9944
9945
9946
9947
9948
9949
9950
9951
9952
9953
9954
9955
9956
9957
9958
9959
9960
9961
9962
9963
9964
9965
9966
9967
9968
9969
9970
9971
9972
9973
9974
9975
9976
9977
9978
9979
9980
9981
9982
9983
9984
9985
9986
9987
9988
9989
9990
9991
9992
9993
9994
9995
9996
9997
9998
9999
10000
10001
10002
10003
10004
10005
10006
10007
10008
10009
10010
10011
10012
10013
10014
10015
10016
10017
10018
10019
10020
10021
10022
10023
10024
10025
10026
10027
10028
10029
10030
10031
10032
10033
10034
10035
10036
10037
10038
10039
10040
10041
10042
10043
10044
10045
10046
10047
10048
10049
10050
10051
10052
10053
10054
10055
10056
10057
10058
10059
10060
10061
10062
10063
10064
10065
10066
10067
10068
10069
10070
10071
10072
10073
10074
10075
10076
10077
10078
10079
10080
10081
10082
10083
10084
10085
10086
10087
10088
10089
10090
10091
10092
10093
10094
10095
10096
10097
10098
10099
10100
10101
10102
10103
10104
10105
10106
10107
10108
10109
10110
10111
10112
10113
10114
10115
10116
10117
10118
10119
10120
10121
10122
10123
10124
10125
10126
10127
10128
10129
10130
10131
10132
10133
10134
10135
10136
10137
10138
10139
10140
10141
10142
10143
10144
10145
10146
10147
10148
10149
10150
10151
10152
10153
10154
10155
10156
10157
10158
10159
10160
10161
10162
10163
10164
10165
10166
10167
10168
10169
10170
10171
10172
10173
10174
10175
10176
10177
10178
10179
10180
10181
10182
10183
10184
10185
10186
10187
10188
10189
10190
10191
10192
10193
10194
10195
10196
10197
10198
10199
10200
10201
10202
10203
10204
10205
10206
10207
10208
10209
10210
10211
10212
10213
10214
10215
10216
10217
10218
10219
10220
10221
10222
10223
10224
10225
10226
10227
|
/* sane - Scanner Access Now Easy.
This file is part of the SANE package, and implements a SANE backend
for various Fujitsu scanners.
Copyright (C) 2000 Randolph Bentson
Copyright (C) 2001 Frederik Ramm
Copyright (C) 2001-2004 Oliver Schirrmeister
Copyright (C) 2003-2016 m. allan noah
JPEG output and low memory usage support funded by:
Archivista GmbH, www.archivista.ch
Endorser support funded by:
O A S Oilfield Accounting Service Ltd, www.oas.ca
Automatic length detection support funded by:
Martin G. Miller, mgmiller at optonline.net
Software image enhancement routines and recent scanner support funded by:
Fujitsu Computer Products of America, Inc. www.fcpa.com
--------------------------------------------------------------------------
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA.
As a special exception, the authors of SANE give permission for
additional uses of the libraries contained in this release of SANE.
The exception is that, if you link a SANE library with other files
to produce an executable, this does not by itself cause the
resulting executable to be covered by the GNU General Public
License. Your use of that executable is in no way restricted on
account of linking the SANE library code into it.
This exception does not, however, invalidate any other reasons why
the executable file might be covered by the GNU General Public
License.
If you submit changes to SANE to the maintainers to be included in
a subsequent release, you agree by submitting the changes that
those changes may be distributed with this exception intact.
If you write modifications of your own for SANE, it is your choice
whether to permit this exception to apply to your modifications.
If you do not wish that, delete this exception notice.
--------------------------------------------------------------------------
The source code is divided in sections which you can easily find by
searching for the tag "@@".
Section 1 - Boilerplate: Init & static stuff
Section 2 - Init: sane_init, _get_devices, _open ...
Section 3 - Options: sane_*_option functions
Section 4 - Scanning: sane_start, _get_param, _read ...
Section 5 - Cleanup: sane_cancel, ...
Section 6 - Misc: sense_handler, hexdump, ...
Section 7 - Image processing: deskew, crop, despeck
Changes:
v1, 2002-05-05, OS
- release memory allocated by sane_get_devices
- several bugfixes
- supports the M3097
- get threshold, contrast and brightness from vpd
- imprinter support
- get_hardware_status now works before calling sane_start
- avoid unnecessary reload of options when using source=fb
v2, 2002-08-08, OS
- bugfix. Imprinter didn't print the first time after
switching on the scanner
- bugfix. reader_generic_passthrough ignored the number of bytes
returned by the scanner
v3, 2002-09-13, OS
- 3092 support (mgoppold a t tbz-pariv.de)
- tested 4097 support
- changed some functions to receive compressed data
v4, 2003-02-13, OS
- fi-4220C support (ron a t roncemer.com)
- SCSI over USB support (ron a t roncemer.com)
v5, 2003-02-20, OS
- set availability of options THRESHOLD und VARIANCE
- option RIF is available for 3091 and 3092
v6, 2003-03-04, OS
- renamed some variables
- bugfix: duplex scanning now works when disconnect is enabled
v7, 2003-03-10, OS
- displays the offending byte in the window descriptor block
v8, 2003-03-28, OS
- fi-4120C support, MAN
- display information about gamma in vital_product_data
v9 2003-06-04, MAN
- separated the 4120 and 4220 into another model
- color support for the 4x20
v10 2003-06-04, MAN
- removed SP15 code
- sane_open actually opens the device you request
v11 2003-06-11, MAN
- fixed bug in that code when a scanner is disconnected
v12 2003-10-06, MAN
- added code to support color modes of more recent scanners
v13 2003-11-07, OS
- Bugfix. If a scanner returned a color image
in format rr...r gg...g bb...b the reader process crashed
- Bugfix. Disable option gamma was for the fi-4120
v14 2003-12-15, OS
- Bugfix: set default threshold range to 0..255 There is a problem
with the M3093 when you are not allows to set the threshold to 0
- Bugfix: set the allowable x- and y-DPI values from VPD. Scanning
with x=100 and y=100 dpi with an fi4120 resulted in an image
with 100,75 dpi
- Bugfix: Set the default value of gamma to 0x80 for all scanners
that don't have built in gamma patterns
- Bugfix: fi-4530 and fi-4210 don't support standard paper size
v15 2003-12-16, OS
- Bugfix: pagewidth and pageheight were disabled for the fi-4530C
v16 2004-02-20, OS
- merged the 3092-routines with the 3091-routines
- inverted the image in mode color and grayscale
- jpg hardware compression support (fi-4530C)
v17 2004-03-04, OS
- enabled option dropoutcolor for the fi-4530C, and fi-4x20C
v18 2004-06-02, OS
- bugfix: can read duplex color now
v19 2004-06-28, MAN
- 4220 use model code not strcmp (stan a t saticed.me.uk)
v20 2004-08-24, OS
- bugfix: 3091 did not work since 15.12.2003
- M4099 supported (bw only)
v21 2006-05-01, MAN
- Complete rewrite, half code size
- better (read: correct) usb command support
- basic support for most fi-series
- most scanner capabilities read from VPD
- reduced model-specific code
- improved scanner detection/initialization
- improved SANE_Option handling
- basic button support
- all IPC and Imprinter options removed temporarily
- duplex broken temporarily
v22 2006-05-04, MAN
- do_scsi_cmd gets basic looping capability
- reverse now divided by mode
- re-write sane_fix/unfix value handling
- fix several bugs in options code
- some options' ranges modified by other options vals
- added advanced read-only options for all
known hardware sensors and buttons
- rewrote hw status function
- initial testing with M3091dc- color mode broken
v23 2006-05-14, MAN
- initial attempt to recover duplex mode
- fix bad usb prodID when config file missing
v24 2006-05-17, MAN
- sane_read must set len=0 when return != good
- simplify do_cmd() calls by removing timeouts
- lengthen most timeouts, shorten those for wait_scanner()
v25 2006-05-19, MAN
- rename scsi-buffer-size to buffer-size, usb uses it too
- default buffer-size increased to 64k
- use sanei_scsi_open_extended() to set buffer size
- fix some compiler warns: 32&64 bit gcc
v26 2006-05-23, MAN
- dont send scanner control (F1) if unsupported
v27 2006-05-30, MAN
- speed up hexdump (adeuring A T gmx D O T net)
- duplex request same size block from both sides
- dont #include or call sanei_thread
- split usb/scsi command DBG into 25 and 30
v28 2006-06-01, MAN
- sane_read() usleep if scanner is busy
- do_*_cmd() no looping (only one caller used it),
remove unneeded casts, cleanup/add error messages
- scanner_control() look at correct has_cmd_* var,
handles own looping on busy
v29 2006-06-04, MAN
- M3091/2 Color mode support (duplex still broken)
- all sensors option names start with 'button-'
- rewrite sane_read and helpers to use buffers,
currently an extreme waste of ram, but should
work with saned and scanimage -T
- merge color conversion funcs into read_from_buf()
- compare bytes tx v/s rx instead of storing EOFs
- remove scanner cmd buf, use buf per func instead
- print color and duplex raster offsets (inquiry)
- print EOM, ILI, and info bytes (request sense)
v30 2006-06-06, MAN
- M3091/2 duplex support, color/gray/ht/lineart ok
- sane_read helpers share code, report more errors
- add error msg if VPD missing or non-extended
- remove references to color_lineart and ht units
- rework init_model to support more known models
- dont send paper size data if using flatbed
v31 2006-06-13, MAN
- add 5220C usb id
- dont show ink level buttons if no imprinter
- run ghs/rs every second instead of every other
v32 2006-06-14, MAN
- add 4220C2 usb id
v33 2006-06-14, MAN (SANE v1.0.18)
- add Fi-5900 usb id and init_model section
v34 2006-07-04, MAN
- add S500 usb id
- gather more data from inq and vpd
- allow background color setting
v35 2006-07-05, MAN
- allow double feed sensor settings
- more consistent naming of global strings
v36 2006-07-06, MAN
- deal with fi-5900 even bytes problem
- less verbose calculateDerivedValues()
v37 2006-07-14, MAN
- mode sense command support
- detect mode page codes instead of hardcoding
- send command support
- brightness/contrast support via LUT
- merge global mode page buffers
v38 2006-07-15, MAN
- add 'useless noise' debug level (35)
- move mode sense probe errors to DBG 35
v39 2006-07-17, MAN
- rewrite contrast slope math for readability
v40 2006-08-26, MAN
- rewrite brightness/contrast more like xsane
- initial gamma support
- add fi-5530 usb id
- rewrite do_*_cmd functions to handle short reads
and to use ptr to return read in length
- new init_user function split from init_model
- init_vpd allows short vpd block for older models
- support MS buffer (s.scipioni AT harvardgroup DOT it)
- support MS prepick
- read only 1 byte of mode sense output
v41 2006-08-28, MAN
- do_usb_cmd() returns io error on cmd/out/status/rs EOF
- fix bug in MS buffer/prepick scsi data block
v42 2006-08-31, MAN
- fix bug in get_hardware_status (#303798)
v43 2006-09-19, MAN
- add model-specific code to init_vpd for M3099
v44 2007-01-26, MAN
- set SANE_CAP_HARD_SELECT on all buttons/sensors
- disable sending gamma LUT, seems wrong on some units?
- support MS overscan
- clamp the scan area to the pagesize on ADF
v45 2007-01-28, MAN
- update overscan code to extend max scan area
v46 2007-03-08, MAN
- tweak fi-4x20c2 and M3093 settings
- add fi-5110EOXM usb id
- add M3093 non-alternating duplex code
v47 2007-04-13, MAN
- change window_gamma determination
- add fi-5650C usb id and color mode
v48 2007-04-16, MAN
- re-enable brightness/contrast for built-in models
v49 2007-06-28, MAN
- add fi-5750C usb id and color mode
v50 2007-07-10, MAN
- updated overscan and bgcolor option descriptions
- added jpeg output support
- restructured usb reading code to use RS len for short reads
- combined calcDerivedValues with sane_get_params
v51 2007-07-26, MAN
- fix bug in jpeg output support
v52 2007-07-27, MAN
- remove unused jpeg function
- reactivate look-up-table based brightness and contrast options
- change range of hardware brightness/contrast to match LUT versions
- call send_lut() from sane_control_option instead of sane_start
v53 2007-11-18, MAN
- add S510 usb id
- OPT_NUM_OPTS type is SANE_TYPE_INT (jblache)
v54 2007-12-29, MAN
- disable SANE_FRAME_JPEG support until SANE 1.1.0
v55 2007-12-29, MAN (SANE v1.0.19)
- add S500M usb id
v56 2008-02-14, MAN
- sanei_config_read has already cleaned string (#310597)
v57 2008-02-24, MAN
- fi-5900 does not (initially) interlace colors
- add mode sense for color interlacing? (page code 32)
- more debug output in init_ms()
v58 2008-04-19, MAN
- page code 32 is not color interlacing, rename to 'unknown'
- increase number of bytes in response buffer of init_ms()
- protect debug modification code in init_ms() if NDEBUG is set
- proper async sane_cancel support
- re-enable JPEG support
- replace s->img_count with s->side
- sane_get_parameters(): dont round up larger than current paper size
- sane_start() rewritten, shorter, more clear
- return values are SANE_Status, not int
- hide unused functions
v59 2008-04-22, MAN
- add fi-6140 usb ID, and fi-6x40 color mode
v60 2008-04-27, MAN
- move call to sanei_usb_init() from sane_init() to find_scanners
- free sane_devArray before calloc'ing a new one
v61 2008-05-11, MAN
- minor cleanups to init_ms()
- add fi-5530C2 usb id
- merge find_scanners into sane_get_devices
- inspect correct bool to enable prepick mode option
v62 2008-05-20, MAN
- check for all supported scsi commands
- use well-known option group strings from saneopts.h
- rename pagewidth to page-width, to meet sane 1.1.0, same for height
- add unused get_window()
v63 2008-05-21, MAN
- use sane 1.1.0 well-known option names for some buttons
- remove 'button-' from other buttons and sensors
v64 2008-05-28, MAN
- strcpy device_name[] instead of strdup/free *device_name
- add send/read diag commands to get scanner serial number
- use model and serial to build sane.name (idea from Ryan Duryea)
- allow both serial_name and device_name to sane_open scanner
- correct mode select/sense 6 vs 10 booleans
- rename product_name to model_name
- simulate missing VPD data for M3097G
- hide get_window
- improve handling of vendor unique section of set_window
- add init_interlace to detect proper color mode without hardcoding
- add ascii output to hexdump
v65 2008-06-24, MAN
- detect endorser type during init_inquiry()
- add endorser options
- add send_endorser() and call from sane_control_option()
- add endorser() and call from sane_start()
- convert set_window() to use local cmd and payload copies
- remove get_window()
- mode_select_buff() now clears the buffer, and called in sane_close()
- fi-4990 quirks added, including modified even_scan_line code
v66 2008-06-26, MAN
- restructure double feed detection options for finer-grained control
- add endorser side option
- prevent init_interlace() from overriding init_model()
- simplify sane_start() and fix interlaced duplex jpeg support
- simplify sane_read() and add non-interlaced duplex jpeg support
- removed unused code
v67 2008-07-01, MAN
- add IPC/DTC/SDTC options
- call check_for_cancel() in sane_cancel, unless s->reader flag is set
v68 2008-07-02, MAN
- add halftone type and pattern options
- support M3097G with IPC and CMP options via modified VPD response
v69 2008-07-03, MAN
- support hot-unplugging scanners
v70 2008-07-05, MAN
- fix bug in sane_get_parameters (failed to copy values)
- autodetect jpeg duplex interlacing mode by inspecting scan width
v71 2008-07-13, MAN
- disable overscan option if vpd does not tell overscan size
- fi-5110EOX crops scan area based on absolute maximum, not paper
- fi-5530C/2 and fi-5650C can't handle 10 bit LUT via USB
- fi-5900 has background color, though it reports otherwise
v72 2008-07-13, MAN
- use mode_sense to determine background color support
- remove fi-5900 background color override
v73 2008-07-14, MAN
- correct overscan dimension calculation
- provide correct overscan size overrides for fi-5110C and fi-4x20C2
- add fi-6130 usb ID
- fi-5750C can't handle 10 bit LUT via USB
v74 2008-08-02, MAN
- replace global scsi blocks with local ones in each function
v75 2008-08-07, ReneR
- added fi-6230 usb ID
v76 2008-08-13, MAN
- add independent maximum area values for flatbed
- override said values for fi-4220C, fi-4220C2 and fi-5220C
v77 2008-08-26, MAN
- override flatbed maximum area for fi-6230C and fi-6240C
- set PF bit in all mode_select(6) CDB's
- set SANE_CAP_INACTIVE on all disabled options
- fix bug in mode_select page for sleep timer
v78 2008-08-26, MAN
- recent model names (fi-6xxx) dont end in 'C'
- simplify flatbed area overrides
- call scanner_control to change source during sane_start
v79 2008-10-01, MAN
- add usb ids for several models
- print additional hardware capability bits
- detect front-side endorser
- disable endorser-side controls if only one side installed
- add quirks for fi-6x70
v80 2008-10-08, MAN
- front-side endorser uses data ID 0x80
v81 2008-10-20, MAN
- increase USB timeouts
- enable get_pixelsize() to update scan params after set_window()
- remove even_scan_line hack
v82 2008-10-31, MAN
- improved front-side endorser vpd detection
- send scanner_control_ric during sane_read of each side
- add fi-6770A and fi-6670A USB ID's
v83 2008-11-06, MAN
- round binary bpl and Bpl up to byte boundary
- use s->params instead of user data in set_window()
- read_from_scanner() only grabs an even number of lines
v84 2008-11-07, MAN
- round lines down to even number to get even # of total bytes
- round binary bpl and Bpl down to byte boundary
v85 2008-12-10, MAN
- round pixels_per_line down to arbitrary limits for fi-4990 & fi-4860
- fi-4860 returns random garbage to serial number queries
- initialize *info to 0 in sane_control_option()
v86 2008-12-18, MAN
- get_pixelsize() sets back window ID for back side scans
v87 2008-12-21, MAN
- accept null pointer as empty device name
- track frontend reading sensor/button values to reload
- deactivate double feed options if df-action == default
v88 2009-01-21, MAN
- dont export private symbols
v89 2009-02-20, MAN
- fi-4750 returns random garbage to serial number queries
v90 2009-02-23, MAN
- added ScanSnap S510M usb ids
v91 2009-03-20, MAN
- remove unused temp file code
v92 2009-04-12, MAN
- disable SANE_FRAME_JPEG support (again)
v93 2009-04-14, MAN (SANE 1.0.20)
- return cmd status for reads on sensors
- ignore errors in scanner_control(),
M3091 has not worked since sane 1.0.19, due to this.
- copy_buffer needs to count lines, or M309[12] cannot duplex
v94 2009-05-22, MAN
- add side option to show which duplex image is being transferred
- convert front and simplex buffers to use much less ram
- add lowmemory option which makes duplex back buffer small too
- refactor image handling code to track eof's instead of lengths
- do color deinterlacing after reading from scanner, before buffering
v95 2009-06-02, MAN
- scanner_control_ric should return a subset of the possible errors
v96 2009-08-07, MAN
- split sane_get_parameters into two functions
- remove unused code from get_pixelsize
- support hardware based auto length detection
v97 2009-09-14, MAN
- use sanei_magic to provide software deskew, autocrop and despeckle
v98 2010-02-09, MAN (SANE 1.0.21)
- clean up #include lines and copyright
- add SANE_I18N to static strings
- don't fail if scsi buffer is too small
- disable bg_color for S1500
- enable flatbed for M3092
v99 2010-05-14, MAN
- sense_handler(): collect rs_info for any ILI, not just EOM
- do_usb_cmd(): use rs_info whenever set, not just EOF
- read_from_*(): better handling of EOF from lower level functions
- sane_read(): improve duplexing logic
v100 2010-06-01, MAN
- store more Request Sense data in scanner struct
- clear Request Sense data at start of every do_cmd() call
- track per-side ILI and global EOM flags
- set per-side EOF flag if ILI and EOM are set
v101 2010-06-23, MAN
- fix compilation bug when jpeg is enabled
v102 2010-09-22, MAN
- fix infinite loop when scan is an odd number of lines
v103 2010-11-23, MAN
- remove compiled-in default config file
- initial support for new fi-6xxx machines
v104 2010-11-24, MAN
- never request more than s->buffer_size from scanner
- silence noisy set_window() calls from init_interlace()
v105 2010-12-02, MAN
- backup and restore image params around image processing code
- cache software crop/deskew parameters for use on backside of duplex
- fi-6110 does not support bgcolor or prepick
v106 2011-01-30, MAN (SANE 1.0.22)
- dont call mode_select with a page code the scanner does not support
v107 2011-11-03, MAN
- M3091 does not support scanner_control(adf)
- Correct buffer overflow in read_from_3091duplex()
- sane_read() now always calls read_from_*()
- read_from_*() are callable when there is no data, and read to eof
- sane_read() will keep alternate duplex reads to similar length
- Added debugging statements
- Corrected comments
- Updated Copyright
v108 2011-11-21, MAN
- merged x/y resolution options
- moved page width/height to start of geometry group
- use mode to pick resolution list v/s range
- improved M3091 resolution choices
v109 2011-12-20, MAN
- added some MS and INQ information
- increased default buffer size for later machines in config file
- renamed new fi-6xx0Z models
v110 2012-05-09, MAN
- correct max_y_fb for fi-62x0 series
- add must_fully_buffer helper routine
- add hwdeskewcrop option, with fallback to software versions
- add 'actual' param to get_pixelsize for post-scan
- add recent model VPD params
- only set params->lines = -1 when using ald without buffering
- fix bugs in background color when using software deskew
v111 2012-05-10, MAN (SANE 1.0.23)
- call send_* and mode_select_* from sane_start
- split read payloads into new debug level
- add paper-protect, staple-detect and df-recovery options
v112 2013-02-22, MAN
- some scanners (fi-6x70 and later) don't enable IPC by default
v113 2013-02-24, MAN
- support for ScanSnap iX500
- fix bug with jpeg de-interlacing code
- allow has_MS_* and has_pixelsize to be set in init_model
- fix use of uninitialized buffer in send_lut
- add send_q_table()
- allow wait_scanner() to be bypassed in object_position
- moved send_lut() to after set_window
v114 2013-03-01, MAN
- support resolutions > 300 for iX500 using diag_preread()
- remove most communication with scanner during sane_control_option()
v115 2013-03-09, MAN
- separate s->mode into s_mode and u_mode
- separate s->params into s_params and u_params
- generate grayscale and binary in software if required (iX500)
v116 2013-03-23, MAN
- call set_mode() in init_interlace
- add swskip option
v117 2013-06-11, MAN (SANE 1.0.24)
- default buffer-mode to off
- improved error handling in sane_start
- image width must be multiple of 8 when swcrop is used before binarization (iX500)
- check hopper sensor before calling object_position(load) on iX500
v118 2013-12-09, MAN
- support fi-7160, fi-7260, fi-7180 and fi-7280
- remove unused var from do_scsi_cmd()
- added more request_sense options
- add adv_paper_protect option
- enable paper protection by default
- increase max_x_fb for fi-6240 and fi-6230
v119 2013-12-18, MAN
- call get_pixelsize after start_scan, not before
- extend get_pixelsize to request backside data
- stop using backup/restore_params
- don't use extended get_pixelsize on M3091 or M3092
- call software crop code on backside images too
v120 2014-01-29, MAN
- only call hopper_before_op code at batch start
- remove unused backup/restore_params
v121 2014-04-07, MAN
- add JFIF APP0 marker with resolution to jpeg images
- improve jpeg duplex parsing code
- simplify jpeg ifdefs
- add offtimer option for more recent scanners
- don't print 0 length line in hexdump
v122 2014-10-28, MAN
- add support for object_position halt
- call object_position halt in check_for_cancel when requested
v123 2014-11-06, MAN
- workaround Linux USB3 bugs by adding command counting code and
sending an even number of reads and writes during disconnect_fd
v124 2014-12-09, MAN
- support resolution controlled max page-height (fi-6/7xxx scanners)
- reorder scanner sections in init_model chronologically
v125 2014-12-16, MAN
- remove USB packet counting code from v123, fix sanei_usb instead
v126 2015-08-23, MAN
- initial support for iX100
- add late_lut support for iX500/iX100
v127 2015-08-25, MAN (SANE 1.0.25)
- separate iX100 from iX500 settings
- iX100 has gray and lineart
v128 2015-11-08, MAN
- do not ask fi-4340 for serial number
v129 2015-11-21, MAN
- br_x and br_y locked to page_width/height until changed
v130 2016-02-23, MAN
- run init_model before init_ms so some scanners can override
- set all M309x and M409x scanners s->broken_diag_serial = 1
v131 2016-06-06, MAN
- hide compression-arg option when jpeg disabled
- add Send/SC/GHS macros for recent scanners
- add initial support for fi-74x0
- add initial support for fi-7030
- set has_MS_lamp=0 for fi-71x0
- add I18N macros to all option titles and descriptions
v132 2016-10-07, MAN
- remove ipc_mode option and variables
- set ipc mode based on other options
- cleanup inverted logic DTC options
- fixes threshold option reported in #315069
v133 2017-04-08, MAN
- initial support for fi-7600/7700
- autodetect various double feed capabilities using VPD
- call send_lut if we are using a downloaded gamma table
v134 2019-02-23, MAN
- rewrite init_vpd for scanners which fail to report
overscan correctly
SANE FLOW DIAGRAM
- sane_init() : initialize backend
. - sane_get_devices() : query list of scanner devices
. - sane_open() : open a particular scanner device
. . - sane_set_io_mode : set blocking mode
. . - sane_get_select_fd : get scanner fd
. .
. . - sane_get_option_descriptor() : get option information
. . - sane_control_option() : change option values
. . - sane_get_parameters() : returns estimated scan parameters
. . - (repeat previous 3 functions)
. .
. . - sane_start() : start image acquisition
. . - sane_get_parameters() : returns actual scan parameters
. . - sane_read() : read image data (from pipe)
. . (sane_read called multiple times; after sane_read returns EOF,
. . loop may continue with sane_start which may return a 2nd page
. . when doing duplex scans, or load the next page from the ADF)
. .
. . - sane_cancel() : cancel operation
. - sane_close() : close opened scanner device
- sane_exit() : terminate use of backend
*/
/*
* @@ Section 1 - Boilerplate
*/
#include "../include/sane/config.h"
#include <string.h> /*memcpy...*/
#include <ctype.h> /*isspace*/
#include <math.h> /*tan*/
#include <unistd.h> /*usleep*/
#include "../include/sane/sanei_backend.h"
#include "../include/sane/sanei_scsi.h"
#include "../include/sane/sanei_usb.h"
#include "../include/sane/saneopts.h"
#include "../include/sane/sanei_config.h"
#include "../include/sane/sanei_magic.h"
#include "fujitsu-scsi.h"
#include "fujitsu.h"
#define DEBUG 1
#define BUILD 134
/* values for SANE_DEBUG_FUJITSU env var:
- errors 5
- function trace 10
- function detail 15
- get/setopt cmds 20
- scsi/usb trace 25
- scsi/usb writes 30
- scsi/usb reads 31
- useless noise 35
*/
/* ------------------------------------------------------------------------- */
/* if JPEG support is not enabled in sane.h, we setup our own defines */
#ifndef SANE_FRAME_JPEG
#define SANE_FRAME_JPEG 0x0B
#define SANE_JPEG_DISABLED 1
#endif
/* ------------------------------------------------------------------------- */
#define STRING_FLATBED SANE_I18N("Flatbed")
#define STRING_ADFFRONT SANE_I18N("ADF Front")
#define STRING_ADFBACK SANE_I18N("ADF Back")
#define STRING_ADFDUPLEX SANE_I18N("ADF Duplex")
#define STRING_LINEART SANE_VALUE_SCAN_MODE_LINEART
#define STRING_HALFTONE SANE_VALUE_SCAN_MODE_HALFTONE
#define STRING_GRAYSCALE SANE_VALUE_SCAN_MODE_GRAY
#define STRING_COLOR SANE_VALUE_SCAN_MODE_COLOR
#define STRING_DEFAULT SANE_I18N("Default")
#define STRING_ON SANE_I18N("On")
#define STRING_OFF SANE_I18N("Off")
#define STRING_DTC SANE_I18N("DTC")
#define STRING_SDTC SANE_I18N("SDTC")
#define STRING_DITHER SANE_I18N("Dither")
#define STRING_DIFFUSION SANE_I18N("Diffusion")
#define STRING_RED SANE_I18N("Red")
#define STRING_GREEN SANE_I18N("Green")
#define STRING_BLUE SANE_I18N("Blue")
#define STRING_WHITE SANE_I18N("White")
#define STRING_BLACK SANE_I18N("Black")
#define STRING_NONE SANE_I18N("None")
#define STRING_JPEG SANE_I18N("JPEG")
#define STRING_CONTINUE SANE_I18N("Continue")
#define STRING_STOP SANE_I18N("Stop")
#define STRING_10MM SANE_I18N("10mm")
#define STRING_15MM SANE_I18N("15mm")
#define STRING_20MM SANE_I18N("20mm")
#define STRING_HORIZONTAL SANE_I18N("Horizontal")
#define STRING_HORIZONTALBOLD SANE_I18N("Horizontal bold")
#define STRING_HORIZONTALNARROW SANE_I18N("Horizontal narrow")
#define STRING_VERTICAL SANE_I18N("Vertical")
#define STRING_VERTICALBOLD SANE_I18N("Vertical bold")
#define STRING_TOPTOBOTTOM SANE_I18N("Top to bottom")
#define STRING_BOTTOMTOTOP SANE_I18N("Bottom to top")
#define STRING_FRONT SANE_I18N("Front")
#define STRING_BACK SANE_I18N("Back")
#define max(a,b) (((a)>(b))?(a):(b))
/* Also set via config file. */
static int global_buffer_size = 64 * 1024;
/*
* used by attach* and sane_get_devices
* a ptr to a null term array of ptrs to SANE_Device structs
* a ptr to a single-linked list of fujitsu structs
*/
static const SANE_Device **sane_devArray = NULL;
static struct fujitsu *fujitsu_devList = NULL;
/*
* @@ Section 2 - SANE & scanner init code
*/
/*
* Called by SANE initially.
*
* From the SANE spec:
* This function must be called before any other SANE function can be
* called. The behavior of a SANE backend is undefined if this
* function is not called first. The version code of the backend is
* returned in the value pointed to by version_code. If that pointer
* is NULL, no version code is returned. Argument authorize is either
* a pointer to a function that is invoked when the backend requires
* authentication for a specific resource or NULL if the frontend does
* not support authentication.
*/
SANE_Status
sane_init (SANE_Int * version_code, SANE_Auth_Callback authorize)
{
authorize = authorize; /* get rid of compiler warning */
DBG_INIT ();
DBG (10, "sane_init: start\n");
if (version_code)
*version_code = SANE_VERSION_CODE (SANE_CURRENT_MAJOR, V_MINOR, BUILD);
DBG (5, "sane_init: fujitsu backend %d.%d.%d, from %s\n",
SANE_CURRENT_MAJOR, V_MINOR, BUILD, PACKAGE_STRING);
sanei_magic_init();
DBG (10, "sane_init: finish\n");
return SANE_STATUS_GOOD;
}
/*
* Called by SANE to find out about supported devices.
*
* From the SANE spec:
* This function can be used to query the list of devices that are
* available. If the function executes successfully, it stores a
* pointer to a NULL terminated array of pointers to SANE_Device
* structures in *device_list. The returned list is guaranteed to
* remain unchanged and valid until (a) another call to this function
* is performed or (b) a call to sane_exit() is performed. This
* function can be called repeatedly to detect when new devices become
* available. If argument local_only is true, only local devices are
* returned (devices directly attached to the machine that SANE is
* running on). If it is false, the device list includes all remote
* devices that are accessible to the SANE library.
*
* SANE does not require that this function is called before a
* sane_open() call is performed. A device name may be specified
* explicitly by a user which would make it unnecessary and
* undesirable to call this function first.
*/
/*
* Read the config file, find scanners with help from sanei_*
* and store in global device structs
*/
SANE_Status
sane_get_devices (const SANE_Device *** device_list, SANE_Bool local_only)
{
SANE_Status ret = SANE_STATUS_GOOD;
struct fujitsu * s;
struct fujitsu * prev = NULL;
char line[PATH_MAX];
const char *lp;
FILE *fp;
int num_devices=0;
int i=0;
local_only = local_only; /* get rid of compiler warning */
DBG (10, "sane_get_devices: start\n");
/* mark all existing scanners as missing, attach_one will remove mark */
for (s = fujitsu_devList; s; s = s->next) {
s->missing = 1;
}
sanei_usb_init();
/* set this to 64K before reading the file */
global_buffer_size = 64 * 1024;
fp = sanei_config_open (FUJITSU_CONFIG_FILE);
if (fp) {
DBG (15, "sane_get_devices: reading config file %s\n",
FUJITSU_CONFIG_FILE);
while (sanei_config_read (line, PATH_MAX, fp)) {
lp = line;
/* ignore comments */
if (*lp == '#')
continue;
/* skip empty lines */
if (*lp == 0)
continue;
if ((strncmp ("option", lp, 6) == 0) && isspace (lp[6])) {
lp += 6;
lp = sanei_config_skip_whitespace (lp);
/* we allow setting buffersize too big */
if ((strncmp (lp, "buffer-size", 11) == 0) && isspace (lp[11])) {
int buf;
lp += 11;
lp = sanei_config_skip_whitespace (lp);
buf = atoi (lp);
if (buf < 4096) {
DBG (5, "sane_get_devices: config option \"buffer-size\" (%d) is < 4096, ignoring!\n", buf);
continue;
}
if (buf > 64*1024) {
DBG (5, "sane_get_devices: config option \"buffer-size\" (%d) is > %d, warning!\n", buf, 64*1024);
}
DBG (15, "sane_get_devices: setting \"buffer-size\" to %d\n", buf);
global_buffer_size = buf;
}
else {
DBG (5, "sane_get_devices: config option \"%s\" unrecognized - ignored.\n", lp);
}
}
else if ((strncmp ("usb", lp, 3) == 0) && isspace (lp[3])) {
DBG (15, "sane_get_devices: looking for '%s'\n", lp);
sanei_usb_attach_matching_devices(lp, attach_one_usb);
}
else if ((strncmp ("scsi", lp, 4) == 0) && isspace (lp[4])) {
DBG (15, "sane_get_devices: looking for '%s'\n", lp);
sanei_config_attach_matching_devices (lp, attach_one_scsi);
}
else{
DBG (5, "sane_get_devices: config line \"%s\" unrecognized - ignored.\n", lp);
}
}
fclose (fp);
}
else {
DBG (5, "sane_get_devices: missing required config file '%s'!\n",
FUJITSU_CONFIG_FILE);
}
/*delete missing scanners from list*/
for (s = fujitsu_devList; s;) {
if(s->missing){
DBG (5, "sane_get_devices: missing scanner %s\n",s->device_name);
/*splice s out of list by changing pointer in prev to next*/
if(prev){
prev->next = s->next;
free(s);
s=prev->next;
}
/*remove s from head of list, using prev to cache it*/
else{
prev = s;
s = s->next;
free(prev);
prev=NULL;
/*reset head to next s*/
fujitsu_devList = s;
}
}
else{
prev = s;
s=prev->next;
}
}
for (s = fujitsu_devList; s; s=s->next) {
DBG (15, "sane_get_devices: found scanner %s\n",s->device_name);
num_devices++;
}
DBG (15, "sane_get_devices: found %d scanner(s)\n",num_devices);
if (sane_devArray)
free (sane_devArray);
sane_devArray = calloc (num_devices + 1, sizeof (SANE_Device*));
if (!sane_devArray)
return SANE_STATUS_NO_MEM;
for (s = fujitsu_devList; s; s=s->next) {
sane_devArray[i++] = (SANE_Device *)&s->sane;
}
sane_devArray[i] = 0;
if(device_list){
*device_list = sane_devArray;
}
DBG (10, "sane_get_devices: finish\n");
return ret;
}
/* callbacks used by sane_get_devices */
static SANE_Status
attach_one_scsi (const char *device_name)
{
return attach_one(device_name,CONNECTION_SCSI);
}
static SANE_Status
attach_one_usb (const char *device_name)
{
return attach_one(device_name,CONNECTION_USB);
}
/* build the scanner struct and link to global list
* unless struct is already loaded, then pretend
*/
static SANE_Status
attach_one (const char *device_name, int connType)
{
struct fujitsu *s;
int ret;
DBG (10, "attach_one: start\n");
DBG (15, "attach_one: looking for '%s'\n", device_name);
for (s = fujitsu_devList; s; s = s->next) {
if (strcmp (s->device_name, device_name) == 0){
DBG (10, "attach_one: already attached!\n");
s->missing = 0;
return SANE_STATUS_GOOD;
}
}
/* build a fujitsu struct to hold it */
if ((s = calloc (sizeof (*s), 1)) == NULL)
return SANE_STATUS_NO_MEM;
/* scsi command/data buffer */
s->buffer_size = global_buffer_size;
/* copy the device name */
strcpy (s->device_name, device_name);
/* connect the fd */
s->connection = connType;
s->fd = -1;
ret = connect_fd(s);
if(ret != SANE_STATUS_GOOD){
free (s);
return ret;
}
/* Now query the device to load its vendor/model/version */
ret = init_inquire (s);
if (ret != SANE_STATUS_GOOD) {
disconnect_fd(s);
free (s);
DBG (5, "attach_one: inquiry failed\n");
return ret;
}
/* load detailed specs/capabilities from the device */
ret = init_vpd (s);
if (ret != SANE_STATUS_GOOD) {
disconnect_fd(s);
free (s);
DBG (5, "attach_one: vpd failed\n");
return ret;
}
/* clean up the scanner struct based on model */
/* this is the only piece of model specific code */
ret = init_model (s);
if (ret != SANE_STATUS_GOOD) {
disconnect_fd(s);
free (s);
DBG (5, "attach_one: model failed\n");
return ret;
}
/* see what mode pages device supports */
ret = init_ms (s);
if (ret != SANE_STATUS_GOOD) {
disconnect_fd(s);
free (s);
DBG (5, "attach_one: ms failed\n");
return ret;
}
/* sets SANE option 'values' to good defaults */
ret = init_user (s);
if (ret != SANE_STATUS_GOOD) {
disconnect_fd(s);
free (s);
DBG (5, "attach_one: user failed\n");
return ret;
}
ret = init_options (s);
if (ret != SANE_STATUS_GOOD) {
disconnect_fd(s);
free (s);
DBG (5, "attach_one: options failed\n");
return ret;
}
ret = init_interlace (s);
if (ret != SANE_STATUS_GOOD) {
disconnect_fd(s);
free (s);
DBG (5, "attach_one: interlace failed\n");
return ret;
}
/* load strings into sane_device struct */
s->sane.name = s->device_name;
s->sane.vendor = s->vendor_name;
s->sane.model = s->model_name;
s->sane.type = "scanner";
/* change name in sane_device struct if scanner has serial number */
ret = init_serial (s);
if (ret == SANE_STATUS_GOOD) {
s->sane.name = s->serial_name;
}
else{
DBG (5, "attach_one: serial number unsupported?\n");
}
/* we close the connection, so that another backend can talk to scanner */
disconnect_fd(s);
/* store this scanner in global vars */
s->next = fujitsu_devList;
fujitsu_devList = s;
DBG (10, "attach_one: finish\n");
return SANE_STATUS_GOOD;
}
/*
* connect the fd in the scanner struct
*/
static SANE_Status
connect_fd (struct fujitsu *s)
{
SANE_Status ret;
int buffer_size = s->buffer_size;
DBG (10, "connect_fd: start\n");
if(s->fd > -1){
DBG (5, "connect_fd: already open\n");
ret = SANE_STATUS_GOOD;
}
else if (s->connection == CONNECTION_USB) {
DBG (15, "connect_fd: opening USB device\n");
ret = sanei_usb_open (s->device_name, &(s->fd));
}
else {
DBG (15, "connect_fd: opening SCSI device\n");
ret = sanei_scsi_open_extended (s->device_name, &(s->fd), sense_handler, s,
&s->buffer_size);
if(!ret && buffer_size != s->buffer_size){
DBG (5, "connect_fd: cannot get requested buffer size (%d/%d)\n",
buffer_size, s->buffer_size);
}
}
if(ret == SANE_STATUS_GOOD){
/* first generation usb scanners can get flaky if not closed
* properly after last use. very first commands sent to device
* must be prepared to correct this- see wait_scanner() */
ret = wait_scanner(s);
if (ret != SANE_STATUS_GOOD) {
DBG (5, "connect_fd: could not wait_scanner\n");
disconnect_fd(s);
}
}
else{
DBG (5, "connect_fd: could not open device: %d\n", ret);
}
DBG (10, "connect_fd: finish\n");
return ret;
}
/*
* This routine will check if a certain device is a Fujitsu scanner
* It also copies interesting data from INQUIRY into the handle structure
*/
static SANE_Status
init_inquire (struct fujitsu *s)
{
int i;
SANE_Status ret;
unsigned char cmd[INQUIRY_len];
size_t cmdLen = INQUIRY_len;
unsigned char in[INQUIRY_std_len];
size_t inLen = INQUIRY_std_len;
DBG (10, "init_inquire: start\n");
memset(cmd,0,cmdLen);
set_SCSI_opcode(cmd, INQUIRY_code);
set_IN_return_size (cmd, inLen);
set_IN_evpd (cmd, 0);
set_IN_page_code (cmd, 0);
ret = do_cmd (
s, 1, 0,
cmd, cmdLen,
NULL, 0,
in, &inLen
);
if (ret != SANE_STATUS_GOOD){
return ret;
}
if (get_IN_periph_devtype (in) != IN_periph_devtype_scanner){
DBG (5, "The device at '%s' is not a scanner.\n", s->device_name);
return SANE_STATUS_INVAL;
}
get_IN_vendor (in, s->vendor_name);
get_IN_product (in, s->model_name);
get_IN_version (in, s->version_name);
s->vendor_name[8] = 0;
s->model_name[16] = 0;
s->version_name[4] = 0;
/* gobble trailing spaces */
for (i = 7; s->vendor_name[i] == ' ' && i >= 0; i--)
s->vendor_name[i] = 0;
for (i = 15; s->model_name[i] == ' ' && i >= 0; i--)
s->model_name[i] = 0;
for (i = 3; s->version_name[i] == ' ' && i >= 0; i--)
s->version_name[i] = 0;
if (strcmp ("FUJITSU", s->vendor_name)) {
DBG (5, "The device at '%s' is reported to be made by '%s'\n", s->device_name, s->vendor_name);
DBG (5, "This backend only supports Fujitsu products.\n");
return SANE_STATUS_INVAL;
}
DBG (15, "init_inquire: Found %s scanner %s version %s at %s\n",
s->vendor_name, s->model_name, s->version_name, s->device_name);
/*some scanners list random data here*/
DBG (15, "inquiry options\n");
s->color_raster_offset = get_IN_color_offset(in);
DBG (15, " color offset: %d lines\n",s->color_raster_offset);
/* FIXME: we dont store all of these? */
DBG (15, " long gray scan: %d\n",get_IN_long_gray(in));
DBG (15, " long color scan: %d\n",get_IN_long_color(in));
DBG (15, " emulation mode: %d\n",get_IN_emulation(in));
DBG (15, " CMP/CGA: %d\n",get_IN_cmp_cga(in));
DBG (15, " background back: %d\n",get_IN_bg_back(in));
DBG (15, " background front: %d\n",get_IN_bg_front(in));
DBG (15, " background fb: %d\n",get_IN_bg_fb(in));
DBG (15, " back only scan: %d\n",get_IN_has_back(in));
s->duplex_raster_offset = get_IN_duplex_offset(in);
DBG (15, " duplex offset: %d lines\n",s->duplex_raster_offset);
DBG (10, "init_inquire: finish\n");
return SANE_STATUS_GOOD;
}
/*
* Use INQUIRY VPD to setup more detail about the scanner
*/
static SANE_Status
init_vpd (struct fujitsu *s)
{
SANE_Status ret;
unsigned char cmd[INQUIRY_len];
size_t cmdLen = INQUIRY_len;
unsigned char in[INQUIRY_vpd_len];
size_t inLen = INQUIRY_vpd_len;
int payload_len, payload_off;
DBG (10, "init_vpd: start\n");
/* get EVPD */
memset(cmd,0,cmdLen);
set_SCSI_opcode(cmd, INQUIRY_code);
set_IN_return_size (cmd, inLen);
set_IN_evpd (cmd, 1);
set_IN_page_code (cmd, 0xf0);
ret = do_cmd (
s, 1, 0,
cmd, cmdLen,
NULL, 0,
in, &inLen
);
/*FIXME no vpd, set some defaults? */
if (ret != SANE_STATUS_GOOD && ret != SANE_STATUS_EOF) {
DBG (5, "init_vpd: Your scanner does not support VPD?\n");
DBG (5, "init_vpd: Please contact kitno455 at gmail dot com\n");
DBG (5, "init_vpd: with details of your scanner model.\n");
return ret;
}
/* In byte 4, the scanner sends the length of the remainder of
* the payload. But, this value is often bogus. */
payload_len = get_IN_page_length(in);
DBG (15, "init_vpd: length=%0x\n", payload_len);
/* M3099 gives all data, but wrong length */
if (strstr (s->model_name, "M3099") && payload_len == 0x19){
DBG (5, "init_vpd: M3099 repair\n");
payload_len = 0x5f;
}
/* M3097G has short vpd, fill in missing part */
else if (strstr (s->model_name, "M3097G") && payload_len == 0x19){
unsigned char vpd3097g[] = {
0, 0,
0xc2, 0x08, 0, 0, 0, 0, 0, 0, 0xed, 0xbf, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0xff, 0xff, 0xff, 0, 0x45, 0x35, 0, 0xe0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0
};
DBG (5, "init_vpd: M3097G repair\n");
payload_len = 0x5f;
memcpy(in+0x1e,vpd3097g,sizeof(vpd3097g));
/*IPC*/
if(strstr (s->model_name, "i")){
DBG (5, "init_vpd: M3097G IPC repair\n");
/*subwin cmd*/
in[0x2b] = 1;
/*rif/dtc/sdtc/outline/emph/sep/mirr/wlf*/
in[0x58] = 0xff;
/*subwin/diffusion*/
in[0x59] = 0xc0;
}
/*CMP*/
if(strstr (s->model_name, "m")){
DBG (5, "init_vpd: M3097G CMP repair\n");
/*4megs*/
in[0x23] = 0x40;
/*mh/mr/mmr*/
in[0x5a] = 0xe0;
}
}
/* all other known scanners have at least 0x5f,
* less would require software changes like above */
else if (payload_len < 0x5f) {
DBG (5, "init_vpd: Your scanner supports only partial VPD?\n");
DBG (5, "init_vpd: Please contact kitno455 at gmail dot com\n");
DBG (5, "init_vpd: with details of your scanner model.\n");
return SANE_STATUS_INVAL;
}
/* Special case- some scanners will under-report the amount of
* valid vpd that they send, and return the default length.
* Adding 4 more bytes allows us to include the overscan info.
* Scanners that don't support overscan seem to have all zeros
* in these bytes, so no harm is done.
* This may be an 'off-by-four' error in the firmware. */
else if (payload_len == 0x5f){
payload_len += 4;
}
/* Having an offset from the beginning of the payload
* is more useful than from byte 4, as that matches the
* documentation more closely. */
payload_off = payload_len + 4;
/* everything that appears in bytes 0 to 0x1d */
DBG (15, "standard options\n");
s->basic_x_res = get_IN_basic_x_res (in);
DBG (15, " basic x res: %d dpi\n",s->basic_x_res);
s->basic_y_res = get_IN_basic_y_res (in);
DBG (15, " basic y res: %d dpi\n",s->basic_y_res);
s->step_x_res[MODE_LINEART] = get_IN_step_x_res (in);
DBG (15, " step x res: %d dpi\n", s->step_x_res[MODE_LINEART]);
s->step_y_res[MODE_LINEART] = get_IN_step_y_res (in);
DBG (15, " step y res: %d dpi\n", s->step_y_res[MODE_LINEART]);
s->max_x_res = get_IN_max_x_res (in);
DBG (15, " max x res: %d dpi\n", s->max_x_res);
s->max_y_res = get_IN_max_y_res (in);
DBG (15, " max y res: %d dpi\n", s->max_y_res);
s->min_x_res = get_IN_min_x_res (in);
DBG (15, " min x res: %d dpi\n", s->min_x_res);
s->min_y_res = get_IN_min_y_res (in);
DBG (15, " min y res: %d dpi\n", s->min_y_res);
/* some scanners list B&W resolutions. */
s->std_res[0] = get_IN_std_res_60 (in);
DBG (15, " 60 dpi: %d\n", s->std_res[0]);
s->std_res[1] = get_IN_std_res_75 (in);
DBG (15, " 75 dpi: %d\n", s->std_res[1]);
s->std_res[2] = get_IN_std_res_100 (in);
DBG (15, " 100 dpi: %d\n", s->std_res[2]);
s->std_res[3] = get_IN_std_res_120 (in);
DBG (15, " 120 dpi: %d\n", s->std_res[3]);
s->std_res[4] = get_IN_std_res_150 (in);
DBG (15, " 150 dpi: %d\n", s->std_res[4]);
s->std_res[5] = get_IN_std_res_160 (in);
DBG (15, " 160 dpi: %d\n", s->std_res[5]);
s->std_res[6] = get_IN_std_res_180 (in);
DBG (15, " 180 dpi: %d\n", s->std_res[6]);
s->std_res[7] = get_IN_std_res_200 (in);
DBG (15, " 200 dpi: %d\n", s->std_res[7]);
s->std_res[8] = get_IN_std_res_240 (in);
DBG (15, " 240 dpi: %d\n", s->std_res[8]);
s->std_res[9] = get_IN_std_res_300 (in);
DBG (15, " 300 dpi: %d\n", s->std_res[9]);
s->std_res[10] = get_IN_std_res_320 (in);
DBG (15, " 320 dpi: %d\n", s->std_res[10]);
s->std_res[11] = get_IN_std_res_400 (in);
DBG (15, " 400 dpi: %d\n", s->std_res[11]);
s->std_res[12] = get_IN_std_res_480 (in);
DBG (15, " 480 dpi: %d\n", s->std_res[12]);
s->std_res[13] = get_IN_std_res_600 (in);
DBG (15, " 600 dpi: %d\n", s->std_res[13]);
s->std_res[14] = get_IN_std_res_800 (in);
DBG (15, " 800 dpi: %d\n", s->std_res[14]);
s->std_res[15] = get_IN_std_res_1200 (in);
DBG (15, " 1200 dpi: %d\n", s->std_res[15]);
/* maximum window width and length are reported in basic units.*/
s->max_x_basic = get_IN_window_width(in);
DBG(15, " max width: %2.2f inches\n",(float)s->max_x_basic/s->basic_x_res);
s->max_y_basic = get_IN_window_length(in);
DBG(15, " max length: %2.2f inches\n",(float)s->max_y_basic/s->basic_y_res);
/* known modes */
s->can_overflow = get_IN_overflow(in);
DBG (15, " overflow: %d\n", s->can_overflow);
s->can_mode[MODE_LINEART] = get_IN_monochrome (in);
DBG (15, " monochrome: %d\n", s->can_mode[MODE_LINEART]);
s->can_mode[MODE_HALFTONE] = get_IN_half_tone (in);
DBG (15, " halftone: %d\n", s->can_mode[MODE_HALFTONE]);
s->can_mode[MODE_GRAYSCALE] = get_IN_multilevel (in);
DBG (15, " grayscale: %d\n", s->can_mode[MODE_GRAYSCALE]);
DBG (15, " color_monochrome: %d\n", get_IN_monochrome_rgb(in));
DBG (15, " color_halftone: %d\n", get_IN_half_tone_rgb(in));
s->can_mode[MODE_COLOR] = get_IN_multilevel_rgb (in);
DBG (15, " color_grayscale: %d\n", s->can_mode[MODE_COLOR]);
/* now we look at vendor specific data in bytes 0x1e onward */
DBG (15, "vendor options\n");
s->has_adf = get_IN_adf(in);
DBG (15, " adf: %d\n", s->has_adf);
s->has_flatbed = get_IN_flatbed(in);
DBG (15, " flatbed: %d\n", s->has_flatbed);
s->has_transparency = get_IN_transparency(in);
DBG (15, " transparency: %d\n", s->has_transparency);
s->has_duplex = get_IN_duplex(in);
s->has_back = s->has_duplex;
DBG (15, " duplex: %d\n", s->has_duplex);
s->has_endorser_b = get_IN_endorser_b(in);
DBG (15, " back endorser: %d\n", s->has_endorser_b);
s->has_barcode = get_IN_barcode(in);
DBG (15, " barcode: %d\n", s->has_barcode);
s->has_operator_panel = get_IN_operator_panel(in);
DBG (15, " operator panel: %d\n", s->has_operator_panel);
s->has_endorser_f = get_IN_endorser_f(in);
DBG (15, " front endorser: %d\n", s->has_endorser_f);
DBG (15, " multi-purpose stacker: %d\n", get_IN_mp_stacker(in));
DBG (15, " prepick: %d\n", get_IN_prepick(in));
DBG (15, " mf detect: %d\n", get_IN_mf_detect(in));
s->has_paper_protect = get_IN_paperprot(in);
DBG (15, " paper protection: %d\n", s->has_paper_protect);
s->adbits = get_IN_adbits(in);
DBG (15, " A/D bits: %d\n",s->adbits);
s->buffer_bytes = get_IN_buffer_bytes(in);
DBG (15, " buffer bytes: %d\n",s->buffer_bytes);
DBG (15, "Standard commands\n");
/* std scsi command support byte 26*/
s->has_cmd_msen10 = get_IN_has_cmd_msen10(in);
DBG (15, " mode_sense_10 cmd: %d\n", s->has_cmd_msen10);
s->has_cmd_msel10 = get_IN_has_cmd_msel10(in);
DBG (15, " mode_select_10 cmd: %d\n", s->has_cmd_msel10);
/* std scsi command support byte 27*/
s->has_cmd_lsen = get_IN_has_cmd_lsen(in);
DBG (15, " log_sense cmd: %d\n", s->has_cmd_lsen);
s->has_cmd_lsel = get_IN_has_cmd_lsel(in);
DBG (15, " log_select cmd: %d\n", s->has_cmd_lsel);
s->has_cmd_change = get_IN_has_cmd_change(in);
DBG (15, " change cmd: %d\n", s->has_cmd_change);
s->has_cmd_rbuff = get_IN_has_cmd_rbuff(in);
DBG (15, " read_buffer cmd: %d\n", s->has_cmd_rbuff);
s->has_cmd_wbuff = get_IN_has_cmd_wbuff(in);
DBG (15, " write_buffer cmd: %d\n", s->has_cmd_wbuff);
s->has_cmd_cav = get_IN_has_cmd_cav(in);
DBG (15, " copy_and_verify cmd: %d\n", s->has_cmd_cav);
s->has_cmd_comp = get_IN_has_cmd_comp(in);
DBG (15, " compare cmd: %d\n", s->has_cmd_comp);
s->has_cmd_gdbs = get_IN_has_cmd_gdbs(in);
DBG (15, " get_d_b_status cmd: %d\n", s->has_cmd_gdbs);
/* std scsi command support byte 28*/
s->has_cmd_op = get_IN_has_cmd_op(in);
DBG (15, " object_pos cmd: %d\n", s->has_cmd_op);
s->has_cmd_send = get_IN_has_cmd_send(in);
DBG (15, " send cmd: %d\n", s->has_cmd_send);
s->has_cmd_read = get_IN_has_cmd_read(in);
DBG (15, " read cmd: %d\n", s->has_cmd_read);
s->has_cmd_gwin = get_IN_has_cmd_gwin(in);
DBG (15, " get_window cmd: %d\n", s->has_cmd_gwin);
s->has_cmd_swin = get_IN_has_cmd_swin(in);
DBG (15, " set_window cmd: %d\n", s->has_cmd_swin);
s->has_cmd_sdiag = get_IN_has_cmd_sdiag(in);
DBG (15, " send_diag cmd: %d\n", s->has_cmd_sdiag);
s->has_cmd_rdiag = get_IN_has_cmd_rdiag(in);
DBG (15, " read_diag cmd: %d\n", s->has_cmd_rdiag);
s->has_cmd_scan = get_IN_has_cmd_scan(in);
DBG (15, " scan cmd: %d\n", s->has_cmd_scan);
/* std scsi command support byte 29*/
s->has_cmd_msen6 = get_IN_has_cmd_msen6(in);
DBG (15, " mode_sense_6 cmd: %d\n", s->has_cmd_msen6);
s->has_cmd_copy = get_IN_has_cmd_copy(in);
DBG (15, " copy cmd: %d\n", s->has_cmd_copy);
s->has_cmd_rel = get_IN_has_cmd_rel(in);
DBG (15, " release cmd: %d\n", s->has_cmd_rel);
s->has_cmd_runit = get_IN_has_cmd_runit(in);
DBG (15, " reserve_unit cmd: %d\n", s->has_cmd_runit);
s->has_cmd_msel6 = get_IN_has_cmd_msel6(in);
DBG (15, " mode_select_6 cmd: %d\n", s->has_cmd_msel6);
s->has_cmd_inq = get_IN_has_cmd_inq(in);
DBG (15, " inquiry cmd: %d\n", s->has_cmd_inq);
s->has_cmd_rs = get_IN_has_cmd_rs(in);
DBG (15, " request_sense cmd: %d\n", s->has_cmd_rs);
s->has_cmd_tur = get_IN_has_cmd_tur(in);
DBG (15, " test_unit_ready cmd: %d\n", s->has_cmd_tur);
/* vendor added scsi command support */
/* FIXME: there are more of these... */
DBG (15, "Vendor commands\n");
s->has_cmd_subwindow = get_IN_has_cmd_subwindow(in);
DBG (15, " subwindow cmd: %d\n", s->has_cmd_subwindow);
s->has_cmd_endorser = get_IN_has_cmd_endorser(in);
DBG (15, " endorser cmd: %d\n", s->has_cmd_endorser);
s->has_cmd_hw_status = get_IN_has_cmd_hw_status (in);
DBG (15, " hardware status cmd: %d\n", s->has_cmd_hw_status);
s->has_cmd_hw_status_2 = get_IN_has_cmd_hw_status_2 (in);
DBG (15, " hardware status 2 cmd: %d\n", s->has_cmd_hw_status_2);
s->has_cmd_hw_status_3 = get_IN_has_cmd_hw_status_3 (in);
DBG (15, " hardware status 3 cmd: %d\n", s->has_cmd_hw_status_3);
s->has_cmd_scanner_ctl = get_IN_has_cmd_scanner_ctl(in);
DBG (15, " scanner control cmd: %d\n", s->has_cmd_scanner_ctl);
s->has_cmd_device_restart = get_IN_has_cmd_device_restart(in);
DBG (15, " device restart cmd: %d\n", s->has_cmd_device_restart);
/* get threshold, brightness and contrast ranges. */
s->brightness_steps = get_IN_brightness_steps(in);
DBG (15, " brightness steps: %d\n", s->brightness_steps);
s->threshold_steps = get_IN_threshold_steps(in);
DBG (15, " threshold steps: %d\n", s->threshold_steps);
s->contrast_steps = get_IN_contrast_steps(in);
DBG (15, " contrast steps: %d\n", s->contrast_steps);
/* dither/gamma patterns */
s->num_internal_gamma = get_IN_num_gamma_internal (in);
DBG (15, " built in gamma patterns: %d\n", s->num_internal_gamma);
s->num_download_gamma = get_IN_num_gamma_download (in);
DBG (15, " download gamma patterns: %d\n", s->num_download_gamma);
s->num_internal_dither = get_IN_num_dither_internal (in);
DBG (15, " built in dither patterns: %d\n", s->num_internal_dither);
s->num_download_dither = get_IN_num_dither_download (in);
DBG (15, " download dither patterns: %d\n", s->num_download_dither);
/* ipc functions */
s->has_rif = get_IN_ipc_bw_rif (in);
DBG (15, " RIF: %d\n", s->has_rif);
s->has_dtc = get_IN_ipc_dtc(in);
DBG (15, " DTC (AutoI): %d\n", s->has_dtc);
s->has_sdtc = get_IN_ipc_sdtc(in);
DBG (15, " SDTC (AutoII): %d\n", s->has_sdtc);
s->has_outline = get_IN_ipc_outline_extraction (in);
DBG (15, " outline extraction: %d\n", s->has_outline);
s->has_emphasis = get_IN_ipc_image_emphasis (in);
DBG (15, " image emphasis: %d\n", s->has_emphasis);
s->has_autosep = get_IN_ipc_auto_separation (in);
DBG (15, " automatic separation: %d\n", s->has_autosep);
s->has_mirroring = get_IN_ipc_mirroring (in);
DBG (15, " mirror image: %d\n", s->has_mirroring);
s->has_wl_follow = get_IN_ipc_wl_follow (in);
DBG (15, " white level follower: %d\n", s->has_wl_follow);
/* byte 58 */
s->has_subwindow = get_IN_ipc_subwindow (in);
DBG (15, " subwindow: %d\n", s->has_subwindow);
s->has_diffusion = get_IN_ipc_diffusion (in);
DBG (15, " diffusion: %d\n", s->has_diffusion);
s->has_ipc3 = get_IN_ipc_ipc3 (in);
DBG (15, " ipc3: %d\n", s->has_ipc3);
s->has_rotation = get_IN_ipc_rotation (in);
DBG (15, " rotation: %d\n", s->has_rotation);
s->has_hybrid_crop_deskew = get_IN_ipc_hybrid_crop_deskew(in);
DBG (15, " hybrid crop deskew: %d\n", s->has_hybrid_crop_deskew);
/* this one is weird, overrides the payload length from scanner */
DBG (15, " vpd extends to byte 6f: %d\n", get_IN_vpd_thru_byte_6f(in));
if(get_IN_vpd_thru_byte_6f(in) && payload_off < 0x6f){
payload_off = 0x6f;
}
/* compression modes */
s->has_comp_MH = get_IN_compression_MH (in);
DBG (15, " compression MH: %d\n", s->has_comp_MH);
s->has_comp_MR = get_IN_compression_MR (in);
DBG (15, " compression MR: %d\n", s->has_comp_MR);
s->has_comp_MMR = get_IN_compression_MMR (in);
DBG (15, " compression MMR: %d\n", s->has_comp_MMR);
s->has_comp_JBIG = get_IN_compression_JBIG (in);
DBG (15, " compression JBIG: %d\n", s->has_comp_JBIG);
s->has_comp_JPG1 = get_IN_compression_JPG_BASE (in);
DBG (15, " compression JPG1: %d\n", s->has_comp_JPG1);
#ifdef SANE_JPEG_DISABLED
DBG (15, " (Disabled)\n");
#endif
s->has_comp_JPG2 = get_IN_compression_JPG_EXT (in);
DBG (15, " compression JPG2: %d\n", s->has_comp_JPG2);
s->has_comp_JPG3 = get_IN_compression_JPG_INDEP (in);
DBG (15, " compression JPG3: %d\n", s->has_comp_JPG3);
/* FIXME: we dont store these? */
DBG (15, " back endorser mech: %d\n", get_IN_endorser_b_mech(in));
DBG (15, " back endorser stamp: %d\n", get_IN_endorser_b_stamp(in));
DBG (15, " back endorser elec: %d\n", get_IN_endorser_b_elec(in));
DBG (15, " endorser max id: %d\n", get_IN_endorser_max_id(in));
DBG (15, " front endorser mech: %d\n", get_IN_endorser_f_mech(in));
DBG (15, " front endorser stamp: %d\n", get_IN_endorser_f_stamp(in));
DBG (15, " front endorser elec: %d\n", get_IN_endorser_f_elec(in));
s->endorser_type_b = get_IN_endorser_b_type(in);
DBG (15, " back endorser type: %d\n", s->endorser_type_b);
s->endorser_type_f = get_IN_endorser_f_type(in);
DBG (15, " back endorser type: %d\n", s->endorser_type_f);
DBG (15, " connection type: %d\n", get_IN_connection(in));
DBG (15, " endorser ext: %d\n", get_IN_endorser_type_ext(in));
DBG (15, " endorser pr_b: %d\n", get_IN_endorser_pre_back(in));
DBG (15, " endorser pr_f: %d\n", get_IN_endorser_pre_front(in));
DBG (15, " endorser po_b: %d\n", get_IN_endorser_post_back(in));
DBG (15, " endorser po_f: %d\n", get_IN_endorser_post_front(in));
s->os_x_basic = get_IN_x_overscan_size(in);
DBG (15, " horizontal overscan: %d\n", s->os_x_basic);
s->os_y_basic = get_IN_y_overscan_size(in);
DBG (15, " vertical overscan: %d\n", s->os_y_basic);
/* not all scanners go this far */
if (payload_off >= 0x68) {
DBG (15, " default bg adf b: %d\n", get_IN_default_bg_adf_b(in));
DBG (15, " default bg adf f: %d\n", get_IN_default_bg_adf_f(in));
DBG (15, " default bg fb: %d\n", get_IN_default_bg_fb(in));
}
if (payload_off >= 0x69) {
DBG (15, " auto color: %d\n", get_IN_auto_color(in));
DBG (15, " blank skip: %d\n", get_IN_blank_skip(in));
DBG (15, " multi image: %d\n", get_IN_multi_image(in));
DBG (15, " f b type indep: %d\n", get_IN_f_b_type_indep(in));
DBG (15, " f b res indep: %d\n", get_IN_f_b_res_indep(in));
}
if (payload_off >= 0x6a) {
DBG (15, " dropout spec: %d\n", get_IN_dropout_spec(in));
DBG (15, " dropout non: %d\n", get_IN_dropout_non(in));
DBG (15, " dropout white: %d\n", get_IN_dropout_white(in));
}
if (payload_off >= 0x6d) {
DBG (15, " skew check: %d\n", get_IN_skew_check(in));
DBG (15, " new feed roller: %d\n", get_IN_new_fd_roll(in));
s->has_adv_paper_prot = get_IN_paper_prot_2(in);
DBG (15, " paper protection: %d\n", s->has_adv_paper_prot);
}
/* this one is weird, overrides the payload length from scanner,
* but the enlarged area is just null bytes, so we ignore this */
if (payload_off >= 0x6f) {
DBG (15, " extra evpd length: %d\n", get_IN_evpd_len(in));
}
if (payload_off >= 0x70) {
DBG (15, " paper count: %d\n", get_IN_paper_count(in));
DBG (15, " paper number: %d\n", get_IN_paper_number(in));
DBG (15, " ext send to: %d\n", get_IN_ext_send_to(in));
s->has_staple_detect = get_IN_staple_det(in);
DBG (15, " staple det: %d\n", s->has_staple_detect);
DBG (15, " pause host: %d\n", get_IN_pause_host(in));
DBG (15, " pause panel: %d\n", get_IN_pause_panel(in));
DBG (15, " pause conf: %d\n", get_IN_pause_conf(in));
DBG (15, " hq print: %d\n", get_IN_hq_print(in));
}
if (payload_off >= 0x71) {
DBG (15, " ext GHS len: %d\n", get_IN_ext_GHS_len(in));
}
if (payload_off >= 0x72) {
DBG (15, " smbc func: %d\n", get_IN_smbc_func(in));
DBG (15, " imprint chk b: %d\n", get_IN_imprint_chk_b(in));
DBG (15, " imprint chk f: %d\n", get_IN_imprint_chk_f(in));
DBG (15, " force w bg: %d\n", get_IN_force_w_bg(in));
s->has_df_recovery = get_IN_mf_recover_lvl(in);
DBG (15, " mf recover lvl: %d\n", s->has_df_recovery);
}
if (payload_off >= 0x73) {
DBG (15, " first read time: %d\n", get_IN_first_read_time(in));
DBG (15, " div scanning: %d\n", get_IN_div_scanning(in));
DBG (15, " start job: %d\n", get_IN_start_job(in));
DBG (15, " lifetime log: %d\n", get_IN_lifetime_log(in));
DBG (15, " imff save rest: %d\n", get_IN_imff_save_rest(in));
DBG (15, " wide scsi type: %d\n", get_IN_wide_scsi_type(in));
}
if (payload_off >= 0x74) {
DBG (15, " lut hybrid crop: %d\n", get_IN_lut_hybrid_crop(in));
DBG (15, " over under amt: %d\n", get_IN_over_under_amt(in));
DBG (15, " rgb lut: %d\n", get_IN_rgb_lut(in));
DBG (15, " num lut dl: %d\n", get_IN_num_lut_dl(in));
}
/* Various items below are poorly documented or missing */
if (payload_off >= 0x76) {
s->has_off_mode = get_IN_erp_lot6_supp(in);
DBG (15, " ErP Lot6 (power off timer): %d\n", s->has_off_mode);
DBG (15, " sync next feed: %d\n", get_IN_sync_next_feed(in));
}
if (payload_off >= 0x79) {
DBG (15, " battery: %d\n", get_IN_battery(in));
DBG (15, " battery save: %d\n", get_IN_battery_save(in));
DBG (15, " object position reverse: %d\n", get_IN_op_reverse(in));
}
if (payload_off >= 0x7a) {
s->has_op_halt = get_IN_op_halt(in);
DBG (15, " object position halt: %d\n", s->has_op_halt);
}
DBG (10, "init_vpd: finish\n");
return SANE_STATUS_GOOD;
}
static SANE_Status
init_ms(struct fujitsu *s)
{
int ret;
int oldDbg=0;
unsigned char cmd[MODE_SENSE_len];
size_t cmdLen = MODE_SENSE_len;
unsigned char in[MODE_SENSE_data_len];
size_t inLen = MODE_SENSE_data_len;
DBG (10, "init_ms: start\n");
if(!s->has_cmd_msen6){
DBG (10, "init_ms: unsupported\n");
return SANE_STATUS_GOOD;
}
/* some of the following probes will produce errors */
/* so we reduce the dbg level to reduce the noise */
/* however, if user builds with NDEBUG, we can't do that */
/* so we protect the code with the following macro */
IF_DBG( oldDbg=DBG_LEVEL; )
IF_DBG( if(DBG_LEVEL < 35){ DBG_LEVEL = 0; } )
memset(cmd,0,cmdLen);
set_SCSI_opcode(cmd, MODE_SENSE_code);
set_MSEN_xfer_length (cmd, inLen);
if(s->has_MS_autocolor){
DBG (35, "init_ms: autocolor\n");
set_MSEN_pc(cmd, MS_pc_autocolor);
ret = do_cmd (
s, 1, 0,
cmd, cmdLen,
NULL, 0,
in, &inLen
);
if(ret != SANE_STATUS_GOOD){
s->has_MS_autocolor=0;
}
}
if(s->has_MS_prepick){
DBG (35, "init_ms: prepick\n");
set_MSEN_pc(cmd, MS_pc_prepick);
inLen = MODE_SENSE_data_len;
ret = do_cmd (
s, 1, 0,
cmd, cmdLen,
NULL, 0,
in, &inLen
);
if(ret != SANE_STATUS_GOOD){
s->has_MS_prepick=0;
}
}
if(s->has_MS_sleep){
DBG (35, "init_ms: sleep\n");
set_MSEN_pc(cmd, MS_pc_sleep);
inLen = MODE_SENSE_data_len;
ret = do_cmd (
s, 1, 0,
cmd, cmdLen,
NULL, 0,
in, &inLen
);
if(ret != SANE_STATUS_GOOD){
s->has_MS_sleep=0;
}
}
if(s->has_MS_duplex){
DBG (35, "init_ms: duplex\n");
set_MSEN_pc(cmd, MS_pc_duplex);
inLen = MODE_SENSE_data_len;
ret = do_cmd (
s, 1, 0,
cmd, cmdLen,
NULL, 0,
in, &inLen
);
if(ret != SANE_STATUS_GOOD){
s->has_MS_duplex=0;
}
}
if(s->has_MS_rand){
DBG (35, "init_ms: rand\n");
set_MSEN_pc(cmd, MS_pc_rand);
inLen = MODE_SENSE_data_len;
ret = do_cmd (
s, 1, 0,
cmd, cmdLen,
NULL, 0,
in, &inLen
);
if(ret != SANE_STATUS_GOOD){
s->has_MS_rand=0;
}
}
if(s->has_MS_bg){
DBG (35, "init_ms: bg\n");
set_MSEN_pc(cmd, MS_pc_bg);
inLen = MODE_SENSE_data_len;
ret = do_cmd (
s, 1, 0,
cmd, cmdLen,
NULL, 0,
in, &inLen
);
if(ret != SANE_STATUS_GOOD){
s->has_MS_bg=0;
}
}
if(s->has_MS_df){
DBG (35, "init_ms: df\n");
set_MSEN_pc(cmd, MS_pc_df);
inLen = MODE_SENSE_data_len;
ret = do_cmd (
s, 1, 0,
cmd, cmdLen,
NULL, 0,
in, &inLen
);
if(ret != SANE_STATUS_GOOD){
s->has_MS_df=0;
}
}
if(s->has_MS_dropout){
DBG (35, "init_ms: dropout\n");
set_MSEN_pc(cmd, MS_pc_dropout);
inLen = MODE_SENSE_data_len;
ret = do_cmd (
s, 1, 0,
cmd, cmdLen,
NULL, 0,
in, &inLen
);
if(ret != SANE_STATUS_GOOD){
s->has_MS_dropout=0;
}
}
if(s->has_MS_buff){
DBG (35, "init_ms: buffer\n");
set_MSEN_pc(cmd, MS_pc_buff);
inLen = MODE_SENSE_data_len;
ret = do_cmd (
s, 1, 0,
cmd, cmdLen,
NULL, 0,
in, &inLen
);
if(ret != SANE_STATUS_GOOD){
s->has_MS_buff=0;
}
}
if(s->has_MS_auto){
DBG (35, "init_ms: auto\n");
set_MSEN_pc(cmd, MS_pc_auto);
inLen = MODE_SENSE_data_len;
ret = do_cmd (
s, 1, 0,
cmd, cmdLen,
NULL, 0,
in, &inLen
);
if(ret != SANE_STATUS_GOOD){
s->has_MS_auto=0;
}
}
if(s->has_MS_lamp){
DBG (35, "init_ms: lamp\n");
set_MSEN_pc(cmd, MS_pc_lamp);
inLen = MODE_SENSE_data_len;
ret = do_cmd (
s, 1, 0,
cmd, cmdLen,
NULL, 0,
in, &inLen
);
if(ret != SANE_STATUS_GOOD){
s->has_MS_lamp=0;
}
}
if(s->has_MS_jobsep){
DBG (35, "init_ms: jobsep\n");
set_MSEN_pc(cmd, MS_pc_jobsep);
inLen = MODE_SENSE_data_len;
ret = do_cmd (
s, 1, 0,
cmd, cmdLen,
NULL, 0,
in, &inLen
);
if(ret != SANE_STATUS_GOOD){
s->has_MS_jobsep=0;
}
}
IF_DBG (DBG_LEVEL = oldDbg;)
DBG (15, " autocolor: %d\n", s->has_MS_autocolor);
DBG (15, " prepick: %d\n", s->has_MS_prepick);
DBG (15, " sleep: %d\n", s->has_MS_sleep);
DBG (15, " duplex: %d\n", s->has_MS_duplex);
DBG (15, " rand: %d\n", s->has_MS_rand);
DBG (15, " bg: %d\n", s->has_MS_bg);
DBG (15, " df: %d\n", s->has_MS_df);
DBG (15, " dropout: %d\n", s->has_MS_dropout);
DBG (15, " buff: %d\n", s->has_MS_buff);
DBG (15, " auto: %d\n", s->has_MS_auto);
DBG (15, " lamp: %d\n", s->has_MS_lamp);
DBG (15, " jobsep: %d\n", s->has_MS_jobsep);
DBG (10, "init_ms: finish\n");
return SANE_STATUS_GOOD;
}
/*
* get model specific info that is not in vpd, and correct
* errors in vpd data. struct is already initialized to 0.
*/
static SANE_Status
init_model (struct fujitsu *s)
{
int i;
DBG (10, "init_model: start\n");
/* for most scanners these are good defaults */
if(s->can_mode[MODE_LINEART]
|| s->can_mode[MODE_HALFTONE]
|| s->can_mode[MODE_GRAYSCALE]
){
s->has_vuid_mono = 1;
}
if(s->can_mode[MODE_COLOR]){
s->has_vuid_color = 1;
}
for(i=MODE_HALFTONE;i<=MODE_COLOR;i++){
s->step_x_res[i] = s->step_x_res[MODE_LINEART];
s->step_y_res[i] = s->step_y_res[MODE_LINEART];
}
s->reverse_by_mode[MODE_LINEART] = 0;
s->reverse_by_mode[MODE_HALFTONE] = 0;
s->reverse_by_mode[MODE_GRAYSCALE] = 1;
s->reverse_by_mode[MODE_COLOR] = 1;
s->ppl_mod_by_mode[MODE_LINEART] = 8;
s->ppl_mod_by_mode[MODE_HALFTONE] = 8;
s->ppl_mod_by_mode[MODE_GRAYSCALE] = 1;
s->ppl_mod_by_mode[MODE_COLOR] = 1;
/* if scanner has built-in gamma tables, we use the first one (0) */
/* otherwise, we use the first downloaded one (0x80) */
/* note that you may NOT need to send the table to use it, */
/* the scanner will fall back to the brightness/contrast LUT */
if (!s->num_internal_gamma && s->num_download_gamma){
s->window_gamma = 0x80;
}
/* endorser type tells string length (among other things) */
if(s->has_endorser_b){
/*old-style is 40 bytes*/
if(s->endorser_type_b == ET_OLD){
s->endorser_string_len = 40;
}
/*short new style is 60 bytes*/
else if(s->endorser_type_b == ET_30){
s->endorser_string_len = 60;
}
/*long new style is 80 bytes*/
else if(s->endorser_type_b == ET_40){
s->endorser_string_len = 80;
}
}
else if(s->has_endorser_f){
/*old-style is 40 bytes*/
if(s->endorser_type_f == ET_OLD){
s->endorser_string_len = 40;
}
/*short new style is 60 bytes*/
else if(s->endorser_type_f == ET_30){
s->endorser_string_len = 60;
}
/*long new style is 80 bytes*/
else if(s->endorser_type_f == ET_40){
s->endorser_string_len = 80;
}
}
/* convert to 1200dpi units */
s->max_x = s->max_x_basic * 1200 / s->basic_x_res;
s->max_y = s->max_y_basic * 1200 / s->basic_y_res;
/* setup the list with a single choice, in 1200dpi units, at max res */
s->max_y_by_res[0].res = s->max_y_res;
s->max_y_by_res[0].len = s->max_y;
/* assume these are same as adf, override below */
s->max_x_fb = s->max_x;
s->max_y_fb = s->max_y;
/* assume we can do these. we will disable
* them at runtime if they cannot */
s->has_pixelsize = 1;
s->has_MS_autocolor = 1;
s->has_MS_prepick = 1;
s->has_MS_sleep = 1;
s->has_MS_duplex = 1;
s->has_MS_rand = 1;
s->has_MS_bg = 1;
s->has_MS_df = 1;
s->has_MS_dropout = 1;
s->has_MS_buff = 1;
s->has_MS_auto = 1;
s->has_MS_lamp = 1;
s->has_MS_jobsep = 1;
/* these two scanners lie about their capabilities,
* and/or differ significantly from most other models */
if (strstr (s->model_name, "M3091")
|| strstr (s->model_name, "M3092")) {
/* lies */
s->has_rif = 1;
s->has_back = 0;
s->adbits = 8;
if (strstr (s->model_name, "M3092"))
s->has_flatbed = 1;
/*actually does have res range in non-color modes */
for(i=MODE_LINEART;i<MODE_COLOR;i++){
s->step_x_res[i] = 1;
s->step_y_res[i] = 1;
}
/*but the color mode y list is very limited, only 75, 150, 300 (and 600)*/
for(i=0;i<16;i++){
s->std_res[i] = 0;
}
s->std_res[1] = 1;
s->std_res[4] = 1;
s->std_res[9] = 1;
/* weirdness */
s->has_vuid_3091 = 1;
s->has_vuid_color = 0;
s->has_vuid_mono = 0;
s->has_short_pixelsize = 1;
s->color_interlace = COLOR_INTERLACE_3091;
s->duplex_interlace = DUPLEX_INTERLACE_3091;
s->ghs_in_rs = 1;
s->window_gamma = 0;
s->reverse_by_mode[MODE_LINEART] = 1;
s->reverse_by_mode[MODE_HALFTONE] = 1;
s->reverse_by_mode[MODE_GRAYSCALE] = 0;
s->reverse_by_mode[MODE_COLOR] = 0;
}
else if (strstr (s->model_name, "M3093")){
/* lies */
s->has_back = 0;
s->adbits = 8;
/* weirdness */
s->duplex_interlace = DUPLEX_INTERLACE_NONE;
}
else if ( strstr (s->model_name, "M309")
|| strstr (s->model_name, "M409")){
/* weirdness */
s->broken_diag_serial = 1;
/* lies */
s->adbits = 8;
}
else if (strstr (s->model_name, "fi-4120C2")
|| strstr (s->model_name, "fi-4220C2") ) {
/* missing from vpd */
s->os_x_basic = 118;
s->os_y_basic = 118;
s->max_y_fb = 14032;
}
else if (strstr (s->model_name, "fi-4220C")){
/* missing from vpd */
s->max_y_fb = 14032;
}
else if (strstr (s->model_name,"fi-4340")
|| strstr (s->model_name, "fi-4750") ) {
/* weirdness */
s->broken_diag_serial = 1;
}
/* some firmware versions use capital f? */
else if (strstr (s->model_name, "Fi-4860")
|| strstr (s->model_name, "fi-4860") ) {
/* weirdness */
s->broken_diag_serial = 1;
s->ppl_mod_by_mode[MODE_LINEART] = 32;
s->ppl_mod_by_mode[MODE_HALFTONE] = 32;
s->ppl_mod_by_mode[MODE_GRAYSCALE] = 4;
s->ppl_mod_by_mode[MODE_COLOR] = 4;
}
/* some firmware versions use capital f? */
else if (strstr (s->model_name, "Fi-4990")
|| strstr (s->model_name, "fi-4990") ) {
/* weirdness */
s->duplex_interlace = DUPLEX_INTERLACE_NONE;
s->color_interlace = COLOR_INTERLACE_RRGGBB;
s->ppl_mod_by_mode[MODE_LINEART] = 32;
s->ppl_mod_by_mode[MODE_HALFTONE] = 32;
s->ppl_mod_by_mode[MODE_GRAYSCALE] = 4;
s->ppl_mod_by_mode[MODE_COLOR] = 4;
}
else if (strstr (s->model_name,"fi-5110C")){
/* missing from vpd */
s->os_x_basic = 147;
s->os_y_basic = 147;
}
else if (strstr (s->model_name,"fi-5110EOX")){
/* weirdness */
s->cropping_mode = CROP_ABSOLUTE;
}
else if (strstr (s->model_name,"fi-5220C")){
/* missing from vpd */
s->max_x_fb = 10764;
s->max_y_fb = 14032;
}
else if (strstr (s->model_name,"fi-5530")
|| strstr (s->model_name,"fi-5650")
|| strstr (s->model_name,"fi-5750")){
/* lies - usb only */
if(s->connection == CONNECTION_USB)
s->adbits = 8;
}
else if (strstr (s->model_name,"S1500")){
/*lies*/
s->has_MS_bg=0;
s->has_MS_prepick=0;
}
/* also includes the 'Z' models */
else if (strstr (s->model_name,"fi-6130")
|| strstr (s->model_name,"fi-6140")){
/* weirdness */
/* these machines have longer max paper at lower res */
s->max_y_by_res[1].res = 200;
s->max_y_by_res[1].len = 151512;
}
/* also includes the 'Z' models */
else if (strstr (s->model_name,"fi-6230")
|| strstr (s->model_name,"fi-6240")){
/* weirdness */
/* these machines have longer max paper at lower res */
s->max_y_by_res[1].res = 200;
s->max_y_by_res[1].len = 151512;
/* missing from vpd */
s->max_x_fb = 10764; /* was previously 10488 */
s->max_y_fb = 14032; /* some scanners can be slightly more? */
}
else if (strstr (s->model_name,"fi-6110")){
/* weirdness */
/* these machines have longer max paper at lower res */
s->max_y_by_res[1].res = 200;
s->max_y_by_res[1].len = 151512;
/*lies*/
s->has_MS_bg=0;
s->has_MS_prepick=0;
}
else if (strstr (s->model_name,"fi-6800")
|| strstr (s->model_name,"fi-5900")){
/* do not need overrides */
}
else if (strstr (s->model_name,"iX500")){
/* locks up scanner if we try to auto detect */
s->has_MS_lamp = 0;
/* weirdness */
s->need_q_table = 1;
s->late_lut = 1;
s->need_diag_preread = 1;
s->ppl_mod_by_mode[MODE_COLOR] = 2;
s->hopper_before_op = 1;
s->no_wait_after_op = 1;
/* lies */
s->adbits = 8;
/* we have to simulate these in software*/
s->can_mode[MODE_LINEART] = 2;
s->can_mode[MODE_GRAYSCALE] = 2;
/* dont bother with this one */
s->can_mode[MODE_HALFTONE] = 0;
}
/*mostly copied from iX500*/
else if (strstr (s->model_name,"iX100")){
/* locks up scanner if we try to auto detect */
s->has_MS_lamp = 0;
/* weirdness */
s->need_q_table = 1;
s->late_lut = 1;
s->need_diag_preread = 1;
s->ppl_mod_by_mode[MODE_COLOR] = 2;
s->hopper_before_op = 1;
s->no_wait_after_op = 1;
/* lies */
s->adbits = 8;
/* dont bother with this one */
s->can_mode[MODE_HALFTONE] = 0;
}
else if (strstr (s->model_name,"fi-7180")
|| strstr (s->model_name,"fi-7160")){
/* locks up scanner if we try to auto detect */
s->has_MS_lamp = 0;
/* weirdness */
/* these machines have longer max paper at lower res */
s->max_y_by_res[1].res = 400;
s->max_y_by_res[1].len = 194268;
s->max_y_by_res[2].res = 300;
s->max_y_by_res[2].len = 260268;
s->max_y_by_res[3].res = 200;
s->max_y_by_res[3].len = 266268;
}
else if (strstr (s->model_name,"fi-7280")
|| strstr (s->model_name,"fi-7260")){
/* weirdness */
/* these machines have longer max paper at lower res */
s->max_y_by_res[1].res = 400;
s->max_y_by_res[1].len = 194268;
s->max_y_by_res[2].res = 300;
s->max_y_by_res[2].len = 260268;
s->max_y_by_res[3].res = 200;
s->max_y_by_res[3].len = 266268;
/* missing from vpd */
s->max_x_fb = 10764;
s->max_y_fb = 14032; /* some scanners can be slightly more? */
}
else if (strstr (s->model_name,"fi-7480")
|| strstr (s->model_name,"fi-7460")){
/* weirdness */
/* these machines have longer max paper at lower res */
s->max_y_by_res[1].res = 400;
s->max_y_by_res[1].len = 194268;
s->max_y_by_res[2].res = 300;
s->max_y_by_res[2].len = 260268;
s->max_y_by_res[3].res = 200;
s->max_y_by_res[3].len = 266268;
}
else if (strstr (s->model_name,"fi-7030")){
/* weirdness */
/* these machines have longer max paper at lower res */
s->max_y_by_res[1].res = 400;
s->max_y_by_res[1].len = 192000;
s->max_y_by_res[2].res = 300;
s->max_y_by_res[2].len = 258000;
s->max_y_by_res[3].res = 200;
s->max_y_by_res[3].len = 264000;
}
else if (strstr (s->model_name,"fi-7700")
|| strstr (s->model_name,"fi-7600")){
/* weirdness */
/* these machines have longer max paper at lower res */
s->max_y_by_res[1].res = 400;
s->max_y_by_res[1].len = 192000;
s->max_y_by_res[2].res = 300;
s->max_y_by_res[2].len = 258000;
s->max_y_by_res[3].res = 200;
s->max_y_by_res[3].len = 264000;
}
DBG (10, "init_model: finish\n");
return SANE_STATUS_GOOD;
}
static SANE_Status
set_mode (struct fujitsu *s, int mode)
{
int i;
/* give the user what they asked for */
s->u_mode = mode;
/* give the scanner the closest mode */
for(i=MODE_COLOR;i>=mode;i--){
if(s->can_mode[i] == 1){
s->s_mode = i;
}
}
return SANE_STATUS_GOOD;
}
/*
* set good default user values.
* struct is already initialized to 0.
*/
static SANE_Status
init_user (struct fujitsu *s)
{
DBG (10, "init_user: start\n");
/* source */
if(s->has_flatbed)
s->source = SOURCE_FLATBED;
else if(s->has_adf)
s->source = SOURCE_ADF_FRONT;
/* scan mode */
if(s->can_mode[MODE_LINEART])
set_mode(s,MODE_LINEART);
else if(s->can_mode[MODE_HALFTONE])
set_mode(s,MODE_HALFTONE);
else if(s->can_mode[MODE_GRAYSCALE])
set_mode(s,MODE_GRAYSCALE);
else if(s->can_mode[MODE_COLOR])
set_mode(s,MODE_COLOR);
/*x res*/
s->resolution_x = s->basic_x_res;
/*y res*/
s->resolution_y = s->basic_y_res;
if(s->resolution_y > s->resolution_x){
s->resolution_y = s->resolution_x;
}
/* page width US-Letter */
s->page_width = 8.5 * 1200;
if(s->page_width > s->max_x){
s->page_width = s->max_x;
}
/* page height US-Letter */
s->page_height = 11 * 1200;
set_max_y(s);
if(s->page_height > s->max_y){
s->page_height = s->max_y;
}
/* bottom-right x */
s->br_x = s->page_width;
/* bottom-right y */
s->br_y = s->page_height;
/* gamma ramp exponent */
s->gamma = 1;
/* safe endorser settings */
s->u_endorser_bits=16;
s->u_endorser_step=1;
s->u_endorser_side=ED_back;
if(s->has_endorser_f){
s->u_endorser_side=ED_front;
}
s->u_endorser_dir=DIR_TTB;
strcpy((char *)s->u_endorser_string,"%05ud");
/* more recent machines default to this being 'on', *
* which causes the scanner to ingest multiple pages *
* even when the user only wants one */
s->buff_mode = MSEL_OFF;
/* useful features of newer scanners which we turn on,
* even though the scanner defaults to off */
if(s->has_paper_protect){
s->paper_protect = MSEL_ON;
}
if(s->has_staple_detect){
s->staple_detect = MSEL_ON;
}
if(s->has_df_recovery){
s->df_recovery = MSEL_ON;
}
if(s->has_adv_paper_prot){
s->adv_paper_prot = MSEL_ON;
}
s->off_time = 240;
DBG (10, "init_user: finish\n");
return SANE_STATUS_GOOD;
}
/*
* This function presets the "option" array to blank
*/
static SANE_Status
init_options (struct fujitsu *s)
{
int i;
DBG (10, "init_options: start\n");
memset (s->opt, 0, sizeof (s->opt));
for (i = 0; i < NUM_OPTIONS; ++i) {
s->opt[i].name = "filler";
s->opt[i].size = sizeof (SANE_Word);
s->opt[i].cap = SANE_CAP_INACTIVE;
}
/* go ahead and setup the first opt, because
* frontend may call control_option on it
* before calling get_option_descriptor
*/
s->opt[OPT_NUM_OPTS].name = SANE_NAME_NUM_OPTIONS;
s->opt[OPT_NUM_OPTS].title = SANE_TITLE_NUM_OPTIONS;
s->opt[OPT_NUM_OPTS].desc = SANE_DESC_NUM_OPTIONS;
s->opt[OPT_NUM_OPTS].type = SANE_TYPE_INT;
s->opt[OPT_NUM_OPTS].cap = SANE_CAP_SOFT_DETECT;
DBG (10, "init_options: finish\n");
return SANE_STATUS_GOOD;
}
/*
* send set window repeatedly to color scanners,
* searching for valid color interlacing mode
*/
static SANE_Status
init_interlace (struct fujitsu *s)
{
SANE_Status ret = SANE_STATUS_GOOD;
int curr_mode = s->u_mode;
int oldDbg=0;
DBG (10, "init_interlace: start\n");
if(s->color_interlace != COLOR_INTERLACE_UNK){
DBG (10, "init_interlace: already loaded\n");
return SANE_STATUS_GOOD;
}
if(!s->has_vuid_color){
DBG (10, "init_interlace: color unsupported\n");
return SANE_STATUS_GOOD;
}
/* set to color mode first */
set_mode(s,MODE_COLOR);
/* load our own private copy of scan params */
ret = update_params(s);
if (ret != SANE_STATUS_GOOD) {
DBG (5, "init_interlace: ERROR: cannot update params\n");
return ret;
}
/*loop thru all the formats we support*/
for(s->color_interlace = COLOR_INTERLACE_RGB;
s->color_interlace <= COLOR_INTERLACE_RRGGBB;
s->color_interlace++){
/* some of the following probes will produce errors */
/* so we reduce the dbg level to reduce the noise */
/* however, if user builds with NDEBUG, we can't do that */
/* so we protect the code with the following macro */
IF_DBG( oldDbg=DBG_LEVEL; )
IF_DBG( if(DBG_LEVEL < 35){ DBG_LEVEL = 0; } )
ret = set_window(s);
IF_DBG (DBG_LEVEL = oldDbg;)
if (ret == SANE_STATUS_GOOD){
break;
}
else{
DBG (15, "init_interlace: not %d\n", s->color_interlace);
}
}
if (ret != SANE_STATUS_GOOD){
DBG (5, "init_interlace: no valid interlacings\n");
return SANE_STATUS_INVAL;
}
DBG (15, "init_interlace: color_interlace: %d\n",s->color_interlace);
/* restore mode */
set_mode(s,curr_mode);
DBG (10, "init_interlace: finish\n");
return SANE_STATUS_GOOD;
}
/*
* send diag query for serial number, and read result back
* use it to build a unique name for scanner in s->serial_name
*/
static SANE_Status
init_serial (struct fujitsu *s)
{
SANE_Status ret = SANE_STATUS_GOOD;
unsigned int sn = 0;
unsigned char cmd[SEND_DIAGNOSTIC_len]; /*also big enough for READ_DIAG*/
size_t cmdLen = SEND_DIAGNOSTIC_len;
unsigned char out[SD_gdi_len];
size_t outLen = SD_gdi_len;
unsigned char in[RD_gdi_len];
size_t inLen = RD_gdi_len;
DBG (10, "init_serial: start\n");
if (!s->has_cmd_sdiag || !s->has_cmd_rdiag || s->broken_diag_serial){
DBG (5, "init_serial: send/read diag not supported, returning\n");
return SANE_STATUS_INVAL;
}
memset(cmd,0,cmdLen);
set_SCSI_opcode(cmd, SEND_DIAGNOSTIC_code);
set_SD_slftst(cmd, 0);
set_SD_xferlen(cmd, outLen);
memcpy(out,SD_gdi_string,outLen);
ret = do_cmd (
s, 1, 0,
cmd, cmdLen,
out, outLen,
NULL, NULL
);
if (ret != SANE_STATUS_GOOD){
DBG (5, "init_serial: send diag error: %d\n", ret);
return ret;
}
memset(cmd,0,cmdLen);
set_SCSI_opcode(cmd, READ_DIAGNOSTIC_code);
set_RD_xferlen(cmd, inLen);
ret = do_cmd (
s, 1, 0,
cmd, cmdLen,
NULL, 0,
in, &inLen
);
if (ret != SANE_STATUS_GOOD){
DBG (5, "init_serial: read diag error: %d\n", ret);
return ret;
}
sn = get_RD_id_serial(in);
DBG (15, "init_serial: found sn %d\n",sn);
sprintf(s->serial_name, "%s:%d", s->model_name, sn);
DBG (15, "init_serial: serial_name: %s\n",s->serial_name);
DBG (10, "init_serial: finish\n");
return SANE_STATUS_GOOD;
}
/*
* From the SANE spec:
* This function is used to establish a connection to a particular
* device. The name of the device to be opened is passed in argument
* name. If the call completes successfully, a handle for the device
* is returned in *h. As a special case, specifying a zero-length
* string as the device requests opening the first available device
* (if there is such a device).
*/
SANE_Status
sane_open (SANE_String_Const name, SANE_Handle * handle)
{
struct fujitsu *dev = NULL;
struct fujitsu *s = NULL;
SANE_Status ret;
DBG (10, "sane_open: start\n");
if(fujitsu_devList){
DBG (15, "sane_open: searching currently attached scanners\n");
}
else{
DBG (15, "sane_open: no scanners currently attached, attaching\n");
ret = sane_get_devices(NULL,0);
if(ret != SANE_STATUS_GOOD){
return ret;
}
}
if(!name || !name[0]){
DBG (15, "sane_open: no device requested, using default\n");
s = fujitsu_devList;
}
else{
DBG (15, "sane_open: device %s requested\n", name);
for (dev = fujitsu_devList; dev; dev = dev->next) {
if (strcmp (dev->sane.name, name) == 0
|| strcmp (dev->device_name, name) == 0) { /*always allow sanei devname*/
s = dev;
break;
}
}
}
if (!s) {
DBG (5, "sane_open: no device found\n");
return SANE_STATUS_INVAL;
}
DBG (15, "sane_open: device %s found\n", s->sane.name);
*handle = s;
/* connect the fd so we can talk to scanner */
ret = connect_fd(s);
if(ret != SANE_STATUS_GOOD){
return ret;
}
DBG (10, "sane_open: finish\n");
return SANE_STATUS_GOOD;
}
/*
* @@ Section 3 - SANE Options functions
*/
/*
* Returns the options we know.
*
* From the SANE spec:
* This function is used to access option descriptors. The function
* returns the option descriptor for option number n of the device
* represented by handle h. Option number 0 is guaranteed to be a
* valid option. Its value is an integer that specifies the number of
* options that are available for device handle h (the count includes
* option 0). If n is not a valid option index, the function returns
* NULL. The returned option descriptor is guaranteed to remain valid
* (and at the returned address) until the device is closed.
*/
const SANE_Option_Descriptor *
sane_get_option_descriptor (SANE_Handle handle, SANE_Int option)
{
struct fujitsu *s = handle;
int i,j;
SANE_Option_Descriptor *opt = &s->opt[option];
DBG (20, "sane_get_option_descriptor: %d\n", option);
if ((unsigned) option >= NUM_OPTIONS)
return NULL;
/* "Mode" group -------------------------------------------------------- */
if(option==OPT_STANDARD_GROUP){
opt->name = SANE_NAME_STANDARD;
opt->title = SANE_TITLE_STANDARD;
opt->desc = SANE_DESC_STANDARD;
opt->type = SANE_TYPE_GROUP;
opt->constraint_type = SANE_CONSTRAINT_NONE;
}
/* source */
if(option==OPT_SOURCE){
i=0;
if(s->has_flatbed){
s->source_list[i++]=STRING_FLATBED;
}
if(s->has_adf){
s->source_list[i++]=STRING_ADFFRONT;
if(s->has_back){
s->source_list[i++]=STRING_ADFBACK;
}
if(s->has_duplex){
s->source_list[i++]=STRING_ADFDUPLEX;
}
}
s->source_list[i]=NULL;
opt->name = SANE_NAME_SCAN_SOURCE;
opt->title = SANE_TITLE_SCAN_SOURCE;
opt->desc = SANE_DESC_SCAN_SOURCE;
opt->type = SANE_TYPE_STRING;
opt->constraint_type = SANE_CONSTRAINT_STRING_LIST;
opt->constraint.string_list = s->source_list;
opt->size = maxStringSize (opt->constraint.string_list);
opt->cap = SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT;
}
/* scan mode */
if(option==OPT_MODE){
i=0;
if(s->can_mode[MODE_LINEART]){
s->mode_list[i++]=STRING_LINEART;
}
if(s->can_mode[MODE_HALFTONE]){
s->mode_list[i++]=STRING_HALFTONE;
}
if(s->can_mode[MODE_GRAYSCALE]){
s->mode_list[i++]=STRING_GRAYSCALE;
}
if(s->can_mode[MODE_COLOR]){
s->mode_list[i++]=STRING_COLOR;
}
s->mode_list[i]=NULL;
opt->name = SANE_NAME_SCAN_MODE;
opt->title = SANE_TITLE_SCAN_MODE;
opt->desc = SANE_DESC_SCAN_MODE;
opt->type = SANE_TYPE_STRING;
opt->constraint_type = SANE_CONSTRAINT_STRING_LIST;
opt->constraint.string_list = s->mode_list;
opt->size = maxStringSize (opt->constraint.string_list);
opt->cap = SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT;
}
/* resolution */
/* some scanners only support fixed res
* build a list of possible choices */
if(option==OPT_RES){
opt->name = SANE_NAME_SCAN_RESOLUTION;
opt->title = SANE_TITLE_SCAN_RESOLUTION;
opt->desc = SANE_DESC_SCAN_RESOLUTION;
opt->type = SANE_TYPE_INT;
opt->unit = SANE_UNIT_DPI;
opt->cap = SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT;
if(s->step_x_res[s->s_mode] && s->step_y_res[s->s_mode]){
s->res_range.min = s->min_x_res;
s->res_range.max = s->max_x_res;
s->res_range.quant = s->step_x_res[s->s_mode];
opt->constraint_type = SANE_CONSTRAINT_RANGE;
opt->constraint.range = &s->res_range;
}
else{
int reses[]
= {60,75,100,120,150,160,180,200,240,300,320,400,480,600,800,1200};
i=0;
for(j=0;j<16;j++){
if(s->std_res[j]
&& s->max_x_res >= reses[j] && s->min_x_res <= reses[j]
&& s->max_y_res >= reses[j] && s->min_y_res <= reses[j]
){
s->res_list[++i] = reses[j];
}
}
s->res_list[0] = i;
opt->constraint_type = SANE_CONSTRAINT_WORD_LIST;
opt->constraint.word_list = s->res_list;
}
}
/* "Geometry" group ---------------------------------------------------- */
if(option==OPT_GEOMETRY_GROUP){
opt->name = SANE_NAME_GEOMETRY;
opt->title = SANE_TITLE_GEOMETRY;
opt->desc = SANE_DESC_GEOMETRY;
opt->type = SANE_TYPE_GROUP;
opt->constraint_type = SANE_CONSTRAINT_NONE;
}
/* top-left x */
if(option==OPT_TL_X){
/* values stored in 1200 dpi units */
/* must be converted to MM for sane */
s->tl_x_range.min = SCANNER_UNIT_TO_FIXED_MM(s->min_x);
s->tl_x_range.max = SCANNER_UNIT_TO_FIXED_MM(get_page_width(s));
s->tl_x_range.quant = MM_PER_UNIT_FIX;
opt->name = SANE_NAME_SCAN_TL_X;
opt->title = SANE_TITLE_SCAN_TL_X;
opt->desc = SANE_DESC_SCAN_TL_X;
opt->type = SANE_TYPE_FIXED;
opt->unit = SANE_UNIT_MM;
opt->constraint_type = SANE_CONSTRAINT_RANGE;
opt->constraint.range = &(s->tl_x_range);
opt->cap = SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT;
}
/* top-left y */
if(option==OPT_TL_Y){
/* values stored in 1200 dpi units */
/* must be converted to MM for sane */
s->tl_y_range.min = SCANNER_UNIT_TO_FIXED_MM(s->min_y);
s->tl_y_range.max = SCANNER_UNIT_TO_FIXED_MM(get_page_height(s));
s->tl_y_range.quant = MM_PER_UNIT_FIX;
opt->name = SANE_NAME_SCAN_TL_Y;
opt->title = SANE_TITLE_SCAN_TL_Y;
opt->desc = SANE_DESC_SCAN_TL_Y;
opt->type = SANE_TYPE_FIXED;
opt->unit = SANE_UNIT_MM;
opt->constraint_type = SANE_CONSTRAINT_RANGE;
opt->constraint.range = &(s->tl_y_range);
opt->cap = SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT;
}
/* bottom-right x */
if(option==OPT_BR_X){
/* values stored in 1200 dpi units */
/* must be converted to MM for sane */
s->br_x_range.min = SCANNER_UNIT_TO_FIXED_MM(s->min_x);
s->br_x_range.max = SCANNER_UNIT_TO_FIXED_MM(get_page_width(s));
s->br_x_range.quant = MM_PER_UNIT_FIX;
opt->name = SANE_NAME_SCAN_BR_X;
opt->title = SANE_TITLE_SCAN_BR_X;
opt->desc = SANE_DESC_SCAN_BR_X;
opt->type = SANE_TYPE_FIXED;
opt->unit = SANE_UNIT_MM;
opt->constraint_type = SANE_CONSTRAINT_RANGE;
opt->constraint.range = &(s->br_x_range);
opt->cap = SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT;
}
/* bottom-right y */
if(option==OPT_BR_Y){
/* values stored in 1200 dpi units */
/* must be converted to MM for sane */
s->br_y_range.min = SCANNER_UNIT_TO_FIXED_MM(s->min_y);
s->br_y_range.max = SCANNER_UNIT_TO_FIXED_MM(get_page_height(s));
s->br_y_range.quant = MM_PER_UNIT_FIX;
opt->name = SANE_NAME_SCAN_BR_Y;
opt->title = SANE_TITLE_SCAN_BR_Y;
opt->desc = SANE_DESC_SCAN_BR_Y;
opt->type = SANE_TYPE_FIXED;
opt->unit = SANE_UNIT_MM;
opt->constraint_type = SANE_CONSTRAINT_RANGE;
opt->constraint.range = &(s->br_y_range);
opt->cap = SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT;
}
/* page width */
if(option==OPT_PAGE_WIDTH){
/* values stored in 1200 dpi units */
/* must be converted to MM for sane */
s->paper_x_range.min = SCANNER_UNIT_TO_FIXED_MM(s->min_x);
s->paper_x_range.max = SCANNER_UNIT_TO_FIXED_MM(s->max_x);
s->paper_x_range.quant = MM_PER_UNIT_FIX;
opt->name = SANE_NAME_PAGE_WIDTH;
opt->title = SANE_TITLE_PAGE_WIDTH;
opt->desc = SANE_DESC_PAGE_WIDTH;
opt->type = SANE_TYPE_FIXED;
opt->unit = SANE_UNIT_MM;
opt->constraint_type = SANE_CONSTRAINT_RANGE;
opt->constraint.range = &s->paper_x_range;
if(s->has_adf){
opt->cap = SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT;
if(s->source == SOURCE_FLATBED){
opt->cap |= SANE_CAP_INACTIVE;
}
}
else{
opt->cap = SANE_CAP_INACTIVE;
}
}
/* page height */
if(option==OPT_PAGE_HEIGHT){
/* values stored in 1200 dpi units */
/* must be converted to MM for sane */
s->paper_y_range.min = SCANNER_UNIT_TO_FIXED_MM(s->min_y);
s->paper_y_range.max = SCANNER_UNIT_TO_FIXED_MM(s->max_y);
s->paper_y_range.quant = MM_PER_UNIT_FIX;
opt->name = SANE_NAME_PAGE_HEIGHT;
opt->title = SANE_TITLE_PAGE_HEIGHT;
opt->desc = SANE_DESC_PAGE_HEIGHT;
opt->type = SANE_TYPE_FIXED;
opt->unit = SANE_UNIT_MM;
opt->constraint_type = SANE_CONSTRAINT_RANGE;
opt->constraint.range = &s->paper_y_range;
if(s->has_adf){
opt->cap = SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT;
if(s->source == SOURCE_FLATBED){
opt->cap |= SANE_CAP_INACTIVE;
}
}
else{
opt->cap = SANE_CAP_INACTIVE;
}
}
/* "Enhancement" group ------------------------------------------------- */
if(option==OPT_ENHANCEMENT_GROUP){
opt->name = SANE_NAME_ENHANCEMENT;
opt->title = SANE_TITLE_ENHANCEMENT;
opt->desc = SANE_DESC_ENHANCEMENT;
opt->type = SANE_TYPE_GROUP;
opt->constraint_type = SANE_CONSTRAINT_NONE;
}
/* brightness */
if(option==OPT_BRIGHTNESS){
opt->name = SANE_NAME_BRIGHTNESS;
opt->title = SANE_TITLE_BRIGHTNESS;
opt->desc = SANE_DESC_BRIGHTNESS;
opt->type = SANE_TYPE_INT;
opt->unit = SANE_UNIT_NONE;
opt->constraint_type = SANE_CONSTRAINT_RANGE;
opt->constraint.range = &s->brightness_range;
s->brightness_range.quant=1;
/* some have hardware brightness (always 0 to 255?) */
/* some use LUT or GT (-127 to +127)*/
if (s->brightness_steps || s->num_download_gamma){
s->brightness_range.min=-127;
s->brightness_range.max=127;
opt->cap = SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT;
}
else{
opt->cap = SANE_CAP_INACTIVE;
}
}
/* contrast */
if(option==OPT_CONTRAST){
opt->name = SANE_NAME_CONTRAST;
opt->title = SANE_TITLE_CONTRAST;
opt->desc = SANE_DESC_CONTRAST;
opt->type = SANE_TYPE_INT;
opt->unit = SANE_UNIT_NONE;
opt->constraint_type = SANE_CONSTRAINT_RANGE;
opt->constraint.range = &s->contrast_range;
s->contrast_range.quant=1;
/* some have hardware contrast (always 0 to 255?) */
/* some use LUT or GT (-127 to +127)*/
if (s->contrast_steps || s->num_download_gamma){
s->contrast_range.min=-127;
s->contrast_range.max=127;
opt->cap = SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT;
}
else {
opt->cap = SANE_CAP_INACTIVE;
}
}
/* gamma */
if(option==OPT_GAMMA){
opt->name = "gamma";
opt->title = SANE_I18N ("Gamma function exponent");
opt->desc = SANE_I18N ("Changes intensity of midtones");
opt->type = SANE_TYPE_FIXED;
opt->unit = SANE_UNIT_NONE;
opt->constraint_type = SANE_CONSTRAINT_RANGE;
opt->constraint.range = &s->gamma_range;
/* value ranges from .3 to 5, should be log scale? */
s->gamma_range.quant=SANE_FIX(0.01);
s->gamma_range.min=SANE_FIX(0.3);
s->gamma_range.max=SANE_FIX(5);
/* scanner has gamma via LUT or GT */
/*if (s->num_download_gamma){
opt->cap = SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT;
}
else {
opt->cap = SANE_CAP_INACTIVE;
}*/
opt->cap = SANE_CAP_INACTIVE;
}
/*threshold*/
if(option==OPT_THRESHOLD){
opt->name = SANE_NAME_THRESHOLD;
opt->title = SANE_TITLE_THRESHOLD;
opt->desc = SANE_DESC_THRESHOLD;
opt->type = SANE_TYPE_INT;
opt->unit = SANE_UNIT_NONE;
opt->constraint_type = SANE_CONSTRAINT_RANGE;
opt->constraint.range = &s->threshold_range;
s->threshold_range.min=0;
s->threshold_range.max=s->threshold_steps;
s->threshold_range.quant=1;
if (s->threshold_steps){
opt->cap = SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT;
if(s->u_mode != MODE_LINEART){
opt->cap |= SANE_CAP_INACTIVE;
}
}
else {
opt->cap = SANE_CAP_INACTIVE;
}
}
/* =============== common ipc params ================================ */
if(option==OPT_RIF){
opt->name = "rif";
opt->title = SANE_I18N ("RIF");
opt->desc = SANE_I18N ("Reverse image format");
opt->type = SANE_TYPE_BOOL;
opt->unit = SANE_UNIT_NONE;
if (s->has_rif)
opt->cap = SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT;
else
opt->cap = SANE_CAP_INACTIVE;
}
if(option==OPT_HT_TYPE){
i=0;
s->ht_type_list[i++]=STRING_DEFAULT;
s->ht_type_list[i++]=STRING_DITHER;
s->ht_type_list[i++]=STRING_DIFFUSION;
s->ht_type_list[i]=NULL;
opt->name = "ht-type";
opt->title = SANE_I18N ("Halftone type");
opt->desc = SANE_I18N ("Control type of halftone filter");
opt->type = SANE_TYPE_STRING;
opt->unit = SANE_UNIT_NONE;
opt->constraint_type = SANE_CONSTRAINT_STRING_LIST;
opt->constraint.string_list = s->ht_type_list;
opt->size = maxStringSize (opt->constraint.string_list);
if(s->has_diffusion){
opt->cap = SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT;
if(s->s_mode != MODE_HALFTONE){
opt->cap |= SANE_CAP_INACTIVE;
}
}
else
opt->cap = SANE_CAP_INACTIVE;
}
if(option==OPT_HT_PATTERN){
opt->name = "ht-pattern";
opt->title = SANE_I18N ("Halftone pattern");
opt->desc = SANE_I18N ("Control pattern of halftone filter");
opt->type = SANE_TYPE_INT;
opt->unit = SANE_UNIT_NONE;
opt->constraint_type = SANE_CONSTRAINT_RANGE;
opt->constraint.range = &s->ht_pattern_range;
s->ht_pattern_range.min=0;
s->ht_pattern_range.max=s->num_internal_dither - 1;
s->ht_pattern_range.quant=1;
if (s->num_internal_dither){
opt->cap = SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT;
if(s->s_mode != MODE_HALFTONE){
opt->cap |= SANE_CAP_INACTIVE;
}
}
else
opt->cap = SANE_CAP_INACTIVE;
}
if(option==OPT_OUTLINE){
opt->name = "outline";
opt->title = SANE_I18N ("Outline");
opt->desc = SANE_I18N ("Perform outline extraction");
opt->type = SANE_TYPE_BOOL;
opt->unit = SANE_UNIT_NONE;
if (s->has_outline)
opt->cap = SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT;
else
opt->cap = SANE_CAP_INACTIVE;
}
if(option==OPT_EMPHASIS){
opt->name = "emphasis";
opt->title = SANE_I18N ("Emphasis");
opt->desc = SANE_I18N ("Negative to smooth or positive to sharpen image");
opt->type = SANE_TYPE_INT;
opt->unit = SANE_UNIT_NONE;
opt->constraint_type = SANE_CONSTRAINT_RANGE;
opt->constraint.range = &s->emphasis_range;
s->emphasis_range.min=-128;
s->emphasis_range.max=127;
s->emphasis_range.quant=1;
if (s->has_emphasis)
opt->cap = SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT;
else
opt->cap = SANE_CAP_INACTIVE;
}
if(option==OPT_SEPARATION){
opt->name = "separation";
opt->title = SANE_I18N ("Separation");
opt->desc = SANE_I18N ("Enable automatic separation of image and text");
opt->type = SANE_TYPE_BOOL;
opt->unit = SANE_UNIT_NONE;
if (s->has_autosep)
opt->cap = SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT;
else
opt->cap = SANE_CAP_INACTIVE;
}
if(option==OPT_MIRRORING){
opt->name = "mirroring";
opt->title = SANE_I18N ("Mirroring");
opt->desc = SANE_I18N ("Reflect output image horizontally");
opt->type = SANE_TYPE_BOOL;
opt->unit = SANE_UNIT_NONE;
if (s->has_mirroring)
opt->cap = SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT;
else
opt->cap = SANE_CAP_INACTIVE;
}
if(option==OPT_WL_FOLLOW){
i=0;
s->wl_follow_list[i++]=STRING_DEFAULT;
s->wl_follow_list[i++]=STRING_ON;
s->wl_follow_list[i++]=STRING_OFF;
s->wl_follow_list[i]=NULL;
opt->name = "wl-follow";
opt->title = SANE_I18N ("White level follower");
opt->desc = SANE_I18N ("Control white level follower");
opt->type = SANE_TYPE_STRING;
opt->unit = SANE_UNIT_NONE;
opt->constraint_type = SANE_CONSTRAINT_STRING_LIST;
opt->constraint.string_list = s->wl_follow_list;
opt->size = maxStringSize (opt->constraint.string_list);
if (s->has_wl_follow)
opt->cap = SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT;
else
opt->cap = SANE_CAP_INACTIVE;
}
/* =============== DTC params ================================ */
/* enabled when in dtc mode (manually or by default) */
if(option==OPT_BP_FILTER){
opt->name = "bp-filter";
opt->title = SANE_I18N ("BP filter");
opt->desc = SANE_I18N ("Improves quality of high resolution ball-point pen text");
opt->type = SANE_TYPE_BOOL;
opt->unit = SANE_UNIT_NONE;
if ( s->has_dtc ){
opt->cap = SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT;
if(get_ipc_mode(s) == WD_ipc_SDTC){
opt->cap |= SANE_CAP_INACTIVE;
}
}
else
opt->cap = SANE_CAP_INACTIVE;
}
if(option==OPT_SMOOTHING){
opt->name = "smoothing";
opt->title = SANE_I18N ("Smoothing");
opt->desc = SANE_I18N ("Enable smoothing for improved OCR");
opt->type = SANE_TYPE_BOOL;
opt->unit = SANE_UNIT_NONE;
if ( s->has_dtc ){
opt->cap = SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT;
if(get_ipc_mode(s) == WD_ipc_SDTC){
opt->cap |= SANE_CAP_INACTIVE;
}
}
else
opt->cap = SANE_CAP_INACTIVE;
}
if(option==OPT_GAMMA_CURVE){
opt->name = "gamma-curve";
opt->title = SANE_I18N ("Gamma curve");
opt->desc = SANE_I18N ("Gamma curve, from light to dark, but upper two may not work");
opt->type = SANE_TYPE_INT;
opt->unit = SANE_UNIT_NONE;
opt->constraint_type = SANE_CONSTRAINT_RANGE;
opt->constraint.range = &s->gamma_curve_range;
s->gamma_curve_range.min=0;
s->gamma_curve_range.max=3;
s->gamma_curve_range.quant=1;
if ( s->has_dtc ){
opt->cap = SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT;
if(get_ipc_mode(s) == WD_ipc_SDTC){
opt->cap |= SANE_CAP_INACTIVE;
}
}
else
opt->cap = SANE_CAP_INACTIVE;
}
if(option==OPT_THRESHOLD_CURVE){
opt->name = "threshold-curve";
opt->title = SANE_I18N ("Threshold curve");
opt->desc = SANE_I18N ("Threshold curve, from light to dark, but upper two may not be linear");
opt->type = SANE_TYPE_INT;
opt->unit = SANE_UNIT_NONE;
opt->constraint_type = SANE_CONSTRAINT_RANGE;
opt->constraint.range = &s->threshold_curve_range;
s->threshold_curve_range.min=0;
s->threshold_curve_range.max=7;
s->threshold_curve_range.quant=1;
if ( s->has_dtc ){
opt->cap = SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT;
if(get_ipc_mode(s) == WD_ipc_SDTC){
opt->cap |= SANE_CAP_INACTIVE;
}
}
else
opt->cap = SANE_CAP_INACTIVE;
}
if(option==OPT_THRESHOLD_WHITE){
opt->name = "threshold-white";
opt->title = SANE_I18N ("Threshold white");
opt->desc = SANE_I18N ("Set pixels equal to threshold to white instead of black");
opt->type = SANE_TYPE_BOOL;
opt->unit = SANE_UNIT_NONE;
if ( s->has_dtc ){
opt->cap = SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT;
if(get_ipc_mode(s) == WD_ipc_SDTC){
opt->cap |= SANE_CAP_INACTIVE;
}
}
else
opt->cap = SANE_CAP_INACTIVE;
}
if(option==OPT_NOISE_REMOVAL){
opt->name = "noise-removal";
opt->title = SANE_I18N ("Noise removal");
opt->desc = SANE_I18N ("Noise removal");
opt->type = SANE_TYPE_BOOL;
opt->unit = SANE_UNIT_NONE;
if ( s->has_dtc ){
opt->cap = SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT;
if(get_ipc_mode(s) == WD_ipc_SDTC){
opt->cap |= SANE_CAP_INACTIVE;
}
}
else
opt->cap = SANE_CAP_INACTIVE;
}
if(option==OPT_MATRIX_5){
opt->name = "matrix-5x5";
opt->title = SANE_I18N ("Matrix 5x5");
opt->desc = SANE_I18N ("Remove 5 pixel square noise");
opt->type = SANE_TYPE_BOOL;
opt->unit = SANE_UNIT_NONE;
if ( s->has_dtc ){
opt->cap = SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT;
if(!s->noise_removal){
opt->cap |= SANE_CAP_INACTIVE;
}
}
else
opt->cap = SANE_CAP_INACTIVE;
}
if(option==OPT_MATRIX_4){
opt->name = "matrix-4x4";
opt->title = SANE_I18N ("Matrix 4x4");
opt->desc = SANE_I18N ("Remove 4 pixel square noise");
opt->type = SANE_TYPE_BOOL;
opt->unit = SANE_UNIT_NONE;
if ( s->has_dtc ){
opt->cap = SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT;
if(!s->noise_removal){
opt->cap |= SANE_CAP_INACTIVE;
}
}
else
opt->cap = SANE_CAP_INACTIVE;
}
if(option==OPT_MATRIX_3){
opt->name = "matrix-3x3";
opt->title = SANE_I18N ("Matrix 3x3");
opt->desc = SANE_I18N ("Remove 3 pixel square noise");
opt->type = SANE_TYPE_BOOL;
opt->unit = SANE_UNIT_NONE;
if ( s->has_dtc ){
opt->cap = SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT;
if(!s->noise_removal){
opt->cap |= SANE_CAP_INACTIVE;
}
}
else
opt->cap = SANE_CAP_INACTIVE;
}
if(option==OPT_MATRIX_2){
opt->name = "matrix-2x2";
opt->title = SANE_I18N ("Matrix 2x2");
opt->desc = SANE_I18N ("Remove 2 pixel square noise");
opt->type = SANE_TYPE_BOOL;
opt->unit = SANE_UNIT_NONE;
if ( s->has_dtc ){
opt->cap = SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT;
if(!s->noise_removal){
opt->cap |= SANE_CAP_INACTIVE;
}
}
else
opt->cap = SANE_CAP_INACTIVE;
}
/* =============== SDTC param ================================ */
/* enabled when in sdtc mode (manually or by default) */
/* called variance with ipc2, sensitivity with ipc3 */
if(option==OPT_VARIANCE){
opt->name = "variance";
opt->title = SANE_I18N ("Variance");
opt->desc = SANE_I18N ("Set SDTC variance rate (sensitivity), 0 equals 127");
opt->type = SANE_TYPE_INT;
opt->unit = SANE_UNIT_NONE;
opt->constraint_type = SANE_CONSTRAINT_RANGE;
opt->constraint.range = &s->variance_range;
s->variance_range.min=0;
s->variance_range.max=255;
s->variance_range.quant=1;
if ( s->has_sdtc ){
opt->cap = SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT;
if(get_ipc_mode(s) == WD_ipc_DTC){
opt->cap |= SANE_CAP_INACTIVE;
}
}
else
opt->cap = SANE_CAP_INACTIVE;
}
/* "Advanced" group ------------------------------------------------------ */
if(option==OPT_ADVANCED_GROUP){
opt->name = SANE_NAME_ADVANCED;
opt->title = SANE_TITLE_ADVANCED;
opt->desc = SANE_DESC_ADVANCED;
opt->type = SANE_TYPE_GROUP;
opt->constraint_type = SANE_CONSTRAINT_NONE;
}
/*automatic width detection */
if(option==OPT_AWD){
opt->name = "awd";
opt->title = SANE_I18N ("Auto width detection");
opt->desc = SANE_I18N ("Scanner detects paper sides. May reduce scanning speed.");
opt->type = SANE_TYPE_BOOL;
opt->unit = SANE_UNIT_NONE;
opt->constraint_type = SANE_CONSTRAINT_NONE;
/* this option is useless by itself? */
if (0 && s->has_MS_auto && s->has_hybrid_crop_deskew){
opt->cap = SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT | SANE_CAP_ADVANCED;
}
else
opt->cap = SANE_CAP_INACTIVE;
}
/*automatic length detection */
if(option==OPT_ALD){
opt->name = "ald";
opt->title = SANE_I18N ("Auto length detection");
opt->desc = SANE_I18N ("Scanner detects paper lower edge. May confuse some frontends.");
opt->type = SANE_TYPE_BOOL;
opt->unit = SANE_UNIT_NONE;
opt->constraint_type = SANE_CONSTRAINT_NONE;
if (s->has_MS_auto){
opt->cap = SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT | SANE_CAP_ADVANCED;
}
else
opt->cap = SANE_CAP_INACTIVE;
}
/*image compression*/
if(option==OPT_COMPRESS){
i=0;
s->compress_list[i++]=STRING_NONE;
if(s->has_comp_JPG1){
#ifndef SANE_JPEG_DISABLED
s->compress_list[i++]=STRING_JPEG;
#endif
}
s->compress_list[i]=NULL;
opt->name = "compression";
opt->title = SANE_I18N ("Compression");
opt->desc = SANE_I18N ("Enable compressed data. May crash your front-end program");
opt->type = SANE_TYPE_STRING;
opt->constraint_type = SANE_CONSTRAINT_STRING_LIST;
opt->constraint.string_list = s->compress_list;
opt->size = maxStringSize (opt->constraint.string_list);
if (i > 1){
opt->cap = SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT;
if ( must_downsample(s) || s->s_mode < MODE_GRAYSCALE ){
opt->cap |= SANE_CAP_INACTIVE;
}
}
else
opt->cap = SANE_CAP_INACTIVE;
}
/*image compression arg*/
if(option==OPT_COMPRESS_ARG){
opt->name = "compression-arg";
opt->title = SANE_I18N ("Compression argument");
opt->desc = SANE_I18N ("Level of JPEG compression. 1 is small file, 7 is large file. 0 (default) is same as 4");
opt->type = SANE_TYPE_INT;
opt->unit = SANE_UNIT_NONE;
opt->constraint_type = SANE_CONSTRAINT_RANGE;
opt->constraint.range = &s->compress_arg_range;
s->compress_arg_range.quant=1;
if(s->has_comp_JPG1){
s->compress_arg_range.min=0;
s->compress_arg_range.max=7;
#ifndef SANE_JPEG_DISABLED
opt->cap = SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT;
#endif
if(s->compress != COMP_JPEG){
opt->cap |= SANE_CAP_INACTIVE;
}
}
else
opt->cap = SANE_CAP_INACTIVE;
}
/*double feed detection*/
if(option==OPT_DF_ACTION){
s->df_action_list[0] = STRING_DEFAULT;
s->df_action_list[1] = STRING_CONTINUE;
s->df_action_list[2] = STRING_STOP;
s->df_action_list[3] = NULL;
opt->name = "df-action";
opt->title = SANE_I18N ("DF action");
opt->desc = SANE_I18N ("Action following double feed error");
opt->type = SANE_TYPE_STRING;
opt->constraint_type = SANE_CONSTRAINT_STRING_LIST;
opt->constraint.string_list = s->df_action_list;
opt->size = maxStringSize (opt->constraint.string_list);
if (s->has_MS_df)
opt->cap = SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT | SANE_CAP_ADVANCED;
else
opt->cap = SANE_CAP_INACTIVE;
}
/*double feed by skew*/
if(option==OPT_DF_SKEW){
opt->name = "df-skew";
opt->title = SANE_I18N ("DF skew");
opt->desc = SANE_I18N ("Enable double feed error due to skew");
opt->type = SANE_TYPE_BOOL;
opt->unit = SANE_UNIT_NONE;
opt->constraint_type = SANE_CONSTRAINT_NONE;
if (s->has_MS_df){
opt->cap = SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT | SANE_CAP_ADVANCED;
if(!s->df_action)
opt->cap |= SANE_CAP_INACTIVE;
}
else
opt->cap = SANE_CAP_INACTIVE;
}
/*double feed by thickness */
if(option==OPT_DF_THICKNESS){
opt->name = "df-thickness";
opt->title = SANE_I18N ("DF thickness");
opt->desc = SANE_I18N ("Enable double feed error due to paper thickness");
opt->type = SANE_TYPE_BOOL;
opt->unit = SANE_UNIT_NONE;
opt->constraint_type = SANE_CONSTRAINT_NONE;
if (s->has_MS_df){
opt->cap = SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT | SANE_CAP_ADVANCED;
if(!s->df_action)
opt->cap |= SANE_CAP_INACTIVE;
}
else
opt->cap = SANE_CAP_INACTIVE;
}
/*double feed by length*/
if(option==OPT_DF_LENGTH){
opt->name = "df-length";
opt->title = SANE_I18N ("DF length");
opt->desc = SANE_I18N ("Enable double feed error due to paper length");
opt->type = SANE_TYPE_BOOL;
opt->unit = SANE_UNIT_NONE;
opt->constraint_type = SANE_CONSTRAINT_NONE;
if (s->has_MS_df){
opt->cap = SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT | SANE_CAP_ADVANCED;
if(!s->df_action)
opt->cap |= SANE_CAP_INACTIVE;
}
else
opt->cap = SANE_CAP_INACTIVE;
}
/*double feed length difference*/
if(option==OPT_DF_DIFF){
s->df_diff_list[0] = STRING_DEFAULT;
s->df_diff_list[1] = STRING_10MM;
s->df_diff_list[2] = STRING_15MM;
s->df_diff_list[3] = STRING_20MM;
s->df_diff_list[4] = NULL;
opt->name = "df-diff";
opt->title = SANE_I18N ("DF length difference");
opt->desc = SANE_I18N ("Difference in page length to trigger double feed error");
opt->type = SANE_TYPE_STRING;
opt->constraint_type = SANE_CONSTRAINT_STRING_LIST;
opt->constraint.string_list = s->df_diff_list;
opt->size = maxStringSize (opt->constraint.string_list);
if (s->has_MS_df){
opt->cap = SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT | SANE_CAP_ADVANCED;
if(!s->df_action || !s->df_diff)
opt->cap |= SANE_CAP_INACTIVE;
}
else
opt->cap = SANE_CAP_INACTIVE;
}
/*df_recovery*/
if(option==OPT_DF_RECOVERY){
s->df_recovery_list[0] = STRING_DEFAULT;
s->df_recovery_list[1] = STRING_OFF;
s->df_recovery_list[2] = STRING_ON;
s->df_recovery_list[3] = NULL;
opt->name = "df-recovery";
opt->title = SANE_I18N ("DF recovery mode");
opt->desc = SANE_I18N ("Request scanner to reverse feed on paper jam");
opt->type = SANE_TYPE_STRING;
opt->constraint_type = SANE_CONSTRAINT_STRING_LIST;
opt->constraint.string_list = s->df_recovery_list;
opt->size = maxStringSize (opt->constraint.string_list);
if (s->has_MS_df && s->has_df_recovery)
opt->cap = SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT | SANE_CAP_ADVANCED;
else
opt->cap = SANE_CAP_INACTIVE;
}
/*paper_protect*/
if(option==OPT_PAPER_PROTECT){
s->paper_protect_list[0] = STRING_DEFAULT;
s->paper_protect_list[1] = STRING_OFF;
s->paper_protect_list[2] = STRING_ON;
s->paper_protect_list[3] = NULL;
opt->name = "paper-protect";
opt->title = SANE_I18N ("Paper protection");
opt->desc = SANE_I18N ("Request scanner to predict jams in the ADF");
opt->type = SANE_TYPE_STRING;
opt->constraint_type = SANE_CONSTRAINT_STRING_LIST;
opt->constraint.string_list = s->paper_protect_list;
opt->size = maxStringSize (opt->constraint.string_list);
if (s->has_MS_df && s->has_paper_protect)
opt->cap = SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT | SANE_CAP_ADVANCED;
else
opt->cap = SANE_CAP_INACTIVE;
}
/*adv_paper_prot*/
if(option==OPT_ADV_PAPER_PROT){
s->adv_paper_prot_list[0] = STRING_DEFAULT;
s->adv_paper_prot_list[1] = STRING_OFF;
s->adv_paper_prot_list[2] = STRING_ON;
s->adv_paper_prot_list[3] = NULL;
opt->name = "adv-paper-protect";
opt->title = SANE_I18N ("Advanced paper protection");
opt->desc = SANE_I18N ("Request scanner to predict jams in the ADF using improved sensors");
opt->type = SANE_TYPE_STRING;
opt->constraint_type = SANE_CONSTRAINT_STRING_LIST;
opt->constraint.string_list = s->adv_paper_prot_list;
opt->size = maxStringSize (opt->constraint.string_list);
if (s->has_MS_df && s->has_adv_paper_prot)
opt->cap = SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT | SANE_CAP_ADVANCED;
else
opt->cap = SANE_CAP_INACTIVE;
}
/*staple detection*/
if(option==OPT_STAPLE_DETECT){
s->staple_detect_list[0] = STRING_DEFAULT;
s->staple_detect_list[1] = STRING_OFF;
s->staple_detect_list[2] = STRING_ON;
s->staple_detect_list[3] = NULL;
opt->name = "staple-detect";
opt->title = SANE_I18N ("Staple detection");
opt->desc = SANE_I18N ("Request scanner to detect jams in the ADF caused by staples");
opt->type = SANE_TYPE_STRING;
opt->constraint_type = SANE_CONSTRAINT_STRING_LIST;
opt->constraint.string_list = s->staple_detect_list;
opt->size = maxStringSize (opt->constraint.string_list);
if (s->has_MS_df && s->has_staple_detect)
opt->cap = SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT | SANE_CAP_ADVANCED;
else
opt->cap = SANE_CAP_INACTIVE;
}
/*background color*/
if(option==OPT_BG_COLOR){
s->bg_color_list[0] = STRING_DEFAULT;
s->bg_color_list[1] = STRING_WHITE;
s->bg_color_list[2] = STRING_BLACK;
s->bg_color_list[3] = NULL;
opt->name = "bgcolor";
opt->title = SANE_I18N ("Background color");
opt->desc = SANE_I18N ("Set color of background for scans. May conflict with overscan option");
opt->type = SANE_TYPE_STRING;
opt->constraint_type = SANE_CONSTRAINT_STRING_LIST;
opt->constraint.string_list = s->bg_color_list;
opt->size = maxStringSize (opt->constraint.string_list);
if (s->has_MS_bg)
opt->cap = SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT | SANE_CAP_ADVANCED;
else
opt->cap = SANE_CAP_INACTIVE;
}
/*dropout color*/
if(option==OPT_DROPOUT_COLOR){
s->do_color_list[0] = STRING_DEFAULT;
s->do_color_list[1] = STRING_RED;
s->do_color_list[2] = STRING_GREEN;
s->do_color_list[3] = STRING_BLUE;
s->do_color_list[4] = NULL;
opt->name = "dropoutcolor";
opt->title = SANE_I18N ("Dropout color");
opt->desc = SANE_I18N ("One-pass scanners use only one color during gray or binary scanning, useful for colored paper or ink");
opt->type = SANE_TYPE_STRING;
opt->constraint_type = SANE_CONSTRAINT_STRING_LIST;
opt->constraint.string_list = s->do_color_list;
opt->size = maxStringSize (opt->constraint.string_list);
if (s->has_MS_dropout || s->has_vuid_3091 || must_downsample(s)){
opt->cap = SANE_CAP_SOFT_SELECT|SANE_CAP_SOFT_DETECT|SANE_CAP_ADVANCED;
if(s->u_mode == MODE_COLOR)
opt->cap |= SANE_CAP_INACTIVE;
}
else
opt->cap = SANE_CAP_INACTIVE;
}
/*buffer mode*/
if(option==OPT_BUFF_MODE){
s->buff_mode_list[0] = STRING_DEFAULT;
s->buff_mode_list[1] = STRING_OFF;
s->buff_mode_list[2] = STRING_ON;
s->buff_mode_list[3] = NULL;
opt->name = "buffermode";
opt->title = SANE_I18N ("Buffer mode");
opt->desc = SANE_I18N ("Request scanner to read pages quickly from ADF into internal memory");
opt->type = SANE_TYPE_STRING;
opt->constraint_type = SANE_CONSTRAINT_STRING_LIST;
opt->constraint.string_list = s->buff_mode_list;
opt->size = maxStringSize (opt->constraint.string_list);
if (s->has_MS_buff)
opt->cap = SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT | SANE_CAP_ADVANCED;
else
opt->cap = SANE_CAP_INACTIVE;
}
/*prepick*/
if(option==OPT_PREPICK){
s->prepick_list[0] = STRING_DEFAULT;
s->prepick_list[1] = STRING_OFF;
s->prepick_list[2] = STRING_ON;
s->prepick_list[3] = NULL;
opt->name = "prepick";
opt->title = SANE_I18N ("Prepick");
opt->desc = SANE_I18N ("Request scanner to grab next page from ADF");
opt->type = SANE_TYPE_STRING;
opt->constraint_type = SANE_CONSTRAINT_STRING_LIST;
opt->constraint.string_list = s->prepick_list;
opt->size = maxStringSize (opt->constraint.string_list);
if (s->has_MS_prepick)
opt->cap = SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT | SANE_CAP_ADVANCED;
else
opt->cap = SANE_CAP_INACTIVE;
}
/*overscan*/
if(option==OPT_OVERSCAN){
s->overscan_list[0] = STRING_DEFAULT;
s->overscan_list[1] = STRING_OFF;
s->overscan_list[2] = STRING_ON;
s->overscan_list[3] = NULL;
opt->name = "overscan";
opt->title = SANE_I18N ("Overscan");
opt->desc = SANE_I18N ("Collect a few mm of background on top side of scan, before paper enters ADF, and increase maximum scan area beyond paper size, to allow collection on remaining sides. May conflict with bgcolor option");
opt->type = SANE_TYPE_STRING;
opt->constraint_type = SANE_CONSTRAINT_STRING_LIST;
opt->constraint.string_list = s->overscan_list;
opt->size = maxStringSize (opt->constraint.string_list);
if (s->has_MS_auto && (s->os_x_basic || s->os_y_basic))
opt->cap = SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT | SANE_CAP_ADVANCED;
else
opt->cap = SANE_CAP_INACTIVE;
}
/*sleep_time*/
if(option==OPT_SLEEP_TIME){
s->sleep_time_range.min = 0;
s->sleep_time_range.max = 60;
s->sleep_time_range.quant = 1;
opt->name = "sleeptimer";
opt->title = SANE_I18N ("Sleep timer");
opt->desc = SANE_I18N ("Time in minutes until the internal power supply switches to sleep mode");
opt->type = SANE_TYPE_INT;
opt->unit = SANE_UNIT_NONE;
opt->constraint_type = SANE_CONSTRAINT_RANGE;
opt->constraint.range=&s->sleep_time_range;
if(s->has_MS_sleep)
opt->cap = SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT | SANE_CAP_ADVANCED;
else
opt->cap = SANE_CAP_INACTIVE;
}
/*off_time*/
if(option==OPT_OFF_TIME){
s->off_time_range.min = 0;
s->off_time_range.max = 960;
s->off_time_range.quant = 1;
opt->name = "offtimer";
opt->title = SANE_I18N ("Off timer");
opt->desc = SANE_I18N ("Time in minutes until the internal power supply switches the scanner off. Will be rounded to nearest 15 minutes. Zero means never power off.");
opt->type = SANE_TYPE_INT;
opt->unit = SANE_UNIT_NONE;
opt->constraint_type = SANE_CONSTRAINT_RANGE;
opt->constraint.range=&s->off_time_range;
if(s->has_off_mode)
opt->cap = SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT | SANE_CAP_ADVANCED;
else
opt->cap = SANE_CAP_INACTIVE;
}
/*duplex offset*/
if(option==OPT_DUPLEX_OFFSET){
s->duplex_offset_range.min = -16;
s->duplex_offset_range.max = 16;
s->duplex_offset_range.quant = 1;
opt->name = "duplexoffset";
opt->title = SANE_I18N ("Duplex offset");
opt->desc = SANE_I18N ("Adjust front/back offset");
opt->type = SANE_TYPE_INT;
opt->unit = SANE_UNIT_NONE;
opt->constraint_type = SANE_CONSTRAINT_RANGE;
opt->constraint.range = &s->duplex_offset_range;
if(s->duplex_interlace == DUPLEX_INTERLACE_3091)
opt->cap = SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT | SANE_CAP_ADVANCED;
else
opt->cap = SANE_CAP_INACTIVE;
}
if(option==OPT_GREEN_OFFSET){
s->green_offset_range.min = -16;
s->green_offset_range.max = 16;
s->green_offset_range.quant = 1;
opt->name = "greenoffset";
opt->title = SANE_I18N ("Green offset");
opt->desc = SANE_I18N ("Adjust green/red offset");
opt->type = SANE_TYPE_INT;
opt->unit = SANE_UNIT_NONE;
opt->constraint_type = SANE_CONSTRAINT_RANGE;
opt->constraint.range = &s->green_offset_range;
if(s->color_interlace == COLOR_INTERLACE_3091)
opt->cap = SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT | SANE_CAP_ADVANCED;
else
opt->cap = SANE_CAP_INACTIVE;
}
if(option==OPT_BLUE_OFFSET){
s->blue_offset_range.min = -16;
s->blue_offset_range.max = 16;
s->blue_offset_range.quant = 1;
opt->name = "blueoffset";
opt->title = SANE_I18N ("Blue offset");
opt->desc = SANE_I18N ("Adjust blue/red offset");
opt->type = SANE_TYPE_INT;
opt->unit = SANE_UNIT_NONE;
opt->constraint_type = SANE_CONSTRAINT_RANGE;
opt->constraint.range = &s->blue_offset_range;
if(s->color_interlace == COLOR_INTERLACE_3091)
opt->cap = SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT | SANE_CAP_ADVANCED;
else
opt->cap = SANE_CAP_INACTIVE;
}
if(option==OPT_LOW_MEM){
opt->name = "lowmemory";
opt->title = SANE_I18N ("Low Memory");
opt->desc = SANE_I18N ("Limit driver memory usage for use in embedded systems. Causes some duplex transfers to alternate sides on each call to sane_read. Value of option 'side' can be used to determine correct image. This option should only be used with custom front-end software.");
opt->type = SANE_TYPE_BOOL;
opt->unit = SANE_UNIT_NONE;
opt->size = sizeof(SANE_Word);
if (1)
opt->cap= SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT | SANE_CAP_ADVANCED;
else
opt->cap = SANE_CAP_INACTIVE;
opt->constraint_type = SANE_CONSTRAINT_NONE;
}
if(option==OPT_SIDE){
opt->name = "side";
opt->title = SANE_I18N ("Duplex side");
opt->desc = SANE_I18N ("Tells which side (0=front, 1=back) of a duplex scan the next call to sane_read will return.");
opt->type = SANE_TYPE_BOOL;
opt->unit = SANE_UNIT_NONE;
opt->size = sizeof(SANE_Word);
opt->cap = SANE_CAP_SOFT_DETECT | SANE_CAP_ADVANCED;
opt->constraint_type = SANE_CONSTRAINT_NONE;
}
/*deskew and crop by hardware*/
if(option==OPT_HWDESKEWCROP){
opt->name = "hwdeskewcrop";
opt->title = SANE_I18N ("Hardware deskew and crop");
opt->desc = SANE_I18N ("Request scanner to rotate and crop pages digitally.");
opt->type = SANE_TYPE_BOOL;
if (s->has_hybrid_crop_deskew)
opt->cap = SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT | SANE_CAP_ADVANCED;
else
opt->cap = SANE_CAP_INACTIVE;
}
/*deskew by software*/
if(option==OPT_SWDESKEW){
opt->name = "swdeskew";
opt->title = SANE_I18N ("Software deskew");
opt->desc = SANE_I18N ("Request driver to rotate skewed pages digitally.");
opt->type = SANE_TYPE_BOOL;
if (1)
opt->cap = SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT | SANE_CAP_ADVANCED;
else
opt->cap = SANE_CAP_INACTIVE;
}
/*software despeckle radius*/
if(option==OPT_SWDESPECK){
opt->name = "swdespeck";
opt->title = SANE_I18N ("Software despeckle diameter");
opt->desc = SANE_I18N ("Maximum diameter of lone dots to remove from scan.");
opt->type = SANE_TYPE_INT;
opt->unit = SANE_UNIT_NONE;
opt->constraint_type = SANE_CONSTRAINT_RANGE;
opt->constraint.range = &s->swdespeck_range;
s->swdespeck_range.quant=1;
if(1){
s->swdespeck_range.min=0;
s->swdespeck_range.max=9;
opt->cap = SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT;
}
else
opt->cap = SANE_CAP_INACTIVE;
}
/*crop by software*/
if(option==OPT_SWCROP){
opt->name = "swcrop";
opt->title = SANE_I18N ("Software crop");
opt->desc = SANE_I18N ("Request driver to remove border from pages digitally.");
opt->type = SANE_TYPE_BOOL;
if (1)
opt->cap = SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT | SANE_CAP_ADVANCED;
else
opt->cap = SANE_CAP_INACTIVE;
}
/* Software blank page skip */
if(option==OPT_SWSKIP){
opt->name = "swskip";
opt->title = SANE_I18N ("Software blank skip percentage");
opt->desc = SANE_I18N("Request driver to discard pages with low percentage of dark pixels");
opt->type = SANE_TYPE_FIXED;
opt->unit = SANE_UNIT_PERCENT;
opt->constraint_type = SANE_CONSTRAINT_RANGE;
opt->constraint.range = &s->swskip_range;
s->swskip_range.quant=SANE_FIX(0.10001);
s->swskip_range.min=SANE_FIX(0);
s->swskip_range.max=SANE_FIX(100);
opt->cap = SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT;
}
/*halt scanner feeder when cancelling*/
if(option==OPT_HALT_ON_CANCEL){
opt->name = "halt-on-cancel";
opt->title = SANE_I18N ("Halt on Cancel");
opt->desc = SANE_I18N ("Request driver to halt the paper feed instead of eject during a cancel.");
opt->type = SANE_TYPE_BOOL;
if (s->has_op_halt)
opt->cap = SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT | SANE_CAP_ADVANCED;
else
opt->cap = SANE_CAP_INACTIVE;
}
/* "Endorser" group ------------------------------------------------------ */
if(option==OPT_ENDORSER_GROUP){
opt->name = "endorser-options";
opt->title = SANE_I18N ("Endorser Options");
opt->desc = SANE_I18N ("Controls for endorser unit");
opt->type = SANE_TYPE_GROUP;
opt->constraint_type = SANE_CONSTRAINT_NONE;
/*flaming hack to get scanimage to hide group*/
if ( !(s->has_endorser_f || s->has_endorser_b) )
opt->type = SANE_TYPE_BOOL;
}
if(option==OPT_ENDORSER){
opt->name = "endorser";
opt->title = SANE_I18N ("Endorser");
opt->desc = SANE_I18N ("Enable endorser unit");
opt->type = SANE_TYPE_BOOL;
opt->unit = SANE_UNIT_NONE;
opt->size = sizeof(SANE_Word);
if (s->has_endorser_f || s->has_endorser_b)
opt->cap= SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT | SANE_CAP_ADVANCED;
else
opt->cap = SANE_CAP_INACTIVE;
opt->constraint_type = SANE_CONSTRAINT_NONE;
}
if(option==OPT_ENDORSER_BITS){
opt->name = "endorser-bits";
opt->title = SANE_I18N ("Endorser bits");
opt->desc = SANE_I18N ("Determines maximum endorser counter value.");
opt->type = SANE_TYPE_INT;
opt->unit = SANE_UNIT_NONE;
opt->size = sizeof(SANE_Word);
/*old type cant do this?*/
if ((s->has_endorser_f && s->endorser_type_f != ET_OLD)
|| (s->has_endorser_b && s->endorser_type_b != ET_OLD)){
opt->cap=SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT | SANE_CAP_ADVANCED;
if(!s->u_endorser)
opt->cap |= SANE_CAP_INACTIVE;
}
else
opt->cap = SANE_CAP_INACTIVE;
opt->constraint_type = SANE_CONSTRAINT_RANGE;
opt->constraint.range = &s->endorser_bits_range;
s->endorser_bits_range.min = 16;
s->endorser_bits_range.max = 24;
s->endorser_bits_range.quant = 8;
}
if(option==OPT_ENDORSER_VAL){
opt->name = "endorser-val";
opt->title = SANE_I18N ("Endorser value");
opt->desc = SANE_I18N ("Initial endorser counter value.");
opt->type = SANE_TYPE_INT;
opt->unit = SANE_UNIT_NONE;
opt->size = sizeof(SANE_Word);
if (s->has_endorser_f || s->has_endorser_b){
opt->cap=SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT | SANE_CAP_ADVANCED;
if(!s->u_endorser)
opt->cap |= SANE_CAP_INACTIVE;
}
else
opt->cap = SANE_CAP_INACTIVE;
opt->constraint_type = SANE_CONSTRAINT_RANGE;
opt->constraint.range = &s->endorser_val_range;
s->endorser_val_range.min = 0;
s->endorser_val_range.max = (1 << s->u_endorser_bits)-1;
s->endorser_val_range.quant = 1;
}
if(option==OPT_ENDORSER_STEP){
opt->name = "endorser-step";
opt->title = SANE_I18N ("Endorser step");
opt->desc = SANE_I18N ("Change endorser counter value by this much for each page.");
opt->type = SANE_TYPE_INT;
opt->unit = SANE_UNIT_NONE;
opt->size = sizeof(SANE_Word);
if (s->has_endorser_f || s->has_endorser_b){
opt->cap=SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT | SANE_CAP_ADVANCED;
if(!s->u_endorser)
opt->cap |= SANE_CAP_INACTIVE;
}
else
opt->cap = SANE_CAP_INACTIVE;
opt->constraint_type = SANE_CONSTRAINT_RANGE;
opt->constraint.range = &s->endorser_step_range;
s->endorser_step_range.min = -2;
s->endorser_step_range.max = 2;
s->endorser_step_range.quant = 1;
}
if(option==OPT_ENDORSER_Y){
opt->name = "endorser-y";
opt->title = SANE_I18N ("Endorser Y");
opt->desc = SANE_I18N ("Endorser print offset from top of paper.");
opt->type = SANE_TYPE_FIXED;
opt->unit = SANE_UNIT_MM;
opt->size = sizeof(SANE_Word);
if (s->has_endorser_f || s->has_endorser_b){
opt->cap=SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT | SANE_CAP_ADVANCED;
if(!s->u_endorser)
opt->cap |= SANE_CAP_INACTIVE;
}
else
opt->cap = SANE_CAP_INACTIVE;
opt->constraint_type = SANE_CONSTRAINT_RANGE;
opt->constraint.range = &(s->endorser_y_range);
/* values stored in 1200 dpi units */
/* must be converted to MM for sane */
s->endorser_y_range.min = SCANNER_UNIT_TO_FIXED_MM(0);
s->endorser_y_range.max = SCANNER_UNIT_TO_FIXED_MM(get_page_height(s));
s->endorser_y_range.quant = MM_PER_UNIT_FIX;
}
if(option==OPT_ENDORSER_FONT){
opt->name = "endorser-font";
opt->title = SANE_I18N ("Endorser font");
opt->desc = SANE_I18N ("Endorser printing font.");
opt->type = SANE_TYPE_STRING;
opt->unit = SANE_UNIT_NONE;
/*only newest can do this?*/
if ((s->has_endorser_f && s->endorser_type_f == ET_40)
|| (s->has_endorser_b && s->endorser_type_b == ET_40)){
opt->cap=SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT | SANE_CAP_ADVANCED;
if(!s->u_endorser)
opt->cap |= SANE_CAP_INACTIVE;
}
else
opt->cap = SANE_CAP_INACTIVE;
opt->constraint_type = SANE_CONSTRAINT_STRING_LIST;
opt->constraint.string_list = s->endorser_font_list;
s->endorser_font_list[0] = STRING_HORIZONTAL;
s->endorser_font_list[1] = STRING_HORIZONTALBOLD;
s->endorser_font_list[2] = STRING_HORIZONTALNARROW;
s->endorser_font_list[3] = STRING_VERTICAL;
s->endorser_font_list[4] = STRING_VERTICALBOLD;
s->endorser_font_list[5] = NULL;
opt->size = maxStringSize (opt->constraint.string_list);
}
if(option==OPT_ENDORSER_DIR){
opt->name = "endorser-dir";
opt->title = SANE_I18N ("Endorser direction");
opt->desc = SANE_I18N ("Endorser printing direction.");
opt->type = SANE_TYPE_STRING;
opt->unit = SANE_UNIT_NONE;
if (s->has_endorser_f || s->has_endorser_b){
opt->cap=SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT | SANE_CAP_ADVANCED;
if(!s->u_endorser)
opt->cap |= SANE_CAP_INACTIVE;
}
else
opt->cap = SANE_CAP_INACTIVE;
opt->constraint_type = SANE_CONSTRAINT_STRING_LIST;
opt->constraint.string_list = s->endorser_dir_list;
s->endorser_dir_list[0] = STRING_TOPTOBOTTOM;
s->endorser_dir_list[1] = STRING_BOTTOMTOTOP;
s->endorser_dir_list[2] = NULL;
opt->size = maxStringSize (opt->constraint.string_list);
}
if(option==OPT_ENDORSER_SIDE){
opt->name = "endorser-side";
opt->title = SANE_I18N ("Endorser side");
opt->desc = SANE_I18N ("Endorser printing side, requires hardware support to change");
opt->type = SANE_TYPE_STRING;
opt->unit = SANE_UNIT_NONE;
/* only show if both endorsers are installed */
if (s->has_endorser_f && s->has_endorser_b){
opt->cap=SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT | SANE_CAP_ADVANCED;
if(!s->u_endorser)
opt->cap |= SANE_CAP_INACTIVE;
}
else
opt->cap = SANE_CAP_INACTIVE;
opt->constraint_type = SANE_CONSTRAINT_STRING_LIST;
opt->constraint.string_list = s->endorser_side_list;
s->endorser_side_list[0] = STRING_FRONT;
s->endorser_side_list[1] = STRING_BACK;
s->endorser_side_list[2] = NULL;
opt->size = maxStringSize (opt->constraint.string_list);
}
if(option==OPT_ENDORSER_STRING){
opt->name = "endorser-string";
opt->title = SANE_I18N ("Endorser string");
opt->desc = SANE_I18N ("Endorser alphanumeric print format. %05ud or %08ud at the end will be replaced by counter value.");
opt->type = SANE_TYPE_STRING;
opt->unit = SANE_UNIT_NONE;
opt->size = s->endorser_string_len + 1;
if (s->has_endorser_f || s->has_endorser_b){
opt->cap=SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT | SANE_CAP_ADVANCED;
if(!s->u_endorser)
opt->cap |= SANE_CAP_INACTIVE;
}
else
opt->cap = SANE_CAP_INACTIVE;
opt->constraint_type = SANE_CONSTRAINT_NONE;
}
/* "Sensor" group ------------------------------------------------------ */
if(option==OPT_SENSOR_GROUP){
opt->name = SANE_NAME_SENSORS;
opt->title = SANE_TITLE_SENSORS;
opt->desc = SANE_DESC_SENSORS;
opt->type = SANE_TYPE_GROUP;
opt->constraint_type = SANE_CONSTRAINT_NONE;
}
if(option==OPT_TOP){
opt->name = "top-edge";
opt->title = SANE_I18N ("Top edge");
opt->desc = SANE_I18N ("Paper is pulled partly into adf");
opt->type = SANE_TYPE_BOOL;
opt->unit = SANE_UNIT_NONE;
if (s->has_cmd_hw_status || s->ghs_in_rs)
opt->cap = SANE_CAP_SOFT_DETECT | SANE_CAP_HARD_SELECT | SANE_CAP_ADVANCED;
else
opt->cap = SANE_CAP_INACTIVE;
}
if(option==OPT_A3){
opt->name = "a3-paper";
opt->title = SANE_I18N ("A3 paper");
opt->desc = SANE_I18N ("A3 paper detected");
opt->type = SANE_TYPE_BOOL;
opt->unit = SANE_UNIT_NONE;
if (s->has_cmd_hw_status)
opt->cap = SANE_CAP_SOFT_DETECT | SANE_CAP_HARD_SELECT | SANE_CAP_ADVANCED;
else
opt->cap = SANE_CAP_INACTIVE;
}
if(option==OPT_B4){
opt->name = "b4-paper";
opt->title = SANE_I18N ("B4 paper");
opt->desc = SANE_I18N ("B4 paper detected");
opt->type = SANE_TYPE_BOOL;
opt->unit = SANE_UNIT_NONE;
if (s->has_cmd_hw_status)
opt->cap = SANE_CAP_SOFT_DETECT | SANE_CAP_HARD_SELECT | SANE_CAP_ADVANCED;
else
opt->cap = SANE_CAP_INACTIVE;
}
if(option==OPT_A4){
opt->name = "a4-paper";
opt->title = SANE_I18N ("A4 paper");
opt->desc = SANE_I18N ("A4 paper detected");
opt->type = SANE_TYPE_BOOL;
opt->unit = SANE_UNIT_NONE;
if (s->has_cmd_hw_status)
opt->cap = SANE_CAP_SOFT_DETECT | SANE_CAP_HARD_SELECT | SANE_CAP_ADVANCED;
else
opt->cap = SANE_CAP_INACTIVE;
}
if(option==OPT_B5){
opt->name = "b5-paper";
opt->title = SANE_I18N ("B5 paper");
opt->desc = SANE_I18N ("B5 paper detected");
opt->type = SANE_TYPE_BOOL;
opt->unit = SANE_UNIT_NONE;
if (s->has_cmd_hw_status)
opt->cap = SANE_CAP_SOFT_DETECT | SANE_CAP_HARD_SELECT | SANE_CAP_ADVANCED;
else
opt->cap = SANE_CAP_INACTIVE;
}
if(option==OPT_HOPPER){
opt->name = SANE_NAME_PAGE_LOADED;
opt->title = SANE_TITLE_PAGE_LOADED;
opt->desc = SANE_DESC_PAGE_LOADED;
opt->type = SANE_TYPE_BOOL;
opt->unit = SANE_UNIT_NONE;
if (s->has_cmd_hw_status || s->ghs_in_rs)
opt->cap = SANE_CAP_SOFT_DETECT | SANE_CAP_HARD_SELECT | SANE_CAP_ADVANCED;
else
opt->cap = SANE_CAP_INACTIVE;
}
if(option==OPT_OMR){
opt->name = "omr-df";
opt->title = SANE_I18N ("OMR or DF");
opt->desc = SANE_I18N ("OMR or double feed detected");
opt->type = SANE_TYPE_BOOL;
opt->unit = SANE_UNIT_NONE;
if (s->has_cmd_hw_status)
opt->cap = SANE_CAP_SOFT_DETECT | SANE_CAP_HARD_SELECT | SANE_CAP_ADVANCED;
else
opt->cap = SANE_CAP_INACTIVE;
}
if(option==OPT_ADF_OPEN){
opt->name = SANE_NAME_COVER_OPEN;
opt->title = SANE_TITLE_COVER_OPEN;
opt->desc = SANE_DESC_COVER_OPEN;
opt->type = SANE_TYPE_BOOL;
opt->unit = SANE_UNIT_NONE;
if (s->has_cmd_hw_status || s->ghs_in_rs)
opt->cap = SANE_CAP_SOFT_DETECT | SANE_CAP_HARD_SELECT | SANE_CAP_ADVANCED;
else
opt->cap = SANE_CAP_INACTIVE;
}
if(option==OPT_SLEEP){
opt->name = "power-save";
opt->title = SANE_I18N ("Power saving");
opt->desc = SANE_I18N ("Scanner in power saving mode");
opt->type = SANE_TYPE_BOOL;
opt->unit = SANE_UNIT_NONE;
if (s->has_cmd_hw_status)
opt->cap = SANE_CAP_SOFT_DETECT | SANE_CAP_HARD_SELECT | SANE_CAP_ADVANCED;
else
opt->cap = SANE_CAP_INACTIVE;
}
if(option==OPT_SEND_SW){
opt->name = SANE_NAME_EMAIL;
opt->title = SANE_TITLE_EMAIL;
opt->desc = SANE_DESC_EMAIL;
opt->type = SANE_TYPE_BOOL;
opt->unit = SANE_UNIT_NONE;
if (s->has_cmd_hw_status || s->ghs_in_rs)
opt->cap = SANE_CAP_SOFT_DETECT | SANE_CAP_HARD_SELECT | SANE_CAP_ADVANCED;
else
opt->cap = SANE_CAP_INACTIVE;
}
if(option==OPT_MANUAL_FEED){
opt->name = "manual-feed";
opt->title = SANE_I18N ("Manual feed");
opt->desc = SANE_I18N ("Manual feed selected");
opt->type = SANE_TYPE_BOOL;
opt->unit = SANE_UNIT_NONE;
if (s->has_cmd_hw_status)
opt->cap = SANE_CAP_SOFT_DETECT | SANE_CAP_HARD_SELECT | SANE_CAP_ADVANCED;
else
opt->cap = SANE_CAP_INACTIVE;
}
if(option==OPT_SCAN_SW){
opt->name = SANE_NAME_SCAN;
opt->title = SANE_TITLE_SCAN;
opt->desc = SANE_DESC_SCAN;
opt->type = SANE_TYPE_BOOL;
opt->unit = SANE_UNIT_NONE;
if (s->has_cmd_hw_status || s->ghs_in_rs)
opt->cap = SANE_CAP_SOFT_DETECT | SANE_CAP_HARD_SELECT | SANE_CAP_ADVANCED;
else
opt->cap = SANE_CAP_INACTIVE;
}
if(option==OPT_FUNCTION){
opt->name = "function";
opt->title = SANE_I18N ("Function");
opt->desc = SANE_I18N ("Function character on screen");
opt->type = SANE_TYPE_INT;
opt->unit = SANE_UNIT_NONE;
if (s->has_cmd_hw_status || s->ghs_in_rs)
opt->cap = SANE_CAP_SOFT_DETECT | SANE_CAP_HARD_SELECT | SANE_CAP_ADVANCED;
else
opt->cap = SANE_CAP_INACTIVE;
}
if(option==OPT_INK_EMPTY){
opt->name = "ink-low";
opt->title = SANE_I18N ("Ink low");
opt->desc = SANE_I18N ("Imprinter ink running low");
opt->type = SANE_TYPE_BOOL;
opt->unit = SANE_UNIT_NONE;
if (s->has_cmd_hw_status && (s->has_endorser_f || s->has_endorser_b))
opt->cap = SANE_CAP_SOFT_DETECT | SANE_CAP_HARD_SELECT | SANE_CAP_ADVANCED;
else
opt->cap = SANE_CAP_INACTIVE;
}
if(option==OPT_DOUBLE_FEED){
opt->name = "double-feed";
opt->title = SANE_I18N ("Double feed");
opt->desc = SANE_I18N ("Double feed detected");
opt->type = SANE_TYPE_BOOL;
opt->unit = SANE_UNIT_NONE;
if (s->has_cmd_hw_status || s->ghs_in_rs)
opt->cap = SANE_CAP_SOFT_DETECT | SANE_CAP_HARD_SELECT | SANE_CAP_ADVANCED;
else
opt->cap = SANE_CAP_INACTIVE;
}
if(option==OPT_ERROR_CODE){
opt->name = "error-code";
opt->title = SANE_I18N ("Error code");
opt->desc = SANE_I18N ("Hardware error code");
opt->type = SANE_TYPE_INT;
opt->unit = SANE_UNIT_NONE;
if (s->has_cmd_hw_status)
opt->cap = SANE_CAP_SOFT_DETECT | SANE_CAP_HARD_SELECT | SANE_CAP_ADVANCED;
else
opt->cap = SANE_CAP_INACTIVE;
}
if(option==OPT_SKEW_ANGLE){
opt->name = "skew-angle";
opt->title = SANE_I18N ("Skew angle");
opt->desc = SANE_I18N ("Requires black background for scanning");
opt->type = SANE_TYPE_INT;
opt->unit = SANE_UNIT_NONE;
if (s->has_cmd_hw_status)
opt->cap = SANE_CAP_SOFT_DETECT | SANE_CAP_HARD_SELECT | SANE_CAP_ADVANCED;
else
opt->cap = SANE_CAP_INACTIVE;
}
if(option==OPT_INK_REMAIN){
opt->name = "ink-remain";
opt->title = SANE_I18N ("Ink remaining");
opt->desc = SANE_I18N ("Imprinter ink level");
opt->type = SANE_TYPE_INT;
opt->unit = SANE_UNIT_NONE;
if (s->has_cmd_hw_status && (s->has_endorser_f || s->has_endorser_b))
opt->cap = SANE_CAP_SOFT_DETECT | SANE_CAP_HARD_SELECT | SANE_CAP_ADVANCED;
else
opt->cap = SANE_CAP_INACTIVE;
}
if(option==OPT_DENSITY_SW){
opt->name = "density";
opt->title = SANE_I18N ("Density");
opt->desc = SANE_I18N ("Density dial");
opt->type = SANE_TYPE_INT;
opt->unit = SANE_UNIT_NONE;
if (s->ghs_in_rs)
opt->cap = SANE_CAP_SOFT_DETECT | SANE_CAP_HARD_SELECT | SANE_CAP_ADVANCED;
else
opt->cap = SANE_CAP_INACTIVE;
}
if(option==OPT_DUPLEX_SW){
opt->name = "duplex";
opt->title = SANE_I18N ("Duplex switch");
opt->desc = SANE_I18N ("Duplex switch");
opt->type = SANE_TYPE_BOOL;
opt->unit = SANE_UNIT_NONE;
if (s->ghs_in_rs)
opt->cap = SANE_CAP_SOFT_DETECT | SANE_CAP_HARD_SELECT | SANE_CAP_ADVANCED;
else
opt->cap = SANE_CAP_INACTIVE;
}
return opt;
}
/**
* Gets or sets an option value.
*
* From the SANE spec:
* This function is used to set or inquire the current value of option
* number n of the device represented by handle h. The manner in which
* the option is controlled is specified by parameter action. The
* possible values of this parameter are described in more detail
* below. The value of the option is passed through argument val. It
* is a pointer to the memory that holds the option value. The memory
* area pointed to by v must be big enough to hold the entire option
* value (determined by member size in the corresponding option
* descriptor).
*
* The only exception to this rule is that when setting the value of a
* string option, the string pointed to by argument v may be shorter
* since the backend will stop reading the option value upon
* encountering the first NUL terminator in the string. If argument i
* is not NULL, the value of *i will be set to provide details on how
* well the request has been met.
*/
SANE_Status
sane_control_option (SANE_Handle handle, SANE_Int option,
SANE_Action action, void *val, SANE_Int * info)
{
struct fujitsu *s = (struct fujitsu *) handle;
SANE_Int dummy = 0;
SANE_Status ret = SANE_STATUS_GOOD;
/* Make sure that all those statements involving *info cannot break (better
* than having to do "if (info) ..." everywhere!)
*/
if (info == 0)
info = &dummy;
/*blast info in case frontend forgot*/
*info = 0;
if (option >= NUM_OPTIONS) {
DBG (5, "sane_control_option: %d too big\n", option);
return SANE_STATUS_INVAL;
}
if (!SANE_OPTION_IS_ACTIVE (s->opt[option].cap)) {
DBG (5, "sane_control_option: %d inactive\n", option);
return SANE_STATUS_INVAL;
}
/*
* SANE_ACTION_GET_VALUE: We have to find out the current setting and
* return it in a human-readable form (often, text).
*/
if (action == SANE_ACTION_GET_VALUE) {
SANE_Word * val_p = (SANE_Word *) val;
DBG (20, "sane_control_option: get value for '%s' (%d)\n", s->opt[option].name,option);
switch (option) {
case OPT_NUM_OPTS:
*val_p = NUM_OPTIONS;
return SANE_STATUS_GOOD;
case OPT_SOURCE:
if(s->source == SOURCE_FLATBED){
strcpy (val, STRING_FLATBED);
}
else if(s->source == SOURCE_ADF_FRONT){
strcpy (val, STRING_ADFFRONT);
}
else if(s->source == SOURCE_ADF_BACK){
strcpy (val, STRING_ADFBACK);
}
else if(s->source == SOURCE_ADF_DUPLEX){
strcpy (val, STRING_ADFDUPLEX);
}
return SANE_STATUS_GOOD;
case OPT_MODE:
if(s->u_mode == MODE_LINEART){
strcpy (val, STRING_LINEART);
}
else if(s->u_mode == MODE_HALFTONE){
strcpy (val, STRING_HALFTONE);
}
else if(s->u_mode == MODE_GRAYSCALE){
strcpy (val, STRING_GRAYSCALE);
}
else if(s->u_mode == MODE_COLOR){
strcpy (val, STRING_COLOR);
}
return SANE_STATUS_GOOD;
case OPT_RES:
*val_p = s->resolution_x;
return SANE_STATUS_GOOD;
case OPT_TL_X:
*val_p = SCANNER_UNIT_TO_FIXED_MM(s->tl_x);
return SANE_STATUS_GOOD;
case OPT_TL_Y:
*val_p = SCANNER_UNIT_TO_FIXED_MM(s->tl_y);
return SANE_STATUS_GOOD;
case OPT_BR_X:
*val_p = SCANNER_UNIT_TO_FIXED_MM(s->br_x);
return SANE_STATUS_GOOD;
case OPT_BR_Y:
*val_p = SCANNER_UNIT_TO_FIXED_MM(s->br_y);
return SANE_STATUS_GOOD;
case OPT_PAGE_WIDTH:
*val_p = SCANNER_UNIT_TO_FIXED_MM(s->page_width);
return SANE_STATUS_GOOD;
case OPT_PAGE_HEIGHT:
*val_p = SCANNER_UNIT_TO_FIXED_MM(s->page_height);
return SANE_STATUS_GOOD;
case OPT_BRIGHTNESS:
*val_p = s->brightness;
return SANE_STATUS_GOOD;
case OPT_CONTRAST:
*val_p = s->contrast;
return SANE_STATUS_GOOD;
case OPT_GAMMA:
*val_p = SANE_FIX(s->gamma);
return SANE_STATUS_GOOD;
case OPT_THRESHOLD:
*val_p = s->threshold;
return SANE_STATUS_GOOD;
/* IPC */
case OPT_RIF:
*val_p = s->rif;
return SANE_STATUS_GOOD;
case OPT_HT_TYPE:
switch (s->ht_type) {
case WD_ht_type_DEFAULT:
strcpy (val, STRING_DEFAULT);
break;
case WD_ht_type_DITHER:
strcpy (val, STRING_DITHER);
break;
case WD_ht_type_DIFFUSION:
strcpy (val, STRING_DIFFUSION);
break;
}
return SANE_STATUS_GOOD;
case OPT_HT_PATTERN:
*val_p = s->ht_pattern;
return SANE_STATUS_GOOD;
case OPT_OUTLINE:
*val_p = s->outline;
return SANE_STATUS_GOOD;
case OPT_EMPHASIS:
*val_p = s->emphasis;
return SANE_STATUS_GOOD;
case OPT_SEPARATION:
*val_p = s->separation;
return SANE_STATUS_GOOD;
case OPT_MIRRORING:
*val_p = s->mirroring;
return SANE_STATUS_GOOD;
case OPT_WL_FOLLOW:
switch (s->wl_follow) {
case WD_wl_follow_DEFAULT:
strcpy (val, STRING_DEFAULT);
break;
case WD_wl_follow_ON:
strcpy (val, STRING_ON);
break;
case WD_wl_follow_OFF:
strcpy (val, STRING_OFF);
break;
}
return SANE_STATUS_GOOD;
/* DTC params*/
case OPT_BP_FILTER:
*val_p = s->bp_filter;
return SANE_STATUS_GOOD;
case OPT_SMOOTHING:
*val_p = s->smoothing;
return SANE_STATUS_GOOD;
case OPT_GAMMA_CURVE:
*val_p = s->gamma_curve;
return SANE_STATUS_GOOD;
case OPT_THRESHOLD_CURVE:
*val_p = s->threshold_curve;
return SANE_STATUS_GOOD;
case OPT_THRESHOLD_WHITE:
*val_p = s->threshold_white;
return SANE_STATUS_GOOD;
case OPT_NOISE_REMOVAL:
*val_p = s->noise_removal;
return SANE_STATUS_GOOD;
case OPT_MATRIX_5:
*val_p = s->matrix_5;
return SANE_STATUS_GOOD;
case OPT_MATRIX_4:
*val_p = s->matrix_4;
return SANE_STATUS_GOOD;
case OPT_MATRIX_3:
*val_p = s->matrix_3;
return SANE_STATUS_GOOD;
case OPT_MATRIX_2:
*val_p = s->matrix_2;
return SANE_STATUS_GOOD;
/* SDTC params*/
case OPT_VARIANCE:
*val_p = s->variance;
return SANE_STATUS_GOOD;
/* Advanced Group */
case OPT_AWD:
*val_p = s->awd;
return SANE_STATUS_GOOD;
case OPT_ALD:
*val_p = s->ald;
return SANE_STATUS_GOOD;
case OPT_COMPRESS:
if(s->compress == COMP_JPEG){
strcpy (val, STRING_JPEG);
}
else{
strcpy (val, STRING_NONE);
}
return SANE_STATUS_GOOD;
case OPT_COMPRESS_ARG:
*val_p = s->compress_arg;
return SANE_STATUS_GOOD;
case OPT_DF_ACTION:
switch (s->df_action) {
case DF_DEFAULT:
strcpy (val, STRING_DEFAULT);
break;
case DF_CONTINUE:
strcpy (val, STRING_CONTINUE);
break;
case DF_STOP:
strcpy (val, STRING_STOP);
break;
}
return SANE_STATUS_GOOD;
case OPT_DF_SKEW:
*val_p = s->df_skew;
return SANE_STATUS_GOOD;
case OPT_DF_THICKNESS:
*val_p = s->df_thickness;
return SANE_STATUS_GOOD;
case OPT_DF_LENGTH:
*val_p = s->df_length;
return SANE_STATUS_GOOD;
case OPT_DF_DIFF:
switch (s->df_diff) {
case MSEL_df_diff_DEFAULT:
strcpy (val, STRING_DEFAULT);
break;
case MSEL_df_diff_10MM:
strcpy (val, STRING_10MM);
break;
case MSEL_df_diff_15MM:
strcpy (val, STRING_15MM);
break;
case MSEL_df_diff_20MM:
strcpy (val, STRING_20MM);
break;
}
return SANE_STATUS_GOOD;
case OPT_DF_RECOVERY:
switch (s->df_recovery) {
case MSEL_DEFAULT:
strcpy (val, STRING_DEFAULT);
break;
case MSEL_ON:
strcpy (val, STRING_ON);
break;
case MSEL_OFF:
strcpy (val, STRING_OFF);
break;
}
return SANE_STATUS_GOOD;
case OPT_PAPER_PROTECT:
switch (s->paper_protect) {
case MSEL_DEFAULT:
strcpy (val, STRING_DEFAULT);
break;
case MSEL_ON:
strcpy (val, STRING_ON);
break;
case MSEL_OFF:
strcpy (val, STRING_OFF);
break;
}
return SANE_STATUS_GOOD;
case OPT_ADV_PAPER_PROT:
switch (s->adv_paper_prot) {
case MSEL_DEFAULT:
strcpy (val, STRING_DEFAULT);
break;
case MSEL_ON:
strcpy (val, STRING_ON);
break;
case MSEL_OFF:
strcpy (val, STRING_OFF);
break;
}
return SANE_STATUS_GOOD;
case OPT_STAPLE_DETECT:
switch (s->staple_detect) {
case MSEL_DEFAULT:
strcpy (val, STRING_DEFAULT);
break;
case MSEL_ON:
strcpy (val, STRING_ON);
break;
case MSEL_OFF:
strcpy (val, STRING_OFF);
break;
}
return SANE_STATUS_GOOD;
case OPT_BG_COLOR:
switch (s->bg_color) {
case COLOR_DEFAULT:
strcpy (val, STRING_DEFAULT);
break;
case COLOR_WHITE:
strcpy (val, STRING_WHITE);
break;
case COLOR_BLACK:
strcpy (val, STRING_BLACK);
break;
}
return SANE_STATUS_GOOD;
case OPT_DROPOUT_COLOR:
switch (s->dropout_color) {
case COLOR_DEFAULT:
strcpy (val, STRING_DEFAULT);
break;
case COLOR_RED:
strcpy (val, STRING_RED);
break;
case COLOR_GREEN:
strcpy (val, STRING_GREEN);
break;
case COLOR_BLUE:
strcpy (val, STRING_BLUE);
break;
}
return SANE_STATUS_GOOD;
case OPT_BUFF_MODE:
switch (s->buff_mode) {
case MSEL_DEFAULT:
strcpy (val, STRING_DEFAULT);
break;
case MSEL_ON:
strcpy (val, STRING_ON);
break;
case MSEL_OFF:
strcpy (val, STRING_OFF);
break;
}
return SANE_STATUS_GOOD;
case OPT_PREPICK:
switch (s->prepick) {
case MSEL_DEFAULT:
strcpy (val, STRING_DEFAULT);
break;
case MSEL_ON:
strcpy (val, STRING_ON);
break;
case MSEL_OFF:
strcpy (val, STRING_OFF);
break;
}
return SANE_STATUS_GOOD;
case OPT_OVERSCAN:
switch (s->overscan) {
case MSEL_DEFAULT:
strcpy (val, STRING_DEFAULT);
break;
case MSEL_ON:
strcpy (val, STRING_ON);
break;
case MSEL_OFF:
strcpy (val, STRING_OFF);
break;
}
return SANE_STATUS_GOOD;
case OPT_SLEEP_TIME:
*val_p = s->sleep_time;
return SANE_STATUS_GOOD;
case OPT_OFF_TIME:
*val_p = s->off_time;
return SANE_STATUS_GOOD;
case OPT_DUPLEX_OFFSET:
*val_p = s->duplex_offset;
return SANE_STATUS_GOOD;
case OPT_GREEN_OFFSET:
*val_p = s->green_offset;
return SANE_STATUS_GOOD;
case OPT_BLUE_OFFSET:
*val_p = s->blue_offset;
return SANE_STATUS_GOOD;
case OPT_LOW_MEM:
*val_p = s->low_mem;
return SANE_STATUS_GOOD;
case OPT_SIDE:
*val_p = s->side;
return SANE_STATUS_GOOD;
case OPT_HWDESKEWCROP:
*val_p = s->hwdeskewcrop;
return SANE_STATUS_GOOD;
case OPT_SWDESKEW:
*val_p = s->swdeskew;
return SANE_STATUS_GOOD;
case OPT_SWDESPECK:
*val_p = s->swdespeck;
return SANE_STATUS_GOOD;
case OPT_SWCROP:
*val_p = s->swcrop;
return SANE_STATUS_GOOD;
case OPT_SWSKIP:
*val_p = SANE_FIX(s->swskip);
return SANE_STATUS_GOOD;
case OPT_HALT_ON_CANCEL:
*val_p = s->halt_on_cancel;
return SANE_STATUS_GOOD;
/* Endorser Group */
case OPT_ENDORSER:
*val_p = s->u_endorser;
return SANE_STATUS_GOOD;
case OPT_ENDORSER_BITS:
*val_p = s->u_endorser_bits;
return SANE_STATUS_GOOD;
case OPT_ENDORSER_VAL:
*val_p = s->u_endorser_val;
return SANE_STATUS_GOOD;
case OPT_ENDORSER_STEP:
*val_p = s->u_endorser_step;
return SANE_STATUS_GOOD;
case OPT_ENDORSER_Y:
*val_p = SCANNER_UNIT_TO_FIXED_MM(s->u_endorser_y);
return SANE_STATUS_GOOD;
case OPT_ENDORSER_FONT:
switch (s->u_endorser_font) {
case FONT_H:
strcpy (val, STRING_HORIZONTAL);
break;
case FONT_HB:
strcpy (val, STRING_HORIZONTALBOLD);
break;
case FONT_HN:
strcpy (val, STRING_HORIZONTALNARROW);
break;
case FONT_V:
strcpy (val, STRING_VERTICAL);
break;
case FONT_VB:
strcpy (val, STRING_VERTICALBOLD);
break;
}
return SANE_STATUS_GOOD;
case OPT_ENDORSER_DIR:
switch (s->u_endorser_dir) {
case DIR_TTB:
strcpy (val, STRING_TOPTOBOTTOM);
break;
case DIR_BTT:
strcpy (val, STRING_BOTTOMTOTOP);
break;
}
return SANE_STATUS_GOOD;
case OPT_ENDORSER_SIDE:
switch (s->u_endorser_side) {
case ED_front:
strcpy (val, STRING_FRONT);
break;
case ED_back:
strcpy (val, STRING_BACK);
break;
}
return SANE_STATUS_GOOD;
case OPT_ENDORSER_STRING:
strncpy(
(SANE_String)val,
(SANE_String)s->u_endorser_string,
s->endorser_string_len+1
);
return SANE_STATUS_GOOD;
/* Sensor Group */
case OPT_TOP:
ret = get_hardware_status(s,option);
*val_p = s->hw_top;
return ret;
case OPT_A3:
ret = get_hardware_status(s,option);
*val_p = s->hw_A3;
return ret;
case OPT_B4:
ret = get_hardware_status(s,option);
*val_p = s->hw_B4;
return ret;
case OPT_A4:
ret = get_hardware_status(s,option);
*val_p = s->hw_A4;
return ret;
case OPT_B5:
ret = get_hardware_status(s,option);
*val_p = s->hw_B5;
return ret;
case OPT_HOPPER:
ret = get_hardware_status(s,option);
*val_p = s->hw_hopper;
return ret;
case OPT_OMR:
ret = get_hardware_status(s,option);
*val_p = s->hw_omr;
return ret;
case OPT_ADF_OPEN:
ret = get_hardware_status(s,option);
*val_p = s->hw_adf_open;
return ret;
case OPT_SLEEP:
ret = get_hardware_status(s,option);
*val_p = s->hw_sleep;
return ret;
case OPT_SEND_SW:
ret = get_hardware_status(s,option);
*val_p = s->hw_send_sw;
return ret;
case OPT_MANUAL_FEED:
ret = get_hardware_status(s,option);
*val_p = s->hw_manual_feed;
return ret;
case OPT_SCAN_SW:
ret = get_hardware_status(s,option);
*val_p = s->hw_scan_sw;
return ret;
case OPT_FUNCTION:
ret = get_hardware_status(s,option);
*val_p = s->hw_function;
return ret;
case OPT_INK_EMPTY:
ret = get_hardware_status(s,option);
*val_p = s->hw_ink_empty;
return ret;
case OPT_DOUBLE_FEED:
ret = get_hardware_status(s,option);
*val_p = s->hw_double_feed;
return ret;
case OPT_ERROR_CODE:
ret = get_hardware_status(s,option);
*val_p = s->hw_error_code;
return ret;
case OPT_SKEW_ANGLE:
ret = get_hardware_status(s,option);
*val_p = s->hw_skew_angle;
return ret;
case OPT_INK_REMAIN:
ret = get_hardware_status(s,option);
*val_p = s->hw_ink_remain;
return ret;
case OPT_DENSITY_SW:
ret = get_hardware_status(s,option);
*val_p = s->hw_density_sw;
return ret;
case OPT_DUPLEX_SW:
ret = get_hardware_status(s,option);
*val_p = s->hw_duplex_sw;
return ret;
}
}
else if (action == SANE_ACTION_SET_VALUE) {
int tmp;
SANE_Word val_c;
SANE_Status status;
DBG (20, "sane_control_option: set value for '%s' (%d)\n", s->opt[option].name,option);
if ( s->started ) {
DBG (5, "sane_control_option: cant set, device busy\n");
return SANE_STATUS_DEVICE_BUSY;
}
if (!SANE_OPTION_IS_SETTABLE (s->opt[option].cap)) {
DBG (5, "sane_control_option: not settable\n");
return SANE_STATUS_INVAL;
}
status = sanei_constrain_value (s->opt + option, val, info);
if (status != SANE_STATUS_GOOD) {
DBG (5, "sane_control_option: bad value\n");
return status;
}
/* may have been changed by constrain, so dont copy until now */
val_c = *(SANE_Word *)val;
/*
* Note - for those options which can assume one of a list of
* valid values, we can safely assume that they will have
* exactly one of those values because that's what
* sanei_constrain_value does. Hence no "else: invalid" branches
* below.
*/
switch (option) {
/* Mode Group */
case OPT_SOURCE:
if (!strcmp (val, STRING_ADFFRONT)) {
tmp = SOURCE_ADF_FRONT;
}
else if (!strcmp (val, STRING_ADFBACK)) {
tmp = SOURCE_ADF_BACK;
}
else if (!strcmp (val, STRING_ADFDUPLEX)) {
tmp = SOURCE_ADF_DUPLEX;
}
else{
tmp = SOURCE_FLATBED;
}
if (s->source == tmp)
return SANE_STATUS_GOOD;
s->source = tmp;
*info |= SANE_INFO_RELOAD_PARAMS | SANE_INFO_RELOAD_OPTIONS;
return SANE_STATUS_GOOD;
case OPT_MODE:
if (!strcmp (val, STRING_LINEART)) {
tmp = MODE_LINEART;
}
else if (!strcmp (val, STRING_HALFTONE)) {
tmp = MODE_HALFTONE;
}
else if (!strcmp (val, STRING_GRAYSCALE)) {
tmp = MODE_GRAYSCALE;
}
else{
tmp = MODE_COLOR;
}
if (tmp == s->u_mode)
return SANE_STATUS_GOOD;
set_mode(s,tmp);
*info |= SANE_INFO_RELOAD_PARAMS | SANE_INFO_RELOAD_OPTIONS;
return SANE_STATUS_GOOD;
case OPT_RES:
if (s->resolution_x == val_c)
return SANE_STATUS_GOOD;
s->resolution_x = val_c;
s->resolution_y = val_c;
set_max_y(s);
*info |= SANE_INFO_RELOAD_PARAMS | SANE_INFO_RELOAD_OPTIONS;
return SANE_STATUS_GOOD;
/* Geometry Group */
case OPT_TL_X:
if (s->tl_x == FIXED_MM_TO_SCANNER_UNIT(val_c))
return SANE_STATUS_GOOD;
s->tl_x = FIXED_MM_TO_SCANNER_UNIT(val_c);
*info |= SANE_INFO_RELOAD_PARAMS | SANE_INFO_RELOAD_OPTIONS;
return SANE_STATUS_GOOD;
case OPT_TL_Y:
if (s->tl_y == FIXED_MM_TO_SCANNER_UNIT(val_c))
return SANE_STATUS_GOOD;
s->tl_y = FIXED_MM_TO_SCANNER_UNIT(val_c);
*info |= SANE_INFO_RELOAD_PARAMS | SANE_INFO_RELOAD_OPTIONS;
return SANE_STATUS_GOOD;
case OPT_BR_X:
if (s->br_x == FIXED_MM_TO_SCANNER_UNIT(val_c))
return SANE_STATUS_GOOD;
s->br_x = FIXED_MM_TO_SCANNER_UNIT(val_c);
*info |= SANE_INFO_RELOAD_PARAMS | SANE_INFO_RELOAD_OPTIONS;
return SANE_STATUS_GOOD;
case OPT_BR_Y:
if (s->br_y == FIXED_MM_TO_SCANNER_UNIT(val_c))
return SANE_STATUS_GOOD;
s->br_y = FIXED_MM_TO_SCANNER_UNIT(val_c);
*info |= SANE_INFO_RELOAD_PARAMS | SANE_INFO_RELOAD_OPTIONS;
return SANE_STATUS_GOOD;
case OPT_PAGE_WIDTH:
if (s->page_width == FIXED_MM_TO_SCANNER_UNIT(val_c))
return SANE_STATUS_GOOD;
/* if full width image, and paper size is changed,
change the image size to match new paper */
if (s->tl_x == 0 && s->br_x == s->page_width){
DBG (20, "sane_control_option: br_x tracking page_width\n");
s->br_x = FIXED_MM_TO_SCANNER_UNIT(val_c);
*info |= SANE_INFO_RELOAD_PARAMS;
}
s->page_width = FIXED_MM_TO_SCANNER_UNIT(val_c);
*info |= SANE_INFO_RELOAD_OPTIONS;
return SANE_STATUS_GOOD;
case OPT_PAGE_HEIGHT:
if (s->page_height == FIXED_MM_TO_SCANNER_UNIT(val_c))
return SANE_STATUS_GOOD;
/* if full height image, and paper size is changed,
change the image size to match new paper */
if (s->tl_y == 0 && s->br_y == s->page_height){
DBG (20, "sane_control_option: br_y tracking page_height\n");
s->br_y = FIXED_MM_TO_SCANNER_UNIT(val_c);
*info |= SANE_INFO_RELOAD_PARAMS;
}
s->page_height = FIXED_MM_TO_SCANNER_UNIT(val_c);
*info |= SANE_INFO_RELOAD_OPTIONS;
return SANE_STATUS_GOOD;
/* Enhancement Group */
case OPT_BRIGHTNESS:
s->brightness = val_c;
return SANE_STATUS_GOOD;
case OPT_CONTRAST:
s->contrast = val_c;
return SANE_STATUS_GOOD;
case OPT_GAMMA:
s->gamma = SANE_UNFIX(val_c);
return SANE_STATUS_GOOD;
case OPT_THRESHOLD:
s->threshold = val_c;
return SANE_STATUS_GOOD;
/* IPC */
case OPT_RIF:
s->rif = val_c;
return SANE_STATUS_GOOD;
case OPT_HT_TYPE:
if (!strcmp(val, STRING_DEFAULT))
s->ht_type = WD_ht_type_DEFAULT;
else if (!strcmp(val, STRING_DITHER))
s->ht_type = WD_ht_type_DITHER;
else if (!strcmp(val, STRING_DIFFUSION))
s->ht_type = WD_ht_type_DIFFUSION;
return SANE_STATUS_GOOD;
case OPT_HT_PATTERN:
s->ht_pattern = val_c;
return SANE_STATUS_GOOD;
case OPT_OUTLINE:
s->outline = val_c;
return SANE_STATUS_GOOD;
case OPT_EMPHASIS:
s->emphasis = val_c;
return SANE_STATUS_GOOD;
case OPT_SEPARATION:
s->separation = val_c;
return SANE_STATUS_GOOD;
case OPT_MIRRORING:
s->mirroring = val_c;
return SANE_STATUS_GOOD;
case OPT_WL_FOLLOW:
if (!strcmp(val, STRING_DEFAULT))
s->wl_follow = WD_wl_follow_DEFAULT;
else if (!strcmp(val, STRING_ON))
s->wl_follow = WD_wl_follow_ON;
else if (!strcmp(val, STRING_OFF))
s->wl_follow = WD_wl_follow_OFF;
return SANE_STATUS_GOOD;
/* DTC params*/
case OPT_BP_FILTER:
s->bp_filter = val_c;
*info |= SANE_INFO_RELOAD_OPTIONS;
return SANE_STATUS_GOOD;
case OPT_SMOOTHING:
s->smoothing = val_c;
*info |= SANE_INFO_RELOAD_OPTIONS;
return SANE_STATUS_GOOD;
case OPT_GAMMA_CURVE:
s->gamma_curve = val_c;
*info |= SANE_INFO_RELOAD_OPTIONS;
return SANE_STATUS_GOOD;
case OPT_THRESHOLD_CURVE:
s->threshold_curve = val_c;
*info |= SANE_INFO_RELOAD_OPTIONS;
return SANE_STATUS_GOOD;
case OPT_THRESHOLD_WHITE:
s->threshold_white = val_c;
*info |= SANE_INFO_RELOAD_OPTIONS;
return SANE_STATUS_GOOD;
case OPT_NOISE_REMOVAL:
s->noise_removal = val_c;
*info |= SANE_INFO_RELOAD_OPTIONS;
return SANE_STATUS_GOOD;
case OPT_MATRIX_5:
s->matrix_5 = val_c;
return SANE_STATUS_GOOD;
case OPT_MATRIX_4:
s->matrix_4 = val_c;
return SANE_STATUS_GOOD;
case OPT_MATRIX_3:
s->matrix_3 = val_c;
return SANE_STATUS_GOOD;
case OPT_MATRIX_2:
s->matrix_2 = val_c;
return SANE_STATUS_GOOD;
/* SDTC params*/
case OPT_VARIANCE:
s->variance = val_c;
*info |= SANE_INFO_RELOAD_OPTIONS;
return SANE_STATUS_GOOD;
/* Advanced Group */
case OPT_AWD:
s->awd = val_c;
*info |= SANE_INFO_RELOAD_OPTIONS;
return SANE_STATUS_GOOD;
case OPT_ALD:
s->ald = val_c;
*info |= SANE_INFO_RELOAD_OPTIONS;
return SANE_STATUS_GOOD;
case OPT_COMPRESS:
if (!strcmp (val, STRING_JPEG)) {
tmp = COMP_JPEG;
}
else{
tmp = COMP_NONE;
}
if (tmp == s->compress)
return SANE_STATUS_GOOD;
s->compress = tmp;
return SANE_STATUS_GOOD;
case OPT_COMPRESS_ARG:
s->compress_arg = val_c;
return SANE_STATUS_GOOD;
case OPT_DF_ACTION:
if (!strcmp(val, STRING_DEFAULT))
s->df_action = DF_DEFAULT;
else if (!strcmp(val, STRING_CONTINUE))
s->df_action = DF_CONTINUE;
else if (!strcmp(val, STRING_STOP))
s->df_action = DF_STOP;
*info |= SANE_INFO_RELOAD_OPTIONS;
return SANE_STATUS_GOOD;
case OPT_DF_SKEW:
s->df_skew = val_c;
return SANE_STATUS_GOOD;
case OPT_DF_THICKNESS:
s->df_thickness = val_c;
return SANE_STATUS_GOOD;
case OPT_DF_LENGTH:
s->df_length = val_c;
return SANE_STATUS_GOOD;
case OPT_DF_DIFF:
if (!strcmp(val, STRING_DEFAULT))
s->df_diff = MSEL_df_diff_DEFAULT;
else if (!strcmp(val, STRING_10MM))
s->df_diff = MSEL_df_diff_10MM;
else if (!strcmp(val, STRING_15MM))
s->df_diff = MSEL_df_diff_15MM;
else if (!strcmp(val, STRING_20MM))
s->df_diff = MSEL_df_diff_20MM;
return SANE_STATUS_GOOD;
case OPT_DF_RECOVERY:
if (!strcmp(val, STRING_DEFAULT))
s->df_recovery = MSEL_DEFAULT;
else if (!strcmp(val, STRING_ON))
s->df_recovery = MSEL_ON;
else if (!strcmp(val, STRING_OFF))
s->df_recovery = MSEL_OFF;
return SANE_STATUS_GOOD;
case OPT_PAPER_PROTECT:
if (!strcmp(val, STRING_DEFAULT))
s->paper_protect = MSEL_DEFAULT;
else if (!strcmp(val, STRING_ON))
s->paper_protect = MSEL_ON;
else if (!strcmp(val, STRING_OFF))
s->paper_protect = MSEL_OFF;
return SANE_STATUS_GOOD;
case OPT_ADV_PAPER_PROT:
if (!strcmp(val, STRING_DEFAULT))
s->adv_paper_prot = MSEL_DEFAULT;
else if (!strcmp(val, STRING_ON))
s->adv_paper_prot = MSEL_ON;
else if (!strcmp(val, STRING_OFF))
s->adv_paper_prot = MSEL_OFF;
return SANE_STATUS_GOOD;
case OPT_STAPLE_DETECT:
if (!strcmp(val, STRING_DEFAULT))
s->staple_detect = MSEL_DEFAULT;
else if (!strcmp(val, STRING_ON))
s->staple_detect = MSEL_ON;
else if (!strcmp(val, STRING_OFF))
s->staple_detect = MSEL_OFF;
return SANE_STATUS_GOOD;
case OPT_BG_COLOR:
if (!strcmp(val, STRING_DEFAULT))
s->bg_color = COLOR_DEFAULT;
else if (!strcmp(val, STRING_WHITE))
s->bg_color = COLOR_WHITE;
else if (!strcmp(val, STRING_BLACK))
s->bg_color = COLOR_BLACK;
return SANE_STATUS_GOOD;
case OPT_DROPOUT_COLOR:
if (!strcmp(val, STRING_DEFAULT))
s->dropout_color = COLOR_DEFAULT;
else if (!strcmp(val, STRING_RED))
s->dropout_color = COLOR_RED;
else if (!strcmp(val, STRING_GREEN))
s->dropout_color = COLOR_GREEN;
else if (!strcmp(val, STRING_BLUE))
s->dropout_color = COLOR_BLUE;
return SANE_STATUS_GOOD;
case OPT_BUFF_MODE:
if (!strcmp(val, STRING_DEFAULT))
s->buff_mode = MSEL_DEFAULT;
else if (!strcmp(val, STRING_ON))
s->buff_mode= MSEL_ON;
else if (!strcmp(val, STRING_OFF))
s->buff_mode= MSEL_OFF;
return SANE_STATUS_GOOD;
case OPT_PREPICK:
if (!strcmp(val, STRING_DEFAULT))
s->prepick = MSEL_DEFAULT;
else if (!strcmp(val, STRING_ON))
s->prepick = MSEL_ON;
else if (!strcmp(val, STRING_OFF))
s->prepick = MSEL_OFF;
return SANE_STATUS_GOOD;
case OPT_OVERSCAN:
if (!strcmp(val, STRING_DEFAULT))
s->overscan = MSEL_DEFAULT;
else if (!strcmp(val, STRING_ON))
s->overscan = MSEL_ON;
else if (!strcmp(val, STRING_OFF))
s->overscan = MSEL_OFF;
*info |= SANE_INFO_RELOAD_OPTIONS;
return SANE_STATUS_GOOD;
case OPT_SLEEP_TIME:
s->sleep_time = val_c;
return set_sleep_mode(s);
case OPT_OFF_TIME:
/* do our own constrain, because we want to round up */
s->off_time = (val_c + 14)/15*15;
if(s->off_time != val_c){
*info |= SANE_INFO_INEXACT;
}
return set_off_mode(s);
case OPT_DUPLEX_OFFSET:
s->duplex_offset = val_c;
return SANE_STATUS_GOOD;
case OPT_GREEN_OFFSET:
s->green_offset = val_c;
return SANE_STATUS_GOOD;
case OPT_BLUE_OFFSET:
s->blue_offset = val_c;
return SANE_STATUS_GOOD;
case OPT_LOW_MEM:
s->low_mem = val_c;
return SANE_STATUS_GOOD;
case OPT_HWDESKEWCROP:
s->hwdeskewcrop = val_c;
return SANE_STATUS_GOOD;
case OPT_SWDESKEW:
s->swdeskew = val_c;
return SANE_STATUS_GOOD;
case OPT_SWDESPECK:
s->swdespeck = val_c;
return SANE_STATUS_GOOD;
case OPT_SWCROP:
s->swcrop = val_c;
return SANE_STATUS_GOOD;
case OPT_SWSKIP:
s->swskip = SANE_UNFIX(val_c);
return SANE_STATUS_GOOD;
case OPT_HALT_ON_CANCEL:
s->halt_on_cancel = val_c;
return SANE_STATUS_GOOD;
/* Endorser Group */
case OPT_ENDORSER:
s->u_endorser = val_c;
*info |= SANE_INFO_RELOAD_OPTIONS;
return SANE_STATUS_GOOD;
case OPT_ENDORSER_BITS:
s->u_endorser_bits = val_c;
return SANE_STATUS_GOOD;
/*this val not used in send_endorser*/
case OPT_ENDORSER_VAL:
s->u_endorser_val = val_c;
return SANE_STATUS_GOOD;
case OPT_ENDORSER_STEP:
s->u_endorser_step = val_c;
return SANE_STATUS_GOOD;
case OPT_ENDORSER_Y:
s->u_endorser_y = FIXED_MM_TO_SCANNER_UNIT(val_c);
return SANE_STATUS_GOOD;
case OPT_ENDORSER_FONT:
if (!strcmp (val, STRING_HORIZONTAL)){
s->u_endorser_font = FONT_H;
}
else if (!strcmp (val, STRING_HORIZONTALBOLD)){
s->u_endorser_font = FONT_HB;
}
else if (!strcmp (val, STRING_HORIZONTALNARROW)){
s->u_endorser_font = FONT_HN;
}
else if (!strcmp (val, STRING_VERTICAL)){
s->u_endorser_font = FONT_V;
}
else if (!strcmp (val, STRING_VERTICALBOLD)){
s->u_endorser_font = FONT_VB;
}
return SANE_STATUS_GOOD;
case OPT_ENDORSER_DIR:
if (!strcmp (val, STRING_TOPTOBOTTOM)){
s->u_endorser_dir = DIR_TTB;
}
else if (!strcmp (val, STRING_BOTTOMTOTOP)){
s->u_endorser_dir = DIR_BTT;
}
return SANE_STATUS_GOOD;
/*this val not used in send_endorser*/
case OPT_ENDORSER_SIDE:
if (!strcmp (val, STRING_FRONT)){
s->u_endorser_side = ED_front;
}
else if (!strcmp (val, STRING_BACK)){
s->u_endorser_side = ED_back;
}
return SANE_STATUS_GOOD;
case OPT_ENDORSER_STRING:
strncpy(
(SANE_String)s->u_endorser_string,
(SANE_String)val,
s->endorser_string_len+1
);
return SANE_STATUS_GOOD;
} /* switch */
} /* else */
return SANE_STATUS_INVAL;
}
static SANE_Status
set_sleep_mode(struct fujitsu *s)
{
SANE_Status ret = SANE_STATUS_GOOD;
unsigned char cmd[MODE_SELECT_len];
size_t cmdLen = MODE_SELECT_len;
unsigned char out[MSEL_header_len + MSEL_data_min_len];
size_t outLen = MSEL_header_len + MSEL_data_min_len;
unsigned char * page = out+MSEL_header_len;
DBG (10, "set_sleep_mode: start\n");
memset(cmd,0,cmdLen);
set_SCSI_opcode(cmd, MODE_SELECT_code);
set_MSEL_pf(cmd, 1);
set_MSEL_xferlen(cmd, outLen);
memset(out,0,outLen);
set_MSEL_pc(page, MS_pc_sleep);
set_MSEL_page_len(page, MSEL_data_min_len-2);
set_MSEL_sleep_mode(page, s->sleep_time);
ret = do_cmd (
s, 1, 0,
cmd, cmdLen,
out, outLen,
NULL, NULL
);
DBG (10, "set_sleep_mode: finish\n");
return ret;
}
static SANE_Status
set_off_mode(struct fujitsu *s)
{
SANE_Status ret = SANE_STATUS_GOOD;
unsigned char cmd[SEND_DIAGNOSTIC_len]; /*also big enough for READ_DIAG*/
size_t cmdLen = SEND_DIAGNOSTIC_len;
unsigned char out[SD_powoff_len];
size_t outLen = SD_powoff_len;
DBG (10, "set_off_mode: start\n");
if (!s->has_cmd_sdiag || !s->has_cmd_rdiag || !s->has_off_mode){
DBG (5, "set_off_mode: not supported, returning\n");
return ret;
}
memset(cmd,0,cmdLen);
set_SCSI_opcode(cmd, SEND_DIAGNOSTIC_code);
set_SD_slftst(cmd, 0);
set_SD_xferlen(cmd, outLen);
memcpy(out,SD_powoff_string,SD_powoff_stringlen);
set_SD_powoff_disable(out,!s->off_time);
set_SD_powoff_interval(out,s->off_time/15);
ret = do_cmd (
s, 1, 0,
cmd, cmdLen,
out, outLen,
NULL, NULL
);
if (ret != SANE_STATUS_GOOD){
DBG (5, "set_off_mode: send diag error: %d\n", ret);
return ret;
}
DBG (10, "set_off_mode: finish\n");
return SANE_STATUS_GOOD;
}
static SANE_Status
get_hardware_status (struct fujitsu *s, SANE_Int option)
{
SANE_Status ret = SANE_STATUS_GOOD;
DBG (10, "get_hardware_status: start\n");
/* only run this if frontend has already read the last time we got it */
/* or if we don't care for such bookkeeping (private use) */
if (!option || s->hw_read[option-OPT_TOP]) {
DBG (15, "get_hardware_status: running\n");
/* mark all values as unread */
memset(s->hw_read,0,sizeof(s->hw_read));
if (s->has_cmd_hw_status){
unsigned char cmd[GET_HW_STATUS_len];
size_t cmdLen = GET_HW_STATUS_len;
unsigned char in[GHS_data_len];
size_t inLen = GHS_data_len;
memset(cmd,0,cmdLen);
set_SCSI_opcode(cmd, GET_HW_STATUS_code);
set_GHS_allocation_length(cmd, inLen);
DBG (15, "get_hardware_status: calling ghs\n");
ret = do_cmd (
s, 1, 0,
cmd, cmdLen,
NULL, 0,
in, &inLen
);
if (ret == SANE_STATUS_GOOD || ret == SANE_STATUS_EOF) {
s->hw_top = get_GHS_top(in);
s->hw_A3 = get_GHS_A3(in);
s->hw_B4 = get_GHS_B4(in);
s->hw_A4 = get_GHS_A4(in);
s->hw_B5 = get_GHS_B5(in);
s->hw_hopper = get_GHS_hopper(in);
s->hw_omr = get_GHS_omr(in);
s->hw_adf_open = get_GHS_adf_open(in);
s->hw_sleep = get_GHS_sleep(in);
s->hw_send_sw = get_GHS_send_sw(in);
s->hw_manual_feed = get_GHS_manual_feed(in);
s->hw_scan_sw = get_GHS_scan_sw(in);
s->hw_function = get_GHS_function(in);
s->hw_ink_empty = get_GHS_ink_empty(in);
s->hw_double_feed = get_GHS_double_feed(in);
s->hw_error_code = get_GHS_error_code(in);
s->hw_skew_angle = get_GHS_skew_angle(in);
if(inLen > 9){
s->hw_ink_remain = get_GHS_ink_remain(in);
}
ret = SANE_STATUS_GOOD;
}
}
/* 3091/2 put hardware status in RS data */
else if (s->ghs_in_rs){
unsigned char cmd[REQUEST_SENSE_len];
size_t cmdLen = REQUEST_SENSE_len;
unsigned char in[RS_return_size];
size_t inLen = RS_return_size;
memset(cmd,0,cmdLen);
set_SCSI_opcode(cmd, REQUEST_SENSE_code);
set_RS_return_size(cmd, inLen);
DBG(15,"get_hardware_status: calling rs\n");
ret = do_cmd(
s,0,0,
cmd, cmdLen,
NULL,0,
in, &inLen
);
/* parse the rs data */
if(ret == SANE_STATUS_GOOD){
if(get_RS_sense_key(in)==0 && get_RS_ASC(in)==0x80){
s->hw_adf_open = get_RS_adf_open(in);
s->hw_send_sw = get_RS_send_sw(in);
s->hw_scan_sw = get_RS_scan_sw(in);
s->hw_duplex_sw = get_RS_duplex_sw(in);
s->hw_top = get_RS_top(in);
s->hw_hopper = get_RS_hopper(in);
s->hw_function = get_RS_function(in);
s->hw_density_sw = get_RS_density(in);
}
else{
DBG (10, "get_hardware_status: unexpected RS values\n");
}
}
}
}
if(option)
s->hw_read[option-OPT_TOP] = 1;
DBG (10, "get_hardware_status: finish\n");
return ret;
}
static SANE_Status
send_endorser(struct fujitsu *s)
{
SANE_Status ret = SANE_STATUS_GOOD;
unsigned char cmd[SEND_len];
size_t cmdLen = SEND_len;
size_t strLen = strlen(s->u_endorser_string);
unsigned char out[S_e_data_max_len]; /*we probably send less below*/
size_t outLen = S_e_data_min_len + strLen; /*fi-5900 might want 1 more byte?*/
DBG (10, "send_endorser: start\n");
if (!s->has_endorser_f && !s->has_endorser_b){
DBG (10, "send_endorser: unsupported\n");
return ret;
}
/*build the payload*/
memset(out,0,outLen);
/*fi-5900 front side uses 0x80, assume all others*/
if(s->u_endorser_side == ED_front){
set_S_endorser_data_id(out,0x80);
}
else{
set_S_endorser_data_id(out,0);
}
set_S_endorser_stamp(out,0);
set_S_endorser_elec(out,0);
if(s->u_endorser_step < 0){
set_S_endorser_decr(out,S_e_decr_dec);
}
else{
set_S_endorser_decr(out,S_e_decr_inc);
}
if(s->u_endorser_bits == 24){
set_S_endorser_lap24(out,S_e_lap_24bit);
}
else{
set_S_endorser_lap24(out,S_e_lap_16bit);
}
set_S_endorser_ctstep(out,abs(s->u_endorser_step));
set_S_endorser_ulx(out,0);
set_S_endorser_uly(out,s->u_endorser_y);
switch (s->u_endorser_font) {
case FONT_H:
set_S_endorser_font(out,S_e_font_horiz);
set_S_endorser_bold(out,0);
break;
case FONT_HB:
set_S_endorser_font(out,S_e_font_horiz);
set_S_endorser_bold(out,1);
break;
case FONT_HN:
set_S_endorser_font(out,S_e_font_horiz_narrow);
set_S_endorser_bold(out,0);
break;
case FONT_V:
set_S_endorser_font(out,S_e_font_vert);
set_S_endorser_bold(out,0);
break;
case FONT_VB:
set_S_endorser_font(out,S_e_font_vert);
set_S_endorser_bold(out,1);
break;
}
set_S_endorser_size(out,0);
set_S_endorser_revs(out,0);
if(s->u_endorser_dir == DIR_BTT){
set_S_endorser_dirs(out,S_e_dir_bottom_top);
}
else{
set_S_endorser_dirs(out,S_e_dir_top_bottom);
}
set_S_endorser_string_length(out, strLen);
set_S_endorser_string(out, s->u_endorser_string, strLen);
/*build the command*/
memset(cmd,0,cmdLen);
set_SCSI_opcode(cmd, SEND_code);
set_S_xfer_datatype (cmd, S_datatype_endorser_data);
set_S_xfer_length (cmd, outLen);
ret = do_cmd (
s, 1, 0,
cmd, cmdLen,
out, outLen,
NULL, NULL
);
DBG (10, "send_endorser: finish %d\n", ret);
return ret;
}
/* instead of internal brightness/contrast/gamma
most scanners use a 256x256 or 1024x256 LUT
default is linear table of slope 1 or 1/4 resp.
brightness and contrast inputs are -127 to +127
contrast rotates slope of line around central input val
high low
. x .
. x . xx
out . x . xxxxxxxx
. x xx
....x....... ............
in in
then brightness moves line vertically, and clamps to 8bit
bright dark
. xxxxxxxx .
. x .
out x . x
. . x
............ xxxxxxxx....
in in
*/
static SANE_Status
send_lut (struct fujitsu *s)
{
int i, j, bytes = 1 << s->adbits;
double b, slope, offset;
SANE_Status ret = SANE_STATUS_GOOD;
unsigned char cmd[SEND_len];
size_t cmdLen = SEND_len;
unsigned char out[S_lut_header_len + S_lut_data_max_len];
size_t outLen = S_lut_header_len + S_lut_data_max_len;
unsigned char * p = out + S_lut_header_len;
DBG (10, "send_lut: start\n");
if(!s->num_download_gamma || !s->adbits){
DBG (10, "send_lut: unsupported\n");
return ret;
}
/* contrast is converted to a slope [0,90] degrees:
* first [-127,127] to [0,254] then to [0,1]
* then multiply by PI/2 to convert to radians
* then take the tangent to get slope (T.O.A)
* then multiply by the normal linear slope
* because the table may not be square, i.e. 1024x256*/
slope = tan(((double)s->contrast+127)/254 * M_PI/2) * 256/bytes;
/* contrast slope must stay centered, so figure
* out vertical offset at central input value */
offset = 127.5-(slope*bytes/2);
/* convert the user brightness setting (-127 to +127)
* into a scale that covers the range required
* to slide the contrast curve entirely off the table */
b = ((double)s->brightness/127) * (256 - offset);
DBG (15, "send_lut: %d %f %d %f %f\n", s->brightness, b,
s->contrast, slope, offset);
outLen = S_lut_header_len + bytes;
memset(cmd,0,cmdLen);
set_SCSI_opcode(cmd, SEND_code);
set_S_xfer_datatype (cmd, S_datatype_lut_data);
set_S_xfer_length (cmd, outLen);
memset(out,0,outLen);
set_S_lut_order (out, S_lut_order_single);
set_S_lut_ssize (out, bytes);
set_S_lut_dsize (out, 256);
for(i=0;i<bytes;i++){
j=slope*i + offset + b;
if(j<0){
j=0;
}
if(j>255){
j=255;
}
*p=j;
p++;
}
ret = do_cmd (
s, 1, 0,
cmd, cmdLen,
out, outLen,
NULL, NULL
);
DBG (10, "send_lut: finish\n");
return ret;
}
static SANE_Status
send_q_table (struct fujitsu *s)
{
SANE_Status ret = SANE_STATUS_GOOD;
unsigned char cmd[SEND_len];
size_t cmdLen = SEND_len;
unsigned char out[S_q_table_header_len + S_q_table_y_len + S_q_table_uv_len];
size_t outLen = S_q_table_header_len + S_q_table_y_len + S_q_table_uv_len;
unsigned char * yp = out + S_q_table_header_len;
unsigned char * uvp = out + S_q_table_header_len + S_q_table_y_len;
/* FIXME: generate these instead of hardcode */
unsigned char ydata[] = {
0x04, 0x03, 0x03, 0x04, 0x03, 0x03, 0x04, 0x04,
0x03, 0x04, 0x05, 0x05, 0x04, 0x05, 0x07, 0x0c,
0x07, 0x07, 0x06, 0x06, 0x07, 0x0e, 0x0a, 0x0b,
0x08, 0x0c, 0x11, 0x0f, 0x12, 0x12, 0x11, 0x0f,
0x10, 0x10, 0x13, 0x15, 0x1b, 0x17, 0x13, 0x14,
0x1a, 0x14, 0x10, 0x10, 0x18, 0x20, 0x18, 0x1a,
0x1c, 0x1d, 0x1e, 0x1f, 0x1e, 0x12, 0x17, 0x21,
0x24, 0x21, 0x1e, 0x24, 0x1b, 0x1e, 0x1e, 0x1d };
unsigned char uvdata[] = {
0x05, 0x05, 0x05, 0x07, 0x06, 0x07, 0x0e, 0x07,
0x07, 0x0e, 0x1d, 0x13, 0x10, 0x13, 0x1d, 0x1d,
0x1d, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d,
0x1d, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d,
0x1d, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d,
0x1d, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d,
0x1d, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d,
0x1d, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d };
DBG (10, "send_q_table: start\n");
memset(cmd,0,cmdLen);
set_SCSI_opcode(cmd, SEND_code);
set_S_xfer_datatype (cmd, S_datatype_jpg_q_table);
set_S_xfer_length (cmd, outLen);
memset(out,0,outLen);
set_S_q_table_y_len (out, S_q_table_y_len);
set_S_q_table_uv_len (out, S_q_table_uv_len);
memcpy (yp, ydata, S_q_table_y_len);
memcpy (uvp, uvdata, S_q_table_uv_len);
ret = do_cmd (
s, 1, 0,
cmd, cmdLen,
out, outLen,
NULL, NULL
);
DBG (10, "send_q_table: finish\n");
return ret;
}
/* only used by iX500? */
#if 0
static SANE_Status
mode_select_unk (struct fujitsu *s, int foo)
{
SANE_Status ret = SANE_STATUS_GOOD;
unsigned char cmd[MODE_SELECT_len];
size_t cmdLen = MODE_SELECT_len;
unsigned char out[MSEL_header_len + MSEL_data_min_len];
size_t outLen = MSEL_header_len + MSEL_data_min_len;
unsigned char * page = out+MSEL_header_len;
DBG (10, "mode_select_unk: start\n");
/*if (!s->has_MS_unk){
DBG (10, "mode_select_unk: unsupported\n");
return SANE_STATUS_GOOD;
}*/
memset(cmd,0,cmdLen);
set_SCSI_opcode(cmd, MODE_SELECT_code);
set_MSEL_pf(cmd, 1);
set_MSEL_xferlen(cmd, outLen);
memset(out,0,outLen);
set_MSEL_pc(page, MS_pc_unk);
set_MSEL_page_len(page, MSEL_data_min_len-2);
*(page + 0x02) = foo;
ret = do_cmd (
s, 1, 0,
cmd, cmdLen,
out, outLen,
NULL, NULL
);
DBG (10, "mode_select_unk: finish\n");
return ret;
}
#endif
/* only used by iX500? */
static SANE_Status
diag_preread (struct fujitsu *s)
{
SANE_Status ret = SANE_STATUS_GOOD;
unsigned char cmd[SEND_DIAGNOSTIC_len]; /*also big enough for READ_DIAG*/
size_t cmdLen = SEND_DIAGNOSTIC_len;
unsigned char out[SD_preread_len];
size_t outLen = SD_preread_len;
DBG (10, "diag_preread: start\n");
if (!s->has_cmd_sdiag || !s->has_cmd_rdiag || !s->need_diag_preread){
DBG (5, "diag_preread: not supported, returning\n");
return ret;
}
memset(cmd,0,cmdLen);
set_SCSI_opcode(cmd, SEND_DIAGNOSTIC_code);
set_SD_slftst(cmd, 0);
set_SD_xferlen(cmd, outLen);
memcpy(out,SD_preread_string,SD_preread_stringlen);
set_SD_preread_xres(out,s->resolution_x);
set_SD_preread_yres(out,s->resolution_y);
/* call helper function, scanner wants lies about paper width */
set_SD_preread_paper_width(out, get_page_width(s));
/* dont call helper function, scanner wants actual length? */
set_SD_preread_paper_length(out, s->page_height);
set_SD_preread_composition(out, s->s_mode);
ret = do_cmd (
s, 1, 0,
cmd, cmdLen,
out, outLen,
NULL, NULL
);
if (ret != SANE_STATUS_GOOD){
DBG (5, "diag_preread: send diag error: %d\n", ret);
return ret;
}
DBG (10, "diag_preread: finish\n");
return SANE_STATUS_GOOD;
}
static SANE_Status
mode_select_df (struct fujitsu *s)
{
SANE_Status ret = SANE_STATUS_GOOD;
unsigned char cmd[MODE_SELECT_len];
size_t cmdLen = MODE_SELECT_len;
unsigned char out[MSEL_header_len + MSEL_data_min_len];
size_t outLen = MSEL_header_len + MSEL_data_min_len;
unsigned char * page = out+MSEL_header_len;
DBG (10, "mode_select_df: start\n");
if(!s->has_MS_df){
DBG (10, "mode_select_df: unsupported\n");
return SANE_STATUS_GOOD;
}
memset(cmd,0,cmdLen);
set_SCSI_opcode(cmd, MODE_SELECT_code);
set_MSEL_pf(cmd, 1);
set_MSEL_xferlen(cmd, outLen);
memset(out,0,outLen);
set_MSEL_pc(page, MS_pc_df);
set_MSEL_page_len(page, MSEL_data_min_len-2);
/* continue/stop */
if(s->df_action != DF_DEFAULT){
set_MSEL_df_enable (page, 1);
/* continue */
if(s->df_action == DF_CONTINUE){
set_MSEL_df_continue (page, 1);
}
/* skew */
if(s->df_skew){
set_MSEL_df_skew (page, 1);
}
/* thickness */
if(s->df_thickness){
set_MSEL_df_thickness (page, 1);
}
/* length */
if(s->df_length){
set_MSEL_df_length (page, 1);
set_MSEL_df_diff (page, s->df_diff);
}
}
set_MSEL_df_paperprot(page,s->paper_protect);
set_MSEL_df_stapledet(page,s->staple_detect);
set_MSEL_df_recovery(page,s->df_recovery);
set_MSEL_df_paperprot2(page,s->adv_paper_prot);
ret = do_cmd (
s, 1, 0,
cmd, cmdLen,
out, outLen,
NULL, NULL
);
DBG (10, "mode_select_df: finish\n");
return ret;
}
static SANE_Status
mode_select_bg (struct fujitsu *s)
{
SANE_Status ret = SANE_STATUS_GOOD;
unsigned char cmd[MODE_SELECT_len];
size_t cmdLen = MODE_SELECT_len;
unsigned char out[MSEL_header_len + MSEL_data_min_len];
size_t outLen = MSEL_header_len + MSEL_data_min_len;
unsigned char * page = out+MSEL_header_len;
DBG (10, "mode_select_bg: start\n");
if(!s->has_MS_bg){
DBG (10, "mode_select_bg: unsupported\n");
return SANE_STATUS_GOOD;
}
memset(cmd,0,cmdLen);
set_SCSI_opcode(cmd, MODE_SELECT_code);
set_MSEL_pf(cmd, 1);
set_MSEL_xferlen(cmd, outLen);
memset(out,0,outLen);
set_MSEL_pc(page, MS_pc_bg);
set_MSEL_page_len(page, MSEL_data_min_len-2);
if(s->bg_color != COLOR_DEFAULT){
set_MSEL_bg_enable (page, 1);
if(s->bg_color == COLOR_BLACK){
set_MSEL_bg_front (page, 1);
set_MSEL_bg_back (page, 1);
set_MSEL_bg_fb (page, 1);
}
}
ret = do_cmd (
s, 1, 0,
cmd, cmdLen,
out, outLen,
NULL, NULL
);
DBG (10, "mode_select_bg: finish\n");
return ret;
}
static SANE_Status
mode_select_dropout (struct fujitsu *s)
{
SANE_Status ret = SANE_STATUS_GOOD;
unsigned char cmd[MODE_SELECT_len];
size_t cmdLen = MODE_SELECT_len;
unsigned char out[MSEL_header_len + MSEL_data_max_len];
size_t outLen = MSEL_header_len + MSEL_data_max_len;
unsigned char * page = out+MSEL_header_len;
DBG (10, "mode_select_dropout: start\n");
if(!s->has_MS_dropout){
DBG (10, "mode_select_dropout: unsupported\n");
return SANE_STATUS_GOOD;
}
memset(cmd,0,cmdLen);
set_SCSI_opcode(cmd, MODE_SELECT_code);
set_MSEL_pf(cmd, 1);
set_MSEL_xferlen(cmd, outLen);
memset(out,0,outLen);
set_MSEL_pc(page, MS_pc_dropout);
set_MSEL_page_len(page, MSEL_data_max_len-2);
set_MSEL_dropout_front (page, s->dropout_color);
set_MSEL_dropout_back (page, s->dropout_color);
ret = do_cmd (
s, 1, 0,
cmd, cmdLen,
out, outLen,
NULL, NULL
);
DBG (10, "mode_select_dropout: finish\n");
return ret;
}
static SANE_Status
mode_select_buff (struct fujitsu *s)
{
SANE_Status ret = SANE_STATUS_GOOD;
unsigned char cmd[MODE_SELECT_len];
size_t cmdLen = MODE_SELECT_len;
unsigned char out[MSEL_header_len + MSEL_data_min_len];
size_t outLen = MSEL_header_len + MSEL_data_min_len;
unsigned char * page = out+MSEL_header_len;
DBG (10, "mode_select_buff: start\n");
if (!s->has_MS_buff){
DBG (10, "mode_select_buff: unsupported\n");
return SANE_STATUS_GOOD;
}
memset(cmd,0,cmdLen);
set_SCSI_opcode(cmd, MODE_SELECT_code);
set_MSEL_pf(cmd, 1);
set_MSEL_xferlen(cmd, outLen);
memset(out,0,outLen);
set_MSEL_pc(page, MS_pc_buff);
set_MSEL_page_len(page, MSEL_data_min_len-2);
set_MSEL_buff_mode(page, s->buff_mode);
set_MSEL_buff_clear(page, 3);
ret = do_cmd (
s, 1, 0,
cmd, cmdLen,
out, outLen,
NULL, NULL
);
DBG (10, "mode_select_buff: finish\n");
return ret;
}
static SANE_Status
mode_select_prepick (struct fujitsu *s)
{
SANE_Status ret = SANE_STATUS_GOOD;
unsigned char cmd[MODE_SELECT_len];
size_t cmdLen = MODE_SELECT_len;
unsigned char out[MSEL_header_len + MSEL_data_min_len];
size_t outLen = MSEL_header_len + MSEL_data_min_len;
unsigned char * page = out+MSEL_header_len;
DBG (10, "mode_select_prepick: start\n");
if (!s->has_MS_prepick){
DBG (10, "mode_select_prepick: unsupported\n");
return SANE_STATUS_GOOD;
}
memset(cmd,0,cmdLen);
set_SCSI_opcode(cmd, MODE_SELECT_code);
set_MSEL_pf(cmd, 1);
set_MSEL_xferlen(cmd, outLen);
memset(out,0,outLen);
set_MSEL_pc(page, MS_pc_prepick);
set_MSEL_page_len(page, MSEL_data_min_len-2);
set_MSEL_prepick(page, s->prepick);
ret = do_cmd (
s, 1, 0,
cmd, cmdLen,
out, outLen,
NULL, NULL
);
DBG (10, "mode_select_prepick: finish\n");
return ret;
}
static SANE_Status
mode_select_auto (struct fujitsu *s)
{
SANE_Status ret = SANE_STATUS_GOOD;
unsigned char cmd[MODE_SELECT_len];
size_t cmdLen = MODE_SELECT_len;
unsigned char out[MSEL_header_len + MSEL_data_min_len];
size_t outLen = MSEL_header_len + MSEL_data_min_len;
unsigned char * page = out+MSEL_header_len;
DBG (10, "mode_select_auto: start\n");
if(!s->has_MS_auto){
DBG (10, "mode_select_auto: unsupported\n");
return SANE_STATUS_GOOD;
}
memset(cmd,0,cmdLen);
set_SCSI_opcode(cmd, MODE_SELECT_code);
set_MSEL_pf(cmd, 1);
set_MSEL_xferlen(cmd, outLen);
memset(out,0,outLen);
set_MSEL_pc(page, MS_pc_auto);
set_MSEL_page_len(page, MSEL_data_min_len-2);
set_MSEL_overscan(page, s->overscan);
set_MSEL_ald(page, s->ald || s->hwdeskewcrop);
set_MSEL_awd(page, s->awd || s->hwdeskewcrop);
set_MSEL_req_driv_crop(page, s->hwdeskewcrop && (s->swcrop || s->swdeskew));
set_MSEL_deskew(page, s->hwdeskewcrop);
ret = do_cmd (
s, 1, 0,
cmd, cmdLen,
out, outLen,
NULL, NULL
);
DBG (10, "mode_select_auto: finish\n");
return ret;
}
/*
* @@ Section 4 - SANE scanning functions
*/
/*
* Called by SANE to retrieve information about the type of data
* that the current scan will return.
*
* From the SANE spec:
* This function is used to obtain the current scan parameters. The
* returned parameters are guaranteed to be accurate between the time
* a scan has been started (sane_start() has been called) and the
* completion of that request. Outside of that window, the returned
* values are best-effort estimates of what the parameters will be
* when sane_start() gets invoked.
*
* Calling this function before a scan has actually started allows,
* for example, to get an estimate of how big the scanned image will
* be. The parameters passed to this function are the handle h of the
* device for which the parameters should be obtained and a pointer p
* to a parameter structure.
*/
SANE_Status
sane_get_parameters (SANE_Handle handle, SANE_Parameters * params)
{
SANE_Status ret = SANE_STATUS_GOOD;
struct fujitsu *s = (struct fujitsu *) handle;
DBG (10, "sane_get_parameters: start\n");
/* not started? update param data from user settings */
if(!s->started){
ret = update_params(s);
if(ret)
return ret;
}
params->format = s->u_params.format;
params->last_frame = s->u_params.last_frame;
params->lines = s->u_params.lines;
params->depth = s->u_params.depth;
params->pixels_per_line = s->u_params.pixels_per_line;
params->bytes_per_line = s->u_params.bytes_per_line;
/* we wont know the end until we get to it */
if(s->ald && !must_fully_buffer(s)){
DBG (15, "sane_get_parameters: hand-scanner mode\n");
params->lines = -1;
}
DBG (10, "sane_get_parameters: finish\n");
return ret;
}
/* set s_params and u_params data based on user settings
* and scanner capabilities. */
SANE_Status
update_params (struct fujitsu * s)
{
SANE_Status ret = SANE_STATUS_GOOD;
SANE_Parameters * params = &(s->s_params);
DBG (10, "update_params: start\n");
/* first, we setup s_params to describe the image to the scanner */
/* this backend only sends single frame images */
params->last_frame = 1;
/* initial ppl from user settings */
params->pixels_per_line = s->resolution_x * (s->br_x - s->tl_x) / 1200;
/* some scanners require even number of bytes in each transfer block,
* so we round to even # of total lines, to ensure last block is even */
params->lines = s->resolution_y * (s->br_y - s->tl_y) / 1200;
params->lines -= params->lines % 2;
if (s->s_mode == MODE_COLOR) {
params->depth = 8;
/* jpeg requires 8x8 squares */
if(s->compress == COMP_JPEG){
params->format = SANE_FRAME_JPEG;
params->pixels_per_line -= params->pixels_per_line % 8;
params->lines -= params->lines % 8;
}
else{
params->format = SANE_FRAME_RGB;
params->pixels_per_line -= params->pixels_per_line
% max(s->ppl_mod_by_mode[s->s_mode], s->ppl_mod_by_mode[s->u_mode]);
}
params->bytes_per_line = params->pixels_per_line * 3;
}
else if (s->s_mode == MODE_GRAYSCALE) {
params->depth = 8;
/* jpeg requires 8x8 squares */
if(s->compress == COMP_JPEG){
params->format = SANE_FRAME_JPEG;
params->pixels_per_line -= params->pixels_per_line % 8;
params->lines -= params->lines % 8;
}
else{
params->format = SANE_FRAME_GRAY;
params->pixels_per_line -= params->pixels_per_line
% max(s->ppl_mod_by_mode[s->s_mode], s->ppl_mod_by_mode[s->u_mode]);
}
params->bytes_per_line = params->pixels_per_line;
}
else {
params->depth = 1;
params->format = SANE_FRAME_GRAY;
params->pixels_per_line -= params->pixels_per_line
% max(s->ppl_mod_by_mode[s->s_mode], s->ppl_mod_by_mode[s->u_mode]);
params->bytes_per_line = params->pixels_per_line / 8;
}
DBG(15,"update_params: x: max=%d, page=%d, gpw=%d, res=%d\n",
s->max_x, s->page_width, get_page_width(s), s->resolution_x);
DBG(15,"update_params: y: max=%d, page=%d, gph=%d, res=%d\n",
s->max_y, s->page_height, get_page_height(s), s->resolution_y);
DBG(15,"update_params: area: tlx=%d, brx=%d, tly=%d, bry=%d\n",
s->tl_x, s->br_x, s->tl_y, s->br_y);
DBG(15,"update_params: params: ppl=%d, Bpl=%d, lines=%d\n",
params->pixels_per_line, params->bytes_per_line, params->lines);
DBG(15,"update_params: params: format=%d, depth=%d, last=%d\n",
params->format, params->depth, params->last_frame);
/* second, we setup u_params to describe the image to the user */
/* use a helper function cause it is called elsewhere */
ret = update_u_params(s);
DBG (10, "update_params: finish\n");
return ret;
}
/* set u_param data based on user settings, and s_params */
SANE_Status
update_u_params (struct fujitsu * s)
{
SANE_Status ret = SANE_STATUS_GOOD;
SANE_Parameters * params = &(s->u_params);
DBG (10, "update_u_params: start\n");
/* for most machines, it is the same, so we just copy */
memcpy(&(s->u_params), &(s->s_params), sizeof(SANE_Parameters));
/* some scanners don't support the user's mode, so params differ */
/* but not in jpeg mode. we don't support that. */
if(must_downsample(s)){
/* making gray from a color scan */
if (s->u_mode == MODE_GRAYSCALE) {
params->format = SANE_FRAME_GRAY;
params->bytes_per_line = params->pixels_per_line;
}
/* making binary from a gray or color scan */
else if (s->u_mode == MODE_LINEART) {
params->depth = 1;
params->format = SANE_FRAME_GRAY;
params->bytes_per_line = params->pixels_per_line / 8;
}
DBG(15,"update_u_params: x: max=%d, page=%d, gpw=%d, res=%d\n",
s->max_x, s->page_width, get_page_width(s), s->resolution_x);
DBG(15,"update_u_params: y: max=%d, page=%d, gph=%d, res=%d\n",
s->max_y, s->page_height, get_page_height(s), s->resolution_y);
DBG(15,"update_u_params: area: tlx=%d, brx=%d, tly=%d, bry=%d\n",
s->tl_x, s->br_x, s->tl_y, s->br_y);
DBG(15,"update_u_params: params: ppl=%d, Bpl=%d, lines=%d\n",
params->pixels_per_line, params->bytes_per_line, params->lines);
DBG(15,"update_u_params: params: format=%d, depth=%d, last=%d\n",
params->format, params->depth, params->last_frame);
}
DBG (10, "update_u_params: finish\n");
return ret;
}
/*
* Called by SANE when a page acquisition operation is to be started.
* commands: scanner control (lampon), send (lut), send (dither),
* set window, object pos, and scan
*
* this will be called between sides of a duplex scan,
* and at the start of each page of an adf batch.
* hence, we spend alot of time playing with s->started, etc.
*/
SANE_Status
sane_start (SANE_Handle handle)
{
struct fujitsu *s = handle;
SANE_Status ret = SANE_STATUS_GOOD;
DBG (10, "sane_start: start\n");
DBG (15, "started=%d, side=%d, source=%d\n", s->started, s->side, s->source);
/* undo any prior sane_cancel calls */
s->cancelled=0;
/* protect this block from sane_cancel */
s->reading=1;
/* not finished with current side, error */
if (s->started && !s->eof_tx[s->side]) {
DBG(5,"sane_start: previous transfer not finished?");
ret = SANE_STATUS_INVAL;
goto errors;
}
/* low mem mode messes up the side marker, reset it */
if(s->source == SOURCE_ADF_DUPLEX && s->low_mem
&& s->eof_tx[SIDE_FRONT] && s->eof_tx[SIDE_BACK]
){
s->side = SIDE_BACK;
}
/* batch start? initialize struct and scanner */
if(!s->started){
/* load side marker */
if(s->source == SOURCE_ADF_BACK){
s->side = SIDE_BACK;
}
else{
s->side = SIDE_FRONT;
}
/* load our own private copy of scan params */
ret = update_params(s);
if (ret != SANE_STATUS_GOOD) {
DBG (5, "sane_start: ERROR: cannot update params\n");
goto errors;
}
/* switch source */
if(s->source == SOURCE_FLATBED){
ret = scanner_control(s, SC_function_fb);
if (ret != SANE_STATUS_GOOD) {
DBG (5, "sane_start: ERROR: cannot control fb, ignoring\n");
}
}
else{
ret = scanner_control(s, SC_function_adf);
if (ret != SANE_STATUS_GOOD) {
DBG (5, "sane_start: ERROR: cannot control adf, ignoring\n");
}
}
/* required for hi res scans on iX500? */
ret = diag_preread(s);
if (ret != SANE_STATUS_GOOD)
DBG (5, "sane_start: WARNING: cannot diag_preread %d\n", ret);
/* enable overscan/auto detection */
ret = mode_select_auto(s);
if (ret != SANE_STATUS_GOOD)
DBG (5, "sane_start: WARNING: cannot mode_select_auto %d\n", ret);
/* enable double feed detection */
ret = mode_select_df(s);
if (ret != SANE_STATUS_GOOD)
DBG (5, "sane_start: WARNING: cannot mode_select_df %d\n", ret);
/* enable background color setting */
ret = mode_select_bg(s);
if (ret != SANE_STATUS_GOOD)
DBG (5, "sane_start: WARNING: cannot mode_select_bg %d\n", ret);
/* enable dropout color setting */
ret = mode_select_dropout(s);
if (ret != SANE_STATUS_GOOD)
DBG (5, "sane_start: WARNING: cannot mode_select_dropout %d\n", ret);
/* enable buffering setting */
ret = mode_select_buff(s);
if (ret != SANE_STATUS_GOOD)
DBG (5, "sane_start: WARNING: cannot mode_select_buff %d\n", ret);
/* enable prepick setting */
ret = mode_select_prepick(s);
if (ret != SANE_STATUS_GOOD)
DBG (5, "sane_start: WARNING: cannot mode_select_prepick %d\n", ret);
/* send endorser config */
ret = send_endorser(s);
if (ret != SANE_STATUS_GOOD)
DBG (5, "sane_start: WARNING: cannot send_endorser %d\n", ret);
/* send lut if scanner has no hardware brightness/contrast,
* or we are going to ask it to use a downloaded gamma table */
if (!s->late_lut && (!s->brightness_steps || !s->contrast_steps || s->window_gamma & 0x80)){
ret = send_lut(s);
if (ret != SANE_STATUS_GOOD)
DBG (5, "sane_start: WARNING: cannot early send_lut %d\n", ret);
}
/* set window command */
ret = set_window(s);
if (ret != SANE_STATUS_GOOD) {
DBG (5, "sane_start: ERROR: cannot set window\n");
goto errors;
}
/* send lut if scanner has no hardware brightness/contrast,
* or we are going to ask it to use a downloaded gamma table */
if (s->late_lut && (!s->brightness_steps || !s->contrast_steps || s->window_gamma & 0x80)){
ret = send_lut(s);
if (ret != SANE_STATUS_GOOD)
DBG (5, "sane_start: WARNING: cannot late send_lut %d\n", ret);
}
/* some scanners need the q table sent, even when not scanning jpeg */
if (s->need_q_table){
ret = send_q_table(s);
if (ret != SANE_STATUS_GOOD)
DBG (5, "sane_start: WARNING: cannot send_q_table %d\n", ret);
}
/* start/stop endorser */
ret = endorser(s);
if (ret != SANE_STATUS_GOOD) {
DBG (5, "sane_start: ERROR: cannot start/stop endorser\n");
goto errors;
}
/* turn lamp on */
ret = scanner_control(s, SC_function_lamp_on);
if (ret != SANE_STATUS_GOOD) {
DBG (5, "sane_start: WARNING: cannot start lamp, ignoring\n");
}
/* iX500 errors if op is called with no paper
* at the beginning of a batch, so we check */
if(s->hopper_before_op && s->source != SOURCE_FLATBED){
ret = get_hardware_status(s,0);
if(!s->hw_hopper){
ret = SANE_STATUS_NO_DOCS;
DBG (5, "sane_start: ERROR: hopper empty\n");
goto errors;
}
}
}
/* if already running, duplex needs to switch sides */
else if(s->source == SOURCE_ADF_DUPLEX){
s->side = !s->side;
}
/* set clean defaults with new sheet of paper */
/* dont reset the transfer vars on backside of duplex page */
/* otherwise buffered back page will be lost */
/* ingest paper with adf (no-op for fb) */
/* dont call object pos or scan on back side of duplex scan */
if(s->side == SIDE_FRONT || s->source == SOURCE_ADF_BACK){
s->bytes_rx[0]=0;
s->bytes_rx[1]=0;
s->lines_rx[0]=0;
s->lines_rx[1]=0;
s->eof_rx[0]=0;
s->eof_rx[1]=0;
s->ili_rx[0]=0;
s->ili_rx[1]=0;
s->eom_rx=0;
s->bytes_tx[0]=0;
s->bytes_tx[1]=0;
s->eof_tx[0]=0;
s->eof_tx[1]=0;
s->buff_rx[0]=0;
s->buff_rx[1]=0;
s->buff_tx[0]=0;
s->buff_tx[1]=0;
/* reset jpeg just in case... */
s->jpeg_stage = JPEG_STAGE_NONE;
s->jpeg_ff_offset = -1;
s->jpeg_front_rst = 0;
s->jpeg_back_rst = 0;
ret = object_position (s, OP_Feed);
if (ret != SANE_STATUS_GOOD) {
DBG (5, "sane_start: ERROR: cannot load page\n");
goto errors;
}
ret = start_scan (s);
if (ret != SANE_STATUS_GOOD) {
DBG (5, "sane_start: ERROR: cannot start_scan\n");
goto errors;
}
/* try to read scan size from scanner */
ret = get_pixelsize(s,0);
if (ret != SANE_STATUS_GOOD) {
DBG (5, "sane_start: ERROR: cannot get pixelsize\n");
goto errors;
}
/* store the number of front bytes */
if ( s->source != SOURCE_ADF_BACK ){
s->bytes_tot[SIDE_FRONT] = s->s_params.bytes_per_line * s->s_params.lines;
s->buff_tot[SIDE_FRONT] = s->buffer_size;
/* the front buffer is normally very small, but some scanners or
* option combinations can't handle it, so we make a big one */
if(
(s->s_mode == MODE_COLOR && s->color_interlace == COLOR_INTERLACE_3091)
|| must_fully_buffer(s)
){
s->buff_tot[SIDE_FRONT] = s->bytes_tot[SIDE_FRONT];
}
}
else{
s->bytes_tot[SIDE_FRONT] = 0;
s->buff_tot[SIDE_FRONT] = 0;
}
/* store the number of back bytes */
if ( s->source == SOURCE_ADF_DUPLEX || s->source == SOURCE_ADF_BACK ){
s->bytes_tot[SIDE_BACK] = s->s_params.bytes_per_line * s->s_params.lines;
s->buff_tot[SIDE_BACK] = s->bytes_tot[SIDE_BACK];
/* the back buffer is normally very large, but some scanners or
* option combinations dont need it, so we make a small one */
if(s->low_mem || s->source == SOURCE_ADF_BACK
|| s->duplex_interlace == DUPLEX_INTERLACE_NONE)
s->buff_tot[SIDE_BACK] = s->buffer_size;
}
else{
s->bytes_tot[SIDE_BACK] = 0;
s->buff_tot[SIDE_BACK] = 0;
}
/* first page of batch */
/* make large buffer to hold the images */
/* and set started flag */
if(!s->started){
ret = setup_buffers(s);
if (ret != SANE_STATUS_GOOD) {
DBG (5, "sane_start: ERROR: cannot load buffers\n");
goto errors;
}
s->started=1;
}
}
else{
/* try to read scan size from scanner */
ret = get_pixelsize(s,0);
if (ret != SANE_STATUS_GOOD) {
DBG (5, "sane_start: ERROR: cannot get pixelsize\n");
goto errors;
}
}
DBG (15, "started=%d, side=%d, source=%d\n", s->started, s->side, s->source);
/* certain options require the entire image to
* be collected from the scanner before we can
* tell the user the size of the image. the sane
* API has no way to inform the frontend of this,
* so we block and buffer. yuck */
if( must_fully_buffer(s) ){
/* get image */
while(!s->eof_rx[s->side] && !ret){
SANE_Int len = 0;
ret = sane_read((SANE_Handle)s, NULL, 0, &len);
}
/* check for errors */
if (ret != SANE_STATUS_GOOD) {
DBG (5, "sane_start: ERROR: cannot buffer image\n");
goto errors;
}
DBG (5, "sane_start: OK: done buffering\n");
/* hardware deskew will tell image size after transfer */
ret = get_pixelsize(s,1);
if (ret != SANE_STATUS_GOOD) {
DBG (5, "sane_start: ERROR: cannot get final pixelsize\n");
goto errors;
}
/* finished buffering, adjust image as required */
if(s->swdeskew && (!s->hwdeskewcrop || s->req_driv_crop)){
buffer_deskew(s,s->side);
}
if(s->swcrop && (!s->hwdeskewcrop || s->req_driv_crop)){
buffer_crop(s,s->side);
}
if(s->swdespeck){
buffer_despeck(s,s->side);
}
if(s->swskip){
/* Skipping means throwing out this image.
* Pretend the user read the whole thing
* and call sane_start again.
* This assumes we are running in batch mode. */
if(buffer_isblank(s,s->side)){
s->bytes_tx[s->side] = s->bytes_rx[s->side];
s->eof_tx[s->side] = 1;
return sane_start(handle);
}
}
}
/* check if user cancelled during this start */
ret = check_for_cancel(s);
/* unprotect this block from sane_cancel */
s->reading=0;
DBG (10, "sane_start: finish %d\n", ret);
return ret;
errors:
DBG (10, "sane_start: error %d\n", ret);
/* if we are started, but something went wrong,
* chances are there is image data inside scanner,
* which should be discarded via cancel command */
if(s->started){
s->cancelled = 1;
check_for_cancel(s);
}
s->started = 0;
s->cancelled = 0;
s->reading = 0;
return ret;
}
static SANE_Status
endorser(struct fujitsu *s)
{
SANE_Status ret = SANE_STATUS_GOOD;
unsigned char cmd[ENDORSER_len];
size_t cmdLen = ENDORSER_len;
unsigned char out[ED_max_len];
size_t outLen = ED_max_len;
DBG (10, "endorser: start\n");
memset(cmd,0,cmdLen);
set_SCSI_opcode(cmd, ENDORSER_code);
memset(out,0,outLen);
if (s->has_endorser_f || s->has_endorser_b){
/*fi-5900 front side uses 0x80, assume all others*/
if(s->u_endorser_side == ED_front){
set_ED_endorser_data_id(out,0x80);
}
else{
set_ED_endorser_data_id(out,0);
}
if(s->u_endorser){
set_ED_stop(out,ED_start);
}
else{
set_ED_stop(out,ED_stop);
}
set_ED_side(out,s->u_endorser_side);
if(s->u_endorser_bits == 24){
set_ED_lap24(out,ED_lap_24bit);
set_ED_initial_count_24(out,s->u_endorser_val);
}
else{
outLen = ED_min_len;
set_ED_lap24(out,ED_lap_16bit);
set_ED_initial_count_16(out,s->u_endorser_val);
}
set_E_xferlen(cmd, outLen);
ret = do_cmd (
s, 1, 0,
cmd, cmdLen,
out, outLen,
NULL, NULL
);
}
DBG (10, "endorser: finish %d\n", ret);
return ret;
}
static SANE_Status
scanner_control (struct fujitsu *s, int function)
{
SANE_Status ret = SANE_STATUS_GOOD;
int tries = 0;
unsigned char cmd[SCANNER_CONTROL_len];
size_t cmdLen = SCANNER_CONTROL_len;
DBG (10, "scanner_control: start\n");
if(s->has_cmd_scanner_ctl){
memset(cmd,0,cmdLen);
set_SCSI_opcode(cmd, SCANNER_CONTROL_code);
set_SC_function (cmd, function);
DBG (15, "scanner_control: function %d\n",function);
/* don't really need to ask for adf if that's the only option */
/* doing so causes the 3091 to complain */
if(function == SC_function_adf && !s->has_flatbed){
DBG (10, "scanner_control: adf function not required\n");
return ret;
}
/* extremely long retry period */
while(tries++ < 120){
ret = do_cmd (
s, 1, 0,
cmd, cmdLen,
NULL, 0,
NULL, NULL
);
if(ret == SANE_STATUS_GOOD || function != SC_function_lamp_on){
break;
}
usleep(500000);
}
if(ret == SANE_STATUS_GOOD){
DBG (15, "scanner_control: success, tries %d, ret %d\n",tries,ret);
}
else{
DBG (5, "scanner_control: error, tries %d, ret %d\n",tries,ret);
}
}
DBG (10, "scanner_control: finish\n");
return ret;
}
static SANE_Status
scanner_control_ric (struct fujitsu *s, int bytes, int side)
{
SANE_Status ret = SANE_STATUS_GOOD;
int tries = 0;
unsigned char cmd[SCANNER_CONTROL_len];
size_t cmdLen = SCANNER_CONTROL_len;
DBG (10, "scanner_control_ric: start\n");
if(s->has_cmd_scanner_ctl){
memset(cmd,0,cmdLen);
set_SCSI_opcode(cmd, SCANNER_CONTROL_code);
set_SC_ric(cmd, 1);
if (side == SIDE_BACK) {
set_SC_ric_dtq(cmd, WD_wid_back);
}
else{
set_SC_ric_dtq(cmd, WD_wid_front);
}
set_SC_ric_len(cmd, bytes);
DBG (15, "scanner_control_ric: %d %d\n",bytes,side);
/* extremely long retry period */
while(tries++ < 120){
ret = do_cmd (
s, 1, 0,
cmd, cmdLen,
NULL, 0,
NULL, NULL
);
if(ret != SANE_STATUS_DEVICE_BUSY){
break;
}
usleep(500000);
}
if(ret == SANE_STATUS_GOOD){
DBG (15, "scanner_control_ric: success, tries %d, ret %d\n",tries,ret);
}
/* some errors pass thru unchanged */
else if(ret == SANE_STATUS_CANCELLED || ret == SANE_STATUS_JAMMED
|| ret == SANE_STATUS_NO_DOCS || ret == SANE_STATUS_COVER_OPEN
){
DBG (5, "scanner_control_ric: error, tries %d, ret %d\n",tries,ret);
}
/* other errors are ignored, since scanner may not support RIC */
else{
DBG (5, "scanner_control_ric: ignoring, tries %d, ret %d\n",tries,ret);
ret = SANE_STATUS_GOOD;
}
}
DBG (10, "scanner_control_ric: finish\n");
return ret;
}
/*
* callocs a buffer to hold the scan data
*/
static SANE_Status
setup_buffers (struct fujitsu *s)
{
SANE_Status ret = SANE_STATUS_GOOD;
int side;
DBG (10, "setup_buffers: start\n");
for(side=0;side<2;side++){
/* free old mem */
if (s->buffers[side]) {
DBG (15, "setup_buffers: free buffer %d.\n",side);
free(s->buffers[side]);
s->buffers[side] = NULL;
}
if(s->buff_tot[side]){
s->buffers[side] = calloc (1,s->buff_tot[side]);
if (!s->buffers[side]) {
DBG (5, "setup_buffers: Error, no buffer %d.\n",side);
return SANE_STATUS_NO_MEM;
}
}
}
DBG (10, "setup_buffers: finish\n");
return ret;
}
/*
* This routine issues a SCSI SET WINDOW command to the scanner, using the
* values currently in the scanner data structure.
*/
static SANE_Status
set_window (struct fujitsu *s)
{
SANE_Status ret = SANE_STATUS_GOOD;
/* The command specifies the number of bytes in the data phase
* the data phase has a header, followed by 1 or 2 window desc blocks
* the header specifies the number of bytes in 1 window desc block
*/
unsigned char cmd[SET_WINDOW_len];
size_t cmdLen = SET_WINDOW_len;
/*this is max size, we might send less below*/
unsigned char out[SW_header_len + SW_desc_len + SW_desc_len];
size_t outLen = SW_header_len + SW_desc_len + SW_desc_len;
unsigned char * header = out; /*header*/
unsigned char * desc1 = out + SW_header_len; /*1st desc*/
unsigned char * desc2 = out + SW_header_len + SW_desc_len; /*2nd desc*/
int length = 0;
DBG (10, "set_window: start\n");
/*build the payload*/
memset(out,0,outLen);
/* set window desc size in header */
set_WPDB_wdblen(header, SW_desc_len);
/* init the window block */
if (s->source == SOURCE_ADF_BACK) {
set_WD_wid (desc1, WD_wid_back);
}
else{
set_WD_wid (desc1, WD_wid_front);
}
set_WD_Xres (desc1, s->resolution_x);
set_WD_Yres (desc1, s->resolution_y);
set_WD_ULX (desc1, s->tl_x);
/* low-end scanners ignore paper-size,
* so we have to center the window ourselves */
if(s->cropping_mode == CROP_ABSOLUTE){
set_WD_ULX (desc1, s->tl_x + (s->max_x - s->page_width) / 2);
}
set_WD_ULY (desc1, s->tl_y);
set_WD_width (desc1, s->s_params.pixels_per_line * 1200/s->resolution_x);
length = s->s_params.lines * 1200/s->resolution_y;
/* stupid trick. 3091/2 require reading extra lines,
* because they have a gap between R G and B */
if(s->s_mode == MODE_COLOR && s->color_interlace == COLOR_INTERLACE_3091){
length += (s->color_raster_offset+s->green_offset) * 1200/300 * 2;
DBG(5,"set_window: Increasing length to %d\n",length);
}
set_WD_length (desc1, length);
set_WD_brightness (desc1, 0);
if(s->brightness_steps){
/*convert our common -127 to +127 range into HW's range
*FIXME: this code assumes hardware range of 0-255 */
set_WD_brightness (desc1, s->brightness+128);
}
set_WD_threshold (desc1, s->threshold);
set_WD_contrast (desc1, 0);
if(s->contrast_steps){
/*convert our common -127 to +127 range into HW's range
*FIXME: this code assumes hardware range of 0-255 */
set_WD_contrast (desc1, s->contrast+128);
}
set_WD_composition (desc1, s->s_mode);
set_WD_bitsperpixel (desc1, s->s_params.depth);
if(s->s_mode == MODE_HALFTONE){
set_WD_ht_type(desc1, s->ht_type);
set_WD_ht_pattern(desc1, s->ht_pattern);
}
set_WD_rif (desc1, s->rif);
set_WD_compress_type(desc1, COMP_NONE);
set_WD_compress_arg(desc1, 0);
/* some scanners support jpeg image compression, for color/gs only */
if(s->s_params.format == SANE_FRAME_JPEG){
set_WD_compress_type(desc1, COMP_JPEG);
set_WD_compress_arg(desc1, s->compress_arg);
}
/* the remainder of the block varies based on model and mode,
* except for gamma and paper size, those are in the same place */
/*vuid c0*/
if(s->has_vuid_3091){
set_WD_vendor_id_code (desc1, WD_VUID_3091);
set_WD_gamma (desc1, s->window_gamma);
if (s->s_mode != MODE_COLOR){
switch (s->dropout_color) {
case COLOR_RED:
set_WD_lamp_color (desc1, WD_LAMP_RED);
break;
case COLOR_GREEN:
set_WD_lamp_color (desc1, WD_LAMP_GREEN);
break;
case COLOR_BLUE:
set_WD_lamp_color (desc1, WD_LAMP_BLUE);
break;
default:
set_WD_lamp_color (desc1, WD_LAMP_DEFAULT);
break;
}
}
/*set_WD_quality(desc1,s->quality);*/
}
/*vuid c1*/
else if(s->s_mode == MODE_COLOR && s->has_vuid_color){
set_WD_vendor_id_code (desc1, WD_VUID_COLOR);
set_WD_gamma (desc1, s->window_gamma);
if(s->color_interlace == COLOR_INTERLACE_RGB){
set_WD_scanning_order (desc1, WD_SCAN_ORDER_DOT);
set_WD_scanning_order_arg (desc1, WD_SCAN_ARG_RGB);
}
else if(s->color_interlace == COLOR_INTERLACE_BGR){
set_WD_scanning_order (desc1, WD_SCAN_ORDER_DOT);
set_WD_scanning_order_arg (desc1, WD_SCAN_ARG_BGR);
}
else if(s->color_interlace == COLOR_INTERLACE_RRGGBB){
set_WD_scanning_order (desc1, WD_SCAN_ORDER_LINE);
set_WD_scanning_order_arg (desc1, WD_SCAN_ARG_RGB);
}
else{
DBG (5,"set_window: unknown color interlacing\n");
return SANE_STATUS_INVAL;
}
/*scanner emphasis ranges from 0 to 7f and smoothing from 80 to ff*/
/* but we expose them to user as a single linear range smooth->emphasis */
/* flip the smooth part over, and tack it onto the upper end of emphasis */
if(s->emphasis < 0)
set_WD_c1_emphasis(desc1,127-s->emphasis);
else
set_WD_c1_emphasis(desc1,s->emphasis);
set_WD_c1_mirroring(desc1,s->mirroring);
set_WD_wl_follow(desc1,s->wl_follow);
}
/*vuid 00*/
else if(s->has_vuid_mono){
set_WD_vendor_id_code (desc1, WD_VUID_MONO);
set_WD_gamma (desc1, s->window_gamma);
set_WD_outline(desc1,s->outline);
/*scanner emphasis ranges from 0 to 7f and smoothing from 80 to ff*/
/* but we expose them to user as a single linear range smooth->emphasis */
/* flip the smooth part over, and tack it onto the upper end of emphasis */
if(s->emphasis < 0)
set_WD_emphasis(desc1,127-s->emphasis);
else
set_WD_emphasis(desc1,s->emphasis);
set_WD_separation(desc1,s->separation);
set_WD_mirroring(desc1,s->mirroring);
if (get_ipc_mode(s) == WD_ipc_SDTC)
set_WD_variance(desc1,s->variance);
else if (get_ipc_mode(s) == WD_ipc_DTC){
set_WD_filtering(desc1,s->bp_filter);
set_WD_smoothing(desc1,s->smoothing);
set_WD_gamma_curve(desc1,s->gamma_curve);
set_WD_threshold_curve(desc1,s->threshold_curve);
set_WD_noise_removal(desc1,s->noise_removal);
if(s->noise_removal){
set_WD_matrix5x5(desc1,s->matrix_5);
set_WD_matrix4x4(desc1,s->matrix_4);
set_WD_matrix3x3(desc1,s->matrix_3);
set_WD_matrix2x2(desc1,s->matrix_2);
}
set_WD_background(desc1,s->threshold_white);
}
set_WD_wl_follow(desc1,s->wl_follow);
set_WD_subwindow_list(desc1,0);
set_WD_ipc_mode(desc1,get_ipc_mode(s));
}
else{
DBG (5,"set_window: no vuid to send?\n");
return SANE_STATUS_INVAL;
}
/* common to all vuids */
if(s->source == SOURCE_FLATBED){
set_WD_paper_selection(desc1,WD_paper_SEL_UNDEFINED);
}
else{
set_WD_paper_selection (desc1, WD_paper_SEL_NON_STANDARD);
/* call helper function, scanner wants lies about paper width */
set_WD_paper_width_X (desc1, get_page_width(s));
/* dont call helper function, scanner wants actual length? */
set_WD_paper_length_Y (desc1, s->page_height);
}
/* when in duplex mode, copy first desc block into second */
if (s->source == SOURCE_ADF_DUPLEX) {
memcpy (desc2, desc1, SW_desc_len);
set_WD_wid (desc2, WD_wid_back);
/* FIXME: do we really need these on back of page? */
set_WD_paper_selection (desc2, WD_paper_SEL_UNDEFINED);
set_WD_paper_width_X (desc2, 0);
set_WD_paper_length_Y (desc2, 0);
}
/* output shorter if not using duplex */
else{
outLen -= SW_desc_len;
}
/*build the command*/
memset(cmd,0,cmdLen);
set_SCSI_opcode(cmd, SET_WINDOW_code);
set_SW_xferlen(cmd, outLen);
ret = do_cmd (
s, 1, 0,
cmd, cmdLen,
out, outLen,
NULL, NULL
);
DBG (10, "set_window: finish\n");
return ret;
}
/* update s_params with actual data size scanner reports */
/* then copy as required to the u_params to send to user */
static SANE_Status
get_pixelsize(struct fujitsu *s, int actual)
{
SANE_Status ret;
unsigned char cmd[READ_len];
size_t cmdLen = READ_len;
unsigned char in[R_PSIZE_len];
size_t inLen = R_PSIZE_len;
DBG (10, "get_pixelsize: start %d\n",actual);
if (!s->has_pixelsize){
DBG (10, "get_pixelsize: unsupported\n");
return SANE_STATUS_GOOD;
}
memset(cmd,0,cmdLen);
set_SCSI_opcode(cmd, READ_code);
set_R_datatype_code (cmd, R_datatype_pixelsize);
if(s->side == SIDE_BACK){
set_R_window_id (cmd, WD_wid_back);
}
else{
set_R_window_id (cmd, WD_wid_front);
}
set_R_xfer_length (cmd, inLen);
ret = do_cmd (
s, 1, 0,
cmd, cmdLen,
NULL, 0,
in, &inLen
);
if (ret == SANE_STATUS_GOOD){
/* when we are called post-scan, the scanner may give
* more accurate data in other fields */
if(actual && !s->has_short_pixelsize && get_PSIZE_paper_w(in)){
DBG(5,"get_pixelsize: Actual width %d -> %d\n", s->s_params.pixels_per_line, get_PSIZE_paper_w(in));
s->s_params.pixels_per_line = get_PSIZE_paper_w(in);
}
else{
s->s_params.pixels_per_line = get_PSIZE_num_x(in);
}
/* stupid trick. 3091/2 require reading extra lines,
* because they have a gap between R G and B
* we only want to report the shorter value to the frontend */
if(s->s_mode == MODE_COLOR && s->color_interlace == COLOR_INTERLACE_3091){
DBG(5,"get_pixelsize: Ignoring length %d\n",get_PSIZE_num_y(in));
}
/* when we are called post-scan, the scanner may give
* more accurate data in other fields */
else if(actual && !s->has_short_pixelsize && get_PSIZE_paper_l(in)){
DBG(5,"get_pixelsize: Actual length %d -> %d\n", s->s_params.lines, get_PSIZE_paper_l(in));
s->s_params.lines = get_PSIZE_paper_l(in);
}
else{
s->s_params.lines = get_PSIZE_num_y(in);
}
/* bytes per line differs by mode */
if (s->s_mode == MODE_COLOR) {
s->s_params.bytes_per_line = s->s_params.pixels_per_line * 3;
}
else if (s->s_mode == MODE_GRAYSCALE) {
s->s_params.bytes_per_line = s->s_params.pixels_per_line;
}
else {
s->s_params.bytes_per_line = s->s_params.pixels_per_line / 8;
}
/* some scanners can request that the driver clean img */
if(!s->has_short_pixelsize && get_PSIZE_req_driv_valid(in)){
s->req_driv_crop = get_PSIZE_req_driv_crop(in);
s->req_driv_lut = get_PSIZE_req_driv_lut(in);
DBG(5,"get_pixelsize: scanner requests: crop=%d, lut=%d\n",
s->req_driv_crop,s->req_driv_lut);
}
DBG (15, "get_pixelsize: scan_x=%d, Bpl=%d, scan_y=%d\n",
s->s_params.pixels_per_line, s->s_params.bytes_per_line, s->s_params.lines );
/* the user params are usually the same */
s->u_params.pixels_per_line = s->s_params.pixels_per_line;
s->u_params.lines = s->s_params.lines;
/* bytes per line differs by mode */
if (s->u_mode == MODE_COLOR) {
s->u_params.bytes_per_line = s->u_params.pixels_per_line * 3;
}
else if (s->u_mode == MODE_GRAYSCALE) {
s->u_params.bytes_per_line = s->u_params.pixels_per_line;
}
else {
s->u_params.bytes_per_line = s->u_params.pixels_per_line / 8;
}
}
else{
DBG (10, "get_pixelsize: got bad status %d, ignoring\n", ret);
s->has_pixelsize = 0;
ret = SANE_STATUS_GOOD;
}
DBG (10, "get_pixelsize: finish\n");
return ret;
}
/*
* Issues the SCSI OBJECT POSITION command if an ADF is in use.
*/
static SANE_Status
object_position (struct fujitsu *s, int action)
{
SANE_Status ret = SANE_STATUS_GOOD;
unsigned char cmd[OBJECT_POSITION_len];
size_t cmdLen = OBJECT_POSITION_len;
DBG (10, "object_position: start %d\n", action);
if (s->source == SOURCE_FLATBED && action < OP_Halt) {
DBG (10, "object_position: flatbed no-op\n");
return SANE_STATUS_GOOD;
}
memset(cmd,0,cmdLen);
set_SCSI_opcode(cmd, OBJECT_POSITION_code);
set_OP_action (cmd, action);
ret = do_cmd (
s, 1, 0,
cmd, cmdLen,
NULL, 0,
NULL, NULL
);
if (ret != SANE_STATUS_GOOD)
return ret;
if(!s->no_wait_after_op)
wait_scanner (s);
DBG (10, "object_position: finish\n");
return ret;
}
/*
* Issues SCAN command.
*
* (This doesn't actually read anything, it just tells the scanner
* to start scanning.)
*/
static SANE_Status
start_scan (struct fujitsu *s)
{
SANE_Status ret = SANE_STATUS_GOOD;
unsigned char cmd[SCAN_len];
size_t cmdLen = SCAN_len;
unsigned char out[] = {WD_wid_front, WD_wid_back};
size_t outLen = 2;
DBG (10, "start_scan: start\n");
if (s->source != SOURCE_ADF_DUPLEX) {
outLen--;
if(s->source == SOURCE_ADF_BACK) {
out[0] = WD_wid_back;
}
}
memset(cmd,0,cmdLen);
set_SCSI_opcode(cmd, SCAN_code);
set_SC_xfer_length (cmd, outLen);
ret = do_cmd (
s, 1, 0,
cmd, cmdLen,
out, outLen,
NULL, NULL
);
DBG (10, "start_scan: finish\n");
return ret;
}
/* checks started and cancelled flags in scanner struct,
* sends cancel command to scanner if required. don't call
* this function asyncronously, wait for pending operation */
static SANE_Status
check_for_cancel(struct fujitsu *s)
{
SANE_Status ret=SANE_STATUS_GOOD;
DBG (10, "check_for_cancel: start %d %d\n",s->started,s->cancelled);
if(s->started && s->cancelled){
/* halt scan */
if(s->halt_on_cancel){
DBG (15, "check_for_cancel: halting\n");
ret = object_position (s, OP_Halt);
}
/* cancel scan */
else{
DBG (15, "check_for_cancel: cancelling\n");
ret = scanner_control(s, SC_function_cancel);
}
if (ret == SANE_STATUS_GOOD || ret == SANE_STATUS_CANCELLED) {
ret = SANE_STATUS_CANCELLED;
}
else{
DBG (5, "check_for_cancel: ERROR: cannot cancel\n");
}
s->started = 0;
s->cancelled = 0;
}
else if(s->cancelled){
DBG (15, "check_for_cancel: already cancelled\n");
ret = SANE_STATUS_CANCELLED;
s->cancelled = 0;
}
DBG (10, "check_for_cancel: finish %d\n",ret);
return ret;
}
/*
* Called by SANE to read data.
*
* From the SANE spec:
* This function is used to read image data from the device
* represented by handle h. Argument buf is a pointer to a memory
* area that is at least maxlen bytes long. The number of bytes
* returned is stored in *len. A backend must set this to zero when
* the call fails (i.e., when a status other than SANE_STATUS_GOOD is
* returned).
*
* When the call succeeds, the number of bytes returned can be
* anywhere in the range from 0 to maxlen bytes.
*/
SANE_Status
sane_read (SANE_Handle handle, SANE_Byte * buf, SANE_Int max_len, SANE_Int * len)
{
struct fujitsu *s = (struct fujitsu *) handle;
SANE_Status ret=SANE_STATUS_GOOD;
DBG (10, "sane_read: start\n");
*len=0;
/* maybe cancelled? */
if(!s->started){
DBG (5, "sane_read: not started, call sane_start\n");
return SANE_STATUS_CANCELLED;
}
/* sane_start required between sides */
if(s->eof_rx[s->side] && s->bytes_tx[s->side] == s->bytes_rx[s->side]){
DBG (15, "sane_read: returning eof\n");
s->eof_tx[s->side] = 1;
/* swap sides if user asked for low-mem mode, we are duplexing,
* and there is data waiting on the other side */
if(s->low_mem && s->source == SOURCE_ADF_DUPLEX
&& (s->bytes_rx[!s->side] > s->bytes_tx[!s->side]
|| (s->eof_rx[!s->side] && !s->eof_tx[!s->side])
)
){
s->side = !s->side;
}
return SANE_STATUS_EOF;
}
/* protect this block from sane_cancel */
s->reading = 1;
/* ----------------------------------------------
* try to read some data from scanner into buffer
* these functions are expected not to overrun */
/* 3091/2 are on crack, get their own duplex reader function */
if(s->source == SOURCE_ADF_DUPLEX
&& s->duplex_interlace == DUPLEX_INTERLACE_3091
){
ret = read_from_3091duplex(s);
if(ret){
DBG(5,"sane_read: 3091 returning %d\n",ret);
return ret;
}
} /* end 3091 */
/* alternating jpeg duplex interlacing */
else if(s->source == SOURCE_ADF_DUPLEX
&& s->s_params.format == SANE_FRAME_JPEG
&& s->jpeg_interlace == JPEG_INTERLACE_ALT
){
ret = read_from_JPEGduplex(s);
if(ret){
DBG(5,"sane_read: jpeg duplex returning %d\n",ret);
return ret;
}
} /* end alt jpeg */
/* alternating pnm duplex interlacing */
else if(s->source == SOURCE_ADF_DUPLEX
&& s->s_params.format != SANE_FRAME_JPEG
&& s->duplex_interlace == DUPLEX_INTERLACE_ALT
){
/* buffer front side */
ret = read_from_scanner(s, SIDE_FRONT);
if(ret){
DBG(5,"sane_read: front returning %d\n",ret);
return ret;
}
/* buffer back side, but don't get too far ahead of the front! */
if(s->bytes_rx[SIDE_BACK] < s->bytes_rx[SIDE_FRONT] + s->buffer_size){
ret = read_from_scanner(s, SIDE_BACK);
if(ret){
DBG(5,"sane_read: back returning %d\n",ret);
return ret;
}
}
} /* end alt pnm */
/* simplex or non-alternating duplex */
else{
ret = read_from_scanner(s, s->side);
if(ret){
DBG(5,"sane_read: side %d returning %d\n",s->side,ret);
return ret;
}
} /*end simplex*/
/* uncommon case, downsample and copy a block from buffer to frontend */
if(must_downsample(s)){
ret = downsample_from_buffer(s,buf,max_len,len,s->side);
}
/* common case, memcpy a block from buffer to frontend */
else{
ret = read_from_buffer(s,buf,max_len,len,s->side);
}
/*finished sending small buffer, reset it*/
if(s->buff_tx[s->side] == s->buff_rx[s->side]
&& s->buff_tot[s->side] < s->bytes_tot[s->side]
){
DBG (15, "sane_read: reset buffers\n");
s->buff_rx[s->side] = 0;
s->buff_tx[s->side] = 0;
}
/* check if user cancelled during this read */
ret = check_for_cancel(s);
/* swap sides if user asked for low-mem mode, we are duplexing,
* and there is data waiting on the other side */
if(s->low_mem && s->source == SOURCE_ADF_DUPLEX
&& (s->bytes_rx[!s->side] > s->bytes_tx[!s->side]
|| (s->eof_rx[!s->side] && !s->eof_tx[!s->side])
)
){
s->side = !s->side;
}
/* unprotect this block from sane_cancel */
s->reading = 0;
DBG (10, "sane_read: finish %d\n", ret);
return ret;
}
/* bare jpeg images dont contain resolution, but JFIF APP0 does, so we add */
static SANE_Status
inject_jfif_header(struct fujitsu *s, int side)
{
SANE_Status ret=SANE_STATUS_GOOD;
unsigned char out[] = {
0xFF, 0xE0, 0x00, 0x10, 0x4A, 0x46, 0x49, 0x46,
0x00, 0x01, 0x02, 0x01, 0x00, 0x48, 0x00, 0x48,
0x00, 0x00
};
size_t outLen=JFIF_APP0_LENGTH;
DBG (10, "inject_jfif_header: start %d\n", side);
putnbyte(out + 12, s->resolution_x, 2);
putnbyte(out + 14, s->resolution_y, 2);
memcpy(s->buffers[side]+s->buff_rx[side], out, outLen);
s->buff_rx[side] += outLen;
s->bytes_rx[side] += outLen;
DBG (10, "inject_jfif_header: finish %d\n", ret);
return ret;
}
static SANE_Status
read_from_JPEGduplex(struct fujitsu *s)
{
SANE_Status ret=SANE_STATUS_GOOD;
unsigned char cmd[READ_len];
size_t cmdLen = READ_len;
unsigned char * in;
size_t inLen = 0;
int bytes = s->buffer_size;
int i = 0;
DBG (10, "read_from_JPEGduplex: start\n");
if(s->eof_rx[SIDE_FRONT] && s->eof_rx[SIDE_BACK]){
DBG (10, "read_from_JPEGduplex: already have eofs, done\n");
return ret;
}
/* we don't know if the following read will give us front or back data
* so we only get enough to fill whichever is smaller (and not yet done) */
if(!s->eof_rx[SIDE_FRONT]){
int avail = s->buff_tot[SIDE_FRONT] - s->buff_rx[SIDE_FRONT];
if(bytes > avail){
bytes = avail;
/* leave space for JFIF header at start of image */
if(s->bytes_rx[SIDE_FRONT] < 2)
bytes -= JFIF_APP0_LENGTH;
}
}
if(!s->eof_rx[SIDE_BACK]){
int avail = s->buff_tot[SIDE_BACK] - s->buff_rx[SIDE_BACK];
if(bytes > avail){
bytes = avail;
/* leave space for JFIF header at start of image */
if(s->bytes_rx[SIDE_BACK] < 2)
bytes -= JFIF_APP0_LENGTH;
}
}
DBG(15, "read_from_JPEGduplex: fto:%d frx:%d bto:%d brx:%d pa:%d\n",
s->bytes_tot[SIDE_FRONT], s->bytes_rx[SIDE_FRONT],
s->bytes_tot[SIDE_BACK], s->bytes_rx[SIDE_BACK],
bytes);
/* this will happen if buffer is not drained yet */
if(bytes < 1){
DBG(5, "read_from_JPEGduplex: Warning: no bytes this pass\n");
return ret;
}
/* fi-6770A gets mad if you 'read' too soon on usb, see if it is ready */
if(!s->bytes_rx[SIDE_FRONT] && s->connection == CONNECTION_USB){
DBG (15, "read: start of usb page, checking RIC\n");
ret = scanner_control_ric(s,bytes,SIDE_FRONT);
if(ret){
DBG(5,"read: ric returning %d\n",ret);
return ret;
}
}
inLen = bytes;
in = malloc(inLen);
if(!in){
DBG(5, "read_from_JPEGduplex: not enough mem for buffer: %d\n",(int)inLen);
return SANE_STATUS_NO_MEM;
}
memset(cmd,0,cmdLen);
set_SCSI_opcode(cmd, READ_code);
set_R_datatype_code (cmd, R_datatype_imagedata);
/* interlaced jpeg duplex always reads from front */
set_R_window_id (cmd, WD_wid_front);
set_R_xfer_length (cmd, inLen);
ret = do_cmd (
s, 1, 0,
cmd, cmdLen,
NULL, 0,
in, &inLen
);
if (ret == SANE_STATUS_GOOD || ret == SANE_STATUS_EOF) {
DBG(15, "read_from_JPEGduplex: got GOOD/EOF, returning GOOD\n");
}
else if (ret == SANE_STATUS_DEVICE_BUSY) {
DBG(5, "read_from_JPEGduplex: got BUSY, returning GOOD\n");
inLen = 0;
ret = SANE_STATUS_GOOD;
}
else {
DBG(5, "read_from_JPEGduplex: error reading data status = %d\n", ret);
inLen = 0;
}
for(i=0;i<(int)inLen;i++){
/* about to change stage */
if(in[i] == 0xff && s->jpeg_ff_offset != 0){
s->jpeg_ff_offset=0;
continue;
}
/* last byte was an ff, this byte will change stage */
if(s->jpeg_ff_offset == 0){
/* first marker after SOI is not APP0, add one */
if(s->jpeg_stage == JPEG_STAGE_SOI && in[i] != 0xe0){
inject_jfif_header(s,SIDE_FRONT);
inject_jfif_header(s,SIDE_BACK);
s->jpeg_stage = JPEG_STAGE_HEAD;
}
/* SOI header, in both sides */
if(in[i] == 0xd8){
s->jpeg_stage = JPEG_STAGE_SOI;
DBG(15, "read_from_JPEGduplex: stage SOI\n");
}
/* headers (HuffTab/QTab/DRI), in both sides */
else if(in[i] == 0xc4 || in[i] == 0xdb || in[i] == 0xdd){
s->jpeg_stage = JPEG_STAGE_HEAD;
DBG(15, "read_from_JPEGduplex: stage head\n");
}
/* start of frame, in both sides, update x first */
else if(in[i]==0xc0){
s->jpeg_stage = JPEG_STAGE_SOF;
DBG(15, "read_from_JPEGduplex: stage sof\n");
}
/* start of scan, first few bytes of marker in both sides
* but rest in front */
else if(in[i]==0xda){
s->jpeg_stage = JPEG_STAGE_SOS;
DBG(15, "read_from_JPEGduplex: stage sos\n");
}
/* found image block. images are not interlaced */
/* copy to front, don't change RST */
else if(in[i] >= 0xd0 && in[i] <= 0xd7
&& s->jpeg_interlace == JPEG_INTERLACE_NONE){
s->jpeg_stage = JPEG_STAGE_FRONT;
DBG(35, "read_from_JPEGduplex: stage front (all)\n");
}
/* found even numbered image block. */
/* images are interlaced, so switch to back. */
/* also change from even RST to proper one */
else if(in[i] == 0xd0 || in[i] == 0xd2
|| in[i] == 0xd4 || in[i] == 0xd6){
s->jpeg_stage = JPEG_STAGE_BACK;
DBG(35, "read_from_JPEGduplex: stage back\n");
/* skip first RST for back side*/
if(!s->jpeg_back_rst){
DBG(15, "read_from_JPEGduplex: stage back jump\n");
s->jpeg_ff_offset++;
s->jpeg_back_rst++;
continue;
}
in[i] = 0xd0 + (s->jpeg_back_rst-1) % 8;
s->jpeg_back_rst++;
}
/* finished back image block, switch to front */
/* also change from odd RST to proper one */
else if(in[i] == 0xd1 || in[i] == 0xd3
|| in[i] == 0xd5 || in[i] == 0xd7){
s->jpeg_stage = JPEG_STAGE_FRONT;
DBG(35, "read_from_JPEGduplex: stage front\n");
in[i] = 0xd0 + (s->jpeg_front_rst % 8);
s->jpeg_front_rst++;
}
/* finished image, update totals */
else if(in[i]==0xd9){
s->jpeg_stage = JPEG_STAGE_EOI;
DBG(15, "read_from_JPEGduplex: stage eoi %d %d\n",(int)inLen,i);
}
/* unknown, warn */
else if(in[i] != 0xff){
DBG(15, "read_from_JPEGduplex: unknown %02x\n", in[i]);
}
}
s->jpeg_ff_offset++;
/* first x byte in start of frame, buffer it */
if(s->jpeg_stage == JPEG_STAGE_SOF && s->jpeg_ff_offset == 7){
s->jpeg_x_byte = in[i];
continue;
}
/* second x byte in start of frame */
if(s->jpeg_stage == JPEG_STAGE_SOF && s->jpeg_ff_offset == 8){
int width = (s->jpeg_x_byte << 8) | in[i];
/* if image width equals what we asked for, then
* the image is not interlaced, clean up the mess */
if(width == s->s_params.pixels_per_line){
DBG(15, "read_from_JPEGduplex: right width, req:%d got:%d\n",
s->s_params.pixels_per_line,width);
/* stop copying to the back */
s->jpeg_interlace = JPEG_INTERLACE_NONE;
/* clear what is already in the back */
s->bytes_rx[SIDE_BACK]=0;
s->lines_rx[SIDE_BACK]=0;
s->buff_rx[SIDE_BACK]=0;
/* and put the high-order width byte into front unchanged */
s->buffers[SIDE_FRONT][s->buff_rx[SIDE_FRONT]++] = s->jpeg_x_byte;
s->bytes_rx[SIDE_FRONT]++;
}
/* image is interlaced afterall, continue */
else{
DBG(15, "read_from_JPEGduplex: wrong width, req:%d got:%d\n",
s->s_params.pixels_per_line,width);
/* put the high-order width byte into front side, shifted down */
s->buffers[SIDE_FRONT][s->buff_rx[SIDE_FRONT]++] = width >> 9;
s->bytes_rx[SIDE_FRONT]++;
/* put the high-order width byte into back side, shifted down */
s->buffers[SIDE_BACK][s->buff_rx[SIDE_BACK]++] = width >> 9;
s->bytes_rx[SIDE_BACK]++;
/* shift down low order byte */
in[i] = (width >> 1) & 0xff;
}
}
/* copy these stages to front */
if(s->jpeg_stage == JPEG_STAGE_SOI
|| s->jpeg_stage == JPEG_STAGE_HEAD
|| s->jpeg_stage == JPEG_STAGE_SOF
|| s->jpeg_stage == JPEG_STAGE_SOS
|| s->jpeg_stage == JPEG_STAGE_EOI
|| s->jpeg_stage == JPEG_STAGE_FRONT
){
/* first byte after ff, send the ff first */
if(s->jpeg_ff_offset == 1){
s->buffers[SIDE_FRONT][s->buff_rx[SIDE_FRONT]++] = 0xff;
s->bytes_rx[SIDE_FRONT]++;
}
s->buffers[SIDE_FRONT][s->buff_rx[SIDE_FRONT]++] = in[i];
s->bytes_rx[SIDE_FRONT]++;
}
/* copy these stages to back */
if( s->jpeg_interlace == JPEG_INTERLACE_ALT
&&
( s->jpeg_stage == JPEG_STAGE_SOI
|| s->jpeg_stage == JPEG_STAGE_HEAD
|| s->jpeg_stage == JPEG_STAGE_SOF
|| s->jpeg_stage == JPEG_STAGE_SOS
|| s->jpeg_stage == JPEG_STAGE_EOI
|| s->jpeg_stage == JPEG_STAGE_BACK )
){
/* first byte after ff, send the ff first */
if(s->jpeg_ff_offset == 1){
s->buffers[SIDE_BACK][s->buff_rx[SIDE_BACK]++] = 0xff;
s->bytes_rx[SIDE_BACK]++;
}
s->buffers[SIDE_BACK][s->buff_rx[SIDE_BACK]++] = in[i];
s->bytes_rx[SIDE_BACK]++;
}
/* reached last byte of SOS section, next byte front */
if(s->jpeg_stage == JPEG_STAGE_SOS && s->jpeg_ff_offset == 0x0d){
s->jpeg_stage = JPEG_STAGE_FRONT;
}
/* last byte of file, update totals, bail out */
if(s->jpeg_stage == JPEG_STAGE_EOI){
s->eof_rx[SIDE_FRONT] = 1;
if(s->jpeg_interlace == JPEG_INTERLACE_ALT)
s->eof_rx[SIDE_BACK] = 1;
}
}
free(in);
/* jpeg uses in-band EOI marker, so this is ususally redundant */
if(ret == SANE_STATUS_EOF){
DBG(15, "read_from_JPEGduplex: got EOF, finishing\n");
s->eof_rx[SIDE_FRONT] = 1;
if(s->jpeg_interlace == JPEG_INTERLACE_ALT)
s->eof_rx[SIDE_BACK] = 1;
ret = SANE_STATUS_GOOD;
}
DBG (10, "read_from_JPEGduplex: finish\n");
return ret;
}
static SANE_Status
read_from_3091duplex(struct fujitsu *s)
{
SANE_Status ret=SANE_STATUS_GOOD;
unsigned char cmd[READ_len];
size_t cmdLen = READ_len;
unsigned char * in;
size_t inLen = 0;
int side = SIDE_FRONT;
int bytes = s->buffer_size;
int off = (s->duplex_raster_offset+s->duplex_offset) * s->resolution_y/300;
unsigned int i;
DBG (10, "read_from_3091duplex: start\n");
if(s->eof_rx[SIDE_FRONT] && s->eof_rx[SIDE_BACK]){
DBG (10, "read_from_3091duplex: already have eofs, done\n");
return ret;
}
/* we don't know if the following read will give us front,back or both data
* so we only get enough to fill whichever is smaller (and not yet done) */
if(!s->eof_rx[SIDE_FRONT]){
int avail = s->buff_tot[SIDE_FRONT] - s->buff_rx[SIDE_FRONT];
if(bytes > avail)
bytes = avail;
}
if(!s->eof_rx[SIDE_BACK]){
int avail = s->buff_tot[SIDE_BACK] - s->buff_rx[SIDE_BACK];
if(bytes > avail)
bytes = avail;
}
/* all requests must end on a line boundary */
bytes -= (bytes % s->s_params.bytes_per_line);
DBG(15, "read_from_3091duplex: front img: to:%d rx:%d tx:%d li:%d\n",
s->bytes_tot[SIDE_FRONT], s->bytes_rx[SIDE_FRONT],
s->bytes_tx[SIDE_FRONT], s->lines_rx[SIDE_FRONT]);
DBG(15, "read_from_3091duplex: front buf: to:%d rx:%d tx:%d\n",
s->buff_tot[SIDE_FRONT], s->buff_rx[SIDE_FRONT],
s->buff_tx[SIDE_FRONT]);
DBG(15, "read_from_3091duplex: back img: to:%d rx:%d tx:%d li:%d\n",
s->bytes_tot[SIDE_BACK], s->bytes_rx[SIDE_BACK],
s->bytes_tx[SIDE_BACK], s->lines_rx[SIDE_BACK]);
DBG(15, "read_from_3091duplex: back buf: to:%d rx:%d tx:%d\n",
s->buff_tot[SIDE_BACK], s->buff_rx[SIDE_BACK],
s->buff_tx[SIDE_BACK]);
DBG(15, "read_from_3091duplex: bu:%d pa:%d of:%d\n",
s->buffer_size, bytes, off);
/* this could happen if the front buffer is not drained fast enough */
if(bytes < 1){
DBG(10, "read_from_3091duplex: Warning: no bytes this pass\n");
return ret;
}
inLen = bytes;
in = malloc(inLen);
if(!in){
DBG(5, "read_from_3091duplex: not enough mem for buffer: %d\n",(int)inLen);
return SANE_STATUS_NO_MEM;
}
memset(cmd,0,cmdLen);
set_SCSI_opcode(cmd, READ_code);
set_R_datatype_code (cmd, R_datatype_imagedata);
/* 3091 duplex always reads from front */
set_R_window_id (cmd, WD_wid_front);
set_R_xfer_length (cmd, inLen);
ret = do_cmd (
s, 1, 0,
cmd, cmdLen,
NULL, 0,
in, &inLen
);
if (ret == SANE_STATUS_GOOD || ret == SANE_STATUS_EOF) {
DBG(15, "read_from_3091duplex: got GOOD/EOF, returning GOOD\n");
}
else if (ret == SANE_STATUS_DEVICE_BUSY) {
DBG(5, "read_from_3091duplex: got BUSY, returning GOOD\n");
inLen = 0;
ret = SANE_STATUS_GOOD;
}
else {
DBG(5, "read_from_3091duplex: error reading data block status = %d\n", ret);
inLen = 0;
}
/* loop thru all lines in read buffer */
for(i=0;i<inLen/s->s_params.bytes_per_line;i++){
/* start is front */
if(s->lines_rx[SIDE_FRONT] < off){
side=SIDE_FRONT;
}
/* end is back */
else if(s->eof_rx[SIDE_FRONT]){
side=SIDE_BACK;
}
/* odd are back */
else if( ((s->lines_rx[SIDE_FRONT] + s->lines_rx[SIDE_BACK] - off) % 2) ){
side=SIDE_BACK;
}
/* even are front */
else{
side=SIDE_FRONT;
}
if(s->s_mode == MODE_COLOR && s->color_interlace == COLOR_INTERLACE_3091){
copy_3091 (s, in + i*s->s_params.bytes_per_line, s->s_params.bytes_per_line, side);
}
else{
copy_buffer (s, in + i*s->s_params.bytes_per_line, s->s_params.bytes_per_line, side);
}
}
if(ret == SANE_STATUS_EOF){
DBG(15, "read_from_3091duplex: got EOF, finishing both sides\n");
s->eof_rx[SIDE_FRONT] = 1;
s->eof_rx[SIDE_BACK] = 1;
ret = SANE_STATUS_GOOD;
}
free(in);
DBG (10, "read_from_3091duplex: finish\n");
return ret;
}
static SANE_Status
read_from_scanner(struct fujitsu *s, int side)
{
SANE_Status ret=SANE_STATUS_GOOD;
unsigned char cmd[READ_len];
size_t cmdLen = READ_len;
unsigned char * in;
size_t inLen = 0;
int bytes = s->buffer_size;
int avail = s->buff_tot[side] - s->buff_rx[side];
int remain = s->bytes_tot[side] - s->bytes_rx[side];
DBG (10, "read_from_scanner: start %d\n", side);
if(s->eof_rx[side]){
DBG (10, "read_from_scanner: already have eof, done\n");
return ret;
}
/* figure out the max amount to transfer */
if(bytes > avail)
bytes = avail;
/* all requests must end on line boundary */
bytes -= (bytes % s->s_params.bytes_per_line);
/* some larger scanners require even bytes per block */
/* so we get even lines, but not on the last block */
/* cause odd number of lines would never finish */
if(bytes % 2 && bytes < remain){
bytes -= s->s_params.bytes_per_line;
}
/* jpeg scans leave space for JFIF header at start of image */
if(s->s_params.format == SANE_FRAME_JPEG && s->bytes_rx[side] < 2)
bytes -= JFIF_APP0_LENGTH;
DBG(15, "read_from_scanner: si:%d re:%d bs:%d by:%d av:%d\n",
side, remain, s->buffer_size, bytes, avail);
DBG(15, "read_from_scanner: img to:%d rx:%d tx:%d li:%d\n",
s->bytes_tot[side], s->bytes_rx[side], s->bytes_tx[side],
s->lines_rx[side]);
DBG(15, "read_from_scanner: buf to:%d rx:%d tx:%d\n",
s->buff_tot[side], s->buff_rx[side], s->buff_tx[side]);
/* this will happen if buffer is not drained yet */
if(bytes < 1){
DBG(5, "read_from_scanner: no bytes this pass\n");
return ret;
}
/* fi-6770A gets mad if you 'read' too soon on usb, see if it is ready */
if(!s->bytes_rx[side] && s->connection == CONNECTION_USB){
DBG (15, "read_from_scanner: start of usb page, checking RIC\n");
ret = scanner_control_ric(s,bytes,side);
if(ret){
DBG(5,"read_from_scanner: ric returning %d\n",ret);
return ret;
}
}
inLen = bytes;
in = malloc(inLen);
if(!in){
DBG(5, "read_from_scanner: not enough mem for buffer: %d\n",(int)inLen);
return SANE_STATUS_NO_MEM;
}
memset(cmd,0,cmdLen);
set_SCSI_opcode(cmd, READ_code);
set_R_datatype_code (cmd, R_datatype_imagedata);
if (side == SIDE_BACK) {
set_R_window_id (cmd, WD_wid_back);
}
else{
set_R_window_id (cmd, WD_wid_front);
}
set_R_xfer_length (cmd, inLen);
ret = do_cmd (
s, 1, 0,
cmd, cmdLen,
NULL, 0,
in, &inLen
);
if (ret == SANE_STATUS_GOOD || ret == SANE_STATUS_EOF) {
DBG(15, "read_from_scanner: got GOOD/EOF, returning GOOD\n");
ret = SANE_STATUS_GOOD;
}
else if (ret == SANE_STATUS_DEVICE_BUSY) {
DBG(5, "read_from_scanner: got BUSY, returning GOOD\n");
inLen = 0;
ret = SANE_STATUS_GOOD;
}
else {
DBG(5, "read_from_scanner: error reading data block status = %d\n",ret);
inLen = 0;
}
DBG(15, "read_from_scanner: read %lu bytes\n",(unsigned long)inLen);
if(inLen){
if(s->s_mode==MODE_COLOR && s->color_interlace == COLOR_INTERLACE_3091){
copy_3091 (s, in, inLen, side);
}
else if(s->s_params.format == SANE_FRAME_JPEG){
copy_JPEG (s, in, inLen, side);
}
else{
copy_buffer (s, in, inLen, side);
}
}
free(in);
/* if this was a short read or not, log it */
s->ili_rx[side] = s->rs_ili;
if(s->ili_rx[side]){
DBG(15, "read_from_scanner: got ILI\n");
}
/* if this was an end of medium, log it */
if(s->rs_eom){
DBG(15, "read_from_scanner: got EOM\n");
s->eom_rx = 1;
}
/* paper ran out. lets try to set the eof flag on both sides,
* but only if that side had a short read last time */
if(s->eom_rx){
int i;
for(i=0;i<2;i++){
if(s->ili_rx[i]){
DBG(15, "read_from_scanner: finishing side %d\n",i);
s->eof_rx[i] = 1;
}
}
}
DBG (10, "read_from_scanner: finish\n");
return ret;
}
static SANE_Status
copy_3091(struct fujitsu *s, unsigned char * buf, int len, int side)
{
SANE_Status ret=SANE_STATUS_GOOD;
int i, j, dest, boff, goff;
DBG (10, "copy_3091: start\n");
/* Data is RR...GG...BB... on each line,
* green is back 8 lines from red at 300 dpi
* blue is back 4 lines from red at 300 dpi.
*
* Here, we get things on correct line, and
* interlace to make RGBRGB.
*
* We add the user-supplied offsets before we scale
* so that they are independent of scanning resolution.
*/
goff = (s->color_raster_offset+s->green_offset) * s->resolution_y/150;
boff = (s->color_raster_offset+s->blue_offset) * s->resolution_y/300;
/* loop thru all lines in read buffer */
for(i=0;i<len;i+=s->s_params.bytes_per_line){
/* red at start of line */
dest = s->lines_rx[side] * s->s_params.bytes_per_line;
if(dest >= 0 && dest < s->bytes_tot[side]){
for (j=0; j<s->s_params.pixels_per_line; j++){
s->buffers[side][dest+j*3] = buf[i+j];
}
}
/* green is in middle of line */
dest = (s->lines_rx[side] - goff) * s->s_params.bytes_per_line;
if(dest >= 0 && dest < s->bytes_tot[side]){
for (j=0; j<s->s_params.pixels_per_line; j++){
s->buffers[side][dest+j*3+1] = buf[i+s->s_params.pixels_per_line+j];
}
}
/* blue is at end of line */
dest = (s->lines_rx[side] - boff) * s->s_params.bytes_per_line;
if(dest >= 0 && dest < s->bytes_tot[side]){
for (j=0; j<s->s_params.pixels_per_line; j++){
s->buffers[side][dest+j*3+2] = buf[i+2*s->s_params.pixels_per_line+j];
}
}
s->lines_rx[side]++;
}
/* even if we have read data, we may not have any
* full lines loaded yet, so we may have to lie */
i = (s->lines_rx[side]-goff) * s->s_params.bytes_per_line;
if(i < 0){
i = 0;
}
s->bytes_rx[side] = i;
s->buff_rx[side] = i;
if(s->bytes_rx[side] == s->bytes_tot[side]){
s->eof_rx[side] = 1;
}
DBG(15, "copy_3091: si:%d imgrx:%d bufrx:%d li:%d eof:%d\n",
side, s->bytes_rx[side], s->buff_rx[side], s->lines_rx[side],
s->eof_rx[side]);
DBG (10, "copy_3091: finish\n");
return ret;
}
static SANE_Status
copy_JPEG(struct fujitsu *s, unsigned char * buf, int len, int side)
{
SANE_Status ret=SANE_STATUS_GOOD;
int i, seen = 0;
DBG (10, "copy_JPEG: start\n");
/* A jpeg image starts with the SOI marker, FF D8.
* This is optionally followed by the JFIF APP0
* marker, FF E0. If that marker is not present,
* we add it, so we can insert the resolution */
if(!s->bytes_rx[side] && len >= 4
&& buf[0] == 0xFF && buf[1] == 0xD8
&& buf[2] == 0xFF && buf[3] != 0xE0
){
/* SOI marker */
for (i=0; i<2; i++){
s->buffers[side][s->buff_rx[side]++] = buf[i];
s->bytes_rx[side]++;
seen++;
}
/* JFIF header after SOI */
inject_jfif_header(s,side);
}
memcpy(s->buffers[side]+s->buff_rx[side],buf+seen,len-seen);
s->buff_rx[side] += len-seen;
s->bytes_rx[side] += len-seen;
/* should never happen with jpeg */
if(s->bytes_rx[side] == s->bytes_tot[side]){
s->eof_rx[side] = 1;
}
DBG (10, "copy_JPEG: finish\n");
return ret;
}
static SANE_Status
copy_buffer(struct fujitsu *s, unsigned char * buf, int len, int side)
{
SANE_Status ret=SANE_STATUS_GOOD;
int i, j;
int bwidth = s->s_params.bytes_per_line;
int pwidth = s->s_params.pixels_per_line;
DBG (10, "copy_buffer: start\n");
/* invert image if scanner needs it for this mode */
/* jpeg data does not use inverting */
if(s->s_params.format != SANE_FRAME_JPEG && s->reverse_by_mode[s->s_mode]){
for(i=0; i<len; i++){
buf[i] ^= 0xff;
}
}
/* scanners interlace colors in many different ways */
if(s->s_params.format == SANE_FRAME_RGB){
switch (s->color_interlace) {
/* scanner returns pixel data as bgrbgr... */
case COLOR_INTERLACE_BGR:
for(i=0; i<len; i+=bwidth){
for (j=0; j<pwidth; j++){
s->buffers[side][s->buff_rx[side]++] = buf[i+j*3+2];
s->buffers[side][s->buff_rx[side]++] = buf[i+j*3+1];
s->buffers[side][s->buff_rx[side]++] = buf[i+j*3];
}
}
break;
/* one line has the following format: rrr...rrrggg...gggbbb...bbb */
case COLOR_INTERLACE_RRGGBB:
for(i=0; i<len; i+=bwidth){
for (j=0; j<pwidth; j++){
s->buffers[side][s->buff_rx[side]++] = buf[i+j];
s->buffers[side][s->buff_rx[side]++] = buf[i+pwidth+j];
s->buffers[side][s->buff_rx[side]++] = buf[i+2*pwidth+j];
}
}
break;
default:
memcpy(s->buffers[side]+s->buff_rx[side],buf,len);
s->buff_rx[side] += len;
break;
}
}
/* jpeg/gray/ht/binary */
else{
memcpy(s->buffers[side]+s->buff_rx[side],buf,len);
s->buff_rx[side] += len;
}
s->bytes_rx[side] += len;
s->lines_rx[side] += len/s->s_params.bytes_per_line;
if(s->bytes_rx[side] == s->bytes_tot[side]){
s->eof_rx[side] = 1;
}
DBG (10, "copy_buffer: finish\n");
return ret;
}
static SANE_Status
read_from_buffer(struct fujitsu *s, SANE_Byte * buf,
SANE_Int max_len, SANE_Int * len, int side)
{
SANE_Status ret=SANE_STATUS_GOOD;
int bytes = max_len;
int remain = s->buff_rx[side] - s->buff_tx[side];
DBG (10, "read_from_buffer: start\n");
/* figure out the max amount to transfer */
if(bytes > remain){
bytes = remain;
}
*len = bytes;
DBG(15, "read_from_buffer: si:%d re:%d ml:%d by:%d\n",
side, remain, max_len, bytes);
DBG(15, "read_from_buffer: img to:%d rx:%d tx:%d\n",
s->bytes_tot[side], s->bytes_rx[side], s->bytes_tx[side]);
DBG(15, "read_from_buffer: buf to:%d rx:%d tx:%d\n",
s->buff_tot[side], s->buff_rx[side], s->buff_tx[side]);
/*FIXME this needs to timeout eventually */
if(!bytes){
DBG(5,"read_from_buffer: nothing to do\n");
return SANE_STATUS_GOOD;
}
memcpy(buf,s->buffers[side]+s->buff_tx[side],bytes);
s->buff_tx[side] += bytes;
s->bytes_tx[side] += bytes;
DBG (10, "read_from_buffer: finish\n");
return ret;
}
/* we have bytes of higher mode image data in s->buffers */
/* user asked for lower mode image. downsample and copy to buf */
static SANE_Status
downsample_from_buffer(struct fujitsu *s, SANE_Byte * buf,
SANE_Int max_len, SANE_Int * len, int side)
{
SANE_Status ret=SANE_STATUS_GOOD;
DBG (10, "downsample_from_buffer: start %d %d %d %d\n", s->bytes_rx[side], s->bytes_tx[side], s->buff_rx[side], s->buff_tx[side]);
if(s->s_mode == MODE_COLOR && s->u_mode == MODE_GRAYSCALE){
while(*len < max_len && s->buff_rx[side] - s->buff_tx[side] >= 3){
int gray = 0;
switch (s->dropout_color) {
case COLOR_RED:
gray = *(s->buffers[side]+s->buff_tx[side]) * 3;
break;
case COLOR_GREEN:
gray = *(s->buffers[side]+s->buff_tx[side]+1) * 3;
break;
case COLOR_BLUE:
gray = *(s->buffers[side]+s->buff_tx[side]+2) * 3;
break;
default:
gray = *(s->buffers[side]+s->buff_tx[side])
+ *(s->buffers[side]+s->buff_tx[side]+1)
+ *(s->buffers[side]+s->buff_tx[side]+2);
break;
}
/* bookkeeping for input */
s->buff_tx[side] += 3;
s->bytes_tx[side] += 3;
/* add byte to output */
*(buf + *len) = gray/3;
(*len)++;
}
}
else if(s->s_mode == MODE_COLOR && s->u_mode == MODE_LINEART){
/* threshold of 0 is actually middle of range */
/*FIXME: add dynamic threshold? */
unsigned char thresh = (s->threshold ? s->threshold : 127);
while(*len < max_len && s->buff_rx[side] - s->buff_tx[side] >= 24){
int i;
unsigned char out = 0;
for(i=0; i<8; i++){
int gray = 0;
switch (s->dropout_color) {
case COLOR_RED:
gray = *(s->buffers[side]+s->buff_tx[side]) * 3;
break;
case COLOR_GREEN:
gray = *(s->buffers[side]+s->buff_tx[side]+1) * 3;
break;
case COLOR_BLUE:
gray = *(s->buffers[side]+s->buff_tx[side]+2) * 3;
break;
default:
gray = *(s->buffers[side]+s->buff_tx[side])
+ *(s->buffers[side]+s->buff_tx[side]+1)
+ *(s->buffers[side]+s->buff_tx[side]+2);
break;
}
/* black if input gray is lower than threshold */
if(gray/3 < thresh){
out |= (0x80 >> i);
}
/* bookkeeping for input */
s->buff_tx[side] += 3;
s->bytes_tx[side] += 3;
}
/* add byte to output */
*(buf + *len) = out;
(*len)++;
}
}
else{
DBG (5, "downsample_from_buffer: invalid mode combination\n");
ret = SANE_STATUS_INVAL;
}
DBG (10, "downsample_from_buffer: finish %d %d %d %d\n", s->bytes_rx[side], s->bytes_tx[side], s->buff_rx[side], s->buff_tx[side]);
return ret;
}
/*
* @@ Section 5 - SANE cleanup functions
*/
/*
* Cancels a scan.
*
* It has been said on the mailing list that sane_cancel is a bit of a
* misnomer because it is routinely called to signal the end of a
* batch - quoting David Mosberger-Tang:
*
* > In other words, the idea is to have sane_start() be called, and
* > collect as many images as the frontend wants (which could in turn
* > consist of multiple frames each as indicated by frame-type) and
* > when the frontend is done, it should call sane_cancel().
* > Sometimes it's better to think of sane_cancel() as "sane_stop()"
* > but that name would have had some misleading connotations as
* > well, that's why we stuck with "cancel".
*
* The current consensus regarding duplex and ADF scans seems to be
* the following call sequence: sane_start; sane_read (repeat until
* EOF); sane_start; sane_read... and then call sane_cancel if the
* batch is at an end. I.e. do not call sane_cancel during the run but
* as soon as you get a SANE_STATUS_NO_DOCS.
*
* From the SANE spec:
* This function is used to immediately or as quickly as possible
* cancel the currently pending operation of the device represented by
* handle h. This function can be called at any time (as long as
* handle h is a valid handle) but usually affects long-running
* operations only (such as image is acquisition). It is safe to call
* this function asynchronously (e.g., from within a signal handler).
* It is important to note that completion of this operaton does not
* imply that the currently pending operation has been cancelled. It
* only guarantees that cancellation has been initiated. Cancellation
* completes only when the cancelled call returns (typically with a
* status value of SANE_STATUS_CANCELLED). Since the SANE API does
* not require any other operations to be re-entrant, this implies
* that a frontend must not call any other operation until the
* cancelled operation has returned.
*/
void
sane_cancel (SANE_Handle handle)
{
struct fujitsu * s = (struct fujitsu *) handle;
DBG (10, "sane_cancel: start\n");
s->cancelled = 1;
/* if there is no other running function to check, we do it */
if(!s->reading)
check_for_cancel(s);
DBG (10, "sane_cancel: finish\n");
}
/*
* Ends use of the scanner.
*
* From the SANE spec:
* This function terminates the association between the device handle
* passed in argument h and the device it represents. If the device is
* presently active, a call to sane_cancel() is performed first. After
* this function returns, handle h must not be used anymore.
*/
void
sane_close (SANE_Handle handle)
{
struct fujitsu * s = (struct fujitsu *) handle;
DBG (10, "sane_close: start\n");
/*clears any held scans*/
mode_select_buff(s);
disconnect_fd(s);
DBG (10, "sane_close: finish\n");
}
static SANE_Status
disconnect_fd (struct fujitsu *s)
{
DBG (10, "disconnect_fd: start\n");
if(s->fd > -1){
if (s->connection == CONNECTION_USB) {
DBG (15, "disconnecting usb device\n");
sanei_usb_close (s->fd);
}
else if (s->connection == CONNECTION_SCSI) {
DBG (15, "disconnecting scsi device\n");
sanei_scsi_close (s->fd);
}
s->fd = -1;
}
DBG (10, "disconnect_fd: finish\n");
return SANE_STATUS_GOOD;
}
/*
* Terminates the backend.
*
* From the SANE spec:
* This function must be called to terminate use of a backend. The
* function will first close all device handles that still might be
* open (it is recommended to close device handles explicitly through
* a call to sane_close(), but backends are required to release all
* resources upon a call to this function). After this function
* returns, no function other than sane_init() may be called
* (regardless of the status value returned by sane_exit(). Neglecting
* to call this function may result in some resources not being
* released properly.
*/
void
sane_exit (void)
{
struct fujitsu *dev, *next;
DBG (10, "sane_exit: start\n");
for (dev = fujitsu_devList; dev; dev = next) {
disconnect_fd(dev);
next = dev->next;
free (dev);
}
if (sane_devArray)
free (sane_devArray);
fujitsu_devList = NULL;
sane_devArray = NULL;
DBG (10, "sane_exit: finish\n");
}
/*
* @@ Section 6 - misc helper functions
*/
/*
* Called by the SANE SCSI core and our usb code on device errors
* parses the request sense return data buffer,
* decides the best SANE_Status for the problem, produces debug msgs,
* and copies the sense buffer into the scanner struct
*/
static SANE_Status
sense_handler (int fd, unsigned char * sensed_data, void *arg)
{
struct fujitsu *s = arg;
unsigned int sense = get_RS_sense_key (sensed_data);
unsigned int asc = get_RS_ASC (sensed_data);
unsigned int ascq = get_RS_ASCQ (sensed_data);
DBG (5, "sense_handler: start\n");
/* kill compiler warning */
fd = fd;
/* copy the rs return data into the scanner struct
so that the caller can use it if he wants */
s->rs_info = get_RS_information (sensed_data);
s->rs_eom = get_RS_EOM (sensed_data);
s->rs_ili = get_RS_ILI (sensed_data);
DBG (5, "Sense=%#02x, ASC=%#02x, ASCQ=%#02x, EOM=%d, ILI=%d, info=%#08lx\n", sense, asc, ascq, s->rs_eom, s->rs_ili, (unsigned long)s->rs_info);
switch (sense) {
case 0x0:
if (0x80 == asc) {
DBG (5, "No sense: hardware status bits?\n");
return SANE_STATUS_GOOD;
}
if (0x00 != asc) {
DBG (5, "No sense: unknown asc\n");
return SANE_STATUS_IO_ERROR;
}
if (0x00 != ascq) {
DBG (5, "No sense: unknown ascq\n");
return SANE_STATUS_IO_ERROR;
}
/* ready, but short read */
if (s->rs_ili) {
DBG (5, "No sense: ILI remainder:%lu\n",(unsigned long)s->rs_info);
}
/* ready, but end of paper */
if (s->rs_eom) {
DBG (5, "No sense: EOM\n");
return SANE_STATUS_EOF;
}
DBG (5, "No sense: ready\n");
return SANE_STATUS_GOOD;
case 0x2:
if (0x00 != asc) {
DBG (5, "Not ready: unknown asc\n");
return SANE_STATUS_IO_ERROR;
}
if (0x00 != ascq) {
DBG (5, "Not ready: unknown ascq\n");
return SANE_STATUS_IO_ERROR;
}
DBG (5, "Not ready: busy\n");
return SANE_STATUS_DEVICE_BUSY;
break;
case 0x3:
if (0x80 != asc) {
DBG (5, "Medium error: unknown asc\n");
return SANE_STATUS_IO_ERROR;
}
if (0x01 == ascq) {
DBG (5, "Medium error: paper jam\n");
return SANE_STATUS_JAMMED;
}
if (0x02 == ascq) {
DBG (5, "Medium error: cover open\n");
return SANE_STATUS_COVER_OPEN;
}
if (0x03 == ascq) {
DBG (5, "Medium error: hopper empty\n");
return SANE_STATUS_NO_DOCS;
}
if (0x04 == ascq) {
DBG (5, "Medium error: unusual paper\n");
return SANE_STATUS_JAMMED;
}
if (0x07 == ascq) {
DBG (5, "Medium error: double feed\n");
return SANE_STATUS_JAMMED;
}
if (0x08 == ascq) {
DBG (5, "Medium error: ADF setup error\n");
return SANE_STATUS_JAMMED;
}
if (0x09 == ascq) {
DBG (5, "Medium error: Carrier sheet\n");
return SANE_STATUS_JAMMED;
}
if (0x10 == ascq) {
DBG (5, "Medium error: no ink cartridge\n");
return SANE_STATUS_IO_ERROR;
}
if (0x13 == ascq) {
DBG (5, "Medium error: temporary no data\n");
return SANE_STATUS_DEVICE_BUSY;
}
if (0x14 == ascq) {
DBG (5, "Medium error: endorser error\n");
return SANE_STATUS_IO_ERROR;
}
if (0x20 == ascq) {
DBG (5, "Medium error: Stop button\n");
return SANE_STATUS_NO_DOCS;
}
if (0x22 == ascq) {
DBG (5, "Medium error: scanning halted\n");
return SANE_STATUS_CANCELLED;
}
if (0x30 == ascq) {
DBG (5, "Medium error: Not enough paper\n");
return SANE_STATUS_NO_DOCS;
}
if (0x31 == ascq) {
DBG (5, "Medium error: scanning disabled\n");
return SANE_STATUS_IO_ERROR;
}
if (0x32 == ascq) {
DBG (5, "Medium error: scanning paused\n");
return SANE_STATUS_DEVICE_BUSY;
}
if (0x33 == ascq) {
DBG (5, "Medium error: WiFi control error\n");
return SANE_STATUS_IO_ERROR;
}
DBG (5, "Medium error: unknown ascq\n");
return SANE_STATUS_IO_ERROR;
break;
case 0x4:
if (0x80 != asc && 0x44 != asc) {
DBG (5, "Hardware error: unknown asc\n");
return SANE_STATUS_IO_ERROR;
}
if ((0x44 == asc) && (0x00 == ascq)) {
DBG (5, "Hardware error: EEPROM error\n");
return SANE_STATUS_IO_ERROR;
}
if ((0x80 == asc) && (0x01 == ascq)) {
DBG (5, "Hardware error: FB motor fuse\n");
return SANE_STATUS_IO_ERROR;
}
if ((0x80 == asc) && (0x02 == ascq)) {
DBG (5, "Hardware error: heater fuse\n");
return SANE_STATUS_IO_ERROR;
}
if ((0x80 == asc) && (0x03 == ascq)) {
DBG (5, "Hardware error: lamp fuse\n");
return SANE_STATUS_IO_ERROR;
}
if ((0x80 == asc) && (0x04 == ascq)) {
DBG (5, "Hardware error: ADF motor fuse\n");
return SANE_STATUS_IO_ERROR;
}
if ((0x80 == asc) && (0x05 == ascq)) {
DBG (5, "Hardware error: mechanical error\n");
return SANE_STATUS_IO_ERROR;
}
if ((0x80 == asc) && (0x06 == ascq)) {
DBG (5, "Hardware error: optical error\n");
return SANE_STATUS_IO_ERROR;
}
if ((0x80 == asc) && (0x07 == ascq)) {
DBG (5, "Hardware error: Fan error\n");
return SANE_STATUS_IO_ERROR;
}
if ((0x80 == asc) && (0x08 == ascq)) {
DBG (5, "Hardware error: IPC option error\n");
return SANE_STATUS_IO_ERROR;
}
if ((0x80 == asc) && (0x10 == ascq)) {
DBG (5, "Hardware error: endorser error\n");
return SANE_STATUS_IO_ERROR;
}
if ((0x80 == asc) && (0x11 == ascq)) {
DBG (5, "Hardware error: endorser fuse\n");
return SANE_STATUS_IO_ERROR;
}
if ((0x80 == asc) && (0x80 == ascq)) {
DBG (5, "Hardware error: interface board timeout\n");
return SANE_STATUS_IO_ERROR;
}
if ((0x80 == asc) && (0x81 == ascq)) {
DBG (5, "Hardware error: interface board error 1\n");
return SANE_STATUS_IO_ERROR;
}
if ((0x80 == asc) && (0x82 == ascq)) {
DBG (5, "Hardware error: interface board error 2\n");
return SANE_STATUS_IO_ERROR;
}
DBG (5, "Hardware error: unknown asc/ascq\n");
return SANE_STATUS_IO_ERROR;
break;
case 0x5:
if ((0x00 == asc) && (0x00 == ascq)) {
DBG (5, "Illegal request: paper edge detected too soon\n");
return SANE_STATUS_INVAL;
}
if ((0x1a == asc) && (0x00 == ascq)) {
DBG (5, "Illegal request: Parameter list error\n");
return SANE_STATUS_INVAL;
}
if ((0x20 == asc) && (0x00 == ascq)) {
DBG (5, "Illegal request: invalid command\n");
return SANE_STATUS_INVAL;
}
if ((0x24 == asc) && (0x00 == ascq)) {
DBG (5, "Illegal request: invalid CDB field\n");
return SANE_STATUS_INVAL;
}
if ((0x25 == asc) && (0x00 == ascq)) {
DBG (5, "Illegal request: unsupported logical unit\n");
return SANE_STATUS_UNSUPPORTED;
}
if ((0x26 == asc) && (0x00 == ascq)) {
DBG (5, "Illegal request: invalid field in parm list\n");
if (get_RS_additional_length(sensed_data) >= 0x0a) {
DBG (5, "Offending byte is %#02x\n", get_RS_offending_byte(sensed_data));
/* move this to set_window() ? */
if (get_RS_offending_byte(sensed_data) >= 8) {
DBG (5, "Window desc block? byte %#02x\n",get_RS_offending_byte(sensed_data)-8);
}
}
return SANE_STATUS_INVAL;
}
if ((0x2C == asc) && (0x00 == ascq)) {
DBG (5, "Illegal request: command sequence error\n");
return SANE_STATUS_INVAL;
}
if ((0x2C == asc) && (0x02 == ascq)) {
DBG (5, "Illegal request: wrong window combination \n");
return SANE_STATUS_INVAL;
}
DBG (5, "Illegal request: unknown asc/ascq\n");
return SANE_STATUS_IO_ERROR;
break;
case 0x6:
if ((0x00 == asc) && (0x00 == ascq)) {
DBG (5, "Unit attention: device reset\n");
return SANE_STATUS_GOOD;
}
if ((0x80 == asc) && (0x01 == ascq)) {
DBG (5, "Unit attention: power saving\n");
return SANE_STATUS_GOOD;
}
DBG (5, "Unit attention: unknown asc/ascq\n");
return SANE_STATUS_IO_ERROR;
break;
case 0xb:
if ((0x43 == asc) && (0x00 == ascq)) {
DBG (5, "Aborted command: message error\n");
return SANE_STATUS_IO_ERROR;
}
if ((0x45 == asc) && (0x00 == ascq)) {
DBG (5, "Aborted command: select failure\n");
return SANE_STATUS_IO_ERROR;
}
if ((0x47 == asc) && (0x00 == ascq)) {
DBG (5, "Aborted command: SCSI parity error\n");
return SANE_STATUS_IO_ERROR;
}
if ((0x48 == asc) && (0x00 == ascq)) {
DBG (5, "Aborted command: initiator error message\n");
return SANE_STATUS_IO_ERROR;
}
if ((0x4e == asc) && (0x00 == ascq)) {
DBG (5, "Aborted command: overlapped commands\n");
return SANE_STATUS_IO_ERROR;
}
if ((0x80 == asc) && (0x01 == ascq)) {
DBG (5, "Aborted command: image transfer error\n");
return SANE_STATUS_IO_ERROR;
}
if ((0x80 == asc) && (0x03 == ascq)) {
DBG (5, "Aborted command: JPEG overflow error\n");
return SANE_STATUS_NO_MEM;
}
DBG (5, "Aborted command: unknown asc/ascq\n");
return SANE_STATUS_IO_ERROR;
break;
default:
DBG (5, "Unknown Sense Code\n");
return SANE_STATUS_IO_ERROR;
}
DBG (5, "sense_handler: should never happen!\n");
return SANE_STATUS_IO_ERROR;
}
/*
* take a bunch of pointers, send commands to scanner
*/
static SANE_Status
do_cmd(struct fujitsu *s, int runRS, int shortTime,
unsigned char * cmdBuff, size_t cmdLen,
unsigned char * outBuff, size_t outLen,
unsigned char * inBuff, size_t * inLen
)
{
/* unset the request sense vars first */
s->rs_info = 0;
s->rs_ili = 0;
s->rs_eom = 0;
if (s->connection == CONNECTION_SCSI) {
return do_scsi_cmd(s, runRS, shortTime,
cmdBuff, cmdLen,
outBuff, outLen,
inBuff, inLen
);
}
if (s->connection == CONNECTION_USB) {
return do_usb_cmd(s, runRS, shortTime,
cmdBuff, cmdLen,
outBuff, outLen,
inBuff, inLen
);
}
return SANE_STATUS_INVAL;
}
SANE_Status
do_scsi_cmd(struct fujitsu *s, int runRS, int shortTime,
unsigned char * cmdBuff, size_t cmdLen,
unsigned char * outBuff, size_t outLen,
unsigned char * inBuff, size_t * inLen
)
{
int ret;
/*shut up compiler*/
runRS=runRS;
shortTime=shortTime;
DBG(10, "do_scsi_cmd: start\n");
DBG(25, "cmd: writing %d bytes\n", (int)cmdLen);
hexdump(30, "cmd: >>", cmdBuff, cmdLen);
if(outBuff && outLen){
DBG(25, "out: writing %d bytes\n", (int)outLen);
hexdump(30, "out: >>", outBuff, outLen);
}
if (inBuff && inLen){
DBG(25, "in: reading %d bytes\n", (int)*inLen);
memset(inBuff,0,*inLen);
}
ret = sanei_scsi_cmd2(s->fd, cmdBuff, cmdLen, outBuff, outLen, inBuff, inLen);
if(ret != SANE_STATUS_GOOD && ret != SANE_STATUS_EOF){
DBG(5,"do_scsi_cmd: return '%s'\n",sane_strstatus(ret));
return ret;
}
/* FIXME: should we look at s->rs_info here? */
if (inBuff && inLen){
hexdump(30, "in: <<", inBuff, *inLen);
DBG(25, "in: read %d bytes\n", (int)*inLen);
}
DBG(10, "do_scsi_cmd: finish\n");
return ret;
}
SANE_Status
do_usb_cmd(struct fujitsu *s, int runRS, int shortTime,
unsigned char * cmdBuff, size_t cmdLen,
unsigned char * outBuff, size_t outLen,
unsigned char * inBuff, size_t * inLen
)
{
/*sanei_usb overwrites the transfer size,
* so make some local copies */
size_t usb_cmdLen = USB_COMMAND_LEN;
size_t usb_outLen = outLen;
size_t usb_statLen = USB_STATUS_LEN;
size_t askLen = 0;
/*copy the callers buffs into larger, padded ones*/
unsigned char usb_cmdBuff[USB_COMMAND_LEN];
unsigned char usb_statBuff[USB_STATUS_LEN];
int cmdTime = USB_COMMAND_TIME;
int outTime = USB_DATA_TIME;
int inTime = USB_DATA_TIME;
int statTime = USB_STATUS_TIME;
int ret = 0;
int ret2 = 0;
DBG (10, "do_usb_cmd: start\n");
if(shortTime){
cmdTime = USB_COMMAND_TIME/60;
outTime = USB_DATA_TIME/60;
inTime = USB_DATA_TIME/60;
statTime = USB_STATUS_TIME/60;
}
/* build a USB packet around the SCSI command */
memset(&usb_cmdBuff,0,USB_COMMAND_LEN);
usb_cmdBuff[0] = USB_COMMAND_CODE;
memcpy(&usb_cmdBuff[USB_COMMAND_OFFSET],cmdBuff,cmdLen);
/* change timeout */
sanei_usb_set_timeout(cmdTime);
/* write the command out */
DBG(25, "cmd: writing %d bytes, timeout %d\n", USB_COMMAND_LEN, cmdTime);
hexdump(30, "cmd: >>", usb_cmdBuff, USB_COMMAND_LEN);
ret = sanei_usb_write_bulk(s->fd, usb_cmdBuff, &usb_cmdLen);
DBG(25, "cmd: wrote %d bytes, retVal %d\n", (int)usb_cmdLen, ret);
if(ret == SANE_STATUS_EOF){
DBG(5,"cmd: got EOF, returning IO_ERROR\n");
return SANE_STATUS_IO_ERROR;
}
if(ret != SANE_STATUS_GOOD){
DBG(5,"cmd: return error '%s'\n",sane_strstatus(ret));
return ret;
}
if(usb_cmdLen != USB_COMMAND_LEN){
DBG(5,"cmd: wrong size %d/%d\n", USB_COMMAND_LEN, (int)usb_cmdLen);
return SANE_STATUS_IO_ERROR;
}
/* this command has a write component, and a place to get it */
if(outBuff && outLen && outTime){
/* change timeout */
sanei_usb_set_timeout(outTime);
DBG(25, "out: writing %d bytes, timeout %d\n", (int)outLen, outTime);
hexdump(30, "out: >>", outBuff, outLen);
ret = sanei_usb_write_bulk(s->fd, outBuff, &usb_outLen);
DBG(25, "out: wrote %d bytes, retVal %d\n", (int)usb_outLen, ret);
if(ret == SANE_STATUS_EOF){
DBG(5,"out: got EOF, returning IO_ERROR\n");
return SANE_STATUS_IO_ERROR;
}
if(ret != SANE_STATUS_GOOD){
DBG(5,"out: return error '%s'\n",sane_strstatus(ret));
return ret;
}
if(usb_outLen != outLen){
DBG(5,"out: wrong size %d/%d\n", (int)outLen, (int)usb_outLen);
return SANE_STATUS_IO_ERROR;
}
}
/* this command has a read component, and a place to put it */
if(inBuff && inLen && inTime){
askLen = *inLen;
memset(inBuff,0,askLen);
/* change timeout */
sanei_usb_set_timeout(inTime);
DBG(25, "in: reading %lu bytes, timeout %d\n",
(unsigned long)askLen, inTime);
ret = sanei_usb_read_bulk(s->fd, inBuff, inLen);
DBG(25, "in: retVal %d\n", ret);
if(ret == SANE_STATUS_EOF){
DBG(5,"in: got EOF, continuing\n");
ret = SANE_STATUS_GOOD;
}
if(ret != SANE_STATUS_GOOD){
DBG(5,"in: return error '%s'\n",sane_strstatus(ret));
return ret;
}
DBG(25, "in: read %lu bytes\n", (unsigned long)*inLen);
if(*inLen){
hexdump(31, "in: <<", inBuff, *inLen);
}
if(*inLen && *inLen != askLen){
ret = SANE_STATUS_EOF;
DBG(5,"in: short read, %lu/%lu\n",
(unsigned long)*inLen,(unsigned long)askLen);
}
}
/*gather the scsi status byte. use ret2 instead of ret for status*/
memset(&usb_statBuff,0,USB_STATUS_LEN);
/* change timeout */
sanei_usb_set_timeout(statTime);
DBG(25, "stat: reading %d bytes, timeout %d\n", USB_STATUS_LEN, statTime);
ret2 = sanei_usb_read_bulk(s->fd, usb_statBuff, &usb_statLen);
hexdump(30, "stat: <<", usb_statBuff, usb_statLen);
DBG(25, "stat: read %d bytes, retVal %d\n", (int)usb_statLen, ret2);
if(ret2 == SANE_STATUS_EOF){
DBG(5,"stat: got EOF, returning IO_ERROR\n");
return SANE_STATUS_IO_ERROR;
}
if(ret2 != SANE_STATUS_GOOD){
DBG(5,"stat: return error '%s'\n",sane_strstatus(ret2));
return ret2;
}
if(usb_statLen != USB_STATUS_LEN){
DBG(5,"stat: wrong size %d/%d\n", USB_STATUS_LEN, (int)usb_statLen);
return SANE_STATUS_IO_ERROR;
}
/* busy status */
if(usb_statBuff[USB_STATUS_OFFSET] == 8){
DBG(25,"stat: busy\n");
return SANE_STATUS_DEVICE_BUSY;
}
/* if there is a non-busy status >0, try to figure out why */
if(usb_statBuff[USB_STATUS_OFFSET] > 0){
DBG(25,"stat: value %d\n", usb_statBuff[USB_STATUS_OFFSET]);
/* caller is interested in having RS run on errors */
if(runRS){
unsigned char rs_cmd[REQUEST_SENSE_len];
size_t rs_cmdLen = REQUEST_SENSE_len;
unsigned char rs_in[RS_return_size];
size_t rs_inLen = RS_return_size;
memset(rs_cmd,0,rs_cmdLen);
set_SCSI_opcode(rs_cmd, REQUEST_SENSE_code);
set_RS_return_size(rs_cmd, rs_inLen);
DBG(25,"rs sub call >>\n");
ret2 = do_cmd(
s,0,0,
rs_cmd, rs_cmdLen,
NULL,0,
rs_in, &rs_inLen
);
DBG(25,"rs sub call <<\n");
if(ret2 == SANE_STATUS_EOF){
DBG(5,"rs: got EOF, returning IO_ERROR\n");
return SANE_STATUS_IO_ERROR;
}
if(ret2 != SANE_STATUS_GOOD){
DBG(5,"rs: return error '%s'\n",sane_strstatus(ret2));
return ret2;
}
/* parse the rs data */
ret2 = sense_handler( 0, rs_in, (void *)s );
/* this was a short read, but the usb layer did not know */
if(s->rs_ili && inBuff && inLen && inTime){
*inLen = askLen - s->rs_info;
DBG(5,"do_usb_cmd: short read via rs, %lu/%lu\n",
(unsigned long)*inLen,(unsigned long)askLen);
}
return ret2;
}
else{
DBG(5,"do_usb_cmd: Not calling rs!\n");
return SANE_STATUS_IO_ERROR;
}
}
DBG (10, "do_usb_cmd: finish\n");
return ret;
}
static SANE_Status
wait_scanner(struct fujitsu *s)
{
SANE_Status ret = SANE_STATUS_GOOD;
unsigned char cmd[TEST_UNIT_READY_len];
size_t cmdLen = TEST_UNIT_READY_len;
DBG (10, "wait_scanner: start\n");
memset(cmd,0,cmdLen);
set_SCSI_opcode(cmd,TEST_UNIT_READY_code);
ret = do_cmd (
s, 0, 1,
cmd, cmdLen,
NULL, 0,
NULL, NULL
);
if (ret != SANE_STATUS_GOOD) {
DBG(5,"WARNING: Brain-dead scanner. Hitting with stick\n");
ret = do_cmd (
s, 0, 1,
cmd, cmdLen,
NULL, 0,
NULL, NULL
);
}
if (ret != SANE_STATUS_GOOD) {
DBG(5,"WARNING: Brain-dead scanner. Hitting with stick again\n");
ret = do_cmd (
s, 0, 1,
cmd, cmdLen,
NULL, 0,
NULL, NULL
);
}
if (ret != SANE_STATUS_GOOD) {
DBG (5, "wait_scanner: error '%s'\n", sane_strstatus (ret));
}
DBG (10, "wait_scanner: finish\n");
return ret;
}
/* certain options require the entire image to
* be collected from the scanner before we can
* tell the user the size of the image. */
static int
must_fully_buffer(struct fujitsu *s)
{
if(s->hwdeskewcrop){
return 1;
}
if(
(s->swdeskew || s->swdespeck || s->swcrop || s->swskip)
&& s->s_params.format != SANE_FRAME_JPEG
){
return 1;
}
return 0;
}
/* certain scanners require the mode of the
* image to be changed in software. */
static int
must_downsample(struct fujitsu *s)
{
if(s->s_mode != s->u_mode
&& s->compress != COMP_JPEG
){
return 1;
}
return 0;
}
/* s->page_width stores the user setting
* for the paper width in adf. sometimes,
* we need a value that differs from this
* due to using FB or overscan.
*/
static int
get_page_width(struct fujitsu *s)
{
int width = s->page_width + 2 * (s->os_x_basic*1200/s->basic_x_res);
/* scanner max for fb */
if(s->source == SOURCE_FLATBED){
return s->max_x_fb;
}
/* current paper size for adf not overscan */
if(s->overscan != MSEL_ON){
return s->page_width;
}
/* cant overscan larger than scanner max */
if(width > s->max_x){
return s->max_x;
}
/* overscan adds a margin to both sides */
return width;
}
/* s->page_height stores the user setting
* for the paper height in adf. sometimes,
* we need a value that differs from this
* due to using FB or overscan.
*/
static int
get_page_height(struct fujitsu *s)
{
int height = s->page_height + 2 * (s->os_y_basic*1200/s->basic_y_res);
/* scanner max for fb */
if(s->source == SOURCE_FLATBED){
return s->max_y_fb;
}
/* current paper size for adf not overscan */
if(s->overscan != MSEL_ON){
return s->page_height;
}
/* cant overscan larger than scanner max */
if(height > s->max_y){
return s->max_y;
}
/* overscan adds a margin to both sides */
return height;
}
/* scanners have two different possible IPC
* modes, which enable a different series of
* subordinate options. Rather than provide
* the user with an option to pick the IPC
* mode, we show them the subordinate ones,
* and pick the right mode to match.
*/
static int
get_ipc_mode(struct fujitsu *s)
{
if ( s->bp_filter
|| s->smoothing
|| s->gamma_curve
|| s->threshold_curve
|| s->threshold_white
|| s->noise_removal
|| s->matrix_5
|| s->matrix_4
|| s->matrix_3
|| s->matrix_2
)
return WD_ipc_DTC;
if(s->variance)
return WD_ipc_SDTC;
/* special case: 0 threshold should activate IPC */
if(!s->threshold){
if(s->has_sdtc)
return WD_ipc_SDTC;
if(s->has_dtc)
return WD_ipc_DTC;
}
return WD_ipc_DEFAULT;
}
/* s->max_y gives the maximum height of paper which can be scanned
* this actually varies by resolution, so a helper to change it */
static int
set_max_y(struct fujitsu *s)
{
int i;
for(i=0;i<4;i++){
if(!s->max_y_by_res[i].res)
break;
if(s->resolution_x <= s->max_y_by_res[i].res){
s->max_y = s->max_y_by_res[i].len;
}
}
return s->max_y;
}
/**
* Convenience method to determine longest string size in a list.
*/
static size_t
maxStringSize (const SANE_String_Const strings[])
{
size_t size, max_size = 0;
int i;
for (i = 0; strings[i]; ++i) {
size = strlen (strings[i]) + 1;
if (size > max_size)
max_size = size;
}
return max_size;
}
/*
* Prints a hex dump of the given buffer onto the debug output stream.
*/
static void
hexdump (int level, char *comment, unsigned char *p, int l)
{
int i;
char line[70]; /* 'xxx: xx xx ... xx xx abc */
char *hex = line+4;
char *bin = line+53;
if(DBG_LEVEL < level)
return;
DBG (level, "%s\n", comment);
for (i = 0; i < l; i++, p++) {
/* at start of line */
if ((i % 16) == 0) {
/* not at start of first line, print current, reset */
if (i) {
DBG (level, "%s\n", line);
}
memset(line,0x20,69);
line[69] = 0;
hex = line + 4;
bin = line + 53;
sprintf (line, "%3.3x:", i);
}
/* the hex section */
sprintf (hex, " %2.2x", *p);
hex += 3;
*hex = ' ';
/* the char section */
if(*p >= 0x20 && *p <= 0x7e){
*bin=*p;
}
else{
*bin='.';
}
bin++;
}
/* print last (partial) line */
if (i)
DBG (level, "%s\n", line);
}
/**
* An advanced method we don't support but have to define.
*/
SANE_Status
sane_set_io_mode (SANE_Handle h, SANE_Bool non_blocking)
{
DBG (10, "sane_set_io_mode\n");
DBG (15, "%d %p\n", non_blocking, h);
return SANE_STATUS_UNSUPPORTED;
}
/**
* An advanced method we don't support but have to define.
*/
SANE_Status
sane_get_select_fd (SANE_Handle h, SANE_Int *fdp)
{
DBG (10, "sane_get_select_fd\n");
DBG (15, "%p %d\n", h, *fdp);
return SANE_STATUS_UNSUPPORTED;
}
/*
* @@ Section 7 - Image processing functions
*/
/* Look in image for likely upper and left paper edges, then rotate
* image so that upper left corner of paper is upper left of image.
* FIXME: should we do this before we binarize instead of after? */
static SANE_Status
buffer_deskew(struct fujitsu *s, int side)
{
SANE_Status ret = SANE_STATUS_GOOD;
int bg_color = 0xd6;
DBG (10, "buffer_deskew: start\n");
/*only find skew on first image from a page, or if first image had error */
if(s->side == SIDE_FRONT || s->source == SOURCE_ADF_BACK || s->deskew_stat){
s->deskew_stat = sanei_magic_findSkew(
&s->s_params,s->buffers[side],s->resolution_x,s->resolution_y,
&s->deskew_vals[0],&s->deskew_vals[1],&s->deskew_slope);
if(s->deskew_stat){
DBG (5, "buffer_deskew: bad findSkew, bailing\n");
goto cleanup;
}
}
/* backside images can use a 'flipped' version of frontside data */
else{
s->deskew_slope *= -1;
s->deskew_vals[0] = s->s_params.pixels_per_line - s->deskew_vals[0];
}
/* tweak the bg color based on scanner settings */
if(s->s_mode == MODE_HALFTONE || s->s_mode == MODE_LINEART){
if(s->bg_color == COLOR_BLACK || s->hwdeskewcrop || s->overscan)
bg_color = 0xff;
else
bg_color = 0;
}
else if(s->bg_color == COLOR_BLACK || s->hwdeskewcrop || s->overscan)
bg_color = 0;
ret = sanei_magic_rotate(&s->s_params,s->buffers[side],
s->deskew_vals[0],s->deskew_vals[1],s->deskew_slope,bg_color);
if(ret){
DBG(5,"buffer_deskew: rotate error: %d",ret);
ret = SANE_STATUS_GOOD;
goto cleanup;
}
cleanup:
DBG (10, "buffer_deskew: finish\n");
return ret;
}
/* Look in image for likely left/right/bottom paper edges, then crop image.
* Does not attempt to rotate the image, that should be done first.
* FIXME: should we do this before we binarize instead of after? */
static SANE_Status
buffer_crop(struct fujitsu *s, int side)
{
SANE_Status ret = SANE_STATUS_GOOD;
DBG (10, "buffer_crop: start\n");
ret = sanei_magic_findEdges(
&s->s_params,s->buffers[side],s->resolution_x,s->resolution_y,
&s->crop_vals[0],&s->crop_vals[1],&s->crop_vals[2],&s->crop_vals[3]);
if(ret){
DBG (5, "buffer_crop: bad edges, bailing\n");
ret = SANE_STATUS_GOOD;
goto cleanup;
}
DBG (15, "buffer_crop: t:%d b:%d l:%d r:%d\n",
s->crop_vals[0],s->crop_vals[1],s->crop_vals[2],s->crop_vals[3]);
/* if we will later binarize this image, make sure the width
* is a multiple of 8 pixels, by adjusting the right side */
if ( must_downsample(s) && s->u_mode < MODE_GRAYSCALE ){
s->crop_vals[3] -= (s->crop_vals[3]-s->crop_vals[2]) % 8;
}
/* now crop the image */
ret = sanei_magic_crop(&s->s_params,s->buffers[side],
s->crop_vals[0],s->crop_vals[1],s->crop_vals[2],s->crop_vals[3]);
if(ret){
DBG (5, "buffer_crop: bad crop, bailing\n");
ret = SANE_STATUS_GOOD;
goto cleanup;
}
/* need to update user with new size */
update_u_params(s);
/* update image size counter to new, smaller size */
s->bytes_rx[side] = s->s_params.lines * s->s_params.bytes_per_line;
s->buff_rx[side] = s->bytes_rx[side];
cleanup:
DBG (10, "buffer_crop: finish\n");
return ret;
}
/* Look in image for disconnected 'spots' of the requested size.
* Replace the spots with the average color of the surrounding pixels.
* FIXME: should we do this before we binarize instead of after? */
static SANE_Status
buffer_despeck(struct fujitsu *s, int side)
{
SANE_Status ret = SANE_STATUS_GOOD;
DBG (10, "buffer_despeck: start\n");
ret = sanei_magic_despeck(&s->s_params,s->buffers[side],s->swdespeck);
if(ret){
DBG (5, "buffer_despeck: bad despeck, bailing\n");
ret = SANE_STATUS_GOOD;
goto cleanup;
}
cleanup:
DBG (10, "buffer_despeck: finish\n");
return ret;
}
/* Look if image has too few dark pixels.*/
static int
buffer_isblank(struct fujitsu *s, int side)
{
SANE_Status ret = SANE_STATUS_GOOD;
int status = 0;
DBG (10, "buffer_isblank: start\n");
ret = sanei_magic_isBlank2(&s->s_params, s->buffers[side],
s->resolution_x, s->resolution_y, s->swskip);
if(ret == SANE_STATUS_NO_DOCS){
DBG (5, "buffer_isblank: blank!\n");
status = 1;
}
else if(ret){
DBG (5, "buffer_isblank: error %d\n",ret);
}
DBG (10, "buffer_isblank: finished\n");
return status;
}
|