Java Code Examples for org.eclipse.swt.graphics.ImageData

The following are top voted examples for showing how to use org.eclipse.swt.graphics.ImageData. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: n4js   File: N4JSDecoratorRow.java   View source code 6 votes vote down vote up
@Override
protected void drawCompositeImage(int ignoredWidth, int ignoredHeight) {
	// base image, possibly shifted to accommodate decorators
	drawImage(getMainData(), shiftFromLeft(), shiftFromTop());
	// row of decorators
	int x = marginFromLeft();
	final int y = marginFromTop();
	for (ImageData decoData : getDecosData()) {
		drawImage(decoData, x, y);
		x += decoData.width;
	}
}
 
Example 2
Project: neoscada   File: URLImageLabel.java   View source code 6 votes vote down vote up
private void processLoad ( final String stringUrl ) throws Exception
{
    final ImageLoader loader = new ImageLoader ();

    final URL url = new URL ( stringUrl );

    final ImageData[] data;
    try ( InputStream is = url.openStream () )
    {
        data = loader.load ( is );
    }

    logger.debug ( "Image loaded" );

    Display.getDefault ().asyncExec ( new Runnable () {
        @Override
        public void run ()
        {
            showImage ( stringUrl, data );
        }
    } );
}
 
Example 3
Project: convertigo-eclipse   File: ViewLabelDecorator.java   View source code 6 votes vote down vote up
protected void drawCompositeImage(int width, int height) {

			drawImage(mBase.getImageData(), 0, 0);
			
			ImageData imageData = mOverlay.getImageData();
			switch (mCorner) {
				case TOP_LEFT :
					drawImage(imageData, 0, 0);
					break;
				case TOP_RIGHT :
					drawImage(imageData, mBase.getBounds().width - imageData.width, 0);
					break;
				case BOTTOM_LEFT :
					drawImage(imageData, 0, mBase.getBounds().height - imageData.height);
					break;
				case BOTTOM_RIGHT :
					drawImage(imageData, mBase.getBounds().width - imageData.width, mBase.getBounds().height - imageData.height);
					break;
			}
		}
 
Example 4
Project: convertigo-eclipse   File: SchemaViewLabelDecorator.java   View source code 6 votes vote down vote up
protected void drawCompositeImage(int width, int height) {

			drawImage(mBase.getImageData(), 0, 0);
			
			ImageData imageData = mOverlay.getImageData();
			switch (mCorner) {
				case TOP_LEFT :
					drawImage(imageData, 0, 0);
					break;
				case TOP_RIGHT :
					drawImage(imageData, mBase.getBounds().width - imageData.width, 0);
					break;
				case BOTTOM_LEFT :
					drawImage(imageData, 0, mBase.getBounds().height - imageData.height);
					break;
				case BOTTOM_RIGHT :
					drawImage(imageData, mBase.getBounds().width - imageData.width, mBase.getBounds().height - imageData.height);
					break;
			}
		}
 
Example 5
Project: convertigo-eclipse   File: SWTX.java   View source code 6 votes vote down vote up
public static void drawShadowImage(GC gc, Image image, int x, int y,
    int alpha) {
  Display display = Display.getCurrent();
  Point imageSize = new Point(image.getBounds().width,
      image.getBounds().height);
  //
  ImageData imgData = new ImageData(imageSize.x, imageSize.y, 24,
      new PaletteData(255, 255, 255));
  imgData.alpha = alpha;
  Image img = new Image(display, imgData);
  GC imgGC = new GC(img);
  imgGC.drawImage(image, 0, 0);
  gc.drawImage(img, x, y);
  imgGC.dispose();
  img.dispose();
}
 
Example 6
Project: AppleCommander   File: SwtImage.java   View source code 6 votes vote down vote up
/**
 * Save the image.
 */
public void save(OutputStream outputStream) throws IOException {
	ImageLoader imageLoader = new ImageLoader();
	imageLoader.data = new ImageData[] { imageData };
	int format = SWT.IMAGE_PNG;
	if ("BMP".equals(getFileExtension())) { //$NON-NLS-1$
		format = SWT.IMAGE_BMP;
	} else if ("RLE".equals(getFileExtension())) { //$NON-NLS-1$
		format = SWT.IMAGE_BMP_RLE;
	} else if ("GIF".equals(getFileExtension())) { //$NON-NLS-1$
		format = SWT.IMAGE_GIF;
	} else if ("ICO".equals(getFileExtension())) { //$NON-NLS-1$
		format = SWT.IMAGE_ICO;
	} else if ("JPEG".equals(getFileExtension())) { //$NON-NLS-1$
		format = SWT.IMAGE_JPEG;
	} else if ("PNG".equals(getFileExtension())) { //$NON-NLS-1$
		format = SWT.IMAGE_PNG;
	}
	imageLoader.save(outputStream, format);
}
 
Example 7
Project: applecommander   File: SwtImage.java   View source code 6 votes vote down vote up
/**
 * Save the image.
 */
public void save(OutputStream outputStream) throws IOException {
	ImageLoader imageLoader = new ImageLoader();
	imageLoader.data = new ImageData[] { imageData };
	int format = SWT.IMAGE_PNG;
	if ("BMP".equals(getFileExtension())) { //$NON-NLS-1$
		format = SWT.IMAGE_BMP;
	} else if ("RLE".equals(getFileExtension())) { //$NON-NLS-1$
		format = SWT.IMAGE_BMP_RLE;
	} else if ("GIF".equals(getFileExtension())) { //$NON-NLS-1$
		format = SWT.IMAGE_GIF;
	} else if ("ICO".equals(getFileExtension())) { //$NON-NLS-1$
		format = SWT.IMAGE_ICO;
	} else if ("JPEG".equals(getFileExtension())) { //$NON-NLS-1$
		format = SWT.IMAGE_JPEG;
	} else if ("PNG".equals(getFileExtension())) { //$NON-NLS-1$
		format = SWT.IMAGE_PNG;
	}
	imageLoader.save(outputStream, format);
}
 
Example 8
Project: pdi   File: Interface.java   View source code 6 votes vote down vote up
private RGB encontraPixel(int x, int y, int indice) {

        labelPosicaoCor.setText(x + "," + y);

        ImageData imageData = null;
        PaletteData paletteData = null;

        if (indice == 1 && imagem1 != null) {
            imageData = imagem1.getImageData();
            paletteData = imageData.palette;
        } else if (indice == 2 && imagem2 != null) {
            imageData = imagem2.getImageData();
            paletteData = imageData.palette;
        } else if (indice == 3 && imagem3 != null) {
            imageData = imagem3.getImageData();
            paletteData = imageData.palette;
        }

        if (paletteData != null && x > -1 && y > -1) {
            int pixel = imageData.getPixel(x, y);
            RGB rgb = paletteData.getRGB(pixel);
            return rgb;
        }

        return null;
    }
 
Example 9
Project: pandionj   File: ColorImageWidget.java   View source code 6 votes vote down vote up
protected ImageData getImageData() {
	int[][] a = (int[][]) array;
	ImageData data = new ImageData(width, height, 24, palette);
	for(int y = 0; y < height; y++) {
		for(int x = 0; x < width; x++) {
			int v = a[y][x];
			int r = (v >> 16) & 0xFF;
			int g = (v >> 8) & 0xFF;
			int b = v & 0xFF;

			int pixel = 0;
			if(valid(r, g, b)) {
				pixel |= (redShift < 0 ? r << -redShift : r >>> redShift) & redMask;
				pixel |= (greenShift < 0 ? g << -greenShift : g >>> greenShift) & greenMask;
				pixel |= (blueShift < 0 ? b << -blueShift : b >>> blueShift) & blueMask;
			}
			//					int pixel = valid(r,g,b) ? palette.getPixel(new RGB(r,g,b)) : palette.getPixel(new RGB(255, 0, 0));
			data.setPixel(x, y, pixel);
		}
	}
	return data;
}
 
Example 10
Project: code   File: AbstractOverlayIcon.java   View source code 6 votes vote down vote up
protected void drawCompositeImage(int width, int height) {
	ImageData base = getBaseImageData();
	drawImage(base, 0, 0);
	if (fOverlays != null) {
		if (fOverlays.length > 0) {
			drawTopRight(fOverlays[0]);
		}

		if (fOverlays.length > 1) {
			drawBottomRight(fOverlays[1]);
		}

		if (fOverlays.length > 2) {
			drawBottomLeft(fOverlays[2]);
		}

		if (fOverlays.length > 3) {
			drawTopLeft(fOverlays[3]);
		}
	}
}
 
Example 11
Project: PhET   File: SWTBenchTest.java   View source code 6 votes vote down vote up
private static Image loadImage(final Display display, final String name) {
    InputStream stream = null;
    try {
        stream = SWTBenchTest.class.getResourceAsStream(name);
        if (stream != null) {
            final ImageData imageData = new ImageData(stream);
            return new Image(display, imageData);
            // if (imageData != null) {
            // ImageData mask = imageData.getTransparencyMask();
            // return new Image(display, imageData, mask);
            // }

        }
    }
    catch (final Exception e) {
        throw new RuntimeException(e);
    }
    return null;
}
 
Example 12
Project: workspacemechanic   File: MechanicPopupTest.java   View source code 6 votes vote down vote up
public File copyWidgetToFile(Control control) throws IOException {
  File file = File.createTempFile("MechanicalPopupTest", "jpg");
  file.deleteOnExit();
  Point size = control.getSize();
  GC gc = new GC(control);
  Image image = null;
  try {
    image = new Image(control.getDisplay(), size.x, size.y);
    gc.copyArea(image, 0, 0);
    ImageLoader loader = new ImageLoader();
    loader.data = new ImageData[] {image.getImageData()};
    loader.save(file.getPath(), SWT.IMAGE_JPEG);
  } finally {
    gc.dispose();
    if (image != null) {
      image.dispose();
    }
  }
  return file;
}
 
Example 13
Project: TuxGuitar-1.3.1-fork   File: ImageWriter.java   View source code 6 votes vote down vote up
public static void write(ImageFormat format, String path, List<ImageData> pages) throws TGFileFormatException {
	try {
		for(int i = 0; i < pages.size() ; i ++ ) {
			OutputStream stream = new FileOutputStream(new File(path + File.separator + "page-" + i + format.getExtension() ));
			
			ImageLoader loader = new ImageLoader();
			loader.data = new ImageData[] { (ImageData)pages.get(i) };
			loader.save(stream, format.getFormat() );
			
			stream.flush();
			stream.close();
		}
	} catch (Throwable throwable) {
		throw new TGFileFormatException("Could not write song!.",throwable);
	}
}
 
Example 14
Project: TuxGuitar-1.3.1-fork   File: TGImageImpl.java   View source code 6 votes vote down vote up
public void applyTransparency( TGColor background ){
	RGB alpha = new RGB( background.getRed(), background.getGreen(), background.getBlue() );
	RGB none = new RGB((0xff ^ alpha.red),(0xff ^ alpha.green),(0xff ^ alpha.blue));
	
	Image srcImage = this.handle;
	ImageData srcData = srcImage.getImageData();
	ImageData maskData = new ImageData(srcData.width,srcData.height,1,new PaletteData(new RGB[]{ none,alpha }  ));
	for(int x = 0; x< maskData.width; x++) {
		for(int y = 0; y < maskData.height; y++) {
			RGB rgb = srcData.palette.getRGB(srcData.getPixel(x, y));
			if(rgb.red == alpha.red && rgb.green == alpha.green && rgb.blue == alpha.blue){
				maskData.setPixel(x, y, maskData.palette.getPixel(none));
			}else{
				maskData.setPixel(x, y, maskData.palette.getPixel(alpha));
			}
		}
	}
	this.handle = new Image(srcImage.getDevice(),srcData,maskData);
	
	srcImage.dispose();
}
 
Example 15
Project: ermasterr   File: InsertedImageEditPart.java   View source code 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected IFigure createFigure() {
    final InsertedImage model = (InsertedImage) getModel();

    final byte[] data = Base64.decodeBase64((model.getBase64EncodedData().getBytes()));
    final ByteArrayInputStream in = new ByteArrayInputStream(data);

    imageData = new ImageData(in);
    changeImage();

    final InsertedImageFigure figure = new InsertedImageFigure(image, model.isFixAspectRatio(), model.getAlpha());
    figure.setMinimumSize(new Dimension(1, 1));

    return figure;
}
 
Example 16
Project: xstreamer   File: ImageViewSaveAsHandler.java   View source code 6 votes vote down vote up
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
	IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
	ImageView imageView = (ImageView) activePart;
	SWTImageCanvas imageCanvas = imageView.imageCanvas;
	if (imageCanvas == null) {
		return null;
	}

	Shell shell = HandlerUtil.getActiveShell(event);

	FileDialog dialog = new FileDialog(shell, SWT.SAVE);
	dialog.setFilterExtensions(new String[] { "*.png", "*.*" });
	dialog.setFilterNames(new String[] { "PNG Files", "All Files" });
	String fileSelected = dialog.open();

	if (fileSelected != null) {
		ImageLoader imageLoader = new ImageLoader();
		imageLoader.data = new ImageData[] { imageCanvas.getImageData() };

		System.out.println("Selected file: " + fileSelected);
		imageLoader.save(fileSelected, SWT.IMAGE_PNG);
	}

	return null;
}
 
Example 17
Project: xstreamer   File: AbstractImageSelectionListener.java   View source code 6 votes vote down vote up
protected void saveImage(String filename, ImageView imageView, int imageType) {
	IPreferenceStore store = us.nineworlds.xstreamer.Activator.getDefault().getPreferenceStore();
	String outputDirectory = store.getString(PreferenceConstants.TEMPLATE_XSTREAMER_XWING_OUTPUT_DIRECTORY);
	if (outputDirectory == null || imageView == null) {
		return;
	}

	ImageLoader imageLoader = new ImageLoader();
	imageLoader.data = new ImageData[] { imageView.imageCanvas.getImageData() };
	FileOutputStream outputStream = null;
	try {
		outputStream = new FileOutputStream(new File(outputDirectory, filename));
		imageLoader.save(outputStream, imageType);
	} catch (FileNotFoundException e) {
		Logger.error("Unable to save image to file: " + filename, e);
	} finally {
		IOUtils.closeQuietly(outputStream);
	}
}
 
Example 18
Project: xstreamer   File: SquadSelectionChangeListener.java   View source code 6 votes vote down vote up
private void saveImage(String filename, ImageView imageView) {
	IPreferenceStore store = us.nineworlds.xstreamer.Activator.getDefault().getPreferenceStore();
	String outputDirectory = store.getString(us.nineworlds.xstreamer.preferences.PreferenceConstants.TEMPLATE_XSTREAMER_XWING_OUTPUT_DIRECTORY);
	if (outputDirectory == null || imageView == null) {
		return;
	}
	ImageLoader imageLoader = new ImageLoader();
	imageLoader.data = new ImageData[] { imageView.imageCanvas.getImageData() };		
	FileOutputStream outputStream = null;
	try {
		outputStream = new FileOutputStream(new File(outputDirectory, filename));
		imageLoader.save(outputStream, SWT.IMAGE_PNG);
	} catch (IOException e) {
		Logger.error("Unable to save image to file: " + filename, e);
	} finally {
		IOUtils.closeQuietly(outputStream);
	}
}
 
Example 19
Project: xstreamer   File: AbstractImageSelectionListener.java   View source code 6 votes vote down vote up
protected void saveImage(String filename, ImageView imageView, int imageType) {
	IPreferenceStore store = us.nineworlds.xstreamer.ia.Activator.getDefault().getPreferenceStore();
	String outputDirectory = store.getString(PreferenceConstants.TEMPLATE_XSTREAMER_IA_OUTPUT_DIRECTORY);
	if (outputDirectory == null || imageView == null) {
		return;
	}

	ImageLoader imageLoader = new ImageLoader();
	imageLoader.data = new ImageData[] { imageView.imageCanvas.getImageData() };
	FileOutputStream outputStream = null;
	try {
		outputStream = new FileOutputStream(new File(outputDirectory, filename));
		imageLoader.save(outputStream, imageType);
	} catch (FileNotFoundException e) {
		Logger.error("Unable to save image to file: " + filename, e);
	} finally {
		IOUtils.closeQuietly(outputStream);
	}
}
 
Example 20
Project: TranskribusSwtGui   File: CanvasImage.java   View source code 6 votes vote down vote up
public void applyGamma(double gamma) {
		if (SWTUtil.isDisposed(img) /*|| SWTUtil.isDisposed(imgBackup)*/) {
			return;
		}
		
		if (true) { 
			logger.debug("this.gamma = "+this.gamma);	
			double scaledGamma = gamma / this.gamma;
			logger.debug("scaledGamma = "+scaledGamma);
			ImageData d = SWTUtil.multScalar(img.getImageData(), scaledGamma, true);
			
			logger.debug("disposing old image and creating new one with scaled image data...");
			img.dispose();
			img = new Image(Display.getDefault(), d);
		}
//		else {
//			logger.debug("gamma = "+gamma);
//			ImageData d = SWTUtil.multScalar(imgBackup.getImageData(), gamma, false);
//			SWTUtil.dispose(img);
//			img = new Image(Display.getDefault(), d);
//		}
		
		this.gamma = gamma;
	}
 
Example 21
Project: TranskribusSwtGui   File: SWTUtil.java   View source code 6 votes vote down vote up
public static ImageData convertToSWT2(BufferedImage bufferedImage) throws IOException {
//		/2) awt.BufferedImage -> raw Data
		java.awt.image.WritableRaster awtRaster = bufferedImage.getRaster();
		java.awt.image.DataBufferByte awtData = (DataBufferByte) awtRaster.getDataBuffer();
		byte[] rawData = awtData.getData();

		//3) raw Data -> swt.ImageData
		org.eclipse.swt.graphics.PaletteData swtPalette = new PaletteData(0xff, 0xff00, 0xff0000);

		int depth = 0x18;
		org.eclipse.swt.graphics.ImageData swtImageData = new ImageData(bufferedImage.getWidth(), bufferedImage.getHeight(), 
				depth, swtPalette, bufferedImage.getWidth(), rawData);
		
		return swtImageData;
//		return new Image(Display.getDefault(), swtImageData);		
	}
 
Example 22
Project: mesfavoris   File: IconImageDescriptor.java   View source code 6 votes vote down vote up
private ImageData loadImageData() {
	ImageData[] imageDatas;
	try {
		imageDatas = new ImageLoader().load(new ByteArrayInputStream(favIconBytes));
	} catch (SWTException e) {
		return null;
	}
	Optional<ImageData> optionalImageData = Arrays.stream(imageDatas).sorted((imageData1,
			imageData2) -> distanceFrom16x16ImageData(imageData1) - distanceFrom16x16ImageData(imageData2))
			.findFirst();
	if (!optionalImageData.isPresent()) {
		return null;
	}
	ImageData imageData = optionalImageData.get();
	if (imageData.width <= 16 && imageData.height <= 16) {
		return imageData;
	}
	return imageData.scaledTo(16, 16);
}
 
Example 23
Project: mesfavoris   File: ImageAssert.java   View source code 6 votes vote down vote up
public static void assertImageDataIs(ImageData expectedImageData,
		ImageData actualImageData) {
	if (expectedImageData.width != actualImageData.width
			|| expectedImageData.height != actualImageData.height) {
		fail(MessageFormat
				.format(
						"Image data do not have the same dimensions ({0}x{1} expected, got {2}x{3})",
						expectedImageData.width, expectedImageData.height,
						actualImageData.width, actualImageData.height));
	}

	for (int y = 0; y < expectedImageData.height; y++) {
		for (int x = 0; x < expectedImageData.width; x++) {
			int actualPixel = actualImageData.getPixel(x, y);
			int expectedPixel = expectedImageData.getPixel(x, y);
			RGB actualRGB = actualImageData.palette.getRGB(actualPixel);
			RGB expectedRGB = expectedImageData.palette
					.getRGB(expectedPixel);
			if (!actualRGB.equals(expectedRGB)) {
				fail(MessageFormat.format(
						"Image data do not match at ({0},{1})", x, y));
			}
		}
	}
}
 
Example 24
Project: ermaster-k   File: ImageUtils.java   View source code 6 votes vote down vote up
public static void drawAtBufferedImage(BufferedImage bimg, Image image,
		int x, int y) throws InterruptedException {

	ImageData data = image.getImageData();

	for (int i = 0; i < image.getBounds().width; i++) {

		for (int j = 0; j < image.getBounds().height; j++) {
			int tmp = 4 * (j * image.getBounds().width + i);

			if (data.data.length > tmp + 2) {
				int r = 0xff & data.data[tmp + 2];
				int g = 0xff & data.data[tmp + 1];
				int b = 0xff & data.data[tmp];

				bimg.setRGB(i + x, j + y, 0xFF << 24 | r << 16 | g << 8
						| b << 0);
			}
		}
	}
}
 
Example 25
Project: ermaster-k   File: ChangeBackgroundColorAction.java   View source code 6 votes vote down vote up
private void setColorToImage() {
	ImageData imageData = ERDiagramActivator.getImageDescriptor(
			ImageKey.CHANGE_BACKGROUND_COLOR).getImageData();
	int blackPixel = imageData.palette.getPixel(new RGB(0, 0, 0));
	imageData.transparentPixel = imageData.palette.getPixel(new RGB(255,
			255, 255));
	imageData.palette.colors[blackPixel] = this.rgb;

	// if (this.image != null) {
	// this.image.dispose();
	// }
	this.image = new Image(Display.getCurrent(), imageData);

	ImageDescriptor descriptor = ImageDescriptor.createFromImage(image);
	this.setImageDescriptor(descriptor);
}
 
Example 26
Project: code   File: AbstractOverlayIcon.java   View source code 6 votes vote down vote up
protected void drawCompositeImage(int width, int height) {
	ImageData base = getBaseImageData();
	drawImage(base, 0, 0);
	if (fOverlays != null) {
		if (fOverlays.length > 0) {
			drawTopRight(fOverlays[0]);
		}

		if (fOverlays.length > 1) {
			drawBottomRight(fOverlays[1]);
		}

		if (fOverlays.length > 2) {
			drawBottomLeft(fOverlays[2]);
		}

		if (fOverlays.length > 3) {
			drawTopLeft(fOverlays[3]);
		}
	}
}
 
Example 27
Project: code   File: AbstractOverlayIcon.java   View source code 6 votes vote down vote up
protected void drawCompositeImage(int width, int height) {
	ImageData base = getBaseImageData();
	drawImage(base, 0, 0);
	if (fOverlays != null) {
		if (fOverlays.length > 0) {
			drawTopRight(fOverlays[0]);
		}

		if (fOverlays.length > 1) {
			drawBottomRight(fOverlays[1]);
		}

		if (fOverlays.length > 2) {
			drawBottomLeft(fOverlays[2]);
		}

		if (fOverlays.length > 3) {
			drawTopLeft(fOverlays[3]);
		}
	}
}
 
Example 28
Project: ether   File: GIFAccess.java   View source code 6 votes vote down vote up
public GIFAccess(URLVideoSource src, int numPlays) throws IOException, URISyntaxException {
	super(src, numPlays);
	ImageLoader loader = new ImageLoader();
	ImageData[] images = loader.load(src.getURL().openStream());
	for(int i = 0; i < images.length; i++) {
		width  = Math.max(width,  images[i].x + images[i].width); 
		height = Math.max(height, images[i].y + images[i].height); 
	}
	nClips = images[0].delayTime - 10;
	if (nClips > 0 && images.length > (nClips * 2 + 1))
		shotStarts = new int[nClips];
	else
		nClips = 1;
	for(int i = 0; i < images.length; i++)
		frames.add(convert(i, i == 0 ? null : frames.get(i-1), images[i]));
	if(shotStarts != null) {
		duration /= nClips * 1000.0;
		duration *= images.length;
	}
	if(shotStarts != null)
		for(int i = 1; i < shotStarts.length; i++)
			shotStarts[i] += shotStarts[i-1];
}
 
Example 29
Project: ether   File: GIFAccess.java   View source code 6 votes vote down vote up
private IHostImage convert(int idx, IHostImage previous, ImageData imageData) {
	if(shotStarts != null) {
		int clip = (idx - 1) / 2;
		if(clip >= 0 && clip < nClips) {
			if(((idx - 1) & 1) == 0) 
				shotStarts[clip] = imageData.delayTime;
			else
				duration += imageData.delayTime;
		}
	} else
		duration += imageData.delayTime / 1000.0;
	IHostImage result = previous == null ? IHostImage.create(width, height, ComponentType.BYTE, ComponentFormat.RGB) : previous.copy();
	for(int y = imageData.height; --y >= 0;)
		for(int x = imageData.width; --x >= 0;) {
			int pixel = imageData.getPixel(x, y);
			if(pixel == imageData.transparentPixel) continue;
			RGB srcrgb = imageData.palette.getRGB(pixel);
			rgb[0] = (byte) srcrgb.red;
			rgb[1] = (byte) srcrgb.green;
			rgb[2] = (byte) srcrgb.blue;
			result.setPixel(x+imageData.x, height-(y+imageData.y+1), rgb);
		}
	return result;
}
 
Example 30
Project: ether   File: Bouncelet.java   View source code 6 votes vote down vote up
public Image getControllerImage(Display display) {
	if(ctrlImage == null) {
		ImageData img = new ImageData(48, 48, 32, RGB_PALETTE);
		for(int y = 0; y < 40; y++)
			for(int x = 0; x < 48; x++) {
				int col = x / 6;
				int row = y / 5;
				int id  = (row * 8) + col; 
				if(x % 6 < 5 && y % 5 < 4) {
					img.setAlpha(x, y+4, 255);
					if(id == this.id)	img.setPixel(x, y+4, color.toARGB32());
					else				img.setPixel(x, y+4, 0x444444);
				} else img.setAlpha(x, y+4, 0);
			}
		ctrlImage = new Image(display, img);
	}
	return ctrlImage;
}
 
Example 31
Project: Sensors   File: SWTResourceManager.java   View source code 5 votes vote down vote up
/**
 * Returns an {@link Image} encoded by the specified {@link InputStream}.
 * 
 * @param stream
 *            the {@link InputStream} encoding the image data
 * @return the {@link Image} encoded by the specified input stream
 */
protected static Image getImage(InputStream stream) throws IOException {
	try {
		Display display = Display.getCurrent();
		ImageData data = new ImageData(stream);
		if (data.transparentPixel > 0) {
			return new Image(display, data, data.getTransparencyMask());
		}
		return new Image(display, data);
	} finally {
		stream.close();
	}
}
 
Example 32
Project: n4js   File: N4JSDecoratorRow.java   View source code 5 votes vote down vote up
/**
 * This method initializes a field on demand, given that each invocation of the delegate allocates anew.
 */
private ImageData getMainData() {
	if (null == mainData) {
		mainData = main.getImageData();
	}
	return mainData;
}
 
Example 33
Project: n4js   File: N4JSDecoratorRow.java   View source code 5 votes vote down vote up
/**
 * This method initializes a field on demand, given that each invocation of the delegate allocates anew.
 */
private ImageData[] getDecosData() {
	if (null == decosData) {
		decosData = new ImageData[decos.length];
		for (int i = 0; i < decosData.length; i++) {
			decosData[i] = decos[i].getImageData();
		}
	}
	return decosData;
}
 
Example 34
Project: n4js   File: N4JSDecoratorRow.java   View source code 5 votes vote down vote up
/**
 * @return Summation over the width of each decorator.
 */
private int getDecosWidth() {
	int result = 0;
	for (ImageData dd : getDecosData()) {
		result += dd.width;
	}
	return result;
}
 
Example 35
Project: n4js   File: N4JSDecoratorRow.java   View source code 5 votes vote down vote up
/**
 * @return The maximum height over all decorators.
 */
private int getDecosHeight() {
	int result = 0;
	for (ImageData dd : getDecosData()) {
		result = Math.max(result, dd.height);
	}
	return result;
}
 
Example 36
Project: AgentWorkbench   File: SWTResourceManager.java   View source code 5 votes vote down vote up
/**
 * Returns an {@link Image} encoded by the specified {@link InputStream}.
 * 
 * @param stream
 *            the {@link InputStream} encoding the image data
 * @return the {@link Image} encoded by the specified input stream
 */
protected static Image getImage(InputStream stream) throws IOException {
	try {
		Display display = Display.getCurrent();
		ImageData data = new ImageData(stream);
		if (data.transparentPixel > 0) {
			return new Image(display, data, data.getTransparencyMask());
		}
		return new Image(display, data);
	} finally {
		stream.close();
	}
}
 
Example 37
Project: neoscada   File: URLImageLabel.java   View source code 5 votes vote down vote up
protected void showImage ( final String url, final ImageData[] data )
{
    if ( isDisposed () || getDisplay ().isDisposed () )
    {
        return;
    }

    if ( data == null || data.length <= 0 )
    {
        logger.info ( "No image data" );
        return;
    }

    synchronized ( this )
    {
        if ( url.equals ( this.currentUrl ) )
        {
            if ( this.currentImage != null )
            {
                this.currentImage.dispose ();
            }
            this.currentImage = new Image ( getDisplay (), data[0] );
            this.label.setImage ( this.currentImage );
        }
        else
        {
            logger.warn ( "Image url changed - current: {}, our: {}", this.currentUrl, url );
        }
    }
}
 
Example 38
Project: avoCADo   File: ImageUtils.java   View source code 5 votes vote down vote up
public static Image getIcon(String filename, int width, int height){
	int ICON_WIDTH  = width;
	int ICON_HEIGHT = height;
			
	File test = new File(ICON_DIR + filename);
	if(test.isFile() != true){
		filename = "no-image.png";
	}
	Image tempImage = new Image(Display.getCurrent(), ICON_DIR + filename);
	ImageData id = tempImage.getImageData().scaledTo(ICON_WIDTH,ICON_HEIGHT);
	return new Image(Display.getCurrent(),id);
}
 
Example 39
Project: scanning   File: Activator.java   View source code 5 votes vote down vote up
public static ImageDescriptor getImageDescriptor(String path) {
	if (plugin==null) {
		final ImageData data = new ImageData("../"+PLUGIN_ID+"/"+path);
		return new ImageDescriptor() {
			@Override
			public ImageData getImageData() {
				return data;
			}
		};
	}
	return imageDescriptorFromPlugin(PLUGIN_ID, path);
}
 
Example 40
Project: Open_Source_ECOA_Toolset_AS5   File: ImageSaveUtil.java   View source code 5 votes vote down vote up
private static void saveEditorContentsAsImage(IEditorPart editorPart, GraphicalViewer viewer, String saveFilePath, int format) {

		ScalableFreeformRootEditPart rootEditPart = (ScalableFreeformRootEditPart) viewer.getEditPartRegistry().get(LayerManager.ID);
		IFigure rootFigure = ((LayerManager) rootEditPart).getLayer(LayerConstants.PRINTABLE_LAYERS);// rootEditPart.getFigure();
		Rectangle rootFigureBounds = rootFigure.getBounds();

		Control figureCanvas = viewer.getControl();
		GC figureCanvasGC = new GC(figureCanvas);

		Image img = new Image(null, rootFigureBounds.width, rootFigureBounds.height);
		GC imageGC = new GC(img);
		imageGC.setBackground(figureCanvasGC.getBackground());
		imageGC.setForeground(figureCanvasGC.getForeground());
		imageGC.setFont(figureCanvasGC.getFont());
		imageGC.setLineStyle(figureCanvasGC.getLineStyle());
		imageGC.setLineWidth(figureCanvasGC.getLineWidth());
		imageGC.setXORMode(figureCanvasGC.getXORMode());
		Graphics imgGraphics = new SWTGraphics(imageGC);

		rootFigure.paint(imgGraphics);

		ImageData[] imgData = new ImageData[1];
		imgData[0] = img.getImageData();

		ImageLoader imgLoader = new ImageLoader();
		imgLoader.data = imgData;
		imgLoader.save(saveFilePath, format);

		figureCanvasGC.dispose();
		imageGC.dispose();
		img.dispose();
	}