public FormatCompliance getFormatCompliance(ByteSource byteSource) throws ImageReadException, IOException { FormatCompliance formatCompliance = FormatCompliance.getDefault(); Map params = null; new TiffReader(isStrict(params)).readContents(byteSource, params, formatCompliance); return formatCompliance; }
public TiffContents readContents(ByteSource byteSource, Map params, FormatCompliance formatCompliance) throws ImageReadException, IOException { Collector collector = new Collector(params); read(byteSource, params, formatCompliance, collector); TiffContents contents = collector.getContents(); return contents; }
private TiffHeader readTiffHeader(InputStream is, FormatCompliance formatCompliance) throws ImageReadException, IOException { int BYTE_ORDER_1 = readByte("BYTE_ORDER_1", is, "Not a Valid TIFF File"); int BYTE_ORDER_2 = readByte("BYTE_ORDER_2", is, "Not a Valid TIFF File"); setByteOrder(BYTE_ORDER_1, BYTE_ORDER_2); int tiffVersion = read2Bytes("tiffVersion", is, "Not a Valid TIFF File"); if (tiffVersion != 42) throw new ImageReadException("Unknown Tiff Version: " + tiffVersion); int offsetToFirstIFD = read4Bytes("offsetToFirstIFD", is, "Not a Valid TIFF File"); skipBytes(is, offsetToFirstIFD - 8, "Not a Valid TIFF File: couldn't find IFDs"); if (debug) System.out.println(""); return new TiffHeader(BYTE_ORDER_1, tiffVersion, offsetToFirstIFD); }
public byte[] getICCProfileBytes(ByteSource byteSource, Map params) throws ImageReadException, IOException { FormatCompliance formatCompliance = FormatCompliance.getDefault(); TiffContents contents = new TiffReader(isStrict(params)) .readFirstDirectory(byteSource, params, false, formatCompliance); TiffDirectory directory = (TiffDirectory) contents.directories.get(0); TiffField field = directory.findField(EXIF_TAG_ICC_PROFILE); if (null == field) return null; return field.oversizeValue; }
entryCount = read2Bytes("DirectoryEntryCount", is, "Not a Valid TIFF File"); } catch (IOException e) int tag = read2Bytes("Tag", is, "Not a Valid TIFF File"); int type = read2Bytes("Type", is, "Not a Valid TIFF File"); int length = read4Bytes("Length", is, "Not a Valid TIFF File"); byte valueOffsetBytes[] = readByteArray("ValueOffset", 4, is, "Not a Valid TIFF File"); int valueOffset = convertByteArrayToInt("ValueOffset", valueOffsetBytes); valueOffset, valueOffsetBytes, getByteOrder()); field.setSortHint(i); int nextDirectoryOffset = read4Bytes("nextDirectoryOffset", is, "Not a Valid TIFF File"); TiffImageData rawImageData = getTiffRawImageData( byteSource, directory); directory.setTiffImageData(rawImageData); JpegImageData rawJpegImageData = getJpegRawImageData( byteSource, directory); directory.setJpegImageData(rawJpegImageData); boolean subDirectoryRead = readDirectory(byteSource, subDirectoryOffset, subDirectoryType,
public List collectRawImageData(ByteSource byteSource, Map params) throws ImageReadException, IOException { FormatCompliance formatCompliance = FormatCompliance.getDefault(); TiffContents contents = new TiffReader(isStrict(params)) .readDirectories(byteSource, true, formatCompliance); List result = new ArrayList(); for (int i = 0; i < contents.directories.size(); i++) { TiffDirectory directory = (TiffDirectory) contents.directories .get(i); List dataElements = directory.getTiffRawImageDataElements(); for (int j = 0; j < dataElements.size(); j++) { TiffDirectory.ImageDataElement element = (TiffDirectory.ImageDataElement) dataElements .get(j); byte bytes[] = byteSource.getBlock(element.offset, element.length); result.add(bytes); } } return result; }
entryCount = read2Bytes("DirectoryEntryCount", is, "Not a Valid TIFF File"); } catch (IOException e) int tag = read2Bytes("Tag", is, "Not a Valid TIFF File"); int type = read2Bytes("Type", is, "Not a Valid TIFF File"); int length = read4Bytes("Length", is, "Not a Valid TIFF File"); byte valueOffsetBytes[] = readByteArray("ValueOffset", 4, is, "Not a Valid TIFF File"); int valueOffset = convertByteArrayToInt("ValueOffset", valueOffsetBytes); valueOffset, valueOffsetBytes, getByteOrder()); field.setSortHint(i); int nextDirectoryOffset = read4Bytes("nextDirectoryOffset", is, "Not a Valid TIFF File"); TiffImageData rawImageData = getTiffRawImageData( byteSource, directory); directory.setTiffImageData(rawImageData); JpegImageData rawJpegImageData = getJpegRawImageData( byteSource, directory); directory.setJpegImageData(rawJpegImageData); boolean subDirectoryRead = readDirectory(byteSource, subDirectoryOffset, subDirectoryType,
public byte[] getICCProfileBytes(ByteSource byteSource, Map params) throws ImageReadException, IOException { FormatCompliance formatCompliance = FormatCompliance.getDefault(); TiffContents contents = new TiffReader(isStrict(params)) .readFirstDirectory(byteSource, params, false, formatCompliance); TiffDirectory directory = (TiffDirectory) contents.directories.get(0); TiffField field = directory.findField(EXIF_TAG_ICC_PROFILE); if (null == field) return null; return field.oversizeValue; }
public List collectRawImageData(ByteSource byteSource, Map params) throws ImageReadException, IOException { FormatCompliance formatCompliance = FormatCompliance.getDefault(); TiffContents contents = new TiffReader(isStrict(params)) .readDirectories(byteSource, true, formatCompliance); List result = new ArrayList(); for (int i = 0; i < contents.directories.size(); i++) { TiffDirectory directory = (TiffDirectory) contents.directories .get(i); List dataElements = directory.getTiffRawImageDataElements(); for (int j = 0; j < dataElements.size(); j++) { TiffDirectory.ImageDataElement element = (TiffDirectory.ImageDataElement) dataElements .get(j); byte bytes[] = byteSource.getBlock(element.offset, element.length); result.add(bytes); } } return result; }
private TiffHeader readTiffHeader(InputStream is, FormatCompliance formatCompliance) throws ImageReadException, IOException { int BYTE_ORDER_1 = readByte("BYTE_ORDER_1", is, "Not a Valid TIFF File"); int BYTE_ORDER_2 = readByte("BYTE_ORDER_2", is, "Not a Valid TIFF File"); setByteOrder(BYTE_ORDER_1, BYTE_ORDER_2); int tiffVersion = read2Bytes("tiffVersion", is, "Not a Valid TIFF File"); if (tiffVersion != 42) throw new ImageReadException("Unknown Tiff Version: " + tiffVersion); int offsetToFirstIFD = read4Bytes("offsetToFirstIFD", is, "Not a Valid TIFF File"); skipBytes(is, offsetToFirstIFD - 8, "Not a Valid TIFF File: couldn't find IFDs"); if (debug) System.out.println(""); return new TiffHeader(BYTE_ORDER_1, tiffVersion, offsetToFirstIFD); }
public FormatCompliance getFormatCompliance(ByteSource byteSource) throws ImageReadException, IOException { FormatCompliance formatCompliance = FormatCompliance.getDefault(); Map params = null; new TiffReader(isStrict(params)).readContents(byteSource, params, formatCompliance); return formatCompliance; }
public BufferedImage getBufferedImage(ByteSource byteSource, Map params) throws ImageReadException, IOException { FormatCompliance formatCompliance = FormatCompliance.getDefault(); TiffContents contents = new TiffReader(isStrict(params)) .readFirstDirectory(byteSource, params, true, formatCompliance); TiffDirectory directory = (TiffDirectory) contents.directories.get(0); BufferedImage result = directory.getTiffImage(params); if (null == result) throw new ImageReadException("TIFF does not contain an image."); return result; }
public String getXmpXml(ByteSource byteSource, Map params) throws ImageReadException, IOException { FormatCompliance formatCompliance = FormatCompliance.getDefault(); TiffContents contents = new TiffReader(isStrict(params)) .readDirectories(byteSource, false, formatCompliance); TiffDirectory directory = (TiffDirectory) contents.directories.get(0); TiffField xmpField = directory.findField(TIFF_TAG_XMP, false); if (xmpField == null) return null; byte bytes[] = xmpField.getByteArrayValue(); try { // segment data is UTF-8 encoded xml. String xml = new String(bytes, "utf-8"); return xml; } catch (UnsupportedEncodingException e) { throw new ImageReadException("Invalid JPEG XMP Segment."); } }
public TiffContents readContents(ByteSource byteSource, Map params, FormatCompliance formatCompliance) throws ImageReadException, IOException { Collector collector = new Collector(params); read(byteSource, params, formatCompliance, collector); TiffContents contents = collector.getContents(); return contents; }
.getDefault(); Map params = null; TiffContents contents = new TiffReader(true).readContents( byteSource, params, formatCompliance);
public BufferedImage getBufferedImage(ByteSource byteSource, Map params) throws ImageReadException, IOException { FormatCompliance formatCompliance = FormatCompliance.getDefault(); TiffContents contents = new TiffReader(isStrict(params)) .readFirstDirectory(byteSource, params, true, formatCompliance); TiffDirectory directory = (TiffDirectory) contents.directories.get(0); BufferedImage result = directory.getTiffImage(params); if (null == result) throw new ImageReadException("TIFF does not contain an image."); return result; }
public String getXmpXml(ByteSource byteSource, Map params) throws ImageReadException, IOException { FormatCompliance formatCompliance = FormatCompliance.getDefault(); TiffContents contents = new TiffReader(isStrict(params)) .readDirectories(byteSource, false, formatCompliance); TiffDirectory directory = (TiffDirectory) contents.directories.get(0); TiffField xmpField = directory.findField(TIFF_TAG_XMP, false); if (xmpField == null) return null; byte bytes[] = xmpField.getByteArrayValue(); try { // segment data is UTF-8 encoded xml. String xml = new String(bytes, "utf-8"); return xml; } catch (UnsupportedEncodingException e) { throw new ImageReadException("Invalid JPEG XMP Segment."); } }
public TiffContents readFirstDirectory(ByteSource byteSource, Map params, boolean readImageData, FormatCompliance formatCompliance) throws ImageReadException, IOException { Collector collector = new FirstDirectoryCollector(readImageData); read(byteSource, params, formatCompliance, collector); TiffContents contents = collector.getContents(); if (contents.directories.size() < 1) throw new ImageReadException( "Image did not contain any directories."); return contents; }
.getDefault(); Map params = null; TiffContents contents = new TiffReader(true).readContents( byteSource, params, formatCompliance);
public Dimension getImageSize(ByteSource byteSource, Map params) throws ImageReadException, IOException { FormatCompliance formatCompliance = FormatCompliance.getDefault(); TiffContents contents = new TiffReader(isStrict(params)) .readFirstDirectory(byteSource, params, false, formatCompliance); TiffDirectory directory = (TiffDirectory) contents.directories.get(0); int width = directory.findField(TIFF_TAG_IMAGE_WIDTH).getIntValue(); int height = directory.findField(TIFF_TAG_IMAGE_LENGTH).getIntValue(); return new Dimension(width, height); }