use of com.android.gallery3d.filtershow.filters.FilterRepresentation in project android_packages_apps_Gallery2 by LineageOS.
the class ImagePreset method applyBorder.
public void applyBorder(Allocation in, Allocation out, boolean copyOut, FilterEnvironment environment) {
FilterRepresentation border = getFilterRepresentationForType(FilterRepresentation.TYPE_BORDER);
if (border != null && mDoApplyGeometry) {
// TODO: should keep the bitmap around
Allocation bitmapIn = in;
if (copyOut) {
bitmapIn = Allocation.createTyped(CachingPipeline.getRenderScriptContext(), in.getType());
bitmapIn.copyFrom(out);
}
environment.applyRepresentation(border, bitmapIn, out);
}
}
use of com.android.gallery3d.filtershow.filters.FilterRepresentation in project android_packages_apps_Gallery2 by LineageOS.
the class ImagePreset method getFilterRepresentation.
public FilterRepresentation getFilterRepresentation(int position) {
FilterRepresentation representation = null;
representation = mFilters.elementAt(position).copy();
return representation;
}
use of com.android.gallery3d.filtershow.filters.FilterRepresentation in project android_packages_apps_Gallery2 by LineageOS.
the class ImagePreset method addFilter.
// If the filter is an "None" effect or border, then just don't add this filter.
public void addFilter(FilterRepresentation representation) {
if (representation instanceof FilterUserPresetRepresentation) {
ImagePreset preset = ((FilterUserPresetRepresentation) representation).getImagePreset();
if (preset.nbFilters() == 1 && preset.contains(FilterRepresentation.TYPE_FX)) {
FilterRepresentation rep = preset.getFilterRepresentationForType(FilterRepresentation.TYPE_FX);
addFilter(rep);
} else {
// user preset replaces everything
mFilters.clear();
for (int i = 0; i < preset.nbFilters(); i++) {
addFilter(preset.getFilterRepresentation(i));
}
}
} else if (representation.getFilterType() == FilterRepresentation.TYPE_GEOMETRY) {
// Add geometry filter, removing duplicates and do-nothing operations.
for (int i = 0; i < mFilters.size(); i++) {
if (sameSerializationName(representation, mFilters.elementAt(i))) {
mFilters.remove(i);
}
}
int index = 0;
for (; index < mFilters.size(); index++) {
FilterRepresentation rep = mFilters.elementAt(index);
if (rep.getFilterType() != FilterRepresentation.TYPE_GEOMETRY) {
break;
}
}
if (!representation.isNil()) {
mFilters.insertElementAt(representation, index);
}
} else if (representation.getFilterType() == FilterRepresentation.TYPE_BORDER) {
removeFilter(representation);
if (!isNoneBorderFilter(representation)) {
mFilters.add(representation);
}
} else if (representation.getFilterType() == FilterRepresentation.TYPE_DUALCAM) {
removeFilter(representation);
if (!isNoneDualCamFilter(representation)) {
mFilters.add(representation);
}
} else if (representation.getFilterType() == FilterRepresentation.TYPE_TRUEPORTRAIT) {
removeFilter(representation);
if (!isNoneTruePortraitFilter(representation)) {
mFilters.add(representation);
}
} else if (representation.getFilterType() == FilterRepresentation.TYPE_FX) {
boolean replaced = false;
for (int i = 0; i < mFilters.size(); i++) {
FilterRepresentation current = mFilters.elementAt(i);
if (current.getFilterType() == FilterRepresentation.TYPE_FX || (current.getFilterType() == FilterRepresentation.TYPE_PRESETFILTER)) {
mFilters.remove(i);
replaced = true;
if (!isNoneFxFilter(representation)) {
mFilters.add(i, representation);
}
break;
}
}
if (!replaced && !isNoneFxFilter(representation)) {
mFilters.add(representation);
}
} else if (representation.getFilterType() == FilterRepresentation.TYPE_PRESETFILTER) {
boolean replaced = false;
for (int i = 0; i < mFilters.size(); i++) {
FilterRepresentation current = mFilters.elementAt(i);
if ((current.getFilterType() == FilterRepresentation.TYPE_PRESETFILTER) || (current.getFilterType() == FilterRepresentation.TYPE_FX)) {
mFilters.remove(i);
replaced = true;
if (!isNonePresetFilter(representation)) {
mFilters.add(i, representation);
}
break;
}
}
if (!replaced && !isNonePresetFilter(representation)) {
mFilters.add(representation);
}
} else if (representation.getFilterType() == FilterRepresentation.TYPE_WATERMARK) {
boolean replaced = false;
for (int i = 0; i < mFilters.size(); i++) {
FilterRepresentation current = mFilters.elementAt(i);
if (current.getFilterType() == FilterRepresentation.TYPE_WATERMARK) {
mFilters.remove(i);
replaced = true;
mFilters.add(i, representation);
break;
}
}
if (!replaced) {
mFilters.add(representation);
}
} else {
mFilters.add(representation);
}
// Enforces Filter type ordering for borders and dual cam
FilterRepresentation border = null;
FilterRepresentation dualcam = null;
FilterRepresentation trueportrait = null;
for (int i = 0; i < mFilters.size(); ) {
FilterRepresentation rep = mFilters.elementAt(i);
if (rep.getFilterType() == FilterRepresentation.TYPE_BORDER) {
border = rep;
mFilters.remove(i);
continue;
} else if (rep.getFilterType() == FilterRepresentation.TYPE_DUALCAM) {
dualcam = rep;
mFilters.remove(i);
continue;
} else if (rep.getFilterType() == FilterRepresentation.TYPE_TRUEPORTRAIT) {
trueportrait = rep;
mFilters.remove(i);
continue;
}
i++;
}
if (border != null) {
mFilters.add(border);
}
if (dualcam != null) {
int i = 0;
for (; i < mFilters.size(); i++) {
FilterRepresentation rep = mFilters.elementAt(i);
if (rep.getFilterType() != FilterRepresentation.TYPE_GEOMETRY) {
break;
}
}
mFilters.add(i, dualcam);
}
if (trueportrait != null) {
int i = 0;
for (; i < mFilters.size(); i++) {
FilterRepresentation rep = mFilters.elementAt(i);
if (rep.getFilterType() != FilterRepresentation.TYPE_GEOMETRY) {
break;
}
}
mFilters.add(i, trueportrait);
}
}
use of com.android.gallery3d.filtershow.filters.FilterRepresentation in project android_packages_apps_Gallery2 by LineageOS.
the class ImagePreset method getFilterRepresentationCopyFrom.
public FilterRepresentation getFilterRepresentationCopyFrom(FilterRepresentation filterRepresentation) {
// TODO: add concept of position in the filters (to allow multiple instances)
if (filterRepresentation == null) {
return null;
}
int position = getPositionForRepresentation(filterRepresentation);
if (position == -1) {
return null;
}
FilterRepresentation representation = mFilters.elementAt(position);
if (representation != null) {
representation = representation.copy();
}
return representation;
}
use of com.android.gallery3d.filtershow.filters.FilterRepresentation in project android_packages_apps_Gallery2 by LineageOS.
the class ImagePreset method fillImageStateAdapter.
public void fillImageStateAdapter(StateAdapter imageStateAdapter) {
if (imageStateAdapter == null) {
return;
}
Vector<State> states = new Vector<State>();
for (FilterRepresentation filter : mFilters) {
if (filter instanceof FilterUserPresetRepresentation) {
// do not show the user preset itself in the state panel
continue;
}
State state = new State(filter.getName());
state.setFilterRepresentation(filter);
states.add(state);
}
imageStateAdapter.fill(states);
}
Aggregations