Java 类org.eclipse.swt.graphics.PaletteData 实例源码

项目:convertigo-eclipse    文件:SWTX.java   
public static void drawShadowImage(GC gc, Image image, int x, int y,
    int alpha) {
  Display display = Display.getCurrent();
  Point imageSize = new Point(image.getBounds().width,
      image.getBounds().height);
  //
  ImageData imgData = new ImageData(imageSize.x, imageSize.y, 24,
      new PaletteData(255, 255, 255));
  imgData.alpha = alpha;
  Image img = new Image(display, imgData);
  GC imgGC = new GC(img);
  imgGC.drawImage(image, 0, 0);
  gc.drawImage(img, x, y);
  imgGC.dispose();
  img.dispose();
}
项目:pdi    文件:Interface.java   
private RGB encontraPixel(int x, int y, int indice) {

        labelPosicaoCor.setText(x + "," + y);

        ImageData imageData = null;
        PaletteData paletteData = null;

        if (indice == 1 && imagem1 != null) {
            imageData = imagem1.getImageData();
            paletteData = imageData.palette;
        } else if (indice == 2 && imagem2 != null) {
            imageData = imagem2.getImageData();
            paletteData = imageData.palette;
        } else if (indice == 3 && imagem3 != null) {
            imageData = imagem3.getImageData();
            paletteData = imageData.palette;
        }

        if (paletteData != null && x > -1 && y > -1) {
            int pixel = imageData.getPixel(x, y);
            RGB rgb = paletteData.getRGB(pixel);
            return rgb;
        }

        return null;
    }
项目:TuxGuitar-1.3.1-fork    文件:TGImageImpl.java   
public void applyTransparency( TGColor background ){
    RGB alpha = new RGB( background.getRed(), background.getGreen(), background.getBlue() );
    RGB none = new RGB((0xff ^ alpha.red),(0xff ^ alpha.green),(0xff ^ alpha.blue));

    Image srcImage = this.handle;
    ImageData srcData = srcImage.getImageData();
    ImageData maskData = new ImageData(srcData.width,srcData.height,1,new PaletteData(new RGB[]{ none,alpha }  ));
    for(int x = 0; x< maskData.width; x++) {
        for(int y = 0; y < maskData.height; y++) {
            RGB rgb = srcData.palette.getRGB(srcData.getPixel(x, y));
            if(rgb.red == alpha.red && rgb.green == alpha.green && rgb.blue == alpha.blue){
                maskData.setPixel(x, y, maskData.palette.getPixel(none));
            }else{
                maskData.setPixel(x, y, maskData.palette.getPixel(alpha));
            }
        }
    }
    this.handle = new Image(srcImage.getDevice(),srcData,maskData);

    srcImage.dispose();
}
项目:TranskribusSwtGui    文件:SWTUtil.java   
public static ImageData convertToSWT2(BufferedImage bufferedImage) throws IOException {
//      /2) awt.BufferedImage -> raw Data
        java.awt.image.WritableRaster awtRaster = bufferedImage.getRaster();
        java.awt.image.DataBufferByte awtData = (DataBufferByte) awtRaster.getDataBuffer();
        byte[] rawData = awtData.getData();

        //3) raw Data -> swt.ImageData
        org.eclipse.swt.graphics.PaletteData swtPalette = new PaletteData(0xff, 0xff00, 0xff0000);

        int depth = 0x18;
        org.eclipse.swt.graphics.ImageData swtImageData = new ImageData(bufferedImage.getWidth(), bufferedImage.getHeight(), 
                depth, swtPalette, bufferedImage.getWidth(), rawData);

        return swtImageData;
//      return new Image(Display.getDefault(), swtImageData);       
    }
项目:ForgedUI-Eclipse    文件:ColorPropertyDescriptor2.java   
@Override
public Image getImage(Object element) {
    if (element instanceof RGB) {
        RGB rgb = (RGB) element;
        if (!rgb.equals(colorRGB)){
            if (colorImage != null){
                colorImage.dispose();
            }
            colorRGB = rgb;
            PaletteData palette = new PaletteData(new RGB[]{rgb, new RGB(0,0,0)});
            ImageData data = new ImageData(1, 1, 1, palette);
            colorImage = new Image(null, data);
        }
    } else {
        if (colorImage != null){
            colorImage.dispose();
            colorImage = null;
        }
        colorRGB = null;
    }
    return colorImage;
}
项目:triquetrum    文件:ShapeUtils.java   
/**
 * Converts an AWT based buffered image into an SWT <code>Image</code>. This will always return an <code>Image</code> that has 24 bit depth regardless of the
 * type of AWT buffered image that is passed into the method.
 *
 * @param device
 * @param awtImage
 *          the {@link java.awt.image.BufferedImage} to be converted to an <code>Image</code>
 *          
 * @return an <code>Image</code> that represents the same image data as the AWT <code>BufferedImage</code> type.
 */
public static org.eclipse.swt.graphics.Image toSWT(Device device, BufferedImage awtImage) {
  device = (device!=null) ? device : Display.getCurrent();
  // We can force bitdepth to be 24 bit because BufferedImage getRGB
  // allows us to always retrieve 24 bit data regardless of source color depth.
  PaletteData palette = new PaletteData(0xFF0000, 0xFF00, 0xFF);
  ImageData swtImageData = new ImageData(awtImage.getWidth(), awtImage.getHeight(), 24, palette);
  // Ensure scansize is aligned on 32 bit.
  int scansize = (((awtImage.getWidth() * 3) + 3) * 4) / 4;
  WritableRaster alphaRaster = awtImage.getAlphaRaster();
  byte[] alphaBytes = new byte[awtImage.getWidth()];
  for (int y = 0; y < awtImage.getHeight(); y++) {
    int[] buff = awtImage.getRGB(0, y, awtImage.getWidth(), 1, null, 0, scansize);
    swtImageData.setPixels(0, y, awtImage.getWidth(), buff, 0);
    if (alphaRaster != null) {
      int[] alpha = alphaRaster.getPixels(0, y, awtImage.getWidth(), 1, (int[]) null);
      for (int i = 0; i < awtImage.getWidth(); i++) {
        alphaBytes[i] = (byte) alpha[i];
      }
      swtImageData.setAlphas(0, y, awtImage.getWidth(), alphaBytes, 0);
    }
  }
  return new org.eclipse.swt.graphics.Image(device, swtImageData);
}
项目:SMVHunter    文件:BaseHeapPanel.java   
/**
 * Creates a linear image of the heap data.
 * @param pixData
 * @param h
 * @param palette
 * @return
 */
protected ImageData createLinearHeapImage(byte[] pixData, int h, PaletteData palette) {
    int w = pixData.length / h;
    if (pixData.length % h != 0) {
        w++;
    }

    // Create the heap image.
    ImageData id = new ImageData(w, h, 8, palette);

    int x = 0;
    int y = 0;
    for (byte b : pixData) {
        if (b >= 0) {
            id.setPixel(x, y, b);
        }

        y++;
        if (y >= h) {
            y = 0;
            x++;
        }
    }

    return id;
}
项目:AndroidRobot    文件:SetCheckPoint2.java   
public ImageData getImageData(BufferedImage bufferedImage) {
    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;
}
项目:AndroidRobot    文件:DeviceSocketClient.java   
private static ImageData getImageData2(BufferedImage bufferedImage){
    DirectColorModel colorModel = (DirectColorModel) bufferedImage.getColorModel();
    //System.out.println("robot:" +colorModel.getRedMask() + " "+colorModel.getGreenMask() + " "+colorModel.getBlueMask());   
    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;
}
项目:PDFReporter-Studio    文件:SPRWCCombo.java   
private Image createImage(final String fontName) {

        Image stringImage = cache.getImage(fontName);
        if (stringImage == null){
            Display display = Display.getCurrent();
            Color TRANSPARENT_COLOR = display.getSystemColor(SWT.COLOR_WHITE);
            Color DRAWING_COLOR = display.getSystemColor(SWT.COLOR_BLACK);
            PaletteData paletteData = new PaletteData(new RGB[] { TRANSPARENT_COLOR.getRGB(), DRAWING_COLOR.getRGB() });
            ImageData imageData = new ImageData(55, 15, 4, paletteData);
            imageData.transparentPixel = 0; // index of the palette

            stringImage = new Image(display, imageData);
            GC stringGc = new GC(stringImage);
            try {
                stringGc.setForeground(DRAWING_COLOR);
                stringGc.setBackground(TRANSPARENT_COLOR);
                stringGc.setFont(cache.getFont(fontName, 10, 0));
                stringGc.drawText("Sample", 0, 0);
            } finally {
                stringGc.dispose();
                cache.storeImage(fontName, stringImage);
            }
        }
        return stringImage;
    }
项目:PDFReporter-Studio    文件:ColorsSelectorWidget.java   
/**
 * Create the image data for the rectangle data without arrow, so it can be cached
 * 
 * @param rect size of the rectangle area
 * @return ImageData that will be placed inside the rectangle area
 */
private ImageData createSliderImage(Rectangle rect){
  int padWidth = governor.getPadMaxX() - governor.getPadMinX();
   int padHeight = governor.getPadMaxY() - governor.getPadMinY();
    float padX = ((float)(circlePosition.x*padWidth))/(getPadWidth()-1);
    float padY = ((float)(circlePosition.y*padHeight))/(getPadHeight()-1);
    ImageData image = new ImageData(Math.max(1, rect.width),Math.max(1, rect.height),32,new PaletteData(0xFF0000,0xFF00,0xFF));
    int sliderHeight = governor.getSliderMax() - governor.getSliderMin();

    int backGroundPixel = image.palette.getPixel(slider.getParent().getBackground().getRGB());
    for(int y = 0; y<image.height; y++){
        float actaulSlider = ((float)sliderHeight / getSliderHeight()) * y;
        RGB actualHueColor = governor.getSliderColor(Math.round(padX), Math.round(padY), Math.round(actaulSlider));
        for(int x = 0; x<image.width; x++){
            if (x > arrowWidth && x<image.width-arrowWidth)
                image.setPixel(x,y,image.palette.getPixel(actualHueColor));
            else 
                image.setPixel(x,y, backGroundPixel);
        }
    }
    return image;
}
项目:PDFReporter-Studio    文件:ColorsSelectorWidget.java   
/**
 * Create the image data for the square data without the selection mark, so it can be cached
 * 
 * @param rect size of the square area
 * @return ImageData that will be placed inside the square area
 */
private ImageData createPadImage(Rectangle rect){
   ImageData imageData=new ImageData(Math.max(1, rect.width),Math.max(1, rect.height),32,new PaletteData(0xFF0000,0xFF00,0xFF));
   int padWidth = governor.getPadMaxX() - governor.getPadMinX();
   int padHeight = governor.getPadMaxY() - governor.getPadMinY();
   //Calculate the actual slider
   int slider = Math.round(((float)governor.getSliderMax() / getSliderHeight())*sliderPosition);
   for(int i=0; i<imageData.width; i++){
    for (int j=0; j<imageData.height; j++){
        float padX = ((float)(i*padWidth))/(imageData.width-1);
        float padY = ((float)(j*padHeight))/(imageData.height-1);
        imageData.setPixel(i,j,imageData.palette.getPixel(governor.getPadColor(Math.round(padX), Math.round(padY), slider)));
    }
   }

   return imageData;
}
项目:PDFReporter-Studio    文件:ColorSchemaGenerator.java   
/**
  * Return a a preview image of an embedded color. The image will have size of 
  * 20x10. The image are cached, so it will be generated only the first time that are 
  * requested.
  * 
  * @param colorName the human name of the color
  * @return an SWT image, preview of the color. It can be null if the human name dosen't match 
  * none of the embedded colors.
  */
 public static Image getImagePreview(String colorName){
//The images are cached and disposed at the end
String key = "colorPreview_"+colorName; //$NON-NLS-1$
Image image = ResourceManager.getImage(key);
if (image == null){
    if (colorsMap == null) getColors();
    String colorCode = colorsMap.get(colorName);
    if (colorCode != null){
        Color color = decodeColor("#"+colorCode); //$NON-NLS-1$
        RGB colorRGB = new RGB(color.getRed(), color.getGreen(), color.getBlue());
        ImageData data = new ImageData(20, 10, 1, new PaletteData(new RGB[]{colorRGB}));
        image = new Image(null,data); 
        GC graphics = new GC(image);
        graphics.setForeground(ColorConstants.black);
        graphics.drawRectangle(0,0,19,9);
        graphics.dispose();
        ResourceManager.addImage(key, image);
    } else return null;
}
return image;
}
项目:PDFReporter-Studio    文件:TemplateBorder.java   
/**
 * Return a border preview for a not visible border. The image is created only the first time is requested, then it is
 * cached and disposed when the application is closed.
 * 
 * @return an image with the words "No Borders" rendereized into it
 */
private Image getNoBordersImage() {
    String key = "linePreset_noBorders";
    Image image = ResourceManager.getImage(key);
    if (image == null) {
        ImageData data = new ImageData(getWidth(), 15, 1, new PaletteData(new RGB[] { ColorConstants.white.getRGB() }));
        // data.transparentPixel = data.getPixel(0, 0);
        image = new Image(null, data);
        GC graphics = new GC(image);
        try {
            // graphics.setTextAntialias(SWT.ON);
            graphics.setFont(ResourceManager.getFont("Time New Roman", 10, SWT.NORMAL));
            graphics.drawString("No Borders", 5, 0);
        } finally {
            graphics.dispose();
        }
        ResourceManager.addImage(key, image);
    }
    return image;
}
项目:PDFReporter-Studio    文件:TemplateBorder.java   
/**
 * Return a border preview for a custom border (not equals to any preset). The image is created only the first time is
 * requested, then it is cached and disposed when the application is closed.
 * 
 * @return an image with the words "Custom" rendereized into it
 */
public static Image getCustomImage() {
    String key = "linePreset_custom";
    Image image = ResourceManager.getImage(key);
    if (image == null) {
        ImageData data = new ImageData(getWidth(), 15, 1, new PaletteData(new RGB[] { ColorConstants.white.getRGB() }));
        // data.transparentPixel = data.getPixel(0, 0);
        image = new Image(null, data);
        GC graphics = new GC(image);
        try {
            graphics.setFont(ResourceManager.getFont("Time New Roman", 10, SWT.NORMAL));
            // graphics.setTextAntialias(SWT.ON);
            graphics.drawString("Custom", 5, 0);
        } finally {
            graphics.dispose();
        }
        ResourceManager.addImage(key, image);
    }
    return image;
}
项目:jhc    文件:PixelsSWT.java   
/**
 * Creates a new instance
 * 
 * @param size the size
 * @param display the display
 * @param initialColor the initial color
 */
protected PixelsSWT(Dimension size, Display display, int initialColor) {

    // Init
    this.size = size;
    this.display = display;

    // Create buffer
    this.buffer = new byte[size.height * size.width * 4];
    this.source = new ImageData(size.width, size.height, 32, new PaletteData(0x00ff0000, 0x0000ff00, 0x000000ff), 1, buffer);

    // TODO: Potentially inefficient
    if (initialColor != 0) {
        for (int y = 0; y < size.height; y++) {
            for (int x = 0; x < size.width; x++) {
                set(x, y, initialColor);
            }
        }
    }
}
项目:ControlAndroidDeviceFromPC    文件:BaseHeapPanel.java   
/**
 * Creates a linear image of the heap data.
 * @param pixData
 * @param h
 * @param palette
 * @return
 */
protected ImageData createLinearHeapImage(byte[] pixData, int h, PaletteData palette) {
    int w = pixData.length / h;
    if (pixData.length % h != 0) {
        w++;
    }

    // Create the heap image.
    ImageData id = new ImageData(w, h, 8, palette);

    int x = 0;
    int y = 0;
    for (byte b : pixData) {
        if (b >= 0) {
            id.setPixel(x, y, b);
        }

        y++;
        if (y >= h) {
            y = 0;
            x++;
        }
    }

    return id;
}
项目:dawnsci    文件:ImageServiceBean.java   
/**
 * Clones everything apart from the data, mask and palette.
 */
public ImageServiceBean  clone() {
    ImageServiceBean ret = new ImageServiceBean();

    ret.min             = (min == null) ? null : min.doubleValue();
    ret.max             = (max == null) ? null : max.doubleValue();
    ret.lo              = lo;
    ret.hi              = hi;
    ret.alpha           = alpha;
    ret.histogramType   = histogramType;
    ret.logColorScale   = logColorScale;
    ret.logOffset       = logOffset;
    ret.maximumCutBound = cloneBound(maximumCutBound);
    ret.minimumCutBound = cloneBound(minimumCutBound);
    ret.nanBound        = cloneBound(nanBound);
    ret.origin          = origin;

    if (getPalette()!=null) {
        ret.palette = new PaletteData(getPalette().getRGBs());
    }
    return ret;
}
项目:swtknob    文件:Knob.java   
/**
 * Returns an invisible cursor
 * 
 * @return
 */
private Cursor getHiddenCursor() {
    Display display = getDisplay();
    Color white = display.getSystemColor(SWT.COLOR_WHITE);
    Color black = display.getSystemColor(SWT.COLOR_BLACK);
    PaletteData palette = new PaletteData(new RGB[] { white.getRGB(), black.getRGB() });
    ImageData sourceData = new ImageData(16, 16, 1, palette);
    sourceData.transparentPixel = 0;
    final Cursor cursor = new Cursor(display, sourceData, 0, 0);
    this.addDisposeListener(new DisposeListener(){
        @Override
        public void widgetDisposed(DisposeEvent arg0) {
            if (cursor != null && !cursor.isDisposed()) {
                cursor.dispose();
            }
        }
    });
    return cursor;
}
项目:AutoDeriv    文件:Decorator.java   
/** change the icon hue */
public static ImageDescriptor loadIcon(String filename, int hueOffset) {
    hueOffset = (int) ((Conf.DECO_ICON_COLOR.getHSB()[0]+360-83)%360);
    ImageDescriptor normal = loadIcon(filename);
    if(hueOffset==0) return normal;
    ImageData data = normal.getImageData();
    PaletteData pal = data.palette;
    RGB rgb = new RGB(0,0,0);

    for (int y = 0; y < data.height; y++) {
        for (int x = 0; x < data.width; x++) {
            int p = data.getPixel(x, y);
            rgb.red = (p & pal.redMask) >> -pal.redShift;
            rgb.green = (p & pal.greenMask) >> -pal.greenShift;
            rgb.blue = (p & pal.blueMask) >> -pal.blueShift;
            float[] hsb = rgb.getHSB();
            rgb = new RGB((hsb[0] + hueOffset) % 360, hsb[1], hsb[2]);
            p = (rgb.red << -pal.redShift) + (rgb.green << -pal.greenShift) + (rgb.blue << -pal.blueShift);
            data.setPixel(x, y, p);
        }
    }
    return ImageDescriptor.createFromImageData(data);
}
项目:DynamicSpotter    文件:ImageUtils.java   
/**
 * Converts the image to <code>ImageData</code>. Expects the
 * <code>DirectColorModel</code>.
 * 
 * @param bufferedImage
 *            the image to convert
 * @return the extracted image data
 */
public static ImageData convertToImageData(BufferedImage bufferedImage) {
    if (!(bufferedImage.getColorModel() instanceof DirectColorModel)) {
        throw new SWTException(SWT.ERROR_UNSUPPORTED_FORMAT);
    }

    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 components = colorModel.getComponentSize().length;
    int[] pixels = new int[components];
    for (int x = 0; x < data.width; x++) {
        for (int y = 0; y < data.height; y++) {
            raster.getPixel(x, y, pixels);
            int pixel = palette.getPixel(new RGB(pixels[0], pixels[1], pixels[2]));
            data.setPixel(x, y, pixel);
        }
    }
    return data;
}
项目:totallicks-tuxguitar    文件:PDFWriter.java   
/**
 * Crea un com.lowagie.text.Image a partir de un org.eclipse.swt.graphics.ImageData
 * @param data
 * @return
 */
public static Image convertToIText(ImageData data){
    try {
        PaletteData palette = data.palette;
        int width = data.width;
        int height = data.height;

        byte bytes[] = new byte[(width * height * 3)];
        for (int y = 0; y < height; y++) {
            for (int x = 0; x < width; x++) {
                RGB rgb = palette.getRGB(data.getPixel(x, y));
                bytes[y * (width * 3) + (x * 3)] = (byte)rgb.red;
                bytes[y * (width * 3) + (x * 3) + 1] = (byte)rgb.green;
                bytes[y * (width * 3) + (x * 3) + 2] = (byte)rgb.blue;
            }
        }
        return Image.getInstance(width,height,3,8,bytes);
    } catch (BadElementException e) {
        e.printStackTrace();
    }
    return null;
}
项目:fullsync    文件:TaskDecisionList.java   
protected Image buildTaskImage(Task t, Action a) {
    ImageData data = new ImageData((16 * 3) + 2, 16, 8, new PaletteData(255, 255, 255));
    data.transparentPixel = data.palette.getPixel(new RGB(0, 0, 0));

    Image image = new Image(null, data);
    GC g = new GC(image);
    try {
        drawSide(g, t, a, Location.SOURCE);
        drawSide(g, t, a, Location.DESTINATION);
        drawLocation(g, a);
    }
    finally {
        g.dispose();
    }
    return image;
}
项目:elexis-3-base    文件:EMediplanServiceImpl.java   
protected Optional<Image> getQrCode(@NonNull String json){
    String encodedJson = getEncodedJson(json);

    Hashtable<EncodeHintType, Object> hintMap = new Hashtable<>();
    hintMap.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.L);

    QRCodeWriter qrCodeWriter = new QRCodeWriter();
    try {
        BitMatrix bitMatrix =
            qrCodeWriter.encode(encodedJson, BarcodeFormat.QR_CODE, 470, 470, hintMap);
        int width = bitMatrix.getWidth();
        int height = bitMatrix.getHeight();

        ImageData data =
            new ImageData(width, height, 24, new PaletteData(0xFF, 0xFF00, 0xFF0000));
        for (int y = 0; y < height; y++) {
            for (int x = 0; x < width; x++) {
                data.setPixel(x, y, bitMatrix.get(x, y) ? 0x000000 : 0xFFFFFF);
            }
        }
        return Optional.of(new Image(Display.getDefault(), data));
    } catch (WriterException e) {
        LoggerFactory.getLogger(getClass()).error("Error creating QR", e);
        return Optional.empty();
    }
}
项目:team-explorer-everywhere    文件:CustomCompareConfiguration.java   
private Image getEmptyImage() {
    if (emptyImage != null) {
        return emptyImage;
    }

    final ImageData imageData = new ImageData(1, 1, 1, new PaletteData(new RGB[] {
        new RGB(0, 0, 0)
    }));
    imageData.transparentPixel = imageData.palette.getPixel(new RGB(0, 0, 0));
    emptyImage = new Image(Display.getDefault(), imageData);
    return emptyImage;
}
项目:TuxGuitar-1.3.1-fork    文件:ImageUtils.java   
/**
 * Crea una mascara a partir de src.
 * 
 * @param src
 * @param alpha
 * @param none
 * @return ImageData
 */
public static ImageData applyMask(ImageData src,RGB alpha,RGB none){
    ImageData maskData = new ImageData(src.width,src.height,1,new PaletteData(new RGB[]{ none,alpha }  ));
    for(int x = 0; x< maskData.width; x++) {
        for(int y = 0; y < maskData.height; y++) {
            RGB rgb = src.palette.getRGB(src.getPixel(x, y));
            if(rgb.red == alpha.red && rgb.green == alpha.green && rgb.blue == alpha.blue){
                maskData.setPixel(x, y, maskData.palette.getPixel(none));
            }else{
                maskData.setPixel(x, y, maskData.palette.getPixel(alpha));
            }
        }
    }
    return maskData;
}
项目:TranskribusSwtGui    文件:SWTUtil.java   
/**
     * Multiplies all pixels of the given ImageData with the given scalar factor
     * and returns a new image data
     */
    public static ImageData multScalar(ImageData data, double factor, boolean inPlace) {
        ImageData newImageData = inPlace ? data : 
                new ImageData (data.width, data.height, 24, new PaletteData (0xFF, 0xFF00, 0xFF0000));

        final int w = data.width;
        final int h = data.height;

        for (int x=0; x<w; ++x) {
            for (int y=0; y<h; ++y) {
                int p = data.getPixel(x, y);

                RGB rgb = data.palette.getRGB(p);

//              System.out.println("rgb = "+rgb);

                rgb.red = CoreUtils.bound(rgb.red *= factor, 0, 255);
                rgb.green = CoreUtils.bound(rgb.green *= factor, 0, 255);
                rgb.blue = CoreUtils.bound(rgb.blue *= factor, 0, 255);

//              rgb.red = CoreUtils.bound((int) Math.pow(rgb.red, gamma), 0, 255);
//              rgb.green = CoreUtils.bound((int) Math.pow(rgb.green, gamma), 0, 255);
//              rgb.blue = CoreUtils.bound((int) Math.pow(rgb.blue, gamma), 0, 255);

//              System.out.println("rgb2 = "+rgb);
                newImageData.setPixel(x, y, newImageData.palette.getPixel(rgb));
            }
        }

        return newImageData;
    }
项目:ether    文件:SWTImageSupport.java   
private static PaletteData getPaletteData(ComponentFormat format) throws IOException {
    switch (format) {
    case RGB:
        return RGB8;
    case RGBA:
        return RGBA8;
    default:
        throw new IllegalArgumentException("unsupported component format: " + format);
    }
}
项目:ForgedUI-Eclipse    文件:SnapFeedbackPolicy.java   
/**
 * @see org.eclipse.draw2d.Figure#paintFigure(org.eclipse.draw2d.Graphics)
 */
protected void paintFigure(Graphics graphics) {
    if (opacity != FRAMES) {
        if (image != null) {
            image.dispose();
            count--;
            image = null;
        }
        if (opacity != FRAMES - 1) {
            Display display = Display.getCurrent();
            PaletteData pData = new PaletteData(0xFF, 0xFF00, 0xFF0000);
            Color localBackgroundColor = createMixedColor();
            int fillColor = pData.getPixel(localBackgroundColor
                    .getRGB());
            localBackgroundColor.dispose();
            ImageData iData = new ImageData(1, 1, 24, pData);
            iData.setPixel(0, 0, fillColor);
            iData.setAlpha(0, 0, 255 * opacity / FRAMES);
            image = new Image(display, iData);
            count++;
        }
        Display.getCurrent().timerExec(100, new Runnable() {
            public void run() {
                opacity = Math.min(FRAMES, opacity + 1);
                repaint();
            }
        });
    }
    Rectangle r = getBounds();
    if (image != null)
        graphics.drawImage(image, 0, 0, 1, 1, r.x, r.y, r.width,
                r.height);
    else
        super.paintFigure(graphics);
}
项目:NEXCORE-UML-Modeler    文件:TitleBarBorder.java   
/**
 * getRotatedLabelImage
 *  
 * @param figure
 * @param rect
 * @return Image
 */
private Image getRotatedLabelImage(IFigure figure, Rectangle rect) {
    // 가로로 된 타이틀 사각형
    Rectangle temp = rect.getCopy().transpose();
    temp.x = temp.y = 0;

    // 이미지를 생성하고 이미지에 대한 GC를 생성한다.
    PaletteData palette = new PaletteData(0xFF, 0xFF00, 0xFF0000);

    ImageData imageData = new ImageData(temp.width, temp.height, 24, palette);
    Image image = new Image(Display.getCurrent(), imageData);
    GC gc = new GC(image);
    Graphics g = new SWTGraphics(gc);
    drawTitleBar(figure, g, temp);
    gc.dispose();

    ImageData data1 = image.getImageData();
    ImageData data2 = new ImageData(data1.height, data1.width, data1.depth, data1.palette);
    for (int x1 = 0; x1 < data1.width; x1++) {
        for (int y1 = 0; y1 < data1.height; y1++) {
            int x2 = y1;
            int y2 = -x1 + data1.width - 1;
            int pixel = data1.getPixel(x1, y1);
            data2.setPixel(x2, y2, pixel);
        }
    }

    Image result = new Image(Display.getCurrent(), data2);
    image.dispose();
    return result;
}
项目:statecharts    文件:SimpleSnapFeedbackPolicy.java   
/**
 * @see org.eclipse.draw2d.Figure#paintFigure(org.eclipse.draw2d.Graphics)
 */
protected void paintFigure(Graphics graphics) {
    if (opacity != FRAMES) {
        if (image != null) {
            image.dispose();
            count--;
            image = null;
        }
        if (opacity != FRAMES - 1) {
            Display display = Display.getCurrent();
            PaletteData pData = new PaletteData(0xFF, 0xFF00, 0xFF0000);
            Color localBackgroundColor = createMixedColor();
            int fillColor = pData.getPixel(localBackgroundColor.getRGB());
            localBackgroundColor.dispose();
            ImageData iData = new ImageData(1, 1, 24, pData);
            iData.setPixel(0, 0, fillColor);
            iData.setAlpha(0, 0, 255 * opacity / FRAMES);
            image = new Image(display, iData);
            count++;
        }
        Display.getCurrent().timerExec(100, new Runnable() {
            public void run() {
                opacity = Math.min(FRAMES, opacity + 1);
                repaint();
            }
        });
    }
    Rectangle r = getBounds();
    if (image != null)
        graphics.drawImage(image, 0, 0, 1, 1, r.x, r.y, r.width, r.height);
    else
        super.paintFigure(graphics);
}
项目:SMVHunter    文件:ScreenShotDialog.java   
/**
 * Updates the display with {@link #mRawImage}.
 * @param shell
 */
private void updateImageDisplay(Shell shell) {
    Image image;
    if (mRawImage == null) {
        Display display = shell.getDisplay();
        image = ImageLoader.createPlaceHolderArt(
                display, 320, 240, display.getSystemColor(SWT.COLOR_BLUE));

        mSave.setEnabled(false);
        mBusyLabel.setText("Screen not available");
    } else {
        // convert raw data to an Image.
        PaletteData palette = new PaletteData(
                mRawImage.getRedMask(),
                mRawImage.getGreenMask(),
                mRawImage.getBlueMask());

        ImageData imageData = new ImageData(mRawImage.width, mRawImage.height,
                mRawImage.bpp, palette, 1, mRawImage.data);
        image = new Image(getParent().getDisplay(), imageData);

        mSave.setEnabled(true);
        mBusyLabel.setText("Captured image:");
    }

    mImageLabel.setImage(image);
    mImageLabel.pack();
    shell.pack();

    // there's no way to restore old cursor; assume it's ARROW
    shell.setCursor(shell.getDisplay().getSystemCursor(SWT.CURSOR_ARROW));
}
项目:PDFReporter-Studio    文件:ColorPreviewWidget.java   
/**
 * update the preview area with the set old and new color
 */
public void updatePreview(){
    if (newColor == null) return;
    Rectangle rect = colorComposite.getClientArea();
    ImageData imageData=new ImageData(Math.max(1, rect.width),Math.max(1, rect.height),32,new PaletteData(0xFF0000,0xFF00,0xFF));
    Image newImage = new Image(getDisplay(), imageData);
   GC gc = new GC(newImage);
   gc.setAntialias(SWT.ON);
   //If there is an old color set paint also it into the preview area to compare it with the new one,
   //otherwise print only the new one
   if (oldColor != null){
    gc.setAlpha(255);
    gc.setBackground(getDisplay().getSystemColor(SWT.COLOR_WHITE));
     gc.fillRectangle(0, 0, imageData.width, imageData.height/2);
     gc.setAlpha(alphaNewColor);
     gc.setBackground(ResourceManager.getColor(newColor));
     gc.fillRectangle(0, 0, imageData.width, imageData.height/2);
    gc.setAlpha(255);
    gc.setBackground(getDisplay().getSystemColor(SWT.COLOR_WHITE));
     gc.fillRectangle(0, imageData.height/2, imageData.width, imageData.height);
     gc.setAlpha(alphaOldColor);
     gc.setBackground(ResourceManager.getColor(oldColor));
     gc.fillRectangle(0, imageData.height/2, imageData.width, imageData.height);
   } else {
    gc.setAlpha(255);
    gc.setBackground(getDisplay().getSystemColor(SWT.COLOR_WHITE));
     gc.fillRectangle(0, 0, imageData.width, imageData.height);
     gc.setAlpha(alphaNewColor);
     gc.setBackground(ResourceManager.getColor(newColor));
     gc.fillRectangle(0, 0, imageData.width, imageData.height);
   }
   if (actualPreviewImage != null){
    actualPreviewImage.dispose();
   }
   gc.dispose();
   actualPreviewImage = newImage;
   colorComposite.setBackgroundImage(newImage);
}
项目:PDFReporter-Studio    文件:SWTImageEffects.java   
/**
 * Enlarge the specified image applying a "border" of the specified size and
 * with a specified background. If no background RGB value is specified a 
 * default white background is used.
 * 
 * @param originalImageData the original image data
 * @param size the additional size for the image area
 * @param backgroundRGB the preferred background, can be <code>null</null>
 * @return the new image data
 */
public static ImageData extendArea(ImageData originalImageData, int size, RGB backgroundRGB) {
    if (originalImageData == null)
        return null;
    if (size == 0)
        return originalImageData;
    // Enlarge the image area in order to be able to draw the border
    ImageData newImageData = new ImageData(originalImageData.width + size * 2, originalImageData.height + size * 2, 24,
            new PaletteData(0xFF, 0xFF00, 0xFF0000));
    int[] pixels = new int[originalImageData.width];

    // Use a white background RGB only if there is no
    // other background specified.
    RGB backRGB = new RGB(255, 255, 255);
    if (backgroundRGB != null) {
        backRGB = backgroundRGB;
    }
    // Prepare a default background
    int pixel = newImageData.palette.getPixel(backRGB);
    int[] backPixels = new int[newImageData.width];
    for (int i = 0; i < backPixels.length; i++) {
        backPixels[i] = pixel;
    }
    for (int row = 0; row < newImageData.height; row++) {
        newImageData.setPixels(0, row, newImageData.width, backPixels, 0);
    }

    // copy the original image data
    for (int row = size; row < size + originalImageData.height; row++) {
        originalImageData.getPixels(0, row - size, originalImageData.width, pixels, 0);
        for (int col = 0; col < pixels.length; col++) {
            pixels[col] = newImageData.palette.getPixel(originalImageData.palette.getRGB(pixels[col]));
        }
        newImageData.setPixels(size, row, originalImageData.width, pixels, 0);
    }
    return newImageData;
}
项目:PDFReporter-Studio    文件:SWTImageEffects.java   
/**
 * @param originalImageData The image data to be embossed.
 * Transparency information will be ignored.
 * @param grayLevel Minimum base level gray to use in embossed outcome.
 * @return An embossed copy of the image data.
 */
public static ImageData emboss(ImageData originalImageData, int grayLevel) {
    // prepare new image data with 24-bit direct palette to hold embossed copy of image
    ImageData newImageData = new ImageData (originalImageData.width, originalImageData.height, 24, new PaletteData (0xFF, 0xFF00, 0xFF0000));
    grayLevel = grayLevel < 0 ? 0 : grayLevel > 255 ? 255 : grayLevel;  
    int rDiff = 0, gDiff = 0, bDiff = 0, gray = 0; // store intensity differences
    int[] rowResult = new int[newImageData.width];
    RGB[] rowRGBData1 = new RGB[newImageData.width], rowRGBData2 = new RGB[newImageData.width];
    getRGBRowData(originalImageData, rowRGBData2, 0); // get first line of pixel data   
    for (int row=0; row <newImageData.height; row++ ) {
        RGB[] tempRow = rowRGBData1;
        // swap references. the second row of pixel data now becomes the first
        if (row < newImageData.height - 1) {
            rowRGBData1 = rowRGBData2;
            rowRGBData2 = tempRow;
            getRGBRowData(originalImageData, rowRGBData2, row + 1);
        }
        for (int col = 0; col < newImageData.width; col++) {
            // for first two columns, compare the target pixel to the pixel above
            if (col  < 2) {
                rDiff = Math.abs(rowRGBData2[col].red - rowRGBData1[col].red);
                gDiff = Math.abs(rowRGBData2[col].green - rowRGBData1[col].green);
                bDiff = Math.abs(rowRGBData2[col].blue - rowRGBData1[col].blue);
            } else {
                // for all columns after the second column, compare the target pixel
                // to the pixel two pixels to the left on the row above
                rDiff = Math.abs(rowRGBData2[col].red - rowRGBData1[col-2].red);
                gDiff = Math.abs(rowRGBData2[col].green - rowRGBData1[col-2].green);
                bDiff = Math.abs(rowRGBData2[col].blue - rowRGBData1[col-2].blue);
            }               
            // calculate gray level
            gray = Math.min(grayLevel + (Math.max(rDiff, Math.max(gDiff, bDiff))), 255);
            rowResult[col] = newImageData.palette.getPixel (new RGB(gray, gray, gray));
        }
        newImageData.setPixels(0, row, newImageData.width, rowResult, 0);           
    }
    return newImageData;
}
项目:PDFReporter-Studio    文件:ScrollableThumbnail.java   
public SelectorFigure() {
    PaletteData pData = new PaletteData(0xFF, 0xFF00, 0xFF0000);
    RGB rgb = ColorConstants.menuBackgroundSelected.getRGB();
    int fillColor = pData.getPixel(rgb);
    iData = new ImageData(1, 1, 24, pData);
    iData.setPixel(0, 0, fillColor);
    iData.setAlpha(0, 0, 55);
    iBounds = new Rectangle(0, 0, 1, 1);
}
项目:screenshot    文件:ScreenShotDialog.java   
/**
 * Updates the display with {@link #mRawImage}.
 * @param shell
 */
private void updateImageDisplay(Shell shell) {
    Image image;
    if (mRawImage == null) {
        Display display = shell.getDisplay();
        image = createPlaceHolderArt(
                display, 320, 240, display.getSystemColor(SWT.COLOR_BLUE));

        mSave.setEnabled(false);
        mBusyLabel.setText("Screen not available");
    } else {
        // convert raw data to an Image.
        PaletteData palette = new PaletteData(
                mRawImage.getRedMask(),
                mRawImage.getGreenMask(),
                mRawImage.getBlueMask());

        ImageData imageData = new ImageData(mRawImage.width, mRawImage.height,
                mRawImage.bpp, palette, 1, mRawImage.data);
        imageData = imageData.scaledTo((int)(mRawImage.width * mScale), (int)(mRawImage.height * mScale));
        image = new Image(getParent().getDisplay(), imageData);

        mSave.setEnabled(true);
        mBusyLabel.setText("Captured image:");
    }

    mImageLabel.setImage(image);
    mImageLabel.pack();
    shell.pack();

    // there's no way to restore old cursor; assume it's ARROW
    shell.setCursor(shell.getDisplay().getSystemCursor(SWT.CURSOR_ARROW));
}
项目:gama    文件:GamaColors.java   
/**
 * Get the color of the icon passed in parameter (supposing it's mono-colored)
 * 
 * @param create
 * @return
 */
public static GamaUIColor get(final GamaIcon icon) {
    final Image image = icon.image();
    final ImageData data = image.getImageData();
    final PaletteData palette = data.palette;
    final int pixelValue = data.getPixel(0, 0);
    return get(palette.getRGB(pixelValue));
}
项目:APICloud-Studio    文件:CSSColorsUI.java   
public static Image toImage(String color, int height, int width)
{
    RGB actualColor = toRGB(color);
    PaletteData paletteData = new PaletteData(new RGB[] { actualColor, new RGB(0, 0, 0) });
    ImageData imageData = new ImageData(16, 16, 1, paletteData);
    return new Image(Display.getDefault(), imageData);
}
项目:mytourbook    文件:CustomControlContribution.java   
/**
     * The control item implementation of this <code>IContributionItem</code> method calls the
     * <code>createControl</code> framework method to create a control under the given parent, and
     * then creates a new tool item to hold it. Subclasses must implement <code>createControl</code>
     * rather than overriding this method.
     */
    @Override
    public final void fill(final ToolBar toolbar, final int index) {

        // toolbar is currently (10.7) two times created
        if (_image != null) {
            _image.dispose();
            _image = null;
        }

        final Control control = createControl(toolbar);
        final Point controlSize = control.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);

        final ToolItem toolItem = new ToolItem(toolbar, SWT.SEPARATOR);
        toolItem.setControl(control);
        toolItem.setWidth(controlSize.x);

        final PaletteData palette = new PaletteData(new RGB[] { new RGB(0, 0, 0) });

        final ImageData imageData = new ImageData(1, controlSize.y, 1, palette);
//      final ImageData imageData = new ImageData(1, 1, 1, new PaletteData(new RGB[] { new RGB(0, 0, 0) }));
//      final ImageData imageData = new ImageData(1, //
//              //
////                textSize.y + 10,
//              controlSize.y,
//              1,
//              new PaletteData(new RGB[] { new RGB(0, 0, 0) }));
        imageData.transparentPixel = 0;
        _image = new Image(Display.getCurrent(), imageData);

        final ToolItem imageItem = new ToolItem(toolbar, SWT.PUSH);
        imageItem.setImage(_image);
    }