diff options
author | Jason Sams <jsams@google.com> | 2012-09-20 01:07:35 -0700 |
---|---|---|
committer | Jason Sams <jsams@google.com> | 2012-09-20 01:07:35 -0700 |
commit | 97e9ee2ea894a6946f3d6346b5d258ed1ca9eae8 (patch) | |
tree | b4e45e023fce924bde89c82f8f1d3ff054c04625 /tests | |
parent | 6704a48bd06f01d2933f83e9b5eda4ed9846bab7 (diff) | |
download | frameworks_base-97e9ee2ea894a6946f3d6346b5d258ed1ca9eae8.zip frameworks_base-97e9ee2ea894a6946f3d6346b5d258ed1ca9eae8.tar.gz frameworks_base-97e9ee2ea894a6946f3d6346b5d258ed1ca9eae8.tar.bz2 |
Cleanup blur test, remove deprecated functions.
Change-Id: I4136110692fdba8a644806fe8c92bfaacc930ca6
Diffstat (limited to 'tests')
5 files changed, 66 insertions, 169 deletions
diff --git a/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/Blur25.java b/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/Blur25.java index 9728c12..a2e4298 100644 --- a/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/Blur25.java +++ b/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/Blur25.java @@ -33,8 +33,6 @@ public class Blur25 extends TestBase { private int MAX_RADIUS = 25; private ScriptC_threshold mScript; - private ScriptC_vertical_blur mScriptVBlur; - private ScriptC_horizontal_blur mScriptHBlur; private int mRadius = MAX_RADIUS; private float mSaturation = 1.0f; private Allocation mScratchPixelsAllocation1; @@ -50,22 +48,17 @@ public class Blur25 extends TestBase { b.setProgress(100); return true; } - public boolean onBar2Setup(SeekBar b, TextView t) { - b.setProgress(50); - t.setText("Saturation"); - return true; - } public void onBar1Changed(int progress) { float fRadius = progress / 100.0f; fRadius *= (float)(MAX_RADIUS); mRadius = (int)fRadius; - mScript.set_radius(mRadius); - } - public void onBar2Changed(int progress) { - mSaturation = (float)progress / 50.0f; - mScriptVBlur.invoke_setSaturation(mSaturation); + if (mUseIntrinsic) { + mIntrinsic.setRadius(mRadius); + } else { + mScript.invoke_setRadius(mRadius); + } } @@ -75,7 +68,7 @@ public class Blur25 extends TestBase { if (mUseIntrinsic) { mIntrinsic = ScriptIntrinsicBlur.create(mRS, Element.U8_4(mRS)); - mIntrinsic.setRadius(25.f); + mIntrinsic.setRadius(MAX_RADIUS); mIntrinsic.setInput(mInPixelsAllocation); } else { @@ -85,23 +78,14 @@ public class Blur25 extends TestBase { mScratchPixelsAllocation1 = Allocation.createTyped(mRS, tb.create()); mScratchPixelsAllocation2 = Allocation.createTyped(mRS, tb.create()); - mScriptVBlur = new ScriptC_vertical_blur(mRS, res, R.raw.vertical_blur); - mScriptHBlur = new ScriptC_horizontal_blur(mRS, res, R.raw.horizontal_blur); - mScript = new ScriptC_threshold(mRS, res, R.raw.threshold); mScript.set_width(width); mScript.set_height(height); - mScript.set_radius(mRadius); - - mScriptVBlur.invoke_setSaturation(mSaturation); - - mScript.bind_InPixel(mInPixelsAllocation); - mScript.bind_OutPixel(mOutPixelsAllocation); - mScript.bind_ScratchPixel1(mScratchPixelsAllocation1); - mScript.bind_ScratchPixel2(mScratchPixelsAllocation2); + mScript.invoke_setRadius(MAX_RADIUS); - mScript.set_vBlurScript(mScriptVBlur); - mScript.set_hBlurScript(mScriptHBlur); + mScript.set_InPixel(mInPixelsAllocation); + mScript.set_ScratchPixel1(mScratchPixelsAllocation1); + mScript.set_ScratchPixel2(mScratchPixelsAllocation2); } } @@ -109,7 +93,9 @@ public class Blur25 extends TestBase { if (mUseIntrinsic) { mIntrinsic.forEach(mOutPixelsAllocation); } else { - mScript.invoke_filter(); + mScript.forEach_copyIn(mInPixelsAllocation, mScratchPixelsAllocation1); + mScript.forEach_horz(mScratchPixelsAllocation2); + mScript.forEach_vert(mOutPixelsAllocation); } } @@ -117,7 +103,7 @@ public class Blur25 extends TestBase { if (mUseIntrinsic) { mIntrinsic.setRadius(MAX_RADIUS); } else { - mScript.set_radius(MAX_RADIUS); + mScript.invoke_setRadius(MAX_RADIUS); } } @@ -125,7 +111,7 @@ public class Blur25 extends TestBase { if (mUseIntrinsic) { mIntrinsic.setRadius(mRadius); } else { - mScript.set_radius(mRadius); + mScript.invoke_setRadius(mRadius); } } } diff --git a/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/horizontal_blur.rs b/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/horizontal_blur.rs deleted file mode 100644 index ee83496..0000000 --- a/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/horizontal_blur.rs +++ /dev/null @@ -1,28 +0,0 @@ -#pragma version(1) -#pragma rs_fp_relaxed - -#include "ip.rsh" - -void root(float4 *out, const void *usrData, uint32_t x, uint32_t y) { - const FilterStruct *fs = (const FilterStruct *)usrData; - float3 blurredPixel = 0; - const float *gPtr = fs->gaussian; - if ((x > fs->radius) && (x < (fs->width - fs->radius))) { - for (int r = -fs->radius; r <= fs->radius; r ++) { - const float4 *i = (const float4 *)rsGetElementAt(fs->ain, x + r, y); - blurredPixel += i->xyz * gPtr[0]; - gPtr++; - } - } else { - for (int r = -fs->radius; r <= fs->radius; r ++) { - // Stepping left and right away from the pixel - int validX = rsClamp((int)x + r, (int)0, (int)(fs->width - 1)); - const float4 *i = (const float4 *)rsGetElementAt(fs->ain, validX, y); - blurredPixel += i->xyz * gPtr[0]; - gPtr++; - } - } - - out->xyz = blurredPixel; -} - diff --git a/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/ip.rsh b/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/ip.rsh deleted file mode 100644 index 1d7a719..0000000 --- a/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/ip.rsh +++ /dev/null @@ -1,15 +0,0 @@ -#pragma rs java_package_name(com.android.rs.image) - -#define MAX_RADIUS 25 - -typedef struct FilterStruct_s { - rs_allocation ain; - - float *gaussian; //[MAX_RADIUS * 2 + 1]; - int height; - int width; - int radius; - -} FilterStruct; - - diff --git a/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/threshold.rs b/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/threshold.rs index 77cd5be..3dfa94b 100644 --- a/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/threshold.rs +++ b/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/threshold.rs @@ -1,26 +1,23 @@ #pragma version(1) +#pragma rs java_package_name(com.android.rs.image) +#pragma rs_fp_relaxed -#include "ip.rsh" int height; int width; -int radius; +static int radius; -uchar4 * InPixel; -uchar4 * OutPixel; -float4 * ScratchPixel1; -float4 * ScratchPixel2; +rs_allocation InPixel; +rs_allocation ScratchPixel1; +rs_allocation ScratchPixel2; -rs_script vBlurScript; -rs_script hBlurScript; - -const int CMD_FINISHED = 1; +const int MAX_RADIUS = 25; // Store our coefficients here static float gaussian[MAX_RADIUS * 2 + 1]; - -static void computeGaussianWeights() { +void setRadius(int rad) { + radius = rad; // Compute gaussian weights for the blur // e is the euler's number float e = 2.718281828459045f; @@ -45,8 +42,7 @@ static void computeGaussianWeights() { float normalizeFactor = 0.0f; float floatR = 0.0f; - int r; - for (r = -radius; r <= radius; r ++) { + for (int r = -radius; r <= radius; r ++) { floatR = (float)r; gaussian[r + radius] = coeff1 * pow(e, floatR * floatR * coeff2); normalizeFactor += gaussian[r + radius]; @@ -54,40 +50,57 @@ static void computeGaussianWeights() { //Now we need to normalize the weights because all our coefficients need to add up to one normalizeFactor = 1.0f / normalizeFactor; - for (r = -radius; r <= radius; r ++) { + for (int r = -radius; r <= radius; r ++) { floatR = (float)r; gaussian[r + radius] *= normalizeFactor; } } +void copyIn(const uchar4 *in, float4 *out) { + *out = convert_float4(*in); +} -static void copyInput() { - rs_allocation ain; - ain = rsGetAllocation(InPixel); - uint32_t dimx = rsAllocationGetDimX(ain); - uint32_t dimy = rsAllocationGetDimY(ain); - for (uint32_t y = 0; y < dimy; y++) { - for (uint32_t x = 0; x < dimx; x++) { - ScratchPixel1[x + y * dimx] = convert_float4(InPixel[x + y * dimx]); +void vert(uchar4 *out, uint32_t x, uint32_t y) { + float3 blurredPixel = 0; + const float *gPtr = gaussian; + if ((y > radius) && (y < (height - radius))) { + for (int r = -radius; r <= radius; r ++) { + const float4 *i = (const float4 *)rsGetElementAt(ScratchPixel2, x, y + r); + blurredPixel += i->xyz * gPtr[0]; + gPtr++; + } + } else { + for (int r = -radius; r <= radius; r ++) { + int validH = rsClamp((int)y + r, (int)0, (int)(height - 1)); + const float4 *i = (const float4 *)rsGetElementAt(ScratchPixel2, x, validH); + blurredPixel += i->xyz * gPtr[0]; + gPtr++; } } -} -void filter() { - copyInput(); - computeGaussianWeights(); - - FilterStruct fs; - fs.gaussian = gaussian; - fs.width = width; - fs.height = height; - fs.radius = radius; + out->xyz = convert_uchar3(clamp(blurredPixel, 0.f, 255.f)); + out->w = 0xff; +} - fs.ain = rsGetAllocation(ScratchPixel1); - rsForEach(hBlurScript, fs.ain, rsGetAllocation(ScratchPixel2), &fs, sizeof(fs)); +void horz(float4 *out, uint32_t x, uint32_t y) { + float3 blurredPixel = 0; + const float *gPtr = gaussian; + if ((x > radius) && (x < (width - radius))) { + for (int r = -radius; r <= radius; r ++) { + const float4 *i = (const float4 *)rsGetElementAt(ScratchPixel1, x + r, y); + blurredPixel += i->xyz * gPtr[0]; + gPtr++; + } + } else { + for (int r = -radius; r <= radius; r ++) { + // Stepping left and right away from the pixel + int validX = rsClamp((int)x + r, (int)0, (int)(width - 1)); + const float4 *i = (const float4 *)rsGetElementAt(ScratchPixel1, validX, y); + blurredPixel += i->xyz * gPtr[0]; + gPtr++; + } + } - fs.ain = rsGetAllocation(ScratchPixel2); - rsForEach(vBlurScript, fs.ain, rsGetAllocation(OutPixel), &fs, sizeof(fs)); - //rsSendToClientBlocking(CMD_FINISHED); + out->xyz = blurredPixel; } diff --git a/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/vertical_blur.rs b/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/vertical_blur.rs deleted file mode 100644 index 60fd71b..0000000 --- a/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/vertical_blur.rs +++ /dev/null @@ -1,59 +0,0 @@ -#pragma version(1) -#pragma rs_fp_relaxed - -#include "ip.rsh" - -static float saturation; -static rs_matrix3x3 colorMat; - -void setSaturation(float sat) { - saturation = sat; - - // Saturation - // Linear weights - //float rWeight = 0.3086f; - //float gWeight = 0.6094f; - //float bWeight = 0.0820f; - - // Gamma 2.2 weights (we haven't converted our image to linear space yet for perf reasons) - float rWeight = 0.299f; - float gWeight = 0.587f; - float bWeight = 0.114f; - - float oneMinusS = 1.0f - saturation; - rsMatrixSet(&colorMat, 0, 0, oneMinusS * rWeight + saturation); - rsMatrixSet(&colorMat, 0, 1, oneMinusS * rWeight); - rsMatrixSet(&colorMat, 0, 2, oneMinusS * rWeight); - rsMatrixSet(&colorMat, 1, 0, oneMinusS * gWeight); - rsMatrixSet(&colorMat, 1, 1, oneMinusS * gWeight + saturation); - rsMatrixSet(&colorMat, 1, 2, oneMinusS * gWeight); - rsMatrixSet(&colorMat, 2, 0, oneMinusS * bWeight); - rsMatrixSet(&colorMat, 2, 1, oneMinusS * bWeight); - rsMatrixSet(&colorMat, 2, 2, oneMinusS * bWeight + saturation); -} - -void root(uchar4 *out, const void *usrData, uint32_t x, uint32_t y) { - const FilterStruct *fs = (const FilterStruct *)usrData; - float3 blurredPixel = 0; - const float *gPtr = fs->gaussian; - if ((y > fs->radius) && (y < (fs->height - fs->radius))) { - for (int r = -fs->radius; r <= fs->radius; r ++) { - const float4 *i = (const float4 *)rsGetElementAt(fs->ain, x, y + r); - blurredPixel += i->xyz * gPtr[0]; - gPtr++; - } - } else { - for (int r = -fs->radius; r <= fs->radius; r ++) { - int validH = rsClamp((int)y + r, (int)0, (int)(fs->height - 1)); - const float4 *i = (const float4 *)rsGetElementAt(fs->ain, x, validH); - blurredPixel += i->xyz * gPtr[0]; - gPtr++; - } - } - - float3 temp = rsMatrixMultiply(&colorMat, blurredPixel); - temp = clamp(temp, 0.f, 255.f); - out->xyz = convert_uchar3(temp); - out->w = 0xff; -} - |