Search in sources :

Example 6 with ImagePreset

use of com.android.gallery3d.filtershow.pipeline.ImagePreset in project android_packages_apps_Gallery2 by LineageOS.

the class Editor method commitLocalRepresentation.

/**
 * Call this to update the preset in MasterImage with a collection of FilterRepresentations.
 * This causes the preview bitmap to be regenerated.
 */
public void commitLocalRepresentation(Collection<FilterRepresentation> reps) {
    ImagePreset preset = MasterImage.getImage().getPreset();
    preset.updateFilterRepresentations(reps);
    if (mButton != null) {
        updateText();
    }
    if (mChangesGeometry) {
        // Regenerate both the filtered and the geometry-only bitmaps
        MasterImage.getImage().resetGeometryImages(true);
    }
    // Regenerate the filtered bitmap.
    MasterImage.getImage().invalidateFiltersOnly();
    preset.fillImageStateAdapter(MasterImage.getImage().getState());
}
Also used : ImagePreset(com.android.gallery3d.filtershow.pipeline.ImagePreset)

Example 7 with ImagePreset

use of com.android.gallery3d.filtershow.pipeline.ImagePreset in project android_packages_apps_Gallery2 by LineageOS.

the class ImageFilterDualCamera method apply.

@Override
public Bitmap apply(Bitmap bitmap, float scaleFactor, int quality) {
    if (mParameters == null) {
        return bitmap;
    }
    Point point = new Point(mParameters.getPoint());
    if (!point.equals(-1, -1)) {
        MasterImage image = MasterImage.getImage();
        Size size = getFilteredSize(image, quality);
        DualCameraEffect effect = image.getDualCameraEffect(size.getWidth(), size.getHeight());
        if (effect == null) {
            return bitmap;
        }
        size = effect.size();
        Bitmap filteredBitmap = image.getBitmapCache().getBitmap(size.getWidth(), size.getHeight(), BitmapCache.FILTERS);
        Log.d(TAG, "filtered: " + size.getWidth() + "x" + size.getHeight());
        filteredBitmap.setHasAlpha(mSupportFusion);
        float intensity = getIntensity();
        effect.map(point);
        int effectType = getEffectType();
        boolean result = effect.render(effectType, point.x, point.y, filteredBitmap, intensity);
        if (!result) {
            showToast(R.string.dualcam_no_segment_toast, Toast.LENGTH_SHORT);
            return bitmap;
        }
        mPaint.reset();
        mPaint.setAntiAlias(true);
        if (quality == FilterEnvironment.QUALITY_FINAL) {
            mPaint.setFilterBitmap(true);
            mPaint.setDither(true);
        }
        Canvas canvas = new Canvas(bitmap);
        ImagePreset preset = getEnvironment().getImagePreset();
        int bmWidth = bitmap.getWidth();
        int bmHeight = bitmap.getHeight();
        GeometryHolder holder;
        if (preset.getDoApplyGeometry()) {
            holder = GeometryMathUtils.unpackGeometry(preset.getGeometryFilters());
        } else {
            holder = new GeometryHolder();
        }
        RectF roiRectF = new RectF();
        roiRectF.left = 0;
        roiRectF.top = 0;
        roiRectF.right = 1;
        roiRectF.bottom = 1;
        int zoomOrientation = image.getZoomOrientation();
        if (isRotated(zoomOrientation)) {
            Matrix mt = new Matrix();
            mt.preRotate(GeometryMathUtils.getRotationForOrientation(zoomOrientation), 0.5f, 0.5f);
            mt.mapRect(roiRectF);
        }
        // Check for ROI cropping
        if (!FilterCropRepresentation.getNil().equals(roiRectF)) {
            if (FilterCropRepresentation.getNil().equals(holder.crop)) {
                // no crop filter, set crop to be roiRect
                holder.crop.set(roiRectF);
            } else if (!roiRectF.contains(holder.crop)) {
                // take smaller intersecting area between roiRect and crop rect
                holder.crop.left = Math.max(holder.crop.left, roiRectF.left);
                holder.crop.top = Math.max(holder.crop.top, roiRectF.top);
                holder.crop.right = Math.min(holder.crop.right, roiRectF.right);
                holder.crop.bottom = Math.min(holder.crop.bottom, roiRectF.bottom);
            }
        }
        RectF crop = new RectF();
        Matrix m = GeometryMathUtils.getOriginalToScreen(holder, crop, true, size.getWidth(), size.getHeight(), bmWidth, bmHeight);
        if (mSupportFusion)
            canvas.drawColor(0, PorterDuff.Mode.CLEAR);
        canvas.save();
        canvas.clipRect(crop);
        canvas.drawBitmap(filteredBitmap, m, mPaint);
        canvas.restore();
        image.getBitmapCache().cache(filteredBitmap);
    }
    return bitmap;
}
Also used : MasterImage(com.android.gallery3d.filtershow.imageshow.MasterImage) GeometryHolder(com.android.gallery3d.filtershow.imageshow.GeometryMathUtils.GeometryHolder) Size(android.util.Size) Canvas(android.graphics.Canvas) ImagePreset(com.android.gallery3d.filtershow.pipeline.ImagePreset) Point(android.graphics.Point) Point(android.graphics.Point) Paint(android.graphics.Paint) RectF(android.graphics.RectF) Bitmap(android.graphics.Bitmap) Matrix(android.graphics.Matrix) DualCameraEffect(com.android.gallery3d.filtershow.tools.DualCameraEffect)

Example 8 with ImagePreset

use of com.android.gallery3d.filtershow.pipeline.ImagePreset in project android_packages_apps_Gallery2 by LineageOS.

the class XmpPresets method extractXMPData.

public static XMresults extractXMPData(Context context, MasterImage mMasterImage, Uri uriToEdit) {
    XMresults ret = new XMresults();
    InputStream is = null;
    XMPMeta xmpMeta = null;
    try {
        is = context.getContentResolver().openInputStream(uriToEdit);
        xmpMeta = XmpUtilHelper.extractXMPMeta(is);
    } catch (FileNotFoundException e) {
    } finally {
        Utils.closeSilently(is);
    }
    if (xmpMeta == null) {
        return null;
    }
    try {
        String strSrcUri = xmpMeta.getPropertyString(XMP_GOOGLE_FILTER_NAMESPACE, XMP_SRC_FILE_URI);
        if (strSrcUri != null) {
            String filterString = xmpMeta.getPropertyString(XMP_GOOGLE_FILTER_NAMESPACE, XMP_FILTERSTACK);
            Uri srcUri = Uri.parse(strSrcUri);
            ret.originalimage = srcUri;
            ret.preset = new ImagePreset();
            ret.presetString = filterString;
            boolean ok = ret.preset.readJsonFromString(filterString);
            if (!ok) {
                return null;
            }
            return ret;
        }
    } catch (XMPException e) {
        e.printStackTrace();
    }
    return null;
}
Also used : XMPMeta(com.adobe.xmp.XMPMeta) InputStream(java.io.InputStream) FileNotFoundException(java.io.FileNotFoundException) ImagePreset(com.android.gallery3d.filtershow.pipeline.ImagePreset) XMPException(com.adobe.xmp.XMPException) Uri(android.net.Uri)

Example 9 with ImagePreset

use of com.android.gallery3d.filtershow.pipeline.ImagePreset in project android_packages_apps_Gallery2 by LineageOS.

the class ExportDialog method initCustomLayout.

private View initCustomLayout() {
    LayoutInflater inflater = getActivity().getLayoutInflater();
    View view = inflater.inflate(R.layout.filtershow_export_dialog, null);
    mSeekBar = (SeekBar) view.findViewById(R.id.qualitySeekBar);
    mSeekVal = (TextView) view.findViewById(R.id.qualityTextView);
    mSliderLabel = getString(R.string.quality) + ": ";
    mSeekBar.setProgress(mQuality);
    mSeekVal.setText(mSliderLabel + mSeekBar.getProgress());
    mSeekBar.setOnSeekBarChangeListener(this);
    mWidthText = (EditText) view.findViewById(R.id.editableWidth);
    mHeightText = (EditText) view.findViewById(R.id.editableHeight);
    mEstimatedSize = (TextView) view.findViewById(R.id.estimadedSize);
    mOriginalBounds = MasterImage.getImage().getOriginalBounds();
    ImagePreset preset = MasterImage.getImage().getPreset();
    if (mOriginalBounds == null || preset == null)
        return null;
    mOriginalBounds = preset.finalGeometryRect(mOriginalBounds.width(), mOriginalBounds.height());
    if (preset != null) {
        mOriginalBounds = preset.finalGeometryRect(mOriginalBounds.width(), mOriginalBounds.height());
    }
    if (mOriginalBounds == null) {
        return null;
    }
    mRatio = mOriginalBounds.width() / (float) mOriginalBounds.height();
    mWidthText.setText("" + mOriginalBounds.width());
    mHeightText.setText("" + mOriginalBounds.height());
    mExportWidth = mOriginalBounds.width();
    mExportHeight = mOriginalBounds.height();
    mWidthText.addTextChangedListener(new Watcher(mWidthText));
    mHeightText.addTextChangedListener(new Watcher(mHeightText));
    return view;
}
Also used : LayoutInflater(android.view.LayoutInflater) ImagePreset(com.android.gallery3d.filtershow.pipeline.ImagePreset) TextWatcher(android.text.TextWatcher) View(android.view.View) TextView(android.widget.TextView)

Example 10 with ImagePreset

use of com.android.gallery3d.filtershow.pipeline.ImagePreset in project android_packages_apps_Gallery2 by LineageOS.

the class MasterImage method resetGeometryImages.

public void resetGeometryImages(boolean force) {
    if (mPreset == null) {
        return;
    }
    ImagePreset newPresetGeometryOnly = new ImagePreset(mPreset);
    newPresetGeometryOnly.setDoApplyFilters(false);
    newPresetGeometryOnly.setDoApplyGeometry(true);
    if (force || mGeometryOnlyPreset == null || !newPresetGeometryOnly.equals(mGeometryOnlyPreset)) {
        mGeometryOnlyPreset = newPresetGeometryOnly;
        RenderingRequest.post(mActivity, null, mGeometryOnlyPreset, RenderingRequest.GEOMETRY_RENDERING, this);
    }
    ImagePreset newPresetFiltersOnly = new ImagePreset(mPreset);
    newPresetFiltersOnly.setDoApplyFilters(true);
    newPresetFiltersOnly.setDoApplyGeometry(false);
    if (force || mFiltersOnlyPreset == null || !newPresetFiltersOnly.same(mFiltersOnlyPreset)) {
        mFiltersOnlyPreset = newPresetFiltersOnly;
        RenderingRequest.post(mActivity, null, mFiltersOnlyPreset, RenderingRequest.FILTERS_RENDERING, this);
    }
}
Also used : ImagePreset(com.android.gallery3d.filtershow.pipeline.ImagePreset)

Aggregations

ImagePreset (com.android.gallery3d.filtershow.pipeline.ImagePreset)28 FilterRepresentation (com.android.gallery3d.filtershow.filters.FilterRepresentation)8 Bitmap (android.graphics.Bitmap)7 Matrix (android.graphics.Matrix)4 Point (android.graphics.Point)4 FilterUserPresetRepresentation (com.android.gallery3d.filtershow.filters.FilterUserPresetRepresentation)4 RectF (android.graphics.RectF)3 Uri (android.net.Uri)3 FilterMirrorRepresentation (com.android.gallery3d.filtershow.filters.FilterMirrorRepresentation)3 FilterRotateRepresentation (com.android.gallery3d.filtershow.filters.FilterRotateRepresentation)3 Canvas (android.graphics.Canvas)2 Paint (android.graphics.Paint)2 Rect (android.graphics.Rect)2 XMPMeta (com.adobe.xmp.XMPMeta)2 Action (com.android.gallery3d.filtershow.category.Action)2 FilterPresetSource (com.android.gallery3d.filtershow.data.FilterPresetSource)2 SaveOption (com.android.gallery3d.filtershow.data.FilterPresetSource.SaveOption)2 HistoryItem (com.android.gallery3d.filtershow.history.HistoryItem)2 GeometryHolder (com.android.gallery3d.filtershow.imageshow.GeometryMathUtils.GeometryHolder)2 MasterImage (com.android.gallery3d.filtershow.imageshow.MasterImage)2