summaryrefslogtreecommitdiff
path: root/components/rtgui/common
diff options
context:
space:
mode:
Diffstat (limited to 'components/rtgui/common')
-rw-r--r--components/rtgui/common/blit.c568
-rw-r--r--components/rtgui/common/dc_client.c39
-rw-r--r--components/rtgui/common/dc_hw.c24
-rw-r--r--components/rtgui/common/filerw.c926
-rw-r--r--components/rtgui/common/font_freetype.c474
-rw-r--r--components/rtgui/common/font_hz_bmp.c4
-rw-r--r--components/rtgui/common/font_hz_file.c4
-rw-r--r--components/rtgui/common/framebuffer_driver.c450
-rw-r--r--components/rtgui/common/image.c30
-rw-r--r--components/rtgui/common/image_bmp.c1290
-rw-r--r--components/rtgui/common/image_container.c890
-rw-r--r--components/rtgui/common/pixel_driver.c308
-rw-r--r--components/rtgui/common/rtgui_object.c35
-rw-r--r--components/rtgui/common/rtgui_system.c467
-rw-r--r--components/rtgui/common/rtgui_xml.c2
15 files changed, 2532 insertions, 2979 deletions
diff --git a/components/rtgui/common/blit.c b/components/rtgui/common/blit.c
index 39d0e32823..a9b0b36749 100644
--- a/components/rtgui/common/blit.c
+++ b/components/rtgui/common/blit.c
@@ -1,32 +1,32 @@
-#include <rtgui/rtgui.h>
-#include <rtgui/blit.h>
-
-/* 2 bpp to 1 bpp */
-static void rtgui_blit_line_2_1(rt_uint8_t* dst_ptr, rt_uint8_t* src_ptr, int line)
-{
- return;
-}
-
-/* 3 bpp to 1 bpp */
-static void rtgui_blit_line_3_1(rt_uint8_t* dst_ptr, rt_uint8_t* src_ptr, int line)
-{
- line = line / 3;
- while (line)
- {
- *dst_ptr = (rt_uint8_t)(((*src_ptr & 0x00E00000)>>16)|
- ((*(src_ptr + 1) & 0x0000E000)>>11) |
- ((*(src_ptr + 2) & 0x000000C0)>>6));
-
- src_ptr += 3;
- dst_ptr ++;
- line --;
- }
- return;
-}
-
-/* 4 bpp to 1 bpp */
-static void rtgui_blit_line_4_1(rt_uint8_t* dst_ptr, rt_uint8_t* src_ptr, int line)
-{
+#include <rtgui/rtgui.h>
+#include <rtgui/blit.h>
+
+/* 2 bpp to 1 bpp */
+static void rtgui_blit_line_2_1(rt_uint8_t* dst_ptr, rt_uint8_t* src_ptr, int line)
+{
+ return;
+}
+
+/* 3 bpp to 1 bpp */
+static void rtgui_blit_line_3_1(rt_uint8_t* dst_ptr, rt_uint8_t* src_ptr, int line)
+{
+ line = line / 3;
+ while (line)
+ {
+ *dst_ptr = (rt_uint8_t)(((*src_ptr & 0x00E00000)>>16)|
+ ((*(src_ptr + 1) & 0x0000E000)>>11) |
+ ((*(src_ptr + 2) & 0x000000C0)>>6));
+
+ src_ptr += 3;
+ dst_ptr ++;
+ line --;
+ }
+ return;
+}
+
+/* 4 bpp to 1 bpp */
+static void rtgui_blit_line_4_1(rt_uint8_t* dst_ptr, rt_uint8_t* src_ptr, int line)
+{
struct _color {rt_uint8_t r, g, b, a;} *c;
c = (struct _color*)src_ptr;
@@ -36,39 +36,39 @@ static void rtgui_blit_line_4_1(rt_uint8_t* dst_ptr, rt_uint8_t* src_ptr, int li
c ++;
dst_ptr ++;
- }
-}
-
-/* 1 bpp to 2 bpp */
-static void rtgui_blit_line_1_2(rt_uint8_t* dst_ptr, rt_uint8_t* src_ptr, int line)
-{
- return;
-}
-
-/* 3 bpp to 2 bpp */
-static void rtgui_blit_line_3_2(rt_uint8_t* dst_ptr, rt_uint8_t* src_ptr, int line)
-{
- rt_uint16_t* dst;
-
- dst = (rt_uint16_t*)dst_ptr;
- line = line / 3;
- while (line)
- {
- *dst = (((*(src_ptr + 2) << 8) & 0x0000F800) |
- ((*(src_ptr + 1) << 3) & 0x000007E0) |
- ((*src_ptr >> 3) & 0x0000001F));
-
- src_ptr += 3;
- dst ++;
- line --;
- }
-
- return;
-}
-
-/* 4 bpp to 2 bpp */
-static void rtgui_blit_line_4_2(rt_uint8_t* dst_ptr, rt_uint8_t* src_ptr, int line)
-{
+ }
+}
+
+/* 1 bpp to 2 bpp */
+static void rtgui_blit_line_1_2(rt_uint8_t* dst_ptr, rt_uint8_t* src_ptr, int line)
+{
+ return;
+}
+
+/* 3 bpp to 2 bpp */
+static void rtgui_blit_line_3_2(rt_uint8_t* dst_ptr, rt_uint8_t* src_ptr, int line)
+{
+ rt_uint16_t* dst;
+
+ dst = (rt_uint16_t*)dst_ptr;
+ line = line / 3;
+ while (line)
+ {
+ *dst = (((*(src_ptr + 2) << 8) & 0x0000F800) |
+ ((*(src_ptr + 1) << 3) & 0x000007E0) |
+ ((*src_ptr >> 3) & 0x0000001F));
+
+ src_ptr += 3;
+ dst ++;
+ line --;
+ }
+
+ return;
+}
+
+/* 4 bpp to 2 bpp */
+static void rtgui_blit_line_4_2(rt_uint8_t* dst_ptr, rt_uint8_t* src_ptr, int line)
+{
struct _color {rt_uint8_t r, g, b, a;} *c;
rt_uint16_t* ptr;
@@ -83,225 +83,225 @@ static void rtgui_blit_line_4_2(rt_uint8_t* dst_ptr, rt_uint8_t* src_ptr, int li
c ++;
ptr ++;
}
-}
-
-static void rtgui_blit_line_1_3(rt_uint8_t* dst_ptr, rt_uint8_t* src_ptr, int line)
-{
- return;
-}
-
-#define HI 1
-#define LO 0
-
-/* Special optimized blit for RGB 5-6-5 --> RGBA 8-8-8-8 */
-static const rt_uint32_t RGB565_RGBA8888_LUT[512] =
-{
- 0x000000ff, 0x00000000, 0x000008ff, 0x00200000,
- 0x000010ff, 0x00400000, 0x000018ff, 0x00610000,
- 0x000020ff, 0x00810000, 0x000029ff, 0x00a10000,
- 0x000031ff, 0x00c20000, 0x000039ff, 0x00e20000,
- 0x000041ff, 0x08000000, 0x00004aff, 0x08200000,
- 0x000052ff, 0x08400000, 0x00005aff, 0x08610000,
- 0x000062ff, 0x08810000, 0x00006aff, 0x08a10000,
- 0x000073ff, 0x08c20000, 0x00007bff, 0x08e20000,
- 0x000083ff, 0x10000000, 0x00008bff, 0x10200000,
- 0x000094ff, 0x10400000, 0x00009cff, 0x10610000,
- 0x0000a4ff, 0x10810000, 0x0000acff, 0x10a10000,
- 0x0000b4ff, 0x10c20000, 0x0000bdff, 0x10e20000,
- 0x0000c5ff, 0x18000000, 0x0000cdff, 0x18200000,
- 0x0000d5ff, 0x18400000, 0x0000deff, 0x18610000,
- 0x0000e6ff, 0x18810000, 0x0000eeff, 0x18a10000,
- 0x0000f6ff, 0x18c20000, 0x0000ffff, 0x18e20000,
- 0x000400ff, 0x20000000, 0x000408ff, 0x20200000,
- 0x000410ff, 0x20400000, 0x000418ff, 0x20610000,
- 0x000420ff, 0x20810000, 0x000429ff, 0x20a10000,
- 0x000431ff, 0x20c20000, 0x000439ff, 0x20e20000,
- 0x000441ff, 0x29000000, 0x00044aff, 0x29200000,
- 0x000452ff, 0x29400000, 0x00045aff, 0x29610000,
- 0x000462ff, 0x29810000, 0x00046aff, 0x29a10000,
- 0x000473ff, 0x29c20000, 0x00047bff, 0x29e20000,
- 0x000483ff, 0x31000000, 0x00048bff, 0x31200000,
- 0x000494ff, 0x31400000, 0x00049cff, 0x31610000,
- 0x0004a4ff, 0x31810000, 0x0004acff, 0x31a10000,
- 0x0004b4ff, 0x31c20000, 0x0004bdff, 0x31e20000,
- 0x0004c5ff, 0x39000000, 0x0004cdff, 0x39200000,
- 0x0004d5ff, 0x39400000, 0x0004deff, 0x39610000,
- 0x0004e6ff, 0x39810000, 0x0004eeff, 0x39a10000,
- 0x0004f6ff, 0x39c20000, 0x0004ffff, 0x39e20000,
- 0x000800ff, 0x41000000, 0x000808ff, 0x41200000,
- 0x000810ff, 0x41400000, 0x000818ff, 0x41610000,
- 0x000820ff, 0x41810000, 0x000829ff, 0x41a10000,
- 0x000831ff, 0x41c20000, 0x000839ff, 0x41e20000,
- 0x000841ff, 0x4a000000, 0x00084aff, 0x4a200000,
- 0x000852ff, 0x4a400000, 0x00085aff, 0x4a610000,
- 0x000862ff, 0x4a810000, 0x00086aff, 0x4aa10000,
- 0x000873ff, 0x4ac20000, 0x00087bff, 0x4ae20000,
- 0x000883ff, 0x52000000, 0x00088bff, 0x52200000,
- 0x000894ff, 0x52400000, 0x00089cff, 0x52610000,
- 0x0008a4ff, 0x52810000, 0x0008acff, 0x52a10000,
- 0x0008b4ff, 0x52c20000, 0x0008bdff, 0x52e20000,
- 0x0008c5ff, 0x5a000000, 0x0008cdff, 0x5a200000,
- 0x0008d5ff, 0x5a400000, 0x0008deff, 0x5a610000,
- 0x0008e6ff, 0x5a810000, 0x0008eeff, 0x5aa10000,
- 0x0008f6ff, 0x5ac20000, 0x0008ffff, 0x5ae20000,
- 0x000c00ff, 0x62000000, 0x000c08ff, 0x62200000,
- 0x000c10ff, 0x62400000, 0x000c18ff, 0x62610000,
- 0x000c20ff, 0x62810000, 0x000c29ff, 0x62a10000,
- 0x000c31ff, 0x62c20000, 0x000c39ff, 0x62e20000,
- 0x000c41ff, 0x6a000000, 0x000c4aff, 0x6a200000,
- 0x000c52ff, 0x6a400000, 0x000c5aff, 0x6a610000,
- 0x000c62ff, 0x6a810000, 0x000c6aff, 0x6aa10000,
- 0x000c73ff, 0x6ac20000, 0x000c7bff, 0x6ae20000,
- 0x000c83ff, 0x73000000, 0x000c8bff, 0x73200000,
- 0x000c94ff, 0x73400000, 0x000c9cff, 0x73610000,
- 0x000ca4ff, 0x73810000, 0x000cacff, 0x73a10000,
- 0x000cb4ff, 0x73c20000, 0x000cbdff, 0x73e20000,
- 0x000cc5ff, 0x7b000000, 0x000ccdff, 0x7b200000,
- 0x000cd5ff, 0x7b400000, 0x000cdeff, 0x7b610000,
- 0x000ce6ff, 0x7b810000, 0x000ceeff, 0x7ba10000,
- 0x000cf6ff, 0x7bc20000, 0x000cffff, 0x7be20000,
- 0x001000ff, 0x83000000, 0x001008ff, 0x83200000,
- 0x001010ff, 0x83400000, 0x001018ff, 0x83610000,
- 0x001020ff, 0x83810000, 0x001029ff, 0x83a10000,
- 0x001031ff, 0x83c20000, 0x001039ff, 0x83e20000,
- 0x001041ff, 0x8b000000, 0x00104aff, 0x8b200000,
- 0x001052ff, 0x8b400000, 0x00105aff, 0x8b610000,
- 0x001062ff, 0x8b810000, 0x00106aff, 0x8ba10000,
- 0x001073ff, 0x8bc20000, 0x00107bff, 0x8be20000,
- 0x001083ff, 0x94000000, 0x00108bff, 0x94200000,
- 0x001094ff, 0x94400000, 0x00109cff, 0x94610000,
- 0x0010a4ff, 0x94810000, 0x0010acff, 0x94a10000,
- 0x0010b4ff, 0x94c20000, 0x0010bdff, 0x94e20000,
- 0x0010c5ff, 0x9c000000, 0x0010cdff, 0x9c200000,
- 0x0010d5ff, 0x9c400000, 0x0010deff, 0x9c610000,
- 0x0010e6ff, 0x9c810000, 0x0010eeff, 0x9ca10000,
- 0x0010f6ff, 0x9cc20000, 0x0010ffff, 0x9ce20000,
- 0x001400ff, 0xa4000000, 0x001408ff, 0xa4200000,
- 0x001410ff, 0xa4400000, 0x001418ff, 0xa4610000,
- 0x001420ff, 0xa4810000, 0x001429ff, 0xa4a10000,
- 0x001431ff, 0xa4c20000, 0x001439ff, 0xa4e20000,
- 0x001441ff, 0xac000000, 0x00144aff, 0xac200000,
- 0x001452ff, 0xac400000, 0x00145aff, 0xac610000,
- 0x001462ff, 0xac810000, 0x00146aff, 0xaca10000,
- 0x001473ff, 0xacc20000, 0x00147bff, 0xace20000,
- 0x001483ff, 0xb4000000, 0x00148bff, 0xb4200000,
- 0x001494ff, 0xb4400000, 0x00149cff, 0xb4610000,
- 0x0014a4ff, 0xb4810000, 0x0014acff, 0xb4a10000,
- 0x0014b4ff, 0xb4c20000, 0x0014bdff, 0xb4e20000,
- 0x0014c5ff, 0xbd000000, 0x0014cdff, 0xbd200000,
- 0x0014d5ff, 0xbd400000, 0x0014deff, 0xbd610000,
- 0x0014e6ff, 0xbd810000, 0x0014eeff, 0xbda10000,
- 0x0014f6ff, 0xbdc20000, 0x0014ffff, 0xbde20000,
- 0x001800ff, 0xc5000000, 0x001808ff, 0xc5200000,
- 0x001810ff, 0xc5400000, 0x001818ff, 0xc5610000,
- 0x001820ff, 0xc5810000, 0x001829ff, 0xc5a10000,
- 0x001831ff, 0xc5c20000, 0x001839ff, 0xc5e20000,
- 0x001841ff, 0xcd000000, 0x00184aff, 0xcd200000,
- 0x001852ff, 0xcd400000, 0x00185aff, 0xcd610000,
- 0x001862ff, 0xcd810000, 0x00186aff, 0xcda10000,
- 0x001873ff, 0xcdc20000, 0x00187bff, 0xcde20000,
- 0x001883ff, 0xd5000000, 0x00188bff, 0xd5200000,
- 0x001894ff, 0xd5400000, 0x00189cff, 0xd5610000,
- 0x0018a4ff, 0xd5810000, 0x0018acff, 0xd5a10000,
- 0x0018b4ff, 0xd5c20000, 0x0018bdff, 0xd5e20000,
- 0x0018c5ff, 0xde000000, 0x0018cdff, 0xde200000,
- 0x0018d5ff, 0xde400000, 0x0018deff, 0xde610000,
- 0x0018e6ff, 0xde810000, 0x0018eeff, 0xdea10000,
- 0x0018f6ff, 0xdec20000, 0x0018ffff, 0xdee20000,
- 0x001c00ff, 0xe6000000, 0x001c08ff, 0xe6200000,
- 0x001c10ff, 0xe6400000, 0x001c18ff, 0xe6610000,
- 0x001c20ff, 0xe6810000, 0x001c29ff, 0xe6a10000,
- 0x001c31ff, 0xe6c20000, 0x001c39ff, 0xe6e20000,
- 0x001c41ff, 0xee000000, 0x001c4aff, 0xee200000,
- 0x001c52ff, 0xee400000, 0x001c5aff, 0xee610000,
- 0x001c62ff, 0xee810000, 0x001c6aff, 0xeea10000,
- 0x001c73ff, 0xeec20000, 0x001c7bff, 0xeee20000,
- 0x001c83ff, 0xf6000000, 0x001c8bff, 0xf6200000,
- 0x001c94ff, 0xf6400000, 0x001c9cff, 0xf6610000,
- 0x001ca4ff, 0xf6810000, 0x001cacff, 0xf6a10000,
- 0x001cb4ff, 0xf6c20000, 0x001cbdff, 0xf6e20000,
- 0x001cc5ff, 0xff000000, 0x001ccdff, 0xff200000,
- 0x001cd5ff, 0xff400000, 0x001cdeff, 0xff610000,
- 0x001ce6ff, 0xff810000, 0x001ceeff, 0xffa10000,
- 0x001cf6ff, 0xffc20000, 0x001cffff, 0xffe20000,
-};
-
-static void rtgui_blit_line_2_3(rt_uint8_t* dst_ptr, rt_uint8_t* src_ptr, int line)
-{
- rt_uint16_t *src;
- rt_uint32_t *dst;
-
- src = (rt_uint16_t*)src_ptr;
- dst = (rt_uint32_t*)dst_ptr;
-
- line = line / 2;
- while (line)
- {
- *dst++ = RGB565_RGBA8888_LUT[src[LO]*2] + RGB565_RGBA8888_LUT[src[HI]*2+1];
- line--;
- src ++;
- }
-}
-
-void rtgui_blit_line_direct(rt_uint8_t* dst_ptr, rt_uint8_t* src_ptr, int line)
-{
- rt_memcpy(dst_ptr, src_ptr, line);
-}
-
-/* convert 4bpp to 3bpp */
-static void rtgui_blit_line_4_3(rt_uint8_t* dst_ptr, rt_uint8_t* src_ptr, int line)
-{
- line = line / 4;
- while (line)
- {
- *dst_ptr++ = *src_ptr++;
- *dst_ptr++ = *src_ptr++;
- *dst_ptr++ = *src_ptr++;
- src_ptr ++;
- line --;
- }
-}
-
-static void rtgui_blit_line_1_4(rt_uint8_t* dst_ptr, rt_uint8_t* src_ptr, int line)
-{
-}
-
-static void rtgui_blit_line_2_4(rt_uint8_t* dst_ptr, rt_uint8_t* src_ptr, int line)
-{
-}
-
-/* convert 3bpp to 4bpp */
-static void rtgui_blit_line_3_4(rt_uint8_t* dst_ptr, rt_uint8_t* src_ptr, int line)
-{
- line = line / 4;
- while (line)
- {
- *dst_ptr++ = *src_ptr++;
- *dst_ptr++ = *src_ptr++;
- *dst_ptr++ = *src_ptr++;
- *dst_ptr++ = 0;
- line --;
- }
-}
-
-static const rtgui_blit_line_func _blit_table[5][5] =
-{
- /* 0_0, 1_0, 2_0, 3_0, 4_0 */
- {RT_NULL, RT_NULL, RT_NULL, RT_NULL, RT_NULL },
- /* 0_1, 1_1, 2_1, 3_1, 4_1 */
- {RT_NULL, rtgui_blit_line_direct, rtgui_blit_line_2_1, rtgui_blit_line_3_1, rtgui_blit_line_4_1 },
- /* 0_2, 1_2, 2_2, 3_2, 4_2 */
- {RT_NULL, rtgui_blit_line_1_2, rtgui_blit_line_direct, rtgui_blit_line_3_2, rtgui_blit_line_4_2 },
- /* 0_3, 1_3, 2_3, 3_3, 4_3 */
- {RT_NULL, rtgui_blit_line_1_3, rtgui_blit_line_2_3, rtgui_blit_line_direct, rtgui_blit_line_4_3 },
- /* 0_4, 1_4, 2_4, 3_4, 4_4 */
- {RT_NULL, rtgui_blit_line_1_4, rtgui_blit_line_2_4, rtgui_blit_line_3_4, rtgui_blit_line_direct },
-};
-
-rtgui_blit_line_func rtgui_blit_line_get(int dst_bpp, int src_bpp)
-{
- RT_ASSERT(dst_bpp>0 && dst_bpp < 5);
- RT_ASSERT(src_bpp>0 && src_bpp < 5);
-
- return _blit_table[dst_bpp][src_bpp];
-}
+}
+
+static void rtgui_blit_line_1_3(rt_uint8_t* dst_ptr, rt_uint8_t* src_ptr, int line)
+{
+ return;
+}
+
+#define HI 1
+#define LO 0
+
+/* Special optimized blit for RGB 5-6-5 --> RGBA 8-8-8-8 */
+static const rt_uint32_t RGB565_RGBA8888_LUT[512] =
+{
+ 0x000000ff, 0x00000000, 0x000008ff, 0x00200000,
+ 0x000010ff, 0x00400000, 0x000018ff, 0x00610000,
+ 0x000020ff, 0x00810000, 0x000029ff, 0x00a10000,
+ 0x000031ff, 0x00c20000, 0x000039ff, 0x00e20000,
+ 0x000041ff, 0x08000000, 0x00004aff, 0x08200000,
+ 0x000052ff, 0x08400000, 0x00005aff, 0x08610000,
+ 0x000062ff, 0x08810000, 0x00006aff, 0x08a10000,
+ 0x000073ff, 0x08c20000, 0x00007bff, 0x08e20000,
+ 0x000083ff, 0x10000000, 0x00008bff, 0x10200000,
+ 0x000094ff, 0x10400000, 0x00009cff, 0x10610000,
+ 0x0000a4ff, 0x10810000, 0x0000acff, 0x10a10000,
+ 0x0000b4ff, 0x10c20000, 0x0000bdff, 0x10e20000,
+ 0x0000c5ff, 0x18000000, 0x0000cdff, 0x18200000,
+ 0x0000d5ff, 0x18400000, 0x0000deff, 0x18610000,
+ 0x0000e6ff, 0x18810000, 0x0000eeff, 0x18a10000,
+ 0x0000f6ff, 0x18c20000, 0x0000ffff, 0x18e20000,
+ 0x000400ff, 0x20000000, 0x000408ff, 0x20200000,
+ 0x000410ff, 0x20400000, 0x000418ff, 0x20610000,
+ 0x000420ff, 0x20810000, 0x000429ff, 0x20a10000,
+ 0x000431ff, 0x20c20000, 0x000439ff, 0x20e20000,
+ 0x000441ff, 0x29000000, 0x00044aff, 0x29200000,
+ 0x000452ff, 0x29400000, 0x00045aff, 0x29610000,
+ 0x000462ff, 0x29810000, 0x00046aff, 0x29a10000,
+ 0x000473ff, 0x29c20000, 0x00047bff, 0x29e20000,
+ 0x000483ff, 0x31000000, 0x00048bff, 0x31200000,
+ 0x000494ff, 0x31400000, 0x00049cff, 0x31610000,
+ 0x0004a4ff, 0x31810000, 0x0004acff, 0x31a10000,
+ 0x0004b4ff, 0x31c20000, 0x0004bdff, 0x31e20000,
+ 0x0004c5ff, 0x39000000, 0x0004cdff, 0x39200000,
+ 0x0004d5ff, 0x39400000, 0x0004deff, 0x39610000,
+ 0x0004e6ff, 0x39810000, 0x0004eeff, 0x39a10000,
+ 0x0004f6ff, 0x39c20000, 0x0004ffff, 0x39e20000,
+ 0x000800ff, 0x41000000, 0x000808ff, 0x41200000,
+ 0x000810ff, 0x41400000, 0x000818ff, 0x41610000,
+ 0x000820ff, 0x41810000, 0x000829ff, 0x41a10000,
+ 0x000831ff, 0x41c20000, 0x000839ff, 0x41e20000,
+ 0x000841ff, 0x4a000000, 0x00084aff, 0x4a200000,
+ 0x000852ff, 0x4a400000, 0x00085aff, 0x4a610000,
+ 0x000862ff, 0x4a810000, 0x00086aff, 0x4aa10000,
+ 0x000873ff, 0x4ac20000, 0x00087bff, 0x4ae20000,
+ 0x000883ff, 0x52000000, 0x00088bff, 0x52200000,
+ 0x000894ff, 0x52400000, 0x00089cff, 0x52610000,
+ 0x0008a4ff, 0x52810000, 0x0008acff, 0x52a10000,
+ 0x0008b4ff, 0x52c20000, 0x0008bdff, 0x52e20000,
+ 0x0008c5ff, 0x5a000000, 0x0008cdff, 0x5a200000,
+ 0x0008d5ff, 0x5a400000, 0x0008deff, 0x5a610000,
+ 0x0008e6ff, 0x5a810000, 0x0008eeff, 0x5aa10000,
+ 0x0008f6ff, 0x5ac20000, 0x0008ffff, 0x5ae20000,
+ 0x000c00ff, 0x62000000, 0x000c08ff, 0x62200000,
+ 0x000c10ff, 0x62400000, 0x000c18ff, 0x62610000,
+ 0x000c20ff, 0x62810000, 0x000c29ff, 0x62a10000,
+ 0x000c31ff, 0x62c20000, 0x000c39ff, 0x62e20000,
+ 0x000c41ff, 0x6a000000, 0x000c4aff, 0x6a200000,
+ 0x000c52ff, 0x6a400000, 0x000c5aff, 0x6a610000,
+ 0x000c62ff, 0x6a810000, 0x000c6aff, 0x6aa10000,
+ 0x000c73ff, 0x6ac20000, 0x000c7bff, 0x6ae20000,
+ 0x000c83ff, 0x73000000, 0x000c8bff, 0x73200000,
+ 0x000c94ff, 0x73400000, 0x000c9cff, 0x73610000,
+ 0x000ca4ff, 0x73810000, 0x000cacff, 0x73a10000,
+ 0x000cb4ff, 0x73c20000, 0x000cbdff, 0x73e20000,
+ 0x000cc5ff, 0x7b000000, 0x000ccdff, 0x7b200000,
+ 0x000cd5ff, 0x7b400000, 0x000cdeff, 0x7b610000,
+ 0x000ce6ff, 0x7b810000, 0x000ceeff, 0x7ba10000,
+ 0x000cf6ff, 0x7bc20000, 0x000cffff, 0x7be20000,
+ 0x001000ff, 0x83000000, 0x001008ff, 0x83200000,
+ 0x001010ff, 0x83400000, 0x001018ff, 0x83610000,
+ 0x001020ff, 0x83810000, 0x001029ff, 0x83a10000,
+ 0x001031ff, 0x83c20000, 0x001039ff, 0x83e20000,
+ 0x001041ff, 0x8b000000, 0x00104aff, 0x8b200000,
+ 0x001052ff, 0x8b400000, 0x00105aff, 0x8b610000,
+ 0x001062ff, 0x8b810000, 0x00106aff, 0x8ba10000,
+ 0x001073ff, 0x8bc20000, 0x00107bff, 0x8be20000,
+ 0x001083ff, 0x94000000, 0x00108bff, 0x94200000,
+ 0x001094ff, 0x94400000, 0x00109cff, 0x94610000,
+ 0x0010a4ff, 0x94810000, 0x0010acff, 0x94a10000,
+ 0x0010b4ff, 0x94c20000, 0x0010bdff, 0x94e20000,
+ 0x0010c5ff, 0x9c000000, 0x0010cdff, 0x9c200000,
+ 0x0010d5ff, 0x9c400000, 0x0010deff, 0x9c610000,
+ 0x0010e6ff, 0x9c810000, 0x0010eeff, 0x9ca10000,
+ 0x0010f6ff, 0x9cc20000, 0x0010ffff, 0x9ce20000,
+ 0x001400ff, 0xa4000000, 0x001408ff, 0xa4200000,
+ 0x001410ff, 0xa4400000, 0x001418ff, 0xa4610000,
+ 0x001420ff, 0xa4810000, 0x001429ff, 0xa4a10000,
+ 0x001431ff, 0xa4c20000, 0x001439ff, 0xa4e20000,
+ 0x001441ff, 0xac000000, 0x00144aff, 0xac200000,
+ 0x001452ff, 0xac400000, 0x00145aff, 0xac610000,
+ 0x001462ff, 0xac810000, 0x00146aff, 0xaca10000,
+ 0x001473ff, 0xacc20000, 0x00147bff, 0xace20000,
+ 0x001483ff, 0xb4000000, 0x00148bff, 0xb4200000,
+ 0x001494ff, 0xb4400000, 0x00149cff, 0xb4610000,
+ 0x0014a4ff, 0xb4810000, 0x0014acff, 0xb4a10000,
+ 0x0014b4ff, 0xb4c20000, 0x0014bdff, 0xb4e20000,
+ 0x0014c5ff, 0xbd000000, 0x0014cdff, 0xbd200000,
+ 0x0014d5ff, 0xbd400000, 0x0014deff, 0xbd610000,
+ 0x0014e6ff, 0xbd810000, 0x0014eeff, 0xbda10000,
+ 0x0014f6ff, 0xbdc20000, 0x0014ffff, 0xbde20000,
+ 0x001800ff, 0xc5000000, 0x001808ff, 0xc5200000,
+ 0x001810ff, 0xc5400000, 0x001818ff, 0xc5610000,
+ 0x001820ff, 0xc5810000, 0x001829ff, 0xc5a10000,
+ 0x001831ff, 0xc5c20000, 0x001839ff, 0xc5e20000,
+ 0x001841ff, 0xcd000000, 0x00184aff, 0xcd200000,
+ 0x001852ff, 0xcd400000, 0x00185aff, 0xcd610000,
+ 0x001862ff, 0xcd810000, 0x00186aff, 0xcda10000,
+ 0x001873ff, 0xcdc20000, 0x00187bff, 0xcde20000,
+ 0x001883ff, 0xd5000000, 0x00188bff, 0xd5200000,
+ 0x001894ff, 0xd5400000, 0x00189cff, 0xd5610000,
+ 0x0018a4ff, 0xd5810000, 0x0018acff, 0xd5a10000,
+ 0x0018b4ff, 0xd5c20000, 0x0018bdff, 0xd5e20000,
+ 0x0018c5ff, 0xde000000, 0x0018cdff, 0xde200000,
+ 0x0018d5ff, 0xde400000, 0x0018deff, 0xde610000,
+ 0x0018e6ff, 0xde810000, 0x0018eeff, 0xdea10000,
+ 0x0018f6ff, 0xdec20000, 0x0018ffff, 0xdee20000,
+ 0x001c00ff, 0xe6000000, 0x001c08ff, 0xe6200000,
+ 0x001c10ff, 0xe6400000, 0x001c18ff, 0xe6610000,
+ 0x001c20ff, 0xe6810000, 0x001c29ff, 0xe6a10000,
+ 0x001c31ff, 0xe6c20000, 0x001c39ff, 0xe6e20000,
+ 0x001c41ff, 0xee000000, 0x001c4aff, 0xee200000,
+ 0x001c52ff, 0xee400000, 0x001c5aff, 0xee610000,
+ 0x001c62ff, 0xee810000, 0x001c6aff, 0xeea10000,
+ 0x001c73ff, 0xeec20000, 0x001c7bff, 0xeee20000,
+ 0x001c83ff, 0xf6000000, 0x001c8bff, 0xf6200000,
+ 0x001c94ff, 0xf6400000, 0x001c9cff, 0xf6610000,
+ 0x001ca4ff, 0xf6810000, 0x001cacff, 0xf6a10000,
+ 0x001cb4ff, 0xf6c20000, 0x001cbdff, 0xf6e20000,
+ 0x001cc5ff, 0xff000000, 0x001ccdff, 0xff200000,
+ 0x001cd5ff, 0xff400000, 0x001cdeff, 0xff610000,
+ 0x001ce6ff, 0xff810000, 0x001ceeff, 0xffa10000,
+ 0x001cf6ff, 0xffc20000, 0x001cffff, 0xffe20000,
+};
+
+static void rtgui_blit_line_2_3(rt_uint8_t* dst_ptr, rt_uint8_t* src_ptr, int line)
+{
+ rt_uint16_t *src;
+ rt_uint32_t *dst;
+
+ src = (rt_uint16_t*)src_ptr;
+ dst = (rt_uint32_t*)dst_ptr;
+
+ line = line / 2;
+ while (line)
+ {
+ *dst++ = RGB565_RGBA8888_LUT[src[LO]*2] + RGB565_RGBA8888_LUT[src[HI]*2+1];
+ line--;
+ src ++;
+ }
+}
+
+void rtgui_blit_line_direct(rt_uint8_t* dst_ptr, rt_uint8_t* src_ptr, int line)
+{
+ rt_memcpy(dst_ptr, src_ptr, line);
+}
+
+/* convert 4bpp to 3bpp */
+static void rtgui_blit_line_4_3(rt_uint8_t* dst_ptr, rt_uint8_t* src_ptr, int line)
+{
+ line = line / 4;
+ while (line)
+ {
+ *dst_ptr++ = *src_ptr++;
+ *dst_ptr++ = *src_ptr++;
+ *dst_ptr++ = *src_ptr++;
+ src_ptr ++;
+ line --;
+ }
+}
+
+static void rtgui_blit_line_1_4(rt_uint8_t* dst_ptr, rt_uint8_t* src_ptr, int line)
+{
+}
+
+static void rtgui_blit_line_2_4(rt_uint8_t* dst_ptr, rt_uint8_t* src_ptr, int line)
+{
+}
+
+/* convert 3bpp to 4bpp */
+static void rtgui_blit_line_3_4(rt_uint8_t* dst_ptr, rt_uint8_t* src_ptr, int line)
+{
+ line = line / 4;
+ while (line)
+ {
+ *dst_ptr++ = *src_ptr++;
+ *dst_ptr++ = *src_ptr++;
+ *dst_ptr++ = *src_ptr++;
+ *dst_ptr++ = 0;
+ line --;
+ }
+}
+
+static const rtgui_blit_line_func _blit_table[5][5] =
+{
+ /* 0_0, 1_0, 2_0, 3_0, 4_0 */
+ {RT_NULL, RT_NULL, RT_NULL, RT_NULL, RT_NULL },
+ /* 0_1, 1_1, 2_1, 3_1, 4_1 */
+ {RT_NULL, rtgui_blit_line_direct, rtgui_blit_line_2_1, rtgui_blit_line_3_1, rtgui_blit_line_4_1 },
+ /* 0_2, 1_2, 2_2, 3_2, 4_2 */
+ {RT_NULL, rtgui_blit_line_1_2, rtgui_blit_line_direct, rtgui_blit_line_3_2, rtgui_blit_line_4_2 },
+ /* 0_3, 1_3, 2_3, 3_3, 4_3 */
+ {RT_NULL, rtgui_blit_line_1_3, rtgui_blit_line_2_3, rtgui_blit_line_direct, rtgui_blit_line_4_3 },
+ /* 0_4, 1_4, 2_4, 3_4, 4_4 */
+ {RT_NULL, rtgui_blit_line_1_4, rtgui_blit_line_2_4, rtgui_blit_line_3_4, rtgui_blit_line_direct },
+};
+
+rtgui_blit_line_func rtgui_blit_line_get(int dst_bpp, int src_bpp)
+{
+ RT_ASSERT(dst_bpp>0 && dst_bpp < 5);
+ RT_ASSERT(src_bpp>0 && src_bpp < 5);
+
+ return _blit_table[dst_bpp][src_bpp];
+}
diff --git a/components/rtgui/common/dc_client.c b/components/rtgui/common/dc_client.c
index 244de209a4..22d2887095 100644
--- a/components/rtgui/common/dc_client.c
+++ b/components/rtgui/common/dc_client.c
@@ -21,9 +21,10 @@
#include <rtgui/driver.h>
#include <rtgui/rtgui_system.h>
-#include <rtgui/widgets/view.h>
+#include <rtgui/rtgui_application.h>
+#include <rtgui/rtgui_server.h>
+#include <rtgui/widgets/container.h>
#include <rtgui/widgets/window.h>
-#include <rtgui/widgets/workbench.h>
#include <rtgui/widgets/title.h>
static void rtgui_dc_client_draw_point(struct rtgui_dc* dc, int x, int y);
@@ -48,14 +49,11 @@ struct rtgui_dc* rtgui_dc_begin_drawing(rtgui_widget_t* owner)
{
RT_ASSERT(owner != RT_NULL);
- if ((rtgui_region_is_flat(&owner->clip) == RT_EOK) &&
+ if ((rtgui_region_is_flat(&owner->clip) == RT_EOK) &&
rtgui_rect_is_equal(&(owner->extent), &(owner->clip.extents)) == RT_EOK)
- {
- /* use hardware DC */
return rtgui_dc_hw_create(owner);
- }
-
- return rtgui_dc_client_create(owner);
+ else
+ return rtgui_dc_client_create(owner);
}
void rtgui_dc_end_drawing(struct rtgui_dc* dc)
@@ -63,7 +61,7 @@ void rtgui_dc_end_drawing(struct rtgui_dc* dc)
dc->engine->fini(dc);
}
-const struct rtgui_dc_engine dc_client_engine =
+const struct rtgui_dc_engine dc_client_engine =
{
rtgui_dc_client_draw_point,
rtgui_dc_client_draw_color_point,
@@ -116,7 +114,7 @@ struct rtgui_dc* rtgui_dc_client_create(rtgui_widget_t* owner)
if (RTGUI_WIDGET_IS_HIDE(widget))
{
RTGUI_WIDGET_DC_SET_UNVISIBLE(owner);
- break;
+ return RT_NULL;
}
widget = widget->parent;
@@ -130,7 +128,7 @@ struct rtgui_dc* rtgui_dc_client_create(rtgui_widget_t* owner)
if (top->drawing == 1)
{
#ifdef RTGUI_USING_MOUSE_CURSOR
-#ifdef __WIN32__
+#ifdef _WIN32
rt_mutex_take(&cursor_mutex, RT_WAITING_FOREVER);
rt_kprintf("hide cursor\n");
rtgui_mouse_hide_cursor();
@@ -141,15 +139,18 @@ struct rtgui_dc* rtgui_dc_client_create(rtgui_widget_t* owner)
#endif
}
}
- else if (RTGUI_IS_WORKBENCH(owner->toplevel) ||
- RTGUI_IS_WIN(owner->toplevel))
+ else if (RTGUI_IS_APPLICATION(owner->toplevel))
+ {
+ RT_ASSERT(0);
+ }
+ else if (RTGUI_IS_WIN(owner->toplevel))
{
rtgui_toplevel_t* top = RTGUI_TOPLEVEL(owner->toplevel);
top->drawing ++;
if (top->drawing == 1)
{
-#ifdef __WIN32__
+#ifdef _WIN32
#ifdef RTGUI_USING_MOUSE_CURSOR
rt_mutex_take(&cursor_mutex, RT_WAITING_FOREVER);
rt_kprintf("hide cursor\n");
@@ -161,7 +162,7 @@ struct rtgui_dc* rtgui_dc_client_create(rtgui_widget_t* owner)
RTGUI_EVENT_UPDATE_BEGIN_INIT(&(eupdate));
eupdate.rect = RTGUI_WIDGET(top)->extent;
- rtgui_thread_send(top->server, (struct rtgui_event*)&eupdate, sizeof(eupdate));
+ rtgui_server_post_event((struct rtgui_event*)&eupdate, sizeof(eupdate));
#endif
}
}
@@ -186,7 +187,7 @@ static rt_bool_t rtgui_dc_client_fini(struct rtgui_dc* dc)
top->drawing --;
if ((top->drawing == 0) && RTGUI_WIDGET_IS_DC_VISIBLE(owner))
{
-#ifdef __WIN32__
+#ifdef _WIN32
#ifdef RTGUI_USING_MOUSE_CURSOR
rt_mutex_release(&cursor_mutex);
/* show cursor */
@@ -206,7 +207,7 @@ static rt_bool_t rtgui_dc_client_fini(struct rtgui_dc* dc)
#endif
}
}
- else if (RTGUI_IS_WORKBENCH(owner->toplevel) ||
+ else if (RTGUI_IS_APPLICATION(owner->toplevel) ||
RTGUI_IS_WIN(owner->toplevel))
{
rtgui_toplevel_t* top = RTGUI_TOPLEVEL(owner->toplevel);
@@ -214,7 +215,7 @@ static rt_bool_t rtgui_dc_client_fini(struct rtgui_dc* dc)
if ((top->drawing == 0) && RTGUI_WIDGET_IS_DC_VISIBLE(owner))
{
-#ifdef __WIN32__
+#ifdef _WIN32
#ifdef RTGUI_USING_MOUSE_CURSOR
rt_mutex_release(&cursor_mutex);
/* show cursor */
@@ -229,7 +230,7 @@ static rt_bool_t rtgui_dc_client_fini(struct rtgui_dc* dc)
RTGUI_EVENT_UPDATE_END_INIT(&(eupdate));
eupdate.rect = owner->extent;
- rtgui_thread_send(top->server, (struct rtgui_event*)&eupdate, sizeof(eupdate));
+ rtgui_server_post_event((struct rtgui_event*)&eupdate, sizeof(eupdate));
#endif
}
}
diff --git a/components/rtgui/common/dc_hw.c b/components/rtgui/common/dc_hw.c
index 5b6670bfd1..2895797974 100644
--- a/components/rtgui/common/dc_hw.c
+++ b/components/rtgui/common/dc_hw.c
@@ -15,9 +15,11 @@
#include <rtgui/dc_hw.h>
#include <rtgui/driver.h>
#include <rtgui/rtgui_system.h>
-#include <rtgui/widgets/view.h>
+#include <rtgui/rtgui_application.h>
+#include <rtgui/rtgui_server.h>
+
+#include <rtgui/widgets/container.h>
#include <rtgui/widgets/window.h>
-#include <rtgui/widgets/workbench.h>
#include <rtgui/widgets/title.h>
static void rtgui_dc_hw_draw_point(struct rtgui_dc* dc, int x, int y);
@@ -81,7 +83,7 @@ struct rtgui_dc* rtgui_dc_hw_create(rtgui_widget_t* owner)
if (RTGUI_WIDGET_IS_HIDE(widget))
{
RTGUI_WIDGET_DC_SET_UNVISIBLE(owner);
- break;
+ return RT_NULL;
}
widget = widget->parent;
@@ -104,7 +106,7 @@ struct rtgui_dc* rtgui_dc_hw_create(rtgui_widget_t* owner)
if (top->drawing == 1)
{
#ifdef RTGUI_USING_MOUSE_CURSOR
-#ifdef __WIN32__
+#ifdef _WIN32
rt_mutex_take(&cursor_mutex, RT_WAITING_FOREVER);
rt_kprintf("hide cursor\n");
rtgui_mouse_hide_cursor();
@@ -115,7 +117,7 @@ struct rtgui_dc* rtgui_dc_hw_create(rtgui_widget_t* owner)
#endif
}
}
- else if (RTGUI_IS_WORKBENCH(owner->toplevel) ||
+ else if (RTGUI_IS_APPLICATION(owner->toplevel) ||
RTGUI_IS_WIN(owner->toplevel))
{
rtgui_toplevel_t* top = RTGUI_TOPLEVEL(owner->toplevel);
@@ -123,7 +125,7 @@ struct rtgui_dc* rtgui_dc_hw_create(rtgui_widget_t* owner)
if (top->drawing == 1)
{
-#ifdef __WIN32__
+#ifdef _WIN32
#ifdef RTGUI_USING_MOUSE_CURSOR
rt_mutex_take(&cursor_mutex, RT_WAITING_FOREVER);
rt_kprintf("hide cursor\n");
@@ -135,7 +137,7 @@ struct rtgui_dc* rtgui_dc_hw_create(rtgui_widget_t* owner)
RTGUI_EVENT_UPDATE_BEGIN_INIT(&(eupdate));
eupdate.rect = RTGUI_WIDGET(top)->extent;
- rtgui_thread_send(top->server, (struct rtgui_event*)&eupdate, sizeof(eupdate));
+ rtgui_server_post_event((struct rtgui_event*)&eupdate, sizeof(eupdate));
#endif
}
}
@@ -162,7 +164,7 @@ static rt_bool_t rtgui_dc_hw_fini(struct rtgui_dc* dc)
top->drawing --;
if ((top->drawing == 0) && RTGUI_WIDGET_IS_DC_VISIBLE(owner))
{
-#ifdef __WIN32__
+#ifdef _WIN32
#ifdef RTGUI_USING_MOUSE_CURSOR
rt_mutex_release(&cursor_mutex);
/* show cursor */
@@ -182,7 +184,7 @@ static rt_bool_t rtgui_dc_hw_fini(struct rtgui_dc* dc)
#endif
}
}
- else if (RTGUI_IS_WORKBENCH(owner->toplevel) ||
+ else if (RTGUI_IS_APPLICATION(owner->toplevel) ||
RTGUI_IS_WIN(owner->toplevel))
{
rtgui_toplevel_t* top = RTGUI_TOPLEVEL(owner->toplevel);
@@ -190,7 +192,7 @@ static rt_bool_t rtgui_dc_hw_fini(struct rtgui_dc* dc)
if ((top->drawing == 0) && RTGUI_WIDGET_IS_DC_VISIBLE(owner))
{
-#ifdef __WIN32__
+#ifdef _WIN32
#ifdef RTGUI_USING_MOUSE_CURSOR
rt_mutex_release(&cursor_mutex);
/* show cursor */
@@ -205,7 +207,7 @@ static rt_bool_t rtgui_dc_hw_fini(struct rtgui_dc* dc)
RTGUI_EVENT_UPDATE_END_INIT(&(eupdate));
eupdate.rect = owner->extent;
- rtgui_thread_send(top->server, (struct rtgui_event*)&eupdate, sizeof(eupdate));
+ rtgui_server_post_event((struct rtgui_event*)&eupdate, sizeof(eupdate));
#endif
}
}
diff --git a/components/rtgui/common/filerw.c b/components/rtgui/common/filerw.c
index 3d50bbb36f..8fd8073970 100644
--- a/components/rtgui/common/filerw.c
+++ b/components/rtgui/common/filerw.c
@@ -1,463 +1,463 @@
-/*
- * File : filerw.c
- * This file is part of RT-Thread RTOS
- * COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
- *
- * The license and distribution terms for this file may be
- * found in the file LICENSE in this distribution or at
- * http://www.rt-thread.org/license/LICENSE
- *
- * Change Logs:
- * Date Author Notes
- * 2009-10-16 Bernard first version
- */
-
-#include <rtgui/filerw.h>
-#include <rtgui/rtgui_system.h>
-
-#ifdef RTGUI_USING_DFS_FILERW
-#include <dfs_posix.h>
-
-/* standard file read/write */
-struct rtgui_filerw_stdio
-{
- /* inherit from rtgui_filerw */
- struct rtgui_filerw parent;
-
- int fd;
- rt_bool_t eof;
-};
-
-static int stdio_seek(struct rtgui_filerw *context, rt_off_t offset, int whence)
-{
- struct rtgui_filerw_stdio* stdio_filerw = (struct rtgui_filerw_stdio *)context;
- int stdio_whence[3] = {SEEK_SET, SEEK_CUR, SEEK_END};
-
- if (whence < RTGUI_FILE_SEEK_SET || whence > RTGUI_FILE_SEEK_END)
- {
- return -1;
- }
-
- return lseek(stdio_filerw->fd, offset, stdio_whence[whence]);
-}
-
-static int stdio_read(struct rtgui_filerw *context, void *ptr, rt_size_t size, rt_size_t maxnum)
-{
- int result;
-
- struct rtgui_filerw_stdio* stdio_filerw = (struct rtgui_filerw_stdio *)context;
-
- /* end of file */
- if (stdio_filerw->eof == RT_TRUE) return -1;
-
- result = read(stdio_filerw->fd, ptr, size * maxnum);
- if (result == 0) stdio_filerw->eof = RT_TRUE;
-
- return result;
-}
-
-static int stdio_write(struct rtgui_filerw *context, const void *ptr, rt_size_t size, rt_size_t num)
-{
- struct rtgui_filerw_stdio* stdio_filerw = (struct rtgui_filerw_stdio *)context;
-
- return write(stdio_filerw->fd, (char*)ptr, size * num);
-}
-
-static int stdio_tell(struct rtgui_filerw* context)
-{
- struct rtgui_filerw_stdio* stdio_filerw = (struct rtgui_filerw_stdio *)context;
-
- return lseek(stdio_filerw->fd, 0, SEEK_CUR);
-}
-
-static int stdio_eof(struct rtgui_filerw* context)
-{
- int result;
- struct rtgui_filerw_stdio* stdio_filerw = (struct rtgui_filerw_stdio *)context;
-
- if (stdio_filerw->eof == RT_TRUE) result = 1;
- else result = -1;
-
- return result;
-}
-
-static int stdio_close(struct rtgui_filerw *context)
-{
- struct rtgui_filerw_stdio* stdio_filerw = (struct rtgui_filerw_stdio *)context;
-
- if (stdio_filerw)
- {
- close(stdio_filerw->fd);
- rtgui_free(stdio_filerw);
-
- return 0;
- }
-
- return -1;
-}
-#elif defined(RTGUI_USING_STDIO_FILERW)
-#include <stdio.h>
-
-/* standard file read/write */
-struct rtgui_filerw_stdio
-{
- /* inherit from rtgui_filerw */
- struct rtgui_filerw parent;
-
- FILE* fp;
-};
-
-static int stdio_seek(struct rtgui_filerw *context, rt_off_t offset, int whence)
-{
- struct rtgui_filerw_stdio* stdio_filerw = (struct rtgui_filerw_stdio *)context;
- int stdio_whence[3] = {SEEK_SET, SEEK_CUR, SEEK_END};
-
- if (whence < RTGUI_FILE_SEEK_SET || whence > RTGUI_FILE_SEEK_END)
- {
- return -1;
- }
-
- if (fseek(stdio_filerw->fp, offset, stdio_whence[whence]) == 0)
- {
- return ftell(stdio_filerw->fp);
- }
-
- return -1;
-}
-
-static int stdio_read(struct rtgui_filerw *context, void *ptr, rt_size_t size, rt_size_t maxnum)
-{
- size_t nread;
- struct rtgui_filerw_stdio* stdio_filerw = (struct rtgui_filerw_stdio *)context;
-
- nread = fread(ptr, size, maxnum, stdio_filerw->fp);
- if (nread == 0 && ferror(stdio_filerw->fp))
- {
- return -1;
- }
-
- return nread;
-}
-
-static int stdio_write(struct rtgui_filerw *context, const void *ptr, rt_size_t size, rt_size_t num)
-{
- size_t nwrote;
- struct rtgui_filerw_stdio* stdio_filerw = (struct rtgui_filerw_stdio *)context;
-
- nwrote = fwrite(ptr, size, num, stdio_filerw->fp);
-
- if ( nwrote == 0 && ferror(stdio_filerw->fp) )
- {
- return -1;
- }
-
- return nwrote;
-}
-
-static int stdio_tell(struct rtgui_filerw* context)
-{
- struct rtgui_filerw_stdio* stdio_filerw = (struct rtgui_filerw_stdio *)context;
-
- return ftell(stdio_filerw->fp);
-}
-
-static int stdio_eof(struct rtgui_filerw* context)
-{
- struct rtgui_filerw_stdio* stdio_filerw = (struct rtgui_filerw_stdio *)context;
-
- return feof(stdio_filerw->fp);
-}
-
-static int stdio_close(struct rtgui_filerw *context)
-{
- struct rtgui_filerw_stdio* stdio_filerw = (struct rtgui_filerw_stdio *)context;
-
- if (stdio_filerw)
- {
- fclose(stdio_filerw->fp);
- rtgui_free(stdio_filerw);
-
- return 0;
- }
-
- return -1;
-}
-#endif
-
-/* memory file read/write */
-struct rtgui_filerw_mem
-{
- /* inherit from rtgui_filerw */
- struct rtgui_filerw parent;
-
- const rt_uint8_t *mem_base, *mem_position, *mem_end;
-};
-
-static int mem_seek(struct rtgui_filerw *context, rt_off_t offset, int whence)
-{
- const rt_uint8_t* newpos;
- struct rtgui_filerw_mem* mem = (struct rtgui_filerw_mem*)context;
-
- RT_ASSERT(mem != RT_NULL);
-
- switch (whence) {
- case RTGUI_FILE_SEEK_SET:
- newpos = mem->mem_base + offset;
- break;
-
- case RTGUI_FILE_SEEK_CUR:
- newpos = mem->mem_position + offset;
- break;
-
- case RTGUI_FILE_SEEK_END:
- newpos = mem->mem_end + offset;
- break;
-
- default:
- return -1;
- }
-
- if ( newpos < mem->mem_base )
- newpos = mem->mem_base;
-
- if ( newpos > mem->mem_end )
- newpos = mem->mem_end;
-
- mem->mem_position = newpos;
- return mem->mem_position- mem->mem_base;
-}
-
-static int mem_read(struct rtgui_filerw *context, void *ptr, rt_size_t size, rt_size_t maxnum)
-{
- int total_bytes;
- int mem_available;
- struct rtgui_filerw_mem* mem = (struct rtgui_filerw_mem*)context;
-
- total_bytes = (maxnum * size);
- if ( (maxnum <= 0) || (size <= 0) || ((total_bytes / maxnum) != size) )
- {
- return -1;
- }
-
- mem_available = mem->mem_end - mem->mem_position;
- if (total_bytes > mem_available)
- total_bytes = mem_available;
-
- rt_memcpy(ptr, mem->mem_position, total_bytes);
- mem->mem_position += total_bytes;
-
- return (total_bytes / size);
-}
-
-static int mem_write(struct rtgui_filerw *context, const void *ptr, rt_size_t size, rt_size_t num)
-{
-#if 0
- struct rtgui_filerw_mem* mem = (struct rtgui_filerw_mem*)context;
-
- if ((mem->mem_position + (num * size)) > mem->mem_end)
- {
- num = (mem->mem_end - mem->mem_position)/size;
- }
-
- rt_memcpy(mem->mem_position, ptr, num*size);
- mem->mem_position += num*size;
-
- return num;
-#else
- return 0; /* not support memory write */
-#endif
-}
-
-static int mem_tell(struct rtgui_filerw* context)
-{
- struct rtgui_filerw_mem* mem = (struct rtgui_filerw_mem*)context;
-
- return mem->mem_position - mem->mem_base;
-}
-
-static int mem_eof(struct rtgui_filerw* context)
-{
- struct rtgui_filerw_mem* mem = (struct rtgui_filerw_mem*)context;
-
- return mem->mem_position >= mem->mem_end;
-}
-
-static int mem_close(struct rtgui_filerw *context)
-{
- struct rtgui_filerw_mem* mem = (struct rtgui_filerw_mem*)context;
-
- if (mem != RT_NULL)
- {
- rtgui_free(mem);
- return 0;
- }
-
- return -1;
-}
-
-const rt_uint8_t* rtgui_filerw_mem_getdata(struct rtgui_filerw* context)
-{
- struct rtgui_filerw_mem* mem = (struct rtgui_filerw_mem*)context;
-
- /* check whether it's a memory filerw */
- if (mem->parent.read != mem_read) return RT_NULL;
-
- return mem->mem_base;
-}
-
-/* file read/write public interface */
-#ifdef RTGUI_USING_DFS_FILERW
-static int parse_mode(const char *mode)
-{
- int f=0;
-
- for (;;)
- {
- switch (*mode)
- {
- case 0: return f;
- case 'b': break;
- case 'r': f=O_RDONLY; break;
- case 'w': f=O_WRONLY|O_CREAT|O_TRUNC; break;
- case 'a': f=O_WRONLY|O_CREAT|O_APPEND; break;
- case '+': f=(f&(~O_WRONLY))|O_RDWR; break;
- }
-
- ++mode;
- }
-}
-
-struct rtgui_filerw* rtgui_filerw_create_file(const char* filename, const char* mode)
-{
- int fd;
- struct rtgui_filerw_stdio *rw;
-
- RT_ASSERT(filename != RT_NULL);
-
- rw = RT_NULL;
- fd = open(filename, parse_mode(mode), 0);
-
- if ( fd >= 0 )
- {
- rw = (struct rtgui_filerw_stdio*) rtgui_malloc(sizeof(struct rtgui_filerw_stdio));
- if (rw != RT_NULL)
- {
- rw->parent.seek = stdio_seek;
- rw->parent.read = stdio_read;
- rw->parent.write = stdio_write;
- rw->parent.tell = stdio_tell;
- rw->parent.close = stdio_close;
- rw->parent.eof = stdio_eof;
-
- rw->fd = fd;
- rw->eof = RT_FALSE;
- }
- }
-
- return &(rw->parent);
-}
-#elif defined(RTGUI_USING_STDIO_FILERW)
-struct rtgui_filerw* rtgui_filerw_create_file(const char* filename, const char* mode)
-{
- FILE *fp;
- struct rtgui_filerw_stdio *rw;
-
- RT_ASSERT(filename != RT_NULL);
-
- rw = RT_NULL;
- fp = fopen(filename, mode);
-
- if ( fp != NULL )
- {
- rw = (struct rtgui_filerw_stdio*) rtgui_malloc(sizeof(struct rtgui_filerw_stdio));
- if (rw != RT_NULL)
- {
- rw->parent.seek = stdio_seek;
- rw->parent.read = stdio_read;
- rw->parent.write = stdio_write;
- rw->parent.tell = stdio_tell;
- rw->parent.close = stdio_close;
- rw->parent.eof = stdio_eof;
-
- rw->fp = fp;
- }
- }
-
- return &(rw->parent);
-}
-#endif
-
-struct rtgui_filerw* rtgui_filerw_create_mem(const rt_uint8_t* mem, rt_size_t size)
-{
- struct rtgui_filerw_mem* rw;
- RT_ASSERT(mem != RT_NULL);
-
- rw = (struct rtgui_filerw_mem*) rtgui_malloc(sizeof(struct rtgui_filerw_mem));
- if (rw != RT_NULL)
- {
- rw->parent.seek = mem_seek;
- rw->parent.read = mem_read;
- rw->parent.write = mem_write;
- rw->parent.tell = mem_tell;
- rw->parent.eof = mem_eof;
- rw->parent.close = mem_close;
-
- rw->mem_base = mem;
- rw->mem_position = mem;
- rw->mem_end = mem + size;
- }
-
- return &(rw->parent);
-}
-
-int rtgui_filerw_seek(struct rtgui_filerw* context, rt_off_t offset, int whence)
-{
- RT_ASSERT(context != RT_NULL);
-
- return context->seek(context, offset, whence);
-}
-
-int rtgui_filerw_read(struct rtgui_filerw* context, void* buffer, rt_size_t size, rt_size_t count)
-{
- RT_ASSERT(context != RT_NULL);
-
- return context->read(context, buffer, size, count);
-}
-
-int rtgui_filerw_write(struct rtgui_filerw* context, const void* buffer, rt_size_t size, rt_size_t count)
-{
- RT_ASSERT(context != RT_NULL);
-
- return context->write(context, buffer, size, count);
-}
-
-int rtgui_filerw_eof (struct rtgui_filerw* context)
-{
- RT_ASSERT(context != RT_NULL);
-
- return context->eof(context);
-}
-
-int rtgui_filerw_tell(struct rtgui_filerw* context)
-{
- RT_ASSERT(context != RT_NULL);
-
- return context->tell(context);
-}
-
-int rtgui_filerw_close(struct rtgui_filerw* context)
-{
- int result;
-
- RT_ASSERT(context != RT_NULL);
-
- /* close context */
- result = context->close(context);
- if (result != 0)
- {
- /* close file failed */
- return -1;
- }
-
- return 0;
-}
+/*
+ * File : filerw.c
+ * This file is part of RT-Thread RTOS
+ * COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rt-thread.org/license/LICENSE
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2009-10-16 Bernard first version
+ */
+
+#include <rtgui/filerw.h>
+#include <rtgui/rtgui_system.h>
+
+#ifdef RTGUI_USING_DFS_FILERW
+#include <dfs_posix.h>
+
+/* standard file read/write */
+struct rtgui_filerw_stdio
+{
+ /* inherit from rtgui_filerw */
+ struct rtgui_filerw parent;
+
+ int fd;
+ rt_bool_t eof;
+};
+
+static int stdio_seek(struct rtgui_filerw *context, rt_off_t offset, int whence)
+{
+ struct rtgui_filerw_stdio* stdio_filerw = (struct rtgui_filerw_stdio *)context;
+ int stdio_whence[3] = {SEEK_SET, SEEK_CUR, SEEK_END};
+
+ if (whence < RTGUI_FILE_SEEK_SET || whence > RTGUI_FILE_SEEK_END)
+ {
+ return -1;
+ }
+
+ return lseek(stdio_filerw->fd, offset, stdio_whence[whence]);
+}
+
+static int stdio_read(struct rtgui_filerw *context, void *ptr, rt_size_t size, rt_size_t maxnum)
+{
+ int result;
+
+ struct rtgui_filerw_stdio* stdio_filerw = (struct rtgui_filerw_stdio *)context;
+
+ /* end of file */
+ if (stdio_filerw->eof == RT_TRUE) return -1;
+
+ result = read(stdio_filerw->fd, ptr, size * maxnum);
+ if (result == 0) stdio_filerw->eof = RT_TRUE;
+
+ return result;
+}
+
+static int stdio_write(struct rtgui_filerw *context, const void *ptr, rt_size_t size, rt_size_t num)
+{
+ struct rtgui_filerw_stdio* stdio_filerw = (struct rtgui_filerw_stdio *)context;
+
+ return write(stdio_filerw->fd, (char*)ptr, size * num);
+}
+
+static int stdio_tell(struct rtgui_filerw* context)
+{
+ struct rtgui_filerw_stdio* stdio_filerw = (struct rtgui_filerw_stdio *)context;
+
+ return lseek(stdio_filerw->fd, 0, SEEK_CUR);
+}
+
+static int stdio_eof(struct rtgui_filerw* context)
+{
+ int result;
+ struct rtgui_filerw_stdio* stdio_filerw = (struct rtgui_filerw_stdio *)context;
+
+ if (stdio_filerw->eof == RT_TRUE) result = 1;
+ else result = -1;
+
+ return result;
+}
+
+static int stdio_close(struct rtgui_filerw *context)
+{
+ struct rtgui_filerw_stdio* stdio_filerw = (struct rtgui_filerw_stdio *)context;
+
+ if (stdio_filerw)
+ {
+ close(stdio_filerw->fd);
+ rtgui_free(stdio_filerw);
+
+ return 0;
+ }
+
+ return -1;
+}
+#elif defined(RTGUI_USING_STDIO_FILERW)
+#include <stdio.h>
+
+/* standard file read/write */
+struct rtgui_filerw_stdio
+{
+ /* inherit from rtgui_filerw */
+ struct rtgui_filerw parent;
+
+ FILE* fp;
+};
+
+static int stdio_seek(struct rtgui_filerw *context, rt_off_t offset, int whence)
+{
+ struct rtgui_filerw_stdio* stdio_filerw = (struct rtgui_filerw_stdio *)context;
+ int stdio_whence[3] = {SEEK_SET, SEEK_CUR, SEEK_END};
+
+ if (whence < RTGUI_FILE_SEEK_SET || whence > RTGUI_FILE_SEEK_END)
+ {
+ return -1;
+ }
+
+ if (fseek(stdio_filerw->fp, offset, stdio_whence[whence]) == 0)
+ {
+ return ftell(stdio_filerw->fp);
+ }
+
+ return -1;
+}
+
+static int stdio_read(struct rtgui_filerw *context, void *ptr, rt_size_t size, rt_size_t maxnum)
+{
+ size_t nread;
+ struct rtgui_filerw_stdio* stdio_filerw = (struct rtgui_filerw_stdio *)context;
+
+ nread = fread(ptr, size, maxnum, stdio_filerw->fp);
+ if (nread == 0 && ferror(stdio_filerw->fp))
+ {
+ return -1;
+ }
+
+ return nread;
+}
+
+static int stdio_write(struct rtgui_filerw *context, const void *ptr, rt_size_t size, rt_size_t num)
+{
+ size_t nwrote;
+ struct rtgui_filerw_stdio* stdio_filerw = (struct rtgui_filerw_stdio *)context;
+
+ nwrote = fwrite(ptr, size, num, stdio_filerw->fp);
+
+ if ( nwrote == 0 && ferror(stdio_filerw->fp) )
+ {
+ return -1;
+ }
+
+ return nwrote;
+}
+
+static int stdio_tell(struct rtgui_filerw* context)
+{
+ struct rtgui_filerw_stdio* stdio_filerw = (struct rtgui_filerw_stdio *)context;
+
+ return ftell(stdio_filerw->fp);
+}
+
+static int stdio_eof(struct rtgui_filerw* context)
+{
+ struct rtgui_filerw_stdio* stdio_filerw = (struct rtgui_filerw_stdio *)context;
+
+ return feof(stdio_filerw->fp);
+}
+
+static int stdio_close(struct rtgui_filerw *context)
+{
+ struct rtgui_filerw_stdio* stdio_filerw = (struct rtgui_filerw_stdio *)context;
+
+ if (stdio_filerw)
+ {
+ fclose(stdio_filerw->fp);
+ rtgui_free(stdio_filerw);
+
+ return 0;
+ }
+
+ return -1;
+}
+#endif
+
+/* memory file read/write */
+struct rtgui_filerw_mem
+{
+ /* inherit from rtgui_filerw */
+ struct rtgui_filerw parent;
+
+ const rt_uint8_t *mem_base, *mem_position, *mem_end;
+};
+
+static int mem_seek(struct rtgui_filerw *context, rt_off_t offset, int whence)
+{
+ const rt_uint8_t* newpos;
+ struct rtgui_filerw_mem* mem = (struct rtgui_filerw_mem*)context;
+
+ RT_ASSERT(mem != RT_NULL);
+
+ switch (whence) {
+ case RTGUI_FILE_SEEK_SET:
+ newpos = mem->mem_base + offset;
+ break;
+
+ case RTGUI_FILE_SEEK_CUR:
+ newpos = mem->mem_position + offset;
+ break;
+
+ case RTGUI_FILE_SEEK_END:
+ newpos = mem->mem_end + offset;
+ break;
+
+ default:
+ return -1;
+ }
+
+ if ( newpos < mem->mem_base )
+ newpos = mem->mem_base;
+
+ if ( newpos > mem->mem_end )
+ newpos = mem->mem_end;
+
+ mem->mem_position = newpos;
+ return mem->mem_position- mem->mem_base;
+}
+
+static int mem_read(struct rtgui_filerw *context, void *ptr, rt_size_t size, rt_size_t maxnum)
+{
+ int total_bytes;
+ int mem_available;
+ struct rtgui_filerw_mem* mem = (struct rtgui_filerw_mem*)context;
+
+ total_bytes = (maxnum * size);
+ if ( (maxnum <= 0) || (size <= 0) || ((total_bytes / maxnum) != size) )
+ {
+ return -1;
+ }
+
+ mem_available = mem->mem_end - mem->mem_position;
+ if (total_bytes > mem_available)
+ total_bytes = mem_available;
+
+ rt_memcpy(ptr, mem->mem_position, total_bytes);
+ mem->mem_position += total_bytes;
+
+ return (total_bytes / size);
+}
+
+static int mem_write(struct rtgui_filerw *context, const void *ptr, rt_size_t size, rt_size_t num)
+{
+#if 0
+ struct rtgui_filerw_mem* mem = (struct rtgui_filerw_mem*)context;
+
+ if ((mem->mem_position + (num * size)) > mem->mem_end)
+ {
+ num = (mem->mem_end - mem->mem_position)/size;
+ }
+
+ rt_memcpy(mem->mem_position, ptr, num*size);
+ mem->mem_position += num*size;
+
+ return num;
+#else
+ return 0; /* not support memory write */
+#endif
+}
+
+static int mem_tell(struct rtgui_filerw* context)
+{
+ struct rtgui_filerw_mem* mem = (struct rtgui_filerw_mem*)context;
+
+ return mem->mem_position - mem->mem_base;
+}
+
+static int mem_eof(struct rtgui_filerw* context)
+{
+ struct rtgui_filerw_mem* mem = (struct rtgui_filerw_mem*)context;
+
+ return mem->mem_position >= mem->mem_end;
+}
+
+static int mem_close(struct rtgui_filerw *context)
+{
+ struct rtgui_filerw_mem* mem = (struct rtgui_filerw_mem*)context;
+
+ if (mem != RT_NULL)
+ {
+ rtgui_free(mem);
+ return 0;
+ }
+
+ return -1;
+}
+
+const rt_uint8_t* rtgui_filerw_mem_getdata(struct rtgui_filerw* context)
+{
+ struct rtgui_filerw_mem* mem = (struct rtgui_filerw_mem*)context;
+
+ /* check whether it's a memory filerw */
+ if (mem->parent.read != mem_read) return RT_NULL;
+
+ return mem->mem_base;
+}
+
+/* file read/write public interface */
+#ifdef RTGUI_USING_DFS_FILERW
+static int parse_mode(const char *mode)
+{
+ int f=0;
+
+ for (;;)
+ {
+ switch (*mode)
+ {
+ case 0: return f;
+ case 'b': break;
+ case 'r': f=O_RDONLY; break;
+ case 'w': f=O_WRONLY|O_CREAT|O_TRUNC; break;
+ case 'a': f=O_WRONLY|O_CREAT|O_APPEND; break;
+ case '+': f=(f&(~O_WRONLY))|O_RDWR; break;
+ }
+
+ ++mode;
+ }
+}
+
+struct rtgui_filerw* rtgui_filerw_create_file(const char* filename, const char* mode)
+{
+ int fd;
+ struct rtgui_filerw_stdio *rw;
+
+ RT_ASSERT(filename != RT_NULL);
+
+ rw = RT_NULL;
+ fd = open(filename, parse_mode(mode), 0);
+
+ if ( fd >= 0 )
+ {
+ rw = (struct rtgui_filerw_stdio*) rtgui_malloc(sizeof(struct rtgui_filerw_stdio));
+ if (rw != RT_NULL)
+ {
+ rw->parent.seek = stdio_seek;
+ rw->parent.read = stdio_read;
+ rw->parent.write = stdio_write;
+ rw->parent.tell = stdio_tell;
+ rw->parent.close = stdio_close;
+ rw->parent.eof = stdio_eof;
+
+ rw->fd = fd;
+ rw->eof = RT_FALSE;
+ }
+ }
+
+ return &(rw->parent);
+}
+#elif defined(RTGUI_USING_STDIO_FILERW)
+struct rtgui_filerw* rtgui_filerw_create_file(const char* filename, const char* mode)
+{
+ FILE *fp;
+ struct rtgui_filerw_stdio *rw;
+
+ RT_ASSERT(filename != RT_NULL);
+
+ rw = RT_NULL;
+ fp = fopen(filename, mode);
+
+ if ( fp != NULL )
+ {
+ rw = (struct rtgui_filerw_stdio*) rtgui_malloc(sizeof(struct rtgui_filerw_stdio));
+ if (rw != RT_NULL)
+ {
+ rw->parent.seek = stdio_seek;
+ rw->parent.read = stdio_read;
+ rw->parent.write = stdio_write;
+ rw->parent.tell = stdio_tell;
+ rw->parent.close = stdio_close;
+ rw->parent.eof = stdio_eof;
+
+ rw->fp = fp;
+ }
+ }
+
+ return &(rw->parent);
+}
+#endif
+
+struct rtgui_filerw* rtgui_filerw_create_mem(const rt_uint8_t* mem, rt_size_t size)
+{
+ struct rtgui_filerw_mem* rw;
+ RT_ASSERT(mem != RT_NULL);
+
+ rw = (struct rtgui_filerw_mem*) rtgui_malloc(sizeof(struct rtgui_filerw_mem));
+ if (rw != RT_NULL)
+ {
+ rw->parent.seek = mem_seek;
+ rw->parent.read = mem_read;
+ rw->parent.write = mem_write;
+ rw->parent.tell = mem_tell;
+ rw->parent.eof = mem_eof;
+ rw->parent.close = mem_close;
+
+ rw->mem_base = mem;
+ rw->mem_position = mem;
+ rw->mem_end = mem + size;
+ }
+
+ return &(rw->parent);
+}
+
+int rtgui_filerw_seek(struct rtgui_filerw* context, rt_off_t offset, int whence)
+{
+ RT_ASSERT(context != RT_NULL);
+
+ return context->seek(context, offset, whence);
+}
+
+int rtgui_filerw_read(struct rtgui_filerw* context, void* buffer, rt_size_t size, rt_size_t count)
+{
+ RT_ASSERT(context != RT_NULL);
+
+ return context->read(context, buffer, size, count);
+}
+
+int rtgui_filerw_write(struct rtgui_filerw* context, const void* buffer, rt_size_t size, rt_size_t count)
+{
+ RT_ASSERT(context != RT_NULL);
+
+ return context->write(context, buffer, size, count);
+}
+
+int rtgui_filerw_eof (struct rtgui_filerw* context)
+{
+ RT_ASSERT(context != RT_NULL);
+
+ return context->eof(context);
+}
+
+int rtgui_filerw_tell(struct rtgui_filerw* context)
+{
+ RT_ASSERT(context != RT_NULL);
+
+ return context->tell(context);
+}
+
+int rtgui_filerw_close(struct rtgui_filerw* context)
+{
+ int result;
+
+ RT_ASSERT(context != RT_NULL);
+
+ /* close context */
+ result = context->close(context);
+ if (result != 0)
+ {
+ /* close file failed */
+ return -1;
+ }
+
+ return 0;
+}
diff --git a/components/rtgui/common/font_freetype.c b/components/rtgui/common/font_freetype.c
index dc231fc04b..11d7788272 100644
--- a/components/rtgui/common/font_freetype.c
+++ b/components/rtgui/common/font_freetype.c
@@ -1,237 +1,237 @@
-#include <rtgui/font_freetype.h>
-
-#ifdef RTGUI_USING_TTF
-#include <ft2build.h>
-#include <freetype/freetype.h>
-#include <freetype/ftglyph.h>
-
-static void rtgui_freetype_font_draw_text(struct rtgui_font* font, struct rtgui_dc* dc, const char* text, rt_ubase_t len, struct rtgui_rect* rect);
-static void rtgui_freetype_font_get_metrics(struct rtgui_font* font, const char* text, rtgui_rect_t* rect);
-
-struct rtgui_font_engine freetype_font_engine =
-{
- RT_NULL,
- RT_NULL,
- rtgui_freetype_font_draw_text,
- rtgui_freetype_font_get_metrics
-};
-
-struct rtgui_freetype_font
-{
- int bold;
- int italic;
-
- FT_Face face;
- FT_Library library;
-};
-
-static void gbk_to_unicode(rt_uint16_t *unicode, const unsigned char *text, int len)
-{
- int i;
- unsigned short wch;
- extern unsigned short ff_convert(unsigned short wch, int direction);
-
- for (i = 0; i < len; )
- {
- if (*text < 0x80)
- {
- wch = *text;
- *unicode = ff_convert(wch, 1);
- text ++;
- i ++;
- }
- else
- {
- wch = wch = *(text + 1) | (*text << 8);
- *unicode = ff_convert(wch, 1);
- text += 2;
- i += 2;
- }
-
- unicode ++;
- }
-
- *unicode = '\0';
-}
-
-static void rtgui_freetype_font_draw_text(struct rtgui_font* font, struct rtgui_dc* dc, const char* text, rt_ubase_t len, struct rtgui_rect* rect)
-{
- int index = 0;
- FT_Error err = 0;
- rt_uint16_t *text_short, *text_ptr;
- struct rtgui_freetype_font* freetype;
-
- RT_ASSERT(font != RT_NULL);
- freetype = (struct rtgui_freetype_font*) font->data;
- RT_ASSERT(freetype != RT_NULL);
-
- /* allocate unicode buffer */
- text_short = (rt_uint16_t*)rtgui_malloc((len + 1)* 2);
- if (text_short == RT_NULL) return ; /* out of memory */
-
- /* convert gbk to unicode */
- gbk_to_unicode(text_short, text, len);
- text_ptr = text_short;
-
- while (*text_ptr)
- {
- index = FT_Get_Char_Index(freetype->face, *text_ptr);
- err = FT_Load_Glyph(freetype->face, index, FT_LOAD_DEFAULT|FT_LOAD_RENDER);
- if (err == 0)
- {
- int rows, x;
- rt_uint8_t* ptr;
-
- /* render font */
- ptr = (rt_uint8_t*)freetype->face->glyph->bitmap.buffer;
-
- for (rows = 0; rows < freetype->face->glyph->bitmap.rows; rows ++)
- for (x = 0; x < freetype->face->glyph->bitmap.width; x++)
- {
- if (*ptr > 0)
- rtgui_dc_draw_color_point(dc, rect->x1 + x, rect->y1 + rows, RTGUI_RGB(0xff - *ptr, 0xff - *ptr, 0xff - *ptr));
- ptr ++;
- }
- }
-
- text_ptr ++;
- rect->x1 += freetype->face->glyph->bitmap.width;
- }
-
- /* release unicode buffer */
- rtgui_free(text_short);
-}
-
-static void rtgui_freetype_font_get_metrics(struct rtgui_font* font, const char* text, rtgui_rect_t* rect)
-{
- int index = 0, len;
- FT_Error err = 0;
- rt_uint16_t w = 0, h = 0;
- rt_uint16_t *text_short, *text_ptr;
- struct rtgui_freetype_font* freetype;
-
- RT_ASSERT(font != RT_NULL);
- RT_ASSERT(rect != RT_NULL);
- freetype = (struct rtgui_freetype_font*) font->data;
- RT_ASSERT(freetype != RT_NULL);
-
- len = strlen(text);
- memset(rect, 0, sizeof(struct rtgui_rect));
-
- /* allocate unicode buffer */
- text_short = (rt_uint16_t*)rtgui_malloc((len + 1)* 2);
- if (text_short == RT_NULL) return ; /* out of memory */
-
- /* convert gbk to unicode */
- gbk_to_unicode(text_short, text, len);
- text_ptr = text_short;
-
- while (*text_ptr)
- {
- index = FT_Get_Char_Index(freetype->face, *text_ptr);
- err = FT_Load_Glyph(freetype->face, index, FT_LOAD_DEFAULT);
-
- if (err == 0)
- {
- w += freetype->face->glyph->bitmap.width;
- if (freetype->face->glyph->bitmap.rows > h)
- {
- h = freetype->face->glyph->bitmap.rows;
- }
- }
-
- text_ptr ++;
- }
-
- rect->x1 = 0; rect->y1 = 0;
- rect->x2 = w; rect->y2 = h;
-
- /* release unicode buffer */
- rtgui_free(text_short);
-}
-
-rtgui_font_t* rtgui_freetype_font_create(const char* filename, int bold, int italic, rt_size_t size)
-{
- FT_Error err = 0;
- struct rtgui_font* font;
-
- font = (struct rtgui_font*) rtgui_malloc (sizeof(struct rtgui_font));
- if (font != RT_NULL)
- {
- struct rtgui_freetype_font* freetype;
-
- freetype = (struct rtgui_freetype_font*) rtgui_malloc (sizeof(struct rtgui_freetype_font));
- if (freetype == RT_NULL)
- {
- rt_free(font);
- font = RT_NULL;
- }
- else
- {
- err = FT_Init_FreeType(&freetype->library);
- if((err = FT_New_Face(freetype->library, filename, 0, &freetype->face)))
- {
- FT_Done_FreeType(freetype->library);
-
- rt_free(font);
- font = RT_NULL;
- }
- else
- {
- err = FT_Select_Charmap(freetype->face, ft_encoding_unicode);
- if(err)
- {
- err = FT_Select_Charmap(freetype->face, ft_encoding_latin_1 );
- }
-
- err = FT_Set_Pixel_Sizes(freetype->face, 0, size);
- if (err != 0)
- {
- rtgui_free(font);
- font = RT_NULL;
-
- FT_Done_FreeType(freetype->library);
- rtgui_free(freetype);
-
- return RT_NULL;
- }
-
- freetype->bold = bold;
- freetype->italic = italic;
-
- rt_kprintf("fonfile:%s\n", filename);
- rt_kprintf("font family_name:%s\n", freetype->face->family_name);
- rt_kprintf("font style_name:%s\n", freetype->face->style_name);
-
- /* set user data */
- font->data = freetype;
- font->family = rt_strdup(freetype->face->family_name);
- font->height = (rt_uint16_t)size;
- font->refer_count = 0;
- font->engine = &freetype_font_engine;
-
- /* add to system */
- rtgui_font_system_add_font(font);
- }
- }
- }
-
- return font;
-}
-
-void rtgui_freetype_font_destroy(rtgui_font_t* font)
-{
- struct rtgui_freetype_font* freetype;
-
- RT_ASSERT(font != RT_NULL);
- freetype = (struct rtgui_freetype_font*) font->data;
- RT_ASSERT(freetype != RT_NULL);
-
- rtgui_font_system_remove_font(font);
-
- FT_Done_Face (freetype->face);
- FT_Done_FreeType(freetype->library);
- rtgui_free(freetype);
- rtgui_free(font);
-}
-#endif
+#include <rtgui/font_freetype.h>
+
+#ifdef RTGUI_USING_TTF
+#include <ft2build.h>
+#include <freetype/freetype.h>
+#include <freetype/ftglyph.h>
+
+static void rtgui_freetype_font_draw_text(struct rtgui_font* font, struct rtgui_dc* dc, const char* text, rt_ubase_t len, struct rtgui_rect* rect);
+static void rtgui_freetype_font_get_metrics(struct rtgui_font* font, const char* text, rtgui_rect_t* rect);
+
+struct rtgui_font_engine freetype_font_engine =
+{
+ RT_NULL,
+ RT_NULL,
+ rtgui_freetype_font_draw_text,
+ rtgui_freetype_font_get_metrics
+};
+
+struct rtgui_freetype_font
+{
+ int bold;
+ int italic;
+
+ FT_Face face;
+ FT_Library library;
+};
+
+static void gbk_to_unicode(rt_uint16_t *unicode, const unsigned char *text, int len)
+{
+ int i;
+ unsigned short wch;
+ extern unsigned short ff_convert(unsigned short wch, int direction);
+
+ for (i = 0; i < len; )
+ {
+ if (*text < 0x80)
+ {
+ wch = *text;
+ *unicode = ff_convert(wch, 1);
+ text ++;
+ i ++;
+ }
+ else
+ {
+ wch = wch = *(text + 1) | (*text << 8);
+ *unicode = ff_convert(wch, 1);
+ text += 2;
+ i += 2;
+ }
+
+ unicode ++;
+ }
+
+ *unicode = '\0';
+}
+
+static void rtgui_freetype_font_draw_text(struct rtgui_font* font, struct rtgui_dc* dc, const char* text, rt_ubase_t len, struct rtgui_rect* rect)
+{
+ int index = 0;
+ FT_Error err = 0;
+ rt_uint16_t *text_short, *text_ptr;
+ struct rtgui_freetype_font* freetype;
+
+ RT_ASSERT(font != RT_NULL);
+ freetype = (struct rtgui_freetype_font*) font->data;
+ RT_ASSERT(freetype != RT_NULL);
+
+ /* allocate unicode buffer */
+ text_short = (rt_uint16_t*)rtgui_malloc((len + 1)* 2);
+ if (text_short == RT_NULL) return ; /* out of memory */
+
+ /* convert gbk to unicode */
+ gbk_to_unicode(text_short, text, len);
+ text_ptr = text_short;
+
+ while (*text_ptr)
+ {
+ index = FT_Get_Char_Index(freetype->face, *text_ptr);
+ err = FT_Load_Glyph(freetype->face, index, FT_LOAD_DEFAULT|FT_LOAD_RENDER);
+ if (err == 0)
+ {
+ int rows, x;
+ rt_uint8_t* ptr;
+
+ /* render font */
+ ptr = (rt_uint8_t*)freetype->face->glyph->bitmap.buffer;
+
+ for (rows = 0; rows < freetype->face->glyph->bitmap.rows; rows ++)
+ for (x = 0; x < freetype->face->glyph->bitmap.width; x++)
+ {
+ if (*ptr > 0)
+ rtgui_dc_draw_color_point(dc, rect->x1 + x, rect->y1 + rows, RTGUI_RGB(0xff - *ptr, 0xff - *ptr, 0xff - *ptr));
+ ptr ++;
+ }
+ }
+
+ text_ptr ++;
+ rect->x1 += freetype->face->glyph->bitmap.width;
+ }
+
+ /* release unicode buffer */
+ rtgui_free(text_short);
+}
+
+static void rtgui_freetype_font_get_metrics(struct rtgui_font* font, const char* text, rtgui_rect_t* rect)
+{
+ int index = 0, len;
+ FT_Error err = 0;
+ rt_uint16_t w = 0, h = 0;
+ rt_uint16_t *text_short, *text_ptr;
+ struct rtgui_freetype_font* freetype;
+
+ RT_ASSERT(font != RT_NULL);
+ RT_ASSERT(rect != RT_NULL);
+ freetype = (struct rtgui_freetype_font*) font->data;
+ RT_ASSERT(freetype != RT_NULL);
+
+ len = strlen(text);
+ memset(rect, 0, sizeof(struct rtgui_rect));
+
+ /* allocate unicode buffer */
+ text_short = (rt_uint16_t*)rtgui_malloc((len + 1)* 2);
+ if (text_short == RT_NULL) return ; /* out of memory */
+
+ /* convert gbk to unicode */
+ gbk_to_unicode(text_short, text, len);
+ text_ptr = text_short;
+
+ while (*text_ptr)
+ {
+ index = FT_Get_Char_Index(freetype->face, *text_ptr);
+ err = FT_Load_Glyph(freetype->face, index, FT_LOAD_DEFAULT);
+
+ if (err == 0)
+ {
+ w += freetype->face->glyph->bitmap.width;
+ if (freetype->face->glyph->bitmap.rows > h)
+ {
+ h = freetype->face->glyph->bitmap.rows;
+ }
+ }
+
+ text_ptr ++;
+ }
+
+ rect->x1 = 0; rect->y1 = 0;
+ rect->x2 = w; rect->y2 = h;
+
+ /* release unicode buffer */
+ rtgui_free(text_short);
+}
+
+rtgui_font_t* rtgui_freetype_font_create(const char* filename, int bold, int italic, rt_size_t size)
+{
+ FT_Error err = 0;
+ struct rtgui_font* font;
+
+ font = (struct rtgui_font*) rtgui_malloc (sizeof(struct rtgui_font));
+ if (font != RT_NULL)
+ {
+ struct rtgui_freetype_font* freetype;
+
+ freetype = (struct rtgui_freetype_font*) rtgui_malloc (sizeof(struct rtgui_freetype_font));
+ if (freetype == RT_NULL)
+ {
+ rt_free(font);
+ font = RT_NULL;
+ }
+ else
+ {
+ err = FT_Init_FreeType(&freetype->library);
+ if((err = FT_New_Face(freetype->library, filename, 0, &freetype->face)))
+ {
+ FT_Done_FreeType(freetype->library);
+
+ rt_free(font);
+ font = RT_NULL;
+ }
+ else
+ {
+ err = FT_Select_Charmap(freetype->face, ft_encoding_unicode);
+ if(err)
+ {
+ err = FT_Select_Charmap(freetype->face, ft_encoding_latin_1 );
+ }
+
+ err = FT_Set_Pixel_Sizes(freetype->face, 0, size);
+ if (err != 0)
+ {
+ rtgui_free(font);
+ font = RT_NULL;
+
+ FT_Done_FreeType(freetype->library);
+ rtgui_free(freetype);
+
+ return RT_NULL;
+ }
+
+ freetype->bold = bold;
+ freetype->italic = italic;
+
+ rt_kprintf("fonfile:%s\n", filename);
+ rt_kprintf("font family_name:%s\n", freetype->face->family_name);
+ rt_kprintf("font style_name:%s\n", freetype->face->style_name);
+
+ /* set user data */
+ font->data = freetype;
+ font->family = rt_strdup(freetype->face->family_name);
+ font->height = (rt_uint16_t)size;
+ font->refer_count = 0;
+ font->engine = &freetype_font_engine;
+
+ /* add to system */
+ rtgui_font_system_add_font(font);
+ }
+ }
+ }
+
+ return font;
+}
+
+void rtgui_freetype_font_destroy(rtgui_font_t* font)
+{
+ struct rtgui_freetype_font* freetype;
+
+ RT_ASSERT(font != RT_NULL);
+ freetype = (struct rtgui_freetype_font*) font->data;
+ RT_ASSERT(freetype != RT_NULL);
+
+ rtgui_font_system_remove_font(font);
+
+ FT_Done_Face (freetype->face);
+ FT_Done_FreeType(freetype->library);
+ rtgui_free(freetype);
+ rtgui_free(font);
+}
+#endif
diff --git a/components/rtgui/common/font_hz_bmp.c b/components/rtgui/common/font_hz_bmp.c
index fd8ea9b058..72088f7848 100644
--- a/components/rtgui/common/font_hz_bmp.c
+++ b/components/rtgui/common/font_hz_bmp.c
@@ -86,7 +86,7 @@ static void rtgui_hz_bitmap_font_draw_text (struct rtgui_font* font, struct rtgu
while (length > 0)
{
len = 0;
- while (((rt_uint8_t)*(text + len)) < 0x80 && *(text + len)) len ++;
+ while (((rt_uint8_t)*(text + len)) < 0x80 && *(text + len) && len < length) len ++;
/* draw text with English font */
if (len > 0)
{
@@ -97,7 +97,7 @@ static void rtgui_hz_bitmap_font_draw_text (struct rtgui_font* font, struct rtgu
}
len = 0;
- while (((rt_uint8_t)*(text + len)) >= 0x80) len ++;
+ while (((rt_uint8_t)*(text + len)) >= 0x80 && len < length) len ++;
if (len > 0)
{
_rtgui_hz_bitmap_font_draw_text(bmp_font, dc, text, len, rect);
diff --git a/components/rtgui/common/font_hz_file.c b/components/rtgui/common/font_hz_file.c
index 35e878f24a..6150864032 100644
--- a/components/rtgui/common/font_hz_file.c
+++ b/components/rtgui/common/font_hz_file.c
@@ -177,7 +177,7 @@ static void rtgui_hz_file_font_draw_text(struct rtgui_font* font, struct rtgui_d
while (length > 0)
{
len = 0;
- while (((rt_uint8_t)*(text + len)) < 0x80 && *(text + len)) len ++;
+ while (((rt_uint8_t)*(text + len)) < 0x80 && *(text + len) && len < length) len ++;
/* draw text with English font */
if (len > 0)
{
@@ -188,7 +188,7 @@ static void rtgui_hz_file_font_draw_text(struct rtgui_font* font, struct rtgui_d
}
len = 0;
- while (((rt_uint8_t)*(text + len)) >= 0x80) len ++;
+ while (((rt_uint8_t)*(text + len)) >= 0x80 && len < length) len ++;
if (len > 0)
{
_rtgui_hz_file_font_draw_text(hz_file_font, dc, text, len, rect);
diff --git a/components/rtgui/common/framebuffer_driver.c b/components/rtgui/common/framebuffer_driver.c
index 78dea306ad..04c21c42a5 100644
--- a/components/rtgui/common/framebuffer_driver.c
+++ b/components/rtgui/common/framebuffer_driver.c
@@ -1,225 +1,225 @@
-#include <rtgui/rtgui_system.h>
-#include <rtgui/driver.h>
-
-#define GET_PIXEL(dst, x, y, type) \
- (type *)((rt_uint8_t*)((dst)->framebuffer) + (y) * (dst)->pitch + (x) * ((dst)->bits_per_pixel/8))
-
-static void _rgb565_set_pixel(rtgui_color_t *c, int x, int y)
-{
- *GET_PIXEL(rtgui_graphic_get_device(), x, y, rt_uint16_t) = rtgui_color_to_565(*c);
-}
-
-static void _rgb565_get_pixel(rtgui_color_t *c, int x, int y)
-{
- rt_uint16_t pixel;
-
- pixel = *GET_PIXEL(rtgui_graphic_get_device(), x, y, rt_uint16_t);
-
- /* get pixel from color */
- *c = rtgui_color_from_565(pixel);
-}
-
-static void _rgb565_draw_hline(rtgui_color_t *c, int x1, int x2, int y)
-{
- rt_ubase_t index;
- rt_uint16_t pixel;
- rt_uint16_t *pixel_ptr;
-
- /* get pixel from color */
- pixel = rtgui_color_to_565(*c);
-
- /* get pixel pointer in framebuffer */
- pixel_ptr = GET_PIXEL(rtgui_graphic_get_device(), x1, y, rt_uint16_t);
-
- for (index = x1; index < x2; index ++)
- {
- *pixel_ptr = pixel;
- pixel_ptr ++;
- }
-}
-
-static void _rgb565_draw_vline(rtgui_color_t *c, int x , int y1, int y2)
-{
- rt_uint8_t *dst;
- rt_uint16_t pixel;
- rt_ubase_t index;
-
- pixel = rtgui_color_to_565(*c);
- dst = GET_PIXEL(rtgui_graphic_get_device(), x, y1, rt_uint8_t);
- for (index = y1; index < y2; index ++)
- {
- *(rt_uint16_t*)dst = pixel;
- dst += rtgui_graphic_get_device()->pitch;
- }
-}
-
-static void _rgb565p_set_pixel(rtgui_color_t *c, int x, int y)
-{
- *GET_PIXEL(rtgui_graphic_get_device(), x, y, rt_uint16_t) = rtgui_color_to_565p(*c);
-}
-
-static void _rgb565p_get_pixel(rtgui_color_t *c, int x, int y)
-{
- rt_uint16_t pixel;
-
- pixel = *GET_PIXEL(rtgui_graphic_get_device(), x, y, rt_uint16_t);
-
- /* get pixel from color */
- *c = rtgui_color_from_565p(pixel);
-}
-
-static void _rgb565p_draw_hline(rtgui_color_t *c, int x1, int x2, int y)
-{
- rt_ubase_t index;
- rt_uint16_t pixel;
- rt_uint16_t *pixel_ptr;
-
- /* get pixel from color */
- pixel = rtgui_color_to_565p(*c);
-
- /* get pixel pointer in framebuffer */
- pixel_ptr = GET_PIXEL(rtgui_graphic_get_device(), x1, y, rt_uint16_t);
-
- for (index = x1; index < x2; index ++)
- {
- *pixel_ptr = pixel;
- pixel_ptr ++;
- }
-}
-
-static void _rgb565p_draw_vline(rtgui_color_t *c, int x , int y1, int y2)
-{
- rt_uint8_t *dst;
- rt_uint16_t pixel;
- rt_ubase_t index;
-
- pixel = rtgui_color_to_565p(*c);
- dst = GET_PIXEL(rtgui_graphic_get_device(), x, y1, rt_uint8_t);
- for (index = y1; index < y2; index ++)
- {
- *(rt_uint16_t*)dst = pixel;
- dst += rtgui_graphic_get_device()->pitch;
- }
-}
-
-/* draw raw hline */
-static void framebuffer_draw_raw_hline(rt_uint8_t *pixels, int x1, int x2, int y)
-{
- rt_uint8_t *dst;
-
- dst = GET_PIXEL(rtgui_graphic_get_device(), x1, y, rt_uint8_t);
- rt_memcpy(dst, pixels, (x2 - x1) * (rtgui_graphic_get_device()->bits_per_pixel/8));
-}
-
-const struct rtgui_graphic_driver_ops _framebuffer_rgb565_ops =
-{
- _rgb565_set_pixel,
- _rgb565_get_pixel,
- _rgb565_draw_hline,
- _rgb565_draw_vline,
- framebuffer_draw_raw_hline,
-};
-
-const struct rtgui_graphic_driver_ops _framebuffer_rgb565p_ops =
-{
- _rgb565p_set_pixel,
- _rgb565p_get_pixel,
- _rgb565p_draw_hline,
- _rgb565p_draw_vline,
- framebuffer_draw_raw_hline,
-};
-
-#define FRAMEBUFFER (rtgui_graphic_get_device()->framebuffer)
-#define MONO_PIXEL(framebuffer, x, y) \
- ((rt_uint8_t**)(framebuffer))[y/8][x]
-
-static void _mono_set_pixel(rtgui_color_t *c, int x, int y)
-{
- if (*c == white)
- MONO_PIXEL(FRAMEBUFFER, x, y) &= ~(1 << (y%8));
- else
- MONO_PIXEL(FRAMEBUFFER, x, y) |= (1 << (y%8));
-}
-
-static void _mono_get_pixel(rtgui_color_t *c, int x, int y)
-{
- if (MONO_PIXEL(FRAMEBUFFER, x, y) & (1 << (y%8)))
- *c = black;
- else
- *c = white;
-}
-
-static void _mono_draw_hline(rtgui_color_t *c, int x1, int x2, int y)
-{
- rt_ubase_t index;
-
- if (*c == white)
- for (index = x1; index < x2; index ++)
- {
- MONO_PIXEL(FRAMEBUFFER, index, y) &= ~(1 << (y%8));
- }
- else
- for (index = x1; index < x2; index ++)
- {
- MONO_PIXEL(FRAMEBUFFER, index, y) |= (1 << (y%8));
- }
-}
-
-static void _mono_draw_vline(rtgui_color_t *c, int x , int y1, int y2)
-{
- rt_ubase_t index;
-
- if (*c == white)
- for (index = y1; index < y2; index ++)
- {
- MONO_PIXEL(FRAMEBUFFER, x, index) &= ~(1 << (index%8));
- }
- else
- for (index = y1; index < y2; index ++)
- {
- MONO_PIXEL(FRAMEBUFFER, x, index) |= (1 << (index%8));
- }
-}
-
-/* draw raw hline */
-static void _mono_draw_raw_hline(rt_uint8_t *pixels, int x1, int x2, int y)
-{
- rt_ubase_t index;
-
- for (index = x1; index < x2; index ++)
- {
- if (pixels[index/8] && (1 << (index % 8)))
- MONO_PIXEL(FRAMEBUFFER, index, y) |= (1 << (y%8));
- else
- MONO_PIXEL(FRAMEBUFFER, index, y) &= ~(1 << (y%8));
- }
-}
-
-const struct rtgui_graphic_driver_ops _framebuffer_mono_ops =
-{
- _mono_set_pixel,
- _mono_get_pixel,
- _mono_draw_hline,
- _mono_draw_vline,
- _mono_draw_raw_hline,
-};
-
-const struct rtgui_graphic_driver_ops *rtgui_framebuffer_get_ops(int pixel_format)
-{
- switch (pixel_format)
- {
- case RTGRAPHIC_PIXEL_FORMAT_MONO:
- return &_framebuffer_mono_ops;
- case RTGRAPHIC_PIXEL_FORMAT_GRAY4:
- break;
- case RTGRAPHIC_PIXEL_FORMAT_GRAY16:
- break;
- case RTGRAPHIC_PIXEL_FORMAT_RGB565:
- return &_framebuffer_rgb565_ops;
- case RTGRAPHIC_PIXEL_FORMAT_RGB565P:
- return &_framebuffer_rgb565p_ops;
- }
-
- return RT_NULL;
-}
-
+#include <rtgui/rtgui_system.h>
+#include <rtgui/driver.h>
+
+#define GET_PIXEL(dst, x, y, type) \
+ (type *)((rt_uint8_t*)((dst)->framebuffer) + (y) * (dst)->pitch + (x) * ((dst)->bits_per_pixel/8))
+
+static void _rgb565_set_pixel(rtgui_color_t *c, int x, int y)
+{
+ *GET_PIXEL(rtgui_graphic_get_device(), x, y, rt_uint16_t) = rtgui_color_to_565(*c);
+}
+
+static void _rgb565_get_pixel(rtgui_color_t *c, int x, int y)
+{
+ rt_uint16_t pixel;
+
+ pixel = *GET_PIXEL(rtgui_graphic_get_device(), x, y, rt_uint16_t);
+
+ /* get pixel from color */
+ *c = rtgui_color_from_565(pixel);
+}
+
+static void _rgb565_draw_hline(rtgui_color_t *c, int x1, int x2, int y)
+{
+ rt_ubase_t index;
+ rt_uint16_t pixel;
+ rt_uint16_t *pixel_ptr;
+
+ /* get pixel from color */
+ pixel = rtgui_color_to_565(*c);
+
+ /* get pixel pointer in framebuffer */
+ pixel_ptr = GET_PIXEL(rtgui_graphic_get_device(), x1, y, rt_uint16_t);
+
+ for (index = x1; index < x2; index ++)
+ {
+ *pixel_ptr = pixel;
+ pixel_ptr ++;
+ }
+}
+
+static void _rgb565_draw_vline(rtgui_color_t *c, int x , int y1, int y2)
+{
+ rt_uint8_t *dst;
+ rt_uint16_t pixel;
+ rt_ubase_t index;
+
+ pixel = rtgui_color_to_565(*c);
+ dst = GET_PIXEL(rtgui_graphic_get_device(), x, y1, rt_uint8_t);
+ for (index = y1; index < y2; index ++)
+ {
+ *(rt_uint16_t*)dst = pixel;
+ dst += rtgui_graphic_get_device()->pitch;
+ }
+}
+
+static void _rgb565p_set_pixel(rtgui_color_t *c, int x, int y)
+{
+ *GET_PIXEL(rtgui_graphic_get_device(), x, y, rt_uint16_t) = rtgui_color_to_565p(*c);
+}
+
+static void _rgb565p_get_pixel(rtgui_color_t *c, int x, int y)
+{
+ rt_uint16_t pixel;
+
+ pixel = *GET_PIXEL(rtgui_graphic_get_device(), x, y, rt_uint16_t);
+
+ /* get pixel from color */
+ *c = rtgui_color_from_565p(pixel);
+}
+
+static void _rgb565p_draw_hline(rtgui_color_t *c, int x1, int x2, int y)
+{
+ rt_ubase_t index;
+ rt_uint16_t pixel;
+ rt_uint16_t *pixel_ptr;
+
+ /* get pixel from color */
+ pixel = rtgui_color_to_565p(*c);
+
+ /* get pixel pointer in framebuffer */
+ pixel_ptr = GET_PIXEL(rtgui_graphic_get_device(), x1, y, rt_uint16_t);
+
+ for (index = x1; index < x2; index ++)
+ {
+ *pixel_ptr = pixel;
+ pixel_ptr ++;
+ }
+}
+
+static void _rgb565p_draw_vline(rtgui_color_t *c, int x , int y1, int y2)
+{
+ rt_uint8_t *dst;
+ rt_uint16_t pixel;
+ rt_ubase_t index;
+
+ pixel = rtgui_color_to_565p(*c);
+ dst = GET_PIXEL(rtgui_graphic_get_device(), x, y1, rt_uint8_t);
+ for (index = y1; index < y2; index ++)
+ {
+ *(rt_uint16_t*)dst = pixel;
+ dst += rtgui_graphic_get_device()->pitch;
+ }
+}
+
+/* draw raw hline */
+static void framebuffer_draw_raw_hline(rt_uint8_t *pixels, int x1, int x2, int y)
+{
+ rt_uint8_t *dst;
+
+ dst = GET_PIXEL(rtgui_graphic_get_device(), x1, y, rt_uint8_t);
+ rt_memcpy(dst, pixels, (x2 - x1) * (rtgui_graphic_get_device()->bits_per_pixel/8));
+}
+
+const struct rtgui_graphic_driver_ops _framebuffer_rgb565_ops =
+{
+ _rgb565_set_pixel,
+ _rgb565_get_pixel,
+ _rgb565_draw_hline,
+ _rgb565_draw_vline,
+ framebuffer_draw_raw_hline,
+};
+
+const struct rtgui_graphic_driver_ops _framebuffer_rgb565p_ops =
+{
+ _rgb565p_set_pixel,
+ _rgb565p_get_pixel,
+ _rgb565p_draw_hline,
+ _rgb565p_draw_vline,
+ framebuffer_draw_raw_hline,
+};
+
+#define FRAMEBUFFER (rtgui_graphic_get_device()->framebuffer)
+#define MONO_PIXEL(framebuffer, x, y) \
+ ((rt_uint8_t**)(framebuffer))[y/8][x]
+
+static void _mono_set_pixel(rtgui_color_t *c, int x, int y)
+{
+ if (*c == white)
+ MONO_PIXEL(FRAMEBUFFER, x, y) &= ~(1 << (y%8));
+ else
+ MONO_PIXEL(FRAMEBUFFER, x, y) |= (1 << (y%8));
+}
+
+static void _mono_get_pixel(rtgui_color_t *c, int x, int y)
+{
+ if (MONO_PIXEL(FRAMEBUFFER, x, y) & (1 << (y%8)))
+ *c = black;
+ else
+ *c = white;
+}
+
+static void _mono_draw_hline(rtgui_color_t *c, int x1, int x2, int y)
+{
+ rt_ubase_t index;
+
+ if (*c == white)
+ for (index = x1; index < x2; index ++)
+ {
+ MONO_PIXEL(FRAMEBUFFER, index, y) &= ~(1 << (y%8));
+ }
+ else
+ for (index = x1; index < x2; index ++)
+ {
+ MONO_PIXEL(FRAMEBUFFER, index, y) |= (1 << (y%8));
+ }
+}
+
+static void _mono_draw_vline(rtgui_color_t *c, int x , int y1, int y2)
+{
+ rt_ubase_t index;
+
+ if (*c == white)
+ for (index = y1; index < y2; index ++)
+ {
+ MONO_PIXEL(FRAMEBUFFER, x, index) &= ~(1 << (index%8));
+ }
+ else
+ for (index = y1; index < y2; index ++)
+ {
+ MONO_PIXEL(FRAMEBUFFER, x, index) |= (1 << (index%8));
+ }
+}
+
+/* draw raw hline */
+static void _mono_draw_raw_hline(rt_uint8_t *pixels, int x1, int x2, int y)
+{
+ rt_ubase_t index;
+
+ for (index = x1; index < x2; index ++)
+ {
+ if (pixels[index/8] && (1 << (index % 8)))
+ MONO_PIXEL(FRAMEBUFFER, index, y) |= (1 << (y%8));
+ else
+ MONO_PIXEL(FRAMEBUFFER, index, y) &= ~(1 << (y%8));
+ }
+}
+
+const struct rtgui_graphic_driver_ops _framebuffer_mono_ops =
+{
+ _mono_set_pixel,
+ _mono_get_pixel,
+ _mono_draw_hline,
+ _mono_draw_vline,
+ _mono_draw_raw_hline,
+};
+
+const struct rtgui_graphic_driver_ops *rtgui_framebuffer_get_ops(int pixel_format)
+{
+ switch (pixel_format)
+ {
+ case RTGRAPHIC_PIXEL_FORMAT_MONO:
+ return &_framebuffer_mono_ops;
+ case RTGRAPHIC_PIXEL_FORMAT_GRAY4:
+ break;
+ case RTGRAPHIC_PIXEL_FORMAT_GRAY16:
+ break;
+ case RTGRAPHIC_PIXEL_FORMAT_RGB565:
+ return &_framebuffer_rgb565_ops;
+ case RTGRAPHIC_PIXEL_FORMAT_RGB565P:
+ return &_framebuffer_rgb565p_ops;
+ }
+
+ return RT_NULL;
+}
+
diff --git a/components/rtgui/common/image.c b/components/rtgui/common/image.c
index 45a1013a69..0160c990ea 100644
--- a/components/rtgui/common/image.c
+++ b/components/rtgui/common/image.c
@@ -64,47 +64,47 @@ void rtgui_system_image_init(void)
#endif
}
-static struct rtgui_image_engine* rtgui_image_get_engine(const char* type)
+static struct rtgui_image_engine* rtgui_image_get_engine_by_filename(const char* fn)
{
struct rtgui_list_node *node;
struct rtgui_image_engine *engine;
+ const char* ext;
+
+ ext = fn + rt_strlen(fn);
+ while (ext != fn)
+ {
+ if (*ext == '.') { ext ++; break; }
+ ext --;
+ }
+ if (ext == fn) return RT_NULL; /* no ext */
rtgui_list_foreach(node, &_rtgui_system_image_list)
{
engine = rtgui_list_entry(node, struct rtgui_image_engine, list);
-
- if (strncasecmp(engine->name, type, strlen(engine->name)) ==0)
+ if (strncasecmp(engine->name, ext, strlen(engine->name)) == 0)
return engine;
}
return RT_NULL;
}
-#if defined(RTGUI_USING_DFS_FILERW) || defined(RTGUI_USING_STDIO_FILERW)
-static struct rtgui_image_engine* rtgui_image_get_engine_by_filename(const char* fn)
+static struct rtgui_image_engine* rtgui_image_get_engine(const char* type)
{
struct rtgui_list_node *node;
struct rtgui_image_engine *engine;
- const char* ext;
-
- ext = fn + rt_strlen(fn);
- while (ext != fn)
- {
- if (*ext == '.') { ext ++; break; }
- ext --;
- }
- if (ext == fn) return RT_NULL; /* no ext */
rtgui_list_foreach(node, &_rtgui_system_image_list)
{
engine = rtgui_list_entry(node, struct rtgui_image_engine, list);
- if (strncasecmp(engine->name, ext, strlen(engine->name)) == 0)
+
+ if (strncasecmp(engine->name, type, strlen(engine->name)) ==0)
return engine;
}
return RT_NULL;
}
+#if defined(RTGUI_USING_DFS_FILERW) || defined(RTGUI_USING_STDIO_FILERW)
struct rtgui_image* rtgui_image_create_from_file(const char* type, const char* filename, rt_bool_t load)
{
struct rtgui_filerw* filerw;
diff --git a/components/rtgui/common/image_bmp.c b/components/rtgui/common/image_bmp.c
index 9dd9798675..1c7c108217 100644
--- a/components/rtgui/common/image_bmp.c
+++ b/components/rtgui/common/image_bmp.c
@@ -1,645 +1,645 @@
-#include <rtthread.h>
-#include <rtgui/dc_hw.h>
-#include <rtgui/image.h>
-#include <rtgui/rtgui_system.h>
-#include <rtgui/image_bmp.h>
-#include <rtgui/blit.h>
-
-#ifdef RTGUI_IMAGE_BMP
-/* Compression encodings for BMP files */
-#ifndef BI_RGB
-#define BI_RGB 0
-#define BI_RLE8 1
-#define BI_RLE4 2
-#define BI_BITFIELDS 3
-#endif
-
-#define hw_driver (rtgui_graphic_driver_get_default())
-
-struct rtgui_image_bmp
-{
- rt_bool_t is_loaded;
-
- rt_uint32_t Rmask;
- rt_uint32_t Gmask;
- rt_uint32_t Bmask;
-
- rt_size_t pixel_offset;
-
- rt_uint8_t byte_per_pixel;
- rt_uint8_t pad;
- rt_uint8_t ExpandBMP;
-
- rt_uint8_t *pixels;
- rt_uint8_t *line_pixels;
- rt_uint32_t pitch;
-
- struct rtgui_filerw* filerw;
-};
-
-struct rtgui_image_bmp_header
-{
- /* The Win32 BMP file header (14 bytes) */
- char magic[2];
- rt_uint32_t bfSize;
- rt_uint16_t bfReserved1;
- rt_uint16_t bfReserved2;
- rt_uint32_t bfOffBits;
-
- /* The Win32 BITMAPINFOHEADER struct (40 bytes) */
- rt_uint32_t biSize;
- rt_int32_t biWidth;
- rt_int32_t biHeight;
- rt_uint16_t biPlanes;
- rt_uint16_t biBitCount;
- rt_uint32_t biCompression;
- rt_uint32_t biSizeImage;
- rt_int32_t biXPelsPerMeter;
- rt_int32_t biYPelsPerMeter;
- rt_uint32_t biClrUsed;
- rt_uint32_t biClrImportant;
-};
-
-static rt_bool_t rtgui_image_bmp_check(struct rtgui_filerw* file);
-static rt_bool_t rtgui_image_bmp_load(struct rtgui_image* image, struct rtgui_filerw* file, rt_bool_t load);
-static void rtgui_image_bmp_unload(struct rtgui_image* image);
-static void rtgui_image_bmp_blit(struct rtgui_image* image, struct rtgui_dc* dc, struct rtgui_rect* rect);
-
-struct rtgui_image_engine rtgui_image_bmp_engine =
-{
- "bmp",
- { RT_NULL },
- rtgui_image_bmp_check,
- rtgui_image_bmp_load,
- rtgui_image_bmp_unload,
- rtgui_image_bmp_blit
-};
-
-rt_inline rt_uint32_t rtgui_filerw_read32(struct rtgui_filerw* src)
-{
- rt_uint32_t value;
- rtgui_filerw_read(src, &value, (sizeof value), 1);
- return value;
-}
-
-rt_inline rt_uint16_t rtgui_filerw_read16(struct rtgui_filerw* src)
-{
- rt_uint16_t value;
- rtgui_filerw_read(src, &value, (sizeof value), 1);
- return value;
-
-}
-
-static rt_bool_t rtgui_image_bmp_check(struct rtgui_filerw* file)
-{
- char magic[2];
- rt_bool_t is_bmp;
- rt_off_t start;
-
- if ( !file ) return 0;
-
- start = rtgui_filerw_tell(file);
-
- /* move to the beginning of file */
- rtgui_filerw_seek(file, 0, RTGUI_FILE_SEEK_SET);
-
- is_bmp = RT_FALSE;
- if ( rtgui_filerw_read(file, magic, 1, sizeof(magic)) == sizeof(magic) )
- {
- if (magic[0] == 'B' &&
- magic[1] == 'M')
- {
- is_bmp = RT_TRUE;
- }
- }
-
- rtgui_filerw_seek(file, start, RTGUI_FILE_SEEK_SET);
-
- return(is_bmp);
-}
-
-static struct rtgui_image_palette* rtgui_image_bmp_load_palette(struct rtgui_image_bmp_header* header, struct rtgui_filerw* src)
-{
- /* Load the palette, if any */
- rt_size_t i;
- struct rtgui_image_palette* palette;
-
- if (header->biClrUsed == 0)
- header->biClrUsed = 1 << header->biBitCount;
-
- palette = rtgui_image_palette_create(header->biClrUsed);
- if (palette == RT_NULL) return RT_NULL;
-
- if ( header->biSize == 12 )
- {
- rt_uint8_t r, g, b;
- for ( i = 0; i < (int)header->biClrUsed; ++i )
- {
- rtgui_filerw_read(src, &b, 1, 1);
- rtgui_filerw_read(src, &g, 1, 1);
- rtgui_filerw_read(src, &r, 1, 1);
- palette->colors[i] = RTGUI_RGB(r, g, b);
- }
- }
- else
- {
- rt_uint8_t r, g, b, a;
- for ( i = 0; i < (int)header->biClrUsed; ++i )
- {
- rtgui_filerw_read(src, &b, 1, 1);
- rtgui_filerw_read(src, &g, 1, 1);
- rtgui_filerw_read(src, &r, 1, 1);
- rtgui_filerw_read(src, &a, 1, 1);
- palette->colors[i] = RTGUI_ARGB(a, r, g, b);
- }
- }
-
- return palette;
-}
-
-static rt_bool_t rtgui_image_bmp_load(struct rtgui_image* image, struct rtgui_filerw* src, rt_bool_t load)
-{
- rt_uint32_t Rmask;
- rt_uint32_t Gmask;
- rt_uint32_t Bmask;
- int ExpandBMP, bmpPitch;
- struct rtgui_image_bmp* bmp;
- struct rtgui_image_bmp_header* header;
- struct rtgui_image_palette* palette;
-
- bmp = RT_NULL;
- header = RT_NULL;
- palette = RT_NULL;
- header = (struct rtgui_image_bmp_header*) rtgui_malloc(sizeof(struct rtgui_image_bmp_header));
- if (header == RT_NULL) return RT_FALSE;
-
- if ( rtgui_filerw_read(src, header->magic, 1, sizeof(header->magic)) ==
- sizeof(sizeof(header->magic)) )
- {
- if (header->magic[0] != 'B' ||
- header->magic[1] != 'M')
- {
- goto __exit;
- }
- }
-
- header->bfSize = rtgui_filerw_read32(src);
- header->bfReserved1 = rtgui_filerw_read16(src);
- header->bfReserved2 = rtgui_filerw_read16(src);
- header->bfOffBits = rtgui_filerw_read32(src);
-
- /* Read the Win32 BITMAPINFOHEADER */
- header->biSize = rtgui_filerw_read32(src);
- if ( header->biSize == 12 )
- {
- header->biWidth = (rt_uint32_t)rtgui_filerw_read16(src);
- header->biHeight = (rt_uint32_t)rtgui_filerw_read16(src);
- header->biPlanes = rtgui_filerw_read16(src);
- header->biBitCount = rtgui_filerw_read16(src);
- header->biCompression = BI_RGB;
- header->biSizeImage = 0;
- header->biXPelsPerMeter = 0;
- header->biYPelsPerMeter = 0;
- header->biClrUsed = 0;
-
- header->biClrImportant = 0;
-
- }
- else
- {
- header->biWidth = rtgui_filerw_read32(src);
- header->biHeight = rtgui_filerw_read32(src);
- header->biPlanes = rtgui_filerw_read16(src);
- header->biBitCount = rtgui_filerw_read16(src);
- header->biCompression = rtgui_filerw_read32(src);
- header->biSizeImage = rtgui_filerw_read32(src);
- header->biXPelsPerMeter = rtgui_filerw_read32(src);
- header->biYPelsPerMeter = rtgui_filerw_read32(src);
- header->biClrUsed = rtgui_filerw_read32(src);
- header->biClrImportant = rtgui_filerw_read32(src);
-
- }
-
- /* allocate palette and expand 1 and 4 bit bitmaps to 8 bits per pixel */
- switch (header->biBitCount)
- {
- case 1:
- ExpandBMP = header->biBitCount;
- palette = rtgui_image_bmp_load_palette(header, src);
- header->biBitCount = 8;
- break;
-
- case 4:
- ExpandBMP = header->biBitCount;
- palette = rtgui_image_bmp_load_palette(header, src);
- header->biBitCount = 8;
- break;
-
- case 8:
- palette = rtgui_image_bmp_load_palette(header, src);
- ExpandBMP = 0;
- break;
-
- default:
- ExpandBMP = 0;
- break;
- }
-
- /* We don't support any BMP compression right now */
- Rmask = Gmask = Bmask = 0;
- switch (header->biCompression)
- {
- case BI_RGB:
- /* If there are no masks, use the defaults */
- if ( header->bfOffBits == (14 + header->biSize) )
- {
- /* Default values for the BMP format */
- switch (header->biBitCount)
- {
- case 15:
- case 16:
- Rmask = 0x7C00;
- Gmask = 0x03E0;
- Bmask = 0x001F;
- break;
-
- case 24:
- case 32:
- Rmask = 0x00FF0000;
- Gmask = 0x0000FF00;
- Bmask = 0x000000FF;
- break;
-
- default:
- break;
- }
- break;
- }
- /* Fall through -- read the RGB masks */
-
- case BI_BITFIELDS:
- switch (header->biBitCount)
- {
- case 15:
- case 16:
- case 32:
- Rmask = rtgui_filerw_read32(src);
- Gmask = rtgui_filerw_read32(src);
- Bmask = rtgui_filerw_read32(src);
- break;
-
- default:
- break;
- }
- break;
-
- default:
- rt_kprintf("Compressed BMP files not supported\n");
- goto __exit;
- }
-
- bmp = (struct rtgui_image_bmp*) rtgui_malloc(sizeof(struct rtgui_image_bmp));
- if (bmp == RT_NULL)
- goto __exit;
-
- /* set image information */
- image->w = header->biWidth;
- image->h = header->biHeight;
- image->engine = &rtgui_image_bmp_engine;
- image->data = bmp;
- bmp->filerw = src;
- bmp->byte_per_pixel = header->biBitCount/8;
- bmp->pitch = image->w * bmp->byte_per_pixel;
- bmp->pixel_offset = header->bfOffBits;
- bmp->Rmask = Rmask; bmp->Gmask = Gmask; bmp->Bmask = Bmask;
- bmp->ExpandBMP = ExpandBMP;
- if (palette != RT_NULL) image->palette = palette;
-
- /* get padding */
- switch (ExpandBMP)
- {
- case 1:
- bmpPitch = (header->biWidth + 7) >> 3;
- bmp->pad = (((bmpPitch)%4) ? (4-((bmpPitch)%4)) : 0);
- break;
-
- case 4:
- bmpPitch = (header->biWidth + 1) >> 1;
- bmp->pad = (((bmpPitch)%4) ? (4-((bmpPitch)%4)) : 0);
- break;
-
- default:
- bmp->pad = ((bmp->pitch%4) ? (4-(bmp->pitch%4)) : 0);
- break;
- }
-
- if (load == RT_TRUE)
- {
- rt_uint8_t *bits;
- rt_uint32_t i;
-
- /* load all pixels */
- bmp->pixels = rtgui_malloc(image->h * bmp->pitch);
- if (bmp->pixels == RT_NULL)
- goto __exit;
-
- /* Read the pixels. Note that the bmp image is upside down */
- if ( rtgui_filerw_seek(src, bmp->pixel_offset, RTGUI_FILE_SEEK_SET) < 0)
- goto __exit;
-
- bits = bmp->pixels + image->h * bmp->pitch;
- while ( bits > bmp->pixels )
- {
- bits -= bmp->pitch;
- switch (ExpandBMP)
- {
- case 1:
- case 4:
- {
- rt_uint8_t pixel = 0;
- int shift = (8 - ExpandBMP);
- for ( i=0; i < image->w; ++i )
- {
- if ( i % (8/ExpandBMP) == 0 )
- {
- if ( !rtgui_filerw_read(src, &pixel, 1, 1) )
- goto __exit;
-
- }
- *(bits+i) = (pixel>>shift);
- pixel <<= ExpandBMP;
- }
- }
- break;
-
- default:
- if ( rtgui_filerw_read(src, bits, 1, bmp->pitch) != bmp->pitch ) goto __exit;
- break;
- }
-
- /* Skip padding bytes */
- if ( bmp->pad )
- {
- rt_uint8_t padbyte;
- for ( i=0; i < bmp->pad; ++i )
- {
- rtgui_filerw_read(src, &padbyte, 1, 1);
- }
- }
- }
-
- rtgui_filerw_close(bmp->filerw);
- bmp->line_pixels = RT_NULL;
- bmp->filerw = RT_NULL;
- bmp->pixel_offset = 0;
- }
- else
- {
- bmp->pixels = RT_NULL;
- bmp->line_pixels = rtgui_malloc(bmp->pitch);
- }
-
- return RT_TRUE;
-
-__exit:
- rtgui_free(header);
- if (palette != RT_NULL)
- {
- rtgui_free(palette);
- image->palette = RT_NULL;
- }
-
- if (bmp != RT_NULL)
- rtgui_free(bmp->pixels);
- rtgui_free(bmp);
- return RT_FALSE;
-}
-
-static void rtgui_image_bmp_unload(struct rtgui_image* image)
-{
- struct rtgui_image_bmp* bmp;
-
- if (image != RT_NULL)
- {
- bmp = (struct rtgui_image_bmp*) image->data;
-
- if (bmp->pixels != RT_NULL) rtgui_free(bmp->pixels);
- if (bmp->line_pixels != RT_NULL) rtgui_free(bmp->line_pixels);
- if (bmp->filerw != RT_NULL)
- {
- rtgui_filerw_close(bmp->filerw);
- bmp->filerw = RT_NULL;
- }
-
- /* release data */
- rtgui_free(bmp);
- }
-}
-
-static void rtgui_image_bmp_blit(struct rtgui_image* image, struct rtgui_dc* dc, struct rtgui_rect* dst_rect)
-{
- int y;
- rt_uint16_t w, h;
- struct rtgui_image_bmp* bmp;
-
- RT_ASSERT(image != RT_NULL || dc != RT_NULL || dst_rect != RT_NULL);
-
- /* this dc is not visible */
- if (rtgui_dc_get_visible(dc) != RT_TRUE) return;
-
- bmp = (struct rtgui_image_bmp*) image->data;
- RT_ASSERT(bmp != RT_NULL);
-
- /* the minimum rect */
- if (image->w < rtgui_rect_width(*dst_rect)) w = image->w;
- else w = rtgui_rect_width(*dst_rect);
- if (image->h < rtgui_rect_height(*dst_rect)) h = image->h;
- else h = rtgui_rect_height(*dst_rect);
-
- if (bmp->pixels != RT_NULL)
- {
- rt_uint8_t* ptr;
-
- /* get pixel pointer */
- ptr = bmp->pixels;
- if (bmp->byte_per_pixel == hw_driver->bits_per_pixel/8)
- {
- for (y = 0; y < h; y ++)
- {
- dc->engine->blit_line(dc,
- dst_rect->x1, dst_rect->x1 + w,
- dst_rect->y1 + y,
- ptr);
- ptr += bmp->pitch;
- }
- }
- else
- {
- rt_size_t pitch;
- rt_uint8_t *line_ptr;
-
- if (image->palette == RT_NULL)
- {
- rtgui_blit_line_func blit_line;
- line_ptr = (rt_uint8_t*) rtgui_malloc((hw_driver->bits_per_pixel/8) * w);
- blit_line = rtgui_blit_line_get(hw_driver->bits_per_pixel/8 , bmp->byte_per_pixel);
- pitch = w * bmp->byte_per_pixel;
- if (line_ptr != RT_NULL)
- {
- for (y = 0; y < h; y ++)
- {
- blit_line(line_ptr, ptr, pitch);
- dc->engine->blit_line(dc,
- dst_rect->x1, dst_rect->x1 + w,
- dst_rect->y1 + y,
- line_ptr);
- ptr += bmp->pitch;
- }
- }
- rtgui_free(line_ptr);
- }
- else
- {
- int x;
- rtgui_color_t color;
-
- /* use palette */
- for (y = 0; y < h; y ++)
- {
- ptr = bmp->pixels + (y * bmp->pitch);
- for (x = 0; x < w; x ++)
- {
- color = image->palette->colors[*ptr]; ptr ++;
- rtgui_dc_draw_color_point(dc, dst_rect->x1 + x, dst_rect->y1 + y, color);
- }
- }
- }
- }
- }
- else
- {
- int offset;
- rt_uint8_t *bits;
-
- /* calculate offset */
- switch (bmp->ExpandBMP)
- {
- case 1:
- offset = (image->h - h) * (image->w/8) * bmp->byte_per_pixel;
- break;
-
- case 4:
- offset = (image->h - h) * (image->w/2) * bmp->byte_per_pixel;
- break;
-
- default:
- offset = (image->h - h) * image->w * bmp->byte_per_pixel;
- break;
- }
- /* seek to the begin of pixel data */
- rtgui_filerw_seek(bmp->filerw, bmp->pixel_offset + offset, RTGUI_FILE_SEEK_SET);
-
- if (bmp->ExpandBMP == 1 || bmp->ExpandBMP == 4)
- {
- int x;
- rtgui_color_t color;
- /* 1, 4 bit per pixels */
-
- /* draw each line */
- for (y = h - 1; y >= 0; y --)
- {
- /* read pixel data */
- rt_uint8_t pixel = 0;
- int shift = (8 - bmp->ExpandBMP);
- int i;
-
- bits = bmp->line_pixels;
- for ( i=0; i < image->w; ++i )
- {
- if ( i % (8/bmp->ExpandBMP) == 0 )
- {
- if ( !rtgui_filerw_read(bmp->filerw, &pixel, 1, 1) )
- return;
- }
- *(bits+i) = (pixel>>shift);
- pixel <<= bmp->ExpandBMP;
- }
-
- /* Skip padding bytes */
- if (bmp->pad)
- {
- int i;
- rt_uint8_t padbyte;
- for ( i=0; i < bmp->pad; ++i )
- rtgui_filerw_read(bmp->filerw, &padbyte, 1, 1);
- }
-
- /* use palette */
- bits = bmp->line_pixels;
- for (x = 0; x < w; x ++)
- {
- color = image->palette->colors[*bits]; bits ++;
- rtgui_dc_draw_color_point(dc, dst_rect->x1 + x, dst_rect->y1 + y, color);
- }
- }
- }
- else
- {
- rt_uint8_t *line_ptr = (rt_uint8_t*) rtgui_malloc((hw_driver->bits_per_pixel/8) * w);
- if (line_ptr == RT_NULL) return;
-
- /* draw each line */
- for (y = h - 1; y >= 0; y --)
- {
- /* read line pixels */
- rtgui_filerw_read(bmp->filerw, bmp->line_pixels, 1, bmp->pitch);
-
- /* Skip padding bytes */
- if (bmp->pad)
- {
- int i;
- rt_uint8_t padbyte;
- for ( i=0; i < bmp->pad; ++i )
- rtgui_filerw_read(bmp->filerw, &padbyte, 1, 1);
- }
-
- if (image->palette == RT_NULL)
- {
- int pitch;
- rtgui_blit_line_func blit_line;
- blit_line = rtgui_blit_line_get(hw_driver->bits_per_pixel/8 , bmp->byte_per_pixel);
- pitch = w * bmp->byte_per_pixel;
- if (line_ptr != RT_NULL)
- {
- blit_line(line_ptr, bmp->line_pixels, pitch);
- dc->engine->blit_line(dc,
- dst_rect->x1, dst_rect->x1 + w,
- dst_rect->y1 + y,
- line_ptr);
- }
- }
- else
- {
- int x;
- rtgui_color_t color;
-
- /* use palette */
- bits = bmp->line_pixels;
- for (x = 0; x < w; x ++)
- {
- color = image->palette->colors[*bits]; bits ++;
- rtgui_dc_draw_color_point(dc, dst_rect->x1 + x, dst_rect->y1 + y, color);
- }
- }
- }
- if (line_ptr != RT_NULL) rtgui_free(line_ptr);
- }
- }
-}
-
-void rtgui_image_bmp_init()
-{
- /* register bmp on image system */
- rtgui_image_register_engine(&rtgui_image_bmp_engine);
-}
-#endif
+#include <rtthread.h>
+#include <rtgui/dc_hw.h>
+#include <rtgui/image.h>
+#include <rtgui/rtgui_system.h>
+#include <rtgui/image_bmp.h>
+#include <rtgui/blit.h>
+
+#ifdef RTGUI_IMAGE_BMP
+/* Compression encodings for BMP files */
+#ifndef BI_RGB
+#define BI_RGB 0
+#define BI_RLE8 1
+#define BI_RLE4 2
+#define BI_BITFIELDS 3
+#endif
+
+#define hw_driver (rtgui_graphic_driver_get_default())
+
+struct rtgui_image_bmp
+{
+ rt_bool_t is_loaded;
+
+ rt_uint32_t Rmask;
+ rt_uint32_t Gmask;
+ rt_uint32_t Bmask;
+
+ rt_size_t pixel_offset;
+
+ rt_uint8_t byte_per_pixel;
+ rt_uint8_t pad;
+ rt_uint8_t ExpandBMP;
+
+ rt_uint8_t *pixels;
+ rt_uint8_t *line_pixels;
+ rt_uint32_t pitch;
+
+ struct rtgui_filerw* filerw;
+};
+
+struct rtgui_image_bmp_header
+{
+ /* The Win32 BMP file header (14 bytes) */
+ char magic[2];
+ rt_uint32_t bfSize;
+ rt_uint16_t bfReserved1;
+ rt_uint16_t bfReserved2;
+ rt_uint32_t bfOffBits;
+
+ /* The Win32 BITMAPINFOHEADER struct (40 bytes) */
+ rt_uint32_t biSize;
+ rt_int32_t biWidth;
+ rt_int32_t biHeight;
+ rt_uint16_t biPlanes;
+ rt_uint16_t biBitCount;
+ rt_uint32_t biCompression;
+ rt_uint32_t biSizeImage;
+ rt_int32_t biXPelsPerMeter;
+ rt_int32_t biYPelsPerMeter;
+ rt_uint32_t biClrUsed;
+ rt_uint32_t biClrImportant;
+};
+
+static rt_bool_t rtgui_image_bmp_check(struct rtgui_filerw* file);
+static rt_bool_t rtgui_image_bmp_load(struct rtgui_image* image, struct rtgui_filerw* file, rt_bool_t load);
+static void rtgui_image_bmp_unload(struct rtgui_image* image);
+static void rtgui_image_bmp_blit(struct rtgui_image* image, struct rtgui_dc* dc, struct rtgui_rect* rect);
+
+struct rtgui_image_engine rtgui_image_bmp_engine =
+{
+ "bmp",
+ { RT_NULL },
+ rtgui_image_bmp_check,
+ rtgui_image_bmp_load,
+ rtgui_image_bmp_unload,
+ rtgui_image_bmp_blit
+};
+
+rt_inline rt_uint32_t rtgui_filerw_read32(struct rtgui_filerw* src)
+{
+ rt_uint32_t value;
+ rtgui_filerw_read(src, &value, (sizeof value), 1);
+ return value;
+}
+
+rt_inline rt_uint16_t rtgui_filerw_read16(struct rtgui_filerw* src)
+{
+ rt_uint16_t value;
+ rtgui_filerw_read(src, &value, (sizeof value), 1);
+ return value;
+
+}
+
+static rt_bool_t rtgui_image_bmp_check(struct rtgui_filerw* file)
+{
+ char magic[2];
+ rt_bool_t is_bmp;
+ rt_off_t start;
+
+ if ( !file ) return 0;
+
+ start = rtgui_filerw_tell(file);
+
+ /* move to the beginning of file */
+ rtgui_filerw_seek(file, 0, RTGUI_FILE_SEEK_SET);
+
+ is_bmp = RT_FALSE;
+ if ( rtgui_filerw_read(file, magic, 1, sizeof(magic)) == sizeof(magic) )
+ {
+ if (magic[0] == 'B' &&
+ magic[1] == 'M')
+ {
+ is_bmp = RT_TRUE;
+ }
+ }
+
+ rtgui_filerw_seek(file, start, RTGUI_FILE_SEEK_SET);
+
+ return(is_bmp);
+}
+
+static struct rtgui_image_palette* rtgui_image_bmp_load_palette(struct rtgui_image_bmp_header* header, struct rtgui_filerw* src)
+{
+ /* Load the palette, if any */
+ rt_size_t i;
+ struct rtgui_image_palette* palette;
+
+ if (header->biClrUsed == 0)
+ header->biClrUsed = 1 << header->biBitCount;
+
+ palette = rtgui_image_palette_create(header->biClrUsed);
+ if (palette == RT_NULL) return RT_NULL;
+
+ if ( header->biSize == 12 )
+ {
+ rt_uint8_t r, g, b;
+ for ( i = 0; i < (int)header->biClrUsed; ++i )
+ {
+ rtgui_filerw_read(src, &b, 1, 1);
+ rtgui_filerw_read(src, &g, 1, 1);
+ rtgui_filerw_read(src, &r, 1, 1);
+ palette->colors[i] = RTGUI_RGB(r, g, b);
+ }
+ }
+ else
+ {
+ rt_uint8_t r, g, b, a;
+ for ( i = 0; i < (int)header->biClrUsed; ++i )
+ {
+ rtgui_filerw_read(src, &b, 1, 1);
+ rtgui_filerw_read(src, &g, 1, 1);
+ rtgui_filerw_read(src, &r, 1, 1);
+ rtgui_filerw_read(src, &a, 1, 1);
+ palette->colors[i] = RTGUI_ARGB(a, r, g, b);
+ }
+ }
+
+ return palette;
+}
+
+static rt_bool_t rtgui_image_bmp_load(struct rtgui_image* image, struct rtgui_filerw* src, rt_bool_t load)
+{
+ rt_uint32_t Rmask;
+ rt_uint32_t Gmask;
+ rt_uint32_t Bmask;
+ int ExpandBMP, bmpPitch;
+ struct rtgui_image_bmp* bmp;
+ struct rtgui_image_bmp_header* header;
+ struct rtgui_image_palette* palette;
+
+ bmp = RT_NULL;
+ header = RT_NULL;
+ palette = RT_NULL;
+ header = (struct rtgui_image_bmp_header*) rtgui_malloc(sizeof(struct rtgui_image_bmp_header));
+ if (header == RT_NULL) return RT_FALSE;
+
+ if ( rtgui_filerw_read(src, header->magic, 1, sizeof(header->magic)) ==
+ sizeof(sizeof(header->magic)) )
+ {
+ if (header->magic[0] != 'B' ||
+ header->magic[1] != 'M')
+ {
+ goto __exit;
+ }
+ }
+
+ header->bfSize = rtgui_filerw_read32(src);
+ header->bfReserved1 = rtgui_filerw_read16(src);
+ header->bfReserved2 = rtgui_filerw_read16(src);
+ header->bfOffBits = rtgui_filerw_read32(src);
+
+ /* Read the Win32 BITMAPINFOHEADER */
+ header->biSize = rtgui_filerw_read32(src);
+ if ( header->biSize == 12 )
+ {
+ header->biWidth = (rt_uint32_t)rtgui_filerw_read16(src);
+ header->biHeight = (rt_uint32_t)rtgui_filerw_read16(src);
+ header->biPlanes = rtgui_filerw_read16(src);
+ header->biBitCount = rtgui_filerw_read16(src);
+ header->biCompression = BI_RGB;
+ header->biSizeImage = 0;
+ header->biXPelsPerMeter = 0;
+ header->biYPelsPerMeter = 0;
+ header->biClrUsed = 0;
+
+ header->biClrImportant = 0;
+
+ }
+ else
+ {
+ header->biWidth = rtgui_filerw_read32(src);
+ header->biHeight = rtgui_filerw_read32(src);
+ header->biPlanes = rtgui_filerw_read16(src);
+ header->biBitCount = rtgui_filerw_read16(src);
+ header->biCompression = rtgui_filerw_read32(src);
+ header->biSizeImage = rtgui_filerw_read32(src);
+ header->biXPelsPerMeter = rtgui_filerw_read32(src);
+ header->biYPelsPerMeter = rtgui_filerw_read32(src);
+ header->biClrUsed = rtgui_filerw_read32(src);
+ header->biClrImportant = rtgui_filerw_read32(src);
+
+ }
+
+ /* allocate palette and expand 1 and 4 bit bitmaps to 8 bits per pixel */
+ switch (header->biBitCount)
+ {
+ case 1:
+ ExpandBMP = header->biBitCount;
+ palette = rtgui_image_bmp_load_palette(header, src);
+ header->biBitCount = 8;
+ break;
+
+ case 4:
+ ExpandBMP = header->biBitCount;
+ palette = rtgui_image_bmp_load_palette(header, src);
+ header->biBitCount = 8;
+ break;
+
+ case 8:
+ palette = rtgui_image_bmp_load_palette(header, src);
+ ExpandBMP = 0;
+ break;
+
+ default:
+ ExpandBMP = 0;
+ break;
+ }
+
+ /* We don't support any BMP compression right now */
+ Rmask = Gmask = Bmask = 0;
+ switch (header->biCompression)
+ {
+ case BI_RGB:
+ /* If there are no masks, use the defaults */
+ if ( header->bfOffBits == (14 + header->biSize) )
+ {
+ /* Default values for the BMP format */
+ switch (header->biBitCount)
+ {
+ case 15:
+ case 16:
+ Rmask = 0x7C00;
+ Gmask = 0x03E0;
+ Bmask = 0x001F;
+ break;
+
+ case 24:
+ case 32:
+ Rmask = 0x00FF0000;
+ Gmask = 0x0000FF00;
+ Bmask = 0x000000FF;
+ break;
+
+ default:
+ break;
+ }
+ break;
+ }
+ /* Fall through -- read the RGB masks */
+
+ case BI_BITFIELDS:
+ switch (header->biBitCount)
+ {
+ case 15:
+ case 16:
+ case 32:
+ Rmask = rtgui_filerw_read32(src);
+ Gmask = rtgui_filerw_read32(src);
+ Bmask = rtgui_filerw_read32(src);
+ break;
+
+ default:
+ break;
+ }
+ break;
+
+ default:
+ rt_kprintf("Compressed BMP files not supported\n");
+ goto __exit;
+ }
+
+ bmp = (struct rtgui_image_bmp*) rtgui_malloc(sizeof(struct rtgui_image_bmp));
+ if (bmp == RT_NULL)
+ goto __exit;
+
+ /* set image information */
+ image->w = header->biWidth;
+ image->h = header->biHeight;
+ image->engine = &rtgui_image_bmp_engine;
+ image->data = bmp;
+ bmp->filerw = src;
+ bmp->byte_per_pixel = header->biBitCount/8;
+ bmp->pitch = image->w * bmp->byte_per_pixel;
+ bmp->pixel_offset = header->bfOffBits;
+ bmp->Rmask = Rmask; bmp->Gmask = Gmask; bmp->Bmask = Bmask;
+ bmp->ExpandBMP = ExpandBMP;
+ if (palette != RT_NULL) image->palette = palette;
+
+ /* get padding */
+ switch (ExpandBMP)
+ {
+ case 1:
+ bmpPitch = (header->biWidth + 7) >> 3;
+ bmp->pad = (((bmpPitch)%4) ? (4-((bmpPitch)%4)) : 0);
+ break;
+
+ case 4:
+ bmpPitch = (header->biWidth + 1) >> 1;
+ bmp->pad = (((bmpPitch)%4) ? (4-((bmpPitch)%4)) : 0);
+ break;
+
+ default:
+ bmp->pad = ((bmp->pitch%4) ? (4-(bmp->pitch%4)) : 0);
+ break;
+ }
+
+ if (load == RT_TRUE)
+ {
+ rt_uint8_t *bits;
+ rt_uint32_t i;
+
+ /* load all pixels */
+ bmp->pixels = rtgui_malloc(image->h * bmp->pitch);
+ if (bmp->pixels == RT_NULL)
+ goto __exit;
+
+ /* Read the pixels. Note that the bmp image is upside down */
+ if ( rtgui_filerw_seek(src, bmp->pixel_offset, RTGUI_FILE_SEEK_SET) < 0)
+ goto __exit;
+
+ bits = bmp->pixels + image->h * bmp->pitch;
+ while ( bits > bmp->pixels )
+ {
+ bits -= bmp->pitch;
+ switch (ExpandBMP)
+ {
+ case 1:
+ case 4:
+ {
+ rt_uint8_t pixel = 0;
+ int shift = (8 - ExpandBMP);
+ for ( i=0; i < image->w; ++i )
+ {
+ if ( i % (8/ExpandBMP) == 0 )
+ {
+ if ( !rtgui_filerw_read(src, &pixel, 1, 1) )
+ goto __exit;
+
+ }
+ *(bits+i) = (pixel>>shift);
+ pixel <<= ExpandBMP;
+ }
+ }
+ break;
+
+ default:
+ if ( rtgui_filerw_read(src, bits, 1, bmp->pitch) != bmp->pitch ) goto __exit;
+ break;
+ }
+
+ /* Skip padding bytes */
+ if ( bmp->pad )
+ {
+ rt_uint8_t padbyte;
+ for ( i=0; i < bmp->pad; ++i )
+ {
+ rtgui_filerw_read(src, &padbyte, 1, 1);
+ }
+ }
+ }
+
+ rtgui_filerw_close(bmp->filerw);
+ bmp->line_pixels = RT_NULL;
+ bmp->filerw = RT_NULL;
+ bmp->pixel_offset = 0;
+ }
+ else
+ {
+ bmp->pixels = RT_NULL;
+ bmp->line_pixels = rtgui_malloc(bmp->pitch);
+ }
+
+ return RT_TRUE;
+
+__exit:
+ rtgui_free(header);
+ if (palette != RT_NULL)
+ {
+ rtgui_free(palette);
+ image->palette = RT_NULL;
+ }
+
+ if (bmp != RT_NULL)
+ rtgui_free(bmp->pixels);
+ rtgui_free(bmp);
+ return RT_FALSE;
+}
+
+static void rtgui_image_bmp_unload(struct rtgui_image* image)
+{
+ struct rtgui_image_bmp* bmp;
+
+ if (image != RT_NULL)
+ {
+ bmp = (struct rtgui_image_bmp*) image->data;
+
+ if (bmp->pixels != RT_NULL) rtgui_free(bmp->pixels);
+ if (bmp->line_pixels != RT_NULL) rtgui_free(bmp->line_pixels);
+ if (bmp->filerw != RT_NULL)
+ {
+ rtgui_filerw_close(bmp->filerw);
+ bmp->filerw = RT_NULL;
+ }
+
+ /* release data */
+ rtgui_free(bmp);
+ }
+}
+
+static void rtgui_image_bmp_blit(struct rtgui_image* image, struct rtgui_dc* dc, struct rtgui_rect* dst_rect)
+{
+ int y;
+ rt_uint16_t w, h;
+ struct rtgui_image_bmp* bmp;
+
+ RT_ASSERT(image != RT_NULL || dc != RT_NULL || dst_rect != RT_NULL);
+
+ /* this dc is not visible */
+ if (rtgui_dc_get_visible(dc) != RT_TRUE) return;
+
+ bmp = (struct rtgui_image_bmp*) image->data;
+ RT_ASSERT(bmp != RT_NULL);
+
+ /* the minimum rect */
+ if (image->w < rtgui_rect_width(*dst_rect)) w = image->w;
+ else w = rtgui_rect_width(*dst_rect);
+ if (image->h < rtgui_rect_height(*dst_rect)) h = image->h;
+ else h = rtgui_rect_height(*dst_rect);
+
+ if (bmp->pixels != RT_NULL)
+ {
+ rt_uint8_t* ptr;
+
+ /* get pixel pointer */
+ ptr = bmp->pixels;
+ if (bmp->byte_per_pixel == hw_driver->bits_per_pixel/8)
+ {
+ for (y = 0; y < h; y ++)
+ {
+ dc->engine->blit_line(dc,
+ dst_rect->x1, dst_rect->x1 + w,
+ dst_rect->y1 + y,
+ ptr);
+ ptr += bmp->pitch;
+ }
+ }
+ else
+ {
+ rt_size_t pitch;
+ rt_uint8_t *line_ptr;
+
+ if (image->palette == RT_NULL)
+ {
+ rtgui_blit_line_func blit_line;
+ line_ptr = (rt_uint8_t*) rtgui_malloc((hw_driver->bits_per_pixel/8) * w);
+ blit_line = rtgui_blit_line_get(hw_driver->bits_per_pixel/8 , bmp->byte_per_pixel);
+ pitch = w * bmp->byte_per_pixel;
+ if (line_ptr != RT_NULL)
+ {
+ for (y = 0; y < h; y ++)
+ {
+ blit_line(line_ptr, ptr, pitch);
+ dc->engine->blit_line(dc,
+ dst_rect->x1, dst_rect->x1 + w,
+ dst_rect->y1 + y,
+ line_ptr);
+ ptr += bmp->pitch;
+ }
+ }
+ rtgui_free(line_ptr);
+ }
+ else
+ {
+ int x;
+ rtgui_color_t color;
+
+ /* use palette */
+ for (y = 0; y < h; y ++)
+ {
+ ptr = bmp->pixels + (y * bmp->pitch);
+ for (x = 0; x < w; x ++)
+ {
+ color = image->palette->colors[*ptr]; ptr ++;
+ rtgui_dc_draw_color_point(dc, dst_rect->x1 + x, dst_rect->y1 + y, color);
+ }
+ }
+ }
+ }
+ }
+ else
+ {
+ int offset;
+ rt_uint8_t *bits;
+
+ /* calculate offset */
+ switch (bmp->ExpandBMP)
+ {
+ case 1:
+ offset = (image->h - h) * (image->w/8) * bmp->byte_per_pixel;
+ break;
+
+ case 4:
+ offset = (image->h - h) * (image->w/2) * bmp->byte_per_pixel;
+ break;
+
+ default:
+ offset = (image->h - h) * image->w * bmp->byte_per_pixel;
+ break;
+ }
+ /* seek to the begin of pixel data */
+ rtgui_filerw_seek(bmp->filerw, bmp->pixel_offset + offset, RTGUI_FILE_SEEK_SET);
+
+ if (bmp->ExpandBMP == 1 || bmp->ExpandBMP == 4)
+ {
+ int x;
+ rtgui_color_t color;
+ /* 1, 4 bit per pixels */
+
+ /* draw each line */
+ for (y = h - 1; y >= 0; y --)
+ {
+ /* read pixel data */
+ rt_uint8_t pixel = 0;
+ int shift = (8 - bmp->ExpandBMP);
+ int i;
+
+ bits = bmp->line_pixels;
+ for ( i=0; i < image->w; ++i )
+ {
+ if ( i % (8/bmp->ExpandBMP) == 0 )
+ {
+ if ( !rtgui_filerw_read(bmp->filerw, &pixel, 1, 1) )
+ return;
+ }
+ *(bits+i) = (pixel>>shift);
+ pixel <<= bmp->ExpandBMP;
+ }
+
+ /* Skip padding bytes */
+ if (bmp->pad)
+ {
+ int i;
+ rt_uint8_t padbyte;
+ for ( i=0; i < bmp->pad; ++i )
+ rtgui_filerw_read(bmp->filerw, &padbyte, 1, 1);
+ }
+
+ /* use palette */
+ bits = bmp->line_pixels;
+ for (x = 0; x < w; x ++)
+ {
+ color = image->palette->colors[*bits]; bits ++;
+ rtgui_dc_draw_color_point(dc, dst_rect->x1 + x, dst_rect->y1 + y, color);
+ }
+ }
+ }
+ else
+ {
+ rt_uint8_t *line_ptr = (rt_uint8_t*) rtgui_malloc((hw_driver->bits_per_pixel/8) * w);
+ if (line_ptr == RT_NULL) return;
+
+ /* draw each line */
+ for (y = h - 1; y >= 0; y --)
+ {
+ /* read line pixels */
+ rtgui_filerw_read(bmp->filerw, bmp->line_pixels, 1, bmp->pitch);
+
+ /* Skip padding bytes */
+ if (bmp->pad)
+ {
+ int i;
+ rt_uint8_t padbyte;
+ for ( i=0; i < bmp->pad; ++i )
+ rtgui_filerw_read(bmp->filerw, &padbyte, 1, 1);
+ }
+
+ if (image->palette == RT_NULL)
+ {
+ int pitch;
+ rtgui_blit_line_func blit_line;
+ blit_line = rtgui_blit_line_get(hw_driver->bits_per_pixel/8 , bmp->byte_per_pixel);
+ pitch = w * bmp->byte_per_pixel;
+ if (line_ptr != RT_NULL)
+ {
+ blit_line(line_ptr, bmp->line_pixels, pitch);
+ dc->engine->blit_line(dc,
+ dst_rect->x1, dst_rect->x1 + w,
+ dst_rect->y1 + y,
+ line_ptr);
+ }
+ }
+ else
+ {
+ int x;
+ rtgui_color_t color;
+
+ /* use palette */
+ bits = bmp->line_pixels;
+ for (x = 0; x < w; x ++)
+ {
+ color = image->palette->colors[*bits]; bits ++;
+ rtgui_dc_draw_color_point(dc, dst_rect->x1 + x, dst_rect->y1 + y, color);
+ }
+ }
+ }
+ if (line_ptr != RT_NULL) rtgui_free(line_ptr);
+ }
+ }
+}
+
+void rtgui_image_bmp_init()
+{
+ /* register bmp on image system */
+ rtgui_image_register_engine(&rtgui_image_bmp_engine);
+}
+#endif
diff --git a/components/rtgui/common/image_container.c b/components/rtgui/common/image_container.c
index 9146f4f829..1088c9bbaf 100644
--- a/components/rtgui/common/image_container.c
+++ b/components/rtgui/common/image_container.c
@@ -1,445 +1,445 @@
-#include <rtgui/image_container.h>
-
-#ifdef RTGUI_IMAGE_CONTAINER
-typedef unsigned int (*rtgui_hash_func_t) (const void* key);
-typedef struct _rtgui_hash_table rtgui_hash_table_t;
-typedef rt_bool_t (*rtgui_equal_func_t) (const void* a, const void* b);
-typedef void (*rtgui_user_func_t) (const void* value, const void* data);
-
-/*
- *Hash tables
- */
-rtgui_hash_table_t* hash_table_create(rtgui_hash_func_t hash_func, rtgui_equal_func_t key_equal_func);
-void hash_table_destroy (rtgui_hash_table_t* hash_table);
-
-void* hash_table_find (rtgui_hash_table_t* hash_table, void* key);
-void hash_table_insert (rtgui_hash_table_t* hash_table, void* key, void* value);
-rt_bool_t hash_table_remove (rtgui_hash_table_t* hash_table, void* key);
-
-void hash_table_foreach(rtgui_hash_table_t* hash_table, rtgui_user_func_t user_func, void* data);
-unsigned int hash_table_get_size (rtgui_hash_table_t* hash_table);
-
-/* Hash Functions
- */
-unsigned int direct_hash (void* v);
-
-#define HASH_TABLE_MIN_SIZE 11
-#define HASH_TABLE_MAX_SIZE 6247
-
-typedef struct _gui_hash_node rtgui_hash_node_t;
-struct _gui_hash_node
-{
- void* key;
- void* value;
- rtgui_hash_node_t *next;
-};
-
-struct _rtgui_hash_table
-{
- rt_uint16_t size;
- rt_uint16_t nnodes;
-
- rtgui_hash_node_t **nodes;
- rtgui_hash_func_t hash_func;
- rtgui_equal_func_t key_equal_func;
-};
-
-static const unsigned int primes[] =
-{
- 11,
- 19,
- 37,
- 73,
- 109,
- 163,
- 251,
- 367,
- 557,
- 823,
- 1237,
- 1861,
- 2777,
- 4177,
- 6247,
-/*
- 9371,
- 14057,
- 21089,
- 31627,
- 47431,
- 71143,
- 106721,
- 160073,
- 240101,
- 360163,
- 540217,
- 810343,
- 1215497,
- 1823231,
- 2734867,
- 4102283,
- 6153409,
- 9230113,
- 13845163,
-*/
-};
-
-static const unsigned int nprimes = sizeof (primes) / sizeof (primes[0]);
-
-static void hash_table_resize (rtgui_hash_table_t *hash_table);
-static rtgui_hash_node_t** hash_table_find_node (rtgui_hash_table_t *hash_table, void* key);
-static rtgui_hash_node_t* hash_node_create (void* key, void* value);
-static void hash_node_destroy (rtgui_hash_node_t *hash_node);
-static void hash_nodes_destroy (rtgui_hash_node_t *hash_node);
-static unsigned int primes_closest (unsigned int num);
-static void hash_table_needresize(rtgui_hash_table_t *hash_table);
-
-rt_inline unsigned int primes_closest (unsigned int num)
-{
- int i;
-
- for (i = 0; i < nprimes; i++)
- if (primes[i] > num)
- return primes[i];
-
- return primes[nprimes - 1];
-}
-
-/* directly hash */
-unsigned int direct_hash (void* v)
-{
- return (unsigned int)v;
-}
-
-rtgui_hash_table_t* hash_table_create(rtgui_hash_func_t hash_func, rtgui_equal_func_t key_equal_func)
-{
- rtgui_hash_table_t *hash_table;
-
- hash_table = (rtgui_hash_table_t*) rt_malloc (sizeof(rtgui_hash_table_t));
- if (hash_table != RT_NULL)
- {
- hash_table->size = HASH_TABLE_MIN_SIZE;
- hash_table->nnodes = 0;
- hash_table->hash_func = hash_func ? hash_func : direct_hash;
- hash_table->key_equal_func = key_equal_func;
- hash_table->nodes = (rtgui_hash_node_t **)rt_malloc ( sizeof(rtgui_hash_node_t*) * hash_table->size);
- if (hash_table->nodes == RT_NULL)
- {
- /* no memory yet */
- rt_free(hash_table);
- return RT_NULL;
- }
-
- rt_memset(hash_table->nodes, 0, sizeof(rtgui_hash_node_t*) * hash_table->size);
- }
-
- return hash_table;
-}
-
-void hash_table_destroy (rtgui_hash_table_t *hash_table)
-{
- unsigned int i;
-
- RT_ASSERT(hash_table != RT_NULL);
-
- for (i = 0; i < hash_table->size; i++)
- hash_nodes_destroy (hash_table->nodes[i]);
-
- rt_free (hash_table->nodes);
- rt_free (hash_table);
-}
-
-static rtgui_hash_node_t** hash_table_find_node (rtgui_hash_table_t *hash_table, void* key)
-{
- rtgui_hash_node_t **node;
-
- node = &hash_table->nodes [(* hash_table->hash_func) (key) % hash_table->size];
-
- if (hash_table->key_equal_func)
- while (*node && !(*hash_table->key_equal_func) ((*node)->key, key))
- node = &(*node)->next;
- else
- while (*node && (*node)->key != key)
- node = &(*node)->next;
-
- return node;
-}
-
-void* hash_table_find (rtgui_hash_table_t* hash_table, void* key)
-{
- rtgui_hash_node_t *node;
-
- RT_ASSERT(hash_table != RT_NULL);
- RT_ASSERT(key != RT_NULL);
-
- node = *hash_table_find_node (hash_table, key);
-
- if (node) return node->value;
- else return RT_NULL;
-}
-
-void hash_table_insert (rtgui_hash_table_t *hash_table, void* key, void* value)
-{
- rtgui_hash_node_t **node;
-
- if (hash_table == RT_NULL)return;
-
- node = hash_table_find_node (hash_table, key);
- if (*node)
- {
- (*node)->value = value;
- }
- else
- {
- *node = hash_node_create (key, value);
- hash_table->nnodes++;
- hash_table_needresize (hash_table);
- }
-}
-
-rt_bool_t hash_table_remove (rtgui_hash_table_t *hash_table, void* key)
-{
- rtgui_hash_node_t **node, *dest;
-
- if (hash_table == RT_NULL) return RT_FALSE;
-
- node = hash_table_find_node (hash_table, key);
- if (*node)
- {
- dest = *node;
- (*node) = dest->next;
- hash_node_destroy (dest);
- hash_table->nnodes--;
-
- hash_table_needresize (hash_table);
-
- return RT_TRUE;
- }
-
- return RT_FALSE;
-}
-
-void hash_table_foreach(rtgui_hash_table_t *hash_table, rtgui_user_func_t user_func, void* data)
-{
- rtgui_hash_node_t *node;
- int i;
-
- RT_ASSERT(hash_table != RT_NULL);
- RT_ASSERT(user_func != RT_NULL);
-
- for (i = 0; i < hash_table->size; i++)
- for (node = hash_table->nodes[i]; node; node = node->next)
- (* user_func) (node->value, data);
-}
-
-unsigned int hash_table_get_size (rtgui_hash_table_t *hash_table)
-{
- if ( hash_table ==NULL ) return 0;
-
- return hash_table->nnodes;
-}
-
-static void hash_table_needresize(rtgui_hash_table_t *hash_table)
-{
- if ((hash_table->size >= 3*hash_table->nnodes && hash_table->size > HASH_TABLE_MIN_SIZE) ||
- (3 * hash_table->size <= hash_table->nnodes && hash_table->size < HASH_TABLE_MAX_SIZE))
- hash_table_resize (hash_table);
-}
-
-static void hash_table_resize (rtgui_hash_table_t *hash_table)
-{
- rtgui_hash_node_t **new_nodes;
- rtgui_hash_node_t *node;
- rtgui_hash_node_t *next;
- unsigned int hash_val;
- int new_size;
- int i;
-
- i = primes_closest(hash_table->nnodes);
- new_size = i > HASH_TABLE_MAX_SIZE ? HASH_TABLE_MAX_SIZE : i < HASH_TABLE_MIN_SIZE ? HASH_TABLE_MIN_SIZE : i ;
-
- new_nodes = (rtgui_hash_node_t **)rt_malloc ( sizeof(rtgui_hash_node_t*) * new_size);
- if (new_nodes == RT_NULL) return; /* no memory yet */
- rt_memset(new_nodes, 0, sizeof(rtgui_hash_node_t*) * new_size);
-
- for (i = 0; i < hash_table->size; i++)
- {
- for (node = hash_table->nodes[i]; node; node = next)
- {
- next = node->next;
-
- hash_val = (* hash_table->hash_func) (node->key) % new_size;
-
- node->next = new_nodes[hash_val];
- new_nodes[hash_val] = node;
- }
- }
-
- rt_free (hash_table->nodes);
- hash_table->nodes = new_nodes;
- hash_table->size = new_size;
-}
-
-static rtgui_hash_node_t* hash_node_create (void* key, void* value)
-{
- rtgui_hash_node_t *hash_node;
-
- hash_node = (rtgui_hash_node_t*) rt_malloc ( sizeof(rtgui_hash_node_t) );
- if (hash_node != RT_NULL)
- {
- /* set value and key */
- hash_node->key = key;
- hash_node->value = value;;
-
- hash_node->next = RT_NULL;
- }
-
- return hash_node;
-}
-
-static void hash_node_destroy (rtgui_hash_node_t *hash_node)
-{
- rt_free(hash_node);
-}
-
-static void hash_nodes_destroy (rtgui_hash_node_t *hash_node)
-{
- if (hash_node)
- {
- rtgui_hash_node_t *node = hash_node;
- rtgui_hash_node_t *temp;
-
- while (node->next)
- {
- node->key = NULL;
- node->value = NULL;
-
- temp = node;
- node = node->next;
- rt_free(temp);
- }
-
- node->key = NULL;
- node->value = NULL;
- rt_free(node);
- }
-}
-
-unsigned int string_hash_func(const void* self)
-{
- const char *p;
- int h=0, g;
-
- for(p = self; *p != '\0'; p += 1)
- {
- h = ( h << 4 ) + *p;
- if ( ( g = h & 0xf0000000 ) )
- {
- h = h ^ (g >> 24);
- h = h ^ g;
- }
- }
-
- return h ;
-}
-rt_bool_t string_equal_func(const void* a, const void* b)
-{
- const char *str1, *str2;
-
- str1 = (const char*)a;
- str2 = (const char*)b;
-
- if (strcmp(str1, str2) == 0) return RT_TRUE;
- return RT_FALSE;
-}
-
-static rtgui_hash_table_t* image_hash_table;
-static rt_bool_t load_image = RT_FALSE;
-void rtgui_system_image_container_init(rt_bool_t load)
-{
- /* create image hash table */
- image_hash_table = hash_table_create(string_hash_func, string_equal_func);
- RT_ASSERT(image_hash_table != RT_NULL);
-
- /* set load type */
- load_image = load;
-}
-
-rtgui_image_item_t* rtgui_image_container_get(const char* filename)
-{
- struct rtgui_image_item* item;
-
- item = hash_table_find(image_hash_table, filename);
- if (item == RT_NULL)
- {
- item = (struct rtgui_image_item*) rt_malloc (sizeof(struct rtgui_image_item));
- if (item == RT_NULL) return RT_NULL;
-
- /* create a image object */
- item->image = rtgui_image_create(filename, load_image);
- if (item->image == RT_NULL)
- {
- rt_free(item);
- return RT_NULL; /* create image failed */
- }
-
- item->refcount = 1;
- item->filename = rt_strdup(filename);
- hash_table_insert(image_hash_table, item->filename, item);
- }
- else
- {
- item->refcount ++; /* increase refcount */
- }
-
- return item;
-}
-
-rtgui_image_item_t* rtgui_image_container_get_memref(const char* type, const rt_uint8_t* memory, rt_uint32_t length)
-{
- char filename[32];
- struct rtgui_image_item* item;
-
- /* create filename for image identification */
- rt_snprintf(filename, sizeof(filename), "0x%08x_%s", memory, type);
-
- /* search in container */
- item = hash_table_find(image_hash_table, filename);
- if (item == RT_NULL)
- {
- item = (struct rtgui_image_item*) rt_malloc (sizeof(struct rtgui_image_item));
- if (item == RT_NULL) return RT_NULL;
-
- /* create image object */
- item->image = rtgui_image_create_from_mem(type, memory, length, load_image);
- if (item->image == RT_NULL)
- {
- rt_free(item);
- return RT_NULL; /* create image failed */
- }
-
- item->refcount = 1;
- item->filename = rt_strdup(filename);
- hash_table_insert(image_hash_table, item->filename, item);
- }
- else item->refcount ++;
-
- return item;
-}
-
-void rtgui_image_container_put(rtgui_image_item_t* item)
-{
- item->refcount --;
- if (item->refcount == 0)
- {
- /* remove item from container */
- hash_table_remove(image_hash_table, item->filename);
-
- /* destroy image and image item */
- rt_free(item->filename);
- rtgui_image_destroy(item->image);
- rt_free(item);
- }
-}
-
-#endif
+#include <rtgui/image_container.h>
+
+#ifdef RTGUI_IMAGE_CONTAINER
+typedef unsigned int (*rtgui_hash_func_t) (const void* key);
+typedef struct _rtgui_hash_table rtgui_hash_table_t;
+typedef rt_bool_t (*rtgui_equal_func_t) (const void* a, const void* b);
+typedef void (*rtgui_user_func_t) (const void* value, const void* data);
+
+/*
+ *Hash tables
+ */
+rtgui_hash_table_t* hash_table_create(rtgui_hash_func_t hash_func, rtgui_equal_func_t key_equal_func);
+void hash_table_destroy (rtgui_hash_table_t* hash_table);
+
+void* hash_table_find (rtgui_hash_table_t* hash_table, void* key);
+void hash_table_insert (rtgui_hash_table_t* hash_table, void* key, void* value);
+rt_bool_t hash_table_remove (rtgui_hash_table_t* hash_table, void* key);
+
+void hash_table_foreach(rtgui_hash_table_t* hash_table, rtgui_user_func_t user_func, void* data);
+unsigned int hash_table_get_size (rtgui_hash_table_t* hash_table);
+
+/* Hash Functions
+ */
+unsigned int direct_hash (void* v);
+
+#define HASH_TABLE_MIN_SIZE 11
+#define HASH_TABLE_MAX_SIZE 6247
+
+typedef struct _gui_hash_node rtgui_hash_node_t;
+struct _gui_hash_node
+{
+ void* key;
+ void* value;
+ rtgui_hash_node_t *next;
+};
+
+struct _rtgui_hash_table
+{
+ rt_uint16_t size;
+ rt_uint16_t nnodes;
+
+ rtgui_hash_node_t **nodes;
+ rtgui_hash_func_t hash_func;
+ rtgui_equal_func_t key_equal_func;
+};
+
+static const unsigned int primes[] =
+{
+ 11,
+ 19,
+ 37,
+ 73,
+ 109,
+ 163,
+ 251,
+ 367,
+ 557,
+ 823,
+ 1237,
+ 1861,
+ 2777,
+ 4177,
+ 6247,
+/*
+ 9371,
+ 14057,
+ 21089,
+ 31627,
+ 47431,
+ 71143,
+ 106721,
+ 160073,
+ 240101,
+ 360163,
+ 540217,
+ 810343,
+ 1215497,
+ 1823231,
+ 2734867,
+ 4102283,
+ 6153409,
+ 9230113,
+ 13845163,
+*/
+};
+
+static const unsigned int nprimes = sizeof (primes) / sizeof (primes[0]);
+
+static void hash_table_resize (rtgui_hash_table_t *hash_table);
+static rtgui_hash_node_t** hash_table_find_node (rtgui_hash_table_t *hash_table, void* key);
+static rtgui_hash_node_t* hash_node_create (void* key, void* value);
+static void hash_node_destroy (rtgui_hash_node_t *hash_node);
+static void hash_nodes_destroy (rtgui_hash_node_t *hash_node);
+static unsigned int primes_closest (unsigned int num);
+static void hash_table_needresize(rtgui_hash_table_t *hash_table);
+
+rt_inline unsigned int primes_closest (unsigned int num)
+{
+ int i;
+
+ for (i = 0; i < nprimes; i++)
+ if (primes[i] > num)
+ return primes[i];
+
+ return primes[nprimes - 1];
+}
+
+/* directly hash */
+unsigned int direct_hash (void* v)
+{
+ return (unsigned int)v;
+}
+
+rtgui_hash_table_t* hash_table_create(rtgui_hash_func_t hash_func, rtgui_equal_func_t key_equal_func)
+{
+ rtgui_hash_table_t *hash_table;
+
+ hash_table = (rtgui_hash_table_t*) rt_malloc (sizeof(rtgui_hash_table_t));
+ if (hash_table != RT_NULL)
+ {
+ hash_table->size = HASH_TABLE_MIN_SIZE;
+ hash_table->nnodes = 0;
+ hash_table->hash_func = hash_func ? hash_func : direct_hash;
+ hash_table->key_equal_func = key_equal_func;
+ hash_table->nodes = (rtgui_hash_node_t **)rt_malloc ( sizeof(rtgui_hash_node_t*) * hash_table->size);
+ if (hash_table->nodes == RT_NULL)
+ {
+ /* no memory yet */
+ rt_free(hash_table);
+ return RT_NULL;
+ }
+
+ rt_memset(hash_table->nodes, 0, sizeof(rtgui_hash_node_t*) * hash_table->size);
+ }
+
+ return hash_table;
+}
+
+void hash_table_destroy (rtgui_hash_table_t *hash_table)
+{
+ unsigned int i;
+
+ RT_ASSERT(hash_table != RT_NULL);
+
+ for (i = 0; i < hash_table->size; i++)
+ hash_nodes_destroy (hash_table->nodes[i]);
+
+ rt_free (hash_table->nodes);
+ rt_free (hash_table);
+}
+
+static rtgui_hash_node_t** hash_table_find_node (rtgui_hash_table_t *hash_table, void* key)
+{
+ rtgui_hash_node_t **node;
+
+ node = &hash_table->nodes [(* hash_table->hash_func) (key) % hash_table->size];
+
+ if (hash_table->key_equal_func)
+ while (*node && !(*hash_table->key_equal_func) ((*node)->key, key))
+ node = &(*node)->next;
+ else
+ while (*node && (*node)->key != key)
+ node = &(*node)->next;
+
+ return node;
+}
+
+void* hash_table_find (rtgui_hash_table_t* hash_table, void* key)
+{
+ rtgui_hash_node_t *node;
+
+ RT_ASSERT(hash_table != RT_NULL);
+ RT_ASSERT(key != RT_NULL);
+
+ node = *hash_table_find_node (hash_table, key);
+
+ if (node) return node->value;
+ else return RT_NULL;
+}
+
+void hash_table_insert (rtgui_hash_table_t *hash_table, void* key, void* value)
+{
+ rtgui_hash_node_t **node;
+
+ if (hash_table == RT_NULL)return;
+
+ node = hash_table_find_node (hash_table, key);
+ if (*node)
+ {
+ (*node)->value = value;
+ }
+ else
+ {
+ *node = hash_node_create (key, value);
+ hash_table->nnodes++;
+ hash_table_needresize (hash_table);
+ }
+}
+
+rt_bool_t hash_table_remove (rtgui_hash_table_t *hash_table, void* key)
+{
+ rtgui_hash_node_t **node, *dest;
+
+ if (hash_table == RT_NULL) return RT_FALSE;
+
+ node = hash_table_find_node (hash_table, key);
+ if (*node)
+ {
+ dest = *node;
+ (*node) = dest->next;
+ hash_node_destroy (dest);
+ hash_table->nnodes--;
+
+ hash_table_needresize (hash_table);
+
+ return RT_TRUE;
+ }
+
+ return RT_FALSE;
+}
+
+void hash_table_foreach(rtgui_hash_table_t *hash_table, rtgui_user_func_t user_func, void* data)
+{
+ rtgui_hash_node_t *node;
+ int i;
+
+ RT_ASSERT(hash_table != RT_NULL);
+ RT_ASSERT(user_func != RT_NULL);
+
+ for (i = 0; i < hash_table->size; i++)
+ for (node = hash_table->nodes[i]; node; node = node->next)
+ (* user_func) (node->value, data);
+}
+
+unsigned int hash_table_get_size (rtgui_hash_table_t *hash_table)
+{
+ if ( hash_table ==NULL ) return 0;
+
+ return hash_table->nnodes;
+}
+
+static void hash_table_needresize(rtgui_hash_table_t *hash_table)
+{
+ if ((hash_table->size >= 3*hash_table->nnodes && hash_table->size > HASH_TABLE_MIN_SIZE) ||
+ (3 * hash_table->size <= hash_table->nnodes && hash_table->size < HASH_TABLE_MAX_SIZE))
+ hash_table_resize (hash_table);
+}
+
+static void hash_table_resize (rtgui_hash_table_t *hash_table)
+{
+ rtgui_hash_node_t **new_nodes;
+ rtgui_hash_node_t *node;
+ rtgui_hash_node_t *next;
+ unsigned int hash_val;
+ int new_size;
+ int i;
+
+ i = primes_closest(hash_table->nnodes);
+ new_size = i > HASH_TABLE_MAX_SIZE ? HASH_TABLE_MAX_SIZE : i < HASH_TABLE_MIN_SIZE ? HASH_TABLE_MIN_SIZE : i ;
+
+ new_nodes = (rtgui_hash_node_t **)rt_malloc ( sizeof(rtgui_hash_node_t*) * new_size);
+ if (new_nodes == RT_NULL) return; /* no memory yet */
+ rt_memset(new_nodes, 0, sizeof(rtgui_hash_node_t*) * new_size);
+
+ for (i = 0; i < hash_table->size; i++)
+ {
+ for (node = hash_table->nodes[i]; node; node = next)
+ {
+ next = node->next;
+
+ hash_val = (* hash_table->hash_func) (node->key) % new_size;
+
+ node->next = new_nodes[hash_val];
+ new_nodes[hash_val] = node;
+ }
+ }
+
+ rt_free (hash_table->nodes);
+ hash_table->nodes = new_nodes;
+ hash_table->size = new_size;
+}
+
+static rtgui_hash_node_t* hash_node_create (void* key, void* value)
+{
+ rtgui_hash_node_t *hash_node;
+
+ hash_node = (rtgui_hash_node_t*) rt_malloc ( sizeof(rtgui_hash_node_t) );
+ if (hash_node != RT_NULL)
+ {
+ /* set value and key */
+ hash_node->key = key;
+ hash_node->value = value;;
+
+ hash_node->next = RT_NULL;
+ }
+
+ return hash_node;
+}
+
+static void hash_node_destroy (rtgui_hash_node_t *hash_node)
+{
+ rt_free(hash_node);
+}
+
+static void hash_nodes_destroy (rtgui_hash_node_t *hash_node)
+{
+ if (hash_node)
+ {
+ rtgui_hash_node_t *node = hash_node;
+ rtgui_hash_node_t *temp;
+
+ while (node->next)
+ {
+ node->key = NULL;
+ node->value = NULL;
+
+ temp = node;
+ node = node->next;
+ rt_free(temp);
+ }
+
+ node->key = NULL;
+ node->value = NULL;
+ rt_free(node);
+ }
+}
+
+unsigned int string_hash_func(const void* self)
+{
+ const char *p;
+ int h=0, g;
+
+ for(p = self; *p != '\0'; p += 1)
+ {
+ h = ( h << 4 ) + *p;
+ if ( ( g = h & 0xf0000000 ) )
+ {
+ h = h ^ (g >> 24);
+ h = h ^ g;
+ }
+ }
+
+ return h ;
+}
+rt_bool_t string_equal_func(const void* a, const void* b)
+{
+ const char *str1, *str2;
+
+ str1 = (const char*)a;
+ str2 = (const char*)b;
+
+ if (strcmp(str1, str2) == 0) return RT_TRUE;
+ return RT_FALSE;
+}
+
+static rtgui_hash_table_t* image_hash_table;
+static rt_bool_t load_image = RT_FALSE;
+void rtgui_system_image_container_init(rt_bool_t load)
+{
+ /* create image hash table */
+ image_hash_table = hash_table_create(string_hash_func, string_equal_func);
+ RT_ASSERT(image_hash_table != RT_NULL);
+
+ /* set load type */
+ load_image = load;
+}
+
+rtgui_image_item_t* rtgui_image_container_get(const char* filename)
+{
+ struct rtgui_image_item* item;
+
+ item = hash_table_find(image_hash_table, filename);
+ if (item == RT_NULL)
+ {
+ item = (struct rtgui_image_item*) rt_malloc (sizeof(struct rtgui_image_item));
+ if (item == RT_NULL) return RT_NULL;
+
+ /* create a image object */
+ item->image = rtgui_image_create(filename, load_image);
+ if (item->image == RT_NULL)
+ {
+ rt_free(item);
+ return RT_NULL; /* create image failed */
+ }
+
+ item->refcount = 1;
+ item->filename = rt_strdup(filename);
+ hash_table_insert(image_hash_table, item->filename, item);
+ }
+ else
+ {
+ item->refcount ++; /* increase refcount */
+ }
+
+ return item;
+}
+
+rtgui_image_item_t* rtgui_image_container_get_memref(const char* type, const rt_uint8_t* memory, rt_uint32_t length)
+{
+ char filename[32];
+ struct rtgui_image_item* item;
+
+ /* create filename for image identification */
+ rt_snprintf(filename, sizeof(filename), "0x%08x_%s", memory, type);
+
+ /* search in container */
+ item = hash_table_find(image_hash_table, filename);
+ if (item == RT_NULL)
+ {
+ item = (struct rtgui_image_item*) rt_malloc (sizeof(struct rtgui_image_item));
+ if (item == RT_NULL) return RT_NULL;
+
+ /* create image object */
+ item->image = rtgui_image_create_from_mem(type, memory, length, load_image);
+ if (item->image == RT_NULL)
+ {
+ rt_free(item);
+ return RT_NULL; /* create image failed */
+ }
+
+ item->refcount = 1;
+ item->filename = rt_strdup(filename);
+ hash_table_insert(image_hash_table, item->filename, item);
+ }
+ else item->refcount ++;
+
+ return item;
+}
+
+void rtgui_image_container_put(rtgui_image_item_t* item)
+{
+ item->refcount --;
+ if (item->refcount == 0)
+ {
+ /* remove item from container */
+ hash_table_remove(image_hash_table, item->filename);
+
+ /* destroy image and image item */
+ rt_free(item->filename);
+ rtgui_image_destroy(item->image);
+ rt_free(item);
+ }
+}
+
+#endif
diff --git a/components/rtgui/common/pixel_driver.c b/components/rtgui/common/pixel_driver.c
index 8edabcb81d..31b22e164e 100644
--- a/components/rtgui/common/pixel_driver.c
+++ b/components/rtgui/common/pixel_driver.c
@@ -1,154 +1,154 @@
-#include <rtgui/rtgui_system.h>
-#include <rtgui/driver.h>
-
-#define gfx_device (rtgui_graphic_get_device()->device)
-#define gfx_device_ops rt_graphix_ops(gfx_device)
-
-static void _pixel_rgb565p_set_pixel(rtgui_color_t *c, int x, int y)
-{
- rt_uint16_t pixel;
-
- pixel = rtgui_color_to_565p(*c);
- gfx_device_ops->set_pixel((char*)&pixel, x, y);
-}
-
-static void _pixel_rgb565_set_pixel(rtgui_color_t *c, int x, int y)
-{
- rt_uint16_t pixel;
-
- pixel = rtgui_color_to_565(*c);
- gfx_device_ops->set_pixel((char*)&pixel, x, y);
-}
-
-static void _pixel_rgb888_set_pixel(rtgui_color_t *c, int x, int y)
-{
- rt_uint32_t pixel;
-
- pixel = rtgui_color_to_888(*c);
- gfx_device_ops->set_pixel((char*)&pixel, x, y);
-}
-
-static void _pixel_rgb565p_get_pixel(rtgui_color_t *c, int x, int y)
-{
- rt_uint16_t pixel;
-
- gfx_device_ops->get_pixel((char*)&pixel, x, y);
- *c = rtgui_color_from_565p(pixel);
-}
-
-static void _pixel_rgb565_get_pixel(rtgui_color_t *c, int x, int y)
-{
- rt_uint16_t pixel;
-
- gfx_device_ops->get_pixel((char*)&pixel, x, y);
- *c = rtgui_color_from_565(pixel);
-}
-
-static void _pixel_rgb888_get_pixel(rtgui_color_t *c, int x, int y)
-{
- rt_uint32_t pixel;
-
- gfx_device_ops->get_pixel((char*)&pixel, x, y);
- *c = rtgui_color_from_888(pixel);
-}
-
-static void _pixel_rgb565p_draw_hline(rtgui_color_t *c, int x1, int x2, int y)
-{
- rt_uint16_t pixel;
-
- pixel = rtgui_color_to_565p(*c);
- gfx_device_ops->draw_hline((char*)&pixel, x1, x2, y);
-}
-
-static void _pixel_rgb565_draw_hline(rtgui_color_t *c, int x1, int x2, int y)
-{
- rt_uint16_t pixel;
-
- pixel = rtgui_color_to_565(*c);
- gfx_device_ops->draw_hline((char*)&pixel, x1, x2, y);
-}
-
-static void _pixel_rgb888_draw_hline(rtgui_color_t *c, int x1, int x2, int y)
-{
- rt_uint32_t pixel;
-
- pixel = rtgui_color_to_888(*c);
- gfx_device_ops->draw_hline((char*)&pixel, x1, x2, y);
-}
-
-static void _pixel_rgb565p_draw_vline(rtgui_color_t *c, int x, int y1, int y2)
-{
- rt_uint16_t pixel;
-
- pixel = rtgui_color_to_565p(*c);
- gfx_device_ops->draw_vline((char*)&pixel, x, y1, y2);
-}
-
-static void _pixel_rgb565_draw_vline(rtgui_color_t *c, int x, int y1, int y2)
-{
- rt_uint16_t pixel;
-
- pixel = rtgui_color_to_565(*c);
- gfx_device_ops->draw_vline((char*)&pixel, x, y1, y2);
-}
-
-static void _pixel_rgb888_draw_vline(rtgui_color_t *c, int x, int y1, int y2)
-{
- rt_uint32_t pixel;
-
- pixel = rtgui_color_to_888(*c);
- gfx_device_ops->draw_vline((char*)&pixel, x, y1, y2);
-}
-
-static void _pixel_draw_raw_hline(rt_uint8_t *pixels, int x1, int x2, int y)
-{
- if (x2 > x1)
- gfx_device_ops->blit_line((char*)pixels, x1, y, (x2 - x1));
- else
- gfx_device_ops->blit_line((char*)pixels, x2, y, (x1 - x2));
-}
-
-/* pixel device */
-const struct rtgui_graphic_driver_ops _pixel_rgb565p_ops =
-{
- _pixel_rgb565p_set_pixel,
- _pixel_rgb565p_get_pixel,
- _pixel_rgb565p_draw_hline,
- _pixel_rgb565p_draw_vline,
- _pixel_draw_raw_hline,
-};
-
-const struct rtgui_graphic_driver_ops _pixel_rgb565_ops =
-{
- _pixel_rgb565_set_pixel,
- _pixel_rgb565_get_pixel,
- _pixel_rgb565_draw_hline,
- _pixel_rgb565_draw_vline,
- _pixel_draw_raw_hline,
-};
-
-const struct rtgui_graphic_driver_ops _pixel_rgb888_ops =
-{
- _pixel_rgb888_set_pixel,
- _pixel_rgb888_get_pixel,
- _pixel_rgb888_draw_hline,
- _pixel_rgb888_draw_vline,
- _pixel_draw_raw_hline,
-};
-
-const struct rtgui_graphic_driver_ops *rtgui_pixel_device_get_ops(int pixel_format)
-{
- switch (pixel_format)
- {
- case RTGRAPHIC_PIXEL_FORMAT_RGB565:
- return &_pixel_rgb565_ops;
-
- case RTGRAPHIC_PIXEL_FORMAT_RGB565P:
- return &_pixel_rgb565p_ops;
-
- case RTGRAPHIC_PIXEL_FORMAT_RGB888:
- return &_pixel_rgb888_ops;
- }
-
- return RT_NULL;
-}
+#include <rtgui/rtgui_system.h>
+#include <rtgui/driver.h>
+
+#define gfx_device (rtgui_graphic_get_device()->device)
+#define gfx_device_ops rt_graphix_ops(gfx_device)
+
+static void _pixel_rgb565p_set_pixel(rtgui_color_t *c, int x, int y)
+{
+ rt_uint16_t pixel;
+
+ pixel = rtgui_color_to_565p(*c);
+ gfx_device_ops->set_pixel((char*)&pixel, x, y);
+}
+
+static void _pixel_rgb565_set_pixel(rtgui_color_t *c, int x, int y)
+{
+ rt_uint16_t pixel;
+
+ pixel = rtgui_color_to_565(*c);
+ gfx_device_ops->set_pixel((char*)&pixel, x, y);
+}
+
+static void _pixel_rgb888_set_pixel(rtgui_color_t *c, int x, int y)
+{
+ rt_uint32_t pixel;
+
+ pixel = rtgui_color_to_888(*c);
+ gfx_device_ops->set_pixel((char*)&pixel, x, y);
+}
+
+static void _pixel_rgb565p_get_pixel(rtgui_color_t *c, int x, int y)
+{
+ rt_uint16_t pixel;
+
+ gfx_device_ops->get_pixel((char*)&pixel, x, y);
+ *c = rtgui_color_from_565p(pixel);
+}
+
+static void _pixel_rgb565_get_pixel(rtgui_color_t *c, int x, int y)
+{
+ rt_uint16_t pixel;
+
+ gfx_device_ops->get_pixel((char*)&pixel, x, y);
+ *c = rtgui_color_from_565(pixel);
+}
+
+static void _pixel_rgb888_get_pixel(rtgui_color_t *c, int x, int y)
+{
+ rt_uint32_t pixel;
+
+ gfx_device_ops->get_pixel((char*)&pixel, x, y);
+ *c = rtgui_color_from_888(pixel);
+}
+
+static void _pixel_rgb565p_draw_hline(rtgui_color_t *c, int x1, int x2, int y)
+{
+ rt_uint16_t pixel;
+
+ pixel = rtgui_color_to_565p(*c);
+ gfx_device_ops->draw_hline((char*)&pixel, x1, x2, y);
+}
+
+static void _pixel_rgb565_draw_hline(rtgui_color_t *c, int x1, int x2, int y)
+{
+ rt_uint16_t pixel;
+
+ pixel = rtgui_color_to_565(*c);
+ gfx_device_ops->draw_hline((char*)&pixel, x1, x2, y);
+}
+
+static void _pixel_rgb888_draw_hline(rtgui_color_t *c, int x1, int x2, int y)
+{
+ rt_uint32_t pixel;
+
+ pixel = rtgui_color_to_888(*c);
+ gfx_device_ops->draw_hline((char*)&pixel, x1, x2, y);
+}
+
+static void _pixel_rgb565p_draw_vline(rtgui_color_t *c, int x, int y1, int y2)
+{
+ rt_uint16_t pixel;
+
+ pixel = rtgui_color_to_565p(*c);
+ gfx_device_ops->draw_vline((char*)&pixel, x, y1, y2);
+}
+
+static void _pixel_rgb565_draw_vline(rtgui_color_t *c, int x, int y1, int y2)
+{
+ rt_uint16_t pixel;
+
+ pixel = rtgui_color_to_565(*c);
+ gfx_device_ops->draw_vline((char*)&pixel, x, y1, y2);
+}
+
+static void _pixel_rgb888_draw_vline(rtgui_color_t *c, int x, int y1, int y2)
+{
+ rt_uint32_t pixel;
+
+ pixel = rtgui_color_to_888(*c);
+ gfx_device_ops->draw_vline((char*)&pixel, x, y1, y2);
+}
+
+static void _pixel_draw_raw_hline(rt_uint8_t *pixels, int x1, int x2, int y)
+{
+ if (x2 > x1)
+ gfx_device_ops->blit_line((char*)pixels, x1, y, (x2 - x1));
+ else
+ gfx_device_ops->blit_line((char*)pixels, x2, y, (x1 - x2));
+}
+
+/* pixel device */
+const struct rtgui_graphic_driver_ops _pixel_rgb565p_ops =
+{
+ _pixel_rgb565p_set_pixel,
+ _pixel_rgb565p_get_pixel,
+ _pixel_rgb565p_draw_hline,
+ _pixel_rgb565p_draw_vline,
+ _pixel_draw_raw_hline,
+};
+
+const struct rtgui_graphic_driver_ops _pixel_rgb565_ops =
+{
+ _pixel_rgb565_set_pixel,
+ _pixel_rgb565_get_pixel,
+ _pixel_rgb565_draw_hline,
+ _pixel_rgb565_draw_vline,
+ _pixel_draw_raw_hline,
+};
+
+const struct rtgui_graphic_driver_ops _pixel_rgb888_ops =
+{
+ _pixel_rgb888_set_pixel,
+ _pixel_rgb888_get_pixel,
+ _pixel_rgb888_draw_hline,
+ _pixel_rgb888_draw_vline,
+ _pixel_draw_raw_hline,
+};
+
+const struct rtgui_graphic_driver_ops *rtgui_pixel_device_get_ops(int pixel_format)
+{
+ switch (pixel_format)
+ {
+ case RTGRAPHIC_PIXEL_FORMAT_RGB565:
+ return &_pixel_rgb565_ops;
+
+ case RTGRAPHIC_PIXEL_FORMAT_RGB565P:
+ return &_pixel_rgb565p_ops;
+
+ case RTGRAPHIC_PIXEL_FORMAT_RGB888:
+ return &_pixel_rgb888_ops;
+ }
+
+ return RT_NULL;
+}
diff --git a/components/rtgui/common/rtgui_object.c b/components/rtgui/common/rtgui_object.c
index f3f779e3a8..a4248cfb29 100644
--- a/components/rtgui/common/rtgui_object.c
+++ b/components/rtgui/common/rtgui_object.c
@@ -17,9 +17,10 @@
static void _rtgui_object_constructor(rtgui_object_t *object)
{
- if (!object) return;
+ if (!object)
+ return;
- object->is_static = RT_FALSE;
+ object->flag = RTGUI_OBJECT_FLAG_NONE;
}
/* Destroys the object */
@@ -28,7 +29,7 @@ static void _rtgui_object_destructor(rtgui_object_t *object)
/* nothing */
}
-DEFINE_CLASS_TYPE(type, "object",
+DEFINE_CLASS_TYPE(type, "object",
RT_NULL,
_rtgui_object_constructor,
_rtgui_object_destructor,
@@ -44,9 +45,9 @@ void rtgui_type_object_construct(const rtgui_type_t *type, rtgui_object_t *objec
}
void rtgui_type_destructors_call(const rtgui_type_t *type, rtgui_object_t *object)
-{
- const rtgui_type_t *t;
-
+{
+ const rtgui_type_t *t;
+
t = type;
while (t)
{
@@ -56,9 +57,9 @@ void rtgui_type_destructors_call(const rtgui_type_t *type, rtgui_object_t *objec
}
rt_bool_t rtgui_type_inherits_from(const rtgui_type_t *type, const rtgui_type_t *parent)
-{
- const rtgui_type_t *t;
-
+{
+ const rtgui_type_t *t;
+
t = type;
while (t)
{
@@ -115,7 +116,6 @@ rtgui_object_t *rtgui_object_create(rtgui_type_t *object_type)
#endif
new_object->type = object_type;
- new_object->is_static = RT_FALSE;
rtgui_type_object_construct(object_type, new_object);
@@ -131,7 +131,8 @@ rtgui_object_t *rtgui_object_create(rtgui_type_t *object_type)
*/
void rtgui_object_destroy(rtgui_object_t *object)
{
- if (!object || object->is_static == RT_TRUE) return;
+ if (!object || object->flag & RTGUI_OBJECT_FLAG_STATIC)
+ return;
#ifdef RTGUI_OBJECT_TRACE
obj_info.objs_number --;
@@ -178,3 +179,15 @@ const rtgui_type_t *rtgui_object_object_type_get(rtgui_object_t *object)
return object->type;
}
+void rtgui_object_set_event_handler(struct rtgui_object *object, rtgui_event_handler_ptr handler)
+{
+ RT_ASSERT(object != RT_NULL);
+
+ object->event_handler = handler;
+}
+
+rt_bool_t rtgui_object_event_handler(struct rtgui_object *object, struct rtgui_event* event)
+{
+ return RT_FALSE;
+}
+
diff --git a/components/rtgui/common/rtgui_system.c b/components/rtgui/common/rtgui_system.c
index 3d9d48445c..a503e946be 100644
--- a/components/rtgui/common/rtgui_system.c
+++ b/components/rtgui/common/rtgui_system.c
@@ -16,15 +16,13 @@
#include <rtgui/image.h>
#include <rtgui/font.h>
#include <rtgui/event.h>
+#include <rtgui/rtgui_application.h>
#include <rtgui/rtgui_server.h>
#include <rtgui/rtgui_system.h>
#include <rtgui/widgets/window.h>
#include <rtgui/rtgui_theme.h>
-#define RTGUI_EVENT_DEBUG
-
#ifdef _WIN32
-#define RTGUI_EVENT_DEBUG
#define RTGUI_MEM_TRACE
#endif
@@ -44,467 +42,6 @@ void rtgui_system_server_init()
}
/************************************************************************/
-/* RTGUI Thread Wrapper */
-/************************************************************************/
-#ifdef RTGUI_EVENT_DEBUG
-const char *event_string[] =
-{
- /* panel event */
- "PANEL_ATTACH", /* attach to a panel */
- "PANEL_DETACH", /* detach from a panel */
- "PANEL_SHOW", /* show in a panel */
- "PANEL_HIDE", /* hide from a panel */
- "PANEL_INFO", /* panel information */
- "PANEL_RESIZE", /* resize panel */
- "PANEL_FULLSCREEN", /* to full screen */
- "PANEL_NORMAL", /* to normal screen */
-
- /* window event */
- "WIN_CREATE", /* create a window */
- "WIN_DESTROY", /* destroy a window */
- "WIN_SHOW", /* show a window */
- "WIN_HIDE", /* hide a window */
- "WIN_ACTIVATE", /* activate a window */
- "WIN_DEACTIVATE", /* deactivate a window */
- "WIN_CLOSE", /* close a window */
- "WIN_MOVE", /* move a window */
- "WIN_RESIZE", /* resize a window */
-
- "SET_WM", /* set window manager */
-
- "UPDATE_BEGIN", /* begin of update rect */
- "UPDATE_END", /* end of update rect */
- "MONITOR_ADD", /* add a monitor rect */
- "MONITOR_REMOVE", /* remove a monitor rect*/
- "PAINT", /* paint on screen */
- "TIMER", /* timer */
-
- /* clip rect information */
- "CLIP_INFO", /* clip rect info */
-
- /* mouse and keyboard event */
- "MOUSE_MOTION", /* mouse motion */
- "MOUSE_BUTTON", /* mouse button info */
- "KBD", /* keyboard info */
-
- /* user command event */
- "COMMAND", /* user command */
-
- /* request's status event */
- "STATUS", /* request result */
- "SCROLLED", /* scroll bar scrolled */
- "RESIZE", /* widget resize */
-};
-
-#define DBG_MSG(x) rt_kprintf x
-
-static void rtgui_event_dump(rt_thread_t tid, rtgui_event_t* event)
-{
- char* sender = "(unknown)";
-
- if (event->sender != RT_NULL) sender = event->sender->name;
-
- if ((event->type == RTGUI_EVENT_TIMER) ||
- (event->type == RTGUI_EVENT_UPDATE_BEGIN) ||
- (event->type == RTGUI_EVENT_UPDATE_END))
- {
- /* don't dump timer event */
- return ;
- }
-
- rt_kprintf("%s -- %s --> %s ", sender, event_string[event->type], tid->name);
- switch (event->type)
- {
- case RTGUI_EVENT_PAINT:
- {
- struct rtgui_event_paint *paint = (struct rtgui_event_paint *)event;
-
- if(paint->wid != RT_NULL)
- rt_kprintf("win: %s", paint->wid->title);
- }
- break;
-
- case RTGUI_EVENT_KBD:
- {
- struct rtgui_event_kbd *ekbd = (struct rtgui_event_kbd*) event;
- if (ekbd->wid != RT_NULL)
- rt_kprintf("win: %s", ekbd->wid->title);
- if (RTGUI_KBD_IS_UP(ekbd)) rt_kprintf(", up");
- else rt_kprintf(", down");
- }
- break;
-
- case RTGUI_EVENT_CLIP_INFO:
- {
- struct rtgui_event_clip_info *info = (struct rtgui_event_clip_info *)event;
-
- if(info->wid != RT_NULL)
- rt_kprintf("win: %s", info->wid->title);
- }
- break;
-
- case RTGUI_EVENT_WIN_CREATE:
- {
- struct rtgui_event_win_create *create = (struct rtgui_event_win_create*)event;
-
- rt_kprintf(" win: %s at (x1:%d, y1:%d, x2:%d, y2:%d)",
-#ifdef RTGUI_USING_SMALL_SIZE
- create->wid->title,
- RTGUI_WIDGET(create->wid)->extent.x1,
- RTGUI_WIDGET(create->wid)->extent.y1,
- RTGUI_WIDGET(create->wid)->extent.x2,
- RTGUI_WIDGET(create->wid)->extent.y2);
-#else
- create->title,
- create->extent.x1,
- create->extent.y1,
- create->extent.x2,
- create->extent.y2);
-#endif
- }
- break;
-
- case RTGUI_EVENT_UPDATE_END:
- {
- struct rtgui_event_update_end* update_end = (struct rtgui_event_update_end*)event;
- rt_kprintf("(x:%d, y1:%d, x2:%d, y2:%d)", update_end->rect.x1,
- update_end->rect.y1,
- update_end->rect.x2,
- update_end->rect.y2);
- }
- break;
-
- case RTGUI_EVENT_WIN_ACTIVATE:
- case RTGUI_EVENT_WIN_DEACTIVATE:
- case RTGUI_EVENT_WIN_SHOW:
- {
- struct rtgui_event_win *win = (struct rtgui_event_win *)event;
-
- if(win->wid != RT_NULL)
- rt_kprintf("win: %s", win->wid->title);
- }
- break;
-
- case RTGUI_EVENT_WIN_MOVE:
- {
- struct rtgui_event_win_move *win = (struct rtgui_event_win_move *)event;
-
- if(win->wid != RT_NULL)
- {
- rt_kprintf("win: %s", win->wid->title);
- rt_kprintf(" to (x:%d, y:%d)", win->x, win->y);
- }
- }
- break;
-
- case RTGUI_EVENT_WIN_RESIZE:
- {
- struct rtgui_event_win_resize* win = (struct rtgui_event_win_resize *)event;
-
- if (win->wid != RT_NULL)
- {
- rt_kprintf("win: %s, rect(x1:%d, y1:%d, x2:%d, y2:%d)", win->wid->title,
- RTGUI_WIDGET(win->wid)->extent.x1,
- RTGUI_WIDGET(win->wid)->extent.y1,
- RTGUI_WIDGET(win->wid)->extent.x2,
- RTGUI_WIDGET(win->wid)->extent.y2);
- }
- }
- break;
-
- case RTGUI_EVENT_MOUSE_BUTTON:
- case RTGUI_EVENT_MOUSE_MOTION:
- {
- struct rtgui_event_mouse *mouse = (struct rtgui_event_mouse*)event;
-
- if (mouse->button & RTGUI_MOUSE_BUTTON_LEFT) rt_kprintf("left ");
- else rt_kprintf("right ");
-
- if (mouse->button & RTGUI_MOUSE_BUTTON_DOWN) rt_kprintf("down ");
- else rt_kprintf("up ");
-
- if (mouse->wid != RT_NULL)
- rt_kprintf("win: %s at (%d, %d)", mouse->wid->title,
- mouse->x, mouse->y);
- else
- rt_kprintf("(%d, %d)", mouse->x, mouse->y);
- }
- break;
-
- case RTGUI_EVENT_MONITOR_ADD:
- {
- struct rtgui_event_monitor *monitor = (struct rtgui_event_monitor*)event;
- if (monitor->panel != RT_NULL)
- {
- rt_kprintf("the rect is:(%d, %d) - (%d, %d)",
- monitor->rect.x1, monitor->rect.y1,
- monitor->rect.x2, monitor->rect.y2);
- }
- else if (monitor->wid != RT_NULL)
- {
- rt_kprintf("win: %s, the rect is:(%d, %d) - (%d, %d)", monitor->wid->title,
- monitor->rect.x1, monitor->rect.y1,
- monitor->rect.x2, monitor->rect.y2);
- }
- }
- break;
- }
-
- rt_kprintf("\n");
-}
-#else
-#define DBG_MSG(x)
-#define rtgui_event_dump(tid, event)
-#endif
-
-rtgui_thread_t* rtgui_thread_register(rt_thread_t tid, rt_mq_t mq)
-{
- rtgui_thread_t* thread = rtgui_malloc(sizeof(rtgui_thread_t));
-
- if (thread != RT_NULL)
- {
- DBG_MSG(("register a rtgui thread: %s, tid: 0x%p\n", tid->name, tid));
-
- /* set tid and mq */
- thread->tid = tid;
- thread->mq = mq;
- thread->widget = RT_NULL;
- thread->on_idle = RT_NULL;
-
- /* set user thread */
- tid->user_data = (rt_uint32_t)thread;
- }
-
- return thread;
-}
-
-void rtgui_thread_deregister(rt_thread_t tid)
-{
- rtgui_thread_t* thread;
-
- /* find rtgui_thread_t */
- thread = (rtgui_thread_t*) (tid->user_data);
-
- if (thread != RT_NULL)
- {
- /* remove rtgui_thread_t */
- tid->user_data = 0;
-
- /* free rtgui_thread_t */
- rtgui_free(thread);
- }
-}
-
-/* get current gui thread */
-rtgui_thread_t* rtgui_thread_self()
-{
- rtgui_thread_t* thread;
- rt_thread_t self;
-
- /* get current thread */
- self = rt_thread_self();
- thread = (rtgui_thread_t*)(self->user_data);
-
- return thread;
-}
-
-void rtgui_thread_set_onidle(rtgui_idle_func onidle)
-{
- rtgui_thread_t* thread;
-
- thread = rtgui_thread_self();
- RT_ASSERT(thread != RT_NULL);
-
- thread->on_idle = onidle;
-}
-
-rtgui_idle_func rtgui_thread_get_onidle()
-{
- rtgui_thread_t* thread;
-
- thread = rtgui_thread_self();
- RT_ASSERT(thread != RT_NULL);
-
- return thread->on_idle;
-}
-
-extern rt_thread_t rt_thread_find(char* name);
-rt_thread_t rtgui_thread_get_server()
-{
- return rt_thread_find("rtgui");
-}
-
-void rtgui_thread_set_widget(rtgui_widget_t* widget)
-{
- rtgui_thread_t* thread;
-
- /* get rtgui_thread */
- thread = (rtgui_thread_t*) (rt_thread_self()->user_data);
-
- if (thread != RT_NULL) thread->widget = widget;
-}
-
-rtgui_widget_t* rtgui_thread_get_widget()
-{
- rtgui_thread_t* thread;
-
- /* get rtgui_thread_t */
- thread = (rtgui_thread_t*) (rt_thread_self()->user_data);
-
- return thread == RT_NULL? RT_NULL : thread->widget;
-}
-
-rt_err_t rtgui_thread_send(rt_thread_t tid, rtgui_event_t* event, rt_size_t event_size)
-{
- rt_err_t result;
- rtgui_thread_t* thread;
-
- rtgui_event_dump(tid, event);
-
- /* find rtgui_thread_t */
- thread = (rtgui_thread_t*) (tid->user_data);
- if (thread == RT_NULL) return -RT_ERROR;
-
- result = rt_mq_send(thread->mq, event, event_size);
- if (result != RT_EOK)
- {
- if (event->type != RTGUI_EVENT_TIMER)
- rt_kprintf("send event to %s failed\n", thread->tid->name);
- }
-
- return result;
-}
-
-rt_err_t rtgui_thread_send_urgent(rt_thread_t tid, rtgui_event_t* event, rt_size_t event_size)
-{
- rt_err_t result;
- rtgui_thread_t* thread;
-
- rtgui_event_dump(tid, event);
-
- /* find rtgui_thread_t */
- thread = (rtgui_thread_t*) (tid->user_data);
- if (thread == RT_NULL) return -RT_ERROR;
-
- result = rt_mq_urgent(thread->mq, event, event_size);
- if (result != RT_EOK)
- rt_kprintf("send ergent event failed\n");
-
- return result;
-}
-
-rt_err_t rtgui_thread_send_sync(rt_thread_t tid, rtgui_event_t* event, rt_size_t event_size)
-{
- rt_err_t r;
- rtgui_thread_t* thread;
- rt_int32_t ack_buffer, ack_status;
- struct rt_mailbox ack_mb;
-
- rtgui_event_dump(tid, event);
-
- /* init ack mailbox */
- r = rt_mb_init(&ack_mb, "ack", &ack_buffer, 1, 0);
- if (r!= RT_EOK) goto __return;
-
- /* find rtgui_thread_t */
- thread = (rtgui_thread_t*) (tid->user_data);
- if (thread == RT_NULL)
- {
- r = -RT_ERROR;
- goto __return;
- }
-
- event->ack = &ack_mb;
- r = rt_mq_send(thread->mq, event, event_size);
- if (r != RT_EOK)
- {
- rt_kprintf("send sync event failed\n");
- goto __return;
- }
-
- r = rt_mb_recv(&ack_mb, (rt_uint32_t*)&ack_status, RT_WAITING_FOREVER);
- if (r!= RT_EOK) goto __return;
-
- if (ack_status != RTGUI_STATUS_OK)
- r = -RT_ERROR;
- else
- r = RT_EOK;
-
-__return:
- /* fini ack mailbox */
- rt_mb_detach(&ack_mb);
-
- return r;
-}
-
-rt_err_t rtgui_thread_ack(rtgui_event_t* event, rt_int32_t status)
-{
- if (event != RT_NULL &&
- event->ack != RT_NULL)
- {
- rt_mb_send(event->ack, status);
- }
-
- return RT_EOK;
-}
-
-rt_err_t rtgui_thread_recv(rtgui_event_t* event, rt_size_t event_size)
-{
- rtgui_thread_t* thread;
- rt_err_t r;
-
- /* find rtgui_thread_t */
- thread = (rtgui_thread_t*) (rt_thread_self()->user_data);
- if (thread == RT_NULL) return -RT_ERROR;
-
- r = rt_mq_recv(thread->mq, event, event_size, RT_WAITING_FOREVER);
-
- return r;
-}
-
-rt_err_t rtgui_thread_recv_nosuspend(rtgui_event_t* event, rt_size_t event_size)
-{
- rtgui_thread_t* thread;
- rt_err_t r;
-
- /* find rtgui_thread */
- thread = (rtgui_thread_t*) (rt_thread_self()->user_data);
- if (thread == RT_NULL) return -RT_ERROR;
-
- r = rt_mq_recv(thread->mq, event, event_size, 0);
-
- return r;
-}
-
-rt_err_t rtgui_thread_recv_filter(rt_uint32_t type, rtgui_event_t* event, rt_size_t event_size)
-{
- rtgui_thread_t* thread;
-
- /* find rtgui_thread_t */
- thread = (rtgui_thread_t*) (rt_thread_self()->user_data);
- if (thread == RT_NULL) return -RT_ERROR;
-
- while (rt_mq_recv(thread->mq, event, event_size, RT_WAITING_FOREVER) == RT_EOK)
- {
- if (event->type == type)
- {
- return RT_EOK;
- }
- else
- {
- /* let widget to handle event */
- if (thread->widget != RT_NULL &&
- thread->widget->event_handler != RT_NULL)
- {
- thread->widget->event_handler(thread->widget, event);
- }
- }
- }
-
- return -RT_ERROR;
-}
-
-/************************************************************************/
/* RTGUI Timer */
/************************************************************************/
static void rtgui_time_out(void* parameter)
@@ -522,7 +59,7 @@ static void rtgui_time_out(void* parameter)
event.timer = timer;
- rtgui_thread_send(timer->tid, &(event.parent), sizeof(rtgui_event_timer_t));
+ rtgui_application_send(timer->tid, &(event.parent), sizeof(rtgui_event_timer_t));
}
rtgui_timer_t* rtgui_timer_create(rt_int32_t time, rt_int32_t flag, rtgui_timeout_func timeout, void* parameter)
diff --git a/components/rtgui/common/rtgui_xml.c b/components/rtgui/common/rtgui_xml.c
index eecb197d59..47407bec3e 100644
--- a/components/rtgui/common/rtgui_xml.c
+++ b/components/rtgui/common/rtgui_xml.c
@@ -1,5 +1,5 @@
#include <rtgui/rtgui_xml.h>
-#include <rtgui/rtgui_system.h>
+#include <rtgui/rtgui_system.h>
/* Internal states that the parser can be in at any given time. */
enum {