package epson.print.copy.Component.ecopycomponent;

import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.ColorMatrix;
import android.graphics.ColorMatrixColorFilter;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.Point;
import android.graphics.PointF;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.support.p000v4.internal.view.SupportMenu;
import android.view.View;
import android.widget.LinearLayout;

import epson.common.Constants;

public class ECopyPreview extends View {

    /* renamed from: A4 */
    final Size f360A4 = new Size(1240, Constants.SCAN_MAX_HEIGHT);
    final Size A4_2Up = new Size(Constants.SCAN_MAX_HEIGHT, 1240);
    final Size A4_2UpPage = new Size(827, 1176);

    /* renamed from: B5 */
    final Size f361B5 = new Size(1075, 1518);
    final int BM_2Up = 35;
    final int BM_Border = 18;
    final int BO_Type1 = 24;
    final int BO_Type2 = 15;
    final Size Hagaki = new Size(591, 874);

    /* renamed from: KG */
    final Size f362KG = new Size(602, 898);

    /* renamed from: L */
    final Size f363L = new Size(526, 750);

    /* renamed from: L2 */
    final Size f364L2 = new Size(750, 1051);
    final int LM_2Up = 32;
    final int LM_Border = 18;
    final int LO_Type1 = 15;
    final int LO_Type2 = 15;
    final Size Max = new Size(Constants.SCAN_MAX_WIDTH, Constants.SCAN_MAX_HEIGHT);

    /* renamed from: P6 */
    final Size f365P6 = new Size(1199, 1500);
    final int PG_2Up = 35;
    final int PL_A4 = Constants.SCAN_MAX_HEIGHT;
    final int PL_B5 = 1518;
    final int PL_Hagaki = 874;
    final int PL_KG = 898;
    final int PL_L = 750;
    final int PL_L2 = 1051;
    final int PL_MAX = Constants.SCAN_MAX_HEIGHT;
    final int PL_P6 = 1500;
    final int PW_A4 = 1240;
    final int PW_B5 = 1075;
    final int PW_Hagaki = 591;
    final int PW_KG = 602;
    final int PW_L = 526;
    final int PW_L2 = 750;
    final int PW_MAX = Constants.SCAN_MAX_WIDTH;
    final int PW_P6 = 1199;
    final int RM_2Up = 32;
    final int RM_Border = 18;
    final int RO_Type1 = 15;
    final int RO_Type2 = 15;
    final int TM_2Up = 30;
    final int TM_Border = 18;
    final int TO_Type1 = 17;
    final int TO_Type2 = 8;
    Drawable backgroundDrawable = new ColorDrawable(0);
    ECopyOptionItem colorOption;
    ECopyOptionItem copiesOpiton;
    Paint copyFramePaint = new Paint();
    Size drawSize;
    Paint grayscalePaint;
    Layout layout;
    ECopyPreviewInvalidateListener listener;
    ICopyPreviewCommitEditedOptionContext optionCommitter;
    ECopyOptionContext optionContext;
    Drawable paperDrawable = new ColorDrawable(-1);
    RectF paperFrame;
    Rect paperPadding;
    Paint paperShadowPaint;
    ECopyOptionItem scaleOption;

    public enum ECopyPreviewColor {
        Color,
        Monochrome
    }

    public interface ECopyPreviewInvalidateListener {
        void needInvalidateView();
    }

    interface ICopyPreviewCommitEditedOptionContext {
        void commit(ECopyOptionContext eCopyOptionContext);
    }

    protected interface ScanImageSizeCalculator {
        void onScanImageSize(int i, int i2, float f);
    }

    private ECopyPreview(Context context) {
        super(context);
        copyFramePaint.setColor(SupportMenu.CATEGORY_MASK);
        copyFramePaint.setStyle(Paint.Style.STROKE);
        copyFramePaint.setStrokeWidth(2.0f);
        paperPadding = new Rect();
        grayscalePaint = new Paint();
        paperShadowPaint = new Paint();
        paperFrame = new RectF();
        ColorMatrix colorMatrix = new ColorMatrix();
        colorMatrix.setSaturation(0.0f);
        grayscalePaint.setColorFilter(new ColorMatrixColorFilter(colorMatrix));
    }

    public void setBackground(Drawable drawable) {
        backgroundDrawable = drawable;
    }

    public void setPaperDrawable(Drawable drawable) {
        paperDrawable = drawable;
    }

    public void setCopyFramePaint(Paint paint) {
        copyFramePaint = paint;
    }

    public void setPaperShadowPaint(Paint paint) {
        paperShadowPaint = paint;
    }

    public void setPaperPadding(Rect rect) {
        paperPadding = new Rect(rect);
        resize();
    }

    private void requestInvalidateView() {
        ((Activity) getContext()).runOnUiThread(new Runnable() {
            public void run() {
                listener.needInvalidateView();
            }
        });
    }

    public void setColor(ECopyPreviewColor eCopyPreviewColor) {
        ECopyOptionItem.ECopyOptionItemChoice eCopyOptionItemChoice = ECopyOptionItem.ECopyOptionItemChoice.ColorEffectsType_Color;
        if (eCopyPreviewColor == ECopyPreviewColor.Monochrome) {
            eCopyOptionItemChoice = ECopyOptionItem.ECopyOptionItemChoice.ColorEffectsType_MonochromeGrayscale;
        }
        colorOption.selectChoice(eCopyOptionItemChoice);
        requestInvalidateView();
    }

    public ECopyPreviewColor getColor() {
        return colorOption.getSelectedChoice() == ECopyOptionItem.ECopyOptionItemChoice.ColorEffectsType_MonochromeGrayscale ? ECopyPreviewColor.Monochrome : ECopyPreviewColor.Color;
    }

    public void setScale(int i) {
        scaleOption.selectValue(i);
        layout.setCopyScale(((float) scaleOption.getSelectedValue()) / 100.0f);
        requestInvalidateView();
    }

    public int getScale() {
        return scaleOption.getSelectedValue();
    }

    public void setCopies(int i) {
        copiesOpiton.selectValue(i);
    }

    public int getCopies() {
        return copiesOpiton.getSelectedValue();
    }

    public void dismiss(boolean z) {
        if (z) {
            optionCommitter.commit(optionContext);
        }
    }

    private void compose(ECopyOptionContext eCopyOptionContext, ICopyPreviewCommitEditedOptionContext iCopyPreviewCommitEditedOptionContext) {
        optionContext = eCopyOptionContext;
        optionCommitter = iCopyPreviewCommitEditedOptionContext;
        copiesOpiton = optionContext.getCopyOptionItemOf(ECopyOptionItem.ECopyOptionItemKey.Copies);
        scaleOption = optionContext.getCopyOptionItemOf(ECopyOptionItem.ECopyOptionItemKey.CopyMagnification);
        colorOption = optionContext.getCopyOptionItemOf(ECopyOptionItem.ECopyOptionItemKey.ColorEffectsType);
        resize();
    }

    private void resize() {
        int i = (drawSize.width - paperPadding.left) - paperPadding.right;
        int i2 = (drawSize.height - paperPadding.top) - paperPadding.bottom;
        ECopyComponent.ECopyType copyType = optionContext.getCopyType();
        if (copyType == ECopyComponent.ECopyType.A4_2up || copyType == ECopyComponent.ECopyType.B5_2up || copyType == ECopyComponent.ECopyType.A4_2up_Book || copyType == ECopyComponent.ECopyType.B5_2up_Book) {
            layout = new Layout2Up(i, i2);
        } else if (copyType == ECopyComponent.ECopyType.Mirror) {
            layout = new LayoutMirror(i, i2);
        } else if (copyType == ECopyComponent.ECopyType.Borderless) {
            layout = new LayoutBorderless(i, i2);
        } else {
            layout = new LayoutStandard(i, i2);
        }
        layout.setCopyScale(((float) scaleOption.getSelectedValue()) / 100.0f);
    }

    protected static ECopyPreview createPreview(Context context, int i, int i2, ECopyPreviewInvalidateListener eCopyPreviewInvalidateListener) {
        ECopyPreview eCopyPreview = new ECopyPreview(context);
        eCopyPreview.setLayoutParams(new LinearLayout.LayoutParams(i, i2));
        eCopyPreview.getClass();
        eCopyPreview.drawSize = new Size(i, i2);
        eCopyPreview.listener = eCopyPreviewInvalidateListener;
        return eCopyPreview;
    }

    protected void drawScanPreview(Bitmap bitmap) {
        layout.setScanImage(bitmap);
        requestInvalidateView();
    }

    protected void calculateScanImageSize(int i, int i2, ScanImageSizeCalculator scanImageSizeCalculator) {
        float scanImageScale = layout.getScanImageScale(i, i2);
        scanImageSizeCalculator.onScanImageSize((int) (((float) i) * scanImageScale), (int) (((float) i2) * scanImageScale), scanImageScale);
    }

    protected void setPaperFrame(RectF rectF) {
        paperFrame = rectF;
        layout.setPaperFrame(rectF);
        requestInvalidateView();
    }

    protected void onDraw(Canvas canvas) {
        canvas.save();
        backgroundDrawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
        backgroundDrawable.draw(canvas);
        Point offset = layout.getOffset();
        offset.offset(paperPadding.left, paperPadding.top);
        RectF paperRect = layout.getPaperRect();
        paperRect.offset((float) offset.x, (float) offset.y);
        if (optionContext.copyType == ECopyComponent.ECopyType.Mirror) {
            canvas.scale(-1.0f, 1.0f);
            canvas.translate(-(paperRect.centerX() * 2.0f), 0.0f);
        }
        canvas.drawRect(paperRect, paperShadowPaint);
        Paint paint = null;
        if (colorOption.getSelectedChoice() == ECopyOptionItem.ECopyOptionItemChoice.ColorEffectsType_MonochromeGrayscale) {
            paint = grayscalePaint;
        }
        canvas.drawBitmap(layout.getBitmap(), (float) offset.x, (float) offset.y, paint);
        RectF copyFrame = layout.getCopyFrame();
        if (!paperFrame.isEmpty() && copyFrame != null) {
            copyFrame.offset((float) offset.x, (float) offset.y);
            Path path = new Path();
            path.addRect(copyFrame, Path.Direction.CW);
            canvas.drawPath(path, copyFramePaint);
        }
        canvas.restore();
    }

    class Size {
        int height;
        int width;

        Size(int i, int i2) {
            width = i;
            height = i2;
        }

        Size(Size size) {
            width = size.width;
            height = size.height;
        }

        private void scale(float f) {
            width = (int) (((float) width) * f);
            height = (int) (((float) height) * f);
        }
    }

    static abstract class Layout {

        enum AspectFit {
            Max,
            Min
        }

        private abstract Bitmap getBitmap();

        private abstract RectF getCopyFrame();

        private abstract Point getOffset();

        private abstract RectF getPaperRect();

        private abstract float getScanImageScale(int i, int i2);

        private abstract void setCopyScale(float f);

        private abstract void setPaperFrame(RectF rectF);

        private abstract void setScanImage(Bitmap bitmap);

        Layout() {
        }

        private void scaleRect(float f, RectF rectF) {
            Matrix matrix = new Matrix();
            matrix.postScale(f, f);
            matrix.mapRect(rectF);
        }

        private float getAspectFitScale(float f, float f2, float f3, float f4, AspectFit aspectFit) {
            PointF pointF = new PointF();
            pointF.x = f / f3;
            pointF.y = f2 / f4;
            return aspectFit == AspectFit.Min ? Math.min(pointF.x, pointF.y) : Math.max(pointF.x, pointF.y);
        }
    }

    class LayoutStandard extends Layout {
        boolean autofitEnabled = false;
        Canvas canvas;
        RectF copyFrame;
        float copyScale = 1.0f;
        float imageScale = 1.0f;
        int layoutHeight;
        int layoutWidth;
        float limitCopyScaleDown = 0.0f;
        Bitmap maxPaperImage;
        Point offset = new Point();
        RectF paper;
        Path paperBorderClipPath = new Path();
        Bitmap paperImage;
        Size paperSize;
        RectF scanFrame;
        Bitmap scanImage;

        LayoutStandard(int i, int i2) {
            layoutWidth = i;
            layoutHeight = i2;
            if  (optionContext.getCopyOptionItemOf(ECopyOptionItem.ECopyOptionItemKey.XScale).getSelectedChoice() == ECopyOptionItem.ECopyOptionItemChoice.XScale_Autofit) {
                autofitEnabled = true;
            }
            ECopyOptionItem copyOptionItemOf = optionContext.getCopyOptionItemOf(ECopyOptionItem.ECopyOptionItemKey.PrintMediaSize);
            switch (copyOptionItemOf.getSelectedChoice()) {
                case PrintMediaSize_A4:
                    paperSize = f360A4;
                    break;
                case PrintMediaSize_B5:
                    paperSize = f361B5;
                    break;
                case PrintMediaSize_L:
                    paperSize = f363L;
                    break;
                case PrintMediaSize_2L:
                    paperSize = f364L2;
                    break;
                case PrintMediaSize_Postcard:
                    paperSize = Hagaki;
                    break;
                case PrintMediaSize_KG:
                    paperSize = f362KG;
                    break;
                case PrintMediaSize_8x10in:
                    paperSize = f365P6;
                    break;
                default:
                    paperSize = Max;
                    break;
            }
            float f = (float) i;
            float f2 = (float) i2;
            float aspectFitScale = getAspectFitScale(f, f2, (float) paperSize.width, (float) paperSize.height, Layout.AspectFit.Min);
            RectF rectF = new RectF(0.0f, 0.0f, (float) paperSize.width, (float) paperSize.height);
            scaleRect(aspectFitScale, rectF);
            paperImage = Bitmap.createBitmap((int) rectF.width(), (int) rectF.height(), Bitmap.Config.ARGB_8888);
            RectF rectF2 = new RectF(0.0f, 0.0f, (float) paperSize.width, (float) paperSize.height);
            rectF2.left += 18.0f;
            rectF2.top += 18.0f;
            rectF2.right -= 18.0f;
            rectF2.bottom -= 18.0f;
            scaleRect(aspectFitScale, rectF2);
            paperBorderClipPath.addRect(rectF2, Path.Direction.CW);
            float aspectFitScale2 = getAspectFitScale(f, f2, (float) Max.width, (float) Max.height, Layout.AspectFit.Min);
            RectF rectF3 = new RectF(0.0f, 0.0f, (float) Max.width, (float) Max.height);
            scaleRect(aspectFitScale2, rectF3);
            maxPaperImage = Bitmap.createBitmap((int) rectF3.width(), (int) rectF3.height(), Bitmap.Config.ARGB_8888);
            invalidatePaperSize();
        }

        private Bitmap getBitmap() {
            boolean showPaper = showPaper();
            Bitmap bitmap = showPaper ? paperImage : maxPaperImage;
            canvas = new Canvas(bitmap);
            canvas.save();
            paperDrawable.setBounds(0, 0, bitmap.getWidth(), bitmap.getHeight());
            paperDrawable.draw(canvas);
            Bitmap bitmap2 = scanImage;
            if (bitmap2 != null) {
                if (showPaper) {
                    float f = copyScale / limitCopyScaleDown;
                    if (autofitEnabled) {
                        f = 1.0f / getAspectFitScale(scanFrame.width(), scanFrame.height(), (float) canvas.getWidth(), (float) canvas.getHeight(), Layout.AspectFit.Max);
                    }
                    Matrix matrix = new Matrix();
                    matrix.postScale(f, f);
                    canvas.clipPath(paperBorderClipPath);
                    canvas.drawBitmap(scanImage, matrix, (Paint) null);
                } else {
                    canvas.drawBitmap(bitmap2, 0.0f, 0.0f, (Paint) null);
                }
            }
            canvas.restore();
            return bitmap;
        }

        private float getScanImageScale(int i, int i2) {
            imageScale = getAspectFitScale((float)  (drawSize.width - paperPadding.left) - paperPadding.right), (float)  (drawSize.height - paperPadding.top) - paperPadding.bottom), (float) i, (float) i2, Layout.AspectFit.Min);
            return imageScale;
        }

        private void setScanImage(Bitmap bitmap) {
            scanImage = bitmap;
        }

        private Point getOffset() {
            return new Point(offset);
        }

        private void setPaperFrame(RectF rectF) {
            scanFrame = new RectF(rectF);
            scaleRect(imageScale, scanFrame);
            copyFrame = new RectF(rectF);
            copyFrame.left += 18.0f;
            copyFrame.top += 18.0f;
            copyFrame.right -= 36.0f;
            copyFrame.bottom -= 36.0f;
            scaleRect(imageScale, copyFrame);
            calcLimitCopyScaleDown();
            invalidatePaperSize();
        }

        private RectF getCopyFrame() {
            RectF rectF;
            if (showPaper() || scanImage == null || (rectF = copyFrame) == null) {
                return null;
            }
            RectF rectF2 = new RectF(rectF);
            float max = 1.0f / Math.max(copyScale, limitCopyScaleDown);
            rectF2.right *= max;
            rectF2.bottom *= max;
            return rectF2;
        }

        private void setCopyScale(float f) {
            copyScale = f;
            invalidatePaperSize();
        }

        private boolean showPaper() {
            boolean z = copyScale < limitCopyScaleDown;
            if (autofitEnabled) {
                return true;
            }
            return z;
        }

        private void invalidatePaperSize() {
            Size size = showPaper() ? paperSize : Max;
            float aspectFitScale = getAspectFitScale((float) layoutWidth, (float) layoutHeight, (float) size.width, (float) size.height, Layout.AspectFit.Min);
            paper = new RectF(0.0f, 0.0f, (float) size.width, (float) size.height);
            scaleRect(aspectFitScale, paper);
            offset.x = ((int) (((float) layoutWidth) - paper.right)) / 2;
            offset.y = ((int) (((float) layoutHeight) - paper.bottom)) / 2;
        }

        private void calcLimitCopyScaleDown() {
            limitCopyScaleDown = getAspectFitScale(copyFrame.right, copyFrame.bottom, paper.width(), paper.height(), Layout.AspectFit.Max);
        }

        private RectF getPaperRect() {
            return new RectF(0.0f, 0.0f, paper.width(), paper.height());
        }
    }

    class LayoutMirror extends LayoutStandard {
        LayoutMirror(int i, int i2) {
            super(i, i2);
        }

        private Bitmap getBitmap() {
            boolean showPaper = showPaper();
            Bitmap bitmap = showPaper ? paperImage : maxPaperImage;
            canvas = new Canvas(bitmap);
            canvas.save();
            paperDrawable.setBounds(0, 0, bitmap.getWidth(), bitmap.getHeight());
            paperDrawable.draw(canvas);
            if (scanImage != null) {
                if (showPaper) {
                    float f = copyScale / limitCopyScaleDown;
                    if (autofitEnabled) {
                        f = 1.0f / getAspectFitScale(scanFrame.width(), scanFrame.height(), (float) canvas.getWidth(), (float) canvas.getHeight(), Layout.AspectFit.Max);
                    }
                    Matrix matrix = new Matrix();
                    matrix.postScale(f, f);
                    matrix.postTranslate(((float) bitmap.getWidth()) - (((float) scanImage.getWidth()) * f), 0.0f);
                    canvas.clipPath(paperBorderClipPath);
                    canvas.drawBitmap(scanImage, matrix, (Paint) null);
                } else {
                    canvas.drawBitmap(scanImage, 0.0f, 0.0f, (Paint) null);
                }
            }
            canvas.restore();
            return bitmap;
        }
    }

    class LayoutBorderless extends LayoutStandard {

        /* renamed from: BO */
        int f367BO;

        /* renamed from: LO */
        int f368LO;

        /* renamed from: RO */
        int f369RO;

        /* renamed from: TO */
        int f370TO;

        LayoutBorderless(int i, int i2) {
            super(i, i2);
            ECopyOptionItem.ECopyOptionItemChoice selectedChoice = optionContext.getCopyOptionItemOf(ECopyOptionItem.ECopyOptionItemKey.PrintMediaSize).getSelectedChoice();
            if (selectedChoice == ECopyOptionItem.ECopyOptionItemChoice.PrintMediaSize_KG || selectedChoice == ECopyOptionItem.ECopyOptionItemChoice.PrintMediaSize_L || selectedChoice == ECopyOptionItem.ECopyOptionItemChoice.PrintMediaSize_Postcard) {
                f368LO = 15;
                f369RO = 15;
                f370TO = 8;
                f367BO = 15;
                return;
            }
            f368LO = 15;
            f369RO = 15;
            f370TO = 17;
            f367BO = 15;
        }

        private Bitmap getBitmap() {
            boolean showPaper = showPaper();
            Bitmap bitmap = showPaper ? paperImage : maxPaperImage;
            canvas = new Canvas(bitmap);
            canvas.save();
            paperDrawable.setBounds(0, 0, bitmap.getWidth(), bitmap.getHeight());
            paperDrawable.draw(canvas);
            if (scanImage != null) {
                if (showPaper) {
                    float f = copyScale;
                    if (autofitEnabled) {
                        f = 1.0f / getAspectFitScale(scanFrame.width(), scanFrame.height(), (float) ((paperImage.getWidth() + f368LO) + f369RO), (float) ((paperImage.getHeight() + f370TO) + f367BO), Layout.AspectFit.Min);
                    }
                    Matrix matrix = new Matrix();
                    matrix.postTranslate((float) (-this.f368LO), (float) (-this.f370TO));
                    matrix.postScale(f, f);
                    canvas.drawBitmap(scanImage, matrix, (Paint) null);
                } else {
                    canvas.drawBitmap(scanImage, (float) (-this.f368LO), (float) (-this.f370TO), (Paint) null);
                }
            }
            canvas.restore();
            return bitmap;
        }

        private void setPaperFrame(RectF rectF) {
            scanFrame = new RectF(rectF);
            scaleRect(imageScale, scanFrame);
            copyFrame = new RectF(rectF);
            scaleRect(imageScale, copyFrame);
            calcLimitCopyScaleDown();
            invalidatePaperSize();
            f368LO = (int) (((float) f368LO) * imageScale);
            f369RO = (int) (((float) f369RO) * imageScale);
            f370TO = (int) (((float) f370TO) * imageScale);
            f367BO = (int) (((float) f367BO) * imageScale);
        }
    }

    class Layout2Up extends Layout {
        RectF copyFrame;
        float imageScale;
        Point offset = new Point();
        RectF page1;
        Bitmap page1Bitmap;
        RectF page2;
        RectF paper;

        private RectF getCopyFrame() {
            return null;
        }

        private void setCopyScale(float f) {
        }

        Layout2Up(int i, int i2) {
            Size size = A4_2Up;
            Size size2 = A4_2UpPage;
            paper = new RectF(0.0f, 0.0f, (float) size.width, (float) size.height);
            page1 = new RectF(30.0f, 32.0f, (float) (size2.width + 30), (float) (size2.height + 32));
            page2 = new RectF(page1.right + 35.0f, page1.top, page1.right + 35.0f + ((float) size2.width), page1.bottom);
            float f = (float) i;
            float f2 = (float) i2;
            float aspectFitScale = getAspectFitScale(f, f2, (float) size.width, (float) size.height, Layout.AspectFit.Min);
            scaleRect(aspectFitScale, paper);
            scaleRect(aspectFitScale, page1);
            scaleRect(aspectFitScale, page2);
            offset.x = ((int) (f - paper.right)) / 2;
            offset.y = ((int) (f2 - paper.bottom)) / 2;
        }

        public Bitmap getBitmap() {
            Bitmap createBitmap = Bitmap.createBitmap((int) paper.width(), (int) paper.height(), Bitmap.Config.ARGB_8888);
            Canvas canvas = new Canvas(createBitmap);
            paperDrawable.setBounds(0, 0, createBitmap.getWidth(), createBitmap.getHeight());
            paperDrawable.draw(canvas);
            Bitmap createBitmap2 = Bitmap.createBitmap((int) page1.width(), (int) page1.height(), Bitmap.Config.ARGB_8888);
            new Canvas(createBitmap2).drawColor(-3355444);
            Bitmap bitmap = page1Bitmap;
            if (bitmap == null) {
                bitmap = createBitmap2;
            }
            canvas.drawBitmap(bitmap, (Rect) null, page1, (Paint) null);
            canvas.drawBitmap(createBitmap2, (Rect) null, page2, (Paint) null);
            return createBitmap;
        }

        private float getScanImageScale(int i, int i2) {
            imageScale = getAspectFitScale(page1.width(), page1.height(), (float) i, (float) i2, Layout.AspectFit.Min);
            return imageScale;
        }

        private void setScanImage(Bitmap bitmap) {
            Rect rect = new Rect((int) copyFrame.left, (int) copyFrame.top, (int) copyFrame.right, (int) copyFrame.bottom);
            page1Bitmap = Bitmap.createBitmap((int) page1.width(), (int) page1.height(), Bitmap.Config.ARGB_8888);
            Canvas canvas = new Canvas(page1Bitmap);
            canvas.drawBitmap(bitmap, rect, new RectF(0.0f, 0.0f, (float) canvas.getWidth(), (float) canvas.getHeight()), (Paint) null);
        }

        private Point getOffset() {
            return new Point(offset);
        }

        private void setPaperFrame(RectF rectF) {
            copyFrame = new RectF(rectF);
            scaleRect(imageScale, copyFrame);
        }

        private RectF getPaperRect() {
            return new RectF(0.0f, 0.0f, paper.width(), paper.height());
        }
    }
}
