use of org.eclipse.swt.graphics.ImageData in project eclipse.platform.swt by eclipse.
the class Test_org_eclipse_swt_graphics_Image method test_hashCode.
@Test
public void test_hashCode() {
Image image = null;
Image image1 = null;
try {
image = new Image(display, 10, 10);
image1 = image;
assertEquals(":a:", image1.hashCode(), image.hashCode());
ImageData imageData = new ImageData(10, 10, 1, new PaletteData(new RGB(0, 0, 0)));
image.dispose();
image = new Image(display, imageData);
image1 = new Image(display, imageData);
boolean equals = (image1.hashCode() == image.hashCode());
assertFalse(":b:", equals);
} finally {
image.dispose();
image1.dispose();
}
// ImageFileNameProvider
try {
image = new Image(display, imageFileNameProvider);
image1 = new Image(display, imageFileNameProvider);
assertEquals(":c:", image1.hashCode(), image.hashCode());
} finally {
image.dispose();
image1.dispose();
}
// ImageDataProvider
try {
image = new Image(display, imageDataProvider);
image1 = new Image(display, imageDataProvider);
assertEquals(":d:", image1.hashCode(), image.hashCode());
} finally {
image.dispose();
image1.dispose();
}
}
use of org.eclipse.swt.graphics.ImageData in project eclipse.platform.swt by eclipse.
the class Test_org_eclipse_swt_graphics_Image method getImageData1.
/**
* Test implementation *
*/
void getImageData1() {
int numFormats = SwtTestUtil.imageFormats.length;
String fileName = SwtTestUtil.imageFilenames[0];
for (int i = 0; i < numFormats; i++) {
String format = SwtTestUtil.imageFormats[i];
try (InputStream stream = SwtTestUtil.class.getResourceAsStream(fileName + "." + format)) {
ImageData data1 = new ImageData(stream);
Image image = new Image(display, data1);
ImageData data2 = image.getImageData();
image.dispose();
assertEquals("Image width should be the same", data1.width, data2.width);
assertEquals("Image height should be the same", data1.height, data2.height);
} catch (IOException e) {
// continue;
}
}
}
use of org.eclipse.swt.graphics.ImageData 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_ImageDataLorg_eclipse_swt_graphics_ImageData.
@Test
public void test_ConstructorLorg_eclipse_swt_graphics_DeviceLorg_eclipse_swt_graphics_ImageDataLorg_eclipse_swt_graphics_ImageData() {
ImageData data = null;
ImageData data1 = new ImageData(10, 10, 1, new PaletteData(new RGB(0, 0, 0)));
Image image = null;
try {
image = new Image(display, data, data1);
image.dispose();
fail("No exception thrown for ImageData source == null");
} catch (IllegalArgumentException e) {
assertSWTProblem("Incorrect exception thrown for ImageData source == null", SWT.ERROR_NULL_ARGUMENT, e);
}
data = new ImageData(10, 10, 1, new PaletteData(new RGB(0, 0, 0)));
data1 = null;
try {
image = new Image(display, data, data1);
image.dispose();
fail("No exception thrown for ImageData mask == null");
} catch (IllegalArgumentException e) {
assertSWTProblem("Incorrect exception thrown for ImageData mask == null", SWT.ERROR_NULL_ARGUMENT, e);
}
data = new ImageData(10, 10, 1, new PaletteData(new RGB(0, 0, 0)));
data1 = new ImageData(1, 10, 1, new PaletteData(new RGB(0, 0, 0)));
try {
image = new Image(display, data, data1);
image.dispose();
fail("No exception thrown for ImageData source width != ImageData mask width");
} catch (IllegalArgumentException e) {
assertSWTProblem("Incorrect exception thrown for ImageData source width != ImageData mask width", SWT.ERROR_INVALID_ARGUMENT, e);
}
data = new ImageData(10, 1, 1, new PaletteData(new RGB(0, 0, 0)));
data1 = new ImageData(10, 10, 1, new PaletteData(new RGB(0, 0, 0)));
try {
image = new Image(display, data, data1);
image.dispose();
fail("No exception thrown for ImageData source height != ImageData mask height");
} catch (IllegalArgumentException e) {
assertSWTProblem("Incorrect exception thrown for ImageData source height != ImageData mask height", SWT.ERROR_INVALID_ARGUMENT, e);
}
data = new ImageData(10, 10, 8, new PaletteData(new RGB(0, 0, 0)));
data1 = new ImageData(10, 10, 8, new PaletteData(new RGB(0, 0, 0)));
// Image now accepts masks where depth != 1
image = new Image(display, data, data1);
image.dispose();
data = new ImageData(10, 10, 8, new PaletteData(0x30, 0x0C, 0x03));
// set opaque red pixel at x=9, y=9
data.setPixel(9, 9, 0x30);
data1 = new ImageData(10, 10, 1, new PaletteData(new RGB(0, 0, 0), new RGB(255, 255, 255)));
data1.setPixel(9, 9, 1);
image = new Image(display, data, data1);
Image gcImage = new Image(display, 10, 10);
GC gc = new GC(gcImage);
Color backgroundColor = display.getSystemColor(SWT.COLOR_BLUE);
gc.setBackground(backgroundColor);
gc.fillRectangle(0, 0, 10, 10);
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));
int bluePixel = gcImageData.getPixel(0, 0);
assertEquals(":b:", getRealRGB(backgroundColor), gcImageData.palette.getRGB(bluePixel));
gc.dispose();
gcImage.dispose();
image.dispose();
}
use of org.eclipse.swt.graphics.ImageData in project eclipse.platform.swt by eclipse.
the class Test_org_eclipse_swt_graphics_Image method test_ConstructorLorg_eclipse_swt_graphics_Device_ImageDataProvider.
@Test
public void test_ConstructorLorg_eclipse_swt_graphics_Device_ImageDataProvider() {
// Null provider
ImageDataProvider provider = null;
try {
Image image = new Image(display, provider);
image.dispose();
fail("No exception thrown for file name == null");
} catch (IllegalArgumentException e) {
assertSWTProblem("Incorrect exception thrown for provider == null", SWT.ERROR_NULL_ARGUMENT, e);
}
// Invalid provider
provider = zoom -> null;
try {
Image image = new Image(display, provider);
image.dispose();
fail("No exception thrown for non-existent file name");
} catch (IllegalArgumentException e) {
assertSWTProblem("Incorrect exception thrown for provider == null", SWT.ERROR_INVALID_ARGUMENT, e);
}
// Valid provider
Image image = new Image(display, imageDataProvider);
image.dispose();
// Corrupt Image provider
provider = zoom -> {
String fileName;
switch(zoom) {
case 100:
fileName = "corrupt.png";
break;
case 150:
fileName = "corrupt.png";
break;
case 200:
fileName = "corrupt.png";
break;
default:
return null;
}
return new ImageData(getPath(fileName));
};
try {
image = new Image(display, provider);
image.dispose();
fail("No exception thrown for corrupt image file.");
} catch (SWTException e) {
assertSWTProblem("Incorrect exception thrown for provider with corrupt images", SWT.ERROR_INVALID_IMAGE, e);
}
// Valid provider only 100% zoom
provider = zoom -> {
String fileName;
switch(zoom) {
case 100:
fileName = "collapseall.png";
break;
case 150:
case 200:
default:
return null;
}
return new ImageData(getPath(fileName));
};
image = new Image(display, provider);
image.dispose();
}
use of org.eclipse.swt.graphics.ImageData in project eclipse.platform.swt by eclipse.
the class Test_org_eclipse_swt_graphics_Image method test_getBounds.
@Test
public void test_getBounds() {
Rectangle bounds = new Rectangle(0, 0, 10, 20);
Image image = new Image(display, bounds.width, bounds.height);
image.dispose();
try {
image.getBounds();
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 bounds1 = image.getBounds();
image.dispose();
assertEquals(":a:", bounds, bounds1);
image = new Image(display, bounds);
bounds1 = image.getBounds();
image.dispose();
assertEquals(":b:", bounds, bounds1);
// create icon image
ImageData imageData = new ImageData(bounds.width, bounds.height, 1, new PaletteData(new RGB(0, 0, 0)));
image = new Image(display, imageData);
bounds1 = image.getBounds();
image.dispose();
assertEquals(":c:", bounds, bounds1);
}
Aggregations