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.

552 lines
17KB

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