Ejemplo n.º 1
0
  public void testFullColorRoundtrip() throws IOException, ImageReadException, ImageWriteException {
    BufferedImage testImages[] = { //
      createFullColorImage(1, 1), // minimal
      createFullColorImage(2, 2), //
      createFullColorImage(10, 10), // larger than 8
      createFullColorImage(300, 300), // larger than 256
    };

    for (int j = 0; j < testImages.length; j++) {
      BufferedImage testImage = testImages[j];

      for (int i = 0; i < FORMAT_INFOS.length; i++) {
        FormatInfo formatInfo = FORMAT_INFOS[i];
        if ((!formatInfo.canRead) || (!formatInfo.canWrite)) continue;

        Debug.debug("fullColor test: " + formatInfo.format.name);

        boolean imageExact = true;
        if (formatInfo.colorSupport == COLOR_BITMAP) imageExact = false;
        if (formatInfo.colorSupport == COLOR_GRAYSCALE) imageExact = false;
        if (formatInfo.colorSupport == COLOR_LIMITED_INDEX) imageExact = false;

        roundtrip(formatInfo, testImage, "fullColor", imageExact);
      }
    }
  }
Ejemplo n.º 2
0
  public void testBitmapRoundtrip() throws IOException, ImageReadException, ImageWriteException {
    BufferedImage testImages[] = { //
      createArgbBitmapImage(1, 1), // minimal
      createArgbBitmapImage(2, 2), //
      createArgbBitmapImage(10, 10), // larger than 8
      createArgbBitmapImage(300, 300), // larger than 256
      createBitmapBitmapImage(1, 1), // minimal
      createBitmapBitmapImage(2, 2), //
      createBitmapBitmapImage(10, 10), // larger than 8
      createBitmapBitmapImage(300, 300), // larger than 256
    };

    for (int j = 0; j < testImages.length; j++) {
      BufferedImage testImage = testImages[j];

      for (int i = 0; i < FORMAT_INFOS.length; i++) {
        FormatInfo formatInfo = FORMAT_INFOS[i];
        if ((!formatInfo.canRead) || (!formatInfo.canWrite)) continue;

        Debug.debug("bitmap test: " + formatInfo.format.name);

        roundtrip(formatInfo, testImage, "bitmap", true);
      }
    }
  }
Ejemplo n.º 3
0
  public void test() throws Exception {

    List images = getImagesWithExifData(300);
    for (int i = 0; i < images.size(); i++) {
      if (i % 10 == 0) Debug.purgeMemory();

      File imageFile = (File) images.get(i);

      //			Debug.debug();
      //			Debug.debug("imageFile", imageFile);

      if (imageFile.getParentFile().getName().toLowerCase().equals("@broken")) continue;

      try {
        Map params = new HashMap();
        boolean ignoreImageData = isPhilHarveyTestImage(imageFile);
        params.put(PARAM_KEY_READ_THUMBNAILS, new Boolean(!ignoreImageData));

        JpegImageMetadata metadata = (JpegImageMetadata) Sanselan.getMetadata(imageFile, params);
        if (null == metadata) continue;

        TiffImageMetadata exifMetadata = metadata.getExif();
        if (null == exifMetadata) continue;

        TiffImageMetadata.GPSInfo gpsInfo = exifMetadata.getGPS();
        if (null == gpsInfo) continue;

        Debug.debug("imageFile", imageFile);
        Debug.debug("gpsInfo", gpsInfo);
        Debug.debug("gpsInfo longitude as degrees east", gpsInfo.getLongitudeAsDegreesEast());
        Debug.debug("gpsInfo latitude as degrees north", gpsInfo.getLatitudeAsDegreesNorth());

        Debug.debug();
      } catch (Exception e) {
        Debug.debug("imageFile", imageFile.getAbsoluteFile());
        Debug.debug("imageFile", imageFile.length());
        Debug.debug(e, 13);

        //				File brokenFolder = new File(imageFile.getParentFile(), "@Broken");
        //				if(!brokenFolder.exists())
        //					brokenFolder.mkdirs();
        //				File movedFile = new File(brokenFolder, imageFile.getName());
        //				imageFile.renameTo(movedFile);

        throw e;
      }
    }
  }
Ejemplo n.º 4
0
 public static final void purgeMemory() {
   try {
     //			Thread.sleep(50);
     System.runFinalization();
     Thread.sleep(50);
     System.gc();
     Thread.sleep(50);
   } catch (Throwable e) {
     Debug.debug(e);
   }
 }
Ejemplo n.º 5
0
  private void compareFilesExact(File a, File b) throws IOException {
    assertTrue(a.exists() && a.isFile());
    assertTrue(b.exists() && b.isFile());
    assertEquals(a.length(), b.length());

    byte aData[] = IOUtils.getFileBytes(a);
    byte bData[] = IOUtils.getFileBytes(b);

    for (int i = 0; i < a.length(); i++) {
      int aByte = 0xff & aData[i];
      int bByte = 0xff & bData[i];

      if (aByte != bByte) {
        Debug.debug("a", a);
        Debug.debug("b", b);
        Debug.debug("i", i);
        Debug.debug("aByte", aByte + " (0x" + Integer.toHexString(aByte) + ")");
        Debug.debug("bByte", bByte + " (0x" + Integer.toHexString(bByte) + ")");
      }
      assertEquals(aByte, bByte);
    }
  }
Ejemplo n.º 6
0
  private void compareImages(BufferedImage a, BufferedImage b, int tolerance) {
    assertEquals(a.getWidth(), b.getWidth());
    assertEquals(a.getHeight(), b.getHeight());

    for (int x = 0; x < a.getWidth(); x++)
      for (int y = 0; y < a.getHeight(); y++) {
        int a_argb = a.getRGB(x, y);
        int b_argb = b.getRGB(x, y);
        if (a_argb != b_argb) {
          if (calculateARGBDistance(a_argb, b_argb) <= tolerance) continue; // ignore.
        }
        if (a_argb != b_argb) {
          Debug.debug("width", a.getWidth());
          Debug.debug("height", a.getHeight());
          Debug.debug("distance", calculateARGBDistance(a_argb, b_argb));
          Debug.debug("x", x);
          Debug.debug("y", y);
          Debug.debug("a_argb", a_argb + " (0x" + Integer.toHexString(a_argb) + ")");
          Debug.debug("b_argb", b_argb + " (0x" + Integer.toHexString(b_argb) + ")");
        }
        assertEquals(a_argb, b_argb);
      }
  }
Ejemplo n.º 7
0
 private static void log(StringBuffer buffer, String s) {
   Debug.debug(s);
   if (buffer != null) buffer.append(s + newline);
 }