@Test public void testMakeColorTransparent() throws IllegalStateException, FileNotFoundException, IOException { assertTrue("Assertions should be enabled.", ImageWorker.class.desiredAssertionStatus()); ImageWorker worker = new ImageWorker(sstImage); assertSame(sstImage, worker.getRenderedImage()); assertEquals( 1, worker.getNumBands()); assertEquals( -1, worker.getTransparentPixel()); assertTrue ( worker.isBytes()); assertFalse ( worker.isBinary()); assertTrue ( worker.isIndexed()); assertTrue ( worker.isColorSpaceRGB()); assertFalse ( worker.isColorSpaceGRAYScale()); assertFalse ( worker.isTranslucent()); assertSame("Expected no operation.", sstImage, worker.forceIndexColorModel(false).getRenderedImage()); assertSame("Expected no operation.", sstImage, worker.forceIndexColorModel(true ).getRenderedImage()); assertSame("Expected no operation.", sstImage, worker.forceColorSpaceRGB() .getRenderedImage()); assertSame("Expected no operation.", sstImage, worker.retainFirstBand() .getRenderedImage()); assertSame("Expected no operation.", sstImage, worker.retainLastBand() .getRenderedImage()); assertEquals( 0, worker.getMinimums()[0], 0); assertEquals(255, worker.getMaximums()[0], 0); assertNotSame(sstImage, worker.getRenderedImage()); assertSame("Expected same databuffer, i.e. pixels should not be duplicated.", sstImage.getTile(0,0).getDataBuffer(), worker.getRenderedImage().getTile(0,0).getDataBuffer()); assertSame(worker, worker.makeColorTransparent(Color.WHITE)); assertEquals(255, worker.getTransparentPixel()); assertFalse ( worker.isTranslucent()); assertSame("Expected same databuffer, i.e. pixels should not be duplicated.", sstImage.getTile(0,0).getDataBuffer(), worker.getRenderedImage().getTile(0,0).getDataBuffer()); worker=new ImageWorker(chlImage).makeColorTransparent(Color.black); show(worker, "CHL01195.png"); assertEquals( 1, worker.getNumBands()); assertEquals( 0, worker.getTransparentPixel()); assertTrue ( worker.isBytes()); assertTrue ( worker.isIndexed()); assertTrue ( worker.isColorSpaceRGB()); assertFalse ( worker.isColorSpaceGRAYScale()); assertFalse ( worker.isTranslucent()); RenderedImage image= worker.getRenderedImage(); assertTrue ( image.getColorModel() instanceof IndexColorModel); IndexColorModel iColorModel=(IndexColorModel) image.getColorModel(); int transparentColor=iColorModel.getRGB(worker.getTransparentPixel())&0x00ffffff; assertTrue ( transparentColor==0); worker=new ImageWorker(bathy).makeColorTransparent(Color.WHITE); show(worker, "BATHY.png"); assertEquals( 1, worker.getNumBands()); assertEquals( 206, worker.getTransparentPixel()); assertTrue ( worker.isBytes()); assertTrue ( worker.isIndexed()); assertTrue ( worker.isColorSpaceRGB()); assertFalse ( worker.isColorSpaceGRAYScale()); assertFalse ( worker.isTranslucent()); image= worker.getRenderedImage(); assertTrue ( image.getColorModel() instanceof IndexColorModel); iColorModel=(IndexColorModel) image.getColorModel(); transparentColor=iColorModel.getRGB(worker.getTransparentPixel())&0x00ffffff; assertTrue ( transparentColor==(Color.WHITE.getRGB()&0x00ffffff)); worker=new ImageWorker(smallWorld).makeColorTransparent(new Color(11,10,50)); show(worker, "small_world.png"); assertEquals( 4, worker.getNumBands()); assertEquals( -1, worker.getTransparentPixel()); assertTrue ( worker.isBytes()); assertFalse ( worker.isIndexed()); assertTrue ( worker.isColorSpaceRGB()); assertFalse ( worker.isColorSpaceGRAYScale()); assertTrue ( worker.isTranslucent()); image= worker.getRenderedImage(); assertTrue ( image.getColorModel() instanceof ComponentColorModel); worker=new ImageWorker(worldImage).makeColorTransparent(Color.white); show(worker, "world.png"); assertEquals( 4, worker.getNumBands()); assertEquals( -1, worker.getTransparentPixel()); assertTrue ( worker.isBytes()); assertFalse ( worker.isIndexed()); assertTrue ( worker.isColorSpaceRGB()); assertFalse ( worker.isColorSpaceGRAYScale()); assertTrue ( worker.isTranslucent()); image= worker.getRenderedImage(); assertTrue ( image.getColorModel() instanceof ComponentColorModel); worker=new ImageWorker(gray).makeColorTransparent(Color.black); show(worker, "gray.png"); assertEquals( 2, worker.getNumBands()); assertEquals( -1, worker.getTransparentPixel()); assertTrue ( worker.isBytes()); assertFalse ( worker.isIndexed()); assertFalse ( worker.isColorSpaceRGB()); assertTrue ( worker.isColorSpaceGRAYScale()); assertTrue ( worker.isTranslucent()); image= worker.getRenderedImage(); assertTrue ( image.getColorModel() instanceof ComponentColorModel); worker=new ImageWorker(grayAlpha).makeColorTransparent(Color.black); show(worker, "gray-alpha.png"); assertEquals( 2, worker.getNumBands()); assertEquals( -1, worker.getTransparentPixel()); assertTrue ( worker.isBytes()); assertFalse ( worker.isIndexed()); assertFalse ( worker.isColorSpaceRGB()); assertTrue ( worker.isColorSpaceGRAYScale()); assertTrue ( worker.isTranslucent()); image= worker.getRenderedImage(); assertTrue ( image.getColorModel() instanceof ComponentColorModel); }
public final ImageWorker makeColorTransparent(final Color transparentColor) throws IllegalStateException { if (transparentColor == null) { throw new IllegalArgumentException( Errors.format(ErrorKeys.NULL_ARGUMENT_$1, "transparentColor")); } final ColorModel cm = image.getColorModel(); if (cm instanceof IndexColorModel) { return maskIndexColorModel(transparentColor); } else if (cm instanceof ComponentColorModel) { switch (image.getSampleModel().getDataType()) { case DataBuffer.TYPE_BYTE: { return maskComponentColorModelByte(transparentColor); } } } throw new IllegalStateException(Errors.format(ErrorKeys.UNSUPPORTED_DATA_TYPE)); }
ImageWorker { public final ImageWorker makeColorTransparent(final Color transparentColor) throws IllegalStateException { if (transparentColor == null) { throw new IllegalArgumentException( Errors.format(ErrorKeys.NULL_ARGUMENT_$1, "transparentColor")); } final ColorModel cm = image.getColorModel(); if (cm instanceof IndexColorModel) { return maskIndexColorModel(transparentColor); } else if (cm instanceof ComponentColorModel) { switch (image.getSampleModel().getDataType()) { case DataBuffer.TYPE_BYTE: { return maskComponentColorModelByte(transparentColor); } } } throw new IllegalStateException(Errors.format(ErrorKeys.UNSUPPORTED_DATA_TYPE)); } }
ImageWorker { public final ImageWorker makeColorTransparent(final Color transparentColor) throws IllegalStateException { if (transparentColor == null) { throw new IllegalArgumentException( Errors.format(ErrorKeys.NULL_ARGUMENT_$1, "transparentColor")); } final ColorModel cm = image.getColorModel(); if (cm instanceof IndexColorModel) { return maskIndexColorModel(transparentColor); } else if (cm instanceof ComponentColorModel) { switch (image.getSampleModel().getDataType()) { case DataBuffer.TYPE_BYTE: { return maskComponentColorModelByte(transparentColor); } } } throw new IllegalStateException(Errors.format(ErrorKeys.UNSUPPORTED_DATA_TYPE)); } ImageWorker();  ImageWorker(final File input);  ImageWorker(final RenderedImage image); }
ImageWorker { public final ImageWorker makeColorTransparent(final Color transparentColor) throws IllegalStateException { if (transparentColor == null) { throw new IllegalArgumentException( Errors.format(ErrorKeys.NULL_ARGUMENT_$1, "transparentColor")); } final ColorModel cm = image.getColorModel(); if (cm instanceof IndexColorModel) { return maskIndexColorModel(transparentColor); } else if (cm instanceof ComponentColorModel) { switch (image.getSampleModel().getDataType()) { case DataBuffer.TYPE_BYTE: { return maskComponentColorModelByte(transparentColor); } } } throw new IllegalStateException(Errors.format(ErrorKeys.UNSUPPORTED_DATA_TYPE)); } ImageWorker();  ImageWorker(final File input);  ImageWorker(final RenderedImage image); final ImageWorker setImage(final RenderedImage image); final void load(final String source, final int imageChoice, final boolean readMetadata); final RenderedImage getRenderedImage(); final BufferedImage getBufferedImage(); final PlanarImage getPlanarImage(); final RenderedOp getRenderedOperation(); final ROI getImageAsROI(); final ROI getROI(); final ImageWorker setROI(final ROI roi); final Object getRenderingHint(final RenderingHints.Key key); final ImageWorker setRenderingHint(final RenderingHints.Key key, final Object value); final ImageWorker setRenderingHints(final RenderingHints
			hints); final ImageWorker removeRenderingHint(final RenderingHints.Key key); final RenderingHints getRenderingHints(); final ImageWorker tileCacheEnabled(final boolean status); final int getNumBands(); final int getTransparentPixel(); final double[] getMinimums(); final double[] getMaximums(); final boolean isBytes(); final boolean isBinary(); final boolean isIndexed(); final boolean isColorSpaceRGB(); final boolean isColorSpaceGRAYScale(); final boolean isTranslucent(); final ImageWorker rescaleToBytes(); final ImageWorker forceIndexColorModel(final boolean error); final ImageWorker forceBitmaskIndexColorModel(); final ImageWorker forceBitmaskIndexColorModel(int suggestedTransparent, final boolean errorDiffusion); final ImageWorker forceIndexColorModelForGIF(final boolean errorDiffusion); final ImageWorker forceComponentColorModel(); final ImageWorker forceComponentColorModel(boolean checkTransparent,boolean optimizeGray); final ImageWorker forceComponentColorModel(boolean checkTransparent); final ImageWorker forceColorSpaceRGB(); final ImageWorker forceColorSpaceIHS(); final ImageWorker bandMerge(int writeband); final ImageWorker addBand(RenderedImage image, boolean before); final ImageWorker forceColorSpaceGRAYScale(); final ImageWorker intensity(); final ImageWorker retainFirstBand(); final ImageWorker retainLastBand(); final ImageWorker retainBands(final int numBands); final ImageWorker retainBands(final int[] bands); final ImageWorker format(final int dataType); final ImageWorker binarize(); final ImageWorker binarize(double threshold); final ImageWorker binarize(final int value0, final int value1); final ImageWorker makeColorTransparent(final Color transparentColor); final ImageWorker invert(); final ImageWorker mask(RenderedImage mask, final boolean maskValue,
			int newValue); final ImageWorker addImage(final RenderedImage renderedImage); final ImageWorker multiplyConst(double[] inValues); final ImageWorker xorConst(int[] values); ImageWorker addTransparencyToIndexColorModel(final RenderedImage alphaChannel,
                                                        final boolean errorDiffusion); final ImageWorker addTransparencyToIndexColorModel(final RenderedImage alphaChannel,
            final boolean translucent, int transparent, final boolean errorDiffusion); final ImageWorker tile(); ImageWorker applyOpacity(float opacity); final ImageWorker write(final File output); final void writePNG(final Object destination, final String compression,
                               final float compressionRate, final boolean nativeAcc,
                               final boolean paletted); final ImageWorker writeGIF(final Object destination,
                                      final String compression,
                                      final float  compressionRate); final void writeJPEG(final Object destination, final String compression,
                                final float compressionRate, final boolean nativeAcc); final void writeTIFF(final Object destination, final String compression,
                                final float compressionRate, final int tileSizeX, final int tileSizeY); ImageWorker affine(AffineTransform tx, Interpolation interpolation, double[] bgValues); ImageWorker crop(float x, float y, float width, float height); final ImageWorker show(); static void main(String[] args); }
ImageWorker { public final ImageWorker makeColorTransparent(final Color transparentColor) throws IllegalStateException { if (transparentColor == null) { throw new IllegalArgumentException( Errors.format(ErrorKeys.NULL_ARGUMENT_$1, "transparentColor")); } final ColorModel cm = image.getColorModel(); if (cm instanceof IndexColorModel) { return maskIndexColorModel(transparentColor); } else if (cm instanceof ComponentColorModel) { switch (image.getSampleModel().getDataType()) { case DataBuffer.TYPE_BYTE: { return maskComponentColorModelByte(transparentColor); } } } throw new IllegalStateException(Errors.format(ErrorKeys.UNSUPPORTED_DATA_TYPE)); } ImageWorker();  ImageWorker(final File input);  ImageWorker(final RenderedImage image); final ImageWorker setImage(final RenderedImage image); final void load(final String source, final int imageChoice, final boolean readMetadata); final RenderedImage getRenderedImage(); final BufferedImage getBufferedImage(); final PlanarImage getPlanarImage(); final RenderedOp getRenderedOperation(); final ROI getImageAsROI(); final ROI getROI(); final ImageWorker setROI(final ROI roi); final Object getRenderingHint(final RenderingHints.Key key); final ImageWorker setRenderingHint(final RenderingHints.Key key, final Object value); final ImageWorker setRenderingHints(final RenderingHints
			hints); final ImageWorker removeRenderingHint(final RenderingHints.Key key); final RenderingHints getRenderingHints(); final ImageWorker tileCacheEnabled(final boolean status); final int getNumBands(); final int getTransparentPixel(); final double[] getMinimums(); final double[] getMaximums(); final boolean isBytes(); final boolean isBinary(); final boolean isIndexed(); final boolean isColorSpaceRGB(); final boolean isColorSpaceGRAYScale(); final boolean isTranslucent(); final ImageWorker rescaleToBytes(); final ImageWorker forceIndexColorModel(final boolean error); final ImageWorker forceBitmaskIndexColorModel(); final ImageWorker forceBitmaskIndexColorModel(int suggestedTransparent, final boolean errorDiffusion); final ImageWorker forceIndexColorModelForGIF(final boolean errorDiffusion); final ImageWorker forceComponentColorModel(); final ImageWorker forceComponentColorModel(boolean checkTransparent,boolean optimizeGray); final ImageWorker forceComponentColorModel(boolean checkTransparent); final ImageWorker forceColorSpaceRGB(); final ImageWorker forceColorSpaceIHS(); final ImageWorker bandMerge(int writeband); final ImageWorker addBand(RenderedImage image, boolean before); final ImageWorker forceColorSpaceGRAYScale(); final ImageWorker intensity(); final ImageWorker retainFirstBand(); final ImageWorker retainLastBand(); final ImageWorker retainBands(final int numBands); final ImageWorker retainBands(final int[] bands); final ImageWorker format(final int dataType); final ImageWorker binarize(); final ImageWorker binarize(double threshold); final ImageWorker binarize(final int value0, final int value1); final ImageWorker makeColorTransparent(final Color transparentColor); final ImageWorker invert(); final ImageWorker mask(RenderedImage mask, final boolean maskValue,
			int newValue); final ImageWorker addImage(final RenderedImage renderedImage); final ImageWorker multiplyConst(double[] inValues); final ImageWorker xorConst(int[] values); ImageWorker addTransparencyToIndexColorModel(final RenderedImage alphaChannel,
                                                        final boolean errorDiffusion); final ImageWorker addTransparencyToIndexColorModel(final RenderedImage alphaChannel,
            final boolean translucent, int transparent, final boolean errorDiffusion); final ImageWorker tile(); ImageWorker applyOpacity(float opacity); final ImageWorker write(final File output); final void writePNG(final Object destination, final String compression,
                               final float compressionRate, final boolean nativeAcc,
                               final boolean paletted); final ImageWorker writeGIF(final Object destination,
                                      final String compression,
                                      final float  compressionRate); final void writeJPEG(final Object destination, final String compression,
                                final float compressionRate, final boolean nativeAcc); final void writeTIFF(final Object destination, final String compression,
                                final float compressionRate, final int tileSizeX, final int tileSizeY); ImageWorker affine(AffineTransform tx, Interpolation interpolation, double[] bgValues); ImageWorker crop(float x, float y, float width, float height); final ImageWorker show(); static void main(String[] args); static final Hints.Key TILING_ALLOWED; }