mirror of
https://github.com/haraldk/TwelveMonkeys.git
synced 2025-08-04 20:15:28 -04:00
Move to a static method the code that copies into a raster with params.
(cherry picked from commit 0ebd18fcb65e31325c9026b4a7e1087dc2a961b3)
This commit is contained in:
parent
1ea443cdcf
commit
214f0acf29
@ -135,33 +135,44 @@ 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);
|
||||||
Rectangle sourceRegion = param.getSourceRegion();
|
}
|
||||||
int sourceXSubsampling = param.getSourceXSubsampling();
|
}
|
||||||
int sourceYSubsampling = param.getSourceYSubsampling();
|
|
||||||
int subsamplingXOffset = param.getSubsamplingXOffset();
|
|
||||||
int subsamplingYOffset = param.getSubsamplingYOffset();
|
|
||||||
Point destinationOffset = param.getDestinationOffset();
|
|
||||||
|
|
||||||
if (sourceRegion == null) {
|
/**
|
||||||
sourceRegion = raster.getBounds();
|
* 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();
|
||||||
|
int sourceXSubsampling = param.getSourceXSubsampling();
|
||||||
|
int sourceYSubsampling = param.getSourceYSubsampling();
|
||||||
|
int subsamplingXOffset = param.getSubsamplingXOffset();
|
||||||
|
int subsamplingYOffset = param.getSubsamplingYOffset();
|
||||||
|
Point destinationOffset = param.getDestinationOffset();
|
||||||
|
|
||||||
if (sourceXSubsampling == 1 && sourceYSubsampling == 1) {
|
if (sourceRegion == null) {
|
||||||
// Only apply offset (and limit to requested region)
|
sourceRegion = dstRaster.getBounds();
|
||||||
raster.setRect(destinationOffset.x, destinationOffset.y, fullSizeRaster);
|
}
|
||||||
}
|
|
||||||
else {
|
|
||||||
// Manual copy, more efficient way might exist
|
|
||||||
byte[] rgba = new byte[4];
|
|
||||||
int xEnd = raster.getWidth() + raster.getMinX();
|
|
||||||
int yEnd = raster.getHeight() + raster.getMinY();
|
|
||||||
|
|
||||||
for (int xDst = destinationOffset.x, xSrc = sourceRegion.x + subsamplingXOffset; xDst < xEnd; xDst++, xSrc += sourceXSubsampling) {
|
if (sourceXSubsampling == 1 && sourceYSubsampling == 1) {
|
||||||
for (int yDst = destinationOffset.y, ySrc = sourceRegion.y + subsamplingYOffset; yDst < yEnd; yDst++, ySrc += sourceYSubsampling) {
|
// Only apply offset (and limit to requested region)
|
||||||
fullSizeRaster.getDataElements(xSrc, ySrc, rgba);
|
dstRaster.setRect(destinationOffset.x, destinationOffset.y, srcRaster);
|
||||||
raster.setDataElements(xDst, yDst, rgba);
|
}
|
||||||
}
|
else {
|
||||||
|
// Manual copy, more efficient way might exist
|
||||||
|
byte[] rgba = new byte[4];
|
||||||
|
int xEnd = dstRaster.getWidth() + dstRaster.getMinX();
|
||||||
|
int yEnd = dstRaster.getHeight() + dstRaster.getMinY();
|
||||||
|
|
||||||
|
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) {
|
||||||
|
srcRaster.getDataElements(xSrc, ySrc, rgba);
|
||||||
|
dstRaster.setDataElements(xDst, yDst, rgba);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user