package epson.colorcorrection;

import org.opencv.core.CvException;
import org.opencv.core.Mat;
import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.imgproc.Imgproc;

public class SDIC_API implements SDIC_CommonDefine {
    static {
        System.loadLibrary("opencv_java3");
    }

    public static int SDIC_API_MakeMask(String str, float f, String str2, int i) {
        SDIC_MAT_PTR sdic_mat_ptr = new SDIC_MAT_PTR();
        SDIC_MAT_PTR sdic_mat_ptr2 = new SDIC_MAT_PTR();
        int i2 = SDIC_CommonDefine.SDIC_ERR_UNKNOWN;
        try {
            sdic_mat_ptr.setMat(Imgcodecs.imread(str, 0));
            Mat mat = sdic_mat_ptr.getMat();
            sdic_mat_ptr.rotateMat(f);
            int MakeMask = SDIC_BCSC.MakeMask(mat, sdic_mat_ptr2, i);
            if (MakeMask != 0 || Imgcodecs.imwrite(str2, sdic_mat_ptr2.getMat())) {
                i2 = MakeMask;
            }
        } catch (CvException unused) {
            i2 = -100;
        } catch (Exception unused2) {
        } catch (Throwable th) {
            sdic_mat_ptr.releaseMat();
            sdic_mat_ptr2.releaseMat();
            throw th;
        }
        sdic_mat_ptr.releaseMat();
        sdic_mat_ptr2.releaseMat();
        return i2;
    }

    /* JADX WARNING: Code restructure failed: missing block: B:5:0x0044, code lost:
        if (org.opencv.imgcodecs.Imgcodecs.imwrite(r16, r12.getMat()) == false) goto L_0x0048;
     */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    public static int SDIC_API_BCSCorrection(java.lang.String r13, float r14, java.lang.String r15, java.lang.String r16, double r17, double r19, double r21) {
        /*
            epson.colorcorrection.SDIC_MAT_PTR r1 = new epson.colorcorrection.SDIC_MAT_PTR
            r1.<init>()
            epson.colorcorrection.SDIC_MAT_PTR r2 = new epson.colorcorrection.SDIC_MAT_PTR
            r2.<init>()
            epson.colorcorrection.SDIC_MAT_PTR r12 = new epson.colorcorrection.SDIC_MAT_PTR
            r12.<init>()
            r0 = -400(0xfffffffffffffe70, float:NaN)
            org.opencv.core.Mat r3 = org.opencv.imgcodecs.Imgcodecs.imread(r13)     // Catch:{ CvException -> 0x0061, Exception -> 0x005d, all -> 0x0052 }
            r1.setMat(r3)     // Catch:{ CvException -> 0x0061, Exception -> 0x005d, all -> 0x0052 }
            org.opencv.core.Mat r3 = r1.getMat()     // Catch:{ CvException -> 0x0061, Exception -> 0x005d, all -> 0x0052 }
            r4 = r14
            r1.rotateMat(r14)     // Catch:{ CvException -> 0x0061, Exception -> 0x005d, all -> 0x0052 }
            r4 = 0
            r5 = r15
            org.opencv.core.Mat r4 = org.opencv.imgcodecs.Imgcodecs.imread(r15, r4)     // Catch:{ CvException -> 0x0061, Exception -> 0x005d, all -> 0x0052 }
            r2.setMat(r4)     // Catch:{ CvException -> 0x0061, Exception -> 0x005d, all -> 0x0052 }
            org.opencv.core.Mat r4 = r2.getMat()     // Catch:{ CvException -> 0x0061, Exception -> 0x005d, all -> 0x0052 }
            r5 = r12
            r6 = r17
            r8 = r19
            r10 = r21
            int r3 = epson.colorcorrection.SDIC_BCSC.BCSCorrection(r3, r4, r5, r6, r8, r10)     // Catch:{ CvException -> 0x0061, Exception -> 0x005d, all -> 0x0052 }
            if (r3 != 0) goto L_0x0047
            org.opencv.core.Mat r4 = r12.getMat()     // Catch:{ CvException -> 0x0061, Exception -> 0x005d, all -> 0x0052 }
            r5 = r16
            boolean r4 = org.opencv.imgcodecs.Imgcodecs.imwrite(r5, r4)     // Catch:{ CvException -> 0x0061, Exception -> 0x005d, all -> 0x0052 }
            if (r4 != 0) goto L_0x0047
            goto L_0x0048
        L_0x0047:
            r0 = r3
        L_0x0048:
            r1.releaseMat()
        L_0x004b:
            r2.releaseMat()
            r12.releaseMat()
            goto L_0x0067
        L_0x0052:
            r0 = move-exception
            r1.releaseMat()
            r2.releaseMat()
            r12.releaseMat()
            throw r0
        L_0x005d:
            r1.releaseMat()
            goto L_0x004b
        L_0x0061:
            r0 = -100
            r1.releaseMat()
            goto L_0x004b
        L_0x0067:
            return r0
        */
        throw new UnsupportedOperationException("Method not decompiled: epson.colorcorrection.SDIC_API.SDIC_API_BCSCorrection(java.lang.String, float, java.lang.String, java.lang.String, double, double, double):int");
    }

    public static int SDIC_API_BCSCorrection(String str, float f, String str2, String str3, int i, double d, double d2, double d3) {
        int i2;
        int i3;
        String str4 = str3;
        SDIC_MAT_PTR sdic_mat_ptr = new SDIC_MAT_PTR();
        SDIC_MAT_PTR sdic_mat_ptr2 = new SDIC_MAT_PTR();
        SDIC_MAT_PTR sdic_mat_ptr3 = new SDIC_MAT_PTR();
        try {
            sdic_mat_ptr.setMat(Imgcodecs.imread(str));
            Mat mat = sdic_mat_ptr.getMat();
            float f2 = f;
            sdic_mat_ptr.rotateMat(f);
            Mat mat2 = new Mat();
            if (sdic_mat_ptr.getMat().channels() == 3) {
                Imgproc.cvtColor(sdic_mat_ptr.getMat(), mat2, 6);
                i3 = i;
            } else if (sdic_mat_ptr.getMat().channels() == 4) {
                Imgproc.cvtColor(sdic_mat_ptr.getMat(), mat2, 10);
                i3 = i;
            } else {
                sdic_mat_ptr.releaseMat();
                sdic_mat_ptr2.releaseMat();
                sdic_mat_ptr3.releaseMat();
                return -4;
            }
            i2 = SDIC_BCSC.MakeMask(mat2, sdic_mat_ptr2, i3);
            mat2.release();
            if (i2 == 0) {
                i2 = SDIC_BCSC.BCSCorrection(mat, sdic_mat_ptr2.getMat(), sdic_mat_ptr3, d, d2, d3);
                if (i2 == 0) {
                    String str5 = str2;
                    Imgcodecs.imwrite(str2, sdic_mat_ptr3.getMat());
                }
                if (str4 != null && str3.length() > 0) {
                    Imgcodecs.imwrite(str4, sdic_mat_ptr2.getMat());
                }
            }
            sdic_mat_ptr.releaseMat();
        } catch (CvException unused) {
            i2 = -100;
            sdic_mat_ptr.releaseMat();
        } catch (Exception unused2) {
            i2 = SDIC_CommonDefine.SDIC_ERR_UNKNOWN;
            sdic_mat_ptr.releaseMat();
        } catch (Throwable th) {
            sdic_mat_ptr.releaseMat();
            sdic_mat_ptr2.releaseMat();
            sdic_mat_ptr3.releaseMat();
            throw th;
        }
        sdic_mat_ptr2.releaseMat();
        sdic_mat_ptr3.releaseMat();
        return i2;
    }

    /* JADX WARNING: Code restructure failed: missing block: B:7:0x0028, code lost:
        return epson.colorcorrection.SDIC_CommonDefine.SDIC_ERR_UNKNOWN;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:9:0x002b, code lost:
        return -100;
     */
    /* JADX WARNING: Exception block dominator not found, dom blocks: [] */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    public static int SDIC_API_PaperWhiteCorrection(java.lang.String r2, float r3, java.lang.String r4) {
        /*
            epson.colorcorrection.SDIC_MAT_PTR r0 = new epson.colorcorrection.SDIC_MAT_PTR
            r0.<init>()
            epson.colorcorrection.SDIC_MAT_PTR r1 = new epson.colorcorrection.SDIC_MAT_PTR
            r1.<init>()
            org.opencv.core.Mat r2 = org.opencv.imgcodecs.Imgcodecs.imread(r2)     // Catch:{ CvException -> 0x002b, Exception -> 0x0028, all -> 0x0026 }
            r0.setMat(r2)     // Catch:{ CvException -> 0x002b, Exception -> 0x0028, all -> 0x0026 }
            org.opencv.core.Mat r2 = r0.getMat()     // Catch:{ CvException -> 0x002b, Exception -> 0x0028, all -> 0x0026 }
            r0.rotateMat(r3)     // Catch:{ CvException -> 0x002b, Exception -> 0x0028, all -> 0x0026 }
            int r2 = epson.colorcorrection.SDIC_PWC.PaperWhiteCorrection(r2, r1)     // Catch:{ CvException -> 0x002b, Exception -> 0x0028, all -> 0x0026 }
            if (r2 != 0) goto L_0x002d
            org.opencv.core.Mat r3 = r1.getMat()     // Catch:{ CvException -> 0x002b, Exception -> 0x0028, all -> 0x0026 }
            org.opencv.imgcodecs.Imgcodecs.imwrite(r4, r3)     // Catch:{ CvException -> 0x002b, Exception -> 0x0028, all -> 0x0026 }
            goto L_0x002d
        L_0x0026:
            r2 = move-exception
            throw r2
        L_0x0028:
            r2 = -400(0xfffffffffffffe70, float:NaN)
            goto L_0x002d
        L_0x002b:
            r2 = -100
        L_0x002d:
            return r2
        */
        throw new UnsupportedOperationException("Method not decompiled: epson.colorcorrection.SDIC_API.SDIC_API_PaperWhiteCorrection(java.lang.String, float, java.lang.String):int");
    }
}
