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
|
/* --------------------------------------------------------------------------------------------------------- */
/* sane - Scanner Access Now Easy.
umax.c
(C) 1997-2007 Oliver Rauch
This file is part of the SANE package.
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, see <https://www.gnu.org/licenses/>.
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.
This file implements a SANE backend for UMAX flatbed scanners. */
/* --------------------------------------------------------------------------------------------------------- */
#define BUILD 45
/* --------------------------------------------------------------------------------------------------------- */
/* SANE-FLOW-DIAGRAMM
- sane_init() : initialize backend, attach scanners(devicename,0)
. - sane_get_devices() : query list of scanner-devices
. - sane_open() : open a particular scanner-device and attach_scanner(devicename,&dev)
. . - 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_start() : start image acquisition
. . - sane_get_parameters() : returns actual scan-parameters
. . - sane_read() : read image-data (from pipe)
in ADF mode this is done often:
. . - sane_start() : start image acquisition
. . - sane_get_parameters() : returns actual scan-parameters
. . - sane_read() : read image-data (from pipe)
. . - sane_cancel() : cancel operation, kill reader_process
. - sane_close() : close opened scanner-device, do_cancel, free buffer and handle
- sane_exit() : terminate use of backend, free devicename and device-struture
*/
/* ------------------------------------------------------------ DBG OUTPUT LEVELS -------------------------- */
#define DBG_error0 0
#define DBG_error 1
#define DBG_sense 2
#define DBG_warning 3
#define DBG_inquiry 4
#define DBG_info 5
#define DBG_info2 6
#define DBG_proc 7
#define DBG_read 8
#define DBG_sane_init 10
#define DBG_sane_proc 11
#define DBG_sane_info 12
#define DBG_sane_option 13
/* ------------------------------------------------------------ SANE DEFINES ------------------------------- */
#define BACKEND_NAME umax
#define UMAX_CONFIG_FILE "umax.conf"
/* ------------------------------------------------------------ SANE INTERNATIONALISATION ------------------ */
#ifndef SANE_I18N
#define SANE_I18N(text) text
#endif
/* ------------------------------------------------------------ INCLUDES ----------------------------------- */
#include "../include/sane/config.h"
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include "../include/sane/sane.h"
#include "../include/sane/sanei.h"
#include "../include/sane/saneopts.h"
#include "../include/sane/sanei_scsi.h"
#include "../include/sane/sanei_debug.h"
#include "../include/sane/sanei_backend.h"
#include "../include/sane/sanei_config.h"
#include "../include/sane/sanei_thread.h"
#ifdef UMAX_ENABLE_USB
# include "sane/sanei_usb.h"
#endif
#include <math.h>
#include <string.h>
#include "umax-scsidef.h"
#include "umax-scanner.c"
#ifdef UMAX_ENABLE_USB
# include "umax-usb.c"
#endif
#include "umax.h"
/* ------------------------------------------------------------ SANE DEFINES ------------------------------- */
#ifndef PATH_MAX
#define PATH_MAX 1024
#endif
/* ------------------------------------------------------------ OPTION DEFINITIONS ------------------------- */
#define SANE_NAME_BATCH_SCAN_START "batch-scan-start"
#define SANE_TITLE_BATCH_SCAN_START "Batch scan start"
#define SANE_DESC_BATCH_SCAN_START "set for first scan of batch"
#define SANE_NAME_BATCH_SCAN_LOOP "batch-scan-loop"
#define SANE_TITLE_BATCH_SCAN_LOOP "Batch scan loop"
#define SANE_DESC_BATCH_SCAN_LOOP "set for middle scans of batch"
#define SANE_NAME_BATCH_SCAN_END "batch-scan-end"
#define SANE_TITLE_BATCH_SCAN_END "Batch scan end"
#define SANE_DESC_BATCH_SCAN_END "set for last scan of batch"
#define SANE_NAME_BATCH_NEXT_TL_Y "batch-scan-next-tl-y"
#define SANE_TITLE_BATCH_NEXT_TL_Y "Batch scan next top left Y"
#define SANE_DESC_BATCH_NEXT_TL_Y "Set top left Y position for next scan"
#define SANE_UMAX_NAME_SELECT_CALIBRATON_EXPOSURE_TIME "select-calibration-exposure-time"
#define SANE_UMAX_TITLE_SELECT_CALIBRATION_EXPOSURE_TIME "Set calibration exposure time"
#define SANE_UMAX_DESC_SELECT_CALIBRATION_EXPOSURE_TIME "Allow different settings for calibration and scan exposure times"
/* ------------------------------------------------------------ STRING DEFINITIONS ------------------------- */
#define FLB_STR SANE_I18N("Flatbed")
#define UTA_STR SANE_I18N("Transparency Adapter")
#define ADF_STR SANE_I18N("Automatic Document Feeder")
#define LINEART_STR SANE_VALUE_SCAN_MODE_LINEART
#define HALFTONE_STR SANE_VALUE_SCAN_MODE_HALFTONE
#define GRAY_STR SANE_VALUE_SCAN_MODE_GRAY
#define COLOR_LINEART_STR SANE_VALUE_SCAN_MODE_COLOR_LINEART
#define COLOR_HALFTONE_STR SANE_VALUE_SCAN_MODE_COLOR_HALFTONE
#define COLOR_STR SANE_VALUE_SCAN_MODE_COLOR
/* ------------------------------------------------------------ DEFINITIONS -------------------------------- */
#define P_200_TO_255(per) ( (SANE_UNFIX(per) + 100) * 255/200 )
#define P_100_TO_255(per) SANE_UNFIX(per * 255/100 )
#define P_100_TO_254(per) 1+SANE_UNFIX(per * 254/100 )
/* ------------------------------------------------------------ GLOBAL VARIABLES --------------------------- */
static SANE_String scan_mode_list[7];
static SANE_String_Const source_list[4];
static SANE_Int bit_depth_list[9];
static SANE_Auth_Callback frontend_authorize_callback;
static int umax_scsi_buffer_size_min = 32768; /* default: minimum scsi buffer size: 32 KB */
static int umax_scsi_buffer_size_max = 131072; /* default: maximum scsi buffer size: 128 KB */
/* number of lines that shall be scanned in one buffer for preview if possible */
/* this value should not be too large because it defines the step size in which */
/* the scanned parts are displayed while preview scan is in progress */
static int umax_preview_lines = 10; /* default: 10 preview lines */
/* number of lines that shall be scanned in one buffer for scan if possible */
static int umax_scan_lines = 40; /* default: 40 scan lines */
static int umax_scsi_maxqueue = 2; /* use command queueing depth 2 as default */
static int umax_handle_bad_sense_error = 0; /* default: handle bad sense error code as device busy */
static int umax_execute_request_sense = 0; /* default: do not use request sense in do_calibration */
static int umax_force_preview_bit_rgb = 0; /* default: do not force preview bit in real color scan */
static int umax_slow = -1; /* don`t use slow scanning speed */
static int umax_smear = -1; /* don`t care about image smearing problem */
static int umax_calibration_area = -1; /* -1=auto, 0=calibration on image, 1=calibration for full ccd */
static int umax_calibration_width_offset = -99999; /* -99999=auto */
static int umax_calibration_width_offset_batch = -99999; /* -99999=auto */
static int umax_calibration_bytespp = -1; /* -1=auto */
static int umax_exposure_time_rgb_bind = -1; /* -1=auto */
static int umax_invert_shading_data = -1; /* -1=auto */
static int umax_lamp_control_available = 0; /* 0=disabled */
static int umax_gamma_lsb_padded = -1; /* -1=auto */
static int umax_connection_type = 1; /* 1=scsi, 2=usb */
/* ------------------------------------------------------------ CALIBRATION MODE --------------------------- */
#ifdef UMAX_CALIBRATION_MODE_SELECTABLE
#define CALIB_MODE_0000 SANE_I18N("Use Image Composition")
#define CALIB_MODE_1111 SANE_I18N("Bi-level black and white (lineart mode)")
#define CALIB_MODE_1110 SANE_I18N("Dithered/halftone black & white (halftone mode)")
#define CALIB_MODE_1101 SANE_I18N("Multi-level black & white (grayscale mode)")
#define CALIB_MODE_1010 SANE_I18N("Multi-level RGB color (one pass color)")
#define CALIB_MODE_1001 SANE_I18N("Ignore calibration")
static SANE_String_Const calibration_list[] =
{
CALIB_MODE_0000,
CALIB_MODE_1111,
CALIB_MODE_1110,
CALIB_MODE_1101,
CALIB_MODE_1010,
CALIB_MODE_1001,
0
};
#endif
/* --------------------------------------------------------------------------------------------------------- */
enum
{
UMAX_CALIBRATION_AREA_IMAGE = 0,
UMAX_CALIBRATION_AREA_CCD
};
static const SANE_Int pattern_dim_list[] =
{
5, /* # of elements */
2, 4, 6, 8, 12
};
static const SANE_Range u8_range =
{
0, /* minimum */
255, /* maximum */
0 /* quantization */
};
static const SANE_Range percentage_range =
{
SANE_FIX(-100), /* minimum */
SANE_FIX( 100), /* maximum */
SANE_FIX( 1) /* quantization */
};
static const SANE_Range percentage_range_100 =
{
SANE_FIX( 0), /* minimum */
SANE_FIX(100), /* maximum */
SANE_FIX( 0) /* quantization */
};
static int num_devices = 0;
static const SANE_Device **devlist = NULL;
static Umax_Device *first_dev = NULL;
static Umax_Scanner *first_handle = NULL;
/* ------------------------------------------------------------ MATH-HELPERS ------------------------------- */
#define min(a, b) (((a)<(b))?(a):(b))
#define max(a, b) (((a)>(b))?(a):(b))
#define inrange(minimum, val, maximum) (min(maximum, max(val, minimum)))
/* ------------------------------------------------------------ umax_test_little_endian -------------------- */
static SANE_Bool umax_test_little_endian(void)
{
SANE_Int testvalue = 255;
unsigned char *firstbyte = (unsigned char *) &testvalue;
if (*firstbyte == 255)
{
return SANE_TRUE;
}
return SANE_FALSE;
}
/* ------------------------------------------------------------ DBG_inq_nz --------------------------------- */
static void DBG_inq_nz(char *text, int flag)
{
if (flag != 0) { DBG(DBG_inquiry,"%s", text); }
}
/*------------------------------------------------------------- DBG_sense_nz ------------------------------- */
static void DBG_sense_nz(char *text, int flag)
{
if (flag != 0) { DBG(DBG_sense,"%s", text); }
}
/* ------------------------------------------------------------ UMAX PRINT INQUIRY ------------------------- */
static void umax_print_inquiry(Umax_Device *dev)
{
unsigned char *inquiry_block;
int i;
inquiry_block=dev->buffer[0];
DBG(DBG_inquiry,"INQUIRY:\n");
DBG(DBG_inquiry,"========\n");
DBG(DBG_inquiry,"\n");
DBG(DBG_inquiry,"vendor........................: '%s'\n", dev->vendor);
DBG(DBG_inquiry,"product.......................: '%s'\n", dev->product);
DBG(DBG_inquiry,"version.......................: '%s'\n", dev->version);
DBG(DBG_inquiry,"peripheral qualifier..........: %d\n", get_inquiry_periph_qual(inquiry_block));
DBG(DBG_inquiry,"peripheral device type........: %d\n", get_inquiry_periph_devtype(inquiry_block));
DBG_inq_nz("RMB bit set (reserved)\n", get_inquiry_rmb(inquiry_block));
DBG_inq_nz("0x01 bit 6\n", get_inquiry_0x01_bit6(inquiry_block));
DBG_inq_nz("0x01 bit 5\n", get_inquiry_0x01_bit5(inquiry_block));
DBG(DBG_inquiry,"\n");
DBG(DBG_inquiry,"CBHS value range..............: %s\n", cbhs_str[dev->inquiry_cbhs]);
DBG(DBG_inquiry,"scanmode......................: %s\n", scanmode_str[get_inquiry_scanmode(inquiry_block)]);
if (dev->inquiry_transavail)
{
DBG(DBG_inquiry,"UTA (transparency)............: available\n");
if (get_inquiry_translamp(inquiry_block) == 0)
{ DBG(DBG_inquiry,"UTA lamp status ..............: off\n"); }
else
{ DBG(DBG_inquiry,"UTA lamp status ..............: on\n"); }
DBG(DBG_inquiry,"\n");
}
DBG(DBG_inquiry,"inquiry block length..........: %d bytes\n", dev->inquiry_len);
if (dev->inquiry_len<=0x8e)
{
DBG(DBG_inquiry, "Inquiry block is unexpected short, should be at least 147 bytes\n");
}
DBG(DBG_inquiry,"\n");
DBG(DBG_inquiry,"ISO Version (reserved).......: %d\n", get_inquiry_iso_version(inquiry_block));
DBG(DBG_inquiry,"ECMA Version (reserved).......: %d\n", get_inquiry_ecma_version(inquiry_block));
DBG(DBG_inquiry,"ANSI Version .................: %d\n", get_inquiry_ansi_version(inquiry_block));
DBG(DBG_inquiry,"\n");
DBG_inq_nz("AENC bit set (reserved)\n", get_inquiry_aenc(inquiry_block));
DBG_inq_nz("TmIOP bit set (reserved)\n", get_inquiry_tmiop(inquiry_block));
DBG_inq_nz("0x03 bit 5\n", get_inquiry_0x03_bit5(inquiry_block));
DBG_inq_nz("0x03 bit 4\n", get_inquiry_0x03_bit4(inquiry_block));
DBG(DBG_inquiry,"reserved byte 0x05 = %d\n", get_inquiry_0x05(inquiry_block));
DBG(DBG_inquiry,"reserved byte 0x06 = %d\n", get_inquiry_0x06(inquiry_block));
DBG(DBG_inquiry,"\n");
DBG(DBG_inquiry,"scsi features (%02x):\n", get_inquiry_scsi_byte(inquiry_block));
DBG(DBG_inquiry,"-------------------\n");
DBG_inq_nz(" - relative address\n", get_inquiry_scsi_reladr(inquiry_block));
DBG_inq_nz(" - wide bus 32 bit\n", get_inquiry_scsi_wbus32(inquiry_block));
DBG_inq_nz(" - wide bus 16 bit\n", get_inquiry_scsi_wbus16(inquiry_block));
DBG_inq_nz(" - synchronous neg.\n", get_inquiry_scsi_sync(inquiry_block));
DBG_inq_nz(" - linked commands\n", get_inquiry_scsi_linked(inquiry_block));
DBG_inq_nz(" - (reserved)\n", get_inquiry_scsi_R(inquiry_block));
DBG_inq_nz(" - command queueing\n", get_inquiry_scsi_cmdqueue(inquiry_block));
DBG_inq_nz(" - sftre\n", get_inquiry_scsi_sftre(inquiry_block));
/* 0x24 */
if (dev->inquiry_len<=0x24)
{
return;
}
DBG(DBG_inquiry,"\n");
DBG(DBG_inquiry,"f/w support function:\n");
DBG(DBG_inquiry,"---------------------\n");
DBG_inq_nz(" - quality calibration\n", dev->inquiry_quality_ctrl);
DBG_inq_nz(" - fast preview function\n", dev->inquiry_preview);
DBG_inq_nz(" - shadow compensation by f/w\n", get_inquiry_fw_shadow_comp(inquiry_block));
DBG_inq_nz(" - reselection phase\n", get_inquiry_fw_reselection(inquiry_block));
DBG_inq_nz(" - lamp intensity control\n", dev->inquiry_lamp_ctrl);
DBG_inq_nz(" - batch scan function\n", get_inquiry_fw_batch_scan(inquiry_block));
DBG_inq_nz(" - calibration mode control by driver\n", get_inquiry_fw_calibration(inquiry_block));
/* 0x36, 0x37 */
DBG(DBG_inquiry,"\n");
DBG(DBG_inquiry,"reserved byte 0x36 = %d\n", get_inquiry_0x36(inquiry_block));
DBG(DBG_inquiry,"reserved byte 0x37 = %d\n", get_inquiry_0x37(inquiry_block));
if (get_inquiry_fw_adjust_exposure_tf(inquiry_block))
{
int unit;
DBG(DBG_inquiry,"\n");
DBG(DBG_inquiry,"adjust exposure time function\n");
unit=get_inquiry_exposure_time_step_unit(inquiry_block);
DBG(DBG_inquiry,"exposure time step units......: %d micro-sec\n", unit);
DBG(DBG_inquiry,"exposure time maximum.........: %d micro-sec\n",
unit*get_inquiry_exposure_time_max(inquiry_block));
DBG(DBG_inquiry,"exposure time minimum (LHG)...: %d micro-sec\n",
unit*get_inquiry_exposure_time_lhg_min(inquiry_block));
DBG(DBG_inquiry,"exposure time minimum color...: %d micro-sec\n",
unit*get_inquiry_exposure_time_color_min(inquiry_block));
DBG(DBG_inquiry,"exposure time default FB (LH).: %d micro-sec\n",
unit*get_inquiry_exposure_time_lh_def_fb(inquiry_block));
DBG(DBG_inquiry,"exposure time default UTA (LH): %d micro-sec\n",
unit*get_inquiry_exposure_time_lh_def_uta(inquiry_block));
DBG(DBG_inquiry,"exposure time default FB gray.: %d micro-sec\n",
unit*get_inquiry_exposure_time_gray_def_fb(inquiry_block));
DBG(DBG_inquiry,"exposure time default UTA gray: %d micro-sec\n",
unit*get_inquiry_exposure_time_gray_def_uta(inquiry_block));
DBG(DBG_inquiry,"exposure time default FB red..: %d micro-sec\n",
unit*get_inquiry_exposure_time_def_r_fb(inquiry_block));
DBG(DBG_inquiry,"exposure time default FB grn..: %d micro-sec\n",
unit*get_inquiry_exposure_time_def_g_fb(inquiry_block));
DBG(DBG_inquiry,"exposure time default FB blue.: %d micro-sec\n",
unit*get_inquiry_exposure_time_def_b_fb(inquiry_block));
DBG(DBG_inquiry,"exposure time default UTA red.: %d micro-sec\n",
unit*get_inquiry_exposure_time_def_r_uta(inquiry_block));
DBG(DBG_inquiry,"exposure time default UTA grn.: %d micro-sec\n",
unit*get_inquiry_exposure_time_def_g_uta(inquiry_block));
DBG(DBG_inquiry,"exposure time default UTA blue: %d micro-sec\n",
unit*get_inquiry_exposure_time_def_b_uta(inquiry_block));
}
/* 0x60 */
if (dev->inquiry_len<=0x60)
{
return;
}
DBG(DBG_inquiry,"\n");
DBG(DBG_inquiry,"scan modes (%02x):\n", get_inquiry_sc_feature_byte0(inquiry_block));
DBG(DBG_inquiry,"----------------\n");
DBG_inq_nz(" - three passes color mode\n", get_inquiry_sc_three_pass_color(inquiry_block));
DBG_inq_nz(" - single pass color mode\n", get_inquiry_sc_one_pass_color(inquiry_block));
DBG_inq_nz(" - lineart mode\n", dev->inquiry_lineart);
DBG_inq_nz(" - halftone mode\n", dev->inquiry_halftone);
DBG_inq_nz(" - gray mode\n", dev->inquiry_gray);
DBG_inq_nz(" - color mode\n", dev->inquiry_color);
DBG_inq_nz(" - transparency (UTA)\n", dev->inquiry_uta);
DBG_inq_nz(" - automatic document feeder (ADF)\n", dev->inquiry_adf);
/* 0x61 */
if (dev->inquiry_len<=0x61)
{
return;
}
DBG(DBG_inquiry,"\n");
DBG(DBG_inquiry,"scanner capability (%02x, %02x, %02x):\n",
get_inquiry_sc_feature_byte1(inquiry_block),
get_inquiry_sc_feature_byte2(inquiry_block),
get_inquiry_sc_feature_byte3(inquiry_block));
DBG(DBG_inquiry,"--------------------------------\n");
DBG_inq_nz(" - double resolution\n", dev->inquiry_dor);
DBG_inq_nz(" - send high byte first\n", get_inquiry_sc_high_byte_first(inquiry_block));
DBG_inq_nz(" - bi-level image reverse\n", dev->inquiry_reverse);
DBG_inq_nz(" - multi-level image reverse\n", dev->inquiry_reverse_multi);
DBG_inq_nz(" - support shadow function\n", dev->inquiry_shadow);
DBG_inq_nz(" - support highlight function\n", dev->inquiry_highlight);
DBG_inq_nz(" - f/w downloadable\n", get_inquiry_sc_downloadable_fw(inquiry_block));
DBG_inq_nz(" - paper length can reach to 14 inch\n", get_inquiry_sc_paper_length_14(inquiry_block));
/* 0x62 */
if (dev->inquiry_len<=0x62)
{
return;
}
DBG_inq_nz(" - shading data/gain uploadable\n", get_inquiry_sc_uploadable_shade(inquiry_block));
DBG_inq_nz(" - analog gamma correction\n", dev->inquiry_analog_gamma);
DBG_inq_nz(" - x, y coordinate base\n", get_inquiry_xy_coordinate_base(inquiry_block));
DBG_inq_nz(" - lineart starts with LSB\n", get_inquiry_lineart_order(inquiry_block));
DBG_inq_nz(" - start density \n", get_inquiry_start_density(inquiry_block));
DBG_inq_nz(" - hardware x scaling\n", get_inquiry_hw_x_scaling(inquiry_block));
DBG_inq_nz(" - hardware y scaling\n", get_inquiry_hw_y_scaling(inquiry_block));
/* 0x63 */
if (dev->inquiry_len<=0x63)
{
return;
}
DBG_inq_nz(" + ADF: no paper\n", get_inquiry_ADF_no_paper(inquiry_block));
DBG_inq_nz(" + ADF: cover open\n", get_inquiry_ADF_cover_open(inquiry_block));
DBG_inq_nz(" + ADF: paper jam\n", get_inquiry_ADF_paper_jam(inquiry_block));
DBG_inq_nz(" - unknown flag; 0x63 bit 3\n", get_inquiry_0x63_bit3(inquiry_block));
DBG_inq_nz(" - unknown lfag: 0x63 bit 4\n", get_inquiry_0x63_bit4(inquiry_block));
DBG_inq_nz(" - lens calib in doc pos\n", get_inquiry_lens_cal_in_doc_pos(inquiry_block));
DBG_inq_nz(" - manual focus\n", get_inquiry_manual_focus(inquiry_block));
DBG_inq_nz(" - UTA lens calib pos selectable\n", get_inquiry_sel_uta_lens_cal_pos(inquiry_block));
/* 0x64 - 0x68*/
if (dev->inquiry_len<=0x68)
{
return;
}
if (dev->inquiry_gamma_dwload)
{
DBG(DBG_inquiry,"\n");
DBG(DBG_inquiry,"gamma download available\n");
DBG_inq_nz("gamma download type 2\n", get_inquiry_gamma_type_2(inquiry_block));
DBG(DBG_inquiry,"lines of gamma curve: %s\n", gamma_lines_str[get_inquiry_gamma_lines(inquiry_block)]);
/* 0x66 */
DBG_inq_nz("gamma input 8 bits/pixel support\n", get_inquiry_gib_8bpp(inquiry_block));
DBG_inq_nz("gamma input 9 bits/pixel support\n", get_inquiry_gib_9bpp(inquiry_block));
DBG_inq_nz("gamma input 10 bits/pixel support\n", get_inquiry_gib_10bpp(inquiry_block));
DBG_inq_nz("gamma input 12 bits/pixel support\n", get_inquiry_gib_12bpp(inquiry_block));
DBG_inq_nz("gamma input 14 bits/pixel support\n", get_inquiry_gib_14bpp(inquiry_block));
DBG_inq_nz("gamma input 16 bits/pixel support\n", get_inquiry_gib_16bpp(inquiry_block));
DBG_inq_nz("0x66 bit 6\n", get_inquiry_0x66_bit6(inquiry_block));
DBG_inq_nz("0x66 bit 7\n", get_inquiry_0x66_bit7(inquiry_block));
/* 0x68 */
DBG_inq_nz("gamma output 8 bits/pixel support\n", get_inquiry_gob_8bpp(inquiry_block));
DBG_inq_nz("gamma output 9 bits/pixel support\n", get_inquiry_gob_9bpp(inquiry_block));
DBG_inq_nz("gamma output 10 bits/pixel support\n", get_inquiry_gob_10bpp(inquiry_block));
DBG_inq_nz("gamma output 12 bits/pixel support\n", get_inquiry_gob_12bpp(inquiry_block));
DBG_inq_nz("gamma output 14 bits/pixel support\n", get_inquiry_gob_14bpp(inquiry_block));
DBG_inq_nz("gamma output 16 bits/pixel support\n", get_inquiry_gob_16bpp(inquiry_block));
DBG_inq_nz("0x68 bit 6\n", get_inquiry_0x68_bit6(inquiry_block));
DBG_inq_nz("0x68 bit 7\n", get_inquiry_0x68_bit7(inquiry_block));
}
/* 0x64 - 0x68 reserved bits */
DBG_inq_nz("0x64 bit 2\n", get_inquiry_0x64_bit2(inquiry_block));
DBG_inq_nz("0x64 bit 3\n", get_inquiry_0x64_bit3(inquiry_block));
DBG_inq_nz("0x64 bit 4\n", get_inquiry_0x64_bit4(inquiry_block));
DBG_inq_nz("0x64 bit 6\n", get_inquiry_0x64_bit6(inquiry_block));
DBG(DBG_inquiry,"\n");
DBG(DBG_inquiry,"reserved byte 0x65 = %d\n", get_inquiry_0x65(inquiry_block));
DBG(DBG_inquiry,"reserved byte 0x67 = %d\n", get_inquiry_0x67(inquiry_block));
/* 0x69 */
if (dev->inquiry_len<=0x69)
{
return;
}
DBG(DBG_inquiry,"\n");
if (get_inquiry_hda(inquiry_block))
{
DBG(DBG_inquiry,"halftone download available\n");
DBG(DBG_inquiry,"halftone pattern download max matrix %dx%d\n",
get_inquiry_max_halftone_matrix(inquiry_block),
get_inquiry_max_halftone_matrix(inquiry_block));
}
/* 0x6a */
if (dev->inquiry_len<=0x6a)
{
return;
}
DBG_inq_nz("built-in halftone patterns:\n", get_inquiry_halftones_supported(inquiry_block));
DBG_inq_nz("built-in halftone pattern size ............: 2x2\n", get_inquiry_halftones_2x2(inquiry_block));
DBG_inq_nz("built-in halftone pattern size ............: 4x4\n", get_inquiry_halftones_4x4(inquiry_block));
DBG_inq_nz("built-in halftone pattern size ............: 6x6\n", get_inquiry_halftones_6x6(inquiry_block));
DBG_inq_nz("built-in halftone pattern size ............: 8x8\n", get_inquiry_halftones_8x8(inquiry_block));
DBG_inq_nz("built-in halftone pattern size ............: 12x12\n", get_inquiry_halftones_12x12(inquiry_block));
/* 0x6b, 0x6c */
DBG(DBG_inquiry,"reserved byte 0x6b = %d\n", get_inquiry_0x6b(inquiry_block));
DBG(DBG_inquiry,"reserved byte 0x6c = %d\n", get_inquiry_0x6c(inquiry_block));
/* 0x6d */
if (dev->inquiry_len<=0x6d)
{
return;
}
DBG(DBG_inquiry,"\n");
DBG(DBG_inquiry,"color sequence............................: %s\n",
color_sequence_str[get_inquiry_colorseq(inquiry_block)]);
DBG_inq_nz("color ordering support....................: pixel\n",
get_inquiry_color_order_pixel(inquiry_block));
DBG_inq_nz("color ordering support....................: line without CCD distance\n",
get_inquiry_color_order_line_no_ccd(inquiry_block));
DBG_inq_nz("color ordering support....................: plane\n",
get_inquiry_color_order_plane(inquiry_block));
DBG_inq_nz("color ordering support....................: line with CCD distance\n",
get_inquiry_color_order_line_w_ccd(inquiry_block));
DBG_inq_nz("color ordering support....................: (reserved)\n",
get_inquiry_color_order_reserved(inquiry_block));
/* 0x6e */
if (dev->inquiry_len<=0x71)
{
return;
}
DBG(DBG_inquiry,"\n");
DBG(DBG_inquiry,"maximum video memory......................: %d KB\n", dev->inquiry_vidmem/1024);
/* 0x72 */
DBG(DBG_inquiry,"\n");
DBG(DBG_inquiry,"reserved byte 0x72 = %d\n", get_inquiry_0x72(inquiry_block));
DBG(DBG_inquiry,"\n");
/* 0x73/0x94 - 0x75/0x96 */
if (dev->inquiry_len<=0x75)
{
return;
}
DBG(DBG_inquiry,"optical resolution........................: %d dpi\n", dev->inquiry_optical_res);
DBG(DBG_inquiry,"maximum x-resolution......................: %d dpi\n", dev->inquiry_x_res);
DBG(DBG_inquiry,"maximum y-resolution......................: %d dpi\n", dev->inquiry_y_res);
/* ---------- */
/* 0x76 0x77 */
if (dev->inquiry_len<=0x77)
{
return;
}
DBG(DBG_inquiry,"\n");
DBG(DBG_inquiry,"FB (flatbed-mode):\n");
DBG(DBG_inquiry,"FB maximum scan width.....................: %2.2f inch\n", dev->inquiry_fb_width);
DBG(DBG_inquiry,"FB maximum scan length....................: %2.2f inch\n", dev->inquiry_fb_length);
/* ---------- */
/* 0x7a - 0x81 */
if (dev->inquiry_len<=0x81)
{
return;
}
DBG(DBG_inquiry,"\n");
DBG(DBG_inquiry,"UTA (transparency-mode):\n");
DBG(DBG_inquiry,"UTA x-original point......................: %2.2f inch\n", dev->inquiry_uta_x_off);
DBG(DBG_inquiry,"UTA y-original point......................: %2.2f inch\n", dev->inquiry_uta_y_off);
DBG(DBG_inquiry,"UTA maximum scan width....................: %2.2f inch\n", dev->inquiry_uta_width);
DBG(DBG_inquiry,"UTA maximum scan length...................: %2.2f inch\n", dev->inquiry_uta_length);
/* ---------- */
/* 0x82-0x85 */
DBG(DBG_inquiry,"\n");
DBG(DBG_inquiry,"reserved byte 0x82 = %d\n", get_inquiry_0x82(inquiry_block));
/* ---------- */
/* 0x83/0xa0 - 0x85/0xa2 */
if (dev->inquiry_len<=0x85)
{
return;
}
DBG(DBG_inquiry,"\n");
DBG(DBG_inquiry,"DOR (double optical resolution-mode):\n");
DBG(DBG_inquiry,"DOR optical resolution....................: %d dpi\n", dev->inquiry_dor_optical_res);
DBG(DBG_inquiry,"DOR maximum x-resolution..................: %d dpi\n", dev->inquiry_dor_x_res);
DBG(DBG_inquiry,"DOR maximum y-resolution..................: %d dpi\n", dev->inquiry_dor_y_res);
/* 0x86 - 0x8d */
if (dev->inquiry_len<=0x8d)
{
return;
}
DBG(DBG_inquiry,"DOR x-original point......................: %2.2f inch\n", dev->inquiry_dor_x_off);
DBG(DBG_inquiry,"DOR y-original point......................: %2.2f inch\n", dev->inquiry_dor_y_off);
DBG(DBG_inquiry,"DOR maximum scan width....................: %2.2f inch\n", dev->inquiry_dor_width);
DBG(DBG_inquiry,"DOR maximum scan length...................: %2.2f inch\n", dev->inquiry_dor_length);
DBG(DBG_inquiry,"\n");
/* ---------- */
/* 0x8e */
DBG(DBG_inquiry,"reserved byte 0x8e = %d\n", get_inquiry_0x8e(inquiry_block));
DBG(DBG_inquiry,"\n");
/* ---------- */
/* 0x8f */
if (dev->inquiry_len<=0x8f)
{
return;
}
DBG(DBG_inquiry,"last calibration lamp density.............: %d\n",
get_inquiry_last_calibration_lamp_density(inquiry_block));
/* 0x90 */
DBG(DBG_inquiry,"\n");
DBG(DBG_inquiry,"reserved byte 0x90 = %d\n", get_inquiry_0x90(inquiry_block));
DBG(DBG_inquiry,"\n");
/* 0x91 */
if (dev->inquiry_len<=0x91)
{
return;
}
DBG(DBG_inquiry,"lamp warmup maximum time..................: %d sec\n", dev->inquiry_max_warmup_time);
/* 0x92 0x93 */
if (dev->inquiry_len<=0x93)
{
return;
}
DBG(DBG_inquiry,"window descriptor block length............: %d bytes\n", get_inquiry_wdb_length(inquiry_block));
/* ----------------- */
/* 0x97 */
if (dev->inquiry_len<=0x97)
{
return;
}
if (get_inquiry_analog_gamma_table(inquiry_block) == 0)
{
DBG(DBG_inquiry,"no analog gamma function\n");
}
else
{
DBG(DBG_inquiry,"mp 8832 analog gamma table\n");
}
/* 0x98, 0x99 */
DBG(DBG_inquiry,"\n");
DBG(DBG_inquiry,"reserved byte 0x98 = %d\n", get_inquiry_0x98(inquiry_block));
DBG(DBG_inquiry,"reserved byte 0x99 = %d\n", get_inquiry_0x99(inquiry_block));
DBG(DBG_inquiry,"\n");
/* 0x9a */
if (dev->inquiry_len<=0x9a)
{
return;
}
DBG(DBG_inquiry,"maximum calibration data lines for shading: %d\n",
get_inquiry_max_calibration_data_lines(inquiry_block));
/* 0x9b */
if (dev->inquiry_len<=0x9b)
{
return;
}
DBG(DBG_inquiry,"fb/uta: color line arrangement mode.......: %d\n",
get_inquiry_fb_uta_line_arrangement_mode(inquiry_block));
/* 0x9c */
if (dev->inquiry_len<=0x9c)
{
return;
}
DBG(DBG_inquiry,"adf: color line arrangement mode.......: %d\n",
get_inquiry_adf_line_arrangement_mode(inquiry_block));
/* 0x9d */
if (dev->inquiry_len<=0x9d)
{
return;
}
DBG(DBG_inquiry,"CCD line distance.........................: %d\n",
get_inquiry_CCD_line_distance(inquiry_block));
DBG(DBG_inquiry,"\n");
DBG(DBG_inquiry,"reserved byte 0x9e = %d\n", get_inquiry_0x9e(inquiry_block));
/* 0xa2 following */
if (dev->inquiry_len<=0xa2)
{
return;
}
DBG(DBG_inquiry,"\n");
for(i=0xa3; i<dev->inquiry_len; i++)
{
DBG(DBG_inquiry,"unknown reserved byte 0x%x = %d\n", i, inquiry_block[i]);
}
}
/* ------------------------------------------------------------ CBHS_CORRECT ------------------------------- */
static int umax_cbhs_correct(int minimum, int cbhs, int maximum)
{
int range = maximum - minimum + 1;
if (range == 256)
{
return cbhs;
}
return (int)( (cbhs/256.0)*range + minimum );
}
/* ------------------------------------------------------------ SENSE_HANDLER ------------------------------ */
static SANE_Status sense_handler(int scsi_fd, unsigned char *result, void *arg) /* is called by sanei_scsi */
{
unsigned char asc, ascq, sensekey;
int asc_ascq, len;
Umax_Device *dev = arg;
DBG(DBG_proc, "check condition sense handler (scsi_fd = %d)\n", scsi_fd);
sensekey = get_RS_sense_key(result);
asc = get_RS_ASC(result);
ascq = get_RS_ASCQ(result);
asc_ascq = (int)(256 * asc + ascq);
len = 7 + get_RS_additional_length(result);
if ( get_RS_error_code(result) != 0x70 )
{
DBG(DBG_error, "invalid sense key error code (%d)\n", get_RS_error_code(result));
switch (dev->handle_bad_sense_error)
{
default:
case 0:
DBG(DBG_error, "=> handled as DEVICE BUSY!\n");
return SANE_STATUS_DEVICE_BUSY;
case 1:
DBG(DBG_error, "=> handled as ok!\n");
return SANE_STATUS_GOOD;
case 2:
DBG(DBG_error, "=> handled as i/o error!\n");
return SANE_STATUS_IO_ERROR;
case 3:
DBG(DBG_error, "=> ignored, sense handler does continue\n");
}
}
DBG(DBG_sense, "check condition sense: %s\n", sense_str[sensekey]);
/* when we reach here then we have no valid data in buffer[0] */
/* but it may be helpful to have the result data in buffer[0] */
memset(dev->buffer[0], 0, rs_return_block_size); /* clear sense data buffer */
memcpy(dev->buffer[0], result, len+1); /* copy sense data to buffer */
if (len > 0x15)
{
int scanner_error = get_RS_scanner_error_code(result);
if (scanner_error < 100)
{
DBG(DBG_sense, "-> %s (#%d)\n", scanner_error_str[scanner_error], scanner_error);
}
else
{
DBG(DBG_sense, "-> error %d\n", scanner_error);
}
}
if (get_RS_ILI(result) != 0)
{
DBG(DBG_sense, "-> ILI-ERROR: requested data length is larger than actual length\n");
}
switch(sensekey)
{
case 0x00: /* no sense */
return SANE_STATUS_GOOD;
break;
case 0x03: /* medium error */
if (asc_ascq == 0x1400)
{
DBG(DBG_sense, "-> misfeed, paper jam\n");
return SANE_STATUS_JAMMED;
}
else if (asc_ascq == 0x1401)
{
DBG(DBG_sense, "-> adf not ready\n");
return SANE_STATUS_NO_DOCS;
}
else
{
DBG(DBG_sense, "-> unknown medium error: asc=%d, ascq=%d\n", asc, ascq);
}
break;
case 0x04: /* hardware error */
if (asc_ascq == 0x4000)
{
DBG(DBG_sense, "-> diagnostic error:\n");
if (len >= 0x13)
{
DBG_sense_nz(" dim light\n", get_RS_asb_dim_light(result));
DBG_sense_nz(" no light\n", get_RS_asb_no_light(result));
DBG_sense_nz(" sensor or motor error\n", get_RS_asb_sensor_motor(result));
DBG_sense_nz(" too light\n", get_RS_asb_too_light(result));
DBG_sense_nz(" calibration error\n", get_RS_asb_calibration(result));
DBG_sense_nz(" rom error\n", get_RS_asb_rom(result));
DBG_sense_nz(" ram error\n", get_RS_asb_ram(result));
DBG_sense_nz(" cpu error\n", get_RS_asb_cpu(result));
DBG_sense_nz(" scsi error\n", get_RS_asb_scsi(result));
DBG_sense_nz(" timer error\n", get_RS_asb_timer(result));
DBG_sense_nz(" filter motor error\n", get_RS_asb_filter_motor(result));
DBG_sense_nz(" dc adjust error\n", get_RS_asb_dc_adjust(result));
DBG_sense_nz(" uta home sensor or motor error\n", get_RS_asb_uta_sensor(result));
}
}
else
{
DBG(DBG_sense, "-> unknown hardware error: asc=%d, ascq=%d\n", asc, ascq);
}
return SANE_STATUS_IO_ERROR;
break;
case 0x05: /* illegal request */
if (asc_ascq == 0x2000)
{
DBG(DBG_sense, "-> invalid command operation code\n");
}
else if (asc_ascq == 0x2400)
{
DBG(DBG_sense, "-> illegal field in CDB\n");
}
else if (asc_ascq == 0x2500)
{
DBG(DBG_sense, "-> logical unit not supported\n");
}
else if (asc_ascq == 0x2600)
{
DBG(DBG_sense, "-> invalid field in parameter list\n");
}
else if (asc_ascq == 0x2c01)
{
DBG(DBG_sense, "-> too many windows specified\n");
}
else if (asc_ascq == 0x2c02)
{
DBG(DBG_sense, "-> invalid combination of windows specified\n");
}
else
{
DBG(DBG_sense, "-> illegal request: asc=%d, ascq=%d\n", asc, ascq);
}
if (len >= 0x11)
{
if (get_RS_SKSV(result) != 0)
{
if (get_RS_CD(result) == 0)
{
DBG(DBG_sense, "-> illegal parameter in CDB\n");
}
else
{
DBG(DBG_sense, "-> illegal parameter is in the data parameters sent during data out phase\n");
}
DBG(DBG_sense, "-> error detected in byte %d\n", get_RS_field_pointer(result));
}
}
return SANE_STATUS_IO_ERROR;
break;
case 0x06: /* unit attention */
if (asc_ascq == 0x2900)
{
DBG(DBG_sense, "-> power on, reset or bus device reset\n");
}
else if (asc_ascq == 0x3f01)
{
DBG(DBG_sense, "-> microcode has been changed\n");
}
else
{
DBG(DBG_sense, "-> unit attention: asc=%d, ascq=%d\n", asc, ascq);
}
break;
case 0x09: /* vendor specific */
if (asc == 0x00)
{
DBG(DBG_sense, "-> button protocol\n");
if (ascq & 1)
{
dev->button0_pressed = 1;
DBG(DBG_sense, "-> button 0 pressed\n");
}
if (ascq & 2)
{
dev->button1_pressed = 1;
DBG(DBG_sense, "-> button 1 pressed\n");
}
if (ascq & 4)
{
dev->button2_pressed = 1;
DBG(DBG_sense, "-> button 2 pressed\n");
}
return SANE_STATUS_GOOD;
}
else if (asc_ascq == 0x8001)
{
DBG(DBG_sense, "-> lamp warmup\n");
return SANE_STATUS_DEVICE_BUSY;
}
else if (asc_ascq == 0x8002)
{
DBG(DBG_sense, "-> calibration by driver\n");
if (dev)
{
dev->do_calibration = 1; /* set flag for calibration by driver */
}
return SANE_STATUS_GOOD;
}
else
{
DBG(DBG_sense, "-> vendor specific sense-code: asc=%d, ascq=%d\n", asc, ascq);
}
break;
}
return SANE_STATUS_GOOD;
}
/* ------------------------------------------------------------ UMAX SET RGB BIND -------------------------- */
static void umax_set_rgb_bind(Umax_Scanner *scanner)
{
if ( (scanner->val[OPT_RGB_BIND].w == SANE_FALSE) &&
(strcmp(scanner->val[OPT_MODE].s, COLOR_STR) == 0) ) /* enable rgb options */
{
if (scanner->device->inquiry_analog_gamma)
{
scanner->opt[OPT_ANALOG_GAMMA].cap |= SANE_CAP_INACTIVE;
scanner->opt[OPT_ANALOG_GAMMA_R].cap &= ~SANE_CAP_INACTIVE;
scanner->opt[OPT_ANALOG_GAMMA_G].cap &= ~SANE_CAP_INACTIVE;
scanner->opt[OPT_ANALOG_GAMMA_B].cap &= ~SANE_CAP_INACTIVE;
}
if (scanner->device->inquiry_highlight)
{
scanner->opt[OPT_HIGHLIGHT].cap |= SANE_CAP_INACTIVE;
scanner->opt[OPT_HIGHLIGHT_R].cap &= ~SANE_CAP_INACTIVE;
scanner->opt[OPT_HIGHLIGHT_G].cap &= ~SANE_CAP_INACTIVE;
scanner->opt[OPT_HIGHLIGHT_B].cap &= ~SANE_CAP_INACTIVE;
}
if (scanner->device->inquiry_shadow)
{
scanner->opt[OPT_SHADOW].cap |= SANE_CAP_INACTIVE;
scanner->opt[OPT_SHADOW_R].cap &= ~SANE_CAP_INACTIVE;
scanner->opt[OPT_SHADOW_G].cap &= ~SANE_CAP_INACTIVE;
scanner->opt[OPT_SHADOW_B].cap &= ~SANE_CAP_INACTIVE;
}
}
else /* only show gray options */
{
if (scanner->device->inquiry_analog_gamma)
{
scanner->opt[OPT_ANALOG_GAMMA].cap &= ~SANE_CAP_INACTIVE;
scanner->opt[OPT_ANALOG_GAMMA_R].cap |= SANE_CAP_INACTIVE;
scanner->opt[OPT_ANALOG_GAMMA_G].cap |= SANE_CAP_INACTIVE;
scanner->opt[OPT_ANALOG_GAMMA_B].cap |= SANE_CAP_INACTIVE;
}
if (scanner->device->inquiry_highlight)
{
scanner->opt[OPT_HIGHLIGHT].cap &= ~SANE_CAP_INACTIVE;
scanner->opt[OPT_HIGHLIGHT_R].cap |= SANE_CAP_INACTIVE;
scanner->opt[OPT_HIGHLIGHT_G].cap |= SANE_CAP_INACTIVE;
scanner->opt[OPT_HIGHLIGHT_B].cap |= SANE_CAP_INACTIVE;
}
if (scanner->device->inquiry_shadow)
{
scanner->opt[OPT_SHADOW].cap &= ~SANE_CAP_INACTIVE;
scanner->opt[OPT_SHADOW_R].cap |= SANE_CAP_INACTIVE;
scanner->opt[OPT_SHADOW_G].cap |= SANE_CAP_INACTIVE;
scanner->opt[OPT_SHADOW_B].cap |= SANE_CAP_INACTIVE;
}
}
if ( (scanner->device->inquiry_exposure_adj) && (scanner->val[OPT_SELECT_EXPOSURE_TIME].w) )
{
if ( (scanner->val[OPT_RGB_BIND].w == SANE_FALSE) &&
(!scanner->device->exposure_time_rgb_bind) &&
(strcmp(scanner->val[OPT_MODE].s, COLOR_STR) == 0) ) /* enable rgb exposure time options */
{
if (scanner->val[OPT_SELECT_CAL_EXPOSURE_TIME].w) /* exposure time setting for calibration enabled */
{
scanner->opt[OPT_CAL_EXPOS_TIME].cap |= SANE_CAP_INACTIVE;
scanner->opt[OPT_CAL_EXPOS_TIME_R].cap &= ~SANE_CAP_INACTIVE;
scanner->opt[OPT_CAL_EXPOS_TIME_G].cap &= ~SANE_CAP_INACTIVE;
scanner->opt[OPT_CAL_EXPOS_TIME_B].cap &= ~SANE_CAP_INACTIVE;
}
else /* no separate settings for calibration exposure times */
{
scanner->opt[OPT_CAL_EXPOS_TIME].cap |= SANE_CAP_INACTIVE;
scanner->opt[OPT_CAL_EXPOS_TIME_R].cap |= SANE_CAP_INACTIVE;
scanner->opt[OPT_CAL_EXPOS_TIME_G].cap |= SANE_CAP_INACTIVE;
scanner->opt[OPT_CAL_EXPOS_TIME_B].cap |= SANE_CAP_INACTIVE;
}
scanner->opt[OPT_SCAN_EXPOS_TIME].cap |= SANE_CAP_INACTIVE;
scanner->opt[OPT_SCAN_EXPOS_TIME_R].cap &= ~SANE_CAP_INACTIVE;
scanner->opt[OPT_SCAN_EXPOS_TIME_G].cap &= ~SANE_CAP_INACTIVE;
scanner->opt[OPT_SCAN_EXPOS_TIME_B].cap &= ~SANE_CAP_INACTIVE;
}
else /* enable gray exposure time options */
{
if (scanner->val[OPT_SELECT_CAL_EXPOSURE_TIME].w) /* exposure time setting for calibration enabled */
{
scanner->opt[OPT_CAL_EXPOS_TIME].cap &= ~SANE_CAP_INACTIVE;
}
else /* no separate settings for calibration exposure times */
{
scanner->opt[OPT_CAL_EXPOS_TIME].cap |= SANE_CAP_INACTIVE;
}
scanner->opt[OPT_CAL_EXPOS_TIME_R].cap |= SANE_CAP_INACTIVE;
scanner->opt[OPT_CAL_EXPOS_TIME_G].cap |= SANE_CAP_INACTIVE;
scanner->opt[OPT_CAL_EXPOS_TIME_B].cap |= SANE_CAP_INACTIVE;
scanner->opt[OPT_SCAN_EXPOS_TIME].cap &= ~SANE_CAP_INACTIVE;
scanner->opt[OPT_SCAN_EXPOS_TIME_R].cap |= SANE_CAP_INACTIVE;
scanner->opt[OPT_SCAN_EXPOS_TIME_G].cap |= SANE_CAP_INACTIVE;
scanner->opt[OPT_SCAN_EXPOS_TIME_B].cap |= SANE_CAP_INACTIVE;
}
}
}
/* ------------------------------------------------------------ UMAX CALCULATE PIXELS ---------------------- */
static int umax_calculate_pixels(int scansize_pixel, int resolution, int resolution_base, int coordinate_base)
/* scansize_pixel = size in pixels at 1200 dpi */
/* resolution = scan resolution */
/* resolution_base = this is the optical resolution * 1 or * 2 */
/* coordinate_base = this is 1200 dpi */
{
unsigned int intsize_inch, intsize_pixel, diffsize_pixel, missing_pixels, del_pixel_1, pix;
int toomuch;
intsize_inch = scansize_pixel / coordinate_base; /* full inches */
intsize_pixel = intsize_inch * resolution; /* pixels in full inches */
diffsize_pixel = scansize_pixel % coordinate_base; /* missing pixels in last inch at 1200 dpi */
missing_pixels = diffsize_pixel * resolution_base / coordinate_base; /* missing pixels at resolution_base dpi */
del_pixel_1 = resolution_base - resolution; /* pixels to erase in one inch */
toomuch = 0; /* number of pixels that must be deleted in last inch */
if (del_pixel_1 != 0) /* search the number of pixels that must deleted */
{
pix = 0;
while (pix <= missing_pixels)
{
toomuch++;
pix = toomuch * resolution_base/del_pixel_1;
}
if (pix > missing_pixels)
{
toomuch--;
}
}
return (intsize_pixel + missing_pixels - toomuch);
}
/* ------------------------------------------------------------ UMAX FORGET LINE --------------------------- */
static int umax_forget_line(Umax_Device *dev, int color)
/* tests if line related to optical resolution has to be skipped for selected resolution */
/* returns 0 if line is ok, -1 if line has to be skipped */
{
unsigned int opt_res = dev->relevant_optical_res * dev->scale_y;
unsigned int forget;
dev->pixelline_opt_res++; /* increment number of lines in optical res */
if (opt_res != dev->y_resolution) /* are there any lines to skip ? */
{
forget = (dev->pixelline_del[color] * opt_res)/(opt_res - dev->y_resolution);
if (dev->pixelline_optic[color]++ == forget)
{
dev->pixelline_del[color]++; /* inc pointer to next line to skip */
return(-1); /* skip line */
}
}
return(0); /* ok, order this line */
}
/* ------------------------------------------------------------ UMAX ORDER LINE TO PIXEL ------------------- */
static void umax_order_line_to_pixel(Umax_Device *dev, unsigned char *source, int color)
/* reads a one-color line and writes it into a pixel-ordered-buffer if line */
/* is not skipped */
/* color = 0:red, 1:green, 2:blue */
{
unsigned int i;
unsigned int line = dev->pixelline_next[color]; /* bufferlinenumber */
unsigned char *dest = dev->pixelbuffer;
if (dest != NULL)
{
if (dev->bits_per_pixel_code == 1) /* 24 bpp */
{
dest += line * dev->width_in_pixels * 3 + color;
for (i=0; i<dev->width_in_pixels; i++) /* cp each pixel into pixelbuffer */
{
*dest++ = *source++;
dest++;
dest++;
}
}
else /* > 24 bpp */
{
dest += line * dev->width_in_pixels * 6 + color * 2;
for(i=0; i<dev->width_in_pixels; i++) /* cp each pixel into pixelbuffer */
{
*dest++ = *source++; /* byte order correct ? , don't know ! */
*dest++ = *source++;
dest++; dest++;
dest++; dest++;
}
}
line++;
if (line >= dev->pixelline_max)
{
line = 0;
}
dev->pixelline_next[color] = line; /* next line of this color */
dev->pixelline_ready[color]++; /* number of ready lines for color */
DBG(DBG_read, "merged line as color %d to line %d\n", color, dev->pixelline_ready[color]);
}
}
/* ------------------------------------------------------------ UMAX ORDER LINE ---------------------------- */
static void umax_order_line(Umax_Device *dev, unsigned char *source)
{
unsigned int CCD_distance = dev->CCD_distance * dev->scale_y;
unsigned int length = (dev->scanlength * dev->scale_y * dev->relevant_optical_res) / dev->y_coordinate_base;
unsigned int color;
do /* search next valid line */
{
if (dev->pixelline_opt_res < CCD_distance)
{
color = dev->CCD_color[0]; /* color 0 */
}
else if (dev->pixelline_opt_res < CCD_distance * 3)
{
color = dev->CCD_color[1 + ((dev->pixelline_opt_res - CCD_distance) % 2)]; /* color 1,2 */
}
else if (dev->pixelline_opt_res < length * 3 - CCD_distance * 3)
{
color = dev->CCD_color[3 + (dev->pixelline_opt_res % 3)]; /* color 3,4,5 */
}
else if (dev->pixelline_opt_res < length * 3 - CCD_distance)
{
color = dev->CCD_color[6 + ((dev->pixelline_opt_res - length*3 + CCD_distance*3) % 2)]; /* color 6,7 */
}
else
{
color = dev->CCD_color[8]; /* color 8 */
}
} while(umax_forget_line(dev, color) != 0); /* until found correct line */
umax_order_line_to_pixel(dev, source, color);
}
/* ------------------------------------------------------------ UMAX GET PIXEL LINE ------------------------ */
static unsigned char * umax_get_pixel_line(Umax_Device *dev)
{
unsigned char *source = NULL;
if (dev->pixelbuffer != NULL)
{
if ( (dev->pixelline_ready[0] > dev->pixelline_written) &&
(dev->pixelline_ready[1] > dev->pixelline_written) &&
(dev->pixelline_ready[2] > dev->pixelline_written) )
{
source = dev->pixelbuffer + dev->pixelline_read * dev->width_in_pixels * 3;
dev->pixelline_written++;
dev->pixelline_read++;
if (dev->pixelline_read >= dev->pixelline_max)
{
dev->pixelline_read = 0;
}
}
}
return source;
}
/* ============================================================ Switches between the SCSI and USB commands = */
/* ------------------------------------------------------------ UMAX SCSI CMD ------------------------------ */
static SANE_Status umax_scsi_cmd(Umax_Device *dev, const void *src, size_t src_size, void *dst, size_t * dst_size)
{
switch (dev->connection_type)
{
case SANE_UMAX_SCSI:
return sanei_scsi_cmd(dev->sfd, src, src_size, dst, dst_size);
break;
#ifdef UMAX_ENABLE_USB
case SANE_UMAX_USB:
return sanei_umaxusb_cmd(dev->sfd, src, src_size, dst, dst_size);
break;
#endif
default:
return(SANE_STATUS_INVAL);
}
}
/* ------------------------------------------------------------ UMAX SCSI OPEN EXTENDED -------------------- */
static SANE_Status umax_scsi_open_extended(const char *devicename, Umax_Device *dev,
SANEI_SCSI_Sense_Handler handler, void *handler_arg, int *buffersize)
{
switch (dev->connection_type)
{
case SANE_UMAX_SCSI:
return sanei_scsi_open_extended(devicename, &dev->sfd, handler, handler_arg, buffersize);
break;
#ifdef UMAX_ENABLE_USB
case SANE_UMAX_USB:
return sanei_umaxusb_open_extended(devicename, &dev->sfd, handler, handler_arg, buffersize);
break;
#endif
default:
return(SANE_STATUS_INVAL);
}
}
/* ------------------------------------------------------------ UMAX SCSI OPEN ----------------------------- */
static SANE_Status umax_scsi_open(const char *devicename, Umax_Device *dev,
SANEI_SCSI_Sense_Handler handler, void *handler_arg)
{
switch (dev->connection_type)
{
case SANE_UMAX_SCSI:
return sanei_scsi_open(devicename, &dev->sfd, handler, handler_arg);
break;
#ifdef UMAX_ENABLE_USB
case SANE_UMAX_USB:
return sanei_umaxusb_open(devicename, &dev->sfd, handler, handler_arg);
break;
#endif
default:
return(SANE_STATUS_INVAL);
}
}
/* ------------------------------------------------------------ UMAX SCSI CLOSE ---------------------------- */
static void umax_scsi_close(Umax_Device *dev)
{
switch (dev->connection_type)
{
case SANE_UMAX_SCSI:
sanei_scsi_close(dev->sfd);
dev->sfd=-1;
break;
#ifdef UMAX_ENABLE_USB
case SANE_UMAX_USB:
sanei_umaxusb_close(dev->sfd);
dev->sfd=-1;
break;
#endif
}
}
/* ------------------------------------------------------------ UMAX SCSI REQ ENTER ------------------------ */
static SANE_Status umax_scsi_req_enter(Umax_Device *dev, const void *src, size_t src_size,
void *dst, size_t * dst_size, void **idp)
{
switch (dev->connection_type)
{
case SANE_UMAX_SCSI:
return sanei_scsi_req_enter (dev->sfd, src, src_size, dst, dst_size, idp);
break;
#ifdef UMAX_ENABLE_USB
case SANE_UMAX_USB:
return sanei_umaxusb_req_enter (dev->sfd, src, src_size, dst, dst_size, idp);
break;
#endif
default:
return(SANE_STATUS_INVAL);
}
}
/* ------------------------------------------------------------ UMAX SCSI REQ WAIT ------------------------- */
static SANE_Status umax_scsi_req_wait(Umax_Device *dev, void *id)
{
switch (dev->connection_type)
{
case SANE_UMAX_SCSI:
return sanei_scsi_req_wait(id);
break;
#ifdef UMAX_ENABLE_USB
case SANE_UMAX_USB:
return sanei_umaxusb_req_wait(id);
break;
#endif
default:
return(SANE_STATUS_INVAL);
}
}
/* ------------------------------------------------------------ UMAX SCSI GET LAMP STATUS ------------------ */
static SANE_Status umax_scsi_get_lamp_status(Umax_Device *dev, int *lamp_on)
{
SANE_Status status;
size_t size = 1;
DBG(DBG_proc, "umax_scsi_get_lamp_status\n");
status = umax_scsi_cmd(dev, get_lamp_status.cmd, get_lamp_status.size, dev->buffer[0], &size);
if (status)
{
DBG(DBG_error, "umax_scsi_get_lamp_status: command returned status %s\n", sane_strstatus(status));
return status;
}
*lamp_on = get_lamp_status_lamp_on(dev->buffer[0]);
DBG(DBG_info, "lamp_status = %d\n", *lamp_on);
return status;
}
/* ------------------------------------------------------------ UMAX SCSI SET LAMP STATUS ------------------ */
static SANE_Status umax_scsi_set_lamp_status(Umax_Device *dev, int lamp_on)
{
SANE_Status status;
DBG(DBG_proc, "umax_scsi_set_lamp_status\n");
DBG(DBG_info, "lamp_status=%d\n", lamp_on);
set_lamp_status_lamp_on(set_lamp_status.cmd, lamp_on);
status = umax_scsi_cmd(dev, set_lamp_status.cmd, set_lamp_status.size, NULL, NULL);
if (status)
{
DBG(DBG_error, "umax_scsi_set_lamp_status: command returned status %s\n", sane_strstatus(status));
}
return status;
}
/* ------------------------------------------------------------ UMAX SET LAMP STATUS ----------------------- */
static SANE_Status umax_set_lamp_status(SANE_Handle handle, int lamp_on)
{
Umax_Scanner *scanner = handle;
int lamp_status;
SANE_Status status;
DBG(DBG_proc, "umax_set_lamp_status\n");
if (umax_scsi_open(scanner->device->sane.name, scanner->device, sense_handler,
scanner->device) != SANE_STATUS_GOOD )
{
DBG(DBG_error, "ERROR: umax_set_lamp_status: open of %s failed:\n", scanner->device->sane.name);
return SANE_STATUS_INVAL;
}
status = umax_scsi_get_lamp_status(scanner->device, &lamp_status);
if (!status)
{
status = umax_scsi_set_lamp_status(scanner->device, lamp_on);
}
umax_scsi_close(scanner->device);
return status;
}
/* ------------------------------------------------------------ UMAX GET DATA BUFFER STATUS ---------------- */
#ifndef UMAX_HIDE_UNUSED /* NOT USED */
static SANE_Status umax_get_data_buffer_status(Umax_Device *dev)
{
SANE_Status status;
DBG(DBG_proc, "get_data_buffer_status\n");
set_GDBS_wait(get_data_buffer_status.cmd,1); /* wait for scanned data */
status = umax_scsi_cmd(dev, get_data_buffer_status.cmd, get_data_buffer_status.size, NULL, NULL);
if (status)
{
DBG(DBG_error, "umax_get_data_buffer_status: command returned status %s\n", sane_strstatus(status));
}
return status;
}
#endif
/* ------------------------------------------------------------ UMAX DO REQUEST SENSE ---------------------- */
static void umax_do_request_sense(Umax_Device *dev)
{
size_t size = rs_return_block_size;
SANE_Status status;
DBG(DBG_proc, "do_request_sense\n");
set_RS_allocation_length(request_sense.cmd, rs_return_block_size);
status = umax_scsi_cmd(dev, request_sense.cmd, request_sense.size, dev->buffer[0], &size);
if (status)
{
DBG(DBG_error, "umax_do_request_sense: command returned status %s\n", sane_strstatus(status));
}
}
/* ------------------------------------------------------------ UMAX WAIT SCANNER -------------------------- */
static SANE_Status umax_wait_scanner(Umax_Device *dev)
{
SANE_Status status;
int cnt = 0;
DBG(DBG_proc, "wait_scanner\n");
do
{
if (cnt > 100) /* maximal 100 * 0.5 sec = 50 sec */
{
DBG(DBG_warning, "scanner does not get ready\n");
return -1;
}
/* test unit ready */
status = umax_scsi_cmd(dev, test_unit_ready.cmd, test_unit_ready.size, NULL, NULL);
cnt++;
if (status)
{
if (cnt == 1)
{
DBG(DBG_info2, "scanner reports %s, waiting ...\n", sane_strstatus(status));
}
usleep(500000); /* wait 0.5 seconds */
}
} while (status != SANE_STATUS_GOOD );
DBG(DBG_info, "scanner ready\n");
return status;
}
#define WAIT_SCANNER { int status = umax_wait_scanner(dev); if (status) return status; }
/* ------------------------------------------------------------ UMAX GRAB SCANNER -------------------------- */
static int umax_grab_scanner(Umax_Device *dev)
{
int status;
DBG(DBG_proc, "grab_scanner\n");
WAIT_SCANNER; /* wait for scanner ready */
status = umax_scsi_cmd(dev, reserve_unit.cmd, reserve_unit.size, NULL, NULL);
if (status)
{
DBG(DBG_error, "umax_grab_scanner: command returned status %s\n", sane_strstatus(status));
}
else
{
DBG(DBG_info, "scanner reserved\n");
}
return status;
}
/* ------------------------------------------------------------ UMAX REPOSITION SCANNER -------------------- */
static int umax_reposition_scanner(Umax_Device *dev)
{
int status;
int pause;
pause = dev->pause_after_reposition + dev->pause_for_moving * (dev->upper_left_y + dev->scanlength) /
( (dev->inquiry_fb_length * dev->y_coordinate_base) );
DBG(DBG_info2, "trying to reposition scanner ...\n");
status = umax_scsi_cmd(dev, object_position.cmd, object_position.size, NULL, NULL);
if (status)
{
DBG(DBG_error, "umax_reposition_scanner: command returned status %s\n", sane_strstatus(status));
return status;
}
if (pause > 0) /* predefined time to wait (Astra 2400S) */
{
DBG(DBG_info2, "pause for repositioning %d msec ...\n", pause);
usleep(((long) pause) * 1000);
DBG(DBG_info, "repositioning pause done\n");
}
else if (pause == 0) /* use TEST UNIT READY */
{
WAIT_SCANNER;
DBG(DBG_info, "scanner repositioned\n");
}
else /* pause < 0 : return without any pause */
{
DBG(DBG_info, "not waiting for finishing reposition scanner\n");
}
return SANE_STATUS_GOOD;
}
/* ------------------------------------------------------------ UMAX GIVE SCANNER -------------------------- */
static int umax_give_scanner(Umax_Device *dev)
{
int status;
DBG(DBG_info2, "trying to release scanner ...\n");
status = umax_scsi_cmd(dev, release_unit.cmd, release_unit.size, NULL, NULL);
if (status)
{
DBG(DBG_error, "umax_give_scanner: command returned status %s\n", sane_strstatus(status));
}
else
{
DBG(DBG_info, "scanner released\n");
}
if (!dev->batch_scan || dev->batch_end)
{
umax_reposition_scanner(dev);
}
else
{
usleep(200000); /* 200 ms pause to make sure program does not exit before scanner is ready */
}
return status;
}
/* ------------------------------------------------------------ UMAX SEND GAMMA DATA ----------------------- */
static void umax_send_gamma_data(Umax_Device *dev, void *gamma_data, int color)
{
unsigned char *data = gamma_data;
unsigned char *dest;
int length;
SANE_Status status;
DBG(DBG_proc, "send_gamma_data\n");
if (dev->inquiry_gamma_dwload == 0)
{
DBG(DBG_error, "ERROR: gamma download not available\n");
return;
}
memcpy(dev->buffer[0], send.cmd, send.size); /* send */
set_S_datatype_code(dev->buffer[0], S_datatype_gamma); /* gamma curve */
dest = dev->buffer[0] + send.size;
if (dev->inquiry_gamma_DCF == 0) /* gamma format type 0 */
{
DBG(DBG_info, "using gamma download curve format type 0\n");
memcpy(dest, gamma_DCF0.cmd, gamma_DCF0.size);
if (color == 1) /* one color */
{
set_DCF0_gamma_lines(dest, DCF0_gamma_one_line);
set_DCF0_gamma_color(dest, 0, DCF0_gamma_color_gray); /* grayscale */
if ( (dev->colormode == RGB) && (dev->three_pass != 0) ) /* 3 pass color */
{
set_DCF0_gamma_color(dest, 0, dev->three_pass_color); /* set color */
}
dest = dest + 2;
memcpy(dest, data, 1024); /* copy data */
set_S_xfer_length(dev->buffer[0], 1026); /* set length */
status = umax_scsi_cmd(dev, dev->buffer[0], send.size + 1026, NULL, NULL);
if (status)
{
DBG(DBG_error, "umax_send_gamma_data(DCF=0, one color): command returned status %s\n", sane_strstatus(status));
}
}
else /* three colors */
{
set_DCF0_gamma_lines(dest, DCF0_gamma_three_lines);
set_DCF0_gamma_color(dest, 0, DCF0_gamma_color_red); /* red */
set_DCF0_gamma_color(dest, 1, DCF0_gamma_color_green); /* green */
set_DCF0_gamma_color(dest, 2, DCF0_gamma_color_blue); /* blue */
dest = dest + 2;
memcpy(dest, data, 1024); /* copy red data */
dest = dest + 1025;
data = data + 1024;
memcpy(dest, data, 1024); /* copy green data */
dest = dest + 1025;
data = data + 1024;
memcpy(dest, data, 1024); /* copy blue data */
set_S_xfer_length(dev->buffer[0], 3076); /* set length */
status = umax_scsi_cmd(dev, dev->buffer[0], send.size + 3076, NULL, NULL);
if (status)
{
DBG(DBG_error, "umax_send_gamma_data(DCF=0, RGB): command returned status %s\n", sane_strstatus(status));
}
}
}
else if (dev->inquiry_gamma_DCF == 1) /* gamma format type 1 */
{
DBG(DBG_info, "using gamma download curve format type 1\n");
memcpy(dest, gamma_DCF1.cmd, gamma_DCF1.size);
set_DCF1_gamma_color(dest, DCF1_gamma_color_gray); /* grayscale */
if ( (dev->colormode == RGB) && (dev->three_pass != 0) ) /* 3 pass color */
{
set_DCF1_gamma_color(dest, dev->three_pass_color); /* set color */
}
dest = dest + 2;
memcpy(dest, data, 256); /* copy data */
set_S_xfer_length(dev->buffer[0], 258); /* set length */
status = umax_scsi_cmd(dev, dev->buffer[0], send.size + 258, NULL, NULL);
if (status)
{
DBG(DBG_error, "umax_send_gamma_data(DCF=1): command returned status %s\n", sane_strstatus(status));
}
}
else if (dev->inquiry_gamma_DCF == 2) /* gamma format type 2 */
{
DBG(DBG_info, "using gamma download curve format type 2\n");
memcpy(dest, gamma_DCF2.cmd, gamma_DCF2.size);
set_DCF2_gamma_color(dest, DCF2_gamma_color_gray); /* grayscale */
if ( (dev->colormode == RGB) && (dev->three_pass != 0) ) /* 3 pass color */
{ set_DCF2_gamma_color(dest, dev->three_pass_color); } /* set color */
if (color == 1)
{
set_DCF2_gamma_lines(dest, DCF2_gamma_one_line);
}
else
{
set_DCF2_gamma_lines(dest, DCF2_gamma_three_lines);
}
set_DCF2_gamma_input_bits(dest, dev->gamma_input_bits_code);
set_DCF2_gamma_output_bits(dest, dev->bits_per_pixel_code);
dest = dev->buffer[0] + send.size + gamma_DCF2.size; /* write to dest */
if (dev->gamma_input_bits_code & 32)
{
length = 65536; /* 16 input bits */
}
else if (dev->gamma_input_bits_code & 16)
{
length = 16384; /* 14 input bits */
}
else if (dev->gamma_input_bits_code & 8)
{
length = 4096; /* 12 input bits */
}
else if (dev->gamma_input_bits_code & 4)
{
length = 1024; /* 10 input bits */
}
else if (dev->gamma_input_bits_code & 2)
{
length = 512; /* 9 input bits */
}
else
{
length = 256; /* 8 input bits */
}
if (dev->bits_per_pixel_code != 1) /* more than 8 output bits per pixel */
{
length = length * 2; /* = 2 output bytes */
}
if (dev->bufsize >= color*length+gamma_DCF2.size)
{
set_S_xfer_length(dev->buffer[0], color*length+gamma_DCF2.size); /* set length */
memcpy(dest, data, color*length); /* copy data */
status = umax_scsi_cmd(dev, dev->buffer[0], send.size+gamma_DCF2.size + length * color, NULL, NULL);
if (status)
{
DBG(DBG_error, "umax_send_gamma_data(DCF=2): command returned status %s\n", sane_strstatus(status));
}
}
else
{
DBG(DBG_error, "ERROR: too small scsi buffer (%d bytes) to send gamma data\n", dev->bufsize);
}
}
else
{
DBG(DBG_error, "ERROR: unknown gamma download curve type for this scanner\n");
}
}
/* ------------------------------------------------------------ UMAX SEND DATA ---------------------------- */
static void umax_send_data(Umax_Device *dev, void *data, int size, int datatype)
{
unsigned char *dest;
SANE_Status status;
memcpy(dev->buffer[0], send.cmd, send.size); /* send */
set_S_datatype_code(dev->buffer[0], datatype); /* set datatype */
set_S_xfer_length(dev->buffer[0], size); /* bytes */
dest=dev->buffer[0] + send.size;
memcpy(dest, data, size); /* copy data */
status = umax_scsi_cmd(dev, dev->buffer[0], send.size + size, NULL, NULL);
if (status)
{
DBG(DBG_error, "umax_send_data: command returned status %s\n", sane_strstatus(status));
}
}
/* ------------------------------------------------------------ UMAX SEND HALFTONE PATTERN ----------------- */
#ifndef UMAX_HIDE_UNUSED
static void umax_send_halftone_pattern(Umax_Device *dev, void *data, int size)
{
DBG(DBG_proc,"send_halftone_pattern\n");
umax_send_data(dev, data, size*size, S_datatype_halftone);
}
#endif
/* ------------------------------------------------------------ UMAX SEND SHADING DATA -------------------- */
static void umax_send_shading_data(Umax_Device *dev, void *data, int size)
{
DBG(DBG_proc,"send_shading_data\n");
umax_send_data(dev, data, size, S_datatype_shading);
}
/* ------------------------------------------------------------ UMAX SEND GAIN DATA ----------------------- */
#ifndef UMAX_HIDE_UNUSED
static void umax_send_gain_data(Umax_Device *dev, void *data, int size)
{
DBG(DBG_proc,"send_gain_data\n");
umax_send_data(dev, data, size, S_datatype_gain);
}
#endif
/* ------------------------------------------------------------ UMAX QUEUE READ IMAGE DATA REQ ------------- */
static SANE_Status umax_queue_read_image_data_req(Umax_Device *dev, unsigned int length, int bufnr)
{
SANE_Status status;
DBG(DBG_proc, "umax_queue_read_image_data_req for buffer[%d], length = %d\n", bufnr, length);
set_R_xfer_length(sread.cmd, length); /* set length */
set_R_datatype_code(sread.cmd, R_datatype_imagedata); /* set datatype */
dev->length_queued[bufnr] = length; /* set length request */
dev->length_read[bufnr] = length; /* set length request, can be changed asynchronous by umax_scsi_req_enter */
status = umax_scsi_req_enter(dev, sread.cmd, sread.size, dev->buffer[bufnr], &(dev->length_read[bufnr]), &(dev->queue_id[bufnr]));
if (status)
{
DBG(DBG_error, "umax_queue_read_image_data_req: command returned status %s\n", sane_strstatus(status));
return -1;
}
else
{
DBG(DBG_info2, "umax_queue_read_image_data_req: id for buffer[%d] is %p\n", bufnr, dev->queue_id[bufnr]);
}
return length;
}
/* ------------------------------------------------------------ UMAX WAIT QUEUED IMAGE DATA ---------------- */
static int umax_wait_queued_image_data(Umax_Device *dev, int bufnr)
{
SANE_Status status;
DBG(DBG_proc, "umax_wait_queued_image_data for buffer[%d] (id=%p)\n", bufnr, dev->queue_id[bufnr]);
status = umax_scsi_req_wait(dev, dev->queue_id[bufnr]);
if (status)
{
DBG(DBG_error, "umax_wait_queued_image_data: wait returned status %s\n", sane_strstatus(status));
return -1;
}
return SANE_STATUS_GOOD;
}
/* ------------------------------------------------------------ UMAX READ DATA ----------------------------- */
static int umax_read_data(Umax_Device *dev, size_t length, int datatype)
{
SANE_Status status;
set_R_xfer_length(sread.cmd, length); /* set length */
set_R_datatype_code(sread.cmd, datatype); /* set datatype */
status = umax_scsi_cmd(dev, sread.cmd, sread.size, dev->buffer[0], &length);
if (status)
{
DBG(DBG_error, "umax_read_data: command returned status %s\n", sane_strstatus(status));
return -1;
}
return length;
}
/* ------------------------------------------------------------ UMAX READ SHADING DATA -------------------- */
static int umax_read_shading_data(Umax_Device *dev, unsigned int length)
{
DBG(DBG_proc,"read_shading_data\n");
return umax_read_data(dev, length, R_datatype_shading);
}
/* ------------------------------------------------------------ UMAX READ GAIN DATA ----------------------- */
#ifndef UMAX_HIDE_UNUSED
static int umax_read_gain_data(Umax_Device *dev, unsigned int length)
{
DBG(DBG_proc,"read_gain_data\n");
return umax_read_data(dev, length, R_datatype_gain);
}
#endif
/* ------------------------------------------------------------ UMAX READ IMAGE DATA ---------------------- */
#ifndef UMAX_HIDE_UNUSED
static int umax_read_image_data(Umax_Device *dev, unsigned int length)
{
DBG(DBG_proc,"read_image_data\n");
WAIT_SCANNER;
return umax_read_data(dev, length, R_datatype_imagedata);
}
#endif
/* ------------------------------------------------------------ UMAX CORRECT LIGHT ------------------------- */
static int umax_correct_light(int light, int analog_gamma_byte) /* correct highlight/shadow if analog gamma is set */
{
double analog_gamma;
analog_gamma=analog_gamma_table[analog_gamma_byte];
return( (int) 255 * pow( ((double) light)/255.0 , (1.0/analog_gamma) )+.5 );
}
/* ------------------------------------------------------------ UMAX SET WINDOW PARAM ---------------------- */
/* set_window_param sets all the window parameters. This means building a */
/* fairly complicated SCSI command before sending it... */
static SANE_Status umax_set_window_param(Umax_Device *dev)
{
SANE_Status status;
int num_dblocks = 1; /* number of window descriptor blocks, usually 1 or 3 */
unsigned char buffer_r[max_WDB_size], buffer_g[max_WDB_size], buffer_b[max_WDB_size];
DBG(DBG_proc, "set_window_param\n");
memset(buffer_r, '\0', max_WDB_size); /* clear buffer */
set_WDB_length(dev->wdb_len); /* length of win descriptor block */
memcpy(buffer_r, window_descriptor_block.cmd, window_descriptor_block.size); /* copy preset data */
set_WD_wid(buffer_r, 0); /* window identifier */
set_WD_auto(buffer_r, dev->set_auto); /* 0 or 1: don't know what it is */
/* geometry */
set_WD_Xres(buffer_r, dev->x_resolution); /* x resolution in dpi */
set_WD_Yres(buffer_r, dev->y_resolution); /* y resolution in dpi */
set_WD_ULX(buffer_r, dev->upper_left_x); /* left_edge x */
set_WD_ULY(buffer_r, dev->upper_left_y); /* upper_edge y */
set_WD_width(buffer_r, dev->scanwidth); /* width */
set_WD_length(buffer_r, dev->scanlength); /* length */
/* BTC */
set_WD_brightness(buffer_r, dev->brightness); /* brightness, only halftone */
set_WD_threshold(buffer_r, dev->threshold); /* threshold, only lineart */
set_WD_contrast(buffer_r, dev->contrast); /* contrast, only halftone */
/* scanmode, preset to LINEART */
set_WD_composition(buffer_r, WD_comp_lineart); /* image composition */
/* = (scan-mode) */
set_WD_bitsperpixel(buffer_r, WD_bits_1); /* bits/pixel (1,8,9,10,12,14,16) */
set_WD_halftone(buffer_r, dev->halftone); /* select halftone-pattern */
set_WD_RIF(buffer_r, dev->reverse); /* reverse, invert black and white */
set_WD_speed(buffer_r, dev->WD_speed); /* set speed */
set_WD_select_color(buffer_r, WD_color_gray); /* color for window-block */
/* set highlight and shadow in dependence of analog gamma */
set_WD_highlight(buffer_r, umax_correct_light(dev->highlight_r, dev->analog_gamma_r));
set_WD_shadow(buffer_r, umax_correct_light(dev->shadow_r, dev->analog_gamma_r));
/* scan options */
set_WD_gamma(buffer_r, dev->digital_gamma_r); /* set digital gamma */
set_WD_module(buffer_r, dev->module); /* flatbed or transparency */
set_WD_CBHS(buffer_r, dev->cbhs_range); /* 50 or 255 */
set_WD_FF(buffer_r, dev->fix_focus_position); /* fix focus position */
set_WD_RMIF(buffer_r, dev->reverse_multi); /* reverse color-values */
set_WD_FDC(buffer_r, dev->lens_cal_in_doc_pos); /* lens calibration in document position */
set_WD_PF(buffer_r, dev->disable_pre_focus); /* disable pre focus */
set_WD_LCL(buffer_r, dev->holder_focus_pos_0mm); /* 0.6mm <-> 0.0mm holder focus position */
set_WD_HBT(buffer_r, dev->low_byte_first); /* set byte order for 16 bit scanners */
set_WD_DOR(buffer_r, dev->dor); /* double-resolution-mode */
set_WD_scan_exposure_level(buffer_r, dev->exposure_time_scan_r); /* scan exposure time */
set_WD_calibration_exposure_level(buffer_r, dev->exposure_time_calibration_r);/* calibration exposure time */
set_WD_batch(buffer_r, dev->batch_scan); /* batch or normal scan */
set_WD_MF(buffer_r, dev->manual_focus); /* automatic <-> manual focus */
set_WD_line_arrangement(buffer_r, WD_line_arrengement_by_fw); /* line arrangement by scanner */
set_WD_warmup(buffer_r, dev->warmup); /* warmup */
set_WD_calibration(buffer_r, dev->calibration); /* image calibration */
set_WD_color_sequence(buffer_r, WD_color_sequence_RGB); /* sequence RGB */
set_WD_color_ordering(buffer_r, WD_color_ordering_pixel); /* set to pixel for pbm, pgm, pnm-file */
set_WD_analog_gamma(buffer_r, dev->analog_gamma_r ); /* analog gamma */
set_WD_lamp_c_density(buffer_r, dev->c_density); /* calibrat. lamp density */
set_WD_lamp_s_density(buffer_r, dev->s_density); /* scan lamp density */
set_WD_next_upper_left(buffer_r, dev->batch_next_tl_y); /* batch scan next top left y position */
set_WD_pixel_count(buffer_r, dev->width_in_pixels); /* pixel count */
set_WD_line_count(buffer_r, dev->length_in_pixels); /* line count */
set_WD_x_coordinate_base(buffer_r, dev->x_coordinate_base); /* dpi (1200) */
set_WD_y_coordinate_base(buffer_r, dev->y_coordinate_base); /* dpi (1200) */
set_WD_calibration_data_lines(buffer_r, dev->calib_lines); /* required lines for calibration by driver */
switch(dev->colormode)
{
case LINEART: /* LINEART */
set_WD_composition(buffer_r, WD_comp_lineart);
set_WD_bitsperpixel(buffer_r, WD_bits_1);
set_WD_select_color(buffer_r, WD_color_gray);
break;
case HALFTONE: /* HALFTONE */
set_WD_composition(buffer_r, WD_comp_dithered);
set_WD_bitsperpixel(buffer_r, WD_bits_1);
set_WD_select_color(buffer_r, WD_color_gray);
break;
case GRAYSCALE: /* GRAYSCALE */
set_WD_composition(buffer_r, WD_comp_gray);
set_WD_bitsperpixel(buffer_r, dev->bits_per_pixel);
set_WD_select_color(buffer_r, WD_color_gray);
break;
case RGB_LINEART: /* COLOR MODES */
case RGB_HALFTONE:
case RGB:
if (dev->colormode == RGB_LINEART )
{
set_WD_composition(buffer_r, WD_comp_rgb_bilevel);
set_WD_bitsperpixel(buffer_r, WD_bits_1);
}
else if (dev->colormode == RGB_HALFTONE )
{
set_WD_composition(buffer_r, WD_comp_rgb_dithered);
set_WD_bitsperpixel(buffer_r, WD_bits_1);
}
else /* RGB */
{
set_WD_composition(buffer_r, WD_comp_rgb_full);
set_WD_bitsperpixel(buffer_r, dev->bits_per_pixel);
}
if (dev->three_pass == 0)
{ /* singlepass */
num_dblocks = 3;
if (dev->do_color_ordering != 0)
{
set_WD_line_arrangement(buffer_r, WD_line_arrengement_by_driver);
if (dev->CCD_distance == 0)
{
set_WD_color_ordering(buffer_r, WD_color_ordering_line_no_ccd);
}
else
{
set_WD_color_ordering(buffer_r, WD_color_ordering_line_w_ccd);
}
}
memcpy(buffer_g, buffer_r, max_WDB_size); /* copy WDB for green */
memcpy(buffer_b, buffer_r, max_WDB_size); /* copy WDB for blue */
set_WD_wid(buffer_r, WD_wid_red); /* window identifier red */
set_WD_wid(buffer_g, WD_wid_green); /* window identifier green */
set_WD_wid(buffer_b, WD_wid_blue); /* window identifier blue */
set_WD_select_color(buffer_r, WD_color_red); /* select red for this window */
set_WD_select_color(buffer_g, WD_color_green); /* select green for this window */
set_WD_select_color(buffer_b, WD_color_blue); /* select blue for this window */
set_WD_gamma(buffer_r, dev->digital_gamma_r); /* digital gamma */
set_WD_gamma(buffer_g, dev->digital_gamma_g);
set_WD_gamma(buffer_b, dev->digital_gamma_b);
set_WD_analog_gamma(buffer_r, dev->analog_gamma_r); /* analog gamma */
set_WD_analog_gamma(buffer_g, dev->analog_gamma_g);
set_WD_analog_gamma(buffer_b, dev->analog_gamma_b);
/* set highlight in dependence of analog gamma */
set_WD_highlight(buffer_r, umax_correct_light(dev->highlight_r, dev->analog_gamma_r));
set_WD_highlight(buffer_g, umax_correct_light(dev->highlight_g, dev->analog_gamma_g));
set_WD_highlight(buffer_b, umax_correct_light(dev->highlight_b, dev->analog_gamma_b));
/* set shadow in dependence of analog gamma */
set_WD_shadow(buffer_r, umax_correct_light(dev->shadow_r, dev->analog_gamma_r));
set_WD_shadow(buffer_g, umax_correct_light(dev->shadow_g, dev->analog_gamma_g));
set_WD_shadow(buffer_b, umax_correct_light(dev->shadow_b, dev->analog_gamma_b));
set_WD_scan_exposure_level(buffer_r, dev->exposure_time_scan_r); /* set scan exposure times */
set_WD_scan_exposure_level(buffer_g, dev->exposure_time_scan_g);
set_WD_scan_exposure_level(buffer_b, dev->exposure_time_scan_b);
set_WD_calibration_exposure_level(buffer_r, dev->exposure_time_calibration_r);/* set calib exp times */
set_WD_calibration_exposure_level(buffer_g, dev->exposure_time_calibration_g);
set_WD_calibration_exposure_level(buffer_b, dev->exposure_time_calibration_b);
}
else
{ /* threepass */
set_WD_wid(buffer_r, 0); /* window identifier */
set_WD_color_ordering(buffer_r, WD_color_ordering_plane); /* ???? */
if (dev->colormode == RGB_LINEART )
{
set_WD_composition(buffer_r, WD_comp_lineart); /* color-lineart-mode */
}
else if (dev->colormode == RGB_HALFTONE )
{
set_WD_composition(buffer_r, WD_comp_dithered); /* color-halftone-mode */
}
else /* RGB */
{
set_WD_composition(buffer_r, WD_comp_gray); /* color-mode */
}
switch (dev->three_pass_color)
{
case WD_wid_red:
set_WD_select_color(buffer_r, WD_color_red); /* color red */
set_WD_gamma(buffer_r, dev->digital_gamma_r);
set_WD_analog_gamma(buffer_r, dev->analog_gamma_r);
set_WD_highlight(buffer_r, umax_correct_light(dev->highlight_r, dev->analog_gamma_r));
set_WD_shadow(buffer_r, umax_correct_light(dev->shadow_r, dev->analog_gamma_r));
set_WD_scan_exposure_level(buffer_r, dev->exposure_time_scan_r);
set_WD_calibration_exposure_level(buffer_r, dev->exposure_time_calibration_r);
break;
case WD_wid_green:
set_WD_select_color(buffer_r, WD_color_green); /* color green */
set_WD_gamma(buffer_r, dev->digital_gamma_g);
set_WD_analog_gamma(buffer_r, dev->analog_gamma_g);
set_WD_highlight(buffer_r, umax_correct_light(dev->highlight_g, dev->analog_gamma_g));
set_WD_shadow(buffer_r, umax_correct_light(dev->shadow_g, dev->analog_gamma_g));
set_WD_scan_exposure_level(buffer_r, dev->exposure_time_scan_g);
set_WD_calibration_exposure_level(buffer_r, dev->exposure_time_calibration_g);
break;
case WD_wid_blue:
set_WD_select_color(buffer_r, WD_color_blue); /* color blue */
set_WD_gamma(buffer_r, dev->digital_gamma_b);
set_WD_analog_gamma(buffer_r, dev->analog_gamma_b);
set_WD_highlight(buffer_r, umax_correct_light(dev->highlight_b, dev->analog_gamma_b));
set_WD_shadow(buffer_r, umax_correct_light(dev->shadow_b, dev->analog_gamma_b));
set_WD_scan_exposure_level(buffer_r, dev->exposure_time_scan_b);
set_WD_calibration_exposure_level(buffer_r, dev->exposure_time_calibration_b);
break;
} /* switch dev->three_pass_color */
} /* if (single_pass) else (three_pass) */
break;
} /* switch dev->colormode, case RGB */
/* prepare SCSI-BUFFER */
memcpy(dev->buffer[0], set_window.cmd, set_window.size); /* SET-WINDOW cmd */
memcpy(WPDB_OFF(dev->buffer[0]), window_parameter_data_block.cmd, window_parameter_data_block.size); /* WPDB */
set_WPDB_wdbnum(WPDB_OFF(dev->buffer[0]), num_dblocks); /* set WD_len */
memcpy(WDB_OFF(dev->buffer[0],1), buffer_r, window_descriptor_block.size); /* add WD_block */
if ( num_dblocks == 3) /* if singelpass RGB */
{
memcpy(WDB_OFF(dev->buffer[0],2), buffer_g, window_descriptor_block.size); /* add green */
memcpy(WDB_OFF(dev->buffer[0],3), buffer_b, window_descriptor_block.size); /* add blue */
}
DBG(DBG_info2, "window descriptor block created with %d bytes\n", dev->wdb_len);
set_SW_xferlen(dev->buffer[0], (window_parameter_data_block.size + (window_descriptor_block.size * num_dblocks)));
status = umax_scsi_cmd(dev, dev->buffer[0], set_window.size + window_parameter_data_block.size +
(window_descriptor_block.size * num_dblocks), NULL, NULL);
if (status)
{
DBG(DBG_error, "umax_set_window_param: command returned status %s\n", sane_strstatus(status));
}
else
{
DBG(DBG_info, "window(s) set\n");
}
return status;
}
/* ------------------------------------------------------------ UMAX DO INQUIRY ---------------------------- */
static void umax_do_inquiry(Umax_Device *dev)
{
size_t size;
SANE_Status status;
DBG(DBG_proc,"do_inquiry\n");
memset(dev->buffer[0], '\0', 256); /* clear buffer */
size = 5;
set_inquiry_return_size(inquiry.cmd, size); /* first get only 5 bytes to get size of inquiry_return_block */
status = umax_scsi_cmd(dev, inquiry.cmd, inquiry.size, dev->buffer[0], &size);
if (status)
{
DBG(DBG_error, "umax_do_inquiry: command returned status %s\n", sane_strstatus(status));
}
size = get_inquiry_additional_length(dev->buffer[0]) + 5;
set_inquiry_return_size(inquiry.cmd, size); /* then get inquiry with actual size */
status = umax_scsi_cmd(dev, inquiry.cmd, inquiry.size, dev->buffer[0], &size);
if (status)
{
DBG(DBG_error, "umax_do_inquiry: command returned status %s\n", sane_strstatus(status));
}
}
/* ------------------------------------------------------------ UMAX START SCAN ---------------------------- */
static SANE_Status umax_start_scan(Umax_Device *dev)
{
int size = 1;
SANE_Status status;
DBG(DBG_proc,"start_scan\n");
if (dev->adf) /* ADF selected: test for ADF errors */
{
umax_do_inquiry(dev); /* get inquiry */
if (get_inquiry_ADF_paper_jam(dev->buffer[0])) /* test for ADF paper jam */
{
DBG(DBG_error,"ERROR: umax_start_scan: ADF paper jam\n");
return SANE_STATUS_JAMMED;
}
else if (get_inquiry_ADF_cover_open(dev->buffer[0])) /* test for ADF cover open */
{
DBG(DBG_error,"ERROR: umax_start_scan: ADF cover open\n");
return SANE_STATUS_COVER_OPEN;
}
else if (get_inquiry_ADF_no_paper(dev->buffer[0])) /* test for ADF no paper */
{
DBG(DBG_error,"ERROR: umax_start_scan: ADF no paper\n");
return SANE_STATUS_NO_DOCS;
}
}
set_SC_quality(scan.cmd, dev->quality); /* 1=qual, 0=fast */
set_SC_adf( scan.cmd, dev->adf); /* ADF, 0=off, 1=use */
set_SC_preview(scan.cmd, dev->preview); /* 1=preview */
set_SC_wid(scan.cmd, 1, 0); /* Window-Identifier */
set_SC_xfer_length(scan.cmd, size); /* following Bytes */
DBG(DBG_info,"starting scan\n");
status = umax_scsi_cmd(dev, scan.cmd, scan.size + size, NULL, NULL);
if (status)
{
DBG(DBG_error, "umax_start_scan: command returned status %s\n", sane_strstatus(status));
}
return status;
}
/* ------------------------------------------------------------ UMAX DO CALIBRATION ------------------------ */
static SANE_Status umax_do_calibration(Umax_Device *dev)
{
SANE_Status status;
unsigned int width = 0;
unsigned int lines = 0;
unsigned int bytespp = 0;
DBG(DBG_proc,"do_calibration\n");
status = umax_wait_scanner(dev);
if ((status == SANE_STATUS_GOOD) && (dev->do_calibration != 0)) /* calibration by driver */
{
unsigned char *shading_data = 0;
unsigned int i, j;
long *average;
DBG(DBG_info,"driver is doing calibration\n");
if (umax_execute_request_sense)
{
DBG(DBG_info,"request sense call is enabled\n");
memset(dev->buffer[0], 0, rs_return_block_size); /* clear sense data buffer */
umax_do_request_sense(dev); /* new request-sense call to get all data */
}
else
{
DBG(DBG_info,"request sense call is disabled\n");
}
if (get_RS_SCC_condition_code(dev->buffer[0]) != 1)
{
DBG(DBG_warning,"WARNING: missing information about shading-data\n");
DBG(DBG_warning," driver tries to guess missing values!\n");
if ((dev->calibration_area != UMAX_CALIBRATION_AREA_CCD) && (!dev->batch_scan))
/* calibration is done with image geometry and depth */
{
DBG(DBG_warning," Calibration is done with selected image geometry and depth!\n");
width = dev->scanwidth * dev->relevant_optical_res / dev->x_coordinate_base;
if (dev->calibration_width_offset > -99999) /* driver or user (umax.conf) define an offset */
{
width = width + dev->calibration_width_offset;
DBG(DBG_warning," Using calibration width offset of %d\n", dev->calibration_width_offset);
}
if (dev->colormode == RGB)
{
width = width * 3;
}
lines = dev->calib_lines;
if (dev->gamma_input_bits_code <= 1)
{
bytespp = 1; /* 8 bit mode */
}
else
{
bytespp = 2; /* 16 bit mode */
}
}
else /* calibration is done with full scanarea and full depth */
{
DBG(DBG_warning," Calibration is done for each CCD pixel with full depth!\n");
width = (int)(dev->inquiry_fb_width * dev->inquiry_optical_res);
if (dev->batch_scan)
{
if (dev->calibration_width_offset_batch > -99999) /* driver or user (umax.conf) define an offset for batch scanning */
{
width = width + dev->calibration_width_offset_batch;
DBG(DBG_warning," Using calibration width offset for batch scanning of %d\n", dev->calibration_width_offset_batch);
}
}
else /* normal scan */
{
if (dev->calibration_width_offset > -99999) /* driver or user (umax.conf) define an offset */
{
width = width + dev->calibration_width_offset;
DBG(DBG_warning," Using calibration width offset of %d\n", dev->calibration_width_offset);
}
}
if (dev->colormode == RGB)
{
width = width * 3;
}
lines = dev->calib_lines;
if (dev->gamma_input_bits_code <= 1)
{
bytespp = 1; /* 8 bit mode */
}
else
{
bytespp = 2; /* 16 bit mode */
}
}
}
else
{
lines = get_RS_SCC_calibration_lines(dev->buffer[0]);
bytespp = get_RS_SCC_calibration_bytespp(dev->buffer[0]);
width = get_RS_SCC_calibration_bytesperline(dev->buffer[0]) / bytespp;
}
if (dev->calibration_bytespp > 0) /* correct bytespp if necessary and driver knows about it or user did select it */
{
bytespp = dev->calibration_bytespp;
}
DBG(DBG_info,"scanner sends %d lines with %d pixels and %d bytes/pixel\n", lines, width, bytespp);
if (width * bytespp > dev->bufsize)
{
DBG(DBG_error,"ERROR: scsi buffer is to small for one shading line, calibration aborted\n");
DBG(DBG_error,"=> change umax.conf options scsi-buffer-size-min and scsi-buffer-size-max\n");
return SANE_STATUS_NO_MEM;
}
/* UMAX S12 sends a kind of uncalibrated image data, bright -> 255, dark -> 0 */
/* (although 0 is not black) my scanner sends values around 220 */
/* for some scanners the data is simply sent back, other scanners want 255-value as awnswer */
average = calloc(width, sizeof(long));
if (average == 0)
{
DBG(DBG_error,"ERROR: could not allocate memory for averaging shading data: calibration aborted\n");
return SANE_STATUS_NO_MEM;
}
shading_data = calloc(width, bytespp);
if (shading_data == 0)
{
DBG(DBG_error,"ERROR: could not allocate memory for shading data: calibration aborted\n");
return SANE_STATUS_NO_MEM;
}
if (bytespp == 1) /* 1 byte per pixel */
{
DBG(DBG_info,"calculating average value for 8 bit shading data!\n");
for (i=0; i<lines; i++)
{
umax_read_shading_data(dev, width * bytespp);
for (j=0; j<width; j++)
{
average[j] += (long) dev->buffer[0][j];
}
DBG(DBG_read,"8 bit shading-line %d read\n", i+1);
}
for (j=0; j<width; j++)
{
shading_data[j] = (unsigned char) (average[j] / lines);
}
}
else if (dev->low_byte_first) /* 2 bytes per pixel with low byte first */
{
DBG(DBG_info,"calculating average value for 16 bit shading data (low byte first)!\n");
for (i=0; i<lines; i++)
{
umax_read_shading_data(dev, width * bytespp);
for (j=0; j<width; j++)
{
average[j] += (long) 256 * dev->buffer[0][2*j+1] + dev->buffer[0][2*j] ;
}
DBG(DBG_read,"16 bit shading-line %d read\n", i+1);
}
for (j=0; j<width; j++)
{
shading_data[2*j+1] = (unsigned char) (average[j] / (256 * lines));
shading_data[2*j] = (unsigned char) (average[j] / lines);
}
}
else /* 2 bytes per pixel with highbyte first */
{
DBG(DBG_info,"calculating average value for 16 bit shading data (high byte first)!\n");
for (i=0; i<lines; i++)
{
umax_read_shading_data(dev, width * bytespp);
for (j=0; j<width; j++)
{
average[j] += (long) 256 * dev->buffer[0][2*j] + dev->buffer[0][2*j + 1] ;
}
DBG(DBG_read,"16 bit shading-line %d read\n", i+1);
}
for (j=0; j<width; j++)
{
shading_data[2*j] = (unsigned char) (average[j] / (256 * lines));
shading_data[2*j+1] = (unsigned char) (average[j] / lines);
}
}
free(average);
if ( (dev->invert_shading_data) ) /* invert data */
{
if (bytespp == 1)
{
DBG(DBG_info,"inverting 8 bit shading data\n");
for (j=0; j<width; j++)
{
shading_data[j] = 255 - shading_data[j];
}
}
else
{
unsigned int value;
DBG(DBG_info,"inverting 16 bit shading data\n");
for (j=0; j<width; j++)
{
value = shading_data[2*j] + shading_data[2*j+1] * 256;
value = 65535 - value;
shading_data[2*j] = (unsigned char) value/256;
shading_data[2*j+1] = (unsigned char) value & 255;
}
}
}
umax_send_shading_data(dev, shading_data, width * bytespp);
DBG(DBG_info,"shading-data sent\n");
free(shading_data);
status = umax_start_scan(dev); /* now start real scan */
dev->do_calibration = 0;
}
return status;
}
/* ------------------------------------------------------------ UMAX DO NEW INQUIRY ------------------------ */
static void umax_do_new_inquiry(Umax_Device *dev, size_t size) /* call inquiry again if wrong length */
{
SANE_Status status;
DBG(DBG_proc,"do_new_inquiry\n");
memset(dev->buffer[0], '\0', 256); /* clear buffer */
set_inquiry_return_size(inquiry.cmd, size);
status = umax_scsi_cmd(dev, inquiry.cmd, inquiry.size, dev->buffer[0], &size);
if (status)
{
DBG(DBG_error, "umax_do_new_inquiry: command returned status %s\n", sane_strstatus(status));
}
}
/* ------------------------------------------------------------ UMAX CORRECT INQUIRY ----------------------- */
static void umax_correct_inquiry(Umax_Device *dev, char *vendor, char *product, char *version)
{
DBG(DBG_info, "umax_correct_inquiry(\"%s %s %s\")\n", vendor, product, version);
if (!strncmp(vendor, "UMAX ", 5))
{
if (!strncmp(product, "Astra 600S ", 11))
{
int add_len = get_inquiry_additional_length(dev->buffer[0]);
DBG(DBG_warning,"setting up special options for %s\n", product);
if (add_len == 0x8f)
{
DBG(DBG_warning," - correcting wrong inquiry data\n");
umax_do_new_inquiry(dev, 0x9b); /* get inquiry with correct length */
set_inquiry_length(dev->buffer[0], 0x9e); /* correct inquiry len */
/* correct color-ordering from pixel to line_with_ccd_distance */
set_inquiry_color_order(dev->buffer[0], IN_color_ordering_line_w_ccd);
set_inquiry_fb_uta_line_arrangement_mode(dev->buffer[0], 32);
set_inquiry_CCD_line_distance(dev->buffer[0], 8);
/* we should reset ADF-bit here too */
if (dev->invert_shading_data == -1) /* nothing defined in umax.conf */
{
DBG(DBG_warning," - activating inversion of shading data\n");
dev->invert_shading_data = 1;
}
}
}
else if (!strncmp(product, "Astra 610S ", 11))
{
int add_len = get_inquiry_additional_length(dev->buffer[0]);
DBG(DBG_warning,"setting up special options for %s\n", product);
if (add_len == 0x8f)
{
DBG(DBG_warning," - correcting wrong inquiry data\n");
umax_do_new_inquiry(dev, 0x9b); /* get inquiry with correct length */
set_inquiry_length(dev->buffer[0], 0x9e); /* correct inquiry len */
/* correct color-ordering from pixel to line_with_ccd_distance */
set_inquiry_color_order(dev->buffer[0], IN_color_ordering_line_w_ccd);
set_inquiry_fb_uta_line_arrangement_mode(dev->buffer[0], 33);
set_inquiry_CCD_line_distance(dev->buffer[0], 8);
if (dev->invert_shading_data == -1) /* nothing defined in umax.conf */
{
DBG(DBG_warning," - activating inversion of shading data\n");
dev->invert_shading_data = 1;
}
}
}
else if ( (!strncmp(product, "Astra 1200S ", 12)) ||
(!strncmp(product, "Perfection600 ", 14)) )
{
DBG(DBG_warning,"using standard options for %s\n", product);
}
else if (!strncmp(product, "Astra 1220S ", 12))
{
DBG(DBG_warning,"setting up special options for %s\n", product);
if (dev->gamma_lsb_padded == -1) /* nothing defined in umax.conf and not by backend */
{
DBG(DBG_warning," - 16 bit gamma table is created lsb padded\n");
dev->gamma_lsb_padded = 1;
}
if (!strncmp(version, "V1.5 ", 4))
{
DBG(DBG_warning," - lamp control enabled for version %s\n", version);
dev->lamp_control_available = 1;
}
}
else if (!strncmp(product, "Astra 2100S ", 12))
{
DBG(DBG_warning,"setting up special options for %s\n", product);
DBG(DBG_warning," - lamp control enabled\n");
dev->lamp_control_available = 1;
if (dev->calibration_bytespp == -1) /* no calibration-bytespp defined in umax.conf */
{
DBG(DBG_warning," - setting calibration_bytespp = 1\n");
dev->calibration_bytespp = 1; /* scanner says 2 bytespp for calibration but 1 bytepp is correct */
}
}
else if (!strncmp(product, "Astra 2200 ", 11))
{
DBG(DBG_warning,"setting up special options for %s\n", product);
DBG(DBG_warning," - lamp control enabled\n");
dev->lamp_control_available = 1;
if (dev->calibration_area == -1) /* no calibration area defined in umax.conf */
{
DBG(DBG_warning," - calibration by driver is done for each CCD pixel\n");
dev->calibration_area = UMAX_CALIBRATION_AREA_CCD;
}
if (dev->calibration_bytespp == -1) /* no calibration-bytespp defined in umax.conf */
{
DBG(DBG_warning," - setting calibration_bytespp = 2\n");
dev->calibration_bytespp = 2;
}
DBG(DBG_warning," - common x and y resolution\n");
dev->common_xy_resolutions = 1;
if (dev->connection_type == SANE_UMAX_USB)
{
DBG(DBG_warning," - disabling quality calibration for USB connection\n");
set_inquiry_fw_quality(dev->buffer[0], 0);
}
}
else if (!strncmp(product, "Astra 2400S ", 12))
{
DBG(DBG_warning,"setting up special options for %s\n", product);
DBG(DBG_warning," - defining pauses\n");
dev->pause_for_color_calibration = 7000; /* pause between start_scan and do_calibration in ms */
dev->pause_for_gray_calibration = 4000; /* pause between start_scan and do_calibration in ms */
dev->pause_after_calibration = 0000; /* pause between do_calibration and read data in ms */
dev->pause_after_reposition = 3000; /* pause after repostion scanner in ms */
dev->pause_for_moving = 3000; /* pause for moving scanhead over full area */
DBG(DBG_warning," - correcting ADF bit in inquiry\n");
set_inquiry_sc_adf(dev->buffer[0], 1); /* set second bit that indicates ADF is supported */
}
else if (!strncmp(product, "Vista-T630 ", 11))
{
DBG(DBG_warning,"setting up special options for %s\n", product);
if (dev->slow == -1) /* option is not predefined in umax.conf */
{
DBG(DBG_warning," - activating slow option\n");
dev->slow = 1;
}
}
else if (!strncmp(product, "UC630 ", 6))
{
DBG(DBG_warning,"setting up special options for %s\n", product);
DBG(DBG_warning," - reposition_scanner waits until move of scan head has finished\n");
dev->pause_after_reposition = 0; /* call wait_scanner */
}
else if (!strncmp(product, "UC840 ", 6))
{
DBG(DBG_warning,"setting up special options for %s\n", product);
DBG(DBG_warning," - reposition_scanner waits until move of scan head has finished\n");
dev->pause_after_reposition = 0; /* call wait_scanner */
}
else if (!strncmp(product, "UC1260 ", 7))
{
DBG(DBG_warning,"setting up special options for %s\n", product);
DBG(DBG_warning," - setting gamma download curve format to type 1\n");
dev->inquiry_gamma_DCF = 1; /* define gamma download curve format */
DBG(DBG_warning," - reposition_scanner waits until move of scan head has finished\n");
dev->pause_after_reposition = 0; /* call wait_scanner */
}
else if (!strncmp(product, "UC1200S ", 8))
{
DBG(DBG_warning,"setting up special options for %s\n", product);
DBG(DBG_warning," - setting gamma download curve format to type 1\n");
dev->inquiry_gamma_DCF = 1; /* define gamma download curve format */
}
else if (!strncmp(product, "UC1200SE ", 9))
{
DBG(DBG_warning,"setting up special options for %s\n", product);
DBG(DBG_warning," - setting gamma download curve format to type 0\n");
dev->inquiry_gamma_DCF = 0; /* define gamma download curve format */
}
else if (!strncmp(product, "ARCUS PLUS ", 11))
{
DBG(DBG_warning,"setting up special options for %s\n", product);
DBG(DBG_warning," - setting gamma download curve format to type 0\n");
dev->inquiry_gamma_DCF = 0; /* define gamma download curve format */
}
else if ( (!strncmp(product, "UMAX S-12G ", 11)) ||
(!strncmp(product, "UMAX S-12 ", 10)) ||
(!strncmp(product, "SuperVista S-12 ", 16)) )
{
DBG(DBG_warning,"setting up special options for %s\n", product);
DBG(DBG_warning," - setting maximum calibration data lines to 66\n");
set_inquiry_max_calibration_data_lines(dev->buffer[0], 66);
if (dev->calibration_width_offset == -99999) /* no calibration-width-offset defined in umax.conf */
{
dev->calibration_width_offset = -1;
DBG(DBG_warning," - adding calibration width offset of %d pixels\n", dev->calibration_width_offset);
}
if (dev->calibration_area == -1) /* no calibration area defined in umax.conf */
{
DBG(DBG_warning," - calibration by driver is done for each CCD pixel\n");
dev->calibration_area = UMAX_CALIBRATION_AREA_CCD;
}
}
else if (!strncmp(product, "Mirage D-16L ", 13))
{
DBG(DBG_warning,"setting up special options for %s\n", product);
if (dev->calibration_area == -1) /* no calibration area defined in umax.conf */
{
DBG(DBG_warning," - calibration by driver is done for each CCD pixel\n");
dev->calibration_area = UMAX_CALIBRATION_AREA_CCD;
}
if (dev->calibration_width_offset == -99999) /* no calibration-width-offset defined in umax.conf */
{
dev->calibration_width_offset = 308;
DBG(DBG_warning," - adding calibration width offset of %d pixels\n", dev->calibration_width_offset);
}
}
else if (!strncmp(product, "PowerLook III ", 14))
{
DBG(DBG_warning,"setting up special options for %s\n", product);
if (dev->calibration_width_offset == -99999) /* no calibration-width-offset defined in umax.conf */
{
dev->calibration_width_offset = 28;
DBG(DBG_warning," - adding calibration width offset of %d pixels\n", dev->calibration_width_offset);
}
/* calibration_area = image */
if (dev->calibration_width_offset_batch == -99999) /* no calibration-width-offset for batch scanning defined in umax.conf */
{
dev->calibration_width_offset_batch = 828;
DBG(DBG_warning," - adding calibration width offset for batch scanning of %d pixels\n", dev->calibration_width_offset_batch);
}
}
else if (!strncmp(product, "Power Look 2000", 15))
{
DBG(DBG_warning,"setting up special options for %s\n", product);
if (dev->calibration_width_offset == -99999) /* no calibration-width-offset defined in umax.conf */
{
dev->calibration_width_offset = 22;
DBG(DBG_warning," - adding calibration width offset of %d pixels\n", dev->calibration_width_offset);
}
/* calibration_area = image */
if (dev->calibration_width_offset_batch == -99999) /* no calibration-width-offset for batch scanning defined in umax.conf */
{
dev->calibration_width_offset_batch = 24;
DBG(DBG_warning," - adding calibration width offset for batch scanning of %d pixels\n", dev->calibration_width_offset_batch);
}
}
else if (!strncmp(product, "PowerLook 2100XL", 16))
{
DBG(DBG_warning,"setting up special options for %s\n", product);
if (dev->calibration_width_offset == -99999) /* no calibration-width-offset defined in umax.conf */
{
dev->calibration_width_offset = 52;
DBG(DBG_warning," - adding calibration width offset of %d pixels\n", dev->calibration_width_offset);
}
/* calibration_area = image */
if (dev->calibration_width_offset_batch == -99999) /* no calibration-width-offset for batch scanning defined in umax.conf */
{
dev->calibration_width_offset_batch = 1052;
DBG(DBG_warning," - adding calibration width offset for batch scanning of %d pixels\n", dev->calibration_width_offset_batch);
}
dev->force_quality_calibration = 1;
DBG(DBG_warning," - always set quality calibration\n");
/* the scanner uses the same exposure times for red, green and blue exposure_time_rgb_bind = 1 */
}
else if (!strncmp(product, "PowerLook 3000 ", 15))
{
DBG(DBG_warning,"setting up special options for %s\n", product);
if (dev->calibration_width_offset == -99999) /* no calibration-width-offset defined in umax.conf */
{
dev->calibration_width_offset = 52;
DBG(DBG_warning," - adding calibration width offset of %d pixels\n", dev->calibration_width_offset);
}
/* calibration_area = image */
if (dev->calibration_width_offset_batch == -99999) /* no calibration-width-offset for batch scanning defined in umax.conf */
{
/* not tested */
dev->calibration_width_offset_batch = 1052;
DBG(DBG_warning," - adding calibration width offset for batch scanning of %d pixels\n", dev->calibration_width_offset_batch);
}
}
else
{
DBG(DBG_warning,"using standard options for %s\n", product);
}
}
else if (!strncmp(vendor, "LinoHell ", 9))
{
if ( (!strncmp(product, "Office ", 7)) || (!strncmp(product, "JADE ", 5)) ) /* is a Supervista S-12 */
{
DBG(DBG_warning,"setting up special options for %s\n", product);
DBG(DBG_warning," - setting maximum calibration data lines to 66\n");
set_inquiry_max_calibration_data_lines(dev->buffer[0], 66);
if (dev->calibration_width_offset == -99999) /* no calibration-width-offset defined in umax.conf */
{
dev->calibration_width_offset = -1;
DBG(DBG_warning," - adding calibration width offset of %d pixels\n", dev->calibration_width_offset);
}
if (dev->calibration_area == -1) /* no calibration area defined in umax.conf */
{
DBG(DBG_warning," - calibration by driver is done for each CCD pixel\n");
dev->calibration_area = UMAX_CALIBRATION_AREA_CCD;
}
}
else if (!strncmp(product, "OPAL2 ", 6)) /* looks like a Mirage II */
{
DBG(DBG_warning,"setting up special options for %s\n", product);
if (dev->gamma_lsb_padded == -1) /* nothing defined in umax.conf and not by backend */
{
DBG(DBG_warning," - 16 bit gamma table is created lsb padded\n");
dev->gamma_lsb_padded = 1;
}
}
}
else if (!strncmp(vendor, "Linotype ", 9))
{
if (!strncmp(product, "SAPHIR4 ", 8)) /* is a Powerlook III */
{
DBG(DBG_warning,"setting up special options for %s\n", product);
if (dev->calibration_width_offset == -99999) /* no calibration-width-offset defined in umax.conf */
{
dev->calibration_width_offset = 28;
DBG(DBG_warning," - adding calibration width offset of %d pixels\n", dev->calibration_width_offset);
}
/* calibration_area = image */
if (dev->calibration_width_offset_batch == -99999) /* no calibration-width-offset for batch scanning defined in umax.conf */
{
dev->calibration_width_offset_batch = 828;
DBG(DBG_warning," - adding calibration width offset for batch scanning of %d pixels\n", dev->calibration_width_offset_batch);
}
}
}
else if (!strncmp(vendor, "HDM ", 4))
{
if (!strncmp(product, "LS4H1S ", 7)) /* is a Powerlook III */
{
DBG(DBG_warning,"setting up special options for %s\n", product);
if (dev->calibration_width_offset == -99999) /* no calibration-width-offset defined in umax.conf */
{
dev->calibration_width_offset = 28;
DBG(DBG_warning," - adding calibration width offset of %d pixels\n", dev->calibration_width_offset);
}
/* calibration_area = image */
if (dev->calibration_width_offset_batch == -99999) /* no calibration-width-offset for batch scanning defined in umax.conf */
{
dev->calibration_width_offset_batch = 828;
DBG(DBG_warning," - adding calibration width offset for batch scanning of %d pixels\n", dev->calibration_width_offset_batch);
}
}
}
else if (!strncmp(vendor, "ESCORT ", 7))
{
if (!strncmp(product, "Galleria 600S ", 14)) /* this is an Astra 600S */
{
int add_len = get_inquiry_additional_length(dev->buffer[0]);
DBG(DBG_warning,"setting up special options for %s\n", product);
if (add_len == 0x8f)
{
DBG(DBG_warning," - correcting wrong inquiry data\n");
umax_do_new_inquiry(dev, 0x9b); /* get inquiry with correct length */
set_inquiry_length(dev->buffer[0], 0x9e); /* correct inquiry len */
/* correct color-ordering from pixel to line_with_ccd_distance */
set_inquiry_color_order(dev->buffer[0], IN_color_ordering_line_w_ccd);
set_inquiry_fb_uta_line_arrangement_mode(dev->buffer[0], 32);
set_inquiry_CCD_line_distance(dev->buffer[0], 8);
/* we should reset ADF-bit here too */
if (dev->invert_shading_data == -1) /* nothing defined in umax.conf */
{
DBG(DBG_warning," - activating inversion of shading data\n");
dev->invert_shading_data = 1;
}
}
}
}
else if (!strncmp(vendor, "TriGem ", 7))
{
if (!strncmp(product, "PowerScanII ", 12)) /* is a Supervista S-12 */
{
DBG(DBG_warning,"setting up special options for %s\n", product);
DBG(DBG_warning," - setting maximum calibration data lines to 66\n");
set_inquiry_max_calibration_data_lines(dev->buffer[0], 66);
if (dev->calibration_width_offset == -99999) /* no calibration-width-offset defined in umax.conf */
{
dev->calibration_width_offset = -1;
DBG(DBG_warning," - adding calibration width offset of %d pixels\n", dev->calibration_width_offset);
}
if (dev->calibration_area == -1) /* no calibration area defined in umax.conf */
{
DBG(DBG_warning," - calibration by driver is done for each CCD pixel\n");
dev->calibration_area = UMAX_CALIBRATION_AREA_CCD;
}
}
}
}
/* ------------------------------------------------------------ UMAX IDENTIFY SCANNER ---------------------- */
static int umax_identify_scanner(Umax_Device *dev)
{
char vendor[10];
char product[0x12];
char version[6];
char *pp;
DBG(DBG_proc,"identify_scanner\n");
umax_do_inquiry(dev); /* get inquiry */
if (get_inquiry_periph_devtype(dev->buffer[0]) != IN_periph_devtype_scanner) { return 1; } /* no scanner */
get_inquiry_vendor( (char *)dev->buffer[0], vendor); vendor[8] = ' '; vendor[9] = '\0';
get_inquiry_product((char *)dev->buffer[0], product); product[16] = ' '; product[17] = '\0';
get_inquiry_version((char *)dev->buffer[0], version); version[4] = ' '; version[5] = '\0';
pp = &vendor[8];
while (*(pp-1) == ' ')
{
*pp-- = '\0';
}
pp = &product[0x10];
while (*(pp-1) == ' ')
{
*pp-- = '\0';
}
pp = &version[4];
while (*pp == ' ')
{
*pp-- = '\0';
}
DBG(DBG_info, "Found %s scanner %sversion %s on device %s\n", vendor, product, version, dev->devicename);
/* look for scanners that do not give all inquiry-information */
/* and if possible use driver-known inquiry-data */
if (get_inquiry_additional_length(dev->buffer[0])>=0x8f)
{
int i = 0;
while (strncmp("END_OF_LIST", scanner_str[2*i], 11) != 0) /* Now identify full supported scanners */
{
if (!strncmp(vendor, scanner_str[2*i], strlen(scanner_str[2*i])) )
{
if (!strncmp(product, scanner_str[2*i+1], strlen(scanner_str[2*i+1])) )
{
umax_correct_inquiry(dev, vendor, product, version);
return 0;
}
}
i++;
}
if (strncmp(vendor, "UMAX ", 5)) { return 1; } /* not UMAX then abort */
DBG(DBG_error0, "WARNING: %s scanner %s version %s on device %s\n"
"is currently an unrecognized device for this backend version.\n"
"Please make sure you use the most recent version of the umax backend.\n"
"You can download new umax-backend versions from:\n"
"http://www.rauch-domain.de/sane-umax\n",
vendor, product, version, dev->devicename);
DBG(DBG_error0,
"Inquiry seems to be ok.\n"
"******************************************************************\n"
"*** !!!! CONTINUE AT YOUR OWN RISK !!!! ***\n"
"******************************************************************\n"
"If you already use the most recent umax-backend version\n"
"then please contact me: Oliver.Rauch@rauch-domain.de\n");
return 0;
}
else /* inquiry-data not complete */
if (!strncmp(vendor, "UMAX ", 5)) /* test UMAX-scanners with short inquiry */
{
inquiry_blk inq_data;
int i;
for(i=0; i < known_inquiry; i++)
{
inq_data = *inquiry_table[i];
if (!strncmp(product, inq_data.scanner, strlen(inq_data.scanner)))
{
DBG(DBG_warning, "inquiry-block-length: %d\n", get_inquiry_additional_length(dev->buffer[0])+5);
DBG(DBG_warning, "using driver-internal inquiry-data for this scanner!\n");
/* copy driver-defined inquiry-data into inquiry-block */
memcpy(dev->buffer[0]+0x24, inq_data.inquiry, inq_data.inquiry_len-0x24);
/* correct variables */
set_inquiry_sc_uta(dev->buffer[0], get_inquiry_transavail(dev->buffer[0])); /* transparency available ? */
set_inquiry_sc_adf(dev->buffer[0], get_inquiry_scanmode(dev->buffer[0])); /* automatic document feeder available ? */
set_inquiry_length(dev->buffer[0], inq_data.inquiry_len);
umax_correct_inquiry(dev, vendor, product, version);
return 0; /* ok */
}
}
DBG(DBG_error0, "ERROR: %s scanner %s version %s on device %s\n"
"is currently an unrecognized device, and inquiry is too short,\n"
"so we are not able to continue!\n"
"Please make sure you use the most recent version of the umax backend.\n"
"You can download new umax-backend versions from:\n"
"http://www.rauch-domain.de/sane-umax\n"
"You already use the most recent umax-backend version:\n"
"Please contact me: Oliver.Rauch@rauch-domain.de\n",
vendor, product, version, dev->devicename);
}
return 1; /* NO SUPPORTED SCANNER: short inquiry-block and unknown scanner */
}
/* ------------------------------------------------------------ UMAX TRIM BUFSIZE -------------------------- */
static void umax_trim_rowbufsize(Umax_Device *dev)
{
unsigned int lines=0;
if (dev->row_bufsize > dev->row_len)
{
lines = dev->row_bufsize / dev->row_len;
if (lines > dev->lines_max) /* reduce number of lines to scan if set up in config file */
{
lines = dev->lines_max;
}
dev->row_bufsize = lines * dev->row_len;
}
DBG(DBG_proc,"trim_rowbufsize: row_bufsize = %d bytes = %d lines\n", dev->row_bufsize, lines);
}
/* ------------------------------------------------------------ UMAX CALCULATE EXPOSURE TIME --------------- */
static void umax_calculate_exposure_time(Umax_Device *dev, int def, int *value)
{
int level;
DBG(DBG_proc,"calculate_exposure_time\n");
if ( (*value))
{
if ( (*value) == -1 ) { (*value) = def; }
else
{
level = (*value) / dev->inquiry_exposure_time_step_unit;
(*value) = inrange(dev->use_exposure_time_min, level, dev->inquiry_exposure_time_max);
}
}
}
/* ------------------------------------------------------------ UMAX CHECK VALUES -------------------------- */
static int umax_check_values(Umax_Device *dev)
{
double inquiry_x_orig;
double inquiry_y_orig;
double inquiry_width;
double inquiry_length;
unsigned int maxwidth;
unsigned int maxlength;
DBG(DBG_proc,"check_values\n");
/* ------------------------------- flatbed ------------------------------- */
dev->module = WD_module_flatbed; /* reset scanmode to flatbed first */
/* --------------------------------- uta --------------------------------- */
if (dev->uta != 0)
{
dev->module = WD_module_transparency;
if ( (dev->inquiry_uta == 0) || (dev->inquiry_transavail == 0) )
{
DBG(DBG_error, "ERROR: transparency mode not supported by scanner\n");
return(1);
}
}
/* --------------------------------- adf --------------------------------- */
if (dev->adf != 0)
{
if (dev->inquiry_adf == 0)
{
DBG(DBG_error,"ERROR: adf mode not supported by scanner\n");
return(1);
}
}
/* --------------------------------- dor --------------------------------- */
if (dev->dor != 0)
{
if (dev->inquiry_dor == 0)
{
DBG(DBG_error, "ERROR: double optical resolution not supported by scanner\n");
return(1);
}
}
/* ------------------------------- resolution ------------------------ */
if (dev->dor == 0) /* standard (FB) */
{
dev->relevant_optical_res = dev->inquiry_optical_res;
dev->relevant_max_x_res = dev->inquiry_x_res;
dev->relevant_max_y_res = dev->inquiry_y_res;
}
else /* DOR mode */
{
dev->relevant_optical_res = dev->inquiry_dor_optical_res;
dev->relevant_max_x_res = dev->inquiry_dor_x_res;
dev->relevant_max_y_res = dev->inquiry_dor_y_res;
}
if (dev->x_resolution <= 0)
{
DBG(DBG_error,"ERROR: no x-resolution given\n");
return(1);
}
if (dev->x_resolution > dev->relevant_max_x_res)
{
dev->x_resolution = dev->relevant_max_x_res;
}
if (dev->x_resolution > dev->relevant_optical_res)
{
dev->scale_x = 2;
}
else
{
dev->scale_x = 1;
}
if (dev->y_resolution <= 0)
{
DBG(DBG_error,"ERROR: no y-resolution given\n");
return(1);
}
if (dev->y_resolution > dev->relevant_max_y_res)
{
dev->y_resolution = dev->relevant_max_y_res;
}
if (dev->y_resolution > dev->relevant_optical_res)
{
dev->scale_y = 2;
}
else if (dev->y_resolution > dev->relevant_optical_res/2)
{
dev->scale_y = 1;
}
else
{
/* astra 600S and 610S need this in umax_forget_line */
dev->scale_y = 0.5;
}
/* ------------------------------- scanarea ------------------------ */
if (dev->module == WD_module_flatbed) /* flatbed mode */
{
inquiry_x_orig = 0; /* flatbed origin */
inquiry_y_orig = 0;
inquiry_width = dev->inquiry_fb_width; /* flatbed width */
inquiry_length = dev->inquiry_fb_length;
}
else /* transparency mode */
{
inquiry_x_orig = dev->inquiry_uta_x_off; /* uta origin */
inquiry_y_orig = dev->inquiry_uta_y_off;
inquiry_width = dev->inquiry_uta_x_off + dev->inquiry_uta_width; /* uta width */
inquiry_length = dev->inquiry_uta_y_off + dev->inquiry_uta_length;
}
if (dev->dor != 0)
{
inquiry_x_orig = dev->inquiry_dor_x_off; /* dor origin */
inquiry_y_orig = dev->inquiry_dor_y_off;
inquiry_width = dev->inquiry_dor_x_off + dev->inquiry_dor_width; /* dor width */
inquiry_length = dev->inquiry_dor_y_off + dev->inquiry_dor_length;
}
/* limit the size to what the scanner can scan. */
/* this is particularly important because the scanners don't have */
/* built-in checks and will happily grind their gears if this is exceeded. */
maxwidth = inquiry_width * dev->x_coordinate_base - dev->upper_left_x - 1;
if ( (dev->scanwidth <= 0) || (dev->scanwidth > maxwidth) )
{
dev->scanwidth = maxwidth;
}
if (dev->upper_left_x < inquiry_x_orig)
{
dev->upper_left_x = inquiry_x_orig;
}
maxlength = inquiry_length * dev->y_coordinate_base - dev->upper_left_y - 1;
if ( (dev->scanlength <= 0) || (dev->scanlength > maxlength) )
{
dev->scanlength = maxlength;
}
if (dev->upper_left_y < inquiry_y_orig)
{
dev->upper_left_y = inquiry_y_orig;
}
/* Now calculate width and length in pixels */
dev->width_in_pixels = umax_calculate_pixels(dev->scanwidth, dev->x_resolution,
dev->relevant_optical_res * dev->scale_x, dev->x_coordinate_base);
dev->length_in_pixels = umax_calculate_pixels(dev->scanlength, dev->y_resolution,
dev->relevant_optical_res * dev->scale_y, dev->y_coordinate_base);
if ((dev->scanwidth <= 0) || (dev->scanlength <= 0))
{
DBG(DBG_error,"ERROR: scanwidth or scanlength not given\n");
return(1);
}
if (dev->bits_per_pixel_code == 1)
{
dev->bytes_per_color = 1;
}
else
{
dev->bytes_per_color = 2;
}
switch(dev->colormode)
{
case LINEART:
dev->width_in_pixels -= dev->width_in_pixels % 8;
dev->row_len = (dev->width_in_pixels / 8);
break;
case HALFTONE:
dev->width_in_pixels -= dev->width_in_pixels % 8;
dev->row_len = (dev->width_in_pixels / 8);
break;
case GRAYSCALE:
dev->row_len = dev->width_in_pixels * dev->bytes_per_color;
break;
case RGB_LINEART:
case RGB_HALFTONE:
if (dev->three_pass)
{
dev->row_len = dev->width_in_pixels / 8 ;
}
else
{
dev->row_len = (dev->width_in_pixels / 8 ) * 3;
}
break;
case RGB:
if (dev->three_pass) /* three (24bpp) or six (30bpp) bytes per pixel */
{
dev->row_len = dev->width_in_pixels * dev->bytes_per_color;
}
else
{
dev->row_len = dev->width_in_pixels * 3 * dev->bytes_per_color;
}
break;
}
/* ------------------------------- wdb length ------------------------ */
if (dev->wdb_len <= 0)
{
dev->wdb_len = dev->inquiry_wdb_len;
if (dev->wdb_len <= 0)
{
DBG(DBG_error,"ERROR: wdb-length not given\n");
return(1);
}
}
if (dev->wdb_len > used_WDB_size)
{
DBG(DBG_warning,"WARNING:window descriptor block too long, will be shortned!\n");
dev->wdb_len = used_WDB_size;
}
/* ----------------------------- cbhs-range ----------------------------- */
dev->threshold = umax_cbhs_correct(dev->inquiry_threshold_min, dev->threshold , dev->inquiry_threshold_max);
dev->contrast = umax_cbhs_correct(dev->inquiry_contrast_min, dev->contrast , dev->inquiry_contrast_max);
dev->brightness = umax_cbhs_correct(dev->inquiry_brightness_min, dev->brightness, dev->inquiry_brightness_max);
dev->highlight_r = umax_cbhs_correct(dev->inquiry_highlight_min, dev->highlight_r, dev->inquiry_highlight_max);
dev->highlight_g = umax_cbhs_correct(dev->inquiry_highlight_min, dev->highlight_g, dev->inquiry_highlight_max);
dev->highlight_b = umax_cbhs_correct(dev->inquiry_highlight_min, dev->highlight_b, dev->inquiry_highlight_max);
dev->shadow_r = umax_cbhs_correct(dev->inquiry_shadow_min, dev->shadow_r, dev->inquiry_shadow_max-1);
dev->shadow_g = umax_cbhs_correct(dev->inquiry_shadow_min, dev->shadow_g, dev->inquiry_shadow_max-1);
dev->shadow_b = umax_cbhs_correct(dev->inquiry_shadow_min, dev->shadow_b, dev->inquiry_shadow_max-1);
if (dev->shadow_r >= dev->highlight_r)
{
dev->shadow_r = dev->highlight_r-1;
}
if (dev->shadow_g >= dev->highlight_g)
{
dev->shadow_g = dev->highlight_g-1;
}
if (dev->shadow_b >= dev->highlight_b)
{
dev->shadow_b = dev->highlight_b-1;
}
/* ----------------------- quality calibration and preview -------------- */
if (dev->inquiry_preview == 0)
{
if (dev->preview)
{
DBG(DBG_warning, "WARNING: fast preview function not supported by scanner\n");
dev->preview = 0;
}
}
/* always set calibration lines because we also need this value if the scanner
requeires calibration by driver */
dev->calib_lines = dev->inquiry_max_calib_lines;
if (dev->force_quality_calibration)
{
dev->quality = 1; /* always use quality calibration */
}
else if (dev->inquiry_quality_ctrl == 0)
{
if (dev->quality)
{
DBG(DBG_warning, "WARNING: quality calibration not supported by scanner\n");
dev->quality = 0;
}
}
else
{
if (dev->preview != 0)
{
DBG(DBG_info, "quality calibration disabled in preview mode\n");
dev->quality = 0; /* do not use quality calibration in preview mode */
}
}
/* --------------------------- lamp intensity control ------------------- */
if (dev->inquiry_lamp_ctrl == 0)
{
if (dev->c_density || dev->s_density)
{
DBG(DBG_warning, "WARNING: scanner doesn't support lamp intensity control\n");
}
dev->c_density = dev->s_density = 0;
}
/* --------------------------- reverse (negative) ----------------------- */
if (dev->reverse != 0)
{
if ( (dev->colormode == LINEART) || (dev->colormode == HALFTONE) ||
(dev->colormode == RGB_LINEART) || (dev->colormode == RGB_HALFTONE) )
{
if (dev->inquiry_reverse == 0)
{
DBG(DBG_error, "ERROR: reverse for bi-level-image not supported\n");
return(1);
}
}
else
{ dev->reverse = 0; }
}
if (dev->reverse_multi != 0)
{
if ((dev->colormode == RGB) || (dev->colormode == GRAYSCALE) )
{
if (dev->inquiry_reverse_multi == 0)
{
DBG(DBG_error, "ERROR: reverse for multi-level-image not supported\n");
return(1);
}
}
else
{
dev->reverse_multi = 0;
}
}
/* ----------------------------- analog gamma ---------------------------- */
if (dev->inquiry_analog_gamma == 0)
{
if (dev->analog_gamma_r + dev->analog_gamma_g + dev->analog_gamma_b != 0)
{
DBG(DBG_warning,"WARNING: analog gamma correction not supported by scanner!\n");
}
dev->analog_gamma_r = dev->analog_gamma_g = dev->analog_gamma_b = 0;
}
/* ---------------------------- digital gamma ---------------------------- */
if ( (dev->digital_gamma_r == 0) || (dev->digital_gamma_g == 0) ||
(dev->digital_gamma_b == 0) )
{
if (dev->inquiry_gamma_dwload == 0)
{
DBG(DBG_warning, "WARNING: gamma download not available\n");
dev->digital_gamma_r = dev->digital_gamma_g = dev->digital_gamma_b = 15;
}
}
/* ---------------------------- speed and smear ------------------------- */
if (dev->slow == 1)
{
dev->WD_speed = WD_speed_slow;
}
else
{
dev->WD_speed = WD_speed_fast;
}
if (dev->smear == 1)
{
dev->WD_speed += WD_speed_smear;
}
/* ---------------------- test bits per pixel --------------------------- */
if ( ( (dev->inquiry_GIB | 1) & dev->gamma_input_bits_code) == 0 )
{
DBG(DBG_warning,"WARNING: selected gamma input bits not supported, gamma ignored\n");
dev->gamma_input_bits_code = 1;
dev->digital_gamma_r = dev->digital_gamma_g = dev->digital_gamma_b = 15;
}
if ( ( (dev->inquiry_GOB | 1) & dev->bits_per_pixel_code) == 0 )
{
DBG(DBG_error,"ERROR: selected bits per pixel not supported\n");
return(1);
}
/* ----------------------- scan mode dependencies ------------------------ */
switch(dev->colormode)
{
case LINEART: /* ------------ LINEART ------------- */
case RGB_LINEART: /* ---------- RGB_LINEART ----------- */
dev->use_exposure_time_min = dev->inquiry_exposure_time_l_min;
if (dev->module == WD_module_flatbed)
{
dev->use_exposure_time_def_r = dev->inquiry_exposure_time_l_fb_def;
}
else
{
dev->use_exposure_time_def_r = dev->inquiry_exposure_time_l_uta_def;
}
if (dev->inquiry_lineart == 0)
{
DBG(DBG_error,"ERROR: lineart mode not supported by scanner\n");
return(1);
}
break;
case HALFTONE: /* ----------- HALFTONE------------ */
case RGB_HALFTONE: /* --------- RGB_HALFTONE---------- */
dev->use_exposure_time_min = dev->inquiry_exposure_time_h_min;
if (dev->module == WD_module_flatbed)
{
dev->use_exposure_time_def_r = dev->inquiry_exposure_time_h_fb_def;
}
else
{
dev->use_exposure_time_def_r = dev->inquiry_exposure_time_h_uta_def;
}
if (dev->inquiry_halftone == 0)
{
DBG(DBG_error,"ERROR: halftone mode not supported by scanner\n");
return(1);
}
break;
case GRAYSCALE: /* ---------- GRAYSCALE ------------- */
dev->use_exposure_time_min = dev->inquiry_exposure_time_g_min;
if (dev->module == WD_module_flatbed)
{
dev->use_exposure_time_def_r = dev->inquiry_exposure_time_g_fb_def;
}
else
{
dev->use_exposure_time_def_r = dev->inquiry_exposure_time_g_uta_def;
}
if (dev->inquiry_gray == 0)
{
DBG(DBG_error, "ERROR: grayscale mode not supported by scanner\n");
return(1);
}
break;
case RGB: /* ----------------- COLOR ---------- */
dev->use_exposure_time_min = dev->inquiry_exposure_time_c_min;
if (dev->module == WD_module_flatbed)
{
dev->use_exposure_time_def_r = dev->inquiry_exposure_time_c_fb_def_r;
dev->use_exposure_time_def_g = dev->inquiry_exposure_time_c_fb_def_g;
dev->use_exposure_time_def_b = dev->inquiry_exposure_time_c_fb_def_b;
}
else
{
dev->use_exposure_time_def_r = dev->inquiry_exposure_time_c_uta_def_r;
dev->use_exposure_time_def_g = dev->inquiry_exposure_time_c_uta_def_g;
dev->use_exposure_time_def_b = dev->inquiry_exposure_time_c_uta_def_b;
}
if (dev->inquiry_color == 0)
{
DBG(DBG_error,"ERROR: color mode not supported by scanner\n");
return(1);
}
if (dev->inquiry_one_pass_color)
{
DBG(DBG_info,"using one pass scanning mode\n");
if (dev->inquiry_color_order & IN_color_ordering_pixel)
{
DBG(DBG_info,"scanner uses color-pixel-ordering\n");
}
else if (dev->inquiry_color_order & IN_color_ordering_line_no_ccd)
{
dev->CCD_distance = 0;
dev->do_color_ordering = 1;
DBG(DBG_info,"scanner uses color-line-ordering without CCD-distance\n");
}
else if (dev->inquiry_color_order & IN_color_ordering_line_w_ccd)
{
dev->CCD_distance = dev->inquiry_CCD_line_distance;
dev->do_color_ordering = 1;
switch (dev->inquiry_fb_uta_color_arrangement) /* define color order for line ordering */
{
case 1:
dev->CCD_color[0] = CCD_color_green;
dev->CCD_color[1] = CCD_color_blue;
dev->CCD_color[2] = CCD_color_green;
dev->CCD_color[3] = CCD_color_blue;
dev->CCD_color[4] = CCD_color_red;
dev->CCD_color[5] = CCD_color_green;
dev->CCD_color[6] = CCD_color_blue;
dev->CCD_color[7] = CCD_color_red;
dev->CCD_color[8] = CCD_color_red;
break;
case 2:
dev->CCD_color[0] = CCD_color_blue;
dev->CCD_color[1] = CCD_color_green;
dev->CCD_color[2] = CCD_color_blue;
dev->CCD_color[3] = CCD_color_green;
dev->CCD_color[4] = CCD_color_red;
dev->CCD_color[5] = CCD_color_blue;
dev->CCD_color[6] = CCD_color_green;
dev->CCD_color[7] = CCD_color_red;
dev->CCD_color[8] = CCD_color_red;
break;
case 3:
dev->CCD_color[0] = CCD_color_red;
dev->CCD_color[1] = CCD_color_blue;
dev->CCD_color[2] = CCD_color_red;
dev->CCD_color[3] = CCD_color_blue;
dev->CCD_color[4] = CCD_color_green;
dev->CCD_color[5] = CCD_color_red;
dev->CCD_color[6] = CCD_color_blue;
dev->CCD_color[7] = CCD_color_green;
dev->CCD_color[8] = CCD_color_green;
break;
case 4: /* may be wrong !!! */
dev->CCD_color[0] = CCD_color_red;
dev->CCD_color[1] = CCD_color_green;
dev->CCD_color[2] = CCD_color_red;
dev->CCD_color[3] = CCD_color_green;
dev->CCD_color[4] = CCD_color_red;
dev->CCD_color[5] = CCD_color_blue;
dev->CCD_color[6] = CCD_color_green;
dev->CCD_color[7] = CCD_color_blue;
dev->CCD_color[8] = CCD_color_blue;
break;
case 32: /* not defined from UMAX, for Astra 600S */
dev->CCD_color[0] = CCD_color_green;
dev->CCD_color[1] = CCD_color_green;
dev->CCD_color[2] = CCD_color_blue;
dev->CCD_color[3] = CCD_color_green;
dev->CCD_color[4] = CCD_color_red;
dev->CCD_color[5] = CCD_color_blue;
dev->CCD_color[6] = CCD_color_red;
dev->CCD_color[7] = CCD_color_blue;
dev->CCD_color[8] = CCD_color_red;
break;
case 33: /* not defined from UMAX, for Astra 610S */
dev->CCD_color[0] = CCD_color_red;
dev->CCD_color[1] = CCD_color_red;
dev->CCD_color[2] = CCD_color_blue;
dev->CCD_color[3] = CCD_color_red;
dev->CCD_color[4] = CCD_color_green;
dev->CCD_color[5] = CCD_color_blue;
dev->CCD_color[6] = CCD_color_green;
dev->CCD_color[7] = CCD_color_blue;
dev->CCD_color[8] = CCD_color_green;
break;
default:
dev->CCD_color[0] = CCD_color_green;
dev->CCD_color[1] = CCD_color_blue;
dev->CCD_color[2] = CCD_color_green;
dev->CCD_color[3] = CCD_color_blue;
dev->CCD_color[4] = CCD_color_red;
dev->CCD_color[5] = CCD_color_green;
dev->CCD_color[6] = CCD_color_blue;
dev->CCD_color[7] = CCD_color_red;
dev->CCD_color[8] = CCD_color_red;
}
DBG(DBG_info,"scanner uses color-line-ordering with CCD-distance of %d lines\n", dev->CCD_distance);
}
else
{
DBG(DBG_error,"ERROR: color-ordering-type not supported \n");
return(1);
}
}
else
{
DBG(DBG_info,"using three pass scanning mode\n");
dev->three_pass=1;
}
break;
} /* switch */
/* ----------------------------- color ordering ------------------------ */
if (dev->do_color_ordering != 0)
{
if ( (dev->colormode != RGB) || (dev->three_pass != 0) )
{
dev->do_color_ordering = 0; /* color ordering not necessary */
}
}
return(0);
}
/* ------------------------------------------------------------ UMAX GET INQUIRY VALUES -------------------- */
static void umax_get_inquiry_values(Umax_Device *dev)
{
unsigned char * inquiry_block;
DBG(DBG_proc,"get_inquiry_values\n");
inquiry_block = dev->buffer[0];
dev->inquiry_len = get_inquiry_additional_length(dev->buffer[0])+5;
dev->cbhs_range = dev->inquiry_cbhs = get_inquiry_CBHS(inquiry_block);
if (dev->cbhs_range > IN_CBHS_255)
{
dev->cbhs_range = IN_CBHS_255;
}
if (dev->cbhs_range == IN_CBHS_50)
{
dev->inquiry_contrast_min = 103; /* minimum value for c */
dev->inquiry_contrast_max = 153; /* maximum value for c */
dev->inquiry_brightness_min = 78; /* minimum value for b */
dev->inquiry_brightness_max = 178; /* maximum value for b */
dev->inquiry_threshold_min = 78; /* minimum value for t */
dev->inquiry_threshold_max = 178; /* maximum value for t */
dev->inquiry_highlight_min = 1; /* minimum value for h */
dev->inquiry_highlight_max = 50; /* maximum value for h */
dev->inquiry_shadow_min = 0; /* minimum value for s */
dev->inquiry_shadow_max = 49; /* maximum value for s */
}
get_inquiry_vendor( (char *)inquiry_block, dev->vendor); dev->vendor[8] ='\0';
get_inquiry_product((char *)inquiry_block, dev->product); dev->product[16]='\0';
get_inquiry_version((char *)inquiry_block, dev->version); dev->version[4] ='\0';
dev->inquiry_batch_scan = get_inquiry_fw_batch_scan(inquiry_block);
dev->inquiry_quality_ctrl = get_inquiry_fw_quality(inquiry_block);
dev->inquiry_preview = get_inquiry_fw_fast_preview(inquiry_block);
dev->inquiry_lamp_ctrl = get_inquiry_fw_lamp_int_cont(inquiry_block);
dev->inquiry_calibration = get_inquiry_fw_calibration(inquiry_block);
dev->inquiry_transavail = get_inquiry_transavail(inquiry_block);
dev->inquiry_adfmode = get_inquiry_scanmode(inquiry_block);
if (dev->inquiry_len<=0x8f)
{
DBG(DBG_warning, "WARNING: inquiry return block is unexpected short.\n");
}
dev->inquiry_uta = get_inquiry_sc_uta(inquiry_block);
dev->inquiry_adf = get_inquiry_sc_adf(inquiry_block);
dev->inquiry_one_pass_color = get_inquiry_sc_one_pass_color(inquiry_block);
dev->inquiry_three_pass_color = get_inquiry_sc_three_pass_color(inquiry_block);
dev->inquiry_color = get_inquiry_sc_color(inquiry_block);
dev->inquiry_gray = get_inquiry_sc_gray(inquiry_block);
dev->inquiry_halftone = get_inquiry_sc_halftone(inquiry_block);
dev->inquiry_lineart = get_inquiry_sc_lineart(inquiry_block);
dev->inquiry_exposure_adj = get_inquiry_fw_adjust_exposure_tf(inquiry_block);
dev->inquiry_exposure_time_step_unit = get_inquiry_exposure_time_step_unit(inquiry_block);
dev->inquiry_exposure_time_max = get_inquiry_exposure_time_max(inquiry_block);
/* --- lineart --- */
dev->inquiry_exposure_time_l_min = get_inquiry_exposure_time_lhg_min(inquiry_block);
dev->inquiry_exposure_time_l_fb_def = get_inquiry_exposure_time_lh_def_fb(inquiry_block);
dev->inquiry_exposure_time_l_uta_def = get_inquiry_exposure_time_lh_def_uta(inquiry_block);
/* --- halftone --- */
dev->inquiry_exposure_time_h_min = get_inquiry_exposure_time_lhg_min(inquiry_block);
dev->inquiry_exposure_time_h_fb_def = get_inquiry_exposure_time_lh_def_fb(inquiry_block);
dev->inquiry_exposure_time_h_uta_def = get_inquiry_exposure_time_lh_def_uta(inquiry_block);
/* --- grayscale --- */
dev->inquiry_exposure_time_g_min = get_inquiry_exposure_time_lhg_min(inquiry_block);
dev->inquiry_exposure_time_g_fb_def = get_inquiry_exposure_time_gray_def_fb(inquiry_block);
dev->inquiry_exposure_time_g_uta_def = get_inquiry_exposure_time_gray_def_uta(inquiry_block);
/* --- color --- */
dev->inquiry_exposure_time_c_min = get_inquiry_exposure_time_color_min(inquiry_block);
dev->inquiry_exposure_time_c_fb_def_r = get_inquiry_exposure_time_def_r_fb(inquiry_block);
dev->inquiry_exposure_time_c_fb_def_g = get_inquiry_exposure_time_def_g_fb(inquiry_block);
dev->inquiry_exposure_time_c_fb_def_b = get_inquiry_exposure_time_def_g_fb(inquiry_block);
dev->inquiry_exposure_time_c_uta_def_r = get_inquiry_exposure_time_def_r_uta(inquiry_block);
dev->inquiry_exposure_time_c_uta_def_g = get_inquiry_exposure_time_def_g_uta(inquiry_block);
dev->inquiry_exposure_time_c_uta_def_b = get_inquiry_exposure_time_def_b_uta(inquiry_block);
dev->inquiry_dor = get_inquiry_sc_double_res(inquiry_block);
dev->inquiry_reverse = get_inquiry_sc_bi_image_reverse(inquiry_block);
dev->inquiry_reverse_multi = get_inquiry_sc_multi_image_reverse(inquiry_block);
dev->inquiry_shadow = 1 - get_inquiry_sc_no_shadow(inquiry_block);
dev->inquiry_highlight = 1 - get_inquiry_sc_no_highlight(inquiry_block);
dev->inquiry_analog_gamma = get_inquiry_analog_gamma(inquiry_block);
dev->inquiry_lineart_order = get_inquiry_lineart_order(inquiry_block);
dev->inquiry_lens_cal_in_doc_pos = get_inquiry_manual_focus(inquiry_block);
dev->inquiry_manual_focus = get_inquiry_manual_focus(inquiry_block);
dev->inquiry_sel_uta_lens_cal_pos = get_inquiry_manual_focus(inquiry_block);
dev->inquiry_gamma_dwload = get_inquiry_gamma_download_available(inquiry_block);
if (get_inquiry_gamma_type_2(inquiry_block) != 0)
{
dev->inquiry_gamma_DCF = 2;
}
dev->inquiry_GIB = get_inquiry_gib(inquiry_block);
dev->inquiry_GOB = get_inquiry_gob(inquiry_block);
dev->inquiry_color_order = get_inquiry_color_order(inquiry_block);
dev->inquiry_vidmem = get_inquiry_max_vidmem(inquiry_block);
/* optical resolution = [0x73] * 100 + [0x94] , 0x94 is not always defined */
dev->inquiry_optical_res = 100 * get_inquiry_max_opt_res(inquiry_block);
if (dev->inquiry_len > 0x94)
{
dev->inquiry_optical_res += get_inquiry_optical_resolution_residue(inquiry_block);
}
/* x resolution = [0x74] * 100 + [0x95] , 0x95 is not always defined */
dev->inquiry_x_res = 100 * get_inquiry_max_x_res(inquiry_block);
if (dev->inquiry_len > 0x95)
{
dev->inquiry_x_res+= get_inquiry_x_resolution_residue(inquiry_block);
};
/* y resolution = [0x75] * 100 + [0x96] , 0x96 is not always defined */
dev->inquiry_y_res = 100 * get_inquiry_max_y_res(inquiry_block);
if (dev->inquiry_len > 0x96)
{
dev->inquiry_y_res+= get_inquiry_y_resolution_residue(inquiry_block);
}
/* optical resolution = [0x83] * 100 + [0xa0] , 0xa0 is not always defined */
dev->inquiry_dor_optical_res = 100 * get_inquiry_dor_max_opt_res(inquiry_block);
if (dev->inquiry_len > 0xa0)
{
dev->inquiry_dor_optical_res += get_inquiry_dor_optical_resolution_residue(inquiry_block);
}
/* x resolution = [0x84] * 100 + [0xa1] , 0xa1 is not always defined */
dev->inquiry_dor_x_res = 100 * get_inquiry_dor_max_x_res(inquiry_block);
if (dev->inquiry_len > 0xa1)
{
dev->inquiry_dor_x_res+= get_inquiry_dor_x_resolution_residue(inquiry_block);
}
/* y resolution = [0x85] * 100 + [0xa2] , 0xa2 is not always defined */
dev->inquiry_dor_y_res = 100 * get_inquiry_dor_max_y_res(inquiry_block);
if (dev->inquiry_len > 0xa2)
{
dev->inquiry_dor_y_res+= get_inquiry_dor_y_resolution_residue(inquiry_block);
}
if (dev->inquiry_dor) /* DOR mode available ? */
{
/* if DOR resolutions are not defined, use double of standard resolution */
if (dev->inquiry_dor_optical_res == 0)
{
dev->inquiry_dor_optical_res = dev->inquiry_optical_res * 2;
}
if (dev->inquiry_dor_x_res == 0)
{
dev->inquiry_dor_x_res = dev->inquiry_x_res * 2;
}
if (dev->inquiry_dor_y_res == 0)
{
dev->inquiry_dor_y_res = dev->inquiry_y_res * 2;
}
}
dev->inquiry_fb_width = (double)get_inquiry_fb_max_scan_width(inquiry_block) * 0.01;
dev->inquiry_fb_length = (double)get_inquiry_fb_max_scan_length(inquiry_block) * 0.01;
dev->inquiry_uta_width = (double)get_inquiry_uta_max_scan_width(inquiry_block) * 0.01;
dev->inquiry_uta_length = (double)get_inquiry_uta_max_scan_length(inquiry_block) * 0.01;
dev->inquiry_uta_x_off = (double)get_inquiry_uta_x_original_point(inquiry_block) * 0.01;
dev->inquiry_uta_y_off = (double)get_inquiry_uta_y_original_point(inquiry_block) * 0.01;
dev->inquiry_dor_width = (double)get_inquiry_dor_max_scan_width(inquiry_block) * 0.01;
dev->inquiry_dor_length = (double)get_inquiry_dor_max_scan_length(inquiry_block) * 0.01;
dev->inquiry_dor_x_off = (double)get_inquiry_dor_x_original_point(inquiry_block) * 0.01;
dev->inquiry_dor_y_off = (double)get_inquiry_dor_y_original_point(inquiry_block) * 0.01;
dev->inquiry_max_warmup_time = get_inquiry_lamp_warmup_maximum_time(inquiry_block) * 2;
dev->inquiry_wdb_len = get_inquiry_wdb_length(inquiry_block);
/* it is not guaranteed that the following values are in the inquiry return block */
/* 0x9a */
if (dev->inquiry_len<=0x9a)
{
return;
}
dev->inquiry_max_calib_lines = get_inquiry_max_calibration_data_lines(inquiry_block);
/* 0x9b */
if (dev->inquiry_len<=0x9b)
{
return;
}
dev->inquiry_fb_uta_color_arrangement = get_inquiry_fb_uta_line_arrangement_mode(inquiry_block);
/* 0x9c */
if (dev->inquiry_len<=0x9c)
{
return;
}
dev->inquiry_adf_color_arrangement = get_inquiry_adf_line_arrangement_mode(inquiry_block);
/* 0x9d */
if (dev->inquiry_len<=0x9d)
{
return;
}
dev->inquiry_CCD_line_distance = get_inquiry_CCD_line_distance(inquiry_block);
return;
}
/* ------------------------------------------------------------ UMAX CALCULATE ANALOG GAMMA ---------------- */
static int umax_calculate_analog_gamma(double value)
{
int gamma;
if (value < 1.0)
{ value=1.0; }
if (value > 2.0)
{ value=2.0; }
gamma=0; /* select gamma_value from analog_gamma_table */
while (value>analog_gamma_table[gamma])
{
gamma++;
}
if (gamma)
{
if ((analog_gamma_table[gamma-1] + analog_gamma_table[gamma]) /2 > value)
{
gamma--;
}
}
return(gamma);
}
/* ------------------------------------------------------------ UMAX OUTPUT IMAGE DATA -------------------- */
static void umax_output_image_data(Umax_Device *dev, FILE *fp, unsigned int data_to_read, int bufnr)
{
if (dev->do_color_ordering == 0) /* pixel ordering */
{
if ((dev->inquiry_lineart_order) && (dev->colormode == LINEART)) /* lineart with LSB first */
{
unsigned int i, j;
int new, old;
for (i=0; i<data_to_read; i++)
{
old = dev->buffer[bufnr][i];
new = 0;
for (j=0; j<8; j++) /* reverse bit order of 1 byte */
{
new = (new << 1) + (old & 1);
old = old >> 1;
}
dev->buffer[bufnr][i]=new;
}
}
fwrite(dev->buffer[bufnr], 1, data_to_read, fp);
}
else /* line ordering */
{
unsigned char *linesource = dev->buffer[bufnr];
unsigned char *pixelsource;
int bytes = 1;
int lines;
int i;
if (dev->bits_per_pixel_code != 1) /* >24 bpp */
{
bytes = 2;
}
lines = data_to_read / (dev->width_in_pixels * bytes);
for(i=0; i<lines; i++)
{
umax_order_line(dev, linesource);
linesource += dev->width_in_pixels * bytes;
pixelsource = umax_get_pixel_line(dev);
if (pixelsource != NULL)
{
fwrite(pixelsource, bytes, dev->width_in_pixels * 3, fp);
}
}
}
}
/* ------------------------------------------------------------ UMAX READER PROCESS ------------------------ */
static int umax_reader_process(Umax_Device *dev, FILE *fp, unsigned int image_size)
{
int status;
int bytes = 1;
int queue_filled = 0;
unsigned int bufnr_queue = 0;
unsigned int bufnr_read = 0;
unsigned int data_left_to_read = image_size;
unsigned int data_left_to_queue = image_size;
unsigned int data_to_read;
unsigned int data_to_queue;
dev->row_bufsize = dev->bufsize;
umax_trim_rowbufsize(dev); /* trim bufsize */
if (dev->bits_per_pixel_code != 1) /* >24 bpp */
{
bytes = 2;
}
DBG(DBG_read,"reading %u bytes in blocks of %u bytes\n", image_size, dev->row_bufsize);
if (dev->pixelbuffer != NULL) /* buffer exists? */
{
free(dev->pixelbuffer);
dev->pixelbuffer = NULL;
}
if (dev->do_color_ordering != 0)
{
DBG(DBG_info,"ordering from line-order to pixel-order\n");
dev->pixelline_max = 3 * dev->CCD_distance * dev->scale_y + 2;
dev->pixelbuffer = malloc(dev->width_in_pixels * dev->pixelline_max * bytes * 3);
if (dev->pixelbuffer == NULL) /* NO MEMORY */
{
return -1;
}
}
WAIT_SCANNER;
do
{
if (data_left_to_queue)
{
data_to_queue = (data_left_to_queue < dev->row_bufsize) ? data_left_to_queue : dev->row_bufsize;
/* umax_get_data_buffer_status(dev); */
status = umax_queue_read_image_data_req(dev, data_to_queue, bufnr_queue);
if (status == 0) /* no error but nothing queued */
{
continue;
}
if (status == -1) /* error */
{
DBG(DBG_error,"ERROR: umax_reader_process: unable to queue read image data request!\n");
free(dev->pixelbuffer);
dev->pixelbuffer = NULL;
return(-1);
}
data_left_to_queue -= data_to_queue;
DBG(DBG_read, "umax_reader_process: read image data queued for buffer[%d] \n", bufnr_queue);
bufnr_queue++;
if (bufnr_queue >= dev->scsi_maxqueue)
{
bufnr_queue = 0;
queue_filled = 1; /* ok, we can start to read the queued buffers - if not already started */
}
if (!data_left_to_queue)
{
queue_filled = 1; /* ok, we can start to read the queued buffer(s) - all read requests are send */
}
}
if (queue_filled) /* queue filled, ok we can read data */
{
status = umax_wait_queued_image_data(dev, bufnr_read);
if (status == -1)
{
DBG(DBG_error,"ERROR: umax_reader_process: unable to get image data from scanner!\n");
free(dev->pixelbuffer);
dev->pixelbuffer = NULL;
return(-1);
}
data_to_read = dev->length_read[bufnr_read]; /* number of bytes in buffer */
umax_output_image_data(dev, fp, data_to_read, bufnr_read);
data_left_to_read -= data_to_read;
DBG(DBG_read, "umax_reader_process: buffer of %d bytes read; %d bytes to go\n", data_to_read, data_left_to_read);
/* if we did not get all requested data increase data_left_to_queue so that we get all needed data */
if (dev->length_read[bufnr_read] != dev->length_queued[bufnr_read])
{
data_left_to_queue += dev->length_queued[bufnr_read] - dev->length_read[bufnr_read];
}
bufnr_read++;
if (bufnr_read >= dev->scsi_maxqueue)
{
bufnr_read = 0;
}
}
} while (data_left_to_read);
free(dev->pixelbuffer);
dev->pixelbuffer = NULL;
return 0;
}
/* ------------------------------------------------------------ UMAX INITIALIZE VALUES --------------------- */
static void umax_initialize_values(Umax_Device *dev) /* called each time before setting scan-values */
{ /* Initialize dev structure */
DBG(DBG_proc,"initialize_values\n");
dev->three_pass = 0; /* 1 if threepas_mode only */
dev->row_len = -1;
dev->max_value = 255; /* maximum value */
dev->wdb_len = 0;
dev->width_in_pixels = 0; /* scan width in pixels */
dev->length_in_pixels = 0; /* scan length in pixels */
dev->scanwidth = 0; /* width in inch at x_coordinate_base dpi */
dev->scanlength = 0; /* length in inch at y_coordinate_base dpi */
dev->x_resolution = 0;
dev->y_resolution = 0;
dev->upper_left_x = 0; /* at 1200pt/inch */
dev->upper_left_y = 0; /* at 1200pt/inch */
dev->bytes_per_color = 0; /* bytes for each color */
dev->bits_per_pixel = 8; /* number of bits per pixel */
dev->bits_per_pixel_code = 1; /* 1 = 8/24 bpp, 2 = 9/27 bpp, 4 = 10/30 bpp */
dev->gamma_input_bits_code = 1; /* 8 = 12/36 bpp, 16 = 14/42 bpp, 32 = 16/48 bpp */
dev->set_auto = 0; /* 0 or 1 */
dev->preview = 0; /* 1 for preview */
dev->quality = 0; /* quality calibration */
dev->warmup = 0; /* warmup-bit */
dev->fix_focus_position = 0; /* fix focus position */
dev->lens_cal_in_doc_pos = 0; /* lens calibration in document position */
dev->disable_pre_focus = 0; /* disable pre focus */
dev->holder_focus_pos_0mm = 0; /* 0.6mm <-> 0.0mm holder focus position */
dev->manual_focus = 0; /* automatic <-> manual focus */
dev->colormode = 0; /* LINEART, HALFTONE, GRAYSCALE or RGB */
dev->adf = 0; /* 1 if adf shall be used */
dev->uta = 0; /* 1 if uta shall be used */
dev->module = WD_module_flatbed;
dev->cbhs_range = WD_CBHS_255;
dev->dor = 0;
dev->halftone = WD_halftone_8x8_1;
dev->reverse = 0;
dev->reverse_multi = 0;
dev->calibration = 0;
dev->exposure_time_calibration_r = 0; /* use this for calibration */
dev->exposure_time_calibration_g = 0; /* use this for calibration */
dev->exposure_time_calibration_b = 0; /* use this for calibration */
dev->exposure_time_scan_r = 0; /* use this for scan */
dev->exposure_time_scan_g = 0; /* use this for scan */
dev->exposure_time_scan_b = 0; /* use this for scan */
dev->c_density = WD_lamp_c_density_auto; /* calibration lamp density */
dev->s_density = WD_lamp_s_density_auto; /* next scan lamp density */
dev->threshold = 128; /* threshold for lineart mode */
dev->brightness = 128; /* brightness for halftone mode */
dev->contrast = 128; /* contrast for halftone mode */
dev->highlight_r = 255; /* highlight gray/red */
dev->highlight_g = 255; /* highlight green */
dev->highlight_b = 255; /* highlight blue */
dev->shadow_r = 0; /* shadow gray/red */
dev->shadow_g = 0; /* shadow green */
dev->shadow_b = 0; /* shadow blue */
dev->digital_gamma_r = WD_gamma_normal;
dev->digital_gamma_g = WD_gamma_normal;
dev->digital_gamma_b = WD_gamma_normal;
dev->analog_gamma_r = 0; /* analog gamma for red and gray to 1.0 */
dev->analog_gamma_g = 0; /* analog gamma for green to 1.0 */
dev->analog_gamma_b = 0; /* analog gamma for blue to 1.0 */
dev->pixelline_ready[0] = 0; /* reset all values for color ordering */
dev->pixelline_ready[1] = 0;
dev->pixelline_ready[2] = 0;
dev->pixelline_next[0] = 0;
dev->pixelline_next[1] = 0;
dev->pixelline_next[2] = 0;
dev->pixelline_del[0] = 1;
dev->pixelline_del[1] = 1;
dev->pixelline_del[2] = 1;
dev->pixelline_optic[0] = 1;
dev->pixelline_optic[1] = 1;
dev->pixelline_optic[2] = 1;
dev->pixelline_max = 0;
dev->pixelline_opt_res = 0;
dev->pixelline_read = 0;
dev->pixelline_written = 0;
dev->CCD_distance = 0;
dev->calib_lines = 0; /* request calibration lines */
dev->do_calibration = 0; /* no calibration by driver */
dev->do_color_ordering = 0; /* no line- to pixel-mode ordering */
dev->button0_pressed = 0; /* reset button 0 pressed flag */
dev->button1_pressed = 0; /* reset button 1 pressed flag */
dev->button2_pressed = 0; /* reset button 2 pressed flag */
}
/* ------------------------------------------------------------ UMAX INIT ---------------------------------- */
static void umax_init(Umax_Device *dev) /* umax_init is called once while driver-initialization */
{
DBG(DBG_proc,"init\n");
dev->devicename = NULL;
dev->pixelbuffer = NULL;
/* config file or predefined settings */
if (dev->connection_type == SANE_UMAX_SCSI)
{
dev->request_scsi_maxqueue = umax_scsi_maxqueue;
}
else /* SANE_UMAX_USB, USB does not support command queueing */
{
DBG(DBG_info2, "setting request_scsi_maxqueue = 1 for USB connection\n");
dev->request_scsi_maxqueue = 1;
}
dev->request_preview_lines = umax_preview_lines;
dev->request_scan_lines = umax_scan_lines;
dev->handle_bad_sense_error = umax_handle_bad_sense_error;
dev->execute_request_sense = umax_execute_request_sense;
dev->scsi_buffer_size_min = umax_scsi_buffer_size_min;
dev->scsi_buffer_size_max = umax_scsi_buffer_size_max;
dev->force_preview_bit_rgb = umax_force_preview_bit_rgb;
dev->slow = umax_slow;
dev->smear = umax_smear;
dev->calibration_area = umax_calibration_area;
dev->calibration_width_offset = umax_calibration_width_offset;
dev->calibration_width_offset_batch = umax_calibration_width_offset_batch;
dev->calibration_bytespp = umax_calibration_bytespp;
dev->exposure_time_rgb_bind = umax_exposure_time_rgb_bind;
dev->invert_shading_data = umax_invert_shading_data;
dev->lamp_control_available = umax_lamp_control_available;
dev->gamma_lsb_padded = umax_gamma_lsb_padded;
DBG(DBG_info, "request_scsi_maxqueue = %d\n", dev->request_scsi_maxqueue);
DBG(DBG_info, "request_preview_lines = %d\n", dev->request_preview_lines);
DBG(DBG_info, "request_scan_lines = %d\n", dev->request_scan_lines);
DBG(DBG_info, "handle_bad_sense_error = %d\n", dev->handle_bad_sense_error);
DBG(DBG_info, "execute_request_sense = %d\n", dev->execute_request_sense);
DBG(DBG_info, "scsi_buffer_size_min = %d\n", dev->scsi_buffer_size_min);
DBG(DBG_info, "scsi_buffer_size_max = %d\n", dev->scsi_buffer_size_max);
DBG(DBG_info, "force_preview_bit_rgb = %d\n", dev->force_preview_bit_rgb);
DBG(DBG_info, "slow = %d\n", dev->slow);
DBG(DBG_info, "smear = %d\n", dev->smear);
DBG(DBG_info, "calibration_area = %d\n", dev->calibration_area);
DBG(DBG_info, "calibration_width_offset = %d\n", dev->calibration_width_offset);
DBG(DBG_info, "calibration_width_offset_batch = %d\n", dev->calibration_width_offset_batch);
DBG(DBG_info, "calibration_bytespp = %d\n", dev->calibration_bytespp);
DBG(DBG_info, "exposure_time_rgb_bind = %d\n", dev->exposure_time_rgb_bind);
DBG(DBG_info, "invert_shading_data = %d\n", dev->invert_shading_data);
DBG(DBG_info, "lamp_control_available = %d\n", dev->lamp_control_available);
dev->inquiry_len = 0;
dev->inquiry_wdb_len = -1;
dev->inquiry_optical_res = -1;
dev->inquiry_x_res = -1;
dev->inquiry_y_res = -1;
dev->inquiry_fb_width = -1;
dev->inquiry_fb_length = -1;
dev->inquiry_uta_width = -1;
dev->inquiry_uta_length = -1;
dev->inquiry_dor_width = -1;
dev->inquiry_dor_length = -1;
dev->inquiry_exposure_adj = 0;
dev->inquiry_exposure_time_step_unit = -1; /* exposure time unit in micro sec */
dev->inquiry_exposure_time_max = -1; /* exposure time maximum */
dev->inquiry_exposure_time_l_min = -1; /* exposure time minimum for lineart */
dev->inquiry_exposure_time_l_fb_def = -1; /* exposure time default for lineart flatbed */
dev->inquiry_exposure_time_l_uta_def = -1; /* exposure time default for lineart uta */
dev->inquiry_exposure_time_h_min = -1; /* exposure time minimum for halftone */
dev->inquiry_exposure_time_h_fb_def = -1; /* exposure time default for halftone flatbed */
dev->inquiry_exposure_time_h_uta_def = -1; /* exposure time default for halftone uta */
dev->inquiry_exposure_time_g_min = -1; /* exposure time minimum for grayscale */
dev->inquiry_exposure_time_g_fb_def = -1; /* exposure time default for grayscale flatbed */
dev->inquiry_exposure_time_g_uta_def = -1; /* exposure time default for grayscale uta */
dev->inquiry_exposure_time_c_min = -1; /* exposure time minimum for color */
dev->inquiry_exposure_time_c_fb_def_r = -1; /* exposure time default for color flatbed red */
dev->inquiry_exposure_time_c_fb_def_g = -1; /* exposure time default for color flatbed green */
dev->inquiry_exposure_time_c_fb_def_b = -1; /* exposure time default for color flatbed blue */
dev->inquiry_exposure_time_c_uta_def_r = -1; /* exposure time default for color uta red */
dev->inquiry_exposure_time_c_uta_def_g = -1; /* exposure time default for color uta green */
dev->inquiry_exposure_time_c_uta_def_b = -1; /* exposure time default for color uta blue */
dev->inquiry_max_warmup_time = 0; /* maximum warmup time */
dev->inquiry_cbhs = WD_CBHS_255;
dev->inquiry_contrast_min = 1; /* minimum value for c */
dev->inquiry_contrast_max = 255; /* maximum value for c */
dev->inquiry_brightness_min = 1; /* minimum value for b */
dev->inquiry_brightness_max = 255; /* maximum value for b */
dev->inquiry_threshold_min = 1; /* minimum value for t */
dev->inquiry_threshold_max = 255; /* maximum value for t */
dev->inquiry_highlight_min = 1; /* minimum value for h */
dev->inquiry_highlight_max = 255; /* maximum value for h */
dev->inquiry_shadow_min = 0; /* minimum value for s */
dev->inquiry_shadow_max = 254; /* maximum value for s */
dev->inquiry_quality_ctrl = 0;
dev->inquiry_preview = 0;
dev->inquiry_lamp_ctrl = 0;
dev->inquiry_transavail = 0;
dev->inquiry_uta = 0;
dev->inquiry_adfmode = 0;
dev->inquiry_adf = 0;
dev->inquiry_dor = 0;
dev->inquiry_reverse = 0;
dev->inquiry_reverse_multi = 0;
dev->inquiry_analog_gamma = 0;
dev->inquiry_gamma_dwload = 0;
dev->inquiry_one_pass_color = 0;
dev->inquiry_three_pass_color = 0;
dev->inquiry_color = 0;
dev->inquiry_gray = 0;
dev->inquiry_halftone = 0;
dev->inquiry_lineart = 0;
dev->inquiry_calibration = 1;
dev->inquiry_shadow = 0;
dev->inquiry_highlight = 0;
dev->inquiry_gamma_DCF = -1;
dev->inquiry_max_calib_lines = 66; /* most scanners use 66 lines, so lets define it as default */
dev->common_xy_resolutions = 0;
dev->x_coordinate_base = 1200; /* these are the 1200pt/inch */
dev->y_coordinate_base = 1200; /* these are the 1200pt/inch */
dev->button0_pressed = 0; /* reset button 0 pressed flag */
dev->button1_pressed = 0; /* reset button 1 pressed flag */
dev->button2_pressed = 0; /* reset button 2 pressed flag */
dev->pause_for_color_calibration = 0; /* pause between start_scan and do_calibration in ms */
dev->pause_for_gray_calibration = 0; /* pause between start_scan and do_calibration in ms */
dev->pause_after_calibration = 0; /* pause between do_calibration and read data in ms */
dev->pause_after_reposition = -1; /* pause after repostion scanner in ms, -1 = do not wait */
dev->pause_for_moving = 0; /* pause for moving scanhead over full area */
if (umax_test_little_endian() == SANE_TRUE)
{
dev->low_byte_first = 1; /* in 2 byte mode send lowbyte first */
DBG(DBG_info, "backend runs on little endian machine\n");
}
else
{
dev->low_byte_first = 0; /* in 2 byte mode send highbyte first */
DBG(DBG_info, "backend runs on big endian machine\n");
}
#ifdef HAVE_SANEI_SCSI_OPEN_EXTENDED
DBG(DBG_info,"variable scsi buffer size (usage of sanei_scsi_open_extended)\n");
#else
DBG(DBG_info,"fixed scsi buffer size = %d bytes\n", sanei_scsi_max_request_size);
#endif
}
/* ------------------------------------------------------------ MAX STRING SIZE ---------------------------- */
static size_t max_string_size(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;
}
/* ------------------------------------------------------------ DO CANCEL ---------------------------------- */
static SANE_Status do_cancel(Umax_Scanner *scanner)
{
SANE_Pid pid;
int status;
DBG(DBG_sane_proc,"do_cancel\n");
scanner->scanning = SANE_FALSE;
if (sanei_thread_is_valid (scanner->reader_pid))
{
DBG(DBG_sane_info,"killing reader_process\n");
sanei_thread_kill(scanner->reader_pid);
pid = sanei_thread_waitpid(scanner->reader_pid, &status);
if (!sanei_thread_is_valid (pid))
{
DBG(DBG_sane_info, "do_cancel: sanei_thread_waitpid failed, already terminated ? (%s)\n", strerror(errno));
}
else
{
DBG(DBG_sane_info, "do_cancel: reader_process terminated with status: %s\n", sane_strstatus(status));
}
sanei_thread_invalidate (scanner->reader_pid);
if (scanner->device->pixelbuffer != NULL) /* pixelbuffer exists? */
{
free(scanner->device->pixelbuffer); /* free pixelbuffer */
scanner->device->pixelbuffer = NULL;
}
}
sanei_scsi_req_flush_all(); /* flush SCSI queue, when we do not do this then sanei_scsi crashes next time */
if (scanner->device->sfd != -1) /* make sure we have a working filedescriptor */
{
umax_give_scanner(scanner->device); /* reposition and release scanner */
DBG(DBG_sane_info,"closing scannerdevice filedescriptor\n");
umax_scsi_close(scanner->device);
}
scanner->device->three_pass_color = 1; /* reset color in color scanning */
return SANE_STATUS_CANCELLED;
}
/* ------------------------------------------------------------ ATTACH SCANNER ----------------------------- */
static SANE_Status attach_scanner(const char *devicename, Umax_Device **devp, int connection_type)
{
Umax_Device *dev;
int i;
DBG(DBG_sane_proc,"attach_scanner: %s, connection_type %d\n", devicename, connection_type);
for (dev = first_dev; dev; dev = dev->next) /* search is scanner already is listed in devicelist */
{
if (strcmp(dev->sane.name, devicename) == 0) /* scanner is already listed */
{
if (devp)
{
*devp = dev; /* return pointer to device */
}
return SANE_STATUS_GOOD;
}
}
/* scanner has not been attached yet */
dev = malloc( sizeof(*dev) );
if (!dev)
{
return SANE_STATUS_NO_MEM;
}
memset(dev, '\0', sizeof(Umax_Device)); /* clear structure */
/* If connection type is not known (==0) then try to open the device as an USB device. */
/* If it fails, try the SCSI method. */
#ifdef UMAX_ENABLE_USB
dev->connection_type = connection_type; /* 0 = unknown, 1=scsi, 2=usb */
if (dev->connection_type != SANE_UMAX_SCSI)
{
dev->bufsize = 16384; /* 16KB */
DBG(DBG_info, "attach_scanner: opening usb device %s\n", devicename);
if (sanei_umaxusb_open(devicename, &dev->sfd, sense_handler, dev) == SANE_STATUS_GOOD)
{
dev->connection_type = SANE_UMAX_USB;
}
else /* opening usb device failed */
{
if (dev->connection_type == SANE_UMAX_USB) /* we know it is not a scsi device: error */
{
DBG(DBG_error, "ERROR: attach_scanner: opening usb device %s failed\n", devicename);
free(dev);
return SANE_STATUS_INVAL;
}
DBG(DBG_info, "attach_scanner: failed to open %s as usb device\n", devicename);
}
}
#else
dev->connection_type = SANE_UMAX_SCSI;
#endif
if (dev->connection_type != SANE_UMAX_USB) /* not an USB device, then try as SCSI */
{
#ifdef HAVE_SANEI_SCSI_OPEN_EXTENDED
dev->bufsize = 16384; /* 16KB */
DBG(DBG_info, "attach_scanner: opening scsi device %s\n", devicename);
if (sanei_scsi_open_extended(devicename, &dev->sfd, sense_handler, dev, (int *) &dev->bufsize) != 0)
{
DBG(DBG_error, "ERROR: attach_scanner: opening scsi device %s failed\n", devicename);
free(dev);
return SANE_STATUS_INVAL;
}
if (dev->bufsize < 4096) /* < 4KB */
{
DBG(DBG_error, "ERROR: attach_scanner: sanei_scsi_open_extended returned too small scsi buffer\n");
umax_scsi_close(dev);
free(dev);
return SANE_STATUS_NO_MEM;
}
DBG(DBG_info, "attach_scanner: sanei_scsi_open_extended returned scsi buffer size = %d\n", dev->bufsize);
#else
dev->bufsize = sanei_scsi_max_request_size;
if (sanei_scsi_open(devicename, dev, sense_handler, dev) != 0)
{
DBG(DBG_error, "ERROR: attach_scanner: opening scsi device %s failed\n", devicename);
free(dev);
return SANE_STATUS_INVAL;
}
#endif
dev->connection_type = SANE_UMAX_SCSI; /* set connection type (may have been unknown == 0) */
}
DBG(DBG_info, "attach_scanner: allocating SCSI buffer[0]\n");
dev->buffer[0] = malloc(dev->bufsize); /* allocate buffer */
for (i=1; i<SANE_UMAX_SCSI_MAXQUEUE; i++)
{
dev->buffer[i] = NULL;
}
if (!dev->buffer[0]) /* malloc failed */
{
DBG(DBG_error, "ERROR: attach scanner: could not allocate buffer[0]\n");
umax_scsi_close(dev);
free(dev);
return SANE_STATUS_NO_MEM;
}
dev->scsi_maxqueue = 1; /* only one buffer outside the reader process */
umax_init(dev); /* preset values in structure dev */
umax_initialize_values(dev); /* reset values */
dev->devicename = strdup(devicename);
if (umax_identify_scanner(dev) != 0)
{
DBG(DBG_error, "ERROR: attach_scanner: scanner-identification failed\n");
umax_scsi_close(dev);
free(dev->buffer[0]);
free(dev);
return SANE_STATUS_INVAL;
}
if (dev->slow == -1) /* option is not predefined in umax.conf and not by backend */
{
dev->slow = 0;
}
if (dev->smear == -1) /* option is not predefined in umax.conf and not by backend */
{
dev->smear = 0;
}
if (dev->invert_shading_data == -1) /* nothing defined in umax.conf and not by backend */
{
dev->invert_shading_data = 0;
}
if (dev->gamma_lsb_padded == -1) /* nothing defined in umax.conf and not by backend */
{
dev->gamma_lsb_padded = 0;
}
umax_get_inquiry_values(dev);
umax_print_inquiry(dev);
DBG(DBG_inquiry,"\n");
DBG(DBG_inquiry,"==================== end of inquiry ====================\n");
DBG(DBG_inquiry,"\n");
umax_scsi_close(dev);
dev->sane.name = dev->devicename;
dev->sane.vendor = dev->vendor;
dev->sane.model = dev->product;
dev->sane.type = "flatbed scanner";
if (strcmp(dev->sane.model,"PSD ") == 0)
{
dev->sane.type = "page scanner";
}
dev->x_range.min = SANE_FIX(0);
dev->x_range.quant = SANE_FIX(0);
dev->x_range.max = SANE_FIX(dev->inquiry_fb_width * MM_PER_INCH);
dev->y_range.min = SANE_FIX(0);
dev->y_range.quant = SANE_FIX(0);
dev->y_range.max = SANE_FIX(dev->inquiry_fb_length * MM_PER_INCH);
#if UMAX_RESOLUTION_PERCENT_STEP
dev->x_dpi_range.min = SANE_FIX(dev->inquiry_optical_res/100);
dev->x_dpi_range.quant = SANE_FIX(dev->inquiry_optical_res/100);
#else
dev->x_dpi_range.min = SANE_FIX(5);
dev->x_dpi_range.quant = SANE_FIX(5);
#endif
dev->x_dpi_range.max = SANE_FIX(dev->inquiry_x_res);
#if UMAX_RESOLUTION_PERCENT_STEP
dev->y_dpi_range.min = SANE_FIX(dev->inquiry_optical_res/100);
dev->y_dpi_range.quant = SANE_FIX(dev->inquiry_optical_res/100);
#else
dev->y_dpi_range.min = SANE_FIX(5);
dev->y_dpi_range.quant = SANE_FIX(5);
#endif
dev->y_dpi_range.max = SANE_FIX(dev->inquiry_y_res);
dev->analog_gamma_range.min = SANE_FIX(1.0);
dev->analog_gamma_range.quant = SANE_FIX(0.01);
dev->analog_gamma_range.max = SANE_FIX(2.0);
DBG(DBG_info,"x_range.max = %f\n", SANE_UNFIX(dev->x_range.max));
DBG(DBG_info,"y_range.max = %f\n", SANE_UNFIX(dev->y_range.max));
DBG(DBG_info,"x_dpi_range.max = %f\n", SANE_UNFIX(dev->x_dpi_range.max));
DBG(DBG_info,"y_dpi_range.max = %f\n", SANE_UNFIX(dev->y_dpi_range.max));
++num_devices;
dev->next = first_dev;
first_dev = dev;
if (devp)
{
*devp = dev;
}
return SANE_STATUS_GOOD;
}
/* ------------------------------------------------------------ READER PROCESS SIGTERM HANDLER ------------ */
static void reader_process_sigterm_handler(int signal)
{
DBG(DBG_sane_info,"reader_process: terminated by signal %d\n", signal);
sanei_scsi_req_flush_all(); /* flush SCSI queue */
_exit (SANE_STATUS_GOOD);
}
/* ------------------------------------------------------------ READER PROCESS ----------------------------- */
static int reader_process(void *data) /* executed as a child process or as thread */
{
Umax_Scanner *scanner = (Umax_Scanner *)data;
FILE *fp;
int status;
unsigned int data_length;
struct SIGACTION act;
unsigned int i;
if (sanei_thread_is_forked())
{
DBG(DBG_sane_proc,"reader_process started (forked)\n");
close(scanner->pipe_read_fd);
scanner->pipe_read_fd = -1;
/* sanei_scsi crashes when the scsi commands are not flushed, done in reader_process_sigterm_handler */
memset(&act, 0, sizeof (act)); /* define SIGTERM-handler */
act.sa_handler = reader_process_sigterm_handler;
sigaction(SIGTERM, &act, 0);
}
else
{
DBG(DBG_sane_proc,"reader_process started (as thread)\n");
}
scanner->device->scsi_maxqueue = scanner->device->request_scsi_maxqueue;
if (scanner->device->request_scsi_maxqueue > 1)
{
for (i = 1; i<SANE_UMAX_SCSI_MAXQUEUE; i++)
{
if (scanner->device->buffer[i])
{
DBG(DBG_info, "reader_process: freeing SCSI buffer[%d]\n", i);
free(scanner->device->buffer[i]); /* free buffer */
scanner->device->buffer[i] = NULL;
}
}
for (i = 1; i<scanner->device->request_scsi_maxqueue; i++)
{
DBG(DBG_info, "reader_process: allocating SCSI buffer[%d]\n", i);
scanner->device->buffer[i] = malloc(scanner->device->bufsize); /* allocate buffer */
if (!scanner->device->buffer[i]) /* malloc failed */
{
DBG(DBG_warning, "WARNING: reader_process: only allocated %d/%d scsi buffers\n", i, scanner->device->request_scsi_maxqueue);
scanner->device->scsi_maxqueue = i;
break; /* leave for loop */
}
}
}
data_length = scanner->params.lines * scanner->params.bytes_per_line;
fp = fdopen(scanner->pipe_write_fd, "w");
if (!fp)
{
return SANE_STATUS_IO_ERROR;
}
DBG(DBG_sane_info,"reader_process: starting to READ data\n");
status = umax_reader_process(scanner->device, fp, data_length);
fclose(fp); /* close write end of pipe */
for (i = 1; i<scanner->device->request_scsi_maxqueue; i++)
{
if (scanner->device->buffer[i])
{
DBG(DBG_info, "reader_process: freeing SCSI buffer[%d]\n", i);
free(scanner->device->buffer[i]); /* free buffer */
scanner->device->buffer[i] = NULL;
}
}
DBG(DBG_sane_info,"reader_process: finished reading data\n");
return status;
}
/* ------------------------------------------------------------ INIT OPTIONS ------------------------------- */
static SANE_Status init_options(Umax_Scanner *scanner)
{
int i;
int scan_modes;
int bit_depths;
DBG(DBG_sane_proc,"init_options\n");
memset(scanner->opt, 0, sizeof (scanner->opt));
memset(scanner->val, 0, sizeof (scanner->val));
for (i = 0; i < NUM_OPTIONS; ++i)
{
scanner->opt[i].size = sizeof (SANE_Word);
scanner->opt[i].cap = SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT;
}
scanner->opt[OPT_NUM_OPTS].name = SANE_NAME_NUM_OPTIONS; /* empty string */
scanner->opt[OPT_NUM_OPTS].title = SANE_TITLE_NUM_OPTIONS;
scanner->opt[OPT_NUM_OPTS].desc = SANE_DESC_NUM_OPTIONS;
scanner->opt[OPT_NUM_OPTS].type = SANE_TYPE_INT;
scanner->opt[OPT_NUM_OPTS].cap = SANE_CAP_SOFT_DETECT;
scanner->val[OPT_NUM_OPTS].w = NUM_OPTIONS;
/* "Mode" group: */
scanner->opt[OPT_MODE_GROUP].title = SANE_I18N("Scan Mode");
scanner->opt[OPT_MODE_GROUP].desc = "";
scanner->opt[OPT_MODE_GROUP].type = SANE_TYPE_GROUP;
scanner->opt[OPT_MODE_GROUP].cap = 0;
scanner->opt[OPT_MODE_GROUP].constraint_type = SANE_CONSTRAINT_NONE;
scan_modes = -1;
if (scanner->device->inquiry_lineart)
{
scan_mode_list[++scan_modes] = LINEART_STR;
}
if (scanner->device->inquiry_halftone)
{
scan_mode_list[++scan_modes]= HALFTONE_STR;
}
if (scanner->device->inquiry_gray)
{
scan_mode_list[++scan_modes]= GRAY_STR;
}
if (scanner->device->inquiry_color)
{
/*
if (scanner->device->inquiry_lineart)
{ scan_mode_list[++scan_modes]= COLOR_LINEART_STR; }
if (scanner->device->inquiry_halftone)
{ scan_mode_list[++scan_modes]= COLOR_HALFTONE_STR; }
*/
scan_mode_list[++scan_modes]= COLOR_STR;
}
scan_mode_list[scan_modes + 1] = 0;
{
int i=0;
source_list[i++]= FLB_STR;
if (scanner->device->inquiry_adfmode)
{
source_list[i++] = ADF_STR;
}
if (scanner->device->inquiry_transavail)
{
source_list[i++] = UTA_STR;
}
source_list[i] = 0;
}
/* scan mode */
scanner->opt[OPT_MODE].name = SANE_NAME_SCAN_MODE;
scanner->opt[OPT_MODE].title = SANE_TITLE_SCAN_MODE;
scanner->opt[OPT_MODE].desc = SANE_DESC_SCAN_MODE;
scanner->opt[OPT_MODE].type = SANE_TYPE_STRING;
scanner->opt[OPT_MODE].size = max_string_size((SANE_String_Const *) scan_mode_list);
scanner->opt[OPT_MODE].constraint_type = SANE_CONSTRAINT_STRING_LIST;
scanner->opt[OPT_MODE].constraint.string_list = (SANE_String_Const *) scan_mode_list;
scanner->val[OPT_MODE].s = (SANE_Char*)strdup(scan_mode_list[0]);
/* source */
scanner->opt[OPT_SOURCE].name = SANE_NAME_SCAN_SOURCE;
scanner->opt[OPT_SOURCE].title = SANE_TITLE_SCAN_SOURCE;
scanner->opt[OPT_SOURCE].desc = SANE_DESC_SCAN_SOURCE;
scanner->opt[OPT_SOURCE].type = SANE_TYPE_STRING;
scanner->opt[OPT_SOURCE].size = max_string_size(source_list);
scanner->opt[OPT_SOURCE].constraint_type = SANE_CONSTRAINT_STRING_LIST;
scanner->opt[OPT_SOURCE].constraint.string_list = source_list;
scanner->val[OPT_SOURCE].s = (SANE_Char*)strdup(source_list[0]);
/* x-resolution */
scanner->opt[OPT_X_RESOLUTION].name = SANE_NAME_SCAN_RESOLUTION;
scanner->opt[OPT_X_RESOLUTION].title = SANE_TITLE_SCAN_RESOLUTION;
scanner->opt[OPT_X_RESOLUTION].desc = SANE_DESC_SCAN_RESOLUTION;
scanner->opt[OPT_X_RESOLUTION].type = SANE_TYPE_FIXED;
scanner->opt[OPT_X_RESOLUTION].unit = SANE_UNIT_DPI;
scanner->opt[OPT_X_RESOLUTION].constraint_type = SANE_CONSTRAINT_RANGE;
scanner->opt[OPT_X_RESOLUTION].constraint.range = &scanner->device->x_dpi_range;
scanner->val[OPT_X_RESOLUTION].w = 100 << SANE_FIXED_SCALE_SHIFT;
/* y-resolution */
scanner->opt[OPT_Y_RESOLUTION].name = SANE_NAME_SCAN_Y_RESOLUTION;
scanner->opt[OPT_Y_RESOLUTION].title = SANE_TITLE_SCAN_Y_RESOLUTION;
scanner->opt[OPT_Y_RESOLUTION].desc = SANE_DESC_SCAN_Y_RESOLUTION;
scanner->opt[OPT_Y_RESOLUTION].type = SANE_TYPE_FIXED;
scanner->opt[OPT_Y_RESOLUTION].unit = SANE_UNIT_DPI;
scanner->opt[OPT_Y_RESOLUTION].constraint_type = SANE_CONSTRAINT_RANGE;
scanner->opt[OPT_Y_RESOLUTION].constraint.range = &scanner->device->y_dpi_range;
scanner->val[OPT_Y_RESOLUTION].w = 100 << SANE_FIXED_SCALE_SHIFT;
scanner->opt[OPT_Y_RESOLUTION].cap |= SANE_CAP_INACTIVE;
/* bind resolution */
scanner->opt[OPT_RESOLUTION_BIND].name = SANE_NAME_RESOLUTION_BIND;
scanner->opt[OPT_RESOLUTION_BIND].title = SANE_TITLE_RESOLUTION_BIND;
scanner->opt[OPT_RESOLUTION_BIND].desc = SANE_DESC_RESOLUTION_BIND;
scanner->opt[OPT_RESOLUTION_BIND].type = SANE_TYPE_BOOL;
scanner->val[OPT_RESOLUTION_BIND].w = SANE_TRUE;
if (scanner->device->common_xy_resolutions) /* disable bind if x and y res have to be the same */
{
scanner->opt[OPT_RESOLUTION_BIND].cap |= SANE_CAP_INACTIVE;
}
/* negative */
scanner->opt[OPT_NEGATIVE].name = SANE_NAME_NEGATIVE;
scanner->opt[OPT_NEGATIVE].title = SANE_TITLE_NEGATIVE;
scanner->opt[OPT_NEGATIVE].desc = SANE_DESC_NEGATIVE;
scanner->opt[OPT_NEGATIVE].type = SANE_TYPE_BOOL;
scanner->val[OPT_NEGATIVE].w = SANE_FALSE;
if (scanner->device->inquiry_reverse_multi == 0)
{
scanner->opt[OPT_NEGATIVE].cap |= SANE_CAP_INACTIVE;
}
/* ------------------------------ */
/* "Geometry" group: */
scanner->opt[OPT_GEOMETRY_GROUP].title = SANE_I18N("Geometry");
scanner->opt[OPT_GEOMETRY_GROUP].desc = "";
scanner->opt[OPT_GEOMETRY_GROUP].type = SANE_TYPE_GROUP;
scanner->opt[OPT_GEOMETRY_GROUP].cap = SANE_CAP_ADVANCED;
scanner->opt[OPT_GEOMETRY_GROUP].constraint_type = SANE_CONSTRAINT_NONE;
/* top-left x */
scanner->opt[OPT_TL_X].name = SANE_NAME_SCAN_TL_X;
scanner->opt[OPT_TL_X].title = SANE_TITLE_SCAN_TL_X;
scanner->opt[OPT_TL_X].desc = SANE_DESC_SCAN_TL_X;
scanner->opt[OPT_TL_X].type = SANE_TYPE_FIXED;
scanner->opt[OPT_TL_X].unit = SANE_UNIT_MM;
scanner->opt[OPT_TL_X].constraint_type = SANE_CONSTRAINT_RANGE;
scanner->opt[OPT_TL_X].constraint.range = &(scanner->device->x_range);
scanner->val[OPT_TL_X].w = 0;
/* top-left y */
scanner->opt[OPT_TL_Y].name = SANE_NAME_SCAN_TL_Y;
scanner->opt[OPT_TL_Y].title = SANE_TITLE_SCAN_TL_Y;
scanner->opt[OPT_TL_Y].desc = SANE_DESC_SCAN_TL_Y;
scanner->opt[OPT_TL_Y].type = SANE_TYPE_FIXED;
scanner->opt[OPT_TL_Y].unit = SANE_UNIT_MM;
scanner->opt[OPT_TL_Y].constraint_type = SANE_CONSTRAINT_RANGE;
scanner->opt[OPT_TL_Y].constraint.range = &(scanner->device->y_range);
scanner->val[OPT_TL_Y].w = 0;
/* bottom-right x */
scanner->opt[OPT_BR_X].name = SANE_NAME_SCAN_BR_X;
scanner->opt[OPT_BR_X].title = SANE_TITLE_SCAN_BR_X;
scanner->opt[OPT_BR_X].desc = SANE_DESC_SCAN_BR_X;
scanner->opt[OPT_BR_X].type = SANE_TYPE_FIXED;
scanner->opt[OPT_BR_X].unit = SANE_UNIT_MM;
scanner->opt[OPT_BR_X].constraint_type = SANE_CONSTRAINT_RANGE;
scanner->opt[OPT_BR_X].constraint.range = &(scanner->device->x_range);
scanner->val[OPT_BR_X].w = scanner->device->x_range.max;
/* bottom-right y */
scanner->opt[OPT_BR_Y].name = SANE_NAME_SCAN_BR_Y;
scanner->opt[OPT_BR_Y].title = SANE_TITLE_SCAN_BR_Y;
scanner->opt[OPT_BR_Y].desc = SANE_DESC_SCAN_BR_Y;
scanner->opt[OPT_BR_Y].type = SANE_TYPE_FIXED;
scanner->opt[OPT_BR_Y].unit = SANE_UNIT_MM;
scanner->opt[OPT_BR_Y].constraint_type = SANE_CONSTRAINT_RANGE;
scanner->opt[OPT_BR_Y].constraint.range = &(scanner->device->y_range);
scanner->val[OPT_BR_Y].w = scanner->device->y_range.max;
/* ------------------------------ */
/* "Enhancement" group: */
scanner->opt[OPT_ENHANCEMENT_GROUP].title = SANE_I18N("Enhancement");
scanner->opt[OPT_ENHANCEMENT_GROUP].desc = "";
scanner->opt[OPT_ENHANCEMENT_GROUP].type = SANE_TYPE_GROUP;
scanner->opt[OPT_ENHANCEMENT_GROUP].cap = 0;
scanner->opt[OPT_ENHANCEMENT_GROUP].constraint_type = SANE_CONSTRAINT_NONE;
/* bit depth */
bit_depths = 0;
if (scanner->device->inquiry_GOB & 1)
{
bit_depth_list[++bit_depths] = 8;
}
if (scanner->device->inquiry_GOB & 2)
{
bit_depth_list[++bit_depths] = 9;
}
if (scanner->device->inquiry_GOB & 4)
{
bit_depth_list[++bit_depths] = 10;
}
if (scanner->device->inquiry_GOB & 8)
{
bit_depth_list[++bit_depths] = 12;
}
if (scanner->device->inquiry_GOB & 16)
{
bit_depth_list[++bit_depths] = 14;
}
if (scanner->device->inquiry_GOB & 32)
{
bit_depth_list[++bit_depths] = 16;
}
bit_depth_list[0] = bit_depths;
scanner->opt[OPT_BIT_DEPTH].name = SANE_NAME_BIT_DEPTH;
scanner->opt[OPT_BIT_DEPTH].title = SANE_TITLE_BIT_DEPTH;
scanner->opt[OPT_BIT_DEPTH].desc = SANE_DESC_BIT_DEPTH;
scanner->opt[OPT_BIT_DEPTH].type = SANE_TYPE_INT;
scanner->opt[OPT_BIT_DEPTH].unit = SANE_UNIT_BIT;
scanner->opt[OPT_BIT_DEPTH].constraint_type = SANE_CONSTRAINT_WORD_LIST;
scanner->opt[OPT_BIT_DEPTH].constraint.word_list = bit_depth_list;
scanner->val[OPT_BIT_DEPTH].w = bit_depth_list[1];
/* quality-calibration */
scanner->opt[OPT_QUALITY].name = SANE_NAME_QUALITY_CAL;
scanner->opt[OPT_QUALITY].title = SANE_TITLE_QUALITY_CAL;
scanner->opt[OPT_QUALITY].desc = SANE_DESC_QUALITY_CAL;
scanner->opt[OPT_QUALITY].type = SANE_TYPE_BOOL;
scanner->val[OPT_QUALITY].w = SANE_FALSE;
if ((scanner->device->inquiry_quality_ctrl == 0) || (scanner->device->force_quality_calibration) )
{
scanner->opt[OPT_QUALITY].cap |= SANE_CAP_INACTIVE;
}
else /* enable quality calibration when available */
{
scanner->val[OPT_QUALITY].w = SANE_TRUE;
}
/* double optical resolution */
scanner->opt[OPT_DOR].name = SANE_NAME_DOR;
scanner->opt[OPT_DOR].title = SANE_TITLE_DOR;
scanner->opt[OPT_DOR].desc = SANE_DESC_DOR;
scanner->opt[OPT_DOR].type = SANE_TYPE_BOOL;
scanner->val[OPT_DOR].w = SANE_FALSE;
if (scanner->device->inquiry_dor == 0)
{
scanner->opt[OPT_DOR].cap |= SANE_CAP_INACTIVE;
}
/* warmup */
scanner->opt[OPT_WARMUP].name = SANE_NAME_WARMUP;
scanner->opt[OPT_WARMUP].title = SANE_TITLE_WARMUP;
scanner->opt[OPT_WARMUP].desc = SANE_DESC_WARMUP;
scanner->opt[OPT_WARMUP].type = SANE_TYPE_BOOL;
scanner->val[OPT_WARMUP].w = SANE_FALSE;
if (scanner->device->inquiry_max_warmup_time == 0)
{
scanner->opt[OPT_WARMUP].cap |= SANE_CAP_INACTIVE;
}
scanner->opt[OPT_RGB_BIND].name = SANE_NAME_RGB_BIND;
scanner->opt[OPT_RGB_BIND].title = SANE_TITLE_RGB_BIND;
scanner->opt[OPT_RGB_BIND].desc = SANE_DESC_RGB_BIND;
scanner->opt[OPT_RGB_BIND].type = SANE_TYPE_BOOL;
scanner->val[OPT_RGB_BIND].w = SANE_FALSE;
/* brightness */
scanner->opt[OPT_BRIGHTNESS].name = SANE_NAME_BRIGHTNESS;
scanner->opt[OPT_BRIGHTNESS].title = SANE_TITLE_BRIGHTNESS;
scanner->opt[OPT_BRIGHTNESS].desc = SANE_DESC_BRIGHTNESS;
scanner->opt[OPT_BRIGHTNESS].type = SANE_TYPE_FIXED;
scanner->opt[OPT_BRIGHTNESS].unit = SANE_UNIT_PERCENT;
scanner->opt[OPT_BRIGHTNESS].constraint_type = SANE_CONSTRAINT_RANGE;
scanner->opt[OPT_BRIGHTNESS].constraint.range = &percentage_range;
scanner->val[OPT_BRIGHTNESS].w = 0;
/* contrast */
scanner->opt[OPT_CONTRAST].name = SANE_NAME_CONTRAST;
scanner->opt[OPT_CONTRAST].title = SANE_TITLE_CONTRAST;
scanner->opt[OPT_CONTRAST].desc = SANE_DESC_CONTRAST;
scanner->opt[OPT_CONTRAST].type = SANE_TYPE_FIXED;
scanner->opt[OPT_CONTRAST].unit = SANE_UNIT_PERCENT;
scanner->opt[OPT_CONTRAST].constraint_type = SANE_CONSTRAINT_RANGE;
scanner->opt[OPT_CONTRAST].constraint.range = &percentage_range;
scanner->val[OPT_CONTRAST].w = 0;
/* threshold */
scanner->opt[OPT_THRESHOLD].name = SANE_NAME_THRESHOLD;
scanner->opt[OPT_THRESHOLD].title = SANE_TITLE_THRESHOLD;
scanner->opt[OPT_THRESHOLD].desc = SANE_DESC_THRESHOLD;
scanner->opt[OPT_THRESHOLD].type = SANE_TYPE_FIXED;
scanner->opt[OPT_THRESHOLD].unit = SANE_UNIT_PERCENT;
scanner->opt[OPT_THRESHOLD].constraint_type = SANE_CONSTRAINT_RANGE;
scanner->opt[OPT_THRESHOLD].constraint.range = &percentage_range_100;
scanner->val[OPT_THRESHOLD].w = SANE_FIX(50);
/* ------------------------------ */
/* highlight, white level */
scanner->opt[OPT_HIGHLIGHT].name = SANE_NAME_HIGHLIGHT;
scanner->opt[OPT_HIGHLIGHT].title = SANE_TITLE_HIGHLIGHT;
scanner->opt[OPT_HIGHLIGHT].desc = SANE_DESC_HIGHLIGHT;
scanner->opt[OPT_HIGHLIGHT].type = SANE_TYPE_FIXED;
scanner->opt[OPT_HIGHLIGHT].unit = SANE_UNIT_PERCENT;
scanner->opt[OPT_HIGHLIGHT].constraint_type = SANE_CONSTRAINT_RANGE;
scanner->opt[OPT_HIGHLIGHT].constraint.range = &percentage_range_100;
scanner->val[OPT_HIGHLIGHT].w = SANE_FIX(100);
scanner->opt[OPT_HIGHLIGHT_R].name = SANE_NAME_HIGHLIGHT_R;
scanner->opt[OPT_HIGHLIGHT_R].title = SANE_TITLE_HIGHLIGHT_R;
scanner->opt[OPT_HIGHLIGHT_R].desc = SANE_DESC_HIGHLIGHT_R;
scanner->opt[OPT_HIGHLIGHT_R].type = SANE_TYPE_FIXED;
scanner->opt[OPT_HIGHLIGHT_R].unit = SANE_UNIT_PERCENT;
scanner->opt[OPT_HIGHLIGHT_R].constraint_type = SANE_CONSTRAINT_RANGE;
scanner->opt[OPT_HIGHLIGHT_R].constraint.range = &percentage_range_100;
scanner->val[OPT_HIGHLIGHT_R].w = SANE_FIX(100);
scanner->opt[OPT_HIGHLIGHT_G].name = SANE_NAME_HIGHLIGHT_G;
scanner->opt[OPT_HIGHLIGHT_G].title = SANE_TITLE_HIGHLIGHT_G;
scanner->opt[OPT_HIGHLIGHT_G].desc = SANE_DESC_HIGHLIGHT_G;
scanner->opt[OPT_HIGHLIGHT_G].type = SANE_TYPE_FIXED;
scanner->opt[OPT_HIGHLIGHT_G].unit = SANE_UNIT_PERCENT;
scanner->opt[OPT_HIGHLIGHT_G].constraint_type = SANE_CONSTRAINT_RANGE;
scanner->opt[OPT_HIGHLIGHT_G].constraint.range = &percentage_range_100;
scanner->val[OPT_HIGHLIGHT_G].w = SANE_FIX(100);
scanner->opt[OPT_HIGHLIGHT_B].name = SANE_NAME_HIGHLIGHT_B;
scanner->opt[OPT_HIGHLIGHT_B].title = SANE_TITLE_HIGHLIGHT_B;
scanner->opt[OPT_HIGHLIGHT_B].desc = SANE_DESC_HIGHLIGHT_B;
scanner->opt[OPT_HIGHLIGHT_B].type = SANE_TYPE_FIXED;
scanner->opt[OPT_HIGHLIGHT_B].unit = SANE_UNIT_PERCENT;
scanner->opt[OPT_HIGHLIGHT_B].constraint_type = SANE_CONSTRAINT_RANGE;
scanner->opt[OPT_HIGHLIGHT_B].constraint.range = &percentage_range_100;
scanner->val[OPT_HIGHLIGHT_B].w = SANE_FIX(100);
/* shadow, black level */
scanner->opt[OPT_SHADOW].name = SANE_NAME_SHADOW;
scanner->opt[OPT_SHADOW].title = SANE_TITLE_SHADOW;
scanner->opt[OPT_SHADOW].desc = SANE_DESC_SHADOW;
scanner->opt[OPT_SHADOW].type = SANE_TYPE_FIXED;
scanner->opt[OPT_SHADOW].unit = SANE_UNIT_PERCENT;
scanner->opt[OPT_SHADOW].constraint_type = SANE_CONSTRAINT_RANGE;
scanner->opt[OPT_SHADOW].constraint.range = &percentage_range_100;
scanner->val[OPT_SHADOW].w = 0;
scanner->opt[OPT_SHADOW_R].name = SANE_NAME_SHADOW_R;
scanner->opt[OPT_SHADOW_R].title = SANE_TITLE_SHADOW_R;
scanner->opt[OPT_SHADOW_R].desc = SANE_DESC_SHADOW_R;
scanner->opt[OPT_SHADOW_R].type = SANE_TYPE_FIXED;
scanner->opt[OPT_SHADOW_R].unit = SANE_UNIT_PERCENT;
scanner->opt[OPT_SHADOW_R].constraint_type = SANE_CONSTRAINT_RANGE;
scanner->opt[OPT_SHADOW_R].constraint.range = &percentage_range_100;
scanner->val[OPT_SHADOW_R].w = 0;
scanner->opt[OPT_SHADOW_G].name = SANE_NAME_SHADOW_G;
scanner->opt[OPT_SHADOW_G].title = SANE_TITLE_SHADOW_G;
scanner->opt[OPT_SHADOW_G].desc = SANE_DESC_SHADOW_G;
scanner->opt[OPT_SHADOW_G].type = SANE_TYPE_FIXED;
scanner->opt[OPT_SHADOW_G].unit = SANE_UNIT_PERCENT;
scanner->opt[OPT_SHADOW_G].constraint_type = SANE_CONSTRAINT_RANGE;
scanner->opt[OPT_SHADOW_G].constraint.range = &percentage_range_100;
scanner->val[OPT_SHADOW_G].w = 0;
scanner->opt[OPT_SHADOW_B].name = SANE_NAME_SHADOW_B;
scanner->opt[OPT_SHADOW_B].title = SANE_TITLE_SHADOW_B;
scanner->opt[OPT_SHADOW_B].desc = SANE_DESC_SHADOW_B;
scanner->opt[OPT_SHADOW_B].type = SANE_TYPE_FIXED;
scanner->opt[OPT_SHADOW_B].unit = SANE_UNIT_PERCENT;
scanner->opt[OPT_SHADOW_B].constraint_type = SANE_CONSTRAINT_RANGE;
scanner->opt[OPT_SHADOW_B].constraint.range = &percentage_range_100;
scanner->val[OPT_SHADOW_B].w = 0;
/* analog-gamma */
scanner->opt[OPT_ANALOG_GAMMA].name = SANE_NAME_ANALOG_GAMMA;
scanner->opt[OPT_ANALOG_GAMMA].title = SANE_TITLE_ANALOG_GAMMA;
scanner->opt[OPT_ANALOG_GAMMA].desc = SANE_DESC_ANALOG_GAMMA;
scanner->opt[OPT_ANALOG_GAMMA].type = SANE_TYPE_FIXED;
scanner->opt[OPT_ANALOG_GAMMA].unit = SANE_UNIT_NONE;
scanner->opt[OPT_ANALOG_GAMMA].constraint_type = SANE_CONSTRAINT_RANGE;
scanner->opt[OPT_ANALOG_GAMMA].constraint.range = &(scanner->device->analog_gamma_range);
scanner->val[OPT_ANALOG_GAMMA].w = 1 << SANE_FIXED_SCALE_SHIFT;
scanner->opt[OPT_ANALOG_GAMMA_R].name = SANE_NAME_ANALOG_GAMMA_R;
scanner->opt[OPT_ANALOG_GAMMA_R].title = SANE_TITLE_ANALOG_GAMMA_R;
scanner->opt[OPT_ANALOG_GAMMA_R].desc = SANE_DESC_ANALOG_GAMMA_R;
scanner->opt[OPT_ANALOG_GAMMA_R].type = SANE_TYPE_FIXED;
scanner->opt[OPT_ANALOG_GAMMA_R].unit = SANE_UNIT_NONE;
scanner->opt[OPT_ANALOG_GAMMA_R].constraint_type = SANE_CONSTRAINT_RANGE;
scanner->opt[OPT_ANALOG_GAMMA_R].constraint.range = &(scanner->device->analog_gamma_range);
scanner->val[OPT_ANALOG_GAMMA_R].w = 1 << SANE_FIXED_SCALE_SHIFT;
scanner->opt[OPT_ANALOG_GAMMA_G].name = SANE_NAME_ANALOG_GAMMA_G;
scanner->opt[OPT_ANALOG_GAMMA_G].title = SANE_TITLE_ANALOG_GAMMA_G;
scanner->opt[OPT_ANALOG_GAMMA_G].desc = SANE_DESC_ANALOG_GAMMA_G;
scanner->opt[OPT_ANALOG_GAMMA_G].type = SANE_TYPE_FIXED;
scanner->opt[OPT_ANALOG_GAMMA_G].unit = SANE_UNIT_NONE;
scanner->opt[OPT_ANALOG_GAMMA_G].constraint_type = SANE_CONSTRAINT_RANGE;
scanner->opt[OPT_ANALOG_GAMMA_G].constraint.range = &(scanner->device->analog_gamma_range);
scanner->val[OPT_ANALOG_GAMMA_G].w = 1 << SANE_FIXED_SCALE_SHIFT;
scanner->opt[OPT_ANALOG_GAMMA_B].name = SANE_NAME_ANALOG_GAMMA_B;
scanner->opt[OPT_ANALOG_GAMMA_B].title = SANE_TITLE_ANALOG_GAMMA_B;
scanner->opt[OPT_ANALOG_GAMMA_B].desc = SANE_DESC_ANALOG_GAMMA_B;
scanner->opt[OPT_ANALOG_GAMMA_B].type = SANE_TYPE_FIXED;
scanner->opt[OPT_ANALOG_GAMMA_B].unit = SANE_UNIT_NONE;
scanner->opt[OPT_ANALOG_GAMMA_B].constraint_type = SANE_CONSTRAINT_RANGE;
scanner->opt[OPT_ANALOG_GAMMA_B].constraint.range = &(scanner->device->analog_gamma_range);
scanner->val[OPT_ANALOG_GAMMA_B].w = 1 << SANE_FIXED_SCALE_SHIFT;
/* custom-gamma table */
scanner->opt[OPT_CUSTOM_GAMMA].name = SANE_NAME_CUSTOM_GAMMA;
scanner->opt[OPT_CUSTOM_GAMMA].title = SANE_TITLE_CUSTOM_GAMMA;
scanner->opt[OPT_CUSTOM_GAMMA].desc = SANE_DESC_CUSTOM_GAMMA;
scanner->opt[OPT_CUSTOM_GAMMA].type = SANE_TYPE_BOOL;
scanner->val[OPT_CUSTOM_GAMMA].w = SANE_TRUE;
/* grayscale gamma vector */
scanner->opt[OPT_GAMMA_VECTOR].name = SANE_NAME_GAMMA_VECTOR;
scanner->opt[OPT_GAMMA_VECTOR].title = SANE_TITLE_GAMMA_VECTOR;
scanner->opt[OPT_GAMMA_VECTOR].desc = SANE_DESC_GAMMA_VECTOR;
scanner->opt[OPT_GAMMA_VECTOR].type = SANE_TYPE_INT;
scanner->opt[OPT_GAMMA_VECTOR].unit = SANE_UNIT_NONE;
scanner->opt[OPT_GAMMA_VECTOR].constraint_type = SANE_CONSTRAINT_RANGE;
scanner->val[OPT_GAMMA_VECTOR].wa = scanner->gamma_table[0];
scanner->opt[OPT_GAMMA_VECTOR].constraint.range = &scanner->output_range;
scanner->opt[OPT_GAMMA_VECTOR].size = scanner->gamma_length * sizeof(SANE_Word);
scanner->output_range.min = 0;
if (bit_depth_list[1] == 8)
{
scanner->output_range.max = 255; /* 8 bits/pixel */
}
else
{
scanner->output_range.max = 65535; /* 9-16 bits/pixel */
}
scanner->output_range.quant = 0;
/* red gamma vector */
scanner->opt[OPT_GAMMA_VECTOR_R].name = SANE_NAME_GAMMA_VECTOR_R;
scanner->opt[OPT_GAMMA_VECTOR_R].title = SANE_TITLE_GAMMA_VECTOR_R;
scanner->opt[OPT_GAMMA_VECTOR_R].desc = SANE_DESC_GAMMA_VECTOR_R;
scanner->opt[OPT_GAMMA_VECTOR_R].type = SANE_TYPE_INT;
scanner->opt[OPT_GAMMA_VECTOR_R].unit = SANE_UNIT_NONE;
scanner->opt[OPT_GAMMA_VECTOR_R].constraint_type = SANE_CONSTRAINT_RANGE;
scanner->val[OPT_GAMMA_VECTOR_R].wa = scanner->gamma_table[1];
scanner->opt[OPT_GAMMA_VECTOR_R].constraint.range = &(scanner->gamma_range);
scanner->opt[OPT_GAMMA_VECTOR_R].size = scanner->gamma_length * sizeof(SANE_Word);
/* green gamma vector */
scanner->opt[OPT_GAMMA_VECTOR_G].name = SANE_NAME_GAMMA_VECTOR_G;
scanner->opt[OPT_GAMMA_VECTOR_G].title = SANE_TITLE_GAMMA_VECTOR_G;
scanner->opt[OPT_GAMMA_VECTOR_G].desc = SANE_DESC_GAMMA_VECTOR_G;
scanner->opt[OPT_GAMMA_VECTOR_G].type = SANE_TYPE_INT;
scanner->opt[OPT_GAMMA_VECTOR_G].unit = SANE_UNIT_NONE;
scanner->opt[OPT_GAMMA_VECTOR_G].constraint_type = SANE_CONSTRAINT_RANGE;
scanner->val[OPT_GAMMA_VECTOR_G].wa = scanner->gamma_table[2];
scanner->opt[OPT_GAMMA_VECTOR_G].constraint.range = &(scanner->gamma_range);
scanner->opt[OPT_GAMMA_VECTOR_G].size = scanner->gamma_length * sizeof(SANE_Word);
/* blue gamma vector */
scanner->opt[OPT_GAMMA_VECTOR_B].name = SANE_NAME_GAMMA_VECTOR_B;
scanner->opt[OPT_GAMMA_VECTOR_B].title = SANE_TITLE_GAMMA_VECTOR_B;
scanner->opt[OPT_GAMMA_VECTOR_B].desc = SANE_DESC_GAMMA_VECTOR_B;
scanner->opt[OPT_GAMMA_VECTOR_B].type = SANE_TYPE_INT;
scanner->opt[OPT_GAMMA_VECTOR_B].unit = SANE_UNIT_NONE;
scanner->opt[OPT_GAMMA_VECTOR_B].constraint_type = SANE_CONSTRAINT_RANGE;
scanner->val[OPT_GAMMA_VECTOR_B].wa = scanner->gamma_table[3];
scanner->opt[OPT_GAMMA_VECTOR_B].constraint.range = &(scanner->gamma_range);
scanner->opt[OPT_GAMMA_VECTOR_B].size = scanner->gamma_length * sizeof(SANE_Word);
/* halftone dimension */
scanner->opt[OPT_HALFTONE_DIMENSION].name = SANE_NAME_HALFTONE_DIMENSION;
scanner->opt[OPT_HALFTONE_DIMENSION].title = SANE_TITLE_HALFTONE_DIMENSION;
scanner->opt[OPT_HALFTONE_DIMENSION].desc = SANE_DESC_HALFTONE_DIMENSION;
scanner->opt[OPT_HALFTONE_DIMENSION].type = SANE_TYPE_INT;
scanner->opt[OPT_HALFTONE_DIMENSION].unit = SANE_UNIT_PIXEL;
scanner->opt[OPT_HALFTONE_DIMENSION].constraint_type = SANE_CONSTRAINT_WORD_LIST;
scanner->opt[OPT_HALFTONE_DIMENSION].constraint.word_list = pattern_dim_list;
scanner->val[OPT_HALFTONE_DIMENSION].w = pattern_dim_list[1];
/* halftone pattern */
scanner->opt[OPT_HALFTONE_PATTERN].name = SANE_NAME_HALFTONE_PATTERN;
scanner->opt[OPT_HALFTONE_PATTERN].title = SANE_TITLE_HALFTONE_PATTERN;
scanner->opt[OPT_HALFTONE_PATTERN].desc = SANE_DESC_HALFTONE_PATTERN;
scanner->opt[OPT_HALFTONE_PATTERN].type = SANE_TYPE_INT;
scanner->opt[OPT_HALFTONE_PATTERN].size = 0;
scanner->opt[OPT_HALFTONE_PATTERN].constraint_type = SANE_CONSTRAINT_RANGE;
scanner->opt[OPT_HALFTONE_PATTERN].constraint.range = &u8_range;
scanner->val[OPT_HALFTONE_PATTERN].wa = scanner->halftone_pattern;
/* ------------------------------ */
/* "Advanced" group: */
scanner->opt[OPT_ADVANCED_GROUP].title = SANE_I18N("Advanced");
scanner->opt[OPT_ADVANCED_GROUP].desc = "";
scanner->opt[OPT_ADVANCED_GROUP].type = SANE_TYPE_GROUP;
scanner->opt[OPT_ADVANCED_GROUP].cap = SANE_CAP_ADVANCED;
scanner->opt[OPT_ADVANCED_GROUP].constraint_type = SANE_CONSTRAINT_NONE;
/* ------------------------------ */
/* select exposure time */
scanner->opt[OPT_SELECT_EXPOSURE_TIME].name = SANE_NAME_SELECT_EXPOSURE_TIME;
scanner->opt[OPT_SELECT_EXPOSURE_TIME].title = SANE_TITLE_SELECT_EXPOSURE_TIME;
scanner->opt[OPT_SELECT_EXPOSURE_TIME].desc = SANE_DESC_SELECT_EXPOSURE_TIME;
scanner->opt[OPT_SELECT_EXPOSURE_TIME].type = SANE_TYPE_BOOL;
scanner->val[OPT_SELECT_EXPOSURE_TIME].w = SANE_FALSE;
/* select calibration exposure time */
scanner->opt[OPT_SELECT_CAL_EXPOSURE_TIME].name = SANE_UMAX_NAME_SELECT_CALIBRATON_EXPOSURE_TIME;
scanner->opt[OPT_SELECT_CAL_EXPOSURE_TIME].title = SANE_UMAX_TITLE_SELECT_CALIBRATION_EXPOSURE_TIME;
scanner->opt[OPT_SELECT_CAL_EXPOSURE_TIME].desc = SANE_UMAX_DESC_SELECT_CALIBRATION_EXPOSURE_TIME;
scanner->opt[OPT_SELECT_CAL_EXPOSURE_TIME].type = SANE_TYPE_BOOL;
scanner->val[OPT_SELECT_CAL_EXPOSURE_TIME].w = SANE_FALSE;
scanner->opt[OPT_SELECT_CAL_EXPOSURE_TIME].cap |= SANE_CAP_INACTIVE;
/* calibration exposure time */
scanner->opt[OPT_CAL_EXPOS_TIME].name = SANE_NAME_CAL_EXPOS_TIME;
scanner->opt[OPT_CAL_EXPOS_TIME].title = SANE_TITLE_CAL_EXPOS_TIME;
scanner->opt[OPT_CAL_EXPOS_TIME].desc = SANE_DESC_CAL_EXPOS_TIME;
scanner->opt[OPT_CAL_EXPOS_TIME].type = SANE_TYPE_INT;
scanner->opt[OPT_CAL_EXPOS_TIME].unit = SANE_UNIT_MICROSECOND;
scanner->opt[OPT_CAL_EXPOS_TIME].constraint_type = SANE_CONSTRAINT_RANGE;
scanner->opt[OPT_CAL_EXPOS_TIME].constraint.range = &(scanner->exposure_time_range);
scanner->val[OPT_CAL_EXPOS_TIME].w = scanner->device->inquiry_exposure_time_g_fb_def *
scanner->device->inquiry_exposure_time_step_unit;
scanner->opt[OPT_CAL_EXPOS_TIME].cap |= SANE_CAP_INACTIVE;
/* calibration exposure time red */
scanner->opt[OPT_CAL_EXPOS_TIME_R].name = SANE_NAME_CAL_EXPOS_TIME_R;
scanner->opt[OPT_CAL_EXPOS_TIME_R].title = SANE_TITLE_CAL_EXPOS_TIME_R;
scanner->opt[OPT_CAL_EXPOS_TIME_R].desc = SANE_DESC_CAL_EXPOS_TIME_R;
scanner->opt[OPT_CAL_EXPOS_TIME_R].type = SANE_TYPE_INT;
scanner->opt[OPT_CAL_EXPOS_TIME_R].unit = SANE_UNIT_MICROSECOND;
scanner->opt[OPT_CAL_EXPOS_TIME_R].constraint_type = SANE_CONSTRAINT_RANGE;
scanner->opt[OPT_CAL_EXPOS_TIME_R].constraint.range = &(scanner->exposure_time_range);
scanner->val[OPT_CAL_EXPOS_TIME_R].w = scanner->device->inquiry_exposure_time_c_fb_def_r *
scanner->device->inquiry_exposure_time_step_unit;
scanner->opt[OPT_CAL_EXPOS_TIME_R].cap |= SANE_CAP_INACTIVE;
/* calibration exposure time green */
scanner->opt[OPT_CAL_EXPOS_TIME_G].name = SANE_NAME_CAL_EXPOS_TIME_G;
scanner->opt[OPT_CAL_EXPOS_TIME_G].title = SANE_TITLE_CAL_EXPOS_TIME_G;
scanner->opt[OPT_CAL_EXPOS_TIME_G].desc = SANE_DESC_CAL_EXPOS_TIME_G;
scanner->opt[OPT_CAL_EXPOS_TIME_G].type = SANE_TYPE_INT;
scanner->opt[OPT_CAL_EXPOS_TIME_G].unit = SANE_UNIT_MICROSECOND;
scanner->opt[OPT_CAL_EXPOS_TIME_G].constraint_type = SANE_CONSTRAINT_RANGE;
scanner->opt[OPT_CAL_EXPOS_TIME_G].constraint.range = &(scanner->exposure_time_range);
scanner->val[OPT_CAL_EXPOS_TIME_G].w = scanner->device->inquiry_exposure_time_c_fb_def_g *
scanner->device->inquiry_exposure_time_step_unit;
scanner->opt[OPT_CAL_EXPOS_TIME_G].cap |= SANE_CAP_INACTIVE;
/* calibration exposure time blue */
scanner->opt[OPT_CAL_EXPOS_TIME_B].name = SANE_NAME_CAL_EXPOS_TIME_B;
scanner->opt[OPT_CAL_EXPOS_TIME_B].title = SANE_TITLE_CAL_EXPOS_TIME_B;
scanner->opt[OPT_CAL_EXPOS_TIME_B].desc = SANE_DESC_CAL_EXPOS_TIME_B;
scanner->opt[OPT_CAL_EXPOS_TIME_B].type = SANE_TYPE_INT;
scanner->opt[OPT_CAL_EXPOS_TIME_B].unit = SANE_UNIT_MICROSECOND;
scanner->opt[OPT_CAL_EXPOS_TIME_B].constraint_type = SANE_CONSTRAINT_RANGE;
scanner->opt[OPT_CAL_EXPOS_TIME_B].constraint.range = &(scanner->exposure_time_range);
scanner->val[OPT_CAL_EXPOS_TIME_B].w = scanner->device->inquiry_exposure_time_c_fb_def_b *
scanner->device->inquiry_exposure_time_step_unit;
scanner->opt[OPT_CAL_EXPOS_TIME_B].cap |= SANE_CAP_INACTIVE;
/* scan exposure time */
scanner->opt[OPT_SCAN_EXPOS_TIME].name = SANE_NAME_SCAN_EXPOS_TIME;
scanner->opt[OPT_SCAN_EXPOS_TIME].title = SANE_TITLE_SCAN_EXPOS_TIME;
scanner->opt[OPT_SCAN_EXPOS_TIME].desc = SANE_DESC_SCAN_EXPOS_TIME;
scanner->opt[OPT_SCAN_EXPOS_TIME].type = SANE_TYPE_INT;
scanner->opt[OPT_SCAN_EXPOS_TIME].unit = SANE_UNIT_MICROSECOND;
scanner->opt[OPT_SCAN_EXPOS_TIME].constraint_type = SANE_CONSTRAINT_RANGE;
scanner->opt[OPT_SCAN_EXPOS_TIME].constraint.range = &(scanner->exposure_time_range);
scanner->val[OPT_SCAN_EXPOS_TIME].w = scanner->device->inquiry_exposure_time_g_fb_def *
scanner->device->inquiry_exposure_time_step_unit;
scanner->opt[OPT_SCAN_EXPOS_TIME].cap |= SANE_CAP_INACTIVE;
/* scan exposure time red */
scanner->opt[OPT_SCAN_EXPOS_TIME_R].name = SANE_NAME_SCAN_EXPOS_TIME_R;
scanner->opt[OPT_SCAN_EXPOS_TIME_R].title = SANE_TITLE_SCAN_EXPOS_TIME_R;
scanner->opt[OPT_SCAN_EXPOS_TIME_R].desc = SANE_DESC_SCAN_EXPOS_TIME_R;
scanner->opt[OPT_SCAN_EXPOS_TIME_R].type = SANE_TYPE_INT;
scanner->opt[OPT_SCAN_EXPOS_TIME_R].unit = SANE_UNIT_MICROSECOND;
scanner->opt[OPT_SCAN_EXPOS_TIME_R].constraint_type = SANE_CONSTRAINT_RANGE;
scanner->opt[OPT_SCAN_EXPOS_TIME_R].constraint.range = &(scanner->exposure_time_range);
scanner->val[OPT_SCAN_EXPOS_TIME_R].w = scanner->device->inquiry_exposure_time_c_fb_def_r *
scanner->device->inquiry_exposure_time_step_unit;
scanner->opt[OPT_SCAN_EXPOS_TIME_R].cap |= SANE_CAP_INACTIVE;
/* scan exposure time green */
scanner->opt[OPT_SCAN_EXPOS_TIME_G].name = SANE_NAME_SCAN_EXPOS_TIME_G;
scanner->opt[OPT_SCAN_EXPOS_TIME_G].title = SANE_TITLE_SCAN_EXPOS_TIME_G;
scanner->opt[OPT_SCAN_EXPOS_TIME_G].desc = SANE_DESC_SCAN_EXPOS_TIME_G;
scanner->opt[OPT_SCAN_EXPOS_TIME_G].type = SANE_TYPE_INT;
scanner->opt[OPT_SCAN_EXPOS_TIME_G].unit = SANE_UNIT_MICROSECOND;
scanner->opt[OPT_SCAN_EXPOS_TIME_G].constraint_type = SANE_CONSTRAINT_RANGE;
scanner->opt[OPT_SCAN_EXPOS_TIME_G].constraint.range = &(scanner->exposure_time_range);
scanner->val[OPT_SCAN_EXPOS_TIME_G].w = scanner->device->inquiry_exposure_time_c_fb_def_g *
scanner->device->inquiry_exposure_time_step_unit;
scanner->opt[OPT_SCAN_EXPOS_TIME_G].cap |= SANE_CAP_INACTIVE;
/* scan exposure time blue */
scanner->opt[OPT_SCAN_EXPOS_TIME_B].name = SANE_NAME_SCAN_EXPOS_TIME_B;
scanner->opt[OPT_SCAN_EXPOS_TIME_B].title = SANE_TITLE_SCAN_EXPOS_TIME_B;
scanner->opt[OPT_SCAN_EXPOS_TIME_B].desc = SANE_DESC_SCAN_EXPOS_TIME_B;
scanner->opt[OPT_SCAN_EXPOS_TIME_B].type = SANE_TYPE_INT;
scanner->opt[OPT_SCAN_EXPOS_TIME_B].unit = SANE_UNIT_MICROSECOND;
scanner->opt[OPT_SCAN_EXPOS_TIME_B].constraint_type = SANE_CONSTRAINT_RANGE;
scanner->opt[OPT_SCAN_EXPOS_TIME_B].constraint.range = &(scanner->exposure_time_range);
scanner->val[OPT_SCAN_EXPOS_TIME_B].w = scanner->device->inquiry_exposure_time_c_fb_def_b *
scanner->device->inquiry_exposure_time_step_unit;
scanner->opt[OPT_SCAN_EXPOS_TIME_B].cap |= SANE_CAP_INACTIVE;
if (scanner->device->inquiry_exposure_adj == 0)
{
scanner->opt[OPT_SELECT_EXPOSURE_TIME].cap |= SANE_CAP_INACTIVE;
}
/* ------------------------------ */
/* select calibration lamp density */
scanner->opt[OPT_SELECT_LAMP_DENSITY].name = SANE_NAME_SELECT_LAMP_DENSITY;
scanner->opt[OPT_SELECT_LAMP_DENSITY].title = SANE_TITLE_SELECT_LAMP_DENSITY;
scanner->opt[OPT_SELECT_LAMP_DENSITY].desc = SANE_DESC_SELECT_LAMP_DENSITY;
scanner->opt[OPT_SELECT_LAMP_DENSITY].type = SANE_TYPE_BOOL;
scanner->val[OPT_SELECT_LAMP_DENSITY].w = SANE_FALSE;
/* calibration lamp density */
scanner->opt[OPT_CAL_LAMP_DEN].name = SANE_NAME_CAL_LAMP_DEN;
scanner->opt[OPT_CAL_LAMP_DEN].title = SANE_TITLE_CAL_LAMP_DEN;
scanner->opt[OPT_CAL_LAMP_DEN].desc = SANE_DESC_CAL_LAMP_DEN;
scanner->opt[OPT_CAL_LAMP_DEN].type = SANE_TYPE_FIXED;
scanner->opt[OPT_CAL_LAMP_DEN].unit = SANE_UNIT_PERCENT;
scanner->opt[OPT_CAL_LAMP_DEN].constraint_type = SANE_CONSTRAINT_RANGE;
scanner->opt[OPT_CAL_LAMP_DEN].constraint.range = &percentage_range_100;
scanner->val[OPT_CAL_LAMP_DEN].w = SANE_FIX(50);
scanner->opt[OPT_CAL_LAMP_DEN].cap |= SANE_CAP_INACTIVE;
/* scan lamp density */
scanner->opt[OPT_SCAN_LAMP_DEN].name = SANE_NAME_SCAN_LAMP_DEN;
scanner->opt[OPT_SCAN_LAMP_DEN].title = SANE_TITLE_SCAN_LAMP_DEN;
scanner->opt[OPT_SCAN_LAMP_DEN].desc = SANE_DESC_SCAN_LAMP_DEN;
scanner->opt[OPT_SCAN_LAMP_DEN].type = SANE_TYPE_FIXED;
scanner->opt[OPT_SCAN_LAMP_DEN].unit = SANE_UNIT_PERCENT;
scanner->opt[OPT_SCAN_LAMP_DEN].constraint_type = SANE_CONSTRAINT_RANGE;
scanner->opt[OPT_SCAN_LAMP_DEN].constraint.range = &percentage_range_100;
scanner->val[OPT_SCAN_LAMP_DEN].w = SANE_FIX(50);
scanner->opt[OPT_SCAN_LAMP_DEN].cap |= SANE_CAP_INACTIVE;
if (scanner->device->inquiry_lamp_ctrl == 0)
{
scanner->opt[OPT_SELECT_LAMP_DENSITY].cap |= SANE_CAP_INACTIVE;
}
/* ------------------------------ */
/* disable pre focus */
scanner->opt[OPT_DISABLE_PRE_FOCUS].name = "disable-pre-focus";
scanner->opt[OPT_DISABLE_PRE_FOCUS].title = SANE_I18N("Disable pre focus");
scanner->opt[OPT_DISABLE_PRE_FOCUS].desc = SANE_I18N("Do not calibrate focus");
scanner->opt[OPT_DISABLE_PRE_FOCUS].type = SANE_TYPE_BOOL;
scanner->val[OPT_DISABLE_PRE_FOCUS].w = SANE_FALSE;
if (scanner->device->inquiry_manual_focus == 0)
{
scanner->opt[OPT_DISABLE_PRE_FOCUS].cap |= SANE_CAP_INACTIVE;
}
/* manual pre focus */
scanner->opt[OPT_MANUAL_PRE_FOCUS].name = "manual-pre-focus";
scanner->opt[OPT_MANUAL_PRE_FOCUS].title = SANE_I18N("Manual pre focus");
scanner->opt[OPT_MANUAL_PRE_FOCUS].desc = "";
scanner->opt[OPT_MANUAL_PRE_FOCUS].type = SANE_TYPE_BOOL;
scanner->val[OPT_MANUAL_PRE_FOCUS].w = SANE_FALSE;
if (scanner->device->inquiry_manual_focus == 0)
{
scanner->opt[OPT_MANUAL_PRE_FOCUS].cap |= SANE_CAP_INACTIVE;
}
/* fix focus position */
scanner->opt[OPT_FIX_FOCUS_POSITION].name = "fix-focus-position";
scanner->opt[OPT_FIX_FOCUS_POSITION].title = SANE_I18N("Fix focus position");
scanner->opt[OPT_FIX_FOCUS_POSITION].desc = "";
scanner->opt[OPT_FIX_FOCUS_POSITION].type = SANE_TYPE_BOOL;
scanner->val[OPT_FIX_FOCUS_POSITION].w = SANE_FALSE;
if (scanner->device->inquiry_manual_focus == 0)
{
scanner->opt[OPT_FIX_FOCUS_POSITION].cap |= SANE_CAP_INACTIVE;
}
/* lens calibration in doc position */
scanner->opt[OPT_LENS_CALIBRATION_DOC_POS].name = "lens-calibration-in-doc-position";
scanner->opt[OPT_LENS_CALIBRATION_DOC_POS].title = SANE_I18N("Lens calibration in doc position");
scanner->opt[OPT_LENS_CALIBRATION_DOC_POS].desc = SANE_I18N("Calibrate lens focus in document position");
scanner->opt[OPT_LENS_CALIBRATION_DOC_POS].type = SANE_TYPE_BOOL;
scanner->val[OPT_LENS_CALIBRATION_DOC_POS].w = SANE_FALSE;
if (scanner->device->inquiry_lens_cal_in_doc_pos == 0)
{
scanner->opt[OPT_LENS_CALIBRATION_DOC_POS].cap |= SANE_CAP_INACTIVE;
}
/* 0mm holder focus position */
scanner->opt[OPT_HOLDER_FOCUS_POS_0MM].name = "holder-focus-position-0mm";
scanner->opt[OPT_HOLDER_FOCUS_POS_0MM].title = SANE_I18N("Holder focus position 0mm");
scanner->opt[OPT_HOLDER_FOCUS_POS_0MM].desc = SANE_I18N("Use 0mm holder focus position instead of 0.6mm");
scanner->opt[OPT_HOLDER_FOCUS_POS_0MM].type = SANE_TYPE_BOOL;
scanner->val[OPT_HOLDER_FOCUS_POS_0MM].w = SANE_FALSE;
if (scanner->device->inquiry_sel_uta_lens_cal_pos == 0)
{
scanner->opt[OPT_HOLDER_FOCUS_POS_0MM].cap |= SANE_CAP_INACTIVE;
}
/* ------------------------------ */
/* lamp on */
scanner->opt[OPT_LAMP_ON].name = "lamp-on";
scanner->opt[OPT_LAMP_ON].title = SANE_I18N("Lamp on");
scanner->opt[OPT_LAMP_ON].desc = SANE_I18N("Turn on scanner lamp");
scanner->opt[OPT_LAMP_ON].type = SANE_TYPE_BUTTON;
scanner->opt[OPT_LAMP_ON].unit = SANE_UNIT_NONE;
scanner->opt[OPT_LAMP_ON].size = 0;
scanner->opt[OPT_LAMP_ON].constraint_type = SANE_CONSTRAINT_NONE;
scanner->val[OPT_LAMP_ON].w = 0;
if (!scanner->device->lamp_control_available) /* lamp state can not be controlled by driver */
{
scanner->opt[OPT_LAMP_ON].cap |= SANE_CAP_INACTIVE;
}
/* ------------------------------ */
/* lamp off */
scanner->opt[OPT_LAMP_OFF].name = "lamp-off";
scanner->opt[OPT_LAMP_OFF].title = SANE_I18N("Lamp off");
scanner->opt[OPT_LAMP_OFF].desc = SANE_I18N("Turn off scanner lamp");
scanner->opt[OPT_LAMP_OFF].type = SANE_TYPE_BUTTON;
scanner->opt[OPT_LAMP_OFF].unit = SANE_UNIT_NONE;
scanner->opt[OPT_LAMP_OFF].size = 0;
scanner->opt[OPT_LAMP_OFF].constraint_type = SANE_CONSTRAINT_NONE;
scanner->val[OPT_LAMP_OFF].w = 0;
if (!scanner->device->lamp_control_available) /* lamp state can not be controlled by driver */
{
scanner->opt[OPT_LAMP_OFF].cap |= SANE_CAP_INACTIVE;
}
/* ------------------------------ */
/* lamp off at exit */
scanner->opt[OPT_LAMP_OFF_AT_EXIT].name = "lamp-off-at-exit";
scanner->opt[OPT_LAMP_OFF_AT_EXIT].title = SANE_I18N("Lamp off at exit");
scanner->opt[OPT_LAMP_OFF_AT_EXIT].desc = SANE_I18N("Turn off lamp when program exits");
scanner->opt[OPT_LAMP_OFF_AT_EXIT].type = SANE_TYPE_BOOL;
scanner->val[OPT_LAMP_OFF_AT_EXIT].w = SANE_FALSE;
if (!scanner->device->lamp_control_available) /* lamp state can not be controlled by driver */
{
scanner->opt[OPT_LAMP_OFF_AT_EXIT].cap |= SANE_CAP_INACTIVE;
}
/* ------------------------------ */
/* batch-scan-start */
scanner->opt[OPT_BATCH_SCAN_START].name = SANE_NAME_BATCH_SCAN_START;
scanner->opt[OPT_BATCH_SCAN_START].title = SANE_TITLE_BATCH_SCAN_START;
scanner->opt[OPT_BATCH_SCAN_START].desc = SANE_DESC_BATCH_SCAN_START;
scanner->opt[OPT_BATCH_SCAN_START].type = SANE_TYPE_BOOL;
scanner->val[OPT_BATCH_SCAN_START].w = SANE_FALSE;
/* batch-scan-loop */
scanner->opt[OPT_BATCH_SCAN_LOOP].name = SANE_NAME_BATCH_SCAN_LOOP;
scanner->opt[OPT_BATCH_SCAN_LOOP].title = SANE_TITLE_BATCH_SCAN_LOOP;
scanner->opt[OPT_BATCH_SCAN_LOOP].desc = SANE_DESC_BATCH_SCAN_LOOP;
scanner->opt[OPT_BATCH_SCAN_LOOP].type = SANE_TYPE_BOOL;
scanner->val[OPT_BATCH_SCAN_LOOP].w = SANE_FALSE;
/* batch-scan-end */
scanner->opt[OPT_BATCH_SCAN_END].name = SANE_NAME_BATCH_SCAN_END;
scanner->opt[OPT_BATCH_SCAN_END].title = SANE_TITLE_BATCH_SCAN_END;
scanner->opt[OPT_BATCH_SCAN_END].desc = SANE_DESC_BATCH_SCAN_END;
scanner->opt[OPT_BATCH_SCAN_END].type = SANE_TYPE_BOOL;
scanner->val[OPT_BATCH_SCAN_END].w = SANE_FALSE;
/* batch-scan-next-y */
scanner->opt[OPT_BATCH_NEXT_TL_Y].name = SANE_NAME_BATCH_NEXT_TL_Y;
scanner->opt[OPT_BATCH_NEXT_TL_Y].title = SANE_TITLE_BATCH_NEXT_TL_Y;
scanner->opt[OPT_BATCH_NEXT_TL_Y].desc = SANE_DESC_BATCH_NEXT_TL_Y;
scanner->opt[OPT_BATCH_NEXT_TL_Y].type = SANE_TYPE_FIXED;
scanner->opt[OPT_BATCH_NEXT_TL_Y].unit = SANE_UNIT_MM;
scanner->opt[OPT_BATCH_NEXT_TL_Y].constraint_type = SANE_CONSTRAINT_RANGE;
scanner->opt[OPT_BATCH_NEXT_TL_Y].constraint.range = &(scanner->device->y_range);
scanner->val[OPT_BATCH_NEXT_TL_Y].w = 0xFFFF; /* mark value as not touched */
if (scanner->device->inquiry_batch_scan == 0)
{
scanner->opt[OPT_BATCH_SCAN_START].cap |= SANE_CAP_INACTIVE;
scanner->opt[OPT_BATCH_SCAN_LOOP].cap |= SANE_CAP_INACTIVE;
scanner->opt[OPT_BATCH_SCAN_END].cap |= SANE_CAP_INACTIVE;
scanner->opt[OPT_BATCH_NEXT_TL_Y].cap |= SANE_CAP_INACTIVE;
}
/* ------------------------------ */
#ifdef UMAX_CALIBRATION_MODE_SELECTABLE
/* calibration mode */
scanner->opt[OPT_CALIB_MODE].name = "calibrationmode";
scanner->opt[OPT_CALIB_MODE].title = SANE_I18N("Calibration mode");
scanner->opt[OPT_CALIB_MODE].desc = SANE_I18N("Define calibration mode");
scanner->opt[OPT_CALIB_MODE].type = SANE_TYPE_STRING;
scanner->opt[OPT_CALIB_MODE].size = max_string_size(calibration_list);
scanner->opt[OPT_CALIB_MODE].constraint_type = SANE_CONSTRAINT_STRING_LIST;
scanner->opt[OPT_CALIB_MODE].constraint.string_list = calibration_list;
scanner->val[OPT_CALIB_MODE].s = (SANE_Char*)strdup(calibration_list[0]);
if (scanner->device->inquiry_calibration == 0)
{
scanner->opt[OPT_CALIB_MODE].cap |= SANE_CAP_INACTIVE;
}
#endif
/* preview */
scanner->opt[OPT_PREVIEW].name = SANE_NAME_PREVIEW;
scanner->opt[OPT_PREVIEW].title = SANE_TITLE_PREVIEW;
scanner->opt[OPT_PREVIEW].desc = SANE_DESC_PREVIEW;
scanner->opt[OPT_PREVIEW].type = SANE_TYPE_BOOL;
scanner->opt[OPT_PREVIEW].cap = SANE_CAP_SOFT_DETECT | SANE_CAP_SOFT_SELECT;
scanner->val[OPT_PREVIEW].w = SANE_FALSE;
sane_control_option(scanner, OPT_MODE, SANE_ACTION_SET_VALUE,
(SANE_String *) scan_mode_list[scan_modes], NULL );
return SANE_STATUS_GOOD;
}
/* ------------------------------------------------------------ ATTACH ONE SCSI ----------------------------- */
/* callback function for sanei_config_attach_matching_devices(dev_name, attach_one_scsi) */
static SANE_Status attach_one_scsi(const char *name)
{
attach_scanner(name, 0, SANE_UMAX_SCSI);
return SANE_STATUS_GOOD;
}
/* ------------------------------------------------------------ ATTACH ONE USB ------------------------------ */
/* callback function for sanei_usb_attach_matching_devices(dev_name, attach_one_usb) */
static SANE_Status attach_one_usb(const char *name)
{
attach_scanner(name, 0, SANE_UMAX_USB);
return SANE_STATUS_GOOD;
}
/* ------------------------------------------------------------ UMAX TEST CONFIGURE OPTION ------------------ */
static SANE_Status umax_test_configure_option(const char *option_str, char *test_name, int *test_value, int test_min, int test_max)
/* returns with 1 if option was found, 0 if option was not found */
{
const char *value_str;
char *end_ptr;
int value;
if (strncmp(option_str, test_name, strlen(test_name)) == 0)
{
value_str = sanei_config_skip_whitespace(option_str+strlen(test_name));
errno = 0;
value = strtol(value_str, &end_ptr, 10);
if (end_ptr == value_str || errno)
{
DBG(DBG_error, "ERROR: invalid value \"%s\" for option %s in %s\n", value_str, test_name, UMAX_CONFIG_FILE);
}
else
{
if (value < test_min)
{
DBG(DBG_error, "ERROR: value \"%d\" is too small for option %s in %s\n", value, test_name, UMAX_CONFIG_FILE);
value = test_min;
}
else if (value > test_max)
{
DBG(DBG_error, "ERROR: value \"%d\" is too large for option %s in %s\n", value, test_name, UMAX_CONFIG_FILE);
value = test_max;
}
*test_value = value;
DBG(DBG_info, "option %s = %d\n", test_name, *test_value);
}
return 1;
}
return 0;
}
/* ------------------------------------------------------------ SANE INIT ---------------------------------- */
SANE_Status sane_init(SANE_Int *version_code, SANE_Auth_Callback authorize)
{
char config_line[PATH_MAX];
const char *option_str;
size_t len;
FILE *fp;
/* we have to initialize these global variables here because sane_init can be called several times */
num_devices = 0;
devlist = NULL;
first_dev = NULL;
first_handle = NULL;
DBG_INIT();
DBG(DBG_sane_init,"sane_init\n");
DBG(DBG_error,"This is sane-umax version %d.%d build %d\n", SANE_CURRENT_MAJOR, SANE_CURRENT_MINOR, BUILD);
#ifdef UMAX_ENABLE_USB
DBG(DBG_error,"compiled with USB support for Astra 2200\n");
#else
DBG(DBG_error,"no USB support for Astra 2200\n");
#endif
DBG(DBG_error,"(C) 1997-2002 by Oliver Rauch\n");
DBG(DBG_error,"EMAIL: Oliver.Rauch@rauch-domain.de\n");
if (version_code)
{
*version_code = SANE_VERSION_CODE(SANE_CURRENT_MAJOR, SANE_CURRENT_MINOR, BUILD);
}
frontend_authorize_callback = authorize; /* store frontend authorize callback */
sanei_thread_init(); /* must be called before any other sanei_thread call */
#ifdef UMAX_ENABLE_USB
sanei_usb_init();
sanei_pv8630_init();
#endif
fp = sanei_config_open(UMAX_CONFIG_FILE);
if (!fp)
{
/* no config-file: try /dev/scanner and /dev/usbscanner. */
attach_scanner("/dev/scanner", 0, SANE_UMAX_SCSI);
#ifdef UMAX_ENABLE_USB
attach_scanner("/dev/usbscanner", 0, SANE_UMAX_USB);
#endif
return SANE_STATUS_GOOD;
}
DBG(DBG_info, "reading configure file %s\n", UMAX_CONFIG_FILE);
while(sanei_config_read(config_line, sizeof(config_line), fp))
{
if (config_line[0] == '#')
{
continue; /* ignore line comments */
}
if (strncmp(config_line, "option", 6) == 0)
{
option_str = sanei_config_skip_whitespace(config_line+6);
if (umax_test_configure_option(option_str, "scsi-maxqueue", &umax_scsi_maxqueue, 1, SANE_UMAX_SCSI_MAXQUEUE));
else if (umax_test_configure_option(option_str, "scsi-buffer-size-min", &umax_scsi_buffer_size_min, 4096, 1048576));
else if (umax_test_configure_option(option_str, "scsi-buffer-size-max", &umax_scsi_buffer_size_max, 4096, 1048576));
else if (umax_test_configure_option(option_str, "preview-lines", &umax_preview_lines, 1, 65535));
else if (umax_test_configure_option(option_str, "scan-lines", &umax_scan_lines, 1, 65535));
else if (umax_test_configure_option(option_str, "handle-bad-sense-error", &umax_handle_bad_sense_error, 0, 3));
else if (umax_test_configure_option(option_str, "execute-request-sense", &umax_execute_request_sense, 0, 1));
else if (umax_test_configure_option(option_str, "force-preview-bit-rgb", &umax_force_preview_bit_rgb, 0, 1));
else if (umax_test_configure_option(option_str, "slow-speed", &umax_slow, -1, 1));
else if (umax_test_configure_option(option_str, "care-about-smearing", &umax_smear, -1, 1));
else if (umax_test_configure_option(option_str, "calibration-full-ccd", &umax_calibration_area, -1, 1));
else if (umax_test_configure_option(option_str, "calibration-width-offset-batch", &umax_calibration_width_offset_batch, -99999, 65535));
else if (umax_test_configure_option(option_str, "calibration-width-offset", &umax_calibration_width_offset, -99999, 65535));
else if (umax_test_configure_option(option_str, "calibration-bytes-pixel", &umax_calibration_bytespp, -1, 2));
else if (umax_test_configure_option(option_str, "exposure-time-rgb-bind", &umax_exposure_time_rgb_bind, -1, 1));
else if (umax_test_configure_option(option_str, "invert-shading-data", &umax_invert_shading_data, -1, 1));
else if (umax_test_configure_option(option_str, "lamp-control-available", &umax_lamp_control_available, 0, 1));
else if (umax_test_configure_option(option_str, "gamma-lsb-padded", &umax_gamma_lsb_padded, -1, 1));
else if (umax_test_configure_option(option_str, "connection-type", &umax_connection_type, 1, 2));
else
{
DBG(DBG_error,"ERROR: unknown option \"%s\" in %s\n", option_str, UMAX_CONFIG_FILE);
}
continue;
}
else if (strncmp(config_line, "scsi", 4) == 0)
{
DBG(DBG_info,"sanei_config_attach_matching_devices(%s)\n", config_line);
sanei_config_attach_matching_devices(config_line, attach_one_scsi);
continue;
}
else if (strncmp(config_line, "usb", 3) == 0)
{
#ifdef UMAX_ENABLE_USB
DBG(DBG_info,"sanei_usb_attach_matching_devices(%s)\n", config_line);
sanei_usb_attach_matching_devices(config_line, attach_one_usb);
#else
DBG(DBG_info,"USB not supported, ignoring config line: %s\n", config_line);
#endif
continue;
}
len = strlen(config_line);
if (!len) /* ignore empty lines */
{
continue;
}
/* umax_connection_type is set by umax.conf: 1=scsi, 2=usb */
attach_scanner(config_line, 0, umax_connection_type); /* try to open as devicename */
}
DBG(DBG_info, "finished reading configure file\n");
fclose(fp);
return SANE_STATUS_GOOD;
}
/* ------------------------------------------------------------ SANE EXIT ---------------------------------- */
void sane_exit(void)
{
Umax_Device *dev, *next;
DBG(DBG_sane_init,"sane_exit\n");
for (dev = first_dev; dev; dev = next)
{
next = dev->next;
free(dev->devicename);
free(dev);
}
if (devlist)
{
free(devlist);
}
}
/* ------------------------------------------------------------ SANE GET DEVICES --------------------------- */
SANE_Status sane_get_devices(const SANE_Device ***device_list, SANE_Bool local_only)
{
Umax_Device *dev;
int i;
DBG(DBG_sane_init,"sane_get_devices(local_only = %d)\n", local_only);
if (devlist)
{
free(devlist);
}
devlist = malloc((num_devices + 1) * sizeof (devlist[0]));
if (!devlist)
{
return SANE_STATUS_NO_MEM;
}
i = 0;
for (dev = first_dev; i < num_devices; dev = dev->next)
{
devlist[i++] = &dev->sane;
}
devlist[i++] = 0;
*device_list = devlist;
return SANE_STATUS_GOOD;
}
/* ------------------------------------------------------------ SANE OPEN ---------------------------------- */
SANE_Status sane_open(SANE_String_Const devicename, SANE_Handle *handle)
{
Umax_Device *dev;
SANE_Status status;
Umax_Scanner *scanner;
unsigned int i, j;
DBG(DBG_sane_init,"sane_open\n");
if (devicename[0]) /* search for devicename */
{
DBG(DBG_sane_info,"sane_open: devicename=%s\n", devicename);
for (dev = first_dev; dev; dev = dev->next)
{
if (strcmp(dev->sane.name, devicename) == 0)
{
break; /* device found, exit for loop */
}
}
if (!dev) /* no device found */
{
status = attach_scanner(devicename, &dev, 0 /* connection-type not known */); /* try to open devicename and set dev */
if (status != SANE_STATUS_GOOD)
{
return status;
}
}
}
else
{
DBG(DBG_sane_info,"sane_open: no devicename, opening first device\n");
dev = first_dev; /* empty devicename -> use first device */
}
if (!dev) /* no device found */
{
return SANE_STATUS_INVAL;
}
scanner = malloc(sizeof (*scanner));
if (!scanner)
{
return SANE_STATUS_NO_MEM;
}
memset(scanner, 0, sizeof (*scanner));
scanner->device = dev;
if (scanner->device->inquiry_GIB & 32)
{
scanner->gamma_length = 65536; /* 16 bits input */
DBG(DBG_sane_info, "Using 16 bits for gamma input\n");
}
else if (scanner->device->inquiry_GIB & 16)
{
scanner->gamma_length = 16384; /* 14 bits input */
DBG(DBG_sane_info, "Using 14 bits for gamma input\n");
}
else if (scanner->device->inquiry_GIB & 8)
{
scanner->gamma_length = 4096; /* 12 bits input */
DBG(DBG_sane_info, "Using 12 bits for gamma input\n");
}
else if (scanner->device->inquiry_GIB & 4)
{
scanner->gamma_length = 1024; /* 10 bits input */
DBG(DBG_sane_info, "Using 10 bits for gamma input\n");
}
else if (scanner->device->inquiry_GIB & 2)
{
scanner->gamma_length = 512; /* 9 bits input */
DBG(DBG_sane_info, "Using 9 bits for gamma input\n");
}
else
{
scanner->gamma_length = 256; /* 8 bits input */
DBG(DBG_sane_info, "Using 8 bits for gamma input\n");
}
scanner->output_bytes = 1; /* 8 bits output */
scanner->gamma_range.min = 0;
scanner->gamma_range.max = scanner->gamma_length-1;
scanner->gamma_range.quant = 0;
scanner->gamma_table[0] = (SANE_Int *) malloc(scanner->gamma_length * sizeof(SANE_Int));
scanner->gamma_table[1] = (SANE_Int *) malloc(scanner->gamma_length * sizeof(SANE_Int));
scanner->gamma_table[2] = (SANE_Int *) malloc(scanner->gamma_length * sizeof(SANE_Int));
scanner->gamma_table[3] = (SANE_Int *) malloc(scanner->gamma_length * sizeof(SANE_Int));
for (j = 0; j < scanner->gamma_length; ++j) /* gamma_table[0] : converts GIB to GOB */
{
scanner->gamma_table[0][j] = j * scanner->device->max_value / scanner->gamma_length;
}
for (i = 1; i < 4; ++i) /* gamma_table[1,2,3] : doesn't convert anything (GIB->GIB) */
{
for (j = 0; j < scanner->gamma_length; ++j)
{
scanner->gamma_table[i][j] = j;
}
}
scanner->exposure_time_range.min = scanner->device->inquiry_exposure_time_c_min *
scanner->device->inquiry_exposure_time_step_unit;
scanner->exposure_time_range.quant = scanner->device->inquiry_exposure_time_step_unit;
scanner->exposure_time_range.max = scanner->device->inquiry_exposure_time_max *
scanner->device->inquiry_exposure_time_step_unit;
init_options(scanner);
scanner->next = first_handle; /* insert newly opened handle into list of open handles: */
first_handle = scanner;
*handle = scanner;
return SANE_STATUS_GOOD;
}
/* ------------------------------------------------------------ SANE CLOSE --------------------------------- */
void sane_close(SANE_Handle handle)
{
Umax_Scanner *prev, *scanner;
DBG(DBG_sane_init,"sane_close\n");
if (!first_handle)
{
DBG(DBG_error, "ERROR: sane_close: no handles opened\n");
return;
}
/* remove handle from list of open handles: */
prev = 0;
for (scanner = first_handle; scanner; scanner = scanner->next)
{
if (scanner == handle)
{
break;
}
prev = scanner;
}
if (!scanner)
{
DBG(DBG_error, "ERROR: sane_close: invalid handle %p\n", handle);
return; /* oops, not a handle we know about */
}
if (scanner->scanning) /* stop scan if still scanning */
{
do_cancel(handle);
}
if (scanner->device->lamp_control_available) /* lamp state can be controlled by driver */
{
if (scanner->val[OPT_LAMP_OFF_AT_EXIT].w) /* turn off scanner lamp on sane_close */
{
umax_set_lamp_status(handle, 0 /* lamp off */);
}
}
if (prev)
{
prev->next = scanner->next;
}
else
{
first_handle = scanner->next;
}
free(scanner->gamma_table[0]); /* free custom gamma tables */
free(scanner->gamma_table[1]);
free(scanner->gamma_table[2]);
free(scanner->gamma_table[3]);
free(scanner->device->buffer[0]); /* free buffer allocated by umax_initialize_values */
scanner->device->buffer[0] = NULL;
scanner->device->bufsize = 0;
free(scanner); /* free scanner */
}
/* ------------------------------------------------------------ SANE GET OPTION DESCRIPTOR ----------------- */
const SANE_Option_Descriptor *sane_get_option_descriptor(SANE_Handle handle, SANE_Int option)
{
Umax_Scanner *scanner = handle;
DBG(DBG_sane_option,"sane_get_option_descriptor %d\n", option);
if ((unsigned) option >= NUM_OPTIONS)
{
return 0;
}
return scanner->opt + option;
}
/* ------------------------------------------------------------ UMAX SET MAX GEOMETRY ---------------------- */
static void umax_set_max_geometry(Umax_Scanner *scanner)
{
if (scanner->val[OPT_DOR].w)
{
scanner->device->x_range.min = SANE_FIX(scanner->device->inquiry_dor_x_off * MM_PER_INCH);
scanner->device->x_range.max = SANE_FIX( (scanner->device->inquiry_dor_x_off + scanner->device->inquiry_dor_width) * MM_PER_INCH);
scanner->device->y_range.min = SANE_FIX(scanner->device->inquiry_dor_y_off * MM_PER_INCH);
scanner->device->y_range.max = SANE_FIX( (scanner->device->inquiry_dor_y_off + scanner->device->inquiry_dor_length) * MM_PER_INCH);
scanner->device->x_dpi_range.max = SANE_FIX(scanner->device->inquiry_dor_x_res);
scanner->device->y_dpi_range.max = SANE_FIX(scanner->device->inquiry_dor_y_res);
}
else if ( (strcmp(scanner->val[OPT_SOURCE].s, FLB_STR) == 0) || (strcmp(scanner->val[OPT_SOURCE].s, ADF_STR) == 0) )
{
scanner->device->x_range.min = 0;
scanner->device->x_range.max = SANE_FIX(scanner->device->inquiry_fb_width * MM_PER_INCH);
scanner->device->y_range.min = 0;
scanner->device->y_range.max = SANE_FIX(scanner->device->inquiry_fb_length * MM_PER_INCH);
scanner->device->x_dpi_range.max = SANE_FIX(scanner->device->inquiry_x_res);
scanner->device->y_dpi_range.max = SANE_FIX(scanner->device->inquiry_y_res);
}
else if (strcmp(scanner->val[OPT_SOURCE].s, UTA_STR) == 0)
{
scanner->device->x_range.min = SANE_FIX(scanner->device->inquiry_uta_x_off * MM_PER_INCH);
scanner->device->x_range.max = SANE_FIX( (scanner->device->inquiry_uta_x_off + scanner->device->inquiry_uta_width) * MM_PER_INCH);
scanner->device->y_range.min = SANE_FIX(scanner->device->inquiry_uta_y_off * MM_PER_INCH);
scanner->device->y_range.max = SANE_FIX( ( scanner->device->inquiry_uta_y_off + scanner->device->inquiry_uta_length) * MM_PER_INCH);
scanner->device->x_dpi_range.max = SANE_FIX(scanner->device->inquiry_x_res);
scanner->device->y_dpi_range.max = SANE_FIX(scanner->device->inquiry_y_res);
}
DBG(DBG_info,"x_range = [%f .. %f]\n", SANE_UNFIX(scanner->device->x_range.min), SANE_UNFIX(scanner->device->x_range.max));
DBG(DBG_info,"y_range = [%f .. %f]\n", SANE_UNFIX(scanner->device->y_range.min), SANE_UNFIX(scanner->device->y_range.max));
DBG(DBG_info,"x_dpi_range = [1 .. %f]\n", SANE_UNFIX(scanner->device->x_dpi_range.max));
DBG(DBG_info,"y_dpi_range = [1 .. %f]\n", SANE_UNFIX(scanner->device->y_dpi_range.max));
/* make sure geometry selection is in bounds */
if ( scanner->val[OPT_TL_X].w < scanner->device->x_range.min)
{
scanner->val[OPT_TL_X].w = scanner->device->x_range.min;
}
if (scanner->val[OPT_TL_Y].w < scanner->device->y_range.min)
{
scanner->val[OPT_TL_Y].w = scanner->device->y_range.min;
}
if ( scanner->val[OPT_BR_X].w > scanner->device->x_range.max)
{
scanner->val[OPT_BR_X].w = scanner->device->x_range.max;
}
if (scanner->val[OPT_BR_Y].w > scanner->device->y_range.max)
{
scanner->val[OPT_BR_Y].w = scanner->device->y_range.max;
}
}
/* ------------------------------------------------------------ SANE CONTROL OPTION ------------------------ */
SANE_Status sane_control_option(SANE_Handle handle, SANE_Int option, SANE_Action action,
void *val, SANE_Int *info)
{
Umax_Scanner *scanner = handle;
SANE_Status status;
SANE_Word w, cap;
SANE_String_Const name;
if (info)
{
*info = 0;
}
if (scanner->scanning)
{
return SANE_STATUS_DEVICE_BUSY;
}
if ((unsigned) option >= NUM_OPTIONS)
{
return SANE_STATUS_INVAL;
}
cap = scanner->opt[option].cap;
if (!SANE_OPTION_IS_ACTIVE (cap))
{
return SANE_STATUS_INVAL;
}
name = scanner->opt[option].name;
if (!name)
{
name = "(no name)";
}
if (action == SANE_ACTION_GET_VALUE)
{
DBG(DBG_sane_option,"get %s [#%d]\n", name, option);
switch (option)
{
/* word options: */
case OPT_NUM_OPTS:
case OPT_RESOLUTION_BIND:
case OPT_X_RESOLUTION:
case OPT_Y_RESOLUTION:
case OPT_TL_X:
case OPT_TL_Y:
case OPT_BR_X:
case OPT_BR_Y:
case OPT_PREVIEW:
case OPT_BIT_DEPTH:
case OPT_NEGATIVE:
case OPT_BATCH_SCAN_START:
case OPT_BATCH_SCAN_LOOP:
case OPT_BATCH_SCAN_END:
case OPT_BATCH_NEXT_TL_Y:
case OPT_QUALITY:
case OPT_DOR:
case OPT_WARMUP:
case OPT_RGB_BIND:
case OPT_ANALOG_GAMMA:
case OPT_ANALOG_GAMMA_R:
case OPT_ANALOG_GAMMA_G:
case OPT_ANALOG_GAMMA_B:
case OPT_BRIGHTNESS:
case OPT_CONTRAST:
case OPT_THRESHOLD:
case OPT_HIGHLIGHT:
case OPT_HIGHLIGHT_R:
case OPT_HIGHLIGHT_G:
case OPT_HIGHLIGHT_B:
case OPT_SHADOW:
case OPT_SHADOW_R:
case OPT_SHADOW_G:
case OPT_SHADOW_B:
case OPT_CUSTOM_GAMMA:
case OPT_HALFTONE_DIMENSION:
case OPT_SELECT_EXPOSURE_TIME:
case OPT_SELECT_CAL_EXPOSURE_TIME:
case OPT_CAL_EXPOS_TIME:
case OPT_CAL_EXPOS_TIME_R:
case OPT_CAL_EXPOS_TIME_G:
case OPT_CAL_EXPOS_TIME_B:
case OPT_SCAN_EXPOS_TIME:
case OPT_SCAN_EXPOS_TIME_R:
case OPT_SCAN_EXPOS_TIME_G:
case OPT_SCAN_EXPOS_TIME_B:
case OPT_CAL_LAMP_DEN:
case OPT_SCAN_LAMP_DEN:
case OPT_DISABLE_PRE_FOCUS:
case OPT_MANUAL_PRE_FOCUS:
case OPT_FIX_FOCUS_POSITION:
case OPT_LENS_CALIBRATION_DOC_POS:
case OPT_HOLDER_FOCUS_POS_0MM:
case OPT_LAMP_OFF_AT_EXIT:
case OPT_SELECT_LAMP_DENSITY:
*(SANE_Word *) val = scanner->val[option].w;
return SANE_STATUS_GOOD;
/* word-array options: */
case OPT_GAMMA_VECTOR:
case OPT_GAMMA_VECTOR_R:
case OPT_GAMMA_VECTOR_G:
case OPT_GAMMA_VECTOR_B:
case OPT_HALFTONE_PATTERN:
memcpy (val, scanner->val[option].wa, scanner->opt[option].size);
return SANE_STATUS_GOOD;
/* string options: */
case OPT_SOURCE:
/* fall through */
case OPT_MODE:
/* fall through */
#ifdef UMAX_CALIBRATION_MODE_SELECTABLE
case OPT_CALIB_MODE:
/* fall through */
#endif
strcpy (val, scanner->val[option].s);
return SANE_STATUS_GOOD;
}
}
else if (action == SANE_ACTION_SET_VALUE)
{
switch (scanner->opt[option].type)
{
case SANE_TYPE_INT:
DBG(DBG_sane_option, "set %s [#%d] to %d\n", name, option, *(SANE_Word *) val);
break;
case SANE_TYPE_FIXED:
DBG(DBG_sane_option, "set %s [#%d] to %f\n", name, option, SANE_UNFIX(*(SANE_Word *) val));
break;
case SANE_TYPE_STRING:
DBG(DBG_sane_option, "set %s [#%d] to %s\n", name, option, (char *) val);
break;
case SANE_TYPE_BOOL:
DBG(DBG_sane_option, "set %s [#%d] to %d\n", name, option, *(SANE_Word *) val);
break;
default:
DBG(DBG_sane_option, "set %s [#%d]\n", name, option);
}
if (!SANE_OPTION_IS_SETTABLE(cap))
{
DBG(DBG_error, "could not set option, not settable\n");
return SANE_STATUS_INVAL;
}
status = sanei_constrain_value(scanner->opt+option, val, info);
if (status != SANE_STATUS_GOOD)
{
DBG(DBG_error, "could not set option, invalid value\n");
return status;
}
switch (option)
{
/* (mostly) side-effect-free word options: */
case OPT_X_RESOLUTION:
case OPT_Y_RESOLUTION:
case OPT_TL_X:
case OPT_TL_Y:
case OPT_BR_X:
case OPT_BR_Y:
if (info)
{
*info |= SANE_INFO_RELOAD_PARAMS;
}
/* fall through */
case OPT_NUM_OPTS:
case OPT_NEGATIVE:
case OPT_BATCH_SCAN_START:
case OPT_BATCH_SCAN_LOOP:
case OPT_BATCH_SCAN_END:
case OPT_BATCH_NEXT_TL_Y:
case OPT_QUALITY:
case OPT_WARMUP:
case OPT_PREVIEW:
case OPT_ANALOG_GAMMA:
case OPT_ANALOG_GAMMA_R:
case OPT_ANALOG_GAMMA_G:
case OPT_ANALOG_GAMMA_B:
case OPT_BRIGHTNESS:
case OPT_CONTRAST:
case OPT_THRESHOLD:
case OPT_HIGHLIGHT:
case OPT_HIGHLIGHT_R:
case OPT_HIGHLIGHT_G:
case OPT_HIGHLIGHT_B:
case OPT_SHADOW:
case OPT_SHADOW_R:
case OPT_SHADOW_G:
case OPT_SHADOW_B:
case OPT_CAL_EXPOS_TIME:
case OPT_CAL_EXPOS_TIME_R:
case OPT_CAL_EXPOS_TIME_G:
case OPT_CAL_EXPOS_TIME_B:
case OPT_SCAN_EXPOS_TIME:
case OPT_SCAN_EXPOS_TIME_R:
case OPT_SCAN_EXPOS_TIME_G:
case OPT_SCAN_EXPOS_TIME_B:
case OPT_CAL_LAMP_DEN:
case OPT_SCAN_LAMP_DEN:
case OPT_DISABLE_PRE_FOCUS:
case OPT_MANUAL_PRE_FOCUS:
case OPT_FIX_FOCUS_POSITION:
case OPT_LENS_CALIBRATION_DOC_POS:
case OPT_HOLDER_FOCUS_POS_0MM:
case OPT_LAMP_OFF_AT_EXIT:
scanner->val[option].w = *(SANE_Word *) val;
return SANE_STATUS_GOOD;
case OPT_DOR:
{
if (scanner->val[option].w != *(SANE_Word *) val)
{
scanner->val[option].w = *(SANE_Word *) val; /* update valure for umax_set_max_geometry */
if (info)
{
*info |= SANE_INFO_RELOAD_PARAMS;
*info |= SANE_INFO_RELOAD_OPTIONS;
}
DBG(DBG_info,"sane_control_option: set DOR = %d\n", scanner->val[option].w);
umax_set_max_geometry(scanner);
}
return SANE_STATUS_GOOD;
}
case OPT_BIT_DEPTH:
{
if (scanner->val[option].w != *(SANE_Word *) val)
{
scanner->val[option].w = *(SANE_Word *) val;
if (info)
{
*info |= SANE_INFO_RELOAD_OPTIONS;
}
scanner->output_range.min = 0;
scanner->output_range.quant = 0;
if (scanner->val[option].w == 8) /* 8 bit mode */
{
scanner->output_bytes = 1; /* 1 bytes output */
scanner->output_range.max = 255;
}
else /* > 8 bit mode */
{
scanner->output_bytes = 2; /* 2 bytes output */
if (scanner->device->gamma_lsb_padded) /* e.g. astra 1220s need lsb padded data */
{
scanner->output_range.max = (int) pow(2, scanner->val[option].w) - 1;
}
else
{
scanner->output_range.max = 65535; /* define maxval for msb padded data */
}
}
if (info)
{
*info |= SANE_INFO_RELOAD_PARAMS;
}
}
return SANE_STATUS_GOOD;
}
case OPT_RGB_BIND:
{
if (scanner->val[option].w != *(SANE_Word *) val)
{
scanner->val[option].w = *(SANE_Word *) val;
if (info)
{
*info |= SANE_INFO_RELOAD_OPTIONS;
}
umax_set_rgb_bind(scanner);
}
return SANE_STATUS_GOOD;
}
case OPT_RESOLUTION_BIND:
{
if (scanner->val[option].w != *(SANE_Word *) val)
{
scanner->val[option].w = *(SANE_Word *) val;
if (info)
{
*info |= SANE_INFO_RELOAD_OPTIONS;
}
if (scanner->val[option].w == SANE_FALSE)
{ /* don't bind */
scanner->opt[OPT_Y_RESOLUTION].cap &= ~SANE_CAP_INACTIVE;
scanner->opt[OPT_X_RESOLUTION].title = SANE_TITLE_SCAN_X_RESOLUTION;
scanner->opt[OPT_X_RESOLUTION].name = SANE_NAME_SCAN_RESOLUTION;
scanner->opt[OPT_X_RESOLUTION].desc = SANE_DESC_SCAN_X_RESOLUTION;
}
else
{ /* bind */
scanner->opt[OPT_Y_RESOLUTION].cap |= SANE_CAP_INACTIVE;
scanner->opt[OPT_X_RESOLUTION].title = SANE_TITLE_SCAN_RESOLUTION;
scanner->opt[OPT_X_RESOLUTION].name = SANE_NAME_SCAN_RESOLUTION;
scanner->opt[OPT_X_RESOLUTION].desc = SANE_DESC_SCAN_RESOLUTION;
}
}
return SANE_STATUS_GOOD;
}
case OPT_SELECT_EXPOSURE_TIME:
case OPT_SELECT_CAL_EXPOSURE_TIME:
{
if (scanner->val[option].w != *(SANE_Word *) val)
{
scanner->val[option].w = *(SANE_Word *) val;
if (info)
{
*info |= SANE_INFO_RELOAD_OPTIONS;
}
if (scanner->val[OPT_SELECT_EXPOSURE_TIME].w == SANE_FALSE)
{
scanner->opt[OPT_SELECT_CAL_EXPOSURE_TIME].cap |= SANE_CAP_INACTIVE;
scanner->opt[OPT_CAL_EXPOS_TIME].cap |= SANE_CAP_INACTIVE;
scanner->opt[OPT_CAL_EXPOS_TIME_R].cap |= SANE_CAP_INACTIVE;
scanner->opt[OPT_CAL_EXPOS_TIME_G].cap |= SANE_CAP_INACTIVE;
scanner->opt[OPT_CAL_EXPOS_TIME_B].cap |= SANE_CAP_INACTIVE;
scanner->opt[OPT_SCAN_EXPOS_TIME].cap |= SANE_CAP_INACTIVE;
scanner->opt[OPT_SCAN_EXPOS_TIME_R].cap |= SANE_CAP_INACTIVE;
scanner->opt[OPT_SCAN_EXPOS_TIME_G].cap |= SANE_CAP_INACTIVE;
scanner->opt[OPT_SCAN_EXPOS_TIME_B].cap |= SANE_CAP_INACTIVE;
}
else /* exposure time selection active */
{
scanner->opt[OPT_SELECT_CAL_EXPOSURE_TIME].cap &= ~SANE_CAP_INACTIVE;
if ( (strcmp(scanner->val[OPT_MODE].s, COLOR_STR) != 0) ||
(scanner->val[OPT_RGB_BIND].w == SANE_TRUE) ||
(scanner->device->exposure_time_rgb_bind) ) /* RGB bind */
{
if (scanner->val[OPT_SELECT_CAL_EXPOSURE_TIME].w)
{
scanner->opt[OPT_CAL_EXPOS_TIME].cap &= ~SANE_CAP_INACTIVE;
}
else
{
scanner->opt[OPT_CAL_EXPOS_TIME].cap |= SANE_CAP_INACTIVE;
}
scanner->opt[OPT_SCAN_EXPOS_TIME].cap &= ~SANE_CAP_INACTIVE;
}
else /* no RGB bind */
{
if (scanner->val[OPT_SELECT_CAL_EXPOSURE_TIME].w)
{
scanner->opt[OPT_CAL_EXPOS_TIME_R].cap &= ~SANE_CAP_INACTIVE;
scanner->opt[OPT_CAL_EXPOS_TIME_G].cap &= ~SANE_CAP_INACTIVE;
scanner->opt[OPT_CAL_EXPOS_TIME_B].cap &= ~SANE_CAP_INACTIVE;
}
else
{
scanner->opt[OPT_CAL_EXPOS_TIME_R].cap |= SANE_CAP_INACTIVE;
scanner->opt[OPT_CAL_EXPOS_TIME_G].cap |= SANE_CAP_INACTIVE;
scanner->opt[OPT_CAL_EXPOS_TIME_B].cap |= SANE_CAP_INACTIVE;
}
scanner->opt[OPT_SCAN_EXPOS_TIME_R].cap &= ~SANE_CAP_INACTIVE;
scanner->opt[OPT_SCAN_EXPOS_TIME_G].cap &= ~SANE_CAP_INACTIVE;
scanner->opt[OPT_SCAN_EXPOS_TIME_B].cap &= ~SANE_CAP_INACTIVE;
}
}
}
return SANE_STATUS_GOOD;
}
case OPT_SELECT_LAMP_DENSITY:
{
if (scanner->val[option].w != *(SANE_Word *) val)
{
scanner->val[option].w = *(SANE_Word *) val;
if (info)
{
*info |= SANE_INFO_RELOAD_OPTIONS;
}
if (scanner->val[option].w == SANE_FALSE)
{
scanner->opt[OPT_CAL_LAMP_DEN].cap |= SANE_CAP_INACTIVE;
scanner->opt[OPT_SCAN_LAMP_DEN].cap |= SANE_CAP_INACTIVE;
}
else
{
scanner->opt[OPT_CAL_LAMP_DEN].cap &= ~SANE_CAP_INACTIVE;
scanner->opt[OPT_SCAN_LAMP_DEN].cap &= ~SANE_CAP_INACTIVE;
}
}
return SANE_STATUS_GOOD;
}
/* side-effect-free word-array options: */
case OPT_HALFTONE_PATTERN:
case OPT_GAMMA_VECTOR:
case OPT_GAMMA_VECTOR_R:
case OPT_GAMMA_VECTOR_G:
case OPT_GAMMA_VECTOR_B:
memcpy (scanner->val[option].wa, val, scanner->opt[option].size);
return SANE_STATUS_GOOD;
/* single string-option with side-effect: */
case OPT_SOURCE:
{
if (scanner->val[option].s)
{
free(scanner->val[option].s);
}
scanner->val[option].s = (SANE_Char *) strdup(val); /* update string for umax_set_max_geometry */
DBG(DBG_info,"sane_control_option: set SOURCE = %s\n", (SANE_Char *) val);
umax_set_max_geometry(scanner);
if (info)
{
*info |= SANE_INFO_RELOAD_PARAMS;
*info |= SANE_INFO_RELOAD_OPTIONS;
}
return SANE_STATUS_GOOD;
}
break;
/* side-effect-free single-string options: */
#ifdef UMAX_CALIBRATION_MODE_SELECTABLE
case OPT_CALIB_MODE:
/* fall through */
#endif
{
if (scanner->val[option].s)
{
free (scanner->val[option].s);
}
scanner->val[option].s = (SANE_Char*)strdup(val);
return SANE_STATUS_GOOD;
}
/* options with side-effects: */
case OPT_CUSTOM_GAMMA:
{
w = *(SANE_Word *) val;
if (w == scanner->val[OPT_CUSTOM_GAMMA].w) { return SANE_STATUS_GOOD; }
scanner->val[OPT_CUSTOM_GAMMA].w = w;
if (w) /* use custom_gamma_table */
{
const char *mode = scanner->val[OPT_MODE].s;
if ( (strcmp(mode, LINEART_STR) == 0) ||
(strcmp(mode, HALFTONE_STR) == 0) ||
(strcmp(mode, GRAY_STR) == 0) )
{ scanner->opt[OPT_GAMMA_VECTOR].cap &= ~SANE_CAP_INACTIVE; }
else if (strcmp(mode, COLOR_STR) == 0)
{
scanner->opt[OPT_GAMMA_VECTOR].cap &= ~SANE_CAP_INACTIVE;
scanner->opt[OPT_GAMMA_VECTOR_R].cap &= ~SANE_CAP_INACTIVE;
scanner->opt[OPT_GAMMA_VECTOR_G].cap &= ~SANE_CAP_INACTIVE;
scanner->opt[OPT_GAMMA_VECTOR_B].cap &= ~SANE_CAP_INACTIVE;
}
}
else /* don't use custom_gamma_table */
{
scanner->opt[OPT_GAMMA_VECTOR].cap |= SANE_CAP_INACTIVE;
scanner->opt[OPT_GAMMA_VECTOR_R].cap |= SANE_CAP_INACTIVE;
scanner->opt[OPT_GAMMA_VECTOR_G].cap |= SANE_CAP_INACTIVE;
scanner->opt[OPT_GAMMA_VECTOR_B].cap |= SANE_CAP_INACTIVE;
}
if (info)
{
*info |= SANE_INFO_RELOAD_OPTIONS;
}
return SANE_STATUS_GOOD;
}
case OPT_MODE:
{
int halftoning;
if (scanner->val[option].s)
{
free (scanner->val[option].s);
}
scanner->val[option].s = (SANE_Char*)strdup(val);
if (info)
{
*info |=SANE_INFO_RELOAD_OPTIONS | SANE_INFO_RELOAD_PARAMS;
}
scanner->opt[OPT_NEGATIVE].cap |= SANE_CAP_INACTIVE;
scanner->opt[OPT_BIT_DEPTH].cap |= SANE_CAP_INACTIVE;
scanner->opt[OPT_CUSTOM_GAMMA].cap |= SANE_CAP_INACTIVE;
scanner->opt[OPT_GAMMA_VECTOR].cap |= SANE_CAP_INACTIVE;
scanner->opt[OPT_GAMMA_VECTOR_R].cap |= SANE_CAP_INACTIVE;
scanner->opt[OPT_GAMMA_VECTOR_G].cap |= SANE_CAP_INACTIVE;
scanner->opt[OPT_GAMMA_VECTOR_B].cap |= SANE_CAP_INACTIVE;
scanner->opt[OPT_CONTRAST].cap |= SANE_CAP_INACTIVE;
scanner->opt[OPT_BRIGHTNESS].cap |= SANE_CAP_INACTIVE;
scanner->opt[OPT_THRESHOLD].cap |= SANE_CAP_INACTIVE;
scanner->opt[OPT_RGB_BIND].cap |= SANE_CAP_INACTIVE;
scanner->opt[OPT_ANALOG_GAMMA].cap |= SANE_CAP_INACTIVE;
scanner->opt[OPT_ANALOG_GAMMA_R].cap |= SANE_CAP_INACTIVE;
scanner->opt[OPT_ANALOG_GAMMA_G].cap |= SANE_CAP_INACTIVE;
scanner->opt[OPT_ANALOG_GAMMA_B].cap |= SANE_CAP_INACTIVE;
scanner->opt[OPT_HIGHLIGHT].cap |= SANE_CAP_INACTIVE;
scanner->opt[OPT_HIGHLIGHT_R].cap |= SANE_CAP_INACTIVE;
scanner->opt[OPT_HIGHLIGHT_G].cap |= SANE_CAP_INACTIVE;
scanner->opt[OPT_HIGHLIGHT_B].cap |= SANE_CAP_INACTIVE;
scanner->opt[OPT_SHADOW].cap |= SANE_CAP_INACTIVE;
scanner->opt[OPT_SHADOW_R].cap |= SANE_CAP_INACTIVE;
scanner->opt[OPT_SHADOW_G].cap |= SANE_CAP_INACTIVE;
scanner->opt[OPT_SHADOW_B].cap |= SANE_CAP_INACTIVE;
scanner->opt[OPT_CAL_EXPOS_TIME].cap |= SANE_CAP_INACTIVE;
scanner->opt[OPT_CAL_EXPOS_TIME_R].cap |= SANE_CAP_INACTIVE;
scanner->opt[OPT_CAL_EXPOS_TIME_G].cap |= SANE_CAP_INACTIVE;
scanner->opt[OPT_CAL_EXPOS_TIME_B].cap |= SANE_CAP_INACTIVE;
scanner->opt[OPT_SCAN_EXPOS_TIME].cap |= SANE_CAP_INACTIVE;
scanner->opt[OPT_SCAN_EXPOS_TIME_R].cap |= SANE_CAP_INACTIVE;
scanner->opt[OPT_SCAN_EXPOS_TIME_G].cap |= SANE_CAP_INACTIVE;
scanner->opt[OPT_SCAN_EXPOS_TIME_B].cap |= SANE_CAP_INACTIVE;
scanner->opt[OPT_HALFTONE_DIMENSION].cap |= SANE_CAP_INACTIVE;
scanner->opt[OPT_HALFTONE_PATTERN].cap |= SANE_CAP_INACTIVE;
halftoning = (strcmp(val, HALFTONE_STR) == 0 || strcmp(val, COLOR_HALFTONE_STR) == 0);
if (halftoning || strcmp(val, LINEART_STR) == 0 || strcmp(val, COLOR_LINEART_STR) == 0)
{ /* one bit modes */
if (scanner->device->inquiry_reverse)
{
scanner->opt[OPT_NEGATIVE].cap &= ~SANE_CAP_INACTIVE;
}
if (halftoning)
{ /* halftoning modes */
scanner->opt[OPT_CONTRAST].cap &= ~SANE_CAP_INACTIVE;
scanner->opt[OPT_BRIGHTNESS].cap &= ~SANE_CAP_INACTIVE;
if (scanner->device->inquiry_highlight)
{
scanner->opt[OPT_HIGHLIGHT].cap &= ~SANE_CAP_INACTIVE;
}
if (scanner->device->inquiry_shadow)
{
scanner->opt[OPT_SHADOW].cap &= ~SANE_CAP_INACTIVE;
}
/* disable halftone pattern download options */
#if 0
scanner->opt[OPT_HALFTONE_DIMENSION].cap &= ~SANE_CAP_INACTIVE;
if (scanner->val[OPT_HALFTONE_DIMENSION].w)
{
scanner->opt[OPT_HALFTONE_PATTERN].cap &= ~SANE_CAP_INACTIVE;
}
#endif
if (scanner->val[OPT_SELECT_EXPOSURE_TIME].w == SANE_TRUE)
{
scanner->opt[OPT_CAL_EXPOS_TIME].cap &= ~SANE_CAP_INACTIVE;
scanner->opt[OPT_SCAN_EXPOS_TIME].cap &= ~SANE_CAP_INACTIVE;
}
scanner->exposure_time_range.min = scanner->device->inquiry_exposure_time_h_min
* scanner->device->inquiry_exposure_time_step_unit;
}
else
{ /* lineart modes */
scanner->opt[OPT_THRESHOLD].cap &= ~SANE_CAP_INACTIVE;
if (scanner->val[OPT_SELECT_EXPOSURE_TIME].w == SANE_TRUE)
{
scanner->opt[OPT_CAL_EXPOS_TIME].cap &= ~SANE_CAP_INACTIVE;
scanner->opt[OPT_SCAN_EXPOS_TIME].cap &= ~SANE_CAP_INACTIVE;
}
scanner->exposure_time_range.min = scanner->device->inquiry_exposure_time_l_min
* scanner->device->inquiry_exposure_time_step_unit;
}
}
else
{ /* multi-bit modes(gray or color) */
scanner->opt[OPT_BIT_DEPTH].cap &= ~SANE_CAP_INACTIVE;
if (scanner->device->inquiry_highlight)
{
scanner->opt[OPT_HIGHLIGHT].cap &= ~SANE_CAP_INACTIVE;
}
if (scanner->device->inquiry_shadow)
{
scanner->opt[OPT_SHADOW].cap &= ~SANE_CAP_INACTIVE;
}
if (scanner->device->inquiry_reverse_multi)
{
scanner->opt[OPT_NEGATIVE].cap &= ~SANE_CAP_INACTIVE;
}
if (scanner->device->inquiry_gamma_dwload)
{
scanner->opt[OPT_CUSTOM_GAMMA].cap &= ~SANE_CAP_INACTIVE;
}
else
{
scanner->val[OPT_CUSTOM_GAMMA].w = SANE_FALSE;
}
if (scanner->device->inquiry_analog_gamma)
{
scanner->opt[OPT_ANALOG_GAMMA].cap &= ~SANE_CAP_INACTIVE;
}
if (scanner->val[OPT_SELECT_EXPOSURE_TIME].w == SANE_TRUE)
{
scanner->opt[OPT_CAL_EXPOS_TIME].cap &= ~SANE_CAP_INACTIVE;
scanner->opt[OPT_SCAN_EXPOS_TIME].cap &= ~SANE_CAP_INACTIVE;
}
if (strcmp(val, COLOR_STR) == 0)
{
if ( (scanner->device->inquiry_analog_gamma) ||
(scanner->device->inquiry_highlight) ||
(scanner->device->inquiry_shadow) ||
(scanner->device->inquiry_exposure_adj) )
{
scanner->opt[OPT_RGB_BIND].cap &= ~SANE_CAP_INACTIVE;
}
scanner->exposure_time_range.min = scanner->device->inquiry_exposure_time_c_min
* scanner->device->inquiry_exposure_time_step_unit;
}
else /* grayscale */
{
scanner->exposure_time_range.min = scanner->device->inquiry_exposure_time_g_min
* scanner->device->inquiry_exposure_time_step_unit;
}
}
umax_set_rgb_bind(scanner);
if (scanner->val[OPT_CUSTOM_GAMMA].w)
{
if (strcmp(val, GRAY_STR) == 0)
{
scanner->opt[OPT_GAMMA_VECTOR].cap &= ~SANE_CAP_INACTIVE;
}
else if (strcmp(val, COLOR_STR) == 0)
{
scanner->opt[OPT_GAMMA_VECTOR].cap &= ~SANE_CAP_INACTIVE;
scanner->opt[OPT_GAMMA_VECTOR_R].cap &= ~SANE_CAP_INACTIVE;
scanner->opt[OPT_GAMMA_VECTOR_G].cap &= ~SANE_CAP_INACTIVE;
scanner->opt[OPT_GAMMA_VECTOR_B].cap &= ~SANE_CAP_INACTIVE;
}
}
return SANE_STATUS_GOOD;
}
case OPT_HALFTONE_DIMENSION: /* halftone pattern dimension affects halftone pattern option: */
{
unsigned dim = *(SANE_Word *) val;
scanner->val[option].w = dim;
if (info)
{
*info |= SANE_INFO_RELOAD_OPTIONS;
}
scanner->opt[OPT_HALFTONE_PATTERN].cap |= SANE_CAP_INACTIVE;
if (dim > 0)
{
scanner->opt[OPT_HALFTONE_PATTERN].cap &= ~SANE_CAP_INACTIVE;
scanner->opt[OPT_HALFTONE_PATTERN].size = dim * sizeof (SANE_Word);
}
return SANE_STATUS_GOOD;
}
case OPT_LAMP_ON:
{
if (!umax_set_lamp_status(handle, 1 /* lamp on */))
{
return SANE_STATUS_GOOD;
}
else
{
return SANE_STATUS_UNSUPPORTED;
}
}
case OPT_LAMP_OFF:
{
if (!umax_set_lamp_status(handle, 0 /* lamp off */))
{
return SANE_STATUS_GOOD;
}
else
{
return SANE_STATUS_UNSUPPORTED;
}
}
}
} /* else */
return SANE_STATUS_INVAL;
}
/* ------------------------------------------------------------ SANE GET PARAMETERS ------------------------ */
SANE_Status sane_get_parameters(SANE_Handle handle, SANE_Parameters *params)
{
Umax_Scanner *scanner = handle;
const char *mode;
DBG(DBG_sane_info,"sane_get_parameters\n");
if (!scanner->scanning)
{ /* not scanning, so lets use recent values */
double width, length, x_dpi, y_dpi;
memset(&scanner->params, 0, sizeof (scanner->params));
width = SANE_UNFIX(scanner->val[OPT_BR_X].w - scanner->val[OPT_TL_X].w);
length = SANE_UNFIX(scanner->val[OPT_BR_Y].w - scanner->val[OPT_TL_Y].w);
x_dpi = SANE_UNFIX(scanner->val[OPT_X_RESOLUTION].w);
y_dpi = SANE_UNFIX(scanner->val[OPT_Y_RESOLUTION].w);
if ( (scanner->val[OPT_RESOLUTION_BIND].w == SANE_TRUE) || (scanner->val[OPT_PREVIEW].w == SANE_TRUE) )
{
y_dpi = x_dpi;
}
if (x_dpi > 0.0 && y_dpi > 0.0 && width > 0.0 && length > 0.0)
{
double x_dots_per_mm = x_dpi / MM_PER_INCH;
double y_dots_per_mm = y_dpi / MM_PER_INCH;
scanner->params.pixels_per_line = width * x_dots_per_mm;
scanner->params.lines = length * y_dots_per_mm;
}
}
mode = scanner->val[OPT_MODE].s;
if (strcmp(mode, LINEART_STR) == 0 || strcmp(mode, HALFTONE_STR) == 0)
{
scanner->params.format = SANE_FRAME_GRAY;
scanner->params.bytes_per_line = (scanner->params.pixels_per_line + 7) / 8;
scanner->params.depth = 1;
}
else if (strcmp(mode, GRAY_STR) == 0)
{
scanner->params.format = SANE_FRAME_GRAY;
scanner->params.bytes_per_line = scanner->params.pixels_per_line * scanner->output_bytes;
scanner->params.depth = 8 * scanner->output_bytes;
}
else if (strcmp(mode, COLOR_LINEART_STR) == 0 || strcmp(mode, COLOR_HALFTONE_STR) == 0 )
{
if (scanner->device->inquiry_one_pass_color)
{
scanner->device->three_pass = 0;
scanner->params.format = SANE_FRAME_RGB;
scanner->params.bytes_per_line = 3 * scanner->params.pixels_per_line;
scanner->params.depth = 8;
}
else /* three pass color */
{
scanner->device->three_pass = 1;
scanner->params.format = SANE_FRAME_RED + scanner->device->three_pass_color - 1;
scanner->params.bytes_per_line = scanner->params.pixels_per_line;
scanner->params.depth = 8;
}
}
else /* RGB */
{
if (scanner->device->inquiry_one_pass_color)
{
scanner->device->three_pass = 0;
scanner->params.format = SANE_FRAME_RGB;
scanner->params.bytes_per_line = 3 * scanner->params.pixels_per_line * scanner->output_bytes;
scanner->params.depth = 8 * scanner->output_bytes;
}
else /* three pass color */
{
scanner->device->three_pass = 1;
scanner->params.format = SANE_FRAME_RED + scanner->device->three_pass_color - 1;
scanner->params.bytes_per_line = scanner->params.pixels_per_line * scanner->output_bytes;
scanner->params.depth = 8 * scanner->output_bytes;
}
}
scanner->params.last_frame = (scanner->params.format != SANE_FRAME_RED && scanner->params.format != SANE_FRAME_GREEN);
if (params)
{
*params = scanner->params;
}
return SANE_STATUS_GOOD;
}
/* ------------------------------------------------------------ SANE START --------------------------------- */
SANE_Status sane_start(SANE_Handle handle)
{
Umax_Scanner *scanner = handle;
const char *mode;
double xbasedots, ybasedots;
const char *scan_source;
int pause;
int status;
int fds[2];
DBG(DBG_sane_init,"sane_start\n");
/* Invalidate reader_pid so a subsequent error and following call to
* do_cancel() won't trip over it. */
sanei_thread_invalidate(scanner->reader_pid);
mode = scanner->val[OPT_MODE].s;
if (scanner->device->sfd == -1) /* first call, don`t run this routine again on multi frame or multi image scan */
{
umax_initialize_values(scanner->device); /* reset values */
scanner->device->three_pass_color = 1;
/* test for adf and uta */
scan_source = scanner->val[OPT_SOURCE].s;
if (strcmp(scan_source, UTA_STR) == 0)
{
if ( (scanner->device->inquiry_uta != 0) && (scanner->device->inquiry_transavail != 0) )
{
scanner->device->uta = 1;
}
else
{
DBG(DBG_error,"ERROR: Transparency Adapter not available\n");
umax_scsi_close(scanner->device);
return SANE_STATUS_INVAL;
}
}
else /* Test if ADF is selected */
{
scanner->device->uta = 0;
if (strcmp(scan_source, ADF_STR) == 0)
{
if ( (scanner->device->inquiry_adf) && (scanner->device->inquiry_adfmode) )
{
scanner->device->adf = 1;
}
else
{
DBG(DBG_error,"ERROR: Automatic Document Feeder not available\n");
umax_scsi_close(scanner->device);
return SANE_STATUS_INVAL;
}
}
else
{
scanner->device->adf = 0;
}
}
if (scanner->device->inquiry_GIB & 32) /* 16 bit input mode */
{
scanner->device->gamma_input_bits_code = 32;
DBG(DBG_sane_info, "Using 16 bits for gamma input\n");
}
else if (scanner->device->inquiry_GIB & 16) /* 14 bit input mode */
{
scanner->device->gamma_input_bits_code = 16;
DBG(DBG_sane_info, "Using 14 bits for gamma input\n");
}
else if (scanner->device->inquiry_GIB & 8) /* 12 bit input mode */
{
scanner->device->gamma_input_bits_code = 8;
DBG(DBG_sane_info, "Using 12 bits for gamma input\n");
}
else if (scanner->device->inquiry_GIB & 4) /* 10 bit input mode */
{
scanner->device->gamma_input_bits_code = 4;
DBG(DBG_sane_info, "Using 10 bits for gamma input\n");
}
else if (scanner->device->inquiry_GIB & 2) /* 9 bit input mode */
{
scanner->device->gamma_input_bits_code = 2;
DBG(DBG_sane_info, "Using 9 bits for gamma input\n");
}
else /* 8 bit input mode */
{
scanner->device->gamma_input_bits_code = 1;
DBG(DBG_sane_info, "Using 8 bits for gamma input\n");
}
if (scanner->val[OPT_BIT_DEPTH].w == 16) /* 16 bit output mode */
{
scanner->device->bits_per_pixel = 16;
scanner->device->bits_per_pixel_code = 32;
scanner->device->max_value = 65535;
DBG(DBG_sane_info,"Using 16 bits for output\n");
}
else if (scanner->val[OPT_BIT_DEPTH].w == 14) /* 14 bit output mode */
{
scanner->device->bits_per_pixel = 14;
scanner->device->bits_per_pixel_code = 16;
scanner->device->max_value = 16383;
DBG(DBG_sane_info,"Using 14 bits for output\n");
}
else if (scanner->val[OPT_BIT_DEPTH].w == 12) /* 12 bit output mode */
{
scanner->device->bits_per_pixel = 12;
scanner->device->bits_per_pixel_code = 8;
scanner->device->max_value = 4095;
DBG(DBG_sane_info,"Using 12 bits for output\n");
}
else if (scanner->val[OPT_BIT_DEPTH].w == 10) /* 10 bit output mode */
{
scanner->device->bits_per_pixel = 10;
scanner->device->bits_per_pixel_code = 4;
scanner->device->max_value = 1023;
DBG(DBG_sane_info,"Using 10 bits for output\n");
}
else if (scanner->val[OPT_BIT_DEPTH].w == 9) /* 9 bit output mode */
{
scanner->device->bits_per_pixel = 9;
scanner->device->bits_per_pixel_code = 2;
scanner->device->max_value = 511;
DBG(DBG_sane_info,"Using 9 bits for output\n");
}
else /* 8 bit output mode */
{
scanner->device->bits_per_pixel = 8;
scanner->device->bits_per_pixel_code = 1;
scanner->device->max_value = 255;
DBG(DBG_sane_info,"Using 8 bits for output\n");
}
scanner->device->reverse = scanner->device->reverse_multi = scanner->val[OPT_NEGATIVE].w;
scanner->device->threshold = P_100_TO_255(scanner->val[OPT_THRESHOLD].w);
scanner->device->brightness = P_200_TO_255(scanner->val[OPT_BRIGHTNESS].w);
scanner->device->contrast = P_200_TO_255(scanner->val[OPT_CONTRAST].w);
scanner->device->batch_scan = ( scanner->val[OPT_BATCH_SCAN_START].w ||
scanner->val[OPT_BATCH_SCAN_LOOP].w ||
scanner->val[OPT_BATCH_SCAN_END].w );
scanner->device->batch_end = scanner->val[OPT_BATCH_SCAN_END].w;
scanner->device->batch_next_tl_y = SANE_UNFIX(scanner->val[OPT_BATCH_NEXT_TL_Y].w) * scanner->device->y_coordinate_base / MM_PER_INCH;
if (scanner->val[OPT_BATCH_NEXT_TL_Y].w == 0xFFFF) /* option not set: use br_y => scanhead stops at end of batch area */
{
scanner->device->batch_next_tl_y = SANE_UNFIX(scanner->val[OPT_BR_Y].w) * scanner->device->y_coordinate_base / MM_PER_INCH;
}
if ((scanner->device->batch_scan) && !scanner->val[OPT_BATCH_SCAN_START].w)
{
scanner->device->calibration = 9; /* no calibration - otherwise the scanhead will go into calibration position */
}
else
{
scanner->device->calibration = 0; /* calibration defined by image type */
}
scanner->device->quality = scanner->val[OPT_QUALITY].w;
scanner->device->dor = scanner->val[OPT_DOR].w;
scanner->device->preview = scanner->val[OPT_PREVIEW].w;
scanner->device->warmup = scanner->val[OPT_WARMUP].w;
scanner->device->fix_focus_position = scanner->val[OPT_FIX_FOCUS_POSITION].w;
scanner->device->lens_cal_in_doc_pos = scanner->val[OPT_LENS_CALIBRATION_DOC_POS].w;
scanner->device->disable_pre_focus = scanner->val[OPT_DISABLE_PRE_FOCUS].w;
scanner->device->holder_focus_pos_0mm = scanner->val[OPT_HOLDER_FOCUS_POS_0MM].w;
scanner->device->manual_focus = scanner->val[OPT_MANUAL_PRE_FOCUS].w;
scanner->device->analog_gamma_r =
scanner->device->analog_gamma_g =
scanner->device->analog_gamma_b = umax_calculate_analog_gamma(SANE_UNFIX(scanner->val[OPT_ANALOG_GAMMA].w));
scanner->device->highlight_r =
scanner->device->highlight_g =
scanner->device->highlight_b = P_100_TO_255(scanner->val[OPT_HIGHLIGHT].w);
scanner->device->shadow_r =
scanner->device->shadow_g =
scanner->device->shadow_b = P_100_TO_255(scanner->val[OPT_SHADOW].w);
if (scanner->val[OPT_SELECT_EXPOSURE_TIME].w == SANE_TRUE)
{
if (scanner->val[OPT_SELECT_CAL_EXPOSURE_TIME].w) /* separate calibration exposure time */
{
scanner->device->exposure_time_calibration_r =
scanner->device->exposure_time_calibration_g =
scanner->device->exposure_time_calibration_b = scanner->val[OPT_CAL_EXPOS_TIME].w;
}
else /* same exposure times for calibration as for scanning */
{
scanner->device->exposure_time_calibration_r =
scanner->device->exposure_time_calibration_g =
scanner->device->exposure_time_calibration_b = scanner->val[OPT_SCAN_EXPOS_TIME].w;
}
scanner->device->exposure_time_scan_r =
scanner->device->exposure_time_scan_g =
scanner->device->exposure_time_scan_b = scanner->val[OPT_SCAN_EXPOS_TIME].w;
}
if (scanner->val[OPT_SELECT_LAMP_DENSITY].w == SANE_TRUE)
{
scanner->device->c_density = P_100_TO_254(scanner->val[OPT_CAL_LAMP_DEN].w);
scanner->device->s_density = P_100_TO_254(scanner->val[OPT_SCAN_LAMP_DEN].w);
}
if (strcmp(mode, LINEART_STR) == 0)
{
scanner->device->colormode = LINEART;
}
else if (strcmp(mode, HALFTONE_STR) == 0)
{
scanner->device->colormode = HALFTONE;
}
else if (strcmp(mode, GRAY_STR) == 0)
{
scanner->device->colormode = GRAYSCALE;
}
else if (strcmp(mode, COLOR_LINEART_STR) == 0)
{
scanner->device->colormode = RGB_LINEART;
}
else if (strcmp(mode, COLOR_HALFTONE_STR) == 0)
{
scanner->device->colormode = RGB_HALFTONE;
}
else if (strcmp(mode, COLOR_STR) == 0)
{
scanner->device->colormode = RGB;
if (scanner->val[OPT_RGB_BIND].w == SANE_FALSE)
{
scanner->device->analog_gamma_r =
umax_calculate_analog_gamma( SANE_UNFIX(scanner->val[OPT_ANALOG_GAMMA_R].w) );
scanner->device->analog_gamma_g =
umax_calculate_analog_gamma( SANE_UNFIX(scanner->val[OPT_ANALOG_GAMMA_G].w) );
scanner->device->analog_gamma_b =
umax_calculate_analog_gamma( SANE_UNFIX(scanner->val[OPT_ANALOG_GAMMA_B].w) );
scanner->device->highlight_r = P_100_TO_255(scanner->val[OPT_HIGHLIGHT_R].w);
scanner->device->highlight_g = P_100_TO_255(scanner->val[OPT_HIGHLIGHT_G].w);
scanner->device->highlight_b = P_100_TO_255(scanner->val[OPT_HIGHLIGHT_B].w);
scanner->device->shadow_r = P_100_TO_255(scanner->val[OPT_SHADOW_R].w);
scanner->device->shadow_g = P_100_TO_255(scanner->val[OPT_SHADOW_G].w);
scanner->device->shadow_b = P_100_TO_255(scanner->val[OPT_SHADOW_B].w);
if ((scanner->val[OPT_SELECT_EXPOSURE_TIME].w == SANE_TRUE) && (!scanner->device->exposure_time_rgb_bind))
{
if (scanner->val[OPT_SELECT_CAL_EXPOSURE_TIME].w) /* separate calibration exposure time */
{
scanner->device->exposure_time_calibration_r = scanner->val[OPT_CAL_EXPOS_TIME_R].w;
scanner->device->exposure_time_calibration_g = scanner->val[OPT_CAL_EXPOS_TIME_G].w;
scanner->device->exposure_time_calibration_b = scanner->val[OPT_CAL_EXPOS_TIME_B].w;
}
else /* same exposure times for calibration as for scanning */
{
scanner->device->exposure_time_calibration_r = scanner->val[OPT_SCAN_EXPOS_TIME_R].w;
scanner->device->exposure_time_calibration_g = scanner->val[OPT_SCAN_EXPOS_TIME_G].w;
scanner->device->exposure_time_calibration_b = scanner->val[OPT_SCAN_EXPOS_TIME_B].w;
}
scanner->device->exposure_time_scan_r = scanner->val[OPT_SCAN_EXPOS_TIME_R].w;
scanner->device->exposure_time_scan_g = scanner->val[OPT_SCAN_EXPOS_TIME_G].w;
scanner->device->exposure_time_scan_b = scanner->val[OPT_SCAN_EXPOS_TIME_B].w;
}
}
}
if (scanner->device->force_preview_bit_rgb != 0) /* in RGB-mode set preview bit, eg. for UMAX S6E */
{
if (scanner->device->colormode == RGB)
{
DBG(DBG_sane_info,"setting preview bit = 1 (option force-preview-bit-rgb)\n");
scanner->device->preview = SANE_TRUE;
}
}
#ifdef UMAX_CALIBRATION_MODE_SELECTABLE
if (strcmp(scanner->val[OPT_CALIB_MODE].s, CALIB_MODE_0000) == 0)
{
scanner->device->calibration = 0;
}
else if (strcmp(scanner->val[OPT_CALIB_MODE].s, CALIB_MODE_1111) == 0)
{
scanner->device->calibration = 15;
}
else if (strcmp(scanner->val[OPT_CALIB_MODE].s, CALIB_MODE_1110) == 0)
{
scanner->device->calibration = 14;
}
else if (strcmp(scanner->val[OPT_CALIB_MODE].s, CALIB_MODE_1101) == 0)
{
scanner->device->calibration = 13;
}
else if (strcmp(scanner->val[OPT_CALIB_MODE].s, CALIB_MODE_1010) == 0)
{
scanner->device->calibration = 10;
}
else if (strcmp(scanner->val[OPT_CALIB_MODE].s, CALIB_MODE_1001) == 0)
{
scanner->device->calibration = 9;
}
#endif
/* get and set geometric values for scanning */
scanner->device->x_resolution = SANE_UNFIX(scanner->val[OPT_X_RESOLUTION].w);
scanner->device->y_resolution = SANE_UNFIX(scanner->val[OPT_Y_RESOLUTION].w);
if ( (scanner->val[OPT_RESOLUTION_BIND].w == SANE_TRUE) || (scanner->val[OPT_PREVIEW].w == SANE_TRUE) )
{
scanner->device->y_resolution = scanner->device->x_resolution;
}
xbasedots = scanner->device->x_coordinate_base / MM_PER_INCH;
ybasedots = scanner->device->y_coordinate_base / MM_PER_INCH;
#if 0
scanner->device->upper_left_x = ((int) (SANE_UNFIX(scanner->val[OPT_TL_X].w) * xbasedots)) & 65534;
scanner->device->upper_left_y = ((int) (SANE_UNFIX(scanner->val[OPT_TL_Y].w) * ybasedots)) & 65534;
scanner->device->scanwidth = ((int)((SANE_UNFIX(scanner->val[OPT_BR_X].w - scanner->val[OPT_TL_X].w)) * xbasedots)) & 65534;
scanner->device->scanlength = ((int)((SANE_UNFIX(scanner->val[OPT_BR_Y].w - scanner->val[OPT_TL_Y].w)) * ybasedots)) & 65534;
#endif
scanner->device->upper_left_x = (int) (SANE_UNFIX(scanner->val[OPT_TL_X].w) * xbasedots);
scanner->device->upper_left_y = (int) (SANE_UNFIX(scanner->val[OPT_TL_Y].w) * ybasedots);
scanner->device->scanwidth = (int)((SANE_UNFIX(scanner->val[OPT_BR_X].w - scanner->val[OPT_TL_X].w)) * xbasedots);
scanner->device->scanlength = (int)((SANE_UNFIX(scanner->val[OPT_BR_Y].w - scanner->val[OPT_TL_Y].w)) * ybasedots);
if (umax_check_values(scanner->device) != 0)
{
DBG(DBG_error,"ERROR: invalid scan-values\n");
scanner->scanning = SANE_FALSE;
return SANE_STATUS_INVAL;
}
/* The scanner defines a x-origin-offset for DOR mode, this offset is used for the */
/* x range in this backend, so the frontend/user knows the correct positions related to */
/* scanner's surface. But the scanner wants x values from origin 0 instead */
/* of the x-origin defined by the scanner`s inquiry */
if (scanner->device->dor != 0) /* dor mode active */
{
DBG(DBG_info,"subtracting DOR x-origin-offset from upper left x\n");
scanner->device->upper_left_x -= scanner->device->inquiry_dor_x_off * scanner->device->x_coordinate_base; /* correct DOR x-origin */
if (scanner->device->upper_left_x < 0) /* rounding errors may create a negative value */
{
scanner->device->upper_left_x = 0; /* but negative values are not allowed */
}
}
scanner->params.bytes_per_line = scanner->device->row_len;
scanner->params.pixels_per_line = scanner->device->width_in_pixels;
scanner->params.lines = scanner->device->length_in_pixels;
/* set exposure times */
if ( scanner->device->inquiry_exposure_adj )
{
umax_calculate_exposure_time(scanner->device, scanner->device->use_exposure_time_def_r, &scanner->device->exposure_time_calibration_r);
umax_calculate_exposure_time(scanner->device, scanner->device->use_exposure_time_def_g, &scanner->device->exposure_time_calibration_g);
umax_calculate_exposure_time(scanner->device, scanner->device->use_exposure_time_def_b, &scanner->device->exposure_time_calibration_b);
umax_calculate_exposure_time(scanner->device, scanner->device->use_exposure_time_def_r, &scanner->device->exposure_time_scan_r);
umax_calculate_exposure_time(scanner->device, scanner->device->use_exposure_time_def_g, &scanner->device->exposure_time_scan_g);
umax_calculate_exposure_time(scanner->device, scanner->device->use_exposure_time_def_b, &scanner->device->exposure_time_scan_b);
}
else
{
scanner->device->exposure_time_calibration_r = scanner->device->exposure_time_calibration_g = scanner->device->exposure_time_calibration_b =
scanner->device->exposure_time_scan_r = scanner->device->exposure_time_scan_g = scanner->device->exposure_time_scan_b = 0;
}
scanner->scanning = SANE_TRUE;
sane_get_parameters(scanner, 0);
DBG(DBG_sane_info,"x_resolution (dpi) = %u\n", scanner->device->x_resolution);
DBG(DBG_sane_info,"y_resolution (dpi) = %u\n", scanner->device->y_resolution);
DBG(DBG_sane_info,"x_coordinate_base (dpi) = %u\n", scanner->device->x_coordinate_base);
DBG(DBG_sane_info,"y_coordinate_base (dpi) = %u\n", scanner->device->y_coordinate_base);
DBG(DBG_sane_info,"upper_left_x (xbase) = %d\n", scanner->device->upper_left_x);
DBG(DBG_sane_info,"upper_left_y (ybase) = %d\n", scanner->device->upper_left_y);
DBG(DBG_sane_info,"scanwidth (xbase) = %u\n", scanner->device->scanwidth);
DBG(DBG_sane_info,"scanlength (ybase) = %u\n", scanner->device->scanlength);
DBG(DBG_sane_info,"width in pixels = %u\n", scanner->device->width_in_pixels);
DBG(DBG_sane_info,"length in pixels = %u\n", scanner->device->length_in_pixels);
DBG(DBG_sane_info,"bits per pixel/color = %u\n", scanner->device->bits_per_pixel);
DBG(DBG_sane_info,"bytes per line = %d\n", scanner->params.bytes_per_line);
DBG(DBG_sane_info,"pixels_per_line = %d\n", scanner->params.pixels_per_line);
DBG(DBG_sane_info,"lines = %d\n", scanner->params.lines);
DBG(DBG_sane_info,"negative = %d\n", scanner->device->reverse);
DBG(DBG_sane_info,"threshold (lineart) = %d\n", scanner->device->threshold);
DBG(DBG_sane_info,"brightness (halftone) = %d\n", scanner->device->brightness);
DBG(DBG_sane_info,"contrast (halftone) = %d\n", scanner->device->contrast);
DBG(DBG_sane_info,"analog_gamma = %d %d %d\n",
scanner->device->analog_gamma_r,
scanner->device->analog_gamma_g,
scanner->device->analog_gamma_b);
DBG(DBG_sane_info,"highlight = %d %d %d\n",
scanner->device->highlight_r,
scanner->device->highlight_g,
scanner->device->highlight_b);
DBG(DBG_sane_info,"shadow = %d %d %d\n",
scanner->device->shadow_r,
scanner->device->shadow_g,
scanner->device->shadow_b);
DBG(DBG_sane_info,"calibrat. exposure time = %d %d %d\n",
scanner->device->exposure_time_calibration_r,
scanner->device->exposure_time_calibration_g,
scanner->device->exposure_time_calibration_b);
DBG(DBG_sane_info,"scan exposure time = %d %d %d\n",
scanner->device->exposure_time_scan_r,
scanner->device->exposure_time_scan_g,
scanner->device->exposure_time_scan_b);
#ifdef UMAX_CALIBRATION_MODE_SELECTABLE
DBG(DBG_sane_info,"calibration = %s\n", scanner->val[OPT_CALIB_MODE].s);
#endif
DBG(DBG_sane_info,"calibration mode number = %d\n", scanner->device->calibration);
DBG(DBG_sane_info,"batch scan = %d\n", scanner->device->batch_scan);
DBG(DBG_sane_info,"batch end = %d\n", scanner->device->batch_end);
DBG(DBG_sane_info,"batch next top left y = %d\n", scanner->device->batch_next_tl_y);
DBG(DBG_sane_info,"quality calibration = %d\n", scanner->device->quality);
DBG(DBG_sane_info,"warm up = %d\n", scanner->device->warmup);
DBG(DBG_sane_info,"fast preview function = %d\n", scanner->device->preview);
DBG(DBG_sane_info,"DOR = %d\n", scanner->device->dor);
DBG(DBG_sane_info,"ADF = %d\n", scanner->device->adf);
DBG(DBG_sane_info,"manual focus = %d\n", scanner->device->manual_focus);
DBG(DBG_sane_info,"fix focus position = %d\n", scanner->device->fix_focus_position);
DBG(DBG_sane_info,"disable pre focus = %d\n", scanner->device->disable_pre_focus);
DBG(DBG_sane_info,"lens cal in doc pos = %d\n", scanner->device->lens_cal_in_doc_pos);
DBG(DBG_sane_info,"holder focus pos 0mm = %d\n", scanner->device->holder_focus_pos_0mm);
if (scanner->val[OPT_PREVIEW].w) /* preview mode */
{
scanner->device->lines_max = scanner->device->request_preview_lines;
}
else /* scan mode */
{
scanner->device->lines_max = scanner->device->request_scan_lines;
}
#ifdef HAVE_SANEI_SCSI_OPEN_EXTENDED
{
unsigned int scsi_bufsize = 0;
scsi_bufsize = scanner->device->width_in_pixels * scanner->device->lines_max;
if (scsi_bufsize == 0) /* no scsi buffer size, take scanner buffer size */
{
scsi_bufsize = scanner->device->inquiry_vidmem;
}
if (scsi_bufsize < scanner->device->scsi_buffer_size_min) /* make sure buffer has at least minimum size */
{
scsi_bufsize = scanner->device->scsi_buffer_size_min;
}
else if (scsi_bufsize > scanner->device->scsi_buffer_size_max) /* make sure buffer does not exceed maximum size */
{
scsi_bufsize = scanner->device->scsi_buffer_size_max;
}
if (umax_scsi_open_extended(scanner->device->sane.name, scanner->device, sense_handler,
scanner->device, (int *) &scsi_bufsize) != 0)
{
DBG(DBG_error, "ERROR: sane_start: open failed\n");
scanner->scanning = SANE_FALSE;
return SANE_STATUS_INVAL;
}
if (scsi_bufsize < scanner->device->scsi_buffer_size_min) /* minimum size must be available */
{
DBG(DBG_error, "ERROR: sane_start: umax_scsi_open_extended returned too small scsi buffer\n");
umax_scsi_close((scanner->device));
scanner->scanning = SANE_FALSE;
return SANE_STATUS_NO_MEM;
}
DBG(DBG_info, "sane_start: umax_scsi_open_extended returned scsi buffer size = %d\n", scsi_bufsize);
if (scsi_bufsize < scanner->device->width_in_pixels) /* print warning when buffer is smaller than one scanline */
{
DBG(DBG_warning, "WARNING: sane_start: scsi buffer is smaller than one scanline\n");
}
if (scsi_bufsize != scanner->device->bufsize)
{
DBG(DBG_info, "sane_start: buffer size has changed, reallocating buffer\n");
if (scanner->device->buffer[0])
{
DBG(DBG_info, "sane_start: freeing SCSI buffer[0]\n");
free(scanner->device->buffer[0]); /* free buffer */
}
scanner->device->bufsize = scsi_bufsize;
DBG(DBG_info, "sane_start: allocating SCSI buffer[0]\n");
scanner->device->buffer[0] = malloc(scanner->device->bufsize); /* allocate buffer */
if (!scanner->device->buffer[0]) /* malloc failed */
{
DBG(DBG_error, "ERROR: sane_start: could not allocate buffer[0]\n");
umax_scsi_close(scanner->device);
scanner->device->bufsize = 0;
scanner->scanning = SANE_FALSE;
return SANE_STATUS_NO_MEM;
}
}
}
#else
if ( umax_scsi_open(scanner->device->sane.name, scanner->device, sense_handler,
scanner->device) != SANE_STATUS_GOOD )
{
scanner->scanning = SANE_FALSE;
DBG(DBG_error, "ERROR: sane_start: open of %s failed:\n", scanner->device->sane.name);
return SANE_STATUS_INVAL;
}
/* there is no need to reallocate the buffer because the size is fixed */
#endif
/* grab scanner */
if (umax_grab_scanner(scanner->device))
{
umax_scsi_close(scanner->device);
scanner->scanning = SANE_FALSE;
DBG(DBG_warning,"WARNING: unable to reserve scanner: device busy\n");
return SANE_STATUS_DEVICE_BUSY;
}
/* halftone pattern download is not ready in this version */
#if 0
/* send halftonepattern */
if ( (strcmp(mode, HALFTONE_STR) == 0) || (strcmp(mode, COLOR_HALFTONE_STR) == 0) )
{
umax_send_halftone_pattern(scanner->device, (char *) &(scanner->halftone_pattern[0]),
scanner->val[OPT_HALFTONE_DIMENSION].w );
scanner->device->halftone = WD_halftone_download;
} /* end of send halftonepattern */
#endif
} /* ------------ end of first call -------------- */
/* send gammacurves */
if (scanner->val[OPT_CUSTOM_GAMMA].w == SANE_TRUE)
{
if (strcmp(mode, COLOR_STR) == 0)
{
if (scanner->device->three_pass == 0) /* one pass color scan */
{
unsigned int i, dest, color, value;
char *gamma;
gamma = malloc( (size_t) (3 * scanner->gamma_length * scanner->output_bytes) );
if (gamma == NULL)
{
DBG(DBG_warning,"WARNING: not able to allocate memory for gamma table, gamma ignored !!!\n");
}
else
{
dest=0;
for(color=1; color <= 3; color++)
{
for(i=0; i < scanner->gamma_length; i++)
{
value = scanner->gamma_table[color][i];
if (scanner->output_bytes == 2)
{
gamma[dest++] = scanner->gamma_table[0][value] / 256;
}
gamma[dest++] = (scanner->gamma_table[0][value] & 255);
}
}
DBG(DBG_sane_info,"sending 3 * %d bytes of gamma data for RGB\n",
scanner->gamma_length * scanner->output_bytes);
umax_send_gamma_data(scanner->device, &gamma[0], 3);
scanner->device->digital_gamma_r =
scanner->device->digital_gamma_g =
scanner->device->digital_gamma_b = WD_gamma_download;
free(gamma);
}
}
else /* three pass color scan */
{
unsigned int i, dest, color, value;
char *gamma;
gamma = malloc( (size_t) (scanner->gamma_length * scanner->output_bytes) );
if (gamma == NULL)
{
DBG(DBG_warning,"not able to allocate memory for gamma table, gamma ignored !!!\n");
}
else
{
dest = 0;
color = scanner->device->three_pass_color;
for(i = 0; i < scanner->gamma_length; i++)
{
value = scanner->gamma_table[color][i];
if (scanner->output_bytes == 2)
{
gamma[dest++] = scanner->gamma_table[0][value] / 256;
}
gamma[dest++] = (scanner->gamma_table[0][value] & 255);
}
DBG(DBG_sane_info,"sending %d bytes of gamma data for color %d\n",
scanner->gamma_length * scanner->output_bytes, color);
umax_send_gamma_data(scanner->device, &gamma[0], 1);
scanner->device->digital_gamma_r =
scanner->device->digital_gamma_g =
scanner->device->digital_gamma_b = WD_gamma_download;
free(gamma);
}
}
}
else if (strcmp(mode, GRAY_STR) == 0) /* grayscale scan */
{
unsigned int i, dest;
char *gamma;
gamma = malloc( (size_t) (scanner->gamma_length * scanner->output_bytes) );
if (gamma == NULL)
{
DBG(DBG_warning,"WARNING: not able to allocate memory for gamma table, gamma ignored !!!\n");
}
else
{
dest=0;
for(i=0; i < scanner->gamma_length; i++)
{
if (scanner->output_bytes == 2)
{
gamma[dest++] = scanner->gamma_table[0][i] / 256;
}
gamma[dest++] = (scanner->gamma_table[0][i] & 255);
}
DBG(DBG_sane_info,"sending %d bytes of gamma data for gray\n",
scanner->gamma_length * scanner->output_bytes);
umax_send_gamma_data(scanner->device, &gamma[0], 1);
scanner->device->digital_gamma_r = WD_gamma_download;
free(gamma);
}
}
} /* end of send gammacurves */
if ( scanner->device->three_pass_color > WD_wid_red) /* three pass scan, not first pass */
{
umax_reposition_scanner(scanner->device);
}
umax_set_window_param(scanner->device);
status = umax_start_scan(scanner->device);
if (status) /* error */
{
umax_give_scanner(scanner->device); /* reposition and release scanner */
return status;
}
pause = scanner->device->pause_for_color_calibration;
if (scanner->device->colormode != RGB)
{
pause = scanner->device->pause_for_gray_calibration;
}
if (pause) /* Astra 2400S needs this pause (7sec in color, 4sec in gray mode) */
{
DBG(DBG_info2,"pause for calibration %d msec ...\n", pause);
usleep(((long) pause) * 1000); /* time in ms */
DBG(DBG_info2,"pause done\n");
}
status = umax_do_calibration(scanner->device);
if (status) /* error */
{
umax_give_scanner(scanner->device); /* reposition and release scanner */
return status;
}
if (scanner->device->pause_after_calibration) /* may be useful */
{
DBG(DBG_info2,"pause after calibration %d msec ...\n", scanner->device->pause_after_calibration);
usleep(((long) scanner->device->pause_after_calibration) * 1000); /* time in ms */
DBG(DBG_info2,"pause done\n");
}
if (pipe(fds) < 0)
{
DBG(DBG_error,"ERROR: could not create pipe\n");
scanner->scanning = SANE_FALSE;
umax_give_scanner(scanner->device); /* reposition and release scanner */
umax_scsi_close(scanner->device);
return SANE_STATUS_IO_ERROR;
}
scanner->pipe_read_fd = fds[0];
scanner->pipe_write_fd = fds[1];
/* start reader_process, deponds on OS if fork() or threads are used */
scanner->reader_pid = sanei_thread_begin(reader_process, (void *) scanner);
if (!sanei_thread_is_valid (scanner->reader_pid))
{
DBG(DBG_error, "ERROR: sanei_thread_begin failed (%s)\n", strerror(errno));
scanner->scanning = SANE_FALSE;
umax_give_scanner(scanner->device); /* reposition and release scanner */
umax_scsi_close(scanner->device);
return SANE_STATUS_NO_MEM; /* any other reason than no memory possible ? */
}
if (sanei_thread_is_forked())
{
close(scanner->pipe_write_fd);
scanner->pipe_write_fd = -1;
}
return SANE_STATUS_GOOD;
}
/* ------------------------------------------------------------ SANE READ ---------------------------------- */
SANE_Status sane_read(SANE_Handle handle, SANE_Byte *buf, SANE_Int max_len, SANE_Int *len)
{
Umax_Scanner *scanner = handle;
ssize_t nread;
*len = 0;
nread = read(scanner->pipe_read_fd, buf, max_len);
DBG(DBG_sane_info, "sane_read: read %ld bytes\n", (long) nread);
if (!(scanner->scanning)) /* OOPS, not scanning */
{
return do_cancel(scanner);
}
if (nread < 0)
{
if (errno == EAGAIN)
{
DBG(DBG_sane_info, "sane_read: EAGAIN\n");
return SANE_STATUS_GOOD;
}
else
{
do_cancel(scanner); /* we had an error, stop scanner */
return SANE_STATUS_IO_ERROR;
}
}
*len = nread;
if (nread == 0) /* EOF */
{
if ( (scanner->device->three_pass == 0) ||
(scanner->device->colormode <= RGB_LINEART) ||
(++(scanner->device->three_pass_color) > 3) )
{
do_cancel(scanner);
}
DBG(DBG_sane_proc,"closing read end of pipe\n");
if (scanner->pipe_read_fd >= 0)
{
close(scanner->pipe_read_fd);
scanner->pipe_read_fd = -1;
}
return SANE_STATUS_EOF;
}
return SANE_STATUS_GOOD;
}
/* ------------------------------------------------------------ SANE CANCEL -------------------------------- */
void sane_cancel(SANE_Handle handle)
{
Umax_Scanner *scanner = handle;
DBG(DBG_sane_init,"sane_cancel\n");
if (scanner->scanning)
{
do_cancel(scanner);
}
}
/* ------------------------------------------------------------ SANE SET IO MODE --------------------------- */
SANE_Status sane_set_io_mode(SANE_Handle handle, SANE_Bool non_blocking)
{
Umax_Scanner *scanner = handle;
DBG(DBG_sane_init,"sane_set_io_mode: non_blocking=%d\n", non_blocking);
if (!scanner->scanning) { return SANE_STATUS_INVAL; }
if (fcntl(scanner->pipe_read_fd, F_SETFL, non_blocking ? O_NONBLOCK : 0) < 0)
{
return SANE_STATUS_IO_ERROR;
}
return SANE_STATUS_GOOD;
}
/* ------------------------------------------------------------ SANE GET SELECT FD ------------------------- */
SANE_Status sane_get_select_fd(SANE_Handle handle, SANE_Int *fd)
{
Umax_Scanner *scanner = handle;
DBG(DBG_sane_init,"sane_get_select_fd\n");
if (!scanner->scanning)
{
return SANE_STATUS_INVAL;
}
*fd = scanner->pipe_read_fd;
return SANE_STATUS_GOOD;
}
/* ------------------------------------------------------------ EOF ---------------------------------------- */
|