mirror of
https://github.com/haraldk/TwelveMonkeys.git
synced 2025-08-05 12:35:29 -04:00
WebP cleanup.
This commit is contained in:
parent
1794e336de
commit
eabb8fd02b
@ -117,7 +117,7 @@ public final class VP8LDecoder {
|
|||||||
|
|
||||||
if (topLevel) {
|
if (topLevel) {
|
||||||
Rectangle bounds = new Rectangle(width, height);
|
Rectangle bounds = new Rectangle(width, height);
|
||||||
fullSizeRaster = getRasterForDecoding(raster, param, bounds);
|
fullSizeRaster = createDecodeRaster(raster, param, bounds);
|
||||||
|
|
||||||
// If multiple indices packed into one pixel xSize is different from raster width
|
// If multiple indices packed into one pixel xSize is different from raster width
|
||||||
decodeRaster = fullSizeRaster.createWritableChild(0, 0, xSize, height, 0, 0, null);
|
decodeRaster = fullSizeRaster.createWritableChild(0, 0, xSize, height, 0, 0, null);
|
||||||
@ -134,11 +134,41 @@ public final class VP8LDecoder {
|
|||||||
transform.applyInverse(fullSizeRaster);
|
transform.applyInverse(fullSizeRaster);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fullSizeRaster != raster && param != null) {
|
if (fullSizeRaster != raster) {
|
||||||
copyIntoRasterWithParams(fullSizeRaster, raster, param);
|
copyIntoRasterWithParams(fullSizeRaster, raster, param);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private WritableRaster createDecodeRaster(WritableRaster raster, ImageReadParam param, Rectangle bounds) {
|
||||||
|
// If the ImageReadParam requires only a subregion of the image, and if the whole image does not fit into the
|
||||||
|
// Raster or subsampling is requested, we need a temporary Raster as we can only decode the whole image at once
|
||||||
|
boolean originSet = false;
|
||||||
|
|
||||||
|
if (param != null) {
|
||||||
|
if (param.getSourceRegion() != null && !param.getSourceRegion().contains(bounds) ||
|
||||||
|
param.getSourceXSubsampling() != 1 || param.getSourceYSubsampling() != 1) {
|
||||||
|
// Can't reuse existing
|
||||||
|
return Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE, bounds.width, bounds.height,
|
||||||
|
4 * bounds.width, 4, new int[] {0, 1, 2, 3}, null);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
bounds.setLocation(param.getDestinationOffset());
|
||||||
|
originSet = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!raster.getBounds().contains(bounds)) {
|
||||||
|
// Can't reuse existing
|
||||||
|
return Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE, bounds.width, bounds.height, 4 * bounds.width,
|
||||||
|
4, new int[] {0, 1, 2, 3}, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
return originSet ?
|
||||||
|
// Recenter to (0, 0)
|
||||||
|
raster.createWritableChild(bounds.x, bounds.y, bounds.width, bounds.height, 0, 0, null) :
|
||||||
|
raster;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Copy a source raster into a destination raster with optional settings applied.
|
* Copy a source raster into a destination raster with optional settings applied.
|
||||||
*/
|
*/
|
||||||
@ -169,36 +199,6 @@ public final class VP8LDecoder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private WritableRaster getRasterForDecoding(WritableRaster raster, ImageReadParam param, Rectangle bounds) {
|
|
||||||
// If the ImageReadParam requires only a subregion of the image, and if the whole image does not fit into the
|
|
||||||
// Raster or subsampling is requested, we need a temporary Raster as we can only decode the whole image at once
|
|
||||||
boolean originSet = false;
|
|
||||||
|
|
||||||
if (param != null) {
|
|
||||||
if (param.getSourceRegion() != null && !param.getSourceRegion().contains(bounds) ||
|
|
||||||
param.getSourceXSubsampling() != 1 || param.getSourceYSubsampling() != 1) {
|
|
||||||
// Can't reuse existing
|
|
||||||
return Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE, bounds.width, bounds.height,
|
|
||||||
4 * bounds.width, 4, new int[] {0, 1, 2, 3}, null);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
bounds.setLocation(param.getDestinationOffset());
|
|
||||||
originSet = true;
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!raster.getBounds().contains(bounds)) {
|
|
||||||
// Can't reuse existing
|
|
||||||
return Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE, bounds.width, bounds.height, 4 * bounds.width,
|
|
||||||
4, new int[] {0, 1, 2, 3}, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
return originSet ?
|
|
||||||
// Recenter to (0, 0)
|
|
||||||
raster.createWritableChild(bounds.x, bounds.y, bounds.width, bounds.height, 0, 0, null) :
|
|
||||||
raster;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void decodeImage(WritableRaster raster, HuffmanInfo huffmanInfo, ColorCache colorCache) throws IOException {
|
private void decodeImage(WritableRaster raster, HuffmanInfo huffmanInfo, ColorCache colorCache) throws IOException {
|
||||||
int width = raster.getWidth();
|
int width = raster.getWidth();
|
||||||
int height = raster.getHeight();
|
int height = raster.getHeight();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user