From d04112d27f12613381611dc870807e7f39c7b8b7 Mon Sep 17 00:00:00 2001 From: James Zern Date: Fri, 31 Jan 2014 15:49:17 -0800 Subject: [PATCH 1/2] vpxenc: cosmetics find_mismatch() / compare_img(): const, whitespace Change-Id: I1c65c2aac378535001720aca31e7437ee5492739 --- vpxenc.c | 54 +++++++++++++++++++++++++++++------------------------- 1 file changed, 29 insertions(+), 25 deletions(-) diff --git a/vpxenc.c b/vpxenc.c index f772432ad..870968193 100644 --- a/vpxenc.c +++ b/vpxenc.c @@ -474,7 +474,8 @@ void usage_exit() { } #define mmin(a, b) ((a) < (b) ? (a) : (b)) -static void find_mismatch(vpx_image_t *img1, vpx_image_t *img2, +static void find_mismatch(const vpx_image_t *const img1, + const vpx_image_t *const img2, int yloc[4], int uloc[4], int vloc[4]) { const unsigned int bsize = 64; const unsigned int bsizey = bsize >> img1->y_chroma_shift; @@ -487,10 +488,10 @@ static void find_mismatch(vpx_image_t *img1, vpx_image_t *img2, for (i = 0, match = 1; match && i < img1->d_h; i += bsize) { for (j = 0; match && j < img1->d_w; j += bsize) { int k, l; - int si = mmin(i + bsize, img1->d_h) - i; - int sj = mmin(j + bsize, img1->d_w) - j; - for (k = 0; match && k < si; k++) - for (l = 0; match && l < sj; l++) { + const int si = mmin(i + bsize, img1->d_h) - i; + const int sj = mmin(j + bsize, img1->d_w) - j; + for (k = 0; match && k < si; ++k) { + for (l = 0; match && l < sj; ++l) { if (*(img1->planes[VPX_PLANE_Y] + (i + k) * img1->stride[VPX_PLANE_Y] + j + l) != *(img2->planes[VPX_PLANE_Y] + @@ -505,6 +506,7 @@ static void find_mismatch(vpx_image_t *img1, vpx_image_t *img2, break; } } + } } } @@ -512,10 +514,10 @@ static void find_mismatch(vpx_image_t *img1, vpx_image_t *img2, for (i = 0, match = 1; match && i < c_h; i += bsizey) { for (j = 0; match && j < c_w; j += bsizex) { int k, l; - int si = mmin(i + bsizey, c_h - i); - int sj = mmin(j + bsizex, c_w - j); - for (k = 0; match && k < si; k++) - for (l = 0; match && l < sj; l++) { + const int si = mmin(i + bsizey, c_h - i); + const int sj = mmin(j + bsizex, c_w - j); + for (k = 0; match && k < si; ++k) { + for (l = 0; match && l < sj; ++l) { if (*(img1->planes[VPX_PLANE_U] + (i + k) * img1->stride[VPX_PLANE_U] + j + l) != *(img2->planes[VPX_PLANE_U] + @@ -525,21 +527,22 @@ static void find_mismatch(vpx_image_t *img1, vpx_image_t *img2, uloc[2] = *(img1->planes[VPX_PLANE_U] + (i + k) * img1->stride[VPX_PLANE_U] + j + l); uloc[3] = *(img2->planes[VPX_PLANE_U] + - (i + k) * img2->stride[VPX_PLANE_V] + j + l); + (i + k) * img2->stride[VPX_PLANE_U] + j + l); match = 0; break; } } + } } } vloc[0] = vloc[1] = vloc[2] = vloc[3] = -1; for (i = 0, match = 1; match && i < c_h; i += bsizey) { for (j = 0; match && j < c_w; j += bsizex) { int k, l; - int si = mmin(i + bsizey, c_h - i); - int sj = mmin(j + bsizex, c_w - j); - for (k = 0; match && k < si; k++) - for (l = 0; match && l < sj; l++) { + const int si = mmin(i + bsizey, c_h - i); + const int sj = mmin(j + bsizex, c_w - j); + for (k = 0; match && k < si; ++k) { + for (l = 0; match && l < sj; ++l) { if (*(img1->planes[VPX_PLANE_V] + (i + k) * img1->stride[VPX_PLANE_V] + j + l) != *(img2->planes[VPX_PLANE_V] + @@ -554,12 +557,13 @@ static void find_mismatch(vpx_image_t *img1, vpx_image_t *img2, break; } } + } } } } -static int compare_img(vpx_image_t *img1, vpx_image_t *img2) -{ +static int compare_img(const vpx_image_t *const img1, + const vpx_image_t *const img2) { const int c_w = (img1->d_w + img1->x_chroma_shift) >> img1->x_chroma_shift; const int c_h = (img1->d_h + img1->y_chroma_shift) >> img1->y_chroma_shift; int match = 1; @@ -569,19 +573,19 @@ static int compare_img(vpx_image_t *img1, vpx_image_t *img2) match &= (img1->d_w == img2->d_w); match &= (img1->d_h == img2->d_h); - for (i = 0; i < img1->d_h; i++) - match &= (memcmp(img1->planes[VPX_PLANE_Y]+i*img1->stride[VPX_PLANE_Y], - img2->planes[VPX_PLANE_Y]+i*img2->stride[VPX_PLANE_Y], + for (i = 0; i < img1->d_h; ++i) + match &= (memcmp(img1->planes[VPX_PLANE_Y] + i * img1->stride[VPX_PLANE_Y], + img2->planes[VPX_PLANE_Y] + i * img2->stride[VPX_PLANE_Y], img1->d_w) == 0); - for (i = 0; i < c_h; i++) - match &= (memcmp(img1->planes[VPX_PLANE_U]+i*img1->stride[VPX_PLANE_U], - img2->planes[VPX_PLANE_U]+i*img2->stride[VPX_PLANE_U], + for (i = 0; i < c_h; ++i) + match &= (memcmp(img1->planes[VPX_PLANE_U] + i * img1->stride[VPX_PLANE_U], + img2->planes[VPX_PLANE_U] + i * img2->stride[VPX_PLANE_U], c_w) == 0); - for (i = 0; i < c_h; i++) - match &= (memcmp(img1->planes[VPX_PLANE_V]+i*img1->stride[VPX_PLANE_U], - img2->planes[VPX_PLANE_V]+i*img2->stride[VPX_PLANE_U], + for (i = 0; i < c_h; ++i) + match &= (memcmp(img1->planes[VPX_PLANE_V] + i * img1->stride[VPX_PLANE_V], + img2->planes[VPX_PLANE_V] + i * img2->stride[VPX_PLANE_V], c_w) == 0); return match; From 6253e8ed477a2a529cd321a7c3d244996fd026fa Mon Sep 17 00:00:00 2001 From: James Zern Date: Fri, 31 Jan 2014 16:10:43 -0800 Subject: [PATCH 2/2] vpxenc: find_mismatch/compare_img: normalize types use uint32_t where appropriate, silences a few warnings Change-Id: Ic362b08868b00f4828982757a7bcee081d50308d --- vpxenc.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/vpxenc.c b/vpxenc.c index 870968193..07d570534 100644 --- a/vpxenc.c +++ b/vpxenc.c @@ -477,13 +477,15 @@ void usage_exit() { static void find_mismatch(const vpx_image_t *const img1, const vpx_image_t *const img2, int yloc[4], int uloc[4], int vloc[4]) { - const unsigned int bsize = 64; - const unsigned int bsizey = bsize >> img1->y_chroma_shift; - const unsigned int bsizex = bsize >> img1->x_chroma_shift; - const int c_w = (img1->d_w + img1->x_chroma_shift) >> img1->x_chroma_shift; - const int c_h = (img1->d_h + img1->y_chroma_shift) >> img1->y_chroma_shift; - unsigned int match = 1; - unsigned int i, j; + const uint32_t bsize = 64; + const uint32_t bsizey = bsize >> img1->y_chroma_shift; + const uint32_t bsizex = bsize >> img1->x_chroma_shift; + const uint32_t c_w = + (img1->d_w + img1->x_chroma_shift) >> img1->x_chroma_shift; + const uint32_t c_h = + (img1->d_h + img1->y_chroma_shift) >> img1->y_chroma_shift; + int match = 1; + uint32_t i, j; yloc[0] = yloc[1] = yloc[2] = yloc[3] = -1; for (i = 0, match = 1; match && i < img1->d_h; i += bsize) { for (j = 0; match && j < img1->d_w; j += bsize) { @@ -564,10 +566,12 @@ static void find_mismatch(const vpx_image_t *const img1, static int compare_img(const vpx_image_t *const img1, const vpx_image_t *const img2) { - const int c_w = (img1->d_w + img1->x_chroma_shift) >> img1->x_chroma_shift; - const int c_h = (img1->d_h + img1->y_chroma_shift) >> img1->y_chroma_shift; + const uint32_t c_w = + (img1->d_w + img1->x_chroma_shift) >> img1->x_chroma_shift; + const uint32_t c_h = + (img1->d_h + img1->y_chroma_shift) >> img1->y_chroma_shift; + uint32_t i; int match = 1; - unsigned int i; match &= (img1->fmt == img2->fmt); match &= (img1->d_w == img2->d_w);