Java Code Examples for org.eclipse.swt.graphics.ImageData#getPixel()

The following examples show how to use org.eclipse.swt.graphics.ImageData#getPixel() . 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 vote down vote up
/**
 * 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: GamaColors.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Get the color of the icon passed in parameter (supposing it's mono-colored)
 *
 * @param create
 * @return
 */
public static GamaUIColor get(final GamaIcon icon) {
	final Image image = icon.image();
	final ImageData data = image.getImageData();
	final PaletteData palette = data.palette;
	final int pixelValue = data.getPixel(0, 0);
	return get(palette.getRGB(pixelValue));
}
 
Example 3
Source File: SharedProjectFileDecorator.java    From saros with GNU General Public License v2.0 5 votes vote down vote up
/** 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 4
Source File: ImageLabel.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
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;
	}
}