Java Code Examples for javax.imageio.plugins.tiff.TIFFField#getAsInt()

The following examples show how to use javax.imageio.plugins.tiff.TIFFField#getAsInt() . 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: 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 2
Source File: TIFFT4Compressor.java    From openjdk-jdk9 with GNU General Public License v2.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 3
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 4
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);
    }
}
 
Example 5
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 6
Source File: TIFFFaxDecompressor.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Invokes the superclass method and then sets instance variables on
 * the basis of the metadata set on this decompressor.
 */
public void beginDecoding() {
    super.beginDecoding();

    if(metadata instanceof TIFFImageMetadata) {
        TIFFImageMetadata tmetadata = (TIFFImageMetadata)metadata;
        TIFFField f;

        f = tmetadata.getTIFFField(BaselineTIFFTagSet.TAG_FILL_ORDER);
        this.fillOrder = f == null ?
           BaselineTIFFTagSet.FILL_ORDER_LEFT_TO_RIGHT : f.getAsInt(0);

        f = tmetadata.getTIFFField(BaselineTIFFTagSet.TAG_COMPRESSION);
        this.compression = f == null ?
            BaselineTIFFTagSet.COMPRESSION_CCITT_RLE : f.getAsInt(0);

        f = tmetadata.getTIFFField(BaselineTIFFTagSet.TAG_T4_OPTIONS);
        this.t4Options = f == null ? 0 : f.getAsInt(0);
        this.oneD = (t4Options & 0x01);
        // uncompressedMode - haven't dealt with this yet.
        this.uncompressedMode = ((t4Options & 0x02) >> 1);
        this.fillBits = ((t4Options & 0x04) >> 2);
        f = tmetadata.getTIFFField(BaselineTIFFTagSet.TAG_T6_OPTIONS);
        this.t6Options = f == null ? 0 : f.getAsInt(0);
    } else {
        this.fillOrder = BaselineTIFFTagSet.FILL_ORDER_LEFT_TO_RIGHT;

        this.compression = BaselineTIFFTagSet.COMPRESSION_CCITT_RLE; // RLE

        this.t4Options = 0; // Irrelevant as applies to T.4 only
        this.oneD = 0; // One-dimensional
        this.uncompressedMode = 0; // Not uncompressed mode
        this.fillBits = 0; // No fill bits
        this.t6Options = 0;
    }
}
 
Example 7
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 8
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 9
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 10
Source File: TIFFFaxDecompressor.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * Invokes the superclass method and then sets instance variables on
 * the basis of the metadata set on this decompressor.
 */
public void beginDecoding() {
    super.beginDecoding();

    if(metadata instanceof TIFFImageMetadata) {
        TIFFImageMetadata tmetadata = (TIFFImageMetadata)metadata;
        TIFFField f;

        f = tmetadata.getTIFFField(BaselineTIFFTagSet.TAG_FILL_ORDER);
        this.fillOrder = f == null ?
           BaselineTIFFTagSet.FILL_ORDER_LEFT_TO_RIGHT : f.getAsInt(0);

        f = tmetadata.getTIFFField(BaselineTIFFTagSet.TAG_COMPRESSION);
        this.compression = f == null ?
            BaselineTIFFTagSet.COMPRESSION_CCITT_RLE : f.getAsInt(0);

        f = tmetadata.getTIFFField(BaselineTIFFTagSet.TAG_T4_OPTIONS);
        this.t4Options = f == null ? 0 : f.getAsInt(0);
        this.oneD = (t4Options & 0x01);
        // uncompressedMode - haven't dealt with this yet.
        this.uncompressedMode = ((t4Options & 0x02) >> 1);
        this.fillBits = ((t4Options & 0x04) >> 2);
        f = tmetadata.getTIFFField(BaselineTIFFTagSet.TAG_T6_OPTIONS);
        this.t6Options = f == null ? 0 : f.getAsInt(0);
    } else {
        this.fillOrder = BaselineTIFFTagSet.FILL_ORDER_LEFT_TO_RIGHT;

        this.compression = BaselineTIFFTagSet.COMPRESSION_CCITT_RLE; // RLE

        this.t4Options = 0; // Irrelevant as applies to T.4 only
        this.oneD = 0; // One-dimensional
        this.uncompressedMode = 0; // Not uncompressed mode
        this.fillBits = 0; // No fill bits
        this.t6Options = 0;
    }
}
 
Example 11
Source File: TIFFImageReader.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
private int getTileOrStripWidth() {
    TIFFField f
            = imageMetadata.getTIFFField(BaselineTIFFTagSet.TAG_TILE_WIDTH);
    return (f == null) ? getWidth() : f.getAsInt(0);
}
 
Example 12
Source File: TIFFYCbCrDecompressor.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
public void beginDecoding() {
    if(decompressor != null) {
        decompressor.beginDecoding();
    }

    TIFFImageMetadata tmetadata = (TIFFImageMetadata)metadata;
    TIFFField f;

    f = tmetadata.getTIFFField(BaselineTIFFTagSet.TAG_Y_CB_CR_SUBSAMPLING);
    if (f != null) {
        if (f.getCount() == 2) {
            this.chromaSubsampleH = f.getAsInt(0);
            this.chromaSubsampleV = f.getAsInt(1);

            if (chromaSubsampleH != 1 && chromaSubsampleH != 2 &&
                chromaSubsampleH != 4) {
                warning("Y_CB_CR_SUBSAMPLING[0] has illegal value " +
                        chromaSubsampleH +
                        " (should be 1, 2, or 4), setting to 1");
                chromaSubsampleH = 1;
            }

            if (chromaSubsampleV != 1 && chromaSubsampleV != 2 &&
                chromaSubsampleV != 4) {
                warning("Y_CB_CR_SUBSAMPLING[1] has illegal value " +
                        chromaSubsampleV +
                        " (should be 1, 2, or 4), setting to 1");
                chromaSubsampleV = 1;
            }
        } else {
            warning("Y_CB_CR_SUBSAMPLING count != 2, " +
                    "assuming no subsampling");
        }
    }

    f =
       tmetadata.getTIFFField(BaselineTIFFTagSet.TAG_Y_CB_CR_COEFFICIENTS);
    if (f != null) {
        if (f.getCount() == 3) {
            this.lumaRed = f.getAsFloat(0);
            this.lumaGreen = f.getAsFloat(1);
            this.lumaBlue = f.getAsFloat(2);
        } else {
            warning("Y_CB_CR_COEFFICIENTS count != 3, " +
                    "assuming default values for CCIR 601-1");
        }
    }

    f =
      tmetadata.getTIFFField(BaselineTIFFTagSet.TAG_REFERENCE_BLACK_WHITE);
    if (f != null) {
        if (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);
        } else {
            warning("REFERENCE_BLACK_WHITE count != 6, ignoring it");
        }
    } else {
            warning("REFERENCE_BLACK_WHITE not found, assuming 0-255/128-255/128-255");
    }

    this.colorConvert = true;

    float BCb = (2.0f - 2.0f*lumaBlue);
    float RCr = (2.0f - 2.0f*lumaRed);

    float GY = (1.0f - lumaBlue - lumaRed)/lumaGreen;
    float GCb = 2.0f*lumaBlue*(lumaBlue - 1.0f)/lumaGreen;
    float GCr = 2.0f*lumaRed*(lumaRed - 1.0f)/lumaGreen;

    for (int i = 0; i < 256; i++) {
        float fY = (i - referenceBlackY)*codingRangeY/
            (referenceWhiteY - referenceBlackY);
        float fCb = (i - referenceBlackCb)*127.0f/
            (referenceWhiteCb - referenceBlackCb);
        float fCr = (i - referenceBlackCr)*127.0f/
            (referenceWhiteCr - referenceBlackCr);

        iYTab[i] = (int)(fY*FRAC_SCALE);
        iCbTab[i] = (int)(fCb*BCb*FRAC_SCALE);
        iCrTab[i] = (int)(fCr*RCr*FRAC_SCALE);

        iGYTab[i] = (int)(fY*GY*FRAC_SCALE);
        iGCbTab[i] = (int)(fCb*GCb*FRAC_SCALE);
        iGCrTab[i] = (int)(fCr*GCr*FRAC_SCALE);
    }
}
 
Example 13
Source File: TIFFImageWriter.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public void prepareReplacePixels(int imageIndex,
                                 Rectangle region) throws IOException {
    synchronized(replacePixelsLock) {
        // Check state and parameters vis-a-vis ImageWriter specification.
        if (stream == null) {
            throw new IllegalStateException("Output not set!");
        }
        if (region == null) {
            throw new IllegalArgumentException("region == null!");
        }
        if (region.getWidth() < 1) {
            throw new IllegalArgumentException("region.getWidth() < 1!");
        }
        if (region.getHeight() < 1) {
            throw new IllegalArgumentException("region.getHeight() < 1!");
        }
        if (inReplacePixelsNest) {
            throw new IllegalStateException
                ("In nested call to prepareReplacePixels!");
        }

        // Read the IFD for the pixel replacement index.
        TIFFIFD replacePixelsIFD = readIFD(imageIndex);

        // Ensure that compression is "none".
        TIFFField f =
            replacePixelsIFD.getTIFFField(BaselineTIFFTagSet.TAG_COMPRESSION);
        int compression = f.getAsInt(0);
        if (compression != BaselineTIFFTagSet.COMPRESSION_NONE) {
            throw new UnsupportedOperationException
                ("canReplacePixels(imageIndex) == false!");
        }

        // Get the image dimensions.
        f =
            replacePixelsIFD.getTIFFField(BaselineTIFFTagSet.TAG_IMAGE_WIDTH);
        if(f == null) {
            throw new IIOException("Cannot read ImageWidth field.");
        }
        int w = f.getAsInt(0);

        f =
            replacePixelsIFD.getTIFFField(BaselineTIFFTagSet.TAG_IMAGE_LENGTH);
        if(f == null) {
            throw new IIOException("Cannot read ImageHeight field.");
        }
        int h = f.getAsInt(0);

        // Create image bounds.
        Rectangle bounds = new Rectangle(0, 0, w, h);

        // Intersect region with bounds.
        region = region.intersection(bounds);

        // Check for empty intersection.
        if(region.isEmpty()) {
            throw new IIOException("Region does not intersect image bounds");
        }

        // Save the region.
        replacePixelsRegion = region;

        // Get the tile offsets.
        f = replacePixelsIFD.getTIFFField(BaselineTIFFTagSet.TAG_TILE_OFFSETS);
        if(f == null) {
            f = replacePixelsIFD.getTIFFField(BaselineTIFFTagSet.TAG_STRIP_OFFSETS);
        }
        replacePixelsTileOffsets = f.getAsLongs();

        // Get the byte counts.
        f = replacePixelsIFD.getTIFFField(BaselineTIFFTagSet.TAG_TILE_BYTE_COUNTS);
        if(f == null) {
            f = replacePixelsIFD.getTIFFField(BaselineTIFFTagSet.TAG_STRIP_BYTE_COUNTS);
        }
        replacePixelsByteCounts = f.getAsLongs();

        replacePixelsOffsetsPosition =
            replacePixelsIFD.getStripOrTileOffsetsPosition();
        replacePixelsByteCountsPosition =
            replacePixelsIFD.getStripOrTileByteCountsPosition();

        // Get the image metadata.
        replacePixelsMetadata = new TIFFImageMetadata(replacePixelsIFD);

        // Save the image index.
        replacePixelsIndex = imageIndex;

        // Set the pixel replacement flag.
        inReplacePixelsNest = true;
    }
}
 
Example 14
Source File: TIFFIFD.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
private int getFieldAsInt(int tagNumber) {
    TIFFField f = getTIFFField(tagNumber);
    return f == null ? -1 : f.getAsInt(0);
}
 
Example 15
Source File: TIFFIFD.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
private int getFieldAsInt(int tagNumber) {
    TIFFField f = getTIFFField(tagNumber);
    return f == null ? -1 : f.getAsInt(0);
}
 
Example 16
Source File: TIFFYCbCrDecompressor.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public void beginDecoding() {
    if(decompressor != null) {
        decompressor.beginDecoding();
    }

    TIFFImageMetadata tmetadata = (TIFFImageMetadata)metadata;
    TIFFField f;

    f = tmetadata.getTIFFField(BaselineTIFFTagSet.TAG_Y_CB_CR_SUBSAMPLING);
    if (f != null) {
        if (f.getCount() == 2) {
            this.chromaSubsampleH = f.getAsInt(0);
            this.chromaSubsampleV = f.getAsInt(1);

            if (chromaSubsampleH != 1 && chromaSubsampleH != 2 &&
                chromaSubsampleH != 4) {
                warning("Y_CB_CR_SUBSAMPLING[0] has illegal value " +
                        chromaSubsampleH +
                        " (should be 1, 2, or 4), setting to 1");
                chromaSubsampleH = 1;
            }

            if (chromaSubsampleV != 1 && chromaSubsampleV != 2 &&
                chromaSubsampleV != 4) {
                warning("Y_CB_CR_SUBSAMPLING[1] has illegal value " +
                        chromaSubsampleV +
                        " (should be 1, 2, or 4), setting to 1");
                chromaSubsampleV = 1;
            }
        } else {
            warning("Y_CB_CR_SUBSAMPLING count != 2, " +
                    "assuming no subsampling");
        }
    }

    f =
       tmetadata.getTIFFField(BaselineTIFFTagSet.TAG_Y_CB_CR_COEFFICIENTS);
    if (f != null) {
        if (f.getCount() == 3) {
            this.lumaRed = f.getAsFloat(0);
            this.lumaGreen = f.getAsFloat(1);
            this.lumaBlue = f.getAsFloat(2);
        } else {
            warning("Y_CB_CR_COEFFICIENTS count != 3, " +
                    "assuming default values for CCIR 601-1");
        }
    }

    f =
      tmetadata.getTIFFField(BaselineTIFFTagSet.TAG_REFERENCE_BLACK_WHITE);
    if (f != null) {
        if (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);
        } else {
            warning("REFERENCE_BLACK_WHITE count != 6, ignoring it");
        }
    } else {
            warning("REFERENCE_BLACK_WHITE not found, assuming 0-255/128-255/128-255");
    }

    this.colorConvert = true;

    float BCb = (2.0f - 2.0f*lumaBlue);
    float RCr = (2.0f - 2.0f*lumaRed);

    float GY = (1.0f - lumaBlue - lumaRed)/lumaGreen;
    float GCb = 2.0f*lumaBlue*(lumaBlue - 1.0f)/lumaGreen;
    float GCr = 2.0f*lumaRed*(lumaRed - 1.0f)/lumaGreen;

    for (int i = 0; i < 256; i++) {
        float fY = (i - referenceBlackY)*codingRangeY/
            (referenceWhiteY - referenceBlackY);
        float fCb = (i - referenceBlackCb)*127.0f/
            (referenceWhiteCb - referenceBlackCb);
        float fCr = (i - referenceBlackCr)*127.0f/
            (referenceWhiteCr - referenceBlackCr);

        iYTab[i] = (int)(fY*FRAC_SCALE);
        iCbTab[i] = (int)(fCb*BCb*FRAC_SCALE);
        iCrTab[i] = (int)(fCr*RCr*FRAC_SCALE);

        iGYTab[i] = (int)(fY*GY*FRAC_SCALE);
        iGCbTab[i] = (int)(fCb*GCb*FRAC_SCALE);
        iGCrTab[i] = (int)(fCr*GCr*FRAC_SCALE);
    }
}
 
Example 17
Source File: TIFFImageReader.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
private int getTileOrStripWidth() {
    TIFFField f
            = imageMetadata.getTIFFField(BaselineTIFFTagSet.TAG_TILE_WIDTH);
    return (f == null) ? getWidth() : f.getAsInt(0);
}
 
Example 18
Source File: TIFFImageWriter.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
public void prepareReplacePixels(int imageIndex,
                                 Rectangle region) throws IOException {
    synchronized(replacePixelsLock) {
        // Check state and parameters vis-a-vis ImageWriter specification.
        if (stream == null) {
            throw new IllegalStateException("Output not set!");
        }
        if (region == null) {
            throw new IllegalArgumentException("region == null!");
        }
        if (region.getWidth() < 1) {
            throw new IllegalArgumentException("region.getWidth() < 1!");
        }
        if (region.getHeight() < 1) {
            throw new IllegalArgumentException("region.getHeight() < 1!");
        }
        if (inReplacePixelsNest) {
            throw new IllegalStateException
                ("In nested call to prepareReplacePixels!");
        }

        // Read the IFD for the pixel replacement index.
        TIFFIFD replacePixelsIFD = readIFD(imageIndex);

        // Ensure that compression is "none".
        TIFFField f =
            replacePixelsIFD.getTIFFField(BaselineTIFFTagSet.TAG_COMPRESSION);
        int compression = f.getAsInt(0);
        if (compression != BaselineTIFFTagSet.COMPRESSION_NONE) {
            throw new UnsupportedOperationException
                ("canReplacePixels(imageIndex) == false!");
        }

        // Get the image dimensions.
        f =
            replacePixelsIFD.getTIFFField(BaselineTIFFTagSet.TAG_IMAGE_WIDTH);
        if(f == null) {
            throw new IIOException("Cannot read ImageWidth field.");
        }
        int w = f.getAsInt(0);

        f =
            replacePixelsIFD.getTIFFField(BaselineTIFFTagSet.TAG_IMAGE_LENGTH);
        if(f == null) {
            throw new IIOException("Cannot read ImageHeight field.");
        }
        int h = f.getAsInt(0);

        // Create image bounds.
        Rectangle bounds = new Rectangle(0, 0, w, h);

        // Intersect region with bounds.
        region = region.intersection(bounds);

        // Check for empty intersection.
        if(region.isEmpty()) {
            throw new IIOException("Region does not intersect image bounds");
        }

        // Save the region.
        replacePixelsRegion = region;

        // Get the tile offsets.
        f = replacePixelsIFD.getTIFFField(BaselineTIFFTagSet.TAG_TILE_OFFSETS);
        if(f == null) {
            f = replacePixelsIFD.getTIFFField(BaselineTIFFTagSet.TAG_STRIP_OFFSETS);
        }
        replacePixelsTileOffsets = f.getAsLongs();

        // Get the byte counts.
        f = replacePixelsIFD.getTIFFField(BaselineTIFFTagSet.TAG_TILE_BYTE_COUNTS);
        if(f == null) {
            f = replacePixelsIFD.getTIFFField(BaselineTIFFTagSet.TAG_STRIP_BYTE_COUNTS);
        }
        replacePixelsByteCounts = f.getAsLongs();

        replacePixelsOffsetsPosition =
            replacePixelsIFD.getStripOrTileOffsetsPosition();
        replacePixelsByteCountsPosition =
            replacePixelsIFD.getStripOrTileByteCountsPosition();

        // Get the image metadata.
        replacePixelsMetadata = new TIFFImageMetadata(replacePixelsIFD);

        // Save the image index.
        replacePixelsIndex = imageIndex;

        // Set the pixel replacement flag.
        inReplacePixelsNest = true;
    }
}
 
Example 19
Source File: TIFFFaxCompressor.java    From openjdk-jdk9 with GNU General Public License v2.0 3 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 FILL_ORDER field if it exists.</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_FILL_ORDER);
        inverseFill = (f != null && f.getAsInt(0) == 2);
    }
}
 
Example 20
Source File: TIFFFaxCompressor.java    From Bytecoder with Apache License 2.0 3 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 FILL_ORDER field if it exists.</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_FILL_ORDER);
        inverseFill = (f != null && f.getAsInt(0) == 2);
    }
}