Skip to content

Commit bd6acda

Browse files
Jason SamsAndroid (Google) Code Review
authored andcommitted
Merge "Fix bugs in grain where values could go out of bounds." into jb-mr1-dev
2 parents 24271a8 + 8a95803 commit bd6acda

File tree

1 file changed

+4
-3
lines changed
  • tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image

1 file changed

+4
-3
lines changed

tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/grain.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ int32_t gHeight;
4343

4444
rs_allocation gBlendSource;
4545
void blend9(uchar *out, uint32_t x, uint32_t y) {
46-
uint32_t x1 = min((int32_t)x+1, (int32_t)gWidth);
46+
uint32_t x1 = min((int32_t)x+1, (int32_t)(gWidth -1));
4747
uint32_t x2 = max((int32_t)x-1, (int32_t)0);
48-
uint32_t y1 = min((int32_t)y+1, (int32_t)gHeight);
48+
uint32_t y1 = min((int32_t)y+1, (int32_t)(gHeight -1));
4949
uint32_t y2 = max((int32_t)y-1, (int32_t)0);
5050

5151
uint p00 = 56 * ((uchar *)rsGetElementAt(gBlendSource, x1, y1))[0];
@@ -69,7 +69,8 @@ void blend9(uchar *out, uint32_t x, uint32_t y) {
6969
p20 += p22;
7070
p20 += p02;
7171

72-
*out = (uchar)(p20 >> 10);
72+
p20 = min(p20 >> 10, (uint)255);
73+
*out = (uchar)p20;
7374
}
7475

7576
float gNoiseStrength;

0 commit comments

Comments
 (0)