diff options
Diffstat (limited to 'src')
9 files changed, 123 insertions, 76 deletions
diff --git a/src/com/android/camera/VideoModule.java b/src/com/android/camera/VideoModule.java index 115b7d0a7..998bbf784 100644 --- a/src/com/android/camera/VideoModule.java +++ b/src/com/android/camera/VideoModule.java @@ -736,6 +736,9 @@ public class VideoModule implements CameraModule, startPreview(); } }).start(); + } else { + // preview already started + mUI.enableShutter(true); } // Initializing it here after the preview is started. diff --git a/src/com/android/gallery3d/filtershow/cache/CachingPipeline.java b/src/com/android/gallery3d/filtershow/cache/CachingPipeline.java index 9d4da0214..8d7fcd5d5 100644 --- a/src/com/android/gallery3d/filtershow/cache/CachingPipeline.java +++ b/src/com/android/gallery3d/filtershow/cache/CachingPipeline.java @@ -30,6 +30,8 @@ public class CachingPipeline { private static final String LOGTAG = "CachingPipeline"; private boolean DEBUG = false; + private static final Bitmap.Config BITMAP_CONFIG = Bitmap.Config.ARGB_8888; + private FiltersManager mFiltersManager = null; private volatile Bitmap mOriginalBitmap = null; private volatile Bitmap mResizedOriginalBitmap = null; @@ -37,6 +39,11 @@ public class CachingPipeline { private volatile Allocation mOriginalAllocation = null; private volatile Allocation mFiltersOnlyOriginalAllocation = null; + protected volatile Allocation mInPixelsAllocation; + protected volatile Allocation mOutPixelsAllocation; + private volatile int mWidth = 0; + private volatile int mHeight = 0; + private volatile GeometryMetadata mPreviousGeometry = null; private volatile float mPreviewScaleFactor = 1.0f; @@ -60,6 +67,21 @@ public class CachingPipeline { } mPreviousGeometry = null; mPreviewScaleFactor = 1.0f; + + destroyPixelAllocations(); + } + + private synchronized void destroyPixelAllocations() { + if (mInPixelsAllocation != null) { + mInPixelsAllocation.destroy(); + mInPixelsAllocation = null; + } + if (mOutPixelsAllocation != null) { + mOutPixelsAllocation.destroy(); + mOutPixelsAllocation = null; + } + mWidth = 0; + mHeight = 0; } private String getType(RenderingRequest request) { @@ -85,6 +107,7 @@ public class CachingPipeline { preset.setScaleFactor(mPreviewScaleFactor); preset.setQuality(ImagePreset.QUALITY_PREVIEW); preset.setupEnvironment(mFiltersManager); + preset.getEnvironment().setCachingPipeline(this); } public void setOriginal(Bitmap bitmap) { @@ -244,4 +267,38 @@ public class CachingPipeline { public synchronized boolean isInitialized() { return mOriginalBitmap != null; } + + public boolean prepareRenderscriptAllocations(Bitmap bitmap) { + RenderScript RS = ImageFilterRS.getRenderScriptContext(); + boolean needsUpdate = false; + if (mOutPixelsAllocation == null || mInPixelsAllocation == null || + bitmap.getWidth() != mWidth || bitmap.getHeight() != mHeight) { + destroyPixelAllocations(); + Bitmap bitmapBuffer = bitmap; + if (bitmap.getConfig() == null || bitmap.getConfig() != BITMAP_CONFIG) { + bitmapBuffer = bitmap.copy(BITMAP_CONFIG, true); + } + mOutPixelsAllocation = Allocation.createFromBitmap(RS, bitmapBuffer, + Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_SCRIPT); + mInPixelsAllocation = Allocation.createTyped(RS, + mOutPixelsAllocation.getType()); + needsUpdate = true; + } + mInPixelsAllocation.copyFrom(bitmap); + if (bitmap.getWidth() != mWidth + || bitmap.getHeight() != mHeight) { + mWidth = bitmap.getWidth(); + mHeight = bitmap.getHeight(); + needsUpdate = true; + } + return needsUpdate; + } + + public Allocation getInPixelsAllocation() { + return mInPixelsAllocation; + } + + public Allocation getOutPixelsAllocation() { + return mOutPixelsAllocation; + } } diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilter.java b/src/com/android/gallery3d/filtershow/filters/ImageFilter.java index bd9dcafcf..63a76627a 100644 --- a/src/com/android/gallery3d/filtershow/filters/ImageFilter.java +++ b/src/com/android/gallery3d/filtershow/filters/ImageFilter.java @@ -22,11 +22,11 @@ import android.widget.Toast; import com.android.gallery3d.filtershow.FilterShowActivity; import com.android.gallery3d.filtershow.imageshow.GeometryMetadata; +import com.android.gallery3d.filtershow.presets.FilterEnvironment; import com.android.gallery3d.filtershow.presets.ImagePreset; public abstract class ImageFilter implements Cloneable { - - private ImagePreset mImagePreset; + private FilterEnvironment mEnvironment = null; protected String mName = "Original"; private final String LOGTAG = "ImageFilter"; @@ -79,11 +79,7 @@ public abstract class ImageFilter implements Cloneable { } public ImagePreset getImagePreset() { - return mImagePreset; - } - - public void setImagePreset(ImagePreset imagePreset) { - mImagePreset = imagePreset; + return getEnvironment().getImagePreset(); } public abstract void useRepresentation(FilterRepresentation representation); @@ -103,4 +99,12 @@ public abstract class ImageFilter implements Cloneable { w, h); return originalToScreen; } + + public void setEnvironment(FilterEnvironment environment) { + mEnvironment = environment; + } + + public FilterEnvironment getEnvironment() { + return mEnvironment; + } } diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilterRS.java b/src/com/android/gallery3d/filtershow/filters/ImageFilterRS.java index 338cf51cd..b91051dbb 100644 --- a/src/com/android/gallery3d/filtershow/filters/ImageFilterRS.java +++ b/src/com/android/gallery3d/filtershow/filters/ImageFilterRS.java @@ -23,53 +23,15 @@ import android.support.v8.renderscript.*; import android.util.Log; import android.content.res.Resources; import com.android.gallery3d.R; +import com.android.gallery3d.filtershow.cache.CachingPipeline; public abstract class ImageFilterRS extends ImageFilter { private static final String LOGTAG = "ImageFilterRS"; - protected static volatile Allocation mInPixelsAllocation; - protected static volatile Allocation mOutPixelsAllocation; - private static volatile RenderScript sRS = null; - private static volatile int sWidth = 0; - private static volatile int sHeight = 0; - private static volatile Resources sResources = null; private volatile boolean mResourcesLoaded = false; - private static final Bitmap.Config BITMAP_CONFIG = Bitmap.Config.ARGB_8888; - - private volatile Bitmap mSourceBitmap = null; - - public Bitmap getSourceBitmap() { - return mSourceBitmap; - } - - // This must be used inside block synchronized on ImageFilterRS class object - protected void prepare(Bitmap bitmap, float scaleFactor, int quality) { - if (mOutPixelsAllocation == null || mInPixelsAllocation == null || - bitmap.getWidth() != sWidth || bitmap.getHeight() != sHeight) { - destroyPixelAllocations(); - Bitmap bitmapBuffer = bitmap; - if (bitmap.getConfig() == null || bitmap.getConfig() != BITMAP_CONFIG) { - bitmapBuffer = bitmap.copy(BITMAP_CONFIG, true); - } - mOutPixelsAllocation = Allocation.createFromBitmap(sRS, bitmapBuffer, - Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_SCRIPT); - mInPixelsAllocation = Allocation.createTyped(sRS, - mOutPixelsAllocation.getType()); - } - mInPixelsAllocation.copyFrom(bitmap); - if (bitmap.getWidth() != sWidth - || bitmap.getHeight() != sHeight || !isResourcesLoaded()) { - freeResources(); - createFilter(sResources, scaleFactor, quality); - sWidth = bitmap.getWidth(); - sHeight = bitmap.getHeight(); - setResourcesLoaded(true); - } - } - // This must be used inside block synchronized on ImageFilterRS class object protected abstract void createFilter(android.content.res.Resources res, float scaleFactor, int quality); @@ -79,7 +41,17 @@ public abstract class ImageFilterRS extends ImageFilter { // This must be used inside block synchronized on ImageFilterRS class object protected void update(Bitmap bitmap) { - mOutPixelsAllocation.copyTo(bitmap); + getOutPixelsAllocation().copyTo(bitmap); + } + + protected Allocation getInPixelsAllocation() { + CachingPipeline pipeline = getEnvironment().getCachingPipeline(); + return pipeline.getInPixelsAllocation(); + } + + protected Allocation getOutPixelsAllocation() { + CachingPipeline pipeline = getEnvironment().getCachingPipeline(); + return pipeline.getOutPixelsAllocation(); } @Override @@ -93,8 +65,14 @@ public abstract class ImageFilterRS extends ImageFilter { Log.w(LOGTAG, "Cannot apply before calling createRenderScriptContext"); return bitmap; } - mSourceBitmap = bitmap; - prepare(bitmap, scaleFactor, quality); + CachingPipeline pipeline = getEnvironment().getCachingPipeline(); + boolean needsUpdate = pipeline.prepareRenderscriptAllocations(bitmap); + if (needsUpdate || !isResourcesLoaded()) { + // the allocations changed size + freeResources(); + createFilter(sResources, scaleFactor, quality); + setResourcesLoaded(true); + } runFilter(); update(bitmap); } @@ -108,7 +86,6 @@ public abstract class ImageFilterRS extends ImageFilter { displayLowMemoryToast(); Log.e(LOGTAG, "not enough memory for filter " + getName(), e); } - mSourceBitmap = null; return bitmap; } @@ -123,24 +100,9 @@ public abstract class ImageFilterRS extends ImageFilter { } sRS = RenderScript.create(context); sResources = context.getResources(); - destroyPixelAllocations(); - } - - private static synchronized void destroyPixelAllocations() { - if (mInPixelsAllocation != null) { - mInPixelsAllocation.destroy(); - mInPixelsAllocation = null; - } - if (mOutPixelsAllocation != null) { - mOutPixelsAllocation.destroy(); - mOutPixelsAllocation = null; - } - sWidth = 0; - sHeight = 0; } public static synchronized void destroyRenderScriptContext() { - destroyPixelAllocations(); sRS.destroy(); sRS = null; sResources = null; diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilterSharpen.java b/src/com/android/gallery3d/filtershow/filters/ImageFilterSharpen.java index af31735a6..f545cd986 100644 --- a/src/com/android/gallery3d/filtershow/filters/ImageFilterSharpen.java +++ b/src/com/android/gallery3d/filtershow/filters/ImageFilterSharpen.java @@ -63,8 +63,8 @@ public class ImageFilterSharpen extends ImageFilterRS { @Override protected void createFilter(android.content.res.Resources res, float scaleFactor, int quality) { - int w = mInPixelsAllocation.getType().getX(); - int h = mInPixelsAllocation.getType().getY(); + int w = getInPixelsAllocation().getType().getX(); + int h = getInPixelsAllocation().getType().getY(); mScaleFactor = scaleFactor; if (mScript == null) { @@ -97,9 +97,9 @@ public class ImageFilterSharpen extends ImageFilterRS { return; } computeKernel(); - mScript.set_gIn(mInPixelsAllocation); - mScript.bind_gPixels(mInPixelsAllocation); - mScript.forEach_root(mInPixelsAllocation, mOutPixelsAllocation); + mScript.set_gIn(getInPixelsAllocation()); + mScript.bind_gPixels(getInPixelsAllocation()); + mScript.forEach_root(getInPixelsAllocation(), getOutPixelsAllocation()); } } diff --git a/src/com/android/gallery3d/filtershow/imageshow/ImageShow.java b/src/com/android/gallery3d/filtershow/imageshow/ImageShow.java index 2de37f6fe..38dc17719 100644 --- a/src/com/android/gallery3d/filtershow/imageshow/ImageShow.java +++ b/src/com/android/gallery3d/filtershow/imageshow/ImageShow.java @@ -28,7 +28,6 @@ import android.graphics.RectF; import android.net.Uri; import android.os.Handler; import android.util.AttributeSet; -import android.util.Log; import android.view.GestureDetector; import android.view.GestureDetector.OnDoubleTapListener; import android.view.GestureDetector.OnGestureListener; @@ -51,7 +50,7 @@ public class ImageShow extends View implements OnGestureListener, private static final String LOGTAG = "ImageShow"; private static final boolean ENABLE_HISTORY_SWAP = false; - private static final boolean ENABLE_COMPARISON = false; + private static final boolean ENABLE_ZOOMED_COMPARISON = false; protected Paint mPaint = new Paint(); protected static int mTextSize = 24; @@ -579,7 +578,7 @@ public class ImageShow extends View implements OnGestureListener, mTouch.y = ey; float scaleFactor = MasterImage.getImage().getScaleFactor(); - if (scaleFactor > 1 && (!ENABLE_COMPARISON || event.getPointerCount() == 2)) { + if (scaleFactor > 1 && (!ENABLE_ZOOMED_COMPARISON || event.getPointerCount() == 2)) { float translateX = (mTouch.x - mTouchDown.x) / scaleFactor; float translateY = (mTouch.y - mTouchDown.y) / scaleFactor; Point originalTranslation = MasterImage.getImage().getOriginalTranslation(); @@ -588,7 +587,7 @@ public class ImageShow extends View implements OnGestureListener, translation.y = (int) (originalTranslation.y + translateY); MasterImage.getImage().setTranslation(translation); mTouchShowOriginal = false; - } else if (!mOriginalDisabled && !mActivity.isShowingHistoryPanel() + } else if (enableComparison() && !mOriginalDisabled && !mActivity.isShowingHistoryPanel() && (System.currentTimeMillis() - mTouchShowOriginalDate > mTouchShowOriginalDelayMin) && event.getPointerCount() == 1) { @@ -611,6 +610,10 @@ public class ImageShow extends View implements OnGestureListener, return true; } + protected boolean enableComparison() { + return true; + } + // listview stuff public void showOriginal(boolean show) { invalidate(); diff --git a/src/com/android/gallery3d/filtershow/presets/FilterEnvironment.java b/src/com/android/gallery3d/filtershow/presets/FilterEnvironment.java index c20502290..c45036012 100644 --- a/src/com/android/gallery3d/filtershow/presets/FilterEnvironment.java +++ b/src/com/android/gallery3d/filtershow/presets/FilterEnvironment.java @@ -17,6 +17,7 @@ package com.android.gallery3d.filtershow.presets; import android.graphics.Bitmap; +import com.android.gallery3d.filtershow.cache.CachingPipeline; import com.android.gallery3d.filtershow.filters.FilterRepresentation; import com.android.gallery3d.filtershow.filters.FiltersManager; import com.android.gallery3d.filtershow.filters.ImageFilter; @@ -26,6 +27,7 @@ public class FilterEnvironment { private float mScaleFactor; private int mQuality; private FiltersManager mFiltersManager; + private CachingPipeline mCachingPipeline; public void setImagePreset(ImagePreset imagePreset) { mImagePreset = imagePreset; @@ -62,7 +64,17 @@ public class FilterEnvironment { public Bitmap applyRepresentation(FilterRepresentation representation, Bitmap bitmap) { ImageFilter filter = mFiltersManager.getFilterForRepresentation(representation); filter.useRepresentation(representation); - filter.setImagePreset(mImagePreset); - return filter.apply(bitmap, mScaleFactor, mQuality); + filter.setEnvironment(this); + Bitmap ret = filter.apply(bitmap, mScaleFactor, mQuality); + filter.setEnvironment(null); + return ret; + } + + public CachingPipeline getCachingPipeline() { + return mCachingPipeline; + } + + public void setCachingPipeline(CachingPipeline cachingPipeline) { + mCachingPipeline = cachingPipeline; } } diff --git a/src/com/android/gallery3d/filtershow/ui/FilterIconButton.java b/src/com/android/gallery3d/filtershow/ui/FilterIconButton.java index f61852c16..3a6fcd25d 100644 --- a/src/com/android/gallery3d/filtershow/ui/FilterIconButton.java +++ b/src/com/android/gallery3d/filtershow/ui/FilterIconButton.java @@ -60,6 +60,7 @@ public class FilterIconButton extends IconButton implements View.OnClickListener public void setup(String text, PanelController controller, LinearLayout parent) { mController = controller; setText(text); + setContentDescription(text); mParentContainer = parent; super.setOnClickListener(this); MasterImage.getImage().addGeometryListener(this); diff --git a/src/com/android/gallery3d/filtershow/ui/ImageCurves.java b/src/com/android/gallery3d/filtershow/ui/ImageCurves.java index 04eed946b..e5ffd8b68 100644 --- a/src/com/android/gallery3d/filtershow/ui/ImageCurves.java +++ b/src/com/android/gallery3d/filtershow/ui/ImageCurves.java @@ -79,6 +79,11 @@ public class ImageCurves extends ImageShow { } @Override + protected boolean enableComparison() { + return false; + } + + @Override public boolean useUtilityPanel() { return true; } |