fix webp decoding using source region without subsampling

This commit is contained in:
Vincent Privat
2025-11-18 00:09:19 +01:00
committed by Harald Kuhr
parent 355a916225
commit 340e79eb8a

View File

@@ -148,8 +148,7 @@ public final class VP8LDecoder {
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);
return createCompatibleRaster(raster, bounds.width, bounds.height);
}
else {
bounds.setLocation(param.getDestinationOffset());
@@ -159,8 +158,7 @@ public final class VP8LDecoder {
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 createCompatibleRaster(raster, bounds.width, bounds.height);
}
return originSet ?
@@ -169,6 +167,11 @@ public final class VP8LDecoder {
raster;
}
private static WritableRaster createCompatibleRaster(WritableRaster src, int width, int height) {
SampleModel sampleModel = src.getSampleModel().createCompatibleSampleModel(width, height);
return Raster.createWritableRaster(sampleModel, sampleModel.createDataBuffer(), null);
}
/**
* Copy a source raster into a destination raster with optional settings applied.
*/
@@ -182,7 +185,8 @@ public final class VP8LDecoder {
if (sourceXSubsampling == 1 && sourceYSubsampling == 1) {
// Only apply offset (and limit to requested region)
dstRaster.setRect(destinationOffset.x, destinationOffset.y, srcRaster);
dstRaster.setRect(destinationOffset.x, destinationOffset.y, srcRaster.createChild(
sourceRegion.x, sourceRegion.y, sourceRegion.width, sourceRegion.height, 0, 0, null));
}
else {
// Subsampled case