rgb2rgb.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485
  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
  12. * modify it under the terms of the GNU Lesser General Public
  13. * License as published by the Free Software Foundation; either
  14. * version 2.1 of the License, or (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 GNU
  19. * Lesser General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Lesser General Public
  22. * License 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. #include <inttypes.h>
  26. #include "libavutil/attributes.h"
  27. #include "libavutil/bswap.h"
  28. #include "config.h"
  29. #include "rgb2rgb.h"
  30. #include "swscale.h"
  31. #include "swscale_internal.h"
  32. void (*rgb32tobgr24)(const uint8_t *src, uint8_t *dst, int src_size);
  33. void (*rgb32tobgr16)(const uint8_t *src, uint8_t *dst, int src_size);
  34. void (*rgb32tobgr15)(const uint8_t *src, uint8_t *dst, int src_size);
  35. void (*rgb24tobgr32)(const uint8_t *src, uint8_t *dst, int src_size);
  36. void (*rgb24tobgr24)(const uint8_t *src, uint8_t *dst, int src_size);
  37. void (*rgb24tobgr16)(const uint8_t *src, uint8_t *dst, int src_size);
  38. void (*rgb24tobgr15)(const uint8_t *src, uint8_t *dst, int src_size);
  39. void (*rgb16tobgr24)(const uint8_t *src, uint8_t *dst, int src_size);
  40. void (*rgb15tobgr24)(const uint8_t *src, uint8_t *dst, int src_size);
  41. void (*rgb32to16)(const uint8_t *src, uint8_t *dst, int src_size);
  42. void (*rgb32to15)(const uint8_t *src, uint8_t *dst, int src_size);
  43. void (*rgb24to16)(const uint8_t *src, uint8_t *dst, int src_size);
  44. void (*rgb24to15)(const uint8_t *src, uint8_t *dst, int src_size);
  45. void (*rgb16to32)(const uint8_t *src, uint8_t *dst, int src_size);
  46. void (*rgb16to15)(const uint8_t *src, uint8_t *dst, int src_size);
  47. void (*rgb15to16)(const uint8_t *src, uint8_t *dst, int src_size);
  48. void (*rgb15to32)(const uint8_t *src, uint8_t *dst, int src_size);
  49. void (*shuffle_bytes_0321)(const uint8_t *src, uint8_t *dst, int src_size);
  50. void (*shuffle_bytes_2103)(const uint8_t *src, uint8_t *dst, int src_size);
  51. void (*shuffle_bytes_1230)(const uint8_t *src, uint8_t *dst, int src_size);
  52. void (*shuffle_bytes_3012)(const uint8_t *src, uint8_t *dst, int src_size);
  53. void (*shuffle_bytes_3210)(const uint8_t *src, uint8_t *dst, int src_size);
  54. void (*shuffle_bytes_3102)(const uint8_t *src, uint8_t *dst, int src_size);
  55. void (*shuffle_bytes_2013)(const uint8_t *src, uint8_t *dst, int src_size);
  56. void (*shuffle_bytes_2130)(const uint8_t *src, uint8_t *dst, int src_size);
  57. void (*shuffle_bytes_1203)(const uint8_t *src, uint8_t *dst, int src_size);
  58. void (*yv12toyuy2)(const uint8_t *ysrc, const uint8_t *usrc,
  59. const uint8_t *vsrc, uint8_t *dst,
  60. int width, int height,
  61. int lumStride, int chromStride, int dstStride);
  62. void (*yv12touyvy)(const uint8_t *ysrc, const uint8_t *usrc,
  63. const uint8_t *vsrc, uint8_t *dst,
  64. int width, int height,
  65. int lumStride, int chromStride, int dstStride);
  66. void (*yuv422ptoyuy2)(const uint8_t *ysrc, const uint8_t *usrc,
  67. const uint8_t *vsrc, uint8_t *dst,
  68. int width, int height,
  69. int lumStride, int chromStride, int dstStride);
  70. void (*yuv422ptouyvy)(const uint8_t *ysrc, const uint8_t *usrc,
  71. const uint8_t *vsrc, uint8_t *dst,
  72. int width, int height,
  73. int lumStride, int chromStride, int dstStride);
  74. void (*yuy2toyv12)(const uint8_t *src, uint8_t *ydst,
  75. uint8_t *udst, uint8_t *vdst,
  76. int width, int height,
  77. int lumStride, int chromStride, int srcStride);
  78. void (*ff_rgb24toyv12)(const uint8_t *src, uint8_t *ydst,
  79. uint8_t *udst, uint8_t *vdst,
  80. int width, int height,
  81. int lumStride, int chromStride, int srcStride,
  82. const int32_t *rgb2yuv);
  83. void (*planar2x)(const uint8_t *src, uint8_t *dst, int width, int height,
  84. int srcStride, int dstStride);
  85. void (*interleaveBytes)(const uint8_t *src1, const uint8_t *src2, uint8_t *dst,
  86. int width, int height, int src1Stride,
  87. int src2Stride, int dstStride);
  88. void (*deinterleaveBytes)(const uint8_t *src, uint8_t *dst1, uint8_t *dst2,
  89. int width, int height, int srcStride,
  90. int dst1Stride, int dst2Stride);
  91. void (*vu9_to_vu12)(const uint8_t *src1, const uint8_t *src2,
  92. uint8_t *dst1, uint8_t *dst2,
  93. int width, int height,
  94. int srcStride1, int srcStride2,
  95. int dstStride1, int dstStride2);
  96. void (*yvu9_to_yuy2)(const uint8_t *src1, const uint8_t *src2,
  97. const uint8_t *src3, uint8_t *dst,
  98. int width, int height,
  99. int srcStride1, int srcStride2,
  100. int srcStride3, int dstStride);
  101. void (*uyvytoyuv420)(uint8_t *ydst, uint8_t *udst, uint8_t *vdst,
  102. const uint8_t *src, int width, int height,
  103. int lumStride, int chromStride, int srcStride);
  104. void (*uyvytoyuv422)(uint8_t *ydst, uint8_t *udst, uint8_t *vdst,
  105. const uint8_t *src, int width, int height,
  106. int lumStride, int chromStride, int srcStride);
  107. void (*yuyvtoyuv420)(uint8_t *ydst, uint8_t *udst, uint8_t *vdst,
  108. const uint8_t *src, int width, int height,
  109. int lumStride, int chromStride, int srcStride);
  110. void (*yuyvtoyuv422)(uint8_t *ydst, uint8_t *udst, uint8_t *vdst,
  111. const uint8_t *src, int width, int height,
  112. int lumStride, int chromStride, int srcStride);
  113. #define BY ((int)( 0.098 * (1 << RGB2YUV_SHIFT) + 0.5))
  114. #define BV ((int)(-0.071 * (1 << RGB2YUV_SHIFT) + 0.5))
  115. #define BU ((int)( 0.439 * (1 << RGB2YUV_SHIFT) + 0.5))
  116. #define GY ((int)( 0.504 * (1 << RGB2YUV_SHIFT) + 0.5))
  117. #define GV ((int)(-0.368 * (1 << RGB2YUV_SHIFT) + 0.5))
  118. #define GU ((int)(-0.291 * (1 << RGB2YUV_SHIFT) + 0.5))
  119. #define RY ((int)( 0.257 * (1 << RGB2YUV_SHIFT) + 0.5))
  120. #define RV ((int)( 0.439 * (1 << RGB2YUV_SHIFT) + 0.5))
  121. #define RU ((int)(-0.148 * (1 << RGB2YUV_SHIFT) + 0.5))
  122. //plain C versions
  123. #include "rgb2rgb_template.c"
  124. /*
  125. * RGB15->RGB16 original by Strepto/Astral
  126. * ported to gcc & bugfixed : A'rpi
  127. * MMXEXT, 3DNOW optimization by Nick Kurshev
  128. * 32-bit C version, and and&add trick by Michael Niedermayer
  129. */
  130. av_cold void ff_sws_rgb2rgb_init(void)
  131. {
  132. rgb2rgb_init_c();
  133. #if ARCH_AARCH64
  134. rgb2rgb_init_aarch64();
  135. #elif ARCH_RISCV
  136. rgb2rgb_init_riscv();
  137. #elif ARCH_X86
  138. rgb2rgb_init_x86();
  139. #elif ARCH_LOONGARCH64
  140. rgb2rgb_init_loongarch();
  141. #endif
  142. }
  143. void rgb32to24(const uint8_t *src, uint8_t *dst, int src_size)
  144. {
  145. int i, num_pixels = src_size >> 2;
  146. for (i = 0; i < num_pixels; i++) {
  147. #if HAVE_BIGENDIAN
  148. /* RGB32 (= A,B,G,R) -> BGR24 (= B,G,R) */
  149. dst[3 * i + 0] = src[4 * i + 1];
  150. dst[3 * i + 1] = src[4 * i + 2];
  151. dst[3 * i + 2] = src[4 * i + 3];
  152. #else
  153. dst[3 * i + 0] = src[4 * i + 2];
  154. dst[3 * i + 1] = src[4 * i + 1];
  155. dst[3 * i + 2] = src[4 * i + 0];
  156. #endif
  157. }
  158. }
  159. void rgb24to32(const uint8_t *src, uint8_t *dst, int src_size)
  160. {
  161. int i;
  162. for (i = 0; 3 * i < src_size; i++) {
  163. #if HAVE_BIGENDIAN
  164. /* RGB24 (= R, G, B) -> BGR32 (= A, R, G, B) */
  165. dst[4 * i + 0] = 255;
  166. dst[4 * i + 1] = src[3 * i + 0];
  167. dst[4 * i + 2] = src[3 * i + 1];
  168. dst[4 * i + 3] = src[3 * i + 2];
  169. #else
  170. dst[4 * i + 0] = src[3 * i + 2];
  171. dst[4 * i + 1] = src[3 * i + 1];
  172. dst[4 * i + 2] = src[3 * i + 0];
  173. dst[4 * i + 3] = 255;
  174. #endif
  175. }
  176. }
  177. void rgb16tobgr32(const uint8_t *src, uint8_t *dst, int src_size)
  178. {
  179. uint8_t *d = dst;
  180. const uint16_t *s = (const uint16_t *)src;
  181. const uint16_t *end = s + src_size / 2;
  182. while (s < end) {
  183. register uint16_t bgr = *s++;
  184. #if HAVE_BIGENDIAN
  185. *d++ = 255;
  186. *d++ = ((bgr&0x001F)<<3) | ((bgr&0x001F)>> 2);
  187. *d++ = ((bgr&0x07E0)>>3) | ((bgr&0x07E0)>> 9);
  188. *d++ = ((bgr&0xF800)>>8) | ((bgr&0xF800)>>13);
  189. #else
  190. *d++ = ((bgr&0xF800)>>8) | ((bgr&0xF800)>>13);
  191. *d++ = ((bgr&0x07E0)>>3) | ((bgr&0x07E0)>> 9);
  192. *d++ = ((bgr&0x001F)<<3) | ((bgr&0x001F)>> 2);
  193. *d++ = 255;
  194. #endif
  195. }
  196. }
  197. void rgb12to15(const uint8_t *src, uint8_t *dst, int src_size)
  198. {
  199. uint16_t rgb, r, g, b;
  200. uint16_t *d = (uint16_t *)dst;
  201. const uint16_t *s = (const uint16_t *)src;
  202. const uint16_t *end = s + src_size / 2;
  203. while (s < end) {
  204. rgb = *s++;
  205. r = rgb & 0xF00;
  206. g = rgb & 0x0F0;
  207. b = rgb & 0x00F;
  208. r = (r << 3) | ((r & 0x800) >> 1);
  209. g = (g << 2) | ((g & 0x080) >> 2);
  210. b = (b << 1) | ( b >> 3);
  211. *d++ = r | g | b;
  212. }
  213. }
  214. void rgb16to24(const uint8_t *src, uint8_t *dst, int src_size)
  215. {
  216. uint8_t *d = dst;
  217. const uint16_t *s = (const uint16_t *)src;
  218. const uint16_t *end = s + src_size / 2;
  219. while (s < end) {
  220. register uint16_t bgr = *s++;
  221. *d++ = ((bgr&0xF800)>>8) | ((bgr&0xF800)>>13);
  222. *d++ = ((bgr&0x07E0)>>3) | ((bgr&0x07E0)>> 9);
  223. *d++ = ((bgr&0x001F)<<3) | ((bgr&0x001F)>> 2);
  224. }
  225. }
  226. void rgb16tobgr16(const uint8_t *src, uint8_t *dst, int src_size)
  227. {
  228. int i, num_pixels = src_size >> 1;
  229. for (i = 0; i < num_pixels; i++) {
  230. unsigned rgb = ((const uint16_t *)src)[i];
  231. ((uint16_t *)dst)[i] = (rgb >> 11) | (rgb & 0x7E0) | (rgb << 11);
  232. }
  233. }
  234. void rgb16tobgr15(const uint8_t *src, uint8_t *dst, int src_size)
  235. {
  236. int i, num_pixels = src_size >> 1;
  237. for (i = 0; i < num_pixels; i++) {
  238. unsigned rgb = ((const uint16_t *)src)[i];
  239. ((uint16_t *)dst)[i] = (rgb >> 11) | ((rgb & 0x7C0) >> 1) | ((rgb & 0x1F) << 10);
  240. }
  241. }
  242. void rgb15tobgr32(const uint8_t *src, uint8_t *dst, int src_size)
  243. {
  244. uint8_t *d = dst;
  245. const uint16_t *s = (const uint16_t *)src;
  246. const uint16_t *end = s + src_size / 2;
  247. while (s < end) {
  248. register uint16_t bgr = *s++;
  249. #if HAVE_BIGENDIAN
  250. *d++ = 255;
  251. *d++ = ((bgr&0x001F)<<3) | ((bgr&0x001F)>> 2);
  252. *d++ = ((bgr&0x03E0)>>2) | ((bgr&0x03E0)>> 7);
  253. *d++ = ((bgr&0x7C00)>>7) | ((bgr&0x7C00)>>12);
  254. #else
  255. *d++ = ((bgr&0x7C00)>>7) | ((bgr&0x7C00)>>12);
  256. *d++ = ((bgr&0x03E0)>>2) | ((bgr&0x03E0)>> 7);
  257. *d++ = ((bgr&0x001F)<<3) | ((bgr&0x001F)>> 2);
  258. *d++ = 255;
  259. #endif
  260. }
  261. }
  262. void rgb15to24(const uint8_t *src, uint8_t *dst, int src_size)
  263. {
  264. uint8_t *d = dst;
  265. const uint16_t *s = (const uint16_t *)src;
  266. const uint16_t *end = s + src_size / 2;
  267. while (s < end) {
  268. register uint16_t bgr = *s++;
  269. *d++ = ((bgr&0x7C00)>>7) | ((bgr&0x7C00)>>12);
  270. *d++ = ((bgr&0x03E0)>>2) | ((bgr&0x03E0)>> 7);
  271. *d++ = ((bgr&0x001F)<<3) | ((bgr&0x001F)>> 2);
  272. }
  273. }
  274. void rgb15tobgr16(const uint8_t *src, uint8_t *dst, int src_size)
  275. {
  276. int i, num_pixels = src_size >> 1;
  277. for (i = 0; i < num_pixels; i++) {
  278. unsigned rgb = ((const uint16_t *)src)[i];
  279. ((uint16_t *)dst)[i] = ((rgb & 0x7C00) >> 10) | ((rgb & 0x3E0) << 1) | (rgb << 11);
  280. }
  281. }
  282. void rgb15tobgr15(const uint8_t *src, uint8_t *dst, int src_size)
  283. {
  284. int i, num_pixels = src_size >> 1;
  285. for (i = 0; i < num_pixels; i++) {
  286. unsigned rgb = ((const uint16_t *)src)[i];
  287. unsigned br = rgb & 0x7C1F;
  288. ((uint16_t *)dst)[i] = (br >> 10) | (rgb & 0x3E0) | (br << 10);
  289. }
  290. }
  291. void rgb12tobgr12(const uint8_t *src, uint8_t *dst, int src_size)
  292. {
  293. uint16_t *d = (uint16_t *)dst;
  294. const uint16_t *s = (const uint16_t *)src;
  295. int i, num_pixels = src_size >> 1;
  296. for (i = 0; i < num_pixels; i++) {
  297. unsigned rgb = s[i];
  298. d[i] = (rgb << 8 | rgb & 0xF0 | rgb >> 8) & 0xFFF;
  299. }
  300. }
  301. #define DEFINE_RGB48TOBGR48(need_bswap, swap) \
  302. void rgb48tobgr48_ ## need_bswap(const uint8_t *src, \
  303. uint8_t *dst, int src_size) \
  304. { \
  305. uint16_t *d = (uint16_t *)dst; \
  306. const uint16_t *s = (const uint16_t *)src; \
  307. int i, num_pixels = src_size >> 1; \
  308. \
  309. for (i = 0; i < num_pixels; i += 3) { \
  310. d[i ] = swap ? av_bswap16(s[i + 2]) : s[i + 2]; \
  311. d[i + 1] = swap ? av_bswap16(s[i + 1]) : s[i + 1]; \
  312. d[i + 2] = swap ? av_bswap16(s[i ]) : s[i ]; \
  313. } \
  314. }
  315. DEFINE_RGB48TOBGR48(nobswap, 0)
  316. DEFINE_RGB48TOBGR48(bswap, 1)
  317. #define DEFINE_RGB64TOBGR48(need_bswap, swap) \
  318. void rgb64tobgr48_ ## need_bswap(const uint8_t *src, \
  319. uint8_t *dst, int src_size) \
  320. { \
  321. uint16_t *d = (uint16_t *)dst; \
  322. const uint16_t *s = (const uint16_t *)src; \
  323. int i, num_pixels = src_size >> 3; \
  324. \
  325. for (i = 0; i < num_pixels; i++) { \
  326. d[3 * i ] = swap ? av_bswap16(s[4 * i + 2]) : s[4 * i + 2]; \
  327. d[3 * i + 1] = swap ? av_bswap16(s[4 * i + 1]) : s[4 * i + 1]; \
  328. d[3 * i + 2] = swap ? av_bswap16(s[4 * i ]) : s[4 * i ]; \
  329. } \
  330. }
  331. DEFINE_RGB64TOBGR48(nobswap, 0)
  332. DEFINE_RGB64TOBGR48(bswap, 1)
  333. #define DEFINE_RGB64TO48(need_bswap, swap) \
  334. void rgb64to48_ ## need_bswap(const uint8_t *src, \
  335. uint8_t *dst, int src_size) \
  336. { \
  337. uint16_t *d = (uint16_t *)dst; \
  338. const uint16_t *s = (const uint16_t *)src; \
  339. int i, num_pixels = src_size >> 3; \
  340. \
  341. for (i = 0; i < num_pixels; i++) { \
  342. d[3 * i ] = swap ? av_bswap16(s[4 * i ]) : s[4 * i ]; \
  343. d[3 * i + 1] = swap ? av_bswap16(s[4 * i + 1]) : s[4 * i + 1]; \
  344. d[3 * i + 2] = swap ? av_bswap16(s[4 * i + 2]) : s[4 * i + 2]; \
  345. } \
  346. }
  347. DEFINE_RGB64TO48(nobswap, 0)
  348. DEFINE_RGB64TO48(bswap, 1)
  349. #define DEFINE_RGB48TOBGR64(need_bswap, swap) \
  350. void rgb48tobgr64_ ## need_bswap(const uint8_t *src, \
  351. uint8_t *dst, int src_size) \
  352. { \
  353. uint16_t *d = (uint16_t *)dst; \
  354. const uint16_t *s = (const uint16_t *)src; \
  355. int i, num_pixels = src_size / 6; \
  356. \
  357. for (i = 0; i < num_pixels; i++) { \
  358. d[4 * i ] = swap ? av_bswap16(s[3 * i + 2]) : s[3 * i + 2]; \
  359. d[4 * i + 1] = swap ? av_bswap16(s[3 * i + 1]) : s[3 * i + 1]; \
  360. d[4 * i + 2] = swap ? av_bswap16(s[3 * i ]) : s[3 * i ]; \
  361. d[4 * i + 3] = 0xFFFF; \
  362. } \
  363. }
  364. DEFINE_RGB48TOBGR64(nobswap, 0)
  365. DEFINE_RGB48TOBGR64(bswap, 1)
  366. #define DEFINE_RGB48TO64(need_bswap, swap) \
  367. void rgb48to64_ ## need_bswap(const uint8_t *src, \
  368. uint8_t *dst, int src_size) \
  369. { \
  370. uint16_t *d = (uint16_t *)dst; \
  371. const uint16_t *s = (const uint16_t *)src; \
  372. int i, num_pixels = src_size / 6; \
  373. \
  374. for (i = 0; i < num_pixels; i++) { \
  375. d[4 * i ] = swap ? av_bswap16(s[3 * i ]) : s[3 * i ]; \
  376. d[4 * i + 1] = swap ? av_bswap16(s[3 * i + 1]) : s[3 * i + 1]; \
  377. d[4 * i + 2] = swap ? av_bswap16(s[3 * i + 2]) : s[3 * i + 2]; \
  378. d[4 * i + 3] = 0xFFFF; \
  379. } \
  380. }
  381. DEFINE_RGB48TO64(nobswap, 0)
  382. DEFINE_RGB48TO64(bswap, 1)
  383. #define DEFINE_X2RGB10TO16(need_bswap, swap, bits, alpha) \
  384. void x2rgb10to ## bits ## _ ## need_bswap(const uint8_t *src, \
  385. uint8_t *dst, int src_size) \
  386. { \
  387. uint16_t *d = (uint16_t *)dst; \
  388. const uint32_t *s = (const uint32_t *)src; \
  389. int i, num_pixels = src_size >> 2; \
  390. unsigned component; \
  391. \
  392. for (i = 0; i < num_pixels; i++) { \
  393. unsigned p = AV_RL32(s + i); \
  394. component = (p >> 20) & 0x3FF; \
  395. d[(3 + alpha) * i + 0] = swap ? av_bswap16(component << 6 | component >> 4) \
  396. : component << 6 | component >> 4; \
  397. component = (p >> 10) & 0x3FF; \
  398. d[(3 + alpha) * i + 1] = swap ? av_bswap16(component << 6 | component >> 4) \
  399. : component << 6 | component >> 4; \
  400. component = p & 0x3FF; \
  401. d[(3 + alpha) * i + 2] = swap ? av_bswap16(component << 6 | component >> 4) \
  402. : component << 6 | component >> 4; \
  403. if (alpha) d[(3 + alpha) * i + 3] = 0xffff; \
  404. } \
  405. }
  406. DEFINE_X2RGB10TO16(nobswap, 0, 48, 0)
  407. DEFINE_X2RGB10TO16(bswap, 1, 48, 0)
  408. DEFINE_X2RGB10TO16(nobswap, 0, 64, 1)
  409. DEFINE_X2RGB10TO16(bswap, 1, 64, 1)
  410. #define DEFINE_X2RGB10TOBGR16(need_bswap, swap, bits, alpha) \
  411. void x2rgb10tobgr ## bits ## _ ## need_bswap(const uint8_t *src, \
  412. uint8_t *dst, int src_size) \
  413. { \
  414. uint16_t *d = (uint16_t *)dst; \
  415. const uint32_t *s = (const uint32_t *)src; \
  416. int i, num_pixels = src_size >> 2; \
  417. unsigned component; \
  418. \
  419. for (i = 0; i < num_pixels; i++) { \
  420. unsigned p = AV_RL32(s + i); \
  421. component = p & 0x3FF; \
  422. d[(3 + alpha) * i + 0] = swap ? av_bswap16(component << 6 | component >> 4) \
  423. : component << 6 | component >> 4; \
  424. component = (p >> 10) & 0x3FF; \
  425. d[(3 + alpha) * i + 1] = swap ? av_bswap16(component << 6 | component >> 4) \
  426. : component << 6 | component >> 4; \
  427. component = (p >> 20) & 0x3FF; \
  428. d[(3 + alpha) * i + 2] = swap ? av_bswap16(component << 6 | component >> 4) \
  429. : component << 6 | component >> 4; \
  430. if (alpha) d[(3 + alpha) * i + 3] = 0xffff; \
  431. } \
  432. }
  433. DEFINE_X2RGB10TOBGR16(nobswap, 0, 48, 0)
  434. DEFINE_X2RGB10TOBGR16(bswap, 1, 48, 0)
  435. DEFINE_X2RGB10TOBGR16(nobswap, 0, 64, 1)
  436. DEFINE_X2RGB10TOBGR16(bswap, 1, 64, 1)