From 340e79eb8a709c7211f182dd04d91f7d64ee61e3 Mon Sep 17 00:00:00 2001 From: Vincent Privat Date: Tue, 18 Nov 2025 00:09:19 +0100 Subject: [PATCH] fix webp decoding using source region without subsampling --- .../imageio/plugins/webp/lossless/VP8LDecoder.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/imageio/imageio-webp/src/main/java/com/twelvemonkeys/imageio/plugins/webp/lossless/VP8LDecoder.java b/imageio/imageio-webp/src/main/java/com/twelvemonkeys/imageio/plugins/webp/lossless/VP8LDecoder.java index 0b979699..73a8695d 100644 --- a/imageio/imageio-webp/src/main/java/com/twelvemonkeys/imageio/plugins/webp/lossless/VP8LDecoder.java +++ b/imageio/imageio-webp/src/main/java/com/twelvemonkeys/imageio/plugins/webp/lossless/VP8LDecoder.java @@ -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