示例#1
0
  private static void initIntBuf(int[] buf, int w, int pitch, int h, int pf, int flags)
      throws Exception {
    int rshift = TJ.getRedOffset(pf) * 8;
    int gshift = TJ.getGreenOffset(pf) * 8;
    int bshift = TJ.getBlueOffset(pf) * 8;
    int ashift = alphaOffset[pf] * 8;
    int index, row, col, halfway = 16;

    Arrays.fill(buf, 0);
    for (row = 0; row < h; row++) {
      for (col = 0; col < w; col++) {
        if ((flags & TJ.FLAG_BOTTOMUP) != 0) index = pitch * (h - row - 1) + col;
        else index = pitch * row + col;
        if (((row / 8) + (col / 8)) % 2 == 0) {
          if (row < halfway) {
            buf[index] |= (255 << rshift);
            buf[index] |= (255 << gshift);
            buf[index] |= (255 << bshift);
          }
        } else {
          buf[index] |= (255 << rshift);
          if (row >= halfway) buf[index] |= (255 << gshift);
        }
        if (ashift >= 0) buf[index] |= (255 << ashift);
      }
    }
  }
示例#2
0
  private static void initBuf(byte[] buf, int w, int pitch, int h, int pf, int flags)
      throws Exception {
    int roffset = TJ.getRedOffset(pf);
    int goffset = TJ.getGreenOffset(pf);
    int boffset = TJ.getBlueOffset(pf);
    int aoffset = alphaOffset[pf];
    int ps = TJ.getPixelSize(pf);
    int index, row, col, halfway = 16;

    Arrays.fill(buf, (byte) 0);
    if (pf == TJ.PF_GRAY) {
      for (row = 0; row < h; row++) {
        for (col = 0; col < w; col++) {
          if ((flags & TJ.FLAG_BOTTOMUP) != 0) index = pitch * (h - row - 1) + col;
          else index = pitch * row + col;
          if (((row / 8) + (col / 8)) % 2 == 0) buf[index] = (row < halfway) ? (byte) 255 : 0;
          else buf[index] = (row < halfway) ? 76 : (byte) 226;
        }
      }
      return;
    }
    for (row = 0; row < h; row++) {
      for (col = 0; col < w; col++) {
        if ((flags & TJ.FLAG_BOTTOMUP) != 0) index = pitch * (h - row - 1) + col * ps;
        else index = pitch * row + col * ps;
        if (((row / 8) + (col / 8)) % 2 == 0) {
          if (row < halfway) {
            buf[index + roffset] = (byte) 255;
            buf[index + goffset] = (byte) 255;
            buf[index + boffset] = (byte) 255;
          }
        } else {
          buf[index + roffset] = (byte) 255;
          if (row >= halfway) buf[index + goffset] = (byte) 255;
        }
        if (aoffset >= 0) buf[index + aoffset] = (byte) 255;
      }
    }
  }
示例#3
0
  private static int checkIntBuf(
      int[] buf, int w, int pitch, int h, int pf, int subsamp, TJScalingFactor sf, int flags)
      throws Exception {
    int rshift = TJ.getRedOffset(pf) * 8;
    int gshift = TJ.getGreenOffset(pf) * 8;
    int bshift = TJ.getBlueOffset(pf) * 8;
    int ashift = alphaOffset[pf] * 8;
    int index, row, col, retval = 1;
    int halfway = 16 * sf.getNum() / sf.getDenom();
    int blockSize = 8 * sf.getNum() / sf.getDenom();

    try {
      for (row = 0; row < halfway; row++) {
        for (col = 0; col < w; col++) {
          if ((flags & TJ.FLAG_BOTTOMUP) != 0) index = pitch * (h - row - 1) + col;
          else index = pitch * row + col;
          int r = (buf[index] >> rshift) & 0xFF;
          int g = (buf[index] >> gshift) & 0xFF;
          int b = (buf[index] >> bshift) & 0xFF;
          int a = ashift >= 0 ? (buf[index] >> ashift) & 0xFF : 255;
          if (((row / blockSize) + (col / blockSize)) % 2 == 0) {
            if (row < halfway) {
              checkVal255(row, col, r, "R");
              checkVal255(row, col, g, "G");
              checkVal255(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", 76);
                checkVal(row, col, g, "G", 76);
                checkVal(row, col, b, "B", 76);
              } else {
                checkVal(row, col, r, "R", 226);
                checkVal(row, col, g, "G", 226);
                checkVal(row, col, b, "B", 226);
              }
            } else {
              checkVal255(row, col, r, "R");
              if (row < halfway) {
                checkVal0(row, col, g, "G");
              } else {
                checkVal255(row, col, g, "G");
              }
              checkVal0(row, col, b, "B");
            }
          }
          checkVal255(row, col, a, "A");
        }
      }
    } catch (Exception e) {
      System.out.println(e);
      retval = 0;
    }

    if (retval == 0) {
      System.out.print("\n");
      for (row = 0; row < h; row++) {
        for (col = 0; col < w; col++) {
          int r = (buf[pitch * row + col] >> rshift) & 0xFF;
          int g = (buf[pitch * row + col] >> gshift) & 0xFF;
          int b = (buf[pitch * row + col] >> bshift) & 0xFF;
          if (r < 0) r += 256;
          if (g < 0) g += 256;
          if (b < 0) b += 256;
          System.out.format("%3d/%3d/%3d ", r, g, b);
        }
        System.out.print("\n");
      }
    }
    return retval;
  }
示例#4
0
  private static int checkBuf(
      byte[] buf, int w, int pitch, int h, int pf, int subsamp, TJScalingFactor sf, int flags)
      throws Exception {
    int roffset = TJ.getRedOffset(pf);
    int goffset = TJ.getGreenOffset(pf);
    int boffset = TJ.getBlueOffset(pf);
    int aoffset = alphaOffset[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 {
      for (row = 0; row < halfway; row++) {
        for (col = 0; col < w; col++) {
          if ((flags & TJ.FLAG_BOTTOMUP) != 0) index = pitch * (h - row - 1) + col * ps;
          else index = pitch * row + col * ps;
          byte r = buf[index + roffset];
          byte g = buf[index + goffset];
          byte b = buf[index + boffset];
          byte a = aoffset >= 0 ? buf[index + aoffset] : (byte) 255;
          if (((row / blockSize) + (col / blockSize)) % 2 == 0) {
            if (row < halfway) {
              checkVal255(row, col, r, "R");
              checkVal255(row, col, g, "G");
              checkVal255(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", 76);
                checkVal(row, col, g, "G", 76);
                checkVal(row, col, b, "B", 76);
              } else {
                checkVal(row, col, r, "R", 226);
                checkVal(row, col, g, "G", 226);
                checkVal(row, col, b, "B", 226);
              }
            } else {
              checkVal255(row, col, r, "R");
              if (row < halfway) {
                checkVal0(row, col, g, "G");
              } else {
                checkVal255(row, col, g, "G");
              }
              checkVal0(row, col, b, "B");
            }
          }
          checkVal255(row, col, a, "A");
        }
      }
    } catch (Exception e) {
      System.out.println(e);
      retval = 0;
    }

    if (retval == 0) {
      System.out.print("\n");
      for (row = 0; row < h; row++) {
        for (col = 0; col < w; col++) {
          int r = buf[pitch * row + col * ps + roffset];
          int g = buf[pitch * row + col * ps + goffset];
          int b = buf[pitch * row + col * ps + boffset];
          if (r < 0) r += 256;
          if (g < 0) g += 256;
          if (b < 0) b += 256;
          System.out.format("%3d/%3d/%3d ", r, g, b);
        }
        System.out.print("\n");
      }
    }
    return retval;
  }