com.sun.imageio.plugins.common.ReaderUtil Java Examples

The following examples show how to use com.sun.imageio.plugins.common.ReaderUtil. 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: WBMPImageReader.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #2
Source File: WBMPImageReader.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example #3
Source File: WBMPImageReader.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example #4
Source File: WBMPImageReader.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example #5
Source File: WBMPImageReader.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #6
Source File: WBMPImageReader.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example #7
Source File: WBMPImageReader.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example #8
Source File: WBMPImageReader.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example #9
Source File: WBMPImageReader.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example #10
Source File: WBMPImageReader.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
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;
}
 
Example #11
Source File: WBMPImageReader.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example #12
Source File: WBMPImageReader.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example #13
Source File: WBMPImageReader.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example #14
Source File: WBMPImageReader.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example #15
Source File: WBMPImageReader.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example #16
Source File: WBMPImageReader.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example #17
Source File: WBMPImageReaderSpi.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
public boolean canDecodeInput(Object source) throws IOException {
    if (!(source instanceof ImageInputStream)) {
        return false;
    }

    ImageInputStream stream = (ImageInputStream)source;

    stream.mark();
    try {
        int type = stream.readByte();   // TypeField
        int fixHeaderField = stream.readByte();
        // check WBMP "header"
        if (type != 0 || fixHeaderField != 0) {
            // while WBMP reader does not support ext WBMP headers
            return false;
        }

        int width = ReaderUtil.readMultiByteInteger(stream);
        int height = ReaderUtil.readMultiByteInteger(stream);
        // check image dimension
        if (width <= 0 || height <= 0) {
            return false;
        }

        long dataLength = stream.length();
        if (dataLength == -1) {
            // We can't verify that amount of data in the stream
            // corresponds to image dimension because we do not know
            // the length of the data stream.
            // Assuming that wbmp image are used for mobile devices,
            // let's introduce an upper limit for image dimension.
            // In case if exact amount of raster data is unknown,
            // let's reject images with dimension above the limit.
            return (width < MAX_WBMP_WIDTH) && (height < MAX_WBMP_HEIGHT);
        }

        dataLength -= stream.getStreamPosition();

        long scanSize = (width / 8) + ((width % 8) == 0 ? 0 : 1);

        return (dataLength == scanSize * height);
    } finally {
        stream.reset();
    }
}
 
Example #18
Source File: WBMPImageReaderSpi.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
public boolean canDecodeInput(Object source) throws IOException {
    if (!(source instanceof ImageInputStream)) {
        return false;
    }

    ImageInputStream stream = (ImageInputStream)source;

    stream.mark();
    try {
        int type = stream.readByte();   // TypeField
        int fixHeaderField = stream.readByte();
        // check WBMP "header"
        if (type != 0 || fixHeaderField != 0) {
            // while WBMP reader does not support ext WBMP headers
            return false;
        }

        int width = ReaderUtil.readMultiByteInteger(stream);
        int height = ReaderUtil.readMultiByteInteger(stream);
        // check image dimension
        if (width <= 0 || height <= 0) {
            return false;
        }

        long dataLength = stream.length();
        if (dataLength == -1) {
            // We can't verify that amount of data in the stream
            // corresponds to image dimension because we do not know
            // the length of the data stream.
            // Assuming that wbmp image are used for mobile devices,
            // let's introduce an upper limit for image dimension.
            // In case if exact amount of raster data is unknown,
            // let's reject images with dimension above the limit.
            return (width < MAX_WBMP_WIDTH) && (height < MAX_WBMP_HEIGHT);
        }

        dataLength -= stream.getStreamPosition();

        long scanSize = (width / 8) + ((width % 8) == 0 ? 0 : 1);

        return (dataLength == scanSize * height);
    } finally {
        stream.reset();
    }
}
 
Example #19
Source File: GIFImageReader.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
private void startPass(int pass) {
    if (updateListeners == null || !imageMetadata.interlaceFlag) {
        return;
    }

    int y = interlaceOffset[interlacePass];
    int yStep = interlaceIncrement[interlacePass];

    int[] vals = ReaderUtil.
        computeUpdatedPixels(sourceRegion,
                             destinationOffset,
                             destinationRegion.x,
                             destinationRegion.y,
                             destinationRegion.x +
                             destinationRegion.width - 1,
                             destinationRegion.y +
                             destinationRegion.height - 1,
                             sourceXSubsampling,
                             sourceYSubsampling,
                             0,
                             y,
                             destinationRegion.width,
                             (destinationRegion.height + yStep - 1)/yStep,
                             1,
                             yStep);

    // Initialized updateMinY and updateYStep
    this.updateMinY = vals[1];
    this.updateYStep = vals[5];

    // Inform IIOReadUpdateListeners of new pass
    int[] bands = { 0 };

    processPassStarted(theImage,
                       interlacePass,
                       sourceMinProgressivePass,
                       sourceMaxProgressivePass,
                       0,
                       updateMinY,
                       1,
                       updateYStep,
                       bands);
}
 
Example #20
Source File: GIFImageReader.java    From jdk1.8-source-analysis with Apache License 2.0 4 votes vote down vote up
private void startPass(int pass) {
    if (updateListeners == null || !imageMetadata.interlaceFlag) {
        return;
    }

    int y = interlaceOffset[interlacePass];
    int yStep = interlaceIncrement[interlacePass];

    int[] vals = ReaderUtil.
        computeUpdatedPixels(sourceRegion,
                             destinationOffset,
                             destinationRegion.x,
                             destinationRegion.y,
                             destinationRegion.x +
                             destinationRegion.width - 1,
                             destinationRegion.y +
                             destinationRegion.height - 1,
                             sourceXSubsampling,
                             sourceYSubsampling,
                             0,
                             y,
                             destinationRegion.width,
                             (destinationRegion.height + yStep - 1)/yStep,
                             1,
                             yStep);

    // Initialized updateMinY and updateYStep
    this.updateMinY = vals[1];
    this.updateYStep = vals[5];

    // Inform IIOReadUpdateListeners of new pass
    int[] bands = { 0 };

    processPassStarted(theImage,
                       interlacePass,
                       sourceMinProgressivePass,
                       sourceMaxProgressivePass,
                       0,
                       updateMinY,
                       1,
                       updateYStep,
                       bands);
}
 
Example #21
Source File: WBMPImageReaderSpi.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
public boolean canDecodeInput(Object source) throws IOException {
    if (!(source instanceof ImageInputStream)) {
        return false;
    }

    ImageInputStream stream = (ImageInputStream)source;

    stream.mark();
    try {
        int type = stream.readByte();   // TypeField
        int fixHeaderField = stream.readByte();
        // check WBMP "header"
        if (type != 0 || fixHeaderField != 0) {
            // while WBMP reader does not support ext WBMP headers
            return false;
        }

        int width = ReaderUtil.readMultiByteInteger(stream);
        int height = ReaderUtil.readMultiByteInteger(stream);
        // check image dimension
        if (width <= 0 || height <= 0) {
            return false;
        }

        long dataLength = stream.length();
        if (dataLength == -1) {
            // We can't verify that amount of data in the stream
            // corresponds to image dimension because we do not know
            // the length of the data stream.
            // Assuming that wbmp image are used for mobile devices,
            // let's introduce an upper limit for image dimension.
            // In case if exact amount of raster data is unknown,
            // let's reject images with dimension above the limit.
            return (width < MAX_WBMP_WIDTH) && (height < MAX_WBMP_HEIGHT);
        }

        dataLength -= stream.getStreamPosition();

        long scanSize = (width / 8) + ((width % 8) == 0 ? 0 : 1);

        return (dataLength == scanSize * height);
    } finally {
        stream.reset();
    }
}
 
Example #22
Source File: GIFImageReader.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
private void startPass(int pass) {
    if (updateListeners == null || !imageMetadata.interlaceFlag) {
        return;
    }

    int y = interlaceOffset[interlacePass];
    int yStep = interlaceIncrement[interlacePass];

    int[] vals = ReaderUtil.
        computeUpdatedPixels(sourceRegion,
                             destinationOffset,
                             destinationRegion.x,
                             destinationRegion.y,
                             destinationRegion.x +
                             destinationRegion.width - 1,
                             destinationRegion.y +
                             destinationRegion.height - 1,
                             sourceXSubsampling,
                             sourceYSubsampling,
                             0,
                             y,
                             destinationRegion.width,
                             (destinationRegion.height + yStep - 1)/yStep,
                             1,
                             yStep);

    // Initialized updateMinY and updateYStep
    this.updateMinY = vals[1];
    this.updateYStep = vals[5];

    // Inform IIOReadUpdateListeners of new pass
    int[] bands = { 0 };

    processPassStarted(theImage,
                       interlacePass,
                       sourceMinProgressivePass,
                       sourceMaxProgressivePass,
                       0,
                       updateMinY,
                       1,
                       updateYStep,
                       bands);
}
 
Example #23
Source File: GIFImageReader.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
private void startPass(int pass) {
    if (updateListeners == null || !imageMetadata.interlaceFlag) {
        return;
    }

    int y = interlaceOffset[interlacePass];
    int yStep = interlaceIncrement[interlacePass];

    int[] vals = ReaderUtil.
        computeUpdatedPixels(sourceRegion,
                             destinationOffset,
                             destinationRegion.x,
                             destinationRegion.y,
                             destinationRegion.x +
                             destinationRegion.width - 1,
                             destinationRegion.y +
                             destinationRegion.height - 1,
                             sourceXSubsampling,
                             sourceYSubsampling,
                             0,
                             y,
                             destinationRegion.width,
                             (destinationRegion.height + yStep - 1)/yStep,
                             1,
                             yStep);

    // Initialized updateMinY and updateYStep
    this.updateMinY = vals[1];
    this.updateYStep = vals[5];

    // Inform IIOReadUpdateListeners of new pass
    int[] bands = { 0 };

    processPassStarted(theImage,
                       interlacePass,
                       sourceMinProgressivePass,
                       sourceMaxProgressivePass,
                       0,
                       updateMinY,
                       1,
                       updateYStep,
                       bands);
}
 
Example #24
Source File: WBMPImageReaderSpi.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
public boolean canDecodeInput(Object source) throws IOException {
    if (!(source instanceof ImageInputStream)) {
        return false;
    }

    ImageInputStream stream = (ImageInputStream)source;

    stream.mark();
    try {
        int type = stream.readByte();   // TypeField
        int fixHeaderField = stream.readByte();
        // check WBMP "header"
        if (type != 0 || fixHeaderField != 0) {
            // while WBMP reader does not support ext WBMP headers
            return false;
        }

        int width = ReaderUtil.readMultiByteInteger(stream);
        int height = ReaderUtil.readMultiByteInteger(stream);
        // check image dimension
        if (width <= 0 || height <= 0) {
            return false;
        }

        long dataLength = stream.length();
        if (dataLength == -1) {
            // We can't verify that amount of data in the stream
            // corresponds to image dimension because we do not know
            // the length of the data stream.
            // Assuming that wbmp image are used for mobile devices,
            // let's introduce an upper limit for image dimension.
            // In case if exact amount of raster data is unknown,
            // let's reject images with dimension above the limit.
            return (width < MAX_WBMP_WIDTH) && (height < MAX_WBMP_HEIGHT);
        }

        dataLength -= stream.getStreamPosition();

        long scanSize = (width / 8) + ((width % 8) == 0 ? 0 : 1);

        return (dataLength == scanSize * height);
    } finally {
        stream.reset();
    }
}
 
Example #25
Source File: WBMPImageReaderSpi.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public boolean canDecodeInput(Object source) throws IOException {
    if (!(source instanceof ImageInputStream)) {
        return false;
    }

    ImageInputStream stream = (ImageInputStream)source;

    stream.mark();
    try {
        int type = stream.readByte();   // TypeField
        int fixHeaderField = stream.readByte();
        // check WBMP "header"
        if (type != 0 || fixHeaderField != 0) {
            // while WBMP reader does not support ext WBMP headers
            return false;
        }

        int width = ReaderUtil.readMultiByteInteger(stream);
        int height = ReaderUtil.readMultiByteInteger(stream);
        // check image dimension
        if (width <= 0 || height <= 0) {
            return false;
        }

        long dataLength = stream.length();
        if (dataLength == -1) {
            // We can't verify that amount of data in the stream
            // corresponds to image dimension because we do not know
            // the length of the data stream.
            // Assuming that wbmp image are used for mobile devices,
            // let's introduce an upper limit for image dimension.
            // In case if exact amount of raster data is unknown,
            // let's reject images with dimension above the limit.
            return (width < MAX_WBMP_WIDTH) && (height < MAX_WBMP_HEIGHT);
        }

        dataLength -= stream.getStreamPosition();

        long scanSize = (width / 8) + ((width % 8) == 0 ? 0 : 1);

        return (dataLength == scanSize * height);
    } finally {
        stream.reset();
    }
}
 
Example #26
Source File: GIFImageReader.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
private void startPass(int pass) {
    if (updateListeners == null || !imageMetadata.interlaceFlag) {
        return;
    }

    int y = interlaceOffset[interlacePass];
    int yStep = interlaceIncrement[interlacePass];

    int[] vals = ReaderUtil.
        computeUpdatedPixels(sourceRegion,
                             destinationOffset,
                             destinationRegion.x,
                             destinationRegion.y,
                             destinationRegion.x +
                             destinationRegion.width - 1,
                             destinationRegion.y +
                             destinationRegion.height - 1,
                             sourceXSubsampling,
                             sourceYSubsampling,
                             0,
                             y,
                             destinationRegion.width,
                             (destinationRegion.height + yStep - 1)/yStep,
                             1,
                             yStep);

    // Initialized updateMinY and updateYStep
    this.updateMinY = vals[1];
    this.updateYStep = vals[5];

    // Inform IIOReadUpdateListeners of new pass
    int[] bands = { 0 };

    processPassStarted(theImage,
                       interlacePass,
                       sourceMinProgressivePass,
                       sourceMaxProgressivePass,
                       0,
                       updateMinY,
                       1,
                       updateYStep,
                       bands);
}
 
Example #27
Source File: WBMPImageReaderSpi.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
public boolean canDecodeInput(Object source) throws IOException {
    if (!(source instanceof ImageInputStream)) {
        return false;
    }

    ImageInputStream stream = (ImageInputStream)source;

    stream.mark();
    try {
        int type = stream.readByte();   // TypeField
        int fixHeaderField = stream.readByte();
        // check WBMP "header"
        if (type != 0 || fixHeaderField != 0) {
            // while WBMP reader does not support ext WBMP headers
            return false;
        }

        int width = ReaderUtil.readMultiByteInteger(stream);
        int height = ReaderUtil.readMultiByteInteger(stream);
        // check image dimension
        if (width <= 0 || height <= 0) {
            return false;
        }

        long dataLength = stream.length();
        if (dataLength == -1) {
            // We can't verify that amount of data in the stream
            // corresponds to image dimension because we do not know
            // the length of the data stream.
            // Assuming that wbmp image are used for mobile devices,
            // let's introduce an upper limit for image dimension.
            // In case if exact amount of raster data is unknown,
            // let's reject images with dimension above the limit.
            return (width < MAX_WBMP_WIDTH) && (height < MAX_WBMP_HEIGHT);
        }

        dataLength -= stream.getStreamPosition();

        long scanSize = (width / 8) + ((width % 8) == 0 ? 0 : 1);

        return (dataLength == scanSize * height);
    } finally {
        stream.reset();
    }
}
 
Example #28
Source File: GIFImageReader.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
private void startPass(int pass) {
    if (updateListeners == null || !imageMetadata.interlaceFlag) {
        return;
    }

    int y = interlaceOffset[interlacePass];
    int yStep = interlaceIncrement[interlacePass];

    int[] vals = ReaderUtil.
        computeUpdatedPixels(sourceRegion,
                             destinationOffset,
                             destinationRegion.x,
                             destinationRegion.y,
                             destinationRegion.x +
                             destinationRegion.width - 1,
                             destinationRegion.y +
                             destinationRegion.height - 1,
                             sourceXSubsampling,
                             sourceYSubsampling,
                             0,
                             y,
                             destinationRegion.width,
                             (destinationRegion.height + yStep - 1)/yStep,
                             1,
                             yStep);

    // Initialized updateMinY and updateYStep
    this.updateMinY = vals[1];
    this.updateYStep = vals[5];

    // Inform IIOReadUpdateListeners of new pass
    int[] bands = { 0 };

    processPassStarted(theImage,
                       interlacePass,
                       sourceMinProgressivePass,
                       sourceMaxProgressivePass,
                       0,
                       updateMinY,
                       1,
                       updateYStep,
                       bands);
}
 
Example #29
Source File: GIFImageReader.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
private void startPass(int pass) {
    if (updateListeners == null || !imageMetadata.interlaceFlag) {
        return;
    }

    int y = interlaceOffset[interlacePass];
    int yStep = interlaceIncrement[interlacePass];

    int[] vals = ReaderUtil.
        computeUpdatedPixels(sourceRegion,
                             destinationOffset,
                             destinationRegion.x,
                             destinationRegion.y,
                             destinationRegion.x +
                             destinationRegion.width - 1,
                             destinationRegion.y +
                             destinationRegion.height - 1,
                             sourceXSubsampling,
                             sourceYSubsampling,
                             0,
                             y,
                             destinationRegion.width,
                             (destinationRegion.height + yStep - 1)/yStep,
                             1,
                             yStep);

    // Initialized updateMinY and updateYStep
    this.updateMinY = vals[1];
    this.updateYStep = vals[5];

    // Inform IIOReadUpdateListeners of new pass
    int[] bands = { 0 };

    processPassStarted(theImage,
                       interlacePass,
                       sourceMinProgressivePass,
                       sourceMaxProgressivePass,
                       0,
                       updateMinY,
                       1,
                       updateYStep,
                       bands);
}
 
Example #30
Source File: GIFImageReader.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
private void startPass(int pass) {
    if (updateListeners == null || !imageMetadata.interlaceFlag) {
        return;
    }

    int y = interlaceOffset[interlacePass];
    int yStep = interlaceIncrement[interlacePass];

    int[] vals = ReaderUtil.
        computeUpdatedPixels(sourceRegion,
                             destinationOffset,
                             destinationRegion.x,
                             destinationRegion.y,
                             destinationRegion.x +
                             destinationRegion.width - 1,
                             destinationRegion.y +
                             destinationRegion.height - 1,
                             sourceXSubsampling,
                             sourceYSubsampling,
                             0,
                             y,
                             destinationRegion.width,
                             (destinationRegion.height + yStep - 1)/yStep,
                             1,
                             yStep);

    // Initialized updateMinY and updateYStep
    this.updateMinY = vals[1];
    this.updateYStep = vals[5];

    // Inform IIOReadUpdateListeners of new pass
    int[] bands = { 0 };

    processPassStarted(theImage,
                       interlacePass,
                       sourceMinProgressivePass,
                       sourceMaxProgressivePass,
                       0,
                       updateMinY,
                       1,
                       updateYStep,
                       bands);
}