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
|
/*
epson.c - SANE library for Epson flatbed scanners.
Based on Kazuhiro Sasayama previous
Work on epson.[ch] file from the SANE package.
Original code taken from sane-0.71
Copyright (C) 1997 Hypercore Software Design, Ltd.
modifications
Copyright (C) 1998-1999 Christian Bucher <bucher@vernetzt.at>
Copyright (C) 1998-1999 Kling & Hautzinger GmbH
Copyright (C) 1999 Norihiko Sawa <sawa@yb3.so-net.ne.jp>
Copyright (C) 2000 Mike Porter <mike@udel.edu> (mjp)
Copyright (C) 2003 EPSON KOWA Corporation
Copyright (C) 1999-2005 Karl Heinz Kremer <khk@khk.net>
Copyright (C) 2006 Claus Boje <claus@egehuset.dk>
*/
#define SANE_EPSON_VERSION "SANE Epson Backend v0.2.47 - 2006-08-21"
#define SANE_EPSON_BUILD 247
/*
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. */
/*
2006-08-21 Fix buffer overflow error (submitted by Johannes Meixner)
2006-06-11 Applied patch from Henning. Fixed a number of compiler warnings
2006-03-12 Added support for perfetion 4990 photo 4800 dpi
2005-01-09 "flaming hack to get USB scanners working without timeouts under linux"
submitted by "Steve" (in comment to bug #300830)
2004-12-18 Added USB IDs for CX-4600 and CX-3650
2004-10-16 Added USB ID for Expression 10000XL
2004-05-08 Disable feed() for Perfection1640
2004-02-08 Reformat all source code with "indent -bli0"
2004-02-01 Added D7 function level as copy of D1 for CX-6400
Added IDs for CX-6400 and Perfection 4870
2003-10-27 Replaced DBG(0, ... with DBG(1, ...
2003-09-12 Increment only once in loop to find USB scanners
Fix rounding problem when determining number of lines to scan
2003-08-21 Removed '//' comments - again ...
Added EPSON Kowa copyright message
2003-08-15 Added support for GT-30000, with support for the ADF in simplex mode
Borrowed some code from the EPSON Kowa IScan version of the backend
Use sanei_scsi_cmd2() to send commands. This makes this backend
useable for SBP-2 under FreeBSD
2003-05-11 Initialize OPT_LIMIT_RESOLUTION before first call to filter_resolution_list()
Fix memory problem in get_identity_information(). Both problems were
reported to the Debian bug database.
2003-03-26 Fixed two warnings reported by der Mouse
2003-02-16 Code cleanup, use more descriptive variable names.
2003-02-15 Move sanei_usb_init() to sane_init(). Thanks to Ron Cemer
for providing the patch.
2003-02-15 Fix problem with "usb <vendor> <product> syntax in config file
2002-12-28 Added advanced option to display only short resolution list for
displays that can not show the complete list.
2002-11-23 Fixed problem with dropout color.
2002-11-03 Full libusb support.
2002-10-05 Fixed problem with incorrect response to sane_get_parameters()
in certain situations.
2002-09-01 USB scanners are now using libsane-usb functions
2002-08-17 Fixed typo in variable name.
Fixed IEEE-1394 problem with Perfection-2450.
Fixed problem with older B3 level SCSI scanners that do
not support the extended status request.
2002-04-22 Declare close_scanner() and open_scanner() before they
are used.
2002-04-13 Check if scanner needs to be opened for the reset call.
(Thanks to Thomas Wenrich for pointing this out)
Added product IDs for Perfection 1650 and 2450
2002-01-18 Recognize GT-xxxx type scanners also when using the SCSI
or IEEE-1394 interface
2002-01-06 Disable TEST_IOCTL again, which was enabled by accident. Also
protect the ioctl portion with an #ifdef __linux__
2002-01-05 Version 0.2.17
Check for and set s->fd to -1 when device is closed.
Removed black gamma table - only use RGB even for grayscale
2002-01-01 Do not call access() for OS/2 systems
2001-11-13 Version 0.2.16
Do not call access() for parallel port scanners.
2001-11-11 Version 0.2.15
Fixed "wait-for-button" functionality, accidentally merged back wrong
version after code freeze.
Corrected "need-strange-reorder" recognition.
Added IOCTL support to header file.
2001-11-10 Version 0.2.14
Added "wait-for-button" functionality
2001-10-30 I18N patches (Stefan Roellin)
2001-10-28 Fixed bug with 1650 recognition
2001-06-09 Version 0.2.09
Changed debug level for sense handler from 0 to 2
2001-05-25 Version 0.2.07
Allow more than 8 bit color depth even for preview mode
since Xsane can handle this. Some code cleanup.
2001-05-24 Removed ancient code that was used to determine the resolution
back when the backend still had a slider for the resolution
selection.
2001-05-22 Version 0.2.06
Added sense_handler to support the GT-8000 scanner. Thanks to Matthias Trute
for figuring out the details.
Also added experimental code to use USB scanner probing. Need kernel patch
for this.
2001-05-19 Version 0.2.05
fixed the year in the recent change log entries - I now that it's
2001...
Finally fixed the TPU problem with B4 level scanners
2001-05-13 Version 0.2.04
Removed check for '\n' before end of line
Free memory malloced in sane_get_devices() in sane_exit() again
2001-04-22 Version 0.2.03
Check first if the scanner does support the set film type
and set focus position before the GUI elements are displayed.
This caused problems with older (B4 level) scanners when a TPU
was connected.
2001-03-31 Version 0.2.02
2001-03-17 Next attempt to get the reported number of lines correct
for the "color shuffling" part.
Added more comments.
2000-12-25 Version 0.2.01
Fixed problem with bilevel scanning with Perfection610: The
line count has to be an even number with this scanner.
Several initialization fixes regarding bit depth selection.
This version goes back into the CVS repository, the 1.0.4
release is out and therefore the code freeze is over.
Some general cleanup, added more comments.
2000-12-09 Version 0.2.00
Cleaned up printing of gamma table data. 16 elements
are now printed in one line without the [epson] in
between the values. Values are only printed for
Debug levels >= 10.
2000-12-04 We've introduced the concept of inverting images
when scanning from a TPU. This is fine, but
the user supplied gamma tables no longer work.
This is because the data a frontend is going
to compute a gamma table for is not what the
scanner actually sent. So, we have to back into
the proper gamma table. I think this works. See
set_gamma_table. (mjp)
2000-12-03 added the 12/14/16 bit support again.
2000-12-03 Version 0.1.38
removed changes regarding 12/14 bit support because
of SANE feature freeze for 1.0.4. The D1 fix for
reading the values from the scanner instead of using
hardcoded values and the fix for the off-by-one error
in the reorder routine are still in the code base.
Also force reload after change of scan mode.
The full backend can be downloaded from my web site at
http://www.freecolormanagement.com/sane
2000-12-03 Fixed off-by-one error in color reordering function.
2000-12-02 Read information about optical resolution and line
distance from scanner instead of hardcoded values.
Add support for color depth > 8 bits per channel.
2000-11-23 Display "Set Focus" control only for scanners that
can actually handle the command.
2000-11-19 Added support for the "set focus position" command,
this is necessary for the Expression1600.
2000-07-28 Changed #include <...> to #include "..." for the
sane/... include files.
2000-07-26 Fixed problem with Perfection610: The variable
s->color_shuffle_line was never correctly initialized
2000-06-28 When closing the scanner device the data that's
still in the scanner, waiting to be transferred
is flushed. This fixes the problem with scanimage -T
2000-06-13 Invert image when scanning negative with TPU,
Show film type only when TPU is selected
2000-06-13 Initialize optical_res to 0 (Dave Hill)
2000-06-07 Fix in sane_close() - found by Henning Meier-Geinitz
2000-06-01 Threshold should only be active when scan depth
is 1 and halftoning is off. (mjp)
2000-05-28 Turned on scanner based color correction.
Dependencies between many options are now
being enforced. For instance, auto area seg
(AAS) should only be on when scan depth == 1.
Added some routines to active and deactivate
options. Routines report if option changed.
Help prevent extraneous option reloads. Split
sane_control_option in getvalue and setvalue.
Further split up setvalue into several different
routines. (mjp)
2000-05-21 In sane_close use close_scanner instead of just the
SCSI close function.
2000-05-20 ... finally fixed the problem with the 610
Added resolution_list to Epson_Device structure in
epson.h - this fixes a bug that caused problems when
more than one EPSON scanner was connected.
2000-05-13 Fixed the color problem with the Perfection 610. The few
lines with "garbage" at the beginning of the scan are not
yet removed.
2000-05-06 Added support for multiple EPSON scanners. At this time
this may not be bug free, but it's a start and it seems
to work well with just one scanner.
2000-04-06 Did some cleanup on the gamma correction part. The user
defined table is now initialized to gamma=1, the gamma
handling is also no longer depending on platform specific
tables (handled instead by pointers to the actual tables)
2000-03-27 Disable request for push button status
2000-03-22 Removed free() calls to static strings to remove
compile warnings. These were introduced to apparently
fix an OS/2 bug. It now turned out that they are not
necessary. The real fix was in the repository for a
long time (2000-01-25).
2000-03-19 Fixed problem with A4 level devices - they use the
line mode instead of the block mode. The routine to
handle this was screwed up pretty bad. Now I have
a solid version that handles all variations of line
mode (automatically deals with the order the color
lines are sent).
2000-03-06 Fixed occasional crash after warm up when the "in warmup
state" went away in between doing ESC G and getting the
extended status message.
2000-03-02 Code cleanup, disabled ZOOM until I have time to
deal with all the side effects.
2000-03-01 More D1 fixes. In the future I have to come up with
a more elegant solution to distinguish between different
function levels. The level > n does not work anymore with
D1.
Added support for "set threshold" and "set zoom".
2000-02-23 First stab at level D1 support, also added a test
for valid "set halftone" command to enable OPT_HALFTONE
2000-02-21 Check for "warming up" in after sane_start. This is
IMHO a horrible hack, but that's the only way without
a major redesign that will work. (KHK)
2000-02-20 Added some cleanup on error conditions in attach()
Use new sanei_config_read() instead of fgets() for
compatibility with OS/2 (Yuri Dario)
2000-02-19 Changed some "int" to "size_t" types
Removed "Preview Resolution"
Implemented resolution list as WORD_LIST instead of
a RANGE (KHK)
2000-02-11 Default scan source is always "Flatbed", regardless
of installed options. Corrected some typos. (KHK)
2000-02-03 Gamma curves now coupled with gamma correction menu.
Only when "User defined" is selected are the curves
selected. (Dave Hill)
Renamed "Contrast" to "Gamma Correction" (KHK)
2000-02-02 "Brown Paper Bag Release" Put the USB fix finally
into the CVS repository.
2000-02-01 Fixed problem with USB scanner not being recognized
because of the changes to attach a few days ago. (KHK)
2000-01-29 fixed core dump with xscanimage by moving the gamma
curves to the standard interface (no longer advanced)
Removed pragma pack() from source code to make it
easier to compile on non-gcc compilers (KHK)
2000-01-26 fixed problem with resolution selection when using the
resolution list in xsane (KHK)
2000-01-25 moved the section where the device name is assigned
in attach. This avoids the core dump of frontend
applications when no scanner is found (Dave Hill)
2000-01-24 reorganization of SCSI related "helper" functions
started support for user defined color correction -
this is not yet available via the UI (Christian Bucher)
2000-01-24 Removed C++ style comments '//' (KHK)
*/
/* #define TEST_IOCTL */
/* DON'T CHANGE THE NEXT LINE ! */
/* #undef FORCE_COLOR_SHUFFLE */
#ifdef _AIX
#include <lalloca.h> /* MUST come first for AIX! */
#endif
/* --------------------- SANE INTERNATIONALISATION ------------------ */
#ifndef SANE_I18N
#define SANE_I18N(text) (text)
#endif
#include "../include/sane/config.h"
#include <lalloca.h>
#include <limits.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include "../include/sane/sane.h"
#include "../include/sane/saneopts.h"
#include "../include/sane/sanei_scsi.h"
#include "../include/sane/sanei_usb.h"
#include "../include/sane/sanei_pio.h"
#define BACKEND_NAME epson
#include "../include/sane/sanei_backend.h"
#include "../include/sane/sanei_config.h"
#include "epson.h"
#include "epson_scsi.h"
#include "epson_usb.h"
#define EPSON_CONFIG_FILE "epson.conf"
#ifndef PATH_MAX
#define PATH_MAX (1024)
#endif
#define walloc(x) (x *)malloc(sizeof(x))
#define walloca(x) (x *)alloca(sizeof(x))
#ifndef XtNumber
#define XtNumber(x) ( sizeof(x)/ sizeof(x[0]) )
#define XtOffset(p_type,field) ((size_t)&(((p_type)NULL)->field))
#define XtOffsetOf(s_type,field) XtOffset(s_type*,field)
#endif
#define NUM_OF_HEX_ELEMENTS (16) /* number of hex numbers per line for data dump */
#define DEVICE_NAME_LEN (16) /* length of device name in extended status */
/* NOTE: you can find these codes with "man ascii". */
#define STX 0x02
#define ACK 0x06
#define NAK 0x15
#define CAN 0x18
#define ESC 0x1B
#define PF 0x19
#define S_ACK "\006"
#define S_CAN "\030"
#define STATUS_FER 0x80 /* fatal error */
#define STATUS_AREA_END 0x20 /* area end */
#define STATUS_OPTION 0x10 /* option installed */
#define EXT_STATUS_FER 0x80 /* fatal error */
#define EXT_STATUS_FBF 0x40 /* flat bed scanner */
#define EXT_STATUS_WU 0x02 /* warming up */
#define EXT_STATUS_PB 0x01 /* scanner has a push button */
#define EXT_STATUS_IST 0x80 /* option detected */
#define EXT_STATUS_EN 0x40 /* option enabled */
#define EXT_STATUS_ERR 0x20 /* other error */
#define EXT_STATUS_PE 0x08 /* no paper */
#define EXT_STATUS_PJ 0x04 /* paper jam */
#define EXT_STATUS_OPN 0x02 /* cover open */
#define EPSON_LEVEL_A1 0
#define EPSON_LEVEL_A2 1
#define EPSON_LEVEL_B1 2
#define EPSON_LEVEL_B2 3
#define EPSON_LEVEL_B3 4
#define EPSON_LEVEL_B4 5
#define EPSON_LEVEL_B5 6
#define EPSON_LEVEL_B6 7
#define EPSON_LEVEL_B7 8
#define EPSON_LEVEL_B8 9
#define EPSON_LEVEL_F5 10
#define EPSON_LEVEL_D1 11
#define EPSON_LEVEL_D7 12
#define EPSON_LEVEL_D8 13
/* there is also a function level "A5", which I'm ignoring here until somebody can
convince me that this is still needed. The A5 level was for the GT-300, which
was (is) a monochrome only scanner. So if somebody really wants to use this
scanner with SANE get in touch with me and we can work something out - khk */
#define EPSON_LEVEL_DEFAULT EPSON_LEVEL_B3
static EpsonCmdRec epson_cmd[] = {
/*
* request identity
* | request identity2
* | | request status
* | | | request condition
* | | | | set color mode
* | | | | | start scanning
* | | | | | | set data format
* | | | | | | | set resolution
* | | | | | | | | set zoom
* | | | | | | | | | set scan area
* | | | | | | | | | | set brightness
* | | | | | | | | | | | set gamma
* | | | | | | | | | | | | set halftoning
* | | | | | | | | | | | | | set color correction
* | | | | | | | | | | | | | | initialize scanner
* | | | | | | | | | | | | | | | set speed
* | | | | | | | | | | | | | | | | set lcount
* | | | | | | | | | | | | | | | | | mirror image
* | | | | | | | | | | | | | | | | | | set gamma table
* | | | | | | | | | | | | | | | | | | | set outline emphasis
* | | | | | | | | | | | | | | | | | | | | set dither
* | | | | | | | | | | | | | | | | | | | | | set color correction coefficients
* | | | | | | | | | | | | | | | | | | | | | | request extension status
* | | | | | | | | | | | | | | | | | | | | | | | control an extension
* | | | | | | | | | | | | | | | | | | | | | | | | forward feed / eject
* | | | | | | | | | | | | | | | | | | | | | | | | | feed
* | | | | | | | | | | | | | | | | | | | | | | | | | | request push button status
* | | | | | | | | | | | | | | | | | | | | | | | | | | | control auto area segmentation
* | | | | | | | | | | | | | | | | | | | | | | | | | | | | set film type
* | | | | | | | | | | | | | | | | | | | | | | | | | | | | | set exposure time
* | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | set bay
* | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | set threshold
* | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | set focus position
* | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | request focus position
* | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
* | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
*/
{"A1", 'I', 0, 'F','S', 0, 'G', 0, 'R', 0, 'A', 0, {0,0,0}, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{"A2", 'I', 0, 'F','S', 0, 'G','D','R','H','A','L',{-3,3,0}, 'Z','B', 0, '@', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{"B1", 'I', 0, 'F','S','C','G','D','R', 0, 'A', 0, {0,0,0}, 0, 'B', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{"B2", 'I', 0, 'F','S','C','G','D','R','H','A','L',{-3,3,0}, 'Z','B', 0, '@', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{"B3", 'I', 0, 'F','S','C','G','D','R','H','A','L',{-3,3,0}, 'Z','B','M','@', 0, 0, 0, 0, 0, 0, 'm','f','e', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{"B4", 'I', 0, 'F','S','C','G','D','R','H','A','L',{-3,3,0}, 'Z','B','M','@','g','d', 0, 'z','Q','b','m','f','e', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{"B5", 'I', 0, 'F','S','C','G','D','R','H','A','L',{-3,3,0}, 'Z','B','M','@','g','d','K','z','Q','b','m','f','e', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{"B6", 'I', 0, 'F','S','C','G','D','R','H','A','L',{-3,3,0}, 'Z','B','M','@','g','d','K','z','Q','b','m','f','e', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{"B7", 'I', 0, 'F','S','C','G','D','R','H','A','L',{-4,3,0}, 'Z','B','M','@','g','d','K','z','Q','b','m','f','e','\f', 0, '!','s','N', 0, 0, 't', 0, 0},
{"B8", 'I', 0, 'F','S','C','G','D','R','H','A','L',{-4,3,0}, 'Z','B','M','@','g','d','K','z','Q','b','m','f','e','\f', 0x19,'!','s','N', 0, 0, 0, 'p','q'},
{"F5", 'I', 0, 'F','S','C','G','D','R','H','A','L',{-3,3,0}, 'Z', 0, 'M','@','g','d','K','z','Q', 0, 'm','f','e','\f', 0, 0, 0, 'N','T','P', 0, 0, 0},
{"D1", 'I','i','F', 0, 'C','G','D','R', 0, 'A', 0, {0,0,0}, 'Z', 0, 0, '@','g','d', 0, 'z', 0, 0, 0, 'f', 0, 0, 0, '!', 0, 0, 0, 0, 0, 0, 0},
{"D7", 'I', 0, 'F', 0, 'C','G','D','R', 0, 'A', 0, {0,0,0}, 'Z', 0, 0, '@','g','d', 0, 'z', 0, 0, 0, 'f', 0, 0, 0, '!', 0, 0, 0, 0, 0, 0, 0},
{"D8", 'I','i','F', 0, 'C','G','D','R', 0, 'A', 0, {0,0,0}, 'Z', 0, 0, '@','g','d', 0, 'z', 0, 0, 0, 'f','e', 0, 0, '!', 0, 0, 0, 0, 0, 0, 0},
};
/*
* Definition of the mode_param struct, that is used to
* specify the valid parameters for the different scan modes.
*
* The depth variable gets updated when the bit depth is modified.
*/
struct mode_param
{
int color;
int mode_flags;
int dropout_mask;
int depth;
};
static struct mode_param mode_params[] = {
{0, 0x00, 0x30, 1},
{0, 0x00, 0x30, 8},
{1, 0x02, 0x00, 8}
};
static const SANE_String_Const mode_list[] = {
SANE_VALUE_SCAN_MODE_LINEART,
SANE_VALUE_SCAN_MODE_GRAY,
SANE_VALUE_SCAN_MODE_COLOR,
NULL
};
static const SANE_String_Const adf_mode_list[] = {
SANE_I18N ("Simplex"),
SANE_I18N ("Duplex"),
NULL
};
/*
* Define the different scan sources:
*/
#define FBF_STR SANE_I18N("Flatbed")
#define TPU_STR SANE_I18N("Transparency Unit")
#define ADF_STR SANE_I18N("Automatic Document Feeder")
/*
* source list need one dummy entry (save device settings is crashing).
* NOTE: no const - this list gets created while exploring the capabilities
* of the scanner.
*/
static SANE_String_Const source_list[] = {
FBF_STR,
NULL,
NULL,
NULL
};
/* some defines to make handling the TPU easier: */
#define FILM_TYPE_POSITIVE (0)
#define FILM_TYPE_NEGATIVE (1)
static const SANE_String_Const film_list[] = {
SANE_I18N ("Positive Film"),
SANE_I18N ("Negative Film"),
NULL
};
static const SANE_String_Const focus_list[] = {
SANE_I18N ("Focus on glass"),
SANE_I18N ("Focus 2.5mm above glass"),
NULL
};
/*
* TODO: add some missing const.
*/
#define HALFTONE_NONE 0x01
#define HALFTONE_TET 0x03
static int halftone_params[] = {
HALFTONE_NONE,
0x00,
0x10,
0x20,
0x80,
0x90,
0xa0,
0xb0,
HALFTONE_TET,
0xc0,
0xd0
};
static const SANE_String_Const halftone_list[] = {
SANE_I18N ("None"),
SANE_I18N ("Halftone A (Hard Tone)"),
SANE_I18N ("Halftone B (Soft Tone)"),
SANE_I18N ("Halftone C (Net Screen)"),
NULL
};
static const SANE_String_Const halftone_list_4[] = {
SANE_I18N ("None"),
SANE_I18N ("Halftone A (Hard Tone)"),
SANE_I18N ("Halftone B (Soft Tone)"),
SANE_I18N ("Halftone C (Net Screen)"),
SANE_I18N ("Dither A (4x4 Bayer)"),
SANE_I18N ("Dither B (4x4 Spiral)"),
SANE_I18N ("Dither C (4x4 Net Screen)"),
SANE_I18N ("Dither D (8x4 Net Screen)"),
NULL
};
static const SANE_String_Const halftone_list_7[] = {
SANE_I18N ("None"),
SANE_I18N ("Halftone A (Hard Tone)"),
SANE_I18N ("Halftone B (Soft Tone)"),
SANE_I18N ("Halftone C (Net Screen)"),
SANE_I18N ("Dither A (4x4 Bayer)"),
SANE_I18N ("Dither B (4x4 Spiral)"),
SANE_I18N ("Dither C (4x4 Net Screen)"),
SANE_I18N ("Dither D (8x4 Net Screen)"),
SANE_I18N ("Text Enhanced Technology"),
SANE_I18N ("Download pattern A"),
SANE_I18N ("Download pattern B"),
NULL
};
static int dropout_params[] = {
0x00, /* none */
0x10, /* red */
0x20, /* green */
0x30 /* blue */
};
static const SANE_String_Const dropout_list[] = {
SANE_I18N ("None"),
SANE_I18N ("Red"),
SANE_I18N ("Green"),
SANE_I18N ("Blue"),
NULL
};
/*
* Color correction:
* One array for the actual parameters that get sent to the scanner (color_params[]),
* one array for the strings that get displayed in the user interface (color_list[])
* and one array to mark the user defined color correction (dolor_userdefined[]).
*/
static int color_params[] = {
0x00,
0x01,
0x10,
0x20,
0x40,
0x80
};
static SANE_Bool color_userdefined[] = {
SANE_FALSE,
SANE_TRUE,
SANE_FALSE,
SANE_FALSE,
SANE_FALSE,
SANE_FALSE
};
static const SANE_String_Const color_list[] = {
SANE_I18N ("No Correction"),
SANE_I18N ("User defined"),
SANE_I18N ("Impact-dot printers"),
SANE_I18N ("Thermal printers"),
SANE_I18N ("Ink-jet printers"),
SANE_I18N ("CRT monitors"),
NULL
};
/*
* Gamma correction:
* The A and B level scanners work differently than the D level scanners, therefore
* I define two different sets of arrays, plus one set of variables that get set to
* the actually used params and list arrays at runtime.
*/
static int gamma_params_ab[] = {
0x01,
0x03,
0x00,
0x10,
0x20
};
static const SANE_String_Const gamma_list_ab[] = {
SANE_I18N ("Default"),
SANE_I18N ("User defined"),
SANE_I18N ("High density printing"),
SANE_I18N ("Low density printing"),
SANE_I18N ("High contrast printing"),
NULL
};
static SANE_Bool gamma_userdefined_ab[] = {
SANE_FALSE,
SANE_TRUE,
SANE_FALSE,
SANE_FALSE,
SANE_FALSE,
};
static int gamma_params_d[] = {
0x03,
0x04
};
static const SANE_String_Const gamma_list_d[] = {
SANE_I18N ("User defined (Gamma=1.0)"),
SANE_I18N ("User defined (Gamma=1.8)"),
NULL
};
static SANE_Bool gamma_userdefined_d[] = {
SANE_TRUE,
SANE_TRUE
};
static SANE_Bool *gamma_userdefined;
static int *gamma_params;
/* flaming hack to get USB scanners
working without timeouts under linux */
/* (cribbed from fujitsu.c) */
static unsigned int r_cmd_count = 0;
static unsigned int w_cmd_count = 0;
/* Bay list:
* this is used for the FilmScan
*/
static const SANE_String_Const bay_list[] = {
" 1 ",
" 2 ",
" 3 ",
" 4 ",
" 5 ",
" 6 ",
NULL
};
/*
* minimum, maximum, quantization.
*/
static const SANE_Range u8_range = { 0, 255, 0 };
static const SANE_Range s8_range = { -127, 127, 0 };
static const SANE_Range zoom_range = { 50, 200, 0 };
/*
* The "switch_params" are used for several boolean choices
*/
static int switch_params[] = {
0,
1
};
#define mirror_params switch_params
#define speed_params switch_params
#define film_params switch_params
static const SANE_Range outline_emphasis_range = { -2, 2, 0 };
/* static const SANE_Range gamma_range = { -2, 2, 0 }; */
struct qf_param
{
SANE_Word tl_x;
SANE_Word tl_y;
SANE_Word br_x;
SANE_Word br_y;
};
/* gcc don't like to overwrite const field */
static /*const */ struct qf_param qf_params[] = {
{0, 0, SANE_FIX (120.0), SANE_FIX (120.0)},
{0, 0, SANE_FIX (148.5), SANE_FIX (210.0)},
{0, 0, SANE_FIX (210.0), SANE_FIX (148.5)},
{0, 0, SANE_FIX (215.9), SANE_FIX (279.4)}, /* 8.5" x 11" */
{0, 0, SANE_FIX (210.0), SANE_FIX (297.0)},
{0, 0, 0, 0}
};
static const SANE_String_Const qf_list[] = {
SANE_I18N ("CD"),
SANE_I18N ("A5 portrait"),
SANE_I18N ("A5 landscape"),
SANE_I18N ("Letter"),
SANE_I18N ("A4"),
SANE_I18N ("Max"),
NULL
};
static SANE_Word *bitDepthList = NULL;
/*
* List of pointers to devices - will be dynamically allocated depending
* on the number of devices found.
*/
static const SANE_Device **devlist = 0;
/*
* Some utility functions
*/
static size_t
max_string_size (const SANE_String_Const strings[])
{
size_t size, max_size = 0;
int i;
for (i = 0; strings[i]; i++)
{
size = strlen (strings[i]) + 1;
if (size > max_size)
max_size = size;
}
return max_size;
}
typedef struct
{
u_char code;
u_char status;
u_char count1;
u_char count2;
u_char buf[1];
} EpsonHdrRec, *EpsonHdr;
typedef struct
{
u_char code;
u_char status;
u_char count1;
u_char count2;
u_char type;
u_char level;
u_char buf[1];
} EpsonIdentRec, *EpsonIdent;
typedef union
{
EpsonHdrRec hdr;
EpsonIdentRec ident;
} EpsonHdrUnionRec, *EpsonHdrUnion;
typedef struct
{
u_char code;
u_char status;
u_short count;
u_char buf[1];
} EpsonParameterRec, *EpsonParameter;
typedef struct
{
u_char code;
u_char status;
u_char buf[4];
} EpsonDataRec, *EpsonData;
/*
*
*
*/
static EpsonHdrUnion command (Epson_Scanner * s, u_char * cmd, size_t cmd_size,
SANE_Status * status);
static SANE_Status get_identity_information (SANE_Handle handle);
static SANE_Status get_identity2_information (SANE_Handle handle);
static int scanner_send (Epson_Scanner * s, void *buf, size_t buf_size,
SANE_Status * status);
static ssize_t scanner_receive (Epson_Scanner * s, void *buf, ssize_t buf_size,
SANE_Status * status);
static SANE_Status color_shuffle (SANE_Handle handle, int *new_length);
static SANE_Status request_focus_position (SANE_Handle handle,
u_char * position);
static SANE_Bool request_push_button_status (SANE_Handle handle,
SANE_Bool * theButtonStatus);
static void activateOption (Epson_Scanner * s, SANE_Int option,
SANE_Bool * change);
static void deactivateOption (Epson_Scanner * s, SANE_Int option,
SANE_Bool * change);
static void setOptionState (Epson_Scanner * s, SANE_Bool state,
SANE_Int option, SANE_Bool * change);
static void close_scanner (Epson_Scanner * s);
static SANE_Status open_scanner (Epson_Scanner * s);
SANE_Status sane_auto_eject (Epson_Scanner * s);
static SANE_Status attach_one_usb (SANE_String_Const devname);
static void filter_resolution_list (Epson_Scanner * s);
static void get_size (char c1, char c2, double *w, double *h);
static void scan_finish (Epson_Scanner * s);
/*
*
*
*/
static int
scanner_send (Epson_Scanner * s, void *buf, size_t buf_size, SANE_Status * status)
{
DBG (3, "send buf, size = %lu\n", (u_long) buf_size);
#if 1
{
unsigned int k;
const u_char *s = buf;
for (k = 0; k < buf_size; k++)
{
DBG (125, "buf[%d] %02x %c\n", k, s[k], isprint (s[k]) ? s[k] : '.');
}
}
#endif
if (s->hw->connection == SANE_EPSON_SCSI)
{
return sanei_epson_scsi_write (s->fd, buf, buf_size, status);
}
else if (s->hw->connection == SANE_EPSON_PIO)
{
size_t n;
if (buf_size == (n = sanei_pio_write (s->fd, buf, buf_size)))
*status = SANE_STATUS_GOOD;
else
*status = SANE_STATUS_INVAL;
return n;
}
else if (s->hw->connection == SANE_EPSON_USB)
{
size_t n;
n = buf_size;
*status = sanei_usb_write_bulk (s->fd, buf, &n);
w_cmd_count++;
DBG (5, "w_cmd_count = %d\n",w_cmd_count);
DBG (5, "r_cmd_count = %d\n",r_cmd_count);
return n;
}
return SANE_STATUS_INVAL;
/* never reached */
}
/*
*
*
*/
static ssize_t
scanner_receive (Epson_Scanner * s, void *buf, ssize_t buf_size, SANE_Status * status)
{
ssize_t n = 0;
if (s->hw->connection == SANE_EPSON_SCSI)
{
n = sanei_epson_scsi_read (s->fd, buf, buf_size, status);
}
else if (s->hw->connection == SANE_EPSON_PIO)
{
if (buf_size == (n = sanei_pio_read (s->fd, buf, (size_t) buf_size)))
*status = SANE_STATUS_GOOD;
else
*status = SANE_STATUS_INVAL;
}
else if (s->hw->connection == SANE_EPSON_USB)
{
/* !!! only report an error if we don't read anything */
n = buf_size; /* buf_size gets overwritten */
*status = sanei_usb_read_bulk (s->fd, (SANE_Byte *) buf, (size_t *) & n);
r_cmd_count += (n+63)/64; /* add # of packets, rounding up */
DBG (5, "w_cmd_count = %d\n",w_cmd_count);
DBG (5, "r_cmd_count = %d\n",r_cmd_count);
if (n > 0)
*status = SANE_STATUS_GOOD;
}
DBG (7, "receive buf, expected = %lu, got = %ld\n", (u_long) buf_size, (long) n);
#if 1
if (n > 0)
{
int k;
const u_char *s = buf;
for (k = 0; k < n; k++)
{
DBG (127, "buf[%d] %02x %c\n", k, s[k], isprint (s[k]) ? s[k] : '.');
}
}
#else
{
int i;
ssize_t k;
ssize_t hex_start = 0;
const u_char *s = buf;
char hex_str[NUM_OF_HEX_ELEMENTS * 3 + 1];
char tmp_str[NUM_OF_HEX_ELEMENTS * 3 + 1];
char ascii_str[NUM_OF_HEX_ELEMENTS * 2 + 1];
hex_str[0] = '\0';
ascii_str[0] = '\0';
for (k = 0; k < buf_size; k++)
{
/* write out the data in lines of 16 bytes */
/* add the next hex value to the hex string */
sprintf (tmp_str, "%s %02x", hex_str, s[k]);
strcpy (hex_str, tmp_str);
/* add the character to the ascii string */
sprintf (tmp_str, "%s %c", ascii_str, isprint (s[k]) ? s[k] : '.');
strcpy (ascii_str, tmp_str);
if ((k % (NUM_OF_HEX_ELEMENTS)) == 0)
{
if (k != 0) /* don't do this the first time */
{
for (i = strlen (hex_str); i < (NUM_OF_HEX_ELEMENTS * 3); i++)
{
hex_str[i] = ' ';
}
hex_str[NUM_OF_HEX_ELEMENTS + 1] = '\0';
DBG (125, "recv buf[%05d]: %s %s\n", hex_start, hex_str,
ascii_str);
hex_start = k;
hex_str[0] = '\0';
ascii_str[0] = '\0';
}
}
}
for (i = strlen (hex_str); i < NUM_OF_HEX_ELEMENTS * 3; i++)
{
hex_str[i] = ' ';
}
hex_str[NUM_OF_HEX_ELEMENTS + 1] = '\0';
DBG (125, "recv buf[%05d]: %s %s\n", hex_start, hex_str, ascii_str);
}
#endif
return n;
}
/*
*
*
*/
static SANE_Status
expect_ack (Epson_Scanner * s)
{
u_char result[1];
size_t len;
SANE_Status status;
len = sizeof (result);
scanner_receive (s, result, len, &status);
if (SANE_STATUS_GOOD != status)
return status;
if (ACK != result[0])
return SANE_STATUS_INVAL;
return SANE_STATUS_GOOD;
}
/*
*
*
*/
static SANE_Status
set_cmd (Epson_Scanner * s, u_char cmd, int val)
{
SANE_Status status;
u_char params[2];
if (!cmd)
return SANE_STATUS_UNSUPPORTED;
params[0] = ESC;
params[1] = cmd;
scanner_send (s, params, 2, &status);
if (SANE_STATUS_GOOD != (status = expect_ack (s)))
return status;
params[0] = val;
scanner_send (s, params, 1, &status);
status = expect_ack (s);
return status;
}
/* A little helper function to correct the extended status reply
gotten from scanners with known buggy firmware.
*/
static void
fix_up_extended_status_reply (const char *model, u_char * buf)
{
if (0 == strncmp (model, "ES-9000H", strlen ("ES-9000H"))
|| 0 == strncmp (model, "GT-30000", strlen ("GT-30000")))
{
DBG (1, "Fixing up buggy ADF max scan dimensions.\n");
buf[2] = 0xB0;
buf[3] = 0x6D;
buf[4] = 0x60;
buf[5] = 0x9F;
}
}
static void
print_params (const SANE_Parameters params)
{
DBG (5, "params.format = %d\n", params.format);
DBG (5, "params.last_frame = %d\n", params.last_frame);
DBG (5, "params.bytes_per_line = %d\n", params.bytes_per_line);
DBG (5, "params.pixels_per_line = %d\n", params.pixels_per_line);
DBG (5, "params.lines = %d\n", params.lines);
DBG (5, "params.depth = %d\n", params.depth);
}
/*
*
*
*/
#define set_focus_position(s,v) set_cmd( s,(s)->hw->cmd->set_focus_position,v)
#define set_color_mode(s,v) set_cmd( s,(s)->hw->cmd->set_color_mode,v)
#define set_data_format(s,v) set_cmd( s,(s)->hw->cmd->set_data_format, v)
#define set_halftoning(s,v) set_cmd( s,(s)->hw->cmd->set_halftoning, v)
#define set_gamma(s,v) set_cmd( s,(s)->hw->cmd->set_gamma, v)
#define set_color_correction(s,v) set_cmd( s,(s)->hw->cmd->set_color_correction, v)
#define set_lcount(s,v) set_cmd( s,(s)->hw->cmd->set_lcount, v)
#define set_bright(s,v) set_cmd( s,(s)->hw->cmd->set_bright, v)
#define mirror_image(s,v) set_cmd( s,(s)->hw->cmd->mirror_image, v)
#define set_speed(s,v) set_cmd( s,(s)->hw->cmd->set_speed, v)
#define set_outline_emphasis(s,v) set_cmd( s,(s)->hw->cmd->set_outline_emphasis, v)
#define control_auto_area_segmentation(s,v) set_cmd( s,(s)->hw->cmd->control_auto_area_segmentation, v)
#define set_film_type(s,v) set_cmd( s,(s)->hw->cmd->set_film_type, v)
#define set_exposure_time(s,v) set_cmd( s,(s)->hw->cmd->set_exposure_time, v)
#define set_bay(s,v) set_cmd( s,(s)->hw->cmd->set_bay, v)
#define set_threshold(s,v) set_cmd( s,(s)->hw->cmd->set_threshold, v)
#define control_extension(s,v) set_cmd( s,(s)->hw->cmd->control_an_extension, v)
/*#define (s,v) set_cmd( s,(s)->hw->cmd->, v) */
static SANE_Status
set_zoom (Epson_Scanner * s, int x_zoom, int y_zoom)
{
SANE_Status status;
u_char cmd[2];
u_char params[2];
if (!s->hw->cmd->set_zoom)
return SANE_STATUS_GOOD;
cmd[0] = ESC;
cmd[1] = s->hw->cmd->set_zoom;
scanner_send (s, cmd, 2, &status);
status = expect_ack (s);
if (status != SANE_STATUS_GOOD)
return status;
params[0] = x_zoom;
params[1] = y_zoom;
scanner_send (s, params, 2, &status);
status = expect_ack (s);
return status;
}
static SANE_Status
set_resolution (Epson_Scanner * s, int xres, int yres)
{
SANE_Status status;
u_char params[4];
if (!s->hw->cmd->set_resolution)
return SANE_STATUS_GOOD;
params[0] = ESC;
params[1] = s->hw->cmd->set_resolution;
scanner_send (s, params, 2, &status);
status = expect_ack (s);
if (status != SANE_STATUS_GOOD)
return status;
params[0] = xres;
params[1] = xres >> 8;
params[2] = yres;
params[3] = yres >> 8;
scanner_send (s, params, 4, &status);
status = expect_ack (s);
return status;
}
/*
* set_scan_area()
*
* Sends the "set scan area" command to the scanner with the currently selected
* scan area. This scan area is already corrected for "color shuffling" if
* necessary.
*/
static SANE_Status
set_scan_area (Epson_Scanner * s, int x, int y, int width, int height)
{
SANE_Status status;
u_char params[8];
DBG (1, "set_scan_area: %p %d %d %d %d\n", (void *) s, x, y, width, height);
if (!s->hw->cmd->set_scan_area)
{
DBG (1, "set_scan_area not supported\n");
return SANE_STATUS_GOOD;
}
/* verify the scan area */
if (x < 0 || y < 0 || width <= 0 || height <= 0)
return SANE_STATUS_INVAL;
params[0] = ESC;
params[1] = s->hw->cmd->set_scan_area;
scanner_send (s, params, 2, &status);
status = expect_ack (s);
if (status != SANE_STATUS_GOOD)
return status;
params[0] = x;
params[1] = x >> 8;
params[2] = y;
params[3] = y >> 8;
params[4] = width;
params[5] = width >> 8;
params[6] = height;
params[7] = height >> 8;
scanner_send (s, params, 8, &status);
status = expect_ack (s);
return status;
}
/*
* set_color_correction_coefficients()
*
* Sends the "set color correction coefficients" command with the currently selected
* parameters to the scanner.
*/
static SANE_Status
set_color_correction_coefficients (Epson_Scanner * s)
{
SANE_Status status;
u_char cmd = s->hw->cmd->set_color_correction_coefficients;
u_char params[2];
const int length = 9;
signed char cct[9];
DBG (1, "set_color_correction_coefficients: starting.\n");
if (!cmd)
return SANE_STATUS_UNSUPPORTED;
params[0] = ESC;
params[1] = cmd;
scanner_send (s, params, 2, &status);
if (SANE_STATUS_GOOD != (status = expect_ack (s)))
return status;
cct[0] = s->val[OPT_CCT_1].w;
cct[1] = s->val[OPT_CCT_2].w;
cct[2] = s->val[OPT_CCT_3].w;
cct[3] = s->val[OPT_CCT_4].w;
cct[4] = s->val[OPT_CCT_5].w;
cct[5] = s->val[OPT_CCT_6].w;
cct[6] = s->val[OPT_CCT_7].w;
cct[7] = s->val[OPT_CCT_8].w;
cct[8] = s->val[OPT_CCT_9].w;
DBG (1, "set_color_correction_coefficients: %d,%d,%d %d,%d,%d %d,%d,%d.\n",
cct[0], cct[1], cct[2], cct[3],
cct[4], cct[5], cct[6], cct[7], cct[8]);
scanner_send (s, cct, length, &status);
status = expect_ack (s);
DBG (1, "set_color_correction_coefficients: ending=%d.\n", status);
return status;
}
/*
*
*
*/
static SANE_Status
set_gamma_table (Epson_Scanner * s)
{
SANE_Status status;
u_char cmd = s->hw->cmd->set_gamma_table;
u_char params[2];
const int length = 257;
u_char gamma[257];
int n;
int table;
/* static const char gamma_cmds[] = { 'M', 'R', 'G', 'B' }; */
static const char gamma_cmds[] = { 'R', 'G', 'B' };
DBG (1, "set_gamma_table: starting.\n");
if (!cmd)
return SANE_STATUS_UNSUPPORTED;
params[0] = ESC;
params[1] = cmd;
/*
* Print the gamma tables before sending them to the scanner.
*/
if (DBG_LEVEL > 0)
{
int c, i, j;
DBG (1, "set_gamma_table()\n");
for (c = 0; c < 3; c++)
{
for (i = 0; i < 256; i += 16)
{
char gammaValues[16 * 3 + 1], newValue[4];
gammaValues[0] = '\0';
for (j = 0; j < 16; j++)
{
sprintf (newValue, " %02x", s->gamma_table[c][i + j]);
strcat (gammaValues, newValue);
}
DBG (10, "Gamma Table[%d][%d] %s\n", c, i, gammaValues);
}
}
}
/*
* TODO: &status in send makes no sense like that.
*/
/*
* When handling inverted images, we must also invert the user
* supplied gamma function. This is *not* just 255-gamma -
* this gives a negative image.
*/
for (table = 0; table < 3; table++)
{
gamma[0] = gamma_cmds[table];
if (s->invert_image)
{
for (n = 0; n < 256; ++n)
{
gamma[n + 1] = 255 - s->gamma_table[table][255 - n];
}
}
else
{
for (n = 0; n < 256; ++n)
{
gamma[n + 1] = s->gamma_table[table][n];
}
}
scanner_send (s, params, 2, &status);
if (SANE_STATUS_GOOD != (status = expect_ack (s)))
return status;
scanner_send (s, gamma, length, &status);
if (SANE_STATUS_GOOD != (status = expect_ack (s)))
return status;
}
DBG (1, "set_gamma_table: complete = %d.\n", status);
return status;
}
void
get_size (char c1, char c2, double *w, double *h)
{
int ind;
unsigned char flag;
double wsizetbl[] = {
11.60, /* A3V */
11.00, /* WLT */
10.12, /* B4V */
8.50, /* LGV */
8.27, /* A4V */
11.69, /* A4H */
8.50, /* LTV */
11.00, /* LTH */
7.17, /* B5V */
10.12, /* B5H */
5.83, /* A5V */
8.27, /* A5H */
7.25, /* EXV */
10.50, /* EXH */
11.69, /* unknown */
11.69, /* unknown */
11.69, /* unknown */
};
double hsizetbl[] = {
16.54, /* A3V */
17.00, /* WLT */
14.33, /* B4V */
14.00, /* LGV */
11.69, /* A4V */
8.27, /* A4H */
11.00, /* LTV */
8.50, /* LTH */
10.12, /* B5V */
7.17, /* B5H */
8.27, /* A5V */
5.83, /* A5H */
10.50, /* EXV */
7.25, /* EXH */
17.00, /* unknown */
17.00, /* unknown */
17.00, /* unknown */
};
flag = c1;
for (ind = 0; ind < 8; ind++)
{
if (flag & 0x80)
goto DetectSize;
flag = flag << 1;
}
flag = c2;
for (; ind < 16; ind++)
{
if (flag & 0x80)
goto DetectSize;
flag = flag << 1;
}
DetectSize:
*w = wsizetbl[ind];
*h = hsizetbl[ind];
DBG (10, "detected width: %f\n", *w);
DBG (10, "detected height: %f\n", *h);
}
/*
* check_ext_status()
*
* Requests the extended status flag from the scanner. The "warming up" condition
* is reported as a warning (only visible if debug level is set to 10 or greater) -
* every other condition is reported as an error.
*
* This function only gets called when we are dealing with a scanner that supports the
* "warming up" code, so it's not a problem for B3 level scanners, that don't handle
* request extended status commands.
*/
static SANE_Status
check_ext_status (Epson_Scanner * s, int *max_x, int *max_y)
{
SANE_Status status;
u_char cmd = s->hw->cmd->request_extended_status;
u_char params[2];
u_char *buf;
EpsonHdr head;
*max_x = 0;
*max_y = 0;
if (cmd == 0)
return SANE_STATUS_UNSUPPORTED;
params[0] = ESC;
params[1] = cmd;
head = (EpsonHdr) command (s, params, 2, &status);
if (NULL == head)
{
DBG (1, "Extended status flag request failed\n");
return status;
}
buf = &head->buf[0];
if (buf[0] & EXT_STATUS_WU)
{
DBG (10, "option: warming up\n");
status = SANE_STATUS_DEVICE_BUSY;
}
if (buf[0] & EXT_STATUS_FER)
{
DBG (1, "option: fatal error\n");
status = SANE_STATUS_INVAL;
}
if (s->hw->ADF && s->hw->use_extension && s->hw->cmd->feed)
{
fix_up_extended_status_reply (s->hw->sane.model, buf);
*max_x = buf[3] << 8 | buf[2];
*max_y = buf[5] << 8 | buf[4];
if (0 == strcmp ("ES-9000H", s->hw->sane.model)
|| 0 == strcmp ("GT-30000", s->hw->sane.model))
{
/* set size of current sheet, but don't clobber zoom
settings (which should always be smaller than the
detected sheet size) */
double w, h;
get_size (buf[16], buf[17], &w, &h);
w = SANE_FIX (w * MM_PER_INCH);
h = SANE_FIX (h * MM_PER_INCH);
if (w < s->val[OPT_BR_X].w)
s->val[OPT_BR_X].w = w;
if (h < s->val[OPT_BR_Y].w)
s->val[OPT_BR_Y].w = h;
}
}
if (buf[1] & EXT_STATUS_ERR)
{
DBG (1, "ADF: other error\n");
status = SANE_STATUS_INVAL;
}
if (buf[1] & EXT_STATUS_PE)
{
DBG (1, "ADF: no paper\n");
status = SANE_STATUS_NO_DOCS;
return status;
}
if (buf[1] & EXT_STATUS_PJ)
{
DBG (1, "ADF: paper jam\n");
status = SANE_STATUS_JAMMED;
}
if (buf[1] & EXT_STATUS_OPN)
{
DBG (1, "ADF: cover open\n");
status = SANE_STATUS_COVER_OPEN;
}
if (buf[6] & EXT_STATUS_ERR)
{
DBG (1, "TPU: other error\n");
status = SANE_STATUS_INVAL;
}
/* return the max. scan area for the ADF */
if (buf[6] & EXT_STATUS_IST)
{
*max_x = buf[8] << 8 | buf[7];
*max_y = buf[10] << 8 | buf[9];
}
/* return the max. scan area for the flatbed */
if (s->hw->devtype == 3 && s->hw->use_extension == 0)
{
double w, h;
get_size (buf[18], buf[19], &w, &h);
*max_x = (int) (w * s->hw->dpi_range.max);
*max_y = (int) (h * s->hw->dpi_range.max);
}
free (head);
return status;
}
/*
* reset()
*
* Send the "initialize scanner" command to the device and reset it.
*
*/
static SANE_Status
reset (Epson_Scanner * s)
{
SANE_Status status;
u_char param[2];
SANE_Bool needToClose = SANE_FALSE;
DBG (5, "reset()\n");
if (!s->hw->cmd->initialize_scanner)
return SANE_STATUS_GOOD;
param[0] = ESC;
param[1] = s->hw->cmd->initialize_scanner;
if (s->fd == -1)
{
needToClose = SANE_TRUE;
DBG (5, "reset calling open_scanner\n");
if ((status = open_scanner (s)) != SANE_STATUS_GOOD)
return status;
}
scanner_send (s, param, 2, &status);
status = expect_ack (s);
if (needToClose)
{
close_scanner (s);
}
return status;
}
/*
* close_scanner()
*
* Close the open scanner. Depending on the connection method, a different
* close function is called.
*/
static void
close_scanner (Epson_Scanner * s)
{
DBG (5, "close_scanner(fd = %d)\n", s->fd);
if (s->fd == -1)
return;
if (r_cmd_count % 2)
{
/* send a request_status. This toggles w_cmd_count and r_cmd_count */
u_char param[3];
u_char result[5];
SANE_Status status;
param[0] = ESC;
param[1] = s->hw->cmd->request_status;
param[2]='\0';
scanner_send(s,param,2,&status);
scanner_receive(s,result,4,&status);
}
DBG (5, "w_cmd_count = %d\n",w_cmd_count);
DBG (5, "r_cmd_count = %d\n",r_cmd_count);
if (w_cmd_count % 2)
{
int junk1,junk2;
/* check extended status. This toggles w_cmd_count%2 only */
check_ext_status (s,&junk1,&junk2);
}
DBG (5, "w_cmd_count = %d\n",w_cmd_count);
DBG (5, "r_cmd_count = %d\n",r_cmd_count);
if (s->hw->connection == SANE_EPSON_SCSI)
{
sanei_scsi_close (s->fd);
}
else if (s->hw->connection == SANE_EPSON_PIO)
{
sanei_pio_close (s->fd);
}
else if (s->hw->connection == SANE_EPSON_USB)
{
sanei_usb_close (s->fd);
}
s->fd = -1;
return;
}
/*
* open_scanner()
*
* Open the scanner device. Depending on the connection method,
* different open functions are called.
*/
static SANE_Status
open_scanner (Epson_Scanner * s)
{
SANE_Status status = 0;
DBG (5, "open_scanner()\n");
if (s->fd != -1)
{
DBG (5, "scanner is already open: fd = %d\n", s->fd);
return SANE_STATUS_GOOD; /* no need to open the scanner */
}
/* don't do this for OS2: */
#ifndef HAVE_OS2_H
#if 0
/* test the device name */
if ((s->hw->connection != SANE_EPSON_PIO)
&& (access (s->hw->sane.name, R_OK | W_OK) != 0))
{
DBG (1, "sane_start: access(%s, R_OK | W_OK) failed\n", s->hw->sane.name);
return SANE_STATUS_ACCESS_DENIED;
}
#endif
#endif
if (s->hw->connection == SANE_EPSON_SCSI)
{
status = sanei_scsi_open (s->hw->sane.name, &s->fd,
sanei_epson_scsi_sense_handler, NULL);
if (SANE_STATUS_GOOD != status)
{
DBG (1, "sane_start: %s open failed: %s\n", s->hw->sane.name,
sane_strstatus (status));
return status;
}
}
else if (s->hw->connection == SANE_EPSON_PIO)
{
status = sanei_pio_open (s->hw->sane.name, &s->fd);
if (SANE_STATUS_GOOD != status)
{
DBG (1, "sane_start: %s open failed: %s\n", s->hw->sane.name,
sane_strstatus (status));
return status;
}
}
else if (s->hw->connection == SANE_EPSON_USB)
{
status = sanei_usb_open (s->hw->sane.name, &s->fd);
return status;
}
return SANE_STATUS_GOOD;
}
/*
* feed ( )
*/
static SANE_Status
feed (Epson_Scanner * s)
{
SANE_Status status;
u_char params[2];
u_char cmd = s->hw->cmd->feed;
DBG (5, "feed()\n");
if (!cmd)
{
DBG (5, "feed() is not supported\n");
return SANE_STATUS_UNSUPPORTED;
}
params[0] = cmd;
scanner_send (s, params, 1, &status);
if (SANE_STATUS_GOOD != (status = expect_ack (s)))
{
close_scanner (s);
return status;
}
return status;
}
/*
* eject()
*
* Eject the current page from the ADF. The scanner is opened prior to
* sending the command and closed afterwards.
*
*/
static SANE_Status
eject (Epson_Scanner * s)
{
SANE_Status status;
u_char params[2];
u_char cmd = s->hw->cmd->eject;
SANE_Bool needToClose = SANE_FALSE;
DBG (5, "eject()\n");
if (!cmd)
return SANE_STATUS_UNSUPPORTED;
if (s->fd == -1)
{
needToClose = SANE_TRUE;
if (SANE_STATUS_GOOD != (status = open_scanner (s)))
return status;
}
params[0] = cmd;
scanner_send (s, params, 1, &status);
if (SANE_STATUS_GOOD != (status = expect_ack (s)))
{
close_scanner (s);
return status;
}
if (needToClose)
close_scanner (s);
return status;
}
/*
*
*
*/
static int num_devices = 0; /* number of EPSON scanners attached to backend */
static Epson_Device *first_dev = NULL; /* first EPSON scanner in list */
static Epson_Scanner *first_handle = NULL;
static EpsonHdrUnion
command (Epson_Scanner * s, u_char * cmd, size_t cmd_size,
SANE_Status * status)
{
EpsonHdrUnion hdrunion, hdrunion_bak;
EpsonHdr head;
u_char *buf;
int count;
if (NULL == (hdrunion = walloc (EpsonHdrUnionRec)))
{
DBG (1, "out of memory (line %d)\n", __LINE__);
*status = SANE_STATUS_NO_MEM;
return (EpsonHdrUnion) 0;
}
head = &(hdrunion->hdr);
scanner_send (s, cmd, cmd_size, status);
if (SANE_STATUS_GOOD != *status)
{
/* this is necessary for the GT-8000. I don't know why, but
it seems to fix the problem. It should not have any
ill effects on other scanners. */
*status = SANE_STATUS_GOOD;
scanner_send (s, cmd, cmd_size, status);
if (SANE_STATUS_GOOD != *status)
return (EpsonHdrUnion) 0;
}
buf = (u_char *) head;
if (s->hw->connection == SANE_EPSON_SCSI)
{
scanner_receive (s, buf, 4, status);
buf += 4;
}
else if (s->hw->connection == SANE_EPSON_USB)
{
int bytes_read;
bytes_read = scanner_receive (s, buf, 4, status);
buf += bytes_read;
}
else
{
scanner_receive (s, buf, 1, status);
buf += 1;
}
if (SANE_STATUS_GOOD != *status)
return (EpsonHdrUnion) 0;
DBG (4, "code %02x\n", (int) head->code);
switch (head->code)
{
case NAK:
/* fall through */
/* !!! is this really sufficient to report an error ? */
case ACK:
break; /* no need to read any more data after ACK or NAK */
case STX:
if (s->hw->connection == SANE_EPSON_SCSI)
{
/* nope */
}
else if (s->hw->connection == SANE_EPSON_USB)
{
/* we've already read the complete data */
}
else
{
scanner_receive (s, buf, 3, status);
/* buf += 3; */
}
if (SANE_STATUS_GOOD != *status)
return (EpsonHdrUnion) 0;
DBG (4, "status %02x\n", (int) head->status);
count = head->count2 * 255 + head->count1;
DBG (4, "count %d\n", count);
hdrunion_bak = hdrunion;
if (NULL == (hdrunion = realloc (hdrunion,
sizeof (EpsonHdrUnionRec) + count)))
{
free(hdrunion_bak);
DBG (1, "out of memory (line %d)\n", __LINE__);
*status = SANE_STATUS_NO_MEM;
return (EpsonHdrUnion) 0;
}
head = &(hdrunion->hdr);
buf = head->buf;
scanner_receive (s, buf, count, status);
if (SANE_STATUS_GOOD != *status)
return (EpsonHdrUnion) 0;
break;
default:
if (0 == head->code)
DBG (1, "Incompatible printer port (probably bi/directional)\n");
else if (cmd[cmd_size - 1] == head->code)
DBG (1, "Incompatible printer port (probably not bi/directional)\n");
DBG (2, "Illegal response of scanner for command: %02x\n", head->code);
break;
}
return hdrunion;
}
/*
* static SANE_Status attach()
*
* Attach one device with name *dev_name to the backend.
*/
static SANE_Status
attach (const char *dev_name, Epson_Device * *devp, int type)
{
SANE_Status status;
Epson_Scanner *s = walloca (Epson_Scanner);
char *str;
struct Epson_Device *dev;
SANE_String_Const *source_list_add = source_list;
int port;
DBG (1, "%s\n", SANE_EPSON_VERSION);
DBG (5, "attach(%s, %d)\n", dev_name, type);
for (dev = first_dev; dev; dev = dev->next)
{
if (strcmp (dev->sane.name, dev_name) == 0)
{
if (devp)
{
*devp = dev;
}
return SANE_STATUS_GOOD;
}
}
dev = malloc (sizeof (*dev));
if (!dev)
{
DBG (1, "out of memory (line %d)\n", __LINE__);
return SANE_STATUS_NO_MEM;
}
/* check for PIO devices */
/* can we convert the device name to an integer? This is only possible
with PIO devices */
port = atoi (dev_name);
if (port != 0)
{
type = SANE_EPSON_PIO;
}
if (strncmp
(dev_name, SANE_EPSON_CONFIG_PIO, strlen (SANE_EPSON_CONFIG_PIO)) == 0)
{
/* we have a match for the PIO string and adjust the device name */
dev_name += strlen (SANE_EPSON_CONFIG_PIO);
dev_name = sanei_config_skip_whitespace (dev_name);
type = SANE_EPSON_PIO;
}
/*
* set dummy values.
*/
s->hw = dev;
s->hw->sane.name = NULL;
s->hw->sane.type = "flatbed scanner";
s->hw->sane.vendor = "Epson";
s->hw->sane.model = NULL;
s->hw->optical_res = 0; /* just to have it initialized */
s->hw->color_shuffle = SANE_FALSE;
s->hw->extension = SANE_FALSE;
s->hw->use_extension = SANE_FALSE;
s->hw->need_color_reorder = SANE_FALSE;
s->hw->need_double_vertical = SANE_FALSE;
s->hw->cmd = &epson_cmd[EPSON_LEVEL_DEFAULT]; /* default function level */
s->hw->connection = type;
DBG (3, "attach: opening %s\n", dev_name);
s->hw->last_res = 0;
s->hw->last_res_preview = 0; /* set resolution to safe values */
/*
* decide if interface is USB, SCSI or parallel.
*/
/*
* if interface is SCSI do an inquiry.
*/
if (s->hw->connection == SANE_EPSON_SCSI)
{
u_char buf[INQUIRY_BUF_SIZE + 1];
size_t buf_size = INQUIRY_BUF_SIZE;
status =
sanei_scsi_open (dev_name, &s->fd, sanei_epson_scsi_sense_handler,
NULL);
if (SANE_STATUS_GOOD != status)
{
DBG (1, "attach: open failed: %s\n", sane_strstatus (status));
return status;
}
DBG (3, "attach: sending INQUIRY\n");
status = sanei_epson_scsi_inquiry (s->fd, 0, buf, &buf_size);
if (SANE_STATUS_GOOD != status)
{
DBG (1, "attach: inquiry failed: %s\n", sane_strstatus (status));
close_scanner (s);
return status;
}
buf[INQUIRY_BUF_SIZE] = 0;
DBG (1, ">%s<\n", buf + 8);
/*
* For USB and PIO scanners this will be done later, once
* we have communication established with the device.
*/
if (buf[0] != TYPE_PROCESSOR
|| strncmp ((char *) (buf + 8), "EPSON", 5) != 0
|| (strncmp ((char *) buf + 16, "SCANNER ", 8) != 0
&& strncmp ((char *) buf + 14, "SCANNER ", 8) != 0
&& strncmp ((char *) buf + 14, "Perfection", 10) != 0
&& strncmp ((char *) buf + 16, "Perfection", 10) != 0
&& strncmp ((char *) buf + 16, "Expression", 10) != 0
&& strncmp ((char *) buf + 16, "GT", 2) != 0))
{
DBG (1, "attach: device doesn't look like an EPSON scanner\n");
close_scanner (s);
return SANE_STATUS_INVAL;
}
}
/* use the SANEI functions to handle a PIO device */
else if (s->hw->connection == SANE_EPSON_PIO)
{
if (SANE_STATUS_GOOD != (status = sanei_pio_open (dev_name, &s->fd)))
{
DBG (1, "Cannot open %s as a parallel-port device: %s\n",
dev_name, sane_strstatus (status));
return status;
}
}
/* use the SANEI functions to handle a USB device */
else if (s->hw->connection == SANE_EPSON_USB)
{
SANE_Word vendor;
SANE_Word product;
SANE_Bool isLibUSB;
isLibUSB = (strncmp (dev_name, "libusb:", strlen ("libusb:")) == 0);
if ((!isLibUSB) && (strlen (dev_name) == 0))
{
int i;
int numIds;
numIds = sanei_epson_getNumberOfUSBProductIds ();
for (i = 0; i < numIds; i++)
{
product = sanei_epson_usb_product_ids[i];
vendor = 0x4b8;
status = sanei_usb_find_devices (vendor, product, attach_one_usb);
}
return SANE_STATUS_INVAL; /* return - the attach_one_usb()
will take care of this */
}
status = sanei_usb_open (dev_name, &s->fd);
if (SANE_STATUS_GOOD != status)
{
return status;
}
/* if the sanei_usb_get_vendor_product call is not supported,
then we just ignore this and rely on the user to config
the correct device.
*/
if (sanei_usb_get_vendor_product (s->fd, &vendor, &product) ==
SANE_STATUS_GOOD)
{
int i; /* loop variable */
int numIds;
SANE_Bool is_valid;
/* check the vendor ID to see if we are dealing with an EPSON device */
if (vendor != SANE_EPSON_VENDOR_ID)
{
/* this is not a supported vendor ID */
DBG (1,
"The device at %s is not manufactured by EPSON (vendor id=0x%x)\n",
dev_name, vendor);
sanei_usb_close (s->fd);
s->fd = -1;
return SANE_STATUS_INVAL;
}
numIds = sanei_epson_getNumberOfUSBProductIds ();
is_valid = SANE_FALSE;
i = 0;
/* check all known product IDs to verify that we know
about the device */
while (i != numIds && !is_valid)
{
if (product == sanei_epson_usb_product_ids[i])
is_valid = SANE_TRUE;
i++;
}
if (is_valid == SANE_FALSE)
{
DBG (1,
"The device at %s is not a supported EPSON scanner (product id=0x%x)\n",
dev_name, product);
sanei_usb_close (s->fd);
s->fd = -1;
return SANE_STATUS_INVAL;
}
DBG (1, "Found valid EPSON scanner: 0x%x/0x%x (vendorID/productID)\n",
vendor, product);
}
else
{
DBG (1,
"Cannot use IOCTL interface to verify that device is a scanner - will continue\n");
}
}
/*
* Initialize the scanner (ESC @).
*/
reset (s);
/*
* Identification Request (ESC I).
*/
if (s->hw->cmd->request_identity != 0)
{
status = get_identity_information (s);
if (status != SANE_STATUS_GOOD)
return status;
} /* request identity */
/*
* Check for "Request Identity 2" command. If this command is available
* get the information from the scanner and store it in dev
*/
if (s->hw->cmd->request_identity2 != 0)
{
status = get_identity2_information (s);
if (status != SANE_STATUS_GOOD)
return status;
} /* request identity 2 */
/*
* Check for the max. supported color depth and assign
* the values to the bitDepthList.
*/
bitDepthList = malloc (sizeof (SANE_Word) * 4);
if (bitDepthList == NULL)
{
DBG (1, "out of memory (line %d)\n", __LINE__);
return SANE_STATUS_NO_MEM;
}
bitDepthList[0] = 1; /* we start with one element in the list */
bitDepthList[1] = 8; /* 8bit is the default */
if (set_data_format (s, 16) == SANE_STATUS_GOOD)
{
s->hw->maxDepth = 16;
bitDepthList[0]++;
bitDepthList[bitDepthList[0]] = 16;
}
else if (set_data_format (s, 14) == SANE_STATUS_GOOD)
{
s->hw->maxDepth = 14;
bitDepthList[0]++;
bitDepthList[bitDepthList[0]] = 14;
}
else if (set_data_format (s, 12) == SANE_STATUS_GOOD)
{
s->hw->maxDepth = 12;
bitDepthList[0]++;
bitDepthList[bitDepthList[0]] = 12;
}
else
{
s->hw->maxDepth = 8;
/* the default depth is already in the list */
}
DBG (1, "Max. supported color depth = %d\n", s->hw->maxDepth);
/*
* Check for "request focus position" command. If this command is
* supported, then the scanner does also support the "set focus
* position" command.
*/
if (request_focus_position (s, &s->currentFocusPosition) ==
SANE_STATUS_GOOD)
{
DBG (1, "Enabling 'Set Focus' support\n");
s->hw->focusSupport = SANE_TRUE;
s->opt[OPT_FOCUS].cap &= ~SANE_CAP_INACTIVE;
/* reflect the current focus position in the GUI */
if (s->currentFocusPosition < 0x4C)
{
/* focus on glass */
s->val[OPT_FOCUS].w = 0;
}
else
{
/* focus 2.5mm above glass */
s->val[OPT_FOCUS].w = 1;
}
}
else
{
DBG (1, "Disabling 'Set Focus' support\n");
s->hw->focusSupport = SANE_FALSE;
s->opt[OPT_FOCUS].cap |= SANE_CAP_INACTIVE;
s->val[OPT_FOCUS].w = 0; /* on glass - just in case */
}
/*
* Set defaults for no extension.
*/
dev->x_range = &dev->fbf_x_range;
dev->y_range = &dev->fbf_y_range;
/*
* Correct for a firmware bug in some Perfection 1650 scanners:
* Firmware version 1.08 reports only half the vertical scan area, we have
* to double the number. To find out if we have to do this, we just compare
* is the vertical range is smaller than the horizontal range.
*/
if ((dev->x_range->max - dev->x_range->min) >
(dev->y_range->max - dev->y_range->min))
{
dev->y_range->max += (dev->y_range->max - dev->y_range->min);
dev->need_double_vertical = SANE_TRUE;
dev->need_color_reorder = SANE_TRUE;
}
/*
* Extended status flag request (ESC f).
* this also requests the scanner device name from the scanner
*/
/*
* because we are also using the device name from this command,
* we have to run this block even if the scanner does not report
* an extension. The extensions are only reported if the ADF or
* the TPU are actually detected.
*/
if (s->hw->cmd->request_extended_status != 0)
{
u_char *buf;
u_char params[2];
EpsonHdr head;
params[0] = ESC;
params[1] = s->hw->cmd->request_extended_status;
if (NULL == (head = (EpsonHdr) command (s, params, 2, &status)))
{
DBG (1, "Extended status flag request failed\n");
dev->sane.model = strdup ("Unknown model");
*source_list_add++ = FBF_STR;
}
else
{
buf = &head->buf[0];
/*
* Add the flatbed option to the source list
*/
*source_list_add++ = FBF_STR;
s->hw->devtype = buf[11] >> 6;
/*
* Get the device name and copy it to dev->sane.model.
* The device name starts at buf[0x1A] and is up to 16 bytes long
* We are overwriting whatever was set previously!
*/
{
char device_name[DEVICE_NAME_LEN + 1];
char *end_ptr;
int len;
/* make sure that the end of string is marked */
device_name[DEVICE_NAME_LEN] = '\0';
/* copy the string to an area where we can work with it */
memcpy (device_name, buf + 0x1A, DEVICE_NAME_LEN);
end_ptr = strchr (device_name, ' ');
if (end_ptr != NULL)
{
*end_ptr = '\0';
}
len = strlen (device_name);
str = malloc (len + 1);
str[len] = '\0';
dev->sane.model = (char *) memcpy (str, device_name, len);
}
/*
* ADF
*/
if (dev->extension && (buf[1] & EXT_STATUS_IST))
{
DBG (1, "ADF detected\n");
/* the GT-30000 does not report the ADF scan area */
if ((strcmp (dev->sane.model, "GT-30000") == 0) ||
(strcmp (dev->sane.model, "ES-9000H") == 0))
{
fix_up_extended_status_reply ((const char *) buf + 26, buf);
dev->duplexSupport = (buf[0] & 0x10) != 0;
if (dev->duplexSupport)
{
DBG (1, "Found DUPLEX ADF\n");
}
}
if (buf[1] & EXT_STATUS_EN)
{
DBG (1, "ADF is enabled\n");
dev->x_range = &dev->adf_x_range;
dev->y_range = &dev->adf_y_range;
}
dev->adf_x_range.min = 0;
dev->adf_x_range.max =
SANE_FIX ((buf[3] << 8 | buf[2]) * 25.4 / dev->dpi_range.max);
dev->adf_x_range.quant = 0;
dev->adf_max_x = buf[3] << 8 | buf[2];
dev->adf_y_range.min = 0;
dev->adf_y_range.max =
SANE_FIX ((buf[5] << 8 | buf[4]) * 25.4 / dev->dpi_range.max);
dev->adf_y_range.quant = 0;
dev->adf_max_y = buf[5] << 8 | buf[4];
DBG (5, "adf tlx %f tly %f brx %f bry %f [mm]\n",
SANE_UNFIX (dev->adf_x_range.min),
SANE_UNFIX (dev->adf_y_range.min),
SANE_UNFIX (dev->adf_x_range.max),
SANE_UNFIX (dev->adf_y_range.max));
*source_list_add++ = ADF_STR;
dev->ADF = SANE_TRUE;
}
/*
* TPU
*/
if (dev->extension && (buf[6] & EXT_STATUS_IST))
{
DBG (1, "TPU detected\n");
if (buf[6] & EXT_STATUS_EN)
{
DBG (1, "TPU is enabled\n");
dev->x_range = &dev->tpu_x_range;
dev->y_range = &dev->tpu_y_range;
}
dev->tpu_x_range.min = 0;
dev->tpu_x_range.max =
SANE_FIX ((buf[8] << 8 | buf[7]) * 25.4 / dev->dpi_range.max);
dev->tpu_x_range.quant = 0;
dev->tpu_y_range.min = 0;
dev->tpu_y_range.max =
SANE_FIX ((buf[10] << 8 | buf[9]) * 25.4 / dev->dpi_range.max);
dev->tpu_y_range.quant = 0;
/*
* Check for Perfection 4990 photo/GT-X800 scanner.
* This scanner only report 3200 dpi back.
* The scanner physically supports 4800 dpi.
* This is simulated here...
* Further details read:
* EPSON Programming guide for EPSON Color Image Scanner Perfection 4990
*/
if (strncmp((char *) buf + 0x1A,"GT-X800",7) == 0)
{
dev->tpu_x_range.max = (dev->tpu_x_range.max/32)*48;
dev->tpu_y_range.max = (dev->tpu_y_range.max/32)*48;
DBG (5, "dpi_range.max %x \n", dev->dpi_range.max);
}
DBG (5, "tpu tlx %f tly %f brx %f bry %f [mm]\n",
SANE_UNFIX (dev->tpu_x_range.min),
SANE_UNFIX (dev->tpu_y_range.min),
SANE_UNFIX (dev->tpu_x_range.max),
SANE_UNFIX (dev->tpu_y_range.max));
*source_list_add++ = TPU_STR;
dev->TPU = SANE_TRUE;
}
/*
* Get the device name and copy it to dev->sane.model.
* The device name starts at buf[0x1A] and is up to 16 bytes long
* We are overwriting whatever was set previously!
*/
{
char device_name[DEVICE_NAME_LEN + 1];
char *end_ptr;
int len;
/* make sure that the end of string is marked */
device_name[DEVICE_NAME_LEN] = '\0';
/* copy the string to an area where we can work with it */
memcpy (device_name, buf + 0x1A, DEVICE_NAME_LEN);
end_ptr = strchr (device_name, ' ');
if (end_ptr != NULL)
{
*end_ptr = '\0';
}
len = strlen (device_name);
str = malloc (len + 1);
str[len] = '\0';
/* finally copy the device name to the structure */
dev->sane.model = (char *) memcpy (str, device_name, len);
}
}
}
else /* command is not known */
{
dev->sane.model = strdup ("EPSON Scanner");
}
*source_list_add = NULL; /* add end marker to source list */
DBG (1, "scanner model: %s\n", dev->sane.model);
/* establish defaults */
s->hw->need_reset_on_source_change = SANE_FALSE;
if (strcmp ("ES-9000H", dev->sane.model) == 0 ||
strcmp ("GT-30000", dev->sane.model) == 0)
{
s->hw->cmd->set_focus_position = 0;
s->hw->cmd->feed = 0x19;
}
else if (strcmp ("GT-8200", dev->sane.model) == 0 ||
strcmp ("Perfection1650", dev->sane.model) == 0 ||
strcmp ("Perfection1640", dev->sane.model) == 0 ||
strcmp ("GT-8700", dev->sane.model) == 0)
{
s->hw->cmd->feed = 0;
s->hw->cmd->set_focus_position = 0;
s->hw->need_reset_on_source_change = SANE_TRUE;
}
/*
* Set values for quick format "max" entry.
*/
qf_params[XtNumber (qf_params) - 1].tl_x = dev->x_range->min;
qf_params[XtNumber (qf_params) - 1].tl_y = dev->y_range->min;
qf_params[XtNumber (qf_params) - 1].br_x = dev->x_range->max;
qf_params[XtNumber (qf_params) - 1].br_y = dev->y_range->max;
/*
* Now we can finally set the device name:
*/
str = malloc (strlen (dev_name) + 1);
dev->sane.name = strcpy (str, dev_name);
close_scanner (s);
/*
* we are done with this one, prepare for the next scanner:
*/
++num_devices;
dev->next = first_dev;
first_dev = dev;
if (devp)
{
*devp = dev;
}
return SANE_STATUS_GOOD;
}
/*
* attach_one()
*
* Part of the SANE API: Attaches the scanner with the device name in *dev.
*/
static SANE_Status
attach_one (const char *dev)
{
DBG (5, "attach_one(%s)\n", dev);
return attach (dev, 0, SANE_EPSON_SCSI);
}
SANE_Status
attach_one_usb (SANE_String_Const devname)
{
int len = strlen (devname);
char *attach_string;
DBG (5, "attach_one_usb(%s)\n", devname);
attach_string = alloca (len + 5);
if (attach_string == NULL)
return SANE_STATUS_NO_MEM;
return attach (devname, 0, SANE_EPSON_USB);
}
/*
* sane_init()
*
*
*/
SANE_Status
sane_init (SANE_Int * version_code, SANE_Auth_Callback authorize)
{
size_t len;
FILE *fp;
(void) authorize; /* get rid of compiler warning */
/* sanei_authorization(devicename, STRINGIFY(BACKEND_NAME), auth_callback); */
DBG_INIT ();
#if defined PACKAGE && defined VERSION
DBG (2, "sane_init: " PACKAGE " " VERSION "\n");
#endif
if (version_code != NULL)
*version_code = SANE_VERSION_CODE (SANE_CURRENT_MAJOR, SANE_CURRENT_MINOR, SANE_EPSON_BUILD);
sanei_usb_init ();
/* default to /dev/scanner instead of insisting on config file */
if ((fp = sanei_config_open (EPSON_CONFIG_FILE)))
{
char line[PATH_MAX];
while (sanei_config_read (line, sizeof (line), fp))
{
int vendor, product;
DBG (4, "sane_init, >%s<\n", line);
if (line[0] == '#') /* ignore line comments */
continue;
len = strlen (line);
if (!len)
continue; /* ignore empty lines */
if (sscanf (line, "usb %i %i", &vendor, &product) == 2)
{
int numIds;
/* add the vendor and product IDs to the list of
known devices before we call the attach function */
numIds = sanei_epson_getNumberOfUSBProductIds ();
if (vendor != 0x4b8)
continue; /* this is not an EPSON device */
sanei_epson_usb_product_ids[numIds - 1] = product;
sanei_usb_attach_matching_devices (line, attach_one_usb);
}
else if (strncmp (line, "usb", 3) == 0)
{
const char *dev_name;
/* remove the "usb" sub string */
dev_name = sanei_config_skip_whitespace (line + 3);
attach_one_usb (dev_name);
}
else
{
sanei_config_attach_matching_devices (line, attach_one);
}
}
fclose (fp);
}
/* read the option section and assign the connection type to the
scanner structure - which we don't have at this time. So I have
to come up with something :-) */
return SANE_STATUS_GOOD;
}
/*
* void sane_exit(void)
*
* Clean up the list of attached scanners.
*/
void
sane_exit (void)
{
Epson_Device *dev, *next;
for (dev = first_dev; dev; dev = next)
{
next = dev->next;
free ((void *) dev->sane.name);
free ((void *) dev->sane.model);
free (dev);
}
free (devlist);
}
/*
*
*
*/
SANE_Status
sane_get_devices (const SANE_Device * **device_list, SANE_Bool local_only)
{
Epson_Device *dev;
int i;
DBG (5, "sane_get_devices()\n");
(void) local_only; /* just to get rid of the compiler warning */
if (devlist)
{
free (devlist);
}
devlist = malloc ((num_devices + 1) * sizeof (devlist[0]));
if (!devlist)
{
DBG (1, "out of memory (line %d)\n", __LINE__);
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;
}
/*
*
*
*/
static SANE_Status
init_options (Epson_Scanner * s)
{
int i;
SANE_Bool dummy;
DBG (5, "init_options()\n");
for (i = 0; i < NUM_OPTIONS; ++i)
{
s->opt[i].size = sizeof (SANE_Word);
s->opt[i].cap = SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT;
}
s->opt[OPT_NUM_OPTS].title = SANE_TITLE_NUM_OPTIONS;
s->opt[OPT_NUM_OPTS].desc = SANE_DESC_NUM_OPTIONS;
s->opt[OPT_NUM_OPTS].type = SANE_TYPE_INT;
s->opt[OPT_NUM_OPTS].cap = SANE_CAP_SOFT_DETECT;
s->val[OPT_NUM_OPTS].w = NUM_OPTIONS;
/* "Scan Mode" group: */
s->opt[OPT_MODE_GROUP].title = SANE_I18N ("Scan Mode");
s->opt[OPT_MODE_GROUP].desc = "";
s->opt[OPT_MODE_GROUP].type = SANE_TYPE_GROUP;
s->opt[OPT_MODE_GROUP].cap = 0;
/* scan mode */
s->opt[OPT_MODE].name = SANE_NAME_SCAN_MODE;
s->opt[OPT_MODE].title = SANE_TITLE_SCAN_MODE;
s->opt[OPT_MODE].desc = SANE_DESC_SCAN_MODE;
s->opt[OPT_MODE].type = SANE_TYPE_STRING;
s->opt[OPT_MODE].size = max_string_size (mode_list);
s->opt[OPT_MODE].constraint_type = SANE_CONSTRAINT_STRING_LIST;
s->opt[OPT_MODE].constraint.string_list = mode_list;
s->val[OPT_MODE].w = 0; /* Binary */
/* bit depth */
s->opt[OPT_BIT_DEPTH].name = SANE_NAME_BIT_DEPTH;
s->opt[OPT_BIT_DEPTH].title = SANE_TITLE_BIT_DEPTH;
s->opt[OPT_BIT_DEPTH].desc = SANE_DESC_BIT_DEPTH;
s->opt[OPT_BIT_DEPTH].type = SANE_TYPE_INT;
s->opt[OPT_BIT_DEPTH].unit = SANE_UNIT_NONE;
s->opt[OPT_BIT_DEPTH].constraint_type = SANE_CONSTRAINT_WORD_LIST;
s->opt[OPT_BIT_DEPTH].constraint.word_list = bitDepthList;
s->opt[OPT_BIT_DEPTH].cap |= SANE_CAP_INACTIVE;
s->val[OPT_BIT_DEPTH].w = bitDepthList[1]; /* the first "real" element is the default */
if (bitDepthList[0] == 1) /* only one element in the list -> hide the option */
s->opt[OPT_BIT_DEPTH].cap |= SANE_CAP_INACTIVE;
/* halftone */
s->opt[OPT_HALFTONE].name = SANE_NAME_HALFTONE;
s->opt[OPT_HALFTONE].title = SANE_TITLE_HALFTONE;
s->opt[OPT_HALFTONE].desc = SANE_I18N ("Selects the halftone.");
s->opt[OPT_HALFTONE].type = SANE_TYPE_STRING;
s->opt[OPT_HALFTONE].size = max_string_size (halftone_list_7);
s->opt[OPT_HALFTONE].constraint_type = SANE_CONSTRAINT_STRING_LIST;
if (s->hw->level >= 7)
s->opt[OPT_HALFTONE].constraint.string_list = halftone_list_7;
else if (s->hw->level >= 4)
s->opt[OPT_HALFTONE].constraint.string_list = halftone_list_4;
else
s->opt[OPT_HALFTONE].constraint.string_list = halftone_list;
s->val[OPT_HALFTONE].w = 1; /* Halftone A */
if (!s->hw->cmd->set_halftoning)
{
s->opt[OPT_HALFTONE].cap |= SANE_CAP_INACTIVE;
}
/* dropout */
s->opt[OPT_DROPOUT].name = "dropout";
s->opt[OPT_DROPOUT].title = SANE_I18N ("Dropout");
s->opt[OPT_DROPOUT].desc = SANE_I18N ("Selects the dropout.");
s->opt[OPT_DROPOUT].type = SANE_TYPE_STRING;
s->opt[OPT_DROPOUT].size = max_string_size (dropout_list);
s->opt[OPT_DROPOUT].cap |= SANE_CAP_ADVANCED;
s->opt[OPT_DROPOUT].constraint_type = SANE_CONSTRAINT_STRING_LIST;
s->opt[OPT_DROPOUT].constraint.string_list = dropout_list;
s->val[OPT_DROPOUT].w = 0; /* None */
/* brightness */
s->opt[OPT_BRIGHTNESS].name = SANE_NAME_BRIGHTNESS;
s->opt[OPT_BRIGHTNESS].title = SANE_TITLE_BRIGHTNESS;
s->opt[OPT_BRIGHTNESS].desc = SANE_I18N ("Selects the brightness.");
s->opt[OPT_BRIGHTNESS].type = SANE_TYPE_INT;
s->opt[OPT_BRIGHTNESS].unit = SANE_UNIT_NONE;
s->opt[OPT_BRIGHTNESS].constraint_type = SANE_CONSTRAINT_RANGE;
s->opt[OPT_BRIGHTNESS].constraint.range = &s->hw->cmd->bright_range;
s->val[OPT_BRIGHTNESS].w = 0; /* Normal */
if (!s->hw->cmd->set_bright)
{
s->opt[OPT_BRIGHTNESS].cap |= SANE_CAP_INACTIVE;
}
/* sharpness */
s->opt[OPT_SHARPNESS].name = "sharpness";
s->opt[OPT_SHARPNESS].title = SANE_I18N ("Sharpness");
s->opt[OPT_SHARPNESS].desc = "";
s->opt[OPT_SHARPNESS].type = SANE_TYPE_INT;
s->opt[OPT_SHARPNESS].unit = SANE_UNIT_NONE;
s->opt[OPT_SHARPNESS].constraint_type = SANE_CONSTRAINT_RANGE;
s->opt[OPT_SHARPNESS].constraint.range = &outline_emphasis_range;
s->val[OPT_SHARPNESS].w = 0; /* Normal */
if (!s->hw->cmd->set_outline_emphasis)
{
s->opt[OPT_SHARPNESS].cap |= SANE_CAP_INACTIVE;
}
/* gamma */
s->opt[OPT_GAMMA_CORRECTION].name = SANE_NAME_GAMMA_CORRECTION;
s->opt[OPT_GAMMA_CORRECTION].title = SANE_TITLE_GAMMA_CORRECTION;
s->opt[OPT_GAMMA_CORRECTION].desc = SANE_DESC_GAMMA_CORRECTION;
s->opt[OPT_GAMMA_CORRECTION].type = SANE_TYPE_STRING;
s->opt[OPT_GAMMA_CORRECTION].constraint_type = SANE_CONSTRAINT_STRING_LIST;
/*
* special handling for D1 function level - at this time I'm not
* testing for D1, I'm just assuming that all D level scanners will
* behave the same way. This has to be confirmed with the next D-level
* scanner
*/
if (s->hw->cmd->level[0] == 'D')
{
s->opt[OPT_GAMMA_CORRECTION].size = max_string_size (gamma_list_d);
s->opt[OPT_GAMMA_CORRECTION].constraint.string_list = gamma_list_d;
s->val[OPT_GAMMA_CORRECTION].w = 1; /* Default */
gamma_userdefined = gamma_userdefined_d;
gamma_params = gamma_params_d;
}
else
{
s->opt[OPT_GAMMA_CORRECTION].size = max_string_size (gamma_list_ab);
s->opt[OPT_GAMMA_CORRECTION].constraint.string_list = gamma_list_ab;
s->val[OPT_GAMMA_CORRECTION].w = 0; /* Default */
gamma_userdefined = gamma_userdefined_ab;
gamma_params = gamma_params_ab;
}
if (!s->hw->cmd->set_gamma)
{
s->opt[OPT_GAMMA_CORRECTION].cap |= SANE_CAP_INACTIVE;
}
/* gamma vector */
/*
s->opt[ OPT_GAMMA_VECTOR].name = SANE_NAME_GAMMA_VECTOR;
s->opt[ OPT_GAMMA_VECTOR].title = SANE_TITLE_GAMMA_VECTOR;
s->opt[ OPT_GAMMA_VECTOR].desc = SANE_DESC_GAMMA_VECTOR;
s->opt[ OPT_GAMMA_VECTOR].type = SANE_TYPE_INT;
s->opt[ OPT_GAMMA_VECTOR].unit = SANE_UNIT_NONE;
s->opt[ OPT_GAMMA_VECTOR].size = 256 * sizeof (SANE_Word);
s->opt[ OPT_GAMMA_VECTOR].constraint_type = SANE_CONSTRAINT_RANGE;
s->opt[ OPT_GAMMA_VECTOR].constraint.range = &u8_range;
s->val[ OPT_GAMMA_VECTOR].wa = &s->gamma_table [ 0] [ 0];
*/
/* red gamma vector */
s->opt[OPT_GAMMA_VECTOR_R].name = SANE_NAME_GAMMA_VECTOR_R;
s->opt[OPT_GAMMA_VECTOR_R].title = SANE_TITLE_GAMMA_VECTOR_R;
s->opt[OPT_GAMMA_VECTOR_R].desc = SANE_DESC_GAMMA_VECTOR_R;
s->opt[OPT_GAMMA_VECTOR_R].type = SANE_TYPE_INT;
s->opt[OPT_GAMMA_VECTOR_R].unit = SANE_UNIT_NONE;
s->opt[OPT_GAMMA_VECTOR_R].size = 256 * sizeof (SANE_Word);
s->opt[OPT_GAMMA_VECTOR_R].constraint_type = SANE_CONSTRAINT_RANGE;
s->opt[OPT_GAMMA_VECTOR_R].constraint.range = &u8_range;
s->val[OPT_GAMMA_VECTOR_R].wa = &s->gamma_table[0][0];
/* green gamma vector */
s->opt[OPT_GAMMA_VECTOR_G].name = SANE_NAME_GAMMA_VECTOR_G;
s->opt[OPT_GAMMA_VECTOR_G].title = SANE_TITLE_GAMMA_VECTOR_G;
s->opt[OPT_GAMMA_VECTOR_G].desc = SANE_DESC_GAMMA_VECTOR_G;
s->opt[OPT_GAMMA_VECTOR_G].type = SANE_TYPE_INT;
s->opt[OPT_GAMMA_VECTOR_G].unit = SANE_UNIT_NONE;
s->opt[OPT_GAMMA_VECTOR_G].size = 256 * sizeof (SANE_Word);
s->opt[OPT_GAMMA_VECTOR_G].constraint_type = SANE_CONSTRAINT_RANGE;
s->opt[OPT_GAMMA_VECTOR_G].constraint.range = &u8_range;
s->val[OPT_GAMMA_VECTOR_G].wa = &s->gamma_table[1][0];
/* red gamma vector */
s->opt[OPT_GAMMA_VECTOR_B].name = SANE_NAME_GAMMA_VECTOR_B;
s->opt[OPT_GAMMA_VECTOR_B].title = SANE_TITLE_GAMMA_VECTOR_B;
s->opt[OPT_GAMMA_VECTOR_B].desc = SANE_DESC_GAMMA_VECTOR_B;
s->opt[OPT_GAMMA_VECTOR_B].type = SANE_TYPE_INT;
s->opt[OPT_GAMMA_VECTOR_B].unit = SANE_UNIT_NONE;
s->opt[OPT_GAMMA_VECTOR_B].size = 256 * sizeof (SANE_Word);
s->opt[OPT_GAMMA_VECTOR_B].constraint_type = SANE_CONSTRAINT_RANGE;
s->opt[OPT_GAMMA_VECTOR_B].constraint.range = &u8_range;
s->val[OPT_GAMMA_VECTOR_B].wa = &s->gamma_table[2][0];
if (s->hw->cmd->set_gamma_table &&
gamma_userdefined[s->val[OPT_GAMMA_CORRECTION].w] == SANE_TRUE)
{
/* s->opt[ OPT_GAMMA_VECTOR].cap &= ~SANE_CAP_INACTIVE; */
s->opt[OPT_GAMMA_VECTOR_R].cap &= ~SANE_CAP_INACTIVE;
s->opt[OPT_GAMMA_VECTOR_G].cap &= ~SANE_CAP_INACTIVE;
s->opt[OPT_GAMMA_VECTOR_B].cap &= ~SANE_CAP_INACTIVE;
}
else
{
/* s->opt[ OPT_GAMMA_VECTOR].cap |= SANE_CAP_INACTIVE; */
s->opt[OPT_GAMMA_VECTOR_R].cap |= SANE_CAP_INACTIVE;
s->opt[OPT_GAMMA_VECTOR_G].cap |= SANE_CAP_INACTIVE;
s->opt[OPT_GAMMA_VECTOR_B].cap |= SANE_CAP_INACTIVE;
}
/* initialize the Gamma tables */
memset (&s->gamma_table[0], 0, 256 * sizeof (SANE_Word));
memset (&s->gamma_table[1], 0, 256 * sizeof (SANE_Word));
memset (&s->gamma_table[2], 0, 256 * sizeof (SANE_Word));
/* memset(&s->gamma_table[3], 0, 256 * sizeof(SANE_Word)); */
for (i = 0; i < 256; i++)
{
s->gamma_table[0][i] = i;
s->gamma_table[1][i] = i;
s->gamma_table[2][i] = i;
/* s->gamma_table[3][i] = i; */
}
/* color correction */
s->opt[OPT_COLOR_CORRECTION].name = "color-correction";
s->opt[OPT_COLOR_CORRECTION].title = SANE_I18N ("Color correction");
s->opt[OPT_COLOR_CORRECTION].desc =
SANE_I18N
("Sets the color correction table for the selected output device.");
s->opt[OPT_COLOR_CORRECTION].type = SANE_TYPE_STRING;
s->opt[OPT_COLOR_CORRECTION].size = 32;
s->opt[OPT_COLOR_CORRECTION].cap |= SANE_CAP_ADVANCED;
s->opt[OPT_COLOR_CORRECTION].constraint_type = SANE_CONSTRAINT_STRING_LIST;
s->opt[OPT_COLOR_CORRECTION].constraint.string_list = color_list;
s->val[OPT_COLOR_CORRECTION].w = 5; /* scanner default: CRT monitors */
if (!s->hw->cmd->set_color_correction)
{
s->opt[OPT_COLOR_CORRECTION].cap |= SANE_CAP_INACTIVE;
}
/* resolution */
s->opt[OPT_RESOLUTION].name = SANE_NAME_SCAN_RESOLUTION;
s->opt[OPT_RESOLUTION].title = SANE_TITLE_SCAN_RESOLUTION;
s->opt[OPT_RESOLUTION].desc = SANE_DESC_SCAN_RESOLUTION;
s->opt[OPT_RESOLUTION].type = SANE_TYPE_INT;
s->opt[OPT_RESOLUTION].unit = SANE_UNIT_DPI;
s->opt[OPT_RESOLUTION].constraint_type = SANE_CONSTRAINT_WORD_LIST;
s->opt[OPT_RESOLUTION].constraint.word_list = s->hw->resolution_list;
s->val[OPT_RESOLUTION].w = s->hw->dpi_range.min;
/* threshold */
s->opt[OPT_THRESHOLD].name = SANE_NAME_THRESHOLD;
s->opt[OPT_THRESHOLD].title = SANE_TITLE_THRESHOLD;
s->opt[OPT_THRESHOLD].desc = SANE_DESC_THRESHOLD;
s->opt[OPT_THRESHOLD].type = SANE_TYPE_INT;
s->opt[OPT_THRESHOLD].unit = SANE_UNIT_NONE;
s->opt[OPT_THRESHOLD].constraint_type = SANE_CONSTRAINT_RANGE;
s->opt[OPT_THRESHOLD].constraint.range = &u8_range;
s->val[OPT_THRESHOLD].w = 0x80;
if (!s->hw->cmd->set_threshold)
{
s->opt[OPT_THRESHOLD].cap |= SANE_CAP_INACTIVE;
}
s->opt[OPT_CCT_GROUP].title = SANE_I18N ("Color correction coefficients");
s->opt[OPT_CCT_GROUP].desc = SANE_I18N ("Matrix multiplication of RGB");
s->opt[OPT_CCT_GROUP].type = SANE_TYPE_GROUP;
s->opt[OPT_CCT_GROUP].cap = SANE_CAP_ADVANCED;
/* color correction coefficients */
s->opt[OPT_CCT_1].name = "cct-1";
s->opt[OPT_CCT_2].name = "cct-2";
s->opt[OPT_CCT_3].name = "cct-3";
s->opt[OPT_CCT_4].name = "cct-4";
s->opt[OPT_CCT_5].name = "cct-5";
s->opt[OPT_CCT_6].name = "cct-6";
s->opt[OPT_CCT_7].name = "cct-7";
s->opt[OPT_CCT_8].name = "cct-8";
s->opt[OPT_CCT_9].name = "cct-9";
s->opt[OPT_CCT_1].title = SANE_I18N ("Green");
s->opt[OPT_CCT_2].title = SANE_I18N ("Shift green to red");
s->opt[OPT_CCT_3].title = SANE_I18N ("Shift green to blue");
s->opt[OPT_CCT_4].title = SANE_I18N ("Shift red to green");
s->opt[OPT_CCT_5].title = SANE_I18N ("Red");
s->opt[OPT_CCT_6].title = SANE_I18N ("Shift red to blue");
s->opt[OPT_CCT_7].title = SANE_I18N ("Shift blue to green");
s->opt[OPT_CCT_8].title = SANE_I18N ("Shift blue to red");
s->opt[OPT_CCT_9].title = SANE_I18N ("Blue");
s->opt[OPT_CCT_1].desc = SANE_I18N ("Controls green level");
s->opt[OPT_CCT_2].desc = SANE_I18N ("Adds to red based on green level");
s->opt[OPT_CCT_3].desc = SANE_I18N ("Adds to blue based on green level");
s->opt[OPT_CCT_4].desc = SANE_I18N ("Adds to green based on red level");
s->opt[OPT_CCT_5].desc = SANE_I18N ("Controls red level");
s->opt[OPT_CCT_6].desc = SANE_I18N ("Adds to blue based on red level");
s->opt[OPT_CCT_7].desc = SANE_I18N ("Adds to green based on blue level");
s->opt[OPT_CCT_8].desc = SANE_I18N ("Adds to red based on blue level");
s->opt[OPT_CCT_9].desc = SANE_I18N ("Controls blue level");
s->opt[OPT_CCT_1].type = SANE_TYPE_INT;
s->opt[OPT_CCT_2].type = SANE_TYPE_INT;
s->opt[OPT_CCT_3].type = SANE_TYPE_INT;
s->opt[OPT_CCT_4].type = SANE_TYPE_INT;
s->opt[OPT_CCT_5].type = SANE_TYPE_INT;
s->opt[OPT_CCT_6].type = SANE_TYPE_INT;
s->opt[OPT_CCT_7].type = SANE_TYPE_INT;
s->opt[OPT_CCT_8].type = SANE_TYPE_INT;
s->opt[OPT_CCT_9].type = SANE_TYPE_INT;
s->opt[OPT_CCT_1].cap |= SANE_CAP_ADVANCED;
s->opt[OPT_CCT_2].cap |= SANE_CAP_ADVANCED;
s->opt[OPT_CCT_3].cap |= SANE_CAP_ADVANCED;
s->opt[OPT_CCT_4].cap |= SANE_CAP_ADVANCED;
s->opt[OPT_CCT_5].cap |= SANE_CAP_ADVANCED;
s->opt[OPT_CCT_6].cap |= SANE_CAP_ADVANCED;
s->opt[OPT_CCT_7].cap |= SANE_CAP_ADVANCED;
s->opt[OPT_CCT_8].cap |= SANE_CAP_ADVANCED;
s->opt[OPT_CCT_9].cap |= SANE_CAP_ADVANCED;
s->opt[OPT_CCT_1].cap |= SANE_CAP_INACTIVE;
s->opt[OPT_CCT_2].cap |= SANE_CAP_INACTIVE;
s->opt[OPT_CCT_3].cap |= SANE_CAP_INACTIVE;
s->opt[OPT_CCT_4].cap |= SANE_CAP_INACTIVE;
s->opt[OPT_CCT_5].cap |= SANE_CAP_INACTIVE;
s->opt[OPT_CCT_6].cap |= SANE_CAP_INACTIVE;
s->opt[OPT_CCT_7].cap |= SANE_CAP_INACTIVE;
s->opt[OPT_CCT_8].cap |= SANE_CAP_INACTIVE;
s->opt[OPT_CCT_9].cap |= SANE_CAP_INACTIVE;
s->opt[OPT_CCT_1].unit = SANE_UNIT_NONE;
s->opt[OPT_CCT_2].unit = SANE_UNIT_NONE;
s->opt[OPT_CCT_3].unit = SANE_UNIT_NONE;
s->opt[OPT_CCT_4].unit = SANE_UNIT_NONE;
s->opt[OPT_CCT_5].unit = SANE_UNIT_NONE;
s->opt[OPT_CCT_6].unit = SANE_UNIT_NONE;
s->opt[OPT_CCT_7].unit = SANE_UNIT_NONE;
s->opt[OPT_CCT_8].unit = SANE_UNIT_NONE;
s->opt[OPT_CCT_9].unit = SANE_UNIT_NONE;
s->opt[OPT_CCT_1].constraint_type = SANE_CONSTRAINT_RANGE;
s->opt[OPT_CCT_2].constraint_type = SANE_CONSTRAINT_RANGE;
s->opt[OPT_CCT_3].constraint_type = SANE_CONSTRAINT_RANGE;
s->opt[OPT_CCT_4].constraint_type = SANE_CONSTRAINT_RANGE;
s->opt[OPT_CCT_5].constraint_type = SANE_CONSTRAINT_RANGE;
s->opt[OPT_CCT_6].constraint_type = SANE_CONSTRAINT_RANGE;
s->opt[OPT_CCT_7].constraint_type = SANE_CONSTRAINT_RANGE;
s->opt[OPT_CCT_8].constraint_type = SANE_CONSTRAINT_RANGE;
s->opt[OPT_CCT_9].constraint_type = SANE_CONSTRAINT_RANGE;
s->opt[OPT_CCT_1].constraint.range = &s8_range;
s->opt[OPT_CCT_2].constraint.range = &s8_range;
s->opt[OPT_CCT_3].constraint.range = &s8_range;
s->opt[OPT_CCT_4].constraint.range = &s8_range;
s->opt[OPT_CCT_5].constraint.range = &s8_range;
s->opt[OPT_CCT_6].constraint.range = &s8_range;
s->opt[OPT_CCT_7].constraint.range = &s8_range;
s->opt[OPT_CCT_8].constraint.range = &s8_range;
s->opt[OPT_CCT_9].constraint.range = &s8_range;
s->val[OPT_CCT_1].w = 32;
s->val[OPT_CCT_2].w = 0;
s->val[OPT_CCT_3].w = 0;
s->val[OPT_CCT_4].w = 0;
s->val[OPT_CCT_5].w = 32;
s->val[OPT_CCT_6].w = 0;
s->val[OPT_CCT_7].w = 0;
s->val[OPT_CCT_8].w = 0;
s->val[OPT_CCT_9].w = 32;
if (!s->hw->cmd->set_color_correction_coefficients)
{
s->opt[OPT_CCT_1].cap |= SANE_CAP_INACTIVE;
s->opt[OPT_CCT_2].cap |= SANE_CAP_INACTIVE;
s->opt[OPT_CCT_3].cap |= SANE_CAP_INACTIVE;
s->opt[OPT_CCT_4].cap |= SANE_CAP_INACTIVE;
s->opt[OPT_CCT_5].cap |= SANE_CAP_INACTIVE;
s->opt[OPT_CCT_6].cap |= SANE_CAP_INACTIVE;
s->opt[OPT_CCT_7].cap |= SANE_CAP_INACTIVE;
s->opt[OPT_CCT_8].cap |= SANE_CAP_INACTIVE;
s->opt[OPT_CCT_9].cap |= SANE_CAP_INACTIVE;
}
/* "Advanced" group: */
s->opt[OPT_ADVANCED_GROUP].title = SANE_I18N ("Advanced");
s->opt[OPT_ADVANCED_GROUP].desc = "";
s->opt[OPT_ADVANCED_GROUP].type = SANE_TYPE_GROUP;
s->opt[OPT_ADVANCED_GROUP].cap = SANE_CAP_ADVANCED;
/* mirror */
s->opt[OPT_MIRROR].name = "mirror";
s->opt[OPT_MIRROR].title = SANE_I18N ("Mirror image");
s->opt[OPT_MIRROR].desc = SANE_I18N ("Mirror the image.");
s->opt[OPT_MIRROR].type = SANE_TYPE_BOOL;
s->val[OPT_MIRROR].w = SANE_FALSE;
if (!s->hw->cmd->mirror_image)
{
s->opt[OPT_MIRROR].cap |= SANE_CAP_INACTIVE;
}
/* speed */
s->opt[OPT_SPEED].name = SANE_NAME_SCAN_SPEED;
s->opt[OPT_SPEED].title = SANE_TITLE_SCAN_SPEED;
s->opt[OPT_SPEED].desc = SANE_DESC_SCAN_SPEED;
s->opt[OPT_SPEED].type = SANE_TYPE_BOOL;
s->val[OPT_SPEED].w = SANE_FALSE;
if (!s->hw->cmd->set_speed)
{
s->opt[OPT_SPEED].cap |= SANE_CAP_INACTIVE;
}
/* preview speed */
s->opt[OPT_PREVIEW_SPEED].name = "preview-speed";
s->opt[OPT_PREVIEW_SPEED].title = SANE_I18N ("Fast preview");
s->opt[OPT_PREVIEW_SPEED].desc = "";
s->opt[OPT_PREVIEW_SPEED].type = SANE_TYPE_BOOL;
s->val[OPT_PREVIEW_SPEED].w = SANE_FALSE;
if (!s->hw->cmd->set_speed)
{
s->opt[OPT_PREVIEW_SPEED].cap |= SANE_CAP_INACTIVE;
}
/* auto area segmentation */
s->opt[OPT_AAS].name = "auto-area-segmentation";
s->opt[OPT_AAS].title = SANE_I18N ("Auto area segmentation");
s->opt[OPT_AAS].desc = "";
s->opt[OPT_AAS].type = SANE_TYPE_BOOL;
s->val[OPT_AAS].w = SANE_TRUE;
if (!s->hw->cmd->control_auto_area_segmentation)
{
s->opt[OPT_AAS].cap |= SANE_CAP_INACTIVE;
}
/* limit resolution list */
s->opt[OPT_LIMIT_RESOLUTION].name = "short-resolution";
s->opt[OPT_LIMIT_RESOLUTION].title = SANE_I18N ("Short resolution list");
s->opt[OPT_LIMIT_RESOLUTION].desc =
SANE_I18N ("Display short resolution list");
s->opt[OPT_LIMIT_RESOLUTION].type = SANE_TYPE_BOOL;
s->val[OPT_LIMIT_RESOLUTION].w = SANE_FALSE;
/* zoom */
s->opt[OPT_ZOOM].name = "zoom";
s->opt[OPT_ZOOM].title = SANE_I18N ("Zoom");
s->opt[OPT_ZOOM].desc =
SANE_I18N ("Defines the zoom factor the scanner will use");
s->opt[OPT_ZOOM].type = SANE_TYPE_INT;
s->opt[OPT_ZOOM].unit = SANE_UNIT_NONE;
s->opt[OPT_ZOOM].constraint_type = SANE_CONSTRAINT_RANGE;
s->opt[OPT_ZOOM].constraint.range = &zoom_range;
s->val[OPT_ZOOM].w = 100;
/* if( ! s->hw->cmd->set_zoom) */
{
s->opt[OPT_ZOOM].cap |= SANE_CAP_INACTIVE;
}
/* "Preview settings" group: */
s->opt[OPT_PREVIEW_GROUP].title = SANE_TITLE_PREVIEW;
s->opt[OPT_PREVIEW_GROUP].desc = "";
s->opt[OPT_PREVIEW_GROUP].type = SANE_TYPE_GROUP;
s->opt[OPT_PREVIEW_GROUP].cap = SANE_CAP_ADVANCED;
/* preview */
s->opt[OPT_PREVIEW].name = SANE_NAME_PREVIEW;
s->opt[OPT_PREVIEW].title = SANE_TITLE_PREVIEW;
s->opt[OPT_PREVIEW].desc = SANE_DESC_PREVIEW;
s->opt[OPT_PREVIEW].type = SANE_TYPE_BOOL;
s->val[OPT_PREVIEW].w = SANE_FALSE;
/* "Geometry" group: */
s->opt[OPT_GEOMETRY_GROUP].title = SANE_I18N ("Geometry");
s->opt[OPT_GEOMETRY_GROUP].desc = "";
s->opt[OPT_GEOMETRY_GROUP].type = SANE_TYPE_GROUP;
s->opt[OPT_GEOMETRY_GROUP].cap = SANE_CAP_ADVANCED;
/* top-left x */
s->opt[OPT_TL_X].name = SANE_NAME_SCAN_TL_X;
s->opt[OPT_TL_X].title = SANE_TITLE_SCAN_TL_X;
s->opt[OPT_TL_X].desc = SANE_DESC_SCAN_TL_X;
s->opt[OPT_TL_X].type = SANE_TYPE_FIXED;
s->opt[OPT_TL_X].unit = SANE_UNIT_MM;
s->opt[OPT_TL_X].constraint_type = SANE_CONSTRAINT_RANGE;
s->opt[OPT_TL_X].constraint.range = s->hw->x_range;
s->val[OPT_TL_X].w = 0;
/* top-left y */
s->opt[OPT_TL_Y].name = SANE_NAME_SCAN_TL_Y;
s->opt[OPT_TL_Y].title = SANE_TITLE_SCAN_TL_Y;
s->opt[OPT_TL_Y].desc = SANE_DESC_SCAN_TL_Y;
s->opt[OPT_TL_Y].type = SANE_TYPE_FIXED;
s->opt[OPT_TL_Y].unit = SANE_UNIT_MM;
s->opt[OPT_TL_Y].constraint_type = SANE_CONSTRAINT_RANGE;
s->opt[OPT_TL_Y].constraint.range = s->hw->y_range;
s->val[OPT_TL_Y].w = 0;
/* bottom-right x */
s->opt[OPT_BR_X].name = SANE_NAME_SCAN_BR_X;
s->opt[OPT_BR_X].title = SANE_TITLE_SCAN_BR_X;
s->opt[OPT_BR_X].desc = SANE_DESC_SCAN_BR_X;
s->opt[OPT_BR_X].type = SANE_TYPE_FIXED;
s->opt[OPT_BR_X].unit = SANE_UNIT_MM;
s->opt[OPT_BR_X].constraint_type = SANE_CONSTRAINT_RANGE;
s->opt[OPT_BR_X].constraint.range = s->hw->x_range;
s->val[OPT_BR_X].w = s->hw->x_range->max;
/* bottom-right y */
s->opt[OPT_BR_Y].name = SANE_NAME_SCAN_BR_Y;
s->opt[OPT_BR_Y].title = SANE_TITLE_SCAN_BR_Y;
s->opt[OPT_BR_Y].desc = SANE_DESC_SCAN_BR_Y;
s->opt[OPT_BR_Y].type = SANE_TYPE_FIXED;
s->opt[OPT_BR_Y].unit = SANE_UNIT_MM;
s->opt[OPT_BR_Y].constraint_type = SANE_CONSTRAINT_RANGE;
s->opt[OPT_BR_Y].constraint.range = s->hw->y_range;
s->val[OPT_BR_Y].w = s->hw->y_range->max;
/* Quick format */
s->opt[OPT_QUICK_FORMAT].name = "quick-format";
s->opt[OPT_QUICK_FORMAT].title = SANE_I18N ("Quick format");
s->opt[OPT_QUICK_FORMAT].desc = "";
s->opt[OPT_QUICK_FORMAT].type = SANE_TYPE_STRING;
s->opt[OPT_QUICK_FORMAT].size = max_string_size (qf_list);
s->opt[OPT_QUICK_FORMAT].cap |= SANE_CAP_ADVANCED;
s->opt[OPT_QUICK_FORMAT].constraint_type = SANE_CONSTRAINT_STRING_LIST;
s->opt[OPT_QUICK_FORMAT].constraint.string_list = qf_list;
s->val[OPT_QUICK_FORMAT].w = XtNumber (qf_params) - 1; /* max */
/* "Optional equipment" group: */
s->opt[OPT_EQU_GROUP].title = SANE_I18N ("Optional equipment");
s->opt[OPT_EQU_GROUP].desc = "";
s->opt[OPT_EQU_GROUP].type = SANE_TYPE_GROUP;
s->opt[OPT_EQU_GROUP].cap = SANE_CAP_ADVANCED;
/* source */
s->opt[OPT_SOURCE].name = SANE_NAME_SCAN_SOURCE;
s->opt[OPT_SOURCE].title = SANE_TITLE_SCAN_SOURCE;
s->opt[OPT_SOURCE].desc = SANE_DESC_SCAN_SOURCE;
s->opt[OPT_SOURCE].type = SANE_TYPE_STRING;
s->opt[OPT_SOURCE].size = max_string_size (source_list);
s->opt[OPT_SOURCE].constraint_type = SANE_CONSTRAINT_STRING_LIST;
s->opt[OPT_SOURCE].constraint.string_list = source_list;
if (!s->hw->extension)
{
s->opt[OPT_SOURCE].cap |= SANE_CAP_INACTIVE;
}
s->val[OPT_SOURCE].w = 0; /* always use Flatbed as default */
/* film type */
s->opt[OPT_FILM_TYPE].name = "film-type";
s->opt[OPT_FILM_TYPE].title = SANE_I18N ("Film type");
s->opt[OPT_FILM_TYPE].desc = "";
s->opt[OPT_FILM_TYPE].type = SANE_TYPE_STRING;
s->opt[OPT_FILM_TYPE].size = max_string_size (film_list);
s->opt[OPT_FILM_TYPE].constraint_type = SANE_CONSTRAINT_STRING_LIST;
s->opt[OPT_FILM_TYPE].constraint.string_list = film_list;
s->val[OPT_FILM_TYPE].w = 0;
deactivateOption (s, OPT_FILM_TYPE, &dummy); /* default is inactive */
/* focus position */
s->opt[OPT_FOCUS].name = SANE_EPSON_FOCUS_NAME;
s->opt[OPT_FOCUS].title = SANE_EPSON_FOCUS_TITLE;
s->opt[OPT_FOCUS].desc = SANE_EPSON_FOCUS_DESC;
s->opt[OPT_FOCUS].type = SANE_TYPE_STRING;
s->opt[OPT_FOCUS].size = max_string_size (focus_list);
s->opt[OPT_FOCUS].constraint_type = SANE_CONSTRAINT_STRING_LIST;
s->opt[OPT_FOCUS].constraint.string_list = focus_list;
s->val[OPT_FOCUS].w = 0;
s->opt[OPT_FOCUS].cap |= SANE_CAP_ADVANCED;
if (s->hw->focusSupport == SANE_TRUE)
{
s->opt[OPT_FOCUS].cap &= ~SANE_CAP_INACTIVE;
}
else
{
s->opt[OPT_FOCUS].cap |= SANE_CAP_INACTIVE;
}
#if 0
if ((!s->hw->TPU) && (!s->hw->cmd->set_bay))
{ /* Hack: Using set_bay to indicate. */
SANE_Bool dummy;
deactivateOption (s, OPT_FILM_TYPE, &dummy);
}
#endif
/* forward feed / eject */
s->opt[OPT_EJECT].name = "eject";
s->opt[OPT_EJECT].title = SANE_I18N ("Eject");
s->opt[OPT_EJECT].desc = SANE_I18N ("Eject the sheet in the ADF");
s->opt[OPT_EJECT].type = SANE_TYPE_BUTTON;
if ((!s->hw->ADF) && (!s->hw->cmd->set_bay))
{ /* Hack: Using set_bay to indicate. */
s->opt[OPT_EJECT].cap |= SANE_CAP_INACTIVE;
}
/* auto forward feed / eject */
s->opt[OPT_AUTO_EJECT].name = "auto-eject";
s->opt[OPT_AUTO_EJECT].title = SANE_I18N ("Auto eject");
s->opt[OPT_AUTO_EJECT].desc = SANE_I18N ("Eject document after scanning");
s->opt[OPT_AUTO_EJECT].type = SANE_TYPE_BOOL;
s->val[OPT_AUTO_EJECT].w = SANE_FALSE;
if (!s->hw->ADF)
{
s->opt[OPT_AUTO_EJECT].cap |= SANE_CAP_INACTIVE;
}
s->opt[OPT_ADF_MODE].name = "adf_mode";
s->opt[OPT_ADF_MODE].title = SANE_I18N ("ADF Mode");
s->opt[OPT_ADF_MODE].desc =
SANE_I18N ("Selects the ADF mode (simplex/duplex)");
s->opt[OPT_ADF_MODE].type = SANE_TYPE_STRING;
s->opt[OPT_ADF_MODE].size = max_string_size (adf_mode_list);
s->opt[OPT_ADF_MODE].constraint_type = SANE_CONSTRAINT_STRING_LIST;
s->opt[OPT_ADF_MODE].constraint.string_list = adf_mode_list;
s->val[OPT_ADF_MODE].w = 0; /* simplex */
if ((!s->hw->ADF) || (s->hw->duplexSupport == SANE_FALSE))
{
s->opt[OPT_ADF_MODE].cap |= SANE_CAP_INACTIVE;
}
/* select bay */
s->opt[OPT_BAY].name = "bay";
s->opt[OPT_BAY].title = SANE_I18N ("Bay");
s->opt[OPT_BAY].desc = SANE_I18N ("Select bay to scan");
s->opt[OPT_BAY].type = SANE_TYPE_STRING;
s->opt[OPT_BAY].size = max_string_size (bay_list);
s->opt[OPT_BAY].constraint_type = SANE_CONSTRAINT_STRING_LIST;
s->opt[OPT_BAY].constraint.string_list = bay_list;
s->val[OPT_BAY].w = 0; /* Bay 1 */
if (!s->hw->cmd->set_bay)
{
s->opt[OPT_BAY].cap |= SANE_CAP_INACTIVE;
}
s->opt[OPT_WAIT_FOR_BUTTON].name = SANE_EPSON_WAIT_FOR_BUTTON_NAME;
s->opt[OPT_WAIT_FOR_BUTTON].title = SANE_EPSON_WAIT_FOR_BUTTON_TITLE;
s->opt[OPT_WAIT_FOR_BUTTON].desc = SANE_EPSON_WAIT_FOR_BUTTON_DESC;
s->opt[OPT_WAIT_FOR_BUTTON].type = SANE_TYPE_BOOL;
s->opt[OPT_WAIT_FOR_BUTTON].unit = SANE_UNIT_NONE;
s->opt[OPT_WAIT_FOR_BUTTON].constraint_type = SANE_CONSTRAINT_NONE;
s->opt[OPT_WAIT_FOR_BUTTON].constraint.range = NULL;
s->opt[OPT_WAIT_FOR_BUTTON].cap |= SANE_CAP_ADVANCED;
if (!s->hw->cmd->request_push_button_status)
{
s->opt[OPT_WAIT_FOR_BUTTON].cap |= SANE_CAP_INACTIVE;
}
return SANE_STATUS_GOOD;
}
/*
*
*
*/
SANE_Status
sane_open (SANE_String_Const devicename, SANE_Handle * handle)
{
Epson_Device *dev;
Epson_Scanner *s;
DBG (5, "sane_open(%s)\n", devicename);
/* search for device */
if (devicename[0])
{
for (dev = first_dev; dev; dev = dev->next)
{
if (strcmp (dev->sane.name, devicename) == 0)
{
break;
}
}
if (!dev)
{
#if 0
status = attach (devicename, &dev, SANE_EPSON_);
if (status != SANE_STATUS_GOOD)
{
return status;
}
#endif
DBG (1, "Error opening the device");
return SANE_STATUS_INVAL;
}
}
else
{
dev = first_dev;
}
if (!dev)
{
return SANE_STATUS_INVAL;
}
s = calloc (sizeof (Epson_Scanner), 1);
if (!s)
{
DBG (1, "out of memory (line %d)\n", __LINE__);
return SANE_STATUS_NO_MEM;
}
s->fd = -1;
s->hw = dev;
init_options (s);
/* insert newly opened handle into list of open handles */
s->next = first_handle;
first_handle = s;
*handle = (SANE_Handle) s;
open_scanner (s);
return SANE_STATUS_GOOD;
}
/*
*
*
*/
void
sane_close (SANE_Handle handle)
{
Epson_Scanner *s, *prev;
/*
* Test if there is still data pending from
* the scanner. If so, then do a cancel
*/
s = (Epson_Scanner *) handle;
/* remove handle from list of open handles */
prev = 0;
for (s = first_handle; s; s = s->next)
{
if (s == handle)
break;
prev = s;
}
if (!s)
{
DBG (1, "close: invalid handle (0x%p)\n", handle);
return;
}
if (prev)
prev->next = s->next;
else
first_handle = s->next;
if (s->fd != -1)
close_scanner (s);
free (s);
}
/*
*
*
*/
const SANE_Option_Descriptor *
sane_get_option_descriptor (SANE_Handle handle, SANE_Int option)
{
Epson_Scanner *s = (Epson_Scanner *) handle;
if (option < 0 || option >= NUM_OPTIONS)
return NULL;
return (s->opt + option);
}
/*
*
*
*/
static const SANE_String_Const *
search_string_list (const SANE_String_Const * list, SANE_String value)
{
while (*list != NULL && strcmp (value, *list) != 0)
{
++list;
}
return ((*list == NULL) ? NULL : list);
}
/*
*
*
*/
/*
Activate, deactivate an option. Subroutines so we can add
debugging info if we want. The change flag is set to TRUE
if we changed an option. If we did not change an option,
then the value of the changed flag is not modified.
*/
static void
activateOption (Epson_Scanner * s, SANE_Int option, SANE_Bool * change)
{
if (!SANE_OPTION_IS_ACTIVE (s->opt[option].cap))
{
s->opt[option].cap &= ~SANE_CAP_INACTIVE;
*change = SANE_TRUE;
}
}
static void
deactivateOption (Epson_Scanner * s, SANE_Int option, SANE_Bool * change)
{
if (SANE_OPTION_IS_ACTIVE (s->opt[option].cap))
{
s->opt[option].cap |= SANE_CAP_INACTIVE;
*change = SANE_TRUE;
}
}
static void
setOptionState (Epson_Scanner * s, SANE_Bool state,
SANE_Int option, SANE_Bool * change)
{
if (state)
{
activateOption (s, option, change);
}
else
{
deactivateOption (s, option, change);
}
}
/**
End of activateOption, deactivateOption, setOptionState.
**/
static SANE_Status
getvalue (SANE_Handle handle, SANE_Int option, void *value)
{
Epson_Scanner *s = (Epson_Scanner *) handle;
SANE_Option_Descriptor *sopt = &(s->opt[option]);
Option_Value *sval = &(s->val[option]);
switch (option)
{
/* case OPT_GAMMA_VECTOR: */
case OPT_GAMMA_VECTOR_R:
case OPT_GAMMA_VECTOR_G:
case OPT_GAMMA_VECTOR_B:
memcpy (value, sval->wa, sopt->size);
break;
case OPT_NUM_OPTS:
case OPT_RESOLUTION:
case OPT_TL_X:
case OPT_TL_Y:
case OPT_BR_X:
case OPT_BR_Y:
case OPT_MIRROR:
case OPT_SPEED:
case OPT_PREVIEW_SPEED:
case OPT_AAS:
case OPT_PREVIEW:
case OPT_BRIGHTNESS:
case OPT_SHARPNESS:
case OPT_AUTO_EJECT:
case OPT_CCT_1:
case OPT_CCT_2:
case OPT_CCT_3:
case OPT_CCT_4:
case OPT_CCT_5:
case OPT_CCT_6:
case OPT_CCT_7:
case OPT_CCT_8:
case OPT_CCT_9:
case OPT_THRESHOLD:
case OPT_ZOOM:
case OPT_BIT_DEPTH:
case OPT_WAIT_FOR_BUTTON:
case OPT_LIMIT_RESOLUTION:
*((SANE_Word *) value) = sval->w;
break;
case OPT_MODE:
case OPT_ADF_MODE:
case OPT_HALFTONE:
case OPT_DROPOUT:
case OPT_QUICK_FORMAT:
case OPT_SOURCE:
case OPT_FILM_TYPE:
case OPT_GAMMA_CORRECTION:
case OPT_COLOR_CORRECTION:
case OPT_BAY:
case OPT_FOCUS:
strcpy ((char *) value, sopt->constraint.string_list[sval->w]);
break;
#if 0
case OPT_MODEL:
strcpy (value, sval->s);
break;
#endif
default:
return SANE_STATUS_INVAL;
}
return SANE_STATUS_GOOD;
}
/**
End of getvalue.
**/
static void
handle_depth_halftone (Epson_Scanner * s, SANE_Bool * reload)
/*
This routine handles common options between OPT_MODE and
OPT_HALFTONE. These options are TET (a HALFTONE mode), AAS
- auto area segmentation, and threshold. Apparently AAS
is some method to differentiate between text and photos.
Or something like that.
AAS is available when the scan color depth is 1 and the
halftone method is not TET.
Threshold is available when halftone is NONE, and depth is 1.
*/
{
int hti = s->val[OPT_HALFTONE].w;
int mdi = s->val[OPT_MODE].w;
SANE_Bool aas = SANE_FALSE;
SANE_Bool thresh = SANE_FALSE;
if (!s->hw->cmd->control_auto_area_segmentation)
return;
if (mode_params[mdi].depth == 1)
{
if (halftone_params[hti] != HALFTONE_TET)
{
aas = SANE_TRUE;
}
if (halftone_params[hti] == HALFTONE_NONE)
{
thresh = SANE_TRUE;
}
}
setOptionState (s, aas, OPT_AAS, reload);
setOptionState (s, thresh, OPT_THRESHOLD, reload);
}
/**
End of handle_depth_halftone.
**/
static void
handle_source (Epson_Scanner * s, SANE_Int optindex, char *value)
/*
Handles setting the source (flatbed, transparency adapter (TPU),
or auto document feeder (ADF)).
For newer scanners it also sets the focus according to the
glass / TPU settings.
*/
{
int force_max = SANE_FALSE;
SANE_Bool dummy;
/* reset the scanner when we are changing the source setting -
this is necessary for the Perfection 1650 */
if (s->hw->need_reset_on_source_change)
reset (s);
s->focusOnGlass = SANE_TRUE; /* this is the default */
if (s->val[OPT_SOURCE].w == optindex)
return;
s->val[OPT_SOURCE].w = optindex;
if (s->val[OPT_TL_X].w == s->hw->x_range->min
&& s->val[OPT_TL_Y].w == s->hw->y_range->min
&& s->val[OPT_BR_X].w == s->hw->x_range->max
&& s->val[OPT_BR_Y].w == s->hw->y_range->max)
{
force_max = SANE_TRUE;
}
if (strcmp (ADF_STR, value) == 0)
{
s->hw->x_range = &s->hw->adf_x_range;
s->hw->y_range = &s->hw->adf_y_range;
s->hw->use_extension = SANE_TRUE;
/* disable film type option */
deactivateOption (s, OPT_FILM_TYPE, &dummy);
s->val[OPT_FOCUS].w = 0;
if (s->hw->duplexSupport)
{
activateOption (s, OPT_ADF_MODE, &dummy);
}
else
{
deactivateOption (s, OPT_ADF_MODE, &dummy);
s->val[OPT_ADF_MODE].w = 0;
}
}
else if (strcmp (TPU_STR, value) == 0)
{
s->hw->x_range = &s->hw->tpu_x_range;
s->hw->y_range = &s->hw->tpu_y_range;
s->hw->use_extension = SANE_TRUE;
/* enable film type option only if the scanner supports it */
if (s->hw->cmd->set_film_type != 0)
{
activateOption (s, OPT_FILM_TYPE, &dummy);
}
else
{
deactivateOption (s, OPT_FILM_TYPE, &dummy);
}
/* enable focus position if the scanner supports it */
if (s->hw->cmd->set_focus_position != 0)
{
s->val[OPT_FOCUS].w = 1;
s->focusOnGlass = SANE_FALSE;
}
deactivateOption (s, OPT_ADF_MODE, &dummy);
deactivateOption (s, OPT_EJECT, &dummy);
deactivateOption (s, OPT_AUTO_EJECT, &dummy);
}
else /* neither ADF nor TPU active */
{
s->hw->x_range = &s->hw->fbf_x_range;
s->hw->y_range = &s->hw->fbf_y_range;
s->hw->use_extension = SANE_FALSE;
/* disable film type option */
deactivateOption (s, OPT_FILM_TYPE, &dummy);
s->val[OPT_FOCUS].w = 0;
deactivateOption (s, OPT_ADF_MODE, &dummy);
}
qf_params[XtNumber (qf_params) - 1].tl_x = s->hw->x_range->min;
qf_params[XtNumber (qf_params) - 1].tl_y = s->hw->y_range->min;
qf_params[XtNumber (qf_params) - 1].br_x = s->hw->x_range->max;
qf_params[XtNumber (qf_params) - 1].br_y = s->hw->y_range->max;
s->opt[OPT_BR_X].constraint.range = s->hw->x_range;
s->opt[OPT_BR_Y].constraint.range = s->hw->y_range;
if (s->val[OPT_TL_X].w < s->hw->x_range->min || force_max)
s->val[OPT_TL_X].w = s->hw->x_range->min;
if (s->val[OPT_TL_Y].w < s->hw->y_range->min || force_max)
s->val[OPT_TL_Y].w = s->hw->y_range->min;
if (s->val[OPT_BR_X].w > s->hw->x_range->max || force_max)
s->val[OPT_BR_X].w = s->hw->x_range->max;
if (s->val[OPT_BR_Y].w > s->hw->y_range->max || force_max)
s->val[OPT_BR_Y].w = s->hw->y_range->max;
setOptionState (s, s->hw->ADF && s->hw->use_extension,
OPT_AUTO_EJECT, &dummy);
setOptionState (s, s->hw->ADF && s->hw->use_extension, OPT_EJECT, &dummy);
#if 0
BAY is part of the filmscan device.We are not sure
if we are really going to support this device in this
code.Is there an online manual for it ?
setOptionState (s, s->hw->ADF && s->hw->use_extension, OPT_BAY, &reload);
#endif
}
/**
End of handle_source.
**/
static SANE_Status
setvalue (SANE_Handle handle, SANE_Int option, void *value, SANE_Int * info)
{
Epson_Scanner *s = (Epson_Scanner *) handle;
SANE_Option_Descriptor *sopt = &(s->opt[option]);
Option_Value *sval = &(s->val[option]);
SANE_Status status;
const SANE_String_Const *optval;
int optindex;
SANE_Bool reload = SANE_FALSE;
DBG (5, "setvalue(option = %d, value = %p)\n", option, value);
status = sanei_constrain_value (sopt, value, info);
if (status != SANE_STATUS_GOOD)
return status;
s->option_has_changed = SANE_TRUE;
optval = NULL;
optindex = 0;
if (sopt->constraint_type == SANE_CONSTRAINT_STRING_LIST)
{
optval = search_string_list (sopt->constraint.string_list,
(char *) value);
if (optval == NULL)
return SANE_STATUS_INVAL;
optindex = optval - sopt->constraint.string_list;
}
switch (option)
{
/* case OPT_GAMMA_VECTOR: */
case OPT_GAMMA_VECTOR_R:
case OPT_GAMMA_VECTOR_G:
case OPT_GAMMA_VECTOR_B:
memcpy (sval->wa, value, sopt->size); /* Word arrays */
break;
case OPT_CCT_1:
case OPT_CCT_2:
case OPT_CCT_3:
case OPT_CCT_4:
case OPT_CCT_5:
case OPT_CCT_6:
case OPT_CCT_7:
case OPT_CCT_8:
case OPT_CCT_9:
sval->w = *((SANE_Word *) value); /* Simple values */
break;
case OPT_DROPOUT:
case OPT_FILM_TYPE:
case OPT_BAY:
case OPT_FOCUS:
sval->w = optindex; /* Simple lists */
break;
case OPT_EJECT:
/* return eject( s ); */
eject (s);
break;
case OPT_RESOLUTION:
sval->w = *((SANE_Word *) value);
reload = SANE_TRUE;
break;
case OPT_TL_X:
case OPT_TL_Y:
case OPT_BR_X:
case OPT_BR_Y:
sval->w = *((SANE_Word *) value);
DBG (1, "set = %f\n", SANE_UNFIX (sval->w));
if (NULL != info)
*info |= SANE_INFO_RELOAD_PARAMS;
break;
case OPT_SOURCE:
handle_source (s, optindex, (char *) value);
reload = SANE_TRUE;
break;
case OPT_MODE:
{
SANE_Bool isColor = mode_params[optindex].color;
SANE_Bool userDefined =
color_userdefined[s->val[OPT_COLOR_CORRECTION].w];
sval->w = optindex;
if (s->hw->cmd->set_halftoning != 0)
{
setOptionState (s, mode_params[optindex].depth == 1,
OPT_HALFTONE, &reload);
}
setOptionState (s, !isColor, OPT_DROPOUT, &reload);
if (s->hw->cmd->set_color_correction)
{
setOptionState (s, isColor, OPT_COLOR_CORRECTION, &reload);
}
if (s->hw->cmd->set_color_correction_coefficients)
{
setOptionState (s, isColor && userDefined, OPT_CCT_1, &reload);
setOptionState (s, isColor && userDefined, OPT_CCT_2, &reload);
setOptionState (s, isColor && userDefined, OPT_CCT_3, &reload);
setOptionState (s, isColor && userDefined, OPT_CCT_4, &reload);
setOptionState (s, isColor && userDefined, OPT_CCT_5, &reload);
setOptionState (s, isColor && userDefined, OPT_CCT_6, &reload);
setOptionState (s, isColor && userDefined, OPT_CCT_7, &reload);
setOptionState (s, isColor && userDefined, OPT_CCT_8, &reload);
setOptionState (s, isColor && userDefined, OPT_CCT_9, &reload);
}
/* if binary, then disable the bit depth selection */
if (optindex == 0)
{
s->opt[OPT_BIT_DEPTH].cap |= SANE_CAP_INACTIVE;
}
else
{
if (bitDepthList[0] == 1)
s->opt[OPT_BIT_DEPTH].cap |= SANE_CAP_INACTIVE;
else
{
s->opt[OPT_BIT_DEPTH].cap &= ~SANE_CAP_INACTIVE;
s->val[OPT_BIT_DEPTH].w = mode_params[optindex].depth;
}
}
handle_depth_halftone (s, &reload);
reload = SANE_TRUE;
break;
}
case OPT_ADF_MODE:
sval->w = optindex;
break;
case OPT_BIT_DEPTH:
sval->w = *((SANE_Word *) value);
mode_params[s->val[OPT_MODE].w].depth = sval->w;
reload = SANE_TRUE;
break;
case OPT_HALFTONE:
sval->w = optindex;
handle_depth_halftone (s, &reload);
break;
case OPT_COLOR_CORRECTION:
{
SANE_Bool f = color_userdefined[optindex];
sval->w = optindex;
setOptionState (s, f, OPT_CCT_1, &reload);
setOptionState (s, f, OPT_CCT_2, &reload);
setOptionState (s, f, OPT_CCT_3, &reload);
setOptionState (s, f, OPT_CCT_4, &reload);
setOptionState (s, f, OPT_CCT_5, &reload);
setOptionState (s, f, OPT_CCT_6, &reload);
setOptionState (s, f, OPT_CCT_7, &reload);
setOptionState (s, f, OPT_CCT_8, &reload);
setOptionState (s, f, OPT_CCT_9, &reload);
break;
}
case OPT_GAMMA_CORRECTION:
{
SANE_Bool f = gamma_userdefined[optindex];
sval->w = optindex;
/* setOptionState(s, f, OPT_GAMMA_VECTOR, &reload ); */
setOptionState (s, f, OPT_GAMMA_VECTOR_R, &reload);
setOptionState (s, f, OPT_GAMMA_VECTOR_G, &reload);
setOptionState (s, f, OPT_GAMMA_VECTOR_B, &reload);
setOptionState (s, !f, OPT_BRIGHTNESS, &reload); /* Note... */
break;
}
case OPT_MIRROR:
case OPT_SPEED:
case OPT_PREVIEW_SPEED:
case OPT_AAS:
case OPT_PREVIEW: /* needed? */
case OPT_BRIGHTNESS:
case OPT_SHARPNESS:
case OPT_AUTO_EJECT:
case OPT_THRESHOLD:
case OPT_ZOOM:
case OPT_WAIT_FOR_BUTTON:
sval->w = *((SANE_Word *) value);
break;
case OPT_LIMIT_RESOLUTION:
sval->w = *((SANE_Word *) value);
filter_resolution_list (s);
reload = SANE_TRUE;
break;
case OPT_QUICK_FORMAT:
sval->w = optindex;
s->val[OPT_TL_X].w = qf_params[sval->w].tl_x;
s->val[OPT_TL_Y].w = qf_params[sval->w].tl_y;
s->val[OPT_BR_X].w = qf_params[sval->w].br_x;
s->val[OPT_BR_Y].w = qf_params[sval->w].br_y;
if (s->val[OPT_TL_X].w < s->hw->x_range->min)
s->val[OPT_TL_X].w = s->hw->x_range->min;
if (s->val[OPT_TL_Y].w < s->hw->y_range->min)
s->val[OPT_TL_Y].w = s->hw->y_range->min;
if (s->val[OPT_BR_X].w > s->hw->x_range->max)
s->val[OPT_BR_X].w = s->hw->x_range->max;
if (s->val[OPT_BR_Y].w > s->hw->y_range->max)
s->val[OPT_BR_Y].w = s->hw->y_range->max;
reload = SANE_TRUE;
break;
default:
return SANE_STATUS_INVAL;
}
if (reload && info != NULL)
{
*info |= SANE_INFO_RELOAD_OPTIONS | SANE_INFO_RELOAD_PARAMS;
}
return SANE_STATUS_GOOD;
}
/**
End of setvalue.
**/
SANE_Status
sane_control_option (SANE_Handle handle,
SANE_Int option,
SANE_Action action, void *value, SANE_Int * info)
{
if (option < 0 || option >= NUM_OPTIONS)
return SANE_STATUS_INVAL;
if (info != NULL)
*info = 0;
switch (action)
{
case SANE_ACTION_GET_VALUE:
return (getvalue (handle, option, value));
case SANE_ACTION_SET_VALUE:
return (setvalue (handle, option, value, info));
default:
return SANE_STATUS_INVAL;
}
return SANE_STATUS_GOOD;
}
/*
* sane_get_parameters()
*
* This function is part of the SANE API and gets called when the front end
* requests information aobut the scan configuration (e.g. color depth, mode,
* bytes and pixels per line, number of lines. This information is returned
* in the SANE_Parameters structure.
*
* Once a scan was started, this routine has to report the correct values, if
* it is called before the scan is actually started, the values are based on
* the current settings.
*
*/
SANE_Status
sane_get_parameters (SANE_Handle handle, SANE_Parameters * params)
{
Epson_Scanner *s = (Epson_Scanner *) handle;
int ndpi;
int bytes_per_pixel;
DBG (5, "sane_get_parameters()\n");
/*
* If sane_start was already called, then just retrieve the parameters
* from the scanner data structure
*/
if (!s->eof && s->ptr != NULL)
{
DBG (5, "Returning saved params structure\n");
if (params != NULL)
{
DBG(1, "Restoring parameters from saved parameters\n");
*params = s->params;
}
DBG (3, "Preview = %d\n", s->val[OPT_PREVIEW].w);
DBG (3, "Resolution = %d\n", s->val[OPT_RESOLUTION].w);
DBG (1, "get para %p %p tlx %f tly %f brx %f bry %f [mm]\n", (void *) s,
(void *) s->val, SANE_UNFIX (s->val[OPT_TL_X].w),
SANE_UNFIX (s->val[OPT_TL_Y].w), SANE_UNFIX (s->val[OPT_BR_X].w),
SANE_UNFIX (s->val[OPT_BR_Y].w));
print_params (s->params);
return SANE_STATUS_GOOD;
}
/* otherwise initialize the params structure and gather the data */
memset (&s->params, 0, sizeof (SANE_Parameters));
ndpi = s->val[OPT_RESOLUTION].w;
s->params.pixels_per_line =
SANE_UNFIX (s->val[OPT_BR_X].w - s->val[OPT_TL_X].w) / 25.4 * ndpi + 0.5;
s->params.lines =
SANE_UNFIX (s->val[OPT_BR_Y].w - s->val[OPT_TL_Y].w) / 25.4 * ndpi + 0.5;
/*
* Make sure that the number of lines is correct for color shuffling:
* The shuffling algorithm produces 2xline_distance lines at the
* beginning and the same amount at the end of the scan that are not
* useable. If s->params.lines gets negative, 0 lines are reported
* back to the frontend.
*/
if (s->hw->color_shuffle)
{
s->params.lines -= 4 * s->line_distance;
if (s->params.lines < 0)
{
s->params.lines = 0;
}
DBG (1, "Adjusted params.lines for color_shuffle by %d to %d\n",
4 * s->line_distance, s->params.lines);
}
DBG (3, "Preview = %d\n", s->val[OPT_PREVIEW].w);
DBG (3, "Resolution = %d\n", s->val[OPT_RESOLUTION].w);
DBG (1, "get para %p %p tlx %f tly %f brx %f bry %f [mm]\n", (void *) s,
(void *) s->val, SANE_UNFIX (s->val[OPT_TL_X].w),
SANE_UNFIX (s->val[OPT_TL_Y].w), SANE_UNFIX (s->val[OPT_BR_X].w),
SANE_UNFIX (s->val[OPT_BR_Y].w));
/*
* Calculate bytes_per_pixel and bytes_per_line for
* any color depths.
*
* The default color depth is stored in mode_params.depth:
*/
if (mode_params[s->val[OPT_MODE].w].depth == 1)
{
s->params.depth = 1;
}
else
{
s->params.depth = s->val[OPT_BIT_DEPTH].w;
}
if (s->params.depth > 8)
{
s->params.depth = 16; /*
* The frontends can only handle 8 or 16 bits
* for gray or color - so if it's more than 8,
* it gets automatically set to 16. This works
* as long as EPSON does not come out with a
* scanner that can handle more than 16 bits
* per color channel.
*/
}
bytes_per_pixel = s->params.depth / 8; /* this works because it can only be set to 1, 8 or 16 */
if (s->params.depth % 8) /* just in case ... */
{
bytes_per_pixel++;
}
/* pixels_per_line is rounded to the next 8bit boundary */
s->params.pixels_per_line = s->params.pixels_per_line & ~7;
s->params.last_frame = SANE_TRUE;
if (mode_params[s->val[OPT_MODE].w].color)
{
s->params.format = SANE_FRAME_RGB;
s->params.bytes_per_line =
3 * s->params.pixels_per_line * bytes_per_pixel;
}
else
{
s->params.format = SANE_FRAME_GRAY;
s->params.bytes_per_line =
s->params.pixels_per_line * s->params.depth / 8;
}
if (NULL != params)
*params = s->params;
print_params (s->params);
return SANE_STATUS_GOOD;
}
/*
* sane_start()
*
* This function is part of the SANE API and gets called from the front end to
* start the scan process.
*
*/
SANE_Status
sane_start (SANE_Handle handle)
{
Epson_Scanner *s = (Epson_Scanner *) handle;
SANE_Status status;
SANE_Bool button_status;
const struct mode_param *mparam;
u_char params[4];
int ndpi;
int left, top;
int lcount;
int i, j; /* loop counter */
DBG (5, "sane_start()\n");
open_scanner (s);
/*
* There is some undocumented special behavior with the TPU enable/disable.
* TPU power ESC e status
* on 0 NAK
* on 1 ACK
* off 0 ACK
* off 1 NAK
*
* It makes no sense to scan with TPU powered on and source flatbed, because
* light will come from both sides.
*/
if (s->hw->extension)
{
int max_x, max_y;
int extensionCtrl;
extensionCtrl = (s->hw->use_extension ? 1 : 0);
if (s->hw->use_extension && (s->val[OPT_ADF_MODE].w == 1))
extensionCtrl = 2;
status = control_extension (s, extensionCtrl);
if (SANE_STATUS_GOOD != status)
{
DBG (1, "You may have to power %s your TPU\n",
s->hw->use_extension ? "on" : "off");
DBG (1, "Also you may have to restart the Sane frontend.\n");
close_scanner (s);
return status;
}
if (s->hw->cmd->request_extended_status != 0)
{
status = check_ext_status (s, &max_x, &max_y);
if (SANE_STATUS_GOOD != status && SANE_STATUS_DEVICE_BUSY != status)
{
close_scanner (s);
return status;
}
}
if (s->hw->ADF && s->hw->use_extension && s->hw->cmd->feed)
{
status = feed (s);
if (SANE_STATUS_GOOD != status)
{
close_scanner (s);
return status;
}
check_ext_status (s, &max_x, &max_y);
s->hw->adf_max_x = max_x;
s->hw->adf_max_y = max_y;
}
/*
* set the focus position according to the extension used:
* if the TPU is selected, then focus 2.5mm above the glass,
* otherwise focus on the glass. Scanners that don't support
* this feature, will just ignore these calls.
*/
if (s->hw->focusSupport == SANE_TRUE)
{
if (s->val[OPT_FOCUS].w == 0)
{
DBG (1, "Setting focus to glass surface\n");
set_focus_position (s, 0x40);
}
else
{
DBG (1, "Setting focus to 2.5mm above glass\n");
set_focus_position (s, 0x59);
}
}
}
/* use the flatbed size for the max. scansize for the GT-30000
and similar scanners if the ADF is not enabled */
if (s->hw->devtype == 3 && s->hw->use_extension == 0)
{
int max_x, max_y;
status = check_ext_status (s, &max_x, &max_y);
if (SANE_STATUS_GOOD != status && SANE_STATUS_DEVICE_BUSY != status)
{
close_scanner (s);
return status;
}
s->hw->fbf_max_x = max_x;
s->hw->fbf_max_y = max_y;
}
mparam = mode_params + s->val[OPT_MODE].w;
DBG (1, "sane_start: Setting data format to %d bits\n", mparam->depth);
status = set_data_format (s, mparam->depth);
if (SANE_STATUS_GOOD != status)
{
DBG (1, "sane_start: set_data_format failed: %s\n",
sane_strstatus (status));
return status;
}
/*
* The byte sequence mode was introduced in B5, for B[34] we need line sequence mode
*/
if ((s->hw->cmd->level[0] == 'D' ||
(s->hw->cmd->level[0] == 'B' && s->hw->level >= 5)) &&
mparam->mode_flags == 0x02)
{
status = set_color_mode (s, 0x13);
}
else
{
status = set_color_mode (s, mparam->mode_flags | (mparam->dropout_mask
& dropout_params[s->
val
[OPT_DROPOUT].
w]));
}
if (SANE_STATUS_GOOD != status)
{
DBG (1, "sane_start: set_color_mode failed: %s\n",
sane_strstatus (status));
return status;
}
if (s->hw->cmd->set_halftoning &&
SANE_OPTION_IS_ACTIVE (s->opt[OPT_HALFTONE].cap))
{
status = set_halftoning (s, halftone_params[s->val[OPT_HALFTONE].w]);
if (SANE_STATUS_GOOD != status)
{
DBG (1, "sane_start: set_halftoning failed: %s\n",
sane_strstatus (status));
return status;
}
}
if (SANE_OPTION_IS_ACTIVE (s->opt[OPT_BRIGHTNESS].cap))
{
status = set_bright (s, s->val[OPT_BRIGHTNESS].w);
if (SANE_STATUS_GOOD != status)
{
DBG (1, "sane_start: set_bright failed: %s\n", sane_strstatus (status));
return status;
}
}
if (SANE_OPTION_IS_ACTIVE (s->opt[OPT_MIRROR].cap))
{
status = mirror_image (s, mirror_params[s->val[OPT_MIRROR].w]);
if (SANE_STATUS_GOOD != status)
{
DBG (1, "sane_start: mirror_image failed: %s\n",
sane_strstatus (status));
return status;
}
}
if (SANE_OPTION_IS_ACTIVE (s->opt[OPT_SPEED].cap))
{
if (s->val[OPT_PREVIEW].w)
status = set_speed (s, speed_params[s->val[OPT_PREVIEW_SPEED].w]);
else
status = set_speed (s, speed_params[s->val[OPT_SPEED].w]);
if (SANE_STATUS_GOOD != status)
{
DBG (1, "sane_start: set_speed failed: %s\n", sane_strstatus (status));
return status;
}
}
/*
* use of speed_params is ok here since they are false and true.
* NOTE: I think I should throw that "params" stuff as long w is already the value.
*/
if (SANE_OPTION_IS_ACTIVE (s->opt[OPT_AAS].cap))
{
status = control_auto_area_segmentation (s,
speed_params[s->val[OPT_AAS].w]);
if (SANE_STATUS_GOOD != status)
{
DBG (1, "sane_start: control_auto_area_segmentation failed: %s\n",
sane_strstatus (status));
return status;
}
}
s->invert_image = SANE_FALSE; /* default: to not inverting the image */
if (SANE_OPTION_IS_ACTIVE (s->opt[OPT_FILM_TYPE].cap))
{
s->invert_image = (s->val[OPT_FILM_TYPE].w == FILM_TYPE_NEGATIVE);
status = set_film_type (s, film_params[s->val[OPT_FILM_TYPE].w]);
if (SANE_STATUS_GOOD != status)
{
DBG (1, "sane_start: set_film_type failed: %s\n",
sane_strstatus (status));
return status;
}
}
if (SANE_OPTION_IS_ACTIVE (s->opt[OPT_BAY].cap))
{
status = set_bay (s, s->val[OPT_BAY].w);
if (SANE_STATUS_GOOD != status)
{
DBG (1, "sane_start: set_bay: %s\n", sane_strstatus (status));
return status;
}
}
if (SANE_OPTION_IS_ACTIVE (s->opt[OPT_SHARPNESS].cap))
{
status = set_outline_emphasis (s, s->val[OPT_SHARPNESS].w);
if (SANE_STATUS_GOOD != status)
{
DBG (1, "sane_start: set_outline_emphasis failed: %s\n",
sane_strstatus (status));
return status;
}
}
if (s->hw->cmd->set_gamma &&
SANE_OPTION_IS_ACTIVE (s->opt[OPT_GAMMA_CORRECTION].cap))
{
int val;
if (s->hw->cmd->level[0] == 'D')
{
/*
* The D1 level has only the two user defined gamma
* settings.
*/
val = gamma_params[s->val[OPT_GAMMA_CORRECTION].w];
}
else
{
val = gamma_params[s->val[OPT_GAMMA_CORRECTION].w];
/*
* If "Default" is selected then determine the actual value
* to send to the scanner: If bilevel mode, just send the
* value from the table (0x01), for grayscale or color mode
* add one and send 0x02.
*/
/* if( s->val[ OPT_GAMMA_CORRECTION].w <= 1) { */
if (s->val[OPT_GAMMA_CORRECTION].w == 0)
{
val += mparam->depth == 1 ? 0 : 1;
}
}
DBG (1, "sane_start: set_gamma( s, 0x%x ).\n", val);
status = set_gamma (s, val);
if (SANE_STATUS_GOOD != status)
{
DBG (1, "sane_start: set_gamma failed: %s\n", sane_strstatus (status));
return status;
}
}
if (s->hw->cmd->set_gamma_table &&
gamma_userdefined[s->val[OPT_GAMMA_CORRECTION].w])
{ /* user defined. */
status = set_gamma_table (s);
if (SANE_STATUS_GOOD != status)
{
DBG (1, "sane_start: set_gamma_table failed: %s\n",
sane_strstatus (status));
return status;
}
}
/*
* TODO: think about if SANE_OPTION_IS_ACTIVE is a good criteria to send commands.
*/
if (SANE_OPTION_IS_ACTIVE (s->opt[OPT_COLOR_CORRECTION].cap))
{
int val = color_params[s->val[OPT_COLOR_CORRECTION].w];
DBG (1, "sane_start: set_color_correction( s, 0x%x )\n", val);
status = set_color_correction (s, val);
if (SANE_STATUS_GOOD != status)
{
DBG (1, "sane_start: set_color_correction failed: %s\n",
sane_strstatus (status));
return status;
}
}
if (1 == s->val[OPT_COLOR_CORRECTION].w)
{ /* user defined. */
status = set_color_correction_coefficients (s);
if (SANE_STATUS_GOOD != status)
{
DBG (1, "sane_start: set_color_correction_coefficients failed: %s\n",
sane_strstatus (status));
return status;
}
}
if (s->hw->cmd->set_threshold != 0
&& SANE_OPTION_IS_ACTIVE (s->opt[OPT_THRESHOLD].cap))
{
status = set_threshold (s, s->val[OPT_THRESHOLD].w);
if (SANE_STATUS_GOOD != status)
{
DBG (1, "sane_start: set_threshold(%d) failed: %s\n",
s->val[OPT_THRESHOLD].w, sane_strstatus (status));
return status;
}
}
ndpi = s->val[OPT_RESOLUTION].w;
status = set_resolution (s, ndpi, ndpi);
if (SANE_STATUS_GOOD != status)
{
DBG (1, "sane_start: set_resolution(%d, %d) failed: %s\n",
ndpi, ndpi, sane_strstatus (status));
return status;
}
status = sane_get_parameters (handle, NULL);
if (status != SANE_STATUS_GOOD)
return status;
/* set the zoom */
if (s->hw->cmd->set_zoom != 0
&& SANE_OPTION_IS_ACTIVE (s->opt[OPT_ZOOM].cap))
{
status = set_zoom (s, s->val[OPT_ZOOM].w, s->val[OPT_ZOOM].w);
if (status != SANE_STATUS_GOOD)
{
DBG (1, "sane_start: set_zoom(%d) failed: %s\n",
s->val[OPT_ZOOM].w, sane_strstatus (status));
return status;
}
}
/*
* Now s->params is initialized.
*/
/*
* If WAIT_FOR_BUTTON is active, then do just that: Wait until the button is
* pressed. If the button was already pressed, then we will get the button
* Pressed event right away.
*/
if (s->val[OPT_WAIT_FOR_BUTTON].w == SANE_TRUE)
{
s->hw->wait_for_button = SANE_TRUE;
while (s->hw->wait_for_button == SANE_TRUE)
{
if (s->canceling == SANE_TRUE)
{
s->hw->wait_for_button = SANE_FALSE;
}
/* get the button status from the scanner */
else if (request_push_button_status (s, &button_status) ==
SANE_STATUS_GOOD)
{
if (button_status == SANE_TRUE)
{
s->hw->wait_for_button = SANE_FALSE;
}
else
{
sleep (1);
}
}
else
{
/* we ran into an error condition, just continue */
s->hw->wait_for_button = SANE_FALSE;
}
}
}
/*
* in file:frontend/preview.c
*
* The preview strategy is as follows:
*
* 1) A preview always acquires an image that covers the entire
* scan surface. This is necessary so the user can see not
* only what is, but also what isn't selected.
*/
left = SANE_UNFIX (s->val[OPT_TL_X].w) / 25.4 * ndpi + 0.5;
top = SANE_UNFIX (s->val[OPT_TL_Y].w) / 25.4 * ndpi + 0.5;
/*
* Calculate correction for line_distance in D1 scanner:
* Start line_distance lines earlier and add line_distance lines at the end
*
* Because the actual line_distance is not yet calculated we have to do this
* first.
*/
s->hw->color_shuffle = SANE_FALSE;
s->current_output_line = 0;
s->lines_written = 0;
s->color_shuffle_line = 0;
if ((s->hw->optical_res != 0) && (mparam->depth == 8)
&& (mparam->mode_flags != 0))
{
s->line_distance = s->hw->max_line_distance * ndpi / s->hw->optical_res;
if (s->line_distance != 0)
{
s->hw->color_shuffle = SANE_TRUE;
}
else
s->hw->color_shuffle = SANE_FALSE;
}
/*
* for debugging purposes:
*/
#ifdef FORCE_COLOR_SHUFFLE
DBG (1, "Test mode: FORCE_COLOR_SHUFFLE = TRUE\n");
s->hw->color_shuffle = SANE_TRUE;
#endif
/*
* Modify the scan area: If the scanner requires color shuffling, then we try to
* scan more lines to compensate for the lines that will be removed from the scan
* due to the color shuffling algorithm.
* At this time we add two times the line distance to the number of scan lines if
* this is possible - if not, then we try to calculate the number of additional
* lines according to the selected scan area.
*/
if (s->hw->color_shuffle == SANE_TRUE)
{
/* start the scan 2*line_distance earlier */
top -= 2 * s->line_distance;
if (top < 0)
{
top = 0;
}
/* scan 4*line_distance lines more */
s->params.lines += 4 * s->line_distance;
}
/*
* If (top + s->params.lines) is larger than the max scan area, reset
* the number of scan lines:
*/
if (SANE_UNFIX (s->val[OPT_BR_Y].w) / 25.4 * ndpi < (s->params.lines + top))
{
s->params.lines = ((int) SANE_UNFIX (s->val[OPT_BR_Y].w) /
25.4 * ndpi + 0.5) - top;
}
status =
set_scan_area (s, left, top, s->params.pixels_per_line, s->params.lines);
if (SANE_STATUS_GOOD != status)
{
DBG (1, "sane_start: set_scan_area failed: %s\n",
sane_strstatus (status));
return status;
}
s->block = SANE_FALSE;
lcount = 1;
/*
* The set line count commands needs to be sent for certain scanners in
* color mode. The D1 level requires it, we are however only testing for
* 'D' and not for the actual numeric level.
*/
if (((s->hw->cmd->level[0] == 'B') &&
((s->hw->level >= 5) || ((s->hw->level >= 4) &&
(!mode_params[s->val[OPT_MODE].w].color))))
|| (s->hw->cmd->level[0] == 'D'))
{
s->block = SANE_TRUE;
lcount = sanei_scsi_max_request_size / s->params.bytes_per_line;
if (lcount >= 255)
{
lcount = 255;
}
if (s->hw->TPU && s->hw->use_extension && lcount > 32)
{
lcount = 32;
}
/*
* The D1 series of scanners only allow an even line number
* for bi-level scanning. If a bit depth of 1 is selected, then
* make sure the next lower even number is selected.
*/
if (s->hw->cmd->level[0] == 'D')
{
if (lcount % 2)
{
lcount -= 1;
}
}
if (lcount == 0)
{
DBG (1, "out of memory (line %d)\n", __LINE__);
return SANE_STATUS_NO_MEM;
}
status = set_lcount (s, lcount);
if (SANE_STATUS_GOOD != status)
{
DBG (1, "sane_start: set_lcount(%d) failed: %s\n",
lcount, sane_strstatus (status));
return status;
}
}
if (s->hw->cmd->request_extended_status != 0
&& SANE_TRUE == s->hw->extension)
{
u_char result[4];
u_char *buf;
size_t len;
params[0] = ESC;
params[1] = s->hw->cmd->request_extended_status;
scanner_send (s, params, 2, &status); /* send ESC f (request extended status) */
if (SANE_STATUS_GOOD == status)
{
len = 4; /* receive header */
scanner_receive (s, result, len, &status);
if (SANE_STATUS_GOOD != status)
return status;
len = result[3] << 8 | result[2];
buf = alloca (len);
scanner_receive (s, buf, len, &status); /* receive actual status data */
if (buf[0] & 0x80)
{
close_scanner (s);
return SANE_STATUS_INVAL;
}
}
else
{
DBG (1, "Extended status flag request failed\n");
}
}
/*
* for debug purpose
* check scanner conditions
*/
#if 1
if (s->hw->cmd->request_condition != 0)
{
u_char result[4];
u_char *buf;
size_t len;
params[0] = ESC;
params[1] = s->hw->cmd->request_condition;
scanner_send (s, params, 2, &status); /* send request condition */
if (SANE_STATUS_GOOD != status)
return status;
len = 4;
scanner_receive (s, result, len, &status);
if (SANE_STATUS_GOOD != status)
return status;
len = result[3] << 8 | result[2];
buf = alloca (len);
scanner_receive (s, buf, len, &status);
if (SANE_STATUS_GOOD != status)
return status;
#if 0
DBG (10, "SANE_START: length=%d\n", len);
for (i = 1; i <= len; i++)
{
DBG (10, "SANE_START: %d: %c\n", i, buf[i - 1]);
}
#endif
DBG (5, "SANE_START: Color: %d\n", (int) buf[1]);
DBG (5, "SANE_START: Resolution (x, y): (%d, %d)\n",
(int) (buf[4] << 8 | buf[3]), (int) (buf[6] << 8 | buf[5]));
DBG (5,
"SANE_START: Scan area(pixels) (x0, y0), (x1, y1): (%d, %d), (%d, %d)\n",
(int) (buf[9] << 8 | buf[8]), (int) (buf[11] << 8 | buf[10]),
(int) (buf[13] << 8 | buf[12]), (int) (buf[15] << 8 | buf[14]));
DBG (5, "SANE_START: Data format: %d\n", (int) buf[17]);
DBG (5, "SANE_START: Halftone: %d\n", (int) buf[19]);
DBG (5, "SANE_START: Brightness: %d\n", (int) buf[21]);
DBG (5, "SANE_START: Gamma: %d\n", (int) buf[23]);
DBG (5, "SANE_START: Zoom (x, y): (%d, %d)\n", (int) buf[26],
(int) buf[25]);
DBG (5, "SANE_START: Color correction: %d\n", (int) buf[28]);
DBG (5, "SANE_START: Sharpness control: %d\n", (int) buf[30]);
DBG (5, "SANE_START: Scanning mode: %d\n", (int) buf[32]);
DBG (5, "SANE_START: Mirroring: %d\n", (int) buf[34]);
DBG (5, "SANE_START: Auto area segmentation: %d\n", (int) buf[36]);
DBG (5, "SANE_START: Threshold: %d\n", (int) buf[38]);
DBG (5, "SANE_START: Line counter: %d\n", (int) buf[40]);
DBG (5, "SANE_START: Option unit control: %d\n", (int) buf[42]);
DBG (5, "SANE_START: Film type: %d\n", (int) buf[44]);
}
#endif
/* set the retry count to 0 */
s->retry_count = 0;
if (s->hw->color_shuffle == SANE_TRUE)
{
/* initialize the line buffers */
for (i = 0; i < s->line_distance * 2 + 1; i++)
{
if (s->line_buffer[i] != NULL)
free (s->line_buffer[i]);
s->line_buffer[i] = malloc (s->params.bytes_per_line);
if (s->line_buffer[i] == NULL)
{
/* free the memory we've malloced so far */
for (j = 0; j < i; j++)
{
free (s->line_buffer[j]);
s->line_buffer[j] = NULL;
}
DBG (1, "out of memory (line %d)\n", __LINE__);
return SANE_STATUS_NO_MEM;
}
}
}
params[0] = ESC;
params[1] = s->hw->cmd->start_scanning;
scanner_send (s, params, 2, &status);
if (SANE_STATUS_GOOD != status)
{
DBG (1, "sane_start: start failed: %s\n", sane_strstatus (status));
return status;
}
s->eof = SANE_FALSE;
s->buf = realloc (s->buf, lcount * s->params.bytes_per_line);
s->ptr = s->end = s->buf;
s->canceling = SANE_FALSE;
return SANE_STATUS_GOOD;
} /* sane_start */
/*
*
* TODO: clean up the eject and direct cmd mess.
*/
SANE_Status
sane_auto_eject (Epson_Scanner * s)
{
DBG (5, "sane_auto_eject()\n");
if (s->hw->ADF && s->hw->use_extension && s->val[OPT_AUTO_EJECT].w)
{ /* sequence! */
SANE_Status status;
u_char params[1];
u_char cmd = s->hw->cmd->eject;
if (!cmd)
return SANE_STATUS_UNSUPPORTED;
params[0] = cmd;
scanner_send (s, params, 1, &status);
if (SANE_STATUS_GOOD != (status = expect_ack (s)))
{
return status;
}
}
return SANE_STATUS_GOOD;
}
/*
*
*
*/
static SANE_Status
read_data_block (Epson_Scanner * s, EpsonDataRec * result)
{
SANE_Status status;
u_char param[3];
scanner_receive (s, result, s->block ? 6 : 4, &status);
if (SANE_STATUS_GOOD != status)
return status;
if (STX != result->code)
{
DBG (1, "code %02x\n", (int) result->code);
DBG (1, "error, expected STX\n");
return SANE_STATUS_INVAL;
}
if (result->status & STATUS_FER)
{
int dummy_x, dummy_y;
DBG (1, "fatal error - Status = %02x\n", result->status);
status = check_ext_status (s, &dummy_x, &dummy_y);
/*
* Hack Alert!!!
* If the status is SANE_STATUS_DEVICE_BUSY then we need to
* re-issue the command again. We can assume that the command that
* caused this problem was ESC G, so in a loop with a sleep 1 we
* are testing this over and over and over again, until the lamp
* "thinks" it is ready.
*
* TODO: Store the last command and execute what was actually used
* as the last command. For all situations this error may occur
* ESC G is very very likely to be the command in question, but
* we better make sure that this is the case.
*
*/
/*
* let's safe some stack space: If this is not the first go around,
* then just return the status and let the loop handle this - otherwise
* we would run this function recursively.
*/
if ((status == SANE_STATUS_DEVICE_BUSY && s->retry_count > 0) ||
(status == SANE_STATUS_GOOD && s->retry_count > 0))
{
return SANE_STATUS_DEVICE_BUSY; /* return busy even if we just read OK
so that the following loop can end
gracefully */
}
while (status == SANE_STATUS_DEVICE_BUSY)
{
if (s->retry_count > SANE_EPSON_MAX_RETRIES)
{
DBG (1, "Max retry count exceeded (%d)\n", s->retry_count);
return SANE_STATUS_INVAL;
}
sleep (1); /* wait one second for the next attempt */
DBG (1, "retrying ESC G - %d\n", ++(s->retry_count));
param[0] = ESC;
param[1] = s->hw->cmd->start_scanning;
scanner_send (s, param, 2, &status);
if (SANE_STATUS_GOOD != status)
{
DBG (1, "read_data_block: start failed: %s\n",
sane_strstatus (status));
return status;
}
status = read_data_block (s, result);
}
}
return status;
}
/*
*
*
*/
void
scan_finish (Epson_Scanner * s)
{
SANE_Status status;
int i, x, y;
DBG (5, "scan_finish()\n");
free (s->buf);
s->buf = NULL;
status = check_ext_status (s, &x, &y);
if (SANE_STATUS_NO_DOCS == status && s->hw->ADF && s->hw->use_extension)
sane_auto_eject (s);
for (i = 0; i < s->line_distance; i++)
{
if (s->line_buffer[i] != NULL)
{
free (s->line_buffer[i]);
s->line_buffer[i] = NULL;
}
}
}
#define GET_COLOR(x) ((x.status>>2) & 0x03)
SANE_Status
sane_read (SANE_Handle handle, SANE_Byte * data, SANE_Int max_length,
SANE_Int * length)
{
Epson_Scanner *s = (Epson_Scanner *) handle;
SANE_Status status;
int index = 0;
SANE_Bool reorder = SANE_FALSE;
SANE_Bool needStrangeReorder = SANE_FALSE;
START_READ:
DBG (5, "sane_read: begin\n");
if (s->ptr == s->end)
{
EpsonDataRec result;
size_t buf_len;
if ((s->fd != -1) && s->eof)
{
if (s->hw->color_shuffle)
{
DBG (1, "Written %d lines after color shuffle\n", s->lines_written);
DBG (1, "Lines requested: %d\n", s->params.lines);
}
*length = 0;
scan_finish (s);
return SANE_STATUS_EOF;
}
DBG (5, "sane_read: begin scan1\n");
if (SANE_STATUS_GOOD != (status = read_data_block (s, &result)))
{
*length = 0;
scan_finish (s);
return status;
}
buf_len = result.buf[1] << 8 | result.buf[0];
DBG (5, "sane_read: buf len = %lu\n", (u_long) buf_len);
if (s->block)
{
buf_len *= (result.buf[3] << 8 | result.buf[2]);
DBG (5, "sane_read: buf len (adjusted) = %lu\n", (u_long) buf_len);
}
if (!s->block && SANE_FRAME_RGB == s->params.format)
{
/*
* Read color data in line mode
*/
/*
* read the first color line - the number of bytes to read
* is already known (from last call to read_data_block()
* We determine where to write the line from the color information
* in the data block. At the end we want the order RGB, but the
* way the data is delivered does not guarantee this - actually it's
* most likely that the order is GRB if it's not RGB!
*/
switch (GET_COLOR (result))
{
case 1:
index = 1;
break;
case 2:
index = 0;
break;
case 3:
index = 2;
break;
}
scanner_receive (s, s->buf + index * s->params.pixels_per_line, buf_len,
&status);
if (SANE_STATUS_GOOD != status)
return status;
/*
* send the ACK signal to the scanner in order to make
* it ready for the next data block.
*/
scanner_send (s, S_ACK, 1, &status);
/*
* ... and request the next data block
*/
if (SANE_STATUS_GOOD != (status = read_data_block (s, &result)))
return status;
buf_len = result.buf[1] << 8 | result.buf[0];
/*
* this should never happen, because we are already in
* line mode, but it does not hurt to check ...
*/
if (s->block)
buf_len *= (result.buf[3] << 8 | result.buf[2]);
DBG (5, "sane_read: buf len2 = %lu\n", (u_long) buf_len);
switch (GET_COLOR (result))
{
case 1:
index = 1;
break;
case 2:
index = 0;
break;
case 3:
index = 2;
break;
}
scanner_receive (s, s->buf + index * s->params.pixels_per_line, buf_len,
&status);
if (SANE_STATUS_GOOD != status)
{
scan_finish (s);
*length = 0;
return status;
}
scanner_send (s, S_ACK, 1, &status);
/*
* ... and the last data block
*/
if (SANE_STATUS_GOOD != (status = read_data_block (s, &result)))
{
*length = 0;
scan_finish (s);
return status;
}
buf_len = result.buf[1] << 8 | result.buf[0];
if (s->block)
buf_len *= (result.buf[3] << 8 | result.buf[2]);
DBG (5, "sane_read: buf len3 = %lu\n", (u_long) buf_len);
switch (GET_COLOR (result))
{
case 1:
index = 1;
break;
case 2:
index = 0;
break;
case 3:
index = 2;
break;
}
scanner_receive (s, s->buf + index * s->params.pixels_per_line, buf_len,
&status);
if (SANE_STATUS_GOOD != status)
{
*length = 0;
scan_finish (s);
return status;
}
}
else
{
/*
* Read data in block mode
*/
/* do we have to reorder the data ? */
if (GET_COLOR (result) == 0x01)
{
reorder = SANE_TRUE;
}
scanner_receive (s, s->buf, buf_len, &status);
if (SANE_STATUS_GOOD != status)
{
*length = 0;
scan_finish (s);
return status;
}
}
if (result.status & STATUS_AREA_END)
{
s->eof = SANE_TRUE;
}
else
{
if (s->canceling)
{
scanner_send (s, S_CAN, 1, &status);
expect_ack (s);
*length = 0;
scan_finish (s);
return SANE_STATUS_CANCELLED;
}
else
scanner_send (s, S_ACK, 1, &status);
}
s->end = s->buf + buf_len;
s->ptr = s->buf;
/*
* if we have to re-order the color components (GRB->RGB) we
* are doing this here:
*/
/*
* Some scaners (e.g. the Perfection 1640 and GT-2200) seem
* to have the R and G channels swapped.
* The GT-8700 is the Asian version of the Perfection1640.
* If the scanner name is one of these, and the scan mode is
* RGB then swap the colors.
*/
needStrangeReorder =
(strstr (s->hw->sane.model, "GT-2200") ||
((strstr (s->hw->sane.model, "1640") &&
strstr (s->hw->sane.model, "Perfection")) ||
strstr (s->hw->sane.model, "GT-8700"))) &&
s->params.format == SANE_FRAME_RGB;
/*
* Certain Perfection 1650 also need this re-ordering of the two
* color channels. These scanners are identified by the problem
* with the half vertical scanning area. When we corrected this,
* we also set the variable s->hw->need_color_reorder
*/
if (s->hw->need_color_reorder)
{
needStrangeReorder = SANE_TRUE;
}
if (needStrangeReorder)
reorder = SANE_FALSE; /* reordering once is enough */
if (s->params.format != SANE_FRAME_RGB)
reorder = SANE_FALSE; /* don't reorder for BW or gray */
if (reorder)
{
SANE_Byte *ptr;
ptr = s->buf;
while (ptr < s->end)
{
if (s->params.depth > 8)
{
SANE_Byte tmp;
/* R->G G->R */
tmp = ptr[0];
ptr[0] = ptr[2]; /* first Byte G */
ptr[2] = tmp; /* first Byte R */
tmp = ptr[1];
ptr[1] = ptr[3]; /* second Byte G */
ptr[3] = tmp; /* second Byte R */
ptr += 6; /* go to next pixel */
}
else
{
/* R->G G->R */
SANE_Byte tmp;
tmp = ptr[0];
ptr[0] = ptr[1]; /* G */
ptr[1] = tmp; /* R */
/* B stays the same */
ptr += 3; /* go to next pixel */
}
}
}
/*
* Do the color_shuffle if everything else is correct - at this time
* most of the stuff is hardcoded for the Perfection 610
*/
if (s->hw->color_shuffle)
{
int new_length = 0;
status = color_shuffle (s, &new_length);
/*
* If no bytes are returned, check if the scanner is already done, if so,
* we'll probably just return, but if there is more data to process get
* the next batch.
*/
if (new_length == 0 && s->end != s->ptr)
{
goto START_READ;
}
s->end = s->buf + new_length;
s->ptr = s->buf;
}
DBG (5, "sane_read: begin scan2\n");
}
/*
* copy the image data to the data memory area
*/
if (!s->block && SANE_FRAME_RGB == s->params.format)
{
max_length /= 3;
if (max_length > s->end - s->ptr)
max_length = s->end - s->ptr;
*length = 3 * max_length;
if (s->invert_image == SANE_TRUE)
{
while (max_length-- != 0)
{
/* invert the three values */
*data++ = (u_char) ~ (s->ptr[0]);
*data++ = (u_char) ~ (s->ptr[s->params.pixels_per_line]);
*data++ = (u_char) ~ (s->ptr[2 * s->params.pixels_per_line]);
++s->ptr;
}
}
else
{
while (max_length-- != 0)
{
*data++ = s->ptr[0];
*data++ = s->ptr[s->params.pixels_per_line];
*data++ = s->ptr[2 * s->params.pixels_per_line];
++s->ptr;
}
}
}
else
{
if (max_length > s->end - s->ptr)
max_length = s->end - s->ptr;
*length = max_length;
if (1 == s->params.depth)
{
if (s->invert_image == SANE_TRUE)
{
while (max_length-- != 0)
*data++ = *s->ptr++;
}
else
{
while (max_length-- != 0)
*data++ = ~*s->ptr++;
}
}
else
{
if (s->invert_image == SANE_TRUE)
{
int i;
for (i = 0; i < max_length; i++)
{
data[i] = (u_char) ~ (s->ptr[i]);
}
}
else
{
memcpy (data, s->ptr, max_length);
}
s->ptr += max_length;
}
}
DBG (5, "sane_read: end\n");
return SANE_STATUS_GOOD;
}
static SANE_Status
color_shuffle (SANE_Handle handle, int *new_length)
{
Epson_Scanner *s = (Epson_Scanner *) handle;
SANE_Byte *buf = s->buf;
int length = s->end - s->buf;
if (s->hw->color_shuffle == SANE_TRUE)
{
SANE_Byte *data_ptr; /* ptr to data to process */
SANE_Byte *data_end; /* ptr to end of processed data */
SANE_Byte *out_data_ptr; /* ptr to memory when writing data */
int i; /* loop counter */
/*
* It looks like we are dealing with a scanner that has an odd way
* of dealing with colors... The red and blue scan lines are shifted
* up or down by a certain number of lines relative to the green line.
*/
DBG (5, "sane_read: color_shuffle\n");
/*
* Initialize the variables we are going to use for the
* copying of the data. data_ptr is the pointer to
* the currently worked on scan line. data_end is the
* end of the data area as calculated from adding *length
* to the start of data.
* out_data_ptr is used when writing out the processed data
* and always points to the beginning of the next line to
* write.
*/
data_ptr = out_data_ptr = buf;
data_end = data_ptr + length;
/*
* The image data is in *buf, we know that the buffer contains s->end - s->buf ( = length)
* bytes of data. The width of one line is in s->params.bytes_per_line
*/
/*
* The buffer area is supposed to have a number of full scan
* lines, let's test if this is the case.
*/
if (length % s->params.bytes_per_line != 0)
{
DBG (1, "ERROR in size of buffer: %d / %d\n",
length, s->params.bytes_per_line);
return SANE_STATUS_INVAL;
}
while (data_ptr < data_end)
{
SANE_Byte *source_ptr, *dest_ptr;
int loop;
/* copy the green information into the current line */
source_ptr = data_ptr + 1;
dest_ptr = s->line_buffer[s->color_shuffle_line] + 1;
for (i = 0; i < s->params.bytes_per_line / 3; i++)
{
*dest_ptr = *source_ptr;
dest_ptr += 3;
source_ptr += 3;
}
/* copy the red information n lines back */
if (s->color_shuffle_line >= s->line_distance)
{
source_ptr = data_ptr + 2;
dest_ptr =
s->line_buffer[s->color_shuffle_line - s->line_distance] + 2;
/* while (source_ptr < s->line_buffer[s->color_shuffle_line] + s->params.bytes_per_line) */
for (loop = 0; loop < s->params.bytes_per_line / 3; loop++)
{
*dest_ptr = *source_ptr;
dest_ptr += 3;
source_ptr += 3;
}
}
/* copy the blue information n lines forward */
source_ptr = data_ptr;
dest_ptr = s->line_buffer[s->color_shuffle_line + s->line_distance];
/* while (source_ptr < s->line_buffer[s->color_shuffle_line] + s->params.bytes_per_line) */
for (loop = 0; loop < s->params.bytes_per_line / 3; loop++)
{
*dest_ptr = *source_ptr;
dest_ptr += 3;
source_ptr += 3;
}
data_ptr += s->params.bytes_per_line;
if (s->color_shuffle_line == s->line_distance)
{
/*
* we just finished the line in line_buffer[0] - write it to the
* output buffer and continue.
*/
/*
* The output buffer is still "buf", but because we are
* only overwriting from the beginning of the memory area
* we are not interfering with the "still to shuffle" data
* in the same area.
*/
/*
* Strip the first and last n lines and limit to
*/
if ((s->current_output_line >= s->line_distance) &&
(s->current_output_line < s->params.lines + s->line_distance))
{
memcpy (out_data_ptr, s->line_buffer[0], s->params.bytes_per_line);
out_data_ptr += s->params.bytes_per_line;
s->lines_written++;
}
s->current_output_line++;
/*
* Now remove the 0-entry and move all other
* lines up by one. There are 2*line_distance + 1
* buffers, * therefore the loop has to run from 0
* to * 2*line_distance, and because we want to
* copy every n+1st entry to n the loop runs
* from - to 2*line_distance-1!
*/
free (s->line_buffer[0]);
for (i = 0; i < s->line_distance * 2; i++)
{
s->line_buffer[i] = s->line_buffer[i + 1];
}
/*
* and create one new buffer at the end
*/
s->line_buffer[s->line_distance * 2] =
malloc (s->params.bytes_per_line);
if (s->line_buffer[s->line_distance * 2] == NULL)
{
int i;
for (i = 0; i < s->line_distance * 2; i++)
{
free (s->line_buffer[i]);
s->line_buffer[i] = NULL;
}
DBG (1, "out of memory (line %d)\n", __LINE__);
return SANE_STATUS_NO_MEM;
}
}
else
{
s->color_shuffle_line++; /* increase the buffer number */
}
}
/*
* At this time we've used up all the new data from the scanner, some of
* it is still in the line_buffers, but we are ready to return some of it
* to the front end software. To do so we have to adjust the size of the
* data area and the *new_length variable.
*/
*new_length = out_data_ptr - buf;
}
return SANE_STATUS_GOOD;
}
/*
* static SANE_Status get_identity_information ( SANE_Handle handle)
*
* Request Identity information from scanner and fill in information
* into dev and/or scanner structures.
*/
static SANE_Status
get_identity_information (SANE_Handle handle)
{
Epson_Scanner *s = (Epson_Scanner *) handle;
Epson_Device *dev = s->hw;
EpsonIdent ident;
u_char param[3];
SANE_Status status;
u_char *buf;
DBG (5, "get_identity_information()\n");
if (!s->hw->cmd->request_identity)
return SANE_STATUS_INVAL;
param[0] = ESC;
param[1] = s->hw->cmd->request_identity;
param[2] = '\0';
if (NULL == (ident = (EpsonIdent) command (s, param, 2, &status)))
{
DBG (1, "ident failed\n");
return SANE_STATUS_INVAL;
}
DBG (1, "type %3c 0x%02x\n", ident->type, ident->type);
DBG (1, "level %3c 0x%02x\n", ident->level, ident->level);
{
char *force = getenv ("SANE_EPSON_CMD_LVL");
if (force)
{
ident->type = force[0];
ident->level = force[1];
DBG (1, "type %3c 0x%02x\n", ident->type, ident->type);
DBG (1, "level %3c 0x%02x\n", ident->level, ident->level);
DBG (1, "forced\n");
}
}
/*
* check if option equipment is installed.
*/
if (ident->status & STATUS_OPTION)
{
DBG (1, "option equipment is installed\n");
dev->extension = SANE_TRUE;
}
else
{
DBG (1, "no option equipment installed\n");
dev->extension = SANE_FALSE;
}
dev->TPU = SANE_FALSE;
dev->ADF = SANE_FALSE;
/*
* set command type and level.
*/
{
int n;
for (n = 0; n < NELEMS (epson_cmd); n++)
{
char type_level[3];
sprintf(type_level, "%c%c", ident->type, ident->level);
if (!strncmp (type_level, epson_cmd[n].level, 2))
break;
}
if (n < NELEMS (epson_cmd))
{
dev->cmd = &epson_cmd[n];
}
else
{
dev->cmd = &epson_cmd[EPSON_LEVEL_DEFAULT];
DBG (1, "Unknown type %c or level %c, using %s\n",
ident->type, ident->level, dev->cmd->level);
}
s->hw->level = dev->cmd->level[1] - '0';
} /* set command type and level */
/*
* Setting available resolutions and xy ranges for sane frontend.
*/
s->hw->res_list_size = 0;
s->hw->res_list =
(SANE_Int *) calloc (s->hw->res_list_size, sizeof (SANE_Int));
if (NULL == s->hw->res_list)
{
DBG (1, "out of memory (line %d)\n", __LINE__);
return SANE_STATUS_NO_MEM;
}
{
int n, k;
int x = 0, y = 0;
int count = ident->count2 * 255 + ident->count1;
/* we need to correct for the difference in size between
the EpsonIdentRec and the EpsonHdrRec */
int correction = sizeof (EpsonIdentRec) - sizeof (EpsonHdrRec);
for (n = (count - correction), buf = ident->buf; n; n -= k, buf += k)
{
switch (*buf)
{
case 'R':
{
int val = buf[2] << 8 | buf[1];
s->hw->res_list_size++;
s->hw->res_list =
(SANE_Int *) realloc (s->hw->res_list,
s->hw->res_list_size * sizeof (SANE_Int));
if (NULL == s->hw->res_list)
{
DBG (1, "out of memory (line %d)\n", __LINE__);
return SANE_STATUS_NO_MEM;
}
s->hw->res_list[s->hw->res_list_size - 1] = (SANE_Int) val;
DBG (1, "resolution (dpi): %d\n", val);
k = 3;
continue;
}
case 'A':
{
x = buf[2] << 8 | buf[1];
y = buf[4] << 8 | buf[3];
DBG (1, "maximum scan area: x %d y %d\n", x, y);
k = 5;
/*
* Check for Perfection 4990 photo/GT-X800 scanner.
* This scanner only report 3200 dpi back.
* The scanner physically supports 4800 dpi.
* This is simulated here...
* Further details read:
* EPSON Programming guide for EPSON Color Image Scanner Perfection 4990
*/
if (s->hw->cmd->request_extended_status != 0)
{
u_char *buf;
u_char params[2];
EpsonHdr head;
params[0] = ESC;
params[1] = s->hw->cmd->request_extended_status;
if (NULL != (head = (EpsonHdr) command (s, params, 2, &status)))
{
buf = &head->buf[0x1A];
DBG (1, "product name %x %x %x %x %x %x %x %x \n", buf[0], buf[1],buf[2],buf[3],buf[4], buf[5],buf[6], buf[7] );
if (strncmp((char *) buf,"GT-X800",7) == 0)
{
int val = 0x12 << 8 | 0xC0;
s->hw->res_list_size++;
s->hw->res_list =
(SANE_Int *) realloc (s->hw->res_list,
s->hw->res_list_size * sizeof (SANE_Int));
if (NULL == s->hw->res_list)
{
DBG (1, "out of memory (line %d)\n", __LINE__);
return SANE_STATUS_NO_MEM;
}
s->hw->res_list[s->hw->res_list_size - 1] = (SANE_Int) val;
x = (x/32)*48;
y = (y/32)*48;
DBG (1, "resolution (dpi): %d\n", val);
DBG (1, "maximum scan area GT-X800: x %d y %d\n", x, y);
}
}
}
continue;
}
default:
break;
} /* case */
break;
} /* for */
dev->dpi_range.min = s->hw->res_list[0];
dev->dpi_range.max = s->hw->res_list[s->hw->res_list_size - 1];
dev->dpi_range.quant = 0;
dev->fbf_x_range.min = 0;
dev->fbf_x_range.max = SANE_FIX (x * 25.4 / dev->dpi_range.max);
dev->fbf_x_range.quant = 0;
dev->fbf_y_range.min = 0;
dev->fbf_y_range.max = SANE_FIX (y * 25.4 / dev->dpi_range.max);
dev->fbf_y_range.quant = 0;
DBG (5, "fbf tlx %f tly %f brx %f bry %f [mm]\n",
SANE_UNFIX (dev->fbf_x_range.min), SANE_UNFIX (dev->fbf_y_range.min),
SANE_UNFIX (dev->fbf_x_range.max),
SANE_UNFIX (dev->fbf_y_range.max));
}
/*
* Copy the resolution list to the resolution_list array so that the frontend can
* display the correct values
*/
s->hw->resolution_list =
malloc ((s->hw->res_list_size + 1) * sizeof (SANE_Word));
if (s->hw->resolution_list == NULL)
{
DBG (1, "out of memory (line %d)\n", __LINE__);
return SANE_STATUS_NO_MEM;
}
*(s->hw->resolution_list) = s->hw->res_list_size;
memcpy (&(s->hw->resolution_list[1]), s->hw->res_list,
s->hw->res_list_size * sizeof (SANE_Word));
/* filter the resolution list */
/* the option is not yet initialized, for now just set it to false */
s->val[OPT_LIMIT_RESOLUTION].w = SANE_FALSE;
filter_resolution_list (s);
return SANE_STATUS_GOOD;
} /* request identity */
/*
* static SANE_Status get_identity2_information ( SANE_Handle handle)
*
* Request Identity2 information from scanner and fill in information
* into dev and/or scanner structures.
*/
static SANE_Status
get_identity2_information (SANE_Handle handle)
{
Epson_Scanner *s = (Epson_Scanner *) handle;
SANE_Status status;
int len;
u_char param[3];
u_char result[4];
u_char *buf;
DBG (5, "get_identity2_information()\n");
if (s->hw->cmd->request_identity2 == 0)
return SANE_STATUS_UNSUPPORTED;
param[0] = ESC;
param[1] = s->hw->cmd->request_identity2;
param[2] = '\0';
scanner_send (s, param, 2, &status);
if (SANE_STATUS_GOOD != status)
return status;
len = 4; /* receive header */
scanner_receive (s, result, len, &status);
if (SANE_STATUS_GOOD != status)
return status;
len = result[3] << 8 | result[2];
buf = alloca (len);
scanner_receive (s, buf, len, &status); /* receive actual status data */
/* the first two bytes of the buffer contain the optical resolution */
s->hw->optical_res = buf[1] << 8 | buf[0];
/*
* the 4th and 5th byte contain the line distance. Both values have to
* be identical, otherwise this software can not handle this scanner.
*/
if (buf[4] != buf[5])
{
close_scanner (s);
return SANE_STATUS_INVAL;
}
s->hw->max_line_distance = buf[4];
return SANE_STATUS_GOOD;
}
/*
* void sane_cancel(SANE_Handle handle)
*
* Set the cancel flag to true. The next time the backend requests data
* from the scanner the CAN message will be sent.
*/
void
sane_cancel (SANE_Handle handle)
{
Epson_Scanner *s = (Epson_Scanner *) handle;
/*
* If the s->ptr pointer is not NULL, then a scan operation
* was started and if s->eof is FALSE, it was not finished.
*/
if (s->buf != NULL)
{
u_char *dummy;
int len;
/* malloc one line */
dummy = malloc (s->params.bytes_per_line);
if (dummy == NULL)
{
DBG (1, "Out of memory\n");
return;
}
else
{
/* there is still data to read from the scanner */
s->canceling = SANE_TRUE;
while (!s->eof &&
SANE_STATUS_CANCELLED != sane_read (s, dummy,
s->params.bytes_per_line,
&len))
{
/* empty body, the while condition does the processing */
}
free (dummy);
}
}
}
static SANE_Status
request_focus_position (SANE_Handle handle, u_char * position)
{
Epson_Scanner *s = (Epson_Scanner *) handle;
SANE_Status status;
int len;
u_char param[3];
u_char result[4];
u_char *buf;
DBG (5, "request_focus_position()\n");
if (s->hw->cmd->request_focus_position == 0)
return SANE_STATUS_UNSUPPORTED;
param[0] = ESC;
param[1] = s->hw->cmd->request_focus_position;
param[2] = '\0';
scanner_send (s, param, 2, &status);
if (SANE_STATUS_GOOD != status)
return status;
len = 4; /* receive header */
scanner_receive (s, result, len, &status);
if (SANE_STATUS_GOOD != status)
return status;
len = result[3] << 8 | result[2];
buf = alloca (len);
scanner_receive (s, buf, len, &status); /* receive actual status data */
*position = buf[1];
DBG (1, "Focus position = 0x%x\n", buf[1]);
return SANE_STATUS_GOOD;
}
/*
* Request the push button status
* returns SANE_TRUE if the button was pressed
* and SANE_FALSE if the button was not pressed
* it also returns SANE_TRUE in case of an error.
* This is necessary so that a process that waits for
* the button does not block indefinitely.
*/
static SANE_Bool
request_push_button_status (SANE_Handle handle, SANE_Bool * theButtonStatus)
{
Epson_Scanner *s = (Epson_Scanner *) handle;
SANE_Status status;
int len;
u_char param[3];
u_char result[4];
u_char *buf;
DBG (5, "request_push_button_status()\n");
if (s->hw->cmd->request_push_button_status == 0)
{
DBG (1, "push button status unsupported\n");
return SANE_STATUS_UNSUPPORTED;
}
param[0] = ESC;
param[1] = s->hw->cmd->request_push_button_status;
param[2] = '\0';
scanner_send (s, param, 2, &status);
if (SANE_STATUS_GOOD != status)
{
DBG (1, "error sending command\n");
return status;
}
len = 4; /* receive header */
scanner_receive (s, result, len, &status);
if (SANE_STATUS_GOOD != status)
return status;
len = result[3] << 8 | result[2]; /* this should be 1 for scanners with one button */
buf = alloca (len);
scanner_receive (s, buf, len, &status); /* receive actual status data */
DBG (1, "Push button status = %d\n", buf[0] & 0x01);
*theButtonStatus = ((buf[0] & 0x01) != 0);
return (SANE_STATUS_GOOD);
}
static void
filter_resolution_list (Epson_Scanner * s)
{
/* re-create the list */
if (s->val[OPT_LIMIT_RESOLUTION].w == SANE_TRUE)
{
/* copy the short list */
/* filter out all values that are not 300 or 400 dpi based */
int i;
int new_size = 0;
SANE_Bool is_correct_resolution = SANE_FALSE;
for (i = 1; i <= s->hw->res_list_size; i++)
{
SANE_Word res;
res = s->hw->res_list[i];
if ((res < 100) || (0 == (res % 300)) || (0 == (res % 400)))
{
/* add the value */
new_size++;
s->hw->resolution_list[new_size] = s->hw->res_list[i];
/* check for a valid current resolution */
if (res == s->val[OPT_RESOLUTION].w)
{
is_correct_resolution = SANE_TRUE;
}
}
}
s->hw->resolution_list[0] = new_size;
if (is_correct_resolution == SANE_FALSE)
{
for (i = 1; i <= new_size; i++)
{
if (s->val[OPT_RESOLUTION].w < s->hw->resolution_list[i])
{
s->val[OPT_RESOLUTION].w = s->hw->resolution_list[i];
i = new_size + 1;
}
}
}
}
else
{
/* copy the full list */
s->hw->resolution_list[0] = s->hw->res_list_size;
memcpy (&(s->hw->resolution_list[1]), s->hw->res_list,
s->hw->res_list_size * sizeof (SANE_Word));
}
}
/**********************************************************************************/
/*
* SANE_Status sane_set_io_mode()
*
* not supported - for asynchronous I/O
*/
SANE_Status
sane_set_io_mode (SANE_Handle handle, SANE_Bool non_blocking)
{
/* get rid of compiler warning */
(void) handle;
(void) non_blocking;
return SANE_STATUS_UNSUPPORTED;
}
/*
* SANE_Status sane_get_select_fd()
*
* not supported - for asynchronous I/O
*/
SANE_Status
sane_get_select_fd (SANE_Handle handle, SANE_Int * fd)
{
/* get rid of compiler warnings */
(void) handle;
(void) fd;
return SANE_STATUS_UNSUPPORTED;
}
/*
vim:ts=2:sw=2:cindent:
*/
|