5

I have Picture data in byte rgb_565 array, and I want convert it in a productive way into argb array. Right now I have found only one (little 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);

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

I need this because making image processing on rgb_565 array seems to be a little annoying. Or maybe it is not so hard?

1 Answer 1

6

Why don't you do it by hand? A table is in my experience fastest:

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;
  }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.