Re-factor checkBufYUV() function to more closely resemble re-factored checkBuf() function

git-svn-id: svn+ssh://svn.code.sf.net/p/libjpeg-turbo/code/trunk@654 632fc199-4ca6-4c93-a231-07263d6284db
This commit is contained in:
DRC
2011-05-27 02:10:42 +00:00
parent ac906c5308
commit 215aa8b78b
2 changed files with 58 additions and 71 deletions

View File

@@ -412,7 +412,7 @@ public class TJUnitTest {
private static int checkBufYUV(byte[] buf, int size, int w, int h, private static int checkBufYUV(byte[] buf, int size, int w, int h,
int subsamp) throws Exception { int subsamp) throws Exception {
int i, j; int row, col;
int hsf = TJ.getMCUWidth(subsamp)/8, vsf = TJ.getMCUHeight(subsamp)/8; int hsf = TJ.getMCUWidth(subsamp)/8, vsf = TJ.getMCUHeight(subsamp)/8;
int pw = PAD(w, hsf), ph = PAD(h, vsf); int pw = PAD(w, hsf), ph = PAD(h, vsf);
int cw = pw / hsf, ch = ph / vsf; int cw = pw / hsf, ch = ph / vsf;
@@ -420,48 +420,45 @@ public class TJUnitTest {
int retval = 1; int retval = 1;
int correctsize = ypitch * ph int correctsize = ypitch * ph
+ (subsamp == TJ.SAMP_GRAY ? 0 : uvpitch * ch * 2); + (subsamp == TJ.SAMP_GRAY ? 0 : uvpitch * ch * 2);
int halfway = 16;
try { try {
if(size != correctsize) if(size != correctsize)
throw new Exception("\nIncorrect size " + size + ". Should be " throw new Exception("\nIncorrect size " + size + ". Should be "
+ correctsize); + correctsize);
for(i = 0; i < 16; i++) { for(row = 0; row < ph; row++) {
for(j = 0; j < pw; j++) { for(col = 0; col < pw; col++) {
byte y = buf[ypitch * i + j]; byte y = buf[ypitch * row + col];
if(((i / 8) + (j / 8)) % 2 == 0) checkVal255(i, j, y, "Y"); if(((row / 8) + (col / 8)) % 2 == 0) {
else checkVal(i, j, y, "Y", 76); if(row < halfway) checkVal255(row, col, y, "Y");
} else checkVal0(row, col, y, "Y");
} }
for(i = 16; i < ph; i++) { else {
for(j = 0; j < pw; j++) { if(row < halfway) checkVal(row, col, y, "Y", 76);
byte y = buf[ypitch * i + j]; else checkVal(row, col, y, "Y", 226);
if(((i / 8) + (j / 8)) % 2 == 0) checkVal0(i, j, y, "Y"); }
else checkVal(i, j, y, "Y", 226);
} }
} }
if(subsamp != TJ.SAMP_GRAY) { if(subsamp != TJ.SAMP_GRAY) {
for(i = 0; i < 16 / vsf; i++) { halfway = 16 / vsf;
for(j = 0; j < cw; j++) { for(row = 0; row < ch; row++) {
byte u = buf[ypitch * ph + (uvpitch * i + j)], for(col = 0; col < cw; col++) {
v = buf[ypitch * ph + uvpitch * ch + (uvpitch * i + j)]; byte u = buf[ypitch * ph + (uvpitch * row + col)],
if(((i * vsf / 8) + (j * hsf / 8)) % 2 == 0) { v = buf[ypitch * ph + uvpitch * ch + (uvpitch * row + col)];
checkVal(i, j, u, "U", 128); checkVal(i, j, v, "V", 128); if(((row * vsf / 8) + (col * hsf / 8)) % 2 == 0) {
checkVal(row, col, u, "U", 128);
checkVal(row, col, v, "V", 128);
} }
else { else {
checkVal(i, j, u, "U", 85); checkVal255(i, j, v, "V"); if(row < halfway) {
} checkVal(row, col, u, "U", 85);
} checkVal255(row, col, v, "V");
} }
for(i = 16 / vsf; i < ch; i++) { else {
for(j = 0; j < cw; j++) { checkVal0(row, col, u, "U");
byte u = buf[ypitch * ph + (uvpitch * i + j)], checkVal(row, col, v, "V", 149);
v = buf[ypitch * ph + uvpitch * ch + (uvpitch * i + j)]; }
if(((i * vsf / 8) + (j * hsf / 8)) % 2 == 0) {
checkVal(i, j, u, "U", 128); checkVal(i, j, v, "V", 128);
}
else {
checkVal0(i, j, u, "U"); checkVal(i, j, v, "V", 149);
} }
} }
} }
@@ -473,27 +470,27 @@ public class TJUnitTest {
} }
if(retval == 0) { if(retval == 0) {
for(i = 0; i < ph; i++) { for(row = 0; row < ph; row++) {
for(j = 0; j < pw; j++) { for(col = 0; col < pw; col++) {
int y = buf[ypitch * i + j]; int y = buf[ypitch * row + col];
if(y < 0) y += 256; if(y < 0) y += 256;
System.out.format("%3d ", y); System.out.format("%3d ", y);
} }
System.out.print("\n"); System.out.print("\n");
} }
System.out.print("\n"); System.out.print("\n");
for(i = 0; i < ch; i++) { for(row = 0; row < ch; row++) {
for(j = 0; j < cw; j++) { for(col = 0; col < cw; col++) {
int u = buf[ypitch * ph + (uvpitch * i + j)]; int u = buf[ypitch * ph + (uvpitch * row + col)];
if(u < 0) u += 256; if(u < 0) u += 256;
System.out.format("%3d ", u); System.out.format("%3d ", u);
} }
System.out.print("\n"); System.out.print("\n");
} }
System.out.print("\n"); System.out.print("\n");
for(i = 0; i < ch; i++) { for(row = 0; row < ch; row++) {
for(j = 0; j < cw; j++) { for(col = 0; col < cw; col++) {
int v = buf[ypitch * ph + uvpitch * ch + (uvpitch * i + j)]; int v = buf[ypitch * ph + uvpitch * ch + (uvpitch * row + col)];
if(v < 0) v += 256; if(v < 0) v += 256;
System.out.format("%3d ", v); System.out.format("%3d ", v);
} }

View File

@@ -247,28 +247,27 @@ int checkBufYUV(unsigned char *buf, int w, int h, int subsamp)
int cw=pw/hsf, ch=ph/vsf; int cw=pw/hsf, ch=ph/vsf;
int ypitch=PAD(pw, 4), uvpitch=PAD(cw, 4); int ypitch=PAD(pw, 4), uvpitch=PAD(cw, 4);
int retval=1; int retval=1;
int halfway=16;
for(row=0; row<16; row++) for(row=0; row<ph; row++)
{ {
for(col=0; col<pw; col++) for(col=0; col<pw; col++)
{ {
unsigned char y=buf[ypitch*row+col]; unsigned char y=buf[ypitch*row+col];
if(((row/8)+(col/8))%2==0) checkval255(y) if(((row/8)+(col/8))%2==0)
else checkval(y, 76) {
} if(row<halfway) checkval255(y) else checkval0(y);
} }
for(row=16; row<ph; row++) else
{ {
for(col=0; col<pw; col++) if(row<halfway) checkval(y, 76) else checkval(y, 226);
{ }
unsigned char y=buf[ypitch*row+col];
if(((row/8)+(col/8))%2==0) checkval0(y)
else checkval(y, 226)
} }
} }
if(subsamp!=TJSAMP_GRAY) if(subsamp!=TJSAMP_GRAY)
{ {
for(row=0; row<16/vsf; row++) halfway=16/vsf;
for(row=0; row<ch; row++)
{ {
for(col=0; col<cw; col++) for(col=0; col<cw; col++)
{ {
@@ -280,23 +279,14 @@ int checkBufYUV(unsigned char *buf, int w, int h, int subsamp)
} }
else else
{ {
checkval(u, 85); checkval255(v); if(row<halfway)
} {
} checkval(u, 85); checkval255(v);
} }
for(row=16/vsf; row<ch; row++) else
{ {
for(col=0; col<cw; col++) checkval0(u); checkval(v, 149);
{ }
unsigned char u=buf[ypitch*ph + (uvpitch*row+col)],
v=buf[ypitch*ph + uvpitch*ch + (uvpitch*row+col)];
if(((row*vsf/8)+(col*hsf/8))%2==0)
{
checkval(u, 128); checkval(v, 128);
}
else
{
checkval0(u); checkval(v, 149);
} }
} }
} }