package epson.print;

import android.graphics.BitmapFactory;
import android.media.ExifInterface;
import android.os.Parcel;
import android.os.Parcelable;

import java.io.File;
import java.io.IOException;

import epson.image.epsonImage;
import epson.print.Util.EPLog;

public class EPImage implements Parcelable {
    public static final Creator<EPImage> CREATOR = new Creator<EPImage>() {
        public EPImage createFromParcel(Parcel parcel) {
            return new EPImage(parcel);
        }

        public EPImage[] newArray(int i) {
            return new EPImage[i];
        }
    };
    public static final int EPS_ROTATE_0 = 0;
    public static final int EPS_ROTATE_180 = 180;
    public static final int EPS_ROTATE_270 = 270;
    public static final int EPS_ROTATE_90 = 90;
    public static final int FILE_INFO_NO_INFO = 0;
    public static final int FILE_INFO_WITH_FILE_TYPE = 2;
    public static final int FILE_INFO_WITH_ORG_FILE_NAME = 1;
    public static final int FILE_TYPE_BMP = 1;
    public static final int FILE_TYPE_JPEG = 2;
    public static final int FILE_TYPE_PNG = 3;
    public static final int FILE_TYPE_SCAN = 4098;
    public static final int FILE_TYPE_TIFF = 4;
    public static final int FILE_TYPE_UNKNOWN = 0;
    public static final int FILE_TYPE_WEB = 4097;
    private static final String TAG = "EPImage";
    public int decodeHeight;
    public volatile String decodeImageFileName;
    public int decodeWidth;
    public int index;
    public boolean isNotPhot;
    public volatile boolean isPaperLandScape;
    public volatile String loadImageFileName;
    private epsonImage mEpsonImage;
    private int mFileInfo;
    private int mFileType;
    private String mOrgFileNameForLogger;
    public volatile int previewHeight;
    public String previewImageFileName;
    public volatile float previewImageRectBottom;
    public int previewImageRectCenterX;
    public int previewImageRectCenterY;
    public volatile float previewImageRectLeft;
    public volatile float previewImageRectRight;
    public volatile float previewImageRectTop;
    public volatile int previewPaperRectBottom;
    public volatile int previewPaperRectLeft;
    public volatile int previewPaperRectRight;
    public volatile int previewPaperRectTop;
    public volatile int previewWidth;
    public String printImageFileName;
    public int rotate;
    public float scaleFactor;
    public volatile int srcHeight;
    public volatile int srcWidth;
    public String thumbnailImageFileName;
    public String webUrl;

    public int describeContents() {
        return 0;
    }

    public EPImage() {
        index = 0;
        loadImageFileName = null;
        srcWidth = 0;
        srcHeight = 0;
        decodeImageFileName = null;
        decodeWidth = 0;
        decodeHeight = 0;
        thumbnailImageFileName = null;
        previewImageFileName = null;
        previewWidth = 0;
        previewHeight = 0;
        printImageFileName = null;
        isPaperLandScape = false;
        isNotPhot = false;
        rotate = 0;
        previewPaperRectLeft = 0;
        previewPaperRectTop = 0;
        previewPaperRectRight = 0;
        previewPaperRectBottom = 0;
        previewImageRectCenterX = 0;
        previewImageRectCenterY = 0;
        previewImageRectLeft = 0.0f;
        previewImageRectTop = 0.0f;
        previewImageRectRight = 0.0f;
        previewImageRectBottom = 0.0f;
        scaleFactor = 1.0f;
        webUrl = null;
        mFileInfo = 0;
        mFileType = 0;
        mOrgFileNameForLogger = null;
    }

    public EPImage(EPImage ePImage) {
        index = 0;
        loadImageFileName = null;
        srcWidth = 0;
        srcHeight = 0;
        decodeImageFileName = null;
        decodeWidth = 0;
        decodeHeight = 0;
        thumbnailImageFileName = null;
        previewImageFileName = null;
        previewWidth = 0;
        previewHeight = 0;
        printImageFileName = null;
        isPaperLandScape = false;
        isNotPhot = false;
        rotate = 0;
        previewPaperRectLeft = 0;
        previewPaperRectTop = 0;
        previewPaperRectRight = 0;
        previewPaperRectBottom = 0;
        previewImageRectCenterX = 0;
        previewImageRectCenterY = 0;
        previewImageRectLeft = 0.0f;
        previewImageRectTop = 0.0f;
        previewImageRectRight = 0.0f;
        previewImageRectBottom = 0.0f;
        scaleFactor = 1.0f;
        webUrl = null;
        mFileInfo = 0;
        mFileType = 0;
        mOrgFileNameForLogger = null;
        index = ePImage.index;
        loadImageFileName = ePImage.loadImageFileName;
        srcWidth = ePImage.srcWidth;
        srcHeight = ePImage.srcHeight;
        decodeImageFileName = ePImage.decodeImageFileName;
        decodeWidth = ePImage.decodeWidth;
        decodeHeight = ePImage.decodeHeight;
        thumbnailImageFileName = ePImage.thumbnailImageFileName;
        previewImageFileName = ePImage.previewImageFileName;
        previewWidth = ePImage.previewWidth;
        previewHeight = ePImage.previewHeight;
        printImageFileName = ePImage.printImageFileName;
        isPaperLandScape = ePImage.isPaperLandScape;
        isNotPhot = ePImage.isNotPhot;
        rotate = ePImage.rotate;
        previewPaperRectLeft = ePImage.previewPaperRectLeft;
        previewPaperRectTop = ePImage.previewPaperRectTop;
        previewPaperRectRight = ePImage.previewPaperRectRight;
        previewPaperRectBottom = ePImage.previewPaperRectBottom;
        previewImageRectCenterX = ePImage.previewImageRectCenterX;
        previewImageRectCenterY = ePImage.previewImageRectCenterY;
        previewImageRectLeft = ePImage.previewImageRectLeft;
        previewImageRectTop = ePImage.previewImageRectTop;
        previewImageRectRight = ePImage.previewImageRectRight;
        previewImageRectBottom = ePImage.previewImageRectBottom;
        scaleFactor = ePImage.scaleFactor;
        webUrl = ePImage.webUrl;
    }

    public EPImage(String str, int i) {
        boolean z = false;
        index = 0;
        loadImageFileName = null;
        srcWidth = 0;
        srcHeight = 0;
        decodeImageFileName = null;
        decodeWidth = 0;
        decodeHeight = 0;
        thumbnailImageFileName = null;
        previewImageFileName = null;
        previewWidth = 0;
        previewHeight = 0;
        printImageFileName = null;
        isPaperLandScape = false;
        isNotPhot = false;
        rotate = 0;
        previewPaperRectLeft = 0;
        previewPaperRectTop = 0;
        previewPaperRectRight = 0;
        previewPaperRectBottom = 0;
        previewImageRectCenterX = 0;
        previewImageRectCenterY = 0;
        previewImageRectLeft = 0.0f;
        previewImageRectTop = 0.0f;
        previewImageRectRight = 0.0f;
        previewImageRectBottom = 0.0f;
        scaleFactor = 1.0f;
        webUrl = null;
        mFileInfo = 0;
        mFileType = 0;
        mOrgFileNameForLogger = null;
        index = i;
        loadImageFileName = str;
        if (loadImageFileName == null) {
            EPLog.m318w(TAG, "loadImageFileName is null");
        } else if (!new File(str).exists()) {
            EPLog.m318w(TAG, str + " is not exists.");
        } else {
            BitmapFactory.Options options = new BitmapFactory.Options();
            options.inJustDecodeBounds = true;
            BitmapFactory.decodeFile(loadImageFileName, options);
            if (options.outWidth <= 0 || options.outHeight <= 0) {
                EPLog.m307e(TAG, "BitmapFactory.decodeFile Failed");
                if (mEpsonImage == null) {
                    mEpsonImage = new epsonImage();
                }
                epsonImage epsonimage = mEpsonImage;
                if (epsonimage != null) {
                    int[] iArr = new int[2];
                    epsonimage.epsmpGetImageSize2(str, iArr);
                    srcWidth = iArr[0];
                    srcHeight = iArr[1];
                    if (srcWidth > srcHeight) {
                        isPaperLandScape = true;
                    } else {
                        isPaperLandScape = false;
                    }
                }
            } else {
                srcWidth = options.outWidth;
                srcHeight = options.outHeight;
                if (srcWidth > srcHeight) {
                    isPaperLandScape = true;
                } else {
                    isPaperLandScape = false;
                }
            }
            try {
                int attributeInt = new ExifInterface(loadImageFileName).getAttributeInt(android.support.media.ExifInterface.TAG_ORIENTATION, 0);
                if (attributeInt == 6 || attributeInt == 8) {
                    int i2 = srcWidth;
                    srcWidth = srcHeight;
                    srcHeight = i2;
                    isPaperLandScape = !isPaperLandScape ? true : z;
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    public String getLoadImageFileName() {
        return loadImageFileName;
    }

    public boolean isExtentionAvailable() {
        return mFileInfo != 2;
    }

    public String getExtention() {
        String str;
        switch (mFileInfo) {
            case 0:
                str = loadImageFileName;
                break;
            case 1:
                str = mOrgFileNameForLogger;
                break;
            case 2:
                return "";
            default:
                return "";
        }
        int lastIndexOf = str.lastIndexOf(47);
        int lastIndexOf2 = str.lastIndexOf(46);
        return (lastIndexOf2 < 0 || lastIndexOf2 < lastIndexOf) ? "" : str.substring(lastIndexOf2);
    }

    public int getFileType() {
        return mFileType;
    }

    public void setOrgName(String str) {
        mFileInfo = 1;
        mOrgFileNameForLogger = str;
    }

    public String getOriginalFileName() {
        String str = mOrgFileNameForLogger;
        if (str != null) {
            return str;
        }
        return loadImageFileName;
    }

    public void setType(int i) {
        mFileInfo = 2;
        mFileType = i;
    }

    private EPImage(Parcel parcel) {
        index = 0;
        loadImageFileName = null;
        srcWidth = 0;
        srcHeight = 0;
        decodeImageFileName = null;
        decodeWidth = 0;
        decodeHeight = 0;
        thumbnailImageFileName = null;
        previewImageFileName = null;
        previewWidth = 0;
        previewHeight = 0;
        printImageFileName = null;
        isPaperLandScape = false;
        isNotPhot = false;
        rotate = 0;
        previewPaperRectLeft = 0;
        previewPaperRectTop = 0;
        previewPaperRectRight = 0;
        previewPaperRectBottom = 0;
        previewImageRectCenterX = 0;
        previewImageRectCenterY = 0;
        previewImageRectLeft = 0.0f;
        previewImageRectTop = 0.0f;
        previewImageRectRight = 0.0f;
        previewImageRectBottom = 0.0f;
        scaleFactor = 1.0f;
        webUrl = null;
        mFileInfo = 0;
        mFileType = 0;
        mOrgFileNameForLogger = null;
        index = parcel.readInt();
        loadImageFileName = parcel.readString();
        srcWidth = parcel.readInt();
        srcHeight = parcel.readInt();
        decodeImageFileName = parcel.readString();
        decodeWidth = parcel.readInt();
        decodeHeight = parcel.readInt();
        thumbnailImageFileName = parcel.readString();
        previewImageFileName = parcel.readString();
        previewWidth = parcel.readInt();
        previewHeight = parcel.readInt();
        printImageFileName = parcel.readString();
        boolean[] zArr = new boolean[1];
        parcel.readBooleanArray(zArr);
        isPaperLandScape = zArr[0];
        parcel.readBooleanArray(zArr);
        isNotPhot = zArr[0];
        rotate = parcel.readInt();
        previewPaperRectLeft = parcel.readInt();
        previewPaperRectTop = parcel.readInt();
        previewPaperRectRight = parcel.readInt();
        previewPaperRectBottom = parcel.readInt();
        previewImageRectCenterX = parcel.readInt();
        previewImageRectCenterY = parcel.readInt();
        previewImageRectLeft = parcel.readFloat();
        previewImageRectTop = parcel.readFloat();
        previewImageRectRight = parcel.readFloat();
        previewImageRectBottom = parcel.readFloat();
        scaleFactor = parcel.readFloat();
        webUrl = parcel.readString();
        mFileInfo = parcel.readInt();
        mFileType = parcel.readInt();
        mOrgFileNameForLogger = parcel.readString();
    }

    public void writeToParcel(Parcel parcel, int i) {
        parcel.writeInt(index);
        parcel.writeString(loadImageFileName);
        parcel.writeInt(srcWidth);
        parcel.writeInt(srcHeight);
        parcel.writeString(decodeImageFileName);
        parcel.writeInt(decodeWidth);
        parcel.writeInt(decodeHeight);
        parcel.writeString(thumbnailImageFileName);
        parcel.writeString(previewImageFileName);
        parcel.writeInt(previewWidth);
        parcel.writeInt(previewHeight);
        parcel.writeString(printImageFileName);
        parcel.writeBooleanArray(new boolean[]{isPaperLandScape});
        parcel.writeBooleanArray(new boolean[]{isNotPhot});
        parcel.writeInt(rotate);
        parcel.writeInt(previewPaperRectLeft);
        parcel.writeInt(previewPaperRectTop);
        parcel.writeInt(previewPaperRectRight);
        parcel.writeInt(previewPaperRectBottom);
        parcel.writeInt(previewImageRectCenterX);
        parcel.writeInt(previewImageRectCenterY);
        parcel.writeFloat(previewImageRectLeft);
        parcel.writeFloat(previewImageRectTop);
        parcel.writeFloat(previewImageRectRight);
        parcel.writeFloat(previewImageRectBottom);
        parcel.writeFloat(scaleFactor);
        parcel.writeString(webUrl);
        parcel.writeInt(mFileInfo);
        parcel.writeInt(mFileType);
        parcel.writeString(mOrgFileNameForLogger);
    }
}
