/lib/DirectFB/DirectFB-1.4.3/src/gfx/convert.h

https://bitbucket.org/thelearninglabs/uclinux-distro-tll-public · C Header · 668 lines · 491 code · 143 blank · 34 comment · 11 complexity · 55ada8596a69a89d127e08eb2cb02078 MD5 · raw file

  1. /*
  2. (c) Copyright 2001-2009 The world wide DirectFB Open Source Community (directfb.org)
  3. (c) Copyright 2000-2004 Convergence (integrated media) GmbH
  4. All rights reserved.
  5. Written by Denis Oliver Kropp <dok@directfb.org>,
  6. Andreas Hundt <andi@fischlustig.de>,
  7. Sven Neumann <neo@directfb.org>,
  8. Ville Syrjälä <syrjala@sci.fi> and
  9. Claudio Ciccani <klan@users.sf.net>.
  10. This library is free software; you can redistribute it and/or
  11. modify it under the terms of the GNU Lesser General Public
  12. License as published by the Free Software Foundation; either
  13. version 2 of the License, or (at your option) any later version.
  14. This library is distributed in the hope that it will be useful,
  15. but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. Lesser General Public License for more details.
  18. You should have received a copy of the GNU Lesser General Public
  19. License along with this library; if not, write to the
  20. Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  21. Boston, MA 02111-1307, USA.
  22. */
  23. #ifndef __GFX__CONVERT_H__
  24. #define __GFX__CONVERT_H__
  25. #include <directfb.h>
  26. #include <direct/memcpy.h>
  27. #include <direct/util.h>
  28. /* pixel packing */
  29. #define PIXEL_RGB332(r,g,b) ( (((r)&0xE0) ) | \
  30. (((g)&0xE0) >> 3) | \
  31. (((b)&0xC0) >> 6) )
  32. #define PIXEL_ARGB1555(a,r,g,b)( (((a)&0x80) << 8) | \
  33. (((r)&0xF8) << 7) | \
  34. (((g)&0xF8) << 2) | \
  35. (((b)&0xF8) >> 3) )
  36. #define PIXEL_RGBA5551(a,r,g,b)( (((a)&0x80) >> 7) | \
  37. (((r)&0xF8) << 8) | \
  38. (((g)&0xF8) << 3) | \
  39. (((b)&0xF8) >> 2) )
  40. #define PIXEL_RGB555(r,g,b) ( (((r)&0xF8) << 7) | \
  41. (((g)&0xF8) << 2) | \
  42. (((b)&0xF8) >> 3) )
  43. #define PIXEL_BGR555(r,g,b) ( (((b)&0xF8) << 7) | \
  44. (((g)&0xF8) << 2) | \
  45. (((r)&0xF8) >> 3) )
  46. #define PIXEL_ARGB2554(a,r,g,b)( (((a)&0xC0) << 8) | \
  47. (((r)&0xF8) << 6) | \
  48. (((g)&0xF8) << 1) | \
  49. (((b)&0xF0) >> 4) )
  50. #define PIXEL_ARGB4444(a,r,g,b)( (((a)&0xF0) << 8) | \
  51. (((r)&0xF0) << 4) | \
  52. (((g)&0xF0) ) | \
  53. (((b)&0xF0) >> 4) )
  54. #define PIXEL_RGBA4444(a,r,g,b)( (((r)&0xF0) << 8) | \
  55. (((g)&0xF0) << 4) | \
  56. (((b)&0xF0) ) | \
  57. (((a)&0xF0) >> 4) )
  58. #define PIXEL_RGB444(r,g,b) ( (((r)&0xF0) << 4) | \
  59. (((g)&0xF0) ) | \
  60. (((b)&0xF0) >> 4) )
  61. #define PIXEL_RGB16(r,g,b) ( (((r)&0xF8) << 8) | \
  62. (((g)&0xFC) << 3) | \
  63. (((b)&0xF8) >> 3) )
  64. #define PIXEL_RGB18(r,g,b) ( (((r)&0xFC) << 10) | \
  65. (((g)&0xFC) << 4) | \
  66. (((b)&0xFC) >> 2) )
  67. #define PIXEL_RGB32(r,g,b) ( (0xff << 24) | \
  68. ((r) << 16) | \
  69. ((g) << 8) | \
  70. (b) )
  71. #define PIXEL_ARGB(a,r,g,b) ( ((a) << 24) | \
  72. ((r) << 16) | \
  73. ((g) << 8) | \
  74. (b) )
  75. #define PIXEL_ARGB8565(a,r,g,b)( ((a) << 16) | \
  76. PIXEL_RGB16 (r, g, b) )
  77. #define PIXEL_ARGB1666(a,r,g,b) ( (((a)&0x80) << 11) | \
  78. (((r)&0xFC) << 10) | \
  79. (((g)&0xFC) << 4) | \
  80. (((b)&0xFC) >> 2) )
  81. #define PIXEL_ARGB6666(a,r,g,b) ( (((a)&0xFC) << 16) | \
  82. (((r)&0xFC) << 10) | \
  83. (((g)&0xFC) << 4) | \
  84. (((b)&0xFC) >> 2) )
  85. #define PIXEL_AYUV(a,y,u,v) ( ((a) << 24) | \
  86. ((y) << 16) | \
  87. ((u) << 8) | \
  88. (v) )
  89. #define PIXEL_AVYU(a,y,u,v) ( ((a) << 24) | \
  90. ((v) << 16) | \
  91. ((y) << 8) | \
  92. (u) )
  93. #define PIXEL_AiRGB(a,r,g,b) ( (((a) ^ 0xff) << 24) | \
  94. ((r) << 16) | \
  95. ((g) << 8) | \
  96. (b) )
  97. #ifdef WORDS_BIGENDIAN
  98. #define PIXEL_YUY2(y,u,v) ( ((u) << 24) | \
  99. ((y) << 16) | \
  100. ((v) << 8) | \
  101. (y) )
  102. #define PIXEL_UYVY(y,u,v) ( ((y) << 24) | \
  103. ((u) << 16) | \
  104. ((y) << 8) | \
  105. (v) )
  106. #else /* little endian */
  107. #define PIXEL_YUY2(y,u,v) ( ((v) << 24) | \
  108. ((y) << 16) | \
  109. ((u) << 8) | \
  110. (y) )
  111. #define PIXEL_UYVY(y,u,v) ( ((y) << 24) | \
  112. ((v) << 16) | \
  113. ((y) << 8) | \
  114. (u) )
  115. #endif
  116. #define PIXEL_VYU(y,u,v) ( ((v) << 16) | \
  117. ((y) << 8) | \
  118. (u) )
  119. /* packed pixel conversions */
  120. #define ARGB1555_TO_RGB332(pixel) ( (((pixel) & 0x7000) >> 7) | \
  121. (((pixel) & 0x0380) >> 5) | \
  122. (((pixel) & 0x0018) >> 3) )
  123. #define ARGB1555_TO_ARGB2554(pixel) ( (((pixel) & 0x8000) ) | \
  124. (((pixel) & 0x7FFF) >> 1) )
  125. #define ARGB1555_TO_ARGB4444(pixel) ( (((pixel) & 0x8000) ? 0xf000 : 0 ) | \
  126. (((pixel) & 0x7800) >> 3) | \
  127. (((pixel) & 0x03C0) >> 2) | \
  128. (((pixel) & 0x0018) >> 1) )
  129. #define ARGB1555_TO_RGBA4444(pixel) ( (((pixel) & 0x8000) ? 0x000f : 0 ) | \
  130. (((pixel) & 0x7800) << 1) | \
  131. (((pixel) & 0x03C0) << 2) | \
  132. (((pixel) & 0x0018) << 3) )
  133. #define ARGB1555_TO_RGB16(pixel) ( (((pixel) & 0x7C00) << 1) | \
  134. (((pixel) & 0x03E0) << 1) | \
  135. (((pixel) & 0x001F)) )
  136. #define ARGB1555_TO_ARGB8565(pixel) ( (((pixel) & 0x8000) ? 0x00FF0000 : 0) | \
  137. ARGB1555_TO_RGB16 (pixel) )
  138. #define ARGB1555_TO_RGB32(pixel) ( (((pixel) & 0x7C00) << 9) | \
  139. (((pixel) & 0x03E0) << 6) | \
  140. (((pixel) & 0x001F) << 3) )
  141. #define ARGB1555_TO_ARGB(pixel) ( (((pixel) & 0x8000) ? 0xFF000000 : 0) | \
  142. (((pixel) & 0x7C00) << 9) | \
  143. (((pixel) & 0x03E0) << 6) | \
  144. (((pixel) & 0x001F) << 3) )
  145. #define ARGB1555_TO_RGB555(pixel) ( (((pixel) & 0x7C00) << 9) | \
  146. (((pixel) & 0x03E0) << 6) | \
  147. (((pixel) & 0x001F) << 3) )
  148. #define ARGB1555_TO_RGB444(pixel) ( (((pixel) & 0x7800) >> 3) | \
  149. (((pixel) & 0x03C0) >> 2) | \
  150. (((pixel) & 0x001E) >> 1) )
  151. /* xRGB to xxRRGGBB, so xRxx left 3, xRGx left 2, xxGB left 1, xxxB */
  152. #define ARGB4444_TO_RGB32(pixel) ( (((pixel) & 0x0F00) << 12) | \
  153. (((pixel) & 0x0FF0) << 8) | \
  154. (((pixel) & 0x00FF) << 4) | \
  155. (((pixel) & 0x000F) ) )
  156. /* RGBx to xxRRGGBB, so Rxxx left 2, RGxx left 1, xGBx, xxBx right 1 */
  157. #define RGBA4444_TO_RGB32(pixel) ( (((pixel) & 0xF000) << 8) | \
  158. (((pixel) & 0xFF00) << 4) | \
  159. (((pixel) & 0x0FF0) ) | \
  160. (((pixel) & 0x00F0) >> 4) )
  161. /* ARGB to AARRGGBB, so Axxx left 4, ARxx left 3, xRGx left 2, xxGB left 1, xxxB */
  162. #define ARGB4444_TO_ARGB(pixel) ( (((pixel) & 0xF000) << 16) | \
  163. (((pixel) & 0xFF00) << 12) | \
  164. (((pixel) & 0x0FF0) << 8) | \
  165. (((pixel) & 0x00FF) << 4) | \
  166. (((pixel) & 0x000F) ) )
  167. /* RGBA to AARRGGBB, so Rxxx left 2, RGxx left 1, xGBx, xxBx right 1, A to the left */
  168. #define RGBA4444_TO_ARGB(pixel) ( (((pixel) & 0x000F) << 28) | \
  169. (((pixel) & 0x000F) << 24) | \
  170. (((pixel) & 0xF000) << 8) | \
  171. (((pixel) & 0xFF00) << 4) | \
  172. (((pixel) & 0x0FF0) ) | \
  173. (((pixel) & 0x00F0) >> 4) )
  174. #define RGB16_TO_RGB332(pixel) ( (((pixel) & 0xE000) >> 8) | \
  175. (((pixel) & 0x0700) >> 6) | \
  176. (((pixel) & 0x0018) >> 3) )
  177. #define RGB16_TO_ARGB1555(pixel) ( 0x8000 | \
  178. (((pixel) & 0xF800) >> 1) | \
  179. (((pixel) & 0x07C0) >> 1) | \
  180. (((pixel) & 0x001F)) )
  181. #define RGB16_TO_ARGB2554(pixel) ( 0xC000 | \
  182. (((pixel) & 0xF800) >> 2) | \
  183. (((pixel) & 0x07C0) >> 2) | \
  184. (((pixel) & 0x001F) >> 1) )
  185. #define RGB16_TO_ARGB4444(pixel) ( 0xF000 | \
  186. (((pixel) & 0xF000) >> 4) | \
  187. (((pixel) & 0x0780) >> 3) | \
  188. (((pixel) & 0x001E) >> 1) )
  189. #define RGB16_TO_RGBA4444(pixel) ( 0x000F | \
  190. (((pixel) & 0xF000) ) | \
  191. (((pixel) & 0x0780) << 1) | \
  192. (((pixel) & 0x001E) << 3) )
  193. #define RGB16_TO_ARGB8565(pixel) ( 0xFF0000 | \
  194. ((pixel) & 0xffff) )
  195. #define RGB16_TO_RGB32(pixel) ( (((pixel) & 0xF800) << 8) | \
  196. (((pixel) & 0x07E0) << 5) | \
  197. (((pixel) & 0x001F) << 3) )
  198. #define RGB16_TO_ARGB(pixel) ( 0xFF000000 | \
  199. (((pixel) & 0xF800) << 8) | \
  200. (((pixel) & 0x07E0) << 5) | \
  201. (((pixel) & 0x001F) << 3) )
  202. #define RGB16_TO_RGB555(pixel) ( (((pixel) & 0xF800) >> 1) | \
  203. (((pixel) & 0x07C0) >> 1) | \
  204. (((pixel) & 0x001F)) )
  205. #define RGB16_TO_BGR555(pixel) ( (((pixel) & 0xF800) >> 12) | \
  206. (((pixel) & 0x07C0) >> 1) | \
  207. (((pixel) & 0x001F) << 10 ) )
  208. #define RGB16_TO_RGB444(pixel) ( (((pixel) & 0xF000) >> 4) | \
  209. (((pixel) & 0x0780) >> 3) | \
  210. (((pixel) & 0x001F) >> 1) )
  211. #define ARGB8565_TO_RGB332(pixel) ( RGB16_TO_RGB332 (pixel) )
  212. #define ARGB8565_TO_ARGB1555(pixel) ( (((pixel) & 0x800000) >> 16) | \
  213. (((pixel) & 0x00F800) >> 1) | \
  214. (((pixel) & 0x0007C0) >> 1) | \
  215. (((pixel) & 0x00001F)) )
  216. #define ARGB8565_TO_ARGB2554(pixel) ( (((pixel) & 0xC00000) >> 16) | \
  217. (((pixel) & 0x00F800) >> 2) | \
  218. (((pixel) & 0x0007C0) >> 2) | \
  219. (((pixel) & 0x00001F) >> 1) )
  220. #define ARGB8565_TO_ARGB4444(pixel) ( (((pixel) & 0xF00000) >> 16) | \
  221. (((pixel) & 0x00F000) >> 4) | \
  222. (((pixel) & 0x000780) >> 3) | \
  223. (((pixel) & 0x00001F) >> 1) )
  224. #define ARGB8565_TO_RGB16(pixel) ( ((pixel) & 0xffff) )
  225. #define ARGB8565_TO_RGB32(pixel) ( RGB16_TO_RGB32 (pixel) )
  226. #define ARGB8565_TO_ARGB(pixel) ( (((pixel) & 0xFF0000) << 8) | \
  227. (((pixel) & 0x00F800) << 8) | \
  228. (((pixel) & 0x0007E0) << 5) | \
  229. (((pixel) & 0x00001F) << 3) )
  230. #define RGB18_TO_ARGB(pixel) ( 0xFF000000 | \
  231. (((pixel) & 0xFC00) << 10) | \
  232. (((pixel) & 0x3F00) << 4) | \
  233. (((pixel) & 0x00FC) << 2) )
  234. #define RGB32_TO_RGB332(pixel) ( (((pixel) & 0xE00000) >> 16) | \
  235. (((pixel) & 0x00E000) >> 11) | \
  236. (((pixel) & 0x0000C0) >> 6) )
  237. #define RGB32_TO_ARGB1555(pixel) ( 0x8000 | \
  238. (((pixel) & 0xF80000) >> 9) | \
  239. (((pixel) & 0x00F800) >> 6) | \
  240. (((pixel) & 0x0000F8) >> 3) )
  241. #define RGB32_TO_ARGB2554(pixel) ( 0xC000 | \
  242. (((pixel) & 0xF80000) >> 10) | \
  243. (((pixel) & 0x00F800) >> 7) | \
  244. (((pixel) & 0x0000F0) >> 4) )
  245. #define RGB32_TO_ARGB4444(pixel) ( 0xF000 | \
  246. (((pixel) & 0xF00000) >> 12) | \
  247. (((pixel) & 0x00F000) >> 8) | \
  248. (((pixel) & 0x0000F0) >> 4) )
  249. #define RGB32_TO_RGBA4444(pixel) ( 0x000F | \
  250. (((pixel) & 0xF00000) >> 8) | \
  251. (((pixel) & 0x00F000) >> 4) | \
  252. (((pixel) & 0x0000F0) ) )
  253. #define RGB32_TO_RGB16(pixel) ( (((pixel) & 0xF80000) >> 8) | \
  254. (((pixel) & 0x00FC00) >> 5) | \
  255. (((pixel) & 0x0000F8) >> 3) )
  256. #define RGB32_TO_ARGB8565(pixel) ( 0xff0000 | \
  257. RGB32_TO_RGB16 (pixel) )
  258. #define RGB32_TO_ARGB1555(pixel) ( 0x8000 | \
  259. (((pixel) & 0xF80000) >> 9) | \
  260. (((pixel) & 0x00F800) >> 6) | \
  261. (((pixel) & 0x0000F8) >> 3) )
  262. #define RGB32_TO_ARGB(pixel) ( 0xFF000000 | (pixel) )
  263. #define ARGB_TO_ARGB8565(pixel) ( (((pixel) & 0xFF000000) >> 8) | \
  264. (((pixel) & 0x00F80000) >> 8) | \
  265. (((pixel) & 0x0000FC00) >> 5) | \
  266. (((pixel) & 0x000000F8) >> 3) )
  267. #define RGB32_TO_RGB555(pixel) ( (((pixel) & 0xF80000) >> 9) | \
  268. (((pixel) & 0x00F800) >> 6) | \
  269. (((pixel) & 0x0000F8) >> 3) )
  270. #define RGB32_TO_BGR555(pixel) ( (((pixel) & 0xF80000) >> 19) | \
  271. (((pixel) & 0x00F800) >> 6) | \
  272. (((pixel) & 0x0000F8) << 7) )
  273. #define RGB32_TO_RGB444(pixel) ( (((pixel) & 0xF00000) >> 12) | \
  274. (((pixel) & 0x00F000) >> 8) | \
  275. (((pixel) & 0x0000F0) >> 4) )
  276. #define ARGB_TO_ARGB1555(pixel) ( (((pixel) & 0x80000000) >> 16) | \
  277. (((pixel) & 0x00F80000) >> 9) | \
  278. (((pixel) & 0x0000F800) >> 6) | \
  279. (((pixel) & 0x000000F8) >> 3) )
  280. #define ARGB_TO_RGBA5551(pixel) ( (((pixel) & 0x80000000) >> 31) | \
  281. (((pixel) & 0x00F80000) >> 8) | \
  282. (((pixel) & 0x0000F800) >> 5) | \
  283. (((pixel) & 0x000000F8) >> 2) )
  284. #define ARGB_TO_ARGB2554(pixel) ( (((pixel) & 0xC0000000) >> 16) | \
  285. (((pixel) & 0x00F80000) >> 10) | \
  286. (((pixel) & 0x0000F800) >> 7) | \
  287. (((pixel) & 0x000000F0) >> 4) )
  288. #define ARGB_TO_ARGB4444(pixel) ( (((pixel) & 0xF0000000) >> 16) | \
  289. (((pixel) & 0x00F00000) >> 12) | \
  290. (((pixel) & 0x0000F000) >> 8) | \
  291. (((pixel) & 0x000000F0) >> 4) )
  292. #define ARGB_TO_RGBA4444(pixel) ( (((pixel) & 0xF0000000) >> 28) | \
  293. (((pixel) & 0x00F00000) >> 8) | \
  294. (((pixel) & 0x0000F000) >> 4) | \
  295. (((pixel) & 0x000000F0) ) )
  296. #define ARGB_TO_RGB444(pixel) ( (((pixel) & 0x00F00000) >> 12) | \
  297. (((pixel) & 0x0000F000) >> 8) | \
  298. (((pixel) & 0x000000F0) >> 4) )
  299. #define ARGB_TO_RGB555(pixel) ( (((pixel) & 0x00F80000) >> 9) | \
  300. (((pixel) & 0x0000F800) >> 6) | \
  301. (((pixel) & 0x000000F8) >> 3) )
  302. #define ARGB_TO_BGR555(pixel) ( (((pixel) & 0x00F80000) >> 19) | \
  303. (((pixel) & 0x0000F800) >> 6) | \
  304. (((pixel) & 0x000000F8) << 7) )
  305. /* RGB <-> YCbCr conversion */
  306. #define YCBCR_TO_RGB( y, cb, cr, r, g, b ) \
  307. do { \
  308. int _y = (y) - 16; \
  309. int _cb = (cb) - 128; \
  310. int _cr = (cr) - 128; \
  311. \
  312. int _r = (298 * _y + 409 * _cr + 128) >> 8; \
  313. int _g = (298 * _y - 100 * _cb - 208 * _cr + 128) >> 8; \
  314. int _b = (298 * _y + 516 * _cb + 128) >> 8; \
  315. \
  316. (r) = CLAMP( _r, 0, 255 ); \
  317. (g) = CLAMP( _g, 0, 255 ); \
  318. (b) = CLAMP( _b, 0, 255 ); \
  319. } while (0)
  320. #define RGB_TO_YCBCR( r, g, b, y, cb, cr ) \
  321. do { \
  322. int _r = (r), _g = (g), _b = (b); \
  323. \
  324. (y) = ( 66 * _r + 129 * _g + 25 * _b + 16*256 + 128) >> 8; \
  325. (cb) = ( - 38 * _r - 74 * _g + 112 * _b + 128*256 + 128) >> 8; \
  326. (cr) = ( 112 * _r - 94 * _g - 18 * _b + 128*256 + 128) >> 8; \
  327. } while (0)
  328. DFBSurfacePixelFormat dfb_pixelformat_for_depth( int depth );
  329. void dfb_pixel_to_color ( DFBSurfacePixelFormat format,
  330. unsigned long pixel,
  331. DFBColor *ret_color );
  332. unsigned long dfb_pixel_from_color( DFBSurfacePixelFormat format,
  333. const DFBColor *color );
  334. static inline u32
  335. dfb_color_to_pixel( DFBSurfacePixelFormat format,
  336. u8 r, u8 g, u8 b )
  337. {
  338. const DFBColor color = { 0, r, g, b };
  339. return dfb_pixel_from_color( format, &color );
  340. }
  341. static inline u32
  342. dfb_color_to_argb( const DFBColor *color )
  343. {
  344. return (color->a << 24) | (color->r << 16) | (color->g << 8) | color->b;
  345. }
  346. static inline u32
  347. dfb_color_to_aycbcr( const DFBColor *color )
  348. {
  349. u32 y, cb, cr;
  350. RGB_TO_YCBCR( color->r, color->g, color->b, y, cb, cr );
  351. return (color->a << 24) | (y << 16) | (cb << 8) | cr;
  352. }
  353. static inline u32
  354. dfb_color_to_acrycb( const DFBColor *color )
  355. {
  356. u32 y, cb, cr;
  357. RGB_TO_YCBCR( color->r, color->g, color->b, y, cb, cr );
  358. return (color->a << 24) | (cr << 16) | (y << 8) | cb;
  359. }
  360. static inline void
  361. dfb_argb_to_rgb332( const u32 *src, u8 *dst, int len )
  362. {
  363. int i;
  364. for (i=0; i<len; i++) {
  365. register u32 argb = src[i];
  366. dst[i] = RGB32_TO_RGB332( argb );
  367. }
  368. }
  369. static inline void
  370. dfb_argb_to_argb1555( const u32 *src, u16 *dst, int len )
  371. {
  372. int i;
  373. for (i=0; i<len; i++) {
  374. register u32 argb = src[i];
  375. dst[i] = ARGB_TO_ARGB1555( argb );
  376. }
  377. }
  378. static inline void
  379. dfb_argb_to_rgba5551( const u32 *src, u16 *dst, int len )
  380. {
  381. int i;
  382. for (i=0; i<len; i++) {
  383. register u32 argb = src[i];
  384. dst[i] = ARGB_TO_RGBA5551( argb );
  385. }
  386. }
  387. static inline void
  388. dfb_argb_to_argb2554( const u32 *src, u16 *dst, int len )
  389. {
  390. int i;
  391. for (i=0; i<len; i++) {
  392. register u32 argb = src[i];
  393. dst[i] = ARGB_TO_ARGB2554( argb );
  394. }
  395. }
  396. static inline void
  397. dfb_argb_to_argb4444( const u32 *src, u16 *dst, int len )
  398. {
  399. int i;
  400. for (i=0; i<len; i++) {
  401. register u32 argb = src[i];
  402. dst[i] = ARGB_TO_ARGB4444( argb );
  403. }
  404. }
  405. static inline void
  406. dfb_argb_to_rgba4444( const u32 *src, u16 *dst, int len )
  407. {
  408. int i;
  409. for (i=0; i<len; i++) {
  410. register u32 rgba = src[i];
  411. dst[i] = ARGB_TO_RGBA4444( rgba );
  412. }
  413. }
  414. static inline void
  415. dfb_argb_to_argb8565( const u32 *src, u8 *dst, int len )
  416. {
  417. int i = -1, j = -1;
  418. while (++i < len) {
  419. register u32 argb = src[i];
  420. register u32 d = ARGB_TO_ARGB8565( argb );
  421. #ifdef WORDS_BIGENDIAN
  422. dst[++j] = (d >> 16) & 0xff;
  423. dst[++j] = (d >> 8) & 0xff;
  424. dst[++j] = (d >> 0) & 0xff;
  425. #else
  426. dst[++j] = (d >> 0) & 0xff;
  427. dst[++j] = (d >> 8) & 0xff;
  428. dst[++j] = (d >> 16) & 0xff;
  429. #endif
  430. }
  431. }
  432. static inline void
  433. dfb_argb_to_rgb16( const u32 *src, u16 *dst, int len )
  434. {
  435. int i;
  436. for (i=0; i<len; i++) {
  437. register u32 argb = src[i];
  438. dst[i] = RGB32_TO_RGB16( argb );
  439. }
  440. }
  441. static inline void
  442. dfb_argb_to_a8( const u32 *src, u8 *dst, int len )
  443. {
  444. int i;
  445. for (i=0; i<len; i++)
  446. dst[i] = src[i] >> 24;
  447. }
  448. void dfb_convert_to_rgb16( DFBSurfacePixelFormat format,
  449. const void *src,
  450. int spitch,
  451. int surface_height,
  452. u16 *dst,
  453. int dpitch,
  454. int width,
  455. int height );
  456. void dfb_convert_to_rgb555( DFBSurfacePixelFormat format,
  457. const void *src,
  458. int spitch,
  459. int surface_height,
  460. u16 *dst,
  461. int dpitch,
  462. int width,
  463. int height );
  464. void dfb_convert_to_argb( DFBSurfacePixelFormat format,
  465. const void *src,
  466. int spitch,
  467. int surface_height,
  468. u32 *dst,
  469. int dpitch,
  470. int width,
  471. int height );
  472. void dfb_convert_to_rgb32( DFBSurfacePixelFormat format,
  473. const void *src,
  474. int spitch,
  475. int surface_height,
  476. u32 *dst,
  477. int dpitch,
  478. int width,
  479. int height );
  480. void dfb_convert_to_rgb24( DFBSurfacePixelFormat format,
  481. const void *src,
  482. int spitch,
  483. int surface_height,
  484. u8 *dst,
  485. int dpitch,
  486. int width,
  487. int height );
  488. void dfb_convert_to_a8( DFBSurfacePixelFormat format,
  489. const void *src,
  490. int spitch,
  491. int surface_height,
  492. u8 *dst,
  493. int dpitch,
  494. int width,
  495. int height );
  496. void dfb_convert_to_a4( DFBSurfacePixelFormat format,
  497. const void *src,
  498. int spitch,
  499. int surface_height,
  500. u8 *dst,
  501. int dpitch,
  502. int width,
  503. int height );
  504. void dfb_convert_to_yuy2( DFBSurfacePixelFormat format,
  505. const void *src,
  506. int spitch,
  507. int surface_height,
  508. u32 *dst,
  509. int dpitch,
  510. int width,
  511. int height );
  512. void dfb_convert_to_uyvy( DFBSurfacePixelFormat format,
  513. const void *src,
  514. int spitch,
  515. int surface_height,
  516. u32 *dst,
  517. int dpitch,
  518. int width,
  519. int height );
  520. #endif