You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-users@xmlgraphics.apache.org by Harshini Madurapperuma <ha...@ifs.lk> on 2007/04/10 13:35:25 UTC

Add Background Image to AWT preview? Need Help !!

Hi all;
 
Is there a way to add a background image to AWT preview?
 
Thanx
Harshini

Re: Add Background Image to AWT preview? Need Help !!

Posted by Warren Young <wa...@etr-usa.com>.
Harshini Madurapperuma wrote:
>  
> Is there a way to add a background image to AWT preview?

I don't know anything about FOP's AWT features, but if you can get the 
rendered preview as a bitmap, you can generate a composite with a very 
simple image processing algorithm called a multiply.  (If you have 
Photoshop, you can try this out before you start coding: it's one of the 
layer blend modes.)

It works like this: For each pixel, get its luminance as a value from 0 
to 1 (darkest to brightest) and multiply the two together.  Then, modify 
the background's luminance with the new value.  Where the FOP output is 
white (the "paper"), nothing will happen to the background because 1 
times x is x.  Where there is text, the background will be obliterated, 
since 0 times x is 0.  If FOP generates any grays (such as for 
antialiasing) they will simply darken the background proportionately to 
the brightness of the gray.

This will work best if the document has no color, only shades of gray. 
There is no such restriction on the background.

If AWT doesn't have a way to get a luminosity for a pixel, look up RGB 
to HSB conversion on the web.  Don't use an RGB to HSL algorithm: HSL is 
a more complex color space than HSB, with no benefit here.  The 
luminosity ("brightness") in HSB goes from 0 to 1, just as we want here, 
but in HSL it goes from -1 to +1.  The HSL <-> RGB conversions are also 
harder to calculate correctly than HSB <-> RGB.

---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org