You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by da...@apache.org on 2012/05/26 23:19:22 UTC

svn commit: r1342971 [13/20] - in /commons/proper/imaging/trunk/src: main/java/org/apache/commons/imaging/formats/bmp/ main/java/org/apache/commons/imaging/formats/bmp/pixelparsers/ main/java/org/apache/commons/imaging/formats/bmp/writers/ main/java/or...

Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/write/TiffImageWriterBase.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/write/TiffImageWriterBase.java?rev=1342971&r1=1342970&r2=1342971&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/write/TiffImageWriterBase.java (original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/write/TiffImageWriterBase.java Sat May 26 21:19:03 2012
@@ -41,23 +41,19 @@ import org.apache.commons.imaging.format
 import org.apache.commons.imaging.formats.tiff.constants.TiffTagConstants;
 
 public abstract class TiffImageWriterBase implements TiffConstants,
-        BinaryConstants
-{
+        BinaryConstants {
 
     protected final int byteOrder;
 
-    public TiffImageWriterBase()
-    {
+    public TiffImageWriterBase() {
         this.byteOrder = DEFAULT_TIFF_BYTE_ORDER;
     }
 
-    public TiffImageWriterBase(int byteOrder)
-    {
+    public TiffImageWriterBase(int byteOrder) {
         this.byteOrder = byteOrder;
     }
 
-    protected final static int imageDataPaddingLength(int dataLength)
-    {
+    protected final static int imageDataPaddingLength(int dataLength) {
         return (4 - (dataLength % 4)) % 4;
     }
 
@@ -65,8 +61,7 @@ public abstract class TiffImageWriterBas
             throws IOException, ImageWriteException;
 
     protected TiffOutputSummary validateDirectories(TiffOutputSet outputSet)
-            throws ImageWriteException
-    {
+            throws ImageWriteException {
         List<TiffOutputDirectory> directories = outputSet.getDirectories();
 
         if (1 > directories.size())
@@ -81,19 +76,15 @@ public abstract class TiffImageWriterBas
 
         List<Integer> directoryIndices = new ArrayList<Integer>();
         Map<Integer, TiffOutputDirectory> directoryTypeMap = new HashMap<Integer, TiffOutputDirectory>();
-        for (int i = 0; i < directories.size(); i++)
-        {
-            TiffOutputDirectory directory = directories
-                    .get(i);
+        for (int i = 0; i < directories.size(); i++) {
+            TiffOutputDirectory directory = directories.get(i);
             final int dirType = directory.type;
             directoryTypeMap.put(dirType, directory);
             // Debug.debug("validating dirType", dirType + " ("
             // + directory.getFields().size() + " fields)");
 
-            if (dirType < 0)
-            {
-                switch (dirType)
-                {
+            if (dirType < 0) {
+                switch (dirType) {
                 case DIRECTORY_TYPE_EXIF:
                     if (exifDirectory != null)
                         throw new ImageWriteException(
@@ -118,8 +109,7 @@ public abstract class TiffImageWriterBas
                     throw new ImageWriteException("Unknown directory: "
                             + dirType);
                 }
-            } else
-            {
+            } else {
                 if (directoryIndices.contains(dirType))
                     throw new ImageWriteException(
                             "More than one directory with index: " + dirType
@@ -130,8 +120,7 @@ public abstract class TiffImageWriterBas
 
             HashSet<Integer> fieldTags = new HashSet<Integer>();
             List fields = directory.getFields();
-            for (int j = 0; j < fields.size(); j++)
-            {
+            for (int j = 0; j < fields.size(); j++) {
                 TiffOutputField field = (TiffOutputField) fields.get(j);
 
                 if (fieldTags.contains(field.tag))
@@ -140,20 +129,17 @@ public abstract class TiffImageWriterBas
                             + ") appears twice in directory.");
                 fieldTags.add(field.tag);
 
-                if (field.tag == ExifTagConstants.EXIF_TAG_EXIF_OFFSET.tag)
-                {
+                if (field.tag == ExifTagConstants.EXIF_TAG_EXIF_OFFSET.tag) {
                     if (exifDirectoryOffsetField != null)
                         throw new ImageWriteException(
                                 "More than one Exif directory offset field.");
                     exifDirectoryOffsetField = field;
-                } else if (field.tag == ExifTagConstants.EXIF_TAG_INTEROP_OFFSET.tag)
-                {
+                } else if (field.tag == ExifTagConstants.EXIF_TAG_INTEROP_OFFSET.tag) {
                     if (interoperabilityDirectoryOffsetField != null)
                         throw new ImageWriteException(
                                 "More than one Interoperability directory offset field.");
                     interoperabilityDirectoryOffsetField = field;
-                } else if (field.tag == ExifTagConstants.EXIF_TAG_GPSINFO.tag)
-                {
+                } else if (field.tag == ExifTagConstants.EXIF_TAG_GPSINFO.tag) {
                     if (gpsDirectoryOffsetField != null)
                         throw new ImageWriteException(
                                 "More than one GPS directory offset field.");
@@ -171,15 +157,13 @@ public abstract class TiffImageWriterBas
         Collections.sort(directoryIndices);
 
         TiffOutputDirectory previousDirectory = null;
-        for (int i = 0; i < directoryIndices.size(); i++)
-        {
+        for (int i = 0; i < directoryIndices.size(); i++) {
             Integer index = directoryIndices.get(i);
             if (index.intValue() != i)
                 throw new ImageWriteException("Missing directory: " + i + ".");
 
             // set up chain of directory references for "normal" directories.
-            TiffOutputDirectory directory = directoryTypeMap
-                    .get(index);
+            TiffOutputDirectory directory = directoryTypeMap.get(index);
             if (null != previousDirectory)
                 previousDirectory.setNextDirectory(directory);
             previousDirectory = directory;
@@ -193,22 +177,20 @@ public abstract class TiffImageWriterBas
                 rootDirectory, directoryTypeMap);
 
         if (interoperabilityDirectory == null
-                && interoperabilityDirectoryOffsetField != null)
-        {
+                && interoperabilityDirectoryOffsetField != null) {
             // perhaps we should just discard field?
             throw new ImageWriteException(
                     "Output set has Interoperability Directory Offset field, but no Interoperability Directory");
-        } else if (interoperabilityDirectory != null)
-        {
-            if (exifDirectory == null)
-            {
+        } else if (interoperabilityDirectory != null) {
+            if (exifDirectory == null) {
                 exifDirectory = outputSet.addExifDirectory();
             }
 
-            if (interoperabilityDirectoryOffsetField == null)
-            {
+            if (interoperabilityDirectoryOffsetField == null) {
                 interoperabilityDirectoryOffsetField = TiffOutputField
-                        .createOffsetField(ExifTagConstants.EXIF_TAG_INTEROP_OFFSET, byteOrder);
+                        .createOffsetField(
+                                ExifTagConstants.EXIF_TAG_INTEROP_OFFSET,
+                                byteOrder);
                 exifDirectory.add(interoperabilityDirectoryOffsetField);
             }
 
@@ -217,15 +199,12 @@ public abstract class TiffImageWriterBas
         }
 
         // make sure offset fields and offset'd directories correspond.
-        if (exifDirectory == null && exifDirectoryOffsetField != null)
-        {
+        if (exifDirectory == null && exifDirectoryOffsetField != null) {
             // perhaps we should just discard field?
             throw new ImageWriteException(
                     "Output set has Exif Directory Offset field, but no Exif Directory");
-        } else if (exifDirectory != null)
-        {
-            if (exifDirectoryOffsetField == null)
-            {
+        } else if (exifDirectory != null) {
+            if (exifDirectoryOffsetField == null) {
                 exifDirectoryOffsetField = TiffOutputField.createOffsetField(
                         ExifTagConstants.EXIF_TAG_EXIF_OFFSET, byteOrder);
                 rootDirectory.add(exifDirectoryOffsetField);
@@ -234,15 +213,12 @@ public abstract class TiffImageWriterBas
             result.add(exifDirectory, exifDirectoryOffsetField);
         }
 
-        if (gpsDirectory == null && gpsDirectoryOffsetField != null)
-        {
+        if (gpsDirectory == null && gpsDirectoryOffsetField != null) {
             // perhaps we should just discard field?
             throw new ImageWriteException(
                     "Output set has GPS Directory Offset field, but no GPS Directory");
-        } else if (gpsDirectory != null)
-        {
-            if (gpsDirectoryOffsetField == null)
-            {
+        } else if (gpsDirectory != null) {
+            if (gpsDirectoryOffsetField == null) {
                 gpsDirectoryOffsetField = TiffOutputField.createOffsetField(
                         ExifTagConstants.EXIF_TAG_GPSINFO, byteOrder);
                 rootDirectory.add(gpsDirectoryOffsetField);
@@ -257,29 +233,27 @@ public abstract class TiffImageWriterBas
     }
 
     public void writeImage(BufferedImage src, OutputStream os, Map params)
-            throws ImageWriteException, IOException
-    {
+            throws ImageWriteException, IOException {
         // make copy of params; we'll clear keys as we consume them.
         params = new HashMap(params);
 
         // clear format key.
         if (params.containsKey(PARAM_KEY_FORMAT))
             params.remove(PARAM_KEY_FORMAT);
-        
+
         TiffOutputSet userExif = null;
-        if (params.containsKey(PARAM_KEY_EXIF))
-        {
+        if (params.containsKey(PARAM_KEY_EXIF)) {
             userExif = (TiffOutputSet) params.remove(PARAM_KEY_EXIF);
         }
-        
+
         String xmpXml = null;
-        if (params.containsKey(PARAM_KEY_XMP_XML))
-        {
+        if (params.containsKey(PARAM_KEY_XMP_XML)) {
             xmpXml = (String) params.get(PARAM_KEY_XMP_XML);
             params.remove(PARAM_KEY_XMP_XML);
         }
-        
-        PixelDensity pixelDensity = (PixelDensity) params.remove(PARAM_KEY_PIXEL_DENSITY);
+
+        PixelDensity pixelDensity = (PixelDensity) params
+                .remove(PARAM_KEY_PIXEL_DENSITY);
         if (pixelDensity == null) {
             pixelDensity = PixelDensity.createFromPixelsPerInch(72, 72);
         }
@@ -288,11 +262,9 @@ public abstract class TiffImageWriterBas
         int height = src.getHeight();
 
         int compression = TIFF_COMPRESSION_LZW; // LZW is default
-        if (params.containsKey(PARAM_KEY_COMPRESSION))
-        {
+        if (params.containsKey(PARAM_KEY_COMPRESSION)) {
             Object value = params.get(PARAM_KEY_COMPRESSION);
-            if (value != null)
-            {
+            if (value != null) {
                 if (!(value instanceof Number))
                     throw new ImageWriteException(
                             "Invalid compression parameter: " + value);
@@ -303,8 +275,7 @@ public abstract class TiffImageWriterBas
         HashMap rawParams = new HashMap(params);
         params.remove(PARAM_KEY_T4_OPTIONS);
         params.remove(PARAM_KEY_T6_OPTIONS);
-        if (params.size() > 0)
-        {
+        if (params.size() > 0) {
             Object firstKey = params.keySet().iterator().next();
             throw new ImageWriteException("Unknown parameter: " + firstKey);
         }
@@ -312,8 +283,9 @@ public abstract class TiffImageWriterBas
         int samplesPerPixel;
         int bitsPerSample;
         int photometricInterpretation;
-        if (compression == TIFF_COMPRESSION_CCITT_1D || compression == TIFF_COMPRESSION_CCITT_GROUP_3 ||
-                compression == TIFF_COMPRESSION_CCITT_GROUP_4) {
+        if (compression == TIFF_COMPRESSION_CCITT_1D
+                || compression == TIFF_COMPRESSION_CCITT_GROUP_3
+                || compression == TIFF_COMPRESSION_CCITT_GROUP_4) {
             samplesPerPixel = 1;
             bitsPerSample = 1;
             photometricInterpretation = 0;
@@ -323,7 +295,6 @@ public abstract class TiffImageWriterBas
             photometricInterpretation = 2;
         }
 
-
         int rowsPerStrip = 64000 / (width * bitsPerSample * samplesPerPixel); // TODO:
         rowsPerStrip = Math.max(1, rowsPerStrip); // must have at least one.
 
@@ -338,11 +309,10 @@ public abstract class TiffImageWriterBas
 
         int t4Options = 0;
         int t6Options = 0;
-        if (compression == TIFF_COMPRESSION_CCITT_1D)
-        {
+        if (compression == TIFF_COMPRESSION_CCITT_1D) {
             for (int i = 0; i < strips.length; i++)
-                strips[i] = T4AndT6Compression.compressModifiedHuffman(strips[i], width,
-                        strips[i].length / ((width + 7) / 8));
+                strips[i] = T4AndT6Compression.compressModifiedHuffman(
+                        strips[i], width, strips[i].length / ((width + 7) / 8));
         } else if (compression == TIFF_COMPRESSION_CCITT_GROUP_3) {
             Integer t4Parameter = (Integer) rawParams.get(PARAM_KEY_T4_OPTIONS);
             if (t4Parameter != null) {
@@ -352,20 +322,22 @@ public abstract class TiffImageWriterBas
             boolean is2D = (t4Options & 1) != 0;
             boolean usesUncompressedMode = (t4Options & 2) != 0;
             if (usesUncompressedMode) {
-                throw new ImageWriteException("T.4 compression with the uncompressed mode extension is not yet supported");
+                throw new ImageWriteException(
+                        "T.4 compression with the uncompressed mode extension is not yet supported");
             }
             boolean hasFillBitsBeforeEOL = (t4Options & 4) != 0;
             for (int i = 0; i < strips.length; i++) {
                 if (is2D) {
-                    strips[i] = T4AndT6Compression.compressT4_2D(strips[i], width,
-                            strips[i].length / ((width + 7) / 8), hasFillBitsBeforeEOL, rowsPerStrip);
+                    strips[i] = T4AndT6Compression.compressT4_2D(strips[i],
+                            width, strips[i].length / ((width + 7) / 8),
+                            hasFillBitsBeforeEOL, rowsPerStrip);
                 } else {
-                    strips[i] = T4AndT6Compression.compressT4_1D(strips[i], width,
-                            strips[i].length / ((width + 7) / 8), hasFillBitsBeforeEOL);
+                    strips[i] = T4AndT6Compression.compressT4_1D(strips[i],
+                            width, strips[i].length / ((width + 7) / 8),
+                            hasFillBitsBeforeEOL);
                 }
             }
-        } else if (compression == TIFF_COMPRESSION_CCITT_GROUP_4)
-        {
+        } else if (compression == TIFF_COMPRESSION_CCITT_GROUP_4) {
             Integer t6Parameter = (Integer) rawParams.get(PARAM_KEY_T6_OPTIONS);
             if (t6Parameter != null) {
                 t6Options = t6Parameter.intValue();
@@ -373,19 +345,17 @@ public abstract class TiffImageWriterBas
             t6Options &= 0x4;
             boolean usesUncompressedMode = (t6Options & TIFF_FLAG_T6_OPTIONS_UNCOMPRESSED_MODE) != 0;
             if (usesUncompressedMode) {
-                throw new ImageWriteException("T.6 compression with the uncompressed mode extension is not yet supported");
+                throw new ImageWriteException(
+                        "T.6 compression with the uncompressed mode extension is not yet supported");
             }
             for (int i = 0; i < strips.length; i++)
                 strips[i] = T4AndT6Compression.compressT6(strips[i], width,
                         strips[i].length / ((width + 7) / 8));
-        } else if (compression == TIFF_COMPRESSION_PACKBITS)
-        {
+        } else if (compression == TIFF_COMPRESSION_PACKBITS) {
             for (int i = 0; i < strips.length; i++)
                 strips[i] = new PackBits().compress(strips[i]);
-        } else if (compression == TIFF_COMPRESSION_LZW)
-        {
-            for (int i = 0; i < strips.length; i++)
-            {
+        } else if (compression == TIFF_COMPRESSION_LZW) {
+            for (int i = 0; i < strips.length; i++) {
                 byte uncompressed[] = strips[i];
 
                 int LZW_MINIMUM_CODE_SIZE = 8;
@@ -396,8 +366,7 @@ public abstract class TiffImageWriterBas
 
                 strips[i] = compressed;
             }
-        } else if (compression == TIFF_COMPRESSION_UNCOMPRESSED)
-        {
+        } else if (compression == TIFF_COMPRESSION_UNCOMPRESSED) {
             // do nothing.
         } else
             throw new ImageWriteException(
@@ -417,17 +386,20 @@ public abstract class TiffImageWriterBas
 
             directory.add(TiffTagConstants.TIFF_TAG_IMAGE_WIDTH, width);
             directory.add(TiffTagConstants.TIFF_TAG_IMAGE_LENGTH, height);
-            directory.add(TiffTagConstants.TIFF_TAG_PHOTOMETRIC_INTERPRETATION, (short)photometricInterpretation);
-            directory.add(TiffTagConstants.TIFF_TAG_COMPRESSION, (short)compression);
-            directory.add(TiffTagConstants.TIFF_TAG_SAMPLES_PER_PIXEL, (short)samplesPerPixel);
-            
-            if (samplesPerPixel == 3)
-            {
-                directory.add(TiffTagConstants.TIFF_TAG_BITS_PER_SAMPLE, (short)bitsPerSample,
-                        (short)bitsPerSample, (short)bitsPerSample);
-            } else if (samplesPerPixel == 1)
-            {
-                directory.add(TiffTagConstants.TIFF_TAG_BITS_PER_SAMPLE, (short)bitsPerSample);
+            directory.add(TiffTagConstants.TIFF_TAG_PHOTOMETRIC_INTERPRETATION,
+                    (short) photometricInterpretation);
+            directory.add(TiffTagConstants.TIFF_TAG_COMPRESSION,
+                    (short) compression);
+            directory.add(TiffTagConstants.TIFF_TAG_SAMPLES_PER_PIXEL,
+                    (short) samplesPerPixel);
+
+            if (samplesPerPixel == 3) {
+                directory.add(TiffTagConstants.TIFF_TAG_BITS_PER_SAMPLE,
+                        (short) bitsPerSample, (short) bitsPerSample,
+                        (short) bitsPerSample);
+            } else if (samplesPerPixel == 1) {
+                directory.add(TiffTagConstants.TIFF_TAG_BITS_PER_SAMPLE,
+                        (short) bitsPerSample);
             }
             // {
             // stripOffsetsField = new WriteField(TIFF_TAG_STRIP_OFFSETS,
@@ -442,25 +414,35 @@ public abstract class TiffImageWriterBas
             // WRITE_BYTE_ORDER));
             // directory.add(field);
             // }
-            directory.add(TiffTagConstants.TIFF_TAG_ROWS_PER_STRIP, rowsPerStrip);
+            directory.add(TiffTagConstants.TIFF_TAG_ROWS_PER_STRIP,
+                    rowsPerStrip);
             if (pixelDensity.isUnitless()) {
-                directory.add(TiffTagConstants.TIFF_TAG_RESOLUTION_UNIT, (short)0);
+                directory.add(TiffTagConstants.TIFF_TAG_RESOLUTION_UNIT,
+                        (short) 0);
                 directory.add(TiffTagConstants.TIFF_TAG_XRESOLUTION,
-                        RationalNumberUtilities.getRationalNumber(pixelDensity.getRawHorizontalDensity()));
+                        RationalNumberUtilities.getRationalNumber(pixelDensity
+                                .getRawHorizontalDensity()));
                 directory.add(TiffTagConstants.TIFF_TAG_YRESOLUTION,
-                        RationalNumberUtilities.getRationalNumber(pixelDensity.getRawVerticalDensity()));
+                        RationalNumberUtilities.getRationalNumber(pixelDensity
+                                .getRawVerticalDensity()));
             } else if (pixelDensity.isInInches()) {
-                directory.add(TiffTagConstants.TIFF_TAG_RESOLUTION_UNIT, (short)2);
+                directory.add(TiffTagConstants.TIFF_TAG_RESOLUTION_UNIT,
+                        (short) 2);
                 directory.add(TiffTagConstants.TIFF_TAG_XRESOLUTION,
-                        RationalNumberUtilities.getRationalNumber(pixelDensity.horizontalDensityInches()));
+                        RationalNumberUtilities.getRationalNumber(pixelDensity
+                                .horizontalDensityInches()));
                 directory.add(TiffTagConstants.TIFF_TAG_YRESOLUTION,
-                        RationalNumberUtilities.getRationalNumber(pixelDensity.verticalDensityInches()));
+                        RationalNumberUtilities.getRationalNumber(pixelDensity
+                                .verticalDensityInches()));
             } else {
-                directory.add(TiffTagConstants.TIFF_TAG_RESOLUTION_UNIT, (short)1);
+                directory.add(TiffTagConstants.TIFF_TAG_RESOLUTION_UNIT,
+                        (short) 1);
                 directory.add(TiffTagConstants.TIFF_TAG_XRESOLUTION,
-                        RationalNumberUtilities.getRationalNumber(pixelDensity.horizontalDensityCentimetres()));
+                        RationalNumberUtilities.getRationalNumber(pixelDensity
+                                .horizontalDensityCentimetres()));
                 directory.add(TiffTagConstants.TIFF_TAG_YRESOLUTION,
-                        RationalNumberUtilities.getRationalNumber(pixelDensity.verticalDensityCentimetres()));
+                        RationalNumberUtilities.getRationalNumber(pixelDensity
+                                .verticalDensityCentimetres()));
             }
             if (t4Options != 0) {
                 directory.add(TiffTagConstants.TIFF_TAG_T4_OPTIONS, t4Options);
@@ -469,9 +451,7 @@ public abstract class TiffImageWriterBas
                 directory.add(TiffTagConstants.TIFF_TAG_T6_OPTIONS, t6Options);
             }
 
-
-            if (null != xmpXml)
-            {
+            if (null != xmpXml) {
                 byte xmpXmlBytes[] = xmpXml.getBytes("utf-8");
                 directory.add(TiffTagConstants.TIFF_TAG_XMP, xmpXmlBytes);
             }
@@ -481,16 +461,18 @@ public abstract class TiffImageWriterBas
         TiffImageData tiffImageData = new TiffImageData.Strips(imageData,
                 rowsPerStrip);
         directory.setTiffImageData(tiffImageData);
-        
+
         if (userExif != null) {
             combineUserExifIntoFinalExif(userExif, outputSet);
         }
 
         write(os, outputSet);
     }
-    
-    private void combineUserExifIntoFinalExif(TiffOutputSet userExif, TiffOutputSet outputSet) throws ImageWriteException {
-        List<TiffOutputDirectory> outputDirectories = outputSet.getDirectories();
+
+    private void combineUserExifIntoFinalExif(TiffOutputSet userExif,
+            TiffOutputSet outputSet) throws ImageWriteException {
+        List<TiffOutputDirectory> outputDirectories = outputSet
+                .getDirectories();
         Collections.sort(outputDirectories, TiffOutputDirectory.COMPARATOR);
         for (TiffOutputDirectory userDirectory : userExif.getDirectories()) {
             int location = Collections.binarySearch(outputDirectories,
@@ -498,7 +480,8 @@ public abstract class TiffImageWriterBas
             if (location < 0) {
                 outputSet.addDirectory(userDirectory);
             } else {
-                TiffOutputDirectory outputDirectory = outputDirectories.get(location);
+                TiffOutputDirectory outputDirectory = outputDirectories
+                        .get(location);
                 for (TiffOutputField userField : userDirectory.getFields()) {
                     if (outputDirectory.findField(userField.tagInfo) == null) {
                         outputDirectory.add(userField);
@@ -509,8 +492,7 @@ public abstract class TiffImageWriterBas
     }
 
     private byte[][] getStrips(BufferedImage src, int samplesPerPixel,
-            int bitsPerSample, int rowsPerStrip)
-    {
+            int bitsPerSample, int rowsPerStrip) {
         int width = src.getWidth();
         int height = src.getHeight();
 
@@ -522,8 +504,7 @@ public abstract class TiffImageWriterBas
 
             int remaining_rows = height;
 
-            for (int i = 0; i < stripCount; i++)
-            {
+            for (int i = 0; i < stripCount; i++) {
                 int rowsInStrip = Math.min(rowsPerStrip, remaining_rows);
                 remaining_rows -= rowsInStrip;
 
@@ -537,19 +518,16 @@ public abstract class TiffImageWriterBas
                 int y = i * rowsPerStrip;
                 int stop = i * rowsPerStrip + rowsPerStrip;
 
-                for (; (y < height) && (y < stop); y++)
-                {
+                for (; (y < height) && (y < stop); y++) {
                     int bitCache = 0;
                     int bitsInCache = 0;
-                    for (int x = 0; x < width; x++)
-                    {
+                    for (int x = 0; x < width; x++) {
                         int rgb = src.getRGB(x, y);
                         int red = 0xff & (rgb >> 16);
                         int green = 0xff & (rgb >> 8);
                         int blue = 0xff & (rgb >> 0);
 
-                        if (bitsPerSample == 1)
-                        {
+                        if (bitsPerSample == 1) {
                             int sample = (red + green + blue) / 3;
                             if (sample > 127)
                                 sample = 0;
@@ -558,22 +536,18 @@ public abstract class TiffImageWriterBas
                             bitCache <<= 1;
                             bitCache |= sample;
                             bitsInCache++;
-                            if (bitsInCache == 8)
-                            {
+                            if (bitsInCache == 8) {
                                 uncompressed[counter++] = (byte) bitCache;
                                 bitCache = 0;
                                 bitsInCache = 0;
                             }
-                        }
-                        else
-                        {
+                        } else {
                             uncompressed[counter++] = (byte) red;
                             uncompressed[counter++] = (byte) green;
                             uncompressed[counter++] = (byte) blue;
                         }
                     }
-                    if (bitsInCache > 0)
-                    {
+                    if (bitsInCache > 0) {
                         bitCache <<= (8 - bitsInCache);
                         uncompressed[counter++] = (byte) bitCache;
                     }
@@ -588,16 +562,14 @@ public abstract class TiffImageWriterBas
     }
 
     protected void writeImageFileHeader(BinaryOutputStream bos)
-            throws IOException
-    {
+            throws IOException {
         int offsetToFirstIFD = TIFF_HEADER_SIZE;
 
         writeImageFileHeader(bos, offsetToFirstIFD);
     }
 
     protected void writeImageFileHeader(BinaryOutputStream bos,
-            int offsetToFirstIFD) throws IOException
-    {
+            int offsetToFirstIFD) throws IOException {
         bos.write(byteOrder);
         bos.write(byteOrder);
 

Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/write/TiffImageWriterLossless.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/write/TiffImageWriterLossless.java?rev=1342971&r1=1342970&r2=1342971&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/write/TiffImageWriterLossless.java (original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/write/TiffImageWriterLossless.java Sat May 26 21:19:03 2012
@@ -41,76 +41,66 @@ import org.apache.commons.imaging.format
 import org.apache.commons.imaging.formats.tiff.constants.ExifTagConstants;
 import org.apache.commons.imaging.util.Debug;
 
-public class TiffImageWriterLossless extends TiffImageWriterBase
-{
+public class TiffImageWriterLossless extends TiffImageWriterBase {
     private final byte exifBytes[];
 
-    public TiffImageWriterLossless(byte exifBytes[])
-    {
+    public TiffImageWriterLossless(byte exifBytes[]) {
         this.exifBytes = exifBytes;
     }
 
-    public TiffImageWriterLossless(int byteOrder, byte exifBytes[])
-    {
+    public TiffImageWriterLossless(int byteOrder, byte exifBytes[]) {
         super(byteOrder);
         this.exifBytes = exifBytes;
     }
 
-    //    private static class TiffPiece
-    //    {
-    //        public final int offset;
-    //        public final int length;
+    // private static class TiffPiece
+    // {
+    // public final int offset;
+    // public final int length;
     //
-    //        public TiffPiece(final int offset, final int length)
-    //        {
-    //            this.offset = offset;
-    //            this.length = length;
-    //        }
-    //    }
-
-    private void dumpElements(List<TiffElement> elements) throws IOException
-    {
-        //        try
-        //        {
+    // public TiffPiece(final int offset, final int length)
+    // {
+    // this.offset = offset;
+    // this.length = length;
+    // }
+    // }
+
+    private void dumpElements(List<TiffElement> elements) throws IOException {
+        // try
+        // {
         ByteSource byteSource = new ByteSourceArray(exifBytes);
 
         dumpElements(byteSource, elements);
-        //        }
-        //        catch (ImageReadException e)
-        //        {
-        //            throw new ImageWriteException(e.getMessage(), e);
-        //        }
+        // }
+        // catch (ImageReadException e)
+        // {
+        // throw new ImageWriteException(e.getMessage(), e);
+        // }
     }
 
     private void dumpElements(ByteSource byteSource, List<TiffElement> elements)
-            throws IOException
-    {
+            throws IOException {
         int last = TIFF_HEADER_SIZE;
-        for (int i = 0; i < elements.size(); i++)
-        {
+        for (int i = 0; i < elements.size(); i++) {
             TiffElement element = elements.get(i);
-            if (element.offset > last)
-            {
+            if (element.offset > last) {
                 final int SLICE_SIZE = 32;
                 int gepLength = element.offset - last;
                 Debug.debug("gap of " + gepLength + " bytes.");
                 byte bytes[] = byteSource.getBlock(last, gepLength);
-                if (bytes.length > 2 * SLICE_SIZE)
-                {
-                    Debug.debug("\t" + "head", BinaryFileFunctions.head(bytes,
-                            SLICE_SIZE));
-                    Debug.debug("\t" + "tail", BinaryFileFunctions.tail(bytes,
-                            SLICE_SIZE));
-                }
-                else
+                if (bytes.length > 2 * SLICE_SIZE) {
+                    Debug.debug("\t" + "head",
+                            BinaryFileFunctions.head(bytes, SLICE_SIZE));
+                    Debug.debug("\t" + "tail",
+                            BinaryFileFunctions.tail(bytes, SLICE_SIZE));
+                } else
                     Debug.debug("\t" + "bytes", bytes);
             }
 
             Debug.debug("element[" + i + "]:" + element.getElementDescription()
                     + " (" + element.offset + " + " + element.length + " = "
                     + (element.offset + element.length) + ")");
-            if (element instanceof TiffDirectory)
-            {
+            if (element instanceof TiffDirectory) {
                 TiffDirectory dir = (TiffDirectory) element;
                 Debug.debug("\t" + "next Directory Offset: "
                         + dir.nextDirectoryOffset);
@@ -120,28 +110,25 @@ public class TiffImageWriterLossless ext
         Debug.debug();
     }
 
-    private List<TiffElement> analyzeOldTiff() throws ImageWriteException, IOException
-    {
-        try
-        {
+    private List<TiffElement> analyzeOldTiff() throws ImageWriteException,
+            IOException {
+        try {
             ByteSource byteSource = new ByteSourceArray(exifBytes);
             Map params = null;
             FormatCompliance formatCompliance = FormatCompliance.getDefault();
-            TiffContents contents = new TiffReader(false).readContents(byteSource,
-                    params, formatCompliance);
+            TiffContents contents = new TiffReader(false).readContents(
+                    byteSource, params, formatCompliance);
 
             List<TiffElement> elements = new ArrayList<TiffElement>();
-            //            result.add(contents.header); // ?
+            // result.add(contents.header); // ?
 
             List<TiffDirectory> directories = contents.directories;
-            for (int d = 0; d < directories.size(); d++)
-            {
+            for (int d = 0; d < directories.size(); d++) {
                 TiffDirectory directory = directories.get(d);
                 elements.add(directory);
 
                 List<TiffField> fields = directory.getDirectoryEntrys();
-                for (int f = 0; f < fields.size(); f++)
-                {
+                for (int f = 0; f < fields.size(); f++) {
                     TiffField field = fields.get(f);
                     if (field.tag == ExifTagConstants.EXIF_TAG_MAKER_NOTE.tag) {
                         // Some maker notes reference values stored
@@ -167,8 +154,7 @@ public class TiffImageWriterLossless ext
                     elements.add(jpegImageData);
 
                 TiffImageData tiffImageData = directory.getTiffImageData();
-                if (tiffImageData != null)
-                {
+                if (tiffImageData != null) {
                     TiffElement.DataElement data[] = tiffImageData
                             .getImageData();
                     for (int i = 0; i < data.length; i++)
@@ -178,32 +164,26 @@ public class TiffImageWriterLossless ext
 
             Collections.sort(elements, TiffElement.COMPARATOR);
 
-            //            dumpElements(byteSource, elements);
+            // dumpElements(byteSource, elements);
 
             List<TiffElement> result = new ArrayList<TiffElement>();
             {
                 final int TOLERANCE = 3;
-                //                int last = TIFF_HEADER_SIZE;
+                // int last = TIFF_HEADER_SIZE;
                 TiffElement start = null;
                 int index = -1;
-                for (int i = 0; i < elements.size(); i++)
-                {
+                for (int i = 0; i < elements.size(); i++) {
                     TiffElement element = elements.get(i);
                     int lastElementByte = element.offset + element.length;
-                    if (start == null)
-                    {
+                    if (start == null) {
                         start = element;
                         index = lastElementByte;
-                    }
-                    else if (element.offset - index > TOLERANCE)
-                    {
+                    } else if (element.offset - index > TOLERANCE) {
                         result.add(new TiffElement.Stub(start.offset, index
                                 - start.offset));
                         start = element;
                         index = lastElementByte;
-                    }
-                    else
-                    {
+                    } else {
                         index = lastElementByte;
                     }
                 }
@@ -212,49 +192,45 @@ public class TiffImageWriterLossless ext
                             - start.offset));
             }
 
-            //            dumpElements(byteSource, result);
+            // dumpElements(byteSource, result);
 
             return result;
-        }
-        catch (ImageReadException e)
-        {
+        } catch (ImageReadException e) {
             throw new ImageWriteException(e.getMessage(), e);
         }
     }
 
     @Override
     public void write(OutputStream os, TiffOutputSet outputSet)
-            throws IOException, ImageWriteException
-    {
+            throws IOException, ImageWriteException {
         List<TiffElement> analysis = analyzeOldTiff();
         int oldLength = exifBytes.length;
         if (analysis.size() < 1)
             throw new ImageWriteException("Couldn't analyze old tiff data.");
-        else if (analysis.size() == 1)
-        {
+        else if (analysis.size() == 1) {
             TiffElement onlyElement = analysis.get(0);
-            //            Debug.debug("onlyElement", onlyElement.getElementDescription());
+            // Debug.debug("onlyElement", onlyElement.getElementDescription());
             if (onlyElement.offset == TIFF_HEADER_SIZE
                     && onlyElement.offset + onlyElement.length
-                            + TIFF_HEADER_SIZE == oldLength)
-            {
+                            + TIFF_HEADER_SIZE == oldLength) {
                 // no gaps in old data, safe to complete overwrite.
                 new TiffImageWriterLossy(byteOrder).write(os, outputSet);
                 return;
             }
         }
 
-        //        if (true)
-        //            throw new ImageWriteException("hahah");
+        // if (true)
+        // throw new ImageWriteException("hahah");
 
-        //        List directories = outputSet.getDirectories();
+        // List directories = outputSet.getDirectories();
 
         TiffOutputSummary outputSummary = validateDirectories(outputSet);
 
-        List<TiffOutputItem> outputItems = outputSet.getOutputItems(outputSummary);
+        List<TiffOutputItem> outputItems = outputSet
+                .getOutputItems(outputSummary);
 
         int outputLength = updateOffsetsStep(analysis, outputItems);
-        //        Debug.debug("outputLength", outputLength);
+        // Debug.debug("outputLength", outputLength);
 
         outputSummary.updateOffsets(byteOrder);
 
@@ -262,24 +238,20 @@ public class TiffImageWriterLossless ext
 
     }
 
-    private static final Comparator<TiffElement> ELEMENT_SIZE_COMPARATOR = new Comparator<TiffElement>()
-    {
-        public int compare(TiffElement e1, TiffElement e2)
-        {
+    private static final Comparator<TiffElement> ELEMENT_SIZE_COMPARATOR = new Comparator<TiffElement>() {
+        public int compare(TiffElement e1, TiffElement e2) {
             return e1.length - e2.length;
         }
     };
 
-    private static final Comparator<TiffOutputItem> ITEM_SIZE_COMPARATOR = new Comparator<TiffOutputItem>()
-    {
-        public int compare(TiffOutputItem e1, TiffOutputItem e2)
-        {
+    private static final Comparator<TiffOutputItem> ITEM_SIZE_COMPARATOR = new Comparator<TiffOutputItem>() {
+        public int compare(TiffOutputItem e1, TiffOutputItem e2) {
             return e1.getItemLength() - e2.getItemLength();
         }
     };
 
-    private int updateOffsetsStep(List<TiffElement> analysis, List<TiffOutputItem> outputItems)
-    {
+    private int updateOffsetsStep(List<TiffElement> analysis,
+            List<TiffOutputItem> outputItems) {
         // items we cannot fit into a gap, we shall append to tail.
         int overflowIndex = exifBytes.length;
 
@@ -289,64 +261,58 @@ public class TiffImageWriterLossless ext
         // should already be in order of offset, but make sure.
         Collections.sort(unusedElements, TiffElement.COMPARATOR);
         Collections.reverse(unusedElements);
-        // any items that represent a gap at the end of the exif segment, can be discarded.
-        while (unusedElements.size() > 0)
-        {
+        // any items that represent a gap at the end of the exif segment, can be
+        // discarded.
+        while (unusedElements.size() > 0) {
             TiffElement element = unusedElements.get(0);
             int elementEnd = element.offset + element.length;
-            if (elementEnd == overflowIndex)
-            {
-                // discarding a tail element.  should only happen once.
+            if (elementEnd == overflowIndex) {
+                // discarding a tail element. should only happen once.
                 overflowIndex -= element.length;
                 unusedElements.remove(0);
-            }
-            else
+            } else
                 break;
         }
 
         Collections.sort(unusedElements, ELEMENT_SIZE_COMPARATOR);
         Collections.reverse(unusedElements);
 
-        //        Debug.debug("unusedElements");
-        //        dumpElements(unusedElements);
+        // Debug.debug("unusedElements");
+        // dumpElements(unusedElements);
 
         // make copy.
-        List<TiffOutputItem> unplacedItems = new ArrayList<TiffOutputItem>(outputItems);
+        List<TiffOutputItem> unplacedItems = new ArrayList<TiffOutputItem>(
+                outputItems);
         Collections.sort(unplacedItems, ITEM_SIZE_COMPARATOR);
         Collections.reverse(unplacedItems);
 
-        while (unplacedItems.size() > 0)
-        {
+        while (unplacedItems.size() > 0) {
             // pop off largest unplaced item.
             TiffOutputItem outputItem = unplacedItems.remove(0);
             int outputItemLength = outputItem.getItemLength();
-            //            Debug.debug("largest unplaced item: "
-            //                    + outputItem.getItemDescription() + " (" + outputItemLength
-            //                    + ")");
+            // Debug.debug("largest unplaced item: "
+            // + outputItem.getItemDescription() + " (" + outputItemLength
+            // + ")");
 
-            // search for the smallest possible element large enough to hold the item.
+            // search for the smallest possible element large enough to hold the
+            // item.
             TiffElement bestFit = null;
-            for (int i = 0; i < unusedElements.size(); i++)
-            {
+            for (int i = 0; i < unusedElements.size(); i++) {
                 TiffElement element = unusedElements.get(i);
                 if (element.length >= outputItemLength)
                     bestFit = element;
                 else
                     break;
             }
-            if (null == bestFit)
-            {
-                // we couldn't place this item.  overflow.
+            if (null == bestFit) {
+                // we couldn't place this item. overflow.
                 outputItem.setOffset(overflowIndex);
                 overflowIndex += outputItemLength;
-            }
-            else
-            {
+            } else {
                 outputItem.setOffset(bestFit.offset);
                 unusedElements.remove(bestFit);
 
-                if (bestFit.length > outputItemLength)
-                {
+                if (bestFit.length > outputItemLength) {
                     // not a perfect fit.
                     int excessOffset = bestFit.offset + outputItemLength;
                     int excessLength = bestFit.length - outputItemLength;
@@ -361,38 +327,36 @@ public class TiffImageWriterLossless ext
 
         return overflowIndex;
         //
-        //        if (true)
-        //            throw new IOException("mew");
+        // if (true)
+        // throw new IOException("mew");
         //
-        //        //        int offset = TIFF_HEADER_SIZE;
-        //        int offset = exifBytes.length;
+        // // int offset = TIFF_HEADER_SIZE;
+        // int offset = exifBytes.length;
         //
-        //        for (int i = 0; i < outputItems.size(); i++)
-        //        {
-        //            TiffOutputItem outputItem = (TiffOutputItem) outputItems.get(i);
+        // for (int i = 0; i < outputItems.size(); i++)
+        // {
+        // TiffOutputItem outputItem = (TiffOutputItem) outputItems.get(i);
         //
-        //            outputItem.setOffset(offset);
-        //            int itemLength = outputItem.getItemLength();
-        //            offset += itemLength;
+        // outputItem.setOffset(offset);
+        // int itemLength = outputItem.getItemLength();
+        // offset += itemLength;
         //
-        //            int remainder = imageDataPaddingLength(itemLength);
-        //            offset += remainder;
-        //        }
+        // int remainder = imageDataPaddingLength(itemLength);
+        // offset += remainder;
+        // }
     }
-    private static class BufferOutputStream extends OutputStream
-    {
+
+    private static class BufferOutputStream extends OutputStream {
         private final byte buffer[];
         private int index;
 
-        public BufferOutputStream(final byte[] buffer, final int index)
-        {
+        public BufferOutputStream(final byte[] buffer, final int index) {
             this.buffer = buffer;
             this.index = index;
         }
 
         @Override
-        public void write(int b) throws IOException
-        {
+        public void write(int b) throws IOException {
             if (index >= buffer.length)
                 throw new IOException("Buffer overflow.");
 
@@ -400,8 +364,7 @@ public class TiffImageWriterLossless ext
         }
 
         @Override
-        public void write(byte b[], int off, int len) throws IOException
-        {
+        public void write(byte b[], int off, int len) throws IOException {
             if (index + len > buffer.length)
                 throw new IOException("Buffer overflow.");
             System.arraycopy(b, off, buffer, index, len);
@@ -410,19 +373,18 @@ public class TiffImageWriterLossless ext
     }
 
     private void writeStep(OutputStream os, TiffOutputSet outputSet,
-            List<TiffElement> analysis, List<TiffOutputItem> outputItems, int outputLength)
-            throws IOException, ImageWriteException
-    {
+            List<TiffElement> analysis, List<TiffOutputItem> outputItems,
+            int outputLength) throws IOException, ImageWriteException {
         TiffOutputDirectory rootDirectory = outputSet.getRootDirectory();
 
         byte output[] = new byte[outputLength];
 
         // copy old data (including maker notes, etc.)
-        System.arraycopy(exifBytes, 0, output, 0, Math.min(exifBytes.length,
-                output.length));
+        System.arraycopy(exifBytes, 0, output, 0,
+                Math.min(exifBytes.length, output.length));
 
-        //        bos.write(exifBytes, TIFF_HEADER_SIZE, exifBytes.length
-        //        - TIFF_HEADER_SIZE);
+        // bos.write(exifBytes, TIFF_HEADER_SIZE, exifBytes.length
+        // - TIFF_HEADER_SIZE);
 
         {
             BufferOutputStream tos = new BufferOutputStream(output, 0);
@@ -430,12 +392,11 @@ public class TiffImageWriterLossless ext
             writeImageFileHeader(bos, rootDirectory.getOffset());
         }
 
-        // zero out the parsed pieces of old exif segment, in case we don't overwrite them.
-        for (int i = 0; i < analysis.size(); i++)
-        {
+        // zero out the parsed pieces of old exif segment, in case we don't
+        // overwrite them.
+        for (int i = 0; i < analysis.size(); i++) {
             TiffElement element = analysis.get(i);
-            for (int j = 0; j < element.length; j++)
-            {
+            for (int j = 0; j < element.length; j++) {
                 int index = element.offset + j;
                 if (index < output.length)
                     output[index] = 0;
@@ -443,12 +404,11 @@ public class TiffImageWriterLossless ext
         }
 
         // write in the new items
-        for (int i = 0; i < outputItems.size(); i++)
-        {
+        for (int i = 0; i < outputItems.size(); i++) {
             TiffOutputItem outputItem = outputItems.get(i);
 
-            BufferOutputStream tos = new BufferOutputStream(output, outputItem
-                    .getOffset());
+            BufferOutputStream tos = new BufferOutputStream(output,
+                    outputItem.getOffset());
             BinaryOutputStream bos = new BinaryOutputStream(tos, byteOrder);
             outputItem.writeItem(bos);
         }

Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/write/TiffImageWriterLossy.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/write/TiffImageWriterLossy.java?rev=1342971&r1=1342970&r2=1342971&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/write/TiffImageWriterLossy.java (original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/write/TiffImageWriterLossy.java Sat May 26 21:19:03 2012
@@ -23,25 +23,22 @@ import java.util.List;
 import org.apache.commons.imaging.ImageWriteException;
 import org.apache.commons.imaging.common.BinaryOutputStream;
 
-public class TiffImageWriterLossy extends TiffImageWriterBase
-{
+public class TiffImageWriterLossy extends TiffImageWriterBase {
 
-    public TiffImageWriterLossy()
-    {
+    public TiffImageWriterLossy() {
     }
 
-    public TiffImageWriterLossy(int byteOrder)
-    {
+    public TiffImageWriterLossy(int byteOrder) {
         super(byteOrder);
     }
 
     @Override
     public void write(OutputStream os, TiffOutputSet outputSet)
-            throws IOException, ImageWriteException
-    {
+            throws IOException, ImageWriteException {
         TiffOutputSummary outputSummary = validateDirectories(outputSet);
 
-        List<TiffOutputItem> outputItems = outputSet.getOutputItems(outputSummary);
+        List<TiffOutputItem> outputItems = outputSet
+                .getOutputItems(outputSummary);
 
         updateOffsetsStep(outputItems);
 
@@ -52,12 +49,10 @@ public class TiffImageWriterLossy extend
         writeStep(bos, outputItems);
     }
 
-    private void updateOffsetsStep(List<TiffOutputItem> outputItems)
-    {
+    private void updateOffsetsStep(List<TiffOutputItem> outputItems) {
         int offset = TIFF_HEADER_SIZE;
 
-        for (int i = 0; i < outputItems.size(); i++)
-        {
+        for (int i = 0; i < outputItems.size(); i++) {
             TiffOutputItem outputItem = outputItems.get(i);
 
             outputItem.setOffset(offset);
@@ -69,13 +64,12 @@ public class TiffImageWriterLossy extend
         }
     }
 
-    private void writeStep(BinaryOutputStream bos, List<TiffOutputItem> outputItems)
-            throws IOException, ImageWriteException
-    {
+    private void writeStep(BinaryOutputStream bos,
+            List<TiffOutputItem> outputItems) throws IOException,
+            ImageWriteException {
         writeImageFileHeader(bos);
 
-        for (int i = 0; i < outputItems.size(); i++)
-        {
+        for (int i = 0; i < outputItems.size(); i++) {
             TiffOutputItem outputItem = outputItems.get(i);
 
             outputItem.writeItem(bos);

Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/write/TiffOutputDirectory.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/write/TiffOutputDirectory.java?rev=1342971&r1=1342970&r2=1342971&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/write/TiffOutputDirectory.java (original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/write/TiffOutputDirectory.java Sat May 26 21:19:03 2012
@@ -57,8 +57,7 @@ import org.apache.commons.imaging.format
 import org.apache.commons.imaging.formats.tiff.taginfos.TagInfoXpString;
 
 public final class TiffOutputDirectory extends TiffOutputItem implements
-        TiffConstants
-{
+        TiffConstants {
     public final int type;
     private final List<TiffOutputField> fields = new ArrayList<TiffOutputField>();
     private final int byteOrder;
@@ -75,304 +74,351 @@ public final class TiffOutputDirectory e
         }
     };
 
-    public void setNextDirectory(TiffOutputDirectory nextDirectory)
-    {
+    public void setNextDirectory(TiffOutputDirectory nextDirectory) {
         this.nextDirectory = nextDirectory;
     }
 
-    public TiffOutputDirectory(final int type, final int byteOrder)
-    {
+    public TiffOutputDirectory(final int type, final int byteOrder) {
         this.type = type;
         this.byteOrder = byteOrder;
     }
-    
-    public void add(TagInfoByte tagInfo, byte... values) throws ImageWriteException {
+
+    public void add(TagInfoByte tagInfo, byte... values)
+            throws ImageWriteException {
         if (tagInfo.length > 0 && tagInfo.length != values.length) {
-            throw new ImageWriteException("Tag expects " + tagInfo.length +
-                    " value(s), not " + values.length);
+            throw new ImageWriteException("Tag expects " + tagInfo.length
+                    + " value(s), not " + values.length);
         }
         byte[] bytes = tagInfo.encodeValue(byteOrder, values);
-        TiffOutputField tiffOutputField = new TiffOutputField(tagInfo.tag, tagInfo,
-                TiffFieldTypeConstants.FIELD_TYPE_BYTE, values.length, bytes);
+        TiffOutputField tiffOutputField = new TiffOutputField(tagInfo.tag,
+                tagInfo, TiffFieldTypeConstants.FIELD_TYPE_BYTE, values.length,
+                bytes);
         add(tiffOutputField);
     }
-    
-    public void add(TagInfoAscii tagInfo, String... values) throws ImageWriteException {
+
+    public void add(TagInfoAscii tagInfo, String... values)
+            throws ImageWriteException {
         byte[] bytes = tagInfo.encodeValue(byteOrder, values);
         if (tagInfo.length > 0 && tagInfo.length != bytes.length) {
-            throw new ImageWriteException("Tag expects " + tagInfo.length +
-                    " byte(s), not " + values.length);
+            throw new ImageWriteException("Tag expects " + tagInfo.length
+                    + " byte(s), not " + values.length);
         }
-        TiffOutputField tiffOutputField = new TiffOutputField(tagInfo.tag, tagInfo,
-                TiffFieldTypeConstants.FIELD_TYPE_ASCII, bytes.length, bytes);
+        TiffOutputField tiffOutputField = new TiffOutputField(tagInfo.tag,
+                tagInfo, TiffFieldTypeConstants.FIELD_TYPE_ASCII, bytes.length,
+                bytes);
         add(tiffOutputField);
     }
-    
-    public void add(TagInfoShort tagInfo, short... values) throws ImageWriteException {
+
+    public void add(TagInfoShort tagInfo, short... values)
+            throws ImageWriteException {
         if (tagInfo.length > 0 && tagInfo.length != values.length) {
-            throw new ImageWriteException("Tag expects " + tagInfo.length +
-                    " value(s), not " + values.length);
+            throw new ImageWriteException("Tag expects " + tagInfo.length
+                    + " value(s), not " + values.length);
         }
         byte[] bytes = tagInfo.encodeValue(byteOrder, values);
-        TiffOutputField tiffOutputField = new TiffOutputField(tagInfo.tag, tagInfo,
-                TiffFieldTypeConstants.FIELD_TYPE_SHORT, values.length, bytes);
+        TiffOutputField tiffOutputField = new TiffOutputField(tagInfo.tag,
+                tagInfo, TiffFieldTypeConstants.FIELD_TYPE_SHORT,
+                values.length, bytes);
         add(tiffOutputField);
     }
-    
-    public void add(TagInfoLong tagInfo, int... values) throws ImageWriteException {
+
+    public void add(TagInfoLong tagInfo, int... values)
+            throws ImageWriteException {
         if (tagInfo.length > 0 && tagInfo.length != values.length) {
-            throw new ImageWriteException("Tag expects " + tagInfo.length +
-                    " value(s), not " + values.length);
+            throw new ImageWriteException("Tag expects " + tagInfo.length
+                    + " value(s), not " + values.length);
         }
         byte[] bytes = tagInfo.encodeValue(byteOrder, values);
-        TiffOutputField tiffOutputField = new TiffOutputField(tagInfo.tag, tagInfo,
-                TiffFieldTypeConstants.FIELD_TYPE_LONG, values.length, bytes);
+        TiffOutputField tiffOutputField = new TiffOutputField(tagInfo.tag,
+                tagInfo, TiffFieldTypeConstants.FIELD_TYPE_LONG, values.length,
+                bytes);
         add(tiffOutputField);
     }
-    
-    public void add(TagInfoRational tagInfo, RationalNumber... values) throws ImageWriteException {
+
+    public void add(TagInfoRational tagInfo, RationalNumber... values)
+            throws ImageWriteException {
         if (tagInfo.length > 0 && tagInfo.length != values.length) {
-            throw new ImageWriteException("Tag expects " + tagInfo.length +
-                    " value(s), not " + values.length);
+            throw new ImageWriteException("Tag expects " + tagInfo.length
+                    + " value(s), not " + values.length);
         }
         byte[] bytes = tagInfo.encodeValue(byteOrder, values);
-        TiffOutputField tiffOutputField = new TiffOutputField(tagInfo.tag, tagInfo,
-                TiffFieldTypeConstants.FIELD_TYPE_RATIONAL, values.length, bytes);
+        TiffOutputField tiffOutputField = new TiffOutputField(tagInfo.tag,
+                tagInfo, TiffFieldTypeConstants.FIELD_TYPE_RATIONAL,
+                values.length, bytes);
         add(tiffOutputField);
     }
-    
-    public void add(TagInfoSByte tagInfo, byte... values) throws ImageWriteException {
+
+    public void add(TagInfoSByte tagInfo, byte... values)
+            throws ImageWriteException {
         if (tagInfo.length > 0 && tagInfo.length != values.length) {
-            throw new ImageWriteException("Tag expects " + tagInfo.length +
-                    " value(s), not " + values.length);
+            throw new ImageWriteException("Tag expects " + tagInfo.length
+                    + " value(s), not " + values.length);
         }
         byte[] bytes = tagInfo.encodeValue(byteOrder, values);
-        TiffOutputField tiffOutputField = new TiffOutputField(tagInfo.tag, tagInfo,
-                TiffFieldTypeConstants.FIELD_TYPE_SBYTE, values.length, bytes);
+        TiffOutputField tiffOutputField = new TiffOutputField(tagInfo.tag,
+                tagInfo, TiffFieldTypeConstants.FIELD_TYPE_SBYTE,
+                values.length, bytes);
         add(tiffOutputField);
     }
-    
-    public void add(TagInfoSShort tagInfo, short... values) throws ImageWriteException {
+
+    public void add(TagInfoSShort tagInfo, short... values)
+            throws ImageWriteException {
         if (tagInfo.length > 0 && tagInfo.length != values.length) {
-            throw new ImageWriteException("Tag expects " + tagInfo.length +
-                    " value(s), not " + values.length);
+            throw new ImageWriteException("Tag expects " + tagInfo.length
+                    + " value(s), not " + values.length);
         }
         byte[] bytes = tagInfo.encodeValue(byteOrder, values);
-        TiffOutputField tiffOutputField = new TiffOutputField(tagInfo.tag, tagInfo,
-                TiffFieldTypeConstants.FIELD_TYPE_SSHORT, values.length, bytes);
+        TiffOutputField tiffOutputField = new TiffOutputField(tagInfo.tag,
+                tagInfo, TiffFieldTypeConstants.FIELD_TYPE_SSHORT,
+                values.length, bytes);
         add(tiffOutputField);
     }
-    
-    public void add(TagInfoSLong tagInfo, int... values) throws ImageWriteException {
+
+    public void add(TagInfoSLong tagInfo, int... values)
+            throws ImageWriteException {
         if (tagInfo.length > 0 && tagInfo.length != values.length) {
-            throw new ImageWriteException("Tag expects " + tagInfo.length +
-                    " value(s), not " + values.length);
+            throw new ImageWriteException("Tag expects " + tagInfo.length
+                    + " value(s), not " + values.length);
         }
         byte[] bytes = tagInfo.encodeValue(byteOrder, values);
-        TiffOutputField tiffOutputField = new TiffOutputField(tagInfo.tag, tagInfo,
-                TiffFieldTypeConstants.FIELD_TYPE_SLONG, values.length, bytes);
+        TiffOutputField tiffOutputField = new TiffOutputField(tagInfo.tag,
+                tagInfo, TiffFieldTypeConstants.FIELD_TYPE_SLONG,
+                values.length, bytes);
         add(tiffOutputField);
     }
 
-    public void add(TagInfoSRational tagInfo, RationalNumber... values) throws ImageWriteException {
+    public void add(TagInfoSRational tagInfo, RationalNumber... values)
+            throws ImageWriteException {
         if (tagInfo.length > 0 && tagInfo.length != values.length) {
-            throw new ImageWriteException("Tag expects " + tagInfo.length +
-                    " value(s), not " + values.length);
+            throw new ImageWriteException("Tag expects " + tagInfo.length
+                    + " value(s), not " + values.length);
         }
         byte[] bytes = tagInfo.encodeValue(byteOrder, values);
-        TiffOutputField tiffOutputField = new TiffOutputField(tagInfo.tag, tagInfo,
-                TiffFieldTypeConstants.FIELD_TYPE_SRATIONAL, values.length, bytes);
+        TiffOutputField tiffOutputField = new TiffOutputField(tagInfo.tag,
+                tagInfo, TiffFieldTypeConstants.FIELD_TYPE_SRATIONAL,
+                values.length, bytes);
         add(tiffOutputField);
     }
-    
-    public void add(TagInfoFloat tagInfo, float... values) throws ImageWriteException {
+
+    public void add(TagInfoFloat tagInfo, float... values)
+            throws ImageWriteException {
         if (tagInfo.length > 0 && tagInfo.length != values.length) {
-            throw new ImageWriteException("Tag expects " + tagInfo.length +
-                    " value(s), not " + values.length);
+            throw new ImageWriteException("Tag expects " + tagInfo.length
+                    + " value(s), not " + values.length);
         }
         byte[] bytes = tagInfo.encodeValue(byteOrder, values);
-        TiffOutputField tiffOutputField = new TiffOutputField(tagInfo.tag, tagInfo,
-                TiffFieldTypeConstants.FIELD_TYPE_FLOAT, values.length, bytes);
+        TiffOutputField tiffOutputField = new TiffOutputField(tagInfo.tag,
+                tagInfo, TiffFieldTypeConstants.FIELD_TYPE_FLOAT,
+                values.length, bytes);
         add(tiffOutputField);
     }
 
-    public void add(TagInfoDouble tagInfo, double... values) throws ImageWriteException {
+    public void add(TagInfoDouble tagInfo, double... values)
+            throws ImageWriteException {
         if (tagInfo.length > 0 && tagInfo.length != values.length) {
-            throw new ImageWriteException("Tag expects " + tagInfo.length +
-                    " value(s), not " + values.length);
+            throw new ImageWriteException("Tag expects " + tagInfo.length
+                    + " value(s), not " + values.length);
         }
         byte[] bytes = tagInfo.encodeValue(byteOrder, values);
-        TiffOutputField tiffOutputField = new TiffOutputField(tagInfo.tag, tagInfo,
-                TiffFieldTypeConstants.FIELD_TYPE_DOUBLE, values.length, bytes);
+        TiffOutputField tiffOutputField = new TiffOutputField(tagInfo.tag,
+                tagInfo, TiffFieldTypeConstants.FIELD_TYPE_DOUBLE,
+                values.length, bytes);
         add(tiffOutputField);
     }
 
-    public void add(TagInfoByteOrShort tagInfo, byte... values) throws ImageWriteException {
+    public void add(TagInfoByteOrShort tagInfo, byte... values)
+            throws ImageWriteException {
         if (tagInfo.length > 0 && tagInfo.length != values.length) {
-            throw new ImageWriteException("Tag expects " + tagInfo.length +
-                    " value(s), not " + values.length);
+            throw new ImageWriteException("Tag expects " + tagInfo.length
+                    + " value(s), not " + values.length);
         }
         byte[] bytes = tagInfo.encodeValue(byteOrder, values);
-        TiffOutputField tiffOutputField = new TiffOutputField(tagInfo.tag, tagInfo,
-                TiffFieldTypeConstants.FIELD_TYPE_BYTE, values.length, bytes);
+        TiffOutputField tiffOutputField = new TiffOutputField(tagInfo.tag,
+                tagInfo, TiffFieldTypeConstants.FIELD_TYPE_BYTE, values.length,
+                bytes);
         add(tiffOutputField);
     }
 
-    public void add(TagInfoByteOrShort tagInfo, short... values) throws ImageWriteException {
+    public void add(TagInfoByteOrShort tagInfo, short... values)
+            throws ImageWriteException {
         if (tagInfo.length > 0 && tagInfo.length != values.length) {
-            throw new ImageWriteException("Tag expects " + tagInfo.length +
-                    " value(s), not " + values.length);
+            throw new ImageWriteException("Tag expects " + tagInfo.length
+                    + " value(s), not " + values.length);
         }
         byte[] bytes = tagInfo.encodeValue(byteOrder, values);
-        TiffOutputField tiffOutputField = new TiffOutputField(tagInfo.tag, tagInfo,
-                TiffFieldTypeConstants.FIELD_TYPE_SHORT, values.length, bytes);
+        TiffOutputField tiffOutputField = new TiffOutputField(tagInfo.tag,
+                tagInfo, TiffFieldTypeConstants.FIELD_TYPE_SHORT,
+                values.length, bytes);
         add(tiffOutputField);
     }
 
-    public void add(TagInfoShortOrLong tagInfo, short... values) throws ImageWriteException {
+    public void add(TagInfoShortOrLong tagInfo, short... values)
+            throws ImageWriteException {
         if (tagInfo.length > 0 && tagInfo.length != values.length) {
-            throw new ImageWriteException("Tag expects " + tagInfo.length +
-                    " value(s), not " + values.length);
+            throw new ImageWriteException("Tag expects " + tagInfo.length
+                    + " value(s), not " + values.length);
         }
         byte[] bytes = tagInfo.encodeValue(byteOrder, values);
-        TiffOutputField tiffOutputField = new TiffOutputField(tagInfo.tag, tagInfo,
-                TiffFieldTypeConstants.FIELD_TYPE_SHORT, values.length, bytes);
+        TiffOutputField tiffOutputField = new TiffOutputField(tagInfo.tag,
+                tagInfo, TiffFieldTypeConstants.FIELD_TYPE_SHORT,
+                values.length, bytes);
         add(tiffOutputField);
     }
 
-    public void add(TagInfoShortOrLong tagInfo, int... values) throws ImageWriteException {
+    public void add(TagInfoShortOrLong tagInfo, int... values)
+            throws ImageWriteException {
         if (tagInfo.length > 0 && tagInfo.length != values.length) {
-            throw new ImageWriteException("Tag expects " + tagInfo.length +
-                    " value(s), not " + values.length);
+            throw new ImageWriteException("Tag expects " + tagInfo.length
+                    + " value(s), not " + values.length);
         }
         byte[] bytes = tagInfo.encodeValue(byteOrder, values);
-        TiffOutputField tiffOutputField = new TiffOutputField(tagInfo.tag, tagInfo,
-                TiffFieldTypeConstants.FIELD_TYPE_LONG, values.length, bytes);
+        TiffOutputField tiffOutputField = new TiffOutputField(tagInfo.tag,
+                tagInfo, TiffFieldTypeConstants.FIELD_TYPE_LONG, values.length,
+                bytes);
         add(tiffOutputField);
     }
 
-    public void add(TagInfoShortOrLongOrRational tagInfo, short... values) throws ImageWriteException {
+    public void add(TagInfoShortOrLongOrRational tagInfo, short... values)
+            throws ImageWriteException {
         if (tagInfo.length > 0 && tagInfo.length != values.length) {
-            throw new ImageWriteException("Tag expects " + tagInfo.length +
-                    " value(s), not " + values.length);
+            throw new ImageWriteException("Tag expects " + tagInfo.length
+                    + " value(s), not " + values.length);
         }
         byte[] bytes = tagInfo.encodeValue(byteOrder, values);
-        TiffOutputField tiffOutputField = new TiffOutputField(tagInfo.tag, tagInfo,
-                TiffFieldTypeConstants.FIELD_TYPE_SHORT, values.length, bytes);
+        TiffOutputField tiffOutputField = new TiffOutputField(tagInfo.tag,
+                tagInfo, TiffFieldTypeConstants.FIELD_TYPE_SHORT,
+                values.length, bytes);
         add(tiffOutputField);
     }
-    
-    public void add(TagInfoShortOrLongOrRational tagInfo, int... values) throws ImageWriteException {
+
+    public void add(TagInfoShortOrLongOrRational tagInfo, int... values)
+            throws ImageWriteException {
         if (tagInfo.length > 0 && tagInfo.length != values.length) {
-            throw new ImageWriteException("Tag expects " + tagInfo.length +
-                    " value(s), not " + values.length);
+            throw new ImageWriteException("Tag expects " + tagInfo.length
+                    + " value(s), not " + values.length);
         }
         byte[] bytes = tagInfo.encodeValue(byteOrder, values);
-        TiffOutputField tiffOutputField = new TiffOutputField(tagInfo.tag, tagInfo,
-                TiffFieldTypeConstants.FIELD_TYPE_LONG, values.length, bytes);
+        TiffOutputField tiffOutputField = new TiffOutputField(tagInfo.tag,
+                tagInfo, TiffFieldTypeConstants.FIELD_TYPE_LONG, values.length,
+                bytes);
         add(tiffOutputField);
     }
 
-    public void add(TagInfoShortOrLongOrRational tagInfo, RationalNumber... values) throws ImageWriteException {
+    public void add(TagInfoShortOrLongOrRational tagInfo,
+            RationalNumber... values) throws ImageWriteException {
         if (tagInfo.length > 0 && tagInfo.length != values.length) {
-            throw new ImageWriteException("Tag expects " + tagInfo.length +
-                    " value(s), not " + values.length);
+            throw new ImageWriteException("Tag expects " + tagInfo.length
+                    + " value(s), not " + values.length);
         }
         byte[] bytes = tagInfo.encodeValue(byteOrder, values);
-        TiffOutputField tiffOutputField = new TiffOutputField(tagInfo.tag, tagInfo,
-                TiffFieldTypeConstants.FIELD_TYPE_RATIONAL, values.length, bytes);
+        TiffOutputField tiffOutputField = new TiffOutputField(tagInfo.tag,
+                tagInfo, TiffFieldTypeConstants.FIELD_TYPE_RATIONAL,
+                values.length, bytes);
         add(tiffOutputField);
     }
-    
-    public void add(TagInfoShortOrRational tagInfo, short... values) throws ImageWriteException {
+
+    public void add(TagInfoShortOrRational tagInfo, short... values)
+            throws ImageWriteException {
         if (tagInfo.length > 0 && tagInfo.length != values.length) {
-            throw new ImageWriteException("Tag expects " + tagInfo.length +
-                    " value(s), not " + values.length);
+            throw new ImageWriteException("Tag expects " + tagInfo.length
+                    + " value(s), not " + values.length);
         }
         byte[] bytes = tagInfo.encodeValue(byteOrder, values);
-        TiffOutputField tiffOutputField = new TiffOutputField(tagInfo.tag, tagInfo,
-                TiffFieldTypeConstants.FIELD_TYPE_SHORT, values.length, bytes);
+        TiffOutputField tiffOutputField = new TiffOutputField(tagInfo.tag,
+                tagInfo, TiffFieldTypeConstants.FIELD_TYPE_SHORT,
+                values.length, bytes);
         add(tiffOutputField);
     }
 
-    public void add(TagInfoShortOrRational tagInfo, RationalNumber... values) throws ImageWriteException {
+    public void add(TagInfoShortOrRational tagInfo, RationalNumber... values)
+            throws ImageWriteException {
         if (tagInfo.length > 0 && tagInfo.length != values.length) {
-            throw new ImageWriteException("Tag expects " + tagInfo.length +
-                    " value(s), not " + values.length);
+            throw new ImageWriteException("Tag expects " + tagInfo.length
+                    + " value(s), not " + values.length);
         }
         byte[] bytes = tagInfo.encodeValue(byteOrder, values);
-        TiffOutputField tiffOutputField = new TiffOutputField(tagInfo.tag, tagInfo,
-                TiffFieldTypeConstants.FIELD_TYPE_RATIONAL, values.length, bytes);
+        TiffOutputField tiffOutputField = new TiffOutputField(tagInfo.tag,
+                tagInfo, TiffFieldTypeConstants.FIELD_TYPE_RATIONAL,
+                values.length, bytes);
         add(tiffOutputField);
     }
 
-    public void add(TagInfoGpsText tagInfo, String value) throws ImageWriteException {
-        byte[] bytes = tagInfo.encodeValue(TiffFieldTypeConstants.FIELD_TYPE_UNKNOWN, value, byteOrder);
-        TiffOutputField tiffOutputField = new TiffOutputField(tagInfo.tag, tagInfo,
-                tagInfo.dataTypes.get(0), bytes.length, bytes);
+    public void add(TagInfoGpsText tagInfo, String value)
+            throws ImageWriteException {
+        byte[] bytes = tagInfo.encodeValue(
+                TiffFieldTypeConstants.FIELD_TYPE_UNKNOWN, value, byteOrder);
+        TiffOutputField tiffOutputField = new TiffOutputField(tagInfo.tag,
+                tagInfo, tagInfo.dataTypes.get(0), bytes.length, bytes);
         add(tiffOutputField);
     }
-    
-    public void add(TagInfoXpString tagInfo, String value) throws ImageWriteException {
-        byte[] bytes = tagInfo.encodeValue(TiffFieldTypeConstants.FIELD_TYPE_BYTE, value, byteOrder);
-        TiffOutputField tiffOutputField = new TiffOutputField(tagInfo.tag, tagInfo,
-                TiffFieldTypeConstants.FIELD_TYPE_BYTE, bytes.length, bytes);
+
+    public void add(TagInfoXpString tagInfo, String value)
+            throws ImageWriteException {
+        byte[] bytes = tagInfo.encodeValue(
+                TiffFieldTypeConstants.FIELD_TYPE_BYTE, value, byteOrder);
+        TiffOutputField tiffOutputField = new TiffOutputField(tagInfo.tag,
+                tagInfo, TiffFieldTypeConstants.FIELD_TYPE_BYTE, bytes.length,
+                bytes);
         add(tiffOutputField);
     }
-    
-    public void add(TagInfoAsciiOrByte tagInfo, String... values) throws ImageWriteException {
-        byte[] bytes = tagInfo.encodeValue(TiffFieldTypeConstants.FIELD_TYPE_ASCII, values, byteOrder);
+
+    public void add(TagInfoAsciiOrByte tagInfo, String... values)
+            throws ImageWriteException {
+        byte[] bytes = tagInfo.encodeValue(
+                TiffFieldTypeConstants.FIELD_TYPE_ASCII, values, byteOrder);
         if (tagInfo.length > 0 && tagInfo.length != bytes.length) {
-            throw new ImageWriteException("Tag expects " + tagInfo.length +
-                    " byte(s), not " + values.length);
+            throw new ImageWriteException("Tag expects " + tagInfo.length
+                    + " byte(s), not " + values.length);
         }
-        TiffOutputField tiffOutputField = new TiffOutputField(tagInfo.tag, tagInfo,
-                TiffFieldTypeConstants.FIELD_TYPE_ASCII, bytes.length, bytes);
+        TiffOutputField tiffOutputField = new TiffOutputField(tagInfo.tag,
+                tagInfo, TiffFieldTypeConstants.FIELD_TYPE_ASCII, bytes.length,
+                bytes);
         add(tiffOutputField);
     }
-    
-    public void add(TagInfoAsciiOrRational tagInfo, String... values) throws ImageWriteException {
-        byte[] bytes = tagInfo.encodeValue(TiffFieldTypeConstants.FIELD_TYPE_ASCII, values, byteOrder);
+
+    public void add(TagInfoAsciiOrRational tagInfo, String... values)
+            throws ImageWriteException {
+        byte[] bytes = tagInfo.encodeValue(
+                TiffFieldTypeConstants.FIELD_TYPE_ASCII, values, byteOrder);
         if (tagInfo.length > 0 && tagInfo.length != bytes.length) {
-            throw new ImageWriteException("Tag expects " + tagInfo.length +
-                    " byte(s), not " + values.length);
+            throw new ImageWriteException("Tag expects " + tagInfo.length
+                    + " byte(s), not " + values.length);
         }
-        TiffOutputField tiffOutputField = new TiffOutputField(tagInfo.tag, tagInfo,
-                TiffFieldTypeConstants.FIELD_TYPE_ASCII, bytes.length, bytes);
+        TiffOutputField tiffOutputField = new TiffOutputField(tagInfo.tag,
+                tagInfo, TiffFieldTypeConstants.FIELD_TYPE_ASCII, bytes.length,
+                bytes);
         add(tiffOutputField);
     }
-    
-    public void add(TagInfoAsciiOrRational tagInfo, RationalNumber... values) throws ImageWriteException {
+
+    public void add(TagInfoAsciiOrRational tagInfo, RationalNumber... values)
+            throws ImageWriteException {
         if (tagInfo.length > 0 && tagInfo.length != values.length) {
-            throw new ImageWriteException("Tag expects " + tagInfo.length +
-                    " value(s), not " + values.length);
+            throw new ImageWriteException("Tag expects " + tagInfo.length
+                    + " value(s), not " + values.length);
         }
-        byte[] bytes = tagInfo.encodeValue(TiffFieldTypeConstants.FIELD_TYPE_RATIONAL, values, byteOrder);
-        TiffOutputField tiffOutputField = new TiffOutputField(tagInfo.tag, tagInfo,
-                TiffFieldTypeConstants.FIELD_TYPE_RATIONAL, bytes.length, bytes);
+        byte[] bytes = tagInfo.encodeValue(
+                TiffFieldTypeConstants.FIELD_TYPE_RATIONAL, values, byteOrder);
+        TiffOutputField tiffOutputField = new TiffOutputField(tagInfo.tag,
+                tagInfo, TiffFieldTypeConstants.FIELD_TYPE_RATIONAL,
+                bytes.length, bytes);
         add(tiffOutputField);
     }
-    
-    public void add(TiffOutputField field)
-    {
+
+    public void add(TiffOutputField field) {
         fields.add(field);
     }
 
-    public List<TiffOutputField> getFields()
-    {
+    public List<TiffOutputField> getFields() {
         return new ArrayList<TiffOutputField>(fields);
     }
 
-    public void removeField(TagInfo tagInfo)
-    {
+    public void removeField(TagInfo tagInfo) {
         removeField(tagInfo.tag);
     }
 
-    public void removeField(int tag)
-    {
+    public void removeField(int tag) {
         List<TiffOutputField> matches = new ArrayList<TiffOutputField>();
-        for (int i = 0; i < fields.size(); i++)
-        {
+        for (int i = 0; i < fields.size(); i++) {
             TiffOutputField field = fields.get(i);
             if (field.tag == tag)
                 matches.add(field);
@@ -380,15 +426,12 @@ public final class TiffOutputDirectory e
         fields.removeAll(matches);
     }
 
-    public TiffOutputField findField(TagInfo tagInfo)
-    {
+    public TiffOutputField findField(TagInfo tagInfo) {
         return findField(tagInfo.tag);
     }
 
-    public TiffOutputField findField(int tag)
-    {
-        for (int i = 0; i < fields.size(); i++)
-        {
+    public TiffOutputField findField(int tag) {
+        for (int i = 0; i < fields.size(); i++) {
             TiffOutputField field = fields.get(i);
             if (field.tag == tag)
                 return field;
@@ -396,11 +439,9 @@ public final class TiffOutputDirectory e
         return null;
     }
 
-    public void sortFields()
-    {
+    public void sortFields() {
         Comparator<TiffOutputField> comparator = new Comparator<TiffOutputField>() {
-            public int compare(TiffOutputField e1, TiffOutputField e2)
-            {
+            public int compare(TiffOutputField e1, TiffOutputField e2) {
                 if (e1.tag != e2.tag)
                     return e1.tag - e2.tag;
                 return e1.getSortHint() - e2.getSortHint();
@@ -409,28 +450,25 @@ public final class TiffOutputDirectory e
         Collections.sort(fields, comparator);
     }
 
-    public String description()
-    {
+    public String description() {
         return TiffDirectory.description(type);
     }
 
     @Override
     public void writeItem(BinaryOutputStream bos) throws IOException,
-            ImageWriteException
-    {
+            ImageWriteException {
         // Write Directory Field Count
         bos.write2Bytes(fields.size()); // DirectoryFieldCount
 
         // Write Fields
-        for (int i = 0; i < fields.size(); i++)
-        {
+        for (int i = 0; i < fields.size(); i++) {
             TiffOutputField field = fields.get(i);
             field.writeField(bos);
 
-//             Debug.debug("\t" + "writing field (" + field.tag + ", 0x" +
-//             Integer.toHexString(field.tag) + ")", field.tagInfo);
-//             if(field.tagInfo.isOffset())
-//             Debug.debug("\t\tOFFSET!", field.bytes);
+            // Debug.debug("\t" + "writing field (" + field.tag + ", 0x" +
+            // Integer.toHexString(field.tag) + ")", field.tagInfo);
+            // if(field.tagInfo.isOffset())
+            // Debug.debug("\t\tOFFSET!", field.bytes);
         }
 
         int nextDirectoryOffset = 0;
@@ -446,64 +484,55 @@ public final class TiffOutputDirectory e
 
     private JpegImageData jpegImageData = null;
 
-    public void setJpegImageData(JpegImageData rawJpegImageData)
-    {
+    public void setJpegImageData(JpegImageData rawJpegImageData) {
         this.jpegImageData = rawJpegImageData;
     }
 
-    public JpegImageData getRawJpegImageData()
-    {
+    public JpegImageData getRawJpegImageData() {
         return jpegImageData;
     }
 
     private TiffImageData tiffImageData = null;
 
-    public void setTiffImageData(TiffImageData rawTiffImageData)
-    {
+    public void setTiffImageData(TiffImageData rawTiffImageData) {
         this.tiffImageData = rawTiffImageData;
     }
 
-    public TiffImageData getRawTiffImageData()
-    {
+    public TiffImageData getRawTiffImageData() {
         return tiffImageData;
     }
 
     @Override
-    public int getItemLength()
-    {
+    public int getItemLength() {
         return TIFF_ENTRY_LENGTH * fields.size() + TIFF_DIRECTORY_HEADER_LENGTH
                 + TIFF_DIRECTORY_FOOTER_LENGTH;
     }
 
     @Override
-    public String getItemDescription()
-    {
+    public String getItemDescription() {
         TiffDirectoryType dirType = TagConstantsUtils
                 .getExifDirectoryType(type);
         return "Directory: " + dirType.name + " (" + type + ")";
     }
 
-    private void removeFieldIfPresent(TagInfo tagInfo)
-    {
+    private void removeFieldIfPresent(TagInfo tagInfo) {
         TiffOutputField field = findField(tagInfo);
         if (null != field)
             fields.remove(field);
     }
 
-    protected List<TiffOutputItem> getOutputItems(TiffOutputSummary outputSummary)
-            throws ImageWriteException
-    {
+    protected List<TiffOutputItem> getOutputItems(
+            TiffOutputSummary outputSummary) throws ImageWriteException {
         // first validate directory fields.
 
         removeFieldIfPresent(TiffTagConstants.TIFF_TAG_JPEG_INTERCHANGE_FORMAT);
         removeFieldIfPresent(TiffTagConstants.TIFF_TAG_JPEG_INTERCHANGE_FORMAT_LENGTH);
 
         TiffOutputField jpegOffsetField = null;
-        if (null != jpegImageData)
-        {
+        if (null != jpegImageData) {
             jpegOffsetField = new TiffOutputField(
-                    TiffTagConstants.TIFF_TAG_JPEG_INTERCHANGE_FORMAT, FIELD_TYPE_LONG, 1,
-                    FieldType.getStubLocalValue());
+                    TiffTagConstants.TIFF_TAG_JPEG_INTERCHANGE_FORMAT,
+                    FIELD_TYPE_LONG, 1, FieldType.getStubLocalValue());
             add(jpegOffsetField);
 
             byte lengthValue[] = FIELD_TYPE_LONG.writeData(
@@ -511,8 +540,8 @@ public final class TiffOutputDirectory e
                     outputSummary.byteOrder);
 
             TiffOutputField jpegLengthField = new TiffOutputField(
-                    TiffTagConstants.TIFF_TAG_JPEG_INTERCHANGE_FORMAT_LENGTH, FIELD_TYPE_LONG,
-                    1, lengthValue);
+                    TiffTagConstants.TIFF_TAG_JPEG_INTERCHANGE_FORMAT_LENGTH,
+                    FIELD_TYPE_LONG, 1, lengthValue);
             add(jpegLengthField);
 
         }
@@ -526,18 +555,15 @@ public final class TiffOutputDirectory e
 
         TiffOutputField imageDataOffsetField;
         ImageDataOffsets imageDataInfo = null;
-        if (null != tiffImageData)
-        {
+        if (null != tiffImageData) {
             boolean stripsNotTiles = tiffImageData.stripsNotTiles();
 
             TagInfo offsetTag;
             TagInfo byteCountsTag;
-            if (stripsNotTiles)
-            {
+            if (stripsNotTiles) {
                 offsetTag = TiffTagConstants.TIFF_TAG_STRIP_OFFSETS;
                 byteCountsTag = TiffTagConstants.TIFF_TAG_STRIP_BYTE_COUNTS;
-            } else
-            {
+            } else {
                 offsetTag = TiffTagConstants.TIFF_TAG_TILE_OFFSETS;
                 byteCountsTag = TiffTagConstants.TIFF_TAG_TILE_BYTE_COUNTS;
             }
@@ -552,8 +578,7 @@ public final class TiffOutputDirectory e
 
             imageDataOffsets = new int[imageData.length];
             imageDataByteCounts = new int[imageData.length];
-            for (int i = 0; i < imageData.length; i++)
-            {
+            for (int i = 0; i < imageData.length; i++) {
                 imageDataByteCounts[i] = imageData[i].length;
             }
 
@@ -561,9 +586,9 @@ public final class TiffOutputDirectory e
 
             // Append imageData-related fields to first directory
             imageDataOffsetField = new TiffOutputField(offsetTag,
-                    FIELD_TYPE_LONG, imageDataOffsets.length, FIELD_TYPE_LONG
-                            .writeData(imageDataOffsets,
-                                    outputSummary.byteOrder));
+                    FIELD_TYPE_LONG, imageDataOffsets.length,
+                    FIELD_TYPE_LONG.writeData(imageDataOffsets,
+                            outputSummary.byteOrder));
             add(imageDataOffsetField);
 
             // --------
@@ -587,8 +612,7 @@ public final class TiffOutputDirectory e
         result.add(this);
         sortFields();
 
-        for (int i = 0; i < fields.size(); i++)
-        {
+        for (int i = 0; i < fields.size(); i++) {
             TiffOutputField field = fields.get(i);
             if (field.isLocalValue())
                 continue;
@@ -598,16 +622,14 @@ public final class TiffOutputDirectory e
             // outputSummary.add(item, field);
         }
 
-        if (null != imageDataInfo)
-        {
+        if (null != imageDataInfo) {
             for (int i = 0; i < imageDataInfo.outputItems.length; i++)
                 result.add(imageDataInfo.outputItems[i]);
 
             outputSummary.addTiffImageData(imageDataInfo);
         }
 
-        if (null != jpegImageData)
-        {
+        if (null != jpegImageData) {
             TiffOutputItem item = new TiffOutputItem.Value("JPEG image data",
                     jpegImageData.data);
             result.add(item);
@@ -616,4 +638,4 @@ public final class TiffOutputDirectory e
 
         return result;
     }
-}
\ No newline at end of file
+}