EscanI2Lib.java 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472
  1. package com.epson.lib.escani2;
  2. import java.util.ArrayList;
  3. import java.util.Locale;
  4. public class EscanI2Lib {
  5. static final /* synthetic */ boolean $assertionsDisabled = false;
  6. public static final int ERROR_CODE_COMM_ERROR = -214;
  7. public static final int ERROR_CODE_COVER_OPEN = -215;
  8. public static final int ERROR_CODE_DOUBLE_FEED = -211;
  9. public static final int ERROR_CODE_ESCANI2_ERROR = -1000;
  10. public static final int ERROR_CODE_FILE_WRITE_ERROR = -202;
  11. public static final int ERROR_CODE_GENERAL_ERROR = -200;
  12. public static final int ERROR_CODE_INTERNAL_ERROR = -100;
  13. public static final int ERROR_CODE_JOB_CANCELED = 1;
  14. public static final int ERROR_CODE_MEMORY_ALLOCATE_ERROR = -201;
  15. public static final int ERROR_CODE_NO_ERROR = 0;
  16. public static final int ERROR_CODE_PAPER_EMPTY = -210;
  17. public static final int ERROR_CODE_PAPER_JAM = -212;
  18. public static final int ERROR_CODE_SCANNER_OCCUPIED = -213;
  19. private static final String LOG_TAG = "EscanI2Lib";
  20. static EscanI2NativeInterface sEscanI2NativeInterface;
  21. static EscanI2Lib sInstance;
  22. int mDuplex;
  23. private boolean mLibraryInitialized;
  24. int mMaxScanSheets;
  25. Observer mObserver;
  26. final Object mObserverLock = new Object();
  27. private boolean mScannerLocked;
  28. private boolean mSetPaperSize;
  29. private boolean mSetScannerDone;
  30. volatile boolean mWaitStartRequest;
  31. int marg_jpeg_quality;
  32. int marg_over_scan;
  33. int marg_threshold;
  34. int mautoCtop;
  35. int mautoSkew;
  36. int mbufferSize;
  37. ColorMode mcolorMode;
  38. DoubleFeedLevel mdoubleFeedLevel;
  39. int mheight;
  40. ImageFormat mimageFormat;
  41. InputUnit minputSource;
  42. int mlookupTableNo;
  43. int moffsetX;
  44. int moffsetY;
  45. int mresolutionMain;
  46. int mresolutionSub;
  47. Gamma muserGamma;
  48. int mwidth;
  49. public enum AutoCrop {
  50. FALSE,
  51. TRUE
  52. }
  53. public enum AutoSkew {
  54. FALSE,
  55. TRUE
  56. }
  57. public enum ColorMode {
  58. MONO_1BIT,
  59. GRAYSCALE_8BIT,
  60. COLOR_24BIT
  61. }
  62. public enum Gamma {
  63. GAMMA_100,
  64. GAMMA_180
  65. }
  66. public enum ImageFormat {
  67. JPG,
  68. RAW
  69. }
  70. public enum InputUnit {
  71. FLATBED,
  72. ADF,
  73. TRANSPARENT_UNIT
  74. }
  75. public interface Observer {
  76. void update(int i, int i2);
  77. }
  78. public enum PagerGuidPosition {
  79. CENTER,
  80. UPPER_LEFT
  81. }
  82. private boolean checkResolution(int i, int i2) {
  83. return i != 300 ? i == 600 && i2 == 600 : i2 == 300;
  84. }
  85. private boolean isDeviceChige() {
  86. return false;
  87. }
  88. private int trunsErrorCode(int i, boolean z) {
  89. if (i == -5007) {
  90. return -211;
  91. }
  92. if (i == -1501) {
  93. return -213;
  94. }
  95. if (i == -1114 || i == -1100) {
  96. return -214;
  97. }
  98. switch (i) {
  99. case -5003:
  100. return z ? -210 : 0;
  101. case -5002:
  102. return -212;
  103. case -5001:
  104. return -215;
  105. default:
  106. switch (i) {
  107. case -102:
  108. return -202;
  109. case -101:
  110. return -201;
  111. default:
  112. return i;
  113. }
  114. }
  115. }
  116. public enum DoubleFeedLevel {
  117. LEVEL_NONE(0),
  118. LEVEL_1(1),
  119. LEVEL_2(2),
  120. LEVEL_UNDEFINED(255);
  121. private int mValue;
  122. private DoubleFeedLevel(int i) {
  123. mValue = i;
  124. }
  125. public int getValue() {
  126. return mValue;
  127. }
  128. }
  129. private EscanI2Lib() {
  130. }
  131. public static synchronized EscanI2Lib getInstance() {
  132. EscanI2Lib escanI2Lib;
  133. synchronized (EscanI2Lib.class) {
  134. if (sEscanI2NativeInterface == null) {
  135. sEscanI2NativeInterface = new EscanI2NativeIf();
  136. }
  137. if (sInstance == null) {
  138. sInstance = new EscanI2Lib();
  139. }
  140. escanI2Lib = sInstance;
  141. }
  142. return escanI2Lib;
  143. }
  144. public static synchronized EscanI2Lib getInstance(EscanI2NativeInterface escanI2NativeInterface) {
  145. EscanI2Lib escanI2Lib;
  146. synchronized (EscanI2Lib.class) {
  147. sEscanI2NativeInterface = escanI2NativeInterface;
  148. if (sInstance == null) {
  149. sInstance = new EscanI2Lib();
  150. }
  151. escanI2Lib = sInstance;
  152. }
  153. return escanI2Lib;
  154. }
  155. public synchronized int initializeLibrary() {
  156. int initializeLibraryJni;
  157. if (!mLibraryInitialized) {
  158. mLibraryInitialized = false;
  159. mSetScannerDone = false;
  160. mScannerLocked = false;
  161. mSetPaperSize = false;
  162. initializeLibraryJni = sEscanI2NativeInterface.initializeLibraryJni();
  163. if (initializeLibraryJni == 0) {
  164. mLibraryInitialized = true;
  165. }
  166. sEscanI2NativeInterface.setPageWriteCallback(new EscanI2NativeInterface.PageWriteCallback() {
  167. public void pageWriteDone(int i, int i2) {
  168. updatePages(i, i2);
  169. }
  170. });
  171. } else {
  172. throw new RuntimeException("initializeLibrary() has already called.");
  173. }
  174. return initializeLibraryJni;
  175. }
  176. /* JADX WARNING: Can't wrap try/catch for region: R(8:10|11|12|13|22|21|8|7) */
  177. /* JADX WARNING: Missing exception handler attribute for start block: B:7:0x0008 */
  178. /* JADX WARNING: Removed duplicated region for block: B:7:0x0008 A[LOOP:0: B:7:0x0008->B:21:0x0008, LOOP_START, SYNTHETIC, Splitter:B:7:0x0008] */
  179. /* Code decompiled incorrectly, please refer to instructions dump. */
  180. public synchronized int releaseLibrary() {
  181. /*
  182. r4 = this;
  183. monitor-enter(r4)
  184. boolean r0 = r4.mLibraryInitialized // Catch:{ all -> 0x002b }
  185. r1 = 0
  186. if (r0 != 0) goto L_0x0008
  187. monitor-exit(r4)
  188. return r1
  189. L_0x0008:
  190. boolean r0 = r4.mWaitStartRequest // Catch:{ all -> 0x002b }
  191. if (r0 == 0) goto L_0x0015
  192. r4.cancelWaiting() // Catch:{ all -> 0x002b }
  193. r2 = 100
  194. java.lang.Thread.sleep(r2) // Catch:{ InterruptedException -> 0x0008 }
  195. goto L_0x0008
  196. L_0x0015:
  197. r4.releaseScanner() // Catch:{ all -> 0x002b }
  198. r4.mLibraryInitialized = r1 // Catch:{ all -> 0x002b }
  199. r4.mSetScannerDone = r1 // Catch:{ all -> 0x002b }
  200. r4.mScannerLocked = r1 // Catch:{ all -> 0x002b }
  201. r4.mSetPaperSize = r1 // Catch:{ all -> 0x002b }
  202. r0 = 0
  203. r4.mObserver = r0 // Catch:{ all -> 0x002b }
  204. com.epson.lib.escani2.EscanI2NativeInterface r0 = sEscanI2NativeInterface // Catch:{ all -> 0x002b }
  205. int r0 = r0.releaseLibraryJni() // Catch:{ all -> 0x002b }
  206. monitor-exit(r4)
  207. return r0
  208. L_0x002b:
  209. r0 = move-exception
  210. monitor-exit(r4)
  211. throw r0
  212. */
  213. throw new UnsupportedOperationException("Method not decompiled: com.epson.lib.escani2.EscanI2Lib.releaseLibrary():int");
  214. }
  215. public int NOT_setScanner(String str) {
  216. return setScanner(str);
  217. }
  218. public synchronized int setScanner(String str) {
  219. if (mLibraryInitialized) {
  220. mSetScannerDone = true;
  221. } else {
  222. throw new RuntimeException("initializeLibrary() has not been called.");
  223. }
  224. return trunsErrorCode(sEscanI2NativeInterface.setScannerJni(str), false);
  225. }
  226. public int waitStartRequest() {
  227. mWaitStartRequest = true;
  228. int waitStartRequest = sEscanI2NativeInterface.waitStartRequest();
  229. mWaitStartRequest = false;
  230. return trunsErrorCode(waitStartRequest, false);
  231. }
  232. public int cancelWaiting() {
  233. sEscanI2NativeInterface.cancelWaitingJni();
  234. return 0;
  235. }
  236. public synchronized int setPaperSize(ScanSize.PaperSize paperSize, int i, int i2, boolean z) {
  237. if (!mSetScannerDone) {
  238. throw new RuntimeException("setScanner() has not been called.");
  239. } else if (checkResolution(i, i2)) {
  240. int[] iArr = ScanSize.get300DpiPixelFromPaperSize(paperSize);
  241. int i3 = 2550;
  242. if (i == 600) {
  243. iArr[0] = iArr[0] * 2;
  244. iArr[1] = iArr[1] * 2;
  245. i3 = 5100;
  246. }
  247. if (!z) {
  248. if (!isDeviceChige()) {
  249. moffsetX = (i3 - iArr[0]) / 2;
  250. moffsetY = 0;
  251. mwidth = iArr[0];
  252. mheight = iArr[1];
  253. mresolutionMain = i;
  254. mresolutionSub = i2;
  255. }
  256. }
  257. moffsetX = 0;
  258. moffsetY = 0;
  259. mwidth = iArr[0];
  260. mheight = iArr[1];
  261. mresolutionMain = i;
  262. mresolutionSub = i2;
  263. } else {
  264. throw new RuntimeException(String.format(Locale.US, "%dx%d dpi is not supported.", new Object[]{Integer.valueOf(i), Integer.valueOf(i2)}));
  265. }
  266. return 0;
  267. }
  268. public synchronized int startScan(AutoCrop autoCrop, AutoSkew autoSkew, ColorMode colorMode, Gamma gamma, int i, InputUnit inputUnit, int i2, int i3, boolean z, boolean z2, ImageFormat imageFormat, int i4, int i5, DoubleFeedLevel doubleFeedLevel) {
  269. ImageFormat imageFormat2;
  270. int trunsErrorCode;
  271. synchronized (this) {
  272. if (mLibraryInitialized) {
  273. mautoCtop = autoCrop.ordinal();
  274. mautoSkew = autoSkew.ordinal();
  275. mcolorMode = colorMode;
  276. muserGamma = gamma;
  277. mlookupTableNo = i;
  278. minputSource = inputUnit;
  279. mMaxScanSheets = i2;
  280. mDuplex = 0;
  281. if (z) {
  282. mDuplex = 1;
  283. }
  284. marg_over_scan = 0;
  285. if (!z2 || isDeviceChige()) {
  286. imageFormat2 = imageFormat;
  287. } else {
  288. marg_over_scan = 1;
  289. imageFormat2 = imageFormat;
  290. }
  291. mimageFormat = imageFormat2;
  292. marg_jpeg_quality = i4;
  293. marg_threshold = i5;
  294. mdoubleFeedLevel = doubleFeedLevel;
  295. mbufferSize = 65536;
  296. mScannerLocked = true;
  297. trunsErrorCode = trunsErrorCode(sEscanI2NativeInterface.startScan(moffsetX, moffsetY, mwidth, mheight, mautoCtop, mautoSkew, mresolutionMain, mresolutionSub, mcolorMode.ordinal(), muserGamma.ordinal(), mlookupTableNo, minputSource.ordinal(), mDuplex > 0 ? mMaxScanSheets * 2 : mMaxScanSheets, i3, mDuplex, marg_over_scan, mimageFormat.ordinal(), marg_jpeg_quality, marg_threshold, mdoubleFeedLevel.getValue(), mbufferSize), true);
  298. } else {
  299. throw new RuntimeException("initializeLibrary() has not been called.");
  300. }
  301. }
  302. return trunsErrorCode;
  303. }
  304. public synchronized int startScan(ScanI2Params scanI2Params, int i, int i2, int i3, int i4, ImageFormat imageFormat, int i5, int i6, int i7) {
  305. int trunsErrorCode;
  306. ScanI2Params scanI2Params2 = scanI2Params;
  307. synchronized (this) {
  308. int startScan = sEscanI2NativeInterface.startScan(i3, i4, i, i2, scanI2Params2.autoCrop.ordinal(), scanI2Params2.autoSkew.ordinal(), scanI2Params2.resolutionMain, scanI2Params2.resolutionSub, scanI2Params2.colorMode.ordinal(), scanI2Params2.userGamma.ordinal(), scanI2Params2.lookupTableNo, scanI2Params2.inputUnit.ordinal(), scanI2Params2.maxScanSheets, scanI2Params2.maxWriteSheets, scanI2Params2.duplex ? 1 : 0, scanI2Params2.overScan ? 1 : 0, imageFormat.ordinal(), i5, i6, scanI2Params2.doubleFeedLevel.getValue(), i7);
  309. mScannerLocked = true;
  310. trunsErrorCode = trunsErrorCode(startScan, true);
  311. }
  312. return trunsErrorCode;
  313. }
  314. /* JADX WARNING: Code restructure failed: missing block: B:13:0x0019, code lost:
  315. return r0;
  316. */
  317. /* Code decompiled incorrectly, please refer to instructions dump. */
  318. public synchronized int releaseScanner() {
  319. /*
  320. r3 = this;
  321. monitor-enter(r3)
  322. boolean r0 = r3.mScannerLocked // Catch:{ all -> 0x001a }
  323. r1 = 0
  324. if (r0 != 0) goto L_0x0008
  325. monitor-exit(r3)
  326. return r1
  327. L_0x0008:
  328. r3.mScannerLocked = r1 // Catch:{ all -> 0x001a }
  329. com.epson.lib.escani2.EscanI2NativeInterface r0 = sEscanI2NativeInterface // Catch:{ all -> 0x001a }
  330. int r0 = r0.releaseScannerJni() // Catch:{ all -> 0x001a }
  331. int r0 = r3.trunsErrorCode(r0, r1) // Catch:{ all -> 0x001a }
  332. r2 = 1
  333. if (r0 != r2) goto L_0x0018
  334. r0 = 0
  335. L_0x0018:
  336. monitor-exit(r3)
  337. return r0
  338. L_0x001a:
  339. r0 = move-exception
  340. monitor-exit(r3)
  341. throw r0
  342. */
  343. throw new UnsupportedOperationException("Method not decompiled: com.epson.lib.escani2.EscanI2Lib.releaseScanner():int");
  344. }
  345. public void cancelScan() {
  346. sEscanI2NativeInterface.cancelScanJni();
  347. }
  348. public int writeScanImage(int i, String str, String str2) {
  349. if (!mScannerLocked) {
  350. throw new RuntimeException("startScan() has not been called");
  351. } else if (str == null) {
  352. throw new IllegalArgumentException("outfile_fmt_a must not be null.");
  353. } else if (mDuplex <= 0 || str2 != null) {
  354. return trunsErrorCode(sEscanI2NativeInterface.scan(i, str, str2), false);
  355. } else {
  356. throw new IllegalArgumentException("outfile_fmt_b must not be null.");
  357. }
  358. }
  359. public void setObserver(Observer observer) {
  360. synchronized (mObserverLock) {
  361. mObserver = observer;
  362. }
  363. }
  364. public int getScanPages(int i) {
  365. if (mLibraryInitialized) {
  366. return sEscanI2NativeInterface.getScanPages(i);
  367. }
  368. throw new RuntimeException("initializeLibrary() has not been called.");
  369. }
  370. public int cleanAdf() {
  371. return trunsErrorCode(sEscanI2NativeInterface.cleanAdf(), true);
  372. }
  373. public int freeBlockedCleanAdf() {
  374. return trunsErrorCode(sEscanI2NativeInterface.freeBlockedCleanAdf(), false);
  375. }
  376. public int calibrateAdf() {
  377. return trunsErrorCode(sEscanI2NativeInterface.calibrateAdf(), true);
  378. }
  379. public int freeBlockedCalibrateAdf() {
  380. return trunsErrorCode(sEscanI2NativeInterface.freeBlockedCalibrateAdf(), false);
  381. }
  382. public int setPowerSaveTime(int i) {
  383. return trunsErrorCode(sEscanI2NativeInterface.setPowerSaveTime(i), false);
  384. }
  385. public int setPowerOffTime(int i) {
  386. return trunsErrorCode(sEscanI2NativeInterface.setPowerOffTime(i), false);
  387. }
  388. public int getMaintAppliedParameters(int[] iArr) {
  389. int[] maintAppliedParameters = sEscanI2NativeInterface.getMaintAppliedParameters();
  390. if (maintAppliedParameters == null) {
  391. return -100;
  392. }
  393. iArr[0] = maintAppliedParameters[0];
  394. iArr[1] = maintAppliedParameters[1];
  395. return 0;
  396. }
  397. public int getMaintCapability(ArrayList<Integer> arrayList, ArrayList<Integer> arrayList2) {
  398. int[] maintCapability = sEscanI2NativeInterface.getMaintCapability();
  399. boolean z = false;
  400. for (int i : maintCapability) {
  401. if (i == -1) {
  402. z = true;
  403. } else if (!z) {
  404. arrayList.add(Integer.valueOf(i));
  405. } else {
  406. arrayList2.add(Integer.valueOf(i));
  407. }
  408. }
  409. if (maintCapability == null) {
  410. return -100;
  411. }
  412. return 0;
  413. }
  414. public int getScannerInfo(ScannerI2Info scannerI2Info) {
  415. return sEscanI2NativeInterface.getScannerInfo(scannerI2Info);
  416. }
  417. public int getCapability(ScannerI2Capability scannerI2Capability) {
  418. return sEscanI2NativeInterface.getCapability(scannerI2Capability);
  419. }
  420. private void updatePages(int i, int i2) {
  421. synchronized (mObserverLock) {
  422. if (mObserver != null) {
  423. mObserver.update(i, i2);
  424. }
  425. }
  426. }
  427. }