diff options
author | Jason Sams <jsams@google.com> | 2012-09-13 11:07:33 -0700 |
---|---|---|
committer | Jason Sams <jsams@google.com> | 2012-09-13 11:07:33 -0700 |
commit | 8a95803738bd178876363406309ff2ae1570c8fe (patch) | |
tree | e2eccd3c3e6440a66404ae4e6216a0c7da57942c /tests | |
parent | 73e0d75c9d3869a39635e55461349b3f5dd75604 (diff) | |
download | frameworks_base-8a95803738bd178876363406309ff2ae1570c8fe.zip frameworks_base-8a95803738bd178876363406309ff2ae1570c8fe.tar.gz frameworks_base-8a95803738bd178876363406309ff2ae1570c8fe.tar.bz2 |
Fix bugs in grain where values could go out of bounds.
Change-Id: Ib2cc3177424cf24bc81b75786dfd9be30fea5378
Diffstat (limited to 'tests')
-rw-r--r-- | tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/grain.rs | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/grain.rs b/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/grain.rs index 7d9d3ac..783bc4a 100644 --- a/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/grain.rs +++ b/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/grain.rs @@ -43,9 +43,9 @@ int32_t gHeight; rs_allocation gBlendSource; void blend9(uchar *out, uint32_t x, uint32_t y) { - uint32_t x1 = min((int32_t)x+1, (int32_t)gWidth); + uint32_t x1 = min((int32_t)x+1, (int32_t)(gWidth -1)); uint32_t x2 = max((int32_t)x-1, (int32_t)0); - uint32_t y1 = min((int32_t)y+1, (int32_t)gHeight); + uint32_t y1 = min((int32_t)y+1, (int32_t)(gHeight -1)); uint32_t y2 = max((int32_t)y-1, (int32_t)0); uint p00 = 56 * ((uchar *)rsGetElementAt(gBlendSource, x1, y1))[0]; @@ -69,7 +69,8 @@ void blend9(uchar *out, uint32_t x, uint32_t y) { p20 += p22; p20 += p02; - *out = (uchar)(p20 >> 10); + p20 = min(p20 >> 10, (uint)255); + *out = (uchar)p20; } float gNoiseStrength; |