mirror of
https://github.com/haraldk/TwelveMonkeys.git
synced 2025-08-04 03:55:28 -04:00
#651: Fix ExtraSamplesColorModel to create correct length elements array.
(cherry picked from commit 433311c10d22c1cae4bbd6f0609c9d60aa1aabb3)
This commit is contained in:
parent
a963e1c355
commit
6fb06da4d7
@ -34,10 +34,7 @@ import com.twelvemonkeys.lang.Validate;
|
||||
|
||||
import java.awt.*;
|
||||
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;
|
||||
import java.awt.image.*;
|
||||
|
||||
import static java.awt.image.DataBuffer.getDataTypeSize;
|
||||
|
||||
@ -99,4 +96,27 @@ final class ExtraSamplesColorModel extends ComponentColorModel {
|
||||
private int getAlphaComponent() {
|
||||
return super.getNumComponents() - 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getDataElements(final int rgb, final Object pixel) {
|
||||
return super.getDataElements(rgb, pixel == null ? createDataArray() : pixel);
|
||||
}
|
||||
|
||||
private Object createDataArray() {
|
||||
switch (transferType) {
|
||||
case DataBuffer.TYPE_BYTE:
|
||||
return new byte[numComponents];
|
||||
case DataBuffer.TYPE_SHORT:
|
||||
case DataBuffer.TYPE_USHORT:
|
||||
return new short[numComponents];
|
||||
case DataBuffer.TYPE_INT:
|
||||
return new int[numComponents];
|
||||
case DataBuffer.TYPE_FLOAT:
|
||||
return new float[numComponents];
|
||||
case DataBuffer.TYPE_DOUBLE:
|
||||
return new double[numComponents];
|
||||
}
|
||||
|
||||
throw new IllegalArgumentException("This method has not been implemented for transferType " + transferType);
|
||||
}
|
||||
}
|
||||
|
@ -32,6 +32,7 @@ package com.twelvemonkeys.imageio.plugins.tiff;
|
||||
|
||||
import com.twelvemonkeys.image.ResampleOp;
|
||||
import com.twelvemonkeys.imageio.color.ColorSpaces;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.awt.*;
|
||||
@ -134,4 +135,20 @@ public class ExtraSamplesColorModelTest {
|
||||
assertEquals(5, resampled.getHeight());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetRGB() {
|
||||
BufferedImage image = createExtraSamplesImage(10, 10, ColorSpaces.getColorSpace(ColorSpace.CS_sRGB), false, 1);
|
||||
|
||||
image.setRGB(0, 0, Color.BLACK.getRGB());
|
||||
assertEquals(Color.BLACK.getRGB(), image.getRGB(0, 0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetRGBs() {
|
||||
BufferedImage image = createExtraSamplesImage(10, 10, ColorSpaces.getColorSpace(ColorSpace.CS_sRGB), false, 1);
|
||||
image.setRGB(0, 0, 2, 1, new int[]{Color.BLACK.getRGB(), Color.WHITE.getRGB()}, 0, 2);
|
||||
assertEquals(Color.BLACK.getRGB(), image.getRGB(0, 0));
|
||||
assertEquals(Color.WHITE.getRGB(), image.getRGB(1, 0));
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user