Search in sources :

Example 41 with ImageData

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();
    }
}
Also used : PaletteData(org.eclipse.swt.graphics.PaletteData) ImageData(org.eclipse.swt.graphics.ImageData) Image(org.eclipse.swt.graphics.Image) RGB(org.eclipse.swt.graphics.RGB) Test(org.junit.Test)

Example 42 with ImageData

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;
        }
    }
}
Also used : InputStream(java.io.InputStream) ImageData(org.eclipse.swt.graphics.ImageData) IOException(java.io.IOException) Image(org.eclipse.swt.graphics.Image)

Example 43 with ImageData

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();
}
Also used : PaletteData(org.eclipse.swt.graphics.PaletteData) ImageData(org.eclipse.swt.graphics.ImageData) Color(org.eclipse.swt.graphics.Color) RGB(org.eclipse.swt.graphics.RGB) Image(org.eclipse.swt.graphics.Image) GC(org.eclipse.swt.graphics.GC) Test(org.junit.Test)

Example 44 with ImageData

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();
}
Also used : SWTException(org.eclipse.swt.SWTException) ImageData(org.eclipse.swt.graphics.ImageData) Image(org.eclipse.swt.graphics.Image) ImageDataProvider(org.eclipse.swt.graphics.ImageDataProvider) Test(org.junit.Test)

Example 45 with ImageData

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);
}
Also used : PaletteData(org.eclipse.swt.graphics.PaletteData) SWTException(org.eclipse.swt.SWTException) ImageData(org.eclipse.swt.graphics.ImageData) Rectangle(org.eclipse.swt.graphics.Rectangle) Image(org.eclipse.swt.graphics.Image) RGB(org.eclipse.swt.graphics.RGB) Test(org.junit.Test)

Aggregations

ImageData (org.eclipse.swt.graphics.ImageData)132 Image (org.eclipse.swt.graphics.Image)78 PaletteData (org.eclipse.swt.graphics.PaletteData)38 RGB (org.eclipse.swt.graphics.RGB)33 Point (org.eclipse.swt.graphics.Point)32 Test (org.junit.Test)26 InputStream (java.io.InputStream)24 GC (org.eclipse.swt.graphics.GC)19 IOException (java.io.IOException)18 SWTException (org.eclipse.swt.SWTException)14 ImageDescriptor (org.eclipse.jface.resource.ImageDescriptor)13 Rectangle (org.eclipse.swt.graphics.Rectangle)12 Color (org.eclipse.swt.graphics.Color)11 ImageLoader (org.eclipse.swt.graphics.ImageLoader)11 Display (org.eclipse.swt.widgets.Display)11 ByteArrayInputStream (java.io.ByteArrayInputStream)7 Cursor (org.eclipse.swt.graphics.Cursor)7 Composite (org.eclipse.swt.widgets.Composite)7 GradientPaint (java.awt.GradientPaint)5 URL (java.net.URL)5