diff options
Diffstat (limited to 'src/com/android/gallery3d/filtershow/filters')
25 files changed, 718 insertions, 154 deletions
diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilter.java b/src/com/android/gallery3d/filtershow/filters/ImageFilter.java index d00c7e31b..b8f0cf84f 100644 --- a/src/com/android/gallery3d/filtershow/filters/ImageFilter.java +++ b/src/com/android/gallery3d/filtershow/filters/ImageFilter.java @@ -18,35 +18,64 @@ package com.android.gallery3d.filtershow.filters; import android.graphics.Bitmap; +import com.android.gallery3d.R; import com.android.gallery3d.filtershow.presets.ImagePreset; public class ImageFilter implements Cloneable { - protected int mMaxParameter = 100; - protected int mMinParameter = -100; + public static int DEFAULT_MAX_PARAMETER = 100; + public static int DEFAULT_MIN_PARAMETER = -100; + public static int DEFAULT_INITIAL_PARAMETER = 0; + + protected int mMaxParameter = DEFAULT_MAX_PARAMETER; + protected int mMinParameter = DEFAULT_MIN_PARAMETER; protected int mPreviewParameter = mMaxParameter; - protected int mDefaultParameter = 0; - protected int mParameter = 0; + protected int mDefaultParameter = DEFAULT_INITIAL_PARAMETER; + protected int mParameter = DEFAULT_INITIAL_PARAMETER; private ImagePreset mImagePreset; protected String mName = "Original"; private final String LOGTAG = "ImageFilter"; - public static final byte TYPE_BORDER =1; - public static final byte TYPE_FX = 2; + public static final byte TYPE_BORDER = 1; + public static final byte TYPE_FX = 2; public static final byte TYPE_WBALANCE = 3; public static final byte TYPE_VIGNETTE = 4; public static final byte TYPE_NORMAL = 5; public static final byte TYPE_TINYPLANET = 6; private byte filterType = TYPE_NORMAL; - public byte getFilterType(){ + public byte getFilterType() { return filterType; } - protected void setFilterType(byte type){ + protected void setFilterType(byte type) { filterType = type; } + public int getButtonId() { + return 0; + } + + public int getTextId() { + return 0; + } + + public int getOverlayBitmaps() { + return 0; + } + + public int getEditingViewId() { + return R.id.imageShow; + } + + public boolean showEditingControls() { + return true; + } + + public boolean showParameterValue() { + return true; + } + @Override public ImageFilter clone() throws CloneNotSupportedException { ImageFilter filter = (ImageFilter) super.clone(); @@ -61,6 +90,10 @@ public class ImageFilter implements Cloneable { return filter; } + public void reset() { + setParameter(mDefaultParameter); + } + public boolean isNil() { if (mParameter == mDefaultParameter) { return true; @@ -93,7 +126,7 @@ public class ImageFilter implements Cloneable { * The maximum allowed value (inclusive) * @return maximum value allowed as input to this filter */ - public int getMaxParameter(){ + public int getMaxParameter() { return mMaxParameter; } @@ -101,7 +134,7 @@ public class ImageFilter implements Cloneable { * The parameter value to be used in previews. * @return parameter value to be used to preview the filter */ - public int getPreviewParameter(){ + public int getPreviewParameter() { return mPreviewParameter; } @@ -109,7 +142,7 @@ public class ImageFilter implements Cloneable { * The minimum allowed value (inclusive) * @return minimum value allowed as input to this filter */ - public int getMinParameter(){ + public int getMinParameter() { return mMinParameter; } @@ -117,7 +150,7 @@ public class ImageFilter implements Cloneable { * Returns the default value returned by this filter. * @return default value */ - public int getDefaultParameter(){ + public int getDefaultParameter() { return mDefaultParameter; } @@ -130,6 +163,9 @@ public class ImageFilter implements Cloneable { } public boolean same(ImageFilter filter) { + if (filter == null) { + return false; + } if (!filter.getName().equalsIgnoreCase(getName())) { return false; } diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilterBWBlue.java b/src/com/android/gallery3d/filtershow/filters/ImageFilterBWBlue.java deleted file mode 100644 index 45f49164b..000000000 --- a/src/com/android/gallery3d/filtershow/filters/ImageFilterBWBlue.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (C) 2012 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.filtershow.filters; - -import android.graphics.Bitmap; - -public class ImageFilterBWBlue extends ImageFilter { - - public ImageFilterBWBlue() { - mName = "B&W - Blue"; - } - - native protected void nativeApplyFilter(Bitmap bitmap, int w, int h); - - @Override - public Bitmap apply(Bitmap bitmap, float scaleFactor, boolean highQuality) { - int w = bitmap.getWidth(); - int h = bitmap.getHeight(); - nativeApplyFilter(bitmap, w, h); - return bitmap; - } - -} diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilterBWGreen.java b/src/com/android/gallery3d/filtershow/filters/ImageFilterBWGreen.java deleted file mode 100644 index 8f91c3c82..000000000 --- a/src/com/android/gallery3d/filtershow/filters/ImageFilterBWGreen.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (C) 2012 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.filtershow.filters; - -import android.graphics.Bitmap; - -public class ImageFilterBWGreen extends ImageFilter { - - public ImageFilterBWGreen() { - mName = "B&W - Green"; - } - - native protected void nativeApplyFilter(Bitmap bitmap, int w, int h); - - @Override - public Bitmap apply(Bitmap bitmap, float scaleFactor, boolean highQuality) { - int w = bitmap.getWidth(); - int h = bitmap.getHeight(); - nativeApplyFilter(bitmap, w, h); - return bitmap; - } - -} diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilterBWRed.java b/src/com/android/gallery3d/filtershow/filters/ImageFilterBWRed.java deleted file mode 100644 index f0c65d71e..000000000 --- a/src/com/android/gallery3d/filtershow/filters/ImageFilterBWRed.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (C) 2012 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.filtershow.filters; - -import android.graphics.Bitmap; - -public class ImageFilterBWRed extends ImageFilter { - - public ImageFilterBWRed() { - mName = "B&W - Red"; - } - - native protected void nativeApplyFilter(Bitmap bitmap, int w, int h); - - @Override - public Bitmap apply(Bitmap bitmap, float scaleFactor, boolean highQuality) { - int w = bitmap.getWidth(); - int h = bitmap.getHeight(); - nativeApplyFilter(bitmap, w, h); - return bitmap; - } - -} diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilterBorder.java b/src/com/android/gallery3d/filtershow/filters/ImageFilterBorder.java index a310358ce..1d198e45c 100644 --- a/src/com/android/gallery3d/filtershow/filters/ImageFilterBorder.java +++ b/src/com/android/gallery3d/filtershow/filters/ImageFilterBorder.java @@ -51,6 +51,9 @@ public class ImageFilterBorder extends ImageFilter { if (!isBorderFilter) { return false; } + if (!(filter instanceof ImageFilterBorder)) { + return false; + } ImageFilterBorder borderFilter = (ImageFilterBorder) filter; if (mNinePatch != borderFilter.mNinePatch) { return false; diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilterBwFilter.java b/src/com/android/gallery3d/filtershow/filters/ImageFilterBwFilter.java index 558abe3c3..1bb5c76ac 100644 --- a/src/com/android/gallery3d/filtershow/filters/ImageFilterBwFilter.java +++ b/src/com/android/gallery3d/filtershow/filters/ImageFilterBwFilter.java @@ -16,6 +16,8 @@ package com.android.gallery3d.filtershow.filters; +import com.android.gallery3d.R; + import android.graphics.Bitmap; import android.graphics.Color; @@ -29,6 +31,16 @@ public class ImageFilterBwFilter extends ImageFilter { } @Override + public int getButtonId() { + return R.id.bwfilterButton; + } + + @Override + public int getTextId() { + return R.string.bwfilter; + } + + @Override public ImageFilter clone() throws CloneNotSupportedException { ImageFilterBwFilter filter = (ImageFilterBwFilter) super.clone(); return filter; diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilterContrast.java b/src/com/android/gallery3d/filtershow/filters/ImageFilterContrast.java index 0c3bb37ca..70e3d8589 100644 --- a/src/com/android/gallery3d/filtershow/filters/ImageFilterContrast.java +++ b/src/com/android/gallery3d/filtershow/filters/ImageFilterContrast.java @@ -16,6 +16,8 @@ package com.android.gallery3d.filtershow.filters; +import com.android.gallery3d.R; + import android.graphics.Bitmap; public class ImageFilterContrast extends ImageFilter { @@ -24,6 +26,16 @@ public class ImageFilterContrast extends ImageFilter { mName = "Contrast"; } + @Override + public int getButtonId() { + return R.id.contrastButton; + } + + @Override + public int getTextId() { + return R.string.contrast; + } + native protected void nativeApplyFilter(Bitmap bitmap, int w, int h, float strength); @Override diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilterCurves.java b/src/com/android/gallery3d/filtershow/filters/ImageFilterCurves.java index 89641d103..ba49a8fcb 100644 --- a/src/com/android/gallery3d/filtershow/filters/ImageFilterCurves.java +++ b/src/com/android/gallery3d/filtershow/filters/ImageFilterCurves.java @@ -18,6 +18,7 @@ package com.android.gallery3d.filtershow.filters; import android.graphics.Bitmap; +import com.android.gallery3d.R; import com.android.gallery3d.filtershow.ui.Spline; public class ImageFilterCurves extends ImageFilter { @@ -31,6 +32,31 @@ public class ImageFilterCurves extends ImageFilter { } @Override + public int getButtonId() { + return R.id.curvesButtonRGB; + } + + @Override + public int getTextId() { + return R.string.curvesRGB; + } + + @Override + public int getOverlayBitmaps() { + return R.drawable.filtershow_button_colors_curve; + } + + @Override + public int getEditingViewId() { + return R.id.imageCurves; + } + + @Override + public boolean showParameterValue() { + return false; + } + + @Override public ImageFilter clone() throws CloneNotSupportedException { ImageFilterCurves filter = (ImageFilterCurves) super.clone(); for (int i = 0; i < 4; i++) { diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilterDownsample.java b/src/com/android/gallery3d/filtershow/filters/ImageFilterDownsample.java new file mode 100644 index 000000000..fa2293ca7 --- /dev/null +++ b/src/com/android/gallery3d/filtershow/filters/ImageFilterDownsample.java @@ -0,0 +1,68 @@ +/* + * Copyright (C) 2012 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.filtershow.filters; + +import android.graphics.Bitmap; + +import com.android.gallery3d.R; + +public class ImageFilterDownsample extends ImageFilter { + + public ImageFilterDownsample() { + mName = "Downsample"; + mMaxParameter = 100; + mMinParameter = 5; + mPreviewParameter = 10; + mDefaultParameter = 50; + mParameter = 50; + } + + @Override + public int getButtonId() { + return R.id.downsampleButton; + } + + @Override + public int getTextId() { + return R.string.downsample; + } + + @Override + public boolean isNil() { + return false; + } + + @Override + public Bitmap apply(Bitmap bitmap, float scaleFactor, boolean highQuality) { + int w = bitmap.getWidth(); + int h = bitmap.getHeight(); + int p = mParameter; + if (p > 0 && p < 100) { + int newWidth = w * p / 100; + int newHeight = h * p / 100; + if (newWidth <= 0 || newHeight <= 0) { + return bitmap; + } + Bitmap ret = Bitmap.createScaledBitmap(bitmap, newWidth, newHeight, true); + if (ret != bitmap) { + bitmap.recycle(); + } + return ret; + } + return bitmap; + } +} diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilterBW.java b/src/com/android/gallery3d/filtershow/filters/ImageFilterEdge.java index f4a7717f9..9eda64874 100644 --- a/src/com/android/gallery3d/filtershow/filters/ImageFilterBW.java +++ b/src/com/android/gallery3d/filtershow/filters/ImageFilterEdge.java @@ -18,20 +18,39 @@ package com.android.gallery3d.filtershow.filters; import android.graphics.Bitmap; -public class ImageFilterBW extends ImageFilter { +import com.android.gallery3d.R; - public ImageFilterBW() { - mName = "Black & White"; +public class ImageFilterEdge extends ImageFilter { + + public ImageFilterEdge() { + mName = "Edge"; + mPreviewParameter = 0; } - native protected void nativeApplyFilter(Bitmap bitmap, int w, int h); + native protected void nativeApplyFilter(Bitmap bitmap, int w, int h, float p); + + @Override + public int getButtonId() { + return R.id.edgeButton; + } + + @Override + public int getTextId() { + return R.string.edge; + } + + @Override + public boolean isNil() { + return false; + } @Override public Bitmap apply(Bitmap bitmap, float scaleFactor, boolean highQuality) { int w = bitmap.getWidth(); int h = bitmap.getHeight(); - nativeApplyFilter(bitmap, w, h); + float p = mParameter + 101; + p = (float) p / 100; + nativeApplyFilter(bitmap, w, h, p); return bitmap; } - } diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilterExposure.java b/src/com/android/gallery3d/filtershow/filters/ImageFilterExposure.java index e38dc8eb5..63f860171 100644 --- a/src/com/android/gallery3d/filtershow/filters/ImageFilterExposure.java +++ b/src/com/android/gallery3d/filtershow/filters/ImageFilterExposure.java @@ -16,6 +16,8 @@ package com.android.gallery3d.filtershow.filters; +import com.android.gallery3d.R; + import android.graphics.Bitmap; public class ImageFilterExposure extends ImageFilter { @@ -24,6 +26,16 @@ public class ImageFilterExposure extends ImageFilter { mName = "Exposure"; } + @Override + public int getButtonId() { + return R.id.exposureButton; + } + + @Override + public int getTextId() { + return R.string.exposure; + } + native protected void nativeApplyFilter(Bitmap bitmap, int w, int h, float bright); @Override diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilterGeometry.java b/src/com/android/gallery3d/filtershow/filters/ImageFilterGeometry.java index bdcb0ea4e..33ecc8ab9 100644 --- a/src/com/android/gallery3d/filtershow/filters/ImageFilterGeometry.java +++ b/src/com/android/gallery3d/filtershow/filters/ImageFilterGeometry.java @@ -23,6 +23,7 @@ import android.graphics.Paint; import android.graphics.Rect; import android.graphics.RectF; +import com.android.gallery3d.filtershow.CropExtras; import com.android.gallery3d.filtershow.imageshow.GeometryMath; import com.android.gallery3d.filtershow.imageshow.GeometryMetadata; @@ -69,22 +70,56 @@ public class ImageFilterGeometry extends ImageFilter { // TODO: implement bilinear or bicubic here... for now, just use // canvas to do a simple implementation... // TODO: and be more memory efficient! (do it in native?) + + CropExtras extras = mGeometry.getCropExtras(); + boolean useExtras = mGeometry.getUseCropExtrasFlag(); + int outputX = 0; + int outputY = 0; + boolean s = false; + if (extras != null && useExtras){ + outputX = extras.getOutputX(); + outputY = extras.getOutputY(); + s = extras.getScaleUp(); + } + + Rect cropBounds = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()); RectF crop = mGeometry.getCropBounds(bitmap); if (crop.width() > 0 && crop.height() > 0) - crop.roundOut(cropBounds); - Bitmap temp = null; - if (mGeometry.hasSwitchedWidthHeight()) { - temp = Bitmap.createBitmap(cropBounds.height(), cropBounds.width(), mConfig); - } else { - temp = Bitmap.createBitmap(cropBounds.width(), cropBounds.height(), mConfig); + cropBounds = GeometryMath.roundNearest(crop); + + int width = cropBounds.width(); + int height = cropBounds.height(); + + if (mGeometry.hasSwitchedWidthHeight()){ + int temp = width; + width = height; + height = temp; } + + if(outputX <= 0 || outputY <= 0){ + outputX = width; + outputY = height; + } + + float scaleX = 1; + float scaleY = 1; + if (s){ + scaleX = (float) outputX / width; + scaleY = (float) outputY / height; + } + + Bitmap temp = null; + temp = Bitmap.createBitmap(outputX, outputY, mConfig); + float[] displayCenter = { temp.getWidth() / 2f, temp.getHeight() / 2f }; Matrix m1 = mGeometry.buildTotalXform(bitmap.getWidth(), bitmap.getHeight(), displayCenter); + m1.postScale(scaleX, scaleY, displayCenter[0], displayCenter[1]); + Canvas canvas = new Canvas(temp); Paint paint = new Paint(); paint.setAntiAlias(true); diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilterHue.java b/src/com/android/gallery3d/filtershow/filters/ImageFilterHue.java index 279718edb..e2ea388dc 100644 --- a/src/com/android/gallery3d/filtershow/filters/ImageFilterHue.java +++ b/src/com/android/gallery3d/filtershow/filters/ImageFilterHue.java @@ -16,6 +16,8 @@ package com.android.gallery3d.filtershow.filters; +import com.android.gallery3d.R; + import android.graphics.Bitmap; public class ImageFilterHue extends ImageFilter { @@ -29,6 +31,16 @@ public class ImageFilterHue extends ImageFilter { } @Override + public int getButtonId() { + return R.id.hueButton; + } + + @Override + public int getTextId() { + return R.string.hue; + } + + @Override public ImageFilter clone() throws CloneNotSupportedException { ImageFilterHue filter = (ImageFilterHue) super.clone(); filter.cmatrix = new ColorSpaceMatrix(cmatrix); diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilterKMeans.java b/src/com/android/gallery3d/filtershow/filters/ImageFilterKMeans.java new file mode 100644 index 000000000..f03baca39 --- /dev/null +++ b/src/com/android/gallery3d/filtershow/filters/ImageFilterKMeans.java @@ -0,0 +1,94 @@ +/* + * Copyright (C) 2012 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.filtershow.filters; + +import android.graphics.Bitmap; +import android.text.format.Time; + +import com.android.gallery3d.R; + +public class ImageFilterKMeans extends ImageFilter { + private int mSeed = 0; + + public ImageFilterKMeans() { + mName = "KMeans"; + mMaxParameter = 20; + mMinParameter = 2; + mPreviewParameter = 4; + mDefaultParameter = 4; + mParameter = 4; + + // set random seed for session + Time t = new Time(); + t.setToNow(); + mSeed = (int) t.toMillis(false); + } + + native protected void nativeApplyFilter(Bitmap bitmap, int width, int height, + Bitmap large_ds_bm, int lwidth, int lheight, Bitmap small_ds_bm, + int swidth, int sheight, int p, int seed); + + @Override + public int getButtonId() { + return R.id.kmeansButton; + } + + @Override + public int getTextId() { + return R.string.kmeans; + } + + @Override + public boolean isNil() { + return false; + } + + @Override + public Bitmap apply(Bitmap bitmap, float scaleFactor, boolean highQuality) { + int w = bitmap.getWidth(); + int h = bitmap.getHeight(); + + Bitmap large_bm_ds = bitmap; + Bitmap small_bm_ds = bitmap; + + // find width/height for larger downsampled bitmap + int lw = w; + int lh = h; + while (lw > 256 && lh > 256) { + lw /= 2; + lh /= 2; + } + if (lw != w) { + large_bm_ds = Bitmap.createScaledBitmap(bitmap, lw, lh, true); + } + + // find width/height for smaller downsampled bitmap + int sw = lw; + int sh = lh; + while (sw > 64 && sh > 64) { + sw /= 2; + sh /= 2; + } + if (sw != lw) { + small_bm_ds = Bitmap.createScaledBitmap(large_bm_ds, sw, sh, true); + } + + int p = Math.max(mParameter, mMinParameter) % (mMaxParameter + 1); + nativeApplyFilter(bitmap, w, h, large_bm_ds, lw, lh, small_bm_ds, sw, sh, p, mSeed); + return bitmap; + } +} diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilterNegative.java b/src/com/android/gallery3d/filtershow/filters/ImageFilterNegative.java new file mode 100644 index 000000000..04fd1e42e --- /dev/null +++ b/src/com/android/gallery3d/filtershow/filters/ImageFilterNegative.java @@ -0,0 +1,47 @@ +package com.android.gallery3d.filtershow.filters; + +import android.graphics.Bitmap; + +import com.android.gallery3d.R; + +public class ImageFilterNegative extends ImageFilter { + + public ImageFilterNegative() { + mName = "Negative"; + } + + @Override + public int getButtonId() { + return R.id.negativeButton; + } + + @Override + public int getTextId() { + return R.string.negative; + } + + @Override + public boolean isNil() { + return false; + } + + @Override + public boolean showEditingControls() { + return false; + } + + @Override + public boolean showParameterValue() { + return false; + } + + native protected void nativeApplyFilter(Bitmap bitmap, int w, int h); + + @Override + public Bitmap apply(Bitmap bitmap, float scaleFactor, boolean highQuality) { + int w = bitmap.getWidth(); + int h = bitmap.getHeight(); + nativeApplyFilter(bitmap, w, h); + return bitmap; + } +} diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilterParametricBorder.java b/src/com/android/gallery3d/filtershow/filters/ImageFilterParametricBorder.java index 3d6954691..ade3cb26b 100644 --- a/src/com/android/gallery3d/filtershow/filters/ImageFilterParametricBorder.java +++ b/src/com/android/gallery3d/filtershow/filters/ImageFilterParametricBorder.java @@ -56,6 +56,9 @@ public class ImageFilterParametricBorder extends ImageFilter { if (!isBorderFilter) { return false; } + if (!(filter instanceof ImageFilterParametricBorder)) { + return false; + } ImageFilterParametricBorder borderFilter = (ImageFilterParametricBorder) filter; if (borderFilter.mBorderColor != mBorderColor) { return false; diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilterRedEye.java b/src/com/android/gallery3d/filtershow/filters/ImageFilterRedEye.java index c77de330f..9ae6f511e 100644 --- a/src/com/android/gallery3d/filtershow/filters/ImageFilterRedEye.java +++ b/src/com/android/gallery3d/filtershow/filters/ImageFilterRedEye.java @@ -17,40 +17,167 @@ package com.android.gallery3d.filtershow.filters; import android.graphics.Bitmap; +import android.graphics.Matrix; +import android.graphics.RectF; -public class ImageFilterRedEye extends ImageFilter { - private static final String TAG = "ImageFilterRedEye"; +import com.android.gallery3d.R; +import com.android.gallery3d.filtershow.imageshow.GeometryMetadata; + +import java.util.Vector; +public class ImageFilterRedEye extends ImageFilter { + private static final String LOGTAG = "ImageFilterRedEye"; + private Vector<RedEyeCandidate> mCandidates = null; public ImageFilterRedEye() { - mName = "Redeye"; + mName = "Red Eye"; + } + @Override + public int getButtonId() { + return R.id.redEyeButton; + } + + @Override + public int getTextId() { + return R.string.redeye; + } + + @Override + public int getEditingViewId() { + return R.id.imageRedEyes; } @Override public ImageFilter clone() throws CloneNotSupportedException { ImageFilterRedEye filter = (ImageFilterRedEye) super.clone(); - + if (mCandidates != null) { + int size = mCandidates.size(); + filter.mCandidates = new Vector<RedEyeCandidate>(); + for (int i = 0; i < size; i++) { + filter.mCandidates.add(new RedEyeCandidate(mCandidates.elementAt(i))); + } + } return filter; } - native protected void nativeApplyFilter(Bitmap bitmap, int w, int h, short []matrix); + @Override + public boolean isNil() { + if (mCandidates != null && mCandidates.size() > 0) { + return false; + } + return true; + } + + @Override + public boolean same(ImageFilter filter) { + boolean isRedEyeFilter = super.same(filter); + if (!isRedEyeFilter) { + return false; + } + ImageFilterRedEye redEyeFilter = (ImageFilterRedEye) filter; + if (redEyeFilter.mCandidates == null && mCandidates == null) { + return true; + } + if (redEyeFilter.mCandidates == null || mCandidates == null) { + return false; + } + if (redEyeFilter.mCandidates.size() != mCandidates.size()) { + return false; + } + int size = mCandidates.size(); + for (int i = 0; i < size; i++) { + RedEyeCandidate c1 = mCandidates.elementAt(i); + RedEyeCandidate c2 = redEyeFilter.mCandidates.elementAt(i); + if (!c1.equals(c2)) { + return false; + } + } + return true; + } + + public Vector<RedEyeCandidate> getCandidates() { + if (mCandidates == null) { + mCandidates = new Vector<RedEyeCandidate>(); + } + return mCandidates; + } + + public void addRect(RectF rect, RectF bounds) { + if (mCandidates == null) { + mCandidates = new Vector<RedEyeCandidate>(); + } + Vector<RedEyeCandidate> intersects = new Vector<RedEyeCandidate>(); + for (int i = 0; i < mCandidates.size(); i++) { + RedEyeCandidate r = mCandidates.elementAt(i); + if (r.intersect(rect)) { + intersects.add(r); + } + } + for (int i = 0; i < intersects.size(); i++) { + RedEyeCandidate r = intersects.elementAt(i); + rect.union(r.mRect); + bounds.union(r.mBounds); + mCandidates.remove(r); + } + mCandidates.add(new RedEyeCandidate(rect, bounds)); + } + + public void clear() { + if (mCandidates == null) { + mCandidates = new Vector<RedEyeCandidate>(); + } + mCandidates.clear(); + } + + native protected void nativeApplyFilter(Bitmap bitmap, int w, int h, short[] matrix); @Override public Bitmap apply(Bitmap bitmap, float scaleFactor, boolean highQuality) { int w = bitmap.getWidth(); int h = bitmap.getHeight(); - float p = mParameter; - float value = p; - int box = Math.min(w, h); - int sizex = Math.min((int)((p+100)*box/400),w/2); - int sizey = Math.min((int)((p+100)*box/800),h/2); - - short [] rect = new short[]{ - (short) (w/2-sizex),(short) (w/2-sizey), - (short) (2*sizex),(short) (2*sizey)}; + short[] rect = new short[4]; - nativeApplyFilter(bitmap, w, h, rect); + if (mCandidates != null && mCandidates.size() > 0) { + for (int i = 0; i < mCandidates.size(); i++) { + RectF r = new RectF(mCandidates.elementAt(i).mRect); + GeometryMetadata geo = getImagePreset().mGeoData; + Matrix originalToScreen = geo.getOriginalToScreen(true, + getImagePreset().getImageLoader().getOriginalBounds().width(), + getImagePreset().getImageLoader().getOriginalBounds().height(), + w, h); + originalToScreen.mapRect(r); + if (r.left < 0) { + r.left = 0; + } + if (r.left > w) { + r.left = w; + } + if (r.top < 0) { + r.top = 0; + } + if (r.top > h) { + r.top = h; + } + if (r.right < 0) { + r.right = 0; + } + if (r.right > w) { + r.right = w; + } + if (r.bottom < 0) { + r.bottom = 0; + } + if (r.bottom > h) { + r.bottom = h; + } + rect[0] = (short) r.left; + rect[1] = (short) r.top; + rect[2] = (short) r.width(); + rect[3] = (short) r.height(); + nativeApplyFilter(bitmap, w, h, rect); + } + } return bitmap; } } diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilterSaturated.java b/src/com/android/gallery3d/filtershow/filters/ImageFilterSaturated.java index 1d3459195..129165b3e 100644 --- a/src/com/android/gallery3d/filtershow/filters/ImageFilterSaturated.java +++ b/src/com/android/gallery3d/filtershow/filters/ImageFilterSaturated.java @@ -16,6 +16,8 @@ package com.android.gallery3d.filtershow.filters; +import com.android.gallery3d.R; + import android.graphics.Bitmap; public class ImageFilterSaturated extends ImageFilter { @@ -24,6 +26,16 @@ public class ImageFilterSaturated extends ImageFilter { mName = "Saturated"; } + @Override + public int getButtonId() { + return R.id.saturationButton; + } + + @Override + public int getTextId() { + return R.string.saturation; + } + native protected void nativeApplyFilter(Bitmap bitmap, int w, int h, float saturation); @Override diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilterShadows.java b/src/com/android/gallery3d/filtershow/filters/ImageFilterShadows.java index 4e6b848ae..de8fcd5ea 100644 --- a/src/com/android/gallery3d/filtershow/filters/ImageFilterShadows.java +++ b/src/com/android/gallery3d/filtershow/filters/ImageFilterShadows.java @@ -16,6 +16,8 @@ package com.android.gallery3d.filtershow.filters; +import com.android.gallery3d.R; + import android.graphics.Bitmap; public class ImageFilterShadows extends ImageFilter { @@ -26,6 +28,16 @@ public class ImageFilterShadows extends ImageFilter { } @Override + public int getButtonId() { + return R.id.shadowRecoveryButton; + } + + @Override + public int getTextId() { + return R.string.shadow_recovery; + } + + @Override public ImageFilter clone() throws CloneNotSupportedException { ImageFilterShadows filter = (ImageFilterShadows) super.clone(); return filter; diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilterSharpen.java b/src/com/android/gallery3d/filtershow/filters/ImageFilterSharpen.java index a355539c2..1951b9b9e 100644 --- a/src/com/android/gallery3d/filtershow/filters/ImageFilterSharpen.java +++ b/src/com/android/gallery3d/filtershow/filters/ImageFilterSharpen.java @@ -28,6 +28,26 @@ public class ImageFilterSharpen extends ImageFilterRS { } @Override + public int getButtonId() { + return R.id.sharpenButton; + } + + @Override + public int getTextId() { + return R.string.sharpness; + } + + @Override + public int getOverlayBitmaps() { + return R.drawable.filtershow_button_colors_sharpen; + } + + @Override + public int getEditingViewId() { + return R.id.imageZoom; + } + + @Override public void createFilter(android.content.res.Resources res, float scaleFactor, boolean highQuality) { int w = mInPixelsAllocation.getType().getX(); diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilterTinyPlanet.java b/src/com/android/gallery3d/filtershow/filters/ImageFilterTinyPlanet.java index 423e55828..36bd62630 100644 --- a/src/com/android/gallery3d/filtershow/filters/ImageFilterTinyPlanet.java +++ b/src/com/android/gallery3d/filtershow/filters/ImageFilterTinyPlanet.java @@ -22,6 +22,8 @@ import android.graphics.RectF; import com.adobe.xmp.XMPException; import com.adobe.xmp.XMPMeta; +import com.android.gallery3d.R; +import com.android.gallery3d.app.Log; import com.android.gallery3d.filtershow.presets.ImagePreset; /** @@ -58,6 +60,16 @@ public class ImageFilterTinyPlanet extends ImageFilter { mAngle = 0; } + @Override + public int getButtonId() { + return R.id.tinyplanetButton; + } + + @Override + public int getTextId() { + return R.string.tinyplanet; + } + public void setAngle(float angle) { mAngle = angle; } @@ -90,8 +102,17 @@ public class ImageFilterTinyPlanet extends ImageFilter { } } - Bitmap mBitmapOut = Bitmap.createBitmap( - outputSize, outputSize, Bitmap.Config.ARGB_8888); + Bitmap mBitmapOut = null; + while (mBitmapOut == null) { + try { + mBitmapOut = Bitmap.createBitmap( + outputSize, outputSize, Bitmap.Config.ARGB_8888); + } catch (java.lang.OutOfMemoryError e) { + System.gc(); + outputSize /= 2; + Log.v(TAG, "No memory to create Full Tiny Planet create half"); + } + } nativeApplyFilter(bitmapIn, bitmapIn.getWidth(), bitmapIn.getHeight(), mBitmapOut, outputSize, mParameter / 100f, mAngle); return mBitmapOut; @@ -112,10 +133,19 @@ public class ImageFilterTinyPlanet extends ImageFilter { // Make sure the intermediate image has the similar size to the // input. + Bitmap paddedBitmap = null; float scale = intermediateWidth / (float) fullPanoWidth; - Bitmap paddedBitmap = Bitmap.createBitmap( + while (paddedBitmap == null) { + try { + paddedBitmap = Bitmap.createBitmap( (int) (fullPanoWidth * scale), (int) (fullPanoHeight * scale), Bitmap.Config.ARGB_8888); + } catch (java.lang.OutOfMemoryError e) { + System.gc(); + scale /= 2; + Log.v(TAG, "No memory to create Full Tiny Planet create half"); + } + } Canvas paddedCanvas = new Canvas(paddedBitmap); int right = left + croppedAreaWidth; diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilterVibrance.java b/src/com/android/gallery3d/filtershow/filters/ImageFilterVibrance.java index 34f8b245e..7720d0490 100644 --- a/src/com/android/gallery3d/filtershow/filters/ImageFilterVibrance.java +++ b/src/com/android/gallery3d/filtershow/filters/ImageFilterVibrance.java @@ -16,6 +16,8 @@ package com.android.gallery3d.filtershow.filters; +import com.android.gallery3d.R; + import android.graphics.Bitmap; public class ImageFilterVibrance extends ImageFilter { @@ -24,6 +26,16 @@ public class ImageFilterVibrance extends ImageFilter { mName = "Vibrance"; } + @Override + public int getButtonId() { + return R.id.vibranceButton; + } + + @Override + public int getTextId() { + return R.string.vibrance; + } + native protected void nativeApplyFilter(Bitmap bitmap, int w, int h, float bright); @Override diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilterVignette.java b/src/com/android/gallery3d/filtershow/filters/ImageFilterVignette.java index 7a471e5b9..3c904fa6c 100644 --- a/src/com/android/gallery3d/filtershow/filters/ImageFilterVignette.java +++ b/src/com/android/gallery3d/filtershow/filters/ImageFilterVignette.java @@ -16,6 +16,8 @@ package com.android.gallery3d.filtershow.filters; +import com.android.gallery3d.R; + import android.graphics.Bitmap; public class ImageFilterVignette extends ImageFilter { @@ -25,6 +27,16 @@ public class ImageFilterVignette extends ImageFilter { mName = "Vignette"; } + @Override + public int getButtonId() { + return R.id.vignetteButton; + } + + @Override + public int getTextId() { + return R.string.vignette; + } + native protected void nativeApplyFilter(Bitmap bitmap, int w, int h, float strength); @Override diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilterWBalance.java b/src/com/android/gallery3d/filtershow/filters/ImageFilterWBalance.java index b00b867b3..8665dc54c 100644 --- a/src/com/android/gallery3d/filtershow/filters/ImageFilterWBalance.java +++ b/src/com/android/gallery3d/filtershow/filters/ImageFilterWBalance.java @@ -16,6 +16,8 @@ package com.android.gallery3d.filtershow.filters; +import com.android.gallery3d.R; + import android.graphics.Bitmap; public class ImageFilterWBalance extends ImageFilter { @@ -26,13 +28,32 @@ public class ImageFilterWBalance extends ImageFilter { mName = "WBalance"; } + @Override + public int getButtonId() { + return R.id.wbalanceButton; + } + + @Override + public int getTextId() { + return R.string.wbalance; + } + + public boolean showEditingControls() { + return false; + } + native protected void nativeApplyFilter(Bitmap bitmap, int w, int h, int locX, int locY); @Override public Bitmap apply(Bitmap bitmap, float scaleFactor, boolean highQuality) { int w = bitmap.getWidth(); int h = bitmap.getHeight(); - nativeApplyFilter(bitmap, w, h, -1,-1); + nativeApplyFilter(bitmap, w, h, -1, -1); return bitmap; } + + @Override + public boolean isNil() { + return false; + } } diff --git a/src/com/android/gallery3d/filtershow/filters/RedEyeCandidate.java b/src/com/android/gallery3d/filtershow/filters/RedEyeCandidate.java new file mode 100644 index 000000000..58d3afa3b --- /dev/null +++ b/src/com/android/gallery3d/filtershow/filters/RedEyeCandidate.java @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2012 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.filtershow.filters; + +import android.graphics.RectF; + +public class RedEyeCandidate { + RectF mRect = new RectF(); + RectF mBounds = new RectF(); + + public RedEyeCandidate(RedEyeCandidate candidate) { + mRect.set(candidate.mRect); + mBounds.set(candidate.mBounds); + } + + public RedEyeCandidate(RectF rect, RectF bounds) { + mRect.set(rect); + mBounds.set(bounds); + } + + public boolean equals(RedEyeCandidate candidate) { + if (candidate.mRect.equals(mRect) + && candidate.mBounds.equals(mBounds)) { + return true; + } + return false; + } + + public boolean intersect(RectF rect) { + return mRect.intersect(rect); + } + + public RectF getRect() { + return mRect; + } +} |