Package org.eclipse.swt.graphics

Examples of org.eclipse.swt.graphics.PaletteData


        return this.coloredBackgroundImage;
    }


    private ImageData tintImageData(ImageData imageData, Color color) {       
        PaletteData palette = imageData.palette;
        imageData = (ImageData) imageData.clone();
       
        if (palette.isDirect) {
            this.tintDirectImageData(imageData, color, palette);           
        } else {
View Full Code Here


    for (int i = 0; i < n; ++i)
      rgbs[i] = counters[i].rgb;
    if (mask != null) {
      rgbs[rgbs.length - 1] = data.transparentPixel != -1 ? data.palette.getRGB(data.transparentPixel) : new RGB(255, 255, 255);
    }
    PaletteData palette = new PaletteData(rgbs);

    // create a new image using the new palette:
    // for each pixel in the old image, look up the best matching
    // index in the new palette
    ImageData newData = new ImageData(width, data.height, 8, palette);
View Full Code Here

  }

  static Image createNewTransparentImg(Display d, int w, int h) {
    final Color white = d.getSystemColor(SWT.COLOR_WHITE);
    final Color black = d.getSystemColor(SWT.COLOR_BLACK);
    final PaletteData palette = new PaletteData(new RGB[] { white.getRGB(),
        black.getRGB() });
    final ImageData sourceData = new ImageData(w, h, 1, palette);
    sourceData.transparentPixel = 0;
    return new Image(d, sourceData);
  }
View Full Code Here

   * @param color The color that the overlay should be.
   * @return
   */
  public static Image addOverlay(Image image, RGB color) {
    // on windows, using the image PaletteData is unreliable.  FIXME: colors are whacked out on windows
        PaletteData palette = new PaletteData(0xFF , 0xFF00 , 0xFF0000);
      int overlayColor = palette.getPixel(color);
        ImageData fullImageData = image.getImageData();
        ImageData transparency = fullImageData.getTransparencyMask();
       
        int width = fullImageData.width;
        int height = fullImageData.height;
View Full Code Here

   * @param color The color that the overlay should be.
   * @return
   */
  public static Image addOverlay(Image image, RGB color) {
    // on windows, using the image PaletteData is unreliable.  FIXME: colors are whacked out on windows
        PaletteData palette = new PaletteData(0xFF , 0xFF00 , 0xFF0000);
      int overlayColor = palette.getPixel(color);
        ImageData fullImageData = image.getImageData();
        ImageData transparency = fullImageData.getTransparencyMask();
       
        int width = fullImageData.width;
        int height = fullImageData.height;
View Full Code Here

        /*
         * create an image with transparent color (this can be done better?)
         */
        Color white = display.getSystemColor(SWT.COLOR_WHITE);
        PaletteData palette = new PaletteData(new RGB[]{white.getRGB()});
        final ImageData sourceData = new ImageData(visibleRect.width, visibleRect.height, 1, palette);
        sourceData.transparentPixel = 0;

        // create the image to draw on
        Image img = new Image(display, sourceData);
View Full Code Here

     */
    public static ImageData convertToSWT(BufferedImage bufferedImage) {
        if (bufferedImage.getColorModel() instanceof DirectColorModel) {
            DirectColorModel colorModel
                    = (DirectColorModel) bufferedImage.getColorModel();
            PaletteData palette = new PaletteData(colorModel.getRedMask(),
                    colorModel.getGreenMask(), colorModel.getBlueMask());
            ImageData data = new ImageData(bufferedImage.getWidth(),
                    bufferedImage.getHeight(), colorModel.getPixelSize(),
                    palette);
            WritableRaster raster = bufferedImage.getRaster();
            int[] pixelArray = new int[3];
            for (int y = 0; y < data.height; y++) {
                for (int x = 0; x < data.width; x++) {
                    raster.getPixel(x, y, pixelArray);
                    int pixel = palette.getPixel(new RGB(pixelArray[0],
                            pixelArray[1], pixelArray[2]));
                    data.setPixel(x, y, pixel);
                }
            }
            return data;
        }
        else if (bufferedImage.getColorModel() instanceof IndexColorModel) {
            IndexColorModel colorModel = (IndexColorModel)
                    bufferedImage.getColorModel();
            int size = colorModel.getMapSize();
            byte[] reds = new byte[size];
            byte[] greens = new byte[size];
            byte[] blues = new byte[size];
            colorModel.getReds(reds);
            colorModel.getGreens(greens);
            colorModel.getBlues(blues);
            RGB[] rgbs = new RGB[size];
            for (int i = 0; i < rgbs.length; i++) {
                rgbs[i] = new RGB(reds[i] & 0xFF, greens[i] & 0xFF,
                        blues[i] & 0xFF);
            }
            PaletteData palette = new PaletteData(rgbs);
            ImageData data = new ImageData(bufferedImage.getWidth(),
                    bufferedImage.getHeight(), colorModel.getPixelSize(),
                    palette);
            data.transparentPixel = colorModel.getTransparentPixel();
            WritableRaster raster = bufferedImage.getRaster();
View Full Code Here

   * @param oy
   *            the y position
   */
  final protected void drawImage(ImageData src, int ox, int oy) {
    ImageData dst = imageData;
    PaletteData srcPalette = src.palette;
    ImageData srcMask = null;
    int alphaMask = 0, alphaShift = 0;
    if (src.maskData != null) {
      srcMask = src.getTransparencyMask ();
      if (src.depth == 32) {
        alphaMask = ~(srcPalette.redMask | srcPalette.greenMask | srcPalette.blueMask);
        while (alphaMask != 0 && ((alphaMask >>> alphaShift) & 1) == 0) alphaShift++;
      }
    }
    for (int srcY = 0, dstY = srcY + oy; srcY < src.height; srcY++, dstY++) {
      for (int srcX = 0, dstX = srcX + ox; srcX < src.width; srcX++, dstX++) {
        if (!(0 <= dstX && dstX < dst.width && 0 <= dstY && dstY < dst.height)) continue;
        int srcPixel = src.getPixel(srcX, srcY);
        int srcAlpha = 255;
        if (src.maskData != null) {
          if (src.depth == 32) {
            srcAlpha = (srcPixel & alphaMask) >>> alphaShift;
            if (srcAlpha == 0) {
              srcAlpha = srcMask.getPixel(srcX, srcY) != 0 ? 255 : 0;
            }
          } else {
            if (srcMask.getPixel(srcX, srcY) == 0) srcAlpha = 0;
          }
        } else if (src.transparentPixel != -1) {
          if (src.transparentPixel == srcPixel) srcAlpha = 0;
        } else if (src.alpha != -1) {
          srcAlpha = src.alpha;
        } else if (src.alphaData != null) {
          srcAlpha = src.getAlpha(srcX, srcY);
        }
        if (srcAlpha == 0) continue;
        int srcRed, srcGreen, srcBlue;
        if (srcPalette.isDirect) {
          srcRed = srcPixel & srcPalette.redMask;
          srcRed = (srcPalette.redShift < 0) ? srcRed >>> -srcPalette.redShift : srcRed << srcPalette.redShift;
          srcGreen = srcPixel & srcPalette.greenMask;
          srcGreen = (srcPalette.greenShift < 0) ? srcGreen >>> -srcPalette.greenShift : srcGreen << srcPalette.greenShift;
          srcBlue = srcPixel & srcPalette.blueMask;
          srcBlue = (srcPalette.blueShift < 0) ? srcBlue >>> -srcPalette.blueShift : srcBlue << srcPalette.blueShift;
        } else {
          RGB rgb = srcPalette.getRGB(srcPixel);
          srcRed = rgb.red;
          srcGreen = rgb.green;
          srcBlue = rgb.blue;
        }
        int dstRed, dstGreen, dstBlue, dstAlpha;
View Full Code Here

   */
  public ImageData getImageData() {
    Point size = getSize();   
   
    /* Create a 24 bit image data with alpha channel */
    imageData = new ImageData(size.x, size.y, 24, new PaletteData(0xFF, 0xFF00, 0xFF0000));
    imageData.alphaData = new byte[imageData.width * imageData.height];
   
    drawCompositeImage(size.x, size.y);
   
    /* Detect minimum transparency */
    boolean transparency = false;
    byte[] alphaData = imageData.alphaData;
    for (int i = 0; i < alphaData.length; i++) {
      int alpha = alphaData[i] & 0xFF;
      if (!(alpha == 0 || alpha == 255)) {
        /* Full alpha channel transparency */
        return imageData;
      }
      if (!transparency && alpha == 0) transparency = true;
    }
    if (transparency) {
      /* Reduce to 1-bit alpha channel transparency */
      PaletteData palette = new PaletteData(new RGB[]{new RGB(0, 0, 0), new RGB(255, 255, 255)});
      ImageData mask = new ImageData(imageData.width, imageData.height, 1, palette);
      for (int y = 0; y < mask.height; y++) {
        for (int x = 0; x < mask.width; x++) {
          mask.setPixel(x, y, imageData.getAlpha(x, y) == 255 ? 1 : 0);
        }
View Full Code Here

        int xoffset = indent;
        int yoffset = (height - size) / 2;

        RGB black = new RGB(0, 0, 0);
        PaletteData dataPalette = new PaletteData(new RGB[] { black, black,
                color });
        ImageData data = new ImageData(width, height, 4, dataPalette);
        data.transparentPixel = 0;

        int end = size - 1;
View Full Code Here

TOP

Related Classes of org.eclipse.swt.graphics.PaletteData

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.