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.

520 lines
17KB

  1. /*
  2. * software RGB to RGB converter
  3. * pluralize by software PAL8 to RGB converter
  4. * software YUV to YUV converter
  5. * software YUV to RGB converter
  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.
  27. */
  28. #include <inttypes.h>
  29. #include "config.h"
  30. #include "libavutil/x86_cpu.h"
  31. #include "libavutil/bswap.h"
  32. #include "rgb2rgb.h"
  33. #include "swscale.h"
  34. #include "swscale_internal.h"
  35. #define FAST_BGR2YV12 // use 7-bit instead of 15-bit coefficients
  36. void (*rgb24tobgr32)(const uint8_t *src, uint8_t *dst, long src_size);
  37. void (*rgb24tobgr16)(const uint8_t *src, uint8_t *dst, long src_size);
  38. void (*rgb24tobgr15)(const uint8_t *src, uint8_t *dst, long src_size);
  39. void (*rgb32tobgr24)(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 (*rgb15tobgr24)(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 (*rgb16tobgr24)(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 (*rgb24to16)(const uint8_t *src, uint8_t *dst, long src_size);
  51. void (*rgb24to15)(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 (*yuv422ptouyvy)(const uint8_t *ysrc, const uint8_t *usrc, const uint8_t *vsrc, uint8_t *dst,
  66. long width, long height,
  67. long lumStride, long chromStride, long dstStride);
  68. void (*yuy2toyv12)(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 (*rgb24toyv12)(const uint8_t *src, uint8_t *ydst, uint8_t *udst, uint8_t *vdst,
  72. long width, long height,
  73. long lumStride, long chromStride, long srcStride);
  74. void (*planar2x)(const uint8_t *src, uint8_t *dst, long width, long height,
  75. long srcStride, long dstStride);
  76. void (*interleaveBytes)(uint8_t *src1, uint8_t *src2, uint8_t *dst,
  77. long width, long height, long src1Stride,
  78. long src2Stride, long dstStride);
  79. void (*vu9_to_vu12)(const uint8_t *src1, const uint8_t *src2,
  80. uint8_t *dst1, uint8_t *dst2,
  81. long width, long height,
  82. long srcStride1, long srcStride2,
  83. long dstStride1, long dstStride2);
  84. void (*yvu9_to_yuy2)(const uint8_t *src1, const uint8_t *src2, const uint8_t *src3,
  85. uint8_t *dst,
  86. long width, long height,
  87. long srcStride1, long srcStride2,
  88. long srcStride3, long dstStride);
  89. #if defined(ARCH_X86) && defined(CONFIG_GPL)
  90. DECLARE_ASM_CONST(8, uint64_t, mmx_null) = 0x0000000000000000ULL;
  91. DECLARE_ASM_CONST(8, uint64_t, mmx_one) = 0xFFFFFFFFFFFFFFFFULL;
  92. DECLARE_ASM_CONST(8, uint64_t, mask32b) = 0x000000FF000000FFULL;
  93. DECLARE_ASM_CONST(8, uint64_t, mask32g) = 0x0000FF000000FF00ULL;
  94. DECLARE_ASM_CONST(8, uint64_t, mask32r) = 0x00FF000000FF0000ULL;
  95. DECLARE_ASM_CONST(8, uint64_t, mask32) = 0x00FFFFFF00FFFFFFULL;
  96. DECLARE_ASM_CONST(8, uint64_t, mask3216br) = 0x00F800F800F800F8ULL;
  97. DECLARE_ASM_CONST(8, uint64_t, mask3216g) = 0x0000FC000000FC00ULL;
  98. DECLARE_ASM_CONST(8, uint64_t, mask3215g) = 0x0000F8000000F800ULL;
  99. DECLARE_ASM_CONST(8, uint64_t, mul3216) = 0x2000000420000004ULL;
  100. DECLARE_ASM_CONST(8, uint64_t, mul3215) = 0x2000000820000008ULL;
  101. DECLARE_ASM_CONST(8, uint64_t, mask24b) = 0x00FF0000FF0000FFULL;
  102. DECLARE_ASM_CONST(8, uint64_t, mask24g) = 0xFF0000FF0000FF00ULL;
  103. DECLARE_ASM_CONST(8, uint64_t, mask24r) = 0x0000FF0000FF0000ULL;
  104. DECLARE_ASM_CONST(8, uint64_t, mask24l) = 0x0000000000FFFFFFULL;
  105. DECLARE_ASM_CONST(8, uint64_t, mask24h) = 0x0000FFFFFF000000ULL;
  106. DECLARE_ASM_CONST(8, uint64_t, mask24hh) = 0xffff000000000000ULL;
  107. DECLARE_ASM_CONST(8, uint64_t, mask24hhh) = 0xffffffff00000000ULL;
  108. DECLARE_ASM_CONST(8, uint64_t, mask24hhhh) = 0xffffffffffff0000ULL;
  109. DECLARE_ASM_CONST(8, uint64_t, mask15b) = 0x001F001F001F001FULL; /* 00000000 00011111 xxB */
  110. DECLARE_ASM_CONST(8, uint64_t, mask15rg) = 0x7FE07FE07FE07FE0ULL; /* 01111111 11100000 RGx */
  111. DECLARE_ASM_CONST(8, uint64_t, mask15s) = 0xFFE0FFE0FFE0FFE0ULL;
  112. DECLARE_ASM_CONST(8, uint64_t, mask15g) = 0x03E003E003E003E0ULL;
  113. DECLARE_ASM_CONST(8, uint64_t, mask15r) = 0x7C007C007C007C00ULL;
  114. #define mask16b mask15b
  115. DECLARE_ASM_CONST(8, uint64_t, mask16g) = 0x07E007E007E007E0ULL;
  116. DECLARE_ASM_CONST(8, uint64_t, mask16r) = 0xF800F800F800F800ULL;
  117. DECLARE_ASM_CONST(8, uint64_t, red_16mask) = 0x0000f8000000f800ULL;
  118. DECLARE_ASM_CONST(8, uint64_t, green_16mask) = 0x000007e0000007e0ULL;
  119. DECLARE_ASM_CONST(8, uint64_t, blue_16mask) = 0x0000001f0000001fULL;
  120. DECLARE_ASM_CONST(8, uint64_t, red_15mask) = 0x00007c0000007c00ULL;
  121. DECLARE_ASM_CONST(8, uint64_t, green_15mask) = 0x000003e0000003e0ULL;
  122. DECLARE_ASM_CONST(8, uint64_t, blue_15mask) = 0x0000001f0000001fULL;
  123. #if 0
  124. static volatile uint64_t __attribute__((aligned(8))) b5Dither;
  125. static volatile uint64_t __attribute__((aligned(8))) g5Dither;
  126. static volatile uint64_t __attribute__((aligned(8))) g6Dither;
  127. static volatile uint64_t __attribute__((aligned(8))) r5Dither;
  128. static uint64_t __attribute__((aligned(8))) dither4[2]={
  129. 0x0103010301030103LL,
  130. 0x0200020002000200LL,};
  131. static uint64_t __attribute__((aligned(8))) dither8[2]={
  132. 0x0602060206020602LL,
  133. 0x0004000400040004LL,};
  134. #endif
  135. #endif /* defined(ARCH_X86) */
  136. #define RGB2YUV_SHIFT 8
  137. #define BY ((int)( 0.098*(1<<RGB2YUV_SHIFT)+0.5))
  138. #define BV ((int)(-0.071*(1<<RGB2YUV_SHIFT)+0.5))
  139. #define BU ((int)( 0.439*(1<<RGB2YUV_SHIFT)+0.5))
  140. #define GY ((int)( 0.504*(1<<RGB2YUV_SHIFT)+0.5))
  141. #define GV ((int)(-0.368*(1<<RGB2YUV_SHIFT)+0.5))
  142. #define GU ((int)(-0.291*(1<<RGB2YUV_SHIFT)+0.5))
  143. #define RY ((int)( 0.257*(1<<RGB2YUV_SHIFT)+0.5))
  144. #define RV ((int)( 0.439*(1<<RGB2YUV_SHIFT)+0.5))
  145. #define RU ((int)(-0.148*(1<<RGB2YUV_SHIFT)+0.5))
  146. //Note: We have C, MMX, MMX2, 3DNOW versions, there is no 3DNOW + MMX2 one.
  147. //plain C versions
  148. #undef HAVE_MMX
  149. #undef HAVE_MMX2
  150. #undef HAVE_3DNOW
  151. #undef HAVE_SSE2
  152. #define RENAME(a) a ## _C
  153. #include "rgb2rgb_template.c"
  154. #if defined(ARCH_X86) && defined(CONFIG_GPL)
  155. //MMX versions
  156. #undef RENAME
  157. #define HAVE_MMX
  158. #undef HAVE_MMX2
  159. #undef HAVE_3DNOW
  160. #undef HAVE_SSE2
  161. #define RENAME(a) a ## _MMX
  162. #include "rgb2rgb_template.c"
  163. //MMX2 versions
  164. #undef RENAME
  165. #define HAVE_MMX
  166. #define HAVE_MMX2
  167. #undef HAVE_3DNOW
  168. #undef HAVE_SSE2
  169. #define RENAME(a) a ## _MMX2
  170. #include "rgb2rgb_template.c"
  171. //3DNOW versions
  172. #undef RENAME
  173. #define HAVE_MMX
  174. #undef HAVE_MMX2
  175. #define HAVE_3DNOW
  176. #undef HAVE_SSE2
  177. #define RENAME(a) a ## _3DNOW
  178. #include "rgb2rgb_template.c"
  179. #endif //ARCH_X86 || ARCH_X86_64
  180. /*
  181. RGB15->RGB16 original by Strepto/Astral
  182. ported to gcc & bugfixed : A'rpi
  183. MMX2, 3DNOW optimization by Nick Kurshev
  184. 32-bit C version, and and&add trick by Michael Niedermayer
  185. */
  186. void sws_rgb2rgb_init(int flags){
  187. #if (defined(HAVE_MMX2) || defined(HAVE_3DNOW) || defined(HAVE_MMX)) && defined(CONFIG_GPL)
  188. if (flags & SWS_CPU_CAPS_MMX2)
  189. rgb2rgb_init_MMX2();
  190. else if (flags & SWS_CPU_CAPS_3DNOW)
  191. rgb2rgb_init_3DNOW();
  192. else if (flags & SWS_CPU_CAPS_MMX)
  193. rgb2rgb_init_MMX();
  194. else
  195. #endif /* defined(HAVE_MMX2) || defined(HAVE_3DNOW) || defined(HAVE_MMX) */
  196. rgb2rgb_init_C();
  197. }
  198. /**
  199. * Palette is assumed to contain BGR32.
  200. */
  201. void palette8torgb32(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette)
  202. {
  203. long i;
  204. /*
  205. for (i=0; i<num_pixels; i++)
  206. ((unsigned *)dst)[i] = ((unsigned *)palette)[src[i]];
  207. */
  208. for (i=0; i<num_pixels; i++)
  209. {
  210. #ifdef WORDS_BIGENDIAN
  211. dst[3]= palette[src[i]*4+2];
  212. dst[2]= palette[src[i]*4+1];
  213. dst[1]= palette[src[i]*4+0];
  214. #else
  215. //FIXME slow?
  216. dst[0]= palette[src[i]*4+2];
  217. dst[1]= palette[src[i]*4+1];
  218. dst[2]= palette[src[i]*4+0];
  219. //dst[3]= 0; /* do we need this cleansing? */
  220. #endif
  221. dst+= 4;
  222. }
  223. }
  224. void palette8tobgr32(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette)
  225. {
  226. long i;
  227. for (i=0; i<num_pixels; i++)
  228. {
  229. #ifdef WORDS_BIGENDIAN
  230. dst[3]= palette[src[i]*4+0];
  231. dst[2]= palette[src[i]*4+1];
  232. dst[1]= palette[src[i]*4+2];
  233. #else
  234. //FIXME slow?
  235. dst[0]= palette[src[i]*4+0];
  236. dst[1]= palette[src[i]*4+1];
  237. dst[2]= palette[src[i]*4+2];
  238. //dst[3]= 0; /* do we need this cleansing? */
  239. #endif
  240. dst+= 4;
  241. }
  242. }
  243. /**
  244. * Palette is assumed to contain BGR32.
  245. */
  246. void palette8torgb24(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette)
  247. {
  248. long i;
  249. /*
  250. Writes 1 byte too much and might cause alignment issues on some architectures?
  251. for (i=0; i<num_pixels; i++)
  252. ((unsigned *)(&dst[i*3])) = ((unsigned *)palette)[src[i]];
  253. */
  254. for (i=0; i<num_pixels; i++)
  255. {
  256. //FIXME slow?
  257. dst[0]= palette[src[i]*4+2];
  258. dst[1]= palette[src[i]*4+1];
  259. dst[2]= palette[src[i]*4+0];
  260. dst+= 3;
  261. }
  262. }
  263. void palette8tobgr24(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette)
  264. {
  265. long i;
  266. /*
  267. Writes 1 byte too much and might cause alignment issues on some architectures?
  268. for (i=0; i<num_pixels; i++)
  269. ((unsigned *)(&dst[i*3])) = ((unsigned *)palette)[src[i]];
  270. */
  271. for (i=0; i<num_pixels; i++)
  272. {
  273. //FIXME slow?
  274. dst[0]= palette[src[i]*4+0];
  275. dst[1]= palette[src[i]*4+1];
  276. dst[2]= palette[src[i]*4+2];
  277. dst+= 3;
  278. }
  279. }
  280. /**
  281. * Palette is assumed to contain BGR16, see rgb32to16 to convert the palette.
  282. */
  283. void palette8torgb16(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette)
  284. {
  285. long i;
  286. for (i=0; i<num_pixels; i++)
  287. ((uint16_t *)dst)[i] = ((const uint16_t *)palette)[src[i]];
  288. }
  289. void palette8tobgr16(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette)
  290. {
  291. long i;
  292. for (i=0; i<num_pixels; i++)
  293. ((uint16_t *)dst)[i] = bswap_16(((const uint16_t *)palette)[src[i]]);
  294. }
  295. /**
  296. * Palette is assumed to contain BGR15, see rgb32to15 to convert the palette.
  297. */
  298. void palette8torgb15(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] = ((const uint16_t *)palette)[src[i]];
  303. }
  304. void palette8tobgr15(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette)
  305. {
  306. long i;
  307. for (i=0; i<num_pixels; i++)
  308. ((uint16_t *)dst)[i] = bswap_16(((const uint16_t *)palette)[src[i]]);
  309. }
  310. void rgb32to24(const uint8_t *src, uint8_t *dst, long src_size)
  311. {
  312. long i;
  313. long num_pixels = src_size >> 2;
  314. for (i=0; i<num_pixels; i++)
  315. {
  316. #ifdef WORDS_BIGENDIAN
  317. /* RGB32 (= A,B,G,R) -> BGR24 (= B,G,R) */
  318. dst[3*i + 0] = src[4*i + 1];
  319. dst[3*i + 1] = src[4*i + 2];
  320. dst[3*i + 2] = src[4*i + 3];
  321. #else
  322. dst[3*i + 0] = src[4*i + 2];
  323. dst[3*i + 1] = src[4*i + 1];
  324. dst[3*i + 2] = src[4*i + 0];
  325. #endif
  326. }
  327. }
  328. void rgb24to32(const uint8_t *src, uint8_t *dst, long src_size)
  329. {
  330. long i;
  331. for (i=0; 3*i<src_size; i++)
  332. {
  333. #ifdef WORDS_BIGENDIAN
  334. /* RGB24 (= R,G,B) -> BGR32 (= A,R,G,B) */
  335. dst[4*i + 0] = 0;
  336. dst[4*i + 1] = src[3*i + 0];
  337. dst[4*i + 2] = src[3*i + 1];
  338. dst[4*i + 3] = src[3*i + 2];
  339. #else
  340. dst[4*i + 0] = src[3*i + 2];
  341. dst[4*i + 1] = src[3*i + 1];
  342. dst[4*i + 2] = src[3*i + 0];
  343. dst[4*i + 3] = 0;
  344. #endif
  345. }
  346. }
  347. void rgb16tobgr32(const uint8_t *src, uint8_t *dst, long src_size)
  348. {
  349. const uint16_t *end;
  350. uint8_t *d = dst;
  351. const uint16_t *s = (const uint16_t *)src;
  352. end = s + src_size/2;
  353. while (s < end)
  354. {
  355. register uint16_t bgr;
  356. bgr = *s++;
  357. #ifdef WORDS_BIGENDIAN
  358. *d++ = 0;
  359. *d++ = (bgr&0x1F)<<3;
  360. *d++ = (bgr&0x7E0)>>3;
  361. *d++ = (bgr&0xF800)>>8;
  362. #else
  363. *d++ = (bgr&0xF800)>>8;
  364. *d++ = (bgr&0x7E0)>>3;
  365. *d++ = (bgr&0x1F)<<3;
  366. *d++ = 0;
  367. #endif
  368. }
  369. }
  370. void rgb16to24(const uint8_t *src, uint8_t *dst, long src_size)
  371. {
  372. const uint16_t *end;
  373. uint8_t *d = dst;
  374. const uint16_t *s = (const uint16_t *)src;
  375. end = s + src_size/2;
  376. while (s < end)
  377. {
  378. register uint16_t bgr;
  379. bgr = *s++;
  380. *d++ = (bgr&0xF800)>>8;
  381. *d++ = (bgr&0x7E0)>>3;
  382. *d++ = (bgr&0x1F)<<3;
  383. }
  384. }
  385. void rgb16tobgr16(const uint8_t *src, uint8_t *dst, long src_size)
  386. {
  387. long i;
  388. long num_pixels = src_size >> 1;
  389. for (i=0; i<num_pixels; i++)
  390. {
  391. unsigned rgb = ((const uint16_t*)src)[i];
  392. ((uint16_t*)dst)[i] = (rgb>>11) | (rgb&0x7E0) | (rgb<<11);
  393. }
  394. }
  395. void rgb16tobgr15(const uint8_t *src, uint8_t *dst, long src_size)
  396. {
  397. long i;
  398. long num_pixels = src_size >> 1;
  399. for (i=0; i<num_pixels; i++)
  400. {
  401. unsigned rgb = ((const uint16_t*)src)[i];
  402. ((uint16_t*)dst)[i] = (rgb>>11) | ((rgb&0x7C0)>>1) | ((rgb&0x1F)<<10);
  403. }
  404. }
  405. void rgb15tobgr32(const uint8_t *src, uint8_t *dst, long src_size)
  406. {
  407. const uint16_t *end;
  408. uint8_t *d = dst;
  409. const uint16_t *s = (const uint16_t *)src;
  410. end = s + src_size/2;
  411. while (s < end)
  412. {
  413. register uint16_t bgr;
  414. bgr = *s++;
  415. #ifdef WORDS_BIGENDIAN
  416. *d++ = 0;
  417. *d++ = (bgr&0x1F)<<3;
  418. *d++ = (bgr&0x3E0)>>2;
  419. *d++ = (bgr&0x7C00)>>7;
  420. #else
  421. *d++ = (bgr&0x7C00)>>7;
  422. *d++ = (bgr&0x3E0)>>2;
  423. *d++ = (bgr&0x1F)<<3;
  424. *d++ = 0;
  425. #endif
  426. }
  427. }
  428. void rgb15to24(const uint8_t *src, uint8_t *dst, long src_size)
  429. {
  430. const uint16_t *end;
  431. uint8_t *d = 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. *d++ = (bgr&0x7C00)>>7;
  439. *d++ = (bgr&0x3E0)>>2;
  440. *d++ = (bgr&0x1F)<<3;
  441. }
  442. }
  443. void rgb15tobgr16(const uint8_t *src, uint8_t *dst, long src_size)
  444. {
  445. long i;
  446. long num_pixels = src_size >> 1;
  447. for (i=0; i<num_pixels; i++)
  448. {
  449. unsigned rgb = ((const uint16_t*)src)[i];
  450. ((uint16_t*)dst)[i] = ((rgb&0x7C00)>>10) | ((rgb&0x3E0)<<1) | (rgb<<11);
  451. }
  452. }
  453. void rgb15tobgr15(const uint8_t *src, uint8_t *dst, long src_size)
  454. {
  455. long i;
  456. long num_pixels = src_size >> 1;
  457. for (i=0; i<num_pixels; i++)
  458. {
  459. unsigned br;
  460. unsigned rgb = ((const uint16_t*)src)[i];
  461. br = rgb&0x7c1F;
  462. ((uint16_t*)dst)[i] = (br>>10) | (rgb&0x3E0) | (br<<10);
  463. }
  464. }
  465. void bgr8torgb8(const uint8_t *src, uint8_t *dst, long src_size)
  466. {
  467. long i;
  468. long num_pixels = src_size;
  469. for (i=0; i<num_pixels; i++)
  470. {
  471. unsigned b,g,r;
  472. register uint8_t rgb;
  473. rgb = src[i];
  474. r = (rgb&0x07);
  475. g = (rgb&0x38)>>3;
  476. b = (rgb&0xC0)>>6;
  477. dst[i] = ((b<<1)&0x07) | ((g&0x07)<<3) | ((r&0x03)<<6);
  478. }
  479. }