use of org.eclipse.swt.graphics.PaletteData in project eclipse.platform.swt by eclipse.
the class Test_org_eclipse_swt_graphics_Image method test_getImageData.
@Test
public void test_getImageData() {
getImageData1();
getImageData2(24, new PaletteData(0xff0000, 0xff00, 0xff));
getImageData2(32, new PaletteData(0xff0000, 0xff00, 0xff));
}
use of org.eclipse.swt.graphics.PaletteData in project eclipse.platform.swt by eclipse.
the class Test_org_eclipse_swt_graphics_Image method test_ConstructorLorg_eclipse_swt_graphics_DeviceLorg_eclipse_swt_graphics_ImageData.
@Test
public void test_ConstructorLorg_eclipse_swt_graphics_DeviceLorg_eclipse_swt_graphics_ImageData() {
ImageData data = null;
Image image = null;
try {
image = new Image(display, data);
image.dispose();
fail("No exception thrown for ImageData == null");
} catch (IllegalArgumentException e) {
assertSWTProblem("Incorrect exception thrown for ImageData == null", SWT.ERROR_NULL_ARGUMENT, e);
}
// Platform-specific test.
// data = new ImageData(10, 10, 1, new PaletteData(0xff0000, 0x00ff00, 0x0000ff));
// try {
// image = new Image(display, data);
// image.dispose();
// fail("Unsupported color depth");
// } catch (SWTException e) {
// }
data = new ImageData(10, 10, 1, new PaletteData(new RGB(0, 0, 0)));
image = new Image(null, data);
image.dispose();
data = new ImageData(10, 10, 1, new PaletteData(new RGB(0, 0, 0)));
image = new Image(display, data);
image.dispose();
data = new ImageData(10, 10, 8, new PaletteData(0x30, 0x0C, 0x03));
// set red pixel at x=9, y=9
data.setPixel(9, 9, 0x30);
image = new Image(display, data);
Image gcImage = new Image(display, 10, 10);
GC gc = new GC(gcImage);
gc.drawImage(image, 0, 0);
ImageData gcImageData = gcImage.getImageData();
int redPixel = gcImageData.getPixel(9, 9);
assertEquals(":a:", getRealRGB(display.getSystemColor(SWT.COLOR_RED)), gcImageData.palette.getRGB(redPixel));
gc.dispose();
gcImage.dispose();
image.dispose();
}
use of org.eclipse.swt.graphics.PaletteData in project eclipse.platform.swt by eclipse.
the class Test_org_eclipse_swt_graphics_Image method getImageData_int.
void getImageData_int(int zoom) {
Rectangle bounds = new Rectangle(0, 0, 10, 20);
Image image = new Image(display, bounds.width, bounds.height);
image.dispose();
try {
image.getImageData(zoom);
fail("No exception thrown for disposed image");
} catch (SWTException e) {
assertSWTProblem("Incorrect exception thrown for disposed image", SWT.ERROR_GRAPHIC_DISPOSED, e);
}
// creates bitmap image and compare size of imageData
image = new Image(display, bounds.width, bounds.height);
ImageData imageDataAtZoom = image.getImageData(zoom);
image.dispose();
Rectangle boundsAtZoom = new Rectangle(0, 0, imageDataAtZoom.width, imageDataAtZoom.height);
assertEquals(":a: Size of ImageData returned from Image.getImageData(int) method doesn't return matches with bounds in Pixel values.", scaleBounds(bounds, zoom, 100), boundsAtZoom);
// create icon image and compare size of imageData
ImageData imageData = new ImageData(bounds.width, bounds.height, 1, new PaletteData(new RGB[] { new RGB(0, 0, 0) }));
image = new Image(display, imageData);
imageDataAtZoom = image.getImageData(zoom);
image.dispose();
boundsAtZoom = new Rectangle(0, 0, imageDataAtZoom.width, imageDataAtZoom.height);
assertEquals(":b: Size of ImageData returned from Image.getImageData(int) method doesn't return matches with bounds in Pixel values.", scaleBounds(bounds, zoom, 100), boundsAtZoom);
// create image with FileNameProvider
image = new Image(display, imageFileNameProvider);
imageDataAtZoom = image.getImageData(zoom);
boundsAtZoom = new Rectangle(0, 0, imageDataAtZoom.width, imageDataAtZoom.height);
bounds = image.getBounds();
image.dispose();
assertEquals(":c: Size of ImageData returned from Image.getImageData(int) method doesn't return matches with bounds in Pixel values.", scaleBounds(bounds, zoom, 100), boundsAtZoom);
// create image with ImageDataProvider
image = new Image(display, imageDataProvider);
imageDataAtZoom = image.getImageData(zoom);
boundsAtZoom = new Rectangle(0, 0, imageDataAtZoom.width, imageDataAtZoom.height);
bounds = image.getBounds();
image.dispose();
assertEquals(":d: Size of ImageData returned from Image.getImageData(int) method doesn't return matches with bounds in Pixel values.", scaleBounds(bounds, zoom, 100), boundsAtZoom);
}
use of org.eclipse.swt.graphics.PaletteData in project eclipse.platform.swt by eclipse.
the class Test_org_eclipse_swt_graphics_Image method test_getBoundsInPixels.
@SuppressWarnings("deprecation")
@Test
public void test_getBoundsInPixels() {
Rectangle bounds = new Rectangle(0, 0, 10, 20);
Image image = new Image(display, bounds.width, bounds.height);
image.dispose();
try {
image.getBoundsInPixels();
fail("No exception thrown for disposed image");
} catch (SWTException e) {
assertSWTProblem("Incorrect exception thrown for disposed image", SWT.ERROR_GRAPHIC_DISPOSED, e);
}
// creates bitmap image
image = new Image(display, bounds.width, bounds.height);
Rectangle boundsInPixels = image.getBoundsInPixels();
image.dispose();
assertEquals(":a: Image.getBoundsInPixels method doesn't return bounds in Pixel values.", boundsInPixels, DPIUtil.autoScaleUp(bounds));
// create icon image
ImageData imageData = new ImageData(bounds.width, bounds.height, 1, new PaletteData(new RGB[] { new RGB(0, 0, 0) }));
image = new Image(display, imageData);
boundsInPixels = image.getBoundsInPixels();
image.dispose();
assertEquals(":b: Image.getBoundsInPixels method doesn't return bounds in Pixel values.", boundsInPixels, DPIUtil.autoScaleUp(bounds));
// create image with FileNameProvider
image = new Image(display, imageFileNameProvider);
boundsInPixels = image.getBoundsInPixels();
bounds = image.getBounds();
image.dispose();
assertEquals(":c: Image.getBoundsInPixels method doesn't return bounds in Pixel values.", boundsInPixels, DPIUtil.autoScaleUp(bounds));
// create image with ImageDataProvider
image = new Image(display, imageDataProvider);
boundsInPixels = image.getBoundsInPixels();
bounds = image.getBounds();
image.dispose();
assertEquals(":d: Image.getBoundsInPixels method doesn't return bounds in Pixel values.", boundsInPixels, DPIUtil.autoScaleUp(bounds));
}
use of org.eclipse.swt.graphics.PaletteData in project eclipse.platform.swt by eclipse.
the class Test_org_eclipse_swt_graphics_Image method getRealRGB.
RGB getRealRGB(Color color) {
Image colorImage = new Image(display, 10, 10);
GC imageGc = new GC(colorImage);
ImageData imageData;
PaletteData palette;
int pixel;
imageGc.setBackground(color);
imageGc.setForeground(color);
imageGc.fillRectangle(0, 0, 10, 10);
imageData = colorImage.getImageData();
palette = imageData.palette;
imageGc.dispose();
colorImage.dispose();
pixel = imageData.getPixel(0, 0);
return palette.getRGB(pixel);
}
Aggregations