public PaletteData getPaletteData() { switch ( getDepth() ) { case 1: palette = new PaletteData( new RGB[] { new RGB( 0, 0, 0 ), new RGB( 255, 255, 255 ) } ); break; default: palette = new PaletteData( 0, 0, 0 ); palette.isDirect = true; break; } return palette; }
/** * Converts BufferedImage to SWT/Image with alpha channel. */ protected Image swing2swt( Device device, BufferedImage img ) { PaletteData palette = new PaletteData( 0xFF0000, 0xFF00, 0xFF ); ImageData data = new ImageData( img.getWidth(), img.getHeight(), 32, palette ); for ( int y = 0; y < data.height; y++ ) { for ( int x = 0; x < data.width; x++ ) { int rgba = img.getRGB( x, y ); int rgb = palette.getPixel( new RGB( ( rgba >> 16 ) & 0xFF, ( rgba >> 8 ) & 0xFF, rgba & 0xFF ) ); int a = ( rgba >> 24 ) & 0xFF; data.setPixel( x, y, rgb ); data.setAlpha( x, y, a ); } } return new Image( device, data ); } }
for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { RGB rgb = imgPixels.palette.getRGB(imgPixels.getPixel(x, y)); if (rgb.red == 255 && rgb.green == 255 && rgb.blue == 255) { inPixels[offset] = (rgb.red << 16) | (rgb.green << 8) | rgb.blue; convolve(kernel, outPixels, inPixels, height, width, true); ImageData dst = new ImageData(imgPixels.width, imgPixels.height, 24, new PaletteData(0xff0000, 0xff00, 0xff));
/** * Returns an array of <code>RGB</code>s which comprise the * indexed color table of the receiver, or null if the receiver * has a direct color model. * * @return the RGB values for the image or null if direct color * * @see PaletteData#getRGBs() */ public RGB[] getRGBs() { return palette.getRGBs(); }
public static Image makeImageTransparent( Display display, Image tempImage, RGB transparentColor ) { ImageData imageData = tempImage.getImageData(); int pixelIndex = imageData.palette.getPixel( transparentColor ); imageData.transparentPixel = pixelIndex; Image image = new Image( display, imageData ); tempImage.dispose(); return image; }
/** * Constructs a new direct palette given the red, green and blue masks. * * @param redMask the red mask * @param greenMask the green mask * @param blueMask the blue mask */ public PaletteData(int redMask, int greenMask, int blueMask) { this.redMask = redMask; this.greenMask = greenMask; this.blueMask = blueMask; this.isDirect = true; this.redShift = shiftForMask(redMask); this.greenShift = shiftForMask(greenMask); this.blueShift = shiftForMask(blueMask); }
void showColorForPixel(int x, int y) { if (x >= 0 && x < imageData.width && y >= 0 && y < imageData.height) { int pixel = imageData.getPixel(x, y); RGB rgb = imageData.palette.getRGB(pixel); boolean hasAlpha = false; int alphaValue = 0;
for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { RGB rgb = imgPixels.palette.getRGB(imgPixels.getPixel(x, y)); if (rgb.red == 255 && rgb.green == 255 && rgb.blue == 255) { inPixels[offset] = (rgb.red << 16) | (rgb.green << 8) new PaletteData(0xff0000, 0xff00, 0xff));
/** * Returns an array of <code>RGB</code>s which comprise the * indexed color table of the receiver, or null if the receiver * has a direct color model. * * @return the RGB values for the image or null if direct color * * @see PaletteData#getRGBs() */ public RGB[] getRGBs() { return palette.getRGBs(); }
private static Image getImage(ResourceManager rm, Color bgColor, Image img) { ImageData imageData = img.getImageData(); imageData.transparentPixel = imageData.palette.getPixel(bgColor .getRGB()); Image image = rm.createImage(createFromImageData(imageData)); img.dispose(); return image; }
/** * Constructs a new direct palette given the red, green and blue masks. * * @param redMask the red mask * @param greenMask the green mask * @param blueMask the blue mask */ public PaletteData(int redMask, int greenMask, int blueMask) { this.redMask = redMask; this.greenMask = greenMask; this.blueMask = blueMask; this.isDirect = true; this.redShift = shiftForMask(redMask); this.greenShift = shiftForMask(greenMask); this.blueShift = shiftForMask(blueMask); }
PaletteData setUpPalette() { if (nComponents == 1) { RGB[] entries = new RGB[256]; for (int i = 0; i < 256; i++) { entries[i] = new RGB(i, i, i); } return new PaletteData(entries); } return new PaletteData(0xFF, 0xFF00, 0xFF0000); } static void skipSegmentFrom(LEDataInputStream byteStream) {
DirectColorModel colorModel = (DirectColorModel) bufferedImage.getColorModel(); PaletteData palette = new PaletteData( colorModel.getRedMask(), colorModel.getGreenMask(), colorModel.getBlueMask() ); ImageData data = new ImageData( bufferedImage.getWidth(), bufferedImage.getHeight(), colorModel.getPixelSize(), palette ); for ( int x = 0; x < data.width; x++ ) { raster.getPixel( x, y, pixelArray ); int pixel = palette.getPixel( new RGB( pixelArray[0], pixelArray[1], pixelArray[2] ) ); data.setPixel( x, y, pixel ); data.setAlpha( x, y, pixelArray[3] ); rgbs[i] = new RGB( reds[i] & 0xFF, greens[i] & 0xFF, blues[i] & 0xFF ); PaletteData palette = new PaletteData( rgbs ); ImageData data = new ImageData( bufferedImage.getWidth(), bufferedImage.getHeight(), colorModel.getPixelSize(), palette );
/** * Set the data of a PLTE chunk to the colors * stored in the specified PaletteData object. */ void setPaletteData(PaletteData palette) { RGB[] rgbs = palette.getRGBs(); for (int i = 0; i < rgbs.length; i++) { int offset = DATA_OFFSET + (i * 3); reference[offset] = (byte) rgbs[i].red; reference[offset + 1] = (byte) rgbs[i].green; reference[offset + 2] = (byte) rgbs[i].blue; } }
/** * Creates and returns a new SWT image with the given size on * the given display which is used as this range indicator's image. * * @param display the display on which to create the image * @param size the image size * @param rangeIndicatorColor the color to be used to paint the range indicator * @return a new image */ private static Image createImage(Display display, Point size, Color rangeIndicatorColor) { int width= size.x; int height= size.y; ImageData imageData= new ImageData(width, height, 1, createPalette(display, rangeIndicatorColor)); for (int y= 0; y < height; y++) for (int x= 0; x < width; x++) imageData.setPixel(x, y, (x + y) % 2); imageData.transparentPixel= imageData.palette.getPixel(imageData.getRGBs()[1]); return new Image(display, imageData); }
/** * Constructs a new direct palette given the red, green and blue masks. * * @param redMask the red mask * @param greenMask the green mask * @param blueMask the blue mask */ public PaletteData(int redMask, int greenMask, int blueMask) { this.redMask = redMask; this.greenMask = greenMask; this.blueMask = blueMask; this.isDirect = true; this.redShift = shiftForMask(redMask); this.greenShift = shiftForMask(greenMask); this.blueShift = shiftForMask(blueMask); }
PaletteData setUpPalette() { if (nComponents == 1) { RGB[] entries = new RGB[256]; for (int i = 0; i < 256; i++) { entries[i] = new RGB(i, i, i); } return new PaletteData(entries); } return new PaletteData(0xFF, 0xFF00, 0xFF0000); } static void skipSegmentFrom(LEDataInputStream byteStream) {
if (bufferedImage.getColorModel() instanceof ComponentColorModel) { ComponentColorModel colorModel = (ComponentColorModel)bufferedImage.getColorModel(); //ASSUMES: 3 BYTE BGR IMAGE TYPE PaletteData palette = new PaletteData(0x0000FF, 0x00FF00,0xFF0000); ImageData data = new ImageData(bufferedImage.getWidth(), bufferedImage.getHeight(), colorModel.getPixelSize(), palette); //This is valid because we are using a 3-byte Data model with no transparent pixels data.transparentPixel = -1; WritableRaster raster = bufferedImage.getRaster(); int[] pixelArray = new int[3]; for (int y = 0; y < data.height; y++) { for (int x = 0; x < data.width; x++) { raster.getPixel(x, y, pixelArray); int pixel = palette.getPixel(new RGB(pixelArray[0], pixelArray[1], pixelArray[2])); data.setPixel(x, y, pixel); } } return data;
/** * Returns an array of <code>RGB</code>s which comprise the * indexed color table of the receiver, or null if the receiver * has a direct color model. * * @return the RGB values for the image or null if direct color * * @see PaletteData#getRGBs() */ public RGB[] getRGBs() { return palette.getRGBs(); }