1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
\r
3 * in Industry THTH ry.
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
15 package org.simantics.utils.ui.gfx;
\r
17 import org.eclipse.jface.resource.ImageDescriptor;
\r
18 import org.eclipse.swt.SWT;
\r
19 import org.eclipse.swt.graphics.ImageData;
\r
20 import org.eclipse.swt.graphics.PaletteData;
\r
21 import org.eclipse.swt.graphics.RGB;
\r
24 * RGBAdjustmentImageDescriptor
\r
25 * @author Toni Kalajainen
\r
27 @SuppressWarnings("deprecation")
\r
28 public class RGBAdjustmentImageDescriptor extends ImageDescriptor {
\r
30 public static final PaletteData DEFAULT_PALETTEDATA =
\r
31 new PaletteData(0x00ff0000, 0x0000ff00, 0x000000ff);
\r
33 ImageDescriptor desc;
\r
36 public RGBAdjustmentImageDescriptor(ImageDescriptor image, int r, int g, int b)
\r
45 public ImageData getImageData() {
\r
46 PaletteData palette = DEFAULT_PALETTEDATA;
\r
47 ImageData orig = ImageCache.getInstance().getImage(desc).getImageData();
\r
48 ImageData id = new ImageData(orig.width, orig.height, 24, palette);
\r
50 PaletteData origPalette = orig.palette;
\r
52 ImageData mask = null;
\r
53 if (orig.getTransparencyType()==SWT.TRANSPARENCY_MASK ||
\r
54 orig.getTransparencyType()==SWT.TRANSPARENCY_PIXEL)
\r
55 mask = orig.getTransparencyMask();
\r
57 for (int x=0; x<orig.width; x++)
\r
58 for (int y=0; y<orig.height; y++) {
\r
59 RGB rgb = origPalette.getRGB( orig.getPixel(x, y) );
\r
61 int nr = Math.min(255, (rgb.red*r)>>8);
\r
62 int ng = Math.min(255, (rgb.green*g)>>8);
\r
63 int nb = Math.min(255, (rgb.blue*b)>>8);
\r
65 rgb = new RGB( nr, ng, nb );
\r
66 id.setPixel(x, y, palette.getPixel(rgb));
\r
69 alpha = orig.getAlpha(x, y);
\r
71 alpha = (mask.getPixel(x, y)==1?255:0);
\r
72 id.setAlpha(x, y, alpha);
\r
78 public boolean equals(Object obj) {
\r
79 if (obj==this) return true;
\r
80 if (!(obj instanceof RGBAdjustmentImageDescriptor))
\r
82 RGBAdjustmentImageDescriptor other = (RGBAdjustmentImageDescriptor) obj;
\r
83 return other.desc.equals(desc) && other.r==r && other.g==g && other.b==b;
\r
87 public int hashCode() {
\r
88 return desc.hashCode() ^ r^g^b;
\r