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.ImageFilterFx;
import com.android.gallery3d.filtershow.filters.ImageFilterParametricBorder;
import com.android.gallery3d.filtershow.filters.ImageFilterRS;
import com.android.gallery3d.filtershow.imageshow.ImageBorder;
private void fillListImages(LinearLayout listFilters) {
// TODO: use listview
// TODO: load the filters straight from the filesystem
- ImagePreset[] preset = new ImagePreset[18];
+
+ ImageFilterFx[] fxArray = new ImageFilterFx[18];
int p = 0;
int[] drawid = {
R.string.ffx_washout_color,
};
- preset[p++] = new ImagePreset();
+ ImagePreset preset = new ImagePreset(); // empty
+ ImageSmallFilter filter = new ImageSmallFilter(this);
+
+ filter.setSelected(true);
+ mCurrentImageSmallFilter = filter;
+
+ filter.setPreviousImageSmallFilter(null);
+ preset.setIsFx(true);
+ filter.setImagePreset(preset);
+
+ filter.setController(this);
+ filter.setImageLoader(mImageLoader);
+ listFilters.addView(filter);
+ ImageSmallFilter previousFilter = filter;
+
BitmapFactory.Options o = new BitmapFactory.Options();
o.inScaled = false;
for (int i = 0; i < drawid.length; i++) {
Bitmap b = BitmapFactory.decodeResource(getResources(), drawid[i], o);
- preset[p++] = new ImagePresetFX(b, getString(fxNameid[i]));
+ fxArray[p++] = new ImageFilterFx(b, getString(fxNameid[i]));
}
- ImageSmallFilter previousFilter = null;
for (int i = 0; i < p; i++) {
- ImageSmallFilter filter = new ImageSmallFilter(this);
- if (i == 0) {
- filter.setSelected(true);
- mCurrentImageSmallFilter = filter;
- }
+ filter = new ImageSmallFilter(this);
+
filter.setPreviousImageSmallFilter(previousFilter);
- preset[i].setIsFx(true);
- filter.setImagePreset(preset[i]);
+ filter.setImageFilter(fxArray[i]);
filter.setController(this);
filter.setImageLoader(mImageLoader);
listFilters.addView(filter);
}
// Default preset (original)
- mImageShow.setImagePreset(preset[0]);
+ mImageShow.setImagePreset(preset);
}
private void fillListBorders(LinearLayout listBorders) {
ImagePreset oldPreset = mImageShow.getImagePreset();
ImagePreset copy = new ImagePreset(oldPreset);
// TODO: use a numerical constant instead.
- if (setBorder) {
- copy.setHistoryName("Border");
- copy.setBorder(imageFilter);
- } else {
- copy.add(imageFilter);
- }
+
+ copy.add(imageFilter);
+
mImageShow.setImagePreset(copy);
invalidateViews();
}
public ImageFilter setImagePreset(ImageFilter filter, String name) {
ImagePreset copy = new ImagePreset(getImagePreset());
copy.add(filter);
- copy.setHistoryName(filter.getName());
copy.setIsFx(false);
mMasterImage.setImagePreset(copy);
return filter;
protected int mParameter = 0;
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_WBALANCE = 3;
+ public static final byte TYPE_VIGNETTE = 4;
+ public static final byte TYPE_NORMAL = 5;
+ private byte filterType = TYPE_NORMAL;
+
+ public byte getFilterType(){
+ return filterType;
+ }
+
+ protected void setFilterType(byte type){
+ filterType = type;
+ }
@Override
public ImageFilter clone() throws CloneNotSupportedException {
ImageFilter filter = (ImageFilter) super.clone();
filter.setName(getName());
filter.setParameter(getParameter());
+ filter.setFilterType(filterType);
return filter;
}
}
public ImageFilterBorder(Drawable ninePatch) {
+ setFilterType(TYPE_BORDER);
mName = "Border";
mNinePatch = ninePatch;
}
private static final String TAG = "ImageFilterFx";
Bitmap fxBitmap;
- public ImageFilterFx(Bitmap fxBitmap) {
- mName = "fx";
+ public ImageFilterFx(Bitmap fxBitmap,String name) {
+ setFilterType(TYPE_FX);
+ mName = name;
this.fxBitmap = fxBitmap;
}
private static final String TAG = "ImageFilterWBalance";
public ImageFilterWBalance() {
+ setFilterType(TYPE_WBALANCE);
mName = "WBalance";
}
public void setImageFilter(ImageFilter filter) {
mImageFilter = filter;
mImagePreset = new ImagePreset();
+ mImagePreset.setName(filter.getName());
mImagePreset.add(mImageFilter);
}
setup();
}
+ public ImagePreset(ImagePreset source, String historyName) {
+ this(source);
+ if (historyName!=null) setHistoryName(historyName);
+ }
+
public ImagePreset(ImagePreset source) {
try {
if (source.mImageBorder != null) {
mGeoData.set(m);
}
- public void setBorder(ImageFilter filter) {
+ private void setBorder(ImageFilter filter) {
mImageBorder = filter;
}
mHistoryName = name;
}
- public void setHistoryName(String name) {
+ private void setHistoryName(String name) {
mHistoryName = name;
}
}
public void add(ImageFilter filter) {
- mFilters.add(filter);
+ if (filter.getFilterType() == ImageFilter.TYPE_BORDER){
+ setHistoryName("Border");
+ setBorder(filter);
+ } else if (filter.getFilterType() == ImageFilter.TYPE_FX){
+ Vector<ImageFilter> fl = mFilters;
+ boolean found = false;
+ for (int i = 0; i < mFilters.size(); i++) {
+ byte type = fl.get(i).getFilterType();
+ if (found) {
+ if (type != ImageFilter.TYPE_VIGNETTE){
+ fl.remove(i);
+ }
+ } else if (type==ImageFilter.TYPE_FX){
+ fl.remove(i);
+ fl.add(i, filter);
+ setHistoryName(filter.getName());
+ found = true;
+ }
+
+ }
+ mFilters.add(filter);
+ setHistoryName(filter.getName());
+ } else {
+ mFilters.add(filter);
+ setHistoryName(filter.getName());
+ }
}
public void remove(String filterName) {
public void setup() {
if (fxBitmap != null) {
- mFilters.add(new ImageFilterFx(fxBitmap));
+ mFilters.add(new ImageFilterFx(fxBitmap,name));
}
}
applyNewCurve();
// Log.v(LOGTAG, "ACTION UP, mCurrentControlPoint set to null!");
mCurrentControlPoint = null;
- ImagePreset copy = new ImagePreset(getImagePreset());
-
+ String name = null;
if (mUseRed && mUseGreen && mUseBlue) {
- copy.setHistoryName("Curves (RGB)");
+ name = "Curves (RGB)";
} else if (mUseRed) {
- copy.setHistoryName("Curves (Red)");
+ name = "Curves (Red)";
} else if (mUseGreen) {
- copy.setHistoryName("Curves (Green)");
+ name = "Curves (Green)";
} else if (mUseBlue) {
- copy.setHistoryName("Curves (Blue)");
+ name = "Curves (Blue)";
}
+
+
+ ImagePreset copy = new ImagePreset(getImagePreset(),name);
+
copy.setIsFx(false);
mImageLoader.getHistory().insert(copy, 0);