Author: damjan Date: Fri Sep 28 05:45:30 2012 New Revision: 1391310 URL: http://svn.apache.org/viewvc?rev=1391310&view=rev Log: Various cleanups.
Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/gif/GifImageParser.java commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/TiffReader.java commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/write/TiffImageWriterLossless.java commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/xpm/XpmImageParser.java commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/icc/IccTag.java Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/gif/GifImageParser.java URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/gif/GifImageParser.java?rev=1391310&r1=1391309&r2=1391310&view=diff ============================================================================== --- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/gif/GifImageParser.java (original) +++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/gif/GifImageParser.java Fri Sep 28 05:45:30 2012 @@ -427,26 +427,6 @@ public class GifImageParser extends Imag return bytes; } - // TODO - unused - private GifHeaderInfo readHeader(ByteSource byteSource) - throws ImageReadException, IOException { - InputStream is = null; - try { - is = byteSource.getInputStream(); - - return readHeader(is, FormatCompliance.getDefault()); - } finally { - try { - if (is != null) { - is.close(); - } - } catch (Exception e) { - Debug.debug(e); - } - - } - } - private GifBlock findBlock(List<GifBlock> v, int code) { for (int i = 0; i < v.size(); i++) { GifBlock gifBlock = v.get(i); Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/TiffReader.java URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/TiffReader.java?rev=1391310&r1=1391309&r2=1391310&view=diff ============================================================================== --- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/TiffReader.java (original) +++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/TiffReader.java Fri Sep 28 05:45:30 2012 @@ -186,11 +186,9 @@ public class TiffReader extends BinaryFi field.fillInValue(byteSource); } catch (TiffValueOutsideFileBoundsException valueOutsideFileException) { if (strict) { - // Java 1.5+ throw new - // IOException(valueOutsideFileException); - IOException ioe = new IOException(); - ioe.initCause(valueOutsideFileException); - throw ioe; + IOException ioEx = new IOException(); + ioEx.initCause(valueOutsideFileException); + throw ioEx; } else { // corrupt field, ignore it continue; 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=1391310&r1=1391309&r2=1391310&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 Fri Sep 28 05:45:30 2012 @@ -53,31 +53,6 @@ public class TiffImageWriterLossless ext this.exifBytes = exifBytes; } - // 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 - // { - ByteSource byteSource = new ByteSourceArray(exifBytes); - - dumpElements(byteSource, elements); - // } - // catch (ImageReadException e) - // { - // throw new ImageWriteException(e.getMessage(), e); - // } - } - private void dumpElements(ByteSource byteSource, List<TiffElement> elements) throws IOException { int last = TIFF_HEADER_SIZE; Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/xpm/XpmImageParser.java URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/xpm/XpmImageParser.java?rev=1391310&r1=1391309&r2=1391310&view=diff ============================================================================== --- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/xpm/XpmImageParser.java (original) +++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/xpm/XpmImageParser.java Fri Sep 28 05:45:30 2012 @@ -223,7 +223,6 @@ public class XpmImageParser extends Imag int gray4LevelArgb; boolean haveMono = false; int monoArgb; - String symbolicName = null; int getBestARGB() { if (haveColor) { @@ -376,6 +375,25 @@ public class XpmImageParser extends Imag } } } + + private void populatePaletteEntry(PaletteEntry paletteEntry, String key, String color) throws ImageReadException { + if (key.equals("m")) { + paletteEntry.monoArgb = parseColor(color); + paletteEntry.haveMono = true; + } else if (key.equals("g4")) { + paletteEntry.gray4LevelArgb = parseColor(color); + paletteEntry.haveGray4Level = true; + } else if (key.equals("g")) { + paletteEntry.grayArgb = parseColor(color); + paletteEntry.haveGray = true; + } else if (key.equals("s")) { + paletteEntry.colorArgb = parseColor(color); + paletteEntry.haveColor = true; + } else if (key.equals("c")) { + paletteEntry.colorArgb = parseColor(color); + paletteEntry.haveColor = true; + } + } private void parsePaletteEntries(XpmHeader xpmHeader, BasicCParser cParser) throws IOException, ImageReadException { @@ -388,8 +406,8 @@ public class XpmImageParser extends Imag + "file ended while reading palette"); } String name = row.substring(0, xpmHeader.numCharsPerPixel); - String[] tokens = BasicCParser.tokenizeRow(row - .substring(xpmHeader.numCharsPerPixel)); + String[] tokens = BasicCParser.tokenizeRow( + row.substring(xpmHeader.numCharsPerPixel)); PaletteEntry paletteEntry = new PaletteEntry(); paletteEntry.index = i; int previousKeyIndex = Integer.MIN_VALUE; @@ -408,23 +426,7 @@ public class XpmImageParser extends Imag String key = tokens[previousKeyIndex]; String color = colorBuffer.toString(); colorBuffer.setLength(0); - if (key.equals("m")) { - paletteEntry.monoArgb = parseColor(color); - paletteEntry.haveMono = true; - } else if (key.equals("g4")) { - paletteEntry.gray4LevelArgb = parseColor(color); - paletteEntry.haveGray4Level = true; - } else if (key.equals("g")) { - paletteEntry.grayArgb = parseColor(color); - paletteEntry.haveGray = true; - } else if (key.equals("s")) { - paletteEntry.symbolicName = color; - paletteEntry.colorArgb = parseColor(color); - paletteEntry.haveColor = true; - } else if (key.equals("c")) { - paletteEntry.colorArgb = parseColor(color); - paletteEntry.haveColor = true; - } + populatePaletteEntry(paletteEntry, key, color); } previousKeyIndex = j; } else { @@ -441,23 +443,7 @@ public class XpmImageParser extends Imag String key = tokens[previousKeyIndex]; String color = colorBuffer.toString(); colorBuffer.setLength(0); - if (key.equals("m")) { - paletteEntry.monoArgb = parseColor(color); - paletteEntry.haveMono = true; - } else if (key.equals("g4")) { - paletteEntry.gray4LevelArgb = parseColor(color); - paletteEntry.haveGray4Level = true; - } else if (key.equals("g")) { - paletteEntry.grayArgb = parseColor(color); - paletteEntry.haveGray = true; - } else if (key.equals("s")) { - paletteEntry.symbolicName = color; - paletteEntry.colorArgb = parseColor(color); - paletteEntry.haveColor = true; - } else if (key.equals("c")) { - paletteEntry.colorArgb = parseColor(color); - paletteEntry.haveColor = true; - } + populatePaletteEntry(paletteEntry, key, color); } xpmHeader.palette.put(name, paletteEntry); } Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/icc/IccTag.java URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/icc/IccTag.java?rev=1391310&r1=1391309&r2=1391310&view=diff ============================================================================== --- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/icc/IccTag.java (original) +++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/icc/IccTag.java Fri Sep 28 05:45:30 2012 @@ -48,17 +48,26 @@ public class IccTag implements BinaryCon public void setData(byte bytes[]) throws IOException { data = bytes; - BinaryInputStream bis = new BinaryInputStream(new ByteArrayInputStream( + BinaryInputStream bis = null; + try { + bis = new BinaryInputStream(new ByteArrayInputStream( bytes), BYTE_ORDER_NETWORK); - data_type_signature = bis.read4Bytes("data type signature", - "ICC: corrupt tag data"); - - itdt = getIccTagDataType(data_type_signature); - // if (itdt != null) - // { - // System.out.println("\t\t\t" + "itdt: " + itdt.name); - // } - + data_type_signature = bis.read4Bytes("data type signature", + "ICC: corrupt tag data"); + + itdt = getIccTagDataType(data_type_signature); + // if (itdt != null) + // { + // System.out.println("\t\t\t" + "itdt: " + itdt.name); + // } + } finally { + try { + if (bis != null) { + bis.close(); + } + } catch (IOException cannotHappen) { + } + } } private IccTagDataType getIccTagDataType(int quad) {