Java Code Examples for org.eclipse.swt.graphics.ImageData#setPixel()
The following examples show how to use
org.eclipse.swt.graphics.ImageData#setPixel() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SDPrintDialogUI.java From tracecompass with Eclipse Public License 2.0 | 6 votes |
/** * Draws region that was selected * * @param img * The corresponding image * @param r * The selected rectangle. * @param color * The color to use for selection * @return image data reference */ public ImageData drawRegionSelected(Image img, Rectangle r, RGB color) { ImageData id = img.getImageData(); for (int a = 0; a < r.width && r.x + a < id.width; a++) { for (int b = 0; b < r.height && r.y + b < id.height; b++) { int index = id.getPixel(r.x + a, r.y + b); RGB rgb = id.palette.getRGB(index); rgb = combine(color, rgb); id.setPixel(r.x + a, r.y + b, id.palette.getPixel(rgb)); } } return id; }
Example 2
Source File: SetCheckPoint2.java From AndroidRobot with Apache License 2.0 | 6 votes |
public ImageData getImageData(BufferedImage bufferedImage) { 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); 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; }
Example 3
Source File: DeviceSocketClient.java From AndroidRobot with Apache License 2.0 | 6 votes |
private static ImageData getImageData2(BufferedImage bufferedImage){ DirectColorModel colorModel = (DirectColorModel) bufferedImage.getColorModel(); //System.out.println("robot:" +colorModel.getRedMask() + " "+colorModel.getGreenMask() + " "+colorModel.getBlueMask()); PaletteData palette = new PaletteData(colorModel.getRedMask(), colorModel.getGreenMask(), colorModel .getBlueMask()); ImageData data = new ImageData(bufferedImage.getWidth(), bufferedImage.getHeight(), colorModel .getPixelSize(), palette); 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; }
Example 4
Source File: SwtUniversalImage.java From hop with Apache License 2.0 | 5 votes |
/** * 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 ); }
Example 5
Source File: AbstractSortableHeader.java From nebula with Eclipse Public License 2.0 | 5 votes |
private ImageData getUpImageData() { ImageData imageData = getEmptyImageData(); int numTransparentPixels = 0; for (int row = height - 1; row >= 0; --row) { for (int col = numTransparentPixels; col < width / 2; ++col) { imageData.setPixel(col, row, 1); imageData.setPixel(width - col - 1, row, 1); } ++numTransparentPixels; } return imageData; }
Example 6
Source File: AbstractSortableHeader.java From nebula with Eclipse Public License 2.0 | 5 votes |
private ImageData getDownImageData() { ImageData imageData = getEmptyImageData(); int numTransparentPixels = 0; for (int row = 0; row < height; ++row) { for (int col = numTransparentPixels; col < width / 2; ++col) { imageData.setPixel(col, row, 1); imageData.setPixel(width - col - 1, row, 1); } ++numTransparentPixels; } return imageData; }
Example 7
Source File: SharedProjectFileDecorator.java From saros with GNU General Public License v2.0 | 5 votes |
/** Returns null, if the image is not a RGB image with 8 Bit per color value */ private static Image tintImage(Image image, Color color) { ImageData data = image.getImageData(); int red = color.getRed(); int green = color.getGreen(); int blue = color.getBlue(); if (data.depth < 24 || !data.palette.isDirect) return null; int rs = data.palette.redShift; int gs = data.palette.greenShift; int bs = data.palette.blueShift; int rm = data.palette.redMask; int gm = data.palette.greenMask; int bm = data.palette.blueMask; if (rs < 0) rs = ~rs + 1; if (gs < 0) gs = ~gs + 1; if (bs < 0) bs = ~bs + 1; for (int x = 0; x < data.width; x++) { for (int y = 0; y < data.height; y++) { int p = data.getPixel(x, y); int r = (p & rm) >>> rs; int g = (p & gm) >>> gs; int b = (p & bm) >>> bs; r = (r * red) / 255; g = (g * green) / 255; b = (b * blue) / 255; data.setPixel(x, y, (r << rs) | (g << gs) | (b << bs)); } } return new Image(image.getDevice(), data); }
Example 8
Source File: CustomColorPalettePopup.java From bonita-studio with GNU General Public License v2.0 | 5 votes |
/** * @see org.eclipse.jface.resource.ImageDescriptor#getImageData() */ public ImageData getImageData() { ImageData data = new ImageData(ICON_SIZE.x, ICON_SIZE.y, 1, new PaletteData(new RGB[] {rgb, OUTLINE_COLOR})); for (int i = 0; i < ICON_SIZE.y; i++) data.setPixel(0, i, 1); for (int i = 0; i < ICON_SIZE.y; i++) data.setPixel(ICON_SIZE.x - 1, i, 1); for (int i = 0; i < ICON_SIZE.x; i++) data.setPixel(i, 0, 1); for (int i = 0; i < ICON_SIZE.x; i++) data.setPixel(i, ICON_SIZE.y - 1, 1); return data; }
Example 9
Source File: SwtUniversalImage.java From pentaho-kettle with Apache License 2.0 | 5 votes |
/** * 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 ); }
Example 10
Source File: ImageDataLoader.java From gama with GNU General Public License v3.0 | 4 votes |
private static ImageData readPGM(final InputStream filename) { int[][] pixels; try (Scanner infile = new Scanner(filename);) { // process the top 4 header lines final String filetype = infile.nextLine(); if (!filetype.equalsIgnoreCase("p2")) { DEBUG.ERR("Not a PGM"); infile.close(); return null; } // infile.nextLine(); final int cols = infile.nextInt(); final int rows = infile.nextInt(); // skip reading maxValue infile.nextInt(); int maxValue = Integer.MIN_VALUE; pixels = new int[rows][cols]; // process the rest lines that hold the actual pixel values for (int r = 0; r < rows; r++) { for (int c = 0; c < cols; c++) { final int n = infile.nextInt(); if (n > maxValue) { maxValue = n; } pixels[r][c] = n * 255; } } for (int r = 0; r < rows; r++) { for (int c = 0; c < cols; c++) { pixels[r][c] = (int) (pixels[r][c] / (double) maxValue); } } } catch (final Exception e) { DEBUG.ERR(e.toString()); return null; } int g; final PaletteData palette = new PaletteData(16711680, 65280, 255); final ImageData data = new ImageData(pixels[0].length, pixels.length, 24, palette); for (int row = 0; row < pixels.length; ++row) { for (int col = 0; col < pixels[row].length; ++col) { g = pixels[row][col]; data.setPixel(col, row, g << 16 | g << 8 | g); } } final ImageData result = data; result.type = IMAGE_PGM; return result; }
Example 11
Source File: ImageDataLoader.java From gama with GNU General Public License v3.0 | 4 votes |
private static ImageData readASC(final InputStream filename) { int[][] pixels; try (Scanner infile = new Scanner(filename);) { // Not a ASC file if (!infile.hasNext("ncols")) { DEBUG.ERR("Not an ASC"); infile.close(); return null; } infile.useLocale(Locale.US); int cols = 0; int rows = 0; double nodata = 0d; // process the top 6 or 5 header lines // ncols infile.next(); cols = infile.nextInt(); // nrows infile.next(); rows = infile.nextInt(); infile.nextLine(); // xllcorner infile.nextLine(); // yllcorner infile.nextLine(); // cellsize String cellsize = infile.nextLine(); if (cellsize.startsWith("dx") || cellsize.startsWith("dy")) infile.nextLine(); // NODATA_value if (infile.hasNext("NODATA_value")) { infile.next(); nodata = infile.nextDouble(); } int maxValue = 0; int minValue = Integer.MAX_VALUE; pixels = new int[rows][cols]; // process the rest lines that hold the actual pixel values for (int r = 0; r < rows; r++) { for (int c = 0; c < cols; c++) { double d = infile.nextDouble(); if (d == nodata) { d = 0d; } if (d > maxValue) { maxValue = (int) d; } else if (d < minValue) { minValue = (int) d; } pixels[r][c] = (int) d; } } final int range = maxValue - minValue; double ratio = 1d; if (range < 255) { ratio = 255d / range; } else { ratio = range / 255d; } for (int r = 0; r < rows; r++) { for (int c = 0; c < cols; c++) { pixels[r][c] = (int) ((pixels[r][c] - minValue) * ratio); } } } catch (final Exception e) { DEBUG.ERR(e.toString()); return null; } int g; final PaletteData palette = new PaletteData(16711680, 65280, 255); final ImageData data = new ImageData(pixels[0].length, pixels.length, 24, palette); for (int row = 0; row < pixels.length; ++row) { for (int col = 0; col < pixels[row].length; ++col) { g = pixels[row][col]; data.setPixel(col, row, g << 16 | g << 8 | g); } } final ImageData result = data; result.type = IMAGE_ASC; return result; }
Example 12
Source File: InsertedImageEditPart.java From erflute with Apache License 2.0 | 4 votes |
private void changeImage() { final InsertedImage model = (InsertedImage) getModel(); final ImageData newImageData = new ImageData(imageData.width, imageData.height, imageData.depth, imageData.palette); for (int x = 0; x < imageData.width; x++) { for (int y = 0; y < imageData.height; y++) { final RGB rgb = imageData.palette.getRGB(imageData.getPixel(x, y)); final float[] hsb = rgb.getHSB(); if (model.getHue() != 0) { hsb[0] = model.getHue() & 360; } hsb[1] = hsb[1] + (model.getSaturation() / 100f); if (hsb[1] > 1.0f) { hsb[1] = 1.0f; } else if (hsb[1] < 0) { hsb[1] = 0f; } hsb[2] = hsb[2] + (model.getBrightness() / 100f); if (hsb[2] > 1.0f) { hsb[2] = 1.0f; } else if (hsb[2] < 0) { hsb[2] = 0f; } final RGB newRGB = new RGB(hsb[0], hsb[1], hsb[2]); final int pixel = imageData.palette.getPixel(newRGB); newImageData.setPixel(x, y, pixel); } } if (image != null && !image.isDisposed()) { image.dispose(); } this.image = new Image(Display.getDefault(), newImageData); }
Example 13
Source File: ImageLabel.java From birt with Eclipse Public License 1.0 | 4 votes |
void onPaint( PaintEvent event ) { Rectangle rect = getClientArea( ); if ( rect.width == 0 || rect.height == 0 ) return; Image img = image; Point extent = getTotalSize( img ); GC gc = event.gc; // determine horizontal position int x = rect.x + hIndent; if ( align == SWT.CENTER ) { x = ( rect.width - extent.x ) / 2; } if ( align == SWT.RIGHT ) { x = rect.width - extent.x - hIndent; } if ( this.backgroundColor != null ) { Color oldBackground = gc.getBackground( ); gc.setBackground( backgroundColor ); gc.fillRectangle( 0, 0, rect.width, rect.height ); gc.setBackground( oldBackground ); } else { if ( ( getStyle( ) & SWT.NO_BACKGROUND ) != 0 ) { gc.setBackground( getBackground( ) ); gc.fillRectangle( rect ); } } // draw border int style = getStyle( ); if ( ( style & SWT.SHADOW_IN ) != 0 || ( style & SWT.SHADOW_OUT ) != 0 ) { paintBorder( gc, rect ); } // draw the image if ( img != null ) { Rectangle imageRect = img.getBounds( ); if ( this.isFocusControl( ) ) { ImageData data = img.getImageData( ); PaletteData palette = new PaletteData( new RGB[]{ this.getDisplay( ) .getSystemColor( SWT.COLOR_WHITE ) .getRGB( ), this.getDisplay( ) .getSystemColor( SWT.COLOR_LIST_SELECTION ) .getRGB( ), } ); ImageData sourceData = new ImageData( data.width, data.height, 1, palette ); for ( int i = 0; i < data.width; i++ ) { for ( int j = 0; j < data.height; j++ ) { if ( data.getPixel( i, j ) != data.transparentPixel ) sourceData.setPixel( i, j, 1 ); } } Image highlightImage = new Image( this.getDisplay( ), sourceData ); gc.drawImage( highlightImage, 0, 0, imageRect.width, imageRect.height, x, ( rect.height - imageRect.height ) / 2, rect.width - 10, imageRect.height ); highlightImage.dispose( ); } else gc.drawImage( img, 0, 0, imageRect.width, imageRect.height, x, ( rect.height - imageRect.height ) / 2, rect.width - 10, imageRect.height ); x += imageRect.width; } }
Example 14
Source File: InsertedImageEditPart.java From ermaster-b with Apache License 2.0 | 4 votes |
private void changeImage() { InsertedImage model = (InsertedImage) this.getModel(); ImageData newImageData = new ImageData(this.imageData.width, this.imageData.height, this.imageData.depth, this.imageData.palette); for (int x = 0; x < this.imageData.width; x++) { for (int y = 0; y < this.imageData.height; y++) { RGB rgb = this.imageData.palette.getRGB(this.imageData .getPixel(x, y)); float[] hsb = rgb.getHSB(); if (model.getHue() != 0) { hsb[0] = model.getHue() & 360; } hsb[1] = hsb[1] + (model.getSaturation() / 100f); if (hsb[1] > 1.0f) { hsb[1] = 1.0f; } else if (hsb[1] < 0) { hsb[1] = 0f; } hsb[2] = hsb[2] + (model.getBrightness() / 100f); if (hsb[2] > 1.0f) { hsb[2] = 1.0f; } else if (hsb[2] < 0) { hsb[2] = 0f; } RGB newRGB = new RGB(hsb[0], hsb[1], hsb[2]); int pixel = imageData.palette.getPixel(newRGB); newImageData.setPixel(x, y, pixel); } } if (this.image != null && !this.image.isDisposed()) { this.image.dispose(); } this.image = new Image(Display.getDefault(), newImageData); }