private static int checkBufYUV(byte[] buf, int size, int w, int h, int subsamp) throws Exception { int row, col; int hsf = TJ.getMCUWidth(subsamp) / 8, vsf = TJ.getMCUHeight(subsamp) / 8; int pw = PAD(w, hsf), ph = PAD(h, vsf); int cw = pw / hsf, ch = ph / vsf; int ypitch = PAD(pw, 4), uvpitch = PAD(cw, 4); int retval = 1; int correctsize = ypitch * ph + (subsamp == TJ.SAMP_GRAY ? 0 : uvpitch * ch * 2); int halfway = 16; try { if (size != correctsize) throw new Exception("\nIncorrect size " + size + ". Should be " + correctsize); for (row = 0; row < ph; row++) { for (col = 0; col < pw; col++) { byte y = buf[ypitch * row + col]; if (((row / 8) + (col / 8)) % 2 == 0) { if (row < halfway) checkVal255(row, col, y, "Y"); else checkVal0(row, col, y, "Y"); } else { if (row < halfway) checkVal(row, col, y, "Y", 76); else checkVal(row, col, y, "Y", 226); } } } if (subsamp != TJ.SAMP_GRAY) { halfway = 16 / vsf; for (row = 0; row < ch; row++) { for (col = 0; col < cw; col++) { byte 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(row, col, u, "U", 128); checkVal(row, col, v, "V", 128); } else { if (row < halfway) { checkVal(row, col, u, "U", 85); checkVal255(row, col, v, "V"); } else { checkVal0(row, col, u, "U"); checkVal(row, col, v, "V", 149); } } } } } } catch (Exception e) { System.out.println(e); retval = 0; } if (retval == 0) { for (row = 0; row < ph; row++) { for (col = 0; col < pw; col++) { int y = buf[ypitch * row + col]; if (y < 0) y += 256; System.out.format("%3d ", y); } System.out.print("\n"); } System.out.print("\n"); for (row = 0; row < ch; row++) { for (col = 0; col < cw; col++) { int u = buf[ypitch * ph + (uvpitch * row + col)]; if (u < 0) u += 256; System.out.format("%3d ", u); } System.out.print("\n"); } System.out.print("\n"); for (row = 0; row < ch; row++) { for (col = 0; col < cw; col++) { int v = buf[ypitch * ph + uvpitch * ch + (uvpitch * row + col)]; if (v < 0) v += 256; System.out.format("%3d ", v); } System.out.print("\n"); } System.out.print("\n"); } return retval; }