Search in sources :

Example 36 with PaletteData

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

Example 37 with PaletteData

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();
}
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) GC(org.eclipse.swt.graphics.GC) Test(org.junit.Test)

Example 38 with PaletteData

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);
}
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)

Example 39 with PaletteData

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));
}
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)

Example 40 with PaletteData

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

Aggregations

PaletteData (org.eclipse.swt.graphics.PaletteData)57 ImageData (org.eclipse.swt.graphics.ImageData)47 RGB (org.eclipse.swt.graphics.RGB)46 Test (org.junit.Test)27 Image (org.eclipse.swt.graphics.Image)22 Point (org.eclipse.swt.graphics.Point)12 GC (org.eclipse.swt.graphics.GC)10 Color (org.eclipse.swt.graphics.Color)9 DirectColorModel (java.awt.image.DirectColorModel)8 IndexColorModel (java.awt.image.IndexColorModel)8 WritableRaster (java.awt.image.WritableRaster)8 Rectangle (org.eclipse.swt.graphics.Rectangle)8 SWTException (org.eclipse.swt.SWTException)7 BufferedImage (java.awt.image.BufferedImage)4 ColorModel (java.awt.image.ColorModel)2 PaintEvent (org.eclipse.swt.events.PaintEvent)2 PaintListener (org.eclipse.swt.events.PaintListener)2 Cursor (org.eclipse.swt.graphics.Cursor)2 Composite (org.eclipse.swt.widgets.Composite)2 Event (org.eclipse.swt.widgets.Event)2