FileDocCategorySizeDatePackage
Utils.javaAPI DocAzureus 3.0.3.42749Thu Feb 09 19:42:44 GMT 2006org.gudy.azureus2.ui.swt.components.images

Utils

public class Utils extends Object
author
Olivier Chalouhi

Fields Summary
Constructors Summary
Methods Summary
public static org.eclipse.swt.graphics.ImagerenderTransparency(org.eclipse.swt.widgets.Display display, org.eclipse.swt.graphics.Image background, org.eclipse.swt.graphics.Image foreground)

    //Checks
    if( display == null || display.isDisposed() ||
        background == null || background.isDisposed() ||        
        foreground == null || foreground.isDisposed()
       ) return null;
    Rectangle r1 = background.getBounds();
    Rectangle r2 = foreground.getBounds();
    if(! r1.equals(r2)) return null;
    
    Image image = new Image(display,r1);
    ImageData backData = background.getImageData();
    ImageData foreData = foreground.getImageData();
    ImageData imgData  = image.getImageData();    
        
    for(int y = 0 ; y < foreData.height ; y++) {
      for(int x = 0 ; x < foreData.width ; x++) {
       int cBack = backData.getPixel(x,y);       
       int cFore = foreData.getPixel(x,y);
       int aFore = foreData.getAlpha(x,y);
       
       int rBack =  cBack         & 0xFF;
       int gBack = (cBack >> 8)  & 0xFF;
       int bBack = (cBack >> 16) & 0xFF;
       
       int rFore =  cFore         & 0xFF;
       int gFore = (cFore >> 8)  & 0xFF;
       int bFore = (cFore >> 16) & 0xFF;
       
       int r = (rBack * aFore + (255 - aFore) * rFore) / 255;
       r = r & 0xFF;
       int g = (gBack * aFore + (255 - aFore) * gFore) / 255;
       g = g & 0xFF;
       int b = (bBack * aFore + (255 - aFore) * bFore) / 255;
       b = b & 0xFF;
       
       int color = r + g << 8 + b << 16;
       imgData.setPixel(x,y,color);
      }
    }
    return image;