break;
default:
throw new
IOException("Unexpected compression type: " + type);
}
ImageReader reader =
ImageIO.getImageReadersByFormatName(format).next();
if (reader == null) {
throw new RuntimeException(I18N.getString("BMPImageReader4") +
" " + format);
}
// prepare input
byte[] buff = new byte[(int)imageSize];
iis.read(buff);
reader.setInput(ImageIO.createImageInputStream(new ByteArrayInputStream(buff)));
if (bi == null) {
ImageTypeSpecifier embType = reader.getImageTypes(0).next();
bi = embType.createBufferedImage(destinationRegion.x +
destinationRegion.width,
destinationRegion.y +
destinationRegion.height);
}
reader.addIIOReadProgressListener(new EmbeddedProgressAdapter() {
public void imageProgress(ImageReader source,
float percentageDone)
{
processImageProgress(percentageDone);
}
});
reader.addIIOReadUpdateListener(new IIOReadUpdateListener() {
public void imageUpdate(ImageReader source,
BufferedImage theImage,
int minX, int minY,
int width, int height,
int periodX, int periodY,
int[] bands)
{
processImageUpdate(theImage, minX, minY,
width, height,
periodX, periodY, bands);
}
public void passComplete(ImageReader source,
BufferedImage theImage)
{
processPassComplete(theImage);
}
public void passStarted(ImageReader source,
BufferedImage theImage,
int pass,
int minPass, int maxPass,
int minX, int minY,
int periodX, int periodY,
int[] bands)
{
processPassStarted(theImage, pass, minPass, maxPass,
minX, minY, periodX, periodY,
bands);
}
public void thumbnailPassComplete(ImageReader source,
BufferedImage thumb) {}
public void thumbnailPassStarted(ImageReader source,
BufferedImage thumb,
int pass,
int minPass, int maxPass,
int minX, int minY,
int periodX, int periodY,
int[] bands) {}
public void thumbnailUpdate(ImageReader source,
BufferedImage theThumbnail,
int minX, int minY,
int width, int height,
int periodX, int periodY,
int[] bands) {}
});
reader.addIIOReadWarningListener(new IIOReadWarningListener() {
public void warningOccurred(ImageReader source, String warning)
{
processWarningOccurred(warning);
}
});
ImageReadParam param = reader.getDefaultReadParam();
param.setDestination(bi);
param.setDestinationBands(bmpParam.getDestinationBands());
param.setDestinationOffset(bmpParam.getDestinationOffset());
param.setSourceBands(bmpParam.getSourceBands());
param.setSourceRegion(bmpParam.getSourceRegion());
param.setSourceSubsampling(bmpParam.getSourceXSubsampling(),
bmpParam.getSourceYSubsampling(),
bmpParam.getSubsamplingXOffset(),
bmpParam.getSubsamplingYOffset());
reader.read(0, param);
return bi;
}