views:

11

answers:

1

I need to port a bit of ActionScript code into Java. btw, never touched a as file in my life.

So far it's been easy, because AS syntax is fairly simple. There's a piece of code that calls

bmpData.paletteMap( bmpData , rect, point, rArray, gArray, bArray); //all arrays of size 256

The entire file is kind of dependent on this function and it is kind of alien to me, i need to understand what it actually does so that i can write my own implementation of paletteMap.

I don't need the code, just an explanation of the procedure. If it's already been done, that's even better.

edit: Here's what i make of the algorithm, is it correct?

private static void paletteMap(int[] rgbStream,int [] r,int[] g,int []b)
    {
        if(r == null || g == null || b == null)
            throw new NullPointerException("Array can't null array.");

        for(int i = 0 ; i  < rgbStream.length; i++)
        {
            int pixel = rgbStream[i], newPixel = 0;

            newPixel = b[pixel & 0xFF]; pixel >>= 8;
            newPixel |= g[pixel & 0xFF] << 8; pixel >>= 8;
            newPixel |= r[pixel & 0xFF] << 16;
            rgbStream[i] = newPixel;
        }
    }

Thanks.

A: 

Taken from AS3 docs, check the BitmapData Class for more detailed information
http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/

Remaps the color channel values in an image that has up 
to four arrays of color palette data, one for each channel.
PatrickS
@PatrickS, i appreciate your answer, but i found the description on that page a bit confusing. I'd like a more descriptive explanation of the process.
st0le