while (imageTypes.hasNext()) { ImageTypeSpecifier imageTypeSpecifier = imageTypes.next(); int bufferedImageType = imageTypeSpecifier.getBufferedImageType(); if (bufferedImageType == BufferedImage.TYPE_BYTE_GRAY) { param.setDestinationType(imageTypeSpecifier);
private List<ImageTypeSpecifier> createIllegalTypes(Iterator<ImageTypeSpecifier> pValidTypes) { List<ImageTypeSpecifier> allTypes = new ArrayList<>(); for (int i = BufferedImage.TYPE_INT_RGB; i < BufferedImage.TYPE_BYTE_INDEXED; i++) { allTypes.add(ImageTypeSpecifier.createFromBufferedImageType(i)); } List<ImageTypeSpecifier> illegalTypes = new ArrayList<>(allTypes); while (pValidTypes.hasNext()) { ImageTypeSpecifier valid = pValidTypes.next(); boolean removed = illegalTypes.remove(valid); // TODO: 4BYTE_ABGR (6) and 4BYTE_ABGR_PRE (7) is essentially the same type... // #$@*%$! ImageTypeSpecifier.equals is not well-defined if (!removed) { for (Iterator<ImageTypeSpecifier> iterator = illegalTypes.iterator(); iterator.hasNext();) { ImageTypeSpecifier illegalType = iterator.next(); if (illegalType.getBufferedImageType() == valid.getBufferedImageType()) { iterator.remove(); } } } } return illegalTypes; }
while (imageTypes.hasNext()) { ImageTypeSpecifier imageTypeSpecifier = imageTypes.next(); int bufferedImageType = imageTypeSpecifier.getBufferedImageType(); if (bufferedImageType == BufferedImage.TYPE_BYTE_GRAY) { param.setDestinationType(imageTypeSpecifier);
@Test public void testGetDestinationSourceExceedsIntegerMax() throws IIOException { ImageReadParam param = new ImageReadParam(); param.setSourceRegion(new Rectangle(42, 7)); BufferedImage destination = ImageReaderBase.getDestination(param, TYPES.iterator(), Integer.MAX_VALUE, 42);// 90 194 313 174 pixels assertEquals(42, destination.getWidth()); assertEquals(7, destination.getHeight()); assertEquals(TYPES.get(0).getBufferedImageType(), destination.getType()); }
@Test public void testGetDestinationParamSourceRegionWider() throws IIOException { ImageReadParam param = new ImageReadParam(); param.setSourceRegion(new Rectangle(42, 1)); BufferedImage destination = ImageReaderBase.getDestination(param, TYPES.iterator(), 3, 3); assertEquals(3, destination.getWidth()); assertEquals(1, destination.getHeight()); assertEquals(TYPES.get(0).getBufferedImageType(), destination.getType()); }
@Override public boolean canEncodeImage(final ImageTypeSpecifier type) { // Fast case, it's a known, supported type switch (type.getBufferedImageType()) { case BufferedImage.TYPE_INT_RGB: case BufferedImage.TYPE_INT_ARGB: case BufferedImage.TYPE_INT_ARGB_PRE: case BufferedImage.TYPE_3BYTE_BGR: case BufferedImage.TYPE_4BYTE_ABGR: case BufferedImage.TYPE_4BYTE_ABGR_PRE: case BufferedImage.TYPE_USHORT_555_RGB: case BufferedImage.TYPE_BYTE_GRAY: case BufferedImage.TYPE_BYTE_INDEXED: return true; case BufferedImage.TYPE_BYTE_BINARY: // Could be supported? Uncertain if the format allows < 8 bit/sample for color map entries case BufferedImage.TYPE_INT_BGR: // TODO: Should be supported, just needs to invert band indices/offsets case BufferedImage.TYPE_USHORT_565_RGB: case BufferedImage.TYPE_USHORT_GRAY: return false; default: // Fall through } // Inspect color model etc. ColorSpace colorSpace = type.getColorModel().getColorSpace(); if (!(colorSpace.getType() == ColorSpace.TYPE_RGB || colorSpace.getType() == ColorSpace.TYPE_GRAY)) { return false; } // TODO! return true; }
@Test public void testGetDestinationParamSourceRegionTaller() throws IIOException { ImageReadParam param = new ImageReadParam(); param.setSourceRegion(new Rectangle(1, 42)); BufferedImage destination = ImageReaderBase.getDestination(param, TYPES.iterator(), 3, 3); assertEquals(1, destination.getWidth()); assertEquals(3, destination.getHeight()); assertEquals(TYPES.get(0).getBufferedImageType(), destination.getType()); }
int bufferedImageType = specifier.getBufferedImageType();
if (type.getBufferedImageType() != BufferedImage.TYPE_BYTE_GRAY) { typeList.add(type);
pParam.getDestinationType() != null && pParam.getDestinationType().getBufferedImageType() != image.getType())) { BufferedImage destination = getDestination(pParam, getImageTypes(pIndex), getWidth(pIndex), getHeight(pIndex));
static int getPreferredCompressionType(ImageTypeSpecifier imageType) { int biType = imageType.getBufferedImageType(); if (biType == BufferedImage.TYPE_USHORT_565_RGB || biType == BufferedImage.TYPE_USHORT_555_RGB) { return BI_BITFIELDS; } return BI_RGB; }
static int getPreferredCompressionType(ImageTypeSpecifier imageType) { int biType = imageType.getBufferedImageType(); if (biType == BufferedImage.TYPE_USHORT_565_RGB || biType == BufferedImage.TYPE_USHORT_555_RGB) { return BI_BITFIELDS; } return BI_RGB; }
static int getPreferredCompressionType(ImageTypeSpecifier imageType) { int biType = imageType.getBufferedImageType(); if (biType == BufferedImage.TYPE_USHORT_565_RGB || biType == BufferedImage.TYPE_USHORT_555_RGB) { return BI_BITFIELDS; } return BI_RGB; }
@Test public void testFilterRotateBICustom() { BufferedImageOp jreOp = new java.awt.image.AffineTransformOp(AffineTransform.getQuadrantRotateInstance(1, Math.min(width, height) / 2, Math.min(width, height) / 2), null); BufferedImageOp tmOp = new com.twelvemonkeys.image.AffineTransformOp(AffineTransform.getQuadrantRotateInstance(1, Math.min(width, height) / 2, Math.min(width, height) / 2), null); for (ImageTypeSpecifier spec : SPECS) { BufferedImage image = spec.createBufferedImage(width, height); BufferedImage tmResult = tmOp.filter(image, null); assertNotNull("No result!", tmResult); BufferedImage jreResult = null; try { jreResult = jreOp.filter(image, null); } catch (ImagingOpException ignore) { // We expect this to fail for certain cases, that's why we crated the class in the first place } if (jreResult != null) { assertEquals("Bad type", jreResult.getType(), tmResult.getType()); assertEquals("Incorrect color model", jreResult.getColorModel(), tmResult.getColorModel()); assertEquals("Incorrect width", jreResult.getWidth(), tmResult.getWidth()); assertEquals("Incorrect height", jreResult.getHeight(), tmResult.getHeight()); } else { assertEquals("Bad type", spec.getBufferedImageType(), tmResult.getType()); assertEquals("Incorrect color model", spec.getColorModel(), tmResult.getColorModel()); assertEquals("Incorrect width", height, tmResult.getWidth()); assertEquals("Incorrect height", width, tmResult.getHeight()); } } }
ImageTypeSpecifier rawType = getRawImageType(imageIndex); if (rawType.getColorModel() instanceof IndexColorModel && rawType.getBufferedImageType() != image.getType()) { checkReadParamBandSettings(param, 4, image.getSampleModel().getNumBands()); WritableRaster raster = Raster.createPackedRaster(buffer, width, height, resource.depth(), null); if (image.getType() == rawType.getBufferedImageType() && ((IndexColorModel) image.getColorModel()).getMapSize() == 2) { WritableRaster raster = Raster.createPackedRaster(buffer, width, height, resource.depth(), null); if (image.getType() == rawType.getBufferedImageType()) {
BufferedImage image = imageReader.read(i, param); assertEquals(type.getBufferedImageType(), image.getType()); if (type.getBufferedImageType() == 0) {
protected static int getBufferedImageType(final ImageReader reader) throws IOException { ImageTypeSpecifier imageTypeSpecifier = reader.getImageTypes(0).next(); ColorModel colorModel = imageTypeSpecifier.getColorModel(); if (isFakeGrayScale(colorModel)) { return BufferedImage.TYPE_BYTE_GRAY; } int imageType = imageTypeSpecifier.getBufferedImageType(); return imageType == BufferedImage.TYPE_CUSTOM ? BufferedImage.TYPE_INT_RGB : imageType; }
@Test public void testGetDestinationParamSourceRegionTaller() throws IIOException { ImageReadParam param = new ImageReadParam(); param.setSourceRegion(new Rectangle(1, 42)); BufferedImage destination = ImageReaderBase.getDestination(param, TYPES.iterator(), 3, 3); assertEquals(1, destination.getWidth()); assertEquals(3, destination.getHeight()); assertEquals(TYPES.get(0).getBufferedImageType(), destination.getType()); }
@Test public void testGetDestinationParamSourceRegionWider() throws IIOException { ImageReadParam param = new ImageReadParam(); param.setSourceRegion(new Rectangle(42, 1)); BufferedImage destination = ImageReaderBase.getDestination(param, TYPES.iterator(), 3, 3); assertEquals(3, destination.getWidth()); assertEquals(1, destination.getHeight()); assertEquals(TYPES.get(0).getBufferedImageType(), destination.getType()); }
@Test public void testGetDestinationSourceExceedsIntegerMax() throws IIOException { ImageReadParam param = new ImageReadParam(); param.setSourceRegion(new Rectangle(42, 7)); BufferedImage destination = ImageReaderBase.getDestination(param, TYPES.iterator(), Integer.MAX_VALUE, 42);// 90 194 313 174 pixels assertEquals(42, destination.getWidth()); assertEquals(7, destination.getHeight()); assertEquals(TYPES.get(0).getBufferedImageType(), destination.getType()); }