X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.utils.ui%2Fsrc%2Forg%2Fsimantics%2Futils%2Fui%2Fgfx%2FRGBAdjustmentImageDescriptor.java;fp=bundles%2Forg.simantics.utils.ui%2Fsrc%2Forg%2Fsimantics%2Futils%2Fui%2Fgfx%2FRGBAdjustmentImageDescriptor.java;h=dfbdb1a0045b40ba32d3b5b52833a549470f1e97;hb=0ae2b770234dfc3cbb18bd38f324125cf0faca07;hp=4ae69e691f87747380d8327e5e6e6bf37f352ba2;hpb=24e2b34260f219f0d1644ca7a138894980e25b14;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.utils.ui/src/org/simantics/utils/ui/gfx/RGBAdjustmentImageDescriptor.java b/bundles/org.simantics.utils.ui/src/org/simantics/utils/ui/gfx/RGBAdjustmentImageDescriptor.java index 4ae69e691..dfbdb1a00 100644 --- a/bundles/org.simantics.utils.ui/src/org/simantics/utils/ui/gfx/RGBAdjustmentImageDescriptor.java +++ b/bundles/org.simantics.utils.ui/src/org/simantics/utils/ui/gfx/RGBAdjustmentImageDescriptor.java @@ -1,91 +1,91 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Association for Decentralized Information Management - * in Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -/* - * 27.12.2006 - */ -package org.simantics.utils.ui.gfx; - -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.ImageData; -import org.eclipse.swt.graphics.PaletteData; -import org.eclipse.swt.graphics.RGB; - -/** - * RGBAdjustmentImageDescriptor - * @author Toni Kalajainen - */ -@SuppressWarnings("deprecation") -public class RGBAdjustmentImageDescriptor extends ImageDescriptor { - - public static final PaletteData DEFAULT_PALETTEDATA = - new PaletteData(0x00ff0000, 0x0000ff00, 0x000000ff); - - ImageDescriptor desc; - int r,g,b; - - public RGBAdjustmentImageDescriptor(ImageDescriptor image, int r, int g, int b) - { - desc = image; - this.r = r; - this.g = g; - this.b = b; - } - - @Override - public ImageData getImageData() { - PaletteData palette = DEFAULT_PALETTEDATA; - ImageData orig = ImageCache.getInstance().getImage(desc).getImageData(); - ImageData id = new ImageData(orig.width, orig.height, 24, palette); - id.setAlpha(0,0,0); - PaletteData origPalette = orig.palette; - - ImageData mask = null; - if (orig.getTransparencyType()==SWT.TRANSPARENCY_MASK || - orig.getTransparencyType()==SWT.TRANSPARENCY_PIXEL) - mask = orig.getTransparencyMask(); - - for (int x=0; x>8); - int ng = Math.min(255, (rgb.green*g)>>8); - int nb = Math.min(255, (rgb.blue*b)>>8); - - rgb = new RGB( nr, ng, nb ); - id.setPixel(x, y, palette.getPixel(rgb)); - int alpha; - if (mask==null) - alpha = orig.getAlpha(x, y); - else - alpha = (mask.getPixel(x, y)==1?255:0); - id.setAlpha(x, y, alpha); - } - return id; - } - - @Override - public boolean equals(Object obj) { - if (obj==this) return true; - if (!(obj instanceof RGBAdjustmentImageDescriptor)) - return false; - RGBAdjustmentImageDescriptor other = (RGBAdjustmentImageDescriptor) obj; - return other.desc.equals(desc) && other.r==r && other.g==g && other.b==b; - } - - @Override - public int hashCode() { - return desc.hashCode() ^ r^g^b; - } - -} +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +/* + * 27.12.2006 + */ +package org.simantics.utils.ui.gfx; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.ImageData; +import org.eclipse.swt.graphics.PaletteData; +import org.eclipse.swt.graphics.RGB; + +/** + * RGBAdjustmentImageDescriptor + * @author Toni Kalajainen + */ +@SuppressWarnings("deprecation") +public class RGBAdjustmentImageDescriptor extends ImageDescriptor { + + public static final PaletteData DEFAULT_PALETTEDATA = + new PaletteData(0x00ff0000, 0x0000ff00, 0x000000ff); + + ImageDescriptor desc; + int r,g,b; + + public RGBAdjustmentImageDescriptor(ImageDescriptor image, int r, int g, int b) + { + desc = image; + this.r = r; + this.g = g; + this.b = b; + } + + @Override + public ImageData getImageData() { + PaletteData palette = DEFAULT_PALETTEDATA; + ImageData orig = ImageCache.getInstance().getImage(desc).getImageData(); + ImageData id = new ImageData(orig.width, orig.height, 24, palette); + id.setAlpha(0,0,0); + PaletteData origPalette = orig.palette; + + ImageData mask = null; + if (orig.getTransparencyType()==SWT.TRANSPARENCY_MASK || + orig.getTransparencyType()==SWT.TRANSPARENCY_PIXEL) + mask = orig.getTransparencyMask(); + + for (int x=0; x>8); + int ng = Math.min(255, (rgb.green*g)>>8); + int nb = Math.min(255, (rgb.blue*b)>>8); + + rgb = new RGB( nr, ng, nb ); + id.setPixel(x, y, palette.getPixel(rgb)); + int alpha; + if (mask==null) + alpha = orig.getAlpha(x, y); + else + alpha = (mask.getPixel(x, y)==1?255:0); + id.setAlpha(x, y, alpha); + } + return id; + } + + @Override + public boolean equals(Object obj) { + if (obj==this) return true; + if (!(obj instanceof RGBAdjustmentImageDescriptor)) + return false; + RGBAdjustmentImageDescriptor other = (RGBAdjustmentImageDescriptor) obj; + return other.desc.equals(desc) && other.r==r && other.g==g && other.b==b; + } + + @Override + public int hashCode() { + return desc.hashCode() ^ r^g^b; + } + +}