Tab police
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/sanselan/trunk@995634 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/src/test/java/org/apache/sanselan/SanselanGuessFormatTest.java b/src/test/java/org/apache/sanselan/SanselanGuessFormatTest.java
index ffb4272..dfb6cfb 100644
--- a/src/test/java/org/apache/sanselan/SanselanGuessFormatTest.java
+++ b/src/test/java/org/apache/sanselan/SanselanGuessFormatTest.java
@@ -23,52 +23,52 @@
public class SanselanGuessFormatTest extends SanselanTest {
- public static final String BMP_IMAGE_FILE = "bmp\\1\\Oregon Scientific DS6639 - DSC_0307 - small.bmp";
- public static final String PNG_IMAGE_FILE = "png\\1\\Oregon Scientific DS6639 - DSC_0307 - small.png";
- public static final String GIF_IMAGE_FILE = "gif\\1\\Oregon Scientific DS6639 - DSC_0307 - small.gif";
- public static final String ICO_IMAGE_FILE = "ico\\1\\Oregon Scientific DS6639 - DSC_0307 - small.ico";
- public static final String TIFF_IMAGE_FILE = "tiff\\1\\Oregon Scientific DS6639 - DSC_0307 - small.tif";
- public static final String JPEG_IMAGE_FILE = "jpg\\1\\Oregon Scientific DS6639 - DSC_0307 - small.jpg";
- public static final String PSD_IMAGE_FILE = "psd\\1\\Oregon Scientific DS6639 - DSC_0307 - small.psd";
- public static final String PBM_IMAGE_FILE = "pxm\\1\\Oregon Scientific DS6639 - DSC_0307 - small.pbm";
- public static final String PGM_IMAGE_FILE = "pxm\\1\\Oregon Scientific DS6639 - DSC_0307 - small.pgm";
- public static final String PPM_IMAGE_FILE = "pxm\\1\\Oregon Scientific DS6639 - DSC_0307 - small.ppm";
- public static final String TGA_IMAGE_FILE = "tga\\1\\Oregon Scientific DS6639 - DSC_0307 - small.tga";
+ public static final String BMP_IMAGE_FILE = "bmp\\1\\Oregon Scientific DS6639 - DSC_0307 - small.bmp";
+ public static final String PNG_IMAGE_FILE = "png\\1\\Oregon Scientific DS6639 - DSC_0307 - small.png";
+ public static final String GIF_IMAGE_FILE = "gif\\1\\Oregon Scientific DS6639 - DSC_0307 - small.gif";
+ public static final String ICO_IMAGE_FILE = "ico\\1\\Oregon Scientific DS6639 - DSC_0307 - small.ico";
+ public static final String TIFF_IMAGE_FILE = "tiff\\1\\Oregon Scientific DS6639 - DSC_0307 - small.tif";
+ public static final String JPEG_IMAGE_FILE = "jpg\\1\\Oregon Scientific DS6639 - DSC_0307 - small.jpg";
+ public static final String PSD_IMAGE_FILE = "psd\\1\\Oregon Scientific DS6639 - DSC_0307 - small.psd";
+ public static final String PBM_IMAGE_FILE = "pxm\\1\\Oregon Scientific DS6639 - DSC_0307 - small.pbm";
+ public static final String PGM_IMAGE_FILE = "pxm\\1\\Oregon Scientific DS6639 - DSC_0307 - small.pgm";
+ public static final String PPM_IMAGE_FILE = "pxm\\1\\Oregon Scientific DS6639 - DSC_0307 - small.ppm";
+ public static final String TGA_IMAGE_FILE = "tga\\1\\Oregon Scientific DS6639 - DSC_0307 - small.tga";
- public void testGuess_all() throws IOException, ImageReadException {
- testGuess(ImageFormat.IMAGE_FORMAT_PNG, PNG_IMAGE_FILE);
- testGuess(ImageFormat.IMAGE_FORMAT_GIF, GIF_IMAGE_FILE);
- // TODO(cmchen): add ability to sniff ICOs if possible.
- // testGuess(ImageFormat.IMAGE_FORMAT_ICO, ICO_IMAGE_FILE);
- testGuess(ImageFormat.IMAGE_FORMAT_TIFF, TIFF_IMAGE_FILE);
- testGuess(ImageFormat.IMAGE_FORMAT_JPEG, JPEG_IMAGE_FILE);
- testGuess(ImageFormat.IMAGE_FORMAT_BMP, BMP_IMAGE_FILE);
- testGuess(ImageFormat.IMAGE_FORMAT_PSD, PSD_IMAGE_FILE);
- testGuess(ImageFormat.IMAGE_FORMAT_PBM, PBM_IMAGE_FILE);
- testGuess(ImageFormat.IMAGE_FORMAT_PGM, PGM_IMAGE_FILE);
- testGuess(ImageFormat.IMAGE_FORMAT_PPM, PPM_IMAGE_FILE);
- // TODO(cmchen): add ability to sniff TGAs if possible.
- // testGuess(ImageFormat.IMAGE_FORMAT_TGA, TGA_IMAGE_FILE);
- // TODO(cmchen): Add test images for these formats.
- // testGuess(ImageFormat.IMAGE_FORMAT_PNM, PNM_IMAGE_FILE);
- // testGuess(ImageFormat.IMAGE_FORMAT_JBIG2, JBIG2_IMAGE_FILE);
- }
+ public void testGuess_all() throws IOException, ImageReadException {
+ testGuess(ImageFormat.IMAGE_FORMAT_PNG, PNG_IMAGE_FILE);
+ testGuess(ImageFormat.IMAGE_FORMAT_GIF, GIF_IMAGE_FILE);
+ // TODO(cmchen): add ability to sniff ICOs if possible.
+ // testGuess(ImageFormat.IMAGE_FORMAT_ICO, ICO_IMAGE_FILE);
+ testGuess(ImageFormat.IMAGE_FORMAT_TIFF, TIFF_IMAGE_FILE);
+ testGuess(ImageFormat.IMAGE_FORMAT_JPEG, JPEG_IMAGE_FILE);
+ testGuess(ImageFormat.IMAGE_FORMAT_BMP, BMP_IMAGE_FILE);
+ testGuess(ImageFormat.IMAGE_FORMAT_PSD, PSD_IMAGE_FILE);
+ testGuess(ImageFormat.IMAGE_FORMAT_PBM, PBM_IMAGE_FILE);
+ testGuess(ImageFormat.IMAGE_FORMAT_PGM, PGM_IMAGE_FILE);
+ testGuess(ImageFormat.IMAGE_FORMAT_PPM, PPM_IMAGE_FILE);
+ // TODO(cmchen): add ability to sniff TGAs if possible.
+ // testGuess(ImageFormat.IMAGE_FORMAT_TGA, TGA_IMAGE_FILE);
+ // TODO(cmchen): Add test images for these formats.
+ // testGuess(ImageFormat.IMAGE_FORMAT_PNM, PNM_IMAGE_FILE);
+ // testGuess(ImageFormat.IMAGE_FORMAT_JBIG2, JBIG2_IMAGE_FILE);
+ }
- public static final String UNKNOWN_IMAGE_FILE = "jpg\\1\\info.txt";
+ public static final String UNKNOWN_IMAGE_FILE = "jpg\\1\\info.txt";
- public void testGuess_unknown() throws IOException, ImageReadException {
- testGuess(ImageFormat.IMAGE_FORMAT_UNKNOWN, UNKNOWN_IMAGE_FILE);
- }
+ public void testGuess_unknown() throws IOException, ImageReadException {
+ testGuess(ImageFormat.IMAGE_FORMAT_UNKNOWN, UNKNOWN_IMAGE_FILE);
+ }
- public void testGuess(ImageFormat expectedFormat, String imagePath)
- throws IOException, ImageReadException {
- imagePath = FilenameUtils.separatorsToSystem(imagePath);
- File imageFile = new File(TEST_IMAGE_FOLDER, imagePath);
+ public void testGuess(ImageFormat expectedFormat, String imagePath)
+ throws IOException, ImageReadException {
+ imagePath = FilenameUtils.separatorsToSystem(imagePath);
+ File imageFile = new File(TEST_IMAGE_FOLDER, imagePath);
- assertTrue(imageFile.exists());
- assertTrue(imageFile.isFile());
- ImageFormat guessedFormat = Sanselan.guessFormat(imageFile);
- assertNotNull(guessedFormat);
- assertEquals(guessedFormat, expectedFormat);
- }
+ assertTrue(imageFile.exists());
+ assertTrue(imageFile.isFile());
+ ImageFormat guessedFormat = Sanselan.guessFormat(imageFile);
+ assertNotNull(guessedFormat);
+ assertEquals(guessedFormat, expectedFormat);
+ }
}
diff --git a/src/test/java/org/apache/sanselan/SanselanTest.java b/src/test/java/org/apache/sanselan/SanselanTest.java
index 7bee24c..17745ab 100644
--- a/src/test/java/org/apache/sanselan/SanselanTest.java
+++ b/src/test/java/org/apache/sanselan/SanselanTest.java
@@ -28,138 +28,138 @@
import org.apache.sanselan.util.Debug;
public abstract class SanselanTest extends TestCase implements
- SanselanTestConstants, SanselanConstants {
+ SanselanTestConstants, SanselanConstants {
- protected File createTempFile(String prefix, String suffix)
- throws IOException {
- File tempFolder = new File("tmp");
- if (!tempFolder.exists())
- tempFolder.mkdirs();
- assertTrue(tempFolder.isDirectory());
+ protected File createTempFile(String prefix, String suffix)
+ throws IOException {
+ File tempFolder = new File("tmp");
+ if (!tempFolder.exists())
+ tempFolder.mkdirs();
+ assertTrue(tempFolder.isDirectory());
- File result = File.createTempFile(prefix, suffix, tempFolder);
- result.deleteOnExit();
- return result;
- }
+ File result = File.createTempFile(prefix, suffix, tempFolder);
+ result.deleteOnExit();
+ return result;
+ }
- public void compareByteArrays(byte a[], byte b[]) {
- assertTrue(a.length == b.length);
- for (int i = 0; i < b.length; i++)
- assertTrue(b[i] == a[i]);
- }
+ public void compareByteArrays(byte a[], byte b[]) {
+ assertTrue(a.length == b.length);
+ for (int i = 0; i < b.length; i++)
+ assertTrue(b[i] == a[i]);
+ }
- protected void purgeMemory() {
- try {
- System.gc();
- Thread.sleep(50);
- System.runFinalization();
- Thread.sleep(50);
- } catch (Exception e) {
- Debug.debug(e);
- }
- }
+ protected void purgeMemory() {
+ try {
+ System.gc();
+ Thread.sleep(50);
+ System.runFinalization();
+ Thread.sleep(50);
+ } catch (Exception e) {
+ Debug.debug(e);
+ }
+ }
- protected boolean isPhilHarveyTestImage(File file) {
- // Debug.debug("isPhilHarveyTestImage file", file.getAbsolutePath());
- // Debug.debug("isPhilHarveyTestImage folder",
- // PHIL_HARVEY_TEST_IMAGE_FOLDER.getAbsolutePath());
- return file.getAbsolutePath().startsWith(
- PHIL_HARVEY_TEST_IMAGE_FOLDER.getAbsolutePath());
- }
+ protected boolean isPhilHarveyTestImage(File file) {
+ // Debug.debug("isPhilHarveyTestImage file", file.getAbsolutePath());
+ // Debug.debug("isPhilHarveyTestImage folder",
+ // PHIL_HARVEY_TEST_IMAGE_FOLDER.getAbsolutePath());
+ return file.getAbsolutePath().startsWith(
+ PHIL_HARVEY_TEST_IMAGE_FOLDER.getAbsolutePath());
+ }
- public static interface ImageFilter {
- public boolean accept(File file) throws IOException, ImageReadException;
- }
+ public static interface ImageFilter {
+ public boolean accept(File file) throws IOException, ImageReadException;
+ }
- protected File getTestImage() throws IOException, ImageReadException {
- return getTestImage(null);
- }
+ protected File getTestImage() throws IOException, ImageReadException {
+ return getTestImage(null);
+ }
- protected File getTestImageByName(final String filename)
- throws IOException, ImageReadException {
- return getTestImage(new ImageFilter() {
- public boolean accept(File file) throws IOException, ImageReadException {
- return file.getName().equals(filename);
- }
- });
- }
+ protected File getTestImageByName(final String filename)
+ throws IOException, ImageReadException {
+ return getTestImage(new ImageFilter() {
+ public boolean accept(File file) throws IOException, ImageReadException {
+ return file.getName().equals(filename);
+ }
+ });
+ }
- protected File getTestImage(ImageFilter filter) throws IOException,
- ImageReadException {
- List images = getTestImages(filter, 1);
+ protected File getTestImage(ImageFilter filter) throws IOException,
+ ImageReadException {
+ List images = getTestImages(filter, 1);
- assertTrue(images.size() > 0);
+ assertTrue(images.size() > 0);
- return (File) images.get(0);
- }
+ return (File) images.get(0);
+ }
- protected List getTestImages() throws IOException, ImageReadException {
- return getTestImages(null, -1);
- }
+ protected List getTestImages() throws IOException, ImageReadException {
+ return getTestImages(null, -1);
+ }
- protected List getTestImages(ImageFilter filter) throws IOException,
- ImageReadException {
- return getTestImages(filter, -1);
- }
+ protected List getTestImages(ImageFilter filter) throws IOException,
+ ImageReadException {
+ return getTestImages(filter, -1);
+ }
- private static final List ALL_IMAGES = new ArrayList();
+ private static final List ALL_IMAGES = new ArrayList();
- static {
- File imagesFolder = TEST_IMAGE_FOLDER;
+ static {
+ File imagesFolder = TEST_IMAGE_FOLDER;
- // imagesFolder = new File(
- // "C:\\personal\\apache\\sanselan\\src\\test\\data\\images\\bmp\\2");
+ // imagesFolder = new File(
+ // "C:\\personal\\apache\\sanselan\\src\\test\\data\\images\\bmp\\2");
- imagesFolder = imagesFolder.getAbsoluteFile();
+ imagesFolder = imagesFolder.getAbsoluteFile();
- Debug.debug("imagesFolder", imagesFolder);
- assertTrue(imagesFolder.exists());
+ Debug.debug("imagesFolder", imagesFolder);
+ assertTrue(imagesFolder.exists());
- FSTraversal.Visitor visitor = new FSTraversal.Visitor() {
+ FSTraversal.Visitor visitor = new FSTraversal.Visitor() {
- public boolean visit(File file, double progressEstimate) {
- if (!Sanselan.hasImageFileExtension(file))
- return true;
- ALL_IMAGES.add(file);
- return true;
- }
- };
- new FSTraversal().traverseFiles(imagesFolder, visitor);
- }
+ public boolean visit(File file, double progressEstimate) {
+ if (!Sanselan.hasImageFileExtension(file))
+ return true;
+ ALL_IMAGES.add(file);
+ return true;
+ }
+ };
+ new FSTraversal().traverseFiles(imagesFolder, visitor);
+ }
- protected List getTestImages(final ImageFilter filter, final int max)
- throws IOException, ImageReadException {
- final List images = new ArrayList();
- int counter = 0;
+ protected List getTestImages(final ImageFilter filter, final int max)
+ throws IOException, ImageReadException {
+ final List images = new ArrayList();
+ int counter = 0;
- for (int i = 0; i < ALL_IMAGES.size(); i++) {
- File file = (File) ALL_IMAGES.get(i);
+ for (int i = 0; i < ALL_IMAGES.size(); i++) {
+ File file = (File) ALL_IMAGES.get(i);
- if (!Sanselan.hasImageFileExtension(file))
- continue;
+ if (!Sanselan.hasImageFileExtension(file))
+ continue;
- if (counter++ % 10 == 0)
- Debug.purgeMemory();
+ if (counter++ % 10 == 0)
+ Debug.purgeMemory();
- if (file.getParentFile().getName().toLowerCase().equals("@broken"))
- continue;
+ if (file.getParentFile().getName().toLowerCase().equals("@broken"))
+ continue;
- if (filter != null && !filter.accept(file))
- continue;
+ if (filter != null && !filter.accept(file))
+ continue;
- images.add(file);
+ images.add(file);
- if (max > 0 && images.size() >= max)
- break;
- }
+ if (max > 0 && images.size() >= max)
+ break;
+ }
- assertTrue(images.size() > 0);
+ assertTrue(images.size() > 0);
- return images;
- }
+ return images;
+ }
- protected boolean isInvalidPNGTestFile(File file) {
- return (file.getParentFile().getName().equalsIgnoreCase("pngsuite") && file
- .getName().toLowerCase().startsWith("x"));
- }
+ protected boolean isInvalidPNGTestFile(File file) {
+ return (file.getParentFile().getName().equalsIgnoreCase("pngsuite") && file
+ .getName().toLowerCase().startsWith("x"));
+ }
}
diff --git a/src/test/java/org/apache/sanselan/SanselanTestConstants.java b/src/test/java/org/apache/sanselan/SanselanTestConstants.java
index f12fb6d..8954e64 100644
--- a/src/test/java/org/apache/sanselan/SanselanTestConstants.java
+++ b/src/test/java/org/apache/sanselan/SanselanTestConstants.java
@@ -22,13 +22,13 @@
public interface SanselanTestConstants {
- static final File PHIL_HARVEY_TEST_IMAGE_FOLDER = new File(
- FilenameUtils.separatorsToSystem("src\\test\\data\\images\\exif\\philHarvey\\"));
+ static final File PHIL_HARVEY_TEST_IMAGE_FOLDER = new File(
+ FilenameUtils.separatorsToSystem("src\\test\\data\\images\\exif\\philHarvey\\"));
- static final File SOURCE_FOLDER = new File("src");
- static final File TEST_SOURCE_FOLDER = new File(SOURCE_FOLDER, "test");
- static final File TEST_DATA_SOURCE_FOLDER = new File(TEST_SOURCE_FOLDER,
- "data");
- static final File TEST_IMAGE_FOLDER = new File(TEST_DATA_SOURCE_FOLDER,
- "images");
+ static final File SOURCE_FOLDER = new File("src");
+ static final File TEST_SOURCE_FOLDER = new File(SOURCE_FOLDER, "test");
+ static final File TEST_DATA_SOURCE_FOLDER = new File(TEST_SOURCE_FOLDER,
+ "data");
+ static final File TEST_IMAGE_FOLDER = new File(TEST_DATA_SOURCE_FOLDER,
+ "images");
}
diff --git a/src/test/java/org/apache/sanselan/common/RationalNumberTest.java b/src/test/java/org/apache/sanselan/common/RationalNumberTest.java
index 80dffdb..4a301db 100644
--- a/src/test/java/org/apache/sanselan/common/RationalNumberTest.java
+++ b/src/test/java/org/apache/sanselan/common/RationalNumberTest.java
@@ -25,100 +25,100 @@
public class RationalNumberTest extends SanselanTest
{
- // public RationalNumberTest()
- // {
- // super("Rational Number Test");
- // }
+ // public RationalNumberTest()
+ // {
+ // super("Rational Number Test");
+ // }
- public void test()
- {
- double testValues[] = {
- 0, //
- 0.1, //
- 0.01, //
- 0.001, //
- 0.0001, //
- 0.00001, //
- 0.000001, //
- 0.0000001, //
- 0.123456789, //
- 1, //
- 0.9, //
- 1.1, //
- 2.0, //
- 123.123, //
- 123123123.123, //
+ public void test()
+ {
+ double testValues[] = {
+ 0, //
+ 0.1, //
+ 0.01, //
+ 0.001, //
+ 0.0001, //
+ 0.00001, //
+ 0.000001, //
+ 0.0000001, //
+ 0.123456789, //
+ 1, //
+ 0.9, //
+ 1.1, //
+ 2.0, //
+ 123.123, //
+ 123123123.123, //
- (double) 123 / 45678, //
- (double) 12 / 34, //
- (double) 1 / 2, //
- (double) 1 / 3, //
- (double) 1 / 4, //
- (double) 1 / 5, //
- (double) 1 / 6, //
- (double) 1 / 7, //
- (double) 1 / 8, //
- (double) 1 / 9, //
- (double) 3 / 2, //
- (double) 2 / 3, //
- (double) 3 / 4, //
- (double) 4 / 5, //
- (double) 5 / 6, //
- (double) 6 / 7, //
- (double) 7 / 8, //
- (double) 8 / 9, //
- (double) 3 / 5, //
- (double) 3 / 6, //
- (double) 3 / 7, //
- (double) 3 / 8, //
- (double) 3 / 9, //
+ (double) 123 / 45678, //
+ (double) 12 / 34, //
+ (double) 1 / 2, //
+ (double) 1 / 3, //
+ (double) 1 / 4, //
+ (double) 1 / 5, //
+ (double) 1 / 6, //
+ (double) 1 / 7, //
+ (double) 1 / 8, //
+ (double) 1 / 9, //
+ (double) 3 / 2, //
+ (double) 2 / 3, //
+ (double) 3 / 4, //
+ (double) 4 / 5, //
+ (double) 5 / 6, //
+ (double) 6 / 7, //
+ (double) 7 / 8, //
+ (double) 8 / 9, //
+ (double) 3 / 5, //
+ (double) 3 / 6, //
+ (double) 3 / 7, //
+ (double) 3 / 8, //
+ (double) 3 / 9, //
- -0.1, //
- -0.01, //
- -0.001, //
- -0.0001, //
- -0.00001, //
- -0.000001, //
- -0.0000001, //
- -0.123456789, //
- -1, //
- -0.9, //
- -1.1, //
- -2.0, //
- -123.123, //
- -123123123.123, //
+ -0.1, //
+ -0.01, //
+ -0.001, //
+ -0.0001, //
+ -0.00001, //
+ -0.000001, //
+ -0.0000001, //
+ -0.123456789, //
+ -1, //
+ -0.9, //
+ -1.1, //
+ -2.0, //
+ -123.123, //
+ -123123123.123, //
- 34, //
+ 34, //
- Integer.MAX_VALUE, //
- Integer.MAX_VALUE + 0.1, //
- Integer.MAX_VALUE - 0.1, //
- -(Integer.MAX_VALUE ), //
- -(Integer.MAX_VALUE + 0.1), //
- -(Integer.MAX_VALUE - 0.1), //
+ Integer.MAX_VALUE, //
+ Integer.MAX_VALUE + 0.1, //
+ Integer.MAX_VALUE - 0.1, //
+ -(Integer.MAX_VALUE ), //
+ -(Integer.MAX_VALUE + 0.1), //
+ -(Integer.MAX_VALUE - 0.1), //
- Long.MAX_VALUE, //
- Long.MAX_VALUE + 0.1, //
- Long.MAX_VALUE - 0.1, //
- -(Long.MAX_VALUE ), //
- -(Long.MAX_VALUE + 0.1), //
- -(Long.MAX_VALUE - 0.1), //
- };
+ Long.MAX_VALUE, //
+ Long.MAX_VALUE + 0.1, //
+ Long.MAX_VALUE - 0.1, //
+ -(Long.MAX_VALUE ), //
+ -(Long.MAX_VALUE + 0.1), //
+ -(Long.MAX_VALUE - 0.1), //
+ };
- for (int i = 0; i < testValues.length; i++)
- {
- double value = testValues[i];
- RationalNumber rational = RationalNumberUtilities
- .getRationalNumber(value);
- double difference = Math.abs(value - rational.doubleValue());
+ for (int i = 0; i < testValues.length; i++)
+ {
+ double value = testValues[i];
+ RationalNumber rational = RationalNumberUtilities
+ .getRationalNumber(value);
+ double difference = Math.abs(value - rational.doubleValue());
- NumberFormat nf = DecimalFormat.getInstance();
- nf.setMaximumFractionDigits(15);
+ NumberFormat nf = DecimalFormat.getInstance();
+ nf.setMaximumFractionDigits(15);
- Debug.debug("value", nf.format(value));
- Debug.debug("rational", rational);
- Debug.debug("difference", difference);
- Debug.debug();
- }
- }
+ Debug.debug("value", nf.format(value));
+ Debug.debug("rational", rational);
+ Debug.debug("difference", difference);
+ Debug.debug();
+ }
+ }
}
diff --git a/src/test/java/org/apache/sanselan/common/byteSources/ByteSourceDataTest.java b/src/test/java/org/apache/sanselan/common/byteSources/ByteSourceDataTest.java
index e3c590e..e6c1158 100644
--- a/src/test/java/org/apache/sanselan/common/byteSources/ByteSourceDataTest.java
+++ b/src/test/java/org/apache/sanselan/common/byteSources/ByteSourceDataTest.java
@@ -30,130 +30,130 @@
public class ByteSourceDataTest extends ByteSourceTest
{
- // public ByteSourceDataTest()
- // {
- // super(ByteSourceDataTest.class.getName());
- // }
+ // public ByteSourceDataTest()
+ // {
+ // super(ByteSourceDataTest.class.getName());
+ // }
- /**
- * @return the suite of tests being tested
- */
- public static Test suite()
- {
- return new TestSuite(ByteSourceDataTest.class);
- }
+ /**
+ * @return the suite of tests being tested
+ */
+ public static Test suite()
+ {
+ return new TestSuite(ByteSourceDataTest.class);
+ }
- private interface ByteSourceFactory
- {
- public ByteSource getByteSource(byte src[]) throws IOException;
- }
+ private interface ByteSourceFactory
+ {
+ public ByteSource getByteSource(byte src[]) throws IOException;
+ }
- private class ByteSourceFileFactory implements ByteSourceFactory
- {
- public ByteSource getByteSource(byte src[]) throws IOException
- {
- File file = createTempFile(src);
+ private class ByteSourceFileFactory implements ByteSourceFactory
+ {
+ public ByteSource getByteSource(byte src[]) throws IOException
+ {
+ File file = createTempFile(src);
- // test that all bytes written to file.
- assertTrue(src.length == file.length());
+ // test that all bytes written to file.
+ assertTrue(src.length == file.length());
- ByteSource byteSource = new ByteSourceFile(file);
- return byteSource;
- }
- }
+ ByteSource byteSource = new ByteSourceFile(file);
+ return byteSource;
+ }
+ }
- private class ByteSourceInputStreamFileFactory implements ByteSourceFactory
- {
- public ByteSource getByteSource(byte src[]) throws IOException
- {
- File file = createTempFile(src);
+ private class ByteSourceInputStreamFileFactory implements ByteSourceFactory
+ {
+ public ByteSource getByteSource(byte src[]) throws IOException
+ {
+ File file = createTempFile(src);
- FileInputStream is = new FileInputStream(file);
+ FileInputStream is = new FileInputStream(file);
- ByteSource byteSource = new ByteSourceInputStream(is, null);
- return byteSource;
- }
- }
+ ByteSource byteSource = new ByteSourceInputStream(is, null);
+ return byteSource;
+ }
+ }
- private class ByteSourceInputStreamRawFactory implements ByteSourceFactory
- {
- public ByteSource getByteSource(byte src[]) throws IOException
- {
- ByteArrayInputStream is = new ByteArrayInputStream(src);
+ private class ByteSourceInputStreamRawFactory implements ByteSourceFactory
+ {
+ public ByteSource getByteSource(byte src[]) throws IOException
+ {
+ ByteArrayInputStream is = new ByteArrayInputStream(src);
- ByteSource byteSource = new ByteSourceInputStream(is, null);
- return byteSource;
- }
+ ByteSource byteSource = new ByteSourceInputStream(is, null);
+ return byteSource;
+ }
- }
+ }
- protected void writeAndReadBytes(ByteSourceFactory byteSourceFactory,
- byte src[]) throws IOException
- {
- ByteSource byteSource = byteSourceFactory.getByteSource(src);
+ protected void writeAndReadBytes(ByteSourceFactory byteSourceFactory,
+ byte src[]) throws IOException
+ {
+ ByteSource byteSource = byteSourceFactory.getByteSource(src);
- // test cache during interrupted read cache by reading only first N bytes.
- {
- InputStream is = byteSource.getInputStream();
- byte prefix[] = new byte[256];
- int read = is.read(prefix);
+ // test cache during interrupted read cache by reading only first N bytes.
+ {
+ InputStream is = byteSource.getInputStream();
+ byte prefix[] = new byte[256];
+ int read = is.read(prefix);
- assertTrue(read <= src.length);
- for (int i = 0; i < read; i++)
- assertTrue(src[i] == prefix[i]);
- }
+ assertTrue(read <= src.length);
+ for (int i = 0; i < read; i++)
+ assertTrue(src[i] == prefix[i]);
+ }
- // test cache by completely reading InputStream N times.
- for (int j = 0; j < 5; j++)
- {
- InputStream is = byteSource.getInputStream();
- byte dst[] = IOUtils.getInputStreamBytes(is);
+ // test cache by completely reading InputStream N times.
+ for (int j = 0; j < 5; j++)
+ {
+ InputStream is = byteSource.getInputStream();
+ byte dst[] = IOUtils.getInputStreamBytes(is);
- compareByteArrays(src, dst);
- }
+ compareByteArrays(src, dst);
+ }
- {
- // test getAll() method.
- byte all[] = byteSource.getAll();
- compareByteArrays(src, all);
- }
+ {
+ // test getAll() method.
+ byte all[] = byteSource.getAll();
+ compareByteArrays(src, all);
+ }
- if (src.length > 2)
- {
- // test optional start param to getInputStream()
+ if (src.length > 2)
+ {
+ // test optional start param to getInputStream()
- int start = src.length / 2;
+ int start = src.length / 2;
- InputStream is = byteSource.getInputStream(start);
- byte dst[] = IOUtils.getInputStreamBytes(is);
+ InputStream is = byteSource.getInputStream(start);
+ byte dst[] = IOUtils.getInputStreamBytes(is);
- assertTrue(src.length == dst.length + start);
- for (int i = 0; i < dst.length; i++)
- assertTrue(dst[i] == src[i + start]);
- }
+ assertTrue(src.length == dst.length + start);
+ for (int i = 0; i < dst.length; i++)
+ assertTrue(dst[i] == src[i + start]);
+ }
- }
+ }
- public void test() throws IOException
- {
- ByteSourceFactory byteSourceFactories[] = {
- new ByteSourceFileFactory(),
- new ByteSourceInputStreamFileFactory(),
- new ByteSourceInputStreamRawFactory(),
- };
+ public void test() throws IOException
+ {
+ ByteSourceFactory byteSourceFactories[] = {
+ new ByteSourceFileFactory(),
+ new ByteSourceInputStreamFileFactory(),
+ new ByteSourceInputStreamRawFactory(),
+ };
- byte testByteArrays[][] = getTestByteArrays();
+ byte testByteArrays[][] = getTestByteArrays();
- for (int i = 0; i < testByteArrays.length; i++)
- {
- byte testByteArray[] = testByteArrays[i];
+ for (int i = 0; i < testByteArrays.length; i++)
+ {
+ byte testByteArray[] = testByteArrays[i];
- for (int j = 0; j < byteSourceFactories.length; j++)
- {
- ByteSourceFactory byteSourceFactory = byteSourceFactories[j];
+ for (int j = 0; j < byteSourceFactories.length; j++)
+ {
+ ByteSourceFactory byteSourceFactory = byteSourceFactories[j];
- writeAndReadBytes(byteSourceFactory, testByteArray);
- }
- }
- }
+ writeAndReadBytes(byteSourceFactory, testByteArray);
+ }
+ }
+ }
}
diff --git a/src/test/java/org/apache/sanselan/common/byteSources/ByteSourceImageTest.java b/src/test/java/org/apache/sanselan/common/byteSources/ByteSourceImageTest.java
index 98ae2d2..b61dbb7 100644
--- a/src/test/java/org/apache/sanselan/common/byteSources/ByteSourceImageTest.java
+++ b/src/test/java/org/apache/sanselan/common/byteSources/ByteSourceImageTest.java
@@ -38,180 +38,180 @@
public class ByteSourceImageTest extends ByteSourceTest
{
- public void test() throws IOException, ImageReadException,
- IllegalAccessException, IllegalArgumentException,
- InvocationTargetException
- {
- List imageFiles = getTestImages();
- for (int i = 0; i < imageFiles.size(); i++)
- {
- if (i % 1 == 0)
- Debug.purgeMemory();
+ public void test() throws IOException, ImageReadException,
+ IllegalAccessException, IllegalArgumentException,
+ InvocationTargetException
+ {
+ List imageFiles = getTestImages();
+ for (int i = 0; i < imageFiles.size(); i++)
+ {
+ if (i % 1 == 0)
+ Debug.purgeMemory();
- File imageFile = (File) imageFiles.get(i);
- Debug.debug("imageFile", imageFile);
- assertNotNull(imageFile);
+ File imageFile = (File) imageFiles.get(i);
+ Debug.debug("imageFile", imageFile);
+ assertNotNull(imageFile);
- byte imageFileBytes[] = IOUtils.getFileBytes(imageFile);
- assertNotNull(imageFileBytes);
- assertTrue(imageFileBytes.length == imageFile.length());
+ byte imageFileBytes[] = IOUtils.getFileBytes(imageFile);
+ assertNotNull(imageFileBytes);
+ assertTrue(imageFileBytes.length == imageFile.length());
- if (imageFile.getName().toLowerCase().endsWith(".ico")
- || imageFile.getName().toLowerCase().endsWith(".tga")
- || imageFile.getName().toLowerCase().endsWith(".jb2")
- || imageFile.getName().toLowerCase().endsWith(".psd"))
- {
- // these formats can't be parsed without a filename hint.
- // they have ambiguous "magic number" signatures.
- continue;
- }
+ if (imageFile.getName().toLowerCase().endsWith(".ico")
+ || imageFile.getName().toLowerCase().endsWith(".tga")
+ || imageFile.getName().toLowerCase().endsWith(".jb2")
+ || imageFile.getName().toLowerCase().endsWith(".psd"))
+ {
+ // these formats can't be parsed without a filename hint.
+ // they have ambiguous "magic number" signatures.
+ continue;
+ }
- checkGuessFormat(imageFile, imageFileBytes);
+ checkGuessFormat(imageFile, imageFileBytes);
- if (imageFile.getName().toLowerCase().endsWith(".png")
- && imageFile.getParentFile().getName().equalsIgnoreCase(
- "pngsuite")
- && imageFile.getName().toLowerCase().startsWith("x"))
- continue;
+ if (imageFile.getName().toLowerCase().endsWith(".png")
+ && imageFile.getParentFile().getName().equalsIgnoreCase(
+ "pngsuite")
+ && imageFile.getName().toLowerCase().startsWith("x"))
+ continue;
- checkGetICCProfileBytes(imageFile, imageFileBytes);
+ checkGetICCProfileBytes(imageFile, imageFileBytes);
- if (!imageFile.getParentFile().getName().toLowerCase().equals(
- "@broken"))
- checkGetImageInfo(imageFile, imageFileBytes);
+ if (!imageFile.getParentFile().getName().toLowerCase().equals(
+ "@broken"))
+ checkGetImageInfo(imageFile, imageFileBytes);
- checkGetImageSize(imageFile, imageFileBytes);
+ checkGetImageSize(imageFile, imageFileBytes);
- ImageFormat imageFormat = Sanselan.guessFormat(imageFile);
- if (ImageFormat.IMAGE_FORMAT_JPEG == imageFormat
- || ImageFormat.IMAGE_FORMAT_UNKNOWN == imageFormat)
- ;
- else
- checkGetBufferedImage(imageFile, imageFileBytes);
- }
- }
+ ImageFormat imageFormat = Sanselan.guessFormat(imageFile);
+ if (ImageFormat.IMAGE_FORMAT_JPEG == imageFormat
+ || ImageFormat.IMAGE_FORMAT_UNKNOWN == imageFormat)
+ ;
+ else
+ checkGetBufferedImage(imageFile, imageFileBytes);
+ }
+ }
- public void checkGetBufferedImage(File file, byte[] bytes)
- throws IOException, ImageReadException
- {
- BufferedImage imageFile = Sanselan.getBufferedImage(file);
- assertNotNull(imageFile);
- assertTrue(imageFile.getWidth() > 0);
- assertTrue(imageFile.getHeight() > 0);
- int imageFileWidth = imageFile.getWidth();
- int imageFileHeight = imageFile.getHeight();
- imageFile = null;
+ public void checkGetBufferedImage(File file, byte[] bytes)
+ throws IOException, ImageReadException
+ {
+ BufferedImage imageFile = Sanselan.getBufferedImage(file);
+ assertNotNull(imageFile);
+ assertTrue(imageFile.getWidth() > 0);
+ assertTrue(imageFile.getHeight() > 0);
+ int imageFileWidth = imageFile.getWidth();
+ int imageFileHeight = imageFile.getHeight();
+ imageFile = null;
- BufferedImage imageBytes = Sanselan.getBufferedImage(bytes);
- assertNotNull(imageBytes);
- assertTrue(imageFileWidth == imageBytes.getWidth());
- assertTrue(imageFileHeight == imageBytes.getHeight());
- }
+ BufferedImage imageBytes = Sanselan.getBufferedImage(bytes);
+ assertNotNull(imageBytes);
+ assertTrue(imageFileWidth == imageBytes.getWidth());
+ assertTrue(imageFileHeight == imageBytes.getHeight());
+ }
- public void checkGetImageSize(File imageFile, byte[] imageFileBytes)
- throws IOException, ImageReadException
- {
- Dimension imageSizeFile = Sanselan.getImageSize(imageFile);
- assertNotNull(imageSizeFile);
- assertTrue(imageSizeFile.width > 0);
- assertTrue(imageSizeFile.height > 0);
+ public void checkGetImageSize(File imageFile, byte[] imageFileBytes)
+ throws IOException, ImageReadException
+ {
+ Dimension imageSizeFile = Sanselan.getImageSize(imageFile);
+ assertNotNull(imageSizeFile);
+ assertTrue(imageSizeFile.width > 0);
+ assertTrue(imageSizeFile.height > 0);
- Dimension imageSizeBytes = Sanselan.getImageSize(imageFileBytes);
- assertNotNull(imageSizeBytes);
- assertTrue(imageSizeFile.width == imageSizeBytes.width);
- assertTrue(imageSizeFile.height == imageSizeBytes.height);
- }
+ Dimension imageSizeBytes = Sanselan.getImageSize(imageFileBytes);
+ assertNotNull(imageSizeBytes);
+ assertTrue(imageSizeFile.width == imageSizeBytes.width);
+ assertTrue(imageSizeFile.height == imageSizeBytes.height);
+ }
- public void checkGuessFormat(File imageFile, byte[] imageFileBytes)
- throws IOException, ImageReadException
- {
- // check guessFormat()
- ImageFormat imageFormatFile = Sanselan.guessFormat(imageFile);
- assertNotNull(imageFormatFile);
- assertTrue(imageFormatFile != ImageFormat.IMAGE_FORMAT_UNKNOWN);
- // Debug.debug("imageFormatFile", imageFormatFile);
+ public void checkGuessFormat(File imageFile, byte[] imageFileBytes)
+ throws IOException, ImageReadException
+ {
+ // check guessFormat()
+ ImageFormat imageFormatFile = Sanselan.guessFormat(imageFile);
+ assertNotNull(imageFormatFile);
+ assertTrue(imageFormatFile != ImageFormat.IMAGE_FORMAT_UNKNOWN);
+ // Debug.debug("imageFormatFile", imageFormatFile);
- ImageFormat imageFormatBytes = Sanselan.guessFormat(imageFileBytes);
- assertNotNull(imageFormatBytes);
- assertTrue(imageFormatBytes != ImageFormat.IMAGE_FORMAT_UNKNOWN);
- // Debug.debug("imageFormatBytes", imageFormatBytes);
+ ImageFormat imageFormatBytes = Sanselan.guessFormat(imageFileBytes);
+ assertNotNull(imageFormatBytes);
+ assertTrue(imageFormatBytes != ImageFormat.IMAGE_FORMAT_UNKNOWN);
+ // Debug.debug("imageFormatBytes", imageFormatBytes);
- assertTrue(imageFormatBytes == imageFormatFile);
- }
+ assertTrue(imageFormatBytes == imageFormatFile);
+ }
- public void checkGetICCProfileBytes(File imageFile, byte[] imageFileBytes)
- throws IOException, ImageReadException
- {
- // check guessFormat()
- byte iccBytesFile[] = Sanselan.getICCProfileBytes(imageFile);
+ public void checkGetICCProfileBytes(File imageFile, byte[] imageFileBytes)
+ throws IOException, ImageReadException
+ {
+ // check guessFormat()
+ byte iccBytesFile[] = Sanselan.getICCProfileBytes(imageFile);
- byte iccBytesBytes[] = Sanselan.getICCProfileBytes(imageFileBytes);
+ byte iccBytesBytes[] = Sanselan.getICCProfileBytes(imageFileBytes);
- assertTrue((iccBytesFile != null) == (iccBytesBytes != null));
+ assertTrue((iccBytesFile != null) == (iccBytesBytes != null));
- if (iccBytesFile == null)
- return;
+ if (iccBytesFile == null)
+ return;
- compareByteArrays(iccBytesFile, iccBytesBytes);
- }
+ compareByteArrays(iccBytesFile, iccBytesBytes);
+ }
- public void checkGetImageInfo(File imageFile, byte[] imageFileBytes)
- throws IOException, ImageReadException, IllegalAccessException,
- IllegalArgumentException, InvocationTargetException
- {
- Map params = new HashMap();
- boolean ignoreImageData = isPhilHarveyTestImage(imageFile);
- ImageFormat imageFormat = Sanselan.guessFormat(imageFile);
- if (imageFormat.equals(ImageFormat.IMAGE_FORMAT_TIFF)
- || imageFormat.equals(ImageFormat.IMAGE_FORMAT_JPEG))
- params
- .put(PARAM_KEY_READ_THUMBNAILS, new Boolean(
- !ignoreImageData));
+ public void checkGetImageInfo(File imageFile, byte[] imageFileBytes)
+ throws IOException, ImageReadException, IllegalAccessException,
+ IllegalArgumentException, InvocationTargetException
+ {
+ Map params = new HashMap();
+ boolean ignoreImageData = isPhilHarveyTestImage(imageFile);
+ ImageFormat imageFormat = Sanselan.guessFormat(imageFile);
+ if (imageFormat.equals(ImageFormat.IMAGE_FORMAT_TIFF)
+ || imageFormat.equals(ImageFormat.IMAGE_FORMAT_JPEG))
+ params
+ .put(PARAM_KEY_READ_THUMBNAILS, new Boolean(
+ !ignoreImageData));
- ImageInfo imageInfoFile = Sanselan.getImageInfo(imageFile, params);
+ ImageInfo imageInfoFile = Sanselan.getImageInfo(imageFile, params);
- ImageInfo imageInfoBytes = Sanselan
- .getImageInfo(imageFileBytes, params);
+ ImageInfo imageInfoBytes = Sanselan
+ .getImageInfo(imageFileBytes, params);
- assertNotNull(imageInfoFile);
- assertNotNull(imageInfoBytes);
+ assertNotNull(imageInfoFile);
+ assertNotNull(imageInfoBytes);
- Method methods[] = ImageInfo.class.getMethods();
- for (int i = 0; i < methods.length; i++)
- {
- Method method = methods[i];
- method.getModifiers();
- if (!Modifier.isPublic(method.getModifiers()))
- continue;
- if (!method.getName().startsWith("get"))
- continue;
- if (method.getName().equals("getClass"))
- continue;
- // if (method.getGenericParameterTypes().length > 0)
- // continue;
+ Method methods[] = ImageInfo.class.getMethods();
+ for (int i = 0; i < methods.length; i++)
+ {
+ Method method = methods[i];
+ method.getModifiers();
+ if (!Modifier.isPublic(method.getModifiers()))
+ continue;
+ if (!method.getName().startsWith("get"))
+ continue;
+ if (method.getName().equals("getClass"))
+ continue;
+ // if (method.getGenericParameterTypes().length > 0)
+ // continue;
- Object valueFile = method.invoke(imageInfoFile, null);
- Object valueBytes = method.invoke(imageInfoBytes, null);
+ Object valueFile = method.invoke(imageInfoFile, null);
+ Object valueBytes = method.invoke(imageInfoBytes, null);
- assertTrue(valueFile.equals(valueBytes));
- }
+ assertTrue(valueFile.equals(valueBytes));
+ }
- // only have to test values from imageInfoFile; we already know values
- // match.
- assertTrue(imageInfoFile.getBitsPerPixel() > 0);
+ // only have to test values from imageInfoFile; we already know values
+ // match.
+ assertTrue(imageInfoFile.getBitsPerPixel() > 0);
- assertNotNull(imageInfoFile.getFormat());
- assertTrue(imageInfoFile.getFormat() != ImageFormat.IMAGE_FORMAT_UNKNOWN);
+ assertNotNull(imageInfoFile.getFormat());
+ assertTrue(imageInfoFile.getFormat() != ImageFormat.IMAGE_FORMAT_UNKNOWN);
- assertNotNull(imageInfoFile.getFormatName());
+ assertNotNull(imageInfoFile.getFormatName());
- assertTrue(imageInfoFile.getWidth() > 0);
- assertTrue(imageInfoFile.getHeight() > 0);
+ assertTrue(imageInfoFile.getWidth() > 0);
+ assertTrue(imageInfoFile.getHeight() > 0);
- assertNotNull(imageInfoFile.getMimeType());
+ assertNotNull(imageInfoFile.getMimeType());
- // TODO: not all adapters count images yet.
- // assertTrue(imageInfoFile.getNumberOfImages() > 0);
+ // TODO: not all adapters count images yet.
+ // assertTrue(imageInfoFile.getNumberOfImages() > 0);
- }
+ }
}
diff --git a/src/test/java/org/apache/sanselan/common/byteSources/ByteSourceTest.java b/src/test/java/org/apache/sanselan/common/byteSources/ByteSourceTest.java
index 1cca4ff..8f62871 100644
--- a/src/test/java/org/apache/sanselan/common/byteSources/ByteSourceTest.java
+++ b/src/test/java/org/apache/sanselan/common/byteSources/ByteSourceTest.java
@@ -28,46 +28,46 @@
public abstract class ByteSourceTest extends SanselanTest
{
- protected File createTempFile(byte src[]) throws IOException
- {
- File file = createTempFile("raw_", ".bin");
+ protected File createTempFile(byte src[]) throws IOException
+ {
+ File file = createTempFile("raw_", ".bin");
- // write test bytes to file.
- OutputStream os = new FileOutputStream(file);
- os = new BufferedOutputStream(os);
- os.write(src);
- os.close();
+ // write test bytes to file.
+ OutputStream os = new FileOutputStream(file);
+ os = new BufferedOutputStream(os);
+ os.write(src);
+ os.close();
- // test that all bytes written to file.
- assertTrue(src.length == file.length());
+ // test that all bytes written to file.
+ assertTrue(src.length == file.length());
- return file;
- }
+ return file;
+ }
- protected byte[][] getTestByteArrays()
- {
- byte emptyArray[] = (new byte[0]);
+ protected byte[][] getTestByteArrays()
+ {
+ byte emptyArray[] = (new byte[0]);
- byte single[] = new byte[1];
- for (int i = 0; i < single.length; i++)
- single[i] = (byte) i;
+ byte single[] = new byte[1];
+ for (int i = 0; i < single.length; i++)
+ single[i] = (byte) i;
- byte simple[] = new byte[256];
- for (int i = 0; i < simple.length; i++)
- simple[i] = (byte) i;
+ byte simple[] = new byte[256];
+ for (int i = 0; i < simple.length; i++)
+ simple[i] = (byte) i;
- byte zeroes[] = new byte[256];
- for (int i = 0; i < zeroes.length; i++)
- zeroes[i] = 0;
+ byte zeroes[] = new byte[256];
+ for (int i = 0; i < zeroes.length; i++)
+ zeroes[i] = 0;
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- for (int i = 0; i < 256 * 256; i++)
- {
- baos.write(0xff & i);
- baos.write(0xff & (i >> 8));
- }
- byte longArray[] = (baos.toByteArray());
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ for (int i = 0; i < 256 * 256; i++)
+ {
+ baos.write(0xff & i);
+ baos.write(0xff & (i >> 8));
+ }
+ byte longArray[] = (baos.toByteArray());
- return new byte[][] { emptyArray, single, simple, zeroes, longArray, };
- }
+ return new byte[][] { emptyArray, single, simple, zeroes, longArray, };
+ }
}
diff --git a/src/test/java/org/apache/sanselan/formats/bmp/BmpBaseTest.java b/src/test/java/org/apache/sanselan/formats/bmp/BmpBaseTest.java
index ff92c2e..2e715fb 100644
--- a/src/test/java/org/apache/sanselan/formats/bmp/BmpBaseTest.java
+++ b/src/test/java/org/apache/sanselan/formats/bmp/BmpBaseTest.java
@@ -29,24 +29,24 @@
public abstract class BmpBaseTest extends SanselanTest
{
- private static boolean isBmp(File file) throws IOException,
- ImageReadException
- {
- ImageFormat format = Sanselan.guessFormat(file);
- return format == ImageFormat.IMAGE_FORMAT_BMP;
- }
+ private static boolean isBmp(File file) throws IOException,
+ ImageReadException
+ {
+ ImageFormat format = Sanselan.guessFormat(file);
+ return format == ImageFormat.IMAGE_FORMAT_BMP;
+ }
- private static final ImageFilter IMAGE_FILTER = new ImageFilter() {
- public boolean accept(File file) throws IOException, ImageReadException
- {
- return isBmp(file);
- }
- };
+ private static final ImageFilter IMAGE_FILTER = new ImageFilter() {
+ public boolean accept(File file) throws IOException, ImageReadException
+ {
+ return isBmp(file);
+ }
+ };
- protected List getBmpImages() throws IOException, ImageReadException
- {
- return getTestImages(IMAGE_FILTER);
- }
+ protected List getBmpImages() throws IOException, ImageReadException
+ {
+ return getTestImages(IMAGE_FILTER);
+ }
}
diff --git a/src/test/java/org/apache/sanselan/formats/bmp/BmpReadTest.java b/src/test/java/org/apache/sanselan/formats/bmp/BmpReadTest.java
index c8637b9..7384c58 100644
--- a/src/test/java/org/apache/sanselan/formats/bmp/BmpReadTest.java
+++ b/src/test/java/org/apache/sanselan/formats/bmp/BmpReadTest.java
@@ -33,30 +33,30 @@
public class BmpReadTest extends BmpBaseTest
{
- public void test() throws IOException, ImageReadException
- {
- Debug.debug("start");
+ public void test() throws IOException, ImageReadException
+ {
+ Debug.debug("start");
- List images = getBmpImages();
- for (int i = 0; i < images.size(); i++)
- {
- if (i % 10 == 0)
- Debug.purgeMemory();
+ List images = getBmpImages();
+ for (int i = 0; i < images.size(); i++)
+ {
+ if (i % 10 == 0)
+ Debug.purgeMemory();
- File imageFile = (File) images.get(i);
- Debug.debug("imageFile", imageFile);
+ File imageFile = (File) images.get(i);
+ Debug.debug("imageFile", imageFile);
- IImageMetadata metadata = Sanselan.getMetadata(imageFile);
- // assertNotNull(metadata);
+ IImageMetadata metadata = Sanselan.getMetadata(imageFile);
+ // assertNotNull(metadata);
- Map params = new HashMap();
-// params.put(PARAM_KEY_VERBOSE, Boolean.TRUE);
- ImageInfo imageInfo = Sanselan.getImageInfo(imageFile, params);
- assertNotNull(imageInfo);
+ Map params = new HashMap();
+// params.put(PARAM_KEY_VERBOSE, Boolean.TRUE);
+ ImageInfo imageInfo = Sanselan.getImageInfo(imageFile, params);
+ assertNotNull(imageInfo);
- BufferedImage image = Sanselan.getBufferedImage(imageFile);
- assertNotNull(image);
- }
- }
+ BufferedImage image = Sanselan.getBufferedImage(imageFile);
+ assertNotNull(image);
+ }
+ }
}
diff --git a/src/test/java/org/apache/sanselan/formats/bmp/BmpRoundtripTest.java b/src/test/java/org/apache/sanselan/formats/bmp/BmpRoundtripTest.java
index 89ee9b9..7d25632 100644
--- a/src/test/java/org/apache/sanselan/formats/bmp/BmpRoundtripTest.java
+++ b/src/test/java/org/apache/sanselan/formats/bmp/BmpRoundtripTest.java
@@ -34,173 +34,173 @@
public class BmpRoundtripTest extends BmpBaseTest
{
- private int[][] getSimpleRawData(int width, int height, int value)
- {
- int[][] result = new int[height][width];
- for (int y = 0; y < height; y++)
- for (int x = 0; x < width; x++)
- result[y][x] = value;
- return result;
- }
+ private int[][] getSimpleRawData(int width, int height, int value)
+ {
+ int[][] result = new int[height][width];
+ for (int y = 0; y < height; y++)
+ for (int x = 0; x < width; x++)
+ result[y][x] = value;
+ return result;
+ }
- private int[][] getAscendingRawData(int width, int height)
- {
- int[][] result = new int[height][width];
- for (int y = 0; y < height; y++)
- for (int x = 0; x < width; x++)
- {
- int alpha = (x + y) % 256;
- int value = (x + y) % 256;
- int argb = (0xff & alpha) << 24 | (0xff & value) << 16
- | (0xff & value) << 8 | (0xff & value) << 0;
+ private int[][] getAscendingRawData(int width, int height)
+ {
+ int[][] result = new int[height][width];
+ for (int y = 0; y < height; y++)
+ for (int x = 0; x < width; x++)
+ {
+ int alpha = (x + y) % 256;
+ int value = (x + y) % 256;
+ int argb = (0xff & alpha) << 24 | (0xff & value) << 16
+ | (0xff & value) << 8 | (0xff & value) << 0;
- result[y][x] = argb;
- }
- return result;
- }
+ result[y][x] = argb;
+ }
+ return result;
+ }
- private int[][] randomRawData(int width, int height)
- {
- Random random = new Random();
- int[][] result = new int[height][width];
- for (int y = 0; y < height; y++)
- for (int x = 0; x < width; x++)
- {
- int argb = random.nextInt();
- result[y][x] = argb;
- }
- return result;
- }
+ private int[][] randomRawData(int width, int height)
+ {
+ Random random = new Random();
+ int[][] result = new int[height][width];
+ for (int y = 0; y < height; y++)
+ for (int x = 0; x < width; x++)
+ {
+ int argb = random.nextInt();
+ result[y][x] = argb;
+ }
+ return result;
+ }
- public void testSmallBlackPixels() throws IOException,
- ImageReadException,
- ImageWriteException
- {
- int[][] smallBlackPixels = getSimpleRawData(256, 256, 0);
- writeAndReadImageData(smallBlackPixels);
- }
-
- public void testSingleBlackPixel() throws IOException, ImageReadException,
- ImageWriteException
- {
- int[][] singleBlackPixel = getSimpleRawData(1, 1, 0);
- writeAndReadImageData(singleBlackPixel);
- }
+ public void testSmallBlackPixels() throws IOException,
+ ImageReadException,
+ ImageWriteException
+ {
+ int[][] smallBlackPixels = getSimpleRawData(256, 256, 0);
+ writeAndReadImageData(smallBlackPixels);
+ }
-
- public void testSmallRedPixels() throws IOException, ImageReadException,
- ImageWriteException
- {
- int[][] smallRedPixels = getSimpleRawData(256, 256, 0xffff0000);
- writeAndReadImageData(smallRedPixels);
- }
-
- public void testSingleRedPixel() throws IOException, ImageReadException,
- ImageWriteException
- {
- int[][] singleRedPixel = getSimpleRawData(1, 1, 0xffff0000);
- writeAndReadImageData(singleRedPixel);
- }
-
- public void testSmallAscendingPixels() throws IOException,
- ImageReadException, ImageWriteException
- {
- int[][] smallAscendingPixels = getAscendingRawData(256, 256);
- writeAndReadImageData(smallAscendingPixels);
- }
-
- public void testSmallRandomPixels() throws IOException,
- ImageReadException,
- ImageWriteException
- {
- int[][] smallRandomPixels = randomRawData(256, 256);
- writeAndReadImageData(smallRandomPixels);
- }
+ public void testSingleBlackPixel() throws IOException, ImageReadException,
+ ImageWriteException
+ {
+ int[][] singleBlackPixel = getSimpleRawData(1, 1, 0);
+ writeAndReadImageData(singleBlackPixel);
+ }
- private BufferedImage imageDataToBufferedImage(int[][] rawData)
- {
- int width = rawData[0].length;
- int height = rawData.length;
- BufferedImage image = new BufferedImage(width, height,
- BufferedImage.TYPE_INT_ARGB);
- for (int y = 0; y < height; y++)
- for (int x = 0; x < width; x++)
- {
- image.setRGB(x, y, rawData[y][x]);
- }
- return image;
- }
- private int[][] bufferedImageToImageData(BufferedImage image)
- {
- int width = image.getWidth();
- int height = image.getHeight();
- int[][] result = new int[height][width];
+ public void testSmallRedPixels() throws IOException, ImageReadException,
+ ImageWriteException
+ {
+ int[][] smallRedPixels = getSimpleRawData(256, 256, 0xffff0000);
+ writeAndReadImageData(smallRedPixels);
+ }
- for (int y = 0; y < height; y++)
- for (int x = 0; x < width; x++)
- {
- result[y][x] = image.getRGB(x, y);
- }
- return result;
- }
+ public void testSingleRedPixel() throws IOException, ImageReadException,
+ ImageWriteException
+ {
+ int[][] singleRedPixel = getSimpleRawData(1, 1, 0xffff0000);
+ writeAndReadImageData(singleRedPixel);
+ }
- private void writeAndReadImageData(int[][] rawData) throws IOException,
- ImageReadException, ImageWriteException
- {
- BufferedImage srcImage = imageDataToBufferedImage(rawData);
+ public void testSmallAscendingPixels() throws IOException,
+ ImageReadException, ImageWriteException
+ {
+ int[][] smallAscendingPixels = getAscendingRawData(256, 256);
+ writeAndReadImageData(smallAscendingPixels);
+ }
- Map writeParams = new HashMap();
- // writeParams.put(SanselanConstants.PARAM_KEY_FORMAT,
- // ImageFormat.IMAGE_FORMAT_BMP);
- // writeParams.put(PngConstants.PARAM_KEY_BMP_FORCE_TRUE_COLOR,
- // Boolean.TRUE);
+ public void testSmallRandomPixels() throws IOException,
+ ImageReadException,
+ ImageWriteException
+ {
+ int[][] smallRandomPixels = randomRawData(256, 256);
+ writeAndReadImageData(smallRandomPixels);
+ }
- byte bytes[] = Sanselan.writeImageToBytes(srcImage,
- ImageFormat.IMAGE_FORMAT_BMP, writeParams);
+ private BufferedImage imageDataToBufferedImage(int[][] rawData)
+ {
+ int width = rawData[0].length;
+ int height = rawData.length;
+ BufferedImage image = new BufferedImage(width, height,
+ BufferedImage.TYPE_INT_ARGB);
+ for (int y = 0; y < height; y++)
+ for (int x = 0; x < width; x++)
+ {
+ image.setRGB(x, y, rawData[y][x]);
+ }
+ return image;
+ }
- // Debug.debug("bytes", bytes);
+ private int[][] bufferedImageToImageData(BufferedImage image)
+ {
+ int width = image.getWidth();
+ int height = image.getHeight();
+ int[][] result = new int[height][width];
- File tempFile = createTempFile("temp", ".bmp");
- IOUtils.writeToFile(bytes, tempFile);
+ for (int y = 0; y < height; y++)
+ for (int x = 0; x < width; x++)
+ {
+ result[y][x] = image.getRGB(x, y);
+ }
+ return result;
+ }
- BufferedImage dstImage = Sanselan.getBufferedImage(bytes);
+ private void writeAndReadImageData(int[][] rawData) throws IOException,
+ ImageReadException, ImageWriteException
+ {
+ BufferedImage srcImage = imageDataToBufferedImage(rawData);
- assertNotNull(dstImage);
- assertTrue(srcImage.getWidth() == dstImage.getWidth());
- assertTrue(srcImage.getHeight() == dstImage.getHeight());
+ Map writeParams = new HashMap();
+ // writeParams.put(SanselanConstants.PARAM_KEY_FORMAT,
+ // ImageFormat.IMAGE_FORMAT_BMP);
+ // writeParams.put(PngConstants.PARAM_KEY_BMP_FORCE_TRUE_COLOR,
+ // Boolean.TRUE);
- int dstData[][] = bufferedImageToImageData(dstImage);
- compare(rawData, dstData);
- }
+ byte bytes[] = Sanselan.writeImageToBytes(srcImage,
+ ImageFormat.IMAGE_FORMAT_BMP, writeParams);
- private void compare(int[][] a, int[][] b)
- {
- assertNotNull(a);
- assertNotNull(b);
- assertTrue(a.length == b.length);
+ // Debug.debug("bytes", bytes);
- for (int y = 0; y < a.length; y++)
- {
- assertTrue(a[y].length == b[y].length);
- // make sure row lengths consistent.
- assertTrue(a[0].length == b[y].length);
- for (int x = 0; x < a[y].length; x++)
- {
- // ignore alpha channel - BMP has no transparency.
- int rgbA = 0xffffff & a[y][x];
- int rgbB = 0xffffff & b[y][x];
+ File tempFile = createTempFile("temp", ".bmp");
+ IOUtils.writeToFile(bytes, tempFile);
- if (rgbA != rgbB)
- {
- Debug.debug("x: " + x + ", y: " + y + ", rgbA: " + rgbA
- + " (0x" + Integer.toHexString(rgbA) + ")"
- + ", rgbB: " + rgbB + " (0x"
- + Integer.toHexString(rgbB) + ")");
- }
- assertTrue(rgbA == rgbB);
- }
- }
- }
+ BufferedImage dstImage = Sanselan.getBufferedImage(bytes);
+
+ assertNotNull(dstImage);
+ assertTrue(srcImage.getWidth() == dstImage.getWidth());
+ assertTrue(srcImage.getHeight() == dstImage.getHeight());
+
+ int dstData[][] = bufferedImageToImageData(dstImage);
+ compare(rawData, dstData);
+ }
+
+ private void compare(int[][] a, int[][] b)
+ {
+ assertNotNull(a);
+ assertNotNull(b);
+ assertTrue(a.length == b.length);
+
+ for (int y = 0; y < a.length; y++)
+ {
+ assertTrue(a[y].length == b[y].length);
+ // make sure row lengths consistent.
+ assertTrue(a[0].length == b[y].length);
+ for (int x = 0; x < a[y].length; x++)
+ {
+ // ignore alpha channel - BMP has no transparency.
+ int rgbA = 0xffffff & a[y][x];
+ int rgbB = 0xffffff & b[y][x];
+
+ if (rgbA != rgbB)
+ {
+ Debug.debug("x: " + x + ", y: " + y + ", rgbA: " + rgbA
+ + " (0x" + Integer.toHexString(rgbA) + ")"
+ + ", rgbB: " + rgbB + " (0x"
+ + Integer.toHexString(rgbB) + ")");
+ }
+ assertTrue(rgbA == rgbB);
+ }
+ }
+ }
}
diff --git a/src/test/java/org/apache/sanselan/formats/gif/GifBaseTest.java b/src/test/java/org/apache/sanselan/formats/gif/GifBaseTest.java
index ec4b8ea..8265b5b 100644
--- a/src/test/java/org/apache/sanselan/formats/gif/GifBaseTest.java
+++ b/src/test/java/org/apache/sanselan/formats/gif/GifBaseTest.java
@@ -29,23 +29,23 @@
public abstract class GifBaseTest extends SanselanTest
{
- private static boolean isGif(File file) throws IOException,
- ImageReadException
- {
- ImageFormat format = Sanselan.guessFormat(file);
- return format == ImageFormat.IMAGE_FORMAT_GIF;
- }
+ private static boolean isGif(File file) throws IOException,
+ ImageReadException
+ {
+ ImageFormat format = Sanselan.guessFormat(file);
+ return format == ImageFormat.IMAGE_FORMAT_GIF;
+ }
- private static final ImageFilter IMAGE_FILTER = new ImageFilter() {
- public boolean accept(File file) throws IOException, ImageReadException
- {
- return isGif(file);
- }
- };
+ private static final ImageFilter IMAGE_FILTER = new ImageFilter() {
+ public boolean accept(File file) throws IOException, ImageReadException
+ {
+ return isGif(file);
+ }
+ };
- protected List getGifImages() throws IOException, ImageReadException
- {
- return getTestImages(IMAGE_FILTER);
- }
+ protected List getGifImages() throws IOException, ImageReadException
+ {
+ return getTestImages(IMAGE_FILTER);
+ }
}
diff --git a/src/test/java/org/apache/sanselan/formats/gif/GifReadTest.java b/src/test/java/org/apache/sanselan/formats/gif/GifReadTest.java
index d7fbd6b..839b37f 100644
--- a/src/test/java/org/apache/sanselan/formats/gif/GifReadTest.java
+++ b/src/test/java/org/apache/sanselan/formats/gif/GifReadTest.java
@@ -31,28 +31,28 @@
public class GifReadTest extends GifBaseTest
{
- public void test() throws IOException, ImageReadException
- {
- Debug.debug("start");
+ public void test() throws IOException, ImageReadException
+ {
+ Debug.debug("start");
- List images = getGifImages();
- for (int i = 0; i < images.size(); i++)
- {
- if (i % 10 == 0)
- Debug.purgeMemory();
+ List images = getGifImages();
+ for (int i = 0; i < images.size(); i++)
+ {
+ if (i % 10 == 0)
+ Debug.purgeMemory();
- File imageFile = (File) images.get(i);
- Debug.debug("imageFile", imageFile);
+ File imageFile = (File) images.get(i);
+ Debug.debug("imageFile", imageFile);
- IImageMetadata metadata = Sanselan.getMetadata(imageFile);
-// assertNotNull(metadata);
+ IImageMetadata metadata = Sanselan.getMetadata(imageFile);
+// assertNotNull(metadata);
- ImageInfo imageInfo = Sanselan.getImageInfo(imageFile);
- assertNotNull(imageInfo);
+ ImageInfo imageInfo = Sanselan.getImageInfo(imageFile);
+ assertNotNull(imageInfo);
- BufferedImage image = Sanselan.getBufferedImage(imageFile);
- assertNotNull(image);
- }
- }
+ BufferedImage image = Sanselan.getBufferedImage(imageFile);
+ assertNotNull(image);
+ }
+ }
}
diff --git a/src/test/java/org/apache/sanselan/formats/ico/IcoBaseTest.java b/src/test/java/org/apache/sanselan/formats/ico/IcoBaseTest.java
index 87f2d81..d4128d3 100644
--- a/src/test/java/org/apache/sanselan/formats/ico/IcoBaseTest.java
+++ b/src/test/java/org/apache/sanselan/formats/ico/IcoBaseTest.java
@@ -27,23 +27,23 @@
public abstract class IcoBaseTest extends SanselanTest
{
- private static boolean isIco(File file)
- {
- return file.getName().toLowerCase().endsWith(".ico") ||
- file.getName().toLowerCase().endsWith(".cur");
- }
+ private static boolean isIco(File file)
+ {
+ return file.getName().toLowerCase().endsWith(".ico") ||
+ file.getName().toLowerCase().endsWith(".cur");
+ }
- private static final ImageFilter IMAGE_FILTER = new ImageFilter() {
- public boolean accept(File file) throws IOException, ImageReadException
- {
- return isIco(file);
- }
- };
+ private static final ImageFilter IMAGE_FILTER = new ImageFilter() {
+ public boolean accept(File file) throws IOException, ImageReadException
+ {
+ return isIco(file);
+ }
+ };
- protected List getIcoImages() throws IOException, ImageReadException
- {
- return getTestImages(IMAGE_FILTER);
- }
+ protected List getIcoImages() throws IOException, ImageReadException
+ {
+ return getTestImages(IMAGE_FILTER);
+ }
}
diff --git a/src/test/java/org/apache/sanselan/formats/ico/IcoReadTest.java b/src/test/java/org/apache/sanselan/formats/ico/IcoReadTest.java
index fbfd920..c27f66e 100644
--- a/src/test/java/org/apache/sanselan/formats/ico/IcoReadTest.java
+++ b/src/test/java/org/apache/sanselan/formats/ico/IcoReadTest.java
@@ -33,29 +33,29 @@
public class IcoReadTest extends IcoBaseTest
{
- public void test() throws IOException, ImageReadException
- {
- Debug.debug("start");
+ public void test() throws IOException, ImageReadException
+ {
+ Debug.debug("start");
- List images = getIcoImages();
- for (int i = 0; i < images.size(); i++)
- {
- if (i % 10 == 0)
- Debug.purgeMemory();
+ List images = getIcoImages();
+ for (int i = 0; i < images.size(); i++)
+ {
+ if (i % 10 == 0)
+ Debug.purgeMemory();
- File imageFile = (File) images.get(i);
- Debug.debug("imageFile", imageFile);
+ File imageFile = (File) images.get(i);
+ Debug.debug("imageFile", imageFile);
- IImageMetadata metadata = Sanselan.getMetadata(imageFile);
- // assertNotNull(metadata);
+ IImageMetadata metadata = Sanselan.getMetadata(imageFile);
+ // assertNotNull(metadata);
- Map params = new HashMap();
- ImageInfo imageInfo = Sanselan.getImageInfo(imageFile, params);
- // assertNotNull(imageInfo);
+ Map params = new HashMap();
+ ImageInfo imageInfo = Sanselan.getImageInfo(imageFile, params);
+ // assertNotNull(imageInfo);
- BufferedImage image = Sanselan.getBufferedImage(imageFile);
- assertNotNull(image);
- }
- }
+ BufferedImage image = Sanselan.getBufferedImage(imageFile);
+ assertNotNull(image);
+ }
+ }
}
diff --git a/src/test/java/org/apache/sanselan/formats/ico/IcoRoundtripTest.java b/src/test/java/org/apache/sanselan/formats/ico/IcoRoundtripTest.java
index b620b8b..0d34531 100644
--- a/src/test/java/org/apache/sanselan/formats/ico/IcoRoundtripTest.java
+++ b/src/test/java/org/apache/sanselan/formats/ico/IcoRoundtripTest.java
@@ -34,559 +34,559 @@
public class IcoRoundtripTest extends IcoBaseTest
{
- // 16x16 test image
- private static final int[][] image = {
- {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
- {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
- {0,0,0,0,1,0,0,0,0,0,1,1,0,0,0,0},
- {0,0,0,1,1,0,0,0,0,1,0,0,1,0,0,0},
- {0,0,1,0,1,0,0,0,1,0,0,0,0,1,0,0},
- {0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0},
- {0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0},
- {0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0},
- {0,0,0,0,1,0,0,0,1,0,1,1,1,0,0,0},
- {0,0,0,0,1,0,0,0,1,1,0,0,0,1,0,0},
- {0,0,0,0,1,0,0,0,1,0,0,0,0,1,0,0},
- {0,0,0,0,1,0,0,0,1,0,0,0,0,1,0,0},
- {0,0,0,0,1,0,0,0,0,1,0,0,0,1,0,0},
- {0,0,0,0,1,0,0,0,0,0,1,1,1,0,0,0},
- {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
- {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
- };
+ // 16x16 test image
+ private static final int[][] image = {
+ {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
+ {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
+ {0,0,0,0,1,0,0,0,0,0,1,1,0,0,0,0},
+ {0,0,0,1,1,0,0,0,0,1,0,0,1,0,0,0},
+ {0,0,1,0,1,0,0,0,1,0,0,0,0,1,0,0},
+ {0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0},
+ {0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0},
+ {0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0},
+ {0,0,0,0,1,0,0,0,1,0,1,1,1,0,0,0},
+ {0,0,0,0,1,0,0,0,1,1,0,0,0,1,0,0},
+ {0,0,0,0,1,0,0,0,1,0,0,0,0,1,0,0},
+ {0,0,0,0,1,0,0,0,1,0,0,0,0,1,0,0},
+ {0,0,0,0,1,0,0,0,0,1,0,0,0,1,0,0},
+ {0,0,0,0,1,0,0,0,0,0,1,1,1,0,0,0},
+ {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
+ {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
+ };
- private Map generatorMap = new HashMap();
+ private Map generatorMap = new HashMap();
- public IcoRoundtripTest()
- {
- generatorMap.put(Integer.valueOf(1), new GeneratorFor1BitBitmaps());
- generatorMap.put(Integer.valueOf(4), new GeneratorFor4BitBitmaps());
- generatorMap.put(Integer.valueOf(8), new GeneratorFor8BitBitmaps());
- generatorMap.put(Integer.valueOf(16), new GeneratorFor16BitBitmaps());
- generatorMap.put(Integer.valueOf(24), new GeneratorFor24BitBitmaps());
- generatorMap.put(Integer.valueOf(32), new GeneratorFor32BitBitmaps());
- }
+ public IcoRoundtripTest()
+ {
+ generatorMap.put(Integer.valueOf(1), new GeneratorFor1BitBitmaps());
+ generatorMap.put(Integer.valueOf(4), new GeneratorFor4BitBitmaps());
+ generatorMap.put(Integer.valueOf(8), new GeneratorFor8BitBitmaps());
+ generatorMap.put(Integer.valueOf(16), new GeneratorFor16BitBitmaps());
+ generatorMap.put(Integer.valueOf(24), new GeneratorFor24BitBitmaps());
+ generatorMap.put(Integer.valueOf(32), new GeneratorFor32BitBitmaps());
+ }
- private static interface BitmapGenerator
- {
- byte[] generateBitmap(int foreground, int background, int paletteSize)
- throws IOException, ImageWriteException;
- }
+ private static interface BitmapGenerator
+ {
+ byte[] generateBitmap(int foreground, int background, int paletteSize)
+ throws IOException, ImageWriteException;
+ }
- private class GeneratorFor1BitBitmaps implements BitmapGenerator
- {
- public byte[] generateBitmap(int foreground, int background, int paletteSize)
- throws IOException, ImageWriteException
- {
- ByteArrayOutputStream byteArrayStream = new ByteArrayOutputStream();
- BinaryOutputStream bos = new BinaryOutputStream(byteArrayStream,
- BinaryOutputStream.BYTE_ORDER_LITTLE_ENDIAN);
- // Palette
- bos.write3Bytes(background);
- bos.write(0);
- bos.write3Bytes(foreground);
- bos.write(0);
- for (int i = 2; i < paletteSize; i++)
- bos.write4Bytes(0);
- // Image
- for (int y = 15; y >= 0; y--)
- {
- for (int x = 0; x < 16; x += 8)
- {
- bos.write(
- ((0x1 & image[y][x]) << 7) |
- ((0x1 & image[y][x+1]) << 6) |
- ((0x1 & image[y][x+2]) << 5) |
- ((0x1 & image[y][x+3]) << 4) |
- ((0x1 & image[y][x+4]) << 3) |
- ((0x1 & image[y][x+5]) << 2) |
- ((0x1 & image[y][x+6]) << 1) |
- ((0x1 & image[y][x+7]) << 0));
- }
- // Pad to multiple of 32 bytes
- bos.write(0);
- bos.write(0);
- }
- // Mask
- for (int y = image.length - 1; y >= 0; y--)
- {
- bos.write(0);
- bos.write(0);
- // Pad to 4 bytes:
- bos.write(0);
- bos.write(0);
- }
- bos.flush();
- return byteArrayStream.toByteArray();
- }
- }
+ private class GeneratorFor1BitBitmaps implements BitmapGenerator
+ {
+ public byte[] generateBitmap(int foreground, int background, int paletteSize)
+ throws IOException, ImageWriteException
+ {
+ ByteArrayOutputStream byteArrayStream = new ByteArrayOutputStream();
+ BinaryOutputStream bos = new BinaryOutputStream(byteArrayStream,
+ BinaryOutputStream.BYTE_ORDER_LITTLE_ENDIAN);
+ // Palette
+ bos.write3Bytes(background);
+ bos.write(0);
+ bos.write3Bytes(foreground);
+ bos.write(0);
+ for (int i = 2; i < paletteSize; i++)
+ bos.write4Bytes(0);
+ // Image
+ for (int y = 15; y >= 0; y--)
+ {
+ for (int x = 0; x < 16; x += 8)
+ {
+ bos.write(
+ ((0x1 & image[y][x]) << 7) |
+ ((0x1 & image[y][x+1]) << 6) |
+ ((0x1 & image[y][x+2]) << 5) |
+ ((0x1 & image[y][x+3]) << 4) |
+ ((0x1 & image[y][x+4]) << 3) |
+ ((0x1 & image[y][x+5]) << 2) |
+ ((0x1 & image[y][x+6]) << 1) |
+ ((0x1 & image[y][x+7]) << 0));
+ }
+ // Pad to multiple of 32 bytes
+ bos.write(0);
+ bos.write(0);
+ }
+ // Mask
+ for (int y = image.length - 1; y >= 0; y--)
+ {
+ bos.write(0);
+ bos.write(0);
+ // Pad to 4 bytes:
+ bos.write(0);
+ bos.write(0);
+ }
+ bos.flush();
+ return byteArrayStream.toByteArray();
+ }
+ }
- private class GeneratorFor4BitBitmaps implements BitmapGenerator
- {
- public byte[] generateBitmap(int foreground, int background, int paletteSize)
- throws IOException, ImageWriteException
- {
- ByteArrayOutputStream byteArrayStream = new ByteArrayOutputStream();
- BinaryOutputStream bos = new BinaryOutputStream(byteArrayStream,
- BinaryOutputStream.BYTE_ORDER_LITTLE_ENDIAN);
- // Palette
- bos.write3Bytes(background);
- bos.write(0);
- bos.write3Bytes(foreground);
- bos.write(0);
- for (int i = 2; i < paletteSize; i++)
- bos.write4Bytes(0);
- // Image
- for (int y = 15; y >= 0; y--)
- {
- for (int x = 0; x < 16; x += 2)
- {
- bos.write(((0xf & image[y][x]) << 4) |
- (0xf & image[y][x+1]));
- }
- }
- // Mask
- for (int y = image.length - 1; y >= 0; y--)
- {
- bos.write(0);
- bos.write(0);
- // Pad to 4 bytes:
- bos.write(0);
- bos.write(0);
- }
- bos.flush();
- return byteArrayStream.toByteArray();
- }
- }
+ private class GeneratorFor4BitBitmaps implements BitmapGenerator
+ {
+ public byte[] generateBitmap(int foreground, int background, int paletteSize)
+ throws IOException, ImageWriteException
+ {
+ ByteArrayOutputStream byteArrayStream = new ByteArrayOutputStream();
+ BinaryOutputStream bos = new BinaryOutputStream(byteArrayStream,
+ BinaryOutputStream.BYTE_ORDER_LITTLE_ENDIAN);
+ // Palette
+ bos.write3Bytes(background);
+ bos.write(0);
+ bos.write3Bytes(foreground);
+ bos.write(0);
+ for (int i = 2; i < paletteSize; i++)
+ bos.write4Bytes(0);
+ // Image
+ for (int y = 15; y >= 0; y--)
+ {
+ for (int x = 0; x < 16; x += 2)
+ {
+ bos.write(((0xf & image[y][x]) << 4) |
+ (0xf & image[y][x+1]));
+ }
+ }
+ // Mask
+ for (int y = image.length - 1; y >= 0; y--)
+ {
+ bos.write(0);
+ bos.write(0);
+ // Pad to 4 bytes:
+ bos.write(0);
+ bos.write(0);
+ }
+ bos.flush();
+ return byteArrayStream.toByteArray();
+ }
+ }
- private class GeneratorFor8BitBitmaps implements BitmapGenerator
- {
- public byte[] generateBitmap(int foreground, int background, int paletteSize)
- throws IOException, ImageWriteException
- {
- ByteArrayOutputStream byteArrayStream = new ByteArrayOutputStream();
- BinaryOutputStream bos = new BinaryOutputStream(byteArrayStream,
- BinaryOutputStream.BYTE_ORDER_LITTLE_ENDIAN);
- // Palette
- bos.write3Bytes(background);
- bos.write(0);
- bos.write3Bytes(foreground);
- bos.write(0);
- for (int i = 2; i < paletteSize; i++)
- bos.write4Bytes(0);
- // Image
- for (int y = 15; y >= 0; y--)
- {
- for (int x = 0; x < 16; x++)
- {
- bos.write(image[y][x]);
- }
- }
- // Mask
- for (int y = image.length - 1; y >= 0; y--)
- {
- bos.write(0);
- bos.write(0);
- // Pad to 4 bytes:
- bos.write(0);
- bos.write(0);
- }
- bos.flush();
- return byteArrayStream.toByteArray();
- }
- }
+ private class GeneratorFor8BitBitmaps implements BitmapGenerator
+ {
+ public byte[] generateBitmap(int foreground, int background, int paletteSize)
+ throws IOException, ImageWriteException
+ {
+ ByteArrayOutputStream byteArrayStream = new ByteArrayOutputStream();
+ BinaryOutputStream bos = new BinaryOutputStream(byteArrayStream,
+ BinaryOutputStream.BYTE_ORDER_LITTLE_ENDIAN);
+ // Palette
+ bos.write3Bytes(background);
+ bos.write(0);
+ bos.write3Bytes(foreground);
+ bos.write(0);
+ for (int i = 2; i < paletteSize; i++)
+ bos.write4Bytes(0);
+ // Image
+ for (int y = 15; y >= 0; y--)
+ {
+ for (int x = 0; x < 16; x++)
+ {
+ bos.write(image[y][x]);
+ }
+ }
+ // Mask
+ for (int y = image.length - 1; y >= 0; y--)
+ {
+ bos.write(0);
+ bos.write(0);
+ // Pad to 4 bytes:
+ bos.write(0);
+ bos.write(0);
+ }
+ bos.flush();
+ return byteArrayStream.toByteArray();
+ }
+ }
- private class GeneratorFor16BitBitmaps implements BitmapGenerator
- {
- public byte[] generateBitmap(int foreground, int background, int paletteSize)
- throws IOException, ImageWriteException
- {
- ByteArrayOutputStream byteArrayStream = new ByteArrayOutputStream();
- BinaryOutputStream bos = new BinaryOutputStream(byteArrayStream,
- BinaryOutputStream.BYTE_ORDER_LITTLE_ENDIAN);
- // Palette
- for (int i = 0; i < paletteSize; i++)
- bos.write4Bytes(0);
- // Image
- for (int y = 15; y >= 0; y--)
- {
- for (int x = 0; x < 16; x++)
- {
- if (image[y][x] == 1)
- bos.write2Bytes((0x1f & (foreground >> 3)) |
- ((0x1f & (foreground >> 11)) << 5) |
- ((0x1f & (foreground >> 19)) << 10));
- else
- bos.write2Bytes((0x1f & (background >> 3)) |
- ((0x1f & (background >> 11)) << 5) |
- ((0x1f & (background >> 19)) << 10));
- }
- }
- // Mask
- for (int y = image.length - 1; y >= 0; y--)
- {
- bos.write(0);
- bos.write(0);
- // Pad to 4 bytes:
- bos.write(0);
- bos.write(0);
- }
- bos.flush();
- return byteArrayStream.toByteArray();
- }
- }
+ private class GeneratorFor16BitBitmaps implements BitmapGenerator
+ {
+ public byte[] generateBitmap(int foreground, int background, int paletteSize)
+ throws IOException, ImageWriteException
+ {
+ ByteArrayOutputStream byteArrayStream = new ByteArrayOutputStream();
+ BinaryOutputStream bos = new BinaryOutputStream(byteArrayStream,
+ BinaryOutputStream.BYTE_ORDER_LITTLE_ENDIAN);
+ // Palette
+ for (int i = 0; i < paletteSize; i++)
+ bos.write4Bytes(0);
+ // Image
+ for (int y = 15; y >= 0; y--)
+ {
+ for (int x = 0; x < 16; x++)
+ {
+ if (image[y][x] == 1)
+ bos.write2Bytes((0x1f & (foreground >> 3)) |
+ ((0x1f & (foreground >> 11)) << 5) |
+ ((0x1f & (foreground >> 19)) << 10));
+ else
+ bos.write2Bytes((0x1f & (background >> 3)) |
+ ((0x1f & (background >> 11)) << 5) |
+ ((0x1f & (background >> 19)) << 10));
+ }
+ }
+ // Mask
+ for (int y = image.length - 1; y >= 0; y--)
+ {
+ bos.write(0);
+ bos.write(0);
+ // Pad to 4 bytes:
+ bos.write(0);
+ bos.write(0);
+ }
+ bos.flush();
+ return byteArrayStream.toByteArray();
+ }
+ }
- private class GeneratorFor24BitBitmaps implements BitmapGenerator
- {
- public byte[] generateBitmap(int foreground, int background, int paletteSize)
- throws IOException, ImageWriteException
- {
- ByteArrayOutputStream byteArrayStream = new ByteArrayOutputStream();
- BinaryOutputStream bos = new BinaryOutputStream(byteArrayStream,
- BinaryOutputStream.BYTE_ORDER_LITTLE_ENDIAN);
- // Palette
- for (int i = 0; i < paletteSize; i++)
- bos.write4Bytes(0);
- // Image
- for (int y = 15; y >= 0; y--)
- {
- for (int x = 0; x < 16; x++)
- {
- if (image[y][x] == 1)
- bos.write3Bytes(0xffffff & foreground);
- else
- bos.write3Bytes(0xffffff & background);
- }
- }
- // Mask
- for (int y = image.length - 1; y >= 0; y--)
- {
- bos.write(0);
- bos.write(0);
- // Pad to 4 bytes:
- bos.write(0);
- bos.write(0);
- }
- bos.flush();
- return byteArrayStream.toByteArray();
- }
- }
+ private class GeneratorFor24BitBitmaps implements BitmapGenerator
+ {
+ public byte[] generateBitmap(int foreground, int background, int paletteSize)
+ throws IOException, ImageWriteException
+ {
+ ByteArrayOutputStream byteArrayStream = new ByteArrayOutputStream();
+ BinaryOutputStream bos = new BinaryOutputStream(byteArrayStream,
+ BinaryOutputStream.BYTE_ORDER_LITTLE_ENDIAN);
+ // Palette
+ for (int i = 0; i < paletteSize; i++)
+ bos.write4Bytes(0);
+ // Image
+ for (int y = 15; y >= 0; y--)
+ {
+ for (int x = 0; x < 16; x++)
+ {
+ if (image[y][x] == 1)
+ bos.write3Bytes(0xffffff & foreground);
+ else
+ bos.write3Bytes(0xffffff & background);
+ }
+ }
+ // Mask
+ for (int y = image.length - 1; y >= 0; y--)
+ {
+ bos.write(0);
+ bos.write(0);
+ // Pad to 4 bytes:
+ bos.write(0);
+ bos.write(0);
+ }
+ bos.flush();
+ return byteArrayStream.toByteArray();
+ }
+ }
- private class GeneratorFor32BitBitmaps implements BitmapGenerator
- {
- public byte[] generateBitmap(int foreground, int background, int paletteSize)
- throws IOException, ImageWriteException
- {
- return generate32bitRGBABitmap(foreground, background, paletteSize, true);
- }
+ private class GeneratorFor32BitBitmaps implements BitmapGenerator
+ {
+ public byte[] generateBitmap(int foreground, int background, int paletteSize)
+ throws IOException, ImageWriteException
+ {
+ return generate32bitRGBABitmap(foreground, background, paletteSize, true);
+ }
- public byte[] generate32bitRGBABitmap(int foreground, int background,
- int paletteSize, boolean writeMask) throws IOException,
- ImageWriteException
- {
- ByteArrayOutputStream byteArrayStream = new ByteArrayOutputStream();
- BinaryOutputStream bos = new BinaryOutputStream(byteArrayStream,
- BinaryOutputStream.BYTE_ORDER_LITTLE_ENDIAN);
- // Palette
- for (int i = 0; i < paletteSize; i++)
- bos.write4Bytes(0);
- // Image
- for (int y = 15; y >= 0; y--)
- {
- for (int x = 0; x < 16; x++)
- {
- if (image[y][x] == 1)
- bos.write4Bytes(foreground);
- else
- bos.write4Bytes(background);
- }
- }
- // Mask
- if (writeMask)
- {
- for (int y = image.length - 1; y >= 0; y--)
- {
- bos.write(0);
- bos.write(0);
- // Pad to 4 bytes:
- bos.write(0);
- bos.write(0);
- }
- }
- bos.flush();
- return byteArrayStream.toByteArray();
- }
- }
+ public byte[] generate32bitRGBABitmap(int foreground, int background,
+ int paletteSize, boolean writeMask) throws IOException,
+ ImageWriteException
+ {
+ ByteArrayOutputStream byteArrayStream = new ByteArrayOutputStream();
+ BinaryOutputStream bos = new BinaryOutputStream(byteArrayStream,
+ BinaryOutputStream.BYTE_ORDER_LITTLE_ENDIAN);
+ // Palette
+ for (int i = 0; i < paletteSize; i++)
+ bos.write4Bytes(0);
+ // Image
+ for (int y = 15; y >= 0; y--)
+ {
+ for (int x = 0; x < 16; x++)
+ {
+ if (image[y][x] == 1)
+ bos.write4Bytes(foreground);
+ else
+ bos.write4Bytes(background);
+ }
+ }
+ // Mask
+ if (writeMask)
+ {
+ for (int y = image.length - 1; y >= 0; y--)
+ {
+ bos.write(0);
+ bos.write(0);
+ // Pad to 4 bytes:
+ bos.write(0);
+ bos.write(0);
+ }
+ }
+ bos.flush();
+ return byteArrayStream.toByteArray();
+ }
+ }
- private void writeICONDIR(BinaryOutputStream bos, int reserved, int type, int count)
- throws IOException, ImageWriteException
- {
- bos.write2Bytes(reserved);
- bos.write2Bytes(type);
- bos.write2Bytes(count);
- }
+ private void writeICONDIR(BinaryOutputStream bos, int reserved, int type, int count)
+ throws IOException, ImageWriteException
+ {
+ bos.write2Bytes(reserved);
+ bos.write2Bytes(type);
+ bos.write2Bytes(count);
+ }
- private void writeICONDIRENTRY(BinaryOutputStream bos, int width, int height,
- int colorCount, int reserved, int planes, int bitCount, int bytesInRes)
- throws IOException, ImageWriteException
- {
- bos.write(width);
- bos.write(height);
- bos.write(colorCount);
- bos.write(reserved);
- bos.write2Bytes(planes);
- bos.write2Bytes(bitCount);
- bos.write4Bytes(bytesInRes);
- bos.write4Bytes(22); // image comes immediately after this
- }
+ private void writeICONDIRENTRY(BinaryOutputStream bos, int width, int height,
+ int colorCount, int reserved, int planes, int bitCount, int bytesInRes)
+ throws IOException, ImageWriteException
+ {
+ bos.write(width);
+ bos.write(height);
+ bos.write(colorCount);
+ bos.write(reserved);
+ bos.write2Bytes(planes);
+ bos.write2Bytes(bitCount);
+ bos.write4Bytes(bytesInRes);
+ bos.write4Bytes(22); // image comes immediately after this
+ }
- private void writeBITMAPINFOHEADER(BinaryOutputStream bos, int width, int height,
- int colorPlanes, int bitCount, int compression, int colorsUsed,
- int colorsImportant) throws IOException, ImageWriteException
- {
- // BITMAPINFOHEADER
- bos.write4Bytes(40); // biSize, always 40 for BITMAPINFOHEADER
- bos.write4Bytes(width); // biWidth
- bos.write4Bytes(height); // biHeight
- bos.write2Bytes(colorPlanes); // biPlanes
- bos.write2Bytes(bitCount); // bitCount
- bos.write4Bytes(compression); // biCompression
- bos.write4Bytes(0); // biSizeImage, can be 0 for uncompressed
- bos.write4Bytes(0); // X pixels per metre
- bos.write4Bytes(0); // Y pixels per metre
- bos.write4Bytes(colorsUsed); // colors used, ignored
- bos.write4Bytes(colorsImportant); // colors important
- }
+ private void writeBITMAPINFOHEADER(BinaryOutputStream bos, int width, int height,
+ int colorPlanes, int bitCount, int compression, int colorsUsed,
+ int colorsImportant) throws IOException, ImageWriteException
+ {
+ // BITMAPINFOHEADER
+ bos.write4Bytes(40); // biSize, always 40 for BITMAPINFOHEADER
+ bos.write4Bytes(width); // biWidth
+ bos.write4Bytes(height); // biHeight
+ bos.write2Bytes(colorPlanes); // biPlanes
+ bos.write2Bytes(bitCount); // bitCount
+ bos.write4Bytes(compression); // biCompression
+ bos.write4Bytes(0); // biSizeImage, can be 0 for uncompressed
+ bos.write4Bytes(0); // X pixels per metre
+ bos.write4Bytes(0); // Y pixels per metre
+ bos.write4Bytes(colorsUsed); // colors used, ignored
+ bos.write4Bytes(colorsImportant); // colors important
+ }
- public void testNormalIcons() throws IOException, ImageWriteException, ImageReadException
- {
- final int foreground = 0xFFF000E0;
- final int background = 0xFF102030;
- for (Iterator it = generatorMap.entrySet().iterator(); it.hasNext(); )
- {
- Map.Entry entry = (Map.Entry) it.next();
- int bitDepth = ((Integer)entry.getKey()).intValue();
- BitmapGenerator bitmapGenerator = (BitmapGenerator) entry.getValue();
+ public void testNormalIcons() throws IOException, ImageWriteException, ImageReadException
+ {
+ final int foreground = 0xFFF000E0;
+ final int background = 0xFF102030;
+ for (Iterator it = generatorMap.entrySet().iterator(); it.hasNext(); )
+ {
+ Map.Entry entry = (Map.Entry) it.next();
+ int bitDepth = ((Integer)entry.getKey()).intValue();
+ BitmapGenerator bitmapGenerator = (BitmapGenerator) entry.getValue();
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- BinaryOutputStream bos = new BinaryOutputStream(baos,
- BinaryOutputStream.BYTE_ORDER_LITTLE_ENDIAN);
- byte[] bitmap = bitmapGenerator.generateBitmap(foreground, background,
- (bitDepth <= 8) ? (1 << bitDepth) : 0);
- writeICONDIR(bos, 0, 1, 1);
- writeICONDIRENTRY(bos, 16, 16, 0, 0, 1, bitDepth, 40 + bitmap.length);
- writeBITMAPINFOHEADER(bos, 16, 2*16, 1, bitDepth, 0, 0, 0);
- bos.write(bitmap);
- bos.flush();
- writeAndReadImageData("16x16x" + bitDepth, baos.toByteArray(), foreground, background);
- }
- }
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ BinaryOutputStream bos = new BinaryOutputStream(baos,
+ BinaryOutputStream.BYTE_ORDER_LITTLE_ENDIAN);
+ byte[] bitmap = bitmapGenerator.generateBitmap(foreground, background,
+ (bitDepth <= 8) ? (1 << bitDepth) : 0);
+ writeICONDIR(bos, 0, 1, 1);
+ writeICONDIRENTRY(bos, 16, 16, 0, 0, 1, bitDepth, 40 + bitmap.length);
+ writeBITMAPINFOHEADER(bos, 16, 2*16, 1, bitDepth, 0, 0, 0);
+ bos.write(bitmap);
+ bos.flush();
+ writeAndReadImageData("16x16x" + bitDepth, baos.toByteArray(), foreground, background);
+ }
+ }
- public void testBadICONDIRENTRYIcons() throws IOException, ImageWriteException, ImageReadException
- {
- final int foreground = 0xFFF000E0;
- final int background = 0xFF102030;
- // Windows ignores the ICONDIRENTRY values when parsing the ICO file.
- for (Iterator it = generatorMap.entrySet().iterator(); it.hasNext(); )
- {
- Map.Entry entry = (Map.Entry) it.next();
- int bitDepth = ((Integer)entry.getKey()).intValue();
- BitmapGenerator bitmapGenerator = (BitmapGenerator) entry.getValue();
+ public void testBadICONDIRENTRYIcons() throws IOException, ImageWriteException, ImageReadException
+ {
+ final int foreground = 0xFFF000E0;
+ final int background = 0xFF102030;
+ // Windows ignores the ICONDIRENTRY values when parsing the ICO file.
+ for (Iterator it = generatorMap.entrySet().iterator(); it.hasNext(); )
+ {
+ Map.Entry entry = (Map.Entry) it.next();
+ int bitDepth = ((Integer)entry.getKey()).intValue();
+ BitmapGenerator bitmapGenerator = (BitmapGenerator) entry.getValue();
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- BinaryOutputStream bos = new BinaryOutputStream(baos,
- BinaryOutputStream.BYTE_ORDER_LITTLE_ENDIAN);
- byte[] bitmap = bitmapGenerator.generateBitmap(foreground, background,
- (bitDepth <= 8) ? (1 << bitDepth) : 0);
- writeICONDIR(bos, 0, 1, 1);
- writeICONDIRENTRY(bos, 3 /* width, should be 16 */,
- 4 /* height, should be 16 */,
- 7 /* colorCount, should be 2 or 0 */,
- 20 /* reserved, should be 0 */,
- 11 /* planes, should be 1 or 0 */,
- 19 /* bitCount, should be bitDepth */,
- 40 + bitmap.length);
- writeBITMAPINFOHEADER(bos, 16, 2*16, 1, bitDepth, 0, 0, 0);
- bos.write(bitmap);
- bos.flush();
- writeAndReadImageData("16x16x" + bitDepth + "-corrupt-icondirentry",
- baos.toByteArray(), foreground, background);
- }
- }
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ BinaryOutputStream bos = new BinaryOutputStream(baos,
+ BinaryOutputStream.BYTE_ORDER_LITTLE_ENDIAN);
+ byte[] bitmap = bitmapGenerator.generateBitmap(foreground, background,
+ (bitDepth <= 8) ? (1 << bitDepth) : 0);
+ writeICONDIR(bos, 0, 1, 1);
+ writeICONDIRENTRY(bos, 3 /* width, should be 16 */,
+ 4 /* height, should be 16 */,
+ 7 /* colorCount, should be 2 or 0 */,
+ 20 /* reserved, should be 0 */,
+ 11 /* planes, should be 1 or 0 */,
+ 19 /* bitCount, should be bitDepth */,
+ 40 + bitmap.length);
+ writeBITMAPINFOHEADER(bos, 16, 2*16, 1, bitDepth, 0, 0, 0);
+ bos.write(bitmap);
+ bos.flush();
+ writeAndReadImageData("16x16x" + bitDepth + "-corrupt-icondirentry",
+ baos.toByteArray(), foreground, background);
+ }
+ }
- public void testColorsUsed() throws IOException, ImageWriteException, ImageReadException
- {
- final int foreground = 0xFFF000E0;
- final int background = 0xFF102030;
- for (Iterator it = generatorMap.entrySet().iterator(); it.hasNext(); )
- {
- Map.Entry entry = (Map.Entry) it.next();
- int bitDepth = ((Integer)entry.getKey()).intValue();
- BitmapGenerator bitmapGenerator = (BitmapGenerator) entry.getValue();
+ public void testColorsUsed() throws IOException, ImageWriteException, ImageReadException
+ {
+ final int foreground = 0xFFF000E0;
+ final int background = 0xFF102030;
+ for (Iterator it = generatorMap.entrySet().iterator(); it.hasNext(); )
+ {
+ Map.Entry entry = (Map.Entry) it.next();
+ int bitDepth = ((Integer)entry.getKey()).intValue();
+ BitmapGenerator bitmapGenerator = (BitmapGenerator) entry.getValue();
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- BinaryOutputStream bos = new BinaryOutputStream(baos,
- BinaryOutputStream.BYTE_ORDER_LITTLE_ENDIAN);
- byte[] bitmap = bitmapGenerator.generateBitmap(foreground, background, 2);
- writeICONDIR(bos, 0, 1, 1);
- writeICONDIRENTRY(bos, 3, 4, 7, 20, 11, 19, 40 + bitmap.length);
- writeBITMAPINFOHEADER(bos, 16, 2*16, 1, bitDepth, 0, 2, 0);
- bos.write(bitmap);
- bos.flush();
- writeAndReadImageData("16x16x" + bitDepth + "-custom-palette",
- baos.toByteArray(), foreground, background);
- }
- }
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ BinaryOutputStream bos = new BinaryOutputStream(baos,
+ BinaryOutputStream.BYTE_ORDER_LITTLE_ENDIAN);
+ byte[] bitmap = bitmapGenerator.generateBitmap(foreground, background, 2);
+ writeICONDIR(bos, 0, 1, 1);
+ writeICONDIRENTRY(bos, 3, 4, 7, 20, 11, 19, 40 + bitmap.length);
+ writeBITMAPINFOHEADER(bos, 16, 2*16, 1, bitDepth, 0, 2, 0);
+ bos.write(bitmap);
+ bos.flush();
+ writeAndReadImageData("16x16x" + bitDepth + "-custom-palette",
+ baos.toByteArray(), foreground, background);
+ }
+ }
- public void testZeroColorPlanes() throws IOException, ImageWriteException
- {
- final int foreground = 0xFFF000E0;
- final int background = 0xFF102030;
- for (Iterator it = generatorMap.entrySet().iterator(); it.hasNext(); )
- {
- Map.Entry entry = (Map.Entry) it.next();
- int bitDepth = ((Integer)entry.getKey()).intValue();
- BitmapGenerator bitmapGenerator = (BitmapGenerator) entry.getValue();
+ public void testZeroColorPlanes() throws IOException, ImageWriteException
+ {
+ final int foreground = 0xFFF000E0;
+ final int background = 0xFF102030;
+ for (Iterator it = generatorMap.entrySet().iterator(); it.hasNext(); )
+ {
+ Map.Entry entry = (Map.Entry) it.next();
+ int bitDepth = ((Integer)entry.getKey()).intValue();
+ BitmapGenerator bitmapGenerator = (BitmapGenerator) entry.getValue();
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- BinaryOutputStream bos = new BinaryOutputStream(baos,
- BinaryOutputStream.BYTE_ORDER_LITTLE_ENDIAN);
- byte[] bitmap = bitmapGenerator.generateBitmap(foreground, background,
- (bitDepth <= 8) ? (1 << bitDepth) : 0);
- writeICONDIR(bos, 0, 1, 1);
- writeICONDIRENTRY(bos, 16, 16, 0, 0, 1, bitDepth, 40 + bitmap.length);
- writeBITMAPINFOHEADER(bos, 16, 2*16, 0 /* should be 1 */, bitDepth, 0, 0, 0);
- bos.write(bitmap);
- bos.flush();
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ BinaryOutputStream bos = new BinaryOutputStream(baos,
+ BinaryOutputStream.BYTE_ORDER_LITTLE_ENDIAN);
+ byte[] bitmap = bitmapGenerator.generateBitmap(foreground, background,
+ (bitDepth <= 8) ? (1 << bitDepth) : 0);
+ writeICONDIR(bos, 0, 1, 1);
+ writeICONDIRENTRY(bos, 16, 16, 0, 0, 1, bitDepth, 40 + bitmap.length);
+ writeBITMAPINFOHEADER(bos, 16, 2*16, 0 /* should be 1 */, bitDepth, 0, 0, 0);
+ bos.write(bitmap);
+ bos.flush();
- boolean threw = false;
- try
- {
- writeAndReadImageData("16x16x" + bitDepth + "-zero-colorPlanes",
- baos.toByteArray(), foreground, background);
- }
- catch (ImageReadException imageReadException)
- {
- threw = true;
- }
- assertTrue(threw);
- }
- }
+ boolean threw = false;
+ try
+ {
+ writeAndReadImageData("16x16x" + bitDepth + "-zero-colorPlanes",
+ baos.toByteArray(), foreground, background);
+ }
+ catch (ImageReadException imageReadException)
+ {
+ threw = true;
+ }
+ assertTrue(threw);
+ }
+ }
- public void testBitfieldCompression() throws IOException, ImageWriteException, ImageReadException
- {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- BinaryOutputStream bos = new BinaryOutputStream(baos,
- BinaryOutputStream.BYTE_ORDER_LITTLE_ENDIAN);
- byte[] bitmap = new GeneratorFor32BitBitmaps().generate32bitRGBABitmap(
- 0xFFFF0000, 0xFFFFFFFF, 0, true);
- writeICONDIR(bos, 0, 1, 1);
- writeICONDIRENTRY(bos, 16, 16, 0, 0, 1, 32, 40 + bitmap.length);
- writeBITMAPINFOHEADER(bos, 16, 2*16, 1, 32, 3 /* BI_BITFIELDS */, 0, 0);
- bos.write4Bytes(0x000000FF); // red mask
- bos.write4Bytes(0x0000FF00); // green mask
- bos.write4Bytes(0x00FF0000); // blue mask
- bos.write(bitmap);
- bos.flush();
- writeAndReadImageData("16x16x32-bitfield-compressed", baos.toByteArray(),
- 0xFF0000FF, 0xFFFFFFFF);
- }
+ public void testBitfieldCompression() throws IOException, ImageWriteException, ImageReadException
+ {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ BinaryOutputStream bos = new BinaryOutputStream(baos,
+ BinaryOutputStream.BYTE_ORDER_LITTLE_ENDIAN);
+ byte[] bitmap = new GeneratorFor32BitBitmaps().generate32bitRGBABitmap(
+ 0xFFFF0000, 0xFFFFFFFF, 0, true);
+ writeICONDIR(bos, 0, 1, 1);
+ writeICONDIRENTRY(bos, 16, 16, 0, 0, 1, 32, 40 + bitmap.length);
+ writeBITMAPINFOHEADER(bos, 16, 2*16, 1, 32, 3 /* BI_BITFIELDS */, 0, 0);
+ bos.write4Bytes(0x000000FF); // red mask
+ bos.write4Bytes(0x0000FF00); // green mask
+ bos.write4Bytes(0x00FF0000); // blue mask
+ bos.write(bitmap);
+ bos.flush();
+ writeAndReadImageData("16x16x32-bitfield-compressed", baos.toByteArray(),
+ 0xFF0000FF, 0xFFFFFFFF);
+ }
- public void test32bitMask() throws IOException, ImageWriteException, ImageReadException
- {
- final int foreground = 0xFFF000E0;
- final int background = 0xFF102030;
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- BinaryOutputStream bos = new BinaryOutputStream(baos,
- BinaryOutputStream.BYTE_ORDER_LITTLE_ENDIAN);
- // For 32 bit RGBA, the AND mask can be missing:
- byte[] bitmap = new GeneratorFor32BitBitmaps().generate32bitRGBABitmap(
- foreground, background, 0, false);
- writeICONDIR(bos, 0, 1, 1);
- writeICONDIRENTRY(bos, 16, 16, 0, 0, 1, 32, 40 + bitmap.length);
- writeBITMAPINFOHEADER(bos, 16, 2*16, 1, 32, 0, 0, 0);
- bos.write(bitmap);
- bos.flush();
- writeAndReadImageData("16x16x32-no-mask", baos.toByteArray(), foreground, background);
- }
+ public void test32bitMask() throws IOException, ImageWriteException, ImageReadException
+ {
+ final int foreground = 0xFFF000E0;
+ final int background = 0xFF102030;
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ BinaryOutputStream bos = new BinaryOutputStream(baos,
+ BinaryOutputStream.BYTE_ORDER_LITTLE_ENDIAN);
+ // For 32 bit RGBA, the AND mask can be missing:
+ byte[] bitmap = new GeneratorFor32BitBitmaps().generate32bitRGBABitmap(
+ foreground, background, 0, false);
+ writeICONDIR(bos, 0, 1, 1);
+ writeICONDIRENTRY(bos, 16, 16, 0, 0, 1, 32, 40 + bitmap.length);
+ writeBITMAPINFOHEADER(bos, 16, 2*16, 1, 32, 0, 0, 0);
+ bos.write(bitmap);
+ bos.flush();
+ writeAndReadImageData("16x16x32-no-mask", baos.toByteArray(), foreground, background);
+ }
- // FIXME: get the BMP decoder to support alpha, then uncomment below
-// public void testAlphaVersusANDMask() throws IOException, ImageWriteException, ImageReadException
-// {
-// ByteArrayOutputStream baos = new ByteArrayOutputStream();
-// BinaryOutputStream bos = new BinaryOutputStream(baos,
-// BinaryOutputStream.BYTE_ORDER_LITTLE_ENDIAN);
-// byte[] bitmap = new GeneratorFor32BitBitmaps().generate32bitRGBABitmap(
-// 0xFF000000, 0x00000000, 0, true);
-// writeICONDIR(bos, 0, 1, 1);
-// writeICONDIRENTRY(bos, 16, 16, 0, 0, 1, 32, 40 + bitmap.length);
-// writeBITMAPINFOHEADER(bos, 16, 2*16, 1, 32, 0, 0, 0);
-// bos.write(bitmap);
-// bos.flush();
-// // The AND mask is fully opaque, yet the fully transparent alpha should win:
-// writeAndReadImageData("16x16x32-alpha-vs-mask", baos.toByteArray(),
-// 0xFF000000, 0x00000000);
-// }
+ // FIXME: get the BMP decoder to support alpha, then uncomment below
+// public void testAlphaVersusANDMask() throws IOException, ImageWriteException, ImageReadException
+// {
+// ByteArrayOutputStream baos = new ByteArrayOutputStream();
+// BinaryOutputStream bos = new BinaryOutputStream(baos,
+// BinaryOutputStream.BYTE_ORDER_LITTLE_ENDIAN);
+// byte[] bitmap = new GeneratorFor32BitBitmaps().generate32bitRGBABitmap(
+// 0xFF000000, 0x00000000, 0, true);
+// writeICONDIR(bos, 0, 1, 1);
+// writeICONDIRENTRY(bos, 16, 16, 0, 0, 1, 32, 40 + bitmap.length);
+// writeBITMAPINFOHEADER(bos, 16, 2*16, 1, 32, 0, 0, 0);
+// bos.write(bitmap);
+// bos.flush();
+// // The AND mask is fully opaque, yet the fully transparent alpha should win:
+// writeAndReadImageData("16x16x32-alpha-vs-mask", baos.toByteArray(),
+// 0xFF000000, 0x00000000);
+// }
- public void testFullyTransparent32bitRGBA() throws IOException, ImageWriteException, ImageReadException
- {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- BinaryOutputStream bos = new BinaryOutputStream(baos,
- BinaryOutputStream.BYTE_ORDER_LITTLE_ENDIAN);
- byte[] bitmap = new GeneratorFor32BitBitmaps().generate32bitRGBABitmap(
- 0x00000000, 0x00FFFFFF, 0, true);
- writeICONDIR(bos, 0, 1, 1);
- writeICONDIRENTRY(bos, 16, 16, 0, 0, 1, 32, 40 + bitmap.length);
- writeBITMAPINFOHEADER(bos, 16, 2*16, 1, 32, 0, 0, 0);
- bos.write(bitmap);
- bos.flush();
- // Because every pixel is fully trasparent, ***ALPHA GETS IGNORED***:
- writeAndReadImageData("16x16x32-fully-transparent", baos.toByteArray(),
- 0xFF000000, 0xFFFFFFFF);
- }
+ public void testFullyTransparent32bitRGBA() throws IOException, ImageWriteException, ImageReadException
+ {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ BinaryOutputStream bos = new BinaryOutputStream(baos,
+ BinaryOutputStream.BYTE_ORDER_LITTLE_ENDIAN);
+ byte[] bitmap = new GeneratorFor32BitBitmaps().generate32bitRGBABitmap(
+ 0x00000000, 0x00FFFFFF, 0, true);
+ writeICONDIR(bos, 0, 1, 1);
+ writeICONDIRENTRY(bos, 16, 16, 0, 0, 1, 32, 40 + bitmap.length);
+ writeBITMAPINFOHEADER(bos, 16, 2*16, 1, 32, 0, 0, 0);
+ bos.write(bitmap);
+ bos.flush();
+ // Because every pixel is fully trasparent, ***ALPHA GETS IGNORED***:
+ writeAndReadImageData("16x16x32-fully-transparent", baos.toByteArray(),
+ 0xFF000000, 0xFFFFFFFF);
+ }
- private void writeAndReadImageData(String description, byte[] rawData,
- int foreground, int background) throws IOException,
- ImageReadException
- {
- // Uncomment to generate ICO files that can be tested with Windows:
- //File exportFile = new File("/tmp/" + description + ".ico");
- //IOUtils.writeToFile(rawData, exportFile);
+ private void writeAndReadImageData(String description, byte[] rawData,
+ int foreground, int background) throws IOException,
+ ImageReadException
+ {
+ // Uncomment to generate ICO files that can be tested with Windows:
+ //File exportFile = new File("/tmp/" + description + ".ico");
+ //IOUtils.writeToFile(rawData, exportFile);
- File tempFile = createTempFile("temp", ".ico");
- IOUtils.writeToFile(rawData, tempFile);
+ File tempFile = createTempFile("temp", ".ico");
+ IOUtils.writeToFile(rawData, tempFile);
- BufferedImage dstImage = Sanselan.getBufferedImage(tempFile);
+ BufferedImage dstImage = Sanselan.getBufferedImage(tempFile);
- assertNotNull(dstImage);
- assertTrue(dstImage.getWidth() == image[0].length);
- assertTrue(dstImage.getHeight() == image.length);
+ assertNotNull(dstImage);
+ assertTrue(dstImage.getWidth() == image[0].length);
+ assertTrue(dstImage.getHeight() == image.length);
- verify(dstImage, foreground, background);
- }
+ verify(dstImage, foreground, background);
+ }
- private void verify(BufferedImage data, int foreground, int background)
- {
- assertNotNull(data);
- assertTrue(data.getHeight() == image.length);
+ private void verify(BufferedImage data, int foreground, int background)
+ {
+ assertNotNull(data);
+ assertTrue(data.getHeight() == image.length);
- for (int y = 0; y < data.getHeight(); y++)
- {
- assertTrue(data.getWidth() == image[y].length);
- for (int x = 0; x < data.getWidth(); x++)
- {
- int imageARGB = (image[y][x] == 1) ? foreground : background;
- int dataARGB = data.getRGB(x, y);
+ for (int y = 0; y < data.getHeight(); y++)
+ {
+ assertTrue(data.getWidth() == image[y].length);
+ for (int x = 0; x < data.getWidth(); x++)
+ {
+ int imageARGB = (image[y][x] == 1) ? foreground : background;
+ int dataARGB = data.getRGB(x, y);
- if (imageARGB != dataARGB)
- {
- Debug.debug("x: " + x + ", y: " + y + ", image: " + imageARGB
- + " (0x" + Integer.toHexString(imageARGB) + ")"
- + ", data: " + dataARGB + " (0x"
- + Integer.toHexString(dataARGB) + ")");
- }
- assertTrue(imageARGB == dataARGB);
- }
- }
- }
+ if (imageARGB != dataARGB)
+ {
+ Debug.debug("x: " + x + ", y: " + y + ", image: " + imageARGB
+ + " (0x" + Integer.toHexString(imageARGB) + ")"
+ + ", data: " + dataARGB + " (0x"
+ + Integer.toHexString(dataARGB) + ")");
+ }
+ assertTrue(imageARGB == dataARGB);
+ }
+ }
+ }
}
diff --git a/src/test/java/org/apache/sanselan/formats/jpeg/JpegBaseTest.java b/src/test/java/org/apache/sanselan/formats/jpeg/JpegBaseTest.java
index ad03d5d..6625eb2 100644
--- a/src/test/java/org/apache/sanselan/formats/jpeg/JpegBaseTest.java
+++ b/src/test/java/org/apache/sanselan/formats/jpeg/JpegBaseTest.java
@@ -29,26 +29,26 @@
public abstract class JpegBaseTest extends SanselanTest
{
- protected static boolean isJpeg(File file) throws IOException,
- ImageReadException
- {
- ImageFormat format = Sanselan.guessFormat(file);
- return format == ImageFormat.IMAGE_FORMAT_JPEG;
- }
+ protected static boolean isJpeg(File file) throws IOException,
+ ImageReadException
+ {
+ ImageFormat format = Sanselan.guessFormat(file);
+ return format == ImageFormat.IMAGE_FORMAT_JPEG;
+ }
- public static final ImageFilter imageFilter = new ImageFilter()
- {
- public boolean accept(File file) throws IOException, ImageReadException
- {
- return isJpeg(file);
- }
- };
+ public static final ImageFilter imageFilter = new ImageFilter()
+ {
+ public boolean accept(File file) throws IOException, ImageReadException
+ {
+ return isJpeg(file);
+ }
+ };
- protected List getJpegImages() throws IOException, ImageReadException
- {
- return getTestImages(imageFilter);
- }
+ protected List getJpegImages() throws IOException, ImageReadException
+ {
+ return getTestImages(imageFilter);
+ }
}
diff --git a/src/test/java/org/apache/sanselan/formats/jpeg/JpegReadTest.java b/src/test/java/org/apache/sanselan/formats/jpeg/JpegReadTest.java
index ca88ed0..1a944e2 100644
--- a/src/test/java/org/apache/sanselan/formats/jpeg/JpegReadTest.java
+++ b/src/test/java/org/apache/sanselan/formats/jpeg/JpegReadTest.java
@@ -32,33 +32,33 @@
public class JpegReadTest extends JpegBaseTest
{
- public void test() throws IOException, ImageReadException
- {
- List images = getJpegImages();
- for (int i = 0; i < images.size(); i++)
- {
- if(i%10==0)
- Debug.purgeMemory();
+ public void test() throws IOException, ImageReadException
+ {
+ List images = getJpegImages();
+ for (int i = 0; i < images.size(); i++)
+ {
+ if(i%10==0)
+ Debug.purgeMemory();
- File imageFile = (File) images.get(i);
- Debug.debug("imageFile", imageFile.getAbsoluteFile());
+ File imageFile = (File) images.get(i);
+ Debug.debug("imageFile", imageFile.getAbsoluteFile());
- // ByteSource byteSource = new ByteSourceFile(imageFile);
- // new JpegUtils().dumpJFIF(byteSource);
+ // ByteSource byteSource = new ByteSourceFile(imageFile);
+ // new JpegUtils().dumpJFIF(byteSource);
- Map params = new HashMap();
- boolean ignoreImageData = isPhilHarveyTestImage(imageFile);
- params
- .put(PARAM_KEY_READ_THUMBNAILS, new Boolean(
- !ignoreImageData));
+ Map params = new HashMap();
+ boolean ignoreImageData = isPhilHarveyTestImage(imageFile);
+ params
+ .put(PARAM_KEY_READ_THUMBNAILS, new Boolean(
+ !ignoreImageData));
- IImageMetadata metadata = Sanselan.getMetadata(imageFile, params);
- // assertNotNull(metadata);
- Debug.debug("metadata", metadata);
+ IImageMetadata metadata = Sanselan.getMetadata(imageFile, params);
+ // assertNotNull(metadata);
+ Debug.debug("metadata", metadata);
- ImageInfo imageInfo = Sanselan.getImageInfo(imageFile, params);
- assertNotNull(imageInfo);
- }
- }
+ ImageInfo imageInfo = Sanselan.getImageInfo(imageFile, params);
+ assertNotNull(imageInfo);
+ }
+ }
}
diff --git a/src/test/java/org/apache/sanselan/formats/jpeg/JpegWithJpegThumbnailTest.java b/src/test/java/org/apache/sanselan/formats/jpeg/JpegWithJpegThumbnailTest.java
index aba66f7..b5b0ec1 100644
--- a/src/test/java/org/apache/sanselan/formats/jpeg/JpegWithJpegThumbnailTest.java
+++ b/src/test/java/org/apache/sanselan/formats/jpeg/JpegWithJpegThumbnailTest.java
@@ -30,15 +30,15 @@
public class JpegWithJpegThumbnailTest extends SanselanTest {
- public void testSingleImage() throws IOException, ImageReadException {
- File imageFile = getTestImageByName("img_F028c_small.jpg");
+ public void testSingleImage() throws IOException, ImageReadException {
+ File imageFile = getTestImageByName("img_F028c_small.jpg");
- Map params = new HashMap();
- IImageMetadata metadata = Sanselan.getMetadata(imageFile, params);
- assertNotNull(metadata);
- JpegImageMetadata jpegMetadata = (JpegImageMetadata) metadata;
- BufferedImage image = jpegMetadata.getEXIFThumbnail();
- assertNotNull(image);
- }
+ Map params = new HashMap();
+ IImageMetadata metadata = Sanselan.getMetadata(imageFile, params);
+ assertNotNull(metadata);
+ JpegImageMetadata jpegMetadata = (JpegImageMetadata) metadata;
+ BufferedImage image = jpegMetadata.getEXIFThumbnail();
+ assertNotNull(image);
+ }
}
diff --git a/src/test/java/org/apache/sanselan/formats/jpeg/exif/AsciiFieldTest.java b/src/test/java/org/apache/sanselan/formats/jpeg/exif/AsciiFieldTest.java
index 50cdc3c..5b30050 100644
--- a/src/test/java/org/apache/sanselan/formats/jpeg/exif/AsciiFieldTest.java
+++ b/src/test/java/org/apache/sanselan/formats/jpeg/exif/AsciiFieldTest.java
@@ -35,44 +35,44 @@
public class AsciiFieldTest extends ExifBaseTest implements AllTagConstants {
- public void testSingleImage() throws IOException, ImageReadException {
- File imageFile = getTestImageByName("Canon Powershot SD750 - 2007.12.26.n.IMG_3704.JPG");
+ public void testSingleImage() throws IOException, ImageReadException {
+ File imageFile = getTestImageByName("Canon Powershot SD750 - 2007.12.26.n.IMG_3704.JPG");
- Map params = new HashMap();
+ Map params = new HashMap();
- IImageMetadata metadata = Sanselan.getMetadata(imageFile, params);
- assertNotNull(metadata);
- JpegImageMetadata jpegMetadata = (JpegImageMetadata) metadata;
+ IImageMetadata metadata = Sanselan.getMetadata(imageFile, params);
+ assertNotNull(metadata);
+ JpegImageMetadata jpegMetadata = (JpegImageMetadata) metadata;
- // note that exif might be null if no Exif metadata is found.
- TiffImageMetadata exif = jpegMetadata.getExif();
- if (null == exif)
- return;
+ // note that exif might be null if no Exif metadata is found.
+ TiffImageMetadata exif = jpegMetadata.getExif();
+ if (null == exif)
+ return;
- List fields = exif.getAllFields();
- Map fieldMap = new Hashtable();
- // Build a simplified field tag -> field map, ignoring directory structures.
- // Good enough for our purposes, since the image in question is known.
- for (int i = 0; i < fields.size(); i++) {
- TiffField field = (TiffField) fields.get(i);
- fieldMap.put(new Integer(field.tag), field);
- }
-
- Map expectedFieldValues = new Hashtable();
- expectedFieldValues.put(new Integer(EXIF_TAG_MAKE.tag), "Canon");
- expectedFieldValues.put(new Integer(EXIF_TAG_MODEL.tag), "Canon PowerShot SD750");
- expectedFieldValues.put(new Integer(EXIF_TAG_MODIFY_DATE.tag), "2007:12:25 13:34:39");
- Iterator expectedTags = expectedFieldValues.keySet().iterator();
- while (expectedTags.hasNext()) {
- Integer tag = (Integer) expectedTags.next();
- Object expectedValue = expectedFieldValues.get(tag);
+ List fields = exif.getAllFields();
+ Map fieldMap = new Hashtable();
+ // Build a simplified field tag -> field map, ignoring directory structures.
+ // Good enough for our purposes, since the image in question is known.
+ for (int i = 0; i < fields.size(); i++) {
+ TiffField field = (TiffField) fields.get(i);
+ fieldMap.put(new Integer(field.tag), field);
+ }
- assertTrue(fieldMap.containsKey(tag));
- TiffField field = (TiffField) fieldMap.get(tag);
- assertNotNull(field);
- Object value = field.getValue();
- assertNotNull(value);
- assertEquals(value, expectedValue);
- }
- }
+ Map expectedFieldValues = new Hashtable();
+ expectedFieldValues.put(new Integer(EXIF_TAG_MAKE.tag), "Canon");
+ expectedFieldValues.put(new Integer(EXIF_TAG_MODEL.tag), "Canon PowerShot SD750");
+ expectedFieldValues.put(new Integer(EXIF_TAG_MODIFY_DATE.tag), "2007:12:25 13:34:39");
+ Iterator expectedTags = expectedFieldValues.keySet().iterator();
+ while (expectedTags.hasNext()) {
+ Integer tag = (Integer) expectedTags.next();
+ Object expectedValue = expectedFieldValues.get(tag);
+
+ assertTrue(fieldMap.containsKey(tag));
+ TiffField field = (TiffField) fieldMap.get(tag);
+ assertNotNull(field);
+ Object value = field.getValue();
+ assertNotNull(value);
+ assertEquals(value, expectedValue);
+ }
+ }
}
diff --git a/src/test/java/org/apache/sanselan/formats/jpeg/exif/ExifBaseTest.java b/src/test/java/org/apache/sanselan/formats/jpeg/exif/ExifBaseTest.java
index de89dcd..0b63384 100644
--- a/src/test/java/org/apache/sanselan/formats/jpeg/exif/ExifBaseTest.java
+++ b/src/test/java/org/apache/sanselan/formats/jpeg/exif/ExifBaseTest.java
@@ -29,84 +29,84 @@
public abstract class ExifBaseTest extends SanselanTest
{
- // public ExifBaseTest(String name)
- // {
- // super(name);
- // }
+ // public ExifBaseTest(String name)
+ // {
+ // super(name);
+ // }
- protected static boolean hasExifData(File file)
- {
- // Debug.debug("hasExifData file", file.getAbsoluteFile());
+ protected static boolean hasExifData(File file)
+ {
+ // Debug.debug("hasExifData file", file.getAbsoluteFile());
- if (!file.getName().toLowerCase().endsWith(".jpg"))
- return false;
- //ImageFormat format = Sanselan.guessFormat(file);
- //if (format != ImageFormat.IMAGE_FORMAT_JPEG)
- // return false;
+ if (!file.getName().toLowerCase().endsWith(".jpg"))
+ return false;
+ //ImageFormat format = Sanselan.guessFormat(file);
+ //if (format != ImageFormat.IMAGE_FORMAT_JPEG)
+ // return false;
- // Debug.debug("possible file", file);
+ // Debug.debug("possible file", file);
- try
- {
- ByteSource byteSource = new ByteSourceFile(file);
- return new JpegImageParser().hasExifSegment(byteSource);
- }
- catch (Exception e)
- {
- // Debug.debug("Error file", file.getAbsoluteFile());
- // Debug.debug(e, 4);
- return false;
- }
- }
+ try
+ {
+ ByteSource byteSource = new ByteSourceFile(file);
+ return new JpegImageParser().hasExifSegment(byteSource);
+ }
+ catch (Exception e)
+ {
+ // Debug.debug("Error file", file.getAbsoluteFile());
+ // Debug.debug(e, 4);
+ return false;
+ }
+ }
- private static final ImageFilter HAS_EXIF_IMAGE_FILTER = new ImageFilter()
- {
- public boolean accept(File file) throws IOException, ImageReadException
- {
- return hasExifData(file);
- }
- };
+ private static final ImageFilter HAS_EXIF_IMAGE_FILTER = new ImageFilter()
+ {
+ public boolean accept(File file) throws IOException, ImageReadException
+ {
+ return hasExifData(file);
+ }
+ };
- private static final ImageFilter JPEG_IMAGE_FILTER = new ImageFilter()
- {
- public boolean accept(File file) throws IOException, ImageReadException
- {
- return file.getName().toLowerCase().endsWith(".jpg");
- }
- };
+ private static final ImageFilter JPEG_IMAGE_FILTER = new ImageFilter()
+ {
+ public boolean accept(File file) throws IOException, ImageReadException
+ {
+ return file.getName().toLowerCase().endsWith(".jpg");
+ }
+ };
- protected File getImageWithExifData() throws IOException,
- ImageReadException
- {
- return getTestImage(HAS_EXIF_IMAGE_FILTER);
- }
+ protected File getImageWithExifData() throws IOException,
+ ImageReadException
+ {
+ return getTestImage(HAS_EXIF_IMAGE_FILTER);
+ }
- protected List getImagesWithExifData() throws IOException,
- ImageReadException
- {
- return getTestImages(HAS_EXIF_IMAGE_FILTER);
- }
+ protected List getImagesWithExifData() throws IOException,
+ ImageReadException
+ {
+ return getTestImages(HAS_EXIF_IMAGE_FILTER);
+ }
- protected List getImagesWithExifData(int max) throws IOException,
- ImageReadException
- {
- return getTestImages(HAS_EXIF_IMAGE_FILTER, max);
- }
+ protected List getImagesWithExifData(int max) throws IOException,
+ ImageReadException
+ {
+ return getTestImages(HAS_EXIF_IMAGE_FILTER, max);
+ }
- protected File getJpegImage() throws IOException, ImageReadException
- {
- return getTestImage(JPEG_IMAGE_FILTER);
- }
+ protected File getJpegImage() throws IOException, ImageReadException
+ {
+ return getTestImage(JPEG_IMAGE_FILTER);
+ }
- protected List getJpegImages() throws IOException, ImageReadException
- {
- return getTestImages(JPEG_IMAGE_FILTER);
- }
+ protected List getJpegImages() throws IOException, ImageReadException
+ {
+ return getTestImages(JPEG_IMAGE_FILTER);
+ }
- protected List getJpegImages(int max) throws IOException,
- ImageReadException
- {
- return getTestImages(JPEG_IMAGE_FILTER, max);
- }
+ protected List getJpegImages(int max) throws IOException,
+ ImageReadException
+ {
+ return getTestImages(JPEG_IMAGE_FILTER, max);
+ }
}
diff --git a/src/test/java/org/apache/sanselan/formats/jpeg/exif/ExifDumpTest.java b/src/test/java/org/apache/sanselan/formats/jpeg/exif/ExifDumpTest.java
index 0423dbb..a37af39 100644
--- a/src/test/java/org/apache/sanselan/formats/jpeg/exif/ExifDumpTest.java
+++ b/src/test/java/org/apache/sanselan/formats/jpeg/exif/ExifDumpTest.java
@@ -34,42 +34,42 @@
public class ExifDumpTest extends ExifBaseTest
{
- // public ExifDumpTest(String name)
- // {
- // super(name);
- // }
+ // public ExifDumpTest(String name)
+ // {
+ // super(name);
+ // }
- public void test() throws IOException, ImageReadException,
- ImageWriteException
- {
- List images = getImagesWithExifData();
- for (int i = 0; i < images.size(); i++)
- {
- if(i%10==0)
- Debug.purgeMemory();
+ public void test() throws IOException, ImageReadException,
+ ImageWriteException
+ {
+ List images = getImagesWithExifData();
+ for (int i = 0; i < images.size(); i++)
+ {
+ if(i%10==0)
+ Debug.purgeMemory();
- File imageFile = (File) images.get(i);
- Debug.debug("imageFile", imageFile);
- Debug.debug();
+ File imageFile = (File) images.get(i);
+ Debug.debug("imageFile", imageFile);
+ Debug.debug();
- ByteSource byteSource = new ByteSourceFile(imageFile);
- Debug.debug("Segments:");
- new JpegUtils().dumpJFIF(byteSource);
+ ByteSource byteSource = new ByteSourceFile(imageFile);
+ Debug.debug("Segments:");
+ new JpegUtils().dumpJFIF(byteSource);
- Map params = new HashMap();
- boolean ignoreImageData = isPhilHarveyTestImage(imageFile);
- params
- .put(PARAM_KEY_READ_THUMBNAILS, new Boolean(
- !ignoreImageData));
+ 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;
- // assertNotNull(metadata.getExif());
+ JpegImageMetadata metadata = (JpegImageMetadata) Sanselan
+ .getMetadata(imageFile, params);
+ if (null == metadata)
+ continue;
+ // assertNotNull(metadata.getExif());
- metadata.dump();
- }
- }
+ metadata.dump();
+ }
+ }
}
diff --git a/src/test/java/org/apache/sanselan/formats/jpeg/exif/ExifRewriteTest.java b/src/test/java/org/apache/sanselan/formats/jpeg/exif/ExifRewriteTest.java
index 0de895e..72d8495 100644
--- a/src/test/java/org/apache/sanselan/formats/jpeg/exif/ExifRewriteTest.java
+++ b/src/test/java/org/apache/sanselan/formats/jpeg/exif/ExifRewriteTest.java
@@ -46,500 +46,500 @@
public class ExifRewriteTest extends ExifBaseTest implements AllTagConstants
{
- // public ExifRewriteTest(String name)
- // {
- // super(name);
- // }
+ // public ExifRewriteTest(String name)
+ // {
+ // super(name);
+ // }
- public void testRemove() throws IOException, ImageReadException,
- ImageWriteException
- {
- List images = getImagesWithExifData();
- for (int i = 0; i < images.size(); i++)
- {
- if(i%10==0)
- Debug.purgeMemory();
+ public void testRemove() throws IOException, ImageReadException,
+ ImageWriteException
+ {
+ List images = getImagesWithExifData();
+ for (int i = 0; i < images.size(); i++)
+ {
+ if(i%10==0)
+ Debug.purgeMemory();
- File imageFile = (File) images.get(i);
- Debug.debug("imageFile", imageFile);
+ File imageFile = (File) images.get(i);
+ Debug.debug("imageFile", imageFile);
- boolean ignoreImageData = isPhilHarveyTestImage(imageFile);
- if (ignoreImageData)
- continue;
+ boolean ignoreImageData = isPhilHarveyTestImage(imageFile);
+ if (ignoreImageData)
+ continue;
- ByteSource byteSource = new ByteSourceFile(imageFile);
- Debug.debug("Source Segments:");
- new JpegUtils().dumpJFIF(byteSource);
+ ByteSource byteSource = new ByteSourceFile(imageFile);
+ Debug.debug("Source Segments:");
+ new JpegUtils().dumpJFIF(byteSource);
- {
- JpegImageMetadata metadata = (JpegImageMetadata) Sanselan
- .getMetadata(imageFile);
- // assertNotNull(metadata.getExif());
- }
+ {
+ JpegImageMetadata metadata = (JpegImageMetadata) Sanselan
+ .getMetadata(imageFile);
+ // assertNotNull(metadata.getExif());
+ }
- {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- new ExifRewriter().removeExifMetadata(byteSource, baos);
- byte bytes[] = baos.toByteArray();
- File tempFile = createTempFile("test", ".jpg");
- Debug.debug("tempFile", tempFile);
- IOUtils.writeToFile(bytes, tempFile);
+ {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ new ExifRewriter().removeExifMetadata(byteSource, baos);
+ byte bytes[] = baos.toByteArray();
+ File tempFile = createTempFile("test", ".jpg");
+ Debug.debug("tempFile", tempFile);
+ IOUtils.writeToFile(bytes, tempFile);
- Debug.debug("Output Segments:");
- new JpegUtils().dumpJFIF(new ByteSourceArray(bytes));
+ Debug.debug("Output Segments:");
+ new JpegUtils().dumpJFIF(new ByteSourceArray(bytes));
- assertTrue(!hasExifData(tempFile));
- }
- }
- }
+ assertTrue(!hasExifData(tempFile));
+ }
+ }
+ }
- public void testInsert() throws IOException, ImageReadException,
- ImageWriteException
- {
- List images = getImagesWithExifData();
- for (int i = 0; i < images.size(); i++)
- {
- if(i%10==0)
- Debug.purgeMemory();
+ public void testInsert() throws IOException, ImageReadException,
+ ImageWriteException
+ {
+ List images = getImagesWithExifData();
+ for (int i = 0; i < images.size(); i++)
+ {
+ if(i%10==0)
+ Debug.purgeMemory();
- File imageFile = (File) images.get(i);
- Debug.debug("imageFile", imageFile);
-
- // This test image contains invalid EXIF and would break the test.
- if (imageFile.getName().equals("Oregon Scientific DS6639 - DSC_0307.JPG")) {
- continue;
- }
+ File imageFile = (File) images.get(i);
+ Debug.debug("imageFile", imageFile);
- boolean ignoreImageData = isPhilHarveyTestImage(imageFile);
- if (ignoreImageData)
- continue;
+ // This test image contains invalid EXIF and would break the test.
+ if (imageFile.getName().equals("Oregon Scientific DS6639 - DSC_0307.JPG")) {
+ continue;
+ }
- ByteSource byteSource = new ByteSourceFile(imageFile);
- Debug.debug("Source Segments:");
- new JpegUtils().dumpJFIF(byteSource);
+ boolean ignoreImageData = isPhilHarveyTestImage(imageFile);
+ if (ignoreImageData)
+ continue;
- JpegImageMetadata originalMetadata = (JpegImageMetadata) Sanselan
- .getMetadata(imageFile);
- assertNotNull(originalMetadata);
+ ByteSource byteSource = new ByteSourceFile(imageFile);
+ Debug.debug("Source Segments:");
+ new JpegUtils().dumpJFIF(byteSource);
- TiffImageMetadata oldExifMetadata = originalMetadata.getExif();
- assertNotNull(oldExifMetadata);
+ JpegImageMetadata originalMetadata = (JpegImageMetadata) Sanselan
+ .getMetadata(imageFile);
+ assertNotNull(originalMetadata);
- ByteSource stripped;
- {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- new ExifRewriter().removeExifMetadata(byteSource, baos);
- byte bytes[] = baos.toByteArray();
- File tempFile = createTempFile("removed", ".jpg");
- Debug.debug("tempFile", tempFile);
- IOUtils.writeToFile(bytes, tempFile);
+ TiffImageMetadata oldExifMetadata = originalMetadata.getExif();
+ assertNotNull(oldExifMetadata);
- Debug.debug("Output Segments:");
- stripped = new ByteSourceArray(bytes);
- new JpegUtils().dumpJFIF(stripped);
+ ByteSource stripped;
+ {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ new ExifRewriter().removeExifMetadata(byteSource, baos);
+ byte bytes[] = baos.toByteArray();
+ File tempFile = createTempFile("removed", ".jpg");
+ Debug.debug("tempFile", tempFile);
+ IOUtils.writeToFile(bytes, tempFile);
- assertTrue(!hasExifData(tempFile));
- }
+ Debug.debug("Output Segments:");
+ stripped = new ByteSourceArray(bytes);
+ new JpegUtils().dumpJFIF(stripped);
- {
- TiffOutputSet outputSet = oldExifMetadata.getOutputSet();
- // outputSet.dump();
+ assertTrue(!hasExifData(tempFile));
+ }
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ {
+ TiffOutputSet outputSet = oldExifMetadata.getOutputSet();
+ // outputSet.dump();
- new ExifRewriter().updateExifMetadataLossy(stripped, baos,
- outputSet);
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
- byte bytes[] = baos.toByteArray();
- File tempFile = createTempFile("inserted" + "_", ".jpg");
- Debug.debug("tempFile", tempFile);
- IOUtils.writeToFile(bytes, tempFile);
+ new ExifRewriter().updateExifMetadataLossy(stripped, baos,
+ outputSet);
- Debug.debug("Output Segments:");
- new JpegUtils().dumpJFIF(new ByteSourceArray(bytes));
+ byte bytes[] = baos.toByteArray();
+ File tempFile = createTempFile("inserted" + "_", ".jpg");
+ Debug.debug("tempFile", tempFile);
+ IOUtils.writeToFile(bytes, tempFile);
- // assertTrue(!hasExifData(tempFile));
+ Debug.debug("Output Segments:");
+ new JpegUtils().dumpJFIF(new ByteSourceArray(bytes));
- JpegImageMetadata newMetadata = (JpegImageMetadata) Sanselan
- .getMetadata(tempFile);
- assertNotNull(newMetadata);
- TiffImageMetadata newExifMetadata = newMetadata.getExif();
- assertNotNull(newExifMetadata);
- // newMetadata.dump();
+ // assertTrue(!hasExifData(tempFile));
- compare(oldExifMetadata, newExifMetadata);
- }
+ JpegImageMetadata newMetadata = (JpegImageMetadata) Sanselan
+ .getMetadata(tempFile);
+ assertNotNull(newMetadata);
+ TiffImageMetadata newExifMetadata = newMetadata.getExif();
+ assertNotNull(newExifMetadata);
+ // newMetadata.dump();
- }
- }
+ compare(oldExifMetadata, newExifMetadata);
+ }
- private interface Rewriter
- {
- public void rewrite(ByteSource byteSource, OutputStream os,
- TiffOutputSet outputSet) throws ImageReadException,
- IOException, ImageWriteException;
- }
+ }
+ }
- private void rewrite(Rewriter rewriter, String name) throws IOException,
- ImageReadException, ImageWriteException
- {
- List images = getImagesWithExifData();
- for (int i = 0; i < images.size(); i++)
- {
- if(i%10==0)
- Debug.purgeMemory();
+ private interface Rewriter
+ {
+ public void rewrite(ByteSource byteSource, OutputStream os,
+ TiffOutputSet outputSet) throws ImageReadException,
+ IOException, ImageWriteException;
+ }
- File imageFile = (File) images.get(i);
-
- // This test image contains invalid EXIF and would break the test.
- if (imageFile.getName().equals("Oregon Scientific DS6639 - DSC_0307.JPG")) {
- continue;
- }
+ private void rewrite(Rewriter rewriter, String name) throws IOException,
+ ImageReadException, ImageWriteException
+ {
+ List images = getImagesWithExifData();
+ for (int i = 0; i < images.size(); i++)
+ {
+ if(i%10==0)
+ Debug.purgeMemory();
- try
- {
+ File imageFile = (File) images.get(i);
- Debug.debug("imageFile", imageFile);
+ // This test image contains invalid EXIF and would break the test.
+ if (imageFile.getName().equals("Oregon Scientific DS6639 - DSC_0307.JPG")) {
+ continue;
+ }
- boolean ignoreImageData = isPhilHarveyTestImage(imageFile);
- if (ignoreImageData)
- continue;
+ try
+ {
- ByteSource byteSource = new ByteSourceFile(imageFile);
- Debug.debug("Source Segments:");
- new JpegUtils().dumpJFIF(byteSource);
+ Debug.debug("imageFile", imageFile);
- JpegImageMetadata oldMetadata = (JpegImageMetadata) Sanselan
- .getMetadata(imageFile);
- if (null == oldMetadata)
- continue;
- assertNotNull(oldMetadata);
+ boolean ignoreImageData = isPhilHarveyTestImage(imageFile);
+ if (ignoreImageData)
+ continue;
- TiffImageMetadata oldExifMetadata = oldMetadata.getExif();
- if (null == oldExifMetadata)
- continue;
- assertNotNull(oldExifMetadata);
- oldMetadata.dump();
+ ByteSource byteSource = new ByteSourceFile(imageFile);
+ Debug.debug("Source Segments:");
+ new JpegUtils().dumpJFIF(byteSource);
- // TiffImageMetadata tiffImageMetadata = metadata.getExif();
- // Photoshop photoshop = metadata.getPhotoshop();
+ JpegImageMetadata oldMetadata = (JpegImageMetadata) Sanselan
+ .getMetadata(imageFile);
+ if (null == oldMetadata)
+ continue;
+ assertNotNull(oldMetadata);
- TiffOutputSet outputSet = oldExifMetadata.getOutputSet();
- // outputSet.dump();
+ TiffImageMetadata oldExifMetadata = oldMetadata.getExif();
+ if (null == oldExifMetadata)
+ continue;
+ assertNotNull(oldExifMetadata);
+ oldMetadata.dump();
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- rewriter.rewrite(byteSource, baos, outputSet);
- byte bytes[] = baos.toByteArray();
- File tempFile = createTempFile(name + "_", ".jpg");
- Debug.debug("tempFile", tempFile);
- IOUtils.writeToFile(bytes, tempFile);
+ // TiffImageMetadata tiffImageMetadata = metadata.getExif();
+ // Photoshop photoshop = metadata.getPhotoshop();
- Debug.debug("Output Segments:");
- new JpegUtils().dumpJFIF(new ByteSourceArray(bytes));
+ TiffOutputSet outputSet = oldExifMetadata.getOutputSet();
+ // outputSet.dump();
- // assertTrue(!hasExifData(tempFile));
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ rewriter.rewrite(byteSource, baos, outputSet);
+ byte bytes[] = baos.toByteArray();
+ File tempFile = createTempFile(name + "_", ".jpg");
+ Debug.debug("tempFile", tempFile);
+ IOUtils.writeToFile(bytes, tempFile);
- JpegImageMetadata newMetadata = (JpegImageMetadata) Sanselan
- .getMetadata(tempFile);
- assertNotNull(newMetadata);
- TiffImageMetadata newExifMetadata = newMetadata.getExif();
- assertNotNull(newExifMetadata);
- // newMetadata.dump();
+ Debug.debug("Output Segments:");
+ new JpegUtils().dumpJFIF(new ByteSourceArray(bytes));
- compare(oldExifMetadata, newExifMetadata);
- }
- catch (IOException e)
- {
- Debug.debug("imageFile", imageFile.getAbsoluteFile());
- Debug.debug(e);
- throw e;
- }
- catch (ImageReadException e)
- {
- Debug.debug("imageFile", imageFile.getAbsoluteFile());
- Debug.debug(e);
- throw e;
- }
- catch (ImageWriteException e)
- {
- Debug.debug("imageFile", imageFile.getAbsoluteFile());
- Debug.debug(e);
- throw e;
- }
+ // assertTrue(!hasExifData(tempFile));
- }
- }
+ JpegImageMetadata newMetadata = (JpegImageMetadata) Sanselan
+ .getMetadata(tempFile);
+ assertNotNull(newMetadata);
+ TiffImageMetadata newExifMetadata = newMetadata.getExif();
+ assertNotNull(newExifMetadata);
+ // newMetadata.dump();
- public void testRewriteLossy() throws IOException, ImageReadException,
- ImageWriteException
- {
- Rewriter rewriter = new Rewriter()
- {
- public void rewrite(ByteSource byteSource, OutputStream os,
- TiffOutputSet outputSet) throws ImageReadException,
- IOException, ImageWriteException
- {
- new ExifRewriter().updateExifMetadataLossy(byteSource, os,
- outputSet);
- }
- };
+ compare(oldExifMetadata, newExifMetadata);
+ }
+ catch (IOException e)
+ {
+ Debug.debug("imageFile", imageFile.getAbsoluteFile());
+ Debug.debug(e);
+ throw e;
+ }
+ catch (ImageReadException e)
+ {
+ Debug.debug("imageFile", imageFile.getAbsoluteFile());
+ Debug.debug(e);
+ throw e;
+ }
+ catch (ImageWriteException e)
+ {
+ Debug.debug("imageFile", imageFile.getAbsoluteFile());
+ Debug.debug(e);
+ throw e;
+ }
- rewrite(rewriter, "lossy");
- }
+ }
+ }
- public void testRewriteLossless() throws IOException, ImageReadException,
- ImageWriteException
- {
- Rewriter rewriter = new Rewriter()
- {
- public void rewrite(ByteSource byteSource, OutputStream os,
- TiffOutputSet outputSet) throws ImageReadException,
- IOException, ImageWriteException
- {
- new ExifRewriter().updateExifMetadataLossless(byteSource, os,
- outputSet);
- }
- };
+ public void testRewriteLossy() throws IOException, ImageReadException,
+ ImageWriteException
+ {
+ Rewriter rewriter = new Rewriter()
+ {
+ public void rewrite(ByteSource byteSource, OutputStream os,
+ TiffOutputSet outputSet) throws ImageReadException,
+ IOException, ImageWriteException
+ {
+ new ExifRewriter().updateExifMetadataLossy(byteSource, os,
+ outputSet);
+ }
+ };
+
+ rewrite(rewriter, "lossy");
+ }
+
+ public void testRewriteLossless() throws IOException, ImageReadException,
+ ImageWriteException
+ {
+ Rewriter rewriter = new Rewriter()
+ {
+ public void rewrite(ByteSource byteSource, OutputStream os,
+ TiffOutputSet outputSet) throws ImageReadException,
+ IOException, ImageWriteException
+ {
+ new ExifRewriter().updateExifMetadataLossless(byteSource, os,
+ outputSet);
+ }
+ };
- rewrite(rewriter, "lossless");
- }
+ rewrite(rewriter, "lossless");
+ }
- private Hashtable makeDirectoryMap(ArrayList directories)
- {
- Hashtable directoryMap = new Hashtable();
- for (int i = 0; i < directories.size(); i++)
- {
- TiffImageMetadata.Directory directory = (TiffImageMetadata.Directory) directories
- .get(i);
- directoryMap.put(new Integer(directory.type), directory);
- }
- return directoryMap;
- }
+ private Hashtable makeDirectoryMap(ArrayList directories)
+ {
+ Hashtable directoryMap = new Hashtable();
+ for (int i = 0; i < directories.size(); i++)
+ {
+ TiffImageMetadata.Directory directory = (TiffImageMetadata.Directory) directories
+ .get(i);
+ directoryMap.put(new Integer(directory.type), directory);
+ }
+ return directoryMap;
+ }
- private Hashtable makeFieldMap(ArrayList items)
- {
- Hashtable fieldMap = new Hashtable();
- for (int i = 0; i < items.size(); i++)
- {
- TiffImageMetadata.Item item = (TiffImageMetadata.Item) items.get(i);
- TiffField field = item.getTiffField();
- Object key = new Integer(field.tag);
- if (!fieldMap.containsKey(key))
- fieldMap.put(key, field);
- }
- return fieldMap;
- }
+ private Hashtable makeFieldMap(ArrayList items)
+ {
+ Hashtable fieldMap = new Hashtable();
+ for (int i = 0; i < items.size(); i++)
+ {
+ TiffImageMetadata.Item item = (TiffImageMetadata.Item) items.get(i);
+ TiffField field = item.getTiffField();
+ Object key = new Integer(field.tag);
+ if (!fieldMap.containsKey(key))
+ fieldMap.put(key, field);
+ }
+ return fieldMap;
+ }
- private void compare(TiffImageMetadata oldExifMetadata,
- TiffImageMetadata newExifMetadata) throws ImageReadException
- {
- assertNotNull(oldExifMetadata);
- assertNotNull(newExifMetadata);
+ private void compare(TiffImageMetadata oldExifMetadata,
+ TiffImageMetadata newExifMetadata) throws ImageReadException
+ {
+ assertNotNull(oldExifMetadata);
+ assertNotNull(newExifMetadata);
- ArrayList oldDirectories = oldExifMetadata.getDirectories();
- ArrayList newDirectories = newExifMetadata.getDirectories();
+ ArrayList oldDirectories = oldExifMetadata.getDirectories();
+ ArrayList newDirectories = newExifMetadata.getDirectories();
- assertTrue(oldDirectories.size() == newDirectories.size());
+ assertTrue(oldDirectories.size() == newDirectories.size());
- Hashtable oldDirectoryMap = makeDirectoryMap(oldDirectories);
- Hashtable newDirectoryMap = makeDirectoryMap(newDirectories);
+ Hashtable oldDirectoryMap = makeDirectoryMap(oldDirectories);
+ Hashtable newDirectoryMap = makeDirectoryMap(newDirectories);
- assertEquals(oldDirectories.size(), oldDirectoryMap.keySet().size());
- ArrayList oldDirectoryTypes = new ArrayList(oldDirectoryMap.keySet());
- Collections.sort(oldDirectoryTypes);
- ArrayList newDirectoryTypes = new ArrayList(newDirectoryMap.keySet());
- Collections.sort(newDirectoryTypes);
- assertEquals(oldDirectoryTypes, newDirectoryTypes);
+ assertEquals(oldDirectories.size(), oldDirectoryMap.keySet().size());
+ ArrayList oldDirectoryTypes = new ArrayList(oldDirectoryMap.keySet());
+ Collections.sort(oldDirectoryTypes);
+ ArrayList newDirectoryTypes = new ArrayList(newDirectoryMap.keySet());
+ Collections.sort(newDirectoryTypes);
+ assertEquals(oldDirectoryTypes, newDirectoryTypes);
- for (int i = 0; i < oldDirectoryTypes.size(); i++)
- {
- Integer dirType = (Integer) oldDirectoryTypes.get(i);
+ for (int i = 0; i < oldDirectoryTypes.size(); i++)
+ {
+ Integer dirType = (Integer) oldDirectoryTypes.get(i);
- // Debug.debug("dirType", dirType);
+ // Debug.debug("dirType", dirType);
- TiffImageMetadata.Directory oldDirectory = (TiffImageMetadata.Directory) oldDirectoryMap
- .get(dirType);
- TiffImageMetadata.Directory newDirectory = (TiffImageMetadata.Directory) newDirectoryMap
- .get(dirType);
- assertNotNull(oldDirectory);
- assertNotNull(newDirectory);
+ TiffImageMetadata.Directory oldDirectory = (TiffImageMetadata.Directory) oldDirectoryMap
+ .get(dirType);
+ TiffImageMetadata.Directory newDirectory = (TiffImageMetadata.Directory) newDirectoryMap
+ .get(dirType);
+ assertNotNull(oldDirectory);
+ assertNotNull(newDirectory);
- ArrayList oldItems = oldDirectory.getItems();
- ArrayList newItems = newDirectory.getItems();
+ ArrayList oldItems = oldDirectory.getItems();
+ ArrayList newItems = newDirectory.getItems();
- // Debug.debug("oldItems.size()", oldItems.size());
- // Debug.debug("newItems.size()", newItems.size());
- // dump("oldItems", oldItems);
- // dump("newItems", newItems);
+ // Debug.debug("oldItems.size()", oldItems.size());
+ // Debug.debug("newItems.size()", newItems.size());
+ // dump("oldItems", oldItems);
+ // dump("newItems", newItems);
- // if (oldItems.size() != newItems.size())
- // ;
- // {
- // dump("oldItems", oldItems);
- // dump("newItems", newItems);
- // }
- // assertTrue(oldItems.size() == newItems.size());
+ // if (oldItems.size() != newItems.size())
+ // ;
+ // {
+ // dump("oldItems", oldItems);
+ // dump("newItems", newItems);
+ // }
+ // assertTrue(oldItems.size() == newItems.size());
- Hashtable oldFieldMap = makeFieldMap(oldItems);
- Hashtable newFieldMap = makeFieldMap(newItems);
+ Hashtable oldFieldMap = makeFieldMap(oldItems);
+ Hashtable newFieldMap = makeFieldMap(newItems);
- Set missingInNew = new HashSet(oldFieldMap.keySet());
- missingInNew.removeAll(newFieldMap.keySet());
+ Set missingInNew = new HashSet(oldFieldMap.keySet());
+ missingInNew.removeAll(newFieldMap.keySet());
- Set missingInOld = new HashSet(newFieldMap.keySet());
- missingInOld.removeAll(oldFieldMap.keySet());
+ Set missingInOld = new HashSet(newFieldMap.keySet());
+ missingInOld.removeAll(oldFieldMap.keySet());
- // dump("missingInNew", missingInNew);
- // dump("missingInOld", missingInOld);
- // dump("newFieldMap.keySet()", newFieldMap.keySet());
- // dump("oldFieldMap.keySet()", oldFieldMap.keySet());
+ // dump("missingInNew", missingInNew);
+ // dump("missingInOld", missingInOld);
+ // dump("newFieldMap.keySet()", newFieldMap.keySet());
+ // dump("oldFieldMap.keySet()", oldFieldMap.keySet());
- assertTrue(missingInNew.size() == 0);
- assertTrue(missingInOld.size() == 0);
+ assertTrue(missingInNew.size() == 0);
+ assertTrue(missingInOld.size() == 0);
- // Debug.debug("oldItems.size()", oldItems.size());
- // Debug.debug("oldFieldMap.keySet().size()", oldFieldMap.keySet().size());
+ // Debug.debug("oldItems.size()", oldItems.size());
+ // Debug.debug("oldFieldMap.keySet().size()", oldFieldMap.keySet().size());
- // assertEquals(oldItems.size(), oldFieldMap.keySet().size());
- // assertEquals(oldFieldMap.keySet(), newFieldMap.keySet());
- // assertEquals(oldFieldMap.keySet(), newFieldMap.keySet());
+ // assertEquals(oldItems.size(), oldFieldMap.keySet().size());
+ // assertEquals(oldFieldMap.keySet(), newFieldMap.keySet());
+ // assertEquals(oldFieldMap.keySet(), newFieldMap.keySet());
- ArrayList oldFieldTags = new ArrayList(oldFieldMap.keySet());
- Collections.sort(oldFieldTags);
- ArrayList newFieldTags = new ArrayList(newFieldMap.keySet());
- Collections.sort(newFieldTags);
- assertEquals(oldFieldTags, newFieldTags);
+ ArrayList oldFieldTags = new ArrayList(oldFieldMap.keySet());
+ Collections.sort(oldFieldTags);
+ ArrayList newFieldTags = new ArrayList(newFieldMap.keySet());
+ Collections.sort(newFieldTags);
+ assertEquals(oldFieldTags, newFieldTags);
- for (int j = 0; j < oldFieldTags.size(); j++)
- {
- Integer fieldTag = (Integer) oldFieldTags.get(j);
+ for (int j = 0; j < oldFieldTags.size(); j++)
+ {
+ Integer fieldTag = (Integer) oldFieldTags.get(j);
- TiffField oldField = (TiffField) oldFieldMap.get(fieldTag);
- TiffField newField = (TiffField) newFieldMap.get(fieldTag);
+ TiffField oldField = (TiffField) oldFieldMap.get(fieldTag);
+ TiffField newField = (TiffField) newFieldMap.get(fieldTag);
- // Debug.debug("fieldTag", fieldTag);
- // Debug.debug("oldField", oldField);
- // Debug.debug("newField", newField);
+ // Debug.debug("fieldTag", fieldTag);
+ // Debug.debug("oldField", oldField);
+ // Debug.debug("newField", newField);
- // fieldTag.
- assertNotNull(oldField);
- assertNotNull(newField);
+ // fieldTag.
+ assertNotNull(oldField);
+ assertNotNull(newField);
- assertEquals(oldField.tag, newField.tag);
- assertEquals(dirType.intValue(), newField.directoryType);
- assertEquals(oldField.directoryType, newField.directoryType);
- assertEquals(oldField.length, newField.length);
- assertEquals(oldField.isLocalValue(), newField.isLocalValue());
+ assertEquals(oldField.tag, newField.tag);
+ assertEquals(dirType.intValue(), newField.directoryType);
+ assertEquals(oldField.directoryType, newField.directoryType);
+ assertEquals(oldField.length, newField.length);
+ assertEquals(oldField.isLocalValue(), newField.isLocalValue());
- if (oldField.tag == 0x202)
- {
- // ignore "jpg from raw length" value. may have off-by-one bug in certain cameras.
- // i.e. Sony DCR-PC110
- continue;
- }
+ if (oldField.tag == 0x202)
+ {
+ // ignore "jpg from raw length" value. may have off-by-one bug in certain cameras.
+ // i.e. Sony DCR-PC110
+ continue;
+ }
- if (!oldField.tagInfo.isOffset())
- {
- if (oldField.tagInfo.isText())
- ;
- else if (oldField.isLocalValue())
- {
- // Debug.debug("oldField.tag", oldField.tag);
- // Debug.debug("newField.tag", newField.tag);
- // Debug.debug("oldField.tagInfo", oldField.tagInfo);
- // Debug.debug("newField.tagInfo", newField.tagInfo);
- // Debug.debug("oldField.fieldType", oldField.fieldType);
- // Debug.debug("newField.fieldType", newField.fieldType);
- // Debug.debug("oldField.getBytesLength", oldField
- // .getBytesLength());
- // Debug.debug("newField.getBytesLength", newField
- // .getBytesLength());
- //
- // Debug.debug("oldField.valueOffsetBytes",
- // oldField.valueOffsetBytes);
- // Debug.debug("newField.valueOffsetBytes",
- // newField.valueOffsetBytes);
+ if (!oldField.tagInfo.isOffset())
+ {
+ if (oldField.tagInfo.isText())
+ ;
+ else if (oldField.isLocalValue())
+ {
+ // Debug.debug("oldField.tag", oldField.tag);
+ // Debug.debug("newField.tag", newField.tag);
+ // Debug.debug("oldField.tagInfo", oldField.tagInfo);
+ // Debug.debug("newField.tagInfo", newField.tagInfo);
+ // Debug.debug("oldField.fieldType", oldField.fieldType);
+ // Debug.debug("newField.fieldType", newField.fieldType);
+ // Debug.debug("oldField.getBytesLength", oldField
+ // .getBytesLength());
+ // Debug.debug("newField.getBytesLength", newField
+ // .getBytesLength());
+ //
+ // Debug.debug("oldField.valueOffsetBytes",
+ // oldField.valueOffsetBytes);
+ // Debug.debug("newField.valueOffsetBytes",
+ // newField.valueOffsetBytes);
- if (oldField.tag == 0x116 || oldField.tag == 0x117)
- compare(oldField, newField);
- else {
- compare(oldField.valueOffsetBytes,
- newField.valueOffsetBytes, oldField
- .getBytesLength(), newField
- .getBytesLength());
- }
- }
- else
- {
- // Debug.debug("oldField.tagInfo", oldField.tagInfo);
- // Debug.debug("oldField.fieldType", oldField.fieldType);
- // Debug.debug("newField.fieldType", newField.fieldType);
- // Debug.debug("oldField.getBytesLength", oldField
- // .getBytesLength());
- // Debug.debug("newField.getBytesLength", newField
- // .getBytesLength());
+ if (oldField.tag == 0x116 || oldField.tag == 0x117)
+ compare(oldField, newField);
+ else {
+ compare(oldField.valueOffsetBytes,
+ newField.valueOffsetBytes, oldField
+ .getBytesLength(), newField
+ .getBytesLength());
+ }
+ }
+ else
+ {
+ // Debug.debug("oldField.tagInfo", oldField.tagInfo);
+ // Debug.debug("oldField.fieldType", oldField.fieldType);
+ // Debug.debug("newField.fieldType", newField.fieldType);
+ // Debug.debug("oldField.getBytesLength", oldField
+ // .getBytesLength());
+ // Debug.debug("newField.getBytesLength", newField
+ // .getBytesLength());
- // Debug.debug("oldField.oversizeValue", oldField.oversizeValue);
- // Debug.debug("newField.oversizeValue", newField.oversizeValue);
+ // Debug.debug("oldField.oversizeValue", oldField.oversizeValue);
+ // Debug.debug("newField.oversizeValue", newField.oversizeValue);
- compare(oldField.oversizeValue, newField.oversizeValue);
- }
- }
+ compare(oldField.oversizeValue, newField.oversizeValue);
+ }
+ }
- }
+ }
- // Debug.debug();
- }
- }
+ // Debug.debug();
+ }
+ }
- private void compare(byte a[], byte b[], int aLength, int bLength)
- {
- // Debug.debug("c0 a", a);
- // Debug.debug("c0 b", b);
- assertEquals(aLength, bLength);
- assertTrue(a.length >= aLength);
- assertTrue(b.length >= bLength);
- assertNotNull(a);
- assertNotNull(b);
- assertEquals(a.length, b.length);
- int length = aLength;
- for (int i = 0; i < length; i++)
- {
- // byte ba = a[i];
- // byte bb = b[i];
- // boolean eq = ba == bb;
- // Debug.debug("i: " + i + ", a[i]: " + ba + ", b[i]: " + bb + " = "
- // + (ba == bb) + " " + eq);
- // if(ba != bb)
- // assertFalse(true);
- //
- // Debug.debug("i: " + i + ", a[i]: " + ba + ", b[i]: " + bb + " = "
- // + (ba == bb) + " " + eq);
- // assertTrue(eq == true);
- assertTrue("0x" + Integer.toHexString(0xff & a[i]) + " != " + "0x" + Integer.toHexString(0xff & b[i]), a[i] == b[i]);
- // Debug.debug("c");
- // assertTrue((0xff & a[i]) == (0xff & b[i]));
- }
- }
+ private void compare(byte a[], byte b[], int aLength, int bLength)
+ {
+ // Debug.debug("c0 a", a);
+ // Debug.debug("c0 b", b);
+ assertEquals(aLength, bLength);
+ assertTrue(a.length >= aLength);
+ assertTrue(b.length >= bLength);
+ assertNotNull(a);
+ assertNotNull(b);
+ assertEquals(a.length, b.length);
+ int length = aLength;
+ for (int i = 0; i < length; i++)
+ {
+ // byte ba = a[i];
+ // byte bb = b[i];
+ // boolean eq = ba == bb;
+ // Debug.debug("i: " + i + ", a[i]: " + ba + ", b[i]: " + bb + " = "
+ // + (ba == bb) + " " + eq);
+ // if(ba != bb)
+ // assertFalse(true);
+ //
+ // Debug.debug("i: " + i + ", a[i]: " + ba + ", b[i]: " + bb + " = "
+ // + (ba == bb) + " " + eq);
+ // assertTrue(eq == true);
+ assertTrue("0x" + Integer.toHexString(0xff & a[i]) + " != " + "0x" + Integer.toHexString(0xff & b[i]), a[i] == b[i]);
+ // Debug.debug("c");
+ // assertTrue((0xff & a[i]) == (0xff & b[i]));
+ }
+ }
- private void compare(TiffField a, TiffField b) throws ImageReadException
- {
- Object v1 = a.getValue();
- Object v2 = b.getValue();
+ private void compare(TiffField a, TiffField b) throws ImageReadException
+ {
+ Object v1 = a.getValue();
+ Object v2 = b.getValue();
- // Debug.debug("v1", v1 + " (" + Debug.getType(v1) + ")");
- // Debug.debug("v2", v2 + " (" + Debug.getType(v2) + ")");
- assertTrue(v1.equals(v2));
- }
+ // Debug.debug("v1", v1 + " (" + Debug.getType(v1) + ")");
+ // Debug.debug("v2", v2 + " (" + Debug.getType(v2) + ")");
+ assertTrue(v1.equals(v2));
+ }
- private void compare(byte a[], byte b[])
- {
- // Debug.debug("c1 a", a);
- // Debug.debug("c1 b", b);
- assertNotNull(a);
- assertNotNull(b);
- assertEquals(a.length, b.length);
- for (int i = 0; i < a.length; i++)
- assertEquals(a[i], b[i]);
- }
+ private void compare(byte a[], byte b[])
+ {
+ // Debug.debug("c1 a", a);
+ // Debug.debug("c1 b", b);
+ assertNotNull(a);
+ assertNotNull(b);
+ assertEquals(a.length, b.length);
+ for (int i = 0; i < a.length; i++)
+ assertEquals(a[i], b[i]);
+ }
}
diff --git a/src/test/java/org/apache/sanselan/formats/jpeg/exif/GpsTest.java b/src/test/java/org/apache/sanselan/formats/jpeg/exif/GpsTest.java
index 18e0d1f..2b7c727 100644
--- a/src/test/java/org/apache/sanselan/formats/jpeg/exif/GpsTest.java
+++ b/src/test/java/org/apache/sanselan/formats/jpeg/exif/GpsTest.java
@@ -31,68 +31,68 @@
public class GpsTest extends ExifBaseTest implements SanselanConstants
{
- public void test() throws Exception
- {
+ public void test() throws Exception
+ {
- List images = getImagesWithExifData(300);
- for (int i = 0; i < images.size(); i++)
- {
- if (i % 10 == 0)
- Debug.purgeMemory();
+ List images = getImagesWithExifData(300);
+ for (int i = 0; i < images.size(); i++)
+ {
+ if (i % 10 == 0)
+ Debug.purgeMemory();
- File imageFile = (File) images.get(i);
+ File imageFile = (File) images.get(i);
-// Debug.debug();
-// Debug.debug("imageFile", imageFile);
+// Debug.debug();
+// Debug.debug("imageFile", imageFile);
- if (imageFile.getParentFile().getName().toLowerCase().equals(
- "@broken"))
- continue;
+ 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));
+ 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;
+ JpegImageMetadata metadata = (JpegImageMetadata) Sanselan
+ .getMetadata(imageFile, params);
+ if (null == metadata)
+ continue;
- TiffImageMetadata exifMetadata = metadata.getExif();
- if (null == exifMetadata)
- continue;
+ TiffImageMetadata exifMetadata = metadata.getExif();
+ if (null == exifMetadata)
+ continue;
- TiffImageMetadata.GPSInfo gpsInfo = exifMetadata.getGPS();
- if (null == gpsInfo)
- 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("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);
+ 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);
+ // File brokenFolder = new File(imageFile.getParentFile(), "@Broken");
+ // if(!brokenFolder.exists())
+ // brokenFolder.mkdirs();
+ // File movedFile = new File(brokenFolder, imageFile.getName());
+ // imageFile.renameTo(movedFile);
- throw e;
- }
- }
+ throw e;
+ }
+ }
- }
+ }
}
diff --git a/src/test/java/org/apache/sanselan/formats/jpeg/exif/MakerNoteFieldTest.java b/src/test/java/org/apache/sanselan/formats/jpeg/exif/MakerNoteFieldTest.java
index 6795989..5182f7e 100644
--- a/src/test/java/org/apache/sanselan/formats/jpeg/exif/MakerNoteFieldTest.java
+++ b/src/test/java/org/apache/sanselan/formats/jpeg/exif/MakerNoteFieldTest.java
@@ -27,46 +27,46 @@
public class MakerNoteFieldTest extends SpecificExifTagTest
{
- // public MakerNoteFieldTest(String name)
- // {
- // super(name);
- // }
+ // public MakerNoteFieldTest(String name)
+ // {
+ // super(name);
+ // }
- protected void checkField(File imageFile, TiffField field)
- throws IOException, ImageReadException, ImageWriteException
- {
- if (field.tag == EXIF_TAG_MAKER_NOTE.tag)
- ;
- else
- // if (field.tag == EXIF_TAG_EXIF_OFFSET.tag)
- // ;
- // else
- return;
+ protected void checkField(File imageFile, TiffField field)
+ throws IOException, ImageReadException, ImageWriteException
+ {
+ if (field.tag == EXIF_TAG_MAKER_NOTE.tag)
+ ;
+ else
+ // if (field.tag == EXIF_TAG_EXIF_OFFSET.tag)
+ // ;
+ // else
+ return;
- Debug.debug("imageFile", imageFile);
- Debug.debug("field", field);
- Debug.debug("field", Debug.getType(field));
+ Debug.debug("imageFile", imageFile);
+ Debug.debug("field", field);
+ Debug.debug("field", Debug.getType(field));
- Debug.debug("field", field.tag);
- Debug.debug("field", field.tagInfo);
- Debug.debug("length", field.length);
- Debug.debug("fieldType", field.fieldType);
- // Debug.debug("field", Debug.getType(field));
- Debug.debug();
+ Debug.debug("field", field.tag);
+ Debug.debug("field", field.tagInfo);
+ Debug.debug("length", field.length);
+ Debug.debug("fieldType", field.fieldType);
+ // Debug.debug("field", Debug.getType(field));
+ Debug.debug();
- // try
- // {
- // Object userCommentValue = field.getValue();
- // Debug.debug("Text field value(" + field.tagInfo.name + ")",
- // userCommentValue);
- // // Debug.debug("userCommentValue", Debug.getType(userCommentValue));
- // }
- // catch (ImageReadException e)
- // {
- // Debug.debug("imageFile", imageFile);
- // Debug.debug(e);
- // }
+ // try
+ // {
+ // Object userCommentValue = field.getValue();
+ // Debug.debug("Text field value(" + field.tagInfo.name + ")",
+ // userCommentValue);
+ // // Debug.debug("userCommentValue", Debug.getType(userCommentValue));
+ // }
+ // catch (ImageReadException e)
+ // {
+ // Debug.debug("imageFile", imageFile);
+ // Debug.debug(e);
+ // }
- }
+ }
}
diff --git a/src/test/java/org/apache/sanselan/formats/jpeg/exif/SpecificExifTagTest.java b/src/test/java/org/apache/sanselan/formats/jpeg/exif/SpecificExifTagTest.java
index e6f0e70..77ae9bc 100644
--- a/src/test/java/org/apache/sanselan/formats/jpeg/exif/SpecificExifTagTest.java
+++ b/src/test/java/org/apache/sanselan/formats/jpeg/exif/SpecificExifTagTest.java
@@ -34,68 +34,68 @@
import org.apache.sanselan.util.Debug;
public abstract class SpecificExifTagTest extends ExifBaseTest
- implements
- AllTagConstants
+ implements
+ AllTagConstants
{
- // public SpecificExifTagTest(String name)
- // {
- // super(name);
- // }
+ // public SpecificExifTagTest(String name)
+ // {
+ // super(name);
+ // }
- public void testSingleImage() throws IOException, ImageReadException,
- ImageWriteException
- {
- File imageFile = getImageWithExifData();
- checkImage(imageFile);
- }
+ public void testSingleImage() throws IOException, ImageReadException,
+ ImageWriteException
+ {
+ File imageFile = getImageWithExifData();
+ checkImage(imageFile);
+ }
- public void testAllImages() throws IOException, ImageReadException,
- ImageWriteException
- {
- List images = getImagesWithExifData();
- for (int i = 0; i < images.size(); i++)
- {
- if(i%10==0)
- Debug.purgeMemory();
+ public void testAllImages() throws IOException, ImageReadException,
+ ImageWriteException
+ {
+ List images = getImagesWithExifData();
+ for (int i = 0; i < images.size(); i++)
+ {
+ if(i%10==0)
+ Debug.purgeMemory();
- File imageFile = (File) images.get(i);
- if (imageFile.getParentFile().getName().toLowerCase().equals(
- "@broken"))
- continue;
- checkImage(imageFile);
- }
- }
+ File imageFile = (File) images.get(i);
+ if (imageFile.getParentFile().getName().toLowerCase().equals(
+ "@broken"))
+ continue;
+ checkImage(imageFile);
+ }
+ }
- protected abstract void checkField(File imageFile, TiffField field)
- throws IOException, ImageReadException, ImageWriteException;
+ protected abstract void checkField(File imageFile, TiffField field)
+ throws IOException, ImageReadException, ImageWriteException;
- private void checkImage(File imageFile) throws IOException,
- ImageReadException, ImageWriteException
- {
- // Debug.debug("imageFile", imageFile.getAbsoluteFile());
+ private void checkImage(File imageFile) throws IOException,
+ ImageReadException, ImageWriteException
+ {
+ // Debug.debug("imageFile", imageFile.getAbsoluteFile());
- Map params = new HashMap();
- boolean ignoreImageData = isPhilHarveyTestImage(imageFile);
- params.put(PARAM_KEY_READ_THUMBNAILS, new Boolean(!ignoreImageData));
+ Map params = new HashMap();
+ boolean ignoreImageData = isPhilHarveyTestImage(imageFile);
+ params.put(PARAM_KEY_READ_THUMBNAILS, new Boolean(!ignoreImageData));
- // note that metadata might be null if no metadata is found.
- IImageMetadata metadata = Sanselan.getMetadata(imageFile, params);
- if (null == metadata)
- return;
- JpegImageMetadata jpegMetadata = (JpegImageMetadata) metadata;
+ // note that metadata might be null if no metadata is found.
+ IImageMetadata metadata = Sanselan.getMetadata(imageFile, params);
+ if (null == metadata)
+ return;
+ JpegImageMetadata jpegMetadata = (JpegImageMetadata) metadata;
- // note that exif might be null if no Exif metadata is found.
- TiffImageMetadata exif = jpegMetadata.getExif();
- if (null == exif)
- return;
+ // note that exif might be null if no Exif metadata is found.
+ TiffImageMetadata exif = jpegMetadata.getExif();
+ if (null == exif)
+ return;
- List fields = exif.getAllFields();
- for (int i = 0; i < fields.size(); i++)
- {
- TiffField field = (TiffField) fields.get(i);
- checkField(imageFile, field);
- }
+ List fields = exif.getAllFields();
+ for (int i = 0; i < fields.size(); i++)
+ {
+ TiffField field = (TiffField) fields.get(i);
+ checkField(imageFile, field);
+ }
- }
+ }
}
diff --git a/src/test/java/org/apache/sanselan/formats/jpeg/exif/TextFieldTest.java b/src/test/java/org/apache/sanselan/formats/jpeg/exif/TextFieldTest.java
index a17797c..b59db07 100644
--- a/src/test/java/org/apache/sanselan/formats/jpeg/exif/TextFieldTest.java
+++ b/src/test/java/org/apache/sanselan/formats/jpeg/exif/TextFieldTest.java
@@ -27,47 +27,47 @@
public class TextFieldTest extends SpecificExifTagTest
{
- // public TextFieldTest(String name)
- // {
- // super(name);
- // }
+ // public TextFieldTest(String name)
+ // {
+ // super(name);
+ // }
- protected void checkField(File imageFile, TiffField field)
- throws IOException, ImageReadException, ImageWriteException
- {
- if (field.tag == EXIF_TAG_USER_COMMENT.tag)
- ;
- else if (field.tag == GPS_TAG_GPS_PROCESSING_METHOD.tag
- && field.directoryType == EXIF_DIRECTORY_GPS.directoryType)
- ;
- else if (field.tag == GPS_TAG_GPS_AREA_INFORMATION.tag
- && field.directoryType == EXIF_DIRECTORY_GPS.directoryType)
- ;
- else
- return;
+ protected void checkField(File imageFile, TiffField field)
+ throws IOException, ImageReadException, ImageWriteException
+ {
+ if (field.tag == EXIF_TAG_USER_COMMENT.tag)
+ ;
+ else if (field.tag == GPS_TAG_GPS_PROCESSING_METHOD.tag
+ && field.directoryType == EXIF_DIRECTORY_GPS.directoryType)
+ ;
+ else if (field.tag == GPS_TAG_GPS_AREA_INFORMATION.tag
+ && field.directoryType == EXIF_DIRECTORY_GPS.directoryType)
+ ;
+ else
+ return;
- // Debug.debug("field", field);
- // Debug.debug("field", Debug.getType(field));
- //
- // Debug.debug("field", field.tag);
- // Debug.debug("field", field.tagInfo);
- // Debug.debug("field", Debug.getType(field));
+ // Debug.debug("field", field);
+ // Debug.debug("field", Debug.getType(field));
+ //
+ // Debug.debug("field", field.tag);
+ // Debug.debug("field", field.tagInfo);
+ // Debug.debug("field", Debug.getType(field));
- try
- {
- Object textFieldValue = field.getValue();
- // Debug.debug("imageFile", imageFile.getAbsoluteFile());
- // Debug.debug("Text field value(" + field.tagInfo.name + ")",
- // textFieldValue);
- // Debug.debug("userCommentValue", Debug.getType(userCommentValue));
- }
- catch (ImageReadException e)
- {
- Debug.debug("imageFile", imageFile.getAbsoluteFile());
- Debug.debug(e);
- throw e;
- }
+ try
+ {
+ Object textFieldValue = field.getValue();
+ // Debug.debug("imageFile", imageFile.getAbsoluteFile());
+ // Debug.debug("Text field value(" + field.tagInfo.name + ")",
+ // textFieldValue);
+ // Debug.debug("userCommentValue", Debug.getType(userCommentValue));
+ }
+ catch (ImageReadException e)
+ {
+ Debug.debug("imageFile", imageFile.getAbsoluteFile());
+ Debug.debug(e);
+ throw e;
+ }
- }
+ }
}
diff --git a/src/test/java/org/apache/sanselan/formats/jpeg/exif/WriteExifMetadataExampleTest.java b/src/test/java/org/apache/sanselan/formats/jpeg/exif/WriteExifMetadataExampleTest.java
index 8671d11..bd24e1e 100644
--- a/src/test/java/org/apache/sanselan/formats/jpeg/exif/WriteExifMetadataExampleTest.java
+++ b/src/test/java/org/apache/sanselan/formats/jpeg/exif/WriteExifMetadataExampleTest.java
@@ -29,75 +29,75 @@
import org.apache.sanselan.util.Debug;
public class WriteExifMetadataExampleTest extends ExifBaseTest
- implements
- AllTagConstants
+ implements
+ AllTagConstants
{
- // public WriteExifMetadataExampleTest(String name)
- // {
- // super(name);
- // }
+ // public WriteExifMetadataExampleTest(String name)
+ // {
+ // super(name);
+ // }
- public void test() throws IOException, ImageReadException,
- ImageWriteException
- {
- List images = getJpegImages();
- for (int i = 0; i < images.size(); i++)
- {
- if (i % 10 == 0)
- Debug.purgeMemory();
+ public void test() throws IOException, ImageReadException,
+ ImageWriteException
+ {
+ List images = getJpegImages();
+ for (int i = 0; i < images.size(); i++)
+ {
+ if (i % 10 == 0)
+ Debug.purgeMemory();
- File imageFile = (File) images.get(i);
- Debug.debug("imageFile", imageFile.getAbsoluteFile());
+ File imageFile = (File) images.get(i);
+ Debug.debug("imageFile", imageFile.getAbsoluteFile());
- File tempFile = createTempFile("test", ".jpg");
- Debug.debug("tempFile", tempFile.getAbsoluteFile());
+ File tempFile = createTempFile("test", ".jpg");
+ Debug.debug("tempFile", tempFile.getAbsoluteFile());
- try
- {
- boolean ignoreImageData = isPhilHarveyTestImage(imageFile);
- if (ignoreImageData)
- continue;
- new WriteExifMetadataExample().changeExifMetadata(imageFile,
- tempFile);
- }
- catch (ExifRewriter.ExifOverflowException e)
- {
- Debug.debug("Error image", imageFile.getAbsoluteFile());
- Debug.debug(e, 4);
- }
- }
- }
+ try
+ {
+ boolean ignoreImageData = isPhilHarveyTestImage(imageFile);
+ if (ignoreImageData)
+ continue;
+ new WriteExifMetadataExample().changeExifMetadata(imageFile,
+ tempFile);
+ }
+ catch (ExifRewriter.ExifOverflowException e)
+ {
+ Debug.debug("Error image", imageFile.getAbsoluteFile());
+ Debug.debug(e, 4);
+ }
+ }
+ }
- public void testInsert() throws IOException, ImageReadException,
- ImageWriteException
- {
- List images = getJpegImages();
- for (int i = 0; i < images.size(); i++)
- {
- if (i % 10 == 0)
- Debug.purgeMemory();
+ public void testInsert() throws IOException, ImageReadException,
+ ImageWriteException
+ {
+ List images = getJpegImages();
+ for (int i = 0; i < images.size(); i++)
+ {
+ if (i % 10 == 0)
+ Debug.purgeMemory();
- File imageFile = (File) images.get(i);
- Debug.debug("imageFile", imageFile.getAbsoluteFile());
+ File imageFile = (File) images.get(i);
+ Debug.debug("imageFile", imageFile.getAbsoluteFile());
- File tempFile = createTempFile("test", ".jpg");
- Debug.debug("tempFile", tempFile.getAbsoluteFile());
+ File tempFile = createTempFile("test", ".jpg");
+ Debug.debug("tempFile", tempFile.getAbsoluteFile());
- try
- {
- boolean ignoreImageData = isPhilHarveyTestImage(imageFile);
- if (ignoreImageData)
- continue;
- new WriteExifMetadataExample().changeExifMetadata(imageFile,
- tempFile);
- }
- catch (ExifRewriter.ExifOverflowException e)
- {
- Debug.debug("Ignoring unavoidable ExifOverflowException", e.getMessage());
- Debug.debug("Error image", imageFile.getAbsoluteFile());
-// Debug.debug(e, 4);
- }
- }
- }
+ try
+ {
+ boolean ignoreImageData = isPhilHarveyTestImage(imageFile);
+ if (ignoreImageData)
+ continue;
+ new WriteExifMetadataExample().changeExifMetadata(imageFile,
+ tempFile);
+ }
+ catch (ExifRewriter.ExifOverflowException e)
+ {
+ Debug.debug("Ignoring unavoidable ExifOverflowException", e.getMessage());
+ Debug.debug("Error image", imageFile.getAbsoluteFile());
+// Debug.debug(e, 4);
+ }
+ }
+ }
}
diff --git a/src/test/java/org/apache/sanselan/formats/jpeg/iptc/IptcBaseTest.java b/src/test/java/org/apache/sanselan/formats/jpeg/iptc/IptcBaseTest.java
index 05c18dd..f81c8e4 100644
--- a/src/test/java/org/apache/sanselan/formats/jpeg/iptc/IptcBaseTest.java
+++ b/src/test/java/org/apache/sanselan/formats/jpeg/iptc/IptcBaseTest.java
@@ -29,77 +29,77 @@
public abstract class IptcBaseTest extends SanselanTest
{
- protected static boolean hasIptcData(File file)
- {
- // Debug.debug("hasIptcData file", file.getAbsoluteFile());
+ protected static boolean hasIptcData(File file)
+ {
+ // Debug.debug("hasIptcData file", file.getAbsoluteFile());
- if (!file.getName().toLowerCase().endsWith(".jpg"))
- return false;
- //ImageFormat format = Sanselan.guessFormat(file);
- //if (format != ImageFormat.IMAGE_FORMAT_JPEG)
- // return false;
+ if (!file.getName().toLowerCase().endsWith(".jpg"))
+ return false;
+ //ImageFormat format = Sanselan.guessFormat(file);
+ //if (format != ImageFormat.IMAGE_FORMAT_JPEG)
+ // return false;
- try
- {
- ByteSource byteSource = new ByteSourceFile(file);
- return new JpegImageParser().hasIptcSegment(byteSource);
- }
- catch (Exception e)
- {
- // Debug.debug("Error file", file.getAbsoluteFile());
- // Debug.debug(e, 4);
- return false;
- }
- }
+ try
+ {
+ ByteSource byteSource = new ByteSourceFile(file);
+ return new JpegImageParser().hasIptcSegment(byteSource);
+ }
+ catch (Exception e)
+ {
+ // Debug.debug("Error file", file.getAbsoluteFile());
+ // Debug.debug(e, 4);
+ return false;
+ }
+ }
- private static final ImageFilter HAS_IPTC_IMAGE_FILTER = new ImageFilter()
- {
- public boolean accept(File file) throws IOException, ImageReadException
- {
- return hasIptcData(file);
- }
- };
+ private static final ImageFilter HAS_IPTC_IMAGE_FILTER = new ImageFilter()
+ {
+ public boolean accept(File file) throws IOException, ImageReadException
+ {
+ return hasIptcData(file);
+ }
+ };
- private static final ImageFilter JPEG_IMAGE_FILTER = new ImageFilter()
- {
- public boolean accept(File file) throws IOException, ImageReadException
- {
- return file.getName().toLowerCase().endsWith(".jpg");
- }
- };
+ private static final ImageFilter JPEG_IMAGE_FILTER = new ImageFilter()
+ {
+ public boolean accept(File file) throws IOException, ImageReadException
+ {
+ return file.getName().toLowerCase().endsWith(".jpg");
+ }
+ };
- protected File getImageWithIptcData() throws IOException,
- ImageReadException
- {
- return getTestImage(HAS_IPTC_IMAGE_FILTER);
- }
+ protected File getImageWithIptcData() throws IOException,
+ ImageReadException
+ {
+ return getTestImage(HAS_IPTC_IMAGE_FILTER);
+ }
- protected List getImagesWithIptcData() throws IOException,
- ImageReadException
- {
- return getTestImages(HAS_IPTC_IMAGE_FILTER);
- }
+ protected List getImagesWithIptcData() throws IOException,
+ ImageReadException
+ {
+ return getTestImages(HAS_IPTC_IMAGE_FILTER);
+ }
- protected List getImagesWithIptcData(int max) throws IOException,
- ImageReadException
- {
- return getTestImages(HAS_IPTC_IMAGE_FILTER, max);
- }
+ protected List getImagesWithIptcData(int max) throws IOException,
+ ImageReadException
+ {
+ return getTestImages(HAS_IPTC_IMAGE_FILTER, max);
+ }
- protected File getJpegImage() throws IOException, ImageReadException
- {
- return getTestImage(JPEG_IMAGE_FILTER);
- }
+ protected File getJpegImage() throws IOException, ImageReadException
+ {
+ return getTestImage(JPEG_IMAGE_FILTER);
+ }
- protected List getJpegImages() throws IOException, ImageReadException
- {
- return getTestImages(JPEG_IMAGE_FILTER);
- }
+ protected List getJpegImages() throws IOException, ImageReadException
+ {
+ return getTestImages(JPEG_IMAGE_FILTER);
+ }
- protected List getJpegImages(int max) throws IOException,
- ImageReadException
- {
- return getTestImages(JPEG_IMAGE_FILTER, max);
- }
+ protected List getJpegImages(int max) throws IOException,
+ ImageReadException
+ {
+ return getTestImages(JPEG_IMAGE_FILTER, max);
+ }
}
diff --git a/src/test/java/org/apache/sanselan/formats/jpeg/iptc/IptcDumpTest.java b/src/test/java/org/apache/sanselan/formats/jpeg/iptc/IptcDumpTest.java
index 3658536..e7760af 100644
--- a/src/test/java/org/apache/sanselan/formats/jpeg/iptc/IptcDumpTest.java
+++ b/src/test/java/org/apache/sanselan/formats/jpeg/iptc/IptcDumpTest.java
@@ -32,53 +32,53 @@
public class IptcDumpTest extends IptcBaseTest
{
- public void test() throws IOException, ImageReadException
- {
- List images = getImagesWithIptcData();
- for (int i = 0; i < images.size(); i++)
- {
- if (i % 10 == 0)
- Debug.purgeMemory();
+ public void test() throws IOException, ImageReadException
+ {
+ List images = getImagesWithIptcData();
+ for (int i = 0; i < images.size(); i++)
+ {
+ if (i % 10 == 0)
+ Debug.purgeMemory();
- File imageFile = (File) images.get(i);
- Debug.debug("imageFile", imageFile);
- Debug.debug();
+ File imageFile = (File) images.get(i);
+ Debug.debug("imageFile", imageFile);
+ Debug.debug();
- // ByteSource byteSource = new ByteSourceFile(imageFile);
- // Debug.debug("Segments:");
- // new JpegUtils().dumpJFIF(byteSource);
+ // ByteSource byteSource = new ByteSourceFile(imageFile);
+ // Debug.debug("Segments:");
+ // new JpegUtils().dumpJFIF(byteSource);
- Map params = new HashMap();
- boolean ignoreImageData = isPhilHarveyTestImage(imageFile);
- params
- .put(PARAM_KEY_READ_THUMBNAILS, new Boolean(
- !ignoreImageData));
- // params.put(PARAM_KEY_VERBOSE, Boolean.TRUE);
+ Map params = new HashMap();
+ boolean ignoreImageData = isPhilHarveyTestImage(imageFile);
+ params
+ .put(PARAM_KEY_READ_THUMBNAILS, new Boolean(
+ !ignoreImageData));
+ // params.put(PARAM_KEY_VERBOSE, Boolean.TRUE);
- JpegImageMetadata metadata = (JpegImageMetadata) Sanselan
- .getMetadata(imageFile, params);
- assertNotNull(metadata);
- assertNotNull(metadata.getPhotoshop());
+ JpegImageMetadata metadata = (JpegImageMetadata) Sanselan
+ .getMetadata(imageFile, params);
+ assertNotNull(metadata);
+ assertNotNull(metadata.getPhotoshop());
- metadata.getPhotoshop().dump();
- // if(metadata.getPhotoshop().getItems().size()>0)
- // Debug.debug("iptc size",
- // metadata.getPhotoshop().getItems().size());
+ metadata.getPhotoshop().dump();
+ // if(metadata.getPhotoshop().getItems().size()>0)
+ // Debug.debug("iptc size",
+ // metadata.getPhotoshop().getItems().size());
- JpegPhotoshopMetadata psMetadata = metadata.getPhotoshop();
- List oldRecords = psMetadata.photoshopApp13Data.getRecords();
+ JpegPhotoshopMetadata psMetadata = metadata.getPhotoshop();
+ List oldRecords = psMetadata.photoshopApp13Data.getRecords();
- System.out.println();
- for (int j = 0; j < oldRecords.size(); j++)
- {
- IPTCRecord record = (IPTCRecord) oldRecords.get(j);
- if (record.iptcType.type != IPTCConstants.IPTC_TYPE_CITY.type)
- System.out.println("Key: " + record.iptcType.name + " (0x"
- + Integer.toHexString(record.iptcType.type)
- + "), value: " + record.value);
- }
- System.out.println();
- }
- }
+ System.out.println();
+ for (int j = 0; j < oldRecords.size(); j++)
+ {
+ IPTCRecord record = (IPTCRecord) oldRecords.get(j);
+ if (record.iptcType.type != IPTCConstants.IPTC_TYPE_CITY.type)
+ System.out.println("Key: " + record.iptcType.name + " (0x"
+ + Integer.toHexString(record.iptcType.type)
+ + "), value: " + record.value);
+ }
+ System.out.println();
+ }
+ }
}
diff --git a/src/test/java/org/apache/sanselan/formats/jpeg/iptc/IptcUpdateTest.java b/src/test/java/org/apache/sanselan/formats/jpeg/iptc/IptcUpdateTest.java
index 058620b..f06391b 100644
--- a/src/test/java/org/apache/sanselan/formats/jpeg/iptc/IptcUpdateTest.java
+++ b/src/test/java/org/apache/sanselan/formats/jpeg/iptc/IptcUpdateTest.java
@@ -37,387 +37,387 @@
public class IptcUpdateTest extends IptcBaseTest
{
- private List imagesWithIptcData;
+ private List imagesWithIptcData;
- public void setUp() throws Exception
- {
- super.setUp();
+ public void setUp() throws Exception
+ {
+ super.setUp();
- imagesWithIptcData = getImagesWithIptcData();
- }
+ imagesWithIptcData = getImagesWithIptcData();
+ }
- public void tearDown() throws Exception
- {
- super.tearDown();
+ public void tearDown() throws Exception
+ {
+ super.tearDown();
- imagesWithIptcData = null;
- }
+ imagesWithIptcData = null;
+ }
- /*
- * Remove all Photoshop IPTC data from a JPEG file.
- */
- public void testRemove() throws IOException, ImageReadException,
- ImageWriteException
- {
- List images = imagesWithIptcData;
- for (int i = 0; i < images.size(); i++)
- {
- if (i % 10 == 0)
- Debug.purgeMemory();
+ /*
+ * Remove all Photoshop IPTC data from a JPEG file.
+ */
+ public void testRemove() throws IOException, ImageReadException,
+ ImageWriteException
+ {
+ List images = imagesWithIptcData;
+ for (int i = 0; i < images.size(); i++)
+ {
+ if (i % 10 == 0)
+ Debug.purgeMemory();
- File imageFile = (File) images.get(i);
- // Debug.debug("imageFile", imageFile);
- // Debug.debug();
+ File imageFile = (File) images.get(i);
+ // Debug.debug("imageFile", imageFile);
+ // Debug.debug();
- ByteSource byteSource = new ByteSourceFile(imageFile);
+ ByteSource byteSource = new ByteSourceFile(imageFile);
- Map params = new HashMap();
- boolean ignoreImageData = isPhilHarveyTestImage(imageFile);
- params
- .put(PARAM_KEY_READ_THUMBNAILS, new Boolean(
- !ignoreImageData));
+ Map params = new HashMap();
+ boolean ignoreImageData = isPhilHarveyTestImage(imageFile);
+ params
+ .put(PARAM_KEY_READ_THUMBNAILS, new Boolean(
+ !ignoreImageData));
- JpegPhotoshopMetadata metadata = new JpegImageParser()
- .getPhotoshopMetadata(byteSource, params);
- assertNotNull(metadata);
- // metadata.dump();
+ JpegPhotoshopMetadata metadata = new JpegImageParser()
+ .getPhotoshopMetadata(byteSource, params);
+ assertNotNull(metadata);
+ // metadata.dump();
- File noIptcFile = createTempFile(imageFile.getName()
- + ".iptc.remove.", ".jpg");
- {
- // test remove
+ File noIptcFile = createTempFile(imageFile.getName()
+ + ".iptc.remove.", ".jpg");
+ {
+ // test remove
- OutputStream os = null;
- try
- {
- os = new FileOutputStream(noIptcFile);
- os = new BufferedOutputStream(os);
- new JpegIptcRewriter().removeIPTC(byteSource, os);
- } finally
- {
- if (os != null) {
- os.close();
- }
- os = null;
- }
-
- JpegPhotoshopMetadata outMetadata = new JpegImageParser()
- .getPhotoshopMetadata(new ByteSourceFile(noIptcFile),
- params);
- assertTrue(outMetadata == null
- || outMetadata.getItems().size() == 0);
- }
-
- }
- }
-
- public void testRemoveInsertUpdate() throws IOException,
- ImageReadException, ImageWriteException
- {
- List images = imagesWithIptcData;
- for (int i = 0; i < images.size(); i++)
- {
- if (i % 10 == 0)
- Debug.purgeMemory();
-
- File imageFile = (File) images.get(i);
- Debug.debug("imageFile", imageFile);
- Debug.debug();
-
- ByteSource byteSource = new ByteSourceFile(imageFile);
- // Debug.debug("Segments:");
- // new JpegUtils().dumpJFIF(byteSource);
-
- Map params = new HashMap();
- boolean ignoreImageData = isPhilHarveyTestImage(imageFile);
- params
- .put(PARAM_KEY_READ_THUMBNAILS, new Boolean(
- !ignoreImageData));
- // params.put(PARAM_KEY_VERBOSE, Boolean.TRUE);
- // params.put(PARAM_KEY_VERBOSE, Boolean.TRUE);
-
- JpegPhotoshopMetadata metadata = new JpegImageParser()
- .getPhotoshopMetadata(byteSource, params);
- assertNotNull(metadata);
- metadata.dump();
-
- File noIptcFile = createTempFile(imageFile.getName()
- + ".iptc.remove.", ".jpg");
- {
- // test remove
-
- OutputStream os = null;
- try
- {
- os = new FileOutputStream(noIptcFile);
- os = new BufferedOutputStream(os);
- new JpegIptcRewriter().removeIPTC(byteSource, os);
- } finally
- {
+ OutputStream os = null;
+ try
+ {
+ os = new FileOutputStream(noIptcFile);
+ os = new BufferedOutputStream(os);
+ new JpegIptcRewriter().removeIPTC(byteSource, os);
+ } finally
+ {
if (os != null) {
os.close();
}
- os = null;
- }
+ os = null;
+ }
- // Debug.debug("Source Segments:");
- // new JpegUtils().dumpJFIF(new ByteSourceFile(noIptcFile));
+ JpegPhotoshopMetadata outMetadata = new JpegImageParser()
+ .getPhotoshopMetadata(new ByteSourceFile(noIptcFile),
+ params);
+ assertTrue(outMetadata == null
+ || outMetadata.getItems().size() == 0);
+ }
- JpegPhotoshopMetadata outMetadata = new JpegImageParser()
- .getPhotoshopMetadata(new ByteSourceFile(noIptcFile),
- params);
- assertTrue(outMetadata == null
- || outMetadata.getItems().size() == 0);
- }
- {
- // test no-change update
+ }
+ }
- List newBlocks = metadata.photoshopApp13Data.getNonIptcBlocks();
- List oldRecords = metadata.photoshopApp13Data.getRecords();
- List newRecords = new ArrayList();
- for (int j = 0; j < oldRecords.size(); j++)
- {
- IPTCRecord record = (IPTCRecord) oldRecords.get(j);
- if (record.iptcType.type != IPTCConstants.IPTC_TYPE_CITY.type
- && record.iptcType.type != IPTCConstants.IPTC_TYPE_CREDIT.type)
- newRecords.add(record);
- }
+ public void testRemoveInsertUpdate() throws IOException,
+ ImageReadException, ImageWriteException
+ {
+ List images = imagesWithIptcData;
+ for (int i = 0; i < images.size(); i++)
+ {
+ if (i % 10 == 0)
+ Debug.purgeMemory();
- newRecords.add(new IPTCRecord(IPTCConstants.IPTC_TYPE_CITY,
- "Albany, NY"));
- newRecords.add(new IPTCRecord(IPTCConstants.IPTC_TYPE_CREDIT,
- "William Sorensen"));
+ File imageFile = (File) images.get(i);
+ Debug.debug("imageFile", imageFile);
+ Debug.debug();
- PhotoshopApp13Data newData = new PhotoshopApp13Data(newRecords,
- newBlocks);
+ ByteSource byteSource = new ByteSourceFile(imageFile);
+ // Debug.debug("Segments:");
+ // new JpegUtils().dumpJFIF(byteSource);
- File updated = createTempFile(imageFile.getName()
- + ".iptc.update.", ".jpg");
- OutputStream os = null;
- try
- {
- os = new FileOutputStream(updated);
- os = new BufferedOutputStream(os);
- new JpegIptcRewriter().writeIPTC(byteSource, os, newData);
- } finally
- {
+ Map params = new HashMap();
+ boolean ignoreImageData = isPhilHarveyTestImage(imageFile);
+ params
+ .put(PARAM_KEY_READ_THUMBNAILS, new Boolean(
+ !ignoreImageData));
+ // params.put(PARAM_KEY_VERBOSE, Boolean.TRUE);
+ // params.put(PARAM_KEY_VERBOSE, Boolean.TRUE);
+
+ JpegPhotoshopMetadata metadata = new JpegImageParser()
+ .getPhotoshopMetadata(byteSource, params);
+ assertNotNull(metadata);
+ metadata.dump();
+
+ File noIptcFile = createTempFile(imageFile.getName()
+ + ".iptc.remove.", ".jpg");
+ {
+ // test remove
+
+ OutputStream os = null;
+ try
+ {
+ os = new FileOutputStream(noIptcFile);
+ os = new BufferedOutputStream(os);
+ new JpegIptcRewriter().removeIPTC(byteSource, os);
+ } finally
+ {
if (os != null) {
os.close();
}
- os = null;
- }
+ os = null;
+ }
- // Debug.debug("Source Segments:");
- // new JpegUtils().dumpJFIF(new ByteSourceFile(updated));
+ // Debug.debug("Source Segments:");
+ // new JpegUtils().dumpJFIF(new ByteSourceFile(noIptcFile));
- ByteSource updateByteSource = new ByteSourceFile(updated);
- JpegPhotoshopMetadata outMetadata = new JpegImageParser()
- .getPhotoshopMetadata(updateByteSource, params);
+ JpegPhotoshopMetadata outMetadata = new JpegImageParser()
+ .getPhotoshopMetadata(new ByteSourceFile(noIptcFile),
+ params);
+ assertTrue(outMetadata == null
+ || outMetadata.getItems().size() == 0);
+ }
+ {
+ // test no-change update
- // Debug.debug("outMetadata", outMetadata.toString());
- // Debug.debug("hasIptcSegment", new JpegImageParser()
- // .hasIptcSegment(updateByteSource));
+ List newBlocks = metadata.photoshopApp13Data.getNonIptcBlocks();
+ List oldRecords = metadata.photoshopApp13Data.getRecords();
+ List newRecords = new ArrayList();
+ for (int j = 0; j < oldRecords.size(); j++)
+ {
+ IPTCRecord record = (IPTCRecord) oldRecords.get(j);
+ if (record.iptcType.type != IPTCConstants.IPTC_TYPE_CITY.type
+ && record.iptcType.type != IPTCConstants.IPTC_TYPE_CREDIT.type)
+ newRecords.add(record);
+ }
- assertNotNull(outMetadata);
- assertTrue(outMetadata.getItems().size() == newRecords.size());
- // assertEquals(metadata.toString(), outMetadata.toString());
- }
+ newRecords.add(new IPTCRecord(IPTCConstants.IPTC_TYPE_CITY,
+ "Albany, NY"));
+ newRecords.add(new IPTCRecord(IPTCConstants.IPTC_TYPE_CREDIT,
+ "William Sorensen"));
- {
- // test update
+ PhotoshopApp13Data newData = new PhotoshopApp13Data(newRecords,
+ newBlocks);
- List newBlocks = metadata.photoshopApp13Data.getNonIptcBlocks();
- List newRecords = new ArrayList();
-
- newRecords.add(new IPTCRecord(IPTCConstants.IPTC_TYPE_CITY,
- "Albany, NY"));
- newRecords.add(new IPTCRecord(IPTCConstants.IPTC_TYPE_CREDIT,
- "William Sorensen"));
-
- PhotoshopApp13Data newData = new PhotoshopApp13Data(newRecords,
- newBlocks);
-
- File updated = createTempFile(imageFile.getName()
- + ".iptc.update.", ".jpg");
- OutputStream os = null;
- try
- {
- os = new FileOutputStream(updated);
- os = new BufferedOutputStream(os);
- new JpegIptcRewriter().writeIPTC(byteSource, os, newData);
- } finally
- {
+ File updated = createTempFile(imageFile.getName()
+ + ".iptc.update.", ".jpg");
+ OutputStream os = null;
+ try
+ {
+ os = new FileOutputStream(updated);
+ os = new BufferedOutputStream(os);
+ new JpegIptcRewriter().writeIPTC(byteSource, os, newData);
+ } finally
+ {
if (os != null) {
os.close();
}
- os = null;
- }
+ os = null;
+ }
- // Debug.debug("Source Segments:");
- // new JpegUtils().dumpJFIF(new ByteSourceFile(updated));
+ // Debug.debug("Source Segments:");
+ // new JpegUtils().dumpJFIF(new ByteSourceFile(updated));
- ByteSource updateByteSource = new ByteSourceFile(updated);
- JpegPhotoshopMetadata outMetadata = new JpegImageParser()
- .getPhotoshopMetadata(updateByteSource, params);
+ ByteSource updateByteSource = new ByteSourceFile(updated);
+ JpegPhotoshopMetadata outMetadata = new JpegImageParser()
+ .getPhotoshopMetadata(updateByteSource, params);
- // Debug.debug("outMetadata", outMetadata.toString());
- // Debug.debug("hasIptcSegment", new JpegImageParser()
- // .hasIptcSegment(updateByteSource));
+ // Debug.debug("outMetadata", outMetadata.toString());
+ // Debug.debug("hasIptcSegment", new JpegImageParser()
+ // .hasIptcSegment(updateByteSource));
- assertNotNull(outMetadata);
- assertTrue(outMetadata.getItems().size() == 2);
- // assertEquals(metadata.toString(), outMetadata.toString());
- }
+ assertNotNull(outMetadata);
+ assertTrue(outMetadata.getItems().size() == newRecords.size());
+ // assertEquals(metadata.toString(), outMetadata.toString());
+ }
- {
- // test insert
+ {
+ // test update
- List newBlocks = new ArrayList();
- List newRecords = new ArrayList();
+ List newBlocks = metadata.photoshopApp13Data.getNonIptcBlocks();
+ List newRecords = new ArrayList();
- newRecords.add(new IPTCRecord(IPTCConstants.IPTC_TYPE_CITY,
- "Albany, NY"));
- newRecords.add(new IPTCRecord(IPTCConstants.IPTC_TYPE_CREDIT,
- "William Sorensen"));
+ newRecords.add(new IPTCRecord(IPTCConstants.IPTC_TYPE_CITY,
+ "Albany, NY"));
+ newRecords.add(new IPTCRecord(IPTCConstants.IPTC_TYPE_CREDIT,
+ "William Sorensen"));
- PhotoshopApp13Data newData = new PhotoshopApp13Data(newRecords,
- newBlocks);
+ PhotoshopApp13Data newData = new PhotoshopApp13Data(newRecords,
+ newBlocks);
- File updated = createTempFile(imageFile.getName()
- + ".iptc.insert.", ".jpg");
- OutputStream os = null;
- try
- {
- os = new FileOutputStream(updated);
- os = new BufferedOutputStream(os);
- new JpegIptcRewriter().writeIPTC(new ByteSourceFile(
- noIptcFile), os, newData);
- } finally
- {
+ File updated = createTempFile(imageFile.getName()
+ + ".iptc.update.", ".jpg");
+ OutputStream os = null;
+ try
+ {
+ os = new FileOutputStream(updated);
+ os = new BufferedOutputStream(os);
+ new JpegIptcRewriter().writeIPTC(byteSource, os, newData);
+ } finally
+ {
if (os != null) {
os.close();
}
- os = null;
- }
+ os = null;
+ }
- // Debug.debug("Source Segments:");
- // new JpegUtils().dumpJFIF(new ByteSourceFile(updated));
+ // Debug.debug("Source Segments:");
+ // new JpegUtils().dumpJFIF(new ByteSourceFile(updated));
- ByteSource updateByteSource = new ByteSourceFile(updated);
- JpegPhotoshopMetadata outMetadata = new JpegImageParser()
- .getPhotoshopMetadata(updateByteSource, params);
+ ByteSource updateByteSource = new ByteSourceFile(updated);
+ JpegPhotoshopMetadata outMetadata = new JpegImageParser()
+ .getPhotoshopMetadata(updateByteSource, params);
- // Debug.debug("outMetadata", outMetadata.toString());
- // Debug.debug("hasIptcSegment", new JpegImageParser()
- // .hasIptcSegment(updateByteSource));
+ // Debug.debug("outMetadata", outMetadata.toString());
+ // Debug.debug("hasIptcSegment", new JpegImageParser()
+ // .hasIptcSegment(updateByteSource));
- assertNotNull(outMetadata);
- assertTrue(outMetadata.getItems().size() == 2);
- // assertEquals(metadata.toString(), outMetadata.toString());
- }
+ assertNotNull(outMetadata);
+ assertTrue(outMetadata.getItems().size() == 2);
+ // assertEquals(metadata.toString(), outMetadata.toString());
+ }
- }
- }
+ {
+ // test insert
- /*
- * Add a few IPTC values to JPEG images, whether or not they have existing
- * IPTC data.
- */
- public void testAddIptcData() throws IOException, ImageReadException,
- ImageWriteException
- {
- List images = getJpegImages();
- for (int i = 0; i < images.size(); i++)
- {
- if (i % 10 == 0)
- Debug.purgeMemory();
+ List newBlocks = new ArrayList();
+ List newRecords = new ArrayList();
- File imageFile = (File) images.get(i);
-// Debug.debug("imageFile", imageFile);
-// Debug.debug();
+ newRecords.add(new IPTCRecord(IPTCConstants.IPTC_TYPE_CITY,
+ "Albany, NY"));
+ newRecords.add(new IPTCRecord(IPTCConstants.IPTC_TYPE_CREDIT,
+ "William Sorensen"));
- ByteSource byteSource = new ByteSourceFile(imageFile);
-// Debug.debug("Segments:");
-// new JpegUtils().dumpJFIF(byteSource);
+ PhotoshopApp13Data newData = new PhotoshopApp13Data(newRecords,
+ newBlocks);
- Map params = new HashMap();
- boolean ignoreImageData = isPhilHarveyTestImage(imageFile);
- params
- .put(PARAM_KEY_READ_THUMBNAILS, new Boolean(
- !ignoreImageData));
-
- JpegPhotoshopMetadata metadata = new JpegImageParser()
- .getPhotoshopMetadata(byteSource, params);
- // metadata.dump();
-
- {
- List newBlocks = new ArrayList();
- List newRecords = new ArrayList();
-
- if (null != metadata)
- {
- boolean keepOldIptcNonTextValues = true;
- if (keepOldIptcNonTextValues)
- newBlocks.addAll(metadata.photoshopApp13Data
- .getNonIptcBlocks());
- boolean keepOldIptcTextValues = true;
- if (keepOldIptcTextValues)
- {
- List oldRecords = metadata.photoshopApp13Data
- .getRecords();
-
- newRecords = new ArrayList();
- for (int j = 0; j < oldRecords.size(); j++)
- {
- IPTCRecord record = (IPTCRecord) oldRecords.get(j);
- if (record.iptcType.type != IPTCConstants.IPTC_TYPE_CITY.type
- && record.iptcType.type != IPTCConstants.IPTC_TYPE_CREDIT.type)
- newRecords.add(record);
- }
- }
- }
-
- newRecords.add(new IPTCRecord(IPTCConstants.IPTC_TYPE_CITY,
- "Albany, NY"));
- newRecords.add(new IPTCRecord(IPTCConstants.IPTC_TYPE_CREDIT,
- "William Sorensen"));
-
- PhotoshopApp13Data newData = new PhotoshopApp13Data(newRecords,
- newBlocks);
-
- File updated = createTempFile(imageFile.getName()
- + ".iptc.add.", ".jpg");
- OutputStream os = null;
- try
- {
- os = new FileOutputStream(updated);
- os = new BufferedOutputStream(os);
- new JpegIptcRewriter().writeIPTC(byteSource, os, newData);
- } finally
- {
+ File updated = createTempFile(imageFile.getName()
+ + ".iptc.insert.", ".jpg");
+ OutputStream os = null;
+ try
+ {
+ os = new FileOutputStream(updated);
+ os = new BufferedOutputStream(os);
+ new JpegIptcRewriter().writeIPTC(new ByteSourceFile(
+ noIptcFile), os, newData);
+ } finally
+ {
if (os != null) {
os.close();
}
- os = null;
- }
+ os = null;
+ }
- // Debug.debug("Destination Segments:");
- // new JpegUtils().dumpJFIF(new ByteSourceFile(updated));
+ // Debug.debug("Source Segments:");
+ // new JpegUtils().dumpJFIF(new ByteSourceFile(updated));
- ByteSource updateByteSource = new ByteSourceFile(updated);
- JpegPhotoshopMetadata outMetadata = new JpegImageParser()
- .getPhotoshopMetadata(updateByteSource, params);
+ ByteSource updateByteSource = new ByteSourceFile(updated);
+ JpegPhotoshopMetadata outMetadata = new JpegImageParser()
+ .getPhotoshopMetadata(updateByteSource, params);
- // Debug.debug("outMetadata", outMetadata.toString());
- // Debug.debug("hasIptcSegment", new JpegImageParser()
- // .hasIptcSegment(updateByteSource));
+ // Debug.debug("outMetadata", outMetadata.toString());
+ // Debug.debug("hasIptcSegment", new JpegImageParser()
+ // .hasIptcSegment(updateByteSource));
- assertNotNull(outMetadata);
- assertTrue(outMetadata.getItems().size() == newRecords.size());
- // assertEquals(metadata.toString(), outMetadata.toString());
- }
+ assertNotNull(outMetadata);
+ assertTrue(outMetadata.getItems().size() == 2);
+ // assertEquals(metadata.toString(), outMetadata.toString());
+ }
- }
- }
+ }
+ }
+
+ /*
+ * Add a few IPTC values to JPEG images, whether or not they have existing
+ * IPTC data.
+ */
+ public void testAddIptcData() throws IOException, ImageReadException,
+ ImageWriteException
+ {
+ List images = getJpegImages();
+ for (int i = 0; i < images.size(); i++)
+ {
+ if (i % 10 == 0)
+ Debug.purgeMemory();
+
+ File imageFile = (File) images.get(i);
+// Debug.debug("imageFile", imageFile);
+// Debug.debug();
+
+ ByteSource byteSource = new ByteSourceFile(imageFile);
+// Debug.debug("Segments:");
+// new JpegUtils().dumpJFIF(byteSource);
+
+ Map params = new HashMap();
+ boolean ignoreImageData = isPhilHarveyTestImage(imageFile);
+ params
+ .put(PARAM_KEY_READ_THUMBNAILS, new Boolean(
+ !ignoreImageData));
+
+ JpegPhotoshopMetadata metadata = new JpegImageParser()
+ .getPhotoshopMetadata(byteSource, params);
+ // metadata.dump();
+
+ {
+ List newBlocks = new ArrayList();
+ List newRecords = new ArrayList();
+
+ if (null != metadata)
+ {
+ boolean keepOldIptcNonTextValues = true;
+ if (keepOldIptcNonTextValues)
+ newBlocks.addAll(metadata.photoshopApp13Data
+ .getNonIptcBlocks());
+ boolean keepOldIptcTextValues = true;
+ if (keepOldIptcTextValues)
+ {
+ List oldRecords = metadata.photoshopApp13Data
+ .getRecords();
+
+ newRecords = new ArrayList();
+ for (int j = 0; j < oldRecords.size(); j++)
+ {
+ IPTCRecord record = (IPTCRecord) oldRecords.get(j);
+ if (record.iptcType.type != IPTCConstants.IPTC_TYPE_CITY.type
+ && record.iptcType.type != IPTCConstants.IPTC_TYPE_CREDIT.type)
+ newRecords.add(record);
+ }
+ }
+ }
+
+ newRecords.add(new IPTCRecord(IPTCConstants.IPTC_TYPE_CITY,
+ "Albany, NY"));
+ newRecords.add(new IPTCRecord(IPTCConstants.IPTC_TYPE_CREDIT,
+ "William Sorensen"));
+
+ PhotoshopApp13Data newData = new PhotoshopApp13Data(newRecords,
+ newBlocks);
+
+ File updated = createTempFile(imageFile.getName()
+ + ".iptc.add.", ".jpg");
+ OutputStream os = null;
+ try
+ {
+ os = new FileOutputStream(updated);
+ os = new BufferedOutputStream(os);
+ new JpegIptcRewriter().writeIPTC(byteSource, os, newData);
+ } finally
+ {
+ if (os != null) {
+ os.close();
+ }
+ os = null;
+ }
+
+ // Debug.debug("Destination Segments:");
+ // new JpegUtils().dumpJFIF(new ByteSourceFile(updated));
+
+ ByteSource updateByteSource = new ByteSourceFile(updated);
+ JpegPhotoshopMetadata outMetadata = new JpegImageParser()
+ .getPhotoshopMetadata(updateByteSource, params);
+
+ // Debug.debug("outMetadata", outMetadata.toString());
+ // Debug.debug("hasIptcSegment", new JpegImageParser()
+ // .hasIptcSegment(updateByteSource));
+
+ assertNotNull(outMetadata);
+ assertTrue(outMetadata.getItems().size() == newRecords.size());
+ // assertEquals(metadata.toString(), outMetadata.toString());
+ }
+
+ }
+ }
}
diff --git a/src/test/java/org/apache/sanselan/formats/jpeg/xmp/JpegXmpBaseTest.java b/src/test/java/org/apache/sanselan/formats/jpeg/xmp/JpegXmpBaseTest.java
index fcbc975..ce5baef 100644
--- a/src/test/java/org/apache/sanselan/formats/jpeg/xmp/JpegXmpBaseTest.java
+++ b/src/test/java/org/apache/sanselan/formats/jpeg/xmp/JpegXmpBaseTest.java
@@ -30,77 +30,77 @@
public abstract class JpegXmpBaseTest extends SanselanTest
{
- protected static boolean hasJpegXmpData(File file)
- {
- if (!file.getName().toLowerCase().endsWith(".jpg"))
- return false;
- //ImageFormat format = Sanselan.guessFormat(file);
- //if (format != ImageFormat.IMAGE_FORMAT_JPEG)
- // return false;
+ protected static boolean hasJpegXmpData(File file)
+ {
+ if (!file.getName().toLowerCase().endsWith(".jpg"))
+ return false;
+ //ImageFormat format = Sanselan.guessFormat(file);
+ //if (format != ImageFormat.IMAGE_FORMAT_JPEG)
+ // return false;
- // Debug.debug("possible file", file);
+ // Debug.debug("possible file", file);
- try
- {
- ByteSource byteSource = new ByteSourceFile(file);
- return new JpegImageParser().hasXmpSegment(byteSource);
- }
- catch (Exception e)
- {
- // Debug.debug("Error file", file.getAbsoluteFile());
- // Debug.debug(e, 4);
- return false;
- }
- }
+ try
+ {
+ ByteSource byteSource = new ByteSourceFile(file);
+ return new JpegImageParser().hasXmpSegment(byteSource);
+ }
+ catch (Exception e)
+ {
+ // Debug.debug("Error file", file.getAbsoluteFile());
+ // Debug.debug(e, 4);
+ return false;
+ }
+ }
- private static final ImageFilter HAS_JPEG_XMP_IMAGE_FILTER = new ImageFilter()
- {
- public boolean accept(File file) throws IOException, ImageReadException
- {
- return hasJpegXmpData(file);
- }
- };
+ private static final ImageFilter HAS_JPEG_XMP_IMAGE_FILTER = new ImageFilter()
+ {
+ public boolean accept(File file) throws IOException, ImageReadException
+ {
+ return hasJpegXmpData(file);
+ }
+ };
-// private static final ImageFilter JPEG_IMAGE_FILTER = new ImageFilter()
-// {
-// public boolean accept(File file) throws IOException, ImageReadException
-// {
-// return file.getName().toLowerCase().endsWith(".jpg");
-// }
-// };
+// private static final ImageFilter JPEG_IMAGE_FILTER = new ImageFilter()
+// {
+// public boolean accept(File file) throws IOException, ImageReadException
+// {
+// return file.getName().toLowerCase().endsWith(".jpg");
+// }
+// };
- protected File getImageWithXmpData() throws IOException,
- ImageReadException
- {
- return getTestImage(HAS_JPEG_XMP_IMAGE_FILTER);
- }
+ protected File getImageWithXmpData() throws IOException,
+ ImageReadException
+ {
+ return getTestImage(HAS_JPEG_XMP_IMAGE_FILTER);
+ }
- protected List getImagesWithXmpData() throws IOException,
- ImageReadException
- {
- return getTestImages(HAS_JPEG_XMP_IMAGE_FILTER);
- }
+ protected List getImagesWithXmpData() throws IOException,
+ ImageReadException
+ {
+ return getTestImages(HAS_JPEG_XMP_IMAGE_FILTER);
+ }
- protected List getImagesWithXmpData(int max) throws IOException,
- ImageReadException
- {
- return getTestImages(HAS_JPEG_XMP_IMAGE_FILTER, max);
- }
+ protected List getImagesWithXmpData(int max) throws IOException,
+ ImageReadException
+ {
+ return getTestImages(HAS_JPEG_XMP_IMAGE_FILTER, max);
+ }
-// protected File getJpegImage() throws IOException, ImageReadException
-// {
-// return getTestImage(JPEG_IMAGE_FILTER);
-// }
+// protected File getJpegImage() throws IOException, ImageReadException
+// {
+// return getTestImage(JPEG_IMAGE_FILTER);
+// }
//
-// protected List getJpegImages() throws IOException, ImageReadException
-// {
-// return getTestImages(JPEG_IMAGE_FILTER);
-// }
+// protected List getJpegImages() throws IOException, ImageReadException
+// {
+// return getTestImages(JPEG_IMAGE_FILTER);
+// }
//
-// protected List getJpegImages(int max) throws IOException,
-// ImageReadException
-// {
-// return getTestImages(JPEG_IMAGE_FILTER, max);
-// }
+// protected List getJpegImages(int max) throws IOException,
+// ImageReadException
+// {
+// return getTestImages(JPEG_IMAGE_FILTER, max);
+// }
}
diff --git a/src/test/java/org/apache/sanselan/formats/jpeg/xmp/JpegXmpDumpTest.java b/src/test/java/org/apache/sanselan/formats/jpeg/xmp/JpegXmpDumpTest.java
index 6201703..da0d309 100644
--- a/src/test/java/org/apache/sanselan/formats/jpeg/xmp/JpegXmpDumpTest.java
+++ b/src/test/java/org/apache/sanselan/formats/jpeg/xmp/JpegXmpDumpTest.java
@@ -32,26 +32,26 @@
public class JpegXmpDumpTest extends JpegXmpBaseTest
{
- public void test() throws IOException, ImageReadException
- {
- List images = getImagesWithXmpData();
- for (int i = 0; i < images.size(); i++)
- {
- if (i % 10 == 0)
- Debug.purgeMemory();
+ public void test() throws IOException, ImageReadException
+ {
+ List images = getImagesWithXmpData();
+ for (int i = 0; i < images.size(); i++)
+ {
+ if (i % 10 == 0)
+ Debug.purgeMemory();
- File imageFile = (File) images.get(i);
- Debug.debug("imageFile", imageFile);
- Debug.debug();
+ File imageFile = (File) images.get(i);
+ Debug.debug("imageFile", imageFile);
+ Debug.debug();
- ByteSource byteSource = new ByteSourceFile(imageFile);
- Map params = new HashMap();
- String xmpXml = new JpegImageParser().getXmpXml(byteSource, params );
- assertNotNull(xmpXml);
+ ByteSource byteSource = new ByteSourceFile(imageFile);
+ Map params = new HashMap();
+ String xmpXml = new JpegImageParser().getXmpXml(byteSource, params );
+ assertNotNull(xmpXml);
- Debug.debug("xmpXml", xmpXml);
- Debug.debug();
- }
- }
+ Debug.debug("xmpXml", xmpXml);
+ Debug.debug();
+ }
+ }
}
diff --git a/src/test/java/org/apache/sanselan/formats/jpeg/xmp/JpegXmpRewriteTest.java b/src/test/java/org/apache/sanselan/formats/jpeg/xmp/JpegXmpRewriteTest.java
index c573ceb..270f537 100644
--- a/src/test/java/org/apache/sanselan/formats/jpeg/xmp/JpegXmpRewriteTest.java
+++ b/src/test/java/org/apache/sanselan/formats/jpeg/xmp/JpegXmpRewriteTest.java
@@ -36,117 +36,117 @@
public class JpegXmpRewriteTest extends JpegXmpBaseTest
{
- public void testRemoveInsertUpdate() throws IOException, ImageReadException,
- ImageWriteException
- {
- List images = getImagesWithXmpData();
- for (int i = 0; i < images.size(); i++)
- {
- if (i % 10 == 0)
- Debug.purgeMemory();
+ public void testRemoveInsertUpdate() throws IOException, ImageReadException,
+ ImageWriteException
+ {
+ List images = getImagesWithXmpData();
+ for (int i = 0; i < images.size(); i++)
+ {
+ if (i % 10 == 0)
+ Debug.purgeMemory();
- File imageFile = (File) images.get(i);
- Debug.debug("imageFile", imageFile);
+ File imageFile = (File) images.get(i);
+ Debug.debug("imageFile", imageFile);
- // boolean ignoreImageData = isPhilHarveyTestImage(imageFile);
- // if (ignoreImageData)
- // continue;
+ // boolean ignoreImageData = isPhilHarveyTestImage(imageFile);
+ // if (ignoreImageData)
+ // continue;
- ByteSource byteSource = new ByteSourceFile(imageFile);
- // Debug.debug("Source Segments:");
- // new JpegUtils().dumpJFIF(byteSource);
+ ByteSource byteSource = new ByteSourceFile(imageFile);
+ // Debug.debug("Source Segments:");
+ // new JpegUtils().dumpJFIF(byteSource);
- Map params = new HashMap();
- String xmpXml = new JpegImageParser().getXmpXml(byteSource, params);
- assertNotNull(xmpXml);
+ Map params = new HashMap();
+ String xmpXml = new JpegImageParser().getXmpXml(byteSource, params);
+ assertNotNull(xmpXml);
- // Debug.debug("xmpXml", xmpXml.length());
- // Debug.debug();
+ // Debug.debug("xmpXml", xmpXml.length());
+ // Debug.debug();
- File noXmpFile = createTempFile(imageFile.getName() + ".", ".jpg");
- {
- // test remove
-
- OutputStream os = null;
- try
- {
- os = new FileOutputStream(noXmpFile);
- os = new BufferedOutputStream(os);
- new JpegXmpRewriter().removeXmpXml(byteSource, os);
- } finally
- {
- if (os != null) {
- os.close();
- }
- os = null;
- }
+ File noXmpFile = createTempFile(imageFile.getName() + ".", ".jpg");
+ {
+ // test remove
- // Debug.debug("Source Segments:");
- // new JpegUtils().dumpJFIF(new ByteSourceFile(noXmpFile));
+ OutputStream os = null;
+ try
+ {
+ os = new FileOutputStream(noXmpFile);
+ os = new BufferedOutputStream(os);
+ new JpegXmpRewriter().removeXmpXml(byteSource, os);
+ } finally
+ {
+ if (os != null) {
+ os.close();
+ }
+ os = null;
+ }
- String outXmp = new JpegImageParser().getXmpXml(
- new ByteSourceFile(noXmpFile), params);
- assertNull(outXmp);
- }
+ // Debug.debug("Source Segments:");
+ // new JpegUtils().dumpJFIF(new ByteSourceFile(noXmpFile));
- {
- // test update
-
- String newXmpXml = "test";
- File updated = createTempFile(imageFile.getName() + ".", ".jpg");
- OutputStream os = null;
- try
- {
- os = new FileOutputStream(updated);
- os = new BufferedOutputStream(os);
- new JpegXmpRewriter().updateXmpXml(byteSource, os,
- newXmpXml);
- } finally
- {
- if (os != null) {
- os.close();
- }
- os = null;
- }
+ String outXmp = new JpegImageParser().getXmpXml(
+ new ByteSourceFile(noXmpFile), params);
+ assertNull(outXmp);
+ }
- // Debug.debug("Source Segments:");
- // new JpegUtils().dumpJFIF(new ByteSourceFile(updated));
+ {
+ // test update
- String outXmp = new JpegImageParser().getXmpXml(
- new ByteSourceFile(updated), params);
- assertNotNull(outXmp);
- assertEquals(outXmp, newXmpXml);
- }
+ String newXmpXml = "test";
+ File updated = createTempFile(imageFile.getName() + ".", ".jpg");
+ OutputStream os = null;
+ try
+ {
+ os = new FileOutputStream(updated);
+ os = new BufferedOutputStream(os);
+ new JpegXmpRewriter().updateXmpXml(byteSource, os,
+ newXmpXml);
+ } finally
+ {
+ if (os != null) {
+ os.close();
+ }
+ os = null;
+ }
- {
- // test insert
-
- String newXmpXml = "test";
- File updated = createTempFile(imageFile.getName() + ".", ".jpg");
- OutputStream os = null;
- try
- {
- os = new FileOutputStream(updated);
- os = new BufferedOutputStream(os);
- new JpegXmpRewriter().updateXmpXml(new ByteSourceFile(noXmpFile), os,
- newXmpXml);
- } finally
- {
- if (os != null) {
- os.close();
- }
- os = null;
- }
+ // Debug.debug("Source Segments:");
+ // new JpegUtils().dumpJFIF(new ByteSourceFile(updated));
- // Debug.debug("Source Segments:");
- // new JpegUtils().dumpJFIF(new ByteSourceFile(updated));
+ String outXmp = new JpegImageParser().getXmpXml(
+ new ByteSourceFile(updated), params);
+ assertNotNull(outXmp);
+ assertEquals(outXmp, newXmpXml);
+ }
- String outXmp = new JpegImageParser().getXmpXml(
- new ByteSourceFile(updated), params);
- assertNotNull(outXmp);
- assertEquals(outXmp, newXmpXml);
- }
- }
- }
+ {
+ // test insert
+
+ String newXmpXml = "test";
+ File updated = createTempFile(imageFile.getName() + ".", ".jpg");
+ OutputStream os = null;
+ try
+ {
+ os = new FileOutputStream(updated);
+ os = new BufferedOutputStream(os);
+ new JpegXmpRewriter().updateXmpXml(new ByteSourceFile(noXmpFile), os,
+ newXmpXml);
+ } finally
+ {
+ if (os != null) {
+ os.close();
+ }
+ os = null;
+ }
+
+ // Debug.debug("Source Segments:");
+ // new JpegUtils().dumpJFIF(new ByteSourceFile(updated));
+
+ String outXmp = new JpegImageParser().getXmpXml(
+ new ByteSourceFile(updated), params);
+ assertNotNull(outXmp);
+ assertEquals(outXmp, newXmpXml);
+ }
+ }
+ }
}
diff --git a/src/test/java/org/apache/sanselan/formats/png/ConvertPngToGifTest.java b/src/test/java/org/apache/sanselan/formats/png/ConvertPngToGifTest.java
index 6ca5cd0..048c023 100644
--- a/src/test/java/org/apache/sanselan/formats/png/ConvertPngToGifTest.java
+++ b/src/test/java/org/apache/sanselan/formats/png/ConvertPngToGifTest.java
@@ -33,33 +33,33 @@
- public void test() throws IOException, ImageReadException,
- ImageWriteException {
+ public void test() throws IOException, ImageReadException,
+ ImageWriteException {
- List images = getPngImages();
- for (int i = 0; i < images.size(); i++) {
- if (i % 10 == 0)
- Debug.purgeMemory();
+ List images = getPngImages();
+ for (int i = 0; i < images.size(); i++) {
+ if (i % 10 == 0)
+ Debug.purgeMemory();
- File imageFile = (File) images.get(i);
- if (isInvalidPNGTestFile(imageFile))
- continue;
- // Debug.debug("imageFile", imageFile);
- // Debug.debug();
+ File imageFile = (File) images.get(i);
+ if (isInvalidPNGTestFile(imageFile))
+ continue;
+ // Debug.debug("imageFile", imageFile);
+ // Debug.debug();
- Hashtable params = new Hashtable();
-// params.put(SanselanConstants.PARAM_KEY_VERBOSE, Boolean.TRUE);
+ Hashtable params = new Hashtable();
+// params.put(SanselanConstants.PARAM_KEY_VERBOSE, Boolean.TRUE);
- BufferedImage image = Sanselan.getBufferedImage(imageFile, params);
- assertNotNull(image);
+ BufferedImage image = Sanselan.getBufferedImage(imageFile, params);
+ assertNotNull(image);
- File outFile = createTempFile(imageFile.getName()+".", ".gif");
-// Debug.debug("outFile", outFile);
+ File outFile = createTempFile(imageFile.getName()+".", ".gif");
+// Debug.debug("outFile", outFile);
- Sanselan.writeImage(image, outFile, ImageFormat.IMAGE_FORMAT_GIF,
- params);
- }
- Debug.debug("complete.");
- }
+ Sanselan.writeImage(image, outFile, ImageFormat.IMAGE_FORMAT_GIF,
+ params);
+ }
+ Debug.debug("complete.");
+ }
}
diff --git a/src/test/java/org/apache/sanselan/formats/png/PngBaseTest.java b/src/test/java/org/apache/sanselan/formats/png/PngBaseTest.java
index 7b145a5..53db95d 100644
--- a/src/test/java/org/apache/sanselan/formats/png/PngBaseTest.java
+++ b/src/test/java/org/apache/sanselan/formats/png/PngBaseTest.java
@@ -29,24 +29,24 @@
public abstract class PngBaseTest extends SanselanTest
{
- private static boolean isPng(File file) throws IOException,
- ImageReadException
- {
- ImageFormat format = Sanselan.guessFormat(file);
- return format == ImageFormat.IMAGE_FORMAT_PNG;
- }
+ private static boolean isPng(File file) throws IOException,
+ ImageReadException
+ {
+ ImageFormat format = Sanselan.guessFormat(file);
+ return format == ImageFormat.IMAGE_FORMAT_PNG;
+ }
- private static final ImageFilter imageFilter = new ImageFilter() {
- public boolean accept(File file) throws IOException, ImageReadException
- {
- return isPng(file);
- }
- };
+ private static final ImageFilter imageFilter = new ImageFilter() {
+ public boolean accept(File file) throws IOException, ImageReadException
+ {
+ return isPng(file);
+ }
+ };
- protected List getPngImages() throws IOException, ImageReadException
- {
- return getTestImages(imageFilter);
- }
+ protected List getPngImages() throws IOException, ImageReadException
+ {
+ return getTestImages(imageFilter);
+ }
diff --git a/src/test/java/org/apache/sanselan/formats/png/PngMultipleRoundtripTest.java b/src/test/java/org/apache/sanselan/formats/png/PngMultipleRoundtripTest.java
index f240ed8..004c422 100644
--- a/src/test/java/org/apache/sanselan/formats/png/PngMultipleRoundtripTest.java
+++ b/src/test/java/org/apache/sanselan/formats/png/PngMultipleRoundtripTest.java
@@ -33,46 +33,46 @@
public class PngMultipleRoundtripTest extends PngBaseTest
{
- public void test() throws IOException, ImageReadException,
- ImageWriteException
- {
- String imagesFolderPath = FilenameUtils.separatorsToSystem("src\\test\\data\\images\\png\\3");
- File imagesFolder = new File(imagesFolderPath);
- assertTrue(imagesFolder.exists() && imagesFolder.isDirectory());
-
- File files[] = imagesFolder.listFiles();
- for (int i = 0; i < files.length; i++)
- {
- File imageFile = files[i];
- if(!imageFile.isFile() )
- continue;
- if(!imageFile.getName().toLowerCase().endsWith(".png"))
- continue;
-
- Debug.debug();
- Debug.debug("imageFile", imageFile);
+ public void test() throws IOException, ImageReadException,
+ ImageWriteException
+ {
+ String imagesFolderPath = FilenameUtils.separatorsToSystem("src\\test\\data\\images\\png\\3");
+ File imagesFolder = new File(imagesFolderPath);
+ assertTrue(imagesFolder.exists() && imagesFolder.isDirectory());
- File lastFile = imageFile;
- for (int j = 0; j < 10; j++)
- {
- Map readParams = new HashMap();
- // readParams.put(SanselanConstants.BUFFERED_IMAGE_FACTORY,
- // new RgbBufferedImageFactory());
- BufferedImage image = Sanselan.getBufferedImage(lastFile,
- readParams);
- assertNotNull(image);
+ File files[] = imagesFolder.listFiles();
+ for (int i = 0; i < files.length; i++)
+ {
+ File imageFile = files[i];
+ if(!imageFile.isFile() )
+ continue;
+ if(!imageFile.getName().toLowerCase().endsWith(".png"))
+ continue;
- File tempFile = createTempFile(imageFile.getName() + "." + j
- + ".", ".png");
- Debug.debug("tempFile", tempFile);
+ Debug.debug();
+ Debug.debug("imageFile", imageFile);
- Map writeParams = new HashMap();
- Sanselan.writeImage(image, tempFile,
- ImageFormat.IMAGE_FORMAT_PNG, writeParams);
+ File lastFile = imageFile;
+ for (int j = 0; j < 10; j++)
+ {
+ Map readParams = new HashMap();
+ // readParams.put(SanselanConstants.BUFFERED_IMAGE_FACTORY,
+ // new RgbBufferedImageFactory());
+ BufferedImage image = Sanselan.getBufferedImage(lastFile,
+ readParams);
+ assertNotNull(image);
- lastFile = tempFile;
- }
- }
- }
+ File tempFile = createTempFile(imageFile.getName() + "." + j
+ + ".", ".png");
+ Debug.debug("tempFile", tempFile);
+
+ Map writeParams = new HashMap();
+ Sanselan.writeImage(image, tempFile,
+ ImageFormat.IMAGE_FORMAT_PNG, writeParams);
+
+ lastFile = tempFile;
+ }
+ }
+ }
}
diff --git a/src/test/java/org/apache/sanselan/formats/png/PngReadTest.java b/src/test/java/org/apache/sanselan/formats/png/PngReadTest.java
index 8050438..e6ad5e8 100644
--- a/src/test/java/org/apache/sanselan/formats/png/PngReadTest.java
+++ b/src/test/java/org/apache/sanselan/formats/png/PngReadTest.java
@@ -33,55 +33,55 @@
- public void test() throws IOException, ImageReadException
- {
- Debug.debug("start");
+ public void test() throws IOException, ImageReadException
+ {
+ Debug.debug("start");
- List images = getPngImages();
- for (int i = 0; i < images.size(); i++)
- {
- if (i % 10 == 0)
- Debug.purgeMemory();
+ List images = getPngImages();
+ for (int i = 0; i < images.size(); i++)
+ {
+ if (i % 10 == 0)
+ Debug.purgeMemory();
- File imageFile = (File) images.get(i);
- Debug.debug("imageFile", imageFile);
- if (isInvalidPNGTestFile(imageFile))
- {
- try
- {
- Sanselan.getMetadata(imageFile);
- fail("Image read should have failed.");
- } catch (Exception e)
- {
- }
+ File imageFile = (File) images.get(i);
+ Debug.debug("imageFile", imageFile);
+ if (isInvalidPNGTestFile(imageFile))
+ {
+ try
+ {
+ Sanselan.getMetadata(imageFile);
+ fail("Image read should have failed.");
+ } catch (Exception e)
+ {
+ }
- try
- {
- Sanselan.getImageInfo(imageFile);
- fail("Image read should have failed.");
- } catch (Exception e)
- {
- }
+ try
+ {
+ Sanselan.getImageInfo(imageFile);
+ fail("Image read should have failed.");
+ } catch (Exception e)
+ {
+ }
- try
- {
- Sanselan.getBufferedImage(imageFile);
- fail("Image read should have failed.");
- } catch (Exception e)
- {
- }
- } else
- {
- IImageMetadata metadata = Sanselan.getMetadata(imageFile);
- // assertNotNull(metadata);
+ try
+ {
+ Sanselan.getBufferedImage(imageFile);
+ fail("Image read should have failed.");
+ } catch (Exception e)
+ {
+ }
+ } else
+ {
+ IImageMetadata metadata = Sanselan.getMetadata(imageFile);
+ // assertNotNull(metadata);
- ImageInfo imageInfo = Sanselan.getImageInfo(imageFile);
- assertNotNull(imageInfo);
+ ImageInfo imageInfo = Sanselan.getImageInfo(imageFile);
+ assertNotNull(imageInfo);
- BufferedImage image = Sanselan.getBufferedImage(imageFile);
- assertNotNull(image);
- }
- }
- }
+ BufferedImage image = Sanselan.getBufferedImage(imageFile);
+ assertNotNull(image);
+ }
+ }
+ }
}
diff --git a/src/test/java/org/apache/sanselan/formats/png/PngTextTest.java b/src/test/java/org/apache/sanselan/formats/png/PngTextTest.java
index a440ceb..e56eea9 100644
--- a/src/test/java/org/apache/sanselan/formats/png/PngTextTest.java
+++ b/src/test/java/org/apache/sanselan/formats/png/PngTextTest.java
@@ -35,62 +35,62 @@
public class PngTextTest extends PngBaseTest
{
- public void test() throws IOException, ImageReadException,
- ImageWriteException
- {
- int width = 1;
- int height = 1;
- BufferedImage srcImage = new BufferedImage(width, height,
- BufferedImage.TYPE_INT_ARGB);
- srcImage.setRGB(0, 0, Color.red.getRGB());
+ public void test() throws IOException, ImageReadException,
+ ImageWriteException
+ {
+ int width = 1;
+ int height = 1;
+ BufferedImage srcImage = new BufferedImage(width, height,
+ BufferedImage.TYPE_INT_ARGB);
+ srcImage.setRGB(0, 0, Color.red.getRGB());
- Map writeParams = new HashMap();
+ Map writeParams = new HashMap();
- List writeTexts = new ArrayList();
- {
- String keyword = "a";
- String text = "b";
- writeTexts.add(new PngText.tEXt(keyword, text));
- }
- {
- String keyword = "c";
- String text = "d";
- writeTexts.add(new PngText.zTXt(keyword, text));
- }
- {
- String keyword = "e";
- String text = "f";
- String languageTag = "g";
- String translatedKeyword = "h";
- writeTexts.add(new PngText.iTXt(keyword, text, languageTag,
- translatedKeyword));
- }
+ List writeTexts = new ArrayList();
+ {
+ String keyword = "a";
+ String text = "b";
+ writeTexts.add(new PngText.tEXt(keyword, text));
+ }
+ {
+ String keyword = "c";
+ String text = "d";
+ writeTexts.add(new PngText.zTXt(keyword, text));
+ }
+ {
+ String keyword = "e";
+ String text = "f";
+ String languageTag = "g";
+ String translatedKeyword = "h";
+ writeTexts.add(new PngText.iTXt(keyword, text, languageTag,
+ translatedKeyword));
+ }
- writeParams.put(PngConstants.PARAM_KEY_PNG_TEXT_CHUNKS, writeTexts);
+ writeParams.put(PngConstants.PARAM_KEY_PNG_TEXT_CHUNKS, writeTexts);
- byte bytes[] = Sanselan.writeImageToBytes(srcImage,
- ImageFormat.IMAGE_FORMAT_PNG, writeParams);
+ byte bytes[] = Sanselan.writeImageToBytes(srcImage,
+ ImageFormat.IMAGE_FORMAT_PNG, writeParams);
- File tempFile = createTempFile("temp", ".png");
- IOUtils.writeToFile(bytes, tempFile);
+ File tempFile = createTempFile("temp", ".png");
+ IOUtils.writeToFile(bytes, tempFile);
- PngImageInfo imageInfo = (PngImageInfo) Sanselan.getImageInfo(bytes);
- assertNotNull(imageInfo);
+ PngImageInfo imageInfo = (PngImageInfo) Sanselan.getImageInfo(bytes);
+ assertNotNull(imageInfo);
- List readTexts = imageInfo.getTextChunks();
- assertEquals(readTexts.size(), 3);
- for (int i = 0; i < readTexts.size(); i++)
- {
- PngText text = (PngText) readTexts.get(i);
- if (text.keyword.equals("a"))
- assertEquals(text.text, "b");
- else if (text.keyword.equals("c"))
- assertEquals(text.text, "d");
- else if (text.keyword.equals("e"))
- assertEquals(text.text, "f");
- else
- fail("unknown text chunk.");
- }
- }
+ List readTexts = imageInfo.getTextChunks();
+ assertEquals(readTexts.size(), 3);
+ for (int i = 0; i < readTexts.size(); i++)
+ {
+ PngText text = (PngText) readTexts.get(i);
+ if (text.keyword.equals("a"))
+ assertEquals(text.text, "b");
+ else if (text.keyword.equals("c"))
+ assertEquals(text.text, "d");
+ else if (text.keyword.equals("e"))
+ assertEquals(text.text, "f");
+ else
+ fail("unknown text chunk.");
+ }
+ }
}
diff --git a/src/test/java/org/apache/sanselan/formats/png/PngWriteForceTrueColorText.java b/src/test/java/org/apache/sanselan/formats/png/PngWriteForceTrueColorText.java
index 9dc10a4..a52836c 100644
--- a/src/test/java/org/apache/sanselan/formats/png/PngWriteForceTrueColorText.java
+++ b/src/test/java/org/apache/sanselan/formats/png/PngWriteForceTrueColorText.java
@@ -29,45 +29,45 @@
public class PngWriteForceTrueColorText extends PngBaseTest {
- public void test() throws Exception {
+ public void test() throws Exception {
- List images = getPngImages();
- for (int i = 0; i < images.size(); i++) {
- if (i % 10 == 0)
- Debug.purgeMemory();
+ List images = getPngImages();
+ for (int i = 0; i < images.size(); i++) {
+ if (i % 10 == 0)
+ Debug.purgeMemory();
- File imageFile = (File) images.get(i);
- try {
- if (isInvalidPNGTestFile(imageFile))
- continue;
+ File imageFile = (File) images.get(i);
+ try {
+ if (isInvalidPNGTestFile(imageFile))
+ continue;
- Debug.debug("imageFile", imageFile);
- // Debug.debug();
+ Debug.debug("imageFile", imageFile);
+ // Debug.debug();
- // params.put(SanselanConstants.PARAM_KEY_VERBOSE,
- // Boolean.TRUE);
+ // params.put(SanselanConstants.PARAM_KEY_VERBOSE,
+ // Boolean.TRUE);
- BufferedImage image = Sanselan.getBufferedImage(imageFile,
- new HashMap());
- assertNotNull(image);
+ BufferedImage image = Sanselan.getBufferedImage(imageFile,
+ new HashMap());
+ assertNotNull(image);
- File outFile = createTempFile(imageFile.getName() + ".", ".gif");
- // Debug.debug("outFile", outFile);
+ File outFile = createTempFile(imageFile.getName() + ".", ".gif");
+ // Debug.debug("outFile", outFile);
- Map params = new HashMap();
- params.put(PngConstants.PARAM_KEY_PNG_FORCE_TRUE_COLOR,
- Boolean.TRUE);
- Sanselan.writeImage(image, outFile,
- ImageFormat.IMAGE_FORMAT_PNG, params);
+ Map params = new HashMap();
+ params.put(PngConstants.PARAM_KEY_PNG_FORCE_TRUE_COLOR,
+ Boolean.TRUE);
+ Sanselan.writeImage(image, outFile,
+ ImageFormat.IMAGE_FORMAT_PNG, params);
- BufferedImage image2 = Sanselan.getBufferedImage(outFile,
- new HashMap());
- } catch (Exception e) {
- Debug.debug("imageFile", imageFile);
- throw e;
- }
- }
- Debug.debug("complete.");
- }
+ BufferedImage image2 = Sanselan.getBufferedImage(outFile,
+ new HashMap());
+ } catch (Exception e) {
+ Debug.debug("imageFile", imageFile);
+ throw e;
+ }
+ }
+ Debug.debug("complete.");
+ }
}
diff --git a/src/test/java/org/apache/sanselan/formats/png/PngWriteReadTest.java b/src/test/java/org/apache/sanselan/formats/png/PngWriteReadTest.java
index bcabca9..263a900 100644
--- a/src/test/java/org/apache/sanselan/formats/png/PngWriteReadTest.java
+++ b/src/test/java/org/apache/sanselan/formats/png/PngWriteReadTest.java
@@ -33,143 +33,143 @@
public class PngWriteReadTest extends SanselanTest
{
- // public PngWriteReadTest(String name)
- // {
- // super(name);
- // }
+ // public PngWriteReadTest(String name)
+ // {
+ // super(name);
+ // }
- private int[][] getSimpleRawData(int width, int height, int value)
- {
- int[][] result = new int[height][width];
- for (int y = 0; y < height; y++)
- for (int x = 0; x < width; x++)
- result[y][x] = value;
- return result;
- }
+ private int[][] getSimpleRawData(int width, int height, int value)
+ {
+ int[][] result = new int[height][width];
+ for (int y = 0; y < height; y++)
+ for (int x = 0; x < width; x++)
+ result[y][x] = value;
+ return result;
+ }
- private int[][] getAscendingRawData(int width, int height)
- {
- int[][] result = new int[height][width];
- for (int y = 0; y < height; y++)
- for (int x = 0; x < width; x++)
- {
- int alpha = (x + y) % 256;
- int value = (x + y) % 256;
- int argb = (0xff & alpha) << 24 | (0xff & value) << 16
- | (0xff & value) << 8 | (0xff & value) << 0;
+ private int[][] getAscendingRawData(int width, int height)
+ {
+ int[][] result = new int[height][width];
+ for (int y = 0; y < height; y++)
+ for (int x = 0; x < width; x++)
+ {
+ int alpha = (x + y) % 256;
+ int value = (x + y) % 256;
+ int argb = (0xff & alpha) << 24 | (0xff & value) << 16
+ | (0xff & value) << 8 | (0xff & value) << 0;
- result[y][x] = argb;
- }
- return result;
- }
+ result[y][x] = argb;
+ }
+ return result;
+ }
- private int[][] randomRawData(int width, int height)
- {
- Random random = new Random();
- int[][] result = new int[height][width];
- for (int y = 0; y < height; y++)
- for (int x = 0; x < width; x++)
- {
- int argb = random.nextInt();
- result[y][x] = argb;
- }
- return result;
- }
+ private int[][] randomRawData(int width, int height)
+ {
+ Random random = new Random();
+ int[][] result = new int[height][width];
+ for (int y = 0; y < height; y++)
+ for (int x = 0; x < width; x++)
+ {
+ int argb = random.nextInt();
+ result[y][x] = argb;
+ }
+ return result;
+ }
- public void test() throws IOException, ImageReadException,
- ImageWriteException
- {
- int[][] smallBlackPixels = getSimpleRawData(256, 256, 0);
- int[][] singleBlackPixel = getSimpleRawData(1, 1, 0);
- int[][] smallRedPixels = getSimpleRawData(256, 256, 0xffff0000);
- int[][] singleRedPixel = getSimpleRawData(1, 1, 0xffff0000);
- int[][] smallAscendingPixels = getAscendingRawData(256, 256);
- int[][] smallRandomPixels = randomRawData(256, 256);
+ public void test() throws IOException, ImageReadException,
+ ImageWriteException
+ {
+ int[][] smallBlackPixels = getSimpleRawData(256, 256, 0);
+ int[][] singleBlackPixel = getSimpleRawData(1, 1, 0);
+ int[][] smallRedPixels = getSimpleRawData(256, 256, 0xffff0000);
+ int[][] singleRedPixel = getSimpleRawData(1, 1, 0xffff0000);
+ int[][] smallAscendingPixels = getAscendingRawData(256, 256);
+ int[][] smallRandomPixels = randomRawData(256, 256);
- int[][][] testData = {
- smallBlackPixels, singleBlackPixel, smallRedPixels,
- singleRedPixel, smallAscendingPixels, smallRandomPixels,
- };
+ int[][][] testData = {
+ smallBlackPixels, singleBlackPixel, smallRedPixels,
+ singleRedPixel, smallAscendingPixels, smallRandomPixels,
+ };
- for (int i = 0; i < testData.length; i++)
- {
- int rawData[][] = testData[i];
- writeAndReadImageData(rawData);
- }
- }
+ for (int i = 0; i < testData.length; i++)
+ {
+ int rawData[][] = testData[i];
+ writeAndReadImageData(rawData);
+ }
+ }
- private BufferedImage imageDataToBufferedImage(int[][] rawData)
- {
- int width = rawData[0].length;
- int height = rawData.length;
- BufferedImage image = new BufferedImage(width, height,
- BufferedImage.TYPE_INT_ARGB);
- for (int y = 0; y < height; y++)
- for (int x = 0; x < width; x++)
- {
- image.setRGB(x, y, rawData[y][x]);
- }
- return image;
- }
+ private BufferedImage imageDataToBufferedImage(int[][] rawData)
+ {
+ int width = rawData[0].length;
+ int height = rawData.length;
+ BufferedImage image = new BufferedImage(width, height,
+ BufferedImage.TYPE_INT_ARGB);
+ for (int y = 0; y < height; y++)
+ for (int x = 0; x < width; x++)
+ {
+ image.setRGB(x, y, rawData[y][x]);
+ }
+ return image;
+ }
- private int[][] bufferedImageToImageData(BufferedImage image)
- {
- int width = image.getWidth();
- int height = image.getHeight();
- int[][] result = new int[height][width];
+ private int[][] bufferedImageToImageData(BufferedImage image)
+ {
+ int width = image.getWidth();
+ int height = image.getHeight();
+ int[][] result = new int[height][width];
- for (int y = 0; y < height; y++)
- for (int x = 0; x < width; x++)
- {
- result[y][x] = image.getRGB(x, y);
- }
- return result;
- }
+ for (int y = 0; y < height; y++)
+ for (int x = 0; x < width; x++)
+ {
+ result[y][x] = image.getRGB(x, y);
+ }
+ return result;
+ }
- private void writeAndReadImageData(int[][] rawData) throws IOException,
- ImageReadException, ImageWriteException
- {
- BufferedImage srcImage = imageDataToBufferedImage(rawData);
+ private void writeAndReadImageData(int[][] rawData) throws IOException,
+ ImageReadException, ImageWriteException
+ {
+ BufferedImage srcImage = imageDataToBufferedImage(rawData);
- Map writeParams = new HashMap();
- // writeParams.put(SanselanConstants.PARAM_KEY_FORMAT, ImageFormat.IMAGE_FORMAT_PNG);
- // writeParams.put(PngConstants.PARAM_KEY_PNG_FORCE_TRUE_COLOR,
- // Boolean.TRUE);
+ Map writeParams = new HashMap();
+ // writeParams.put(SanselanConstants.PARAM_KEY_FORMAT, ImageFormat.IMAGE_FORMAT_PNG);
+ // writeParams.put(PngConstants.PARAM_KEY_PNG_FORCE_TRUE_COLOR,
+ // Boolean.TRUE);
- byte bytes[] = Sanselan.writeImageToBytes(srcImage,
- ImageFormat.IMAGE_FORMAT_PNG, writeParams);
+ byte bytes[] = Sanselan.writeImageToBytes(srcImage,
+ ImageFormat.IMAGE_FORMAT_PNG, writeParams);
- // Debug.debug("bytes", bytes);
+ // Debug.debug("bytes", bytes);
- File tempFile = createTempFile("temp", ".png");
- IOUtils.writeToFile(bytes, tempFile);
+ File tempFile = createTempFile("temp", ".png");
+ IOUtils.writeToFile(bytes, tempFile);
- BufferedImage dstImage = Sanselan.getBufferedImage(bytes);
+ BufferedImage dstImage = Sanselan.getBufferedImage(bytes);
- assertNotNull(dstImage);
- assertTrue(srcImage.getWidth() == dstImage.getWidth());
- assertTrue(srcImage.getHeight() == dstImage.getHeight());
+ assertNotNull(dstImage);
+ assertTrue(srcImage.getWidth() == dstImage.getWidth());
+ assertTrue(srcImage.getHeight() == dstImage.getHeight());
- int dstData[][] = bufferedImageToImageData(dstImage);
- compare(rawData, dstData);
- }
+ int dstData[][] = bufferedImageToImageData(dstImage);
+ compare(rawData, dstData);
+ }
- private void compare(int[][] a, int[][] b)
- {
- assertNotNull(a);
- assertNotNull(b);
- assertTrue(a.length == b.length);
+ private void compare(int[][] a, int[][] b)
+ {
+ assertNotNull(a);
+ assertNotNull(b);
+ assertTrue(a.length == b.length);
- for (int y = 0; y < a.length; y++)
- {
- assertTrue(a[y].length == b[y].length);
- // make sure row lengths consistent.
- assertTrue(a[0].length == b[y].length);
- for (int x = 0; x < a[y].length; x++)
- {
- assertTrue(a[y][x] == b[y][x]);
- }
- }
- }
+ for (int y = 0; y < a.length; y++)
+ {
+ assertTrue(a[y].length == b[y].length);
+ // make sure row lengths consistent.
+ assertTrue(a[0].length == b[y].length);
+ for (int x = 0; x < a[y].length; x++)
+ {
+ assertTrue(a[y][x] == b[y][x]);
+ }
+ }
+ }
}
diff --git a/src/test/java/org/apache/sanselan/formats/tiff/TiffBaseTest.java b/src/test/java/org/apache/sanselan/formats/tiff/TiffBaseTest.java
index 9f26cc0..c14c5cf 100644
--- a/src/test/java/org/apache/sanselan/formats/tiff/TiffBaseTest.java
+++ b/src/test/java/org/apache/sanselan/formats/tiff/TiffBaseTest.java
@@ -29,23 +29,23 @@
public abstract class TiffBaseTest extends SanselanTest
{
- private static boolean isTiff(File file) throws IOException,
- ImageReadException
- {
- ImageFormat format = Sanselan.guessFormat(file);
- return format == ImageFormat.IMAGE_FORMAT_TIFF;
- }
+ private static boolean isTiff(File file) throws IOException,
+ ImageReadException
+ {
+ ImageFormat format = Sanselan.guessFormat(file);
+ return format == ImageFormat.IMAGE_FORMAT_TIFF;
+ }
- private static final ImageFilter imageFilter = new ImageFilter() {
- public boolean accept(File file) throws IOException, ImageReadException
- {
- return isTiff(file);
- }
- };
+ private static final ImageFilter imageFilter = new ImageFilter() {
+ public boolean accept(File file) throws IOException, ImageReadException
+ {
+ return isTiff(file);
+ }
+ };
- protected List getTiffImages() throws IOException, ImageReadException
- {
- return getTestImages(imageFilter);
- }
+ protected List getTiffImages() throws IOException, ImageReadException
+ {
+ return getTestImages(imageFilter);
+ }
}
diff --git a/src/test/java/org/apache/sanselan/formats/tiff/TiffLZWTest.java b/src/test/java/org/apache/sanselan/formats/tiff/TiffLZWTest.java
index e71b968..c7243ca 100644
--- a/src/test/java/org/apache/sanselan/formats/tiff/TiffLZWTest.java
+++ b/src/test/java/org/apache/sanselan/formats/tiff/TiffLZWTest.java
@@ -31,250 +31,250 @@
public class TiffLZWTest extends TiffBaseTest implements BinaryConstants
{
- public void testTrivial() throws IOException
- {
- byte bytes[] = { 0, };
- compressRoundtripAndValidate(bytes);
- }
+ public void testTrivial() throws IOException
+ {
+ byte bytes[] = { 0, };
+ compressRoundtripAndValidate(bytes);
+ }
- public void testMedium() throws IOException
- {
- int LENGTH = 1024 * 32;
- byte bytes[] = new byte[LENGTH];
- for (int modulator = 1; modulator < 255; modulator += 3)
- {
- for (int i = 0; i < LENGTH; i++)
- bytes[i] = (byte) (0xff & (i % modulator));
+ public void testMedium() throws IOException
+ {
+ int LENGTH = 1024 * 32;
+ byte bytes[] = new byte[LENGTH];
+ for (int modulator = 1; modulator < 255; modulator += 3)
+ {
+ for (int i = 0; i < LENGTH; i++)
+ bytes[i] = (byte) (0xff & (i % modulator));
- compressRoundtripAndValidate(bytes);
- }
- }
+ compressRoundtripAndValidate(bytes);
+ }
+ }
-// public void testTiffImageData() throws IOException, ImageReadException,
-// ImageWriteException
-// {
-// List images = getTiffImages();
-// for (int i = 0; i < images.size(); i++)
-// {
-// if (i % 10 == 0)
-// Debug.purgeMemory();
+// public void testTiffImageData() throws IOException, ImageReadException,
+// ImageWriteException
+// {
+// List images = getTiffImages();
+// for (int i = 0; i < images.size(); i++)
+// {
+// if (i % 10 == 0)
+// Debug.purgeMemory();
//
-// File imageFile = (File) images.get(i);
-// Debug.debug("imageFile", imageFile);
+// File imageFile = (File) images.get(i);
+// Debug.debug("imageFile", imageFile);
//
-// ByteSource byteSource = new ByteSourceFile(imageFile);
-// Map params = new HashMap();
-// List data = new TiffImageParser().collectRawImageData(byteSource,
-// params);
+// ByteSource byteSource = new ByteSourceFile(imageFile);
+// Map params = new HashMap();
+// List data = new TiffImageParser().collectRawImageData(byteSource,
+// params);
//
-// for (int j = 0; j < data.size(); j++)
-// {
-// byte bytes[] = (byte[]) data.get(j);
-// decompressRoundtripAndValidate(bytes);
-// }
-// }
-// }
+// for (int j = 0; j < data.size(); j++)
+// {
+// byte bytes[] = (byte[]) data.get(j);
+// decompressRoundtripAndValidate(bytes);
+// }
+// }
+// }
- private void compressRoundtripAndValidate(byte src[]) throws IOException
- {
- final boolean DEBUG = false;
+ private void compressRoundtripAndValidate(byte src[]) throws IOException
+ {
+ final boolean DEBUG = false;
- if (DEBUG)
- {
- Debug.debug();
- Debug.debug("roundtripAndValidate: " + src.length);
- Debug.debug();
- }
+ if (DEBUG)
+ {
+ Debug.debug();
+ Debug.debug("roundtripAndValidate: " + src.length);
+ Debug.debug();
+ }
- int LZW_MINIMUM_CODE_SIZE = 8;
- final List codes = new ArrayList();
- MyLZWCompressor.Listener compressionListener = new MyLZWCompressor.Listener() {
- public void dataCode(int code)
- {
- codes.add(new Integer(code));
- }
+ int LZW_MINIMUM_CODE_SIZE = 8;
+ final List codes = new ArrayList();
+ MyLZWCompressor.Listener compressionListener = new MyLZWCompressor.Listener() {
+ public void dataCode(int code)
+ {
+ codes.add(new Integer(code));
+ }
- public void eoiCode(int code)
- {
- codes.add(new Integer(code));
- }
+ public void eoiCode(int code)
+ {
+ codes.add(new Integer(code));
+ }
- public void clearCode(int code)
- {
- codes.add(new Integer(code));
- }
+ public void clearCode(int code)
+ {
+ codes.add(new Integer(code));
+ }
- public void init(int clearCode, int eoiCode)
- {
- }
- };
+ public void init(int clearCode, int eoiCode)
+ {
+ }
+ };
- MyLZWCompressor compressor = new MyLZWCompressor(LZW_MINIMUM_CODE_SIZE,
- BYTE_ORDER_MSB, true, compressionListener);
- byte compressed[] = compressor.compress(src);
+ MyLZWCompressor compressor = new MyLZWCompressor(LZW_MINIMUM_CODE_SIZE,
+ BYTE_ORDER_MSB, true, compressionListener);
+ byte compressed[] = compressor.compress(src);
- MyLZWDecompressor.Listener decompressionListener = new MyLZWDecompressor.Listener() {
+ MyLZWDecompressor.Listener decompressionListener = new MyLZWDecompressor.Listener() {
- int index = 0;
- int clearCode, eoiCode;
+ int index = 0;
+ int clearCode, eoiCode;
- public void code(int code)
- {
- if (DEBUG)
- {
- if (code == clearCode)
- {
- Debug.debug("clearCode: " + index + "/" + codes.size());
- Debug.debug();
- }
- if (code == eoiCode)
- {
- Debug.debug("eoiCode: " + index + "/" + codes.size());
- Debug.debug();
- }
- }
- Integer expectedCode = (Integer) codes.get(index++);
- if (code != expectedCode.intValue())
- {
- Debug.debug("bad code: " + index + "/" + codes.size());
- Debug.debug("code: " + code + " (0x"
- + Integer.toHexString(code) + ") "
- + Integer.toBinaryString(code));
- Debug.debug("expected: " + expectedCode + " (0x"
- + Integer.toHexString(expectedCode.intValue())
- + ") "
- + Integer.toBinaryString(expectedCode.intValue()));
- Debug.debug("clearCode: " + clearCode + " (0x"
- + Integer.toHexString(clearCode) + ") "
- + Integer.toBinaryString(clearCode));
- Debug.debug("eoiCode: " + eoiCode + " (0x"
- + Integer.toHexString(eoiCode) + ") "
- + Integer.toBinaryString(eoiCode));
- Debug.debug();
- }
- }
+ public void code(int code)
+ {
+ if (DEBUG)
+ {
+ if (code == clearCode)
+ {
+ Debug.debug("clearCode: " + index + "/" + codes.size());
+ Debug.debug();
+ }
+ if (code == eoiCode)
+ {
+ Debug.debug("eoiCode: " + index + "/" + codes.size());
+ Debug.debug();
+ }
+ }
+ Integer expectedCode = (Integer) codes.get(index++);
+ if (code != expectedCode.intValue())
+ {
+ Debug.debug("bad code: " + index + "/" + codes.size());
+ Debug.debug("code: " + code + " (0x"
+ + Integer.toHexString(code) + ") "
+ + Integer.toBinaryString(code));
+ Debug.debug("expected: " + expectedCode + " (0x"
+ + Integer.toHexString(expectedCode.intValue())
+ + ") "
+ + Integer.toBinaryString(expectedCode.intValue()));
+ Debug.debug("clearCode: " + clearCode + " (0x"
+ + Integer.toHexString(clearCode) + ") "
+ + Integer.toBinaryString(clearCode));
+ Debug.debug("eoiCode: " + eoiCode + " (0x"
+ + Integer.toHexString(eoiCode) + ") "
+ + Integer.toBinaryString(eoiCode));
+ Debug.debug();
+ }
+ }
- public void init(int clearCode, int eoiCode)
- {
- this.clearCode = clearCode;
- this.eoiCode = eoiCode;
- }
+ public void init(int clearCode, int eoiCode)
+ {
+ this.clearCode = clearCode;
+ this.eoiCode = eoiCode;
+ }
- };
- InputStream is = new ByteArrayInputStream(compressed);
- MyLZWDecompressor decompressor = new MyLZWDecompressor(
- LZW_MINIMUM_CODE_SIZE, BYTE_ORDER_NETWORK,
- decompressionListener);
- decompressor.setTiffLZWMode();
- byte decompressed[] = decompressor.decompress(is, src.length);
+ };
+ InputStream is = new ByteArrayInputStream(compressed);
+ MyLZWDecompressor decompressor = new MyLZWDecompressor(
+ LZW_MINIMUM_CODE_SIZE, BYTE_ORDER_NETWORK,
+ decompressionListener);
+ decompressor.setTiffLZWMode();
+ byte decompressed[] = decompressor.decompress(is, src.length);
- assertEquals(src.length, decompressed.length);
- for (int i = 0; i < src.length; i++)
- assertEquals(src[i], decompressed[i]);
- }
+ assertEquals(src.length, decompressed.length);
+ for (int i = 0; i < src.length; i++)
+ assertEquals(src[i], decompressed[i]);
+ }
- private void decompressRoundtripAndValidate(byte src[]) throws IOException
- {
- Debug.debug();
- Debug.debug("roundtripAndValidate: " + src.length);
- Debug.debug();
+ private void decompressRoundtripAndValidate(byte src[]) throws IOException
+ {
+ Debug.debug();
+ Debug.debug("roundtripAndValidate: " + src.length);
+ Debug.debug();
- int LZW_MINIMUM_CODE_SIZE = 8;
- final List codes = new ArrayList();
+ int LZW_MINIMUM_CODE_SIZE = 8;
+ final List codes = new ArrayList();
- MyLZWDecompressor.Listener decompressionListener = new MyLZWDecompressor.Listener() {
+ MyLZWDecompressor.Listener decompressionListener = new MyLZWDecompressor.Listener() {
- public void code(int code)
- {
- Debug.debug("listener code: " + code + " (0x"
- + Integer.toHexString(code) + ") "
- + Integer.toBinaryString(code) + ", index: "
- + codes.size());
- codes.add(new Integer(code));
- }
+ public void code(int code)
+ {
+ Debug.debug("listener code: " + code + " (0x"
+ + Integer.toHexString(code) + ") "
+ + Integer.toBinaryString(code) + ", index: "
+ + codes.size());
+ codes.add(new Integer(code));
+ }
- public void init(int clearCode, int eoiCode)
- {
- }
+ public void init(int clearCode, int eoiCode)
+ {
+ }
- };
- InputStream is = new ByteArrayInputStream(src);
- MyLZWDecompressor decompressor = new MyLZWDecompressor(
- LZW_MINIMUM_CODE_SIZE, BYTE_ORDER_NETWORK,
- decompressionListener);
- decompressor.setTiffLZWMode();
- byte decompressed[] = decompressor.decompress(is, src.length);
+ };
+ InputStream is = new ByteArrayInputStream(src);
+ MyLZWDecompressor decompressor = new MyLZWDecompressor(
+ LZW_MINIMUM_CODE_SIZE, BYTE_ORDER_NETWORK,
+ decompressionListener);
+ decompressor.setTiffLZWMode();
+ byte decompressed[] = decompressor.decompress(is, src.length);
- MyLZWCompressor.Listener compressionListener = new MyLZWCompressor.Listener() {
+ MyLZWCompressor.Listener compressionListener = new MyLZWCompressor.Listener() {
- int clearCode, eoiCode;
+ int clearCode, eoiCode;
- public void init(int clearCode, int eoiCode)
- {
- this.clearCode = clearCode;
- this.eoiCode = eoiCode;
- }
+ public void init(int clearCode, int eoiCode)
+ {
+ this.clearCode = clearCode;
+ this.eoiCode = eoiCode;
+ }
- int index = 0;
+ int index = 0;
- private void code(int code)
- {
+ private void code(int code)
+ {
- if (code == clearCode)
- {
- Debug.debug("clearCode: " + index + "/" + codes.size());
- Debug.debug();
- }
- if (code == eoiCode)
- {
- Debug.debug("eoiCode: " + index + "/" + codes.size());
- Debug.debug();
- }
- Integer expectedCode = (Integer) codes.get(index++);
- if (code != expectedCode.intValue())
- {
- Debug.debug("bad code: " + index + "/" + codes.size());
- Debug.debug("code: " + code + " (0x"
- + Integer.toHexString(code) + ") "
- + Integer.toBinaryString(code));
- Debug.debug("expected: " + expectedCode + " (0x"
- + Integer.toHexString(expectedCode.intValue())
- + ") "
- + Integer.toBinaryString(expectedCode.intValue()));
- Debug.debug("clearCode: " + clearCode + " (0x"
- + Integer.toHexString(clearCode) + ") "
- + Integer.toBinaryString(clearCode));
- Debug.debug("eoiCode: " + eoiCode + " (0x"
- + Integer.toHexString(eoiCode) + ") "
- + Integer.toBinaryString(eoiCode));
- Debug.debug();
- }
- }
+ if (code == clearCode)
+ {
+ Debug.debug("clearCode: " + index + "/" + codes.size());
+ Debug.debug();
+ }
+ if (code == eoiCode)
+ {
+ Debug.debug("eoiCode: " + index + "/" + codes.size());
+ Debug.debug();
+ }
+ Integer expectedCode = (Integer) codes.get(index++);
+ if (code != expectedCode.intValue())
+ {
+ Debug.debug("bad code: " + index + "/" + codes.size());
+ Debug.debug("code: " + code + " (0x"
+ + Integer.toHexString(code) + ") "
+ + Integer.toBinaryString(code));
+ Debug.debug("expected: " + expectedCode + " (0x"
+ + Integer.toHexString(expectedCode.intValue())
+ + ") "
+ + Integer.toBinaryString(expectedCode.intValue()));
+ Debug.debug("clearCode: " + clearCode + " (0x"
+ + Integer.toHexString(clearCode) + ") "
+ + Integer.toBinaryString(clearCode));
+ Debug.debug("eoiCode: " + eoiCode + " (0x"
+ + Integer.toHexString(eoiCode) + ") "
+ + Integer.toBinaryString(eoiCode));
+ Debug.debug();
+ }
+ }
- public void dataCode(int code)
- {
- code(code);
- }
+ public void dataCode(int code)
+ {
+ code(code);
+ }
- public void eoiCode(int code)
- {
- code(code);
- }
+ public void eoiCode(int code)
+ {
+ code(code);
+ }
- public void clearCode(int code)
- {
- code(code);
- }
+ public void clearCode(int code)
+ {
+ code(code);
+ }
- };
+ };
- MyLZWCompressor compressor = new MyLZWCompressor(LZW_MINIMUM_CODE_SIZE,
- BYTE_ORDER_MSB, true, compressionListener);
- byte compressed[] = compressor.compress(decompressed);
+ MyLZWCompressor compressor = new MyLZWCompressor(LZW_MINIMUM_CODE_SIZE,
+ BYTE_ORDER_MSB, true, compressionListener);
+ byte compressed[] = compressor.compress(decompressed);
- assertEquals(src.length, compressed.length);
- for (int i = 0; i < src.length; i++)
- assertEquals(src[i], compressed[i]);
- }
+ assertEquals(src.length, compressed.length);
+ for (int i = 0; i < src.length; i++)
+ assertEquals(src[i], compressed[i]);
+ }
}
diff --git a/src/test/java/org/apache/sanselan/formats/tiff/TiffReadTest.java b/src/test/java/org/apache/sanselan/formats/tiff/TiffReadTest.java
index 0c2e281..e3eef36 100644
--- a/src/test/java/org/apache/sanselan/formats/tiff/TiffReadTest.java
+++ b/src/test/java/org/apache/sanselan/formats/tiff/TiffReadTest.java
@@ -31,26 +31,26 @@
public class TiffReadTest extends TiffBaseTest
{
- public void test() throws IOException, ImageReadException
- {
- List images = getTiffImages();
- for (int i = 0; i < images.size(); i++)
- {
- if (i % 10 == 0)
- Debug.purgeMemory();
+ public void test() throws IOException, ImageReadException
+ {
+ List images = getTiffImages();
+ for (int i = 0; i < images.size(); i++)
+ {
+ if (i % 10 == 0)
+ Debug.purgeMemory();
- File imageFile = (File) images.get(i);
- Debug.debug("imageFile", imageFile);
+ File imageFile = (File) images.get(i);
+ Debug.debug("imageFile", imageFile);
- IImageMetadata metadata = Sanselan.getMetadata(imageFile);
- assertNotNull(metadata);
+ IImageMetadata metadata = Sanselan.getMetadata(imageFile);
+ assertNotNull(metadata);
- ImageInfo imageInfo = Sanselan.getImageInfo(imageFile);
- assertNotNull(imageInfo);
+ ImageInfo imageInfo = Sanselan.getImageInfo(imageFile);
+ assertNotNull(imageInfo);
- BufferedImage image = Sanselan.getBufferedImage(imageFile);
- assertNotNull(image);
- }
- }
+ BufferedImage image = Sanselan.getBufferedImage(imageFile);
+ assertNotNull(image);
+ }
+ }
}
diff --git a/src/test/java/org/apache/sanselan/formats/tiff/TiffRoundtripTest.java b/src/test/java/org/apache/sanselan/formats/tiff/TiffRoundtripTest.java
index 35e94cc..3ce5ec5 100644
--- a/src/test/java/org/apache/sanselan/formats/tiff/TiffRoundtripTest.java
+++ b/src/test/java/org/apache/sanselan/formats/tiff/TiffRoundtripTest.java
@@ -34,34 +34,34 @@
public class TiffRoundtripTest extends TiffBaseTest {
- public void test() throws IOException, ImageReadException,
- ImageWriteException {
- List images = getTiffImages();
- for (int i = 0; i < images.size(); i++) {
- if (i % 10 == 0)
- Debug.purgeMemory();
+ public void test() throws IOException, ImageReadException,
+ ImageWriteException {
+ List images = getTiffImages();
+ for (int i = 0; i < images.size(); i++) {
+ if (i % 10 == 0)
+ Debug.purgeMemory();
- File imageFile = (File) images.get(i);
- Debug.debug("imageFile", imageFile);
+ File imageFile = (File) images.get(i);
+ Debug.debug("imageFile", imageFile);
- IImageMetadata metadata = Sanselan.getMetadata(imageFile);
- assertNotNull(metadata);
+ IImageMetadata metadata = Sanselan.getMetadata(imageFile);
+ assertNotNull(metadata);
- ImageInfo imageInfo = Sanselan.getImageInfo(imageFile);
- assertNotNull(imageInfo);
+ ImageInfo imageInfo = Sanselan.getImageInfo(imageFile);
+ assertNotNull(imageInfo);
- BufferedImage image = Sanselan.getBufferedImage(imageFile);
- assertNotNull(image);
+ BufferedImage image = Sanselan.getBufferedImage(imageFile);
+ assertNotNull(image);
- File tempFile = createTempFile(imageFile.getName() + ".", ".tif");
- Map params = new HashMap();
- Sanselan.writeImage(image, tempFile, ImageFormat.IMAGE_FORMAT_TIFF,
- params);
- image = null;
+ File tempFile = createTempFile(imageFile.getName() + ".", ".tif");
+ Map params = new HashMap();
+ Sanselan.writeImage(image, tempFile, ImageFormat.IMAGE_FORMAT_TIFF,
+ params);
+ image = null;
- BufferedImage image2 = Sanselan.getBufferedImage(tempFile);
- assertNotNull(image2);
- }
- }
+ BufferedImage image2 = Sanselan.getBufferedImage(tempFile);
+ assertNotNull(image2);
+ }
+ }
}
diff --git a/src/test/java/org/apache/sanselan/formats/xmp/XmpDumpTest.java b/src/test/java/org/apache/sanselan/formats/xmp/XmpDumpTest.java
index 878fbd4..57c04e6 100644
--- a/src/test/java/org/apache/sanselan/formats/xmp/XmpDumpTest.java
+++ b/src/test/java/org/apache/sanselan/formats/xmp/XmpDumpTest.java
@@ -29,32 +29,32 @@
public class XmpDumpTest extends SanselanTest
{
- public void test() throws IOException, ImageReadException
- {
- List images = getTestImages();
- for (int i = 0; i < images.size(); i++)
- {
- if (i % 10 == 0)
- Debug.purgeMemory();
+ public void test() throws IOException, ImageReadException
+ {
+ List images = getTestImages();
+ for (int i = 0; i < images.size(); i++)
+ {
+ if (i % 10 == 0)
+ Debug.purgeMemory();
- File imageFile = (File) images.get(i);
+ File imageFile = (File) images.get(i);
- if (imageFile.getName().toLowerCase().endsWith(".png")
- && isInvalidPNGTestFile(imageFile))
- continue;
+ if (imageFile.getName().toLowerCase().endsWith(".png")
+ && isInvalidPNGTestFile(imageFile))
+ continue;
- Debug.debug("imageFile", imageFile);
- Debug.debug();
+ Debug.debug("imageFile", imageFile);
+ Debug.debug();
- String xmpXml = Sanselan.getXmpXml(imageFile);
- if (null == xmpXml)
- continue;
+ String xmpXml = Sanselan.getXmpXml(imageFile);
+ if (null == xmpXml)
+ continue;
- assertNotNull(xmpXml);
+ assertNotNull(xmpXml);
- Debug.debug("xmpXml", xmpXml);
- Debug.debug();
- }
- }
+ Debug.debug("xmpXml", xmpXml);
+ Debug.debug();
+ }
+ }
}
diff --git a/src/test/java/org/apache/sanselan/formats/xmp/XmpUpdateTest.java b/src/test/java/org/apache/sanselan/formats/xmp/XmpUpdateTest.java
index 6031c16..1941b18 100644
--- a/src/test/java/org/apache/sanselan/formats/xmp/XmpUpdateTest.java
+++ b/src/test/java/org/apache/sanselan/formats/xmp/XmpUpdateTest.java
@@ -34,63 +34,63 @@
public class XmpUpdateTest extends SanselanTest
{
- public void test() throws IOException, ImageReadException,
- ImageWriteException
- {
- List images = getTestImages();
- for (int i = 0; i < images.size(); i++)
- {
- if (i % 10 == 0)
- Debug.purgeMemory();
+ public void test() throws IOException, ImageReadException,
+ ImageWriteException
+ {
+ List images = getTestImages();
+ for (int i = 0; i < images.size(); i++)
+ {
+ if (i % 10 == 0)
+ Debug.purgeMemory();
- File imageFile = (File) images.get(i);
+ File imageFile = (File) images.get(i);
- if (imageFile.getName().toLowerCase().endsWith(".png")
- && isInvalidPNGTestFile(imageFile))
- continue;
-
- Debug.debug("imageFile", imageFile);
- Debug.debug();
+ if (imageFile.getName().toLowerCase().endsWith(".png")
+ && isInvalidPNGTestFile(imageFile))
+ continue;
- ImageFormat imageFormat = Sanselan.guessFormat(imageFile);
+ Debug.debug("imageFile", imageFile);
+ Debug.debug();
- String xmpXml = Sanselan.getXmpXml(imageFile);
- if (null == xmpXml
- && imageFormat.equals(ImageFormat.IMAGE_FORMAT_GIF))
- xmpXml = "temporary test until I can locate a GIF with XMP in the wild.";
- if (null == xmpXml)
- continue;
+ ImageFormat imageFormat = Sanselan.guessFormat(imageFile);
- assertNotNull(xmpXml);
+ String xmpXml = Sanselan.getXmpXml(imageFile);
+ if (null == xmpXml
+ && imageFormat.equals(ImageFormat.IMAGE_FORMAT_GIF))
+ xmpXml = "temporary test until I can locate a GIF with XMP in the wild.";
+ if (null == xmpXml)
+ continue;
- if (imageFormat.equals(ImageFormat.IMAGE_FORMAT_PNG))
- ;
- else if (imageFormat.equals(ImageFormat.IMAGE_FORMAT_TIFF))
- ;
- else if (imageFormat.equals(ImageFormat.IMAGE_FORMAT_GIF))
- ;
- else
- continue;
+ assertNotNull(xmpXml);
- File tempFile = this.createTempFile(imageFile.getName() + ".", "."
- + imageFormat.extension);
- BufferedImage image = Sanselan.getBufferedImage(imageFile);
+ if (imageFormat.equals(ImageFormat.IMAGE_FORMAT_PNG))
+ ;
+ else if (imageFormat.equals(ImageFormat.IMAGE_FORMAT_TIFF))
+ ;
+ else if (imageFormat.equals(ImageFormat.IMAGE_FORMAT_GIF))
+ ;
+ else
+ continue;
- // ----
+ File tempFile = this.createTempFile(imageFile.getName() + ".", "."
+ + imageFormat.extension);
+ BufferedImage image = Sanselan.getBufferedImage(imageFile);
- Map params = new HashMap();
- params.put(PARAM_KEY_XMP_XML, xmpXml);
- Sanselan.writeImage(image, tempFile, imageFormat, params);
+ // ----
- String xmpXmlOut = Sanselan.getXmpXml(tempFile);
+ Map params = new HashMap();
+ params.put(PARAM_KEY_XMP_XML, xmpXml);
+ Sanselan.writeImage(image, tempFile, imageFormat, params);
- assertNotNull(xmpXmlOut);
+ String xmpXmlOut = Sanselan.getXmpXml(tempFile);
- assertEquals(xmpXmlOut, xmpXml);
+ assertNotNull(xmpXmlOut);
-// Debug.debug("xmpXmlOut", xmpXmlOut.length());
- // Debug.debug("xmpXml", xmpXml);
- // Debug.debug();
- }
- }
+ assertEquals(xmpXmlOut, xmpXml);
+
+// Debug.debug("xmpXmlOut", xmpXmlOut.length());
+ // Debug.debug("xmpXml", xmpXml);
+ // Debug.debug();
+ }
+ }
}
diff --git a/src/test/java/org/apache/sanselan/roundtrip/RoundtripTest.java b/src/test/java/org/apache/sanselan/roundtrip/RoundtripTest.java
index ecc9173..f36b3f4 100644
--- a/src/test/java/org/apache/sanselan/roundtrip/RoundtripTest.java
+++ b/src/test/java/org/apache/sanselan/roundtrip/RoundtripTest.java
@@ -35,410 +35,410 @@
public class RoundtripTest extends SanselanTest
{
- private static final int COLOR_FULL_RGB = 0;
- private static final int COLOR_LIMITED_INDEX = 1;
- private static final int COLOR_GRAYSCALE = 2;
- private static final int COLOR_BITMAP = 3;
+ private static final int COLOR_FULL_RGB = 0;
+ private static final int COLOR_LIMITED_INDEX = 1;
+ private static final int COLOR_GRAYSCALE = 2;
+ private static final int COLOR_BITMAP = 3;
- private static class FormatInfo
- {
+ private static class FormatInfo
+ {
- public final ImageFormat format;
- public final boolean canRead;
- public final boolean canWrite;
- public final int colorSupport;
- public final boolean identicalSecondWrite;
+ public final ImageFormat format;
+ public final boolean canRead;
+ public final boolean canWrite;
+ public final int colorSupport;
+ public final boolean identicalSecondWrite;
- public FormatInfo(ImageFormat format, boolean canRead,
- boolean canWrite, int colorSupport,
- final boolean identicalSecondWrite)
- {
- this.canRead = canRead;
- this.canWrite = canWrite;
- this.colorSupport = colorSupport;
- this.format = format;
- this.identicalSecondWrite = identicalSecondWrite;
- }
- }
+ public FormatInfo(ImageFormat format, boolean canRead,
+ boolean canWrite, int colorSupport,
+ final boolean identicalSecondWrite)
+ {
+ this.canRead = canRead;
+ this.canWrite = canWrite;
+ this.colorSupport = colorSupport;
+ this.format = format;
+ this.identicalSecondWrite = identicalSecondWrite;
+ }
+ }
- private static final FormatInfo FORMAT_INFOS[] = { //
- new FormatInfo(ImageFormat.IMAGE_FORMAT_PNG, true, true,
- COLOR_FULL_RGB, true), //
- new FormatInfo(ImageFormat.IMAGE_FORMAT_GIF, true, true,
- COLOR_LIMITED_INDEX, true), //
- new FormatInfo(ImageFormat.IMAGE_FORMAT_ICO, true, true,
- COLOR_FULL_RGB, true), //
- new FormatInfo(ImageFormat.IMAGE_FORMAT_TIFF, true, true,
- COLOR_FULL_RGB, true), //
- new FormatInfo(ImageFormat.IMAGE_FORMAT_JPEG, false, false,
- COLOR_FULL_RGB, true), //
- new FormatInfo(ImageFormat.IMAGE_FORMAT_BMP, true, true,
- COLOR_FULL_RGB, true), //
- new FormatInfo(ImageFormat.IMAGE_FORMAT_PSD, true, false,
- COLOR_FULL_RGB, true), //
- new FormatInfo(ImageFormat.IMAGE_FORMAT_PBM, true, true,
- COLOR_BITMAP, true), //
- new FormatInfo(ImageFormat.IMAGE_FORMAT_PGM, true, true,
- COLOR_GRAYSCALE, true), //
- new FormatInfo(ImageFormat.IMAGE_FORMAT_PPM, true, true,
- COLOR_FULL_RGB, true), //
- // new FormatInfo(ImageFormat.IMAGE_FORMAT_PNM, true, true,
- // COLOR_FULL_RGB, true), //
- new FormatInfo(ImageFormat.IMAGE_FORMAT_TGA, false, false,
- COLOR_FULL_RGB, true), //
- };
+ private static final FormatInfo FORMAT_INFOS[] = { //
+ new FormatInfo(ImageFormat.IMAGE_FORMAT_PNG, true, true,
+ COLOR_FULL_RGB, true), //
+ new FormatInfo(ImageFormat.IMAGE_FORMAT_GIF, true, true,
+ COLOR_LIMITED_INDEX, true), //
+ new FormatInfo(ImageFormat.IMAGE_FORMAT_ICO, true, true,
+ COLOR_FULL_RGB, true), //
+ new FormatInfo(ImageFormat.IMAGE_FORMAT_TIFF, true, true,
+ COLOR_FULL_RGB, true), //
+ new FormatInfo(ImageFormat.IMAGE_FORMAT_JPEG, false, false,
+ COLOR_FULL_RGB, true), //
+ new FormatInfo(ImageFormat.IMAGE_FORMAT_BMP, true, true,
+ COLOR_FULL_RGB, true), //
+ new FormatInfo(ImageFormat.IMAGE_FORMAT_PSD, true, false,
+ COLOR_FULL_RGB, true), //
+ new FormatInfo(ImageFormat.IMAGE_FORMAT_PBM, true, true,
+ COLOR_BITMAP, true), //
+ new FormatInfo(ImageFormat.IMAGE_FORMAT_PGM, true, true,
+ COLOR_GRAYSCALE, true), //
+ new FormatInfo(ImageFormat.IMAGE_FORMAT_PPM, true, true,
+ COLOR_FULL_RGB, true), //
+ // new FormatInfo(ImageFormat.IMAGE_FORMAT_PNM, true, true,
+ // COLOR_FULL_RGB, true), //
+ new FormatInfo(ImageFormat.IMAGE_FORMAT_TGA, false, false,
+ COLOR_FULL_RGB, true), //
+ };
- private BufferedImage createArgbBitmapImage(int width, int height)
- {
- BufferedImage result = new BufferedImage(width, height,
- BufferedImage.TYPE_INT_ARGB);
- for (int x = 0; x < width; x++)
- for (int y = 0; y < height; y++)
- {
- // alternating black and white.
- int modulator = y + 2; // make sure lines vary.
- int argb = (x + y) % modulator == 0 ? 0xff000000 : 0xffffffff;
- result.setRGB(x, y, argb);
- }
- return result;
- }
+ private BufferedImage createArgbBitmapImage(int width, int height)
+ {
+ BufferedImage result = new BufferedImage(width, height,
+ BufferedImage.TYPE_INT_ARGB);
+ for (int x = 0; x < width; x++)
+ for (int y = 0; y < height; y++)
+ {
+ // alternating black and white.
+ int modulator = y + 2; // make sure lines vary.
+ int argb = (x + y) % modulator == 0 ? 0xff000000 : 0xffffffff;
+ result.setRGB(x, y, argb);
+ }
+ return result;
+ }
- private BufferedImage createBitmapBitmapImage(int width, int height)
- {
- BufferedImage result = new BufferedImage(width, height,
- BufferedImage.TYPE_BYTE_BINARY);
- for (int x = 0; x < width; x++)
- for (int y = 0; y < height; y++)
- {
- // alternating black and white.
- int modulator = y + 2; // make sure lines vary.
- int argb = (x + y) % modulator == 0 ? 0xff000000 : 0xffffffff;
- result.setRGB(x, y, argb);
- }
- return result;
- }
+ private BufferedImage createBitmapBitmapImage(int width, int height)
+ {
+ BufferedImage result = new BufferedImage(width, height,
+ BufferedImage.TYPE_BYTE_BINARY);
+ for (int x = 0; x < width; x++)
+ for (int y = 0; y < height; y++)
+ {
+ // alternating black and white.
+ int modulator = y + 2; // make sure lines vary.
+ int argb = (x + y) % modulator == 0 ? 0xff000000 : 0xffffffff;
+ result.setRGB(x, y, argb);
+ }
+ return result;
+ }
- private BufferedImage createArgbGrayscaleImage(int width, int height)
- {
- BufferedImage result = new BufferedImage(width, height,
- BufferedImage.TYPE_INT_ARGB);
- for (int x = 0; x < width; x++)
- for (int y = 0; y < height; y++)
- {
- int value = (256 * (x + y)) / (width + height);
- int argb = (0xff << 24) | (value << 16) | (value << 8)
- | (value << 0);
+ private BufferedImage createArgbGrayscaleImage(int width, int height)
+ {
+ BufferedImage result = new BufferedImage(width, height,
+ BufferedImage.TYPE_INT_ARGB);
+ for (int x = 0; x < width; x++)
+ for (int y = 0; y < height; y++)
+ {
+ int value = (256 * (x + y)) / (width + height);
+ int argb = (0xff << 24) | (value << 16) | (value << 8)
+ | (value << 0);
- result.setRGB(x, y, argb);
- }
- return result;
- }
+ result.setRGB(x, y, argb);
+ }
+ return result;
+ }
- private BufferedImage createGrayscaleGrayscaleImage(int width, int height)
- {
- BufferedImage result = new BufferedImage(width, height,
- BufferedImage.TYPE_BYTE_GRAY);
- for (int x = 0; x < width; x++)
- for (int y = 0; y < height; y++)
- {
- int value = (256 * (x + y)) / (width + height);
- int argb = (0xff << 24) | (value << 16) | (value << 8)
- | (value << 0);
+ private BufferedImage createGrayscaleGrayscaleImage(int width, int height)
+ {
+ BufferedImage result = new BufferedImage(width, height,
+ BufferedImage.TYPE_BYTE_GRAY);
+ for (int x = 0; x < width; x++)
+ for (int y = 0; y < height; y++)
+ {
+ int value = (256 * (x + y)) / (width + height);
+ int argb = (0xff << 24) | (value << 16) | (value << 8)
+ | (value << 0);
- result.setRGB(x, y, argb);
- }
- return result;
- }
+ result.setRGB(x, y, argb);
+ }
+ return result;
+ }
- private BufferedImage createLimitedColorImage(int width, int height)
- {
- int colors[] = { 0xffffffff, 0xff000000, 0xfff00000, 0xff0000ff,
- 0xff123456, 0xfffefeff, 0xff7f817f, };
+ private BufferedImage createLimitedColorImage(int width, int height)
+ {
+ int colors[] = { 0xffffffff, 0xff000000, 0xfff00000, 0xff0000ff,
+ 0xff123456, 0xfffefeff, 0xff7f817f, };
- BufferedImage result = new BufferedImage(width, height,
- BufferedImage.TYPE_INT_ARGB);
- for (int x = 0; x < width; x++)
- for (int y = 0; y < height; y++)
- {
- int argb = colors[(x + y) % colors.length];
- result.setRGB(x, y, argb);
- }
- return result;
- }
+ BufferedImage result = new BufferedImage(width, height,
+ BufferedImage.TYPE_INT_ARGB);
+ for (int x = 0; x < width; x++)
+ for (int y = 0; y < height; y++)
+ {
+ int argb = colors[(x + y) % colors.length];
+ result.setRGB(x, y, argb);
+ }
+ return result;
+ }
- private BufferedImage createFullColorImage(int width, int height)
- {
- BufferedImage result = new BufferedImage(width, height,
- BufferedImage.TYPE_INT_ARGB);
- for (int x = 0; x < width; x++)
- for (int y = 0; y < height; y++)
- {
- int red = (x * 255) / width;
- int green = (y * 255) / height;
- int blue = ((x + y) * 255) / (width + height);
- int argb = (0xff << 24) | (red << 16) | (green << 8)
- | (blue << 0);
- result.setRGB(x, y, argb);
- }
- return result;
- }
+ private BufferedImage createFullColorImage(int width, int height)
+ {
+ BufferedImage result = new BufferedImage(width, height,
+ BufferedImage.TYPE_INT_ARGB);
+ for (int x = 0; x < width; x++)
+ for (int y = 0; y < height; y++)
+ {
+ int red = (x * 255) / width;
+ int green = (y * 255) / height;
+ int blue = ((x + y) * 255) / (width + height);
+ int argb = (0xff << 24) | (red << 16) | (green << 8)
+ | (blue << 0);
+ result.setRGB(x, y, argb);
+ }
+ return result;
+ }
- private void compareImagesExact(BufferedImage a, BufferedImage b)
- {
- compareImages(a, b, 0);
- }
+ private void compareImagesExact(BufferedImage a, BufferedImage b)
+ {
+ compareImages(a, b, 0);
+ }
- // private void compareImagesOffByOne(BufferedImage a, BufferedImage b)
- // {
- // compareImages(a, b, 3); // one bit of rounding error for each channel
- // }
+ // private void compareImagesOffByOne(BufferedImage a, BufferedImage b)
+ // {
+ // compareImages(a, b, 3); // one bit of rounding error for each channel
+ // }
- private void compareImages(BufferedImage a, BufferedImage b, int tolerance)
- {
- assertEquals(a.getWidth(), b.getWidth());
- assertEquals(a.getHeight(), b.getHeight());
+ 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);
- }
- }
+ 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);
+ }
+ }
- private int calculateARGBDistance(int a, int b)
- {
- int aAlpha = 0xff & (a >> 24);
- int aRed = 0xff & (a >> 16);
- int aGreen = 0xff & (a >> 8);
- int aBlue = 0xff & (a >> 0);
- int bAlpha = 0xff & (b >> 24);
- int bRed = 0xff & (b >> 16);
- int bGreen = 0xff & (b >> 8);
- int bBlue = 0xff & (b >> 0);
- int diff = Math.abs(aAlpha - bAlpha) + Math.abs(aRed - bRed)
- + Math.abs(aGreen - bGreen) + Math.abs(aBlue - bBlue);
- return diff;
+ private int calculateARGBDistance(int a, int b)
+ {
+ int aAlpha = 0xff & (a >> 24);
+ int aRed = 0xff & (a >> 16);
+ int aGreen = 0xff & (a >> 8);
+ int aBlue = 0xff & (a >> 0);
+ int bAlpha = 0xff & (b >> 24);
+ int bRed = 0xff & (b >> 16);
+ int bGreen = 0xff & (b >> 8);
+ int bBlue = 0xff & (b >> 0);
+ int diff = Math.abs(aAlpha - bAlpha) + Math.abs(aRed - bRed)
+ + Math.abs(aGreen - bGreen) + Math.abs(aBlue - bBlue);
+ return diff;
- }
+ }
- private void compareFilesExact(File a, File b) throws IOException
- {
- assertTrue(a.exists() && a.isFile());
- assertTrue(b.exists() && b.isFile());
- assertEquals(a.length(), b.length());
+ 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);
+ 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];
+ 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);
- }
- }
+ 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);
+ }
+ }
- public void testBitmapRoundtrip() throws IOException, ImageReadException,
- ImageWriteException
- {
- BufferedImage testImages[] = { //
+ 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
+ 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
- };
+ 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 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;
+ 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);
+ Debug.debug("bitmap test: " + formatInfo.format.name);
- roundtrip(formatInfo, testImage, "bitmap", true);
- }
- }
- }
+ roundtrip(formatInfo, testImage, "bitmap", true);
+ }
+ }
+ }
- public void testGrayscaleRoundtrip() throws IOException,
- ImageReadException, ImageWriteException
- {
- BufferedImage testImages[] = { //
+ public void testGrayscaleRoundtrip() throws IOException,
+ ImageReadException, ImageWriteException
+ {
+ BufferedImage testImages[] = { //
- createArgbBitmapImage(1, 1), // minimal
- createArgbGrayscaleImage(2, 2), //
- createArgbGrayscaleImage(10, 10), // larger than 8
- createArgbGrayscaleImage(300, 300), // larger than 256
+ createArgbBitmapImage(1, 1), // minimal
+ createArgbGrayscaleImage(2, 2), //
+ createArgbGrayscaleImage(10, 10), // larger than 8
+ createArgbGrayscaleImage(300, 300), // larger than 256
- createGrayscaleGrayscaleImage(1, 1), // minimal
- createGrayscaleGrayscaleImage(2, 2), //
- createGrayscaleGrayscaleImage(10, 10), // larger than 8
- createGrayscaleGrayscaleImage(300, 300), // larger than 256
- };
+ createGrayscaleGrayscaleImage(1, 1), // minimal
+ createGrayscaleGrayscaleImage(2, 2), //
+ createGrayscaleGrayscaleImage(10, 10), // larger than 8
+ createGrayscaleGrayscaleImage(300, 300), // larger than 256
+ };
- for (int j = 0; j < testImages.length; j++)
- {
- BufferedImage testImage = testImages[j];
+ 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;
+ for (int i = 0; i < FORMAT_INFOS.length; i++)
+ {
+ FormatInfo formatInfo = FORMAT_INFOS[i];
+ if ((!formatInfo.canRead) || (!formatInfo.canWrite))
+ continue;
- Debug.debug("grayscale test: " + formatInfo.format.name);
+ Debug.debug("grayscale test: " + formatInfo.format.name);
- boolean imageExact = true;
- if (formatInfo.colorSupport == COLOR_BITMAP)
- imageExact = false;
+ boolean imageExact = true;
+ if (formatInfo.colorSupport == COLOR_BITMAP)
+ imageExact = false;
- roundtrip(formatInfo, testImage, "gray", imageExact);
- }
- }
- }
+ roundtrip(formatInfo, testImage, "gray", imageExact);
+ }
+ }
+ }
- public void testLimitedColorRoundtrip() throws IOException,
- ImageReadException, ImageWriteException
- {
- BufferedImage testImages[] = { //
+ public void testLimitedColorRoundtrip() throws IOException,
+ ImageReadException, ImageWriteException
+ {
+ BufferedImage testImages[] = { //
- createLimitedColorImage(1, 1), // minimal
- createLimitedColorImage(2, 2), //
- createLimitedColorImage(10, 10), // larger than 8
- createLimitedColorImage(300, 300), // larger than 256
- };
+ createLimitedColorImage(1, 1), // minimal
+ createLimitedColorImage(2, 2), //
+ createLimitedColorImage(10, 10), // larger than 8
+ createLimitedColorImage(300, 300), // larger than 256
+ };
- for (int j = 0; j < testImages.length; j++)
- {
- BufferedImage testImage = testImages[j];
+ 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;
+ for (int i = 0; i < FORMAT_INFOS.length; i++)
+ {
+ FormatInfo formatInfo = FORMAT_INFOS[i];
+ if ((!formatInfo.canRead) || (!formatInfo.canWrite))
+ continue;
- Debug.debug("indexable test: " + formatInfo.format.name);
+ Debug.debug("indexable test: " + formatInfo.format.name);
- boolean imageExact = true;
- if (formatInfo.colorSupport == COLOR_BITMAP)
- imageExact = false;
- if (formatInfo.colorSupport == COLOR_GRAYSCALE)
- imageExact = false;
+ boolean imageExact = true;
+ if (formatInfo.colorSupport == COLOR_BITMAP)
+ imageExact = false;
+ if (formatInfo.colorSupport == COLOR_GRAYSCALE)
+ imageExact = false;
- roundtrip(formatInfo, testImage, "indexable", imageExact);
- }
- }
- }
+ roundtrip(formatInfo, testImage, "indexable", imageExact);
+ }
+ }
+ }
- public void testFullColorRoundtrip() throws IOException,
- ImageReadException, ImageWriteException
- {
- BufferedImage testImages[] = { //
+ 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
- };
+ 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 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;
+ 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);
+ 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;
+ 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);
- }
- }
- }
+ roundtrip(formatInfo, testImage, "fullColor", imageExact);
+ }
+ }
+ }
- private void roundtrip(FormatInfo formatInfo, BufferedImage testImage,
- String tempPrefix, boolean imageExact) throws IOException,
- ImageReadException, ImageWriteException
- {
- File temp1 = createTempFile(tempPrefix + ".", "."
- + formatInfo.format.extension);
- // Debug.debug("tempFile: " + tempFile.getName());
+ private void roundtrip(FormatInfo formatInfo, BufferedImage testImage,
+ String tempPrefix, boolean imageExact) throws IOException,
+ ImageReadException, ImageWriteException
+ {
+ File temp1 = createTempFile(tempPrefix + ".", "."
+ + formatInfo.format.extension);
+ // Debug.debug("tempFile: " + tempFile.getName());
- Map params = new HashMap();
- Sanselan.writeImage(testImage, temp1, formatInfo.format, params);
+ Map params = new HashMap();
+ Sanselan.writeImage(testImage, temp1, formatInfo.format, params);
- Map readParams = new HashMap();
- readParams.put(SanselanConstants.BUFFERED_IMAGE_FACTORY,
- new RgbBufferedImageFactory());
- BufferedImage image2 = Sanselan.getBufferedImage(temp1, readParams);
- assertNotNull(image2);
+ Map readParams = new HashMap();
+ readParams.put(SanselanConstants.BUFFERED_IMAGE_FACTORY,
+ new RgbBufferedImageFactory());
+ BufferedImage image2 = Sanselan.getBufferedImage(temp1, readParams);
+ assertNotNull(image2);
- if (imageExact)
- {
- // note tolerance when comparing grayscale images
- // BufferedImages of
- compareImagesExact(testImage, image2);
- }
+ if (imageExact)
+ {
+ // note tolerance when comparing grayscale images
+ // BufferedImages of
+ compareImagesExact(testImage, image2);
+ }
- File temp2 = createTempFile(tempPrefix + ".", "."
- + formatInfo.format.extension);
- // Debug.debug("tempFile: " + tempFile.getName());
- Sanselan.writeImage(image2, temp2, formatInfo.format, params);
+ File temp2 = createTempFile(tempPrefix + ".", "."
+ + formatInfo.format.extension);
+ // Debug.debug("tempFile: " + tempFile.getName());
+ Sanselan.writeImage(image2, temp2, formatInfo.format, params);
- compareFilesExact(temp1, temp2);
- }
+ compareFilesExact(temp1, temp2);
+ }
}
diff --git a/src/test/java/org/apache/sanselan/sampleUsage/ImageReadExample.java b/src/test/java/org/apache/sanselan/sampleUsage/ImageReadExample.java
index 5c3a157..e875481 100644
--- a/src/test/java/org/apache/sanselan/sampleUsage/ImageReadExample.java
+++ b/src/test/java/org/apache/sanselan/sampleUsage/ImageReadExample.java
@@ -33,44 +33,44 @@
public class ImageReadExample
{
- public static BufferedImage imageReadExample(File file)
- throws ImageReadException, IOException
- {
- Map params = new HashMap();
+ public static BufferedImage imageReadExample(File file)
+ throws ImageReadException, IOException
+ {
+ Map params = new HashMap();
- // set optional parameters if you like
- params.put(SanselanConstants.BUFFERED_IMAGE_FACTORY,
- new ManagedImageBufferedImageFactory());
+ // set optional parameters if you like
+ params.put(SanselanConstants.BUFFERED_IMAGE_FACTORY,
+ new ManagedImageBufferedImageFactory());
- // params.put(SanselanConstants.PARAM_KEY_VERBOSE, Boolean.TRUE);
+ // params.put(SanselanConstants.PARAM_KEY_VERBOSE, Boolean.TRUE);
- // read image
- BufferedImage image = Sanselan.getBufferedImage(file, params);
+ // read image
+ BufferedImage image = Sanselan.getBufferedImage(file, params);
- return image;
- }
+ return image;
+ }
- public static class ManagedImageBufferedImageFactory
- implements
- IBufferedImageFactory
- {
+ public static class ManagedImageBufferedImageFactory
+ implements
+ IBufferedImageFactory
+ {
- public BufferedImage getColorBufferedImage(int width, int height,
- boolean hasAlpha)
- {
- GraphicsEnvironment ge = GraphicsEnvironment
- .getLocalGraphicsEnvironment();
- GraphicsDevice gd = ge.getDefaultScreenDevice();
- GraphicsConfiguration gc = gd.getDefaultConfiguration();
- return gc.createCompatibleImage(width, height,
- Transparency.TRANSLUCENT);
- }
+ public BufferedImage getColorBufferedImage(int width, int height,
+ boolean hasAlpha)
+ {
+ GraphicsEnvironment ge = GraphicsEnvironment
+ .getLocalGraphicsEnvironment();
+ GraphicsDevice gd = ge.getDefaultScreenDevice();
+ GraphicsConfiguration gc = gd.getDefaultConfiguration();
+ return gc.createCompatibleImage(width, height,
+ Transparency.TRANSLUCENT);
+ }
- public BufferedImage getGrayscaleBufferedImage(int width, int height,
- boolean hasAlpha)
- {
- return getColorBufferedImage(width, height, hasAlpha);
- }
- }
+ public BufferedImage getGrayscaleBufferedImage(int width, int height,
+ boolean hasAlpha)
+ {
+ return getColorBufferedImage(width, height, hasAlpha);
+ }
+ }
}
diff --git a/src/test/java/org/apache/sanselan/sampleUsage/ImageWriteExample.java b/src/test/java/org/apache/sanselan/sampleUsage/ImageWriteExample.java
index 967b3f7..1a72da4 100644
--- a/src/test/java/org/apache/sanselan/sampleUsage/ImageWriteExample.java
+++ b/src/test/java/org/apache/sanselan/sampleUsage/ImageWriteExample.java
@@ -31,22 +31,22 @@
public class ImageWriteExample
{
- public static byte[] imageWriteExample(File file)
- throws ImageReadException, ImageWriteException, IOException
- {
- // read image
- BufferedImage image = Sanselan.getBufferedImage(file);
+ public static byte[] imageWriteExample(File file)
+ throws ImageReadException, ImageWriteException, IOException
+ {
+ // read image
+ BufferedImage image = Sanselan.getBufferedImage(file);
- ImageFormat format = ImageFormat.IMAGE_FORMAT_TIFF;
- Map params = new HashMap();
+ ImageFormat format = ImageFormat.IMAGE_FORMAT_TIFF;
+ Map params = new HashMap();
- // set optional parameters if you like
- params.put(SanselanConstants.PARAM_KEY_COMPRESSION, new Integer(
- TiffConstants.TIFF_COMPRESSION_UNCOMPRESSED));
+ // set optional parameters if you like
+ params.put(SanselanConstants.PARAM_KEY_COMPRESSION, new Integer(
+ TiffConstants.TIFF_COMPRESSION_UNCOMPRESSED));
- byte bytes[] = Sanselan.writeImageToBytes(image, format, params);
+ byte bytes[] = Sanselan.writeImageToBytes(image, format, params);
- return bytes;
- }
+ return bytes;
+ }
}
diff --git a/src/test/java/org/apache/sanselan/sampleUsage/MetadataExample.java b/src/test/java/org/apache/sanselan/sampleUsage/MetadataExample.java
index 7f96cc0..1eccadc 100644
--- a/src/test/java/org/apache/sanselan/sampleUsage/MetadataExample.java
+++ b/src/test/java/org/apache/sanselan/sampleUsage/MetadataExample.java
@@ -32,133 +32,133 @@
public class MetadataExample
{
- public static void metadataExample(File file) throws ImageReadException,
- IOException
- {
- // get all metadata stored in EXIF format (ie. from JPEG or TIFF).
- // org.w3c.dom.Node node = Sanselan.getMetadataObsolete(imageBytes);
- IImageMetadata metadata = Sanselan.getMetadata(file);
+ public static void metadataExample(File file) throws ImageReadException,
+ IOException
+ {
+ // get all metadata stored in EXIF format (ie. from JPEG or TIFF).
+ // org.w3c.dom.Node node = Sanselan.getMetadataObsolete(imageBytes);
+ IImageMetadata metadata = Sanselan.getMetadata(file);
- //System.out.println(metadata);
+ //System.out.println(metadata);
- if (metadata instanceof JpegImageMetadata)
- {
- JpegImageMetadata jpegMetadata = (JpegImageMetadata) metadata;
+ if (metadata instanceof JpegImageMetadata)
+ {
+ JpegImageMetadata jpegMetadata = (JpegImageMetadata) metadata;
- // Jpeg EXIF metadata is stored in a TIFF-based directory structure
- // and is identified with TIFF tags.
- // Here we look for the "x resolution" tag, but
- // we could just as easily search for any other tag.
- //
- // see the TiffConstants file for a list of TIFF tags.
+ // Jpeg EXIF metadata is stored in a TIFF-based directory structure
+ // and is identified with TIFF tags.
+ // Here we look for the "x resolution" tag, but
+ // we could just as easily search for any other tag.
+ //
+ // see the TiffConstants file for a list of TIFF tags.
- System.out.println("file: " + file.getPath());
+ System.out.println("file: " + file.getPath());
- // print out various interesting EXIF tags.
- printTagValue(jpegMetadata, TiffConstants.TIFF_TAG_XRESOLUTION);
- printTagValue(jpegMetadata, TiffConstants.TIFF_TAG_DATE_TIME);
- printTagValue(jpegMetadata,
- TiffConstants.EXIF_TAG_DATE_TIME_ORIGINAL);
- printTagValue(jpegMetadata, TiffConstants.EXIF_TAG_CREATE_DATE);
- printTagValue(jpegMetadata, TiffConstants.EXIF_TAG_ISO);
- printTagValue(jpegMetadata,
- TiffConstants.EXIF_TAG_SHUTTER_SPEED_VALUE);
- printTagValue(jpegMetadata, TiffConstants.EXIF_TAG_APERTURE_VALUE);
- printTagValue(jpegMetadata, TiffConstants.EXIF_TAG_BRIGHTNESS_VALUE);
- printTagValue(jpegMetadata, TiffConstants.GPS_TAG_GPS_LATITUDE_REF);
- printTagValue(jpegMetadata, TiffConstants.GPS_TAG_GPS_LATITUDE);
- printTagValue(jpegMetadata, TiffConstants.GPS_TAG_GPS_LONGITUDE_REF);
- printTagValue(jpegMetadata, TiffConstants.GPS_TAG_GPS_LONGITUDE);
+ // print out various interesting EXIF tags.
+ printTagValue(jpegMetadata, TiffConstants.TIFF_TAG_XRESOLUTION);
+ printTagValue(jpegMetadata, TiffConstants.TIFF_TAG_DATE_TIME);
+ printTagValue(jpegMetadata,
+ TiffConstants.EXIF_TAG_DATE_TIME_ORIGINAL);
+ printTagValue(jpegMetadata, TiffConstants.EXIF_TAG_CREATE_DATE);
+ printTagValue(jpegMetadata, TiffConstants.EXIF_TAG_ISO);
+ printTagValue(jpegMetadata,
+ TiffConstants.EXIF_TAG_SHUTTER_SPEED_VALUE);
+ printTagValue(jpegMetadata, TiffConstants.EXIF_TAG_APERTURE_VALUE);
+ printTagValue(jpegMetadata, TiffConstants.EXIF_TAG_BRIGHTNESS_VALUE);
+ printTagValue(jpegMetadata, TiffConstants.GPS_TAG_GPS_LATITUDE_REF);
+ printTagValue(jpegMetadata, TiffConstants.GPS_TAG_GPS_LATITUDE);
+ printTagValue(jpegMetadata, TiffConstants.GPS_TAG_GPS_LONGITUDE_REF);
+ printTagValue(jpegMetadata, TiffConstants.GPS_TAG_GPS_LONGITUDE);
- System.out.println();
+ System.out.println();
- // simple interface to GPS data
- TiffImageMetadata exifMetadata = jpegMetadata.getExif();
- if (null != exifMetadata)
- {
- TiffImageMetadata.GPSInfo gpsInfo = exifMetadata.getGPS();
- if (null != gpsInfo)
- {
- String gpsDescription = gpsInfo.toString();
- double longitude = gpsInfo.getLongitudeAsDegreesEast();
- double latitude = gpsInfo.getLatitudeAsDegreesNorth();
+ // simple interface to GPS data
+ TiffImageMetadata exifMetadata = jpegMetadata.getExif();
+ if (null != exifMetadata)
+ {
+ TiffImageMetadata.GPSInfo gpsInfo = exifMetadata.getGPS();
+ if (null != gpsInfo)
+ {
+ String gpsDescription = gpsInfo.toString();
+ double longitude = gpsInfo.getLongitudeAsDegreesEast();
+ double latitude = gpsInfo.getLatitudeAsDegreesNorth();
- System.out.println(" " + "GPS Description: " + gpsDescription);
- System.out.println(" " + "GPS Longitude (Degrees East): " + longitude);
- System.out.println(" " + "GPS Latitude (Degrees North): " + latitude);
- }
- }
+ System.out.println(" " + "GPS Description: " + gpsDescription);
+ System.out.println(" " + "GPS Longitude (Degrees East): " + longitude);
+ System.out.println(" " + "GPS Latitude (Degrees North): " + latitude);
+ }
+ }
- // more specific example of how to manually access GPS values
- TiffField gpsLatitudeRefField = jpegMetadata
- .findEXIFValueWithExactMatch(TiffConstants.GPS_TAG_GPS_LATITUDE_REF);
- TiffField gpsLatitudeField = jpegMetadata
- .findEXIFValueWithExactMatch(TiffConstants.GPS_TAG_GPS_LATITUDE);
- TiffField gpsLongitudeRefField = jpegMetadata
- .findEXIFValueWithExactMatch(TiffConstants.GPS_TAG_GPS_LONGITUDE_REF);
- TiffField gpsLongitudeField = jpegMetadata
- .findEXIFValueWithExactMatch(TiffConstants.GPS_TAG_GPS_LONGITUDE);
- if (gpsLatitudeRefField != null && gpsLatitudeField != null
- && gpsLongitudeRefField != null
- && gpsLongitudeField != null)
- {
- // all of these values are strings.
- String gpsLatitudeRef = (String) gpsLatitudeRefField.getValue();
- RationalNumber gpsLatitude[] = (RationalNumber[]) (gpsLatitudeField
- .getValue());
- String gpsLongitudeRef = (String) gpsLongitudeRefField
- .getValue();
- RationalNumber gpsLongitude[] = (RationalNumber[]) gpsLongitudeField
- .getValue();
+ // more specific example of how to manually access GPS values
+ TiffField gpsLatitudeRefField = jpegMetadata
+ .findEXIFValueWithExactMatch(TiffConstants.GPS_TAG_GPS_LATITUDE_REF);
+ TiffField gpsLatitudeField = jpegMetadata
+ .findEXIFValueWithExactMatch(TiffConstants.GPS_TAG_GPS_LATITUDE);
+ TiffField gpsLongitudeRefField = jpegMetadata
+ .findEXIFValueWithExactMatch(TiffConstants.GPS_TAG_GPS_LONGITUDE_REF);
+ TiffField gpsLongitudeField = jpegMetadata
+ .findEXIFValueWithExactMatch(TiffConstants.GPS_TAG_GPS_LONGITUDE);
+ if (gpsLatitudeRefField != null && gpsLatitudeField != null
+ && gpsLongitudeRefField != null
+ && gpsLongitudeField != null)
+ {
+ // all of these values are strings.
+ String gpsLatitudeRef = (String) gpsLatitudeRefField.getValue();
+ RationalNumber gpsLatitude[] = (RationalNumber[]) (gpsLatitudeField
+ .getValue());
+ String gpsLongitudeRef = (String) gpsLongitudeRefField
+ .getValue();
+ RationalNumber gpsLongitude[] = (RationalNumber[]) gpsLongitudeField
+ .getValue();
- RationalNumber gpsLatitudeDegrees = gpsLatitude[0];
- RationalNumber gpsLatitudeMinutes = gpsLatitude[1];
- RationalNumber gpsLatitudeSeconds = gpsLatitude[2];
+ RationalNumber gpsLatitudeDegrees = gpsLatitude[0];
+ RationalNumber gpsLatitudeMinutes = gpsLatitude[1];
+ RationalNumber gpsLatitudeSeconds = gpsLatitude[2];
- RationalNumber gpsLongitudeDegrees = gpsLongitude[0];
- RationalNumber gpsLongitudeMinutes = gpsLongitude[1];
- RationalNumber gpsLongitudeSeconds = gpsLongitude[2];
+ RationalNumber gpsLongitudeDegrees = gpsLongitude[0];
+ RationalNumber gpsLongitudeMinutes = gpsLongitude[1];
+ RationalNumber gpsLongitudeSeconds = gpsLongitude[2];
- // This will format the gps info like so:
- //
- // gpsLatitude: 8 degrees, 40 minutes, 42.2 seconds S
- // gpsLongitude: 115 degrees, 26 minutes, 21.8 seconds E
+ // This will format the gps info like so:
+ //
+ // gpsLatitude: 8 degrees, 40 minutes, 42.2 seconds S
+ // gpsLongitude: 115 degrees, 26 minutes, 21.8 seconds E
- System.out.println(" " + "GPS Latitude: "
- + gpsLatitudeDegrees.toDisplayString() + " degrees, "
- + gpsLatitudeMinutes.toDisplayString() + " minutes, "
- + gpsLatitudeSeconds.toDisplayString() + " seconds "
- + gpsLatitudeRef);
- System.out.println(" " + "GPS Longitude: "
- + gpsLongitudeDegrees.toDisplayString() + " degrees, "
- + gpsLongitudeMinutes.toDisplayString() + " minutes, "
- + gpsLongitudeSeconds.toDisplayString() + " seconds "
- + gpsLongitudeRef);
+ System.out.println(" " + "GPS Latitude: "
+ + gpsLatitudeDegrees.toDisplayString() + " degrees, "
+ + gpsLatitudeMinutes.toDisplayString() + " minutes, "
+ + gpsLatitudeSeconds.toDisplayString() + " seconds "
+ + gpsLatitudeRef);
+ System.out.println(" " + "GPS Longitude: "
+ + gpsLongitudeDegrees.toDisplayString() + " degrees, "
+ + gpsLongitudeMinutes.toDisplayString() + " minutes, "
+ + gpsLongitudeSeconds.toDisplayString() + " seconds "
+ + gpsLongitudeRef);
- }
+ }
- System.out.println();
+ System.out.println();
- ArrayList items = jpegMetadata.getItems();
- for (int i = 0; i < items.size(); i++)
- {
- Object item = items.get(i);
- System.out.println(" " + "item: " + item);
- }
+ ArrayList items = jpegMetadata.getItems();
+ for (int i = 0; i < items.size(); i++)
+ {
+ Object item = items.get(i);
+ System.out.println(" " + "item: " + item);
+ }
- System.out.println();
- }
- }
+ System.out.println();
+ }
+ }
- private static void printTagValue(JpegImageMetadata jpegMetadata,
- TagInfo tagInfo)
- {
- TiffField field = jpegMetadata.findEXIFValueWithExactMatch(tagInfo);
- if (field == null)
- System.out.println(tagInfo.name + ": " + "Not Found.");
- else
- System.out.println(tagInfo.name + ": "
- + field.getValueDescription());
- }
+ private static void printTagValue(JpegImageMetadata jpegMetadata,
+ TagInfo tagInfo)
+ {
+ TiffField field = jpegMetadata.findEXIFValueWithExactMatch(tagInfo);
+ if (field == null)
+ System.out.println(tagInfo.name + ": " + "Not Found.");
+ else
+ System.out.println(tagInfo.name + ": "
+ + field.getValueDescription());
+ }
}
diff --git a/src/test/java/org/apache/sanselan/sampleUsage/SampleUsage.java b/src/test/java/org/apache/sanselan/sampleUsage/SampleUsage.java
index 32cd8c8..232fd2d 100644
--- a/src/test/java/org/apache/sanselan/sampleUsage/SampleUsage.java
+++ b/src/test/java/org/apache/sanselan/sampleUsage/SampleUsage.java
@@ -34,77 +34,77 @@
public class SampleUsage
{
- public SampleUsage()
- {
+ public SampleUsage()
+ {
- try
- {
- // <b>Code won't work unless these variables are properly initialized.
- // Sanselan works equally well with File, byte array or InputStream inputs.</b>
- BufferedImage someImage = null;
- byte someBytes[] = null;
- File someFile = null;
- InputStream someInputStream = null;
- OutputStream someOutputStream = null;
+ try
+ {
+ // <b>Code won't work unless these variables are properly initialized.
+ // Sanselan works equally well with File, byte array or InputStream inputs.</b>
+ BufferedImage someImage = null;
+ byte someBytes[] = null;
+ File someFile = null;
+ InputStream someInputStream = null;
+ OutputStream someOutputStream = null;
- // <b>The Sanselan class provides a simple interface to the library. </b>
+ // <b>The Sanselan class provides a simple interface to the library. </b>
- // <b>how to read an image: </b>
- byte imageBytes[] = someBytes;
- BufferedImage image_1 = Sanselan.getBufferedImage(imageBytes);
+ // <b>how to read an image: </b>
+ byte imageBytes[] = someBytes;
+ BufferedImage image_1 = Sanselan.getBufferedImage(imageBytes);
- // <b>methods of Sanselan usually accept files, byte arrays, or inputstreams as arguments. </b>
- BufferedImage image_2 = Sanselan.getBufferedImage(imageBytes);
- File file = someFile;
- BufferedImage image_3 = Sanselan.getBufferedImage(file);
- InputStream is = someInputStream;
- BufferedImage image_4 = Sanselan.getBufferedImage(is);
+ // <b>methods of Sanselan usually accept files, byte arrays, or inputstreams as arguments. </b>
+ BufferedImage image_2 = Sanselan.getBufferedImage(imageBytes);
+ File file = someFile;
+ BufferedImage image_3 = Sanselan.getBufferedImage(file);
+ InputStream is = someInputStream;
+ BufferedImage image_4 = Sanselan.getBufferedImage(is);
- // <b>Write an image. </b>
- BufferedImage image = someImage;
- File dst = someFile;
- ImageFormat format = ImageFormat.IMAGE_FORMAT_PNG;
- Map optional_params = new HashMap();
- Sanselan.writeImage(image, dst, format, optional_params);
+ // <b>Write an image. </b>
+ BufferedImage image = someImage;
+ File dst = someFile;
+ ImageFormat format = ImageFormat.IMAGE_FORMAT_PNG;
+ Map optional_params = new HashMap();
+ Sanselan.writeImage(image, dst, format, optional_params);
- OutputStream os = someOutputStream;
- Sanselan.writeImage(image, os, format, optional_params);
+ OutputStream os = someOutputStream;
+ Sanselan.writeImage(image, os, format, optional_params);
- // <b>get the image's embedded ICC Profile, if it has one. </b>
- byte iccProfileBytes[] = Sanselan.getICCProfileBytes(imageBytes);
+ // <b>get the image's embedded ICC Profile, if it has one. </b>
+ byte iccProfileBytes[] = Sanselan.getICCProfileBytes(imageBytes);
- ICC_Profile iccProfile = Sanselan.getICCProfile(imageBytes);
+ ICC_Profile iccProfile = Sanselan.getICCProfile(imageBytes);
- // <b>get the image's width and height. </b>
- Dimension d = Sanselan.getImageSize(imageBytes);
+ // <b>get the image's width and height. </b>
+ Dimension d = Sanselan.getImageSize(imageBytes);
- // <b>get all of the image's info (ie. bits per pixel, size, transparency, etc.) </b>
- ImageInfo imageInfo = Sanselan.getImageInfo(imageBytes);
+ // <b>get all of the image's info (ie. bits per pixel, size, transparency, etc.) </b>
+ ImageInfo imageInfo = Sanselan.getImageInfo(imageBytes);
- if (imageInfo.getColorType() == ImageInfo.COLOR_TYPE_GRAYSCALE)
- System.out.println("Grayscale image.");
- if (imageInfo.getHeight() > 1000)
- System.out.println("Large image.");
+ if (imageInfo.getColorType() == ImageInfo.COLOR_TYPE_GRAYSCALE)
+ System.out.println("Grayscale image.");
+ if (imageInfo.getHeight() > 1000)
+ System.out.println("Large image.");
- // <b>try to guess the image's format. </b>
- ImageFormat image_format = Sanselan.guessFormat(imageBytes);
- image_format.equals(ImageFormat.IMAGE_FORMAT_PNG);
+ // <b>try to guess the image's format. </b>
+ ImageFormat image_format = Sanselan.guessFormat(imageBytes);
+ image_format.equals(ImageFormat.IMAGE_FORMAT_PNG);
- // <b>get all metadata stored in EXIF format (ie. from JPEG or TIFF). </b>
- // <b>org.w3c.dom.Node node = Sanselan.getMetadataObsolete(imageBytes); </b>
- IImageMetadata metdata = Sanselan.getMetadata(imageBytes);
+ // <b>get all metadata stored in EXIF format (ie. from JPEG or TIFF). </b>
+ // <b>org.w3c.dom.Node node = Sanselan.getMetadataObsolete(imageBytes); </b>
+ IImageMetadata metdata = Sanselan.getMetadata(imageBytes);
- // <b>print a dump of information about an image to stdout. </b>
- Sanselan.dumpImageFile(imageBytes);
+ // <b>print a dump of information about an image to stdout. </b>
+ Sanselan.dumpImageFile(imageBytes);
- // <b>get a summary of format errors. </b>
- FormatCompliance formatCompliance = Sanselan
- .getFormatCompliance(imageBytes);
+ // <b>get a summary of format errors. </b>
+ FormatCompliance formatCompliance = Sanselan
+ .getFormatCompliance(imageBytes);
- }
- catch (Exception e)
- {
+ }
+ catch (Exception e)
+ {
- }
- }
+ }
+ }
}
diff --git a/src/test/java/org/apache/sanselan/sampleUsage/WriteExifMetadataExample.java b/src/test/java/org/apache/sanselan/sampleUsage/WriteExifMetadataExample.java
index 2b14332..5a51a9d 100644
--- a/src/test/java/org/apache/sanselan/sampleUsage/WriteExifMetadataExample.java
+++ b/src/test/java/org/apache/sanselan/sampleUsage/WriteExifMetadataExample.java
@@ -37,315 +37,315 @@
public class WriteExifMetadataExample
{
- public void removeExifMetadata(File jpegImageFile, File dst)
- throws IOException, ImageReadException, ImageWriteException
- {
- OutputStream os = null;
- try
- {
- os = new FileOutputStream(dst);
- os = new BufferedOutputStream(os);
+ public void removeExifMetadata(File jpegImageFile, File dst)
+ throws IOException, ImageReadException, ImageWriteException
+ {
+ OutputStream os = null;
+ try
+ {
+ os = new FileOutputStream(dst);
+ os = new BufferedOutputStream(os);
- new ExifRewriter().removeExifMetadata(jpegImageFile, os);
- } finally
- {
- if (os != null)
- try
- {
- os.close();
- } catch (IOException e)
- {
+ new ExifRewriter().removeExifMetadata(jpegImageFile, os);
+ } finally
+ {
+ if (os != null)
+ try
+ {
+ os.close();
+ } catch (IOException e)
+ {
- }
- }
- }
+ }
+ }
+ }
- /**
- * This example illustrates how to add/update EXIF metadata in a JPEG file.
- *
- * @param jpegImageFile
- * A source image file.
- * @param dst
- * The output file.
- * @throws IOException
- * @throws ImageReadException
- * @throws ImageWriteException
- */
- public void changeExifMetadata(File jpegImageFile, File dst)
- throws IOException, ImageReadException, ImageWriteException
- {
- OutputStream os = null;
- try
- {
- TiffOutputSet outputSet = null;
+ /**
+ * This example illustrates how to add/update EXIF metadata in a JPEG file.
+ *
+ * @param jpegImageFile
+ * A source image file.
+ * @param dst
+ * The output file.
+ * @throws IOException
+ * @throws ImageReadException
+ * @throws ImageWriteException
+ */
+ public void changeExifMetadata(File jpegImageFile, File dst)
+ throws IOException, ImageReadException, ImageWriteException
+ {
+ OutputStream os = null;
+ try
+ {
+ TiffOutputSet outputSet = null;
- // note that metadata might be null if no metadata is found.
- IImageMetadata metadata = Sanselan.getMetadata(jpegImageFile);
- JpegImageMetadata jpegMetadata = (JpegImageMetadata) metadata;
- if (null != jpegMetadata)
- {
- // note that exif might be null if no Exif metadata is found.
- TiffImageMetadata exif = jpegMetadata.getExif();
+ // note that metadata might be null if no metadata is found.
+ IImageMetadata metadata = Sanselan.getMetadata(jpegImageFile);
+ JpegImageMetadata jpegMetadata = (JpegImageMetadata) metadata;
+ if (null != jpegMetadata)
+ {
+ // note that exif might be null if no Exif metadata is found.
+ TiffImageMetadata exif = jpegMetadata.getExif();
- if (null != exif)
- {
- // TiffImageMetadata class is immutable (read-only).
- // TiffOutputSet class represents the Exif data to write.
- //
- // Usually, we want to update existing Exif metadata by
- // changing
- // the values of a few fields, or adding a field.
- // In these cases, it is easiest to use getOutputSet() to
- // start with a "copy" of the fields read from the image.
- outputSet = exif.getOutputSet();
- }
- }
+ if (null != exif)
+ {
+ // TiffImageMetadata class is immutable (read-only).
+ // TiffOutputSet class represents the Exif data to write.
+ //
+ // Usually, we want to update existing Exif metadata by
+ // changing
+ // the values of a few fields, or adding a field.
+ // In these cases, it is easiest to use getOutputSet() to
+ // start with a "copy" of the fields read from the image.
+ outputSet = exif.getOutputSet();
+ }
+ }
- // if file does not contain any exif metadata, we create an empty
- // set of exif metadata. Otherwise, we keep all of the other
- // existing tags.
- if (null == outputSet)
- outputSet = new TiffOutputSet();
+ // if file does not contain any exif metadata, we create an empty
+ // set of exif metadata. Otherwise, we keep all of the other
+ // existing tags.
+ if (null == outputSet)
+ outputSet = new TiffOutputSet();
- {
- // Example of how to add a field/tag to the output set.
- //
- // Note that you should first remove the field/tag if it already
- // exists in this directory, or you may end up with duplicate
- // tags. See above.
- //
- // Certain fields/tags are expected in certain Exif directories;
- // Others can occur in more than one directory (and often have a
- // different meaning in different directories).
- //
- // TagInfo constants often contain a description of what
- // directories are associated with a given tag.
- //
- // see
- // org.apache.sanselan.formats.tiff.constants.AllTagConstants
- //
- TiffOutputField aperture = TiffOutputField.create(
- TiffConstants.EXIF_TAG_APERTURE_VALUE,
- outputSet.byteOrder, new Double(0.3));
- TiffOutputDirectory exifDirectory = outputSet
- .getOrCreateExifDirectory();
- // make sure to remove old value if present (this method will
- // not fail if the tag does not exist).
- exifDirectory
- .removeField(TiffConstants.EXIF_TAG_APERTURE_VALUE);
- exifDirectory.add(aperture);
- }
+ {
+ // Example of how to add a field/tag to the output set.
+ //
+ // Note that you should first remove the field/tag if it already
+ // exists in this directory, or you may end up with duplicate
+ // tags. See above.
+ //
+ // Certain fields/tags are expected in certain Exif directories;
+ // Others can occur in more than one directory (and often have a
+ // different meaning in different directories).
+ //
+ // TagInfo constants often contain a description of what
+ // directories are associated with a given tag.
+ //
+ // see
+ // org.apache.sanselan.formats.tiff.constants.AllTagConstants
+ //
+ TiffOutputField aperture = TiffOutputField.create(
+ TiffConstants.EXIF_TAG_APERTURE_VALUE,
+ outputSet.byteOrder, new Double(0.3));
+ TiffOutputDirectory exifDirectory = outputSet
+ .getOrCreateExifDirectory();
+ // make sure to remove old value if present (this method will
+ // not fail if the tag does not exist).
+ exifDirectory
+ .removeField(TiffConstants.EXIF_TAG_APERTURE_VALUE);
+ exifDirectory.add(aperture);
+ }
- {
- // Example of how to add/update GPS info to output set.
+ {
+ // Example of how to add/update GPS info to output set.
- // New York City
- double longitude = -74.0; // 74 degrees W (in Degrees East)
- double latitude = 40 + 43 / 60.0; // 40 degrees N (in Degrees
- // North)
+ // New York City
+ double longitude = -74.0; // 74 degrees W (in Degrees East)
+ double latitude = 40 + 43 / 60.0; // 40 degrees N (in Degrees
+ // North)
- outputSet.setGPSInDegrees(longitude, latitude);
- }
+ outputSet.setGPSInDegrees(longitude, latitude);
+ }
- // printTagValue(jpegMetadata, TiffConstants.TIFF_TAG_DATE_TIME);
+ // printTagValue(jpegMetadata, TiffConstants.TIFF_TAG_DATE_TIME);
- os = new FileOutputStream(dst);
- os = new BufferedOutputStream(os);
+ os = new FileOutputStream(dst);
+ os = new BufferedOutputStream(os);
- new ExifRewriter().updateExifMetadataLossless(jpegImageFile, os,
- outputSet);
+ new ExifRewriter().updateExifMetadataLossless(jpegImageFile, os,
+ outputSet);
- os.close();
- os = null;
- } finally
- {
- if (os != null)
- try
- {
- os.close();
- } catch (IOException e)
- {
+ os.close();
+ os = null;
+ } finally
+ {
+ if (os != null)
+ try
+ {
+ os.close();
+ } catch (IOException e)
+ {
- }
- }
- }
+ }
+ }
+ }
- /**
- * This example illustrates how to remove a tag (if present) from EXIF
- * metadata in a JPEG file.
- *
- * In this case, we remove the "aperture" tag from the EXIF metadata if
- * present.
- *
- * @param jpegImageFile
- * A source image file.
- * @param dst
- * The output file.
- * @throws IOException
- * @throws ImageReadException
- * @throws ImageWriteException
- */
- public void removeExifTag(File jpegImageFile, File dst) throws IOException,
- ImageReadException, ImageWriteException
- {
- OutputStream os = null;
- try
- {
- TiffOutputSet outputSet = null;
+ /**
+ * This example illustrates how to remove a tag (if present) from EXIF
+ * metadata in a JPEG file.
+ *
+ * In this case, we remove the "aperture" tag from the EXIF metadata if
+ * present.
+ *
+ * @param jpegImageFile
+ * A source image file.
+ * @param dst
+ * The output file.
+ * @throws IOException
+ * @throws ImageReadException
+ * @throws ImageWriteException
+ */
+ public void removeExifTag(File jpegImageFile, File dst) throws IOException,
+ ImageReadException, ImageWriteException
+ {
+ OutputStream os = null;
+ try
+ {
+ TiffOutputSet outputSet = null;
- // note that metadata might be null if no metadata is found.
- IImageMetadata metadata = Sanselan.getMetadata(jpegImageFile);
- JpegImageMetadata jpegMetadata = (JpegImageMetadata) metadata;
- if (null != jpegMetadata)
- {
- // note that exif might be null if no Exif metadata is found.
- TiffImageMetadata exif = jpegMetadata.getExif();
+ // note that metadata might be null if no metadata is found.
+ IImageMetadata metadata = Sanselan.getMetadata(jpegImageFile);
+ JpegImageMetadata jpegMetadata = (JpegImageMetadata) metadata;
+ if (null != jpegMetadata)
+ {
+ // note that exif might be null if no Exif metadata is found.
+ TiffImageMetadata exif = jpegMetadata.getExif();
- if (null != exif)
- {
- // TiffImageMetadata class is immutable (read-only).
- // TiffOutputSet class represents the Exif data to write.
- //
- // Usually, we want to update existing Exif metadata by
- // changing
- // the values of a few fields, or adding a field.
- // In these cases, it is easiest to use getOutputSet() to
- // start with a "copy" of the fields read from the image.
- outputSet = exif.getOutputSet();
- }
- }
+ if (null != exif)
+ {
+ // TiffImageMetadata class is immutable (read-only).
+ // TiffOutputSet class represents the Exif data to write.
+ //
+ // Usually, we want to update existing Exif metadata by
+ // changing
+ // the values of a few fields, or adding a field.
+ // In these cases, it is easiest to use getOutputSet() to
+ // start with a "copy" of the fields read from the image.
+ outputSet = exif.getOutputSet();
+ }
+ }
- if (null == outputSet)
- {
- // file does not contain any exif metadata. We don't need to
- // update the file; just copy it.
- IOUtils.copyFileNio(jpegImageFile, dst);
- return;
- }
+ if (null == outputSet)
+ {
+ // file does not contain any exif metadata. We don't need to
+ // update the file; just copy it.
+ IOUtils.copyFileNio(jpegImageFile, dst);
+ return;
+ }
- {
- // Example of how to remove a single tag/field.
- // There are two ways to do this.
+ {
+ // Example of how to remove a single tag/field.
+ // There are two ways to do this.
- // Option 1: brute force
- // Note that this approach is crude: Exif data is organized in
- // directories. The same tag/field may appear in more than one
- // directory, and have different meanings in each.
- outputSet.removeField(TiffConstants.EXIF_TAG_APERTURE_VALUE);
+ // Option 1: brute force
+ // Note that this approach is crude: Exif data is organized in
+ // directories. The same tag/field may appear in more than one
+ // directory, and have different meanings in each.
+ outputSet.removeField(TiffConstants.EXIF_TAG_APERTURE_VALUE);
- // Option 2: precision
- // We know the exact directory the tag should appear in, in this
- // case the "exif" directory.
- // One complicating factor is that in some cases, manufacturers
- // will place the same tag in different directories.
- // To learn which directory a tag appears in, either refer to
- // the constants in ExifTagConstants.java or go to Phil Harvey's
- // EXIF website.
- TiffOutputDirectory exifDirectory = outputSet
- .getExifDirectory();
- if (null != exifDirectory)
- exifDirectory
- .removeField(TiffConstants.EXIF_TAG_APERTURE_VALUE);
- }
+ // Option 2: precision
+ // We know the exact directory the tag should appear in, in this
+ // case the "exif" directory.
+ // One complicating factor is that in some cases, manufacturers
+ // will place the same tag in different directories.
+ // To learn which directory a tag appears in, either refer to
+ // the constants in ExifTagConstants.java or go to Phil Harvey's
+ // EXIF website.
+ TiffOutputDirectory exifDirectory = outputSet
+ .getExifDirectory();
+ if (null != exifDirectory)
+ exifDirectory
+ .removeField(TiffConstants.EXIF_TAG_APERTURE_VALUE);
+ }
- os = new FileOutputStream(dst);
- os = new BufferedOutputStream(os);
+ os = new FileOutputStream(dst);
+ os = new BufferedOutputStream(os);
- new ExifRewriter().updateExifMetadataLossless(jpegImageFile, os,
- outputSet);
+ new ExifRewriter().updateExifMetadataLossless(jpegImageFile, os,
+ outputSet);
- os.close();
- os = null;
- } finally
- {
- if (os != null)
- try
- {
- os.close();
- } catch (IOException e)
- {
+ os.close();
+ os = null;
+ } finally
+ {
+ if (os != null)
+ try
+ {
+ os.close();
+ } catch (IOException e)
+ {
- }
- }
- }
+ }
+ }
+ }
- /**
- * This example illustrates how to set the GPS values in JPEG EXIF metadata.
- *
- * @param jpegImageFile
- * A source image file.
- * @param dst
- * The output file.
- * @throws IOException
- * @throws ImageReadException
- * @throws ImageWriteException
- */
- public void setExifGPSTag(File jpegImageFile, File dst) throws IOException,
- ImageReadException, ImageWriteException
- {
- OutputStream os = null;
- try
- {
- TiffOutputSet outputSet = null;
+ /**
+ * This example illustrates how to set the GPS values in JPEG EXIF metadata.
+ *
+ * @param jpegImageFile
+ * A source image file.
+ * @param dst
+ * The output file.
+ * @throws IOException
+ * @throws ImageReadException
+ * @throws ImageWriteException
+ */
+ public void setExifGPSTag(File jpegImageFile, File dst) throws IOException,
+ ImageReadException, ImageWriteException
+ {
+ OutputStream os = null;
+ try
+ {
+ TiffOutputSet outputSet = null;
- // note that metadata might be null if no metadata is found.
- IImageMetadata metadata = Sanselan.getMetadata(jpegImageFile);
- JpegImageMetadata jpegMetadata = (JpegImageMetadata) metadata;
- if (null != jpegMetadata)
- {
- // note that exif might be null if no Exif metadata is found.
- TiffImageMetadata exif = jpegMetadata.getExif();
+ // note that metadata might be null if no metadata is found.
+ IImageMetadata metadata = Sanselan.getMetadata(jpegImageFile);
+ JpegImageMetadata jpegMetadata = (JpegImageMetadata) metadata;
+ if (null != jpegMetadata)
+ {
+ // note that exif might be null if no Exif metadata is found.
+ TiffImageMetadata exif = jpegMetadata.getExif();
- if (null != exif)
- {
- // TiffImageMetadata class is immutable (read-only).
- // TiffOutputSet class represents the Exif data to write.
- //
- // Usually, we want to update existing Exif metadata by
- // changing
- // the values of a few fields, or adding a field.
- // In these cases, it is easiest to use getOutputSet() to
- // start with a "copy" of the fields read from the image.
- outputSet = exif.getOutputSet();
- }
- }
+ if (null != exif)
+ {
+ // TiffImageMetadata class is immutable (read-only).
+ // TiffOutputSet class represents the Exif data to write.
+ //
+ // Usually, we want to update existing Exif metadata by
+ // changing
+ // the values of a few fields, or adding a field.
+ // In these cases, it is easiest to use getOutputSet() to
+ // start with a "copy" of the fields read from the image.
+ outputSet = exif.getOutputSet();
+ }
+ }
- // if file does not contain any exif metadata, we create an empty
- // set of exif metadata. Otherwise, we keep all of the other
- // existing tags.
- if (null == outputSet)
- outputSet = new TiffOutputSet();
+ // if file does not contain any exif metadata, we create an empty
+ // set of exif metadata. Otherwise, we keep all of the other
+ // existing tags.
+ if (null == outputSet)
+ outputSet = new TiffOutputSet();
- {
- // Example of how to add/update GPS info to output set.
+ {
+ // Example of how to add/update GPS info to output set.
- // New York City
- double longitude = -74.0; // 74 degrees W (in Degrees East)
- double latitude = 40 + 43 / 60.0; // 40 degrees N (in Degrees
- // North)
+ // New York City
+ double longitude = -74.0; // 74 degrees W (in Degrees East)
+ double latitude = 40 + 43 / 60.0; // 40 degrees N (in Degrees
+ // North)
- outputSet.setGPSInDegrees(longitude, latitude);
- }
+ outputSet.setGPSInDegrees(longitude, latitude);
+ }
- os = new FileOutputStream(dst);
- os = new BufferedOutputStream(os);
+ os = new FileOutputStream(dst);
+ os = new BufferedOutputStream(os);
- new ExifRewriter().updateExifMetadataLossless(jpegImageFile, os,
- outputSet);
+ new ExifRewriter().updateExifMetadataLossless(jpegImageFile, os,
+ outputSet);
- os.close();
- os = null;
- } finally
- {
- if (os != null)
- try
- {
- os.close();
- } catch (IOException e)
- {
+ os.close();
+ os = null;
+ } finally
+ {
+ if (os != null)
+ try
+ {
+ os.close();
+ } catch (IOException e)
+ {
- }
- }
- }
+ }
+ }
+ }
}
diff --git a/src/test/java/org/apache/sanselan/test/util/FSTraversal.java b/src/test/java/org/apache/sanselan/test/util/FSTraversal.java
index 4234c50..6da10b7 100644
--- a/src/test/java/org/apache/sanselan/test/util/FSTraversal.java
+++ b/src/test/java/org/apache/sanselan/test/util/FSTraversal.java
@@ -24,167 +24,167 @@
public class FSTraversal
{
- public static final int MODE_FILES = 1;
- public static final int MODE_FOLDERS = 2;
- public static final int MODE_FILES_AND_FOLDERS = 3;
- public static final int MODE_ALL = 4;
+ public static final int MODE_FILES = 1;
+ public static final int MODE_FOLDERS = 2;
+ public static final int MODE_FILES_AND_FOLDERS = 3;
+ public static final int MODE_ALL = 4;
- public interface Visitor
- {
- public boolean visit(File file, double progressEstimate);
- }
+ public interface Visitor
+ {
+ public boolean visit(File file, double progressEstimate);
+ }
- public boolean traverseFiles(File file, Visitor visitor)
- {
+ public boolean traverseFiles(File file, Visitor visitor)
+ {
- return traverse(file, MODE_FILES, visitor);
- }
+ return traverse(file, MODE_FILES, visitor);
+ }
- public boolean traverseFolders(File file, Visitor visitor)
- {
+ public boolean traverseFolders(File file, Visitor visitor)
+ {
- return traverse(file, MODE_FOLDERS, visitor);
- }
+ return traverse(file, MODE_FOLDERS, visitor);
+ }
- public boolean traverseAll(File file, Visitor visitor)
- {
+ public boolean traverseAll(File file, Visitor visitor)
+ {
- return traverse(file, MODE_FILES_AND_FOLDERS, visitor);
- }
+ return traverse(file, MODE_FILES_AND_FOLDERS, visitor);
+ }
- public boolean traverse(File file, int mode, Visitor visitor)
- {
- return traverse(file, mode, visitor, 0, 1);
- }
+ public boolean traverse(File file, int mode, Visitor visitor)
+ {
+ return traverse(file, mode, visitor, 0, 1);
+ }
- private boolean traverse(File file, int mode, Visitor visitor,
- double estimate, double estimateIncrement)
- {
+ private boolean traverse(File file, int mode, Visitor visitor,
+ double estimate, double estimateIncrement)
+ {
- if (file.isFile())
- {
- if ((mode == MODE_FILES) || (mode == MODE_FILES_AND_FOLDERS)
- || (mode == MODE_ALL))
- {
- if (!visitor.visit(file, estimate))
- return false;
- }
- }
- else if (file.isDirectory())
- {
- File files[] = file.listFiles();
- if (files != null)
- {
- for (int i = 0; i < files.length; i++)
- {
- File child = files[i];
- if (ON_MAC_OS_X && child.isDirectory())
- {
- String name = child.getName();
- if (name.equalsIgnoreCase("automount")
- || name.equalsIgnoreCase("private")
- || name.equalsIgnoreCase("Network")
- || name.equalsIgnoreCase("Volumes"))
- {
- continue;
- // return true;
- }
- }
+ if (file.isFile())
+ {
+ if ((mode == MODE_FILES) || (mode == MODE_FILES_AND_FOLDERS)
+ || (mode == MODE_ALL))
+ {
+ if (!visitor.visit(file, estimate))
+ return false;
+ }
+ }
+ else if (file.isDirectory())
+ {
+ File files[] = file.listFiles();
+ if (files != null)
+ {
+ for (int i = 0; i < files.length; i++)
+ {
+ File child = files[i];
+ if (ON_MAC_OS_X && child.isDirectory())
+ {
+ String name = child.getName();
+ if (name.equalsIgnoreCase("automount")
+ || name.equalsIgnoreCase("private")
+ || name.equalsIgnoreCase("Network")
+ || name.equalsIgnoreCase("Volumes"))
+ {
+ continue;
+ // return true;
+ }
+ }
- if (!traverse(child, mode, visitor, estimate
- + estimateIncrement * i / files.length,
- estimateIncrement / files.length))
- return false;
- }
- }
+ if (!traverse(child, mode, visitor, estimate
+ + estimateIncrement * i / files.length,
+ estimateIncrement / files.length))
+ return false;
+ }
+ }
- if ((mode == MODE_FOLDERS) || (mode == MODE_FILES_AND_FOLDERS)
- || (mode == MODE_ALL))
- {
- if (!visitor.visit(file, estimate))
- return false;
- }
- }
- else
- {
- if (mode == MODE_ALL)
- {
- if (!visitor.visit(file, estimate))
- return false;
- }
- }
+ if ((mode == MODE_FOLDERS) || (mode == MODE_FILES_AND_FOLDERS)
+ || (mode == MODE_ALL))
+ {
+ if (!visitor.visit(file, estimate))
+ return false;
+ }
+ }
+ else
+ {
+ if (mode == MODE_ALL)
+ {
+ if (!visitor.visit(file, estimate))
+ return false;
+ }
+ }
- return true;
- }
+ return true;
+ }
- public boolean traverseFiles(Visitor visitor)
- {
+ public boolean traverseFiles(Visitor visitor)
+ {
- return traverse(MODE_FILES, visitor);
- }
+ return traverse(MODE_FILES, visitor);
+ }
- public boolean traverseFolders(Visitor visitor)
- {
+ public boolean traverseFolders(Visitor visitor)
+ {
- return traverse(MODE_FOLDERS, visitor);
- }
+ return traverse(MODE_FOLDERS, visitor);
+ }
- public boolean traverseAll(Visitor visitor)
- {
+ public boolean traverseAll(Visitor visitor)
+ {
- return traverse(MODE_FILES_AND_FOLDERS, visitor);
- }
+ return traverse(MODE_FILES_AND_FOLDERS, visitor);
+ }
- public boolean traverse(int mode, Visitor visitor)
- {
- return traverse(mode, visitor, 0, 1);
- }
+ public boolean traverse(int mode, Visitor visitor)
+ {
+ return traverse(mode, visitor, 0, 1);
+ }
- private static boolean ON_MAC_OS_X;
+ private static boolean ON_MAC_OS_X;
- static
- {
- try
- {
- ON_MAC_OS_X = (System.getProperty("mrj.version") != null);
- }
- catch (Exception e)
- {
- Debug.debug(e);
+ static
+ {
+ try
+ {
+ ON_MAC_OS_X = (System.getProperty("mrj.version") != null);
+ }
+ catch (Exception e)
+ {
+ Debug.debug(e);
- ON_MAC_OS_X = false;
- }
- }
+ ON_MAC_OS_X = false;
+ }
+ }
- private boolean traverse(int mode, Visitor visitor, double estimate,
- double estimateIncrement)
- {
- File roots[] = File.listRoots();
+ private boolean traverse(int mode, Visitor visitor, double estimate,
+ double estimateIncrement)
+ {
+ File roots[] = File.listRoots();
- if (ON_MAC_OS_X)
- {
- File Volumes = new File("/Volumes/");
- roots = Volumes.listFiles();
- }
- else
- roots = File.listRoots();
+ if (ON_MAC_OS_X)
+ {
+ File Volumes = new File("/Volumes/");
+ roots = Volumes.listFiles();
+ }
+ else
+ roots = File.listRoots();
- if (roots == null)
- return false;
+ if (roots == null)
+ return false;
- for (int i = 0; i < roots.length; i++)
- {
- File root = roots[i];
+ for (int i = 0; i < roots.length; i++)
+ {
+ File root = roots[i];
- if (root == null || !root.exists())
- continue;
+ if (root == null || !root.exists())
+ continue;
- if (!traverse(roots[i], mode, visitor, estimate + estimateIncrement
- * i / roots.length, estimateIncrement / roots.length))
- return false;
- }
+ if (!traverse(roots[i], mode, visitor, estimate + estimateIncrement
+ * i / roots.length, estimateIncrement / roots.length))
+ return false;
+ }
- return true;
- }
+ return true;
+ }
}
\ No newline at end of file