Search in sources :

Example 1 with FilterMirrorRepresentation

use of com.android.gallery3d.filtershow.filters.FilterMirrorRepresentation in project android_packages_apps_Gallery2 by LineageOS.

the class FilterShowActivity method showRepresentation.

public void showRepresentation(FilterRepresentation representation) {
    if (representation == null) {
        return;
    }
    Fragment currentPanel = getSupportFragmentManager().findFragmentByTag(MainPanel.FRAGMENT_TAG);
    if (currentPanel instanceof MainPanel && ((MainPanel) currentPanel).hasEditorPanel()) {
        if (representation.equals(MasterImage.getImage().getCurrentFilterRepresentation())) {
            return;
        }
        // cancel previous filter.
        cancelCurrentFilter();
        showDefaultImageView();
        removeSeekBarPanel();
    }
    if (representation instanceof FilterRotateRepresentation) {
        FilterRotateRepresentation r = (FilterRotateRepresentation) representation;
        r.rotateCW();
    }
    if (representation instanceof FilterMirrorRepresentation) {
        FilterMirrorRepresentation r = (FilterMirrorRepresentation) representation;
        r.cycle();
    }
    if (representation.isBooleanFilter()) {
        ImagePreset preset = MasterImage.getImage().getPreset();
        if (preset.getRepresentation(representation) != null) {
            // remove
            ImagePreset copy = new ImagePreset(preset);
            copy.removeFilter(representation);
            FilterRepresentation filterRepresentation = representation.copy();
            MasterImage.getImage().setPreset(copy, filterRepresentation, true);
            MasterImage.getImage().setCurrentFilterRepresentation(null);
            setActionBar();
            showActionBar(true);
            return;
        }
    }
    if (representation.getFilterType() == FilterRepresentation.TYPE_DUALCAM) {
        DisplayMetrics dm = getResources().getDisplayMetrics();
        float[] mTmpPoint = new float[2];
        mTmpPoint[0] = dm.widthPixels / 2;
        mTmpPoint[1] = dm.heightPixels / 2;
        Matrix m = MasterImage.getImage().getScreenToImageMatrix(true);
        m.mapPoints(mTmpPoint);
        if (representation instanceof FilterDualCamBasicRepresentation) {
            ((FilterDualCamBasicRepresentation) representation).setPoint((int) mTmpPoint[0], (int) mTmpPoint[1]);
        }
        if (representation instanceof FilterDualCamFusionRepresentation) {
            ((FilterDualCamFusionRepresentation) representation).setPoint((int) mTmpPoint[0], (int) mTmpPoint[1]);
        }
    }
    if (representation.getFilterType() == FilterRepresentation.TYPE_WATERMARK) {
        if (MasterImage.getImage().getCurrentFilterRepresentation() != null && representation.getSerializationName().equals(MasterImage.getImage().getCurrentFilterRepresentation().getSerializationName())) {
            return;
        }
        showWaterMark(representation);
    }
    if (TrueScannerActs.SERIALIZATION_NAME.equals(representation.getSerializationName())) {
        Bitmap b = MasterImage.getImage().getOriginalBitmapHighres();
        int w = b.getWidth();
        int h = b.getHeight();
        if (w < h) {
            w = h;
            h = b.getWidth();
        }
        if (w <= TrueScannerActs.MIN_WIDTH || h <= TrueScannerActs.MIN_HEIGHT) {
            Toast.makeText(this, getString(R.string.image_size_too_small), Toast.LENGTH_SHORT).show();
            return;
        }
    }
    useFilterRepresentation(representation);
    loadEditorPanel(representation);
}
Also used : FilterMirrorRepresentation(com.android.gallery3d.filtershow.filters.FilterMirrorRepresentation) FilterDualCamFusionRepresentation(com.android.gallery3d.filtershow.filters.FilterDualCamFusionRepresentation) ImagePreset(com.android.gallery3d.filtershow.pipeline.ImagePreset) FilterRepresentation(com.android.gallery3d.filtershow.filters.FilterRepresentation) Fragment(android.support.v4.app.Fragment) MediaPickerFragment(com.android.gallery3d.filtershow.mediapicker.MediaPickerFragment) DialogFragment(android.support.v4.app.DialogFragment) DisplayMetrics(android.util.DisplayMetrics) FilterDualCamBasicRepresentation(com.android.gallery3d.filtershow.filters.FilterDualCamBasicRepresentation) Point(android.graphics.Point) Bitmap(android.graphics.Bitmap) Matrix(android.graphics.Matrix) MainPanel(com.android.gallery3d.filtershow.category.MainPanel) FilterRotateRepresentation(com.android.gallery3d.filtershow.filters.FilterRotateRepresentation)

Example 2 with FilterMirrorRepresentation

use of com.android.gallery3d.filtershow.filters.FilterMirrorRepresentation in project android_packages_apps_Gallery2 by LineageOS.

the class EditorMirror method reflectCurrentFilter.

@Override
public void reflectCurrentFilter() {
    MasterImage master = MasterImage.getImage();
    master.setCurrentFilterRepresentation(master.getPreset().getFilterWithSerializationName(FilterMirrorRepresentation.SERIALIZATION_NAME));
    super.reflectCurrentFilter();
    FilterRepresentation rep = getLocalRepresentation();
    if (rep == null || rep instanceof FilterMirrorRepresentation) {
        mImageMirror.setFilterMirrorRepresentation((FilterMirrorRepresentation) rep);
    } else {
        Log.w(TAG, "Could not reflect current filter, not of type: " + FilterMirrorRepresentation.class.getSimpleName());
    }
    mImageMirror.invalidate();
}
Also used : MasterImage(com.android.gallery3d.filtershow.imageshow.MasterImage) FilterMirrorRepresentation(com.android.gallery3d.filtershow.filters.FilterMirrorRepresentation) FilterRepresentation(com.android.gallery3d.filtershow.filters.FilterRepresentation)

Example 3 with FilterMirrorRepresentation

use of com.android.gallery3d.filtershow.filters.FilterMirrorRepresentation in project android_packages_apps_Gallery2 by LineageOS.

the class ImageShow method drawImageAndAnimate.

public void drawImageAndAnimate(Canvas canvas, Bitmap image) {
    if (image == null) {
        return;
    }
    MasterImage master = MasterImage.getImage();
    Matrix m = master.computeImageToScreen(image, 0, false);
    if (m == null) {
        return;
    }
    canvas.save();
    RectF d = new RectF(0, 0, image.getWidth(), image.getHeight());
    m.mapRect(d);
    d.roundOut(mImageBounds);
    master.setImageBounds(canvas, mImageBounds);
    boolean showAnimatedImage = master.onGoingNewLookAnimation();
    if (!showAnimatedImage && mDidStartAnimation) {
        // animation ended, but do we have the correct image to show?
        if (master.getPreset().equals(master.getCurrentPreset())) {
            // we do, let's stop showing the animated image
            mDidStartAnimation = false;
            MasterImage.getImage().resetAnimBitmap();
        } else {
            showAnimatedImage = true;
        }
    } else if (showAnimatedImage) {
        mDidStartAnimation = true;
    }
    if (showAnimatedImage) {
        canvas.save();
        // Animation uses the image before the change
        Bitmap previousImage = master.getPreviousImage();
        Matrix mp = master.computeImageToScreen(previousImage, 0, false);
        RectF dp = new RectF(0, 0, previousImage.getWidth(), previousImage.getHeight());
        mp.mapRect(dp);
        Rect previousBounds = new Rect();
        dp.roundOut(previousBounds);
        float centerX = dp.centerX();
        float centerY = dp.centerY();
        boolean needsToDrawImage = true;
        if (master.getCurrentLookAnimation() == MasterImage.CIRCLE_ANIMATION) {
            float maskScale = MasterImage.getImage().getMaskScale();
            if (maskScale >= 0.0f) {
                float maskW = sMask.getWidth() / 2.0f;
                float maskH = sMask.getHeight() / 2.0f;
                Point point = mActivity.hintTouchPoint(this);
                float maxMaskScale = 2 * Math.max(getWidth(), getHeight()) / Math.min(maskW, maskH);
                maskScale = maskScale * maxMaskScale;
                float x = point.x - maskW * maskScale;
                float y = point.y - maskH * maskScale;
                // Prepare the shader
                mShaderMatrix.reset();
                mShaderMatrix.setScale(1.0f / maskScale, 1.0f / maskScale);
                mShaderMatrix.preTranslate(-x + mImageBounds.left, -y + mImageBounds.top);
                float scaleImageX = mImageBounds.width() / (float) image.getWidth();
                float scaleImageY = mImageBounds.height() / (float) image.getHeight();
                mShaderMatrix.preScale(scaleImageX, scaleImageY);
                mMaskPaint.reset();
                Shader maskShader = createShader(image);
                maskShader.setLocalMatrix(mShaderMatrix);
                mMaskPaint.setShader(maskShader);
                // as needed
                drawShadow(canvas, mImageBounds);
                canvas.drawBitmap(previousImage, m, mPaint);
                canvas.clipRect(mImageBounds);
                canvas.translate(x, y);
                canvas.scale(maskScale, maskScale);
                canvas.drawBitmap(sMask, 0, 0, mMaskPaint);
                needsToDrawImage = false;
            }
        } else if (master.getCurrentLookAnimation() == MasterImage.ROTATE_ANIMATION) {
            Rect d1 = computeImageBounds(master.getPreviousImage().getHeight(), master.getPreviousImage().getWidth());
            Rect d2 = computeImageBounds(master.getPreviousImage().getWidth(), master.getPreviousImage().getHeight());
            float finalScale = d1.width() / (float) d2.height();
            finalScale = (1.0f * (1.0f - master.getAnimFraction())) + (finalScale * master.getAnimFraction());
            canvas.rotate(master.getAnimRotationValue(), centerX, centerY);
            canvas.scale(finalScale, finalScale, centerX, centerY);
        } else if (master.getCurrentLookAnimation() == MasterImage.MIRROR_ANIMATION) {
            if (master.getCurrentFilterRepresentation() instanceof FilterMirrorRepresentation) {
                FilterMirrorRepresentation rep = (FilterMirrorRepresentation) master.getCurrentFilterRepresentation();
                ImagePreset preset = master.getPreset();
                ArrayList<FilterRepresentation> geometry = (ArrayList<FilterRepresentation>) preset.getGeometryFilters();
                GeometryMathUtils.GeometryHolder holder = null;
                holder = GeometryMathUtils.unpackGeometry(geometry);
                if (holder.rotation.value() == 90 || holder.rotation.value() == 270) {
                    if (rep.isHorizontal() && !rep.isVertical()) {
                        canvas.scale(1, master.getAnimRotationValue(), centerX, centerY);
                    } else if (rep.isVertical() && !rep.isHorizontal()) {
                        canvas.scale(1, master.getAnimRotationValue(), centerX, centerY);
                    } else if (rep.isHorizontal() && rep.isVertical()) {
                        canvas.scale(master.getAnimRotationValue(), 1, centerX, centerY);
                    } else {
                        canvas.scale(master.getAnimRotationValue(), 1, centerX, centerY);
                    }
                } else {
                    if (rep.isHorizontal() && !rep.isVertical()) {
                        canvas.scale(master.getAnimRotationValue(), 1, centerX, centerY);
                    } else if (rep.isVertical() && !rep.isHorizontal()) {
                        canvas.scale(master.getAnimRotationValue(), 1, centerX, centerY);
                    } else if (rep.isHorizontal() && rep.isVertical()) {
                        canvas.scale(1, master.getAnimRotationValue(), centerX, centerY);
                    } else {
                        canvas.scale(1, master.getAnimRotationValue(), centerX, centerY);
                    }
                }
            }
        }
        if (needsToDrawImage) {
            // as needed
            drawShadow(canvas, previousBounds);
            if (hasFusionApplied() || this instanceof ImageFusion) {
                previousImage.setHasAlpha(true);
            }
            canvas.drawBitmap(previousImage, mp, mPaint);
        }
        canvas.restore();
    } else {
        // as needed
        drawShadow(canvas, mImageBounds);
        if (hasFusionApplied() || this instanceof ImageFusion) {
            image.setHasAlpha(true);
        }
        canvas.drawBitmap(image, m, mPaint);
    }
    canvas.restore();
}
Also used : FilterMirrorRepresentation(com.android.gallery3d.filtershow.filters.FilterMirrorRepresentation) Rect(android.graphics.Rect) ImagePreset(com.android.gallery3d.filtershow.pipeline.ImagePreset) ArrayList(java.util.ArrayList) FilterRepresentation(com.android.gallery3d.filtershow.filters.FilterRepresentation) Point(android.graphics.Point) Shader(android.graphics.Shader) BitmapShader(android.graphics.BitmapShader) RectF(android.graphics.RectF) Bitmap(android.graphics.Bitmap) Matrix(android.graphics.Matrix)

Example 4 with FilterMirrorRepresentation

use of com.android.gallery3d.filtershow.filters.FilterMirrorRepresentation in project android_packages_apps_Gallery2 by LineageOS.

the class FilterShowActivity method useFilterRepresentation.

public void useFilterRepresentation(FilterRepresentation filterRepresentation) {
    if (filterRepresentation == null) {
        return;
    }
    if (!(filterRepresentation instanceof FilterRotateRepresentation) && !(filterRepresentation instanceof FilterMirrorRepresentation) && MasterImage.getImage().getCurrentFilterRepresentation() == filterRepresentation) {
        return;
    }
    if (filterRepresentation.getFilterType() == FilterWatermarkRepresentation.TYPE_WATERMARK_CATEGORY) {
        return;
    }
    boolean addToHistory = filterRepresentation.getFilterType() != FilterWatermarkRepresentation.TYPE_WATERMARK;
    if (filterRepresentation instanceof FilterUserPresetRepresentation || filterRepresentation instanceof FilterRotateRepresentation || filterRepresentation instanceof FilterMirrorRepresentation) {
        MasterImage.getImage().onNewLook(filterRepresentation);
    }
    ImagePreset oldPreset = MasterImage.getImage().getPreset();
    ImagePreset copy = new ImagePreset(oldPreset);
    FilterRepresentation representation = copy.getRepresentation(filterRepresentation);
    if (representation == null) {
        filterRepresentation = filterRepresentation.copy();
        copy.addFilter(filterRepresentation);
    } else {
        if (filterRepresentation.allowsSingleInstanceOnly()) {
            // null.
            if (!representation.equals(filterRepresentation)) {
                // Only do this if the filter isn't the same
                // (state panel clicks can lead us here)
                copy.removeFilter(representation);
                copy.addFilter(filterRepresentation);
            }
        }
    }
    MasterImage.getImage().setPreset(copy, filterRepresentation, addToHistory);
    MasterImage.getImage().setCurrentFilterRepresentation(filterRepresentation);
}
Also used : FilterMirrorRepresentation(com.android.gallery3d.filtershow.filters.FilterMirrorRepresentation) ImagePreset(com.android.gallery3d.filtershow.pipeline.ImagePreset) FilterRepresentation(com.android.gallery3d.filtershow.filters.FilterRepresentation) FilterRotateRepresentation(com.android.gallery3d.filtershow.filters.FilterRotateRepresentation) FilterUserPresetRepresentation(com.android.gallery3d.filtershow.filters.FilterUserPresetRepresentation)

Example 5 with FilterMirrorRepresentation

use of com.android.gallery3d.filtershow.filters.FilterMirrorRepresentation in project android_packages_apps_Gallery2 by LineageOS.

the class ImagePreset method equals.

public boolean equals(ImagePreset preset) {
    if (preset == null) {
        return false;
    }
    if (preset.mFilters.size() != mFilters.size()) {
        return false;
    }
    if (mDoApplyGeometry != preset.mDoApplyGeometry) {
        return false;
    }
    if (mDoApplyFilters != preset.mDoApplyFilters) {
        if (mFilters.size() > 0 || preset.mFilters.size() > 0) {
            return false;
        }
    }
    for (int i = 0; i < preset.mFilters.size(); i++) {
        FilterRepresentation a = preset.mFilters.elementAt(i);
        FilterRepresentation b = mFilters.elementAt(i);
        boolean isGeometry = false;
        if (a instanceof FilterRotateRepresentation || a instanceof FilterMirrorRepresentation || a instanceof FilterCropRepresentation || a instanceof FilterStraightenRepresentation) {
            isGeometry = true;
        }
        boolean evaluate = true;
        if (!isGeometry && mDoApplyGeometry && !mDoApplyFilters) {
            evaluate = false;
        } else if (isGeometry && !mDoApplyGeometry && mDoApplyFilters) {
            evaluate = false;
        }
        if (evaluate && !a.equals(b)) {
            return false;
        }
    }
    return true;
}
Also used : FilterMirrorRepresentation(com.android.gallery3d.filtershow.filters.FilterMirrorRepresentation) FilterStraightenRepresentation(com.android.gallery3d.filtershow.filters.FilterStraightenRepresentation) FilterRepresentation(com.android.gallery3d.filtershow.filters.FilterRepresentation) FilterCropRepresentation(com.android.gallery3d.filtershow.filters.FilterCropRepresentation) FilterRotateRepresentation(com.android.gallery3d.filtershow.filters.FilterRotateRepresentation)

Aggregations

FilterMirrorRepresentation (com.android.gallery3d.filtershow.filters.FilterMirrorRepresentation)5 FilterRepresentation (com.android.gallery3d.filtershow.filters.FilterRepresentation)5 FilterRotateRepresentation (com.android.gallery3d.filtershow.filters.FilterRotateRepresentation)3 ImagePreset (com.android.gallery3d.filtershow.pipeline.ImagePreset)3 Bitmap (android.graphics.Bitmap)2 Matrix (android.graphics.Matrix)2 Point (android.graphics.Point)2 BitmapShader (android.graphics.BitmapShader)1 Rect (android.graphics.Rect)1 RectF (android.graphics.RectF)1 Shader (android.graphics.Shader)1 DialogFragment (android.support.v4.app.DialogFragment)1 Fragment (android.support.v4.app.Fragment)1 DisplayMetrics (android.util.DisplayMetrics)1 MainPanel (com.android.gallery3d.filtershow.category.MainPanel)1 FilterCropRepresentation (com.android.gallery3d.filtershow.filters.FilterCropRepresentation)1 FilterDualCamBasicRepresentation (com.android.gallery3d.filtershow.filters.FilterDualCamBasicRepresentation)1 FilterDualCamFusionRepresentation (com.android.gallery3d.filtershow.filters.FilterDualCamFusionRepresentation)1 FilterStraightenRepresentation (com.android.gallery3d.filtershow.filters.FilterStraightenRepresentation)1 FilterUserPresetRepresentation (com.android.gallery3d.filtershow.filters.FilterUserPresetRepresentation)1