Android - convert byte of rgb_565 array to argb or rgb array

I have image data in an rgb_565 byte array and I want to convert it to an efficient path into an argb array. Right now, I have found only one (slightly slow) way to do this:

Bitmap mPhotoPicture = BitmapFactory.decodeByteArray(imageData, 0 , imageData.length); 

where imageData is my byte[] array in rgb_565, and then:

 int pixels[] = new int[CameraView.PICTURE_HEIGHT*CameraView.PICTURE_WIDTH]; mPhotoPicture.getPixels(pixels, 0,PICTURE_WIDTH, 0, 0, PICTURE_WIDTH, PICTURE_HEIGHT); 

I believe that creating a Bitmap object is exacting and not necessary in this case. Is there any other faster way to convert rgb_565 array to argb array?

I need this because image processing on the rgb_565 array seems a bit annoying. Or maybe it's not that difficult?

+4
source share
1 answer

Why don't you do it manually? The table works faster in my experience:

C code:

 static unsigned char rb_table[32]; static unsigned char g_table[64]; void init (void) { // precalculate conversion tables: int i; for (i=0; i<32; i++) rb_table[i] = 255*i/31; for (i=0; i<64; i++) g_table[i] = 255*i/63; } void convert (unsigned int * dest, unsigned short * src, int n) { // do bulk data conversion from 565 to rgb32 int i; for (i=0; i<n; i++) { unsigned short color = src[i]; unsigned int red = rb_table[(color>>11)&31]<<16; unsigned int green = g_table[(color>>5)&63]<<8; unsigned int blue = rb_table[color&31]; dest[i] = red|green|blue; } } 
+6
source

All Articles