image_xpm.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632
  1. /*
  2. * File : image_xpm.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
  5. *
  6. * The license and distribution terms for this file may be
  7. * found in the file LICENSE in this distribution or at
  8. * http://www.rt-thread.org/license/LICENSE
  9. *
  10. * Change Logs:
  11. * Date Author Notes
  12. * 2009-10-16 Bernard first version
  13. */
  14. #include <stdio.h>
  15. #include <string.h>
  16. #include <rtgui/filerw.h>
  17. #include <rtgui/image_xpm.h>
  18. #include <rtgui/rtgui_system.h>
  19. #ifdef RTGUI_IMAGE_XPM
  20. #define XPM_MAGIC_LEN 9
  21. static rt_bool_t rtgui_image_xpm_check(struct rtgui_filerw *file);
  22. static rt_bool_t rtgui_image_xpm_load(struct rtgui_image *image, struct rtgui_filerw *file, rt_bool_t load);
  23. static void rtgui_image_xpm_unload(struct rtgui_image *image);
  24. static void rtgui_image_xpm_blit(struct rtgui_image *image, struct rtgui_dc *dc, struct rtgui_rect *rect);
  25. struct rtgui_image_engine rtgui_image_xpm_engine =
  26. {
  27. "xpm",
  28. {RT_NULL},
  29. rtgui_image_xpm_check,
  30. rtgui_image_xpm_load,
  31. rtgui_image_xpm_unload,
  32. rtgui_image_xpm_blit,
  33. };
  34. struct rgb_item
  35. {
  36. char *name;
  37. rt_uint8_t r;
  38. rt_uint8_t g;
  39. rt_uint8_t b;
  40. };
  41. const struct rgb_item rgbRecord[234] =
  42. {
  43. {"AliceBlue", 240, 248, 255},
  44. {"AntiqueWhite", 250, 235, 215},
  45. {"Aquamarine", 50, 191, 193},
  46. {"Azure", 240, 255, 255},
  47. {"Beige", 245, 245, 220},
  48. {"Bisque", 255, 228, 196},
  49. {"Black", 0, 0, 0},
  50. {"BlanchedAlmond", 255, 235, 205},
  51. {"Blue", 0, 0, 255},
  52. {"BlueViolet", 138, 43, 226},
  53. {"Brown", 165, 42, 42},
  54. {"burlywood", 222, 184, 135},
  55. {"CadetBlue", 95, 146, 158},
  56. {"chartreuse", 127, 255, 0},
  57. {"chocolate", 210, 105, 30},
  58. {"Coral", 255, 114, 86},
  59. {"CornflowerBlue", 34, 34, 152},
  60. {"cornsilk", 255, 248, 220},
  61. {"Cyan", 0, 255, 255},
  62. {"DarkGoldenrod", 184, 134, 11},
  63. {"DarkGreen", 0, 86, 45},
  64. {"DarkKhaki", 189, 183, 107},
  65. {"DarkOliveGreen", 85, 86, 47},
  66. {"DarkOrange", 255, 140, 0},
  67. {"DarkOrchid", 139, 32, 139},
  68. {"DarkSalmon", 233, 150, 122},
  69. {"DarkSeaGreen", 143, 188, 143},
  70. {"DarkSlateBlue", 56, 75, 102},
  71. {"DarkSlateGray", 47, 79, 79},
  72. {"DarkTurquoise", 0, 166, 166},
  73. {"DarkViolet", 148, 0, 211},
  74. {"DeepPink", 255, 20, 147},
  75. {"DeepSkyBlue", 0, 191, 255},
  76. {"DimGray", 84, 84, 84},
  77. {"DodgerBlue", 30, 144, 255},
  78. {"Firebrick", 142, 35, 35},
  79. {"FloralWhite", 255, 250, 240},
  80. {"ForestGreen", 80, 159, 105},
  81. {"gainsboro", 220, 220, 220},
  82. {"GhostWhite", 248, 248, 255},
  83. {"Gold", 218, 170, 0},
  84. {"Goldenrod", 239, 223, 132},
  85. {"Gray", 126, 126, 126},
  86. {"Gray0", 0, 0, 0},
  87. {"Gray1", 3, 3, 3},
  88. {"Gray10", 26, 26, 26},
  89. {"Gray100", 255, 255, 255},
  90. {"Gray11", 28, 28, 28},
  91. {"Gray12", 31, 31, 31},
  92. {"Gray13", 33, 33, 33},
  93. {"Gray14", 36, 36, 36},
  94. {"Gray15", 38, 38, 38},
  95. {"Gray16", 41, 41, 41},
  96. {"Gray17", 43, 43, 43},
  97. {"Gray18", 46, 46, 46},
  98. {"Gray19", 48, 48, 48},
  99. {"Gray2", 5, 5, 5},
  100. {"Gray20", 51, 51, 51},
  101. {"Gray21", 54, 54, 54},
  102. {"Gray22", 56, 56, 56},
  103. {"Gray23", 59, 59, 59},
  104. {"Gray24", 61, 61, 61},
  105. {"Gray25", 64, 64, 64},
  106. {"Gray26", 66, 66, 66},
  107. {"Gray27", 69, 69, 69},
  108. {"Gray28", 71, 71, 71},
  109. {"Gray29", 74, 74, 74},
  110. {"Gray3", 8, 8, 8},
  111. {"Gray30", 77, 77, 77},
  112. {"Gray31", 79, 79, 79},
  113. {"Gray32", 82, 82, 82},
  114. {"Gray33", 84, 84, 84},
  115. {"Gray34", 87, 87, 87},
  116. {"Gray35", 89, 89, 89},
  117. {"Gray36", 92, 92, 92},
  118. {"Gray37", 94, 94, 94},
  119. {"Gray38", 97, 97, 97},
  120. {"Gray39", 99, 99, 99},
  121. {"Gray4", 10, 10, 10},
  122. {"Gray40", 102, 102, 102},
  123. {"Gray41", 105, 105, 105},
  124. {"Gray42", 107, 107, 107},
  125. {"Gray43", 110, 110, 110},
  126. {"Gray44", 112, 112, 112},
  127. {"Gray45", 115, 115, 115},
  128. {"Gray46", 117, 117, 117},
  129. {"Gray47", 120, 120, 120},
  130. {"Gray48", 122, 122, 122},
  131. {"Gray49", 125, 125, 125},
  132. {"Gray5", 13, 13, 13},
  133. {"Gray50", 127, 127, 127},
  134. {"Gray51", 130, 130, 130},
  135. {"Gray52", 133, 133, 133},
  136. {"Gray53", 135, 135, 135},
  137. {"Gray54", 138, 138, 138},
  138. {"Gray55", 140, 140, 140},
  139. {"Gray56", 143, 143, 143},
  140. {"Gray57", 145, 145, 145},
  141. {"Gray58", 148, 148, 148},
  142. {"Gray59", 150, 150, 150},
  143. {"Gray6", 15, 15, 15},
  144. {"Gray60", 153, 153, 153},
  145. {"Gray61", 156, 156, 156},
  146. {"Gray62", 158, 158, 158},
  147. {"Gray63", 161, 161, 161},
  148. {"Gray64", 163, 163, 163},
  149. {"Gray65", 166, 166, 166},
  150. {"Gray66", 168, 168, 168},
  151. {"Gray67", 171, 171, 171},
  152. {"Gray68", 173, 173, 173},
  153. {"Gray69", 176, 176, 176},
  154. {"Gray7", 18, 18, 18},
  155. {"Gray70", 179, 179, 179},
  156. {"Gray71", 181, 181, 181},
  157. {"Gray72", 184, 184, 184},
  158. {"Gray73", 186, 186, 186},
  159. {"Gray74", 189, 189, 189},
  160. {"Gray75", 191, 191, 191},
  161. {"Gray76", 194, 194, 194},
  162. {"Gray77", 196, 196, 196},
  163. {"Gray78", 199, 199, 199},
  164. {"Gray79", 201, 201, 201},
  165. {"Gray8", 20, 20, 20},
  166. {"Gray80", 204, 204, 204},
  167. {"Gray81", 207, 207, 207},
  168. {"Gray82", 209, 209, 209},
  169. {"Gray83", 212, 212, 212},
  170. {"Gray84", 214, 214, 214},
  171. {"Gray85", 217, 217, 217},
  172. {"Gray86", 219, 219, 219},
  173. {"Gray87", 222, 222, 222},
  174. {"Gray88", 224, 224, 224},
  175. {"Gray89", 227, 227, 227},
  176. {"Gray9", 23, 23, 23},
  177. {"Gray90", 229, 229, 229},
  178. {"Gray91", 232, 232, 232},
  179. {"Gray92", 235, 235, 235},
  180. {"Gray93", 237, 237, 237},
  181. {"Gray94", 240, 240, 240},
  182. {"Gray95", 242, 242, 242},
  183. {"Gray96", 245, 245, 245},
  184. {"Gray97", 247, 247, 247},
  185. {"Gray98", 250, 250, 250},
  186. {"Gray99", 252, 252, 252},
  187. {"Green", 0, 255, 0},
  188. {"GreenYellow", 173, 255, 47},
  189. {"honeydew", 240, 255, 240},
  190. {"HotPink", 255, 105, 180},
  191. {"IndianRed", 107, 57, 57},
  192. {"ivory", 255, 255, 240},
  193. {"Khaki", 179, 179, 126},
  194. {"lavender", 230, 230, 250},
  195. {"LavenderBlush", 255, 240, 245},
  196. {"LawnGreen", 124, 252, 0},
  197. {"LemonChiffon", 255, 250, 205},
  198. {"LightBlue", 176, 226, 255},
  199. {"LightCoral", 240, 128, 128},
  200. {"LightCyan", 224, 255, 255},
  201. {"LightGoldenrod", 238, 221, 130},
  202. {"LightGoldenrodYellow", 250, 250, 210},
  203. {"LightGray", 168, 168, 168},
  204. {"LightPink", 255, 182, 193},
  205. {"LightSalmon", 255, 160, 122},
  206. {"LightSeaGreen", 32, 178, 170},
  207. {"LightSkyBlue", 135, 206, 250},
  208. {"LightSlateBlue", 132, 112, 255},
  209. {"LightSlateGray", 119, 136, 153},
  210. {"LightSteelBlue", 124, 152, 211},
  211. {"LightYellow", 255, 255, 224},
  212. {"LimeGreen", 0, 175, 20},
  213. {"linen", 250, 240, 230},
  214. {"Magenta", 255, 0, 255},
  215. {"Maroon", 143, 0, 82},
  216. {"MediumAquamarine", 0, 147, 143},
  217. {"MediumBlue", 50, 50, 204},
  218. {"MediumForestGreen", 50, 129, 75},
  219. {"MediumGoldenrod", 209, 193, 102},
  220. {"MediumOrchid", 189, 82, 189},
  221. {"MediumPurple", 147, 112, 219},
  222. {"MediumSeaGreen", 52, 119, 102},
  223. {"MediumSlateBlue", 106, 106, 141},
  224. {"MediumSpringGreen", 35, 142, 35},
  225. {"MediumTurquoise", 0, 210, 210},
  226. {"MediumVioletRed", 213, 32, 121},
  227. {"MidnightBlue", 47, 47, 100},
  228. {"MintCream", 245, 255, 250},
  229. {"MistyRose", 255, 228, 225},
  230. {"moccasin", 255, 228, 181},
  231. {"NavajoWhite", 255, 222, 173},
  232. {"Navy", 35, 35, 117},
  233. {"NavyBlue", 35, 35, 117},
  234. {"OldLace", 253, 245, 230},
  235. {"OliveDrab", 107, 142, 35},
  236. {"Orange", 255, 135, 0},
  237. {"OrangeRed", 255, 69, 0},
  238. {"Orchid", 239, 132, 239},
  239. {"PaleGoldenrod", 238, 232, 170},
  240. {"PaleGreen", 115, 222, 120},
  241. {"PaleTurquoise", 175, 238, 238},
  242. {"PaleVioletRed", 219, 112, 147},
  243. {"PapayaWhip", 255, 239, 213},
  244. {"PeachPuff", 255, 218, 185},
  245. {"peru", 205, 133, 63},
  246. {"Pink", 255, 181, 197},
  247. {"Plum", 197, 72, 155},
  248. {"PowderBlue", 176, 224, 230},
  249. {"purple", 160, 32, 240},
  250. {"Red", 255, 0, 0},
  251. {"RosyBrown", 188, 143, 143},
  252. {"RoyalBlue", 65, 105, 225},
  253. {"SaddleBrown", 139, 69, 19},
  254. {"Salmon", 233, 150, 122},
  255. {"SandyBrown", 244, 164, 96},
  256. {"SeaGreen", 82, 149, 132},
  257. {"seashell", 255, 245, 238},
  258. {"Sienna", 150, 82, 45},
  259. {"SkyBlue", 114, 159, 255},
  260. {"SlateBlue", 126, 136, 171},
  261. {"SlateGray", 112, 128, 144},
  262. {"snow", 255, 250, 250},
  263. {"SpringGreen", 65, 172, 65},
  264. {"SteelBlue", 84, 112, 170},
  265. {"Tan", 222, 184, 135},
  266. {"Thistle", 216, 191, 216},
  267. {"tomato", 255, 99, 71},
  268. {"Transparent", 0, 0, 1},
  269. {"Turquoise", 25, 204, 223},
  270. {"Violet", 156, 62, 206},
  271. {"VioletRed", 243, 62, 150},
  272. {"Wheat", 245, 222, 179},
  273. {"White", 255, 255, 255},
  274. {"WhiteSmoke", 245, 245, 245},
  275. {"Yellow", 255, 255, 0},
  276. {"YellowGreen", 50, 216, 56}
  277. };
  278. /* Hash table to look up colors from pixel strings */
  279. #define STARTING_HASH_SIZE 256
  280. struct hash_entry
  281. {
  282. char key[10];
  283. rtgui_color_t color;
  284. struct hash_entry *next;
  285. };
  286. struct color_hash
  287. {
  288. struct hash_entry **table;
  289. struct hash_entry *entries; /* array of all entries */
  290. struct hash_entry *next_free;
  291. int size;
  292. int maxnum;
  293. };
  294. static int hash_key(const char *key, int cpp, int size)
  295. {
  296. int hash;
  297. hash = 0;
  298. while (cpp-- > 0)
  299. {
  300. hash = hash * 33 + *key++;
  301. }
  302. return hash & (size - 1);
  303. }
  304. static struct color_hash *create_colorhash(int maxnum)
  305. {
  306. int bytes, s;
  307. struct color_hash *hash;
  308. /* we know how many entries we need, so we can allocate
  309. everything here */
  310. hash = rtgui_malloc(sizeof *hash);
  311. if (!hash) return RT_NULL;
  312. /* use power-of-2 sized hash table for decoding speed */
  313. for (s = STARTING_HASH_SIZE; s < maxnum; s <<= 1) ;
  314. hash->size = s;
  315. hash->maxnum = maxnum;
  316. bytes = hash->size *sizeof(struct hash_entry **);
  317. hash->entries = RT_NULL; /* in case rt_malloc fails */
  318. hash->table = rtgui_malloc(bytes);
  319. if (!hash->table) return RT_NULL;
  320. rt_memset(hash->table, 0, bytes);
  321. hash->entries = rtgui_malloc(maxnum *sizeof(struct hash_entry));
  322. if (!hash->entries) return RT_NULL;
  323. hash->next_free = hash->entries;
  324. return hash;
  325. }
  326. static int add_colorhash(struct color_hash *hash,
  327. char *key, int cpp, rtgui_color_t *color)
  328. {
  329. int index = hash_key(key, cpp, hash->size);
  330. struct hash_entry *e = hash->next_free++;
  331. e->color = *color;
  332. rt_memset(e->key, 0, sizeof(e->key));
  333. rt_strncpy(e->key, key, cpp);
  334. e->next = hash->table[index];
  335. hash->table[index] = e;
  336. return 1;
  337. }
  338. static void get_colorhash(struct color_hash *hash, const char *key, int cpp, rtgui_color_t *c)
  339. {
  340. struct hash_entry *entry = hash->table[hash_key(key, cpp, hash->size)];
  341. while (entry)
  342. {
  343. if (rt_memcmp(key, entry->key, cpp) == 0)
  344. {
  345. *c = entry->color;
  346. return;
  347. }
  348. entry = entry->next;
  349. }
  350. return ; /* garbage in - garbage out */
  351. }
  352. static void free_colorhash(struct color_hash *hash)
  353. {
  354. if (hash && hash->table)
  355. {
  356. rtgui_free(hash->table);
  357. rtgui_free(hash->entries);
  358. rtgui_free(hash);
  359. }
  360. }
  361. #if defined(_MSC_VER) || defined(__CC_ARM)
  362. int strcasecmp(const char *s1, const char *s2)
  363. {
  364. register unsigned int x2;
  365. register unsigned int x1;
  366. while (1)
  367. {
  368. x2 = *s2 - 'A';
  369. if (x2 < 26u) x2 += 32;
  370. x1 = *s1 - 'A';
  371. if (x1 < 26u) x1 += 32;
  372. s1++;
  373. s2++;
  374. if (x2 != x1)
  375. break;
  376. if (x1 == (unsigned int) - 'A')
  377. break;
  378. }
  379. return x1 - x2;
  380. }
  381. #endif
  382. static int hex2int(const char *str)
  383. {
  384. int i = 0;
  385. int r = 0;
  386. for (i = 0; i < 2; i++)
  387. {
  388. if (str[i] >= '0' && str[i] <= '9') r += str[i] - '0';
  389. else if (str[i] >= 'a' && str[i] <= 'f') r += str[i] - 'a' + 10;
  390. else if (str[i] >= 'A' && str[i] <= 'F') r += str[i] - 'A' + 10;
  391. if (!i) r *= 16;
  392. }
  393. return r;
  394. }
  395. void rtgui_image_xpm_init()
  396. {
  397. /* register xpm engine */
  398. rtgui_image_register_engine(&rtgui_image_xpm_engine);
  399. }
  400. static rt_bool_t rtgui_image_xpm_check(struct rtgui_filerw *file)
  401. {
  402. #if 0
  403. rt_uint8_t buffer[XPM_MAGIC_LEN];
  404. rt_size_t start;
  405. rt_bool_t result;
  406. result = RT_FALSE;
  407. start = rtgui_filerw_tell(file);
  408. /* seek to the begining of file */
  409. if (start != 0) rtgui_filerw_seek(file, 0, SEEK_SET);
  410. rtgui_filerw_read(file, &buffer[0], XPM_MAGIC_LEN, 1);
  411. if (rt_memcmp(buffer, "/* XPM */", (rt_ubase_t)XPM_MAGIC_LEN) == 0)
  412. result = RT_TRUE;
  413. rtgui_filerw_seek(file, start, SEEK_SET);
  414. return result;
  415. #else
  416. /* we can not check image type for memory file */
  417. return RT_TRUE;
  418. #endif
  419. }
  420. static int _str2int(const char *str, int strlen, int *p)
  421. {
  422. int i;
  423. *p = 0;
  424. /* Skip the leading chars. */
  425. for (i = 0; i < strlen; i++)
  426. {
  427. if ('0' <= str[i] && str[i] <= '9')
  428. break;
  429. }
  430. for (; i < strlen; i++)
  431. {
  432. if (str[i] < '0' || '9' < str[i])
  433. break;
  434. *p = (*p) * 10 + str[i] - '0';
  435. }
  436. return i;
  437. }
  438. static rt_bool_t rtgui_image_xpm_load(struct rtgui_image *image, struct rtgui_filerw *file, rt_bool_t load)
  439. {
  440. const char **xpm;
  441. const char *buf;
  442. const char *buf_tmp;
  443. int w, h;
  444. int colors = 0;
  445. int colors_pp = 0;
  446. int i, j;
  447. /* color hash table */
  448. struct color_hash *colors_table = RT_NULL;
  449. if (image == RT_NULL) return RT_FALSE;
  450. xpm = (const char **)rtgui_filerw_mem_getdata(file);
  451. if (xpm == RT_NULL) return RT_FALSE;
  452. /* set image engine */
  453. image->engine = &rtgui_image_xpm_engine;
  454. /* parse xpm image */
  455. i = rt_strlen(xpm[0]);
  456. /* Add one for the space. */
  457. j = _str2int(xpm[0], i, &w) + 1;
  458. j += _str2int(xpm[0] + j, i - j, &h) + 1;
  459. j += _str2int(xpm[0] + j, i - j, &colors) + 1;
  460. j += _str2int(xpm[0] + j, i - j, &colors_pp) + 1;
  461. image->w = w;
  462. image->h = h;
  463. /* build color table */
  464. colors_table = create_colorhash(colors);
  465. if (!colors_table)
  466. {
  467. return RT_FALSE;
  468. }
  469. for (i = 0; i < colors; i++)
  470. {
  471. char color_name[10];
  472. rtgui_color_t c = 0;
  473. buf = xpm[i + 1];
  474. for (j = 0; j < colors_pp; j++)
  475. {
  476. color_name[j] = buf[j];
  477. }
  478. color_name[j] = '\0';
  479. /* build rtgui_color */
  480. if ((buf_tmp = strstr(buf, "c #")) != RT_NULL)
  481. {
  482. c = RTGUI_ARGB(0, hex2int(buf_tmp + 3),
  483. hex2int(buf_tmp + 5),
  484. hex2int(buf_tmp + 7));
  485. }
  486. else if ((buf_tmp = strstr(buf, "c ")) != RT_NULL)
  487. {
  488. int k;
  489. if (strcasecmp(buf_tmp + 2, "None") == 0)
  490. {
  491. goto color_none;
  492. }
  493. for (k = 0; k < 234; k++)
  494. {
  495. if (strcasecmp(buf_tmp + 2, rgbRecord[k].name) == 0)
  496. {
  497. c = RTGUI_ARGB(0, rgbRecord[k].r,
  498. rgbRecord[k].g,
  499. rgbRecord[k].b);
  500. break;
  501. }
  502. }
  503. }
  504. else
  505. {
  506. color_none:
  507. c = RTGUI_RGB(0, 0, 0);
  508. }
  509. /* add to color hash table */
  510. add_colorhash(colors_table, color_name, colors_pp, &c);
  511. }
  512. /* build rgb pixel data */
  513. image->data = (rt_uint8_t *) rtgui_malloc(image->w * image->h * sizeof(rtgui_color_t));
  514. memset(image->data, 0, image->w * image->h * sizeof(rtgui_color_t));
  515. {
  516. rtgui_color_t *ptr = (rtgui_color_t *) image->data;
  517. for (h = 0; h < image->h; h++)
  518. {
  519. buf = xpm[colors + 1 + h];
  520. for (w = 0; w < image->w; w++, buf += colors_pp)
  521. {
  522. get_colorhash(colors_table, buf, colors_pp, ptr);
  523. ptr ++;
  524. }
  525. }
  526. }
  527. free_colorhash(colors_table);
  528. rtgui_filerw_close(file);
  529. return RT_TRUE;
  530. }
  531. static void rtgui_image_xpm_unload(struct rtgui_image *image)
  532. {
  533. if (image != RT_NULL)
  534. {
  535. /* release data */
  536. rtgui_free(image->data);
  537. image->data = RT_NULL;
  538. }
  539. }
  540. static void rtgui_image_xpm_blit(struct rtgui_image *image, struct rtgui_dc *dc, struct rtgui_rect *rect)
  541. {
  542. rt_uint16_t x, y;
  543. rtgui_color_t *ptr;
  544. RT_ASSERT(image != RT_NULL && dc != RT_NULL && rect != RT_NULL);
  545. RT_ASSERT(image->data != RT_NULL);
  546. ptr = (rtgui_color_t *) image->data;
  547. /* draw each point within dc */
  548. for (y = 0; y < image->h; y ++)
  549. {
  550. for (x = 0; x < image->w; x++)
  551. {
  552. /* not alpha */
  553. if ((*ptr >> 24) != 255)
  554. {
  555. rtgui_dc_draw_color_point(dc, x + rect->x1, y + rect->y1, *ptr);
  556. }
  557. /* move to next color buffer */
  558. ptr ++;
  559. }
  560. }
  561. }
  562. #endif