Trying to read raw image data in Java via JNI

I am using JNI to get raw image data in the following format:

Image data is returned in DATA32 format (32 bits) per pixel in a linear array ordered at the upper left of the image, in the lower right direction from left to right to left. Each pixel has the top 8 bits as its alpha channel, and the bottom 8 bits is the blue channel, hence the ARGB pixel bits (most to least significant, 8 bits per channel). You have to return data at some point.

DATA32 format is essentially an unsigned int in C.

So I get an int [] array and then try to create a Buffered Image from it

        int w = 1920;
        int h = 1200;

        BufferedImage b = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); 


        int[] f = (new Capture()).capture();
        for(int i = 0; i < f.length; i++){;
                b.setRGB(x, y, f[i]);
        }

      

f - array with pixel data.

According to Java documentation, this should work as BufferedImage.TYPE_INT_ARGB:

Represents an image with 8-bit RGBA color components packed into whole pixels. The image has a DirectColorModel with alpha. These colors in this image are considered non-multiplied with alpha. When this type is used as the imageType argument for the BufferedImage constructor, the generated image is consistent with images created in JDK1.1 and earlier.

If 8-bit RGBA doesn't mean that all the components combined together are encoded into 8 bits? But this is impossible.

This code works, but the generated image looks nothing like the image it should produce. There are tons of artifacts. Can anyone see something clearly wrong here?

Note. I am getting data with pixels

imlib_context_set_image(im);
data = imlib_image_get_data();

      

in my C code using imlib2 library with api http://docs.enlightenment.org/api/imlib2/html/imlib2_8c.html#17817446139a645cc017e9f79124e5a2

0


a source to share


1 answer


I'm an idiot.

This is just a mistake.

I forgot to include how I calculate x, y above.

I mainly used



 int x = i%w;
 int y = i/h;

      

in a for loop, which is not correct. Should be

 int x = i%w;
 int y = i/w;

      

I can't believe I made this stupid mistake.

0


a source







All Articles