static int checkBuf()

in java/TJUnitTest.java [330:447]


  static int checkBuf(Object buf, int w, int pitch, int h, int pf, int subsamp,
                      TJScalingFactor sf, boolean bottomUp) throws Exception {
    int roffset = TJ.getRedOffset(pf);
    int goffset = TJ.getGreenOffset(pf);
    int boffset = TJ.getBlueOffset(pf);
    int aoffset = TJ.getAlphaOffset(pf);
    int ps = TJ.getPixelSize(pf);
    int index, row, col, retval = 1;
    int halfway = 16 * sf.getNum() / sf.getDenom();
    int blockSize = 8 * sf.getNum() / sf.getDenom();

    try {

      if (pf == TJ.PF_GRAY)
        roffset = goffset = boffset = 0;

      if (pf == TJ.PF_CMYK) {
        for (row = 0; row < h; row++) {
          for (col = 0; col < w; col++) {
            if (bottomUp)
              index = (h - row - 1) * w + col;
            else
              index = row * w + col;
            int c = getVal(buf, index * ps);
            int m = getVal(buf, index * ps + 1);
            int y = getVal(buf, index * ps + 2);
            int k = getVal(buf, index * ps + 3);
            checkValMax(row, col, c, "C");
            if (((row / blockSize) + (col / blockSize)) % 2 == 0) {
              checkValMax(row, col, m, "M");
              checkValMax(row, col, y, "Y");
              if (row < halfway)
                checkValMax(row, col, k, "K");
              else
                checkVal0(row, col, k, "K");
            } else {
              checkVal0(row, col, y, "Y");
              checkValMax(row, col, k, "K");
              if (row < halfway)
                checkVal0(row, col, m, "M");
              else
                checkValMax(row, col, m, "M");
            }
          }
        }
        return 1;
      }

      for (row = 0; row < halfway; row++) {
        for (col = 0; col < w; col++) {
          if (bottomUp)
            index = pitch * (h - row - 1) + col * ps;
          else
            index = pitch * row + col * ps;
          int r = getVal(buf, index + roffset);
          int g = getVal(buf, index + goffset);
          int b = getVal(buf, index + boffset);
          int a = aoffset >= 0 ? getVal(buf, index + aoffset) : maxSample;
          if (((row / blockSize) + (col / blockSize)) % 2 == 0) {
            if (row < halfway) {
              checkValMax(row, col, r, "R");
              checkValMax(row, col, g, "G");
              checkValMax(row, col, b, "B");
            } else {
              checkVal0(row, col, r, "R");
              checkVal0(row, col, g, "G");
              checkVal0(row, col, b, "B");
            }
          } else {
            if (subsamp == TJ.SAMP_GRAY) {
              if (row < halfway) {
                checkVal(row, col, r, "R", redToY);
                checkVal(row, col, g, "G", redToY);
                checkVal(row, col, b, "B", redToY);
              } else {
                checkVal(row, col, r, "R", yellowToY);
                checkVal(row, col, g, "G", yellowToY);
                checkVal(row, col, b, "B", yellowToY);
              }
            } else {
              checkValMax(row, col, r, "R");
              if (row < halfway) {
                checkVal0(row, col, g, "G");
              } else {
                checkValMax(row, col, g, "G");
              }
              checkVal0(row, col, b, "B");
            }
          }
          checkValMax(row, col, a, "A");
        }
      }
    } catch (Exception e) {
      System.out.println("\n" + e.getMessage());
      retval = 0;
    }

    if (retval == 0) {
      for (row = 0; row < h; row++) {
        for (col = 0; col < w; col++) {
          if (pf == TJ.PF_CMYK) {
            int c = getVal(buf, pitch * row + col * ps);
            int m = getVal(buf, pitch * row + col * ps + 1);
            int y = getVal(buf, pitch * row + col * ps + 2);
            int k = getVal(buf, pitch * row + col * ps + 3);
            System.out.format("%3d/%3d/%3d/%3d ", c, m, y, k);
          } else {
            int r = getVal(buf, pitch * row + col * ps + roffset);
            int g = getVal(buf, pitch * row + col * ps + goffset);
            int b = getVal(buf, pitch * row + col * ps + boffset);
            System.out.format("%3d/%3d/%3d ", r, g, b);
          }
        }
        System.out.print("\n");
      }
    }
    return retval;
  }