类javax.imageio.plugins.tiff.TIFFField源码实例Demo

下面列出了怎么用javax.imageio.plugins.tiff.TIFFField的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: Bytecoder   文件: TIFFT4Compressor.java
/**
 * 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);
        }
    }
}
 
源代码2 项目: Bytecoder   文件: TIFFYCbCrColorConverter.java
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);
    }
}
 
源代码3 项目: Bytecoder   文件: TIFFImageReader.java
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);
}
 
源代码4 项目: openjdk-jdk9   文件: TIFFT4Compressor.java
/**
 * 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);
        }
    }
}
 
源代码5 项目: openjdk-jdk9   文件: TIFFYCbCrColorConverter.java
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);
    }
}
 
源代码6 项目: openjdk-jdk9   文件: TIFFImageReader.java
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);
}
 
源代码7 项目: Bytecoder   文件: TIFFImageWriter.java
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;
}
 
源代码8 项目: Bytecoder   文件: TIFFJPEGDecompressor.java
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;
    }
}
 
源代码9 项目: Bytecoder   文件: TIFFIFD.java
/**
 * Returns an {@code Iterator} over the TIFF fields. The
 * traversal is in the order of increasing tag number.
 */
// Note: the sort is guaranteed for low fields by the use of an
// array wherein the index corresponds to the tag number and for
// the high fields by the use of a TreeMap with tag number keys.
public Iterator<TIFFField> iterator() {
    return Arrays.asList(getTIFFFields()).iterator();
}
 
源代码10 项目: Bytecoder   文件: TIFFFaxDecompressor.java
/**
 * 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;
    }
}
 
源代码11 项目: Bytecoder   文件: TIFFImageMetadata.java
private void mergeNativeTree(Node root) throws IIOInvalidTreeException {
    Node node = root;
    if (!node.getNodeName().equals(nativeMetadataFormatName)) {
        fatal(node, "Root must be " + nativeMetadataFormatName);
    }

    node = node.getFirstChild();
    if (node == null || !node.getNodeName().equals("TIFFIFD")) {
        fatal(root, "Root must have \"TIFFIFD\" child");
    }
    TIFFIFD ifd = parseIFD(node);

    List<TIFFTagSet> rootIFDTagSets = rootIFD.getTagSetList();
    Iterator<TIFFTagSet> tagSetIter = ifd.getTagSetList().iterator();
    while(tagSetIter.hasNext()) {
        Object o = tagSetIter.next();
        if(o instanceof TIFFTagSet && !rootIFDTagSets.contains(o)) {
            rootIFD.addTagSet((TIFFTagSet)o);
        }
    }

    Iterator<TIFFField> ifdIter = ifd.iterator();
    while(ifdIter.hasNext()) {
        TIFFField field = ifdIter.next();
        rootIFD.addTIFFField(field);
    }
}
 
源代码12 项目: Bytecoder   文件: TIFFT6Compressor.java
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;
}
 
源代码13 项目: Bytecoder   文件: TIFFFieldNode.java
public TIFFFieldNode(TIFFField field) {
    super(getNodeName(field));

    isIFD = isIFD(field);

    this.field = field;

    TIFFTag tag = field.getTag();
    int tagNumber = tag.getNumber();
    String tagName = tag.getName();

    if(isIFD) {
        if(tagNumber != 0) {
            setAttribute("parentTagNumber", Integer.toString(tagNumber));
        }
        if(tagName != null) {
            setAttribute("parentTagName", tagName);
        }

        TIFFDirectory dir = field.hasDirectory() ?
            field.getDirectory() : (TIFFDirectory)field.getData();
        TIFFTagSet[] tagSets = dir.getTagSets();
        if(tagSets != null) {
            StringBuilder tagSetNames = new StringBuilder();
            for(int i = 0; i < tagSets.length; i++) {
                tagSetNames.append(tagSets[i].getClass().getName());
                if(i != tagSets.length - 1) {
                    tagSetNames.append(",");
                }
            }
            setAttribute("tagSets", tagSetNames.toString());
        }
    } else {
        setAttribute("number", Integer.toString(tagNumber));
        setAttribute("name", tagName);
    }
}
 
源代码14 项目: Bytecoder   文件: TIFFImageReader.java
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;
}
 
源代码15 项目: Bytecoder   文件: TIFFImageReader.java
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;
}
 
源代码16 项目: Bytecoder   文件: TIFFImageReader.java
private int getCompression() {
    TIFFField f
            = imageMetadata.getTIFFField(BaselineTIFFTagSet.TAG_COMPRESSION);
    if (f == null) {
        return BaselineTIFFTagSet.COMPRESSION_NONE;
    } else {
        return f.getAsInt(0);
    }
}
 
源代码17 项目: Bytecoder   文件: TIFFImageReader.java
public boolean isImageTiled(int imageIndex) throws IOException {
    seekToImage(imageIndex);

    TIFFField f
            = imageMetadata.getTIFFField(BaselineTIFFTagSet.TAG_TILE_WIDTH);
    return f != null;
}
 
源代码18 项目: openjdk-jdk9   文件: TIFFImageWriter.java
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;
}
 
源代码19 项目: openjdk-jdk9   文件: TIFFJPEGDecompressor.java
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;
    }
}
 
源代码20 项目: openjdk-jdk9   文件: TIFFIFD.java
/**
 * Returns an {@code Iterator} over the TIFF fields. The
 * traversal is in the order of increasing tag number.
 */
// Note: the sort is guaranteed for low fields by the use of an
// array wherein the index corresponds to the tag number and for
// the high fields by the use of a TreeMap with tag number keys.
public Iterator<TIFFField> iterator() {
    return Arrays.asList(getTIFFFields()).iterator();
}
 
源代码21 项目: openjdk-jdk9   文件: TIFFFaxDecompressor.java
/**
 * 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;
    }
}
 
源代码22 项目: openjdk-jdk9   文件: TIFFImageMetadata.java
private void mergeNativeTree(Node root) throws IIOInvalidTreeException {
    Node node = root;
    if (!node.getNodeName().equals(nativeMetadataFormatName)) {
        fatal(node, "Root must be " + nativeMetadataFormatName);
    }

    node = node.getFirstChild();
    if (node == null || !node.getNodeName().equals("TIFFIFD")) {
        fatal(root, "Root must have \"TIFFIFD\" child");
    }
    TIFFIFD ifd = parseIFD(node);

    List<TIFFTagSet> rootIFDTagSets = rootIFD.getTagSetList();
    Iterator<TIFFTagSet> tagSetIter = ifd.getTagSetList().iterator();
    while(tagSetIter.hasNext()) {
        Object o = tagSetIter.next();
        if(o instanceof TIFFTagSet && !rootIFDTagSets.contains(o)) {
            rootIFD.addTagSet((TIFFTagSet)o);
        }
    }

    Iterator<TIFFField> ifdIter = ifd.iterator();
    while(ifdIter.hasNext()) {
        TIFFField field = ifdIter.next();
        rootIFD.addTIFFField(field);
    }
}
 
源代码23 项目: openjdk-jdk9   文件: TIFFT6Compressor.java
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;
}
 
源代码24 项目: openjdk-jdk9   文件: TIFFFieldNode.java
public TIFFFieldNode(TIFFField field) {
    super(getNodeName(field));

    isIFD = isIFD(field);

    this.field = field;

    TIFFTag tag = field.getTag();
    int tagNumber = tag.getNumber();
    String tagName = tag.getName();

    if(isIFD) {
        if(tagNumber != 0) {
            setAttribute("parentTagNumber", Integer.toString(tagNumber));
        }
        if(tagName != null) {
            setAttribute("parentTagName", tagName);
        }

        TIFFDirectory dir = field.hasDirectory() ?
            field.getDirectory() : (TIFFDirectory)field.getData();
        TIFFTagSet[] tagSets = dir.getTagSets();
        if(tagSets != null) {
            StringBuilder tagSetNames = new StringBuilder();
            for(int i = 0; i < tagSets.length; i++) {
                tagSetNames.append(tagSets[i].getClass().getName());
                if(i != tagSets.length - 1) {
                    tagSetNames.append(",");
                }
            }
            setAttribute("tagSets", tagSetNames.toString());
        }
    } else {
        setAttribute("number", Integer.toString(tagNumber));
        setAttribute("name", tagName);
    }
}
 
源代码25 项目: openjdk-jdk9   文件: TIFFImageReader.java
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;
}
 
源代码26 项目: openjdk-jdk9   文件: TIFFImageReader.java
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;
}
 
源代码27 项目: openjdk-jdk9   文件: TIFFImageReader.java
private int getCompression() {
    TIFFField f
            = imageMetadata.getTIFFField(BaselineTIFFTagSet.TAG_COMPRESSION);
    if (f == null) {
        return BaselineTIFFTagSet.COMPRESSION_NONE;
    } else {
        return f.getAsInt(0);
    }
}
 
源代码28 项目: openjdk-jdk9   文件: TIFFImageReader.java
public boolean isImageTiled(int imageIndex) throws IOException {
    seekToImage(imageIndex);

    TIFFField f
            = imageMetadata.getTIFFField(BaselineTIFFTagSet.TAG_TILE_WIDTH);
    return f != null;
}
 
源代码29 项目: MyBox   文件: ImageTiffFile.java
public static IIOMetadata getWriterMeta(ImageAttributes attributes, BufferedImage image,
        ImageWriter writer, ImageWriteParam param) {
    try {
        IIOMetadata metaData;
        if (attributes != null && attributes.getColorType() != null) {
            ImageTypeSpecifier imageTypeSpecifier;
            switch (attributes.getColorType()) {
                case ARGB:
                    imageTypeSpecifier = ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_ARGB);
                    break;
                case RGB:
                    imageTypeSpecifier = ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB);
                    break;
                case BINARY:
                    imageTypeSpecifier = ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_BYTE_BINARY);
                    break;
                case GRAY:
                    imageTypeSpecifier = ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_BYTE_GRAY);
                    break;
                default:
                    imageTypeSpecifier = ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB);
                    break;
            }
            metaData = writer.getDefaultImageMetadata(imageTypeSpecifier, param);
        } else if (image != null) {
            metaData = writer.getDefaultImageMetadata(new ImageTypeSpecifier(image), param);
        } else {
            metaData = writer.getDefaultImageMetadata(
                    ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_ARGB), param);
        }

        if (metaData == null || metaData.isReadOnly() || attributes == null) {
            return metaData;
        }
        if (attributes.getDensity() > 0) {
            String nativeName = metaData.getNativeMetadataFormatName();  // javax_imageio_tiff_image_1.0
            Node nativeTree = metaData.getAsTree(nativeName);
            long[] xRes = new long[]{attributes.getDensity(), 1};
            long[] yRes = new long[]{attributes.getDensity(), 1};
            TIFFField fieldXRes = new TIFFField(
                    BaselineTIFFTagSet.getInstance().getTag(BaselineTIFFTagSet.TAG_X_RESOLUTION),
                    TIFFTag.TIFF_RATIONAL, 1, new long[][]{xRes});
            TIFFField fieldYRes = new TIFFField(
                    BaselineTIFFTagSet.getInstance().getTag(BaselineTIFFTagSet.TAG_Y_RESOLUTION),
                    TIFFTag.TIFF_RATIONAL, 1, new long[][]{yRes});
            nativeTree.getFirstChild().appendChild(fieldXRes.getAsNativeNode());
            nativeTree.getFirstChild().appendChild(fieldYRes.getAsNativeNode());
            char[] fieldUnit = new char[]{BaselineTIFFTagSet.RESOLUTION_UNIT_INCH};
            TIFFField fieldResUnit = new TIFFField(
                    BaselineTIFFTagSet.getInstance().getTag(BaselineTIFFTagSet.TAG_RESOLUTION_UNIT),
                    TIFFTag.TIFF_SHORT, 1, fieldUnit);
            nativeTree.getFirstChild().appendChild(fieldResUnit.getAsNativeNode());
            metaData.mergeTree(nativeName, nativeTree);
        }

        return metaData;

    } catch (Exception e) {
        logger.error(e.toString());
        return null;
    }
}
 
源代码30 项目: Bytecoder   文件: TIFFImageWriter.java
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;
    }
}
 
 类所在包
 同包方法