diff options
Diffstat (limited to 'java/tests/ImageProcessing_jb/src/com/android/rs/image/wbalance.rs')
-rw-r--r-- | java/tests/ImageProcessing_jb/src/com/android/rs/image/wbalance.rs | 42 |
1 files changed, 12 insertions, 30 deletions
diff --git a/java/tests/ImageProcessing_jb/src/com/android/rs/image/wbalance.rs b/java/tests/ImageProcessing_jb/src/com/android/rs/image/wbalance.rs index 58f64d10..c46c4912 100644 --- a/java/tests/ImageProcessing_jb/src/com/android/rs/image/wbalance.rs +++ b/java/tests/ImageProcessing_jb/src/com/android/rs/image/wbalance.rs @@ -17,37 +17,19 @@ #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; - +rs_allocation histogramValues; static float3 scale; 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]; + int4 hv = rsGetElementAt_int4(histogramValues, i); + int r = hv.r; + int g = hv.g; + int b = hv.b; sum_r += r; sum_g += g; sum_b += b; @@ -71,9 +53,10 @@ static uchar4 estimateWhite() { 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]; + int4 hv = rsGetElementAt_int4(histogramValues, i); + int r = hv.r; + int g = hv.g; + int b = hv.b; tmp_r += r; tmp_g += g; tmp_b += b; @@ -113,9 +96,9 @@ void prepareWhiteBalance() { int maximum = max(estimation.r, max(estimation.g, estimation.b)); float avg = (minimum + maximum) / 2.f; - scale.r = avg/estimation.r; - scale.g = avg/estimation.g; - scale.b = avg/estimation.b; + scale.r = avg / estimation.r; + scale.g = avg / estimation.g; + scale.b = avg / estimation.b; } uchar4 RS_KERNEL whiteBalanceKernel(uchar4 in) { @@ -128,4 +111,3 @@ uchar4 RS_KERNEL whiteBalanceKernel(uchar4 in) { out.a = 255; return out; } - |