import android.content.ContentValues;
import android.content.Intent;
import android.content.res.Resources;
+import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Bundle;
import com.android.gallery3d.filtershow.cache.ImageLoader;
import com.android.gallery3d.filtershow.filters.ImageFilter;
import com.android.gallery3d.filtershow.filters.ImageFilterBorder;
+import com.android.gallery3d.filtershow.filters.ImageFilterParametricBorder;
import com.android.gallery3d.filtershow.filters.ImageFilterRS;
import com.android.gallery3d.filtershow.imageshow.ImageBorder;
import com.android.gallery3d.filtershow.imageshow.ImageCrop;
// TODO: use listview
// TODO: load the borders straight from the filesystem
int p = 0;
- ImageFilter[] borders = new ImageFilter[8];
+ ImageFilter[] borders = new ImageFilter[7];
borders[p++] = new ImageFilterBorder(null);
+ borders[p++] = new ImageFilterParametricBorder(Color.WHITE, 100, 0);
+ borders[p++] = new ImageFilterParametricBorder(Color.BLACK, 100, 0);
+ borders[p++] = new ImageFilterParametricBorder(Color.WHITE, 100, 100);
+ borders[p++] = new ImageFilterParametricBorder(Color.BLACK, 100, 100);
Drawable npd3 = getResources().getDrawable(R.drawable.filtershow_border_film3);
borders[p++] = new ImageFilterBorder(npd3);
Drawable npd = getResources().getDrawable(
R.drawable.filtershow_border_scratch3);
borders[p++] = new ImageFilterBorder(npd);
- Drawable npd2 = getResources().getDrawable(R.drawable.filtershow_border_black);
- borders[p++] = new ImageFilterBorder(npd2);
- Drawable npd6 = getResources().getDrawable(
- R.drawable.filtershow_border_rounded_black);
- borders[p++] = new ImageFilterBorder(npd6);
- Drawable npd4 = getResources().getDrawable(R.drawable.filtershow_border_white);
- borders[p++] = new ImageFilterBorder(npd4);
- Drawable npd5 = getResources().getDrawable(
- R.drawable.filtershow_border_rounded_white);
- borders[p++] = new ImageFilterBorder(npd5);
for (int i = 0; i < p; i++) {
ImageSmallFilter filter = new ImageSmallFilter(getBaseContext());
filter.setImageFilter(borders[i]);
filter.setController(this);
+ filter.setBorder(true);
filter.setImageLoader(mImageLoader);
filter.setShowTitle(false);
listBorders.addView(filter);
invalidateViews();
}
- public void useImageFilter(ImageFilter imageFilter) {
+ public void useImageFilter(ImageFilter imageFilter, boolean setBorder) {
if (imageFilter == null) {
return;
}
ImagePreset oldPreset = mImageShow.getImagePreset();
ImagePreset copy = new ImagePreset(oldPreset);
// TODO: use a numerical constant instead.
- if (imageFilter.getName().equalsIgnoreCase("Border")) {
- copy.remove("Border");
+ if (setBorder) {
copy.setHistoryName("Border");
+ copy.setBorder(imageFilter);
+ } else {
+ copy.add(imageFilter);
}
- copy.add(imageFilter);
mImageShow.setImagePreset(copy);
invalidateViews();
}
--- /dev/null
+
+package com.android.gallery3d.filtershow.filters;
+
+import android.graphics.Bitmap;
+import android.graphics.Canvas;
+import android.graphics.Color;
+import android.graphics.Paint;
+import android.graphics.Path;
+import android.graphics.RectF;
+
+public class ImageFilterParametricBorder extends ImageFilter {
+ private int mBorderColor = Color.WHITE;
+ private int mBorderSize = 10;
+ private int mBorderCornerRadius = 10;
+
+ public ImageFilterParametricBorder() {
+ mName = "Border";
+ }
+
+ public ImageFilterParametricBorder(int color, int size, int radius) {
+ setBorder(color, size, radius);
+ }
+
+ @Override
+ public ImageFilter clone() throws CloneNotSupportedException {
+ ImageFilterParametricBorder filter = (ImageFilterParametricBorder) super.clone();
+ filter.setBorder(mBorderColor, mBorderSize, mBorderCornerRadius);
+ return filter;
+ }
+
+ @Override
+ public boolean same(ImageFilter filter) {
+ boolean isBorderFilter = super.same(filter);
+ if (!isBorderFilter) {
+ return false;
+ }
+ ImageFilterParametricBorder borderFilter = (ImageFilterParametricBorder) filter;
+ if (borderFilter.mBorderColor != mBorderColor) {
+ return false;
+ }
+ if (borderFilter.mBorderSize != mBorderSize) {
+ return false;
+ }
+ if (borderFilter.mBorderCornerRadius != mBorderCornerRadius) {
+ return false;
+ }
+ return true;
+ }
+
+ public void setBorder(int color, int size, int radius) {
+ mBorderColor = color;
+ mBorderSize = size;
+ mBorderCornerRadius = radius;
+ }
+
+ @Override
+ public Bitmap apply(Bitmap bitmap, float scaleFactor, boolean highQuality) {
+ Canvas canvas = new Canvas(bitmap);
+ Path border = new Path();
+ border.moveTo(0, 0);
+ int w = bitmap.getWidth();
+ int h = bitmap.getHeight();
+ float bs = mBorderSize * scaleFactor;
+ float r = mBorderCornerRadius * scaleFactor;
+ border.lineTo(0, h);
+ border.lineTo(w, h);
+ border.lineTo(w, 0);
+ border.lineTo(0, 0);
+ border.addRoundRect(new RectF(bs, bs, w - bs, h - bs),
+ r, r, Path.Direction.CW);
+
+ Paint paint = new Paint();
+ paint.setAntiAlias(true);
+ paint.setColor(mBorderColor);
+ canvas.drawPath(border, paint);
+ return bitmap;
+ }
+
+}
package com.android.gallery3d.filtershow.imageshow;
-import com.android.gallery3d.filtershow.FilterShowActivity;
-import com.android.gallery3d.filtershow.filters.ImageFilter;
-import com.android.gallery3d.filtershow.presets.ImagePreset;
-
import android.content.Context;
import android.graphics.Bitmap;
-import android.graphics.Canvas;
-import android.graphics.Paint;
import android.util.AttributeSet;
-import android.util.Log;
import android.view.View;
-import android.view.View.MeasureSpec;
+
+import com.android.gallery3d.filtershow.FilterShowActivity;
+import com.android.gallery3d.filtershow.filters.ImageFilter;
+import com.android.gallery3d.filtershow.presets.ImagePreset;
public class ImageSmallFilter extends ImageShow implements View.OnClickListener {
private FilterShowActivity mController = null;
private ImageFilter mImageFilter = null;
private boolean mShowTitle = true;
+ private boolean mSetBorder = false;
public ImageSmallFilter(Context context, AttributeSet attrs) {
super(context, attrs);
mImagePreset.add(mImageFilter);
}
+ public void setBorder(boolean value) {
+ mSetBorder = value;
+ }
+
public void setController(FilterShowActivity activity) {
mController = activity;
}
+ @Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int parentWidth = MeasureSpec.getSize(widthMeasureSpec);
int parentHeight = MeasureSpec.getSize(heightMeasureSpec);
setMeasuredDimension(parentHeight, parentHeight);
}
+ @Override
public void onClick(View v) {
if (mController != null) {
if (mImageFilter != null) {
- mController.useImageFilter(mImageFilter);
+ mController.useImageFilter(mImageFilter, mSetBorder);
} else if (mImagePreset != null) {
mController.useImagePreset(mImagePreset);
}
}
}
+ @Override
public Bitmap getOriginalFrontBitmap() {
if (mImageLoader == null) {
return null;
invalidate();
}
+ @Override
public boolean showTitle() {
return mShowTitle;
}
+ @Override
public boolean showControls() {
return false;
}
+ @Override
public boolean showHires() {
return false;
}
package com.android.gallery3d.filtershow.presets;
import android.graphics.Bitmap;
-import android.graphics.RectF;
import android.util.Log;
import com.android.gallery3d.filtershow.ImageStateAdapter;
import com.android.gallery3d.filtershow.filters.ImageFilter;
-import com.android.gallery3d.filtershow.filters.ImageFilterStraighten;
import com.android.gallery3d.filtershow.imageshow.GeometryMetadata;
import com.android.gallery3d.filtershow.imageshow.ImageShow;
public class ImagePreset {
private static final String LOGTAG = "ImagePreset";
- ImageShow mEndPoint = null;
+
+ private ImageShow mEndPoint = null;
+ private ImageFilter mImageBorder = null;
+ private float mScaleFactor = 1.0f;
+ private boolean mIsHighQuality = false;
+
protected Vector<ImageFilter> mFilters = new Vector<ImageFilter>();
protected String mName = "Original";
protected String mHistoryName = "Original";
protected boolean mIsFxPreset = false;
- enum FullRotate {
- ZERO, NINETY, HUNDRED_EIGHTY, TWO_HUNDRED_SEVENTY
- }
-
- // This is where the geometry metadata lives now.
public final GeometryMetadata mGeoData = new GeometryMetadata();
- public void setGeometry(GeometryMetadata m) {
- mGeoData.set(m);
+ enum FullRotate {
+ ZERO, NINETY, HUNDRED_EIGHTY, TWO_HUNDRED_SEVENTY
}
- private float mScaleFactor = 1.0f;
- private boolean mIsHighQuality = false;
-
public ImagePreset() {
setup();
}
public ImagePreset(ImagePreset source) {
try {
+ if (source.mImageBorder != null) {
+ mImageBorder = source.mImageBorder.clone();
+ }
for (int i = 0; i < source.mFilters.size(); i++) {
add(source.mFilters.elementAt(i).clone());
}
mGeoData.set(source.mGeoData);
}
+ public void setGeometry(GeometryMetadata m) {
+ mGeoData.set(m);
+ }
+
+ public void setBorder(ImageFilter filter) {
+ mImageBorder = filter;
+ }
+
public boolean isFx() {
return mIsFxPreset;
}
if (!mGeoData.equals(preset.mGeoData)) {
return false;
}
+
+ if (mImageBorder != preset.mImageBorder) {
+ return false;
+ }
+
+ if (mImageBorder != null && !mImageBorder.same(preset.mImageBorder)) {
+ return false;
+ }
+
for (int i = 0; i < preset.mFilters.size(); i++) {
ImageFilter a = preset.mFilters.elementAt(i);
ImageFilter b = mFilters.elementAt(i);
// First we apply any transform -- 90 rotate, flip, straighten, crop
Bitmap bitmap = mGeoData.apply(original, mScaleFactor, mIsHighQuality);
- // TODO -- apply borders separately
- ImageFilter borderFilter = null;
+ if (mImageBorder != null) {
+ bitmap = mImageBorder.apply(bitmap, mScaleFactor, mIsHighQuality);
+ }
+
for (int i = 0; i < mFilters.size(); i++) {
ImageFilter filter = mFilters.elementAt(i);
- if (filter.getName().equalsIgnoreCase("Border")) {
- // TODO don't use the name as an id
- borderFilter = filter;
- } else {
- bitmap = filter.apply(bitmap, mScaleFactor, mIsHighQuality);
- }
- }
- if (borderFilter != null) {
- bitmap = borderFilter.apply(bitmap, mScaleFactor, mIsHighQuality);
+ bitmap = filter.apply(bitmap, mScaleFactor, mIsHighQuality);
}
+
if (mEndPoint != null) {
mEndPoint.updateFilteredImage(bitmap);
}