Convert a RGB565 byte[] to Luminance source

Skip to first unread message


Sep 9, 2014, 7:26:07 AM9/9/14
I have a byte[] of RGB565 and I want to convert it to the YUV byte[]. I tried other methods but i have performance issues(poor performance 4 fps). It'll be faster if I use the incoming RGB byte[].
Guys help me.


Lachezar Dobrev

Sep 9, 2014, 8:20:54 AM9/9/14
to Umresh, zxing
You should "probably" try and use the RGB as luminance source,
rather than converting to YUV and then using that for luminance

This implementation is RGB-888, so a RGB-565 might require some
changing in the shift-and-mask operations.
Also this implementation converts the whole frame upfront, which
might not be the best solution, but you can try.

I just realised, that RGB-565 does not fit in a byte. Is it int[],
or is it two bytes per pixel?


Sep 9, 2014, 9:09:30 AM9/9/14

I'm using this vuforia code
if (imageRGB565 != null) {
int imageWidth = imageRGB565.getWidth();
int imageHeight = imageRGB565.getHeight();
int stride = imageRGB565.getStride();
ByteBuffer pixels = imageRGB565.getPixels();
byte[] pixelArray = new byte[pixels.remaining()];
pixels.get(pixelArray, 0, pixelArray.length);

saveCapturedImage(pixelArray, imageWidth, imageHeight);
here I get byte[] (pixelArray) and the frame format is set to RGB565. So I converted it to bitmap and used RGBLuminance for bitmap version. I tried pixel version too but it didn't detect but bitmap version detected. The problem is the performance is poor and is there any way to improve it.

Thanks for your help.

Lachezar Dobrev

Sep 10, 2014, 4:35:42 AM9/10/14
to Umresh, zxing
This code seems severely ineffective.
It creates a large byte array, then it seems to perform pre-emptive
conversion of the image.
Are you SURE you need the image? I was left with the impression that
you need to scan the frame for a bar-code. You should try to shorten
the process of bringing the frame into a LuminanceSource instead. A
new implementation of the LuminanceSource should be better.

The code is too short to give any deeper impression.


Sep 10, 2014, 5:20:48 AM9/10/14
I don't need to save the image but I have to use the data in pixelArray byte[] and its a RGB565. If i convert the byte[] to int[] and use in RGBLuminanceSource I get error.
I convert to int[] saying 3 bytes/pixel and store the values in an int[] then pass to RGBLuminance, it the converts it to byte[]. I get error in
int pixel = pixels[offset + x];
Reply all
Reply to author
0 new messages