Merge "Update IP_JB to Mr1" into jb-mr2-dev
This commit is contained in:
@ -24,6 +24,6 @@ LOCAL_SRC_FILES := $(call all-java-files-under, src) \
|
|||||||
#LOCAL_STATIC_JAVA_LIBRARIES := android.renderscript
|
#LOCAL_STATIC_JAVA_LIBRARIES := android.renderscript
|
||||||
|
|
||||||
LOCAL_PACKAGE_NAME := ImageProcessingJB
|
LOCAL_PACKAGE_NAME := ImageProcessingJB
|
||||||
LOCAL_SDK_VERSION := 16
|
LOCAL_SDK_VERSION := 17
|
||||||
|
|
||||||
include $(BUILD_PACKAGE)
|
include $(BUILD_PACKAGE)
|
||||||
|
@ -0,0 +1,34 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2012 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.android.rs.imagejb;
|
||||||
|
|
||||||
|
import java.lang.Math;
|
||||||
|
|
||||||
|
|
||||||
|
public class BWFilter extends TestBase {
|
||||||
|
private ScriptC_bwfilter mScript;
|
||||||
|
|
||||||
|
public void createTest(android.content.res.Resources res) {
|
||||||
|
mScript = new ScriptC_bwfilter(mRS);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void runTest() {
|
||||||
|
mScript.invoke_prepareBwFilter(50, 50, 50);
|
||||||
|
mScript.forEach_bwFilterKernel(mInPixelsAllocation, mOutPixelsAllocation);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,178 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2012 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.android.rs.imagejb;
|
||||||
|
|
||||||
|
import java.lang.Math;
|
||||||
|
import java.lang.Short;
|
||||||
|
|
||||||
|
import android.renderscript.Allocation;
|
||||||
|
import android.renderscript.Element;
|
||||||
|
import android.renderscript.Matrix4f;
|
||||||
|
import android.renderscript.RenderScript;
|
||||||
|
import android.renderscript.Script;
|
||||||
|
import android.renderscript.ScriptC;
|
||||||
|
import android.renderscript.ScriptGroup;
|
||||||
|
import android.renderscript.ScriptIntrinsicBlend;
|
||||||
|
import android.renderscript.Type;
|
||||||
|
import android.util.Log;
|
||||||
|
import android.widget.SeekBar;
|
||||||
|
import android.widget.TextView;
|
||||||
|
import android.widget.AdapterView;
|
||||||
|
import android.widget.ArrayAdapter;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.Spinner;
|
||||||
|
|
||||||
|
public class Blend extends TestBase {
|
||||||
|
private ScriptIntrinsicBlend mBlend;
|
||||||
|
private ScriptC_blend mBlendHelper;
|
||||||
|
private short image1Alpha = 128;
|
||||||
|
private short image2Alpha = 128;
|
||||||
|
|
||||||
|
String mIntrinsicNames[];
|
||||||
|
|
||||||
|
private Allocation image1;
|
||||||
|
private Allocation image2;
|
||||||
|
private int currentIntrinsic = 0;
|
||||||
|
|
||||||
|
private AdapterView.OnItemSelectedListener mIntrinsicSpinnerListener =
|
||||||
|
new AdapterView.OnItemSelectedListener() {
|
||||||
|
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
|
||||||
|
currentIntrinsic = pos;
|
||||||
|
if (mRS != null) {
|
||||||
|
runTest();
|
||||||
|
act.updateDisplay();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onNothingSelected(AdapterView parent) {
|
||||||
|
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
public void createTest(android.content.res.Resources res) {
|
||||||
|
mBlend = ScriptIntrinsicBlend.create(mRS, Element.U8_4(mRS));
|
||||||
|
mBlendHelper = new ScriptC_blend(mRS);
|
||||||
|
mBlendHelper.set_alpha((short)128);
|
||||||
|
|
||||||
|
image1 = Allocation.createTyped(mRS, mInPixelsAllocation.getType());
|
||||||
|
image2 = Allocation.createTyped(mRS, mInPixelsAllocation2.getType());
|
||||||
|
|
||||||
|
mIntrinsicNames = new String[14];
|
||||||
|
mIntrinsicNames[0] = "Source";
|
||||||
|
mIntrinsicNames[1] = "Destination";
|
||||||
|
mIntrinsicNames[2] = "Source Over";
|
||||||
|
mIntrinsicNames[3] = "Destination Over";
|
||||||
|
mIntrinsicNames[4] = "Source In";
|
||||||
|
mIntrinsicNames[5] = "Destination In";
|
||||||
|
mIntrinsicNames[6] = "Source Out";
|
||||||
|
mIntrinsicNames[7] = "Destination Out";
|
||||||
|
mIntrinsicNames[8] = "Source Atop";
|
||||||
|
mIntrinsicNames[9] = "Destination Atop";
|
||||||
|
mIntrinsicNames[10] = "XOR";
|
||||||
|
mIntrinsicNames[11] = "Add";
|
||||||
|
mIntrinsicNames[12] = "Subtract";
|
||||||
|
mIntrinsicNames[13] = "Multiply";
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean onSpinner1Setup(Spinner s) {
|
||||||
|
s.setAdapter(new ArrayAdapter<String>(
|
||||||
|
act, R.layout.spinner_layout, mIntrinsicNames));
|
||||||
|
s.setOnItemSelectedListener(mIntrinsicSpinnerListener);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean onBar1Setup(SeekBar b, TextView t) {
|
||||||
|
t.setText("Image 1 Alpha");
|
||||||
|
b.setMax(255);
|
||||||
|
b.setProgress(image1Alpha);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onBar1Changed(int progress) {
|
||||||
|
image1Alpha = (short)progress;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean onBar2Setup(SeekBar b, TextView t) {
|
||||||
|
t.setText("Image 2 Alpha");
|
||||||
|
b.setMax(255);
|
||||||
|
b.setProgress(image2Alpha);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onBar2Changed(int progress) {
|
||||||
|
image2Alpha = (short)progress;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void runTest() {
|
||||||
|
image1.copy2DRangeFrom(0, 0, mInPixelsAllocation.getType().getX(), mInPixelsAllocation.getType().getY(), mInPixelsAllocation, 0, 0);
|
||||||
|
image2.copy2DRangeFrom(0, 0, mInPixelsAllocation2.getType().getX(), mInPixelsAllocation2.getType().getY(), mInPixelsAllocation2, 0, 0);
|
||||||
|
|
||||||
|
mBlendHelper.set_alpha(image1Alpha);
|
||||||
|
mBlendHelper.forEach_setImageAlpha(image1);
|
||||||
|
|
||||||
|
mBlendHelper.set_alpha(image2Alpha);
|
||||||
|
mBlendHelper.forEach_setImageAlpha(image2);
|
||||||
|
|
||||||
|
switch (currentIntrinsic) {
|
||||||
|
case 0:
|
||||||
|
mBlend.forEachSrc(image1, image2);
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
mBlend.forEachDst(image1, image2);
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
mBlend.forEachSrcOver(image1, image2);
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
mBlend.forEachDstOver(image1, image2);
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
mBlend.forEachSrcIn(image1, image2);
|
||||||
|
break;
|
||||||
|
case 5:
|
||||||
|
mBlend.forEachDstIn(image1, image2);
|
||||||
|
break;
|
||||||
|
case 6:
|
||||||
|
mBlend.forEachSrcOut(image1, image2);
|
||||||
|
break;
|
||||||
|
case 7:
|
||||||
|
mBlend.forEachDstOut(image1, image2);
|
||||||
|
break;
|
||||||
|
case 8:
|
||||||
|
mBlend.forEachSrcAtop(image1, image2);
|
||||||
|
break;
|
||||||
|
case 9:
|
||||||
|
mBlend.forEachDstAtop(image1, image2);
|
||||||
|
break;
|
||||||
|
case 10:
|
||||||
|
mBlend.forEachXor(image1, image2);
|
||||||
|
break;
|
||||||
|
case 11:
|
||||||
|
mBlend.forEachAdd(image1, image2);
|
||||||
|
break;
|
||||||
|
case 12:
|
||||||
|
mBlend.forEachSubtract(image1, image2);
|
||||||
|
break;
|
||||||
|
case 13:
|
||||||
|
mBlend.forEachMultiply(image1, image2);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
mOutPixelsAllocation.copy2DRangeFrom(0, 0, image2.getType().getX(), image2.getType().getY(), image2, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -21,12 +21,16 @@ import java.lang.Math;
|
|||||||
import android.renderscript.Allocation;
|
import android.renderscript.Allocation;
|
||||||
import android.renderscript.Element;
|
import android.renderscript.Element;
|
||||||
import android.renderscript.RenderScript;
|
import android.renderscript.RenderScript;
|
||||||
|
import android.renderscript.ScriptIntrinsicBlur;
|
||||||
import android.renderscript.Type;
|
import android.renderscript.Type;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.widget.SeekBar;
|
import android.widget.SeekBar;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
public class Blur25 extends TestBase {
|
public class Blur25 extends TestBase {
|
||||||
|
private boolean mUseIntrinsic = false;
|
||||||
|
private ScriptIntrinsicBlur mIntrinsic;
|
||||||
|
|
||||||
private int MAX_RADIUS = 25;
|
private int MAX_RADIUS = 25;
|
||||||
private ScriptC_threshold mScript;
|
private ScriptC_threshold mScript;
|
||||||
private float mRadius = MAX_RADIUS;
|
private float mRadius = MAX_RADIUS;
|
||||||
@ -35,7 +39,8 @@ public class Blur25 extends TestBase {
|
|||||||
private Allocation mScratchPixelsAllocation2;
|
private Allocation mScratchPixelsAllocation2;
|
||||||
|
|
||||||
|
|
||||||
public Blur25() {
|
public Blur25(boolean useIntrinsic) {
|
||||||
|
mUseIntrinsic = useIntrinsic;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean onBar1Setup(SeekBar b, TextView t) {
|
public boolean onBar1Setup(SeekBar b, TextView t) {
|
||||||
@ -50,7 +55,11 @@ public class Blur25 extends TestBase {
|
|||||||
if (mRadius <= 0.10f) {
|
if (mRadius <= 0.10f) {
|
||||||
mRadius = 0.10f;
|
mRadius = 0.10f;
|
||||||
}
|
}
|
||||||
mScript.invoke_setRadius((int)mRadius);
|
if (mUseIntrinsic) {
|
||||||
|
mIntrinsic.setRadius(mRadius);
|
||||||
|
} else {
|
||||||
|
mScript.invoke_setRadius((int)mRadius);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -58,33 +67,52 @@ public class Blur25 extends TestBase {
|
|||||||
int width = mInPixelsAllocation.getType().getX();
|
int width = mInPixelsAllocation.getType().getX();
|
||||||
int height = mInPixelsAllocation.getType().getY();
|
int height = mInPixelsAllocation.getType().getY();
|
||||||
|
|
||||||
Type.Builder tb = new Type.Builder(mRS, Element.F32_4(mRS));
|
if (mUseIntrinsic) {
|
||||||
tb.setX(width);
|
mIntrinsic = ScriptIntrinsicBlur.create(mRS, Element.U8_4(mRS));
|
||||||
tb.setY(height);
|
mIntrinsic.setRadius(MAX_RADIUS);
|
||||||
mScratchPixelsAllocation1 = Allocation.createTyped(mRS, tb.create());
|
mIntrinsic.setInput(mInPixelsAllocation);
|
||||||
mScratchPixelsAllocation2 = Allocation.createTyped(mRS, tb.create());
|
} else {
|
||||||
|
|
||||||
mScript = new ScriptC_threshold(mRS, res, R.raw.threshold);
|
Type.Builder tb = new Type.Builder(mRS, Element.F32_4(mRS));
|
||||||
mScript.set_width(width);
|
tb.setX(width);
|
||||||
mScript.set_height(height);
|
tb.setY(height);
|
||||||
mScript.invoke_setRadius(MAX_RADIUS);
|
mScratchPixelsAllocation1 = Allocation.createTyped(mRS, tb.create());
|
||||||
|
mScratchPixelsAllocation2 = Allocation.createTyped(mRS, tb.create());
|
||||||
|
|
||||||
mScript.set_InPixel(mInPixelsAllocation);
|
mScript = new ScriptC_threshold(mRS, res, R.raw.threshold);
|
||||||
mScript.set_ScratchPixel1(mScratchPixelsAllocation1);
|
mScript.set_width(width);
|
||||||
mScript.set_ScratchPixel2(mScratchPixelsAllocation2);
|
mScript.set_height(height);
|
||||||
|
mScript.invoke_setRadius(MAX_RADIUS);
|
||||||
|
|
||||||
|
mScript.set_InPixel(mInPixelsAllocation);
|
||||||
|
mScript.set_ScratchPixel1(mScratchPixelsAllocation1);
|
||||||
|
mScript.set_ScratchPixel2(mScratchPixelsAllocation2);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void runTest() {
|
public void runTest() {
|
||||||
mScript.forEach_copyIn(mInPixelsAllocation, mScratchPixelsAllocation1);
|
if (mUseIntrinsic) {
|
||||||
mScript.forEach_horz(mScratchPixelsAllocation2);
|
mIntrinsic.forEach(mOutPixelsAllocation);
|
||||||
mScript.forEach_vert(mOutPixelsAllocation);
|
} else {
|
||||||
|
mScript.forEach_copyIn(mInPixelsAllocation, mScratchPixelsAllocation1);
|
||||||
|
mScript.forEach_horz(mScratchPixelsAllocation2);
|
||||||
|
mScript.forEach_vert(mOutPixelsAllocation);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setupBenchmark() {
|
public void setupBenchmark() {
|
||||||
mScript.invoke_setRadius(MAX_RADIUS);
|
if (mUseIntrinsic) {
|
||||||
|
mIntrinsic.setRadius(MAX_RADIUS);
|
||||||
|
} else {
|
||||||
|
mScript.invoke_setRadius(MAX_RADIUS);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void exitBenchmark() {
|
public void exitBenchmark() {
|
||||||
mScript.invoke_setRadius((int)mRadius);
|
if (mUseIntrinsic) {
|
||||||
|
mIntrinsic.setRadius(mRadius);
|
||||||
|
} else {
|
||||||
|
mScript.invoke_setRadius((int)mRadius);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,14 +24,19 @@ import android.renderscript.Matrix4f;
|
|||||||
import android.renderscript.RenderScript;
|
import android.renderscript.RenderScript;
|
||||||
import android.renderscript.Script;
|
import android.renderscript.Script;
|
||||||
import android.renderscript.ScriptC;
|
import android.renderscript.ScriptC;
|
||||||
|
import android.renderscript.ScriptGroup;
|
||||||
|
import android.renderscript.ScriptIntrinsicColorMatrix;
|
||||||
import android.renderscript.Type;
|
import android.renderscript.Type;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
public class ColorMatrix extends TestBase {
|
public class ColorMatrix extends TestBase {
|
||||||
private ScriptC_colormatrix mScript;
|
private ScriptC_colormatrix mScript;
|
||||||
|
private ScriptIntrinsicColorMatrix mIntrinsic;
|
||||||
|
private boolean mUseIntrinsic;
|
||||||
private boolean mUseGrey;
|
private boolean mUseGrey;
|
||||||
|
|
||||||
public ColorMatrix(boolean useGrey) {
|
public ColorMatrix(boolean useIntrinsic, boolean useGrey) {
|
||||||
|
mUseIntrinsic = useIntrinsic;
|
||||||
mUseGrey = useGrey;
|
mUseGrey = useGrey;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -41,12 +46,25 @@ public class ColorMatrix extends TestBase {
|
|||||||
m.set(1, 1, 0.9f);
|
m.set(1, 1, 0.9f);
|
||||||
m.set(1, 2, 0.2f);
|
m.set(1, 2, 0.2f);
|
||||||
|
|
||||||
mScript = new ScriptC_colormatrix(mRS, res, R.raw.colormatrix);
|
if (mUseIntrinsic) {
|
||||||
mScript.invoke_setMatrix(m);
|
mIntrinsic = ScriptIntrinsicColorMatrix.create(mRS, Element.U8_4(mRS));
|
||||||
|
if (mUseGrey) {
|
||||||
|
mIntrinsic.setGreyscale();
|
||||||
|
} else {
|
||||||
|
mIntrinsic.setColorMatrix(m);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
mScript = new ScriptC_colormatrix(mRS, res, R.raw.colormatrix);
|
||||||
|
mScript.invoke_setMatrix(m);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void runTest() {
|
public void runTest() {
|
||||||
mScript.forEach_root(mInPixelsAllocation, mOutPixelsAllocation);
|
if (mUseIntrinsic) {
|
||||||
|
mIntrinsic.forEach(mInPixelsAllocation, mOutPixelsAllocation);
|
||||||
|
} else {
|
||||||
|
mScript.forEach_root(mInPixelsAllocation, mOutPixelsAllocation);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,35 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2012 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.android.rs.imagejb;
|
||||||
|
|
||||||
|
import java.lang.Math;
|
||||||
|
|
||||||
|
import android.renderscript.Allocation;
|
||||||
|
|
||||||
|
public class Contrast extends TestBase {
|
||||||
|
private ScriptC_contrast mScript;
|
||||||
|
|
||||||
|
public void createTest(android.content.res.Resources res) {
|
||||||
|
mScript = new ScriptC_contrast(mRS);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void runTest() {
|
||||||
|
mScript.invoke_setBright(50.f);
|
||||||
|
mScript.forEach_contrast(mInPixelsAllocation, mOutPixelsAllocation);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -24,16 +24,21 @@ import android.renderscript.Matrix4f;
|
|||||||
import android.renderscript.RenderScript;
|
import android.renderscript.RenderScript;
|
||||||
import android.renderscript.Script;
|
import android.renderscript.Script;
|
||||||
import android.renderscript.ScriptC;
|
import android.renderscript.ScriptC;
|
||||||
|
import android.renderscript.ScriptGroup;
|
||||||
|
import android.renderscript.ScriptIntrinsicConvolve3x3;
|
||||||
import android.renderscript.Type;
|
import android.renderscript.Type;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
public class Convolve3x3 extends TestBase {
|
public class Convolve3x3 extends TestBase {
|
||||||
private ScriptC_convolve3x3 mScript;
|
private ScriptC_convolve3x3 mScript;
|
||||||
|
private ScriptIntrinsicConvolve3x3 mIntrinsic;
|
||||||
|
|
||||||
private int mWidth;
|
private int mWidth;
|
||||||
private int mHeight;
|
private int mHeight;
|
||||||
|
private boolean mUseIntrinsic;
|
||||||
|
|
||||||
public Convolve3x3() {
|
public Convolve3x3(boolean useIntrinsic) {
|
||||||
|
mUseIntrinsic = useIntrinsic;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void createTest(android.content.res.Resources res) {
|
public void createTest(android.content.res.Resources res) {
|
||||||
@ -45,11 +50,17 @@ public class Convolve3x3 extends TestBase {
|
|||||||
f[3] = -1.f; f[4] = 5.f; f[5] = -1.f;
|
f[3] = -1.f; f[4] = 5.f; f[5] = -1.f;
|
||||||
f[6] = 0.f; f[7] = -1.f; f[8] = 0.f;
|
f[6] = 0.f; f[7] = -1.f; f[8] = 0.f;
|
||||||
|
|
||||||
mScript = new ScriptC_convolve3x3(mRS, res, R.raw.convolve3x3);
|
if (mUseIntrinsic) {
|
||||||
mScript.set_gCoeffs(f);
|
mIntrinsic = ScriptIntrinsicConvolve3x3.create(mRS, Element.U8_4(mRS));
|
||||||
mScript.set_gIn(mInPixelsAllocation);
|
mIntrinsic.setCoefficients(f);
|
||||||
mScript.set_gWidth(mWidth);
|
mIntrinsic.setInput(mInPixelsAllocation);
|
||||||
mScript.set_gHeight(mHeight);
|
} else {
|
||||||
|
mScript = new ScriptC_convolve3x3(mRS, res, R.raw.convolve3x3);
|
||||||
|
mScript.set_gCoeffs(f);
|
||||||
|
mScript.set_gIn(mInPixelsAllocation);
|
||||||
|
mScript.set_gWidth(mWidth);
|
||||||
|
mScript.set_gHeight(mHeight);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void runTest() {
|
public void runTest() {
|
||||||
|
@ -24,16 +24,21 @@ import android.renderscript.Matrix4f;
|
|||||||
import android.renderscript.RenderScript;
|
import android.renderscript.RenderScript;
|
||||||
import android.renderscript.Script;
|
import android.renderscript.Script;
|
||||||
import android.renderscript.ScriptC;
|
import android.renderscript.ScriptC;
|
||||||
|
import android.renderscript.ScriptGroup;
|
||||||
|
import android.renderscript.ScriptIntrinsicConvolve5x5;
|
||||||
import android.renderscript.Type;
|
import android.renderscript.Type;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
public class Convolve5x5 extends TestBase {
|
public class Convolve5x5 extends TestBase {
|
||||||
private ScriptC_convolve5x5 mScript;
|
private ScriptC_convolve5x5 mScript;
|
||||||
|
private ScriptIntrinsicConvolve5x5 mIntrinsic;
|
||||||
|
|
||||||
private int mWidth;
|
private int mWidth;
|
||||||
private int mHeight;
|
private int mHeight;
|
||||||
|
private boolean mUseIntrinsic;
|
||||||
|
|
||||||
public Convolve5x5() {
|
public Convolve5x5(boolean useIntrinsic) {
|
||||||
|
mUseIntrinsic = useIntrinsic;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void createTest(android.content.res.Resources res) {
|
public void createTest(android.content.res.Resources res) {
|
||||||
@ -59,15 +64,25 @@ public class Convolve5x5 extends TestBase {
|
|||||||
f[15]= -3.f; f[16]= 0.f; f[17]= 6.f; f[18]= 0.f; f[19]= -3.f;
|
f[15]= -3.f; f[16]= 0.f; f[17]= 6.f; f[18]= 0.f; f[19]= -3.f;
|
||||||
f[20]= -1.f; f[21]= -3.f; f[22]= -4.f; f[23]= -3.f; f[24]= -1.f;
|
f[20]= -1.f; f[21]= -3.f; f[22]= -4.f; f[23]= -3.f; f[24]= -1.f;
|
||||||
|
|
||||||
mScript = new ScriptC_convolve5x5(mRS, res, R.raw.convolve5x5);
|
if (mUseIntrinsic) {
|
||||||
mScript.set_gCoeffs(f);
|
mIntrinsic = ScriptIntrinsicConvolve5x5.create(mRS, Element.U8_4(mRS));
|
||||||
mScript.set_gIn(mInPixelsAllocation);
|
mIntrinsic.setCoefficients(f);
|
||||||
mScript.set_gWidth(mWidth);
|
mIntrinsic.setInput(mInPixelsAllocation);
|
||||||
mScript.set_gHeight(mHeight);
|
} else {
|
||||||
|
mScript = new ScriptC_convolve5x5(mRS, res, R.raw.convolve5x5);
|
||||||
|
mScript.set_gCoeffs(f);
|
||||||
|
mScript.set_gIn(mInPixelsAllocation);
|
||||||
|
mScript.set_gWidth(mWidth);
|
||||||
|
mScript.set_gHeight(mHeight);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void runTest() {
|
public void runTest() {
|
||||||
mScript.forEach_root(mOutPixelsAllocation);
|
if (mUseIntrinsic) {
|
||||||
|
mIntrinsic.forEach(mOutPixelsAllocation);
|
||||||
|
} else {
|
||||||
|
mScript.forEach_root(mOutPixelsAllocation);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,63 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2012 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.android.rs.imagejb;
|
||||||
|
|
||||||
|
import java.lang.Math;
|
||||||
|
|
||||||
|
import android.renderscript.Allocation;
|
||||||
|
import android.renderscript.Element;
|
||||||
|
import android.renderscript.RenderScript;
|
||||||
|
import android.renderscript.ScriptIntrinsicLUT;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
public class CrossProcess extends TestBase {
|
||||||
|
private ScriptIntrinsicLUT mIntrinsic;
|
||||||
|
|
||||||
|
public void createTest(android.content.res.Resources res) {
|
||||||
|
mIntrinsic = ScriptIntrinsicLUT.create(mRS, Element.U8_4(mRS));
|
||||||
|
for (int ct=0; ct < 256; ct++) {
|
||||||
|
float f = ((float)ct) / 255.f;
|
||||||
|
|
||||||
|
float r = f;
|
||||||
|
if (r < 0.5f) {
|
||||||
|
r = 4.0f * r * r * r;
|
||||||
|
} else {
|
||||||
|
r = 1.0f - r;
|
||||||
|
r = 1.0f - (4.0f * r * r * r);
|
||||||
|
}
|
||||||
|
mIntrinsic.setRed(ct, (int)(r * 255.f + 0.5f));
|
||||||
|
|
||||||
|
float g = f;
|
||||||
|
if (g < 0.5f) {
|
||||||
|
g = 2.0f * g * g;
|
||||||
|
} else {
|
||||||
|
g = 1.0f - g;
|
||||||
|
g = 1.0f - (2.0f * g * g);
|
||||||
|
}
|
||||||
|
mIntrinsic.setGreen(ct, (int)(g * 255.f + 0.5f));
|
||||||
|
|
||||||
|
float b = f * 0.5f + 0.25f;
|
||||||
|
mIntrinsic.setBlue(ct, (int)(b * 255.f + 0.5f));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void runTest() {
|
||||||
|
mIntrinsic.forEach(mInPixelsAllocation, mOutPixelsAllocation);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,35 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2012 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.android.rs.imagejb;
|
||||||
|
|
||||||
|
import java.lang.Math;
|
||||||
|
|
||||||
|
import android.renderscript.Allocation;
|
||||||
|
|
||||||
|
public class Exposure extends TestBase {
|
||||||
|
private ScriptC_exposure mScript;
|
||||||
|
|
||||||
|
public void createTest(android.content.res.Resources res) {
|
||||||
|
mScript = new ScriptC_exposure(mRS);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void runTest() {
|
||||||
|
mScript.invoke_setBright(50.f);
|
||||||
|
mScript.forEach_exposure(mInPixelsAllocation, mOutPixelsAllocation);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,138 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2012 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.android.rs.imagejb;
|
||||||
|
|
||||||
|
import android.renderscript.Allocation;
|
||||||
|
import android.renderscript.Element;
|
||||||
|
import android.renderscript.Sampler;
|
||||||
|
import android.renderscript.Type;
|
||||||
|
import android.widget.SeekBar;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
public class Fisheye extends TestBase {
|
||||||
|
private ScriptC_fisheye_full mScript_full = null;
|
||||||
|
private ScriptC_fisheye_relaxed mScript_relaxed = null;
|
||||||
|
private ScriptC_fisheye_approx_full mScript_approx_full = null;
|
||||||
|
private ScriptC_fisheye_approx_relaxed mScript_approx_relaxed = null;
|
||||||
|
private final boolean approx;
|
||||||
|
private final boolean relaxed;
|
||||||
|
private float center_x = 0.5f;
|
||||||
|
private float center_y = 0.5f;
|
||||||
|
private float scale = 0.5f;
|
||||||
|
|
||||||
|
public Fisheye(boolean approx, boolean relaxed) {
|
||||||
|
this.approx = approx;
|
||||||
|
this.relaxed = relaxed;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean onBar1Setup(SeekBar b, TextView t) {
|
||||||
|
t.setText("Scale");
|
||||||
|
b.setMax(100);
|
||||||
|
b.setProgress(25);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
public boolean onBar2Setup(SeekBar b, TextView t) {
|
||||||
|
t.setText("Shift center X");
|
||||||
|
b.setMax(100);
|
||||||
|
b.setProgress(50);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
public boolean onBar3Setup(SeekBar b, TextView t) {
|
||||||
|
t.setText("Shift center Y");
|
||||||
|
b.setMax(100);
|
||||||
|
b.setProgress(50);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onBar1Changed(int progress) {
|
||||||
|
scale = progress / 50.0f;
|
||||||
|
do_init();
|
||||||
|
}
|
||||||
|
public void onBar2Changed(int progress) {
|
||||||
|
center_x = progress / 100.0f;
|
||||||
|
do_init();
|
||||||
|
}
|
||||||
|
public void onBar3Changed(int progress) {
|
||||||
|
center_y = progress / 100.0f;
|
||||||
|
do_init();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void do_init() {
|
||||||
|
if (approx) {
|
||||||
|
if (relaxed)
|
||||||
|
mScript_approx_relaxed.invoke_init_filter(
|
||||||
|
mInPixelsAllocation.getType().getX(),
|
||||||
|
mInPixelsAllocation.getType().getY(), center_x,
|
||||||
|
center_y, scale);
|
||||||
|
else
|
||||||
|
mScript_approx_full.invoke_init_filter(
|
||||||
|
mInPixelsAllocation.getType().getX(),
|
||||||
|
mInPixelsAllocation.getType().getY(), center_x,
|
||||||
|
center_y, scale);
|
||||||
|
} else if (relaxed)
|
||||||
|
mScript_relaxed.invoke_init_filter(
|
||||||
|
mInPixelsAllocation.getType().getX(),
|
||||||
|
mInPixelsAllocation.getType().getY(), center_x, center_y,
|
||||||
|
scale);
|
||||||
|
else
|
||||||
|
mScript_full.invoke_init_filter(
|
||||||
|
mInPixelsAllocation.getType().getX(),
|
||||||
|
mInPixelsAllocation.getType().getY(), center_x, center_y,
|
||||||
|
scale);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void createTest(android.content.res.Resources res) {
|
||||||
|
if (approx) {
|
||||||
|
if (relaxed) {
|
||||||
|
mScript_approx_relaxed = new ScriptC_fisheye_approx_relaxed(mRS,
|
||||||
|
res, R.raw.fisheye_approx_relaxed);
|
||||||
|
mScript_approx_relaxed.set_in_alloc(mInPixelsAllocation);
|
||||||
|
mScript_approx_relaxed.set_sampler(Sampler.CLAMP_LINEAR(mRS));
|
||||||
|
} else {
|
||||||
|
mScript_approx_full = new ScriptC_fisheye_approx_full(mRS, res,
|
||||||
|
R.raw.fisheye_approx_full);
|
||||||
|
mScript_approx_full.set_in_alloc(mInPixelsAllocation);
|
||||||
|
mScript_approx_full.set_sampler(Sampler.CLAMP_LINEAR(mRS));
|
||||||
|
}
|
||||||
|
} else if (relaxed) {
|
||||||
|
mScript_relaxed = new ScriptC_fisheye_relaxed(mRS, res,
|
||||||
|
R.raw.fisheye_relaxed);
|
||||||
|
mScript_relaxed.set_in_alloc(mInPixelsAllocation);
|
||||||
|
mScript_relaxed.set_sampler(Sampler.CLAMP_LINEAR(mRS));
|
||||||
|
} else {
|
||||||
|
mScript_full = new ScriptC_fisheye_full(mRS, res,
|
||||||
|
R.raw.fisheye_full);
|
||||||
|
mScript_full.set_in_alloc(mInPixelsAllocation);
|
||||||
|
mScript_full.set_sampler(Sampler.CLAMP_LINEAR(mRS));
|
||||||
|
}
|
||||||
|
do_init();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void runTest() {
|
||||||
|
if (approx) {
|
||||||
|
if (relaxed)
|
||||||
|
mScript_approx_relaxed.forEach_root(mOutPixelsAllocation);
|
||||||
|
else
|
||||||
|
mScript_approx_full.forEach_root(mOutPixelsAllocation);
|
||||||
|
} else if (relaxed)
|
||||||
|
mScript_relaxed.forEach_root(mOutPixelsAllocation);
|
||||||
|
else
|
||||||
|
mScript_full.forEach_root(mOutPixelsAllocation);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,93 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2012 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.android.rs.imagejb;
|
||||||
|
|
||||||
|
import java.lang.Math;
|
||||||
|
|
||||||
|
import android.renderscript.Allocation;
|
||||||
|
import android.renderscript.Element;
|
||||||
|
import android.renderscript.RenderScript;
|
||||||
|
import android.renderscript.ScriptIntrinsicConvolve3x3;
|
||||||
|
import android.renderscript.ScriptIntrinsicColorMatrix;
|
||||||
|
import android.renderscript.Type;
|
||||||
|
import android.renderscript.Matrix4f;
|
||||||
|
import android.renderscript.ScriptGroup;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
public class GroupTest extends TestBase {
|
||||||
|
private ScriptIntrinsicConvolve3x3 mConvolve;
|
||||||
|
private ScriptIntrinsicColorMatrix mMatrix;
|
||||||
|
|
||||||
|
private Allocation mScratchPixelsAllocation1;
|
||||||
|
private ScriptGroup mGroup;
|
||||||
|
|
||||||
|
private int mWidth;
|
||||||
|
private int mHeight;
|
||||||
|
private boolean mUseNative;
|
||||||
|
|
||||||
|
|
||||||
|
public GroupTest(boolean useNative) {
|
||||||
|
mUseNative = useNative;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void createTest(android.content.res.Resources res) {
|
||||||
|
mWidth = mInPixelsAllocation.getType().getX();
|
||||||
|
mHeight = mInPixelsAllocation.getType().getY();
|
||||||
|
|
||||||
|
mConvolve = ScriptIntrinsicConvolve3x3.create(mRS, Element.U8_4(mRS));
|
||||||
|
mMatrix = ScriptIntrinsicColorMatrix.create(mRS, Element.U8_4(mRS));
|
||||||
|
|
||||||
|
float f[] = new float[9];
|
||||||
|
f[0] = 0.f; f[1] = -1.f; f[2] = 0.f;
|
||||||
|
f[3] = -1.f; f[4] = 5.f; f[5] = -1.f;
|
||||||
|
f[6] = 0.f; f[7] = -1.f; f[8] = 0.f;
|
||||||
|
mConvolve.setCoefficients(f);
|
||||||
|
|
||||||
|
Matrix4f m = new Matrix4f();
|
||||||
|
m.set(1, 0, 0.2f);
|
||||||
|
m.set(1, 1, 0.9f);
|
||||||
|
m.set(1, 2, 0.2f);
|
||||||
|
mMatrix.setColorMatrix(m);
|
||||||
|
|
||||||
|
Type.Builder tb = new Type.Builder(mRS, Element.U8_4(mRS));
|
||||||
|
tb.setX(mWidth);
|
||||||
|
tb.setY(mHeight);
|
||||||
|
Type connect = tb.create();
|
||||||
|
|
||||||
|
if (mUseNative) {
|
||||||
|
ScriptGroup.Builder b = new ScriptGroup.Builder(mRS);
|
||||||
|
b.addKernel(mConvolve.getKernelID());
|
||||||
|
b.addKernel(mMatrix.getKernelID());
|
||||||
|
b.addConnection(connect, mConvolve.getKernelID(), mMatrix.getKernelID());
|
||||||
|
mGroup = b.create();
|
||||||
|
} else {
|
||||||
|
mScratchPixelsAllocation1 = Allocation.createTyped(mRS, connect);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void runTest() {
|
||||||
|
mConvolve.setInput(mInPixelsAllocation);
|
||||||
|
if (mUseNative) {
|
||||||
|
mGroup.setOutput(mMatrix.getKernelID(), mOutPixelsAllocation);
|
||||||
|
mGroup.execute();
|
||||||
|
} else {
|
||||||
|
mConvolve.forEach(mScratchPixelsAllocation1);
|
||||||
|
mMatrix.forEach(mScratchPixelsAllocation1, mOutPixelsAllocation);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -23,14 +23,7 @@ import android.os.Message;
|
|||||||
import android.graphics.BitmapFactory;
|
import android.graphics.BitmapFactory;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
import android.renderscript.ScriptC;
|
|
||||||
import android.renderscript.RenderScript;
|
|
||||||
import android.renderscript.Type;
|
|
||||||
import android.renderscript.Allocation;
|
|
||||||
import android.renderscript.Element;
|
|
||||||
import android.renderscript.Script;
|
|
||||||
import android.view.SurfaceView;
|
import android.view.SurfaceView;
|
||||||
import android.view.SurfaceHolder;
|
|
||||||
import android.widget.AdapterView;
|
import android.widget.AdapterView;
|
||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
@ -39,13 +32,14 @@ import android.widget.Spinner;
|
|||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import java.lang.Math;
|
import android.renderscript.ScriptC;
|
||||||
|
import android.renderscript.RenderScript;
|
||||||
|
import android.renderscript.Type;
|
||||||
|
import android.renderscript.Allocation;
|
||||||
|
import android.renderscript.Element;
|
||||||
|
import android.renderscript.Script;
|
||||||
|
|
||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
import android.app.Instrumentation;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.net.Uri;
|
|
||||||
import java.io.BufferedWriter;
|
import java.io.BufferedWriter;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileWriter;
|
import java.io.FileWriter;
|
||||||
@ -54,12 +48,70 @@ import java.io.IOException;
|
|||||||
public class ImageProcessingActivityJB extends Activity
|
public class ImageProcessingActivityJB extends Activity
|
||||||
implements SeekBar.OnSeekBarChangeListener {
|
implements SeekBar.OnSeekBarChangeListener {
|
||||||
private final String TAG = "Img";
|
private final String TAG = "Img";
|
||||||
private final String RESULT_FILE = "image_processing_result.csv";
|
public final String RESULT_FILE = "image_processing_result.csv";
|
||||||
|
|
||||||
|
RenderScript mRS;
|
||||||
|
Allocation mInPixelsAllocation;
|
||||||
|
Allocation mInPixelsAllocation2;
|
||||||
|
Allocation mOutPixelsAllocation;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Define enum type for test names
|
||||||
|
*/
|
||||||
|
public enum TestName {
|
||||||
|
// totally there are 38 test cases
|
||||||
|
LEVELS_VEC3_RELAXED ("Levels Vec3 Relaxed"),
|
||||||
|
LEVELS_VEC4_RELAXED ("Levels Vec4 Relaxed"),
|
||||||
|
LEVELS_VEC3_FULL ("Levels Vec3 Full"),
|
||||||
|
LEVELS_VEC4_FULL ("Levels Vec4 Full"),
|
||||||
|
BLUR_RADIUS_25 ("Blur radius 25"),
|
||||||
|
INTRINSIC_BLUE_RADIUS_25 ("Intrinsic Blur radius 25"),
|
||||||
|
GREYSCALE ("Greyscale"),
|
||||||
|
GRAIN ("Grain"),
|
||||||
|
FISHEYE_FULL ("Fisheye Full"),
|
||||||
|
FISHEYE_RELAXED ("Fisheye Relaxed"),
|
||||||
|
FISHEYE_APPROXIMATE_FULL ("Fisheye Approximate Full"),
|
||||||
|
FISHEYE_APPROXIMATE_RELAXED ("Fisheye Approximate Relaxed"),
|
||||||
|
VIGNETTE_FULL ("Vignette Full"),
|
||||||
|
VIGNETTE_RELAXED ("Vignette Relaxed"),
|
||||||
|
VIGNETTE_APPROXIMATE_FULL ("Vignette Approximate Full"),
|
||||||
|
VIGNETTE_APPROXIMATE_RELAXED ("Vignette Approximate Relaxed"),
|
||||||
|
GROUP_TEST_EMULATED ("Group Test (emulated)"),
|
||||||
|
GROUP_TEST_NATIVE ("Group Test (native)"),
|
||||||
|
CONVOLVE_3X3 ("Convolve 3x3"),
|
||||||
|
INTRINSICS_CONVOLVE_3X3 ("Intrinsics Convolve 3x3"),
|
||||||
|
COLOR_MATRIX ("ColorMatrix"),
|
||||||
|
INTRINSICS_COLOR_MATRIX ("Intrinsics ColorMatrix"),
|
||||||
|
INTRINSICS_COLOR_MATRIX_GREY ("Intrinsics ColorMatrix Grey"),
|
||||||
|
COPY ("Copy"),
|
||||||
|
CROSS_PROCESS_USING_LUT ("CrossProcess (using LUT)"),
|
||||||
|
CONVOLVE_5X5 ("Convolve 5x5"),
|
||||||
|
INTRINSICS_CONVOLVE_5X5 ("Intrinsics Convolve 5x5"),
|
||||||
|
MANDELBROT ("Mandelbrot"),
|
||||||
|
INTRINSICS_BLEND ("Intrinsics Blend"),
|
||||||
|
VIBRANCE ("Vibrance"),
|
||||||
|
BW_FILTER ("BW Filter"),
|
||||||
|
SHADOWS ("Shadows"),
|
||||||
|
CONTRAST ("Contrast"),
|
||||||
|
EXPOSURE ("Exposure"),
|
||||||
|
WHITE_BALANCE ("White Balance");
|
||||||
|
|
||||||
|
|
||||||
|
private final String name;
|
||||||
|
|
||||||
|
private TestName(String s) {
|
||||||
|
name = s;
|
||||||
|
}
|
||||||
|
|
||||||
|
// return quoted string as displayed test name
|
||||||
|
public String toString() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Bitmap mBitmapIn;
|
Bitmap mBitmapIn;
|
||||||
Bitmap mBitmapIn2;
|
Bitmap mBitmapIn2;
|
||||||
Bitmap mBitmapOut;
|
Bitmap mBitmapOut;
|
||||||
String mTestNames[];
|
|
||||||
|
|
||||||
private Spinner mSpinner;
|
private Spinner mSpinner;
|
||||||
private SeekBar mBar1;
|
private SeekBar mBar1;
|
||||||
@ -91,12 +143,15 @@ public class ImageProcessingActivityJB extends Activity
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Handler mHandler = new Handler() {
|
private Handler mHandler = new Handler() {
|
||||||
|
// Allow the filter to complete without blocking the UI
|
||||||
|
// thread. When the message arrives that the op is complete
|
||||||
|
// we will either mark completion or start a new filter if
|
||||||
|
// more work is ready. Either way, display the result.
|
||||||
@Override
|
@Override
|
||||||
public void handleMessage(Message msg) {
|
public void handleMessage(Message msg) {
|
||||||
mTest.updateBitmap(mBitmapOut);
|
mTest.updateBitmap(mBitmapOut);
|
||||||
mDisplayView.invalidate();
|
mDisplayView.invalidate();
|
||||||
|
|
||||||
android.util.Log.v("Img", "mRunCount hdl " + mRunCount);
|
|
||||||
boolean doTest = false;
|
boolean doTest = false;
|
||||||
synchronized(this) {
|
synchronized(this) {
|
||||||
if (mRunCount > 0) {
|
if (mRunCount > 0) {
|
||||||
@ -175,56 +230,119 @@ public class ImageProcessingActivityJB extends Activity
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void changeTest(int testID) {
|
void changeTest(TestName testName) {
|
||||||
if (mTest != null) {
|
if (mTest != null) {
|
||||||
mTest.destroy();
|
mTest.destroy();
|
||||||
}
|
}
|
||||||
switch(testID) {
|
switch(testName) {
|
||||||
case 0:
|
case LEVELS_VEC3_RELAXED:
|
||||||
mTest = new LevelsV4(false, false);
|
mTest = new LevelsV4(false, false);
|
||||||
break;
|
break;
|
||||||
case 1:
|
case LEVELS_VEC4_RELAXED:
|
||||||
mTest = new LevelsV4(false, true);
|
mTest = new LevelsV4(false, true);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case LEVELS_VEC3_FULL:
|
||||||
mTest = new LevelsV4(true, false);
|
mTest = new LevelsV4(true, false);
|
||||||
break;
|
break;
|
||||||
case 3:
|
case LEVELS_VEC4_FULL:
|
||||||
mTest = new LevelsV4(true, true);
|
mTest = new LevelsV4(true, true);
|
||||||
break;
|
break;
|
||||||
case 4:
|
case BLUR_RADIUS_25:
|
||||||
mTest = new Blur25();
|
mTest = new Blur25(false);
|
||||||
break;
|
break;
|
||||||
case 5:
|
case INTRINSIC_BLUE_RADIUS_25:
|
||||||
|
mTest = new Blur25(true);
|
||||||
|
break;
|
||||||
|
case GREYSCALE:
|
||||||
mTest = new Greyscale();
|
mTest = new Greyscale();
|
||||||
break;
|
break;
|
||||||
case 6:
|
case GRAIN:
|
||||||
mTest = new Grain();
|
mTest = new Grain();
|
||||||
break;
|
break;
|
||||||
case 7:
|
case FISHEYE_FULL:
|
||||||
mTest = new Vignette(false);
|
mTest = new Fisheye(false, false);
|
||||||
break;
|
break;
|
||||||
case 8:
|
case FISHEYE_RELAXED:
|
||||||
mTest = new Vignette(true);
|
mTest = new Fisheye(false, true);
|
||||||
break;
|
break;
|
||||||
case 9:
|
case FISHEYE_APPROXIMATE_FULL:
|
||||||
mTest = new Convolve3x3();
|
mTest = new Fisheye(true, false);
|
||||||
break;
|
break;
|
||||||
case 10:
|
case FISHEYE_APPROXIMATE_RELAXED:
|
||||||
mTest = new ColorMatrix(false);
|
mTest = new Fisheye(true, true);
|
||||||
break;
|
break;
|
||||||
case 11:
|
case VIGNETTE_FULL:
|
||||||
|
mTest = new Vignette(false, false);
|
||||||
|
break;
|
||||||
|
case VIGNETTE_RELAXED:
|
||||||
|
mTest = new Vignette(false, true);
|
||||||
|
break;
|
||||||
|
case VIGNETTE_APPROXIMATE_FULL:
|
||||||
|
mTest = new Vignette(true, false);
|
||||||
|
break;
|
||||||
|
case VIGNETTE_APPROXIMATE_RELAXED:
|
||||||
|
mTest = new Vignette(true, true);
|
||||||
|
break;
|
||||||
|
case GROUP_TEST_EMULATED:
|
||||||
|
mTest = new GroupTest(false);
|
||||||
|
break;
|
||||||
|
case GROUP_TEST_NATIVE:
|
||||||
|
mTest = new GroupTest(true);
|
||||||
|
break;
|
||||||
|
case CONVOLVE_3X3:
|
||||||
|
mTest = new Convolve3x3(false);
|
||||||
|
break;
|
||||||
|
case INTRINSICS_CONVOLVE_3X3:
|
||||||
|
mTest = new Convolve3x3(true);
|
||||||
|
break;
|
||||||
|
case COLOR_MATRIX:
|
||||||
|
mTest = new ColorMatrix(false, false);
|
||||||
|
break;
|
||||||
|
case INTRINSICS_COLOR_MATRIX:
|
||||||
|
mTest = new ColorMatrix(true, false);
|
||||||
|
break;
|
||||||
|
case INTRINSICS_COLOR_MATRIX_GREY:
|
||||||
|
mTest = new ColorMatrix(true, true);
|
||||||
|
break;
|
||||||
|
case COPY:
|
||||||
mTest = new Copy();
|
mTest = new Copy();
|
||||||
break;
|
break;
|
||||||
case 12:
|
case CROSS_PROCESS_USING_LUT:
|
||||||
mTest = new Convolve5x5();
|
mTest = new CrossProcess();
|
||||||
break;
|
break;
|
||||||
case 13:
|
case CONVOLVE_5X5:
|
||||||
|
mTest = new Convolve5x5(false);
|
||||||
|
break;
|
||||||
|
case INTRINSICS_CONVOLVE_5X5:
|
||||||
|
mTest = new Convolve5x5(true);
|
||||||
|
break;
|
||||||
|
case MANDELBROT:
|
||||||
mTest = new Mandelbrot();
|
mTest = new Mandelbrot();
|
||||||
break;
|
break;
|
||||||
|
case INTRINSICS_BLEND:
|
||||||
|
mTest = new Blend();
|
||||||
|
break;
|
||||||
|
case VIBRANCE:
|
||||||
|
mTest = new Vibrance();
|
||||||
|
break;
|
||||||
|
case BW_FILTER:
|
||||||
|
mTest = new BWFilter();
|
||||||
|
break;
|
||||||
|
case SHADOWS:
|
||||||
|
mTest = new Shadows();
|
||||||
|
break;
|
||||||
|
case CONTRAST:
|
||||||
|
mTest = new Contrast();
|
||||||
|
break;
|
||||||
|
case EXPOSURE:
|
||||||
|
mTest = new Exposure();
|
||||||
|
break;
|
||||||
|
case WHITE_BALANCE:
|
||||||
|
mTest = new WhiteBalance();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
mTest.createBaseTest(this, mBitmapIn, mBitmapIn2);
|
mTest.createBaseTest(this, mBitmapIn, mBitmapIn2, mBitmapOut);
|
||||||
setupBars();
|
setupBars();
|
||||||
|
|
||||||
mTest.runTest();
|
mTest.runTest();
|
||||||
@ -233,30 +351,14 @@ public class ImageProcessingActivityJB extends Activity
|
|||||||
}
|
}
|
||||||
|
|
||||||
void setupTests() {
|
void setupTests() {
|
||||||
mTestNames = new String[14];
|
mTestSpinner.setAdapter(new ArrayAdapter<TestName>(
|
||||||
mTestNames[0] = "Levels Vec3 Relaxed";
|
this, R.layout.spinner_layout, TestName.values()));
|
||||||
mTestNames[1] = "Levels Vec4 Relaxed";
|
|
||||||
mTestNames[2] = "Levels Vec3 Full";
|
|
||||||
mTestNames[3] = "Levels Vec4 Full";
|
|
||||||
mTestNames[4] = "Blur radius 25";
|
|
||||||
mTestNames[5] = "Greyscale";
|
|
||||||
mTestNames[6] = "Grain";
|
|
||||||
mTestNames[7] = "Vignette Full";
|
|
||||||
mTestNames[8] = "Vignette Relaxed";
|
|
||||||
mTestNames[9] = "Convolve 3x3";
|
|
||||||
mTestNames[10] = "ColorMatrix";
|
|
||||||
mTestNames[11] = "Copy";
|
|
||||||
mTestNames[12] = "Convolve 5x5";
|
|
||||||
mTestNames[13] = "Mandelbrot";
|
|
||||||
|
|
||||||
mTestSpinner.setAdapter(new ArrayAdapter<String>(
|
|
||||||
this, R.layout.spinner_layout, mTestNames));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private AdapterView.OnItemSelectedListener mTestSpinnerListener =
|
private AdapterView.OnItemSelectedListener mTestSpinnerListener =
|
||||||
new AdapterView.OnItemSelectedListener() {
|
new AdapterView.OnItemSelectedListener() {
|
||||||
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
|
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
|
||||||
changeTest(pos);
|
changeTest(TestName.values()[pos]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onNothingSelected(AdapterView parent) {
|
public void onNothingSelected(AdapterView parent) {
|
||||||
@ -305,8 +407,15 @@ public class ImageProcessingActivityJB extends Activity
|
|||||||
mBenchmarkResult = (TextView) findViewById(R.id.benchmarkText);
|
mBenchmarkResult = (TextView) findViewById(R.id.benchmarkText);
|
||||||
mBenchmarkResult.setText("Result: not run");
|
mBenchmarkResult.setText("Result: not run");
|
||||||
|
|
||||||
|
|
||||||
|
mRS = RenderScript.create(this);
|
||||||
|
mInPixelsAllocation = Allocation.createFromBitmap(mRS, mBitmapIn);
|
||||||
|
mInPixelsAllocation2 = Allocation.createFromBitmap(mRS, mBitmapIn2);
|
||||||
|
mOutPixelsAllocation = Allocation.createFromBitmap(mRS, mBitmapOut);
|
||||||
|
|
||||||
|
|
||||||
setupTests();
|
setupTests();
|
||||||
changeTest(0);
|
changeTest(TestName.LEVELS_VEC3_RELAXED);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -337,10 +446,10 @@ public class ImageProcessingActivityJB extends Activity
|
|||||||
try {
|
try {
|
||||||
BufferedWriter rsWriter = new BufferedWriter(new FileWriter(resultFile));
|
BufferedWriter rsWriter = new BufferedWriter(new FileWriter(resultFile));
|
||||||
Log.v(TAG, "Saved results in: " + resultFile.getAbsolutePath());
|
Log.v(TAG, "Saved results in: " + resultFile.getAbsolutePath());
|
||||||
for (int i = 0; i < mTestNames.length; i++ ) {
|
for (TestName tn: TestName.values()) {
|
||||||
changeTest(i);
|
changeTest(tn);
|
||||||
float t = getBenchmark();
|
float t = getBenchmark();
|
||||||
String s = new String("" + mTestNames[i] + ", " + t);
|
String s = new String("" + tn.toString() + ", " + t);
|
||||||
rsWriter.write(s + "\n");
|
rsWriter.write(s + "\n");
|
||||||
Log.v(TAG, "Test " + s + "ms\n");
|
Log.v(TAG, "Test " + s + "ms\n");
|
||||||
}
|
}
|
||||||
@ -348,7 +457,7 @@ public class ImageProcessingActivityJB extends Activity
|
|||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Log.v(TAG, "Unable to write result file " + e.getMessage());
|
Log.v(TAG, "Unable to write result file " + e.getMessage());
|
||||||
}
|
}
|
||||||
changeTest(0);
|
changeTest(TestName.LEVELS_VEC3_RELAXED);
|
||||||
}
|
}
|
||||||
|
|
||||||
// For benchmark test
|
// For benchmark test
|
||||||
@ -365,7 +474,6 @@ public class ImageProcessingActivityJB extends Activity
|
|||||||
mTest.finish();
|
mTest.finish();
|
||||||
} while (t > java.lang.System.currentTimeMillis());
|
} while (t > java.lang.System.currentTimeMillis());
|
||||||
|
|
||||||
|
|
||||||
//Log.v(TAG, "Benchmarking");
|
//Log.v(TAG, "Benchmarking");
|
||||||
int ct = 0;
|
int ct = 0;
|
||||||
t = java.lang.System.currentTimeMillis();
|
t = java.lang.System.currentTimeMillis();
|
||||||
|
@ -0,0 +1,35 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2012 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.android.rs.imagejb;
|
||||||
|
|
||||||
|
import java.lang.Math;
|
||||||
|
|
||||||
|
import android.renderscript.Allocation;
|
||||||
|
|
||||||
|
public class Shadows extends TestBase {
|
||||||
|
private ScriptC_shadows mScript;
|
||||||
|
|
||||||
|
public void createTest(android.content.res.Resources res) {
|
||||||
|
mScript = new ScriptC_shadows(mRS);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void runTest() {
|
||||||
|
mScript.invoke_prepareShadows(50.f);
|
||||||
|
mScript.forEach_shadowsKernel(mInPixelsAllocation, mOutPixelsAllocation);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -106,26 +106,20 @@ public class TestBase {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void createBaseTest(ImageProcessingActivityJB ipact, Bitmap b, Bitmap b2) {
|
public final void createBaseTest(ImageProcessingActivityJB ipact, Bitmap b, Bitmap b2, Bitmap outb) {
|
||||||
act = ipact;
|
act = ipact;
|
||||||
mRS = RenderScript.create(act);
|
mRS = ipact.mRS;
|
||||||
mRS.setMessageHandler(new MessageProcessor(act));
|
mRS.setMessageHandler(new MessageProcessor(act));
|
||||||
mMessageScript = new ScriptC_msg(mRS);
|
|
||||||
mInPixelsAllocation = Allocation.createFromBitmap(mRS, b,
|
mInPixelsAllocation = ipact.mInPixelsAllocation;
|
||||||
Allocation.MipmapControl.MIPMAP_NONE,
|
mInPixelsAllocation2 = ipact.mInPixelsAllocation2;
|
||||||
Allocation.USAGE_SCRIPT);
|
mOutPixelsAllocation = ipact.mOutPixelsAllocation;
|
||||||
mInPixelsAllocation2 = Allocation.createFromBitmap(mRS, b2,
|
|
||||||
Allocation.MipmapControl.MIPMAP_NONE,
|
|
||||||
Allocation.USAGE_SCRIPT);
|
|
||||||
mOutPixelsAllocation = Allocation.createFromBitmap(mRS, b,
|
|
||||||
Allocation.MipmapControl.MIPMAP_NONE,
|
|
||||||
Allocation.USAGE_SCRIPT);
|
|
||||||
createTest(act.getResources());
|
createTest(act.getResources());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Must override
|
// Must override
|
||||||
public void createTest(android.content.res.Resources res) {
|
public void createTest(android.content.res.Resources res) {
|
||||||
android.util.Log.e("img", "implement createTest");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Must override
|
// Must override
|
||||||
@ -133,7 +127,6 @@ public class TestBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
final public void runTestSendMessage() {
|
final public void runTestSendMessage() {
|
||||||
android.util.Log.v("Img", "run");
|
|
||||||
runTest();
|
runTest();
|
||||||
mMessageScript.invoke_sendMsg();
|
mMessageScript.invoke_sendMsg();
|
||||||
}
|
}
|
||||||
@ -143,8 +136,7 @@ public class TestBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void destroy() {
|
public void destroy() {
|
||||||
mRS.destroy();
|
mRS.setMessageHandler(null);
|
||||||
mRS = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateBitmap(Bitmap b) {
|
public void updateBitmap(Bitmap b) {
|
||||||
|
@ -0,0 +1,36 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2012 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.android.rs.imagejb;
|
||||||
|
|
||||||
|
import java.lang.Math;
|
||||||
|
|
||||||
|
import android.renderscript.Allocation;
|
||||||
|
|
||||||
|
public class Vibrance extends TestBase {
|
||||||
|
private ScriptC_vibrance mScript;
|
||||||
|
|
||||||
|
public void createTest(android.content.res.Resources res) {
|
||||||
|
mScript = new ScriptC_vibrance(mRS);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void runTest() {
|
||||||
|
mScript.set_vibrance(50.f);
|
||||||
|
mScript.invoke_prepareVibrance();
|
||||||
|
mScript.forEach_vibranceKernel(mInPixelsAllocation, mOutPixelsAllocation);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -26,6 +26,9 @@ import android.widget.TextView;
|
|||||||
public class Vignette extends TestBase {
|
public class Vignette extends TestBase {
|
||||||
private ScriptC_vignette_full mScript_full = null;
|
private ScriptC_vignette_full mScript_full = null;
|
||||||
private ScriptC_vignette_relaxed mScript_relaxed = null;
|
private ScriptC_vignette_relaxed mScript_relaxed = null;
|
||||||
|
private ScriptC_vignette_approx_full mScript_approx_full = null;
|
||||||
|
private ScriptC_vignette_approx_relaxed mScript_approx_relaxed = null;
|
||||||
|
private final boolean approx;
|
||||||
private final boolean relaxed;
|
private final boolean relaxed;
|
||||||
private float center_x = 0.5f;
|
private float center_x = 0.5f;
|
||||||
private float center_y = 0.5f;
|
private float center_y = 0.5f;
|
||||||
@ -33,7 +36,8 @@ public class Vignette extends TestBase {
|
|||||||
private float shade = 0.5f;
|
private float shade = 0.5f;
|
||||||
private float slope = 20.0f;
|
private float slope = 20.0f;
|
||||||
|
|
||||||
public Vignette(boolean relaxed) {
|
public Vignette(boolean approx, boolean relaxed) {
|
||||||
|
this.approx = approx;
|
||||||
this.relaxed = relaxed;
|
this.relaxed = relaxed;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -90,7 +94,18 @@ public class Vignette extends TestBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void do_init() {
|
private void do_init() {
|
||||||
if (relaxed)
|
if (approx) {
|
||||||
|
if (relaxed)
|
||||||
|
mScript_approx_relaxed.invoke_init_vignette(
|
||||||
|
mInPixelsAllocation.getType().getX(),
|
||||||
|
mInPixelsAllocation.getType().getY(), center_x,
|
||||||
|
center_y, scale, shade, slope);
|
||||||
|
else
|
||||||
|
mScript_approx_full.invoke_init_vignette(
|
||||||
|
mInPixelsAllocation.getType().getX(),
|
||||||
|
mInPixelsAllocation.getType().getY(), center_x,
|
||||||
|
center_y, scale, shade, slope);
|
||||||
|
} else if (relaxed)
|
||||||
mScript_relaxed.invoke_init_vignette(
|
mScript_relaxed.invoke_init_vignette(
|
||||||
mInPixelsAllocation.getType().getX(),
|
mInPixelsAllocation.getType().getX(),
|
||||||
mInPixelsAllocation.getType().getY(), center_x, center_y,
|
mInPixelsAllocation.getType().getY(), center_x, center_y,
|
||||||
@ -103,7 +118,14 @@ public class Vignette extends TestBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void createTest(android.content.res.Resources res) {
|
public void createTest(android.content.res.Resources res) {
|
||||||
if (relaxed)
|
if (approx) {
|
||||||
|
if (relaxed)
|
||||||
|
mScript_approx_relaxed = new ScriptC_vignette_approx_relaxed(
|
||||||
|
mRS, res, R.raw.vignette_approx_relaxed);
|
||||||
|
else
|
||||||
|
mScript_approx_full = new ScriptC_vignette_approx_full(
|
||||||
|
mRS, res, R.raw.vignette_approx_full);
|
||||||
|
} else if (relaxed)
|
||||||
mScript_relaxed = new ScriptC_vignette_relaxed(mRS, res,
|
mScript_relaxed = new ScriptC_vignette_relaxed(mRS, res,
|
||||||
R.raw.vignette_relaxed);
|
R.raw.vignette_relaxed);
|
||||||
else
|
else
|
||||||
@ -113,7 +135,14 @@ public class Vignette extends TestBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void runTest() {
|
public void runTest() {
|
||||||
if (relaxed)
|
if (approx) {
|
||||||
|
if (relaxed)
|
||||||
|
mScript_approx_relaxed.forEach_root(mInPixelsAllocation,
|
||||||
|
mOutPixelsAllocation);
|
||||||
|
else
|
||||||
|
mScript_approx_full.forEach_root(mInPixelsAllocation,
|
||||||
|
mOutPixelsAllocation);
|
||||||
|
} else if (relaxed)
|
||||||
mScript_relaxed.forEach_root(mInPixelsAllocation,
|
mScript_relaxed.forEach_root(mInPixelsAllocation,
|
||||||
mOutPixelsAllocation);
|
mOutPixelsAllocation);
|
||||||
else
|
else
|
||||||
|
@ -0,0 +1,38 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2012 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.android.rs.imagejb;
|
||||||
|
|
||||||
|
import java.lang.Math;
|
||||||
|
|
||||||
|
import android.renderscript.Allocation;
|
||||||
|
|
||||||
|
public class WhiteBalance extends TestBase {
|
||||||
|
private ScriptC_wbalance mScript;
|
||||||
|
|
||||||
|
public void createTest(android.content.res.Resources res) {
|
||||||
|
mScript = new ScriptC_wbalance(mRS);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void runTest() {
|
||||||
|
mScript.set_histogramSource(mInPixelsAllocation);
|
||||||
|
mScript.set_histogramWidth(mInPixelsAllocation.getType().getX());
|
||||||
|
mScript.set_histogramHeight(mInPixelsAllocation.getType().getY());
|
||||||
|
mScript.invoke_prepareWhiteBalance();
|
||||||
|
mScript.forEach_whiteBalanceKernel(mInPixelsAllocation, mOutPixelsAllocation);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,23 @@
|
|||||||
|
// Copyright (C) 2011 The Android Open Source Project
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
#include "ip.rsh"
|
||||||
|
|
||||||
|
uchar alpha = 0x0;
|
||||||
|
|
||||||
|
void setImageAlpha(uchar4 *v_out, uint32_t x, uint32_t y) {
|
||||||
|
v_out->rgba = convert_uchar4((convert_uint4(v_out->rgba) * alpha) >> (uint4)8);
|
||||||
|
v_out->a = alpha;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,52 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2012 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "ip.rsh"
|
||||||
|
//#pragma rs_fp_relaxed
|
||||||
|
|
||||||
|
static float sr = 0.f;
|
||||||
|
static float sg = 0.f;
|
||||||
|
static float sb = 0.f;
|
||||||
|
|
||||||
|
void prepareBwFilter(uint32_t rw, uint32_t gw, uint32_t bw) {
|
||||||
|
|
||||||
|
sr = rw;
|
||||||
|
sg = gw;
|
||||||
|
sb = bw;
|
||||||
|
|
||||||
|
float imageMin = min(sg,sb);
|
||||||
|
imageMin = fmin(sr,imageMin);
|
||||||
|
float imageMax = max(sg,sb);
|
||||||
|
imageMax = fmax(sr,imageMax);
|
||||||
|
float avg = (imageMin + imageMax)/2;
|
||||||
|
sb /= avg;
|
||||||
|
sg /= avg;
|
||||||
|
sr /= avg;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void bwFilterKernel(const uchar4 *in, uchar4 *out) {
|
||||||
|
float r = in->r * sr;
|
||||||
|
float g = in->g * sg;
|
||||||
|
float b = in->b * sb;
|
||||||
|
float localMin, localMax, avg;
|
||||||
|
localMin = fmin(g,b);
|
||||||
|
localMin = fmin(r,localMin);
|
||||||
|
localMax = fmax(g,b);
|
||||||
|
localMax = fmax(r,localMax);
|
||||||
|
avg = (localMin+localMax) * 0.5f;
|
||||||
|
out->r = out->g = out->b = rsClamp(avg, 0, 255);
|
||||||
|
}
|
@ -14,10 +14,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#pragma version(1)
|
#include "ip.rsh"
|
||||||
#pragma rs java_package_name(com.android.rs.imagejb)
|
|
||||||
#pragma rs_fp_relaxed
|
|
||||||
|
|
||||||
|
|
||||||
static rs_matrix4x4 Mat;
|
static rs_matrix4x4 Mat;
|
||||||
|
|
||||||
@ -29,10 +26,10 @@ void setMatrix(rs_matrix4x4 m) {
|
|||||||
Mat = m;
|
Mat = m;
|
||||||
}
|
}
|
||||||
|
|
||||||
void root(const uchar4 *in, uchar4 *out) {
|
uchar4 __attribute__((kernel)) root(uchar4 in) {
|
||||||
float4 f = convert_float4(*in);
|
float4 f = convert_float4(in);
|
||||||
f = rsMatrixMultiply(&Mat, f);
|
f = rsMatrixMultiply(&Mat, f);
|
||||||
f = clamp(f, 0.f, 255.f);
|
f = clamp(f, 0.f, 255.f);
|
||||||
*out = convert_uchar4(f);
|
return convert_uchar4(f);
|
||||||
}
|
}
|
||||||
|
|
@ -0,0 +1,37 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2012 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "ip.rsh"
|
||||||
|
|
||||||
|
static float brightM = 0.f;
|
||||||
|
static float brightC = 0.f;
|
||||||
|
|
||||||
|
void setBright(float v) {
|
||||||
|
brightM = pow(2.f, v / 100.f);
|
||||||
|
brightC = 127.f - brightM * 127.f;
|
||||||
|
}
|
||||||
|
|
||||||
|
void contrast(const uchar4 *in, uchar4 *out)
|
||||||
|
{
|
||||||
|
#if 0
|
||||||
|
out->r = rsClamp((int)(brightM * in->r + brightC), 0, 255);
|
||||||
|
out->g = rsClamp((int)(brightM * in->g + brightC), 0, 255);
|
||||||
|
out->b = rsClamp((int)(brightM * in->b + brightC), 0, 255);
|
||||||
|
#else
|
||||||
|
float3 v = convert_float3(in->rgb) * brightM + brightC;
|
||||||
|
out->rgb = convert_uchar3(clamp(v, 0.f, 255.f));
|
||||||
|
#endif
|
||||||
|
}
|
@ -14,9 +14,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#pragma version(1)
|
#include "ip.rsh"
|
||||||
#pragma rs java_package_name(com.android.rs.imagejb)
|
|
||||||
#pragma rs_fp_relaxed
|
|
||||||
|
|
||||||
int32_t gWidth;
|
int32_t gWidth;
|
||||||
int32_t gHeight;
|
int32_t gHeight;
|
||||||
@ -24,25 +22,21 @@ rs_allocation gIn;
|
|||||||
|
|
||||||
float gCoeffs[9];
|
float gCoeffs[9];
|
||||||
|
|
||||||
static inline uchar4 GetElementAt_uchar4(rs_allocation a, uint32_t x, uint32_t y) {
|
uchar4 __attribute__((kernel)) root(uint32_t x, uint32_t y) {
|
||||||
return ((uchar4 *)rsGetElementAt(a, x, y))[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
void root(uchar4 *out, uint32_t x, uint32_t y) {
|
|
||||||
uint32_t x1 = min((int32_t)x+1, gWidth-1);
|
uint32_t x1 = min((int32_t)x+1, gWidth-1);
|
||||||
uint32_t x2 = max((int32_t)x-1, 0);
|
uint32_t x2 = max((int32_t)x-1, 0);
|
||||||
uint32_t y1 = min((int32_t)y+1, gHeight-1);
|
uint32_t y1 = min((int32_t)y+1, gHeight-1);
|
||||||
uint32_t y2 = max((int32_t)y-1, 0);
|
uint32_t y2 = max((int32_t)y-1, 0);
|
||||||
|
|
||||||
float4 p00 = convert_float4(GetElementAt_uchar4(gIn, x1, y1));
|
float4 p00 = convert_float4(rsGetElementAt_uchar4(gIn, x1, y1));
|
||||||
float4 p01 = convert_float4(GetElementAt_uchar4(gIn, x, y1));
|
float4 p01 = convert_float4(rsGetElementAt_uchar4(gIn, x, y1));
|
||||||
float4 p02 = convert_float4(GetElementAt_uchar4(gIn, x2, y1));
|
float4 p02 = convert_float4(rsGetElementAt_uchar4(gIn, x2, y1));
|
||||||
float4 p10 = convert_float4(GetElementAt_uchar4(gIn, x1, y));
|
float4 p10 = convert_float4(rsGetElementAt_uchar4(gIn, x1, y));
|
||||||
float4 p11 = convert_float4(GetElementAt_uchar4(gIn, x, y));
|
float4 p11 = convert_float4(rsGetElementAt_uchar4(gIn, x, y));
|
||||||
float4 p12 = convert_float4(GetElementAt_uchar4(gIn, x2, y));
|
float4 p12 = convert_float4(rsGetElementAt_uchar4(gIn, x2, y));
|
||||||
float4 p20 = convert_float4(GetElementAt_uchar4(gIn, x1, y2));
|
float4 p20 = convert_float4(rsGetElementAt_uchar4(gIn, x1, y2));
|
||||||
float4 p21 = convert_float4(GetElementAt_uchar4(gIn, x, y2));
|
float4 p21 = convert_float4(rsGetElementAt_uchar4(gIn, x, y2));
|
||||||
float4 p22 = convert_float4(GetElementAt_uchar4(gIn, x2, y2));
|
float4 p22 = convert_float4(rsGetElementAt_uchar4(gIn, x2, y2));
|
||||||
p00 *= gCoeffs[0];
|
p00 *= gCoeffs[0];
|
||||||
p01 *= gCoeffs[1];
|
p01 *= gCoeffs[1];
|
||||||
p02 *= gCoeffs[2];
|
p02 *= gCoeffs[2];
|
||||||
@ -65,7 +59,7 @@ void root(uchar4 *out, uint32_t x, uint32_t y) {
|
|||||||
p20 += p02;
|
p20 += p02;
|
||||||
|
|
||||||
p20 = clamp(p20, 0.f, 255.f);
|
p20 = clamp(p20, 0.f, 255.f);
|
||||||
*out = convert_uchar4(p20);
|
return convert_uchar4(p20);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -0,0 +1,72 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2012 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "ip.rsh"
|
||||||
|
|
||||||
|
int32_t gWidth;
|
||||||
|
int32_t gHeight;
|
||||||
|
rs_allocation gIn;
|
||||||
|
|
||||||
|
float gCoeffs[25];
|
||||||
|
|
||||||
|
uchar4 __attribute__((kernel)) root(uint32_t x, uint32_t y) {
|
||||||
|
uint32_t x0 = max((int32_t)x-2, 0);
|
||||||
|
uint32_t x1 = max((int32_t)x-1, 0);
|
||||||
|
uint32_t x2 = x;
|
||||||
|
uint32_t x3 = min((int32_t)x+1, gWidth-1);
|
||||||
|
uint32_t x4 = min((int32_t)x+2, gWidth-1);
|
||||||
|
|
||||||
|
uint32_t y0 = max((int32_t)y-2, 0);
|
||||||
|
uint32_t y1 = max((int32_t)y-1, 0);
|
||||||
|
uint32_t y2 = y;
|
||||||
|
uint32_t y3 = min((int32_t)y+1, gHeight-1);
|
||||||
|
uint32_t y4 = min((int32_t)y+2, gHeight-1);
|
||||||
|
|
||||||
|
float4 p0 = convert_float4(rsGetElementAt_uchar4(gIn, x0, y0)) * gCoeffs[0]
|
||||||
|
+ convert_float4(rsGetElementAt_uchar4(gIn, x1, y0)) * gCoeffs[1]
|
||||||
|
+ convert_float4(rsGetElementAt_uchar4(gIn, x2, y0)) * gCoeffs[2]
|
||||||
|
+ convert_float4(rsGetElementAt_uchar4(gIn, x3, y0)) * gCoeffs[3]
|
||||||
|
+ convert_float4(rsGetElementAt_uchar4(gIn, x4, y0)) * gCoeffs[4];
|
||||||
|
|
||||||
|
float4 p1 = convert_float4(rsGetElementAt_uchar4(gIn, x0, y1)) * gCoeffs[5]
|
||||||
|
+ convert_float4(rsGetElementAt_uchar4(gIn, x1, y1)) * gCoeffs[6]
|
||||||
|
+ convert_float4(rsGetElementAt_uchar4(gIn, x2, y1)) * gCoeffs[7]
|
||||||
|
+ convert_float4(rsGetElementAt_uchar4(gIn, x3, y1)) * gCoeffs[8]
|
||||||
|
+ convert_float4(rsGetElementAt_uchar4(gIn, x4, y1)) * gCoeffs[9];
|
||||||
|
|
||||||
|
float4 p2 = convert_float4(rsGetElementAt_uchar4(gIn, x0, y2)) * gCoeffs[10]
|
||||||
|
+ convert_float4(rsGetElementAt_uchar4(gIn, x1, y2)) * gCoeffs[11]
|
||||||
|
+ convert_float4(rsGetElementAt_uchar4(gIn, x2, y2)) * gCoeffs[12]
|
||||||
|
+ convert_float4(rsGetElementAt_uchar4(gIn, x3, y2)) * gCoeffs[13]
|
||||||
|
+ convert_float4(rsGetElementAt_uchar4(gIn, x4, y2)) * gCoeffs[14];
|
||||||
|
|
||||||
|
float4 p3 = convert_float4(rsGetElementAt_uchar4(gIn, x0, y3)) * gCoeffs[15]
|
||||||
|
+ convert_float4(rsGetElementAt_uchar4(gIn, x1, y3)) * gCoeffs[16]
|
||||||
|
+ convert_float4(rsGetElementAt_uchar4(gIn, x2, y3)) * gCoeffs[17]
|
||||||
|
+ convert_float4(rsGetElementAt_uchar4(gIn, x3, y3)) * gCoeffs[18]
|
||||||
|
+ convert_float4(rsGetElementAt_uchar4(gIn, x4, y3)) * gCoeffs[19];
|
||||||
|
|
||||||
|
float4 p4 = convert_float4(rsGetElementAt_uchar4(gIn, x0, y4)) * gCoeffs[20]
|
||||||
|
+ convert_float4(rsGetElementAt_uchar4(gIn, x1, y4)) * gCoeffs[21]
|
||||||
|
+ convert_float4(rsGetElementAt_uchar4(gIn, x2, y4)) * gCoeffs[22]
|
||||||
|
+ convert_float4(rsGetElementAt_uchar4(gIn, x3, y4)) * gCoeffs[23]
|
||||||
|
+ convert_float4(rsGetElementAt_uchar4(gIn, x4, y4)) * gCoeffs[24];
|
||||||
|
|
||||||
|
p0 = clamp(p0 + p1 + p2 + p3 + p4, 0.f, 255.f);
|
||||||
|
return convert_uchar4(p0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -1,78 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2012 The Android Open Source Project
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma version(1)
|
|
||||||
#pragma rs java_package_name(com.android.rs.imagejb)
|
|
||||||
#pragma rs_fp_relaxed
|
|
||||||
|
|
||||||
int32_t gWidth;
|
|
||||||
int32_t gHeight;
|
|
||||||
rs_allocation gIn;
|
|
||||||
|
|
||||||
float gCoeffs[25];
|
|
||||||
|
|
||||||
static inline uchar4 GetElementAt_uchar4(rs_allocation a, uint32_t x, uint32_t y) {
|
|
||||||
return ((uchar4 *)rsGetElementAt(a, x, y))[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
void root(uchar4 *out, uint32_t x, uint32_t y) {
|
|
||||||
uint32_t x0 = max((int32_t)x-2, 0);
|
|
||||||
uint32_t x1 = max((int32_t)x-1, 0);
|
|
||||||
uint32_t x2 = x;
|
|
||||||
uint32_t x3 = min((int32_t)x+1, gWidth-1);
|
|
||||||
uint32_t x4 = min((int32_t)x+2, gWidth-1);
|
|
||||||
|
|
||||||
uint32_t y0 = max((int32_t)y-2, 0);
|
|
||||||
uint32_t y1 = max((int32_t)y-1, 0);
|
|
||||||
uint32_t y2 = y;
|
|
||||||
uint32_t y3 = min((int32_t)y+1, gHeight-1);
|
|
||||||
uint32_t y4 = min((int32_t)y+2, gHeight-1);
|
|
||||||
|
|
||||||
float4 p0 = convert_float4(GetElementAt_uchar4(gIn, x0, y0)) * gCoeffs[0]
|
|
||||||
+ convert_float4(GetElementAt_uchar4(gIn, x1, y0)) * gCoeffs[1]
|
|
||||||
+ convert_float4(GetElementAt_uchar4(gIn, x2, y0)) * gCoeffs[2]
|
|
||||||
+ convert_float4(GetElementAt_uchar4(gIn, x3, y0)) * gCoeffs[3]
|
|
||||||
+ convert_float4(GetElementAt_uchar4(gIn, x4, y0)) * gCoeffs[4];
|
|
||||||
|
|
||||||
float4 p1 = convert_float4(GetElementAt_uchar4(gIn, x0, y1)) * gCoeffs[5]
|
|
||||||
+ convert_float4(GetElementAt_uchar4(gIn, x1, y1)) * gCoeffs[6]
|
|
||||||
+ convert_float4(GetElementAt_uchar4(gIn, x2, y1)) * gCoeffs[7]
|
|
||||||
+ convert_float4(GetElementAt_uchar4(gIn, x3, y1)) * gCoeffs[8]
|
|
||||||
+ convert_float4(GetElementAt_uchar4(gIn, x4, y1)) * gCoeffs[9];
|
|
||||||
|
|
||||||
float4 p2 = convert_float4(GetElementAt_uchar4(gIn, x0, y2)) * gCoeffs[10]
|
|
||||||
+ convert_float4(GetElementAt_uchar4(gIn, x1, y2)) * gCoeffs[11]
|
|
||||||
+ convert_float4(GetElementAt_uchar4(gIn, x2, y2)) * gCoeffs[12]
|
|
||||||
+ convert_float4(GetElementAt_uchar4(gIn, x3, y2)) * gCoeffs[13]
|
|
||||||
+ convert_float4(GetElementAt_uchar4(gIn, x4, y2)) * gCoeffs[14];
|
|
||||||
|
|
||||||
float4 p3 = convert_float4(GetElementAt_uchar4(gIn, x0, y3)) * gCoeffs[15]
|
|
||||||
+ convert_float4(GetElementAt_uchar4(gIn, x1, y3)) * gCoeffs[16]
|
|
||||||
+ convert_float4(GetElementAt_uchar4(gIn, x2, y3)) * gCoeffs[17]
|
|
||||||
+ convert_float4(GetElementAt_uchar4(gIn, x3, y3)) * gCoeffs[18]
|
|
||||||
+ convert_float4(GetElementAt_uchar4(gIn, x4, y3)) * gCoeffs[19];
|
|
||||||
|
|
||||||
float4 p4 = convert_float4(GetElementAt_uchar4(gIn, x0, y4)) * gCoeffs[20]
|
|
||||||
+ convert_float4(GetElementAt_uchar4(gIn, x1, y4)) * gCoeffs[21]
|
|
||||||
+ convert_float4(GetElementAt_uchar4(gIn, x2, y4)) * gCoeffs[22]
|
|
||||||
+ convert_float4(GetElementAt_uchar4(gIn, x3, y4)) * gCoeffs[23]
|
|
||||||
+ convert_float4(GetElementAt_uchar4(gIn, x4, y4)) * gCoeffs[24];
|
|
||||||
|
|
||||||
p0 = clamp(p0 + p1 + p2 + p3 + p4, 0.f, 255.f);
|
|
||||||
*out = convert_uchar4(p0);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
@ -0,0 +1,23 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2012 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "ip.rsh"
|
||||||
|
|
||||||
|
uchar4 __attribute__((kernel)) root(uchar4 v_in) {
|
||||||
|
return v_in;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2012 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "ip.rsh"
|
||||||
|
|
||||||
|
static float bright = 0.f;
|
||||||
|
|
||||||
|
void setBright(float v) {
|
||||||
|
bright = 255.f / (255.f - v);
|
||||||
|
}
|
||||||
|
|
||||||
|
void exposure(const uchar4 *in, uchar4 *out)
|
||||||
|
{
|
||||||
|
out->r = rsClamp((int)(bright * in->r), 0, 255);
|
||||||
|
out->g = rsClamp((int)(bright * in->g), 0, 255);
|
||||||
|
out->b = rsClamp((int)(bright * in->b), 0, 255);
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,58 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2012 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
rs_allocation in_alloc;
|
||||||
|
rs_sampler sampler;
|
||||||
|
|
||||||
|
static float2 center, neg_center, inv_dimensions, axis_scale;
|
||||||
|
static float alpha, radius2, factor;
|
||||||
|
|
||||||
|
void init_filter(uint32_t dim_x, uint32_t dim_y, float center_x, float center_y, float k) {
|
||||||
|
center.x = center_x;
|
||||||
|
center.y = center_y;
|
||||||
|
neg_center = -center;
|
||||||
|
inv_dimensions.x = 1.f / (float)dim_x;
|
||||||
|
inv_dimensions.y = 1.f / (float)dim_y;
|
||||||
|
alpha = k * 2.0f + 0.75f;
|
||||||
|
|
||||||
|
axis_scale = (float2)1.f;
|
||||||
|
if (dim_x > dim_y)
|
||||||
|
axis_scale.y = (float)dim_y / (float)dim_x;
|
||||||
|
else
|
||||||
|
axis_scale.x = (float)dim_x / (float)dim_y;
|
||||||
|
|
||||||
|
const float bound2 = 0.25f * (axis_scale.x*axis_scale.x + axis_scale.y*axis_scale.y);
|
||||||
|
const float bound = sqrt(bound2);
|
||||||
|
const float radius = 1.15f * bound;
|
||||||
|
radius2 = radius*radius;
|
||||||
|
const float max_radian = M_PI_2 - atan(alpha / bound * sqrt(radius2 - bound2));
|
||||||
|
factor = bound / max_radian;
|
||||||
|
}
|
||||||
|
|
||||||
|
uchar4 __attribute__((kernel)) root(uint32_t x, uint32_t y) {
|
||||||
|
// Convert x and y to floating point coordinates with center as origin
|
||||||
|
const float2 inCoord = {(float)x, (float)y};
|
||||||
|
const float2 coord = mad(inCoord, inv_dimensions, neg_center);
|
||||||
|
const float2 scaledCoord = axis_scale * coord;
|
||||||
|
const float dist2 = scaledCoord.x*scaledCoord.x + scaledCoord.y*scaledCoord.y;
|
||||||
|
const float inv_dist = rsqrt(dist2);
|
||||||
|
const float radian = M_PI_2 - atan((alpha * sqrt(radius2 - dist2)) * inv_dist);
|
||||||
|
const float scalar = radian * factor * inv_dist;
|
||||||
|
const float2 new_coord = mad(coord, scalar, center);
|
||||||
|
const float4 fout = rsSample(in_alloc, sampler, new_coord);
|
||||||
|
return rsPackColorTo8888(fout);
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,58 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2012 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
rs_allocation in_alloc;
|
||||||
|
rs_sampler sampler;
|
||||||
|
|
||||||
|
static float2 center, neg_center, inv_dimensions, axis_scale;
|
||||||
|
static float alpha, radius2, factor;
|
||||||
|
|
||||||
|
void init_filter(uint32_t dim_x, uint32_t dim_y, float center_x, float center_y, float k) {
|
||||||
|
center.x = center_x;
|
||||||
|
center.y = center_y;
|
||||||
|
neg_center = -center;
|
||||||
|
inv_dimensions.x = 1.f / (float)dim_x;
|
||||||
|
inv_dimensions.y = 1.f / (float)dim_y;
|
||||||
|
alpha = k * 2.0f + 0.75f;
|
||||||
|
|
||||||
|
axis_scale = (float2)1.f;
|
||||||
|
if (dim_x > dim_y)
|
||||||
|
axis_scale.y = (float)dim_y / (float)dim_x;
|
||||||
|
else
|
||||||
|
axis_scale.x = (float)dim_x / (float)dim_y;
|
||||||
|
|
||||||
|
const float bound2 = 0.25f * (axis_scale.x*axis_scale.x + axis_scale.y*axis_scale.y);
|
||||||
|
const float bound = sqrt(bound2);
|
||||||
|
const float radius = 1.15f * bound;
|
||||||
|
radius2 = radius*radius;
|
||||||
|
const float max_radian = M_PI_2 - atan(alpha / bound * sqrt(radius2 - bound2));
|
||||||
|
factor = bound / max_radian;
|
||||||
|
}
|
||||||
|
|
||||||
|
uchar4 __attribute__((kernel)) root(uint32_t x, uint32_t y) {
|
||||||
|
// Convert x and y to floating point coordinates with center as origin
|
||||||
|
const float2 inCoord = {(float)x, (float)y};
|
||||||
|
const float2 coord = mad(inCoord, inv_dimensions, neg_center);
|
||||||
|
const float2 scaledCoord = axis_scale * coord;
|
||||||
|
const float dist2 = scaledCoord.x*scaledCoord.x + scaledCoord.y*scaledCoord.y;
|
||||||
|
const float inv_dist = half_rsqrt(dist2);
|
||||||
|
const float radian = M_PI_2 - atan((alpha * half_sqrt(radius2 - dist2)) * inv_dist);
|
||||||
|
const float scalar = radian * factor * inv_dist;
|
||||||
|
const float2 new_coord = mad(coord, scalar, center);
|
||||||
|
const float4 fout = rsSample(in_alloc, sampler, new_coord);
|
||||||
|
return rsPackColorTo8888(fout);
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,20 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2012 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "ip.rsh"
|
||||||
|
|
||||||
|
#include "fisheye_approx.rsh"
|
||||||
|
|
@ -0,0 +1,20 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2012 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "ip.rsh"
|
||||||
|
|
||||||
|
#include "fisheye_approx.rsh"
|
||||||
|
|
@ -0,0 +1,20 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2012 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "ip.rsh"
|
||||||
|
|
||||||
|
#include "fisheye.rsh"
|
||||||
|
|
@ -0,0 +1,20 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2012 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "ip.rsh"
|
||||||
|
|
||||||
|
#include "fisheye.rsh"
|
||||||
|
|
@ -14,20 +14,10 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#pragma version(1)
|
#include "ip.rsh"
|
||||||
#pragma rs java_package_name(com.android.rs.imagejb)
|
|
||||||
#pragma rs_fp_relaxed
|
|
||||||
|
|
||||||
void genRand(uchar *out) {
|
uchar __attribute__((kernel)) genRand() {
|
||||||
*out = (uchar)rsRand(0xff);
|
return (uchar)rsRand(0xff);
|
||||||
}
|
|
||||||
|
|
||||||
static inline uchar GetElementAt_uchar(rs_allocation a, uint32_t x, uint32_t y) {
|
|
||||||
return ((uchar *)rsGetElementAt(a, x, y))[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline float4 GetElementAt_float4(rs_allocation a, uint32_t x, uint32_t y) {
|
|
||||||
return ((float4 *)rsGetElementAt(a, x, y))[0];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -50,21 +40,21 @@ int32_t gWMask;
|
|||||||
int32_t gHMask;
|
int32_t gHMask;
|
||||||
|
|
||||||
rs_allocation gBlendSource;
|
rs_allocation gBlendSource;
|
||||||
void blend9(uchar *out, uint32_t x, uint32_t y) {
|
uchar __attribute__((kernel)) blend9(uint32_t x, uint32_t y) {
|
||||||
uint32_t x1 = (x-1) & gWMask;
|
uint32_t x1 = (x-1) & gWMask;
|
||||||
uint32_t x2 = (x+1) & gWMask;
|
uint32_t x2 = (x+1) & gWMask;
|
||||||
uint32_t y1 = (y-1) & gHMask;
|
uint32_t y1 = (y-1) & gHMask;
|
||||||
uint32_t y2 = (y+1) & gHMask;
|
uint32_t y2 = (y+1) & gHMask;
|
||||||
|
|
||||||
uint p00 = 56 * GetElementAt_uchar(gBlendSource, x1, y1);
|
uint p00 = 56 * rsGetElementAt_uchar(gBlendSource, x1, y1);
|
||||||
uint p01 = 114 * GetElementAt_uchar(gBlendSource, x, y1);
|
uint p01 = 114 * rsGetElementAt_uchar(gBlendSource, x, y1);
|
||||||
uint p02 = 56 * GetElementAt_uchar(gBlendSource, x2, y1);
|
uint p02 = 56 * rsGetElementAt_uchar(gBlendSource, x2, y1);
|
||||||
uint p10 = 114 * GetElementAt_uchar(gBlendSource, x1, y);
|
uint p10 = 114 * rsGetElementAt_uchar(gBlendSource, x1, y);
|
||||||
uint p11 = 230 * GetElementAt_uchar(gBlendSource, x, y);
|
uint p11 = 230 * rsGetElementAt_uchar(gBlendSource, x, y);
|
||||||
uint p12 = 114 * GetElementAt_uchar(gBlendSource, x2, y);
|
uint p12 = 114 * rsGetElementAt_uchar(gBlendSource, x2, y);
|
||||||
uint p20 = 56 * GetElementAt_uchar(gBlendSource, x1, y2);
|
uint p20 = 56 * rsGetElementAt_uchar(gBlendSource, x1, y2);
|
||||||
uint p21 = 114 * GetElementAt_uchar(gBlendSource, x, y2);
|
uint p21 = 114 * rsGetElementAt_uchar(gBlendSource, x, y2);
|
||||||
uint p22 = 56 * GetElementAt_uchar(gBlendSource, x2, y2);
|
uint p22 = 56 * rsGetElementAt_uchar(gBlendSource, x2, y2);
|
||||||
|
|
||||||
p00 += p01;
|
p00 += p01;
|
||||||
p02 += p10;
|
p02 += p10;
|
||||||
@ -78,15 +68,15 @@ void blend9(uchar *out, uint32_t x, uint32_t y) {
|
|||||||
p20 += p02;
|
p20 += p02;
|
||||||
|
|
||||||
p20 = min(p20 >> 10, (uint)255);
|
p20 = min(p20 >> 10, (uint)255);
|
||||||
*out = (uchar)p20;
|
return (uchar)p20;
|
||||||
}
|
}
|
||||||
|
|
||||||
float gNoiseStrength;
|
float gNoiseStrength;
|
||||||
|
|
||||||
rs_allocation gNoise;
|
rs_allocation gNoise;
|
||||||
void root(const uchar4 *in, uchar4 *out, uint32_t x, uint32_t y) {
|
uchar4 __attribute__((kernel)) root(uchar4 in, uint32_t x, uint32_t y) {
|
||||||
float4 ip = convert_float4(*in);
|
float4 ip = convert_float4(in);
|
||||||
float pnoise = (float) GetElementAt_uchar(gNoise, x & gWMask, y & gHMask);
|
float pnoise = (float) rsGetElementAt_uchar(gNoise, x & gWMask, y & gHMask);
|
||||||
|
|
||||||
float energy_level = ip.r + ip.g + ip.b;
|
float energy_level = ip.r + ip.g + ip.b;
|
||||||
float energy_mask = (28.f - sqrt(energy_level)) * 0.03571f;
|
float energy_mask = (28.f - sqrt(energy_level)) * 0.03571f;
|
||||||
@ -97,5 +87,5 @@ void root(const uchar4 *in, uchar4 *out, uint32_t x, uint32_t y) {
|
|||||||
|
|
||||||
uchar4 p = convert_uchar4(ip);
|
uchar4 p = convert_uchar4(ip);
|
||||||
p.a = 0xff;
|
p.a = 0xff;
|
||||||
*out = p;
|
return p;
|
||||||
}
|
}
|
@ -14,17 +14,23 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#pragma version(1)
|
#include "ip.rsh"
|
||||||
#pragma rs java_package_name(com.android.rs.imagejb)
|
|
||||||
#pragma rs_fp_relaxed
|
|
||||||
|
|
||||||
const static float3 gMonoMult = {0.299f, 0.587f, 0.114f};
|
const static float3 gMonoMult = {0.299f, 0.587f, 0.114f};
|
||||||
|
|
||||||
void root(const uchar4 *v_in, uchar4 *out) {
|
uchar4 __attribute__((kernel)) root(uchar4 v_in) {
|
||||||
float4 f4 = rsUnpackColor8888(*v_in);
|
float4 f4 = rsUnpackColor8888(v_in);
|
||||||
|
|
||||||
float3 mono = dot(f4.rgb, gMonoMult);
|
float3 mono = dot(f4.rgb, gMonoMult);
|
||||||
*out = rsPackColorTo8888(mono);
|
return rsPackColorTo8888(mono);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uchar __attribute__((kernel)) toU8(uchar4 v_in) {
|
||||||
|
float4 f4 = convert_float4(v_in);
|
||||||
|
return (uchar)dot(f4.rgb, gMonoMult);
|
||||||
|
}
|
||||||
|
|
||||||
|
uchar4 __attribute__((kernel)) toU8_4(uchar v_in) {
|
||||||
|
return (uchar4)v_in;
|
||||||
|
}
|
||||||
|
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2012 The Android Open Source Project
|
* Copyright (C) 2013 The Android Open Source Project
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@ -17,8 +17,4 @@
|
|||||||
#pragma version(1)
|
#pragma version(1)
|
||||||
#pragma rs java_package_name(com.android.rs.imagejb)
|
#pragma rs java_package_name(com.android.rs.imagejb)
|
||||||
|
|
||||||
void root(const uchar4 *in, uchar4 *out) {
|
|
||||||
*out = *in;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
@ -21,24 +21,26 @@ float outWMinOutB;
|
|||||||
float overInWMinInB;
|
float overInWMinInB;
|
||||||
rs_matrix3x3 colorMat;
|
rs_matrix3x3 colorMat;
|
||||||
|
|
||||||
void root(const uchar4 *in, uchar4 *out, uint32_t x, uint32_t y) {
|
uchar4 __attribute__((kernel)) root(uchar4 in, uint32_t x, uint32_t y) {
|
||||||
float3 pixel = convert_float4(*in).rgb;
|
uchar4 out;
|
||||||
|
float3 pixel = convert_float4(in).rgb;
|
||||||
pixel = rsMatrixMultiply(&colorMat, pixel);
|
pixel = rsMatrixMultiply(&colorMat, pixel);
|
||||||
pixel = clamp(pixel, 0.f, 255.f);
|
pixel = clamp(pixel, 0.f, 255.f);
|
||||||
pixel = (pixel - inBlack) * overInWMinInB;
|
pixel = (pixel - inBlack) * overInWMinInB;
|
||||||
pixel = pixel * outWMinOutB + outBlack;
|
pixel = pixel * outWMinOutB + outBlack;
|
||||||
pixel = clamp(pixel, 0.f, 255.f);
|
pixel = clamp(pixel, 0.f, 255.f);
|
||||||
out->xyz = convert_uchar3(pixel);
|
out.xyz = convert_uchar3(pixel);
|
||||||
out->w = 0xff;
|
out.w = 0xff;
|
||||||
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
void root4(const uchar4 *in, uchar4 *out, uint32_t x, uint32_t y) {
|
uchar4 __attribute__((kernel)) root4(uchar4 in, uint32_t x, uint32_t y) {
|
||||||
float4 pixel = convert_float4(*in);
|
float4 pixel = convert_float4(in);
|
||||||
pixel.rgb = rsMatrixMultiply(&colorMat, pixel.rgb);
|
pixel.rgb = rsMatrixMultiply(&colorMat, pixel.rgb);
|
||||||
pixel = clamp(pixel, 0.f, 255.f);
|
pixel = clamp(pixel, 0.f, 255.f);
|
||||||
pixel = (pixel - inBlack) * overInWMinInB;
|
pixel = (pixel - inBlack) * overInWMinInB;
|
||||||
pixel = pixel * outWMinOutB + outBlack;
|
pixel = pixel * outWMinOutB + outBlack;
|
||||||
pixel = clamp(pixel, 0.f, 255.f);
|
pixel = clamp(pixel, 0.f, 255.f);
|
||||||
*out = convert_uchar4(pixel);
|
return convert_uchar4(pixel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,8 +14,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#pragma version(1)
|
#include "ip.rsh"
|
||||||
#pragma rs java_package_name(com.android.rs.imagejb)
|
|
||||||
|
|
||||||
#include "levels.rsh"
|
#include "levels.rsh"
|
||||||
|
|
||||||
|
@ -14,9 +14,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#pragma version(1)
|
#include "ip.rsh"
|
||||||
#pragma rs java_package_name(com.android.rs.imagejb)
|
|
||||||
#pragma rs_fp_relaxed
|
|
||||||
|
|
||||||
#include "levels.rsh"
|
#include "levels.rsh"
|
||||||
|
|
@ -12,8 +12,7 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
#pragma version(1)
|
#include "ip.rsh"
|
||||||
#pragma rs java_package_name(com.android.rs.imagejb)
|
|
||||||
|
|
||||||
uint32_t gMaxIteration = 500;
|
uint32_t gMaxIteration = 500;
|
||||||
uint32_t gDimX = 1024;
|
uint32_t gDimX = 1024;
|
||||||
@ -23,7 +22,7 @@ float lowerBoundX = -2.f;
|
|||||||
float lowerBoundY = -2.f;
|
float lowerBoundY = -2.f;
|
||||||
float scaleFactor = 4.f;
|
float scaleFactor = 4.f;
|
||||||
|
|
||||||
void root(uchar4 *out, uint32_t x, uint32_t y) {
|
uchar4 __attribute__((kernel)) root(uint32_t x, uint32_t y) {
|
||||||
float2 p;
|
float2 p;
|
||||||
p.x = lowerBoundX + ((float)x / gDimX) * scaleFactor;
|
p.x = lowerBoundX + ((float)x / gDimX) * scaleFactor;
|
||||||
p.y = lowerBoundY + ((float)y / gDimY) * scaleFactor;
|
p.y = lowerBoundY + ((float)y / gDimY) * scaleFactor;
|
||||||
@ -41,16 +40,16 @@ void root(uchar4 *out, uint32_t x, uint32_t y) {
|
|||||||
|
|
||||||
if(iter >= gMaxIteration) {
|
if(iter >= gMaxIteration) {
|
||||||
// write a non-transparent black pixel
|
// write a non-transparent black pixel
|
||||||
*out = (uchar4){0, 0, 0, 0xff};
|
return (uchar4){0, 0, 0, 0xff};
|
||||||
} else {
|
} else {
|
||||||
float mi3 = gMaxIteration / 3.f;
|
float mi3 = gMaxIteration / 3.f;
|
||||||
if (iter <= (gMaxIteration / 3))
|
if (iter <= (gMaxIteration / 3))
|
||||||
*out = (uchar4){0xff * (iter / mi3), 0, 0, 0xff};
|
return (uchar4){0xff * (iter / mi3), 0, 0, 0xff};
|
||||||
else if (iter <= (((gMaxIteration / 3) * 2)))
|
else if (iter <= (((gMaxIteration / 3) * 2)))
|
||||||
*out = (uchar4){0xff - (0xff * ((iter - mi3) / mi3)),
|
return (uchar4){0xff - (0xff * ((iter - mi3) / mi3)),
|
||||||
(0xff * ((iter - mi3) / mi3)), 0, 0xff};
|
(0xff * ((iter - mi3) / mi3)), 0, 0xff};
|
||||||
else
|
else
|
||||||
*out = (uchar4){0, 0xff - (0xff * ((iter - (mi3 * 2)) / mi3)),
|
return (uchar4){0, 0xff - (0xff * ((iter - (mi3 * 2)) / mi3)),
|
||||||
(0xff * ((iter - (mi3 * 2)) / mi3)), 0xff};
|
(0xff * ((iter - (mi3 * 2)) / mi3)), 0xff};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,192 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2012 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "ip.rsh"
|
||||||
|
//#pragma rs_fp_relaxed
|
||||||
|
|
||||||
|
static double shadowFilterMap[] = {
|
||||||
|
-0.00591, 0.0001,
|
||||||
|
1.16488, 0.01668,
|
||||||
|
-0.18027, -0.06791,
|
||||||
|
-0.12625, 0.09001,
|
||||||
|
0.15065, -0.03897
|
||||||
|
};
|
||||||
|
|
||||||
|
static double poly[] = {
|
||||||
|
0., 0.,
|
||||||
|
0., 0.,
|
||||||
|
0.
|
||||||
|
};
|
||||||
|
|
||||||
|
static const int ABITS = 4;
|
||||||
|
static const int HSCALE = 256;
|
||||||
|
static const int k1=255 << ABITS;
|
||||||
|
static const int k2=HSCALE << ABITS;
|
||||||
|
|
||||||
|
static double fastevalPoly(double *poly,int n, double x){
|
||||||
|
|
||||||
|
double f =x;
|
||||||
|
double sum = poly[0]+poly[1]*f;
|
||||||
|
int i;
|
||||||
|
for (i = 2; i < n; i++) {
|
||||||
|
f*=x;
|
||||||
|
sum += poly[i]*f;
|
||||||
|
}
|
||||||
|
return sum;
|
||||||
|
}
|
||||||
|
|
||||||
|
static ushort3 rgb2hsv( uchar4 rgb)
|
||||||
|
{
|
||||||
|
int iMin,iMax,chroma;
|
||||||
|
|
||||||
|
int ri = rgb.r;
|
||||||
|
int gi = rgb.g;
|
||||||
|
int bi = rgb.b;
|
||||||
|
short rv,rs,rh;
|
||||||
|
|
||||||
|
if (ri > gi) {
|
||||||
|
iMax = max (ri, bi);
|
||||||
|
iMin = min (gi, bi);
|
||||||
|
} else {
|
||||||
|
iMax = max (gi, bi);
|
||||||
|
iMin = min (ri, bi);
|
||||||
|
}
|
||||||
|
|
||||||
|
chroma = iMax - iMin;
|
||||||
|
// set value
|
||||||
|
rv = (short)( iMax << ABITS);
|
||||||
|
|
||||||
|
// set saturation
|
||||||
|
if (rv == 0)
|
||||||
|
rs = 0;
|
||||||
|
else
|
||||||
|
rs = (short)((k1*chroma)/iMax);
|
||||||
|
|
||||||
|
// set hue
|
||||||
|
if (rs == 0)
|
||||||
|
rh = 0;
|
||||||
|
else {
|
||||||
|
if ( ri == iMax ) {
|
||||||
|
rh = (short)( (k2*(6*chroma+gi - bi))/(6*chroma));
|
||||||
|
if (rh >= k2) rh -= k2;
|
||||||
|
} else if (gi == iMax)
|
||||||
|
rh = (short)( (k2*(2*chroma+bi - ri ))/(6*chroma));
|
||||||
|
else // (bi == iMax )
|
||||||
|
rh = (short)( (k2*(4*chroma+ri - gi ))/(6*chroma));
|
||||||
|
}
|
||||||
|
|
||||||
|
ushort3 out;
|
||||||
|
out.x = rv;
|
||||||
|
out.y = rs;
|
||||||
|
out.z = rh;
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
static uchar4 hsv2rgb(ushort3 hsv)
|
||||||
|
{
|
||||||
|
int ABITS = 4;
|
||||||
|
int HSCALE = 256;
|
||||||
|
int m;
|
||||||
|
int H,X,ih,is,iv;
|
||||||
|
int k1=255<<ABITS;
|
||||||
|
int k2=HSCALE<<ABITS;
|
||||||
|
int k3=1<<(ABITS-1);
|
||||||
|
int rr=0;
|
||||||
|
int rg=0;
|
||||||
|
int rb=0;
|
||||||
|
short cv = hsv.x;
|
||||||
|
short cs = hsv.y;
|
||||||
|
short ch = hsv.z;
|
||||||
|
|
||||||
|
// set chroma and min component value m
|
||||||
|
//chroma = ( cv * cs )/k1;
|
||||||
|
//m = cv - chroma;
|
||||||
|
m = ((int)cv*(k1 - (int)cs ))/k1;
|
||||||
|
|
||||||
|
// chroma == 0 <-> cs == 0 --> m=cv
|
||||||
|
if (cs == 0) {
|
||||||
|
rb = ( rg = ( rr =( cv >> ABITS) ));
|
||||||
|
} else {
|
||||||
|
ih=(int)ch;
|
||||||
|
is=(int)cs;
|
||||||
|
iv=(int)cv;
|
||||||
|
|
||||||
|
H = (6*ih)/k2;
|
||||||
|
X = ((iv*is)/k2)*(k2- abs(6*ih- 2*(H>>1)*k2 - k2)) ;
|
||||||
|
|
||||||
|
// removing additional bits --> unit8
|
||||||
|
X=( (X+iv*(k1 - is ))/k1 + k3 ) >> ABITS;
|
||||||
|
m=m >> ABITS;
|
||||||
|
|
||||||
|
// ( chroma + m ) --> cv ;
|
||||||
|
cv=(short) (cv >> ABITS);
|
||||||
|
switch (H) {
|
||||||
|
case 0:
|
||||||
|
rr = cv;
|
||||||
|
rg = X;
|
||||||
|
rb = m;
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
rr = X;
|
||||||
|
rg = cv;
|
||||||
|
rb = m;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
rr = m;
|
||||||
|
rg = cv;
|
||||||
|
rb = X;
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
rr = m;
|
||||||
|
rg = X;
|
||||||
|
rb = cv;
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
rr = X;
|
||||||
|
rg = m;
|
||||||
|
rb = cv;
|
||||||
|
break;
|
||||||
|
case 5:
|
||||||
|
rr = cv;
|
||||||
|
rg = m ;
|
||||||
|
rb = X;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
uchar4 rgb;
|
||||||
|
|
||||||
|
rgb.r = rr;
|
||||||
|
rgb.g = rg;
|
||||||
|
rgb.b = rb;
|
||||||
|
|
||||||
|
return rgb;
|
||||||
|
}
|
||||||
|
|
||||||
|
void prepareShadows(float scale) {
|
||||||
|
double s = (scale>=0)?scale:scale/5;
|
||||||
|
for (int i = 0; i < 5; i++) {
|
||||||
|
poly[i] = fastevalPoly(shadowFilterMap+i*2,2 , s);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void shadowsKernel(const uchar4 *in, uchar4 *out) {
|
||||||
|
ushort3 hsv = rgb2hsv(*in);
|
||||||
|
double v = (fastevalPoly(poly,5,hsv.x/4080.)*4080);
|
||||||
|
if (v>4080) v = 4080;
|
||||||
|
hsv.x = (unsigned short) ((v>0)?v:0);
|
||||||
|
*out = hsv2rgb(hsv);
|
||||||
|
}
|
@ -1,6 +1,20 @@
|
|||||||
#pragma version(1)
|
/*
|
||||||
#pragma rs java_package_name(com.android.rs.imagejb)
|
* Copyright (C) 2013 The Android Open Source Project
|
||||||
#pragma rs_fp_relaxed
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "ip.rsh"
|
||||||
|
|
||||||
|
|
||||||
int height;
|
int height;
|
||||||
@ -56,51 +70,49 @@ void setRadius(int rad) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void copyIn(const uchar4 *in, float4 *out) {
|
float4 __attribute__((kernel)) copyIn(uchar4 in) {
|
||||||
*out = convert_float4(*in);
|
return convert_float4(in);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline float4 GetElementAt_float4(rs_allocation a, uint32_t x, uint32_t y) {
|
uchar4 __attribute__((kernel)) vert(uint32_t x, uint32_t y) {
|
||||||
return ((float4 *)rsGetElementAt(a, x, y))[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
void vert(uchar4 *out, uint32_t x, uint32_t y) {
|
|
||||||
float3 blurredPixel = 0;
|
float3 blurredPixel = 0;
|
||||||
int gi = 0;
|
int gi = 0;
|
||||||
|
uchar4 out;
|
||||||
if ((y > radius) && (y < (height - radius))) {
|
if ((y > radius) && (y < (height - radius))) {
|
||||||
for (int r = -radius; r <= radius; r ++) {
|
for (int r = -radius; r <= radius; r ++) {
|
||||||
float4 i = GetElementAt_float4(ScratchPixel2, x, y + r);
|
float4 i = rsGetElementAt_float4(ScratchPixel2, x, y + r);
|
||||||
blurredPixel += i.xyz * gaussian[gi++];
|
blurredPixel += i.xyz * gaussian[gi++];
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (int r = -radius; r <= radius; r ++) {
|
for (int r = -radius; r <= radius; r ++) {
|
||||||
int validH = rsClamp((int)y + r, (int)0, (int)(height - 1));
|
int validH = rsClamp((int)y + r, (int)0, (int)(height - 1));
|
||||||
float4 i = GetElementAt_float4(ScratchPixel2, x, validH);
|
float4 i = rsGetElementAt_float4(ScratchPixel2, x, validH);
|
||||||
blurredPixel += i.xyz * gaussian[gi++];
|
blurredPixel += i.xyz * gaussian[gi++];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
out->xyz = convert_uchar3(clamp(blurredPixel, 0.f, 255.f));
|
out.xyz = convert_uchar3(clamp(blurredPixel, 0.f, 255.f));
|
||||||
out->w = 0xff;
|
out.w = 0xff;
|
||||||
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
void horz(float4 *out, uint32_t x, uint32_t y) {
|
float4 __attribute__((kernel)) horz(uint32_t x, uint32_t y) {
|
||||||
float4 blurredPixel = 0;
|
float4 blurredPixel = 0;
|
||||||
int gi = 0;
|
int gi = 0;
|
||||||
if ((x > radius) && (x < (width - radius))) {
|
if ((x > radius) && (x < (width - radius))) {
|
||||||
for (int r = -radius; r <= radius; r ++) {
|
for (int r = -radius; r <= radius; r ++) {
|
||||||
float4 i = GetElementAt_float4(ScratchPixel1, x + r, y);
|
float4 i = rsGetElementAt_float4(ScratchPixel1, x + r, y);
|
||||||
blurredPixel += i * gaussian[gi++];
|
blurredPixel += i * gaussian[gi++];
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (int r = -radius; r <= radius; r ++) {
|
for (int r = -radius; r <= radius; r ++) {
|
||||||
// Stepping left and right away from the pixel
|
// Stepping left and right away from the pixel
|
||||||
int validX = rsClamp((int)x + r, (int)0, (int)(width - 1));
|
int validX = rsClamp((int)x + r, (int)0, (int)(width - 1));
|
||||||
float4 i = GetElementAt_float4(ScratchPixel1, validX, y);
|
float4 i = rsGetElementAt_float4(ScratchPixel1, validX, y);
|
||||||
blurredPixel += i * gaussian[gi++];
|
blurredPixel += i * gaussian[gi++];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
*out = blurredPixel;
|
return blurredPixel;
|
||||||
}
|
}
|
||||||
|
|
@ -0,0 +1,70 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2012 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "ip.rsh"
|
||||||
|
|
||||||
|
float vibrance = 0.f;
|
||||||
|
|
||||||
|
static const float Rf = 0.2999f;
|
||||||
|
static const float Gf = 0.587f;
|
||||||
|
static const float Bf = 0.114f;
|
||||||
|
|
||||||
|
static float S = 0.f;
|
||||||
|
static float MS = 0.f;
|
||||||
|
static float Rt = 0.f;
|
||||||
|
static float Gt = 0.f;
|
||||||
|
static float Bt = 0.f;
|
||||||
|
static float Vib = 0.f;
|
||||||
|
|
||||||
|
void vibranceKernel(const uchar4 *in, uchar4 *out) {
|
||||||
|
|
||||||
|
float R, G, B;
|
||||||
|
|
||||||
|
int r = in->r;
|
||||||
|
int g = in->g;
|
||||||
|
int b = in->b;
|
||||||
|
float red = (r-max(g, b))/256.f;
|
||||||
|
float sx = (float)(Vib/(1+exp(-red*3)));
|
||||||
|
S = sx+1;
|
||||||
|
MS = 1.0f - S;
|
||||||
|
Rt = Rf * MS;
|
||||||
|
Gt = Gf * MS;
|
||||||
|
Bt = Bf * MS;
|
||||||
|
int t = (r + g) / 2;
|
||||||
|
R = r;
|
||||||
|
G = g;
|
||||||
|
B = b;
|
||||||
|
|
||||||
|
float Rc = R * (Rt + S) + G * Gt + B * Bt;
|
||||||
|
float Gc = R * Rt + G * (Gt + S) + B * Bt;
|
||||||
|
float Bc = R * Rt + G * Gt + B * (Bt + S);
|
||||||
|
|
||||||
|
out->r = rsClamp(Rc, 0, 255);
|
||||||
|
out->g = rsClamp(Gc, 0, 255);
|
||||||
|
out->b = rsClamp(Bc, 0, 255);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void prepareVibrance() {
|
||||||
|
|
||||||
|
Vib = vibrance/100.f;
|
||||||
|
S = Vib + 1;
|
||||||
|
MS = 1.0f - S;
|
||||||
|
Rt = Rf * MS;
|
||||||
|
Gt = Gf * MS;
|
||||||
|
Bt = Bf * MS;
|
||||||
|
|
||||||
|
}
|
@ -44,9 +44,9 @@ void init_vignette(uint32_t dim_x, uint32_t dim_y, float center_x, float center_
|
|||||||
opp_shade = 1.f - desired_shade;
|
opp_shade = 1.f - desired_shade;
|
||||||
}
|
}
|
||||||
|
|
||||||
void root(const uchar4 *in, uchar4 *out, uint32_t x, uint32_t y) {
|
uchar4 __attribute__((kernel)) root(uchar4 in, uint32_t x, uint32_t y) {
|
||||||
// Convert x and y to floating point coordinates with center as origin
|
// Convert x and y to floating point coordinates with center as origin
|
||||||
const float4 fin = convert_float4(*in);
|
const float4 fin = convert_float4(in);
|
||||||
const float2 inCoord = {(float)x, (float)y};
|
const float2 inCoord = {(float)x, (float)y};
|
||||||
const float2 coord = mad(inCoord, inv_dimensions, neg_center);
|
const float2 coord = mad(inCoord, inv_dimensions, neg_center);
|
||||||
const float sloped_dist_ratio = length(axis_scale * coord) * sloped_inv_max_dist;
|
const float sloped_dist_ratio = length(axis_scale * coord) * sloped_inv_max_dist;
|
||||||
@ -54,6 +54,6 @@ void root(const uchar4 *in, uchar4 *out, uint32_t x, uint32_t y) {
|
|||||||
float4 fout;
|
float4 fout;
|
||||||
fout.rgb = fin.rgb * lumen;
|
fout.rgb = fin.rgb * lumen;
|
||||||
fout.w = fin.w;
|
fout.w = fin.w;
|
||||||
*out = convert_uchar4(fout);
|
return convert_uchar4(fout);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,59 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2012 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
static float2 neg_center, axis_scale, inv_dimensions;
|
||||||
|
static float sloped_neg_range, sloped_inv_max_dist, shade, opp_shade;
|
||||||
|
|
||||||
|
void init_vignette(uint32_t dim_x, uint32_t dim_y, float center_x, float center_y,
|
||||||
|
float desired_scale, float desired_shade, float desired_slope) {
|
||||||
|
|
||||||
|
neg_center.x = -center_x;
|
||||||
|
neg_center.y = -center_y;
|
||||||
|
inv_dimensions.x = 1.f / (float)dim_x;
|
||||||
|
inv_dimensions.y = 1.f / (float)dim_y;
|
||||||
|
|
||||||
|
axis_scale = (float2)1.f;
|
||||||
|
if (dim_x > dim_y)
|
||||||
|
axis_scale.y = (float)dim_y / (float)dim_x;
|
||||||
|
else
|
||||||
|
axis_scale.x = (float)dim_x / (float)dim_y;
|
||||||
|
|
||||||
|
const float max_dist = 0.5f * length(axis_scale);
|
||||||
|
sloped_inv_max_dist = desired_slope * 1.f/max_dist;
|
||||||
|
|
||||||
|
// Range needs to be between 1.3 to 0.6. When scale is zero then range is
|
||||||
|
// 1.3 which means no vignette at all because the luminousity difference is
|
||||||
|
// less than 1/256. Expect input scale to be between 0.0 and 1.0.
|
||||||
|
const float neg_range = 0.7f*sqrt(desired_scale) - 1.3f;
|
||||||
|
sloped_neg_range = exp(neg_range * desired_slope);
|
||||||
|
|
||||||
|
shade = desired_shade;
|
||||||
|
opp_shade = 1.f - desired_shade;
|
||||||
|
}
|
||||||
|
|
||||||
|
uchar4 __attribute__((kernel)) root(uchar4 in, uint32_t x, uint32_t y) {
|
||||||
|
// Convert x and y to floating point coordinates with center as origin
|
||||||
|
const float4 fin = convert_float4(in);
|
||||||
|
const float2 inCoord = {(float)x, (float)y};
|
||||||
|
const float2 coord = mad(inCoord, inv_dimensions, neg_center);
|
||||||
|
const float sloped_dist_ratio = fast_length(axis_scale * coord) * sloped_inv_max_dist;
|
||||||
|
const float lumen = opp_shade + shade * half_recip(1.f + sloped_neg_range * exp(sloped_dist_ratio));
|
||||||
|
float4 fout;
|
||||||
|
fout.rgb = fin.rgb * lumen;
|
||||||
|
fout.w = fin.w;
|
||||||
|
return convert_uchar4(fout);
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,20 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2012 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "ip.rsh"
|
||||||
|
|
||||||
|
#include "vignette_approx.rsh"
|
||||||
|
|
@ -0,0 +1,20 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2012 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "ip.rsh"
|
||||||
|
|
||||||
|
#include "vignette_approx.rsh"
|
||||||
|
|
@ -14,8 +14,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#pragma version(1)
|
#include "ip.rsh"
|
||||||
#pragma rs java_package_name(com.android.rs.imagejb)
|
|
||||||
|
|
||||||
#include "vignette.rsh"
|
#include "vignette.rsh"
|
||||||
|
|
||||||
|
@ -14,9 +14,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#pragma version(1)
|
#include "ip.rsh"
|
||||||
#pragma rs java_package_name(com.android.rs.imagejb)
|
|
||||||
#pragma rs_fp_relaxed
|
|
||||||
|
|
||||||
#include "vignette.rsh"
|
#include "vignette.rsh"
|
||||||
|
|
@ -0,0 +1,142 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2012 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "ip.rsh"
|
||||||
|
//#pragma rs_fp_relaxed
|
||||||
|
|
||||||
|
static int histR[256] = {0}, histG[256] = {0}, histB[256] = {0};
|
||||||
|
|
||||||
|
rs_allocation histogramSource;
|
||||||
|
uint32_t histogramHeight;
|
||||||
|
uint32_t histogramWidth;
|
||||||
|
|
||||||
|
static float scaleR;
|
||||||
|
static float scaleG;
|
||||||
|
static float scaleB;
|
||||||
|
|
||||||
|
static uchar4 estimateWhite() {
|
||||||
|
|
||||||
|
for (int i = 0; i < 256; i++) {
|
||||||
|
histR[i] = 0; histG[i] = 0; histB[i] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (uint32_t i = 0; i < histogramHeight; i++) {
|
||||||
|
for (uint32_t j = 0; j < histogramWidth; j++) {
|
||||||
|
uchar4 in = rsGetElementAt_uchar4(histogramSource, j, i);
|
||||||
|
histR[in.r]++;
|
||||||
|
histG[in.g]++;
|
||||||
|
histB[in.b]++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int min_r = -1, min_g = -1, min_b = -1;
|
||||||
|
int max_r = 0, max_g = 0, max_b = 0;
|
||||||
|
int sum_r = 0, sum_g = 0, sum_b = 0;
|
||||||
|
|
||||||
|
for (int i = 1; i < 255; i++) {
|
||||||
|
int r = histR[i];
|
||||||
|
int g = histG[i];
|
||||||
|
int b = histB[i];
|
||||||
|
sum_r += r;
|
||||||
|
sum_g += g;
|
||||||
|
sum_b += b;
|
||||||
|
|
||||||
|
if (r>0){
|
||||||
|
if (min_r < 0) min_r = i;
|
||||||
|
max_r = i;
|
||||||
|
}
|
||||||
|
if (g>0){
|
||||||
|
if (min_g < 0) min_g = i;
|
||||||
|
max_g = i;
|
||||||
|
}
|
||||||
|
if (b>0){
|
||||||
|
if (min_b < 0) min_b = i;
|
||||||
|
max_b = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int sum15r = 0, sum15g = 0, sum15b = 0;
|
||||||
|
int count15r = 0, count15g = 0, count15b = 0;
|
||||||
|
int tmp_r = 0, tmp_g = 0, tmp_b = 0;
|
||||||
|
|
||||||
|
for (int i = 254; i >0; i--) {
|
||||||
|
int r = histR[i];
|
||||||
|
int g = histG[i];
|
||||||
|
int b = histB[i];
|
||||||
|
tmp_r += r;
|
||||||
|
tmp_g += g;
|
||||||
|
tmp_b += b;
|
||||||
|
|
||||||
|
if ((tmp_r > sum_r/20) && (tmp_r < sum_r/5)) {
|
||||||
|
sum15r += r*i;
|
||||||
|
count15r += r;
|
||||||
|
}
|
||||||
|
if ((tmp_g > sum_g/20) && (tmp_g < sum_g/5)) {
|
||||||
|
sum15g += g*i;
|
||||||
|
count15g += g;
|
||||||
|
}
|
||||||
|
if ((tmp_b > sum_b/20) && (tmp_b < sum_b/5)) {
|
||||||
|
sum15b += b*i;
|
||||||
|
count15b += b;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
uchar4 out;
|
||||||
|
|
||||||
|
if ((count15r>0) && (count15g>0) && (count15b>0) ){
|
||||||
|
out.r = sum15r/count15r;
|
||||||
|
out.g = sum15g/count15g;
|
||||||
|
out.b = sum15b/count15b;
|
||||||
|
}else {
|
||||||
|
out.r = out.g = out.b = 255;
|
||||||
|
}
|
||||||
|
|
||||||
|
return out;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void prepareWhiteBalance() {
|
||||||
|
uchar4 estimation = estimateWhite();
|
||||||
|
int minimum = min(estimation.r, min(estimation.g, estimation.b));
|
||||||
|
int maximum = max(estimation.r, max(estimation.g, estimation.b));
|
||||||
|
float avg = (minimum + maximum) / 2.f;
|
||||||
|
|
||||||
|
scaleR = avg/estimation.r;
|
||||||
|
scaleG = avg/estimation.g;
|
||||||
|
scaleB = avg/estimation.b;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static unsigned char contrastClamp(int c)
|
||||||
|
{
|
||||||
|
int N = 255;
|
||||||
|
c &= ~(c >> 31);
|
||||||
|
c -= N;
|
||||||
|
c &= (c >> 31);
|
||||||
|
c += N;
|
||||||
|
return (unsigned char) c;
|
||||||
|
}
|
||||||
|
|
||||||
|
void whiteBalanceKernel(const uchar4 *in, uchar4 *out) {
|
||||||
|
float Rc = in->r*scaleR;
|
||||||
|
float Gc = in->g*scaleG;
|
||||||
|
float Bc = in->b*scaleB;
|
||||||
|
|
||||||
|
out->r = contrastClamp(Rc);
|
||||||
|
out->g = contrastClamp(Gc);
|
||||||
|
out->b = contrastClamp(Bc);
|
||||||
|
}
|
Reference in New Issue
Block a user