Move to a static method the code that copies into a raster with params.

(cherry picked from commit 0ebd18fcb65e31325c9026b4a7e1087dc2a961b3)
This commit is contained in:
tc-wleite 2023-03-14 20:59:54 -03:00 committed by Harald Kuhr
parent 1ea443cdcf
commit 214f0acf29

View File

@ -135,7 +135,19 @@ public final class VP8LDecoder {
} }
if (fullSizeRaster != raster && param != null) { if (fullSizeRaster != raster && param != null) {
// Copy into destination raster with settings applied copyIntoRasterWithParams(fullSizeRaster, decodeRaster, param);
}
}
/**
* Copy a source raster into a destination raster with settings applied.
*
* TODO: This piece of was inside readVP8Lossless(), but as it can be used in
* readAlpha(), this utility static method was created here. Probably, it should
* be moved to another class.
*/
public static void copyIntoRasterWithParams(final Raster srcRaster, final WritableRaster dstRaster,
final ImageReadParam param) {
Rectangle sourceRegion = param.getSourceRegion(); Rectangle sourceRegion = param.getSourceRegion();
int sourceXSubsampling = param.getSourceXSubsampling(); int sourceXSubsampling = param.getSourceXSubsampling();
int sourceYSubsampling = param.getSourceYSubsampling(); int sourceYSubsampling = param.getSourceYSubsampling();
@ -144,24 +156,23 @@ public final class VP8LDecoder {
Point destinationOffset = param.getDestinationOffset(); Point destinationOffset = param.getDestinationOffset();
if (sourceRegion == null) { if (sourceRegion == null) {
sourceRegion = raster.getBounds(); sourceRegion = dstRaster.getBounds();
} }
if (sourceXSubsampling == 1 && sourceYSubsampling == 1) { if (sourceXSubsampling == 1 && sourceYSubsampling == 1) {
// Only apply offset (and limit to requested region) // Only apply offset (and limit to requested region)
raster.setRect(destinationOffset.x, destinationOffset.y, fullSizeRaster); dstRaster.setRect(destinationOffset.x, destinationOffset.y, srcRaster);
} }
else { else {
// Manual copy, more efficient way might exist // Manual copy, more efficient way might exist
byte[] rgba = new byte[4]; byte[] rgba = new byte[4];
int xEnd = raster.getWidth() + raster.getMinX(); int xEnd = dstRaster.getWidth() + dstRaster.getMinX();
int yEnd = raster.getHeight() + raster.getMinY(); int yEnd = dstRaster.getHeight() + dstRaster.getMinY();
for (int xDst = destinationOffset.x, xSrc = sourceRegion.x + subsamplingXOffset; xDst < xEnd; xDst++, xSrc += sourceXSubsampling) { for (int xDst = destinationOffset.x, xSrc = sourceRegion.x + subsamplingXOffset; xDst < xEnd; xDst++, xSrc += sourceXSubsampling) {
for (int yDst = destinationOffset.y, ySrc = sourceRegion.y + subsamplingYOffset; yDst < yEnd; yDst++, ySrc += sourceYSubsampling) { for (int yDst = destinationOffset.y, ySrc = sourceRegion.y + subsamplingYOffset; yDst < yEnd; yDst++, ySrc += sourceYSubsampling) {
fullSizeRaster.getDataElements(xSrc, ySrc, rgba); srcRaster.getDataElements(xSrc, ySrc, rgba);
raster.setDataElements(xDst, yDst, rgba); dstRaster.setDataElements(xDst, yDst, rgba);
}
} }
} }
} }