package epson.scan.i2lib;


import androidx.annotation.NonNull;

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

public class ImageProcessThread extends Thread {
    private static final String LOG_TAG = "ImageProcessThread";
    private final int mBlackAndWhiteThreshold;
    private final ImageProcessController mImageProcessController;

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

    public ImageProcessThread(@NonNull ImageProcessController imageProcessController, int i) {
        super(LOG_TAG);
        mImageProcessController = imageProcessController;
        mBlackAndWhiteThreshold = i;
    }

    public void run() {
        while (!isInterrupted()) {
            try {
                ImageProcessController.ImageProcessInfo checkNexImageProcessRequest = mImageProcessController.checkNexImageProcessRequest();
                if (checkNexImageProcessRequest.endRequested()) {
                    mImageProcessController.putImageProcessEnd(checkNexImageProcessRequest, true);
                    return;
                } else if (!processImage(checkNexImageProcessRequest, mBlackAndWhiteThreshold)) {
                    mImageProcessController.putImageProcessEnd(checkNexImageProcessRequest, false);
                    return;
                } else {
                    mImageProcessController.putImageProcessEnd(checkNexImageProcessRequest, true);
                }
            } catch (InterruptedException unused) {
                return;
            }
        }
    }


    private boolean processImage(@android.support.annotation.NonNull epson.scan.i2lib.ImageProcessController.ImageProcessInfo r6, int r7) {

        throw new UnsupportedOperationException("Method not decompiled: epson.scan.i2lib.ImageProcessThread.processImage(epson.scan.i2lib.ImageProcessController$ImageProcessInfo, int):boolean");
    }

    private static Mat openImageFile(@NonNull String str) {
        Mat imread = Imgcodecs.imread(str, -1);
        if (imread != null && imread.width() > 0 && imread.height() > 0) {
            return imread;
        }
        return null;
    }

    private static void rotate180(@NonNull Mat mat, @NonNull Mat mat2) {
        if (mat.width() <= 0 || mat.height() <= 0) {
            throw new IllegalArgumentException("orgImage size error");
        }
        Core.flip(mat, mat2, -1);
    }

    private static void blackAndWhite(@NonNull Mat mat, @NonNull Mat mat2, int i) {
        if (mat.width() <= 0 || mat.height() <= 0) {
            throw new IllegalArgumentException("orgImage size error");
        }
        Imgproc.threshold(mat, mat2, i, 255.0d, 0);
    }
}
