Java 类javax.imageio.IIOException 实例源码

项目:incubator-netbeans    文件:AfterDeleteAfterMoveEndsTest.java   
@Override
public void doMove(VCSFileProxy from, VCSFileProxy to) throws IOException {
    if(!startAcceptingEvents) {
        return;
    }
    System.out.println(" intercepted doMove from " + from + " to " + to );
    events.add(DO_MOVE + " from " + from + " " + to);

    // invoke rename
    from.toFile().renameTo(to.toFile());

    // now wait if afterDelete doesn't happen before we leave doMove();
    long t = System.currentTimeMillis();
    while(afterDelete == null) {
        try {
            Thread.sleep(200);
        } catch (InterruptedException ex) {
            throw new IIOException("doMove from " + from + " to " + to , ex);
        }
        if(System.currentTimeMillis() - t > TIMEOUT) {
            events.add(TIMEDOUT + " from " + from + " " + to);
            return;
        }
    }
}
项目:openjdk-jdk10    文件:GIFImageWriter.java   
private void writeCommentExtension(GIFWritableImageMetadata im)
  throws IOException {
    if (im.comments != null) {
        try {
            Iterator<byte[]> iter = im.comments.iterator();
            while (iter.hasNext()) {
                stream.write(0x21);
                stream.write(0xfe);
                writeBlocks(iter.next());
                stream.write(0x00);
            }
        } catch (IOException e) {
            throw new IIOException("I/O error writing Comment Extension!", e);
        }
    }
}
项目:OpenJSharp    文件:JPEGBuffer.java   
/**
 * Fills the data array from the stream, starting with
 * the buffer and then reading directly from the stream
 * if necessary.  The buffer is left in an appropriate
 * state.  If the end of the stream is encountered, an
 * <code>IIOException</code> is thrown with the
 * message "Image Format Error".
 */
void readData(byte [] data) throws IOException {
    int count = data.length;
    // First see what's left in the buffer.
    if (bufAvail >= count) {  // It's enough
        System.arraycopy(buf, bufPtr, data, 0, count);
        bufAvail -= count;
        bufPtr += count;
        return;
    }
    int offset = 0;
    if (bufAvail > 0) {  // Some there, but not enough
        System.arraycopy(buf, bufPtr, data, 0, bufAvail);
        offset = bufAvail;
        count -= bufAvail;
        bufAvail = 0;
        bufPtr = 0;
    }
    // Now read the rest directly from the stream
    if (iis.read(data, offset, count) != count) {
        throw new IIOException ("Image format Error");
    }
}
项目:OpenJSharp    文件:JPEGBuffer.java   
/**
 * Skips <code>count</code> bytes, leaving the buffer
 * in an appropriate state.  If the end of the stream is
 * encountered, an <code>IIOException</code> is thrown with the
 * message "Image Format Error".
 */
void skipData(int count) throws IOException {
    // First see what's left in the buffer.
    if (bufAvail >= count) {  // It's enough
        bufAvail -= count;
        bufPtr += count;
        return;
    }
    if (bufAvail > 0) {  // Some there, but not enough
        count -= bufAvail;
        bufAvail = 0;
        bufPtr = 0;
    }
    // Now read the rest directly from the stream
    if (iis.skipBytes(count) != count) {
        throw new IIOException ("Image format Error");
    }
}
项目:OpenJSharp    文件:MarkerSegment.java   
/**
 * Constructor for creating <code>MarkerSegment</code>s by reading
 * from an <code>ImageInputStream</code>.
 */
MarkerSegment(JPEGBuffer buffer) throws IOException {

    buffer.loadBuf(3);  // tag plus length
    tag = buffer.buf[buffer.bufPtr++] & 0xff;
    length = (buffer.buf[buffer.bufPtr++] & 0xff) << 8;
    length |= buffer.buf[buffer.bufPtr++] & 0xff;
    length -= 2;  // JPEG length includes itself, we don't

    if (length < 0) {
        throw new IIOException("Invalid segment length: " + length);
    }
    buffer.bufAvail -= 3;
    // Now that we know the true length, ensure that we've got it,
    // or at least a bufferful if length is too big.
    buffer.loadBuf(length);
}
项目:jdk8u-jdk    文件:ImageInputStreamImpl.java   
/**
 * Resets the current stream byte and bit positions from the stack
 * of marked positions.
 *
 * <p> An <code>IOException</code> will be thrown if the previous
 * marked position lies in the discarded portion of the stream.
 *
 * @exception IOException if an I/O error occurs.
 */
public void reset() throws IOException {
    if (markByteStack.empty()) {
        return;
    }

    long pos = ((Long)markByteStack.pop()).longValue();
    if (pos < flushedPos) {
        throw new IIOException
            ("Previous marked position has been discarded!");
    }
    seek(pos);

    int offset = ((Integer)markBitStack.pop()).intValue();
    setBitOffset(offset);
}
项目:openjdk-jdk10    文件:SIMPImageReader.java   
private void checkState(int imageIndex) throws IOException {
    if (stream == null) {
        throw new IllegalStateException("input not set.");
    }
    if (imageIndex != 0) {
        throw new IndexOutOfBoundsException("index != 0");
    }
    if (width==-1) {
        byte[] sig = new byte[4];
        stream.reset();
        stream.read(sig);
        boolean ok = sig[0]=='S' && sig[1]=='I' &&
                     sig[2]=='M' && sig[3]=='P';
        if (!ok) {
            throw new IIOException("Not a SIMP image");
        }
        width = stream.readByte();
        height = stream.readByte();
    }
    if (width <= 0 || height <= 0) {
        throw new IOException("bad image size");
    }
    metadata = new SIMPMetadata(width, height);
}
项目:openjdk-jdk10    文件:MarkerSegment.java   
/**
 * Constructor for creating {@code MarkerSegment}s by reading
 * from an {@code ImageInputStream}.
 */
MarkerSegment(JPEGBuffer buffer) throws IOException {

    buffer.loadBuf(3);  // tag plus length
    tag = buffer.buf[buffer.bufPtr++] & 0xff;
    length = (buffer.buf[buffer.bufPtr++] & 0xff) << 8;
    length |= buffer.buf[buffer.bufPtr++] & 0xff;
    length -= 2;  // JPEG length includes itself, we don't

    if (length < 0) {
        throw new IIOException("Invalid segment length: " + length);
    }
    buffer.bufAvail -= 3;
    // Now that we know the true length, ensure that we've got it,
    // or at least a bufferful if length is too big.
    buffer.loadBuf(length);
}
项目:OpenJSharp    文件:PNGImageReader.java   
private void parse_hIST_chunk(int chunkLength) throws IOException,
    IIOException
{
    if (!metadata.PLTE_present) {
        throw new IIOException("hIST chunk without prior PLTE chunk!");
    }

    /* According to PNG specification length of
     * hIST chunk is specified in bytes and
     * hIST chunk consists of 2 byte elements
     * (so we expect length is even).
     */
    metadata.hIST_histogram = new char[chunkLength/2];
    stream.readFully(metadata.hIST_histogram,
                     0, metadata.hIST_histogram.length);

    metadata.hIST_present = true;
}
项目:openjdk-jdk10    文件: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);
}
项目:OpenJSharp    文件:PNGImageWriter.java   
private void write_IHDR() throws IOException {
        // Write IHDR chunk
        ChunkStream cs = new ChunkStream(PNGImageReader.IHDR_TYPE, stream);
        cs.writeInt(metadata.IHDR_width);
        cs.writeInt(metadata.IHDR_height);
        cs.writeByte(metadata.IHDR_bitDepth);
        cs.writeByte(metadata.IHDR_colorType);
        if (metadata.IHDR_compressionMethod != 0) {
            throw new IIOException(
"Only compression method 0 is defined in PNG 1.1");
        }
        cs.writeByte(metadata.IHDR_compressionMethod);
        if (metadata.IHDR_filterMethod != 0) {
            throw new IIOException(
"Only filter method 0 is defined in PNG 1.1");
        }
        cs.writeByte(metadata.IHDR_filterMethod);
        if (metadata.IHDR_interlaceMethod < 0 ||
            metadata.IHDR_interlaceMethod > 1) {
            throw new IIOException(
"Only interlace methods 0 (node) and 1 (adam7) are defined in PNG 1.1");
        }
        cs.writeByte(metadata.IHDR_interlaceMethod);
        cs.finish();
    }
项目:OpenJSharp    文件:ImageInputStreamImpl.java   
/**
 * Resets the current stream byte and bit positions from the stack
 * of marked positions.
 *
 * <p> An <code>IOException</code> will be thrown if the previous
 * marked position lies in the discarded portion of the stream.
 *
 * @exception IOException if an I/O error occurs.
 */
public void reset() throws IOException {
    if (markByteStack.empty()) {
        return;
    }

    long pos = ((Long)markByteStack.pop()).longValue();
    if (pos < flushedPos) {
        throw new IIOException
            ("Previous marked position has been discarded!");
    }
    seek(pos);

    int offset = ((Integer)markBitStack.pop()).intValue();
    setBitOffset(offset);
}
项目:jdk8u-jdk    文件:JPEGBuffer.java   
/**
 * Fills the data array from the stream, starting with
 * the buffer and then reading directly from the stream
 * if necessary.  The buffer is left in an appropriate
 * state.  If the end of the stream is encountered, an
 * <code>IIOException</code> is thrown with the
 * message "Image Format Error".
 */
void readData(byte [] data) throws IOException {
    int count = data.length;
    // First see what's left in the buffer.
    if (bufAvail >= count) {  // It's enough
        System.arraycopy(buf, bufPtr, data, 0, count);
        bufAvail -= count;
        bufPtr += count;
        return;
    }
    int offset = 0;
    if (bufAvail > 0) {  // Some there, but not enough
        System.arraycopy(buf, bufPtr, data, 0, bufAvail);
        offset = bufAvail;
        count -= bufAvail;
        bufAvail = 0;
        bufPtr = 0;
    }
    // Now read the rest directly from the stream
    if (iis.read(data, offset, count) != count) {
        throw new IIOException ("Image format Error");
    }
}
项目:jdk8u-jdk    文件:PNGImageWriter.java   
private void write_IHDR() throws IOException {
        // Write IHDR chunk
        ChunkStream cs = new ChunkStream(PNGImageReader.IHDR_TYPE, stream);
        cs.writeInt(metadata.IHDR_width);
        cs.writeInt(metadata.IHDR_height);
        cs.writeByte(metadata.IHDR_bitDepth);
        cs.writeByte(metadata.IHDR_colorType);
        if (metadata.IHDR_compressionMethod != 0) {
            throw new IIOException(
"Only compression method 0 is defined in PNG 1.1");
        }
        cs.writeByte(metadata.IHDR_compressionMethod);
        if (metadata.IHDR_filterMethod != 0) {
            throw new IIOException(
"Only filter method 0 is defined in PNG 1.1");
        }
        cs.writeByte(metadata.IHDR_filterMethod);
        if (metadata.IHDR_interlaceMethod < 0 ||
            metadata.IHDR_interlaceMethod > 1) {
            throw new IIOException(
"Only interlace methods 0 (node) and 1 (adam7) are defined in PNG 1.1");
        }
        cs.writeByte(metadata.IHDR_interlaceMethod);
        cs.finish();
    }
项目:openjdk-jdk10    文件:ImageInputStreamImpl.java   
/**
 * Resets the current stream byte and bit positions from the stack
 * of marked positions.
 *
 * <p> An {@code IOException} will be thrown if the previous
 * marked position lies in the discarded portion of the stream.
 *
 * @exception IOException if an I/O error occurs.
 */
public void reset() throws IOException {
    if (markByteStack.empty()) {
        return;
    }

    long pos = markByteStack.pop().longValue();
    if (pos < flushedPos) {
        throw new IIOException
            ("Previous marked position has been discarded!");
    }
    seek(pos);

    int offset = markBitStack.pop().intValue();
    setBitOffset(offset);
}
项目:jdk8u-jdk    文件:GIFImageWriter.java   
private void writePlainTextExtension(GIFWritableImageMetadata im)
  throws IOException {
    if (im.hasPlainTextExtension) {
        try {
            stream.write(0x21);
            stream.write(0x1);

            stream.write(12);

            stream.writeShort(im.textGridLeft);
            stream.writeShort(im.textGridTop);
            stream.writeShort(im.textGridWidth);
            stream.writeShort(im.textGridHeight);
            stream.write(im.characterCellWidth);
            stream.write(im.characterCellHeight);
            stream.write(im.textForegroundColor);
            stream.write(im.textBackgroundColor);

            writeBlocks(im.text);

            stream.write(0x00);
        } catch (IOException e) {
            throw new IIOException("I/O error writing Plain Text Extension!", e);
        }
    }
}
项目:jdk8u-jdk    文件:PNGImageReader.java   
private void skipPass(int passWidth, int passHeight)
    throws IOException, IIOException  {
    if ((passWidth == 0) || (passHeight == 0)) {
        return;
    }

    int inputBands = inputBandsForColorType[metadata.IHDR_colorType];
    int bytesPerRow = (inputBands*passWidth*metadata.IHDR_bitDepth + 7)/8;

    // Read the image row-by-row
    for (int srcY = 0; srcY < passHeight; srcY++) {
        // Skip filter byte and the remaining row bytes
        pixelStream.skipBytes(1 + bytesPerRow);

        // If read has been aborted, just return
        // processReadAborted will be called later
        if (abortRequested()) {
            return;
        }
    }
}
项目:openjdk-jdk10    文件:PNGImageReader.java   
private void parse_hIST_chunk(int chunkLength) throws IOException,
    IIOException
{
    if (!metadata.PLTE_present) {
        throw new IIOException("hIST chunk without prior PLTE chunk!");
    }

    /* According to PNG specification length of
     * hIST chunk is specified in bytes and
     * hIST chunk consists of 2 byte elements
     * (so we expect length is even).
     */
    metadata.hIST_histogram = new char[chunkLength/2];
    stream.readFully(metadata.hIST_histogram,
                     0, metadata.hIST_histogram.length);

    metadata.hIST_present = true;
}
项目:OpenJSharp    文件:DQTMarkerSegment.java   
Qtable(JPEGBuffer buffer) throws IIOException {
    elementPrecision = buffer.buf[buffer.bufPtr] >>> 4;
    tableID = buffer.buf[buffer.bufPtr++] & 0xf;
    if (elementPrecision != 0) {
        // IJG is compiled for 8-bits, so this shouldn't happen
        throw new IIOException ("Unsupported element precision");
    }
    data = new int [QTABLE_SIZE];
    // Read from zig-zag order to natural order
    for (int i = 0; i < QTABLE_SIZE; i++) {
        data[i] = buffer.buf[buffer.bufPtr+zigzag[i]] & 0xff;
    }
    buffer.bufPtr += QTABLE_SIZE;
}
项目:openjdk-jdk10    文件:PNGImageReader.java   
public int getHeight(int imageIndex) throws IIOException {
    if (imageIndex != 0) {
        throw new IndexOutOfBoundsException("imageIndex != 0!");
    }

    readHeader();

    return metadata.IHDR_height;
}
项目:openjdk-jdk10    文件:WBMPImageReader.java   
public void readHeader() throws IOException {
    if (gotHeader)
        return;

    if (iis == null) {
        throw new IllegalStateException("Input source not set!");
    }

    metadata = new WBMPMetadata();

    wbmpType = iis.readByte();   // TypeField
    byte fixHeaderField = iis.readByte();

    // check for valid wbmp image
    if (fixHeaderField != 0
        || !isValidWbmpType(wbmpType))
    {
        throw new IIOException(I18N.getString("WBMPImageReader2"));
    }

    metadata.wbmpType = wbmpType;

    // Read image width
    width = ReaderUtil.readMultiByteInteger(iis);
    metadata.width = width;

    // Read image height
    height = ReaderUtil.readMultiByteInteger(iis);
    metadata.height = height;

    gotHeader = true;
}
项目:OpenJSharp    文件:GIFImageReader.java   
public int getHeight(int imageIndex) throws IIOException {
    checkIndex(imageIndex);

    int index = locateImage(imageIndex);
    if (index != imageIndex) {
        throw new IndexOutOfBoundsException();
    }
    readMetadata();
    return imageMetadata.imageHeight;
}
项目:OpenJSharp    文件:GIFImageReader.java   
public IIOMetadata getImageMetadata(int imageIndex) throws IIOException {
    checkIndex(imageIndex);

    int index = locateImage(imageIndex);
    if (index != imageIndex) {
        throw new IndexOutOfBoundsException("Bad image index!");
    }
    readMetadata();
    return imageMetadata;
}
项目:OpenJSharp    文件:GIFImageReader.java   
private int locateImage(int imageIndex) throws IIOException {
    readHeader();

    try {
        // Find closest known index
        int index = Math.min(imageIndex, imageStartPosition.size() - 1);

        // Seek to that position
        Long l = (Long)imageStartPosition.get(index);
        stream.seek(l.longValue());

        // Skip images until at desired index or last image found
        while (index < imageIndex) {
            if (!skipImage()) {
                --index;
                return index;
            }

            Long l1 = new Long(stream.getStreamPosition());
            imageStartPosition.add(l1);
            ++index;
        }
    } catch (IOException e) {
        throw new IIOException("Couldn't seek!", e);
    }

    if (currIndex != imageIndex) {
        imageMetadata = null;
    }
    currIndex = imageIndex;
    return imageIndex;
}
项目:openjdk-jdk10    文件:JFIFMarkerSegment.java   
/**
 * Add an ICC Profile APP2 segment by constructing it from
 * the given ICC_ColorSpace object.
 */
void addICC(ICC_ColorSpace cs) throws IOException {
    if (iccSegment != null) {
        throw new IIOException
            ("> 1 ICC APP2 Marker Segment not supported");
    }
    iccSegment = new ICCMarkerSegment(cs);
}
项目:OpenJSharp    文件:GIFImageWriter.java   
private void writeGraphicControlExtension(int disposalMethod,
                                          boolean userInputFlag,
                                          boolean transparentColorFlag,
                                          int delayTime,
                                          int transparentColorIndex)
  throws IOException {
    try {
        stream.write(0x21);
        stream.write(0xf9);

        stream.write(4);

        int packedFields = (disposalMethod & 0x3) << 2;
        if (userInputFlag) {
            packedFields |= 0x2;
        }
        if (transparentColorFlag) {
            packedFields |= 0x1;
        }
        stream.write(packedFields);

        stream.writeShort((short)delayTime);

        stream.write(transparentColorIndex);
        stream.write(0x00);
    } catch (IOException e) {
        throw new IIOException("I/O error writing Graphic Control Extension!", e);
    }
}
项目:openjdk-jdk10    文件:BMPImageReader.java   
@Override
public int getWidth(int imageIndex) throws IOException {
    checkIndex(imageIndex);
    try {
        readHeader();
    } catch (IllegalArgumentException e) {
        throw new IIOException(I18N.getString("BMPImageReader6"), e);
    }
    return width;
}
项目:openjdk-jdk10    文件:ImageUtil.java   
/** Checks that the provided {@code ImageWriter} can encode
 * the provided {@code ImageTypeSpecifier} or not.  If not, an
 * {@code IIOException} will be thrown.
 * @param writer The provided {@code ImageWriter}.
 * @param type The image to be tested.
 * @throws IIOException If the writer cannot encoded the provided image.
 */
public static final void canEncodeImage(ImageWriter writer,
                                        ImageTypeSpecifier type)
    throws IIOException {
    ImageWriterSpi spi = writer.getOriginatingProvider();

    if(type != null && spi != null && !spi.canEncodeImage(type))  {
        throw new IIOException(I18N.getString("ImageUtil2")+" "+
                               writer.getClass().getName());
    }
}
项目:OpenJSharp    文件:GIFImageWriter.java   
private void writeImageDescriptor(int imageLeftPosition,
                                  int imageTopPosition,
                                  int imageWidth,
                                  int imageHeight,
                                  boolean interlaceFlag,
                                  boolean sortFlag,
                                  int bitsPerPixel,
                                  byte[] localColorTable)
  throws IOException {

    try {
        stream.write(0x2c);

        stream.writeShort((short)imageLeftPosition);
        stream.writeShort((short)imageTopPosition);
        stream.writeShort((short)imageWidth);
        stream.writeShort((short)imageHeight);

        int packedFields = localColorTable != null ? 0x80 : 0x00;
        if (interlaceFlag) {
            packedFields |= 0x40;
        }
        if (sortFlag) {
            packedFields |= 0x8;
        }
        packedFields |= (bitsPerPixel - 1);
        stream.write(packedFields);

        if (localColorTable != null) {
            stream.write(localColorTable);
        }
    } catch (IOException e) {
        throw new IIOException("I/O error writing Image Descriptor!", e);
    }
}
项目:openjdk-jdk10    文件:GIFImageWriter.java   
private void writeGraphicControlExtension(int disposalMethod,
                                          boolean userInputFlag,
                                          boolean transparentColorFlag,
                                          int delayTime,
                                          int transparentColorIndex)
  throws IOException {
    try {
        stream.write(0x21);
        stream.write(0xf9);

        stream.write(4);

        int packedFields = (disposalMethod & 0x3) << 2;
        if (userInputFlag) {
            packedFields |= 0x2;
        }
        if (transparentColorFlag) {
            packedFields |= 0x1;
        }
        stream.write(packedFields);

        stream.writeShort((short)delayTime);

        stream.write(transparentColorIndex);
        stream.write(0x00);
    } catch (IOException e) {
        throw new IIOException("I/O error writing Graphic Control Extension!", e);
    }
}
项目:OpenJSharp    文件:BMPImageReader.java   
public int getHeight(int imageIndex) throws IOException {
    checkIndex(imageIndex);
    try {
        readHeader();
    } catch (IllegalArgumentException e) {
        throw new IIOException(I18N.getString("BMPImageReader6"), e);
    }
    return height;
}
项目:openjdk-jdk10    文件:BMPImageReader.java   
public int getHeight(int imageIndex) throws IOException {
    checkIndex(imageIndex);
    try {
        readHeader();
    } catch (IllegalArgumentException e) {
        throw new IIOException(I18N.getString("BMPImageReader6"), e);
    }
    return height;
}
项目:OpenJSharp    文件:BMPImageReader.java   
public IIOMetadata getImageMetadata(int imageIndex)
  throws IOException {
    checkIndex(imageIndex);
    if (metadata == null) {
        try {
            readHeader();
        } catch (IllegalArgumentException e) {
            throw new IIOException(I18N.getString("BMPImageReader6"), e);
        }
    }
    return metadata;
}
项目:OpenJSharp    文件:ImageUtil.java   
/** Checks that the provided <code>ImageWriter</code> can encode
 * the provided <code>ImageTypeSpecifier</code> or not.  If not, an
 * <code>IIOException</code> will be thrown.
 * @param writer The provided <code>ImageWriter</code>.
 * @param type The image to be tested.
 * @throws IIOException If the writer cannot encoded the provided image.
 */
public static final void canEncodeImage(ImageWriter writer,
                                        ImageTypeSpecifier type)
    throws IIOException {
    ImageWriterSpi spi = writer.getOriginatingProvider();

    if(type != null && spi != null && !spi.canEncodeImage(type))  {
        throw new IIOException(I18N.getString("ImageUtil2")+" "+
                               writer.getClass().getName());
    }
}
项目:OpenJSharp    文件:PNGImageReader.java   
private void parse_sPLT_chunk(int chunkLength)
    throws IOException, IIOException {
    metadata.sPLT_paletteName = readNullTerminatedString("ISO-8859-1", 80);
    chunkLength -= metadata.sPLT_paletteName.length() + 1;

    int sampleDepth = stream.readUnsignedByte();
    metadata.sPLT_sampleDepth = sampleDepth;

    int numEntries = chunkLength/(4*(sampleDepth/8) + 2);
    metadata.sPLT_red = new int[numEntries];
    metadata.sPLT_green = new int[numEntries];
    metadata.sPLT_blue = new int[numEntries];
    metadata.sPLT_alpha = new int[numEntries];
    metadata.sPLT_frequency = new int[numEntries];

    if (sampleDepth == 8) {
        for (int i = 0; i < numEntries; i++) {
            metadata.sPLT_red[i] = stream.readUnsignedByte();
            metadata.sPLT_green[i] = stream.readUnsignedByte();
            metadata.sPLT_blue[i] = stream.readUnsignedByte();
            metadata.sPLT_alpha[i] = stream.readUnsignedByte();
            metadata.sPLT_frequency[i] = stream.readUnsignedShort();
        }
    } else if (sampleDepth == 16) {
        for (int i = 0; i < numEntries; i++) {
            metadata.sPLT_red[i] = stream.readUnsignedShort();
            metadata.sPLT_green[i] = stream.readUnsignedShort();
            metadata.sPLT_blue[i] = stream.readUnsignedShort();
            metadata.sPLT_alpha[i] = stream.readUnsignedShort();
            metadata.sPLT_frequency[i] = stream.readUnsignedShort();
        }
    } else {
        throw new IIOException("sPLT sample depth not 8 or 16!");
    }

    metadata.sPLT_present = true;
}
项目:openjdk-jdk10    文件:TIFFFaxDecompressor.java   
private void getNextChangingElement(int a0, boolean isWhite, int[] ret) throws IIOException {
    // Local copies of instance variables
    int[] pce = this.prevChangingElems;
    int ces = this.changingElemSize;

    // If the previous match was at an odd element, we still
    // have to search the preceeding element.
    // int start = lastChangingElement & ~0x1;
    int start = lastChangingElement > 0 ? lastChangingElement - 1 : 0;
    if (isWhite) {
        start &= ~0x1; // Search even numbered elements
    } else {
        start |= 0x1; // Search odd numbered elements
    }

    int i = start;
    for (; i < ces; i += 2) {
        int temp = pce[i];
        if (temp > a0) {
            lastChangingElement = i;
            ret[0] = temp;
            break;
        }
    }

    if (i + 1 < ces) {
        ret[1] = pce[i + 1];
    }
}
项目:OpenJSharp    文件:PNGImageReader.java   
public int getHeight(int imageIndex) throws IIOException {
    if (imageIndex != 0) {
        throw new IndexOutOfBoundsException("imageIndex != 0!");
    }

    readHeader();

    return metadata.IHDR_height;
}
项目:OpenJSharp    文件:PNGImageReader.java   
public IIOMetadata getImageMetadata(int imageIndex) throws IIOException {
    if (imageIndex != 0) {
        throw new IndexOutOfBoundsException("imageIndex != 0!");
    }
    readMetadata();
    return metadata;
}
项目:openjdk-jdk10    文件:JPEGBuffer.java   
/**
 * Ensures that there are at least {@code count} bytes available
 * in the buffer, loading more data and moving any remaining
 * bytes to the front.  A count of 0 means to just fill the buffer.
 * If the count is larger than the buffer size, just fills the buffer.
 * If the end of the stream is encountered before a non-0 count can
 * be satisfied, an {@code IIOException} is thrown with the
 * message "Image Format Error".
 */
void loadBuf(int count) throws IOException {
    if (debug) {
        System.out.print("loadbuf called with ");
        System.out.print("count " + count + ", ");
        System.out.println("bufAvail " + bufAvail + ", ");
    }
    if (count != 0) {
        if (bufAvail >= count) {  // have enough
            return;
        }
    } else {
        if (bufAvail == BUFFER_SIZE) {  // already full
            return;
        }
    }
    // First copy any remaining bytes down to the beginning
    if ((bufAvail > 0) && (bufAvail < BUFFER_SIZE)) {
        System.arraycopy(buf, bufPtr, buf, 0, bufAvail);
    }
    // Now fill the rest of the buffer
    int ret = iis.read(buf, bufAvail, buf.length - bufAvail);
    if (debug) {
        System.out.println("iis.read returned " + ret);
    }
    if (ret != -1) {
        bufAvail += ret;
    }
    bufPtr = 0;
    int minimum = Math.min(BUFFER_SIZE, count);
    if (bufAvail < minimum) {
        throw new IIOException ("Image Format Error");
    }
}
项目:openjdk-jdk10    文件:JPEGImageWriter.java   
/**
 * Finds all DHT marker segments and returns all the q
 * tables as a single array of JPEGQTables.  The metadata
 * must not be for a progressive image, or an exception
 * will be thrown when two Huffman tables with the same
 * table id are encountered.
 */
private JPEGHuffmanTable[] collectHTablesFromMetadata
    (JPEGMetadata metadata, boolean wantDC) throws IIOException {
    ArrayList<DHTMarkerSegment.Htable> tables = new ArrayList<>();
    Iterator<MarkerSegment> iter = metadata.markerSequence.iterator();
    while (iter.hasNext()) {
        MarkerSegment seg = iter.next();
        if (seg instanceof DHTMarkerSegment) {
            DHTMarkerSegment dht = (DHTMarkerSegment) seg;
            for (int i = 0; i < dht.tables.size(); i++) {
                DHTMarkerSegment.Htable htable = dht.tables.get(i);
                if (htable.tableClass == (wantDC ? 0 : 1)) {
                    tables.add(htable);
                }
            }
        }
    }
    JPEGHuffmanTable [] retval = null;
    if (tables.size() != 0) {
        DHTMarkerSegment.Htable [] htables =
            new DHTMarkerSegment.Htable[tables.size()];
        tables.toArray(htables);
        retval = new JPEGHuffmanTable[tables.size()];
        for (int i = 0; i < retval.length; i++) {
            retval[i] = null;
            for (int j = 0; j < tables.size(); j++) {
                if (htables[j].tableID == i) {
                    if (retval[i] != null) {
                        throw new IIOException("Metadata has duplicate Htables!");
                    }
                    retval[i] = new JPEGHuffmanTable(htables[j].numCodes,
                                                     htables[j].values);
                }
            }
        }
    }

    return retval;
}