コード例 #1
0
ファイル: TJUnitTest.java プロジェクト: sbesson/bioformats
  private static void decompTest(
      TJDecompressor tjd,
      byte[] jpegBuf,
      int jpegSize,
      int w,
      int h,
      int pf,
      String baseName,
      int subsamp,
      int flags,
      TJScalingFactor sf)
      throws Exception {
    String pfStr, tempstr;
    double t;
    int scaledWidth = sf.getScaled(w);
    int scaledHeight = sf.getScaled(h);
    int temp1, temp2, imgType = pf;
    BufferedImage img = null;
    byte[] dstBuf = null;

    if (yuv == YUVENCODE) return;

    if (bi) {
      pf = biTypePF(imgType);
      pfStr = biTypeStr(imgType);
    } else pfStr = pixFormatStr[pf];

    System.out.print("JPEG -> ");
    if (yuv == YUVDECODE) System.out.print("YUV " + subName[subsamp] + " ... ");
    else {
      System.out.print(pfStr + " ");
      if (bi) System.out.print("(" + pixFormatStr[pf] + ") ");
      if ((flags & TJ.FLAG_BOTTOMUP) != 0) System.out.print("Bottom-Up ");
      else System.out.print("Top-Down  ");
      if (!sf.isOne()) System.out.print(sf.getNum() + "/" + sf.getDenom() + " ... ");
      else System.out.print("... ");
    }

    t = getTime();
    tjd.setJPEGImage(jpegBuf, jpegSize);
    if (tjd.getWidth() != w || tjd.getHeight() != h || tjd.getSubsamp() != subsamp)
      throw new Exception("Incorrect JPEG header");

    temp1 = scaledWidth;
    temp2 = scaledHeight;
    temp1 = tjd.getScaledWidth(temp1, temp2);
    temp2 = tjd.getScaledHeight(temp1, temp2);
    if (temp1 != scaledWidth || temp2 != scaledHeight) throw new Exception("Scaled size mismatch");

    if (yuv == YUVDECODE) dstBuf = tjd.decompressToYUV(flags);
    else {
      if (bi) img = tjd.decompress(scaledWidth, scaledHeight, imgType, flags);
      else dstBuf = tjd.decompress(scaledWidth, 0, scaledHeight, pf, flags);
    }
    t = getTime() - t;

    if (bi) {
      tempstr =
          baseName
              + "_dec_"
              + pfStr
              + "_"
              + (((flags & TJ.FLAG_BOTTOMUP) != 0) ? "BU" : "TD")
              + "_"
              + subName[subsamp]
              + "_"
              + (double) sf.getNum() / (double) sf.getDenom()
              + "x"
              + ".png";
      File file = new File(tempstr);
      ImageIO.write(img, "png", file);
    }

    if (yuv == YUVDECODE) {
      if (checkBufYUV(dstBuf, dstBuf.length, w, h, subsamp) == 1) System.out.print("Passed.");
      else {
        System.out.print("FAILED!");
        exitStatus = -1;
      }
    } else {
      if ((bi && checkImg(img, pf, subsamp, sf, flags) == 1)
          || (!bi
              && checkBuf(
                      dstBuf,
                      scaledWidth,
                      scaledWidth * TJ.getPixelSize(pf),
                      scaledHeight,
                      pf,
                      subsamp,
                      sf,
                      flags)
                  == 1)) System.out.print("Passed.");
      else {
        System.out.print("FAILED!");
        exitStatus = -1;
      }
    }
    System.out.format("  %.6f ms\n", t * 1000.);
  }