Hi Eddie,

The typical way to merge an alpha channel into another image is to use
the AlphaComposite.DstIn mode.  This takes the destination color and
multiplies it by the source alpha.  Wherever the source was transparent
the destination becomes transparent.  Wherever the source was opaque the
destination is untouched.  The destination is blended towards
transparent
wherever the source is translucent.  The destination colors do not
change.

To get a grayscale image to be interpreted as alpha, simply associate it
with an IndexColorModel in which each component has the alpha value of
its index:

        int rgbs[] = new int[256];
        for (int i = 0; i < 256; i++) {
                rgbs[i] = i << 24;
                // OR rgbs[i] = (i << 24) | (i < 16) | (i << 8) | i;
                // OR rgbs[i] = (i << 24) | (any lower 24 bits you want);
        }

Thus index 0 is transparent, index 255 is opaque, all others are
translucent.
Since the DstIn operation ignores the source color information, the
lower
24 bits of the palette colors are irrelevent but you may want to set
them
to something interesting for your own purposes.

The sequence would be:

        Copy src image to temp Argb image using Src
        Composite "grayalpha" image onto temp image using DstIn
        Composite temp image onto dest image using SrcOver

SrcIn can be used in a similar way, but the order in which you merge
the buffers would be a little different:

        Copy "grayalpha" image to temp IntArgb image using Src
        Composite src image onto temp using SrcIn
        Composite temp image onto dest image using SrcOver

Depending on which loops we've created optimal implementations of one
or the other of these sequences may work faster for you.  Also,
depending
on the format of your src or "grayalpha" images and whether or not you
need to reuse it later, you may be able to reuse them as the temp image.

(Note that this is all theory.  I haven't actually tried this in the
lab.
 Let me know how it works for you...)

                                ...jim

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA2D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to