Search in sources :

Example 31 with FilterRepresentation

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);
    }
}
Also used : Allocation(android.renderscript.Allocation) FilterRepresentation(com.android.gallery3d.filtershow.filters.FilterRepresentation)

Example 32 with FilterRepresentation

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;
}
Also used : FilterRepresentation(com.android.gallery3d.filtershow.filters.FilterRepresentation)

Example 33 with FilterRepresentation

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);
    }
}
Also used : FilterRepresentation(com.android.gallery3d.filtershow.filters.FilterRepresentation) FilterUserPresetRepresentation(com.android.gallery3d.filtershow.filters.FilterUserPresetRepresentation)

Example 34 with FilterRepresentation

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;
}
Also used : FilterRepresentation(com.android.gallery3d.filtershow.filters.FilterRepresentation)

Example 35 with FilterRepresentation

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);
}
Also used : State(com.android.gallery3d.filtershow.state.State) FilterRepresentation(com.android.gallery3d.filtershow.filters.FilterRepresentation) Vector(java.util.Vector) FilterUserPresetRepresentation(com.android.gallery3d.filtershow.filters.FilterUserPresetRepresentation)

Aggregations

FilterRepresentation (com.android.gallery3d.filtershow.filters.FilterRepresentation)78 Action (com.android.gallery3d.filtershow.category.Action)12 FiltersManager (com.android.gallery3d.filtershow.filters.FiltersManager)12 CategoryAdapter (com.android.gallery3d.filtershow.category.CategoryAdapter)11 Point (android.graphics.Point)8 ImagePreset (com.android.gallery3d.filtershow.pipeline.ImagePreset)8 Bitmap (android.graphics.Bitmap)7 FilterUserPresetRepresentation (com.android.gallery3d.filtershow.filters.FilterUserPresetRepresentation)6 FilterShowActivity (com.android.gallery3d.filtershow.FilterShowActivity)5 FilterDualCamFusionRepresentation (com.android.gallery3d.filtershow.filters.FilterDualCamFusionRepresentation)5 FilterMirrorRepresentation (com.android.gallery3d.filtershow.filters.FilterMirrorRepresentation)5 MasterImage (com.android.gallery3d.filtershow.imageshow.MasterImage)5 FilterGradRepresentation (com.android.gallery3d.filtershow.filters.FilterGradRepresentation)4 FilterRotateRepresentation (com.android.gallery3d.filtershow.filters.FilterRotateRepresentation)4 ArrayList (java.util.ArrayList)4 Uri (android.net.Uri)3 LayoutInflater (android.view.LayoutInflater)3 View (android.view.View)3 OnClickListener (android.view.View.OnClickListener)3 FilterCropRepresentation (com.android.gallery3d.filtershow.filters.FilterCropRepresentation)3