summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/com/android/camera/VideoModule.java3
-rw-r--r--src/com/android/gallery3d/filtershow/cache/CachingPipeline.java57
-rw-r--r--src/com/android/gallery3d/filtershow/filters/ImageFilter.java18
-rw-r--r--src/com/android/gallery3d/filtershow/filters/ImageFilterRS.java78
-rw-r--r--src/com/android/gallery3d/filtershow/filters/ImageFilterSharpen.java10
-rw-r--r--src/com/android/gallery3d/filtershow/imageshow/ImageShow.java11
-rw-r--r--src/com/android/gallery3d/filtershow/presets/FilterEnvironment.java16
-rw-r--r--src/com/android/gallery3d/filtershow/ui/FilterIconButton.java1
-rw-r--r--src/com/android/gallery3d/filtershow/ui/ImageCurves.java5
-rwxr-xr-xtests/src/com/android/gallery3d/power/ImageAndVideoCapture.java116
10 files changed, 123 insertions, 192 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;
}
diff --git a/tests/src/com/android/gallery3d/power/ImageAndVideoCapture.java b/tests/src/com/android/gallery3d/power/ImageAndVideoCapture.java
deleted file mode 100755
index cd5079355..000000000
--- a/tests/src/com/android/gallery3d/power/ImageAndVideoCapture.java
+++ /dev/null
@@ -1,116 +0,0 @@
-/*
- * Copyright (C) 2009 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.gallery3d.power;
-
-import com.android.camera.CameraActivity;
-
-import android.app.Instrumentation;
-import android.provider.MediaStore;
-import android.test.ActivityInstrumentationTestCase2;
-import android.test.suitebuilder.annotation.LargeTest;
-import android.util.Log;
-import android.view.KeyEvent;
-import android.content.Intent;
-/**
- * Junit / Instrumentation test case for camera power measurement
- *
- * Running the test suite:
- *
- * adb shell am instrument \
- * -e com.android.camera.power.ImageAndVideoCapture \
- * -w com.android.camera.tests/android.test.InstrumentationTestRunner
- *
- */
-
-public class ImageAndVideoCapture extends ActivityInstrumentationTestCase2 <CameraActivity> {
- private String TAG = "ImageAndVideoCapture";
- private static final int TOTAL_NUMBER_OF_IMAGECAPTURE = 5;
- private static final int TOTAL_NUMBER_OF_VIDEOCAPTURE = 5;
- private static final long WAIT_FOR_IMAGE_CAPTURE_TO_BE_TAKEN = 1500; //1.5 sedconds
- private static final long WAIT_FOR_VIDEO_CAPTURE_TO_BE_TAKEN = 10000; //10 seconds
- private static final long WAIT_FOR_PREVIEW = 1500; //1.5 seconds
- private static final long WAIT_FOR_STABLE_STATE = 2000; //2 seconds
-
- public ImageAndVideoCapture() {
- super(CameraActivity.class);
- }
-
- @Override
- protected void setUp() throws Exception {
- getActivity();
- super.setUp();
- }
-
- @Override
- protected void tearDown() throws Exception {
- super.tearDown();
- }
-
- @LargeTest
- public void testLaunchCamera() {
- // This test case capture the baseline for the image preview.
- try {
- Thread.sleep(WAIT_FOR_STABLE_STATE);
- } catch (Exception e) {
- Log.v(TAG, "Got exception", e);
- assertTrue("testImageCaptureDoNothing", false);
- }
- }
-
- @LargeTest
- public void testCapture5Image() {
- // This test case will use the default camera setting
- Instrumentation inst = getInstrumentation();
- try {
- for (int i = 0; i < TOTAL_NUMBER_OF_IMAGECAPTURE; i++) {
- Thread.sleep(WAIT_FOR_IMAGE_CAPTURE_TO_BE_TAKEN);
- inst.sendKeyDownUpSync(KeyEvent.KEYCODE_DPAD_UP);
- inst.sendKeyDownUpSync(KeyEvent.KEYCODE_DPAD_CENTER);
- Thread.sleep(WAIT_FOR_IMAGE_CAPTURE_TO_BE_TAKEN);
- }
- Thread.sleep(WAIT_FOR_STABLE_STATE);
- } catch (Exception e) {
- Log.v(TAG, "Got exception", e);
- assertTrue("testImageCapture", false);
- }
- }
-
- @LargeTest
- public void testCapture5Videos() {
- // This test case will use the default camera setting
- Instrumentation inst = getInstrumentation();
- try {
- // Switch to the video mode
- Intent intent = new Intent(MediaStore.INTENT_ACTION_VIDEO_CAMERA);
- intent.setClass(getInstrumentation().getTargetContext(),
- CameraActivity.class);
- getActivity().startActivity(intent);
- for (int i = 0; i < TOTAL_NUMBER_OF_VIDEOCAPTURE; i++) {
- Thread.sleep(WAIT_FOR_PREVIEW);
- // record a video
- inst.sendKeyDownUpSync(KeyEvent.KEYCODE_DPAD_CENTER);
- Thread.sleep(WAIT_FOR_VIDEO_CAPTURE_TO_BE_TAKEN);
- inst.sendKeyDownUpSync(KeyEvent.KEYCODE_DPAD_CENTER);
- Thread.sleep(WAIT_FOR_PREVIEW);
- }
- Thread.sleep(WAIT_FOR_STABLE_STATE);
- } catch (Exception e) {
- Log.v(TAG, "Got exception", e);
- assertTrue("testVideoCapture", false);
- }
- }
-}