package com.bef.effectsdk.algorithm;

import android.graphics.Bitmap;
import com.bef.effectsdk.ResourceFinder;
import com.bytedance.covode.number.Covode;
import com.bytedance.frameworks.apm.trace.MethodCollector;

public class GeneralObjDetector {
    public final int ModelType_kPureDetect = 1;
    public final int ParamType_kDetectShortSideLen = 1;
    public ResourceFinder mFinder;
    public long mFinderHandle;
    public long mNativeHandle;

    static {
        Covode.recordClassIndex(2811);
    }

    private native long nativeCreate();

    private native int nativeDestroy(long j);

    private native int nativeInit(long j, long j2, int i);

    private native int nativeInitWithPath(long j, String str, int i);

    private native GeneralObjDetectResult nativeProcess(long j, Bitmap bitmap, int i);

    private native int nativeSetParamF(long j, int i, float f);

    private native int nativeSetParamS(long j, int i, String str);

    private boolean isFinderHandleValid() {
        if (0 != this.mFinderHandle) {
            return true;
        }
        return false;
    }

    private boolean isNativeHandleValid() {
        if (0 != this.mNativeHandle) {
            return true;
        }
        return false;
    }

    public boolean create() {
        MethodCollector.i(7950);
        this.mNativeHandle = nativeCreate();
        boolean isNativeHandleValid = isNativeHandleValid();
        MethodCollector.o(7950);
        return isNativeHandleValid;
    }

    public void destroy() {
        MethodCollector.i(9920);
        if (isNativeHandleValid()) {
            nativeDestroy(this.mNativeHandle);
            this.mNativeHandle = 0;
        }
        if (this.mFinder != null && isFinderHandleValid()) {
            this.mFinder.release(this.mFinderHandle);
            this.mFinderHandle = 0;
        }
        MethodCollector.o(9920);
    }

    public boolean init(ResourceFinder resourceFinder, int i) {
        MethodCollector.i(8174);
        if (resourceFinder == null || !isNativeHandleValid()) {
            MethodCollector.o(8174);
            return false;
        }
        this.mFinder = resourceFinder;
        this.mFinderHandle = resourceFinder.createNativeResourceFinder(this.mNativeHandle);
        if (!isFinderHandleValid()) {
            destroy();
            MethodCollector.o(8174);
            return false;
        }
        if (nativeInit(this.mNativeHandle, this.mFinderHandle, i) == 0) {
            MethodCollector.o(8174);
            return true;
        }
        MethodCollector.o(8174);
        return false;
    }

    public boolean initWithPath(String str, int i) {
        MethodCollector.i(8382);
        if (str == null || str.length() == 0 || !isNativeHandleValid()) {
            MethodCollector.o(8382);
            return false;
        } else if (nativeInitWithPath(this.mNativeHandle, str, i) == 0) {
            MethodCollector.o(8382);
            return true;
        } else {
            MethodCollector.o(8382);
            return false;
        }
    }

    public GeneralObjDetectResult process(Bitmap bitmap, int i) {
        MethodCollector.i(9710);
        if (!isNativeHandleValid() || bitmap == null) {
            GeneralObjDetectResult generalObjDetectResult = new GeneralObjDetectResult();
            MethodCollector.o(9710);
            return generalObjDetectResult;
        }
        GeneralObjDetectResult nativeProcess = nativeProcess(this.mNativeHandle, bitmap, i);
        nativeProcess.logData();
        MethodCollector.o(9710);
        return nativeProcess;
    }

    public boolean setParamF(int i, float f) {
        MethodCollector.i(8950);
        if (!isNativeHandleValid()) {
            MethodCollector.o(8950);
            return false;
        } else if (nativeSetParamF(this.mNativeHandle, i, f) == 0) {
            MethodCollector.o(8950);
            return true;
        } else {
            MethodCollector.o(8950);
            return false;
        }
    }

    public boolean setParamS(int i, String str) {
        MethodCollector.i(9332);
        if (!isNativeHandleValid()) {
            MethodCollector.o(9332);
            return false;
        } else if (nativeSetParamS(this.mNativeHandle, i, str) == 0) {
            MethodCollector.o(9332);
            return true;
        } else {
            MethodCollector.o(9332);
            return false;
        }
    }
}
