mirror of
https://github.com/haraldk/TwelveMonkeys.git
synced 2025-08-03 11:35:29 -04:00
Merge pull request #429 from ikhaldeev/fix-extra-samples-alpha
Fix getAlphaRaster for ExtraSamplesColorModel (TIFFImageReader)
This commit is contained in:
commit
7cb1c6811a
@ -7,6 +7,7 @@ import java.awt.color.ColorSpace;
|
||||
import java.awt.image.ComponentColorModel;
|
||||
import java.awt.image.ComponentSampleModel;
|
||||
import java.awt.image.SampleModel;
|
||||
import java.awt.image.WritableRaster;
|
||||
|
||||
/**
|
||||
* ExtraSamplesColorModel.
|
||||
@ -41,4 +42,19 @@ final class ExtraSamplesColorModel extends ComponentColorModel {
|
||||
// Must have the same number of components
|
||||
return numComponents == sm.getNumBands() && transferType == sm.getTransferType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public WritableRaster getAlphaRaster(WritableRaster raster) {
|
||||
if (hasAlpha() == false) {
|
||||
return null;
|
||||
}
|
||||
|
||||
int x = raster.getMinX();
|
||||
int y = raster.getMinY();
|
||||
int[] band = new int[1];
|
||||
band[0] = super.getNumComponents() - 1;
|
||||
return raster.createWritableChild(x, y, raster.getWidth(),
|
||||
raster.getHeight(), x, y,
|
||||
band);
|
||||
}
|
||||
}
|
||||
|
@ -40,6 +40,7 @@ import javax.imageio.stream.ImageInputStream;
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.awt.image.Raster;
|
||||
import java.awt.image.WritableRaster;
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteOrder;
|
||||
import java.util.Arrays;
|
||||
@ -586,6 +587,25 @@ public class TIFFImageReaderTest extends ImageReaderAbstractTest<TIFFImageReader
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAlphaRasterForMultipleExtraSamples() throws IOException {
|
||||
ImageReader reader = createReader();
|
||||
try (ImageInputStream stream = ImageIO.createImageInputStream(getClassLoaderResource("/tiff/extra-channels.tif"))) {
|
||||
reader.setInput(stream);
|
||||
|
||||
BufferedImage image = reader.read(0);
|
||||
assertNotNull(image);
|
||||
|
||||
assertEquals(0x00, image.getRGB(0, 0));
|
||||
assertEquals(0xf5, (image.getRGB(50, 50) & 0xff000000) >>> 24);
|
||||
|
||||
int[] alpha = new int[1];
|
||||
WritableRaster alphaRaster = image.getAlphaRaster();
|
||||
assertEquals(0x00, alphaRaster.getPixel(0, 0, alpha)[0]);
|
||||
assertEquals(0xf5, alphaRaster.getPixel(50, 50, alpha)[0]);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReadWithSubsampleParamPixelsJPEG() throws IOException {
|
||||
// Tiled "new style" JPEG
|
||||
|
BIN
imageio/imageio-tiff/src/test/resources/tiff/extra-channels.tif
Executable file
BIN
imageio/imageio-tiff/src/test/resources/tiff/extra-channels.tif
Executable file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user