帮助!如何从RGB888获得RGB565? [英] help! how to get RGB565 from RGB888?

查看:58
本文介绍了帮助!如何从RGB888获得RGB565?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
我需要从rgb888获得rgb565,因为我想在TFT上显示图片,
我已经尝试过这样的方式

 #define COLOR_TO_MTK_COLOR_SIMUL(color)(((((color)>>>>>" 19)& 0x1f)\

                                            |(((((color)>>  10 )& 0x3f)\

                                            |(((color)>>  3 )& 0x1f)


但这是非常糟糕的方法.

解决方案

在我看来,您正确提取了颜色分量,但忘记将分量移回原位以形成RGB565格式. br/>

inline unsigned RGB888_to_RGB565 (unsigned rgb)
{
    return 
        (((rgb >> 19) & 0x1f) << 11) |
        (((rgb >> 10) & 0x3f) <<  6) |
        (((rgb >>  3) & 0x1f)      );
}



这是您获得不良结果的原因吗?如果不是,请以哪种方式告诉您您得到的结果太差或太出乎意料.


您好,我发现了一个错误:

 未签名  RGB888_to_RGB565(未签名  rgb)
{
    返回
        ((((rgb>>  19 )& 0x1f)<<  11 )| //  19 + 10 + 3 = 32//000000000000000000011111//00001F//1111100000000000 
        ((((rgb>>  10 )& 0x3f)<<  5 )| //  000000000011111111111111//003FFF//0000011111100000 
        ((((rgb>>  3 )& 0x1f))); //  000111111111111111111111//1FFFFF//
}

 int  main(){
     color = RGB888_to_RGB565(0x0000ff);
    pc.printf(" ,color);
} 



不,是6,是5.为您提供代码,可以帮助我解决工作中的一个大问题,这是我对您的贡献.
再见我的朋友...


朋友们,也许可以帮忙:

串行PC(USBTX,USBRX);

未签名  int  RGB565CONVERT( int  r, int  g, int  b, const  字符 *颜色){
     RGB565;

    RGB565 =((((r& 0xF8)< 8)|(((g& 0xF8)< 3)|(((b& 0xF8)> 3)));
    pc.printf(" ,color,RGB565);
    返回 RGB565;
}

未签名  int  RGB888_to_RGB565( unsigned   rgb,常量 字符 *颜色){
     RGB565;

    RGB565 =((((rgb>>  19 )& 0x1f)<<  11 ) |(((rgb>>  10 )& 0x3f)<<  5 )| ((((rgb>>  3 )& 0x1f)));
    pc.printf(" ,color,RGB565);
    返回 RGB565;
}

 int  main(){
    // 长颜色= RGB888_to_RGB565(0x0000ff); 
    //  pc.printf(%X \ n",color); 
    RGB888_to_RGB565(0x0000ff," );
    RGB565CONVERT( 0  0  0 " );
    RGB565CONVERT( 0  0  255 " );
    RGB565CONVERT( 0  255  0 " );
    RGB565CONVERT( 0  255  255 " );
    RGB565CONVERT( 255  0  0 " );
    RGB565CONVERT( 255  0  255 " );
    RGB565CONVERT( 255  255  0 " );
    RGB565CONVERT( 0  0  128 " );
    RGB565CONVERT( 0  128  0 " );
    RGB565CONVERT( 0  128  128 " );
    RGB565CONVERT( 128  0  0 " );
    RGB565CONVERT( 128  0  128 " );
    RGB565CONVERT( 255  128  0 " );
    RGB565CONVERT( 128  128  128 " );
    RGB565CONVERT( 64  64  64 " );
    RGB565CONVERT( 128  128  255 " );
    RGB565CONVERT( 128  255  128 " );
    RGB565CONVERT( 128  255  255 " );
    RGB565CONVERT( 255  128  128 " );
    RGB565CONVERT( 255  128  255 " );
    RGB565CONVERT( 255  255  128 " );
    RGB565CONVERT( 255  255  255 " );
    RGB565CONVERT( 224  224  224 " );
    RGB565CONVERT( 192  192  192 " );
    RGB565CONVERT( 160  160  160 " );
    RGB565CONVERT( 128  128  128 " );
    RGB565CONVERT( 96  96  96 " );
    RGB565CONVERT( 64  64  64 " );
    RGB565CONVERT( 32  32  32 " );
    RGB565CONVERT( 51  51  51 " );
    RGB565CONVERT( 102  102  102 " );
    RGB565CONVERT( 204  204  204 " );
    RGB565CONVERT( 229  229  229 " );
    RGB565CONVERT( 242  242  242 " );
    RGB565CONVERT( 139  0  0 " );
    RGB565CONVERT( 255  48  48 " );
    RGB565CONVERT( 0  100  0 " );
    RGB565CONVERT( 152  251  152 " );
    RGB565CONVERT( 238  221  130 " );
    RGB565CONVERT( 255  215  0 " );
    RGB565CONVERT( 255  140  0 " );
    
} 




OUTPUT:

 #define BRIGHTBLUE 0x001F
 #define NEGRO 0x0000
 #define BRIGHTBLUE 0x001F
 #define BRIGHTGREEN 0x07E0
 #define BRIGHTCYAN 0x07FF
 #define BRIGHTRED 0xF800
 #define BRIGHTMAGENTA 0xF81F
 #define BRIGHTYELLOW 0xFFE0
 #define AZUL 0x0010
 #define VERDE 0x0400
 #define CIAN 0x0410
 #define ROJO 0x8000
 #define MAGENTA 0x8010
 #define棕色0xFC00
 #define gris_claro 0x8410
 #define gris_oscuro 0x4208
 #define lightblue 0x841F
 #define verde_claro 0x87F0
 #define LIGHTCYAN 0x87FF
 #define LIGHTRED 0xFC10
 #define LIGHTMAGENTA 0xFC1F
 #define AMARILLO 0xFFF0
 #define BLANCO 0xFFFF
 #define GREY0 0xE71C
 #define GREY1 0xC618
 #define GREY2 0xA514
 #define GREY3 0x8410
 #define GREY4 0x630C
 #define GREY5 0x4208
 #define GREY6 0x2104
 #define GREY20 0x3186
 #define GREY40 0x632C
 #define GREY80 0xCE79
 #define GREY90 0xE73C
 #define GREY95 0xF79E
 #define RED4 0x8800
 #define FIREBRICK1 0xF986
 #define DARKGREEN 0x0320
 #define PALEGREEN 0x9FD3
 #define LIGHTYELLOW 0xEEF0
 #define GOLD 0xFEA0
 #define DARKORANGE 0xFC60  


********************************************复制到类似be的代码中*** ************************
PD:对不起,我的英语不好.我是厄瓜多尔人,我说西班牙语....

Hello anybody,
I need to get rgb565 from rgb888,because I want to show pictures on TFT,
I have tried the way like this

#define COLOR_TO_MTK_COLOR_SIMUL(color) ((((color) >> 19) & 0x1f) \

                                            |((((color) >> 10) & 0x3f)  \

                                            |(((color) >> 3) & 0x1f)


but it is very bad method.

Is there anybody meet this problem?

解决方案

Appears to me that you extracted the color components correctly but forgot to shift the components back into place to form the RGB565 format.

inline unsigned RGB888_to_RGB565 (unsigned rgb)
{
    return 
        (((rgb >> 19) & 0x1f) << 11) |
        (((rgb >> 10) & 0x3f) <<  6) |
        (((rgb >>  3) & 0x1f)      );
}



Is that the reason you were getting bad results? If not, please tell in which way the results you got were too bad or unexpected.


Hi, i found a error:

unsigned long RGB888_to_RGB565 (unsigned long rgb)
{
    return
        (((rgb >> 19) & 0x1f) << 11) |//19+10+3=32  //000000000000000000011111  //00001F    //1111100000000000
        (((rgb >> 10) & 0x3f) <<  5) |              //000000000011111111111111  //003FFF    //0000011111100000
        (((rgb >>  3) & 0x1f)      );               //000111111111111111111111  //1FFFFF    //
}

int main() {
    long color = RGB888_to_RGB565(0x0000ff);
    pc.printf("%X\n",color);
}



No is 6, is 5. Tank you for you code, it help me to solve a great problem in my job, its my contribution for you.
Bye my friend...


Hello friends, may be it can help:

Serial pc(USBTX,USBRX);

unsigned int RGB565CONVERT(int r,int g,int b,const char* color) {
    long RGB565;

    RGB565=(((r&0xF8)<<8)|((g&0xFC)<<3)|((b&0xF8)>>3));
    pc.printf("#define  %s      0x%0.4X\n",color,RGB565);
    return RGB565;
}

unsigned int RGB888_to_RGB565 (unsigned long rgb,const char* color) {
    long RGB565;

    RGB565= (((rgb >> 19) & 0x1f) << 11)|(((rgb >> 10) & 0x3f) <<  5)|(((rgb >>  3) & 0x1f));
    pc.printf("#define  %s      0x%0.4X\n",color,RGB565);
    return RGB565;
}

int main() {
    //long color = RGB888_to_RGB565(0x0000ff);
    //pc.printf("%X\n",color);
    RGB888_to_RGB565(0x0000ff,"BRIGHTBLUE");
    RGB565CONVERT(0,0,0,"NEGRO");
    RGB565CONVERT(0,0,255,"BRIGHTBLUE");
    RGB565CONVERT(0,255,0,"BRIGHTGREEN");
    RGB565CONVERT(0,255,255,"BRIGHTCYAN");
    RGB565CONVERT(255,0,0,"BRIGHTRED");
    RGB565CONVERT(255,0,255,"BRIGHTMAGENTA");
    RGB565CONVERT(255,255,0,"BRIGHTYELLOW");
    RGB565CONVERT(0,0,128,"AZUL");
    RGB565CONVERT(0,128,0,"VERDE");
    RGB565CONVERT(0,128,128,"CIAN");
    RGB565CONVERT(128,0,0,"ROJO");
    RGB565CONVERT(128,0,128,"MAGENTA");
    RGB565CONVERT(255,128,0,"BROWN");
    RGB565CONVERT(128,128,128,"gris_claro");
    RGB565CONVERT(64,64,64,"gris_oscuro");
    RGB565CONVERT(128,128,255,"lightblue");
    RGB565CONVERT(128,255,128,"verde_claro");
    RGB565CONVERT(128,255,255,"LIGHTCYAN");
    RGB565CONVERT(255,128,128,"LIGHTRED");
    RGB565CONVERT(255,128,255,"LIGHTMAGENTA");
    RGB565CONVERT(255,255,128,"AMARILLO");
    RGB565CONVERT(255,255,255,"BLANCO");
    RGB565CONVERT(224,224,224,"GRAY0");
    RGB565CONVERT(192,192,192,"GRAY1");
    RGB565CONVERT(160,160,160,"GRAY2");
    RGB565CONVERT(128,128,128,"GRAY3");
    RGB565CONVERT(96,96,96,"GRAY4");
    RGB565CONVERT(64,64,64,"GRAY5");
    RGB565CONVERT(32,32,32,"GRAY6");
    RGB565CONVERT(51,51,51,"GRAY20");
    RGB565CONVERT(102,102,102,"GRAY40");
    RGB565CONVERT(204,204,204,"GRAY80");
    RGB565CONVERT(229,229,229,"GRAY90");
    RGB565CONVERT(242,242,242,"GRAY95");
    RGB565CONVERT(139,0,0,"RED4");
    RGB565CONVERT(255,48,48,"FIREBRICK1");
    RGB565CONVERT(0,100,0,"DARKGREEN");
    RGB565CONVERT(152,251,152,"PALEGREEN");
    RGB565CONVERT(238,221,130,"LIGHTYELLOW");
    RGB565CONVERT(255,215,0,"GOLD");
    RGB565CONVERT(255,140,0,"DARKORANGE");
    
}




OUTPUT:

#define  BRIGHTBLUE                       0x001F
#define  NEGRO      0x0000
#define  BRIGHTBLUE      0x001F
#define  BRIGHTGREEN      0x07E0
#define  BRIGHTCYAN      0x07FF
#define  BRIGHTRED      0xF800
#define  BRIGHTMAGENTA      0xF81F
#define  BRIGHTYELLOW      0xFFE0
#define  AZUL      0x0010
#define  VERDE      0x0400
#define  CIAN      0x0410
#define  ROJO      0x8000
#define  MAGENTA      0x8010
#define  BROWN      0xFC00
#define  gris_claro      0x8410
#define  gris_oscuro      0x4208
#define  lightblue      0x841F
#define  verde_claro      0x87F0
#define  LIGHTCYAN      0x87FF
#define  LIGHTRED      0xFC10
#define  LIGHTMAGENTA      0xFC1F
#define  AMARILLO      0xFFF0
#define  BLANCO      0xFFFF
#define  GRAY0      0xE71C
#define  GRAY1      0xC618
#define  GRAY2      0xA514
#define  GRAY3      0x8410
#define  GRAY4      0x630C
#define  GRAY5      0x4208
#define  GRAY6      0x2104
#define  GRAY20      0x3186
#define  GRAY40      0x632C
#define  GRAY80      0xCE79
#define  GRAY90      0xE73C
#define  GRAY95      0xF79E
#define  RED4      0x8800
#define  FIREBRICK1      0xF986
#define  DARKGREEN      0x0320
#define  PALEGREEN      0x9FD3
#define  LIGHTYELLOW      0xEEF0
#define  GOLD      0xFEA0
#define  DARKORANGE      0xFC60


****************************************Copy into code such as it be***************************
PD: sorry, my english not is good... i am Ecuatorian, i talk spanish.... Copien tal como esta el codigo en su programa...


这篇关于帮助!如何从RGB888获得RGB565?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆