Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d4e3912d authored by nicolasroard's avatar nicolasroard Committed by Android (Google) Code Review
Browse files

Merge "Re-enable caching step in RS filters" into gb-ub-photos-bryce

parents 62cc2aa4 0c90af22
Loading
Loading
Loading
Loading
+12 −4
Original line number Diff line number Diff line
@@ -64,13 +64,16 @@ public abstract class ImageFilterRS extends ImageFilter {
            if (DEBUG) {
                Log.v(LOGTAG, "apply filter " + getName() + " in pipeline " + pipeline.getName());
            }
            pipeline.prepareRenderscriptAllocations(bitmap);
            Resources rsc = pipeline.getResources();
            if (pipeline.prepareRenderscriptAllocations(bitmap)
                    || !isResourcesLoaded()) {
                freeResources();
                createFilter(rsc, scaleFactor, quality);
                setResourcesLoaded(true);
            }
            bindScriptValues();
            runFilter();
            update(bitmap);
            freeResources();
            if (DEBUG) {
                Log.v(LOGTAG, "DONE apply filter " + getName() + " in pipeline " + pipeline.getName());
            }
@@ -158,6 +161,11 @@ public abstract class ImageFilterRS extends ImageFilter {
     */
    abstract protected void resetScripts();

    /**
     * Scripts values should be bound here
     */
    abstract protected void bindScriptValues();

    public void freeResources() {
        if (!isResourcesLoaded()) {
            return;
+10 −8
Original line number Diff line number Diff line
@@ -22,7 +22,6 @@ public class ImageFilterSharpen extends ImageFilterRS {

    private static final String LOGTAG = "ImageFilterSharpen";
    private ScriptC_convolve3x3 mScript;
    float mScaleFactor;

    private FilterBasicRepresentation mParameters;

@@ -63,19 +62,14 @@ public class ImageFilterSharpen extends ImageFilterRS {
    @Override
    protected void createFilter(android.content.res.Resources res, float scaleFactor,
            int quality) {
        int w = getInPixelsAllocation().getType().getX();
        int h = getInPixelsAllocation().getType().getY();
        mScaleFactor = scaleFactor;

        if (mScript == null) {
            mScript = new ScriptC_convolve3x3(getRenderScriptContext(), res, R.raw.convolve3x3);
        }
        mScript.set_gWidth(w);
        mScript.set_gHeight(h);
    }

    private void computeKernel() {
        float p1 = mParameters.getValue() * mScaleFactor;
        float scaleFactor = getEnvironment().getScaleFactor();
        float p1 = mParameters.getValue() * scaleFactor;
        float value = p1 / 100.0f;
        float f[] = new float[9];
        float p = value;
@@ -91,6 +85,14 @@ public class ImageFilterSharpen extends ImageFilterRS {
        mScript.set_gCoeffs(f);
    }

    @Override
    protected void bindScriptValues() {
        int w = getInPixelsAllocation().getType().getX();
        int h = getInPixelsAllocation().getType().getY();
        mScript.set_gWidth(w);
        mScript.set_gHeight(h);
    }

    @Override
    protected void runFilter() {
        if (mParameters == null) {
+1 −0
Original line number Diff line number Diff line
@@ -77,4 +77,5 @@ public class FilterEnvironment {
    public void setCachingPipeline(CachingPipeline cachingPipeline) {
        mCachingPipeline = cachingPipeline;
    }

}