How does one convert 16-bit RGB565 to 24-bit RGB888?

后端 未结 8 812
深忆病人
深忆病人 2020-11-27 03:22

I’ve got my hands on a 16-bit rgb565 image (specifically, an Android framebuffer dump), and I would like to convert it to 24-bit rgb888 for viewing on a normal monitor.

相关标签:
8条回答
  • 2020-11-27 04:01

    I used the following and got good results. Turned out my Logitek cam was 16bit RGB555 and using the following to convert to 24bit RGB888 allowed me to save as a jpeg using the smaller animals ijg: Thanks for the hint found here on stackoverflow.

    // Convert a 16 bit inbuf array to a 24 bit outbuf array
    BOOL JpegFile::ByteConvert(BYTE* inbuf, BYTE* outbuf, UINT width, UINT height)
    {     UINT row_cnt, pix_cnt;     
          ULONG off1 = 0, off2 = 0;
          BYTE  tbi1, tbi2, R5, G5, B5, R8, G8, B8;
    
          if (inbuf==NULL)
              return FALSE;
    
          for (row_cnt = 0; row_cnt <= height; row_cnt++) 
          {     off1 = row_cnt * width * 2;
                off2 = row_cnt * width * 3;
                for(pix_cnt=0; pix_cnt < width; pix_cnt++)
                {    tbi1 = inbuf[off1 + (pix_cnt * 2)];
                     tbi2 = inbuf[off1 + (pix_cnt * 2) + 1];
                     B5 = tbi1 & 0x1F;
                     G5 = (((tbi1 & 0xE0) >> 5) | ((tbi2 & 0x03) << 3)) & 0x1F;
                     R5 = (tbi2 >> 2) & 0x1F;
                     R8 = ( R5 * 527 + 23 ) >> 6;
                     G8 = ( G5 * 527 + 23 ) >> 6;
                     B8 = ( B5 * 527 + 23 ) >> 6;
                     outbuf[off2 + (pix_cnt * 3)] = R8;
                     outbuf[off2 + (pix_cnt * 3) + 1] = G8;
                     outbuf[off2 + (pix_cnt * 3) + 2] = B8;
                }
           }
           return TRUE;
    }        
    
    0 讨论(0)
  • 2020-11-27 04:02

    There is an error jleedev !!!

    unsigned char green = (buf & 0x07c0) >> 5;
    unsigned char blue = buf & 0x003f;
    

    the good code

    unsigned char green = (buf & 0x07e0) >> 5;
    unsigned char blue = buf & 0x001f;
    

    Cheers, Andy

    0 讨论(0)
提交回复
热议问题