package epson.colorcorrection;

import android.util.Log;

import com.epson.cameracopy.device.RectangleDetector;
import com.google.common.primitives.UnsignedBytes;

import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.core.MatOfByte;
import org.opencv.core.Point;
import org.opencv.core.Rect;
import org.opencv.imgproc.Imgproc;

public class SDIC_BCSC extends SDIC_Exception implements SDIC_CommonDefine {
    private static int saturate_cast(int i) {
        if (i > 255) {
            i = 255;
        }
        if (i < 0) {
            return 0;
        }
        return i;
    }

    static {
        System.loadLibrary("opencv_java3");
    }

    public static int BCSCorrection(Mat mat, Mat mat2, SDIC_MAT_PTR sdic_mat_ptr, double d, double d2, double d3) {
        return RectangleDetector.bcsCorrection(mat.getNativeObjAddr(), mat2.getNativeObjAddr(), sdic_mat_ptr.getMat().getNativeObjAddr(), d, d2, d3);
    }

    public static int BCSCorrectionJAVA(Mat mat, Mat mat2, SDIC_MAT_PTR sdic_mat_ptr, double d, double d2, double d3) {
        int i;
        int cols = mat.cols();
        int rows = mat.rows();
        int channels = mat.channels();
        Mat mat3 = new Mat(rows, cols, mat.type());
        Runtime runtime = Runtime.getRuntime();
        runtime.maxMemory();
        float f = ((float) runtime.totalMemory()) / 1048576.0f;
        float freeMemory = f - (f - (((float) runtime.freeMemory()) / 1048576.0f));
        float f2 = 2.0f;
        float f3 = (freeMemory / 2.0f) / 3.5f;
        if (f3 > 2.0f) {
            f2 = f3;
        }
        int i2 = ((f2 * 1048576.0f) / ((float) (cols * channels)));
        if (i2 >= mat.rows()) {
            i2 = mat.rows();
        }
        Rect rect = new Rect(0, 0, cols, i2);
        int ceil = Math.ceil((rows) / (i2));
        LogMemory(String.format("BCSC S - [%d] w:%d h:%d c:%d m:%.2fMB use:%.2fMB", new Object[]{Integer.valueOf(ceil), Integer.valueOf(cols), Integer.valueOf(rows), Integer.valueOf(channels), Float.valueOf(((float) ((cols * rows) * channels)) / 1048576.0f), Float.valueOf(f2)}));
        int i3 = 0;
        int i4 = 0;
        while (true) {
            if (rows <= 0) {
                i = i4;
                break;
            }
            rect.height = rows < i2 ? rows : i2;
            Mat submat = mat.submat(rect);
            Mat submat2 = mat2.submat(rect);
            Mat submat3 = mat3.submat(rect);
            i = BCSCorrection_ROI(submat, submat2, submat3, d, d2, d3);
            submat.release();
            submat2.release();
            submat3.release();
            i3++;
            LogMemory(String.format("BCSC R - [%d/%d] %d", new Object[]{Integer.valueOf(i3), Integer.valueOf(ceil), Integer.valueOf(rect.height)}));
            if (i != 0) {
                break;
            }
            rows -= i2;
            rect.f438y += i2;
            i4 = i;
        }
        if (i == 0) {
            sdic_mat_ptr.setMat(mat3);
        }
        LogMemory(String.format("BCSC E use:%.2fMB", new Object[]{Float.valueOf(f2)}));
        return i;
    }

    /* JADX WARNING: Code restructure failed: missing block: B:15:0x0039, code lost:
        if (r1 != -1) goto L_0x003b;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:16:0x003b, code lost:
        r9.release();
     */
    /* JADX WARNING: Code restructure failed: missing block: B:31:0x0065, code lost:
        if (r9.empty() != false) goto L_0x007f;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:34:0x006e, code lost:
        if (r9.empty() != false) goto L_0x007f;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:41:0x007c, code lost:
        if (r1 != -1) goto L_0x003b;
     */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    public static int BCSCorrection_ROI(org.opencv.core.Mat r7, org.opencv.core.Mat r8, org.opencv.core.Mat r9, double r10, double r12, double r14) {
        /*
            r0 = -1
            r1 = 0
            int r1 = CheckImage(r7, r8)     // Catch:{ SDIC_Exception -> 0x0071, CvException -> 0x0068, Exception -> 0x005f }
            if (r1 != 0) goto L_0x0057
            long r2 = r7.dataAddr()     // Catch:{ SDIC_Exception -> 0x0071, CvException -> 0x0068, Exception -> 0x005f }
            long r4 = r9.dataAddr()     // Catch:{ SDIC_Exception -> 0x0071, CvException -> 0x0068, Exception -> 0x005f }
            int r6 = (r2 > r4 ? 1 : (r2 == r4 ? 0 : -1))
            if (r6 == 0) goto L_0x0051
            r9.empty()     // Catch:{ SDIC_Exception -> 0x0071, CvException -> 0x0068, Exception -> 0x005f }
            int r1 = Contrast(r7, r8, r9, r12)     // Catch:{ SDIC_Exception -> 0x0071, CvException -> 0x0068, Exception -> 0x005f }
            if (r1 != 0) goto L_0x004b
            org.opencv.core.Mat r7 = r9.clone()     // Catch:{ SDIC_Exception -> 0x0071, CvException -> 0x0068, Exception -> 0x005f }
            int r1 = Saturation(r7, r8, r9, r14)     // Catch:{ SDIC_Exception -> 0x0071, CvException -> 0x0068, Exception -> 0x005f }
            if (r1 != 0) goto L_0x0045
            org.opencv.core.Mat r7 = r9.clone()     // Catch:{ SDIC_Exception -> 0x0071, CvException -> 0x0068, Exception -> 0x005f }
            int r1 = Brightness(r7, r8, r9, r10)     // Catch:{ SDIC_Exception -> 0x0071, CvException -> 0x0068, Exception -> 0x005f }
            if (r1 != 0) goto L_0x003f
            if (r1 == 0) goto L_0x007f
            boolean r7 = r9.empty()
            if (r7 != 0) goto L_0x007f
            if (r1 == r0) goto L_0x007f
        L_0x003b:
            r9.release()
            goto L_0x007f
        L_0x003f:
            epson.colorcorrection.SDIC_Exception r7 = new epson.colorcorrection.SDIC_Exception     // Catch:{ SDIC_Exception -> 0x0071, CvException -> 0x0068, Exception -> 0x005f }
            r7.<init>(r1)     // Catch:{ SDIC_Exception -> 0x0071, CvException -> 0x0068, Exception -> 0x005f }
            throw r7     // Catch:{ SDIC_Exception -> 0x0071, CvException -> 0x0068, Exception -> 0x005f }
        L_0x0045:
            epson.colorcorrection.SDIC_Exception r7 = new epson.colorcorrection.SDIC_Exception     // Catch:{ SDIC_Exception -> 0x0071, CvException -> 0x0068, Exception -> 0x005f }
            r7.<init>(r1)     // Catch:{ SDIC_Exception -> 0x0071, CvException -> 0x0068, Exception -> 0x005f }
            throw r7     // Catch:{ SDIC_Exception -> 0x0071, CvException -> 0x0068, Exception -> 0x005f }
        L_0x004b:
            epson.colorcorrection.SDIC_Exception r7 = new epson.colorcorrection.SDIC_Exception     // Catch:{ SDIC_Exception -> 0x0071, CvException -> 0x0068, Exception -> 0x005f }
            r7.<init>(r1)     // Catch:{ SDIC_Exception -> 0x0071, CvException -> 0x0068, Exception -> 0x005f }
            throw r7     // Catch:{ SDIC_Exception -> 0x0071, CvException -> 0x0068, Exception -> 0x005f }
        L_0x0051:
            epson.colorcorrection.SDIC_Exception r7 = new epson.colorcorrection.SDIC_Exception     // Catch:{ SDIC_Exception -> 0x0071, CvException -> 0x0068, Exception -> 0x005f }
            r7.<init>(r0)     // Catch:{ SDIC_Exception -> 0x0071, CvException -> 0x0068, Exception -> 0x005f }
            throw r7     // Catch:{ SDIC_Exception -> 0x0071, CvException -> 0x0068, Exception -> 0x005f }
        L_0x0057:
            epson.colorcorrection.SDIC_Exception r7 = new epson.colorcorrection.SDIC_Exception     // Catch:{ SDIC_Exception -> 0x0071, CvException -> 0x0068, Exception -> 0x005f }
            r7.<init>(r1)     // Catch:{ SDIC_Exception -> 0x0071, CvException -> 0x0068, Exception -> 0x005f }
            throw r7     // Catch:{ SDIC_Exception -> 0x0071, CvException -> 0x0068, Exception -> 0x005f }
        L_0x005d:
            r7 = move-exception
            goto L_0x0080
        L_0x005f:
            r1 = -400(0xfffffffffffffe70, float:NaN)
            boolean r7 = r9.empty()
            if (r7 != 0) goto L_0x007f
            goto L_0x003b
        L_0x0068:
            r1 = -100
            boolean r7 = r9.empty()
            if (r7 != 0) goto L_0x007f
            goto L_0x003b
        L_0x0071:
            r7 = move-exception
            int r1 = r7.mCode     // Catch:{ all -> 0x005d }
            if (r1 == 0) goto L_0x007f
            boolean r7 = r9.empty()
            if (r7 != 0) goto L_0x007f
            if (r1 == r0) goto L_0x007f
            goto L_0x003b
        L_0x007f:
            return r1
        L_0x0080:
            if (r1 == 0) goto L_0x008d
            boolean r8 = r9.empty()
            if (r8 != 0) goto L_0x008d
            if (r1 == r0) goto L_0x008d
            r9.release()
        L_0x008d:
            throw r7
        */
        throw new UnsupportedOperationException("Method not decompiled: epson.colorcorrection.SDIC_BCSC.BCSCorrection_ROI(org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Mat, double, double, double):int");
    }

    /* JADX WARNING: Code restructure failed: missing block: B:101:0x01c4, code lost:
        if (r2.empty() != false) goto L_?;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:104:0x01c9, code lost:
        r2.release();
     */
    /* JADX WARNING: Code restructure failed: missing block: B:105:0x01cd, code lost:
        r1.setMat(r2);
     */
    /* JADX WARNING: Code restructure failed: missing block: B:117:?, code lost:
        return r4;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:119:?, code lost:
        return epson.colorcorrection.SDIC_CommonDefine.SDIC_ERR_UNKNOWN;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:120:?, code lost:
        return r4;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:121:?, code lost:
        return -100;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:123:?, code lost:
        return r4;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:124:?, code lost:
        return r4;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:39:0x010a, code lost:
        r0 = th;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:40:0x010b, code lost:
        r2 = r17;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:41:0x010e, code lost:
        r0 = e;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:42:0x010f, code lost:
        r2 = r17;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:58:0x0152, code lost:
        r0 = th;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:59:0x0154, code lost:
        r0 = e;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:78:0x0194, code lost:
        r0 = th;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:80:0x0198, code lost:
        r0 = e;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:82:0x019c, code lost:
        r0 = th;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:83:0x019d, code lost:
        r17 = r2;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:84:0x01a0, code lost:
        r17 = r2;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:86:0x01a2, code lost:
        r4 = epson.colorcorrection.SDIC_CommonDefine.SDIC_ERR_UNKNOWN;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:88:0x01a8, code lost:
        if (r17.empty() != false) goto L_?;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:89:0x01aa, code lost:
        r17.release();
     */
    /* JADX WARNING: Code restructure failed: missing block: B:90:0x01ae, code lost:
        r17 = r2;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:92:0x01b0, code lost:
        r4 = -100;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:94:0x01b6, code lost:
        if (r17.empty() != false) goto L_?;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:95:0x01b9, code lost:
        r0 = e;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:96:0x01ba, code lost:
        r17 = r2;
     */
    /* JADX WARNING: Exception block dominator not found, dom blocks: [B:22:0x00b4, B:65:0x0160] */
    /* JADX WARNING: Failed to process nested try/catch */
    /* JADX WARNING: Removed duplicated region for block: B:100:0x01c0  */
    /* JADX WARNING: Removed duplicated region for block: B:105:0x01cd  */
    /* JADX WARNING: Removed duplicated region for block: B:119:? A[RETURN, SYNTHETIC] */
    /* JADX WARNING: Removed duplicated region for block: B:121:? A[RETURN, SYNTHETIC] */
    /* JADX WARNING: Removed duplicated region for block: B:85:? A[ExcHandler: Exception (unused java.lang.Exception), PHI: r2 
  PHI: (r2v4 org.opencv.core.Mat) = (r2v0 org.opencv.core.Mat), (r2v14 org.opencv.core.Mat), (r2v14 org.opencv.core.Mat), (r2v13 org.opencv.core.Mat) binds: [B:1:0x0009, B:55:0x0147, B:56:?, B:16:0x008e] A[DONT_GENERATE, DONT_INLINE], SYNTHETIC, Splitter:B:1:0x0009] */
    /* JADX WARNING: Removed duplicated region for block: B:87:? A[ExcHandler: Exception (unused java.lang.Exception), PHI: r17 
  PHI: (r17v13 org.opencv.core.Mat) = (r17v16 org.opencv.core.Mat), (r17v17 org.opencv.core.Mat), (r17v21 org.opencv.core.Mat) binds: [B:65:0x0160, B:53:0x0143, B:22:0x00b4] A[DONT_GENERATE, DONT_INLINE], SYNTHETIC, Splitter:B:22:0x00b4] */
    /* JADX WARNING: Removed duplicated region for block: B:91:? A[ExcHandler: CvException (unused org.opencv.core.CvException), PHI: r2 
  PHI: (r2v3 org.opencv.core.Mat) = (r2v0 org.opencv.core.Mat), (r2v14 org.opencv.core.Mat), (r2v14 org.opencv.core.Mat), (r2v13 org.opencv.core.Mat) binds: [B:1:0x0009, B:55:0x0147, B:56:?, B:16:0x008e] A[DONT_GENERATE, DONT_INLINE], SYNTHETIC, Splitter:B:1:0x0009] */
    /* JADX WARNING: Removed duplicated region for block: B:93:? A[ExcHandler: CvException (unused org.opencv.core.CvException), PHI: r17 
  PHI: (r17v12 org.opencv.core.Mat) = (r17v16 org.opencv.core.Mat), (r17v17 org.opencv.core.Mat), (r17v21 org.opencv.core.Mat) binds: [B:65:0x0160, B:53:0x0143, B:22:0x00b4] A[DONT_GENERATE, DONT_INLINE], SYNTHETIC, Splitter:B:22:0x00b4] */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    public static int MakeMask(org.opencv.core.Mat r19, epson.colorcorrection.SDIC_MAT_PTR r20, int r21) {
        /*
            r1 = r20
            r0 = r21
            org.opencv.core.Mat r2 = new org.opencv.core.Mat
            r2.<init>()
            boolean r5 = r19.empty()     // Catch:{ SDIC_Exception -> 0x01b9, CvException -> 0x01ae, Exception -> 0x01a0, all -> 0x019c }
            if (r5 != 0) goto L_0x018b
            long r5 = r19.dataAddr()     // Catch:{ SDIC_Exception -> 0x01b9, CvException -> 0x01ae, Exception -> 0x01a0, all -> 0x019c }
            long r7 = r2.dataAddr()     // Catch:{ SDIC_Exception -> 0x01b9, CvException -> 0x01ae, Exception -> 0x01a0, all -> 0x019c }
            int r9 = (r5 > r7 ? 1 : (r5 == r7 ? 0 : -1))
            if (r9 == 0) goto L_0x0182
            boolean r5 = r19.isContinuous()     // Catch:{ SDIC_Exception -> 0x01b9, CvException -> 0x01ae, Exception -> 0x01a0, all -> 0x019c }
            if (r5 == 0) goto L_0x0179
            int r5 = r19.channels()     // Catch:{ SDIC_Exception -> 0x01b9, CvException -> 0x01ae, Exception -> 0x01a0, all -> 0x019c }
            r6 = 1
            if (r5 != r6) goto L_0x0170
            boolean r5 = r2.empty()     // Catch:{ SDIC_Exception -> 0x01b9, CvException -> 0x01ae, Exception -> 0x01a0, all -> 0x019c }
            if (r5 == 0) goto L_0x0167
            if (r0 == 0) goto L_0x015e
            int r5 = r0 * 2
            int r7 = r5 + 1
            byte[] r8 = MakeBlurFilter(r0, r7)     // Catch:{ SDIC_Exception -> 0x01b9, CvException -> 0x01ae, Exception -> 0x01a0, all -> 0x019c }
            int r9 = r19.rows()     // Catch:{ SDIC_Exception -> 0x01b9, CvException -> 0x01ae, Exception -> 0x01a0, all -> 0x019c }
            int r9 = r9 + r5
            int r10 = r19.cols()     // Catch:{ SDIC_Exception -> 0x01b9, CvException -> 0x01ae, Exception -> 0x01a0, all -> 0x019c }
            int r10 = r10 + r5
            int r5 = org.opencv.core.CvType.CV_8UC1     // Catch:{ SDIC_Exception -> 0x01b9, CvException -> 0x01ae, Exception -> 0x01a0, all -> 0x019c }
            org.opencv.core.Mat r5 = org.opencv.core.Mat.zeros(r9, r10, r5)     // Catch:{ SDIC_Exception -> 0x01b9, CvException -> 0x01ae, Exception -> 0x01a0, all -> 0x019c }
            org.opencv.core.Rect r9 = new org.opencv.core.Rect     // Catch:{ SDIC_Exception -> 0x01b9, CvException -> 0x01ae, Exception -> 0x01a0, all -> 0x019c }
            int r10 = r19.cols()     // Catch:{ SDIC_Exception -> 0x01b9, CvException -> 0x01ae, Exception -> 0x01a0, all -> 0x019c }
            int r11 = r19.rows()     // Catch:{ SDIC_Exception -> 0x01b9, CvException -> 0x01ae, Exception -> 0x01a0, all -> 0x019c }
            r9.<init>(r0, r0, r10, r11)     // Catch:{ SDIC_Exception -> 0x01b9, CvException -> 0x01ae, Exception -> 0x01a0, all -> 0x019c }
            org.opencv.core.Mat r9 = r5.submat(r9)     // Catch:{ SDIC_Exception -> 0x01b9, CvException -> 0x01ae, Exception -> 0x01a0, all -> 0x019c }
            r10 = r19
            r10.copyTo(r9)     // Catch:{ SDIC_Exception -> 0x01b9, CvException -> 0x01ae, Exception -> 0x01a0, all -> 0x019c }
            java.util.ArrayList r11 = new java.util.ArrayList     // Catch:{ SDIC_Exception -> 0x01b9, CvException -> 0x01ae, Exception -> 0x01a0, all -> 0x019c }
            r11.<init>()     // Catch:{ SDIC_Exception -> 0x01b9, CvException -> 0x01ae, Exception -> 0x01a0, all -> 0x019c }
            org.opencv.core.Mat r12 = new org.opencv.core.Mat     // Catch:{ SDIC_Exception -> 0x01b9, CvException -> 0x01ae, Exception -> 0x01a0, all -> 0x019c }
            r12.<init>()     // Catch:{ SDIC_Exception -> 0x01b9, CvException -> 0x01ae, Exception -> 0x01a0, all -> 0x019c }
            org.opencv.core.Mat r13 = r5.clone()     // Catch:{ SDIC_Exception -> 0x01b9, CvException -> 0x01ae, Exception -> 0x01a0, all -> 0x019c }
            org.opencv.imgproc.Imgproc.findContours(r13, r11, r12, r6, r6)     // Catch:{ SDIC_Exception -> 0x01b9, CvException -> 0x01ae, Exception -> 0x01a0, all -> 0x019c }
            r13.release()     // Catch:{ SDIC_Exception -> 0x01b9, CvException -> 0x01ae, Exception -> 0x01a0, all -> 0x019c }
            r12.release()     // Catch:{ SDIC_Exception -> 0x01b9, CvException -> 0x01ae, Exception -> 0x01a0, all -> 0x019c }
            org.opencv.core.Size r12 = r19.size()     // Catch:{ SDIC_Exception -> 0x01b9, CvException -> 0x01ae, Exception -> 0x01a0, all -> 0x019c }
            double r12 = r12.width     // Catch:{ SDIC_Exception -> 0x01b9, CvException -> 0x01ae, Exception -> 0x01a0, all -> 0x019c }
            int r12 =  r12     // Catch:{ SDIC_Exception -> 0x01b9, CvException -> 0x01ae, Exception -> 0x01a0, all -> 0x019c }
            int r12 = r12 + r0
            int r12 = r12 - r6
            org.opencv.core.Size r10 = r19.size()     // Catch:{ SDIC_Exception -> 0x01b9, CvException -> 0x01ae, Exception -> 0x01a0, all -> 0x019c }
            double r13 = r10.height     // Catch:{ SDIC_Exception -> 0x01b9, CvException -> 0x01ae, Exception -> 0x01a0, all -> 0x019c }
            int r10 =  r13     // Catch:{ SDIC_Exception -> 0x01b9, CvException -> 0x01ae, Exception -> 0x01a0, all -> 0x019c }
            int r10 = r10 + r0
            int r10 = r10 - r6
            int r6 = r11.size()     // Catch:{ SDIC_Exception -> 0x01b9, CvException -> 0x01ae, Exception -> 0x01a0, all -> 0x019c }
            r13 = 0
        L_0x008c:
            if (r13 >= r6) goto L_0x0140
            java.lang.Object r14 = r11.get(r13)     // Catch:{ SDIC_Exception -> 0x0139, CvException -> 0x01ae, Exception -> 0x01a0, all -> 0x0132 }
            org.opencv.core.MatOfPoint r14 = (org.opencv.core.MatOfPoint) r14     // Catch:{ SDIC_Exception -> 0x0139, CvException -> 0x01ae, Exception -> 0x01a0, all -> 0x0132 }
            java.util.List r14 = r14.toList()     // Catch:{ SDIC_Exception -> 0x0139, CvException -> 0x01ae, Exception -> 0x01a0, all -> 0x0132 }
            int r15 = r14.size()     // Catch:{ SDIC_Exception -> 0x0139, CvException -> 0x01ae, Exception -> 0x01a0, all -> 0x0132 }
            r3 = 0
        L_0x009d:
            if (r3 >= r15) goto L_0x0125
            java.lang.Object r16 = r14.get(r3)     // Catch:{ SDIC_Exception -> 0x0139, CvException -> 0x01ae, Exception -> 0x01a0, all -> 0x0132 }
            r4 = r16
            org.opencv.core.Point r4 = (org.opencv.core.Point) r4     // Catch:{ SDIC_Exception -> 0x0139, CvException -> 0x01ae, Exception -> 0x01a0, all -> 0x0132 }
            r19 = r14
            r16 = r15
            double r14 = r4.f432x     // Catch:{ SDIC_Exception -> 0x0139, CvException -> 0x01ae, Exception -> 0x01a0, all -> 0x0132 }
            r17 = r2
            double r1 =  r0
            int r18 = (r14 > r1 ? 1 : (r14 == r1 ? 0 : -1))
            if (r18 == 0) goto L_0x0112
            double r14 = r4.f433y     // Catch:{ SDIC_Exception -> 0x010e, CvException -> 0x01b0, Exception -> 0x01a2, all -> 0x010a }
            int r18 = (r14 > r1 ? 1 : (r14 == r1 ? 0 : -1))
            if (r18 == 0) goto L_0x0112
            double r1 = r4.f432x     // Catch:{ SDIC_Exception -> 0x010e, CvException -> 0x01b0, Exception -> 0x01a2, all -> 0x010a }
            double r14 =  r12     // Catch:{ SDIC_Exception -> 0x010e, CvException -> 0x01b0, Exception -> 0x01a2, all -> 0x010a }
            int r18 = (r1 > r14 ? 1 : (r1 == r14 ? 0 : -1))
            if (r18 == 0) goto L_0x0112
            double r1 = r4.f433y     // Catch:{ SDIC_Exception -> 0x010e, CvException -> 0x01b0, Exception -> 0x01a2, all -> 0x010a }
            double r14 =  r10     // Catch:{ SDIC_Exception -> 0x010e, CvException -> 0x01b0, Exception -> 0x01a2, all -> 0x010a }
            int r18 = (r1 > r14 ? 1 : (r1 == r14 ? 0 : -1))
            if (r18 == 0) goto L_0x0112
            org.opencv.core.Rect r1 = new org.opencv.core.Rect     // Catch:{ SDIC_Exception -> 0x010e, CvException -> 0x01b0, Exception -> 0x01a2, all -> 0x010a }
            double r14 = r4.f432x     // Catch:{ SDIC_Exception -> 0x010e, CvException -> 0x01b0, Exception -> 0x01a2, all -> 0x010a }
            int r2 =  r14     // Catch:{ SDIC_Exception -> 0x010e, CvException -> 0x01b0, Exception -> 0x01a2, all -> 0x010a }
            int r2 = r2 - r0
            double r14 = r4.f433y     // Catch:{ SDIC_Exception -> 0x010e, CvException -> 0x01b0, Exception -> 0x01a2, all -> 0x010a }
            int r4 =  r14     // Catch:{ SDIC_Exception -> 0x010e, CvException -> 0x01b0, Exception -> 0x01a2, all -> 0x010a }
            int r4 = r4 - r0
            r1.<init>(r2, r4, r7, r7)     // Catch:{ SDIC_Exception -> 0x010e, CvException -> 0x01b0, Exception -> 0x01a2, all -> 0x010a }
            org.opencv.core.Mat r1 = r5.submat(r1)     // Catch:{ SDIC_Exception -> 0x010e, CvException -> 0x01b0, Exception -> 0x01a2, all -> 0x010a }
            byte[] r2 = GetPixcelData(r1)     // Catch:{ SDIC_Exception -> 0x010e, CvException -> 0x01b0, Exception -> 0x01a2, all -> 0x010a }
            r4 = 0
        L_0x00de:
            if (r4 >= r7) goto L_0x0103
            r14 = 0
        L_0x00e1:
            if (r14 >= r7) goto L_0x00fc
            int r15 = r7 * r4
            int r15 = r15 + r14
            byte r0 = r8[r15]     // Catch:{ SDIC_Exception -> 0x010e, CvException -> 0x01b0, Exception -> 0x01a2, all -> 0x010a }
            r0 = r0 & 255(0xff, float:3.57E-43)
            r18 = r6
            byte r6 = r2[r15]     // Catch:{ SDIC_Exception -> 0x010e, CvException -> 0x01b0, Exception -> 0x01a2, all -> 0x010a }
            r6 = r6 & 255(0xff, float:3.57E-43)
            if (r6 <= r0) goto L_0x00f5
            byte r0 = (byte) r0     // Catch:{ SDIC_Exception -> 0x010e, CvException -> 0x01b0, Exception -> 0x01a2, all -> 0x010a }
            r2[r15] = r0     // Catch:{ SDIC_Exception -> 0x010e, CvException -> 0x01b0, Exception -> 0x01a2, all -> 0x010a }
        L_0x00f5:
            int r14 = r14 + 1
            r6 = r18
            r0 = r21
            goto L_0x00e1
        L_0x00fc:
            r18 = r6
            int r4 = r4 + 1
            r0 = r21
            goto L_0x00de
        L_0x0103:
            r18 = r6
            r0 = 0
            PutPixcelData(r1, r0, r0, r2)     // Catch:{ SDIC_Exception -> 0x010e, CvException -> 0x01b0, Exception -> 0x01a2, all -> 0x010a }
            goto L_0x0115
        L_0x010a:
            r0 = move-exception
            r2 = r17
            goto L_0x0135
        L_0x010e:
            r0 = move-exception
            r2 = r17
            goto L_0x013c
        L_0x0112:
            r18 = r6
            r0 = 0
        L_0x0115:
            int r3 = r3 + 1
            r14 = r19
            r15 = r16
            r2 = r17
            r6 = r18
            r0 = r21
            r1 = r20
            goto L_0x009d
        L_0x0125:
            r17 = r2
            r18 = r6
            r0 = 0
            int r13 = r13 + 1
            r0 = r21
            r1 = r20
            goto L_0x008c
        L_0x0132:
            r0 = move-exception
            r17 = r2
        L_0x0135:
            r1 = r20
            goto L_0x01d2
        L_0x0139:
            r0 = move-exception
            r17 = r2
        L_0x013c:
            r1 = r20
            goto L_0x01bc
        L_0x0140:
            r17 = r2
            r0 = 0
            org.opencv.core.Mat r2 = r9.clone()     // Catch:{ SDIC_Exception -> 0x015a, CvException -> 0x01b0, Exception -> 0x01a2, all -> 0x0156 }
            r5.release()     // Catch:{ SDIC_Exception -> 0x0154, CvException -> 0x01ae, Exception -> 0x01a0, all -> 0x0152 }
            r1 = r20
            r1.setMat(r2)
            r4 = 0
            goto L_0x01d0
        L_0x0152:
            r0 = move-exception
            goto L_0x0135
        L_0x0154:
            r0 = move-exception
            goto L_0x013c
        L_0x0156:
            r0 = move-exception
            r1 = r20
            goto L_0x0195
        L_0x015a:
            r0 = move-exception
            r1 = r20
            goto L_0x0199
        L_0x015e:
            r17 = r2
            epson.colorcorrection.SDIC_Exception r0 = new epson.colorcorrection.SDIC_Exception     // Catch:{ SDIC_Exception -> 0x0198, CvException -> 0x01b0, Exception -> 0x01a2, all -> 0x0194 }
            r2 = -7
            r0.<init>(r2)     // Catch:{ SDIC_Exception -> 0x0198, CvException -> 0x01b0, Exception -> 0x01a2, all -> 0x0194 }
            throw r0     // Catch:{ SDIC_Exception -> 0x0198, CvException -> 0x01b0, Exception -> 0x01a2, all -> 0x0194 }
        L_0x0167:
            r17 = r2
            epson.colorcorrection.SDIC_Exception r0 = new epson.colorcorrection.SDIC_Exception     // Catch:{ SDIC_Exception -> 0x0198, CvException -> 0x01b0, Exception -> 0x01a2, all -> 0x0194 }
            r2 = -6
            r0.<init>(r2)     // Catch:{ SDIC_Exception -> 0x0198, CvException -> 0x01b0, Exception -> 0x01a2, all -> 0x0194 }
            throw r0     // Catch:{ SDIC_Exception -> 0x0198, CvException -> 0x01b0, Exception -> 0x01a2, all -> 0x0194 }
        L_0x0170:
            r17 = r2
            epson.colorcorrection.SDIC_Exception r0 = new epson.colorcorrection.SDIC_Exception     // Catch:{ SDIC_Exception -> 0x0198, CvException -> 0x01b0, Exception -> 0x01a2, all -> 0x0194 }
            r2 = -4
            r0.<init>(r2)     // Catch:{ SDIC_Exception -> 0x0198, CvException -> 0x01b0, Exception -> 0x01a2, all -> 0x0194 }
            throw r0     // Catch:{ SDIC_Exception -> 0x0198, CvException -> 0x01b0, Exception -> 0x01a2, all -> 0x0194 }
        L_0x0179:
            r17 = r2
            epson.colorcorrection.SDIC_Exception r0 = new epson.colorcorrection.SDIC_Exception     // Catch:{ SDIC_Exception -> 0x0198, CvException -> 0x01b0, Exception -> 0x01a2, all -> 0x0194 }
            r2 = -3
            r0.<init>(r2)     // Catch:{ SDIC_Exception -> 0x0198, CvException -> 0x01b0, Exception -> 0x01a2, all -> 0x0194 }
            throw r0     // Catch:{ SDIC_Exception -> 0x0198, CvException -> 0x01b0, Exception -> 0x01a2, all -> 0x0194 }
        L_0x0182:
            r17 = r2
            epson.colorcorrection.SDIC_Exception r0 = new epson.colorcorrection.SDIC_Exception     // Catch:{ SDIC_Exception -> 0x0198, CvException -> 0x01b0, Exception -> 0x01a2, all -> 0x0194 }
            r2 = -1
            r0.<init>(r2)     // Catch:{ SDIC_Exception -> 0x0198, CvException -> 0x01b0, Exception -> 0x01a2, all -> 0x0194 }
            throw r0     // Catch:{ SDIC_Exception -> 0x0198, CvException -> 0x01b0, Exception -> 0x01a2, all -> 0x0194 }
        L_0x018b:
            r17 = r2
            epson.colorcorrection.SDIC_Exception r0 = new epson.colorcorrection.SDIC_Exception     // Catch:{ SDIC_Exception -> 0x0198, CvException -> 0x01b0, Exception -> 0x01a2, all -> 0x0194 }
            r2 = -2
            r0.<init>(r2)     // Catch:{ SDIC_Exception -> 0x0198, CvException -> 0x01b0, Exception -> 0x01a2, all -> 0x0194 }
            throw r0     // Catch:{ SDIC_Exception -> 0x0198, CvException -> 0x01b0, Exception -> 0x01a2, all -> 0x0194 }
        L_0x0194:
            r0 = move-exception
        L_0x0195:
            r2 = r17
            goto L_0x01d2
        L_0x0198:
            r0 = move-exception
        L_0x0199:
            r2 = r17
            goto L_0x01bc
        L_0x019c:
            r0 = move-exception
            r17 = r2
            goto L_0x01d2
        L_0x01a0:
            r17 = r2
        L_0x01a2:
            r4 = -400(0xfffffffffffffe70, float:NaN)
            boolean r0 = r17.empty()
            if (r0 != 0) goto L_0x01d0
        L_0x01aa:
            r17.release()
            goto L_0x01d0
        L_0x01ae:
            r17 = r2
        L_0x01b0:
            r4 = -100
            boolean r0 = r17.empty()
            if (r0 != 0) goto L_0x01d0
            goto L_0x01aa
        L_0x01b9:
            r0 = move-exception
            r17 = r2
        L_0x01bc:
            int r4 = r0.mCode     // Catch:{ all -> 0x01d1 }
            if (r4 == 0) goto L_0x01cd
            boolean r0 = r2.empty()
            if (r0 != 0) goto L_0x01d0
            r1 = -1
            if (r4 == r1) goto L_0x01d0
            r2.release()
            goto L_0x01d0
        L_0x01cd:
            r1.setMat(r2)
        L_0x01d0:
            return r4
        L_0x01d1:
            r0 = move-exception
        L_0x01d2:
            r1.setMat(r2)
            throw r0
        */
        throw new UnsupportedOperationException("Method not decompiled: epson.colorcorrection.SDIC_BCSC.MakeMask(org.opencv.core.Mat, epson.colorcorrection.SDIC_MAT_PTR, int):int");
    }

    private static int Brightness(Mat mat, Mat mat2, Mat mat3, double d) {
        if (d < 0.0010000000474974513d && d > -0.0010000000474974513d) {
            return 0;
        }
        if (d > 1.0d || d < -1.0d) {
            return -7;
        }
        byte[] GetPixcelData = GetPixcelData(mat2);
        byte[] GetPixcelData2 = GetPixcelData(mat);
        byte[] GetPixcelData3 = GetPixcelData(mat);
        int channels = mat.channels();
        int i = (mat.total()) * channels;
        int i2 = 0;
        int i3 = 0;
        while (i2 < i) {
            byte b = GetPixcelData[i3] & UnsignedBytes.MAX_VALUE;
            if (b > 0) {
                int i4 = ((b) * d);
                for (int i5 = 0; i5 < 3; i5++) {
                    int i6 = i2 + i5;
                    int i7 = (GetPixcelData2[i6] & UnsignedBytes.MAX_VALUE) + i4;
                    if (i7 > 255) {
                        i7 = 255;
                    }
                    if (i7 < 0) {
                        i7 = 0;
                    }
                    GetPixcelData3[i6] = (byte) i7;
                }
            }
            i2 += channels;
            i3++;
        }
        mat3.put(0, 0, GetPixcelData3);
        return 0;
    }

    private static int Contrast(Mat mat, Mat mat2, Mat mat3, double d) {
        double d2;
        Mat mat4 = mat;
        Mat mat5 = mat3;
        if (d > 1.0d || d < 0.0d) {
            return -7;
        }
        if (d < 0.0010000000474974513d) {
            mat4.copyTo(mat5);
            return 0;
        }
        Mat mat6 = new Mat();
        if (mat.channels() == 3) {
            Imgproc.cvtColor(mat4, mat6, 6);
        } else if (mat.channels() != 4) {
            return -4;
        } else {
            Imgproc.cvtColor(mat4, mat6, 10);
        }
        Mat mat7 = new Mat();
        Mat mat8 = new Mat();
        Core.reduce(mat6, mat7, 1, 1);
        mat6.release();
        Core.reduce(mat7, mat8, 0, 1);
        mat7.release();
        MatOfByte matOfByte = new MatOfByte(mat8);
        byte b = matOfByte.toArray()[0];
        byte b2 = UnsignedBytes.MAX_VALUE;
        byte b3 = b & UnsignedBytes.MAX_VALUE;
        mat8.release();
        matOfByte.release();
        int i = 256;
        double[] dArr = new double[256];
        int[] iArr = new int[256];
        double d3 = 20.0d * d;
        int i2 = 0;
        while (true) {
            d2 = 255.0d;
            if (i2 >= i) {
                break;
            }
            dArr[i2] = 1.0d / (Math.exp((((b3 - i2)) * d3) / 255.0d) + 1.0d);
            i2++;
            b3 = b3;
            i = 256;
        }
        double d4 = dArr[0];
        double d5 = dArr[255] - d4;
        for (int i3 = 0; i3 < 256; i3++) {
            iArr[i3] = (((((dArr[i3] - d4) / d5) * 255.0d) + 0.5d)) & 255;
        }
        byte[] GetPixcelData = GetPixcelData(mat2);
        byte[] GetPixcelData2 = GetPixcelData(mat);
        byte[] GetPixcelData3 = GetPixcelData(mat);
        int channels = mat.channels();
        int i4 = (mat.total()) * channels;
        int i5 = 0;
        int i6 = 0;
        while (i5 < i4) {
            byte b4 = GetPixcelData[i6] & b2;
            if (b4 > 0) {
                double d6 = (b4) / d2;
                int i7 = 0;
                while (i7 < 3) {
                    int i8 = i5 + i7;
                    byte b5 = GetPixcelData2[i8] & b2;
                    int i9 = iArr[b5] - b5;
                    int[] iArr2 = iArr;
                    double d7 = b5;
                    byte[] bArr = GetPixcelData;
                    byte[] bArr2 = GetPixcelData2;
                    int i10 = (d7 + ((i9) * d6));
                    int i11 = i10 > 255 ? 255 : i10;
                    if (i11 < 0) {
                        i11 = 0;
                    }
                    GetPixcelData3[i8] = (byte) i11;
                    i7++;
                    GetPixcelData = bArr;
                    GetPixcelData2 = bArr2;
                    iArr = iArr2;
                    b2 = UnsignedBytes.MAX_VALUE;
                }
            }
            i5 += channels;
            i6++;
            GetPixcelData = GetPixcelData;
            GetPixcelData2 = GetPixcelData2;
            iArr = iArr;
            b2 = UnsignedBytes.MAX_VALUE;
            d2 = 255.0d;
        }
        mat5.put(0, 0, GetPixcelData3);
        return 0;
    }

    /* JADX WARNING: Removed duplicated region for block: B:101:0x0184  */
    /* JADX WARNING: Removed duplicated region for block: B:96:0x0175  */
    /* JADX WARNING: Removed duplicated region for block: B:98:0x017a  */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    private static int Saturation(org.opencv.core.Mat r21, org.opencv.core.Mat r22, org.opencv.core.Mat r23, double r24) {
        /*
            r0 = r21
            r1 = r23
            org.opencv.core.Mat r2 = new org.opencv.core.Mat
            r2.<init>()
            org.opencv.core.Mat r3 = new org.opencv.core.Mat
            r3.<init>()
            r4 = 4562254509136412672(0x3f50624de0000000, double:0.0010000000474974513)
            r6 = 0
            int r7 = (r24 > r4 ? 1 : (r24 == r4 ? 0 : -1))
            if (r7 >= 0) goto L_0x002f
            r4 = -4661117527718363136(0xbf50624de0000000, double:-0.0010000000474974513)
            int r7 = (r24 > r4 ? 1 : (r24 == r4 ? 0 : -1))
            if (r7 <= 0) goto L_0x002f
            r0.copyTo(r1)     // Catch:{ SDIC_Exception -> 0x002b, CvException -> 0x0028, Exception -> 0x0025 }
            return r6
        L_0x0025:
            r1 = r3
            goto L_0x0166
        L_0x0028:
            r1 = r3
            goto L_0x0169
        L_0x002b:
            r0 = move-exception
            r1 = r3
            goto L_0x016d
        L_0x002f:
            r4 = 4607182418800017408(0x3ff0000000000000, double:1.0)
            int r7 = (r24 > r4 ? 1 : (r24 == r4 ? 0 : -1))
            if (r7 > 0) goto L_0x015e
            r4 = -4616189618054758400(0xbff0000000000000, double:-1.0)
            int r7 = (r24 > r4 ? 1 : (r24 == r4 ? 0 : -1))
            if (r7 < 0) goto L_0x015e
            int r4 = r21.channels()     // Catch:{ SDIC_Exception -> 0x002b, CvException -> 0x0028, Exception -> 0x0025 }
            r5 = 4
            r7 = 40
            r8 = 3
            r9 = 1
            if (r4 != r8) goto L_0x004a
            org.opencv.imgproc.Imgproc.cvtColor(r0, r2, r7)     // Catch:{ SDIC_Exception -> 0x002b, CvException -> 0x0028, Exception -> 0x0025 }
            goto L_0x005e
        L_0x004a:
            int r4 = r21.channels()     // Catch:{ SDIC_Exception -> 0x002b, CvException -> 0x0028, Exception -> 0x0025 }
            if (r4 != r5) goto L_0x0156
            org.opencv.core.Mat r4 = new org.opencv.core.Mat     // Catch:{ SDIC_Exception -> 0x002b, CvException -> 0x0028, Exception -> 0x0025 }
            r4.<init>()     // Catch:{ SDIC_Exception -> 0x002b, CvException -> 0x0028, Exception -> 0x0025 }
            org.opencv.imgproc.Imgproc.cvtColor(r0, r4, r9)     // Catch:{ SDIC_Exception -> 0x002b, CvException -> 0x0028, Exception -> 0x0025 }
            org.opencv.imgproc.Imgproc.cvtColor(r4, r2, r7)     // Catch:{ SDIC_Exception -> 0x002b, CvException -> 0x0028, Exception -> 0x0025 }
            r4.release()     // Catch:{ SDIC_Exception -> 0x002b, CvException -> 0x0028, Exception -> 0x0025 }
        L_0x005e:
            long r10 = r21.total()     // Catch:{ SDIC_Exception -> 0x002b, CvException -> 0x0028, Exception -> 0x0025 }
            r12 = 3
            long r10 = r10 * r12
            int r4 =  r10     // Catch:{ SDIC_Exception -> 0x002b, CvException -> 0x0028, Exception -> 0x0025 }
            r10 = 4643176031446892544(0x406fe00000000000, double:255.0)
            double r12 = r24 / r10
            byte[] r7 = GetPixcelData(r22)     // Catch:{ SDIC_Exception -> 0x002b, CvException -> 0x0028, Exception -> 0x0025 }
            byte[] r14 = GetPixcelData(r2)     // Catch:{ SDIC_Exception -> 0x002b, CvException -> 0x0028, Exception -> 0x0025 }
            r2.release()     // Catch:{ SDIC_Exception -> 0x002b, CvException -> 0x0028, Exception -> 0x0025 }
            r15 = 0
            r2 = 255(0xff, float:3.57E-43)
            int r17 = (r24 > r15 ? 1 : (r24 == r15 ? 0 : -1))
            if (r17 <= 0) goto L_0x00c0
            r15 = 0
        L_0x0082:
            if (r9 >= r4) goto L_0x00be
            byte r6 = r7[r15]     // Catch:{ SDIC_Exception -> 0x0114, CvException -> 0x0112, Exception -> 0x0110 }
            r6 = r6 & r2
            if (r6 <= 0) goto L_0x00b2
            byte r5 = r14[r9]     // Catch:{ SDIC_Exception -> 0x0114, CvException -> 0x0112, Exception -> 0x0110 }
            r5 = r5 & r2
            int r18 = r9 + 1
            byte r8 = r14[r18]     // Catch:{ SDIC_Exception -> 0x0114, CvException -> 0x0112, Exception -> 0x0110 }
            r8 = r8 & r2
            double r10 =  r6     // Catch:{ SDIC_Exception -> 0x0114, CvException -> 0x0112, Exception -> 0x0110 }
            double r10 = r10 * r12
            double r0 =  r5     // Catch:{ SDIC_Exception -> 0x0114, CvException -> 0x0112, Exception -> 0x0110 }
            int r5 = 255 - r5
            int r6 = 255 - r8
            int r5 = r5 * r6
            double r5 =  r5     // Catch:{ SDIC_Exception -> 0x0114, CvException -> 0x0112, Exception -> 0x0110 }
            double r5 = r5 * r10
            r10 = 4643176031446892544(0x406fe00000000000, double:255.0)
            double r5 = r5 / r10
            double r0 = r0 + r5
            int r0 =  r0     // Catch:{ SDIC_Exception -> 0x0114, CvException -> 0x0112, Exception -> 0x0110 }
            if (r0 <= r2) goto L_0x00ab
            r6 = 255(0xff, float:3.57E-43)
            goto L_0x00ac
        L_0x00ab:
            r6 = r0
        L_0x00ac:
            if (r6 >= 0) goto L_0x00af
            r6 = 0
        L_0x00af:
            byte r0 = (byte) r6     // Catch:{ SDIC_Exception -> 0x0114, CvException -> 0x0112, Exception -> 0x0110 }
            r14[r9] = r0     // Catch:{ SDIC_Exception -> 0x0114, CvException -> 0x0112, Exception -> 0x0110 }
        L_0x00b2:
            int r9 = r9 + 3
            int r15 = r15 + 1
            r0 = r21
            r1 = r23
            r5 = 4
            r6 = 0
            r8 = 3
            goto L_0x0082
        L_0x00be:
            r1 = r3
            goto L_0x0118
        L_0x00c0:
            r0 = 0
        L_0x00c1:
            if (r9 >= r4) goto L_0x0117
            byte r1 = r7[r0]     // Catch:{ SDIC_Exception -> 0x0114, CvException -> 0x0112, Exception -> 0x0110 }
            r1 = r1 & r2
            if (r1 <= 0) goto L_0x0103
            byte r5 = r14[r9]     // Catch:{ SDIC_Exception -> 0x0114, CvException -> 0x0112, Exception -> 0x0110 }
            r5 = r5 & r2
            int r6 = r9 + 1
            byte r8 = r14[r6]     // Catch:{ SDIC_Exception -> 0x0114, CvException -> 0x0112, Exception -> 0x0110 }
            r8 = r8 & r2
            double r10 =  r1
            double r10 = r10 * r12
            r1 = r3
            double r2 =  r5
            double r19 = r2 * r10
            double r2 = r2 + r19
            int r2 =  r2
            r3 = 255(0xff, float:3.57E-43)
            if (r2 <= r3) goto L_0x00e0
            r2 = 255(0xff, float:3.57E-43)
        L_0x00e0:
            if (r2 >= 0) goto L_0x00e3
            r2 = 0
        L_0x00e3:
            byte r2 = (byte) r2
            r14[r9] = r2     // Catch:{ SDIC_Exception -> 0x0153, CvException -> 0x0151, Exception -> 0x014f }
            double r2 =  r8     // Catch:{ SDIC_Exception -> 0x0153, CvException -> 0x0151, Exception -> 0x014f }
            int r5 = r5 * r8
            r8 = r4
            double r4 =  r5     // Catch:{ SDIC_Exception -> 0x0153, CvException -> 0x0151, Exception -> 0x014f }
            r19 = 4647679631074263040(0x407fe00000000000, double:510.0)
            double r4 = r4 / r19
            double r4 = r4 * r10
            double r2 = r2 + r4
            int r2 =  r2     // Catch:{ SDIC_Exception -> 0x0153, CvException -> 0x0151, Exception -> 0x014f }
            r3 = 255(0xff, float:3.57E-43)
            if (r2 <= r3) goto L_0x00fc
            r2 = 255(0xff, float:3.57E-43)
        L_0x00fc:
            if (r2 >= 0) goto L_0x00ff
            r2 = 0
        L_0x00ff:
            byte r2 = (byte) r2     // Catch:{ SDIC_Exception -> 0x0153, CvException -> 0x0151, Exception -> 0x014f }
            r14[r6] = r2     // Catch:{ SDIC_Exception -> 0x0153, CvException -> 0x0151, Exception -> 0x014f }
            goto L_0x0107
        L_0x0103:
            r1 = r3
            r8 = r4
            r3 = 255(0xff, float:3.57E-43)
        L_0x0107:
            int r9 = r9 + 3
            int r0 = r0 + 1
            r3 = r1
            r4 = r8
            r2 = 255(0xff, float:3.57E-43)
            goto L_0x00c1
        L_0x0110:
            r1 = r3
            goto L_0x014f
        L_0x0112:
            r1 = r3
            goto L_0x0151
        L_0x0114:
            r0 = move-exception
            r1 = r3
            goto L_0x0154
        L_0x0117:
            r1 = r3
        L_0x0118:
            int r0 = r21.rows()     // Catch:{ SDIC_Exception -> 0x0153, CvException -> 0x0151, Exception -> 0x014f }
            int r2 = r21.cols()     // Catch:{ SDIC_Exception -> 0x0153, CvException -> 0x0151, Exception -> 0x014f }
            int r3 = r21.type()     // Catch:{ SDIC_Exception -> 0x0153, CvException -> 0x0151, Exception -> 0x014f }
            org.opencv.core.Mat r2 = SetPixcelData(r0, r2, r3, r14)     // Catch:{ SDIC_Exception -> 0x0153, CvException -> 0x0151, Exception -> 0x014f }
            r0 = 54
            org.opencv.imgproc.Imgproc.cvtColor(r2, r1, r0)     // Catch:{ SDIC_Exception -> 0x016c, CvException -> 0x0169, Exception -> 0x0166 }
            int r0 = r21.channels()     // Catch:{ SDIC_Exception -> 0x016c, CvException -> 0x0169, Exception -> 0x0166 }
            r3 = 3
            if (r0 != r3) goto L_0x013d
            r2.release()     // Catch:{ SDIC_Exception -> 0x016c, CvException -> 0x0169, Exception -> 0x0166 }
            org.opencv.core.Mat r2 = r1.clone()     // Catch:{ SDIC_Exception -> 0x016c, CvException -> 0x0169, Exception -> 0x0166 }
            r0 = 0
            goto L_0x014d
        L_0x013d:
            int r0 = r21.channels()     // Catch:{ SDIC_Exception -> 0x016c, CvException -> 0x0169, Exception -> 0x0166 }
            r3 = 4
            if (r0 != r3) goto L_0x014c
            r2.release()     // Catch:{ SDIC_Exception -> 0x016c, CvException -> 0x0169, Exception -> 0x0166 }
            r0 = 0
            org.opencv.imgproc.Imgproc.cvtColor(r1, r2, r0)     // Catch:{ SDIC_Exception -> 0x016c, CvException -> 0x0169, Exception -> 0x0166 }
            goto L_0x014d
        L_0x014c:
            r0 = 0
        L_0x014d:
            r6 = 0
            goto L_0x016f
        L_0x014f:
            r2 = 0
            goto L_0x0166
        L_0x0151:
            r2 = 0
            goto L_0x0169
        L_0x0153:
            r0 = move-exception
        L_0x0154:
            r2 = 0
            goto L_0x016d
        L_0x0156:
            r1 = r3
            epson.colorcorrection.SDIC_Exception r0 = new epson.colorcorrection.SDIC_Exception     // Catch:{ SDIC_Exception -> 0x016c, CvException -> 0x0169, Exception -> 0x0166 }
            r3 = -4
            r0.<init>(r3)     // Catch:{ SDIC_Exception -> 0x016c, CvException -> 0x0169, Exception -> 0x0166 }
            throw r0     // Catch:{ SDIC_Exception -> 0x016c, CvException -> 0x0169, Exception -> 0x0166 }
        L_0x015e:
            r1 = r3
            epson.colorcorrection.SDIC_Exception r0 = new epson.colorcorrection.SDIC_Exception     // Catch:{ SDIC_Exception -> 0x016c, CvException -> 0x0169, Exception -> 0x0166 }
            r3 = -7
            r0.<init>(r3)     // Catch:{ SDIC_Exception -> 0x016c, CvException -> 0x0169, Exception -> 0x0166 }
            throw r0     // Catch:{ SDIC_Exception -> 0x016c, CvException -> 0x0169, Exception -> 0x0166 }
        L_0x0166:
            r6 = -400(0xfffffffffffffe70, float:NaN)
            goto L_0x016f
        L_0x0169:
            r6 = -100
            goto L_0x016f
        L_0x016c:
            r0 = move-exception
        L_0x016d:
            int r6 = r0.mCode
        L_0x016f:
            boolean r0 = r1.empty()
            if (r0 != 0) goto L_0x0178
            r1.release()
        L_0x0178:
            if (r6 == 0) goto L_0x0184
            boolean r0 = r2.empty()
            if (r0 != 0) goto L_0x018c
            r2.release()
            goto L_0x018c
        L_0x0184:
            r1 = r23
            r2.copyTo(r1)
            r2.release()
        L_0x018c:
            return r6
        */
        throw new UnsupportedOperationException("Method not decompiled: epson.colorcorrection.SDIC_BCSC.Saturation(org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Mat, double):int");
    }

    private static int CheckImage(Mat mat, Mat mat2) {
        if (mat.empty() || mat2.empty()) {
            return -2;
        }
        if (!mat.isContinuous() || !mat2.isContinuous()) {
            return -3;
        }
        if (mat2.size().width != mat.size().width || mat2.size().height != mat.size().height) {
            return -5;
        }
        if (mat2.channels() == 1) {
            return (mat.channels() == 3 || mat.channels() == 4) ? 0 : -4;
        }
        return -4;
    }

    private static double LengthBw2Point(Point point, Point point2) {
        double d = point2.f432x - point.f432x;
        double d2 = point2.f433y - point.f433y;
        return Math.sqrt((d * d) + (d2 * d2));
    }

    private static byte[] MakeBlurFilter(int i, int i2) {
        byte[] bArr = new byte[(i2 * i2)];
        double d = i;
        Point point = new Point(d, d);
        for (int i3 = 0; i3 < i2; i3++) {
            for (int i4 = 0; i4 < i2; i4++) {
                double LengthBw2Point = LengthBw2Point(new Point(i4, i3), point);
                double d2 = i2;
                if (LengthBw2Point > d2) {
                    LengthBw2Point = d2;
                }
                bArr[(i3 * i2) + i4] = (byte) (((((LengthBw2Point / d2) * 255.0d) + 0.5d)) & 255);
            }
        }
        return bArr;
    }

    private static void PutPixcelData(Mat mat, int i, int i2, byte[] bArr) {
        mat.put(i, i2, bArr);
    }

    public static Mat SetPixcelData(int i, int i2, int i3, byte[] bArr) {
        Mat mat = new Mat(i, i2, i3);
        mat.put(0, 0, bArr);
        return mat;
    }

    public static byte[] GetPixcelData(Mat mat) {
        byte[] bArr = new byte[(mat.rows() * mat.cols() * mat.channels())];
        mat.get(0, 0, bArr);
        return bArr;
    }

    public static byte[] MakePixcelData(Mat mat) {
        return new byte[(mat.rows() * mat.cols() * mat.channels())];
    }

    private static void LogMemory(String str) {
        Runtime runtime = Runtime.getRuntime();
        float f = (float) runtime.totalMemory();
        float freeMemory = (float) runtime.freeMemory();
        Log.d("LogMemory", String.format("max:%.2fMB total:%.2fMB free:%.2fMB used:%.2fMB %s", new Object[]{Float.valueOf(((float) runtime.maxMemory()) / 1048576.0f), Float.valueOf(f / 1048576.0f), Float.valueOf(freeMemory / 1048576.0f), Float.valueOf((f - freeMemory) / 1048576.0f), str}));
    }
}
