package com.epson.lib.escani2;

public class ScanI2Runner {
    private static final String LOG_TAG = "ScanI2Runner";
    private volatile boolean mCancelScan;
    private EscanI2Lib mEscanI2Lib;
    private int[] mScanPages;

    public int[] getScanPages() {
        return mScanPages;
    }

    public boolean isCancelScan() {
        return mCancelScan;
    }

    private void setCancelScan(boolean z) {
        mCancelScan = z;
    }

    public ScanI2Runner() {
        mScanPages = new int[2];
        mEscanI2Lib = EscanI2Lib.getInstance();
        mCancelScan = false;
    }

    public ScanI2Runner(EscanI2Lib escanI2Lib) {
        mScanPages = new int[2];
        throw new UnsupportedOperationException("ScanI2Runner(EscanI2Lib) is test only.");
    }

    public void cancelScan() {
        setCancelScan(true);
        EscanI2Lib escanI2Lib = mEscanI2Lib;
        if (escanI2Lib != null) {
            escanI2Lib.cancelScan();
        }
    }

    /* JADX WARNING: Removed duplicated region for block: B:63:0x0122  */
    /* JADX WARNING: Removed duplicated region for block: B:70:0x0137  */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    public int doScan(java.lang.String r17, com.epson.lib.escani2.ScanI2Params r18, java.lang.String[] r19, com.epson.lib.escani2.EscanI2Lib.Observer r20) {
        /*
            r16 = this;
            r1 = r16
            r0 = r17
            r12 = r18
            if (r0 == 0) goto L_0x0147
            boolean r2 = r17.isEmpty()
            if (r2 == 0) goto L_0x0010
            goto L_0x0147
        L_0x0010:
            r13 = 1
            r14 = 0
            r15 = 0
            int[] r2 = r1.mScanPages     // Catch:{ Throwable -> 0x0132, all -> 0x011e }
            r2[r15] = r15     // Catch:{ Throwable -> 0x0132, all -> 0x011e }
            int[] r2 = r1.mScanPages     // Catch:{ Throwable -> 0x0132, all -> 0x011e }
            r2[r13] = r15     // Catch:{ Throwable -> 0x0132, all -> 0x011e }
            com.epson.lib.escani2.EscanI2Lib r2 = r1.mEscanI2Lib     // Catch:{ Throwable -> 0x0132, all -> 0x011e }
            int r2 = r2.initializeLibrary()     // Catch:{ Throwable -> 0x0132, all -> 0x011e }
            if (r2 == 0) goto L_0x002e
            com.epson.lib.escani2.EscanI2Lib r0 = r1.mEscanI2Lib
            r0.releaseLibrary()
            com.epson.lib.escani2.EscanI2Lib r0 = r1.mEscanI2Lib
            r0.setObserver(r14)
            return r2
        L_0x002e:
            com.epson.lib.escani2.EscanI2Lib r2 = r1.mEscanI2Lib     // Catch:{ Throwable -> 0x0132, all -> 0x011e }
            int r0 = r2.setScanner(r0)     // Catch:{ Throwable -> 0x0132, all -> 0x011e }
            if (r0 == 0) goto L_0x0041
            com.epson.lib.escani2.EscanI2Lib r2 = r1.mEscanI2Lib
            r2.releaseLibrary()
            com.epson.lib.escani2.EscanI2Lib r2 = r1.mEscanI2Lib
            r2.setObserver(r14)
            return r0
        L_0x0041:
            com.epson.lib.escani2.EscanI2Lib r0 = r1.mEscanI2Lib     // Catch:{ Throwable -> 0x0132, all -> 0x011e }
            r2 = r20
            r0.setObserver(r2)     // Catch:{ Throwable -> 0x0132, all -> 0x011e }
            com.epson.lib.escani2.EscanI2Lib$ImageFormat r8 = com.epson.lib.escani2.EscanI2Lib.ImageFormat.JPG     // Catch:{ Throwable -> 0x0132, all -> 0x011e }
            int r0 = r12.qualityHW     // Catch:{ Throwable -> 0x0132, all -> 0x011e }
            if (r0 != 0) goto L_0x0053
            r0 = 90
            r9 = 90
            goto L_0x0056
        L_0x0053:
            int r0 = r12.qualityHW     // Catch:{ Throwable -> 0x0132, all -> 0x011e }
            r9 = r0
        L_0x0056:
            r10 = 128(0x80, float:1.794E-43)
            r11 = 65536(0x10000, float:9.18355E-41)
            boolean r0 = r16.isCancelScan()     // Catch:{ Throwable -> 0x0132, all -> 0x011e }
            if (r0 == 0) goto L_0x006b
            com.epson.lib.escani2.EscanI2Lib r0 = r1.mEscanI2Lib
            r0.releaseLibrary()
            com.epson.lib.escani2.EscanI2Lib r0 = r1.mEscanI2Lib
            r0.setObserver(r14)
            return r15
        L_0x006b:
            com.epson.lib.escani2.ScannerI2Info r0 = new com.epson.lib.escani2.ScannerI2Info     // Catch:{ Throwable -> 0x0132, all -> 0x011e }
            r0.<init>()     // Catch:{ Throwable -> 0x0132, all -> 0x011e }
            com.epson.lib.escani2.EscanI2Lib r2 = r1.mEscanI2Lib     // Catch:{ Throwable -> 0x0132, all -> 0x011e }
            int r2 = r2.getScannerInfo(r0)     // Catch:{ Throwable -> 0x0132, all -> 0x011e }
            if (r2 == 0) goto L_0x0083
            com.epson.lib.escani2.EscanI2Lib r0 = r1.mEscanI2Lib
            r0.releaseLibrary()
            com.epson.lib.escani2.EscanI2Lib r0 = r1.mEscanI2Lib
            r0.setObserver(r14)
            return r2
        L_0x0083:
            com.epson.lib.escani2.ScanSize r2 = r12.scanSize     // Catch:{ Throwable -> 0x0132, all -> 0x011e }
            int[] r0 = r2.getValidScanSize(r0, r12)     // Catch:{ Throwable -> 0x0132, all -> 0x011e }
            if (r0 != 0) goto L_0x0096
            com.epson.lib.escani2.EscanI2Lib r0 = r1.mEscanI2Lib
            r0.releaseLibrary()
            com.epson.lib.escani2.EscanI2Lib r0 = r1.mEscanI2Lib
            r0.setObserver(r14)
            return r15
        L_0x0096:
            boolean r2 = r16.isCancelScan()     // Catch:{ Throwable -> 0x0132, all -> 0x011e }
            if (r2 == 0) goto L_0x00a7
            com.epson.lib.escani2.EscanI2Lib r0 = r1.mEscanI2Lib
            r0.releaseLibrary()
            com.epson.lib.escani2.EscanI2Lib r0 = r1.mEscanI2Lib
            r0.setObserver(r14)
            return r15
        L_0x00a7:
            com.epson.lib.escani2.EscanI2Lib r2 = r1.mEscanI2Lib     // Catch:{ Throwable -> 0x011c, all -> 0x011a }
            r4 = r0[r15]     // Catch:{ Throwable -> 0x011c, all -> 0x011a }
            r5 = r0[r13]     // Catch:{ Throwable -> 0x011c, all -> 0x011a }
            r3 = 2
            r6 = r0[r3]     // Catch:{ Throwable -> 0x011c, all -> 0x011a }
            r3 = 3
            r7 = r0[r3]     // Catch:{ Throwable -> 0x011c, all -> 0x011a }
            r3 = r18
            int r0 = r2.startScan(r3, r4, r5, r6, r7, r8, r9, r10, r11)     // Catch:{ Throwable -> 0x011c, all -> 0x011a }
            if (r0 == 0) goto L_0x00cb
            com.epson.lib.escani2.EscanI2Lib r2 = r1.mEscanI2Lib
            r2.releaseScanner()
            com.epson.lib.escani2.EscanI2Lib r2 = r1.mEscanI2Lib
            r2.releaseLibrary()
            com.epson.lib.escani2.EscanI2Lib r2 = r1.mEscanI2Lib
            r2.setObserver(r14)
            return r0
        L_0x00cb:
            r0 = r19[r15]     // Catch:{ Throwable -> 0x011c, all -> 0x011a }
            boolean r2 = r12.duplex     // Catch:{ Throwable -> 0x011c, all -> 0x011a }
            if (r2 == 0) goto L_0x00d4
            r2 = r19[r13]     // Catch:{ Throwable -> 0x011c, all -> 0x011a }
            goto L_0x00d5
        L_0x00d4:
            r2 = r14
        L_0x00d5:
            boolean r3 = r16.isCancelScan()     // Catch:{ Throwable -> 0x011c, all -> 0x011a }
            if (r3 == 0) goto L_0x00f0
            com.epson.lib.escani2.EscanI2Lib r0 = r1.mEscanI2Lib     // Catch:{ Throwable -> 0x011c, all -> 0x011a }
            r0.releaseScanner()     // Catch:{ Throwable -> 0x011c, all -> 0x011a }
            com.epson.lib.escani2.EscanI2Lib r0 = r1.mEscanI2Lib
            r0.releaseScanner()
            com.epson.lib.escani2.EscanI2Lib r0 = r1.mEscanI2Lib
            r0.releaseLibrary()
            com.epson.lib.escani2.EscanI2Lib r0 = r1.mEscanI2Lib
            r0.setObserver(r14)
            return r15
        L_0x00f0:
            com.epson.lib.escani2.EscanI2Lib r3 = r1.mEscanI2Lib     // Catch:{ Throwable -> 0x011c, all -> 0x011a }
            int r0 = r3.writeScanImage(r15, r0, r2)     // Catch:{ Throwable -> 0x011c, all -> 0x011a }
            int[] r2 = r1.mScanPages     // Catch:{ Throwable -> 0x011c, all -> 0x011a }
            com.epson.lib.escani2.EscanI2Lib r3 = r1.mEscanI2Lib     // Catch:{ Throwable -> 0x011c, all -> 0x011a }
            int r3 = r3.getScanPages(r15)     // Catch:{ Throwable -> 0x011c, all -> 0x011a }
            r2[r15] = r3     // Catch:{ Throwable -> 0x011c, all -> 0x011a }
            int[] r2 = r1.mScanPages     // Catch:{ Throwable -> 0x011c, all -> 0x011a }
            com.epson.lib.escani2.EscanI2Lib r3 = r1.mEscanI2Lib     // Catch:{ Throwable -> 0x011c, all -> 0x011a }
            int r3 = r3.getScanPages(r13)     // Catch:{ Throwable -> 0x011c, all -> 0x011a }
            r2[r13] = r3     // Catch:{ Throwable -> 0x011c, all -> 0x011a }
            com.epson.lib.escani2.EscanI2Lib r2 = r1.mEscanI2Lib
            r2.releaseScanner()
            com.epson.lib.escani2.EscanI2Lib r2 = r1.mEscanI2Lib
            r2.releaseLibrary()
            com.epson.lib.escani2.EscanI2Lib r2 = r1.mEscanI2Lib
            r2.setObserver(r14)
            return r0
        L_0x011a:
            r0 = move-exception
            goto L_0x0120
        L_0x011c:
            goto L_0x0133
        L_0x011e:
            r0 = move-exception
            r13 = 0
        L_0x0120:
            if (r13 == 0) goto L_0x0127
            com.epson.lib.escani2.EscanI2Lib r2 = r1.mEscanI2Lib
            r2.releaseScanner()
        L_0x0127:
            com.epson.lib.escani2.EscanI2Lib r2 = r1.mEscanI2Lib
            r2.releaseLibrary()
            com.epson.lib.escani2.EscanI2Lib r2 = r1.mEscanI2Lib
            r2.setObserver(r14)
            throw r0
        L_0x0132:
            r13 = 0
        L_0x0133:
            r0 = -200(0xffffffffffffff38, float:NaN)
            if (r13 == 0) goto L_0x013c
            com.epson.lib.escani2.EscanI2Lib r2 = r1.mEscanI2Lib
            r2.releaseScanner()
        L_0x013c:
            com.epson.lib.escani2.EscanI2Lib r2 = r1.mEscanI2Lib
            r2.releaseLibrary()
            com.epson.lib.escani2.EscanI2Lib r2 = r1.mEscanI2Lib
            r2.setObserver(r14)
            return r0
        L_0x0147:
            r0 = -214(0xffffffffffffff2a, float:NaN)
            return r0
        */
        throw new UnsupportedOperationException("Method not decompiled: com.epson.lib.escani2.ScanI2Runner.doScan(java.lang.String, com.epson.lib.escani2.ScanI2Params, java.lang.String[], com.epson.lib.escani2.EscanI2Lib$Observer):int");
    }
}
