Przeglądaj źródła

Merge pull request #64 from whj4674672/gui

【新增】新增大小端支持
yangfasheng 5 lat temu
rodzic
commit
4d585c6b7f
2 zmienionych plików z 27 dodań i 3 usunięć
  1. 19 0
      include/rtgui/blit.h
  2. 8 3
      include/rtgui/color.h

+ 19 - 0
include/rtgui/blit.h

@@ -54,10 +54,18 @@ extern "C" {
 #endif
 
 /* Assemble R-G-B values into a specified pixel format and store them */
+#ifdef RTGUI_RGB565_CHANGE_ENDIAN
+#define RGB565_FROM_RGB(Pixel, r, g, b)                                 \
+{                                                                       \
+    Pixel = (((r>>3)<<3)|((g>>5)|((g>>2)<<13))|((b>>3)<<8));            \
+}
+#else
 #define RGB565_FROM_RGB(Pixel, r, g, b)                                 \
 {                                                                       \
     Pixel = ((r>>3)<<11)|((g>>2)<<5)|(b>>3);                            \
 }
+#endif
+
 #define BGR565_FROM_RGB(Pixel, r, g, b)                                 \
 {                                                                       \
     Pixel = ((b>>3)<<11)|((g>>2)<<5)|(r>>3);                            \
@@ -108,12 +116,23 @@ extern "C" {
 }
 
 /* Load pixel of the specified format from a buffer and get its R-G-B values */
+#ifdef RTGUI_RGB565_CHANGE_ENDIAN
+#define RGB_FROM_RGB565(Pixel, r, g, b)                                                                               \
+    {                                                                                                                 \
+    rt_uint16_t swap_data = (((Pixel & 0x00ff) << 8) + ((Pixel & 0xff00) >> 8));                                      \
+    r = rtgui_blit_expand_byte[3][((swap_data&0xF800)>>11)];                                                          \
+    g = rtgui_blit_expand_byte[2][((swap_data&0x07E0)>>5)];                                                           \
+    b = rtgui_blit_expand_byte[3][(swap_data&0x001F)];                                                                \
+}
+#else
 #define RGB_FROM_RGB565(Pixel, r, g, b)                                 \
     {                                                                   \
     r = rtgui_blit_expand_byte[3][((Pixel&0xF800)>>11)];                \
     g = rtgui_blit_expand_byte[2][((Pixel&0x07E0)>>5)];                 \
     b = rtgui_blit_expand_byte[3][(Pixel&0x001F)];                      \
 }
+#endif
+
 #define RGB_FROM_BGR565(Pixel, r, g, b)                                 \
     {                                                                   \
     b = rtgui_blit_expand_byte[3][((Pixel&0xF800)>>11)];                \

+ 8 - 3
include/rtgui/color.h

@@ -114,13 +114,16 @@ rt_inline rtgui_color_t rtgui_color_from_mono(rt_uint8_t pixel)
     return color;
 }
 
+
 /* convert rtgui color to RRRRRGGGGGGBBBBB */
 rt_inline rt_uint16_t rtgui_color_to_565(rtgui_color_t c)
 {
     rt_uint16_t pixel;
-
+#ifdef RTGUI_RGB565_CHANGE_ENDIAN
+    pixel = (rt_uint16_t)(((RTGUI_RGB_R(c) >> 3) << 3) | (((RTGUI_RGB_G(c) >> 5) | ((RTGUI_RGB_G(c) >> 2) << 13))) | ((RTGUI_RGB_B(c) >> 3) << 8));
+#else
     pixel = (rt_uint16_t)(((RTGUI_RGB_R(c) >> 3) << 11) | ((RTGUI_RGB_G(c) >> 2) << 5) | (RTGUI_RGB_B(c) >> 3));
-
+#endif
     return pixel;
 }
 
@@ -128,7 +131,9 @@ rt_inline rtgui_color_t rtgui_color_from_565(rt_uint16_t pixel)
 {
     rt_uint16_t r, g, b;
     rtgui_color_t color;
-
+#ifdef RTGUI_RGB565_CHANGE_ENDIAN
+    pixel = (((pixel & 0x00ff) << 8) + ((pixel & 0xff00) >> 8));
+#endif
     r = (pixel >> 11) & 0x1f;
     g = (pixel >> 5)  & 0x3f;
     b = pixel & 0x1f;