diff options
author | Treehugger Robot <treehugger-gerrit@google.com> | 2023-03-19 07:22:55 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2023-03-19 07:22:55 +0000 |
commit | bbd87d959729768899c90458ff9669aef57b3846 (patch) | |
tree | 7e917e6915033c650e5215dfaeedde023878e9c2 | |
parent | f5be8edd6c9ab935b32c4635a8d896e42a1528aa (diff) | |
parent | c55e65311c7b96d2a01d9624e318685c0cc12654 (diff) | |
download | Gallery2-bbd87d959729768899c90458ff9669aef57b3846.tar.gz |
Merge "Check for Potential Null Pointer" am: d307c0f8c5 am: e0c9efaacb am: d44628ce3a am: c55e65311candroid-14.0.0_r45android-14.0.0_r44android-14.0.0_r43android-14.0.0_r42android-14.0.0_r41android-14.0.0_r40android-14.0.0_r39android-14.0.0_r38android-14.0.0_r27android-14.0.0_r26android-14.0.0_r25android-14.0.0_r24android-14.0.0_r23android-14.0.0_r22android-14.0.0_r21android-14.0.0_r20android-14.0.0_r19android-14.0.0_r18android-14.0.0_r17android-14.0.0_r16android14-qpr1-s2-releaseandroid14-qpr1-releaseandroid14-d2-s5-releaseandroid14-d2-s4-releaseandroid14-d2-s3-releaseandroid14-d2-s2-releaseandroid14-d2-s1-releaseandroid14-d2-release
Original change: https://android-review.googlesource.com/c/platform/packages/apps/Gallery2/+/2431892
Change-Id: I1003bf125a8a35ad179b7fcdb33d51227a7cec56
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r-- | jni/filters/edge.c | 4 | ||||
-rw-r--r-- | jni/filters/geometry.c | 12 | ||||
-rw-r--r-- | jni/filters/wbalance.c | 56 |
3 files changed, 35 insertions, 37 deletions
diff --git a/jni/filters/edge.c b/jni/filters/edge.c index 5e7be3c4c..75e99a1c9 100644 --- a/jni/filters/edge.c +++ b/jni/filters/edge.c @@ -46,7 +46,7 @@ void JNIFUNCF(ImageFilterEdge, nativeApplyFilter, jobject bitmap, jint width, ji // set initial buffer to black memset(buf, 0, buf_len * sizeof(char)); for (j = 3; j < buf_len; j+=4) { - *(buf + j) = 255; // set initial alphas + *(buf + j) = (uint8_t) 255; // set initial alphas } // apply sobel filter @@ -120,7 +120,7 @@ void JNIFUNCF(ImageFilterEdge, nativeApplyFilter, jobject bitmap, jint width, ji int last_row = row_stride * (height - 1); memset((dst + last_row), 0, row_stride * sizeof(char)); for (j = 3; j < row_stride; j+=4) { - *(dst + last_row + j) = 255; // set alphas + *(dst + last_row + j) = (uint8_t) 255; // set alphas } AndroidBitmap_unlockPixels(env, bitmap); } diff --git a/jni/filters/geometry.c b/jni/filters/geometry.c index c2d80f380..023092208 100644 --- a/jni/filters/geometry.c +++ b/jni/filters/geometry.c @@ -170,11 +170,13 @@ void JNIFUNCF(ImageFilterGeometry, nativeApplyFilterStraighten, jobject src, jin AndroidBitmap_lockPixels(env, src, (void**) &source); AndroidBitmap_lockPixels(env, dst, (void**) &destination); // TODO: implement straighten - int i = 0; - for (; i < len; i += 4) { - destination[RED] = 128; - destination[GREEN] = source[GREEN]; - destination[BLUE] = 128; + if (source != NULL && destination != NULL) { + int i = 0; + for (; i < len; i += 4) { + destination[RED] = (uint8_t) 128; + destination[GREEN] = (uint8_t) source[GREEN]; + destination[BLUE] = (uint8_t) 128; + } } AndroidBitmap_unlockPixels(env, dst); AndroidBitmap_unlockPixels(env, src); diff --git a/jni/filters/wbalance.c b/jni/filters/wbalance.c index 99a7d2e0d..2ca4c7273 100644 --- a/jni/filters/wbalance.c +++ b/jni/filters/wbalance.c @@ -18,7 +18,7 @@ #include "filters.h" -void estmateWhite(unsigned char *src, int len, int *wr, int *wb, int *wg){ +void estmateWhite(unsigned char *src, int len, int *wr, int *wb, int *wg) { int STEP = 4; int RANGE = 256; @@ -27,7 +27,7 @@ void estmateWhite(unsigned char *src, int len, int *wr, int *wb, int *wg){ int *histB = (int *) malloc(256*sizeof(int)); int i; for (i = 0; i < 255; i++) { - histR[i] = histG[i] = histB[i] =0; + histR[i] = histG[i] = histB[i] = 0; } for (i = 0; i < len; i+=STEP) { @@ -35,9 +35,8 @@ void estmateWhite(unsigned char *src, int len, int *wr, int *wb, int *wg){ histG[(src[GREEN])]++; histB[(src[BLUE])]++; } - 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; + int min_r = -1, min_g = -1, min_b = -1; + int sum_r = 0, sum_g = 0, sum_b = 0; for (i = 1; i < RANGE-1; i++) { int r = histR[i]; @@ -47,25 +46,22 @@ void estmateWhite(unsigned char *src, int len, int *wr, int *wb, int *wg){ sum_g += g; sum_b += b; - if (r>0){ - if (min_r < 0) min_r = i; - max_r = i; + if (r > 0 && min_r < 0) { + min_r = i; } - if (g>0){ - if (min_g < 0) min_g = i; - max_g = i; + if (g > 0 && min_g < 0) { + min_g = i; } - if (b>0){ - if (min_b < 0) min_b = i; - max_b = i; + if (b > 0 && min_b < 0) { + min_b = i; } } - int sum15r = 0,sum15g=0,sum15b=0; - int count15r = 0,count15g=0,count15b=0; - int tmp_r = 0,tmp_g=0,tmp_b=0; + int sum15r = 0, sum15g = 0, sum15b = 0; + int count15r = 0, count15g=0, count15b = 0; + int tmp_r = 0, tmp_g = 0, tmp_b = 0; - for (i = RANGE-2; i >0; i--) { + for (i = RANGE-2; i > 0; i--) { int r = histR[i]; int g = histG[i]; int b = histB[i]; @@ -91,33 +87,33 @@ void estmateWhite(unsigned char *src, int len, int *wr, int *wb, int *wg){ free(histG); free(histB); - if ((count15r>0) && (count15g>0) && (count15b>0) ){ + if ((count15r > 0) && (count15g > 0) && (count15b > 0)) { *wr = sum15r/count15r; *wb = sum15g/count15g; *wg = sum15b/count15b; - }else { + } else { *wg = *wb = *wr=255; } } -void estmateWhiteBox(unsigned char *src, int iw, int ih, int x,int y, int *wr, int *wb, int *wg){ +void estmateWhiteBox(unsigned char *src, int iw, int ih, int x,int y, int *wr, int *wb, int *wg) { int r = 0; int g = 0; int b = 0; int sum = 0; - int xp,yp; + int xp, yp; int bounds = 5; - if (x<0) x = bounds; - if (y<0) y = bounds; - if (x>=(iw-bounds)) x = (iw-bounds-1); - if (y>=(ih-bounds)) y = (ih-bounds-1); + if (x < 0) x = bounds; + if (y < 0) y = bounds; + if (x >= (iw-bounds)) x = (iw-bounds-1); + if (y >= (ih-bounds)) y = (ih-bounds-1); int startx = x - bounds; int starty = y - bounds; int endx = x + bounds; int endy = y + bounds; - for(yp= starty;yp<endy;yp++) { - for(xp= startx;xp<endx;xp++) { + for (yp = starty; yp < endy; yp++) { + for (xp = startx; xp < endx; xp++) { int i = 4*(xp+yp*iw); r += src[RED]; g += src[GREEN]; @@ -141,7 +137,7 @@ void JNIFUNCF(ImageFilterWBalance, nativeApplyFilter, jobject bitmap, jint width int wg; int wb; - if (locX==-1) + if (locX == -1) estmateWhite(rgb,len,&wr,&wg,&wb); else estmateWhiteBox(rgb, width, height,locX,locY,&wr,&wg,&wb); @@ -153,7 +149,7 @@ void JNIFUNCF(ImageFilterWBalance, nativeApplyFilter, jobject bitmap, jint width float scaleG = avg/wg; float scaleB = avg/wb; - for (i = 0; i < len; i+=4) + for (i = 0; i < len; i += 4) { int r = rgb[RED]; int g = rgb[GREEN]; |