You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

548 lines
19KB

  1. /*
  2. * rgb2rgb.c, Software RGB to RGB convertor
  3. * pluralize by Software PAL8 to RGB convertor
  4. * Software YUV to YUV convertor
  5. * Software YUV to RGB convertor
  6. * Written by Nick Kurshev.
  7. * palette & YUV & runtime CPU stuff by Michael (michaelni@gmx.at)
  8. *
  9. * This file is part of FFmpeg.
  10. *
  11. * FFmpeg is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 2 of the License, or
  14. * (at your option) any later version.
  15. *
  16. * FFmpeg is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with FFmpeg; if not, write to the Free Software
  23. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  24. *
  25. * the C code (not assembly, mmx, ...) of this file can be used
  26. * under the LGPL license too
  27. */
  28. #include <inttypes.h>
  29. #include "config.h"
  30. #include "rgb2rgb.h"
  31. #include "swscale.h"
  32. #include "swscale_internal.h"
  33. #include "x86_cpu.h"
  34. #include "bswap.h"
  35. #define FAST_BGR2YV12 // use 7 bit coeffs instead of 15bit
  36. void (*rgb24to32)(const uint8_t *src,uint8_t *dst,long src_size);
  37. void (*rgb24to16)(const uint8_t *src,uint8_t *dst,long src_size);
  38. void (*rgb24to15)(const uint8_t *src,uint8_t *dst,long src_size);
  39. void (*rgb32to24)(const uint8_t *src,uint8_t *dst,long src_size);
  40. void (*rgb32to16)(const uint8_t *src,uint8_t *dst,long src_size);
  41. void (*rgb32to15)(const uint8_t *src,uint8_t *dst,long src_size);
  42. void (*rgb15to16)(const uint8_t *src,uint8_t *dst,long src_size);
  43. void (*rgb15to24)(const uint8_t *src,uint8_t *dst,long src_size);
  44. void (*rgb15to32)(const uint8_t *src,uint8_t *dst,long src_size);
  45. void (*rgb16to15)(const uint8_t *src,uint8_t *dst,long src_size);
  46. void (*rgb16to24)(const uint8_t *src,uint8_t *dst,long src_size);
  47. void (*rgb16to32)(const uint8_t *src,uint8_t *dst,long src_size);
  48. //void (*rgb24tobgr32)(const uint8_t *src, uint8_t *dst, long src_size);
  49. void (*rgb24tobgr24)(const uint8_t *src, uint8_t *dst, long src_size);
  50. void (*rgb24tobgr16)(const uint8_t *src, uint8_t *dst, long src_size);
  51. void (*rgb24tobgr15)(const uint8_t *src, uint8_t *dst, long src_size);
  52. void (*rgb32tobgr32)(const uint8_t *src, uint8_t *dst, long src_size);
  53. //void (*rgb32tobgr24)(const uint8_t *src, uint8_t *dst, long src_size);
  54. void (*rgb32tobgr16)(const uint8_t *src, uint8_t *dst, long src_size);
  55. void (*rgb32tobgr15)(const uint8_t *src, uint8_t *dst, long src_size);
  56. void (*yv12toyuy2)(const uint8_t *ysrc, const uint8_t *usrc, const uint8_t *vsrc, uint8_t *dst,
  57. long width, long height,
  58. long lumStride, long chromStride, long dstStride);
  59. void (*yv12touyvy)(const uint8_t *ysrc, const uint8_t *usrc, const uint8_t *vsrc, uint8_t *dst,
  60. long width, long height,
  61. long lumStride, long chromStride, long dstStride);
  62. void (*yuv422ptoyuy2)(const uint8_t *ysrc, const uint8_t *usrc, const uint8_t *vsrc, uint8_t *dst,
  63. long width, long height,
  64. long lumStride, long chromStride, long dstStride);
  65. void (*yuy2toyv12)(const uint8_t *src, uint8_t *ydst, uint8_t *udst, uint8_t *vdst,
  66. long width, long height,
  67. long lumStride, long chromStride, long srcStride);
  68. void (*rgb24toyv12)(const uint8_t *src, uint8_t *ydst, uint8_t *udst, uint8_t *vdst,
  69. long width, long height,
  70. long lumStride, long chromStride, long srcStride);
  71. void (*planar2x)(const uint8_t *src, uint8_t *dst, long width, long height,
  72. long srcStride, long dstStride);
  73. void (*interleaveBytes)(uint8_t *src1, uint8_t *src2, uint8_t *dst,
  74. long width, long height, long src1Stride,
  75. long src2Stride, long dstStride);
  76. void (*vu9_to_vu12)(const uint8_t *src1, const uint8_t *src2,
  77. uint8_t *dst1, uint8_t *dst2,
  78. long width, long height,
  79. long srcStride1, long srcStride2,
  80. long dstStride1, long dstStride2);
  81. void (*yvu9_to_yuy2)(const uint8_t *src1, const uint8_t *src2, const uint8_t *src3,
  82. uint8_t *dst,
  83. long width, long height,
  84. long srcStride1, long srcStride2,
  85. long srcStride3, long dstStride);
  86. #if defined(ARCH_X86) && defined(CONFIG_GPL)
  87. static const uint64_t mmx_null __attribute__((aligned(8))) = 0x0000000000000000ULL;
  88. static const uint64_t mmx_one __attribute__((aligned(8))) = 0xFFFFFFFFFFFFFFFFULL;
  89. static const uint64_t mask32b attribute_used __attribute__((aligned(8))) = 0x000000FF000000FFULL;
  90. static const uint64_t mask32g attribute_used __attribute__((aligned(8))) = 0x0000FF000000FF00ULL;
  91. static const uint64_t mask32r attribute_used __attribute__((aligned(8))) = 0x00FF000000FF0000ULL;
  92. static const uint64_t mask32 __attribute__((aligned(8))) = 0x00FFFFFF00FFFFFFULL;
  93. static const uint64_t mask3216br __attribute__((aligned(8))) = 0x00F800F800F800F8ULL;
  94. static const uint64_t mask3216g __attribute__((aligned(8))) = 0x0000FC000000FC00ULL;
  95. static const uint64_t mask3215g __attribute__((aligned(8))) = 0x0000F8000000F800ULL;
  96. static const uint64_t mul3216 __attribute__((aligned(8))) = 0x2000000420000004ULL;
  97. static const uint64_t mul3215 __attribute__((aligned(8))) = 0x2000000820000008ULL;
  98. static const uint64_t mask24b attribute_used __attribute__((aligned(8))) = 0x00FF0000FF0000FFULL;
  99. static const uint64_t mask24g attribute_used __attribute__((aligned(8))) = 0xFF0000FF0000FF00ULL;
  100. static const uint64_t mask24r attribute_used __attribute__((aligned(8))) = 0x0000FF0000FF0000ULL;
  101. static const uint64_t mask24l __attribute__((aligned(8))) = 0x0000000000FFFFFFULL;
  102. static const uint64_t mask24h __attribute__((aligned(8))) = 0x0000FFFFFF000000ULL;
  103. static const uint64_t mask24hh __attribute__((aligned(8))) = 0xffff000000000000ULL;
  104. static const uint64_t mask24hhh __attribute__((aligned(8))) = 0xffffffff00000000ULL;
  105. static const uint64_t mask24hhhh __attribute__((aligned(8))) = 0xffffffffffff0000ULL;
  106. static const uint64_t mask15b __attribute__((aligned(8))) = 0x001F001F001F001FULL; /* 00000000 00011111 xxB */
  107. static const uint64_t mask15rg __attribute__((aligned(8))) = 0x7FE07FE07FE07FE0ULL; /* 01111111 11100000 RGx */
  108. static const uint64_t mask15s __attribute__((aligned(8))) = 0xFFE0FFE0FFE0FFE0ULL;
  109. static const uint64_t mask15g __attribute__((aligned(8))) = 0x03E003E003E003E0ULL;
  110. static const uint64_t mask15r __attribute__((aligned(8))) = 0x7C007C007C007C00ULL;
  111. #define mask16b mask15b
  112. static const uint64_t mask16g __attribute__((aligned(8))) = 0x07E007E007E007E0ULL;
  113. static const uint64_t mask16r __attribute__((aligned(8))) = 0xF800F800F800F800ULL;
  114. static const uint64_t red_16mask __attribute__((aligned(8))) = 0x0000f8000000f800ULL;
  115. static const uint64_t green_16mask __attribute__((aligned(8))) = 0x000007e0000007e0ULL;
  116. static const uint64_t blue_16mask __attribute__((aligned(8))) = 0x0000001f0000001fULL;
  117. static const uint64_t red_15mask __attribute__((aligned(8))) = 0x00007c0000007c00ULL;
  118. static const uint64_t green_15mask __attribute__((aligned(8))) = 0x000003e0000003e0ULL;
  119. static const uint64_t blue_15mask __attribute__((aligned(8))) = 0x0000001f0000001fULL;
  120. #ifdef FAST_BGR2YV12
  121. static const uint64_t bgr2YCoeff attribute_used __attribute__((aligned(8))) = 0x000000210041000DULL;
  122. static const uint64_t bgr2UCoeff attribute_used __attribute__((aligned(8))) = 0x0000FFEEFFDC0038ULL;
  123. static const uint64_t bgr2VCoeff attribute_used __attribute__((aligned(8))) = 0x00000038FFD2FFF8ULL;
  124. #else
  125. static const uint64_t bgr2YCoeff attribute_used __attribute__((aligned(8))) = 0x000020E540830C8BULL;
  126. static const uint64_t bgr2UCoeff attribute_used __attribute__((aligned(8))) = 0x0000ED0FDAC23831ULL;
  127. static const uint64_t bgr2VCoeff attribute_used __attribute__((aligned(8))) = 0x00003831D0E6F6EAULL;
  128. #endif
  129. static const uint64_t bgr2YOffset attribute_used __attribute__((aligned(8))) = 0x1010101010101010ULL;
  130. static const uint64_t bgr2UVOffset attribute_used __attribute__((aligned(8))) = 0x8080808080808080ULL;
  131. static const uint64_t w1111 attribute_used __attribute__((aligned(8))) = 0x0001000100010001ULL;
  132. #if 0
  133. static volatile uint64_t __attribute__((aligned(8))) b5Dither;
  134. static volatile uint64_t __attribute__((aligned(8))) g5Dither;
  135. static volatile uint64_t __attribute__((aligned(8))) g6Dither;
  136. static volatile uint64_t __attribute__((aligned(8))) r5Dither;
  137. static uint64_t __attribute__((aligned(8))) dither4[2]={
  138. 0x0103010301030103LL,
  139. 0x0200020002000200LL,};
  140. static uint64_t __attribute__((aligned(8))) dither8[2]={
  141. 0x0602060206020602LL,
  142. 0x0004000400040004LL,};
  143. #endif
  144. #endif /* defined(ARCH_X86) */
  145. #define RGB2YUV_SHIFT 8
  146. #define BY ((int)( 0.098*(1<<RGB2YUV_SHIFT)+0.5))
  147. #define BV ((int)(-0.071*(1<<RGB2YUV_SHIFT)+0.5))
  148. #define BU ((int)( 0.439*(1<<RGB2YUV_SHIFT)+0.5))
  149. #define GY ((int)( 0.504*(1<<RGB2YUV_SHIFT)+0.5))
  150. #define GV ((int)(-0.368*(1<<RGB2YUV_SHIFT)+0.5))
  151. #define GU ((int)(-0.291*(1<<RGB2YUV_SHIFT)+0.5))
  152. #define RY ((int)( 0.257*(1<<RGB2YUV_SHIFT)+0.5))
  153. #define RV ((int)( 0.439*(1<<RGB2YUV_SHIFT)+0.5))
  154. #define RU ((int)(-0.148*(1<<RGB2YUV_SHIFT)+0.5))
  155. //Note: we have C, MMX, MMX2, 3DNOW version therse no 3DNOW+MMX2 one
  156. //Plain C versions
  157. #undef HAVE_MMX
  158. #undef HAVE_MMX2
  159. #undef HAVE_3DNOW
  160. #undef HAVE_SSE2
  161. #define RENAME(a) a ## _C
  162. #include "rgb2rgb_template.c"
  163. #if defined(ARCH_X86) && defined(CONFIG_GPL)
  164. //MMX versions
  165. #undef RENAME
  166. #define HAVE_MMX
  167. #undef HAVE_MMX2
  168. #undef HAVE_3DNOW
  169. #undef HAVE_SSE2
  170. #define RENAME(a) a ## _MMX
  171. #include "rgb2rgb_template.c"
  172. //MMX2 versions
  173. #undef RENAME
  174. #define HAVE_MMX
  175. #define HAVE_MMX2
  176. #undef HAVE_3DNOW
  177. #undef HAVE_SSE2
  178. #define RENAME(a) a ## _MMX2
  179. #include "rgb2rgb_template.c"
  180. //3DNOW versions
  181. #undef RENAME
  182. #define HAVE_MMX
  183. #undef HAVE_MMX2
  184. #define HAVE_3DNOW
  185. #undef HAVE_SSE2
  186. #define RENAME(a) a ## _3DNOW
  187. #include "rgb2rgb_template.c"
  188. #endif //ARCH_X86 || ARCH_X86_64
  189. /*
  190. rgb15->rgb16 Original by Strepto/Astral
  191. ported to gcc & bugfixed : A'rpi
  192. MMX2, 3DNOW optimization by Nick Kurshev
  193. 32bit c version, and and&add trick by Michael Niedermayer
  194. */
  195. void sws_rgb2rgb_init(int flags){
  196. #if (defined(HAVE_MMX2) || defined(HAVE_3DNOW) || defined(HAVE_MMX)) && defined(CONFIG_GPL)
  197. if (flags & SWS_CPU_CAPS_MMX2)
  198. rgb2rgb_init_MMX2();
  199. else if (flags & SWS_CPU_CAPS_3DNOW)
  200. rgb2rgb_init_3DNOW();
  201. else if (flags & SWS_CPU_CAPS_MMX)
  202. rgb2rgb_init_MMX();
  203. else
  204. #endif /* defined(HAVE_MMX2) || defined(HAVE_3DNOW) || defined(HAVE_MMX) */
  205. rgb2rgb_init_C();
  206. }
  207. /**
  208. * Palette is assumed to contain BGR32.
  209. */
  210. void palette8torgb32(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette)
  211. {
  212. long i;
  213. /*
  214. for (i=0; i<num_pixels; i++)
  215. ((unsigned *)dst)[i] = ((unsigned *)palette)[ src[i] ];
  216. */
  217. for (i=0; i<num_pixels; i++)
  218. {
  219. #ifdef WORDS_BIGENDIAN
  220. dst[3]= palette[ src[i]*4+2 ];
  221. dst[2]= palette[ src[i]*4+1 ];
  222. dst[1]= palette[ src[i]*4+0 ];
  223. #else
  224. //FIXME slow?
  225. dst[0]= palette[ src[i]*4+2 ];
  226. dst[1]= palette[ src[i]*4+1 ];
  227. dst[2]= palette[ src[i]*4+0 ];
  228. //dst[3]= 0; /* do we need this cleansing? */
  229. #endif
  230. dst+= 4;
  231. }
  232. }
  233. void palette8tobgr32(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette)
  234. {
  235. long i;
  236. for (i=0; i<num_pixels; i++)
  237. {
  238. #ifdef WORDS_BIGENDIAN
  239. dst[3]= palette[ src[i]*4+0 ];
  240. dst[2]= palette[ src[i]*4+1 ];
  241. dst[1]= palette[ src[i]*4+2 ];
  242. #else
  243. //FIXME slow?
  244. dst[0]= palette[ src[i]*4+0 ];
  245. dst[1]= palette[ src[i]*4+1 ];
  246. dst[2]= palette[ src[i]*4+2 ];
  247. //dst[3]= 0; /* do we need this cleansing? */
  248. #endif
  249. dst+= 4;
  250. }
  251. }
  252. /**
  253. * Palette is assumed to contain BGR32.
  254. */
  255. void palette8torgb24(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette)
  256. {
  257. long i;
  258. /*
  259. writes 1 byte o much and might cause alignment issues on some architectures?
  260. for (i=0; i<num_pixels; i++)
  261. ((unsigned *)(&dst[i*3])) = ((unsigned *)palette)[ src[i] ];
  262. */
  263. for (i=0; i<num_pixels; i++)
  264. {
  265. //FIXME slow?
  266. dst[0]= palette[ src[i]*4+2 ];
  267. dst[1]= palette[ src[i]*4+1 ];
  268. dst[2]= palette[ src[i]*4+0 ];
  269. dst+= 3;
  270. }
  271. }
  272. void palette8tobgr24(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette)
  273. {
  274. long i;
  275. /*
  276. writes 1 byte o much and might cause alignment issues on some architectures?
  277. for (i=0; i<num_pixels; i++)
  278. ((unsigned *)(&dst[i*3])) = ((unsigned *)palette)[ src[i] ];
  279. */
  280. for (i=0; i<num_pixels; i++)
  281. {
  282. //FIXME slow?
  283. dst[0]= palette[ src[i]*4+0 ];
  284. dst[1]= palette[ src[i]*4+1 ];
  285. dst[2]= palette[ src[i]*4+2 ];
  286. dst+= 3;
  287. }
  288. }
  289. /**
  290. * Palette is assumed to contain bgr16, see rgb32to16 to convert the palette
  291. */
  292. void palette8torgb16(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette)
  293. {
  294. long i;
  295. for (i=0; i<num_pixels; i++)
  296. ((uint16_t *)dst)[i] = ((uint16_t *)palette)[ src[i] ];
  297. }
  298. void palette8tobgr16(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette)
  299. {
  300. long i;
  301. for (i=0; i<num_pixels; i++)
  302. ((uint16_t *)dst)[i] = bswap_16(((uint16_t *)palette)[ src[i] ]);
  303. }
  304. /**
  305. * Palette is assumed to contain BGR15, see rgb32to15 to convert the palette.
  306. */
  307. void palette8torgb15(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette)
  308. {
  309. long i;
  310. for (i=0; i<num_pixels; i++)
  311. ((uint16_t *)dst)[i] = ((uint16_t *)palette)[ src[i] ];
  312. }
  313. void palette8tobgr15(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette)
  314. {
  315. long i;
  316. for (i=0; i<num_pixels; i++)
  317. ((uint16_t *)dst)[i] = bswap_16(((uint16_t *)palette)[ src[i] ]);
  318. }
  319. void rgb32tobgr24(const uint8_t *src, uint8_t *dst, long src_size)
  320. {
  321. long i;
  322. long num_pixels = src_size >> 2;
  323. for (i=0; i<num_pixels; i++)
  324. {
  325. #ifdef WORDS_BIGENDIAN
  326. /* RGB32 (= A,B,G,R) -> BGR24 (= B,G,R) */
  327. dst[3*i + 0] = src[4*i + 1];
  328. dst[3*i + 1] = src[4*i + 2];
  329. dst[3*i + 2] = src[4*i + 3];
  330. #else
  331. dst[3*i + 0] = src[4*i + 2];
  332. dst[3*i + 1] = src[4*i + 1];
  333. dst[3*i + 2] = src[4*i + 0];
  334. #endif
  335. }
  336. }
  337. void rgb24tobgr32(const uint8_t *src, uint8_t *dst, long src_size)
  338. {
  339. long i;
  340. for (i=0; 3*i<src_size; i++)
  341. {
  342. #ifdef WORDS_BIGENDIAN
  343. /* RGB24 (= R,G,B) -> BGR32 (= A,R,G,B) */
  344. dst[4*i + 0] = 0;
  345. dst[4*i + 1] = src[3*i + 0];
  346. dst[4*i + 2] = src[3*i + 1];
  347. dst[4*i + 3] = src[3*i + 2];
  348. #else
  349. dst[4*i + 0] = src[3*i + 2];
  350. dst[4*i + 1] = src[3*i + 1];
  351. dst[4*i + 2] = src[3*i + 0];
  352. dst[4*i + 3] = 0;
  353. #endif
  354. }
  355. }
  356. void rgb16tobgr32(const uint8_t *src, uint8_t *dst, long src_size)
  357. {
  358. const uint16_t *end;
  359. uint8_t *d = (uint8_t *)dst;
  360. const uint16_t *s = (uint16_t *)src;
  361. end = s + src_size/2;
  362. while (s < end)
  363. {
  364. register uint16_t bgr;
  365. bgr = *s++;
  366. #ifdef WORDS_BIGENDIAN
  367. *d++ = 0;
  368. *d++ = (bgr&0x1F)<<3;
  369. *d++ = (bgr&0x7E0)>>3;
  370. *d++ = (bgr&0xF800)>>8;
  371. #else
  372. *d++ = (bgr&0xF800)>>8;
  373. *d++ = (bgr&0x7E0)>>3;
  374. *d++ = (bgr&0x1F)<<3;
  375. *d++ = 0;
  376. #endif
  377. }
  378. }
  379. void rgb16tobgr24(const uint8_t *src, uint8_t *dst, long src_size)
  380. {
  381. const uint16_t *end;
  382. uint8_t *d = (uint8_t *)dst;
  383. const uint16_t *s = (const uint16_t *)src;
  384. end = s + src_size/2;
  385. while (s < end)
  386. {
  387. register uint16_t bgr;
  388. bgr = *s++;
  389. *d++ = (bgr&0xF800)>>8;
  390. *d++ = (bgr&0x7E0)>>3;
  391. *d++ = (bgr&0x1F)<<3;
  392. }
  393. }
  394. void rgb16tobgr16(const uint8_t *src, uint8_t *dst, long src_size)
  395. {
  396. long i;
  397. long num_pixels = src_size >> 1;
  398. for (i=0; i<num_pixels; i++)
  399. {
  400. unsigned b,g,r;
  401. register uint16_t rgb;
  402. rgb = src[2*i];
  403. r = rgb&0x1F;
  404. g = (rgb&0x7E0)>>5;
  405. b = (rgb&0xF800)>>11;
  406. dst[2*i] = (b&0x1F) | ((g&0x3F)<<5) | ((r&0x1F)<<11);
  407. }
  408. }
  409. void rgb16tobgr15(const uint8_t *src, uint8_t *dst, long src_size)
  410. {
  411. long i;
  412. long num_pixels = src_size >> 1;
  413. for (i=0; i<num_pixels; i++)
  414. {
  415. unsigned b,g,r;
  416. register uint16_t rgb;
  417. rgb = src[2*i];
  418. r = rgb&0x1F;
  419. g = (rgb&0x7E0)>>5;
  420. b = (rgb&0xF800)>>11;
  421. dst[2*i] = (b&0x1F) | ((g&0x1F)<<5) | ((r&0x1F)<<10);
  422. }
  423. }
  424. void rgb15tobgr32(const uint8_t *src, uint8_t *dst, long src_size)
  425. {
  426. const uint16_t *end;
  427. uint8_t *d = (uint8_t *)dst;
  428. const uint16_t *s = (const uint16_t *)src;
  429. end = s + src_size/2;
  430. while (s < end)
  431. {
  432. register uint16_t bgr;
  433. bgr = *s++;
  434. #ifdef WORDS_BIGENDIAN
  435. *d++ = 0;
  436. *d++ = (bgr&0x1F)<<3;
  437. *d++ = (bgr&0x3E0)>>2;
  438. *d++ = (bgr&0x7C00)>>7;
  439. #else
  440. *d++ = (bgr&0x7C00)>>7;
  441. *d++ = (bgr&0x3E0)>>2;
  442. *d++ = (bgr&0x1F)<<3;
  443. *d++ = 0;
  444. #endif
  445. }
  446. }
  447. void rgb15tobgr24(const uint8_t *src, uint8_t *dst, long src_size)
  448. {
  449. const uint16_t *end;
  450. uint8_t *d = (uint8_t *)dst;
  451. const uint16_t *s = (uint16_t *)src;
  452. end = s + src_size/2;
  453. while (s < end)
  454. {
  455. register uint16_t bgr;
  456. bgr = *s++;
  457. *d++ = (bgr&0x7C00)>>7;
  458. *d++ = (bgr&0x3E0)>>2;
  459. *d++ = (bgr&0x1F)<<3;
  460. }
  461. }
  462. void rgb15tobgr16(const uint8_t *src, uint8_t *dst, long src_size)
  463. {
  464. long i;
  465. long num_pixels = src_size >> 1;
  466. for (i=0; i<num_pixels; i++)
  467. {
  468. unsigned b,g,r;
  469. register uint16_t rgb;
  470. rgb = src[2*i];
  471. r = rgb&0x1F;
  472. g = (rgb&0x3E0)>>5;
  473. b = (rgb&0x7C00)>>10;
  474. dst[2*i] = (b&0x1F) | ((g&0x3F)<<5) | ((r&0x1F)<<11);
  475. }
  476. }
  477. void rgb15tobgr15(const uint8_t *src, uint8_t *dst, long src_size)
  478. {
  479. long i;
  480. long num_pixels = src_size >> 1;
  481. for (i=0; i<num_pixels; i++)
  482. {
  483. unsigned b,g,r;
  484. register uint16_t rgb;
  485. rgb = src[2*i];
  486. r = rgb&0x1F;
  487. g = (rgb&0x3E0)>>5;
  488. b = (rgb&0x7C00)>>10;
  489. dst[2*i] = (b&0x1F) | ((g&0x1F)<<5) | ((r&0x1F)<<10);
  490. }
  491. }
  492. void rgb8tobgr8(const uint8_t *src, uint8_t *dst, long src_size)
  493. {
  494. long i;
  495. long num_pixels = src_size;
  496. for (i=0; i<num_pixels; i++)
  497. {
  498. unsigned b,g,r;
  499. register uint8_t rgb;
  500. rgb = src[i];
  501. r = (rgb&0x07);
  502. g = (rgb&0x38)>>3;
  503. b = (rgb&0xC0)>>6;
  504. dst[i] = ((b<<1)&0x07) | ((g&0x07)<<3) | ((r&0x03)<<6);
  505. }
  506. }