Search code examples
pythoncamerargb

RGB565 1D array to 3d RGB image


I have a 1D RGB565 array that I get from a camera and would like to convert it to a 3D RGB image.

So the image has QVGA resolution (320x240) and with the RGB565 format that results to a 153600 byte array.

enter image description here

Is there a quick way to convert that to an image, preferably with PIL?

thanks


Solution

  • this solves my problem

    And here's the code:

    length = 76800 # 320*240
    one = [46888] * length # this would be the list of 76800 16bit RGB565 values
    xdim = 320
    ydim = 240
    im = Image.new("RGB",(xdim,ydim))
    for y in range(ydim):
       for x in range(xdim):
          px = one[i]
          i = i+1
          im.putpixel((x,y),((px&0xF800) >> 8, (px&0x07E0) >> 3, (px&0x001F) << 3))