pl110_template.h 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  1. /*
  2. * Arm PrimeCell PL110 Color LCD Controller
  3. *
  4. * Copyright (c) 2005 CodeSourcery, LLC.
  5. * Written by Paul Brook
  6. *
  7. * This code is licensed under the GNU LGPL
  8. *
  9. * Framebuffer format conversion routines.
  10. */
  11. #ifndef ORDER
  12. #if BITS == 8
  13. #define COPY_PIXEL(to, from) *(to++) = from
  14. #elif BITS == 15 || BITS == 16
  15. #define COPY_PIXEL(to, from) do { *(uint16_t *)to = from; to += 2; } while (0)
  16. #elif BITS == 24
  17. #define COPY_PIXEL(to, from) \
  18. do { \
  19. *(to++) = from; \
  20. *(to++) = (from) >> 8; \
  21. *(to++) = (from) >> 16; \
  22. } while (0)
  23. #elif BITS == 32
  24. #define COPY_PIXEL(to, from) do { *(uint32_t *)to = from; to += 4; } while (0)
  25. #else
  26. #error unknown bit depth
  27. #endif
  28. #undef RGB
  29. #define BORDER bgr
  30. #define ORDER 0
  31. #include "pl110_template.h"
  32. #define ORDER 1
  33. #include "pl110_template.h"
  34. #define ORDER 2
  35. #include "pl110_template.h"
  36. #undef BORDER
  37. #define RGB
  38. #define BORDER rgb
  39. #define ORDER 0
  40. #include "pl110_template.h"
  41. #define ORDER 1
  42. #include "pl110_template.h"
  43. #define ORDER 2
  44. #include "pl110_template.h"
  45. #undef BORDER
  46. static drawfn glue(pl110_draw_fn_,BITS)[48] =
  47. {
  48. glue(pl110_draw_line1_lblp_bgr,BITS),
  49. glue(pl110_draw_line2_lblp_bgr,BITS),
  50. glue(pl110_draw_line4_lblp_bgr,BITS),
  51. glue(pl110_draw_line8_lblp_bgr,BITS),
  52. glue(pl110_draw_line16_555_lblp_bgr,BITS),
  53. glue(pl110_draw_line32_lblp_bgr,BITS),
  54. glue(pl110_draw_line16_lblp_bgr,BITS),
  55. glue(pl110_draw_line12_lblp_bgr,BITS),
  56. glue(pl110_draw_line1_bbbp_bgr,BITS),
  57. glue(pl110_draw_line2_bbbp_bgr,BITS),
  58. glue(pl110_draw_line4_bbbp_bgr,BITS),
  59. glue(pl110_draw_line8_bbbp_bgr,BITS),
  60. glue(pl110_draw_line16_555_bbbp_bgr,BITS),
  61. glue(pl110_draw_line32_bbbp_bgr,BITS),
  62. glue(pl110_draw_line16_bbbp_bgr,BITS),
  63. glue(pl110_draw_line12_bbbp_bgr,BITS),
  64. glue(pl110_draw_line1_lbbp_bgr,BITS),
  65. glue(pl110_draw_line2_lbbp_bgr,BITS),
  66. glue(pl110_draw_line4_lbbp_bgr,BITS),
  67. glue(pl110_draw_line8_lbbp_bgr,BITS),
  68. glue(pl110_draw_line16_555_lbbp_bgr,BITS),
  69. glue(pl110_draw_line32_lbbp_bgr,BITS),
  70. glue(pl110_draw_line16_lbbp_bgr,BITS),
  71. glue(pl110_draw_line12_lbbp_bgr,BITS),
  72. glue(pl110_draw_line1_lblp_rgb,BITS),
  73. glue(pl110_draw_line2_lblp_rgb,BITS),
  74. glue(pl110_draw_line4_lblp_rgb,BITS),
  75. glue(pl110_draw_line8_lblp_rgb,BITS),
  76. glue(pl110_draw_line16_555_lblp_rgb,BITS),
  77. glue(pl110_draw_line32_lblp_rgb,BITS),
  78. glue(pl110_draw_line16_lblp_rgb,BITS),
  79. glue(pl110_draw_line12_lblp_rgb,BITS),
  80. glue(pl110_draw_line1_bbbp_rgb,BITS),
  81. glue(pl110_draw_line2_bbbp_rgb,BITS),
  82. glue(pl110_draw_line4_bbbp_rgb,BITS),
  83. glue(pl110_draw_line8_bbbp_rgb,BITS),
  84. glue(pl110_draw_line16_555_bbbp_rgb,BITS),
  85. glue(pl110_draw_line32_bbbp_rgb,BITS),
  86. glue(pl110_draw_line16_bbbp_rgb,BITS),
  87. glue(pl110_draw_line12_bbbp_rgb,BITS),
  88. glue(pl110_draw_line1_lbbp_rgb,BITS),
  89. glue(pl110_draw_line2_lbbp_rgb,BITS),
  90. glue(pl110_draw_line4_lbbp_rgb,BITS),
  91. glue(pl110_draw_line8_lbbp_rgb,BITS),
  92. glue(pl110_draw_line16_555_lbbp_rgb,BITS),
  93. glue(pl110_draw_line32_lbbp_rgb,BITS),
  94. glue(pl110_draw_line16_lbbp_rgb,BITS),
  95. glue(pl110_draw_line12_lbbp_rgb,BITS),
  96. };
  97. #undef BITS
  98. #undef COPY_PIXEL
  99. #else
  100. #if ORDER == 0
  101. #define NAME glue(glue(lblp_, BORDER), BITS)
  102. #ifdef HOST_WORDS_BIGENDIAN
  103. #define SWAP_WORDS 1
  104. #endif
  105. #elif ORDER == 1
  106. #define NAME glue(glue(bbbp_, BORDER), BITS)
  107. #ifndef HOST_WORDS_BIGENDIAN
  108. #define SWAP_WORDS 1
  109. #endif
  110. #else
  111. #define SWAP_PIXELS 1
  112. #define NAME glue(glue(lbbp_, BORDER), BITS)
  113. #ifdef HOST_WORDS_BIGENDIAN
  114. #define SWAP_WORDS 1
  115. #endif
  116. #endif
  117. #define FN_2(x, y) FN(x, y) FN(x+1, y)
  118. #define FN_4(x, y) FN_2(x, y) FN_2(x+2, y)
  119. #define FN_8(y) FN_4(0, y) FN_4(4, y)
  120. static void glue(pl110_draw_line1_,NAME)(void *opaque, uint8_t *d, const uint8_t *src, int width, int deststep)
  121. {
  122. uint32_t *palette = opaque;
  123. uint32_t data;
  124. while (width > 0) {
  125. data = *(uint32_t *)src;
  126. #ifdef SWAP_PIXELS
  127. #define FN(x, y) COPY_PIXEL(d, palette[(data >> (y + 7 - (x))) & 1]);
  128. #else
  129. #define FN(x, y) COPY_PIXEL(d, palette[(data >> ((x) + y)) & 1]);
  130. #endif
  131. #ifdef SWAP_WORDS
  132. FN_8(24)
  133. FN_8(16)
  134. FN_8(8)
  135. FN_8(0)
  136. #else
  137. FN_8(0)
  138. FN_8(8)
  139. FN_8(16)
  140. FN_8(24)
  141. #endif
  142. #undef FN
  143. width -= 32;
  144. src += 4;
  145. }
  146. }
  147. static void glue(pl110_draw_line2_,NAME)(void *opaque, uint8_t *d, const uint8_t *src, int width, int deststep)
  148. {
  149. uint32_t *palette = opaque;
  150. uint32_t data;
  151. while (width > 0) {
  152. data = *(uint32_t *)src;
  153. #ifdef SWAP_PIXELS
  154. #define FN(x, y) COPY_PIXEL(d, palette[(data >> (y + 6 - (x)*2)) & 3]);
  155. #else
  156. #define FN(x, y) COPY_PIXEL(d, palette[(data >> ((x)*2 + y)) & 3]);
  157. #endif
  158. #ifdef SWAP_WORDS
  159. FN_4(0, 24)
  160. FN_4(0, 16)
  161. FN_4(0, 8)
  162. FN_4(0, 0)
  163. #else
  164. FN_4(0, 0)
  165. FN_4(0, 8)
  166. FN_4(0, 16)
  167. FN_4(0, 24)
  168. #endif
  169. #undef FN
  170. width -= 16;
  171. src += 4;
  172. }
  173. }
  174. static void glue(pl110_draw_line4_,NAME)(void *opaque, uint8_t *d, const uint8_t *src, int width, int deststep)
  175. {
  176. uint32_t *palette = opaque;
  177. uint32_t data;
  178. while (width > 0) {
  179. data = *(uint32_t *)src;
  180. #ifdef SWAP_PIXELS
  181. #define FN(x, y) COPY_PIXEL(d, palette[(data >> (y + 4 - (x)*4)) & 0xf]);
  182. #else
  183. #define FN(x, y) COPY_PIXEL(d, palette[(data >> ((x)*4 + y)) & 0xf]);
  184. #endif
  185. #ifdef SWAP_WORDS
  186. FN_2(0, 24)
  187. FN_2(0, 16)
  188. FN_2(0, 8)
  189. FN_2(0, 0)
  190. #else
  191. FN_2(0, 0)
  192. FN_2(0, 8)
  193. FN_2(0, 16)
  194. FN_2(0, 24)
  195. #endif
  196. #undef FN
  197. width -= 8;
  198. src += 4;
  199. }
  200. }
  201. static void glue(pl110_draw_line8_,NAME)(void *opaque, uint8_t *d, const uint8_t *src, int width, int deststep)
  202. {
  203. uint32_t *palette = opaque;
  204. uint32_t data;
  205. while (width > 0) {
  206. data = *(uint32_t *)src;
  207. #define FN(x) COPY_PIXEL(d, palette[(data >> (x)) & 0xff]);
  208. #ifdef SWAP_WORDS
  209. FN(24)
  210. FN(16)
  211. FN(8)
  212. FN(0)
  213. #else
  214. FN(0)
  215. FN(8)
  216. FN(16)
  217. FN(24)
  218. #endif
  219. #undef FN
  220. width -= 4;
  221. src += 4;
  222. }
  223. }
  224. static void glue(pl110_draw_line16_,NAME)(void *opaque, uint8_t *d, const uint8_t *src, int width, int deststep)
  225. {
  226. uint32_t data;
  227. unsigned int r, g, b;
  228. while (width > 0) {
  229. data = *(uint32_t *)src;
  230. #ifdef SWAP_WORDS
  231. data = bswap32(data);
  232. #endif
  233. #ifdef RGB
  234. #define LSB r
  235. #define MSB b
  236. #else
  237. #define LSB b
  238. #define MSB r
  239. #endif
  240. #if 0
  241. LSB = data & 0x1f;
  242. data >>= 5;
  243. g = data & 0x3f;
  244. data >>= 6;
  245. MSB = data & 0x1f;
  246. data >>= 5;
  247. #else
  248. LSB = (data & 0x1f) << 3;
  249. data >>= 5;
  250. g = (data & 0x3f) << 2;
  251. data >>= 6;
  252. MSB = (data & 0x1f) << 3;
  253. data >>= 5;
  254. #endif
  255. COPY_PIXEL(d, glue(rgb_to_pixel,BITS)(r, g, b));
  256. LSB = (data & 0x1f) << 3;
  257. data >>= 5;
  258. g = (data & 0x3f) << 2;
  259. data >>= 6;
  260. MSB = (data & 0x1f) << 3;
  261. data >>= 5;
  262. COPY_PIXEL(d, glue(rgb_to_pixel,BITS)(r, g, b));
  263. #undef MSB
  264. #undef LSB
  265. width -= 2;
  266. src += 4;
  267. }
  268. }
  269. static void glue(pl110_draw_line32_,NAME)(void *opaque, uint8_t *d, const uint8_t *src, int width, int deststep)
  270. {
  271. uint32_t data;
  272. unsigned int r, g, b;
  273. while (width > 0) {
  274. data = *(uint32_t *)src;
  275. #ifdef RGB
  276. #define LSB r
  277. #define MSB b
  278. #else
  279. #define LSB b
  280. #define MSB r
  281. #endif
  282. #ifndef SWAP_WORDS
  283. LSB = data & 0xff;
  284. g = (data >> 8) & 0xff;
  285. MSB = (data >> 16) & 0xff;
  286. #else
  287. LSB = (data >> 24) & 0xff;
  288. g = (data >> 16) & 0xff;
  289. MSB = (data >> 8) & 0xff;
  290. #endif
  291. COPY_PIXEL(d, glue(rgb_to_pixel,BITS)(r, g, b));
  292. #undef MSB
  293. #undef LSB
  294. width--;
  295. src += 4;
  296. }
  297. }
  298. static void glue(pl110_draw_line16_555_,NAME)(void *opaque, uint8_t *d, const uint8_t *src, int width, int deststep)
  299. {
  300. /* RGB 555 plus an intensity bit (which we ignore) */
  301. uint32_t data;
  302. unsigned int r, g, b;
  303. while (width > 0) {
  304. data = *(uint32_t *)src;
  305. #ifdef SWAP_WORDS
  306. data = bswap32(data);
  307. #endif
  308. #ifdef RGB
  309. #define LSB r
  310. #define MSB b
  311. #else
  312. #define LSB b
  313. #define MSB r
  314. #endif
  315. LSB = (data & 0x1f) << 3;
  316. data >>= 5;
  317. g = (data & 0x1f) << 3;
  318. data >>= 5;
  319. MSB = (data & 0x1f) << 3;
  320. data >>= 5;
  321. COPY_PIXEL(d, glue(rgb_to_pixel,BITS)(r, g, b));
  322. LSB = (data & 0x1f) << 3;
  323. data >>= 5;
  324. g = (data & 0x1f) << 3;
  325. data >>= 5;
  326. MSB = (data & 0x1f) << 3;
  327. data >>= 6;
  328. COPY_PIXEL(d, glue(rgb_to_pixel,BITS)(r, g, b));
  329. #undef MSB
  330. #undef LSB
  331. width -= 2;
  332. src += 4;
  333. }
  334. }
  335. static void glue(pl110_draw_line12_,NAME)(void *opaque, uint8_t *d, const uint8_t *src, int width, int deststep)
  336. {
  337. /* RGB 444 with 4 bits of zeroes at the top of each halfword */
  338. uint32_t data;
  339. unsigned int r, g, b;
  340. while (width > 0) {
  341. data = *(uint32_t *)src;
  342. #ifdef SWAP_WORDS
  343. data = bswap32(data);
  344. #endif
  345. #ifdef RGB
  346. #define LSB r
  347. #define MSB b
  348. #else
  349. #define LSB b
  350. #define MSB r
  351. #endif
  352. LSB = (data & 0xf) << 4;
  353. data >>= 4;
  354. g = (data & 0xf) << 4;
  355. data >>= 4;
  356. MSB = (data & 0xf) << 4;
  357. data >>= 8;
  358. COPY_PIXEL(d, glue(rgb_to_pixel,BITS)(r, g, b));
  359. LSB = (data & 0xf) << 4;
  360. data >>= 4;
  361. g = (data & 0xf) << 4;
  362. data >>= 4;
  363. MSB = (data & 0xf) << 4;
  364. data >>= 8;
  365. COPY_PIXEL(d, glue(rgb_to_pixel,BITS)(r, g, b));
  366. #undef MSB
  367. #undef LSB
  368. width -= 2;
  369. src += 4;
  370. }
  371. }
  372. #undef SWAP_PIXELS
  373. #undef NAME
  374. #undef SWAP_WORDS
  375. #undef ORDER
  376. #endif