Loading libs/rs/java/ImageProcessing/res/raw/threshold.rs +55 −39 Original line number Original line Diff line number Diff line Loading @@ -26,17 +26,19 @@ float gamma; float saturation; float saturation; float inWMinInB; static float inWMinInB; float outWMinOutB; static float outWMinOutB; static float overInWMinInB; //static float3 gammaV; #pragma rs export_var(height, width, radius, InPixel, OutPixel, ScratchPixel, inBlack, outBlack, inWhite, outWhite, gamma, saturation) #pragma rs export_var(height, width, radius, InPixel, OutPixel, ScratchPixel, inBlack, outBlack, inWhite, outWhite, gamma, saturation) #pragma rs export_func(filter, processNoBlur, computeColorMatrix, computeGaussianWeights); #pragma rs export_func(filter, filterBenchmark); // Store our coefficients here // Store our coefficients here float gaussian[MAX_RADIUS * 2 + 1]; static float gaussian[MAX_RADIUS * 2 + 1]; float colorMat[4][4]; static float colorMat[4][4]; void computeColorMatrix() { static void computeColorMatrix() { // Saturation // Saturation // Linear weights // Linear weights //float rWeight = 0.3086f; //float rWeight = 0.3086f; Loading Loading @@ -64,9 +66,10 @@ void computeColorMatrix() { inWMinInB = inWhite - inBlack; inWMinInB = inWhite - inBlack; outWMinOutB = outWhite - outBlack; outWMinOutB = outWhite - outBlack; overInWMinInB = 1.f / inWMinInB; } } void computeGaussianWeights() { static void computeGaussianWeights() { // Compute gaussian weights for the blur // Compute gaussian weights for the blur // e is the euler's number // e is the euler's number float e = 2.718281828459045f; float e = 2.718281828459045f; Loading Loading @@ -107,40 +110,53 @@ void computeGaussianWeights() { } } // This needs to be inline // This needs to be inline void levelsSaturation(float4 *currentPixel) { static float4 levelsSaturation(float4 currentPixel) { #if 0 // Color matrix multiply // Color matrix multiply float tempX = colorMat[0][0] * currentPixel->x + colorMat[1][0] * currentPixel->y + colorMat[2][0] * currentPixel->z; float tempX = colorMat[0][0] * currentPixel.x + colorMat[1][0] * currentPixel.y + colorMat[2][0] * currentPixel.z; float tempY = colorMat[0][1] * currentPixel->x + colorMat[1][1] * currentPixel->y + colorMat[2][1] * currentPixel->z; float tempY = colorMat[0][1] * currentPixel.x + colorMat[1][1] * currentPixel.y + colorMat[2][1] * currentPixel.z; float tempZ = colorMat[0][2] * currentPixel->x + colorMat[1][2] * currentPixel->y + colorMat[2][2] * currentPixel->z; float tempZ = colorMat[0][2] * currentPixel.x + colorMat[1][2] * currentPixel.y + colorMat[2][2] * currentPixel.z; currentPixel->x = tempX; currentPixel.x = tempX; currentPixel->y = tempY; currentPixel.y = tempY; currentPixel->z = tempZ; currentPixel.z = tempZ; // Clamp to 0..255 // Clamp to 0..255 // Inline the code here to avoid funciton calls // Inline the code here to avoid funciton calls currentPixel->x = currentPixel->x > 255.0f ? 255.0f : currentPixel->x; currentPixel.x = currentPixel.x > 255.0f ? 255.0f : currentPixel.x; currentPixel->y = currentPixel->y > 255.0f ? 255.0f : currentPixel->y; currentPixel.y = currentPixel.y > 255.0f ? 255.0f : currentPixel.y; currentPixel->z = currentPixel->z > 255.0f ? 255.0f : currentPixel->z; currentPixel.z = currentPixel.z > 255.0f ? 255.0f : currentPixel.z; currentPixel->x = currentPixel->x <= 0.0f ? 0.1f : currentPixel->x; currentPixel.x = currentPixel.x <= 0.0f ? 0.1f : currentPixel.x; currentPixel->y = currentPixel->y <= 0.0f ? 0.1f : currentPixel->y; currentPixel.y = currentPixel.y <= 0.0f ? 0.1f : currentPixel.y; currentPixel->z = currentPixel->z <= 0.0f ? 0.1f : currentPixel->z; currentPixel.z = currentPixel.z <= 0.0f ? 0.1f : currentPixel.z; currentPixel->x = pow( (currentPixel->x - inBlack) / (inWMinInB), gamma) * (outWMinOutB) + outBlack; currentPixel.x = pow( (currentPixel.x - inBlack) * overInWMinInB, gamma) * outWMinOutB + outBlack; currentPixel->y = pow( (currentPixel->y - inBlack) / (inWMinInB), gamma) * (outWMinOutB) + outBlack; currentPixel.y = pow( (currentPixel.y - inBlack) * overInWMinInB, gamma) * outWMinOutB + outBlack; currentPixel->z = pow( (currentPixel->z - inBlack) / (inWMinInB), gamma) * (outWMinOutB) + outBlack; currentPixel.z = pow( (currentPixel.z - inBlack) * overInWMinInB, gamma) * outWMinOutB + outBlack; currentPixel->x = currentPixel->x > 255.0f ? 255.0f : currentPixel->x; currentPixel.x = currentPixel.x > 255.0f ? 255.0f : currentPixel.x; currentPixel->y = currentPixel->y > 255.0f ? 255.0f : currentPixel->y; currentPixel.y = currentPixel.y > 255.0f ? 255.0f : currentPixel.y; currentPixel->z = currentPixel->z > 255.0f ? 255.0f : currentPixel->z; currentPixel.z = currentPixel.z > 255.0f ? 255.0f : currentPixel.z; currentPixel->x = currentPixel->x <= 0.0f ? 0.1f : currentPixel->x; currentPixel.x = currentPixel.x <= 0.0f ? 0.1f : currentPixel.x; currentPixel->y = currentPixel->y <= 0.0f ? 0.1f : currentPixel->y; currentPixel.y = currentPixel.y <= 0.0f ? 0.1f : currentPixel.y; currentPixel->z = currentPixel->z <= 0.0f ? 0.1f : currentPixel->z; currentPixel.z = currentPixel.z <= 0.0f ? 0.1f : currentPixel.z; #else float3 temp; // Color matrix multiply temp.x = colorMat[0][0] * currentPixel.x + colorMat[1][0] * currentPixel.y + colorMat[2][0] * currentPixel.z; temp.y = colorMat[0][1] * currentPixel.x + colorMat[1][1] * currentPixel.y + colorMat[2][1] * currentPixel.z; temp.z = colorMat[0][2] * currentPixel.x + colorMat[1][2] * currentPixel.y + colorMat[2][2] * currentPixel.z; temp = (clamp(temp, 0.1f, 255.f) - inBlack) * overInWMinInB; temp = pow(temp, (float3)gamma); currentPixel.xyz = clamp(temp * outWMinOutB + outBlack, 0.1f, 255.f); #endif return currentPixel; } } void processNoBlur() { static void processNoBlur() { int w, h, r; int w, h, r; int count = 0; int count = 0; Loading @@ -156,7 +172,7 @@ void processNoBlur() { currentPixel.y = (float)(input->g); currentPixel.y = (float)(input->g); currentPixel.z = (float)(input->b); currentPixel.z = (float)(input->b); levelsSaturation(¤tPixel); currentPixel = levelsSaturation(currentPixel); c4u_t *output = OutPixel + h*width + w; c4u_t *output = OutPixel + h*width + w; output->r = (uint8_t)currentPixel.x; output->r = (uint8_t)currentPixel.x; Loading @@ -168,7 +184,7 @@ void processNoBlur() { rsSendToClient(&count, 1, 4, 0); rsSendToClient(&count, 1, 4, 0); } } void horizontalBlur() { static void horizontalBlur() { float4 blurredPixel = 0; float4 blurredPixel = 0; float4 currentPixel = 0; float4 currentPixel = 0; // Horizontal blur // Horizontal blur Loading Loading @@ -209,7 +225,7 @@ void horizontalBlur() { } } } } void horizontalBlurLevels() { static void horizontalBlurLevels() { float4 blurredPixel = 0; float4 blurredPixel = 0; float4 currentPixel = 0; float4 currentPixel = 0; // Horizontal blur // Horizontal blur Loading Loading @@ -241,7 +257,7 @@ void horizontalBlurLevels() { blurredPixel += currentPixel*weight; blurredPixel += currentPixel*weight; } } levelsSaturation(&blurredPixel); blurredPixel = levelsSaturation(blurredPixel); c4u_t *output = ScratchPixel + h*width + w; c4u_t *output = ScratchPixel + h*width + w; output->r = (uint8_t)blurredPixel.x; output->r = (uint8_t)blurredPixel.x; Loading @@ -252,7 +268,7 @@ void horizontalBlurLevels() { } } } } void verticalBlur() { static void verticalBlur() { float4 blurredPixel = 0; float4 blurredPixel = 0; float4 currentPixel = 0; float4 currentPixel = 0; // Vertical blur // Vertical blur Loading libs/rs/java/ImageProcessing/res/raw/threshold_bc.bc −248 B (8.32 KiB) File changed.No diff preview for this file type. View original file View changed file libs/rs/java/ImageProcessing/src/com/android/rs/image/ScriptC_Threshold.java +2 −2 Original line number Original line Diff line number Diff line Loading @@ -102,12 +102,12 @@ public class ScriptC_Threshold setVar(mFieldIndex_hue, v); setVar(mFieldIndex_hue, v); } } private final static int mInvokableIndex_Filter = 2; private final static int mInvokableIndex_Filter = 4; public void invokable_Filter() { public void invokable_Filter() { invokeData(mInvokableIndex_Filter); invokeData(mInvokableIndex_Filter); } } private final static int mInvokableIndex_FilterBenchmark = 3; private final static int mInvokableIndex_FilterBenchmark = 5; public void invokable_FilterBenchmark() { public void invokable_FilterBenchmark() { invokeData(mInvokableIndex_FilterBenchmark); invokeData(mInvokableIndex_FilterBenchmark); } } Loading Loading
libs/rs/java/ImageProcessing/res/raw/threshold.rs +55 −39 Original line number Original line Diff line number Diff line Loading @@ -26,17 +26,19 @@ float gamma; float saturation; float saturation; float inWMinInB; static float inWMinInB; float outWMinOutB; static float outWMinOutB; static float overInWMinInB; //static float3 gammaV; #pragma rs export_var(height, width, radius, InPixel, OutPixel, ScratchPixel, inBlack, outBlack, inWhite, outWhite, gamma, saturation) #pragma rs export_var(height, width, radius, InPixel, OutPixel, ScratchPixel, inBlack, outBlack, inWhite, outWhite, gamma, saturation) #pragma rs export_func(filter, processNoBlur, computeColorMatrix, computeGaussianWeights); #pragma rs export_func(filter, filterBenchmark); // Store our coefficients here // Store our coefficients here float gaussian[MAX_RADIUS * 2 + 1]; static float gaussian[MAX_RADIUS * 2 + 1]; float colorMat[4][4]; static float colorMat[4][4]; void computeColorMatrix() { static void computeColorMatrix() { // Saturation // Saturation // Linear weights // Linear weights //float rWeight = 0.3086f; //float rWeight = 0.3086f; Loading Loading @@ -64,9 +66,10 @@ void computeColorMatrix() { inWMinInB = inWhite - inBlack; inWMinInB = inWhite - inBlack; outWMinOutB = outWhite - outBlack; outWMinOutB = outWhite - outBlack; overInWMinInB = 1.f / inWMinInB; } } void computeGaussianWeights() { static void computeGaussianWeights() { // Compute gaussian weights for the blur // Compute gaussian weights for the blur // e is the euler's number // e is the euler's number float e = 2.718281828459045f; float e = 2.718281828459045f; Loading Loading @@ -107,40 +110,53 @@ void computeGaussianWeights() { } } // This needs to be inline // This needs to be inline void levelsSaturation(float4 *currentPixel) { static float4 levelsSaturation(float4 currentPixel) { #if 0 // Color matrix multiply // Color matrix multiply float tempX = colorMat[0][0] * currentPixel->x + colorMat[1][0] * currentPixel->y + colorMat[2][0] * currentPixel->z; float tempX = colorMat[0][0] * currentPixel.x + colorMat[1][0] * currentPixel.y + colorMat[2][0] * currentPixel.z; float tempY = colorMat[0][1] * currentPixel->x + colorMat[1][1] * currentPixel->y + colorMat[2][1] * currentPixel->z; float tempY = colorMat[0][1] * currentPixel.x + colorMat[1][1] * currentPixel.y + colorMat[2][1] * currentPixel.z; float tempZ = colorMat[0][2] * currentPixel->x + colorMat[1][2] * currentPixel->y + colorMat[2][2] * currentPixel->z; float tempZ = colorMat[0][2] * currentPixel.x + colorMat[1][2] * currentPixel.y + colorMat[2][2] * currentPixel.z; currentPixel->x = tempX; currentPixel.x = tempX; currentPixel->y = tempY; currentPixel.y = tempY; currentPixel->z = tempZ; currentPixel.z = tempZ; // Clamp to 0..255 // Clamp to 0..255 // Inline the code here to avoid funciton calls // Inline the code here to avoid funciton calls currentPixel->x = currentPixel->x > 255.0f ? 255.0f : currentPixel->x; currentPixel.x = currentPixel.x > 255.0f ? 255.0f : currentPixel.x; currentPixel->y = currentPixel->y > 255.0f ? 255.0f : currentPixel->y; currentPixel.y = currentPixel.y > 255.0f ? 255.0f : currentPixel.y; currentPixel->z = currentPixel->z > 255.0f ? 255.0f : currentPixel->z; currentPixel.z = currentPixel.z > 255.0f ? 255.0f : currentPixel.z; currentPixel->x = currentPixel->x <= 0.0f ? 0.1f : currentPixel->x; currentPixel.x = currentPixel.x <= 0.0f ? 0.1f : currentPixel.x; currentPixel->y = currentPixel->y <= 0.0f ? 0.1f : currentPixel->y; currentPixel.y = currentPixel.y <= 0.0f ? 0.1f : currentPixel.y; currentPixel->z = currentPixel->z <= 0.0f ? 0.1f : currentPixel->z; currentPixel.z = currentPixel.z <= 0.0f ? 0.1f : currentPixel.z; currentPixel->x = pow( (currentPixel->x - inBlack) / (inWMinInB), gamma) * (outWMinOutB) + outBlack; currentPixel.x = pow( (currentPixel.x - inBlack) * overInWMinInB, gamma) * outWMinOutB + outBlack; currentPixel->y = pow( (currentPixel->y - inBlack) / (inWMinInB), gamma) * (outWMinOutB) + outBlack; currentPixel.y = pow( (currentPixel.y - inBlack) * overInWMinInB, gamma) * outWMinOutB + outBlack; currentPixel->z = pow( (currentPixel->z - inBlack) / (inWMinInB), gamma) * (outWMinOutB) + outBlack; currentPixel.z = pow( (currentPixel.z - inBlack) * overInWMinInB, gamma) * outWMinOutB + outBlack; currentPixel->x = currentPixel->x > 255.0f ? 255.0f : currentPixel->x; currentPixel.x = currentPixel.x > 255.0f ? 255.0f : currentPixel.x; currentPixel->y = currentPixel->y > 255.0f ? 255.0f : currentPixel->y; currentPixel.y = currentPixel.y > 255.0f ? 255.0f : currentPixel.y; currentPixel->z = currentPixel->z > 255.0f ? 255.0f : currentPixel->z; currentPixel.z = currentPixel.z > 255.0f ? 255.0f : currentPixel.z; currentPixel->x = currentPixel->x <= 0.0f ? 0.1f : currentPixel->x; currentPixel.x = currentPixel.x <= 0.0f ? 0.1f : currentPixel.x; currentPixel->y = currentPixel->y <= 0.0f ? 0.1f : currentPixel->y; currentPixel.y = currentPixel.y <= 0.0f ? 0.1f : currentPixel.y; currentPixel->z = currentPixel->z <= 0.0f ? 0.1f : currentPixel->z; currentPixel.z = currentPixel.z <= 0.0f ? 0.1f : currentPixel.z; #else float3 temp; // Color matrix multiply temp.x = colorMat[0][0] * currentPixel.x + colorMat[1][0] * currentPixel.y + colorMat[2][0] * currentPixel.z; temp.y = colorMat[0][1] * currentPixel.x + colorMat[1][1] * currentPixel.y + colorMat[2][1] * currentPixel.z; temp.z = colorMat[0][2] * currentPixel.x + colorMat[1][2] * currentPixel.y + colorMat[2][2] * currentPixel.z; temp = (clamp(temp, 0.1f, 255.f) - inBlack) * overInWMinInB; temp = pow(temp, (float3)gamma); currentPixel.xyz = clamp(temp * outWMinOutB + outBlack, 0.1f, 255.f); #endif return currentPixel; } } void processNoBlur() { static void processNoBlur() { int w, h, r; int w, h, r; int count = 0; int count = 0; Loading @@ -156,7 +172,7 @@ void processNoBlur() { currentPixel.y = (float)(input->g); currentPixel.y = (float)(input->g); currentPixel.z = (float)(input->b); currentPixel.z = (float)(input->b); levelsSaturation(¤tPixel); currentPixel = levelsSaturation(currentPixel); c4u_t *output = OutPixel + h*width + w; c4u_t *output = OutPixel + h*width + w; output->r = (uint8_t)currentPixel.x; output->r = (uint8_t)currentPixel.x; Loading @@ -168,7 +184,7 @@ void processNoBlur() { rsSendToClient(&count, 1, 4, 0); rsSendToClient(&count, 1, 4, 0); } } void horizontalBlur() { static void horizontalBlur() { float4 blurredPixel = 0; float4 blurredPixel = 0; float4 currentPixel = 0; float4 currentPixel = 0; // Horizontal blur // Horizontal blur Loading Loading @@ -209,7 +225,7 @@ void horizontalBlur() { } } } } void horizontalBlurLevels() { static void horizontalBlurLevels() { float4 blurredPixel = 0; float4 blurredPixel = 0; float4 currentPixel = 0; float4 currentPixel = 0; // Horizontal blur // Horizontal blur Loading Loading @@ -241,7 +257,7 @@ void horizontalBlurLevels() { blurredPixel += currentPixel*weight; blurredPixel += currentPixel*weight; } } levelsSaturation(&blurredPixel); blurredPixel = levelsSaturation(blurredPixel); c4u_t *output = ScratchPixel + h*width + w; c4u_t *output = ScratchPixel + h*width + w; output->r = (uint8_t)blurredPixel.x; output->r = (uint8_t)blurredPixel.x; Loading @@ -252,7 +268,7 @@ void horizontalBlurLevels() { } } } } void verticalBlur() { static void verticalBlur() { float4 blurredPixel = 0; float4 blurredPixel = 0; float4 currentPixel = 0; float4 currentPixel = 0; // Vertical blur // Vertical blur Loading
libs/rs/java/ImageProcessing/res/raw/threshold_bc.bc −248 B (8.32 KiB) File changed.No diff preview for this file type. View original file View changed file
libs/rs/java/ImageProcessing/src/com/android/rs/image/ScriptC_Threshold.java +2 −2 Original line number Original line Diff line number Diff line Loading @@ -102,12 +102,12 @@ public class ScriptC_Threshold setVar(mFieldIndex_hue, v); setVar(mFieldIndex_hue, v); } } private final static int mInvokableIndex_Filter = 2; private final static int mInvokableIndex_Filter = 4; public void invokable_Filter() { public void invokable_Filter() { invokeData(mInvokableIndex_Filter); invokeData(mInvokableIndex_Filter); } } private final static int mInvokableIndex_FilterBenchmark = 3; private final static int mInvokableIndex_FilterBenchmark = 5; public void invokable_FilterBenchmark() { public void invokable_FilterBenchmark() { invokeData(mInvokableIndex_FilterBenchmark); invokeData(mInvokableIndex_FilterBenchmark); } } Loading