Modified: commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/psd/datareaders/CompressedDataReader.java URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/psd/datareaders/CompressedDataReader.java?rev=995859&r1=995858&r2=995859&view=diff ============================================================================== --- commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/psd/datareaders/CompressedDataReader.java (original) +++ commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/psd/datareaders/CompressedDataReader.java Fri Sep 10 16:33:35 2010 @@ -33,53 +33,53 @@ import org.apache.sanselan.formats.psd.d public class CompressedDataReader extends DataReader { - public CompressedDataReader(DataParser fDataParser) - { - super(fDataParser); - } - - public void readData(InputStream is, BufferedImage bi, - ImageContents imageContents, BinaryFileParser bfp) - throws ImageReadException, IOException - { - PSDHeaderInfo header = imageContents.header; - int width = header.Columns; - int height = header.Rows; - - // this.setDebug(true); - int scanline_count = height * header.Channels; - int scanline_bytecounts[] = new int[scanline_count]; - for (int i = 0; i < scanline_count; i++) - scanline_bytecounts[i] = bfp.read2Bytes("scanline_bytecount[" + i - + "]", is, "PSD: bad Image Data"); - bfp.setDebug(false); - // System.out.println("fImageContents.Compression: " - // + imageContents.Compression); - - int depth = header.Depth; - - int channel_count = dataParser.getBasicChannelsCount(); - int data[][][] = new int[channel_count][height][]; - // channels[0] = - for (int channel = 0; channel < channel_count; channel++) - for (int y = 0; y < height; y++) - { - int index = channel * height + y; - byte packed[] = bfp.readByteArray("scanline", - scanline_bytecounts[index], is, - "PSD: Missing Image Data"); - - byte unpacked[] = new PackBits().decompress(packed, width); - InputStream bais = new ByteArrayInputStream(unpacked); - MyBitInputStream mbis = new MyBitInputStream(bais, - BYTE_ORDER_MSB); - BitsToByteInputStream bbis = new BitsToByteInputStream(mbis, 8); // we want all samples to be bytes - int scanline[] = bbis.readBitsArray(depth, width); - data[channel][y] = scanline; + public CompressedDataReader(DataParser fDataParser) + { + super(fDataParser); + } + + public void readData(InputStream is, BufferedImage bi, + ImageContents imageContents, BinaryFileParser bfp) + throws ImageReadException, IOException + { + PSDHeaderInfo header = imageContents.header; + int width = header.Columns; + int height = header.Rows; + + // this.setDebug(true); + int scanline_count = height * header.Channels; + int scanline_bytecounts[] = new int[scanline_count]; + for (int i = 0; i < scanline_count; i++) + scanline_bytecounts[i] = bfp.read2Bytes("scanline_bytecount[" + i + + "]", is, "PSD: bad Image Data"); + bfp.setDebug(false); + // System.out.println("fImageContents.Compression: " + // + imageContents.Compression); + + int depth = header.Depth; + + int channel_count = dataParser.getBasicChannelsCount(); + int data[][][] = new int[channel_count][height][]; + // channels[0] = + for (int channel = 0; channel < channel_count; channel++) + for (int y = 0; y < height; y++) + { + int index = channel * height + y; + byte packed[] = bfp.readByteArray("scanline", + scanline_bytecounts[index], is, + "PSD: Missing Image Data"); + + byte unpacked[] = new PackBits().decompress(packed, width); + InputStream bais = new ByteArrayInputStream(unpacked); + MyBitInputStream mbis = new MyBitInputStream(bais, + BYTE_ORDER_MSB); + BitsToByteInputStream bbis = new BitsToByteInputStream(mbis, 8); // we want all samples to be bytes + int scanline[] = bbis.readBitsArray(depth, width); + data[channel][y] = scanline; - } + } - dataParser.parseData(data, bi, imageContents); + dataParser.parseData(data, bi, imageContents); - } + } } \ No newline at end of file
Modified: commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/psd/datareaders/DataReader.java URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/psd/datareaders/DataReader.java?rev=995859&r1=995858&r2=995859&view=diff ============================================================================== --- commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/psd/datareaders/DataReader.java (original) +++ commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/psd/datareaders/DataReader.java Fri Sep 10 16:33:35 2010 @@ -28,19 +28,19 @@ import org.apache.sanselan.formats.psd.d public abstract class DataReader implements BinaryConstants { - protected final DataParser dataParser; + protected final DataParser dataParser; - public DataReader(DataParser fDataParser) - { - this.dataParser = fDataParser; - } + public DataReader(DataParser fDataParser) + { + this.dataParser = fDataParser; + } - public abstract void readData(InputStream is, BufferedImage bi, - ImageContents imageContents, BinaryFileParser bfp) - throws ImageReadException, IOException; + public abstract void readData(InputStream is, BufferedImage bi, + ImageContents imageContents, BinaryFileParser bfp) + throws ImageReadException, IOException; - public void dump() - { - dataParser.dump(); - } + public void dump() + { + dataParser.dump(); + } } \ No newline at end of file Modified: commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/psd/datareaders/UncompressedDataReader.java URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/psd/datareaders/UncompressedDataReader.java?rev=995859&r1=995858&r2=995859&view=diff ============================================================================== --- commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/psd/datareaders/UncompressedDataReader.java (original) +++ commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/psd/datareaders/UncompressedDataReader.java Fri Sep 10 16:33:35 2010 @@ -30,37 +30,37 @@ import org.apache.sanselan.formats.psd.d public class UncompressedDataReader extends DataReader { - public UncompressedDataReader(DataParser fDataParser) - { - super(fDataParser); - } - - public void readData(InputStream is, BufferedImage bi, - ImageContents imageContents, BinaryFileParser bfp) - throws ImageReadException, IOException - { - PSDHeaderInfo header = imageContents.header; - int width = header.Columns; - int height = header.Rows; - - bfp.setDebug(false); - - int channel_count = dataParser.getBasicChannelsCount(); - int depth = header.Depth; - MyBitInputStream mbis = new MyBitInputStream(is, BYTE_ORDER_MSB); - BitsToByteInputStream bbis = new BitsToByteInputStream(mbis, 8); // we want all samples to be bytes - - int data[][][] = new int[channel_count][height][width]; - for (int channel = 0; channel < channel_count; channel++) - for (int y = 0; y < height; y++) - for (int x = 0; x < width; x++) - { - int b = bbis.readBits(depth); + public UncompressedDataReader(DataParser fDataParser) + { + super(fDataParser); + } + + public void readData(InputStream is, BufferedImage bi, + ImageContents imageContents, BinaryFileParser bfp) + throws ImageReadException, IOException + { + PSDHeaderInfo header = imageContents.header; + int width = header.Columns; + int height = header.Rows; + + bfp.setDebug(false); + + int channel_count = dataParser.getBasicChannelsCount(); + int depth = header.Depth; + MyBitInputStream mbis = new MyBitInputStream(is, BYTE_ORDER_MSB); + BitsToByteInputStream bbis = new BitsToByteInputStream(mbis, 8); // we want all samples to be bytes + + int data[][][] = new int[channel_count][height][width]; + for (int channel = 0; channel < channel_count; channel++) + for (int y = 0; y < height; y++) + for (int x = 0; x < width; x++) + { + int b = bbis.readBits(depth); - data[channel][y][x] = (byte) b; - } + data[channel][y][x] = (byte) b; + } - dataParser.parseData(data, bi, imageContents); + dataParser.parseData(data, bi, imageContents); - } + } } \ No newline at end of file Modified: commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tga/TgaImageParser.java URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tga/TgaImageParser.java?rev=995859&r1=995858&r2=995859&view=diff ============================================================================== --- commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tga/TgaImageParser.java (original) +++ commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tga/TgaImageParser.java Fri Sep 10 16:33:35 2010 @@ -38,212 +38,212 @@ // */ //public class TgaImageParser extends ImageParser implements TgaConstants //{ -// public TgaImageParser() -// { -// this.setByteOrder(BYTE_ORDER_INTEL); -// setDebug(true); -// } -// -// public String getName() -// { -// return "Tga"; -// } -// -// public String getDefaultExtension() -// { -// return DEFAULT_EXTENSION; -// } -// -// private static final String DEFAULT_EXTENSION = ".tga"; -// -// private static final String ACCEPTED_EXTENSIONS[] = { -// ".tga", ".tpic", -// }; -// -// protected String[] getAcceptedExtensions() -// { -// return ACCEPTED_EXTENSIONS; -// } -// -// protected ImageFormat[] getAcceptedTypes() -// { -// return new ImageFormat[]{ -// ImageFormat.IMAGE_FORMAT_TGA, // -// }; -// } -// -// public IImageMetadata getMetadata(ByteSource byteSource, Map params) -// throws ImageReadException, IOException -// { -// return null; -// } -// -// public byte[] getICCProfileBytes(ByteSource byteSource) -// throws ImageReadException, IOException -// { -// return null; -// } -// -// private static final int TGA_FILE_HEADER_LENGTH = 18; -// -// public Dimension getImageSize(ByteSource byteSource) -// throws ImageReadException, IOException -// { -//// int length = (int) byteSource.getLength(); -//// if (length < TGA_FILE_HEADER_LENGTH) -//// return null; -// -// InputStream is = byteSource.getInputStream(); -// -// is.skip(12); -// -// int width = this.read2Bytes("image width", is, "image width"); -// int height = this.read2Bytes("image height", is, "image height"); -// -// return new Dimension(width, height); -// } -// -// private static final int TGA_FILE_FOOTER_LENGTH = 26; -// private static final String TGA_FILE_FOOTER_SIGNATURE = "TRUEVISION-XFILE"; -// -// private final boolean isNewTGAFormat(ByteSource byteSource) -// throws ImageReadException, IOException -// { -// int length = (int) byteSource.getLength(); -// if (length < TGA_FILE_FOOTER_LENGTH) -// return true; -// -// InputStream is = byteSource.getInputStream(length -// - TGA_FILE_FOOTER_LENGTH); -// -// byte bytes[] = this.readByteArray("tga_file_footer", -// TGA_FILE_FOOTER_LENGTH, is, "tga_file_footer"); -// -// Debug.debug("bytes", bytes); -// -// Debug.debug("kTGA_FILE_FOOTER_SIGNATURE", TGA_FILE_FOOTER_SIGNATURE); -// Debug.debug("kTGA_FILE_FOOTER_SIGNATURE", TGA_FILE_FOOTER_SIGNATURE -// .length()); -// -// return this.compareByteArrays(bytes, 8, TGA_FILE_FOOTER_SIGNATURE -// .getBytes(), 0, TGA_FILE_FOOTER_SIGNATURE.length()); -// } -// -// private static final int TGA_IMAGE_TYPE_NO_IMAGE = 0; -// private static final int UNCOMPRESSED_COLOR_MAPPED = 1; -// private static final int UNCOMPRESSED_RGB = 2; -// private static final int UNCOMPRESSED_BLACK_AND_WHITE = 3; -// private static final int COMPRESSED_COLOR_MAPPED_RLE = 9; -// private static final int COMPRESSED_RGB_RLE = 10; -// private static final int COMPRESSED_BLACK_AND_WHITE = 11; -// private static final int COMPRESSED_COLOR_MAPPED_DATA_HUFFMAN_DELTA_RLE = 32; -// private static final int COMPRESSED_COLOR_MAPPED_DATA_RLE = 33; -// -// public ImageInfo getImageInfo(ByteSource byteSource) -// throws ImageReadException, IOException -// { -//// int length = (int) byteSource.getLength(); -//// if (length < TGA_FILE_HEADER_LENGTH) -//// return null; -// -// InputStream is = byteSource.getInputStream(); -// -// int id_string_length = this.readByte("id_string_length", is, -// "id_string_length"); -// int color_map_type = this.readByte("color_map_type", is, -// "color_map_type"); -// int image_type = this.readByte("image_type", is, "image_type"); -// -// int color_map_first_entry_index = this.read2Bytes( -// "color_map_first_entry_index", is, -// "color_map_first_entry_index"); -// int color_map_length = this.read2Bytes("color_map_length", is, -// "color_map_length"); -// int color_map_entry_size = this.readByte("color_map_entry_size", is, -// "color_map_entry_size"); -// -// int origin_x = this.read2Bytes("origin_x", is, "origin_x"); -// int origin_y = this.read2Bytes("origin_y", is, "origin_y"); -// -// int width = this.read2Bytes("image width", is, "image width"); -// int height = this.read2Bytes("image height", is, "image height"); -// -// int pixel_depth = this.readByte("pixel_depth", is, "pixel_depth"); -// int image_descriptor = this.readByte("image_descriptor", is, -// "image_descriptor"); -// // charles -// -// switch (image_type) -// { -// case UNCOMPRESSED_COLOR_MAPPED : -// break; -// case UNCOMPRESSED_RGB : -// break; -// case UNCOMPRESSED_BLACK_AND_WHITE : -// break; -// case COMPRESSED_COLOR_MAPPED_RLE : -// break; -// case COMPRESSED_RGB_RLE : -// break; -// case COMPRESSED_BLACK_AND_WHITE : -// break; -// case COMPRESSED_COLOR_MAPPED_DATA_HUFFMAN_DELTA_RLE : -// break; -// case COMPRESSED_COLOR_MAPPED_DATA_RLE : -// break; -// -// default : -// -// } -// String FormatDetails; -// int BitsPerPixel; -// ArrayList Comments; -// ImageFormat Format = ImageFormat.IMAGE_FORMAT_TGA; -// String FormatName = Format.name; -// String MimeType = "image/tga"; -// int NumberOfImages = 1; // charles could have thumbnail(s). -// int PhysicalHeightDpi; -// float PhysicalHeightInch; -// int PhysicalWidthDpi; -// float PhysicalWidthInch; -// boolean isProgressive = false; -// boolean isTransparent = pixel_depth > 24; -// boolean usesPalette; -// int ColorType; -// -// return null; -// // return new ImageInfo(FormatDetails, BitsPerPixel, Comments, Format, -// // FormatName, height, MimeType, NumberOfImages, -// // PhysicalHeightDpi, PhysicalHeightInch, PhysicalWidthDpi, -// // PhysicalWidthInch, width, isProgressive, isTransparent, -// // usesPalette, ColorType); -// -// // boolean is_new_tga_format = isNewTGAFormat(byteSource); -// // -// // Debug.debug("is_new_tga_format", is_new_tga_format); -// } -// -// public boolean dumpImageFile(PrintWriter pw, ByteSource byteSource) -// throws ImageReadException, IOException -// { -// return false; -// } -// -// public BufferedImage getBufferedImage(ByteSource byteSource, Map params) -// throws ImageReadException, IOException -// { -// return null; -// } -// -// // public void writeImage(BufferedImage src, OutputStream os, Map params) -// // throws ImageWriteException, IOException -// // { -// // return false; -// // } -// -// public boolean embedICCProfile(File src, File dst, byte profile[]) -// { -// return false; -// } +// public TgaImageParser() +// { +// this.setByteOrder(BYTE_ORDER_INTEL); +// setDebug(true); +// } +// +// public String getName() +// { +// return "Tga"; +// } +// +// public String getDefaultExtension() +// { +// return DEFAULT_EXTENSION; +// } +// +// private static final String DEFAULT_EXTENSION = ".tga"; +// +// private static final String ACCEPTED_EXTENSIONS[] = { +// ".tga", ".tpic", +// }; +// +// protected String[] getAcceptedExtensions() +// { +// return ACCEPTED_EXTENSIONS; +// } +// +// protected ImageFormat[] getAcceptedTypes() +// { +// return new ImageFormat[]{ +// ImageFormat.IMAGE_FORMAT_TGA, // +// }; +// } +// +// public IImageMetadata getMetadata(ByteSource byteSource, Map params) +// throws ImageReadException, IOException +// { +// return null; +// } +// +// public byte[] getICCProfileBytes(ByteSource byteSource) +// throws ImageReadException, IOException +// { +// return null; +// } +// +// private static final int TGA_FILE_HEADER_LENGTH = 18; +// +// public Dimension getImageSize(ByteSource byteSource) +// throws ImageReadException, IOException +// { +//// int length = (int) byteSource.getLength(); +//// if (length < TGA_FILE_HEADER_LENGTH) +//// return null; +// +// InputStream is = byteSource.getInputStream(); +// +// is.skip(12); +// +// int width = this.read2Bytes("image width", is, "image width"); +// int height = this.read2Bytes("image height", is, "image height"); +// +// return new Dimension(width, height); +// } +// +// private static final int TGA_FILE_FOOTER_LENGTH = 26; +// private static final String TGA_FILE_FOOTER_SIGNATURE = "TRUEVISION-XFILE"; +// +// private final boolean isNewTGAFormat(ByteSource byteSource) +// throws ImageReadException, IOException +// { +// int length = (int) byteSource.getLength(); +// if (length < TGA_FILE_FOOTER_LENGTH) +// return true; +// +// InputStream is = byteSource.getInputStream(length +// - TGA_FILE_FOOTER_LENGTH); +// +// byte bytes[] = this.readByteArray("tga_file_footer", +// TGA_FILE_FOOTER_LENGTH, is, "tga_file_footer"); +// +// Debug.debug("bytes", bytes); +// +// Debug.debug("kTGA_FILE_FOOTER_SIGNATURE", TGA_FILE_FOOTER_SIGNATURE); +// Debug.debug("kTGA_FILE_FOOTER_SIGNATURE", TGA_FILE_FOOTER_SIGNATURE +// .length()); +// +// return this.compareByteArrays(bytes, 8, TGA_FILE_FOOTER_SIGNATURE +// .getBytes(), 0, TGA_FILE_FOOTER_SIGNATURE.length()); +// } +// +// private static final int TGA_IMAGE_TYPE_NO_IMAGE = 0; +// private static final int UNCOMPRESSED_COLOR_MAPPED = 1; +// private static final int UNCOMPRESSED_RGB = 2; +// private static final int UNCOMPRESSED_BLACK_AND_WHITE = 3; +// private static final int COMPRESSED_COLOR_MAPPED_RLE = 9; +// private static final int COMPRESSED_RGB_RLE = 10; +// private static final int COMPRESSED_BLACK_AND_WHITE = 11; +// private static final int COMPRESSED_COLOR_MAPPED_DATA_HUFFMAN_DELTA_RLE = 32; +// private static final int COMPRESSED_COLOR_MAPPED_DATA_RLE = 33; +// +// public ImageInfo getImageInfo(ByteSource byteSource) +// throws ImageReadException, IOException +// { +//// int length = (int) byteSource.getLength(); +//// if (length < TGA_FILE_HEADER_LENGTH) +//// return null; +// +// InputStream is = byteSource.getInputStream(); +// +// int id_string_length = this.readByte("id_string_length", is, +// "id_string_length"); +// int color_map_type = this.readByte("color_map_type", is, +// "color_map_type"); +// int image_type = this.readByte("image_type", is, "image_type"); +// +// int color_map_first_entry_index = this.read2Bytes( +// "color_map_first_entry_index", is, +// "color_map_first_entry_index"); +// int color_map_length = this.read2Bytes("color_map_length", is, +// "color_map_length"); +// int color_map_entry_size = this.readByte("color_map_entry_size", is, +// "color_map_entry_size"); +// +// int origin_x = this.read2Bytes("origin_x", is, "origin_x"); +// int origin_y = this.read2Bytes("origin_y", is, "origin_y"); +// +// int width = this.read2Bytes("image width", is, "image width"); +// int height = this.read2Bytes("image height", is, "image height"); +// +// int pixel_depth = this.readByte("pixel_depth", is, "pixel_depth"); +// int image_descriptor = this.readByte("image_descriptor", is, +// "image_descriptor"); +// // charles +// +// switch (image_type) +// { +// case UNCOMPRESSED_COLOR_MAPPED : +// break; +// case UNCOMPRESSED_RGB : +// break; +// case UNCOMPRESSED_BLACK_AND_WHITE : +// break; +// case COMPRESSED_COLOR_MAPPED_RLE : +// break; +// case COMPRESSED_RGB_RLE : +// break; +// case COMPRESSED_BLACK_AND_WHITE : +// break; +// case COMPRESSED_COLOR_MAPPED_DATA_HUFFMAN_DELTA_RLE : +// break; +// case COMPRESSED_COLOR_MAPPED_DATA_RLE : +// break; +// +// default : +// +// } +// String FormatDetails; +// int BitsPerPixel; +// ArrayList Comments; +// ImageFormat Format = ImageFormat.IMAGE_FORMAT_TGA; +// String FormatName = Format.name; +// String MimeType = "image/tga"; +// int NumberOfImages = 1; // charles could have thumbnail(s). +// int PhysicalHeightDpi; +// float PhysicalHeightInch; +// int PhysicalWidthDpi; +// float PhysicalWidthInch; +// boolean isProgressive = false; +// boolean isTransparent = pixel_depth > 24; +// boolean usesPalette; +// int ColorType; +// +// return null; +// // return new ImageInfo(FormatDetails, BitsPerPixel, Comments, Format, +// // FormatName, height, MimeType, NumberOfImages, +// // PhysicalHeightDpi, PhysicalHeightInch, PhysicalWidthDpi, +// // PhysicalWidthInch, width, isProgressive, isTransparent, +// // usesPalette, ColorType); +// +// // boolean is_new_tga_format = isNewTGAFormat(byteSource); +// // +// // Debug.debug("is_new_tga_format", is_new_tga_format); +// } +// +// public boolean dumpImageFile(PrintWriter pw, ByteSource byteSource) +// throws ImageReadException, IOException +// { +// return false; +// } +// +// public BufferedImage getBufferedImage(ByteSource byteSource, Map params) +// throws ImageReadException, IOException +// { +// return null; +// } +// +// // public void writeImage(BufferedImage src, OutputStream os, Map params) +// // throws ImageWriteException, IOException +// // { +// // return false; +// // } +// +// public boolean embedICCProfile(File src, File dst, byte profile[]) +// { +// return false; +// } // //} \ No newline at end of file Modified: commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/JpegImageData.java URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/JpegImageData.java?rev=995859&r1=995858&r2=995859&view=diff ============================================================================== --- commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/JpegImageData.java (original) +++ commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/JpegImageData.java Fri Sep 10 16:33:35 2010 @@ -19,14 +19,14 @@ package org.apache.sanselan.formats.tiff public class JpegImageData extends TiffElement.DataElement { - public JpegImageData(int offset, int length, final byte data[]) - { - super(offset, length, data); - } + public JpegImageData(int offset, int length, final byte data[]) + { + super(offset, length, data); + } - public String getElementDescription(boolean verbose) - { - return "Jpeg image data: " + data.length + " bytes"; - } + public String getElementDescription(boolean verbose) + { + return "Jpeg image data: " + data.length + " bytes"; + } } \ No newline at end of file Modified: commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/TiffContents.java URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/TiffContents.java?rev=995859&r1=995858&r2=995859&view=diff ============================================================================== --- commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/TiffContents.java (original) +++ commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/TiffContents.java Fri Sep 10 16:33:35 2010 @@ -25,90 +25,90 @@ import org.apache.sanselan.util.Debug; public class TiffContents { - public final TiffHeader header; - public final ArrayList directories; + public final TiffHeader header; + public final ArrayList directories; - public TiffContents(TiffHeader tiffHeader, ArrayList directories) - { - this.header = tiffHeader; - this.directories = directories; - } - - public ArrayList getElements() throws ImageReadException - { - ArrayList result = new ArrayList(); - - result.add(header); - - for (int i = 0; i < directories.size(); i++) - { - TiffDirectory directory = (TiffDirectory) directories.get(i); - - result.add(directory); - - ArrayList fields = directory.entries; - for (int j = 0; j < fields.size(); j++) - { - TiffField field = (TiffField) fields.get(j); - TiffElement oversizeValue = field.getOversizeValueElement(); - if (null != oversizeValue) - result.add(oversizeValue); - } - - if (directory.hasTiffImageData()) - result.addAll(directory.getTiffRawImageDataElements()); - if (directory.hasJpegImageData()) - result.add(directory.getJpegRawImageDataElement()); - } - - return result; - } - - public TiffField findField(TagInfo tag) throws ImageReadException - { - for (int i = 0; i < directories.size(); i++) - { - TiffDirectory directory = (TiffDirectory) directories.get(i); - - TiffField field = directory.findField(tag); - if (null != field) - return field; - } - - return null; - } - - public void dissect(boolean verbose) throws ImageReadException - { - ArrayList elements = getElements(); - - Collections.sort(elements, TiffElement.COMPARATOR); - - int lastEnd = 0; - for (int i = 0; i < elements.size(); i++) - { - TiffElement element = (TiffElement) elements.get(i); - - if (element.offset > lastEnd) - Debug.debug("\t" + "gap: " + (element.offset - lastEnd)); - if (element.offset < lastEnd) - Debug.debug("\t" + "overlap"); - - Debug.debug("element, start: " + element.offset + ", length: " - + element.length + ", end: " - + (element.offset + element.length) + ": " - + element.getElementDescription(false)); - if (verbose) - { - String verbosity = element.getElementDescription(true); - if (null != verbosity) - Debug.debug(verbosity); - } - - lastEnd = element.offset + element.length; - } - Debug.debug("end: " + lastEnd); - Debug.debug(); - } + public TiffContents(TiffHeader tiffHeader, ArrayList directories) + { + this.header = tiffHeader; + this.directories = directories; + } + + public ArrayList getElements() throws ImageReadException + { + ArrayList result = new ArrayList(); + + result.add(header); + + for (int i = 0; i < directories.size(); i++) + { + TiffDirectory directory = (TiffDirectory) directories.get(i); + + result.add(directory); + + ArrayList fields = directory.entries; + for (int j = 0; j < fields.size(); j++) + { + TiffField field = (TiffField) fields.get(j); + TiffElement oversizeValue = field.getOversizeValueElement(); + if (null != oversizeValue) + result.add(oversizeValue); + } + + if (directory.hasTiffImageData()) + result.addAll(directory.getTiffRawImageDataElements()); + if (directory.hasJpegImageData()) + result.add(directory.getJpegRawImageDataElement()); + } + + return result; + } + + public TiffField findField(TagInfo tag) throws ImageReadException + { + for (int i = 0; i < directories.size(); i++) + { + TiffDirectory directory = (TiffDirectory) directories.get(i); + + TiffField field = directory.findField(tag); + if (null != field) + return field; + } + + return null; + } + + public void dissect(boolean verbose) throws ImageReadException + { + ArrayList elements = getElements(); + + Collections.sort(elements, TiffElement.COMPARATOR); + + int lastEnd = 0; + for (int i = 0; i < elements.size(); i++) + { + TiffElement element = (TiffElement) elements.get(i); + + if (element.offset > lastEnd) + Debug.debug("\t" + "gap: " + (element.offset - lastEnd)); + if (element.offset < lastEnd) + Debug.debug("\t" + "overlap"); + + Debug.debug("element, start: " + element.offset + ", length: " + + element.length + ", end: " + + (element.offset + element.length) + ": " + + element.getElementDescription(false)); + if (verbose) + { + String verbosity = element.getElementDescription(true); + if (null != verbosity) + Debug.debug(verbosity); + } + + lastEnd = element.offset + element.length; + } + Debug.debug("end: " + lastEnd); + Debug.debug(); + } } \ No newline at end of file Modified: commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/TiffDirectory.java URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/TiffDirectory.java?rev=995859&r1=995858&r2=995859&view=diff ============================================================================== --- commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/TiffDirectory.java (original) +++ commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/TiffDirectory.java Fri Sep 10 16:33:35 2010 @@ -30,274 +30,274 @@ public class TiffDirectory extends TiffE //extends BinaryFileFunctions { - public String description() - { - return TiffDirectory.description(type); - } - - public String getElementDescription(boolean verbose) - { - if (!verbose) - return "TIFF Directory (" + description() + ")"; - - int entryOffset = offset + TIFF_DIRECTORY_HEADER_LENGTH; - - StringBuffer result = new StringBuffer(); - for (int i = 0; i < entries.size(); i++) - { - TiffField entry = (TiffField) entries.get(i); - - result.append("\t"); - result.append("[" + entryOffset + "]: "); - result.append(entry.tagInfo.name); - result.append(" (" + entry.tag + ", 0x" - + Integer.toHexString(entry.tag) + ")"); - result.append(", " + entry.fieldType.name); - result.append(", " + entry.fieldType.getRawBytes(entry).length); - result.append(": " + entry.getValueDescription()); - - result.append("\n"); - - entryOffset += TIFF_ENTRY_LENGTH; - // entry.fillInValue(byteSource); - } - return result.toString(); - } - - public static final String description(int type) - { - switch (type) - { - case DIRECTORY_TYPE_UNKNOWN : - return "Unknown"; - case DIRECTORY_TYPE_ROOT : - return "Root"; - case DIRECTORY_TYPE_SUB : - return "Sub"; - case DIRECTORY_TYPE_THUMBNAIL : - return "Thumbnail"; - case DIRECTORY_TYPE_EXIF : - return "Exif"; - case DIRECTORY_TYPE_GPS : - return "Gps"; - case DIRECTORY_TYPE_INTEROPERABILITY : - return "Interoperability"; - default : - return "Bad Type"; - } - } - - public final int type; - public final ArrayList entries; - // public final int offset; - public final int nextDirectoryOffset; - - public TiffDirectory(int type, ArrayList entries, final int offset, - int nextDirectoryOffset) - { - super(offset, TIFF_DIRECTORY_HEADER_LENGTH + entries.size() - * TIFF_ENTRY_LENGTH + TIFF_DIRECTORY_FOOTER_LENGTH); - - this.type = type; - this.entries = entries; - this.nextDirectoryOffset = nextDirectoryOffset; - } - - public ArrayList getDirectoryEntrys() - { - return new ArrayList(entries); - } - - protected void fillInValues(ByteSource byteSource) - throws ImageReadException, IOException - { - for (int i = 0; i < entries.size(); i++) - { - TiffField entry = (TiffField) entries.get(i); - - entry.fillInValue(byteSource); - } - } - - public void dump() - { - for (int i = 0; i < entries.size(); i++) - { - TiffField entry = (TiffField) entries.get(i); - entry.dump(); - } - - } - - public boolean hasJpegImageData() throws ImageReadException - { - if (null != findField(TIFF_TAG_JPEG_INTERCHANGE_FORMAT)) - return true; - - return false; - } - - public boolean hasTiffImageData() throws ImageReadException - { - if (null != findField(TIFF_TAG_TILE_OFFSETS)) - return true; - - if (null != findField(TIFF_TAG_STRIP_OFFSETS)) - return true; - - return false; - } - - public BufferedImage getTiffImage() throws ImageReadException, IOException - { - Map params = null; - return getTiffImage(params); - } - - public BufferedImage getTiffImage(Map params) throws ImageReadException, - IOException - { - if (null == tiffImageData) - return null; - - return new TiffImageParser().getBufferedImage(this, params); - } - - public TiffField findField(TagInfo tag) throws ImageReadException - { - boolean failIfMissing = false; - return findField(tag, failIfMissing); - } - - public TiffField findField(TagInfo tag, boolean failIfMissing) - throws ImageReadException - { - if (entries == null) - return null; - - for (int i = 0; i < entries.size(); i++) - { - TiffField field = (TiffField) entries.get(i); - if (field.tag == tag.tag) - return field; - } - - if (failIfMissing) - throw new ImageReadException("Missing expected field: " - + tag.getDescription()); - - return null; - } - - public final class ImageDataElement extends TiffElement - { - public ImageDataElement(int offset, int length) - { - super(offset, length); - } - - public String getElementDescription(boolean verbose) - { - if (verbose) - return null; - return "ImageDataElement"; - } - } - - private ArrayList getRawImageDataElements(TiffField offsetsField, - TiffField byteCountsField) throws ImageReadException - { - int offsets[] = offsetsField.getIntArrayValue(); - int byteCounts[] = byteCountsField.getIntArrayValue(); - - if (offsets.length != byteCounts.length) - throw new ImageReadException("offsets.length(" + offsets.length - + ") != byteCounts.length(" + byteCounts.length + ")"); - - ArrayList result = new ArrayList(); - for (int i = 0; i < offsets.length; i++) - { - result.add(new ImageDataElement(offsets[i], byteCounts[i])); - } - return result; - } - - public ArrayList getTiffRawImageDataElements() throws ImageReadException - { - TiffField tileOffsets = findField(TIFF_TAG_TILE_OFFSETS); - TiffField tileByteCounts = findField(TIFF_TAG_TILE_BYTE_COUNTS); - TiffField stripOffsets = findField(TIFF_TAG_STRIP_OFFSETS); - TiffField stripByteCounts = findField(TIFF_TAG_STRIP_BYTE_COUNTS); - - if ((tileOffsets != null) && (tileByteCounts != null)) - { - return getRawImageDataElements(tileOffsets, tileByteCounts); - } - else if ((stripOffsets != null) && (stripByteCounts != null)) - { - return getRawImageDataElements(stripOffsets, stripByteCounts); - } - else - throw new ImageReadException("Couldn't find image data."); - } - - public boolean imageDataInStrips() throws ImageReadException - { - TiffField tileOffsets = findField(TIFF_TAG_TILE_OFFSETS); - TiffField tileByteCounts = findField(TIFF_TAG_TILE_BYTE_COUNTS); - TiffField stripOffsets = findField(TIFF_TAG_STRIP_OFFSETS); - TiffField stripByteCounts = findField(TIFF_TAG_STRIP_BYTE_COUNTS); - - if ((tileOffsets != null) && (tileByteCounts != null)) - return false; - else if ((stripOffsets != null) && (stripByteCounts != null)) - return true; - else if ((stripOffsets != null) && (stripByteCounts != null)) - return true; - else - throw new ImageReadException("Couldn't find image data."); - } - - public ImageDataElement getJpegRawImageDataElement() - throws ImageReadException - { - TiffField jpegInterchangeFormat = findField(TIFF_TAG_JPEG_INTERCHANGE_FORMAT); - TiffField jpegInterchangeFormatLength = findField(TIFF_TAG_JPEG_INTERCHANGE_FORMAT_LENGTH); - - if ((jpegInterchangeFormat != null) - && (jpegInterchangeFormatLength != null)) - { - int offset = jpegInterchangeFormat.getIntArrayValue()[0]; - int byteCount = jpegInterchangeFormatLength.getIntArrayValue()[0]; - - return new ImageDataElement(offset, byteCount); - } - else - throw new ImageReadException("Couldn't find image data."); - } - - private TiffImageData tiffImageData = null; - - public void setTiffImageData(TiffImageData rawImageData) - { - this.tiffImageData = rawImageData; - } - - public TiffImageData getTiffImageData() - { - return tiffImageData; - } - - private JpegImageData jpegImageData = null; - - public void setJpegImageData(JpegImageData value) - { - this.jpegImageData = value; - } - - public JpegImageData getJpegImageData() - { - return jpegImageData; - } + public String description() + { + return TiffDirectory.description(type); + } + + public String getElementDescription(boolean verbose) + { + if (!verbose) + return "TIFF Directory (" + description() + ")"; + + int entryOffset = offset + TIFF_DIRECTORY_HEADER_LENGTH; + + StringBuffer result = new StringBuffer(); + for (int i = 0; i < entries.size(); i++) + { + TiffField entry = (TiffField) entries.get(i); + + result.append("\t"); + result.append("[" + entryOffset + "]: "); + result.append(entry.tagInfo.name); + result.append(" (" + entry.tag + ", 0x" + + Integer.toHexString(entry.tag) + ")"); + result.append(", " + entry.fieldType.name); + result.append(", " + entry.fieldType.getRawBytes(entry).length); + result.append(": " + entry.getValueDescription()); + + result.append("\n"); + + entryOffset += TIFF_ENTRY_LENGTH; + // entry.fillInValue(byteSource); + } + return result.toString(); + } + + public static final String description(int type) + { + switch (type) + { + case DIRECTORY_TYPE_UNKNOWN : + return "Unknown"; + case DIRECTORY_TYPE_ROOT : + return "Root"; + case DIRECTORY_TYPE_SUB : + return "Sub"; + case DIRECTORY_TYPE_THUMBNAIL : + return "Thumbnail"; + case DIRECTORY_TYPE_EXIF : + return "Exif"; + case DIRECTORY_TYPE_GPS : + return "Gps"; + case DIRECTORY_TYPE_INTEROPERABILITY : + return "Interoperability"; + default : + return "Bad Type"; + } + } + + public final int type; + public final ArrayList entries; + // public final int offset; + public final int nextDirectoryOffset; + + public TiffDirectory(int type, ArrayList entries, final int offset, + int nextDirectoryOffset) + { + super(offset, TIFF_DIRECTORY_HEADER_LENGTH + entries.size() + * TIFF_ENTRY_LENGTH + TIFF_DIRECTORY_FOOTER_LENGTH); + + this.type = type; + this.entries = entries; + this.nextDirectoryOffset = nextDirectoryOffset; + } + + public ArrayList getDirectoryEntrys() + { + return new ArrayList(entries); + } + + protected void fillInValues(ByteSource byteSource) + throws ImageReadException, IOException + { + for (int i = 0; i < entries.size(); i++) + { + TiffField entry = (TiffField) entries.get(i); + + entry.fillInValue(byteSource); + } + } + + public void dump() + { + for (int i = 0; i < entries.size(); i++) + { + TiffField entry = (TiffField) entries.get(i); + entry.dump(); + } + + } + + public boolean hasJpegImageData() throws ImageReadException + { + if (null != findField(TIFF_TAG_JPEG_INTERCHANGE_FORMAT)) + return true; + + return false; + } + + public boolean hasTiffImageData() throws ImageReadException + { + if (null != findField(TIFF_TAG_TILE_OFFSETS)) + return true; + + if (null != findField(TIFF_TAG_STRIP_OFFSETS)) + return true; + + return false; + } + + public BufferedImage getTiffImage() throws ImageReadException, IOException + { + Map params = null; + return getTiffImage(params); + } + + public BufferedImage getTiffImage(Map params) throws ImageReadException, + IOException + { + if (null == tiffImageData) + return null; + + return new TiffImageParser().getBufferedImage(this, params); + } + + public TiffField findField(TagInfo tag) throws ImageReadException + { + boolean failIfMissing = false; + return findField(tag, failIfMissing); + } + + public TiffField findField(TagInfo tag, boolean failIfMissing) + throws ImageReadException + { + if (entries == null) + return null; + + for (int i = 0; i < entries.size(); i++) + { + TiffField field = (TiffField) entries.get(i); + if (field.tag == tag.tag) + return field; + } + + if (failIfMissing) + throw new ImageReadException("Missing expected field: " + + tag.getDescription()); + + return null; + } + + public final class ImageDataElement extends TiffElement + { + public ImageDataElement(int offset, int length) + { + super(offset, length); + } + + public String getElementDescription(boolean verbose) + { + if (verbose) + return null; + return "ImageDataElement"; + } + } + + private ArrayList getRawImageDataElements(TiffField offsetsField, + TiffField byteCountsField) throws ImageReadException + { + int offsets[] = offsetsField.getIntArrayValue(); + int byteCounts[] = byteCountsField.getIntArrayValue(); + + if (offsets.length != byteCounts.length) + throw new ImageReadException("offsets.length(" + offsets.length + + ") != byteCounts.length(" + byteCounts.length + ")"); + + ArrayList result = new ArrayList(); + for (int i = 0; i < offsets.length; i++) + { + result.add(new ImageDataElement(offsets[i], byteCounts[i])); + } + return result; + } + + public ArrayList getTiffRawImageDataElements() throws ImageReadException + { + TiffField tileOffsets = findField(TIFF_TAG_TILE_OFFSETS); + TiffField tileByteCounts = findField(TIFF_TAG_TILE_BYTE_COUNTS); + TiffField stripOffsets = findField(TIFF_TAG_STRIP_OFFSETS); + TiffField stripByteCounts = findField(TIFF_TAG_STRIP_BYTE_COUNTS); + + if ((tileOffsets != null) && (tileByteCounts != null)) + { + return getRawImageDataElements(tileOffsets, tileByteCounts); + } + else if ((stripOffsets != null) && (stripByteCounts != null)) + { + return getRawImageDataElements(stripOffsets, stripByteCounts); + } + else + throw new ImageReadException("Couldn't find image data."); + } + + public boolean imageDataInStrips() throws ImageReadException + { + TiffField tileOffsets = findField(TIFF_TAG_TILE_OFFSETS); + TiffField tileByteCounts = findField(TIFF_TAG_TILE_BYTE_COUNTS); + TiffField stripOffsets = findField(TIFF_TAG_STRIP_OFFSETS); + TiffField stripByteCounts = findField(TIFF_TAG_STRIP_BYTE_COUNTS); + + if ((tileOffsets != null) && (tileByteCounts != null)) + return false; + else if ((stripOffsets != null) && (stripByteCounts != null)) + return true; + else if ((stripOffsets != null) && (stripByteCounts != null)) + return true; + else + throw new ImageReadException("Couldn't find image data."); + } + + public ImageDataElement getJpegRawImageDataElement() + throws ImageReadException + { + TiffField jpegInterchangeFormat = findField(TIFF_TAG_JPEG_INTERCHANGE_FORMAT); + TiffField jpegInterchangeFormatLength = findField(TIFF_TAG_JPEG_INTERCHANGE_FORMAT_LENGTH); + + if ((jpegInterchangeFormat != null) + && (jpegInterchangeFormatLength != null)) + { + int offset = jpegInterchangeFormat.getIntArrayValue()[0]; + int byteCount = jpegInterchangeFormatLength.getIntArrayValue()[0]; + + return new ImageDataElement(offset, byteCount); + } + else + throw new ImageReadException("Couldn't find image data."); + } + + private TiffImageData tiffImageData = null; + + public void setTiffImageData(TiffImageData rawImageData) + { + this.tiffImageData = rawImageData; + } + + public TiffImageData getTiffImageData() + { + return tiffImageData; + } + + private JpegImageData jpegImageData = null; + + public void setJpegImageData(JpegImageData value) + { + this.jpegImageData = value; + } + + public JpegImageData getJpegImageData() + { + return jpegImageData; + } } Modified: commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/TiffElement.java URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/TiffElement.java?rev=995859&r1=995858&r2=995859&view=diff ============================================================================== --- commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/TiffElement.java (original) +++ commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/TiffElement.java Fri Sep 10 16:33:35 2010 @@ -20,57 +20,57 @@ import java.util.Comparator; public abstract class TiffElement { - public final int offset; - public final int length; + public final int offset; + public final int length; - public TiffElement(int offset, int length) - { - this.offset = offset; - this.length = length; - } - - public String getElementDescription() - { - return getElementDescription(false); - } - - public abstract String getElementDescription(boolean verbose); - - public static final Comparator COMPARATOR = new Comparator() - { - public int compare(Object o1, Object o2) - { - TiffElement e1 = (TiffElement) o1; - TiffElement e2 = (TiffElement) o2; - return e1.offset - e2.offset; - } - }; - - public static abstract class DataElement extends TiffElement - { - public final byte data[]; - - public DataElement(int offset, int length, final byte data[]) - { - super(offset, length); - - this.data = data; - } - - } - - public static final class Stub extends TiffElement - { - public Stub(int offset, int length) - { - super(offset, length); - } - - public String getElementDescription(boolean verbose) - { - return "Element, offset: " + offset + ", length: " + length - + ", last: " + (offset + length) + ""; - } + public TiffElement(int offset, int length) + { + this.offset = offset; + this.length = length; + } + + public String getElementDescription() + { + return getElementDescription(false); + } + + public abstract String getElementDescription(boolean verbose); + + public static final Comparator COMPARATOR = new Comparator() + { + public int compare(Object o1, Object o2) + { + TiffElement e1 = (TiffElement) o1; + TiffElement e2 = (TiffElement) o2; + return e1.offset - e2.offset; + } + }; + + public static abstract class DataElement extends TiffElement + { + public final byte data[]; + + public DataElement(int offset, int length, final byte data[]) + { + super(offset, length); + + this.data = data; + } + + } + + public static final class Stub extends TiffElement + { + public Stub(int offset, int length) + { + super(offset, length); + } + + public String getElementDescription(boolean verbose) + { + return "Element, offset: " + offset + ", length: " + length + + ", last: " + (offset + length) + ""; + } - } + } } \ No newline at end of file