javax.imageio.plugins.tiff.BaselineTIFFTagSet Java Examples

The following examples show how to use javax.imageio.plugins.tiff.BaselineTIFFTagSet. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TIFFYCbCrColorConverter.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public TIFFYCbCrColorConverter(TIFFImageMetadata metadata) {
    TIFFImageMetadata tmetadata = metadata;

    TIFFField f =
       tmetadata.getTIFFField(BaselineTIFFTagSet.TAG_Y_CB_CR_COEFFICIENTS);
    if (f != null && f.getCount() == 3) {
        this.lumaRed = f.getAsFloat(0);
        this.lumaGreen = f.getAsFloat(1);
        this.lumaBlue = f.getAsFloat(2);
    }

    f =
      tmetadata.getTIFFField(BaselineTIFFTagSet.TAG_REFERENCE_BLACK_WHITE);
    if (f != null && f.getCount() == 6) {
        this.referenceBlackY = f.getAsFloat(0);
        this.referenceWhiteY = f.getAsFloat(1);
        this.referenceBlackCb = f.getAsFloat(2);
        this.referenceWhiteCb = f.getAsFloat(3);
        this.referenceBlackCr = f.getAsFloat(4);
        this.referenceWhiteCr = f.getAsFloat(5);
    }
}
 
Example #2
Source File: TIFFImageWriter.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
private TIFFIFD readIFD(int imageIndex) throws IOException {
    if (stream == null) {
        throw new IllegalStateException("Output not set!");
    }
    if (imageIndex < 0) {
        throw new IndexOutOfBoundsException("imageIndex < 0!");
    }

    stream.mark();
    long[] ifdpos = new long[1];
    long[] ifd = new long[1];
    locateIFD(imageIndex, ifdpos, ifd);
    if (ifd[0] == 0) {
        stream.reset();
        throw new IndexOutOfBoundsException
            ("imageIndex out of bounds!");
    }

    List<TIFFTagSet> tagSets = new ArrayList<TIFFTagSet>(1);
    tagSets.add(BaselineTIFFTagSet.getInstance());
    TIFFIFD rootIFD = new TIFFIFD(tagSets);
    rootIFD.initialize(stream, true, false, false);
    stream.reset();

    return rootIFD;
}
 
Example #3
Source File: TIFFImageWriter.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
/**
 * Converts a native
 * {@code javax_imageio_tiff_image_1.0} tree to a
 * {@code TIFFImageMetadata} object.
 *
 * @param inData The metadata object.
 * @return a {@code TIFFImageMetadata} or {@code null} if
 * the native tree derived from the input object is {@code null}.
 * @throws IllegalArgumentException if {@code inData} is
 * {@code null} or does not support the native metadata format.
 * @throws IIOInvalidTreeException if {@code inData} generates an
 * invalid native metadata tree.
 */
private TIFFImageMetadata convertNativeImageMetadata(IIOMetadata inData)
    throws IIOInvalidTreeException {

    if(inData == null) {
        throw new NullPointerException("inData == null!");
    } else if(!Arrays.asList(inData.getMetadataFormatNames()).contains(
                  TIFFImageMetadata.NATIVE_METADATA_FORMAT_NAME)) {
        throw new IllegalArgumentException
            ("inData does not support native metadata format!");
    }

    TIFFImageMetadata outData = null;

    String formatName = TIFFImageMetadata.NATIVE_METADATA_FORMAT_NAME;
    Node tree = inData.getAsTree(formatName);
    if (tree != null) {
        List<TIFFTagSet> tagSets = new ArrayList<TIFFTagSet>(1);
        tagSets.add(BaselineTIFFTagSet.getInstance());
        outData = new TIFFImageMetadata(tagSets);
        outData.setFromTree(formatName, tree);
    }

    return outData;
}
 
Example #4
Source File: TIFFImageWriter.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
/**
 * Converts a standard {@code javax_imageio_1.0} tree to a
 * {@code TIFFImageMetadata} object.
 *
 * @param inData The metadata object.
 * @return a {@code TIFFImageMetadata} or {@code null} if
 * the standard tree derived from the input object is {@code null}.
 * @throws IllegalArgumentException if {@code inData} is
 * {@code null}.
 * @throws IllegalArgumentException if {@code inData} does not support
 * the standard metadata format.
 * @throws IIOInvalidTreeException if {@code inData} generates an
 * invalid standard metadata tree.
 */
private TIFFImageMetadata convertStandardImageMetadata(IIOMetadata inData)
    throws IIOInvalidTreeException {

    if(inData == null) {
        throw new NullPointerException("inData == null!");
    } else if(!inData.isStandardMetadataFormatSupported()) {
        throw new IllegalArgumentException
            ("inData does not support standard metadata format!");
    }

    TIFFImageMetadata outData = null;

    String formatName = IIOMetadataFormatImpl.standardMetadataFormatName;
    Node tree = inData.getAsTree(formatName);
    if (tree != null) {
        List<TIFFTagSet> tagSets = new ArrayList<TIFFTagSet>(1);
        tagSets.add(BaselineTIFFTagSet.getInstance());
        outData = new TIFFImageMetadata(tagSets);
        outData.setFromTree(formatName, tree);
    }

    return outData;
}
 
Example #5
Source File: TIFFImageWriter.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
public IIOMetadata
    getDefaultImageMetadata(ImageTypeSpecifier imageType,
                            ImageWriteParam param) {

    List<TIFFTagSet> tagSets = new ArrayList<TIFFTagSet>(1);
    tagSets.add(BaselineTIFFTagSet.getInstance());
    TIFFImageMetadata imageMetadata = new TIFFImageMetadata(tagSets);

    if(imageType != null) {
        TIFFImageMetadata im =
            (TIFFImageMetadata)convertImageMetadata(imageMetadata,
                                                    imageType,
                                                    param);
        if(im != null) {
            imageMetadata = im;
        }
    }

    return imageMetadata;
}
 
Example #6
Source File: TIFFT4Compressor.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
/**
 * Sets the value of the {@code metadata} field.
 *
 * <p> The implementation in this class also sets local options
 * from the T4_OPTIONS field if it exists, and if it doesn't, adds
 * it with default values.</p>
 *
 * @param metadata the {@code IIOMetadata} object for the
 * image being written.
 *
 * @see #getMetadata()
 */
public void setMetadata(IIOMetadata metadata) {
    super.setMetadata(metadata);

    if (metadata instanceof TIFFImageMetadata) {
        TIFFImageMetadata tim = (TIFFImageMetadata)metadata;
        TIFFField f = tim.getTIFFField(BaselineTIFFTagSet.TAG_T4_OPTIONS);
        if (f != null) {
            int options = f.getAsInt(0);
            is1DMode = (options & 0x1) == 0;
            isEOLAligned = (options & 0x4) == 0x4;
        } else {
            long[] oarray = new long[1];
            oarray[0] = (isEOLAligned ? 0x4 : 0x0) |
                (is1DMode ? 0x0 : 0x1);

            BaselineTIFFTagSet base = BaselineTIFFTagSet.getInstance();
            TIFFField T4Options =
              new TIFFField(base.getTag(BaselineTIFFTagSet.TAG_T4_OPTIONS),
                            TIFFTag.TIFF_LONG,
                            1,
                            oarray);
            tim.rootIFD.addTIFFField(T4Options);
        }
    }
}
 
Example #7
Source File: TIFFImageReader.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
private long getTileOrStripOffset(int tileIndex) throws IIOException {
    TIFFField f
            = imageMetadata.getTIFFField(BaselineTIFFTagSet.TAG_TILE_OFFSETS);
    if (f == null) {
        f = imageMetadata.getTIFFField(BaselineTIFFTagSet.TAG_STRIP_OFFSETS);
    }
    if (f == null) {
        f = imageMetadata.getTIFFField(BaselineTIFFTagSet.TAG_JPEG_INTERCHANGE_FORMAT);
    }

    if (f == null) {
        throw new IIOException("Missing required strip or tile offsets field.");
    }

    return f.getAsLong(tileIndex);
}
 
Example #8
Source File: TIFFImageReader.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
protected void resetLocal() {
    stream = null;
    gotHeader = false;
    imageReadParam = getDefaultReadParam();
    streamMetadata = null;
    currIndex = -1;
    imageMetadata = null;
    imageStartPosition = new ArrayList<Long>();
    numImages = -1;
    imageTypeMap = new HashMap<Integer, List<ImageTypeSpecifier>>();
    width = -1;
    height = -1;
    numBands = -1;
    tileOrStripWidth = -1;
    tileOrStripHeight = -1;
    planarConfiguration = BaselineTIFFTagSet.PLANAR_CONFIGURATION_CHUNKY;
}
 
Example #9
Source File: TIFFImageWriter.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public IIOMetadata
    getDefaultImageMetadata(ImageTypeSpecifier imageType,
                            ImageWriteParam param) {

    List<TIFFTagSet> tagSets = new ArrayList<TIFFTagSet>(1);
    tagSets.add(BaselineTIFFTagSet.getInstance());
    TIFFImageMetadata imageMetadata = new TIFFImageMetadata(tagSets);

    if(imageType != null) {
        TIFFImageMetadata im =
            (TIFFImageMetadata)convertImageMetadata(imageMetadata,
                                                    imageType,
                                                    param);
        if(im != null) {
            imageMetadata = im;
        }
    }

    return imageMetadata;
}
 
Example #10
Source File: TIFFImageWriter.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Converts a standard {@code javax_imageio_1.0} tree to a
 * {@code TIFFImageMetadata} object.
 *
 * @param inData The metadata object.
 * @return a {@code TIFFImageMetadata} or {@code null} if
 * the standard tree derived from the input object is {@code null}.
 * @throws IllegalArgumentException if {@code inData} is
 * {@code null}.
 * @throws IllegalArgumentException if {@code inData} does not support
 * the standard metadata format.
 * @throws IIOInvalidTreeException if {@code inData} generates an
 * invalid standard metadata tree.
 */
private TIFFImageMetadata convertStandardImageMetadata(IIOMetadata inData)
    throws IIOInvalidTreeException {

    if(inData == null) {
        throw new NullPointerException("inData == null!");
    } else if(!inData.isStandardMetadataFormatSupported()) {
        throw new IllegalArgumentException
            ("inData does not support standard metadata format!");
    }

    TIFFImageMetadata outData = null;

    String formatName = IIOMetadataFormatImpl.standardMetadataFormatName;
    Node tree = inData.getAsTree(formatName);
    if (tree != null) {
        List<TIFFTagSet> tagSets = new ArrayList<TIFFTagSet>(1);
        tagSets.add(BaselineTIFFTagSet.getInstance());
        outData = new TIFFImageMetadata(tagSets);
        outData.setFromTree(formatName, tree);
    }

    return outData;
}
 
Example #11
Source File: TIFFImageWriter.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Converts a native
 * {@code javax_imageio_tiff_image_1.0} tree to a
 * {@code TIFFImageMetadata} object.
 *
 * @param inData The metadata object.
 * @return a {@code TIFFImageMetadata} or {@code null} if
 * the native tree derived from the input object is {@code null}.
 * @throws IllegalArgumentException if {@code inData} is
 * {@code null} or does not support the native metadata format.
 * @throws IIOInvalidTreeException if {@code inData} generates an
 * invalid native metadata tree.
 */
private TIFFImageMetadata convertNativeImageMetadata(IIOMetadata inData)
    throws IIOInvalidTreeException {

    if(inData == null) {
        throw new NullPointerException("inData == null!");
    } else if(!Arrays.asList(inData.getMetadataFormatNames()).contains(
                  TIFFImageMetadata.NATIVE_METADATA_FORMAT_NAME)) {
        throw new IllegalArgumentException
            ("inData does not support native metadata format!");
    }

    TIFFImageMetadata outData = null;

    String formatName = TIFFImageMetadata.NATIVE_METADATA_FORMAT_NAME;
    Node tree = inData.getAsTree(formatName);
    if (tree != null) {
        List<TIFFTagSet> tagSets = new ArrayList<TIFFTagSet>(1);
        tagSets.add(BaselineTIFFTagSet.getInstance());
        outData = new TIFFImageMetadata(tagSets);
        outData.setFromTree(formatName, tree);
    }

    return outData;
}
 
Example #12
Source File: TIFFImageWriter.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private TIFFIFD readIFD(int imageIndex) throws IOException {
    if (stream == null) {
        throw new IllegalStateException("Output not set!");
    }
    if (imageIndex < 0) {
        throw new IndexOutOfBoundsException("imageIndex < 0!");
    }

    stream.mark();
    long[] ifdpos = new long[1];
    long[] ifd = new long[1];
    locateIFD(imageIndex, ifdpos, ifd);
    if (ifd[0] == 0) {
        stream.reset();
        throw new IndexOutOfBoundsException
            ("imageIndex out of bounds!");
    }

    List<TIFFTagSet> tagSets = new ArrayList<TIFFTagSet>(1);
    tagSets.add(BaselineTIFFTagSet.getInstance());
    TIFFIFD rootIFD = new TIFFIFD(tagSets);
    rootIFD.initialize(stream, true, false, false);
    stream.reset();

    return rootIFD;
}
 
Example #13
Source File: TIFFImageReader.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private long getTileOrStripOffset(int tileIndex) throws IIOException {
    TIFFField f
            = imageMetadata.getTIFFField(BaselineTIFFTagSet.TAG_TILE_OFFSETS);
    if (f == null) {
        f = imageMetadata.getTIFFField(BaselineTIFFTagSet.TAG_STRIP_OFFSETS);
    }
    if (f == null) {
        f = imageMetadata.getTIFFField(BaselineTIFFTagSet.TAG_JPEG_INTERCHANGE_FORMAT);
    }

    if (f == null) {
        throw new IIOException("Missing required strip or tile offsets field.");
    }

    return f.getAsLong(tileIndex);
}
 
Example #14
Source File: TIFFJPEGDecompressor.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
public void beginDecoding() {
    // Initialize the JPEG reader if needed.
    if(this.JPEGReader == null) {
        // Get all JPEG readers.
        Iterator<ImageReader> iter = ImageIO.getImageReadersByFormatName("jpeg");

        if(!iter.hasNext()) {
            throw new IllegalStateException("No JPEG readers found!");
        }

        // Initialize reader to the first one.
        this.JPEGReader = iter.next();

        this.JPEGParam = JPEGReader.getDefaultReadParam();
    }

    // Get the JPEGTables field.
    TIFFImageMetadata tmetadata = (TIFFImageMetadata)metadata;
    TIFFField f =
        tmetadata.getTIFFField(BaselineTIFFTagSet.TAG_JPEG_TABLES);

    if (f != null) {
        this.hasJPEGTables = true;
        this.tables = f.getAsBytes();
    } else {
        this.hasJPEGTables = false;
    }
}
 
Example #15
Source File: TIFFIFD.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
private static void initializeEssentialTags() {
    Set<Integer> tags = essentialTags;
    if (tags == null) {
        essentialTags = tags = Set.of(
            BaselineTIFFTagSet.TAG_BITS_PER_SAMPLE,
            BaselineTIFFTagSet.TAG_COLOR_MAP,
            BaselineTIFFTagSet.TAG_COMPRESSION,
            BaselineTIFFTagSet.TAG_EXTRA_SAMPLES,
            BaselineTIFFTagSet.TAG_FILL_ORDER,
            BaselineTIFFTagSet.TAG_ICC_PROFILE,
            BaselineTIFFTagSet.TAG_IMAGE_LENGTH,
            BaselineTIFFTagSet.TAG_IMAGE_WIDTH,
            BaselineTIFFTagSet.TAG_JPEG_AC_TABLES,
            BaselineTIFFTagSet.TAG_JPEG_DC_TABLES,
            BaselineTIFFTagSet.TAG_JPEG_INTERCHANGE_FORMAT,
            BaselineTIFFTagSet.TAG_JPEG_INTERCHANGE_FORMAT_LENGTH,
            BaselineTIFFTagSet.TAG_JPEG_PROC,
            BaselineTIFFTagSet.TAG_JPEG_Q_TABLES,
            BaselineTIFFTagSet.TAG_JPEG_RESTART_INTERVAL,
            BaselineTIFFTagSet.TAG_JPEG_TABLES,
            BaselineTIFFTagSet.TAG_PHOTOMETRIC_INTERPRETATION,
            BaselineTIFFTagSet.TAG_PLANAR_CONFIGURATION,
            BaselineTIFFTagSet.TAG_PREDICTOR,
            BaselineTIFFTagSet.TAG_REFERENCE_BLACK_WHITE,
            BaselineTIFFTagSet.TAG_ROWS_PER_STRIP,
            BaselineTIFFTagSet.TAG_SAMPLES_PER_PIXEL,
            BaselineTIFFTagSet.TAG_SAMPLE_FORMAT,
            BaselineTIFFTagSet.TAG_STRIP_BYTE_COUNTS,
            BaselineTIFFTagSet.TAG_STRIP_OFFSETS,
            BaselineTIFFTagSet.TAG_T4_OPTIONS,
            BaselineTIFFTagSet.TAG_T6_OPTIONS,
            BaselineTIFFTagSet.TAG_TILE_BYTE_COUNTS,
            BaselineTIFFTagSet.TAG_TILE_LENGTH,
            BaselineTIFFTagSet.TAG_TILE_OFFSETS,
            BaselineTIFFTagSet.TAG_TILE_WIDTH,
            BaselineTIFFTagSet.TAG_Y_CB_CR_COEFFICIENTS,
            BaselineTIFFTagSet.TAG_Y_CB_CR_SUBSAMPLING
        );
    }
}
 
Example #16
Source File: TIFFImageReader.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private long getTileOrStripByteCount(int tileIndex) throws IOException {
    TIFFField f
            = imageMetadata.getTIFFField(BaselineTIFFTagSet.TAG_TILE_BYTE_COUNTS);
    if (f == null) {
        f
                = imageMetadata.getTIFFField(BaselineTIFFTagSet.TAG_STRIP_BYTE_COUNTS);
    }
    if (f == null) {
        f = imageMetadata.getTIFFField(BaselineTIFFTagSet.TAG_JPEG_INTERCHANGE_FORMAT_LENGTH);
    }

    long tileOrStripByteCount;
    if (f != null) {
        tileOrStripByteCount = f.getAsLong(tileIndex);
    } else {
        processWarningOccurred("TIFF directory contains neither StripByteCounts nor TileByteCounts field: attempting to calculate from strip or tile width and height.");

        // Initialize to number of bytes per strip or tile assuming
        // no compression.
        int bitsPerPixel = bitsPerSample[0];
        for (int i = 1; i < samplesPerPixel; i++) {
            bitsPerPixel += bitsPerSample[i];
        }
        int bytesPerRow = (getTileOrStripWidth() * bitsPerPixel + 7) / 8;
        tileOrStripByteCount = bytesPerRow * getTileOrStripHeight();

        // Clamp to end of stream if possible.
        long streamLength = stream.length();
        if (streamLength != -1) {
            tileOrStripByteCount
                    = Math.min(tileOrStripByteCount,
                            streamLength - getTileOrStripOffset(tileIndex));
        } else {
            processWarningOccurred("Stream length is unknown: cannot clamp estimated strip or tile byte count to EOF.");
        }
    }

    return tileOrStripByteCount;
}
 
Example #17
Source File: TIFFT6Compressor.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
public int encode(byte[] b, int off,
                  int width, int height,
                  int[] bitsPerSample,
                  int scanlineStride) throws IOException {
    if (bitsPerSample.length != 1 || bitsPerSample[0] != 1) {
        throw new IIOException(
                         "Bits per sample must be 1 for T6 compression!");
    }


    if (metadata instanceof TIFFImageMetadata) {
        TIFFImageMetadata tim = (TIFFImageMetadata)metadata;

        long[] options = new long[1];
        options[0] = 0;

        BaselineTIFFTagSet base = BaselineTIFFTagSet.getInstance();
        TIFFField T6Options =
            new TIFFField(base.getTag(BaselineTIFFTagSet.TAG_T6_OPTIONS),
                          TIFFTag.TIFF_LONG,
                          1,
                          options);
        tim.rootIFD.addTIFFField(T6Options);
    }

    // See comment in TIFFT4Compressor
    int maxBits = 9*((width + 1)/2) + 2;
    int bufSize = (maxBits + 7)/8;
    bufSize = height*(bufSize + 2) + 12;

    byte[] compData = new byte[bufSize];
    int bytes = encodeT6(b, scanlineStride, 8*off, width, height,
                         compData);
    stream.write(compData, 0, bytes);
    return bytes;
}
 
Example #18
Source File: TIFFFaxDecompressor.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public void decodeRaw(byte[] b, int dstOffset,
                      int pixelBitStride, // will always be 1
                      int scanlineStride) throws IOException {

    this.buffer = b;

    this.w = srcWidth;
    this.h = srcHeight;
    this.bitsPerScanline = scanlineStride*8;
    this.lineBitNum = 8*dstOffset;

    this.data = new byte[byteCount];
    this.bitPointer = 0;
    this.bytePointer = 0;
    this.prevChangingElems = new int[w + 1];
    this.currChangingElems = new int[w + 1];

    stream.seek(offset);
    stream.readFully(data);

    if (compression == BaselineTIFFTagSet.COMPRESSION_CCITT_RLE) {
        decodeRLE();
    } else if (compression == BaselineTIFFTagSet.COMPRESSION_CCITT_T_4) {
        decodeT4();
    } else if (compression == BaselineTIFFTagSet.COMPRESSION_CCITT_T_6) {
        this.uncompressedMode = ((t6Options & 0x02) >> 1);
        decodeT6();
    } else {
        throw new IIOException("Unknown compression type " + compression);
    }
}
 
Example #19
Source File: TIFFImageReader.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private int getTileOrStripHeight() {
    TIFFField f
            = imageMetadata.getTIFFField(BaselineTIFFTagSet.TAG_TILE_LENGTH);
    if (f != null) {
        return f.getAsInt(0);
    }

    f = imageMetadata.getTIFFField(BaselineTIFFTagSet.TAG_ROWS_PER_STRIP);
    // Default for ROWS_PER_STRIP is 2^32 - 1, i.e., infinity
    int h = (f == null) ? -1 : f.getAsInt(0);
    return (h == -1) ? getHeight() : h;
}
 
Example #20
Source File: TIFFImageReader.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
private void readMetadata() throws IIOException {
    if (stream == null) {
        throw new IllegalStateException("Input not set!");
    }

    if (imageMetadata != null) {
        return;
    }
    try {
        // Create an object to store the image metadata
        List<TIFFTagSet> tagSets;
        boolean readUnknownTags = false;
        if (imageReadParam instanceof TIFFImageReadParam) {
            TIFFImageReadParam tp = (TIFFImageReadParam)imageReadParam;
            tagSets = tp.getAllowedTagSets();
            readUnknownTags = tp.getReadUnknownTags();
        } else {
            tagSets = new ArrayList<TIFFTagSet>(1);
            tagSets.add(BaselineTIFFTagSet.getInstance());
        }

        this.imageMetadata = new TIFFImageMetadata(tagSets);
        imageMetadata.initializeFromStream(stream, ignoreMetadata,
                                           readUnknownTags);
    } catch (IIOException iioe) {
        throw iioe;
    } catch (IOException ioe) {
        throw new IIOException("I/O error reading image metadata!", ioe);
    }
}
 
Example #21
Source File: TIFFImageReader.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
private int getTileOrStripHeight() {
    TIFFField f
            = imageMetadata.getTIFFField(BaselineTIFFTagSet.TAG_TILE_LENGTH);
    if (f != null) {
        return f.getAsInt(0);
    }

    f = imageMetadata.getTIFFField(BaselineTIFFTagSet.TAG_ROWS_PER_STRIP);
    // Default for ROWS_PER_STRIP is 2^32 - 1, i.e., infinity
    int h = (f == null) ? -1 : f.getAsInt(0);
    return (h == -1) ? getHeight() : h;
}
 
Example #22
Source File: TIFFIFD.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private static void initializeEssentialTags() {
    Set<Integer> tags = essentialTags;
    if (tags == null) {
        essentialTags = tags = Set.of(
            BaselineTIFFTagSet.TAG_BITS_PER_SAMPLE,
            BaselineTIFFTagSet.TAG_COLOR_MAP,
            BaselineTIFFTagSet.TAG_COMPRESSION,
            BaselineTIFFTagSet.TAG_EXTRA_SAMPLES,
            BaselineTIFFTagSet.TAG_FILL_ORDER,
            BaselineTIFFTagSet.TAG_ICC_PROFILE,
            BaselineTIFFTagSet.TAG_IMAGE_LENGTH,
            BaselineTIFFTagSet.TAG_IMAGE_WIDTH,
            BaselineTIFFTagSet.TAG_JPEG_AC_TABLES,
            BaselineTIFFTagSet.TAG_JPEG_DC_TABLES,
            BaselineTIFFTagSet.TAG_JPEG_INTERCHANGE_FORMAT,
            BaselineTIFFTagSet.TAG_JPEG_INTERCHANGE_FORMAT_LENGTH,
            BaselineTIFFTagSet.TAG_JPEG_PROC,
            BaselineTIFFTagSet.TAG_JPEG_Q_TABLES,
            BaselineTIFFTagSet.TAG_JPEG_RESTART_INTERVAL,
            BaselineTIFFTagSet.TAG_JPEG_TABLES,
            BaselineTIFFTagSet.TAG_PHOTOMETRIC_INTERPRETATION,
            BaselineTIFFTagSet.TAG_PLANAR_CONFIGURATION,
            BaselineTIFFTagSet.TAG_PREDICTOR,
            BaselineTIFFTagSet.TAG_REFERENCE_BLACK_WHITE,
            BaselineTIFFTagSet.TAG_ROWS_PER_STRIP,
            BaselineTIFFTagSet.TAG_SAMPLES_PER_PIXEL,
            BaselineTIFFTagSet.TAG_SAMPLE_FORMAT,
            BaselineTIFFTagSet.TAG_STRIP_BYTE_COUNTS,
            BaselineTIFFTagSet.TAG_STRIP_OFFSETS,
            BaselineTIFFTagSet.TAG_T4_OPTIONS,
            BaselineTIFFTagSet.TAG_T6_OPTIONS,
            BaselineTIFFTagSet.TAG_TILE_BYTE_COUNTS,
            BaselineTIFFTagSet.TAG_TILE_LENGTH,
            BaselineTIFFTagSet.TAG_TILE_OFFSETS,
            BaselineTIFFTagSet.TAG_TILE_WIDTH,
            BaselineTIFFTagSet.TAG_Y_CB_CR_COEFFICIENTS,
            BaselineTIFFTagSet.TAG_Y_CB_CR_SUBSAMPLING
        );
    }
}
 
Example #23
Source File: TIFFImageReader.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
private long getTileOrStripByteCount(int tileIndex) throws IOException {
    TIFFField f
            = imageMetadata.getTIFFField(BaselineTIFFTagSet.TAG_TILE_BYTE_COUNTS);
    if (f == null) {
        f
                = imageMetadata.getTIFFField(BaselineTIFFTagSet.TAG_STRIP_BYTE_COUNTS);
    }
    if (f == null) {
        f = imageMetadata.getTIFFField(BaselineTIFFTagSet.TAG_JPEG_INTERCHANGE_FORMAT_LENGTH);
    }

    long tileOrStripByteCount;
    if (f != null) {
        tileOrStripByteCount = f.getAsLong(tileIndex);
    } else {
        processWarningOccurred("TIFF directory contains neither StripByteCounts nor TileByteCounts field: attempting to calculate from strip or tile width and height.");

        // Initialize to number of bytes per strip or tile assuming
        // no compression.
        int bitsPerPixel = bitsPerSample[0];
        for (int i = 1; i < samplesPerPixel; i++) {
            bitsPerPixel += bitsPerSample[i];
        }
        int bytesPerRow = (getTileOrStripWidth() * bitsPerPixel + 7) / 8;
        tileOrStripByteCount = bytesPerRow * getTileOrStripHeight();

        // Clamp to end of stream if possible.
        long streamLength = stream.length();
        if (streamLength != -1) {
            tileOrStripByteCount
                    = Math.min(tileOrStripByteCount,
                            streamLength - getTileOrStripOffset(tileIndex));
        } else {
            processWarningOccurred("Stream length is unknown: cannot clamp estimated strip or tile byte count to EOF.");
        }
    }

    return tileOrStripByteCount;
}
 
Example #24
Source File: TIFFImageReader.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
private int getCompression() {
    TIFFField f
            = imageMetadata.getTIFFField(BaselineTIFFTagSet.TAG_COMPRESSION);
    if (f == null) {
        return BaselineTIFFTagSet.COMPRESSION_NONE;
    } else {
        return f.getAsInt(0);
    }
}
 
Example #25
Source File: TIFFImageReader.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
public boolean isRandomAccessEasy(int imageIndex) throws IOException {
    if (currIndex != -1) {
        seekToImage(currIndex);
        return getCompression() == BaselineTIFFTagSet.COMPRESSION_NONE;
    } else {
        return false;
    }
}
 
Example #26
Source File: TIFFImageReader.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
public boolean isImageTiled(int imageIndex) throws IOException {
    seekToImage(imageIndex);

    TIFFField f
            = imageMetadata.getTIFFField(BaselineTIFFTagSet.TAG_TILE_WIDTH);
    return f != null;
}
 
Example #27
Source File: TIFFJPEGDecompressor.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public void beginDecoding() {
    // Initialize the JPEG reader if needed.
    if(this.JPEGReader == null) {
        // Get all JPEG readers.
        Iterator<ImageReader> iter = ImageIO.getImageReadersByFormatName("jpeg");

        if(!iter.hasNext()) {
            throw new IllegalStateException("No JPEG readers found!");
        }

        // Initialize reader to the first one.
        this.JPEGReader = iter.next();

        this.JPEGParam = JPEGReader.getDefaultReadParam();
    }

    // Get the JPEGTables field.
    TIFFImageMetadata tmetadata = (TIFFImageMetadata)metadata;
    TIFFField f =
        tmetadata.getTIFFField(BaselineTIFFTagSet.TAG_JPEG_TABLES);

    if (f != null) {
        this.hasJPEGTables = true;
        this.tables = f.getAsBytes();
    } else {
        this.hasJPEGTables = false;
    }
}
 
Example #28
Source File: TIFFImageWriter.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
public boolean canReplacePixels(int imageIndex) throws IOException {
    if (getOutput() == null) {
        throw new IllegalStateException("getOutput() == null!");
    }

    TIFFIFD rootIFD = readIFD(imageIndex);
    TIFFField f = rootIFD.getTIFFField(BaselineTIFFTagSet.TAG_COMPRESSION);
    int compression = f.getAsInt(0);

    return compression == BaselineTIFFTagSet.COMPRESSION_NONE;
}
 
Example #29
Source File: TIFFImageWriter.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public boolean canReplacePixels(int imageIndex) throws IOException {
    if (getOutput() == null) {
        throw new IllegalStateException("getOutput() == null!");
    }

    TIFFIFD rootIFD = readIFD(imageIndex);
    TIFFField f = rootIFD.getTIFFField(BaselineTIFFTagSet.TAG_COMPRESSION);
    int compression = f.getAsInt(0);

    return compression == BaselineTIFFTagSet.COMPRESSION_NONE;
}
 
Example #30
Source File: TIFFImageReader.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private int getCompression() {
    TIFFField f
            = imageMetadata.getTIFFField(BaselineTIFFTagSet.TAG_COMPRESSION);
    if (f == null) {
        return BaselineTIFFTagSet.COMPRESSION_NONE;
    } else {
        return f.getAsInt(0);
    }
}