javax.imageio.plugins.tiff.TIFFTag#getSizeOfType ( )源码实例Demo

下面列出了javax.imageio.plugins.tiff.TIFFTag#getSizeOfType ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: Bytecoder   文件: TIFFIFD.java
public void writeToStream(ImageOutputStream stream)
    throws IOException {

    int numFields = getNumTIFFFields();
    stream.writeShort(numFields);

    long nextSpace = stream.getStreamPosition() + 12*numFields + 4;

    Iterator<TIFFField> iter = iterator();
    while (iter.hasNext()) {
        TIFFField f = iter.next();

        TIFFTag tag = f.getTag();

        int type = f.getType();
        int count = f.getCount();

        // Deal with unknown tags
        if (type == 0) {
            type = TIFFTag.TIFF_UNDEFINED;
        }
        int size = count*TIFFTag.getSizeOfType(type);

        if (type == TIFFTag.TIFF_ASCII) {
            int chars = 0;
            for (int i = 0; i < count; i++) {
                chars += f.getAsString(i).length() + 1;
            }
            count = chars;
            size = count;
        }

        int tagNumber = f.getTagNumber();
        stream.writeShort(tagNumber);
        stream.writeShort(type);
        stream.writeInt(count);

        // Write a dummy value to fill space
        stream.writeInt(0);
        stream.mark(); // Mark beginning of next field
        stream.skipBytes(-4);

        long pos;

        if (size > 4 || tag.isIFDPointer()) {
            // Ensure IFD or value is written on a word boundary
            nextSpace = (nextSpace + 3) & ~0x3;

            stream.writeInt((int)nextSpace);
            stream.seek(nextSpace);
            pos = nextSpace;

            if (tag.isIFDPointer() && f.hasDirectory()) {
                TIFFIFD subIFD = getDirectoryAsIFD(f.getDirectory());
                subIFD.writeToStream(stream);
                nextSpace = subIFD.lastPosition;
            } else {
                writeTIFFFieldToStream(f, stream);
                nextSpace = stream.getStreamPosition();
            }
        } else {
            pos = stream.getStreamPosition();
            writeTIFFFieldToStream(f, stream);
        }

        // If we are writing the data for the
        // StripByteCounts, TileByteCounts, StripOffsets,
        // TileOffsets, JPEGInterchangeFormat, or
        // JPEGInterchangeFormatLength fields, record the current stream
        // position for backpatching
        if (tagNumber ==
            BaselineTIFFTagSet.TAG_STRIP_BYTE_COUNTS ||
            tagNumber == BaselineTIFFTagSet.TAG_TILE_BYTE_COUNTS ||
            tagNumber == BaselineTIFFTagSet.TAG_JPEG_INTERCHANGE_FORMAT_LENGTH) {
            this.stripOrTileByteCountsPosition = pos;
        } else if (tagNumber ==
                   BaselineTIFFTagSet.TAG_STRIP_OFFSETS ||
                   tagNumber ==
                   BaselineTIFFTagSet.TAG_TILE_OFFSETS ||
                   tagNumber ==
                   BaselineTIFFTagSet.TAG_JPEG_INTERCHANGE_FORMAT) {
            this.stripOrTileOffsetsPosition = pos;
        }

        stream.reset(); // Go to marked position of next field
    }

    this.lastPosition = nextSpace;
}
 
源代码2 项目: openjdk-jdk9   文件: TIFFIFD.java
public void writeToStream(ImageOutputStream stream)
    throws IOException {

    int numFields = getNumTIFFFields();
    stream.writeShort(numFields);

    long nextSpace = stream.getStreamPosition() + 12*numFields + 4;

    Iterator<TIFFField> iter = iterator();
    while (iter.hasNext()) {
        TIFFField f = iter.next();

        TIFFTag tag = f.getTag();

        int type = f.getType();
        int count = f.getCount();

        // Deal with unknown tags
        if (type == 0) {
            type = TIFFTag.TIFF_UNDEFINED;
        }
        int size = count*TIFFTag.getSizeOfType(type);

        if (type == TIFFTag.TIFF_ASCII) {
            int chars = 0;
            for (int i = 0; i < count; i++) {
                chars += f.getAsString(i).length() + 1;
            }
            count = chars;
            size = count;
        }

        int tagNumber = f.getTagNumber();
        stream.writeShort(tagNumber);
        stream.writeShort(type);
        stream.writeInt(count);

        // Write a dummy value to fill space
        stream.writeInt(0);
        stream.mark(); // Mark beginning of next field
        stream.skipBytes(-4);

        long pos;

        if (size > 4 || tag.isIFDPointer()) {
            // Ensure IFD or value is written on a word boundary
            nextSpace = (nextSpace + 3) & ~0x3;

            stream.writeInt((int)nextSpace);
            stream.seek(nextSpace);
            pos = nextSpace;

            if (tag.isIFDPointer() && f.hasDirectory()) {
                TIFFIFD subIFD = getDirectoryAsIFD(f.getDirectory());
                subIFD.writeToStream(stream);
                nextSpace = subIFD.lastPosition;
            } else {
                writeTIFFFieldToStream(f, stream);
                nextSpace = stream.getStreamPosition();
            }
        } else {
            pos = stream.getStreamPosition();
            writeTIFFFieldToStream(f, stream);
        }

        // If we are writing the data for the
        // StripByteCounts, TileByteCounts, StripOffsets,
        // TileOffsets, JPEGInterchangeFormat, or
        // JPEGInterchangeFormatLength fields, record the current stream
        // position for backpatching
        if (tagNumber ==
            BaselineTIFFTagSet.TAG_STRIP_BYTE_COUNTS ||
            tagNumber == BaselineTIFFTagSet.TAG_TILE_BYTE_COUNTS ||
            tagNumber == BaselineTIFFTagSet.TAG_JPEG_INTERCHANGE_FORMAT_LENGTH) {
            this.stripOrTileByteCountsPosition = pos;
        } else if (tagNumber ==
                   BaselineTIFFTagSet.TAG_STRIP_OFFSETS ||
                   tagNumber ==
                   BaselineTIFFTagSet.TAG_TILE_OFFSETS ||
                   tagNumber ==
                   BaselineTIFFTagSet.TAG_JPEG_INTERCHANGE_FORMAT) {
            this.stripOrTileOffsetsPosition = pos;
        }

        stream.reset(); // Go to marked position of next field
    }

    this.lastPosition = nextSpace;
}