Hi,

I'm having trouble with LookupOp on Java 1.3 and hope someone will be
able to help. I'm trying to fill an image of TYPE_INT_ARGB with a
given color while leaving the alpha channel intact and this should be
easy to do with LookupOp. If I create a ByteLookupOp like this:

                byte[] rt = new byte[256];
                byte[] gt = new byte[256];
                byte[] bt = new byte[256];
                for (int i = 0; i < 255; i++) {
                        rt[i] = r;
                        gt[i] = g;
                        bt[i] = b;
                }
                byte[][] table = { rt, gt, bt };
                LookupTable lookup = new ByteLookupTable(0, table);
                op = new LookupOp(lookup, null);
                image = op.filter(image, null);

The Java VM crashes when I call op.filter(). This happens on both
Solaris and Windows. If I replace the ByteLookupOp with a
ShortLookupOp I get an exception saying that the destination image
has only two bands whereas the source has 4 bands. I got this code
from the "Java 2D Graphics book" by the way.

I decided to go my own way and write a class:

class ColorLookupTable extends LookupTable {
        private byte r, g, b;

        public ColorLookupTable(Color color) {
                super(0, 4);
                r = (byte)color.getRed();
                g = (byte)color.getGreen();
                b = (byte)color.getBlue();
        }

        public int[] lookupPixel(int[] src, int[] dst){
                if (dst == null)
                        dst = new int[src.length];
                dst[0] = r;
                dst[1] = g;
                dst[2] = b;
                dst[3] = src[3];
                return dst;
        }
}

This works fine, but I have three questions: Why do I have to make my
array have the order RGBA (by experiment) when my image is
TYPE_INT_ARGB? Is using my own class slower as it seems that
ByteLookupTable is treated as a special case and performed in native
code (hence the VM crash)? Am I going about things in completely the
wrong way?

Thanks

Jerry

Jerry Huxtable
http://www.jhlabs.com

===========================================================================
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