imgconvert_template.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878
  1. /*
  2. * templates for image conversion routines
  3. * Copyright (c) 2001, 2002, 2003 Fabrice Bellard.
  4. *
  5. * This file is part of FFmpeg.
  6. *
  7. * FFmpeg is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * FFmpeg is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with FFmpeg; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. /* This header has no multiple inclusion guards as it gets
  22. * included multiple times. */
  23. #ifndef RGB_OUT
  24. #define RGB_OUT(d, r, g, b) RGBA_OUT(d, r, g, b, 0xff)
  25. #endif
  26. static void glue(yuv420p_to_, RGB_NAME)(AVPicture *dst, const AVPicture *src,
  27. int width, int height)
  28. {
  29. const uint8_t *y1_ptr, *y2_ptr, *cb_ptr, *cr_ptr;
  30. uint8_t *d, *d1, *d2;
  31. int w, y, cb, cr, r_add, g_add, b_add, width2;
  32. uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
  33. unsigned int r, g, b;
  34. d = dst->data[0];
  35. y1_ptr = src->data[0];
  36. cb_ptr = src->data[1];
  37. cr_ptr = src->data[2];
  38. width2 = (width + 1) >> 1;
  39. for(;height >= 2; height -= 2) {
  40. d1 = d;
  41. d2 = d + dst->linesize[0];
  42. y2_ptr = y1_ptr + src->linesize[0];
  43. for(w = width; w >= 2; w -= 2) {
  44. YUV_TO_RGB1_CCIR(cb_ptr[0], cr_ptr[0]);
  45. /* output 4 pixels */
  46. YUV_TO_RGB2_CCIR(r, g, b, y1_ptr[0]);
  47. RGB_OUT(d1, r, g, b);
  48. YUV_TO_RGB2_CCIR(r, g, b, y1_ptr[1]);
  49. RGB_OUT(d1 + BPP, r, g, b);
  50. YUV_TO_RGB2_CCIR(r, g, b, y2_ptr[0]);
  51. RGB_OUT(d2, r, g, b);
  52. YUV_TO_RGB2_CCIR(r, g, b, y2_ptr[1]);
  53. RGB_OUT(d2 + BPP, r, g, b);
  54. d1 += 2 * BPP;
  55. d2 += 2 * BPP;
  56. y1_ptr += 2;
  57. y2_ptr += 2;
  58. cb_ptr++;
  59. cr_ptr++;
  60. }
  61. /* handle odd width */
  62. if (w) {
  63. YUV_TO_RGB1_CCIR(cb_ptr[0], cr_ptr[0]);
  64. YUV_TO_RGB2_CCIR(r, g, b, y1_ptr[0]);
  65. RGB_OUT(d1, r, g, b);
  66. YUV_TO_RGB2_CCIR(r, g, b, y2_ptr[0]);
  67. RGB_OUT(d2, r, g, b);
  68. d1 += BPP;
  69. d2 += BPP;
  70. y1_ptr++;
  71. y2_ptr++;
  72. cb_ptr++;
  73. cr_ptr++;
  74. }
  75. d += 2 * dst->linesize[0];
  76. y1_ptr += 2 * src->linesize[0] - width;
  77. cb_ptr += src->linesize[1] - width2;
  78. cr_ptr += src->linesize[2] - width2;
  79. }
  80. /* handle odd height */
  81. if (height) {
  82. d1 = d;
  83. for(w = width; w >= 2; w -= 2) {
  84. YUV_TO_RGB1_CCIR(cb_ptr[0], cr_ptr[0]);
  85. /* output 2 pixels */
  86. YUV_TO_RGB2_CCIR(r, g, b, y1_ptr[0]);
  87. RGB_OUT(d1, r, g, b);
  88. YUV_TO_RGB2_CCIR(r, g, b, y1_ptr[1]);
  89. RGB_OUT(d1 + BPP, r, g, b);
  90. d1 += 2 * BPP;
  91. y1_ptr += 2;
  92. cb_ptr++;
  93. cr_ptr++;
  94. }
  95. /* handle width */
  96. if (w) {
  97. YUV_TO_RGB1_CCIR(cb_ptr[0], cr_ptr[0]);
  98. /* output 2 pixels */
  99. YUV_TO_RGB2_CCIR(r, g, b, y1_ptr[0]);
  100. RGB_OUT(d1, r, g, b);
  101. d1 += BPP;
  102. y1_ptr++;
  103. cb_ptr++;
  104. cr_ptr++;
  105. }
  106. }
  107. }
  108. static void glue(yuvj420p_to_, RGB_NAME)(AVPicture *dst, const AVPicture *src,
  109. int width, int height)
  110. {
  111. const uint8_t *y1_ptr, *y2_ptr, *cb_ptr, *cr_ptr;
  112. uint8_t *d, *d1, *d2;
  113. int w, y, cb, cr, r_add, g_add, b_add, width2;
  114. uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
  115. unsigned int r, g, b;
  116. d = dst->data[0];
  117. y1_ptr = src->data[0];
  118. cb_ptr = src->data[1];
  119. cr_ptr = src->data[2];
  120. width2 = (width + 1) >> 1;
  121. for(;height >= 2; height -= 2) {
  122. d1 = d;
  123. d2 = d + dst->linesize[0];
  124. y2_ptr = y1_ptr + src->linesize[0];
  125. for(w = width; w >= 2; w -= 2) {
  126. YUV_TO_RGB1(cb_ptr[0], cr_ptr[0]);
  127. /* output 4 pixels */
  128. YUV_TO_RGB2(r, g, b, y1_ptr[0]);
  129. RGB_OUT(d1, r, g, b);
  130. YUV_TO_RGB2(r, g, b, y1_ptr[1]);
  131. RGB_OUT(d1 + BPP, r, g, b);
  132. YUV_TO_RGB2(r, g, b, y2_ptr[0]);
  133. RGB_OUT(d2, r, g, b);
  134. YUV_TO_RGB2(r, g, b, y2_ptr[1]);
  135. RGB_OUT(d2 + BPP, r, g, b);
  136. d1 += 2 * BPP;
  137. d2 += 2 * BPP;
  138. y1_ptr += 2;
  139. y2_ptr += 2;
  140. cb_ptr++;
  141. cr_ptr++;
  142. }
  143. /* handle odd width */
  144. if (w) {
  145. YUV_TO_RGB1(cb_ptr[0], cr_ptr[0]);
  146. YUV_TO_RGB2(r, g, b, y1_ptr[0]);
  147. RGB_OUT(d1, r, g, b);
  148. YUV_TO_RGB2(r, g, b, y2_ptr[0]);
  149. RGB_OUT(d2, r, g, b);
  150. d1 += BPP;
  151. d2 += BPP;
  152. y1_ptr++;
  153. y2_ptr++;
  154. cb_ptr++;
  155. cr_ptr++;
  156. }
  157. d += 2 * dst->linesize[0];
  158. y1_ptr += 2 * src->linesize[0] - width;
  159. cb_ptr += src->linesize[1] - width2;
  160. cr_ptr += src->linesize[2] - width2;
  161. }
  162. /* handle odd height */
  163. if (height) {
  164. d1 = d;
  165. for(w = width; w >= 2; w -= 2) {
  166. YUV_TO_RGB1(cb_ptr[0], cr_ptr[0]);
  167. /* output 2 pixels */
  168. YUV_TO_RGB2(r, g, b, y1_ptr[0]);
  169. RGB_OUT(d1, r, g, b);
  170. YUV_TO_RGB2(r, g, b, y1_ptr[1]);
  171. RGB_OUT(d1 + BPP, r, g, b);
  172. d1 += 2 * BPP;
  173. y1_ptr += 2;
  174. cb_ptr++;
  175. cr_ptr++;
  176. }
  177. /* handle width */
  178. if (w) {
  179. YUV_TO_RGB1(cb_ptr[0], cr_ptr[0]);
  180. /* output 2 pixels */
  181. YUV_TO_RGB2(r, g, b, y1_ptr[0]);
  182. RGB_OUT(d1, r, g, b);
  183. d1 += BPP;
  184. y1_ptr++;
  185. cb_ptr++;
  186. cr_ptr++;
  187. }
  188. }
  189. }
  190. static void glue(RGB_NAME, _to_yuv420p)(AVPicture *dst, const AVPicture *src,
  191. int width, int height)
  192. {
  193. int wrap, wrap3, width2;
  194. int r, g, b, r1, g1, b1, w;
  195. uint8_t *lum, *cb, *cr;
  196. const uint8_t *p;
  197. lum = dst->data[0];
  198. cb = dst->data[1];
  199. cr = dst->data[2];
  200. width2 = (width + 1) >> 1;
  201. wrap = dst->linesize[0];
  202. wrap3 = src->linesize[0];
  203. p = src->data[0];
  204. for(;height>=2;height -= 2) {
  205. for(w = width; w >= 2; w -= 2) {
  206. RGB_IN(r, g, b, p);
  207. r1 = r;
  208. g1 = g;
  209. b1 = b;
  210. lum[0] = RGB_TO_Y_CCIR(r, g, b);
  211. RGB_IN(r, g, b, p + BPP);
  212. r1 += r;
  213. g1 += g;
  214. b1 += b;
  215. lum[1] = RGB_TO_Y_CCIR(r, g, b);
  216. p += wrap3;
  217. lum += wrap;
  218. RGB_IN(r, g, b, p);
  219. r1 += r;
  220. g1 += g;
  221. b1 += b;
  222. lum[0] = RGB_TO_Y_CCIR(r, g, b);
  223. RGB_IN(r, g, b, p + BPP);
  224. r1 += r;
  225. g1 += g;
  226. b1 += b;
  227. lum[1] = RGB_TO_Y_CCIR(r, g, b);
  228. cb[0] = RGB_TO_U_CCIR(r1, g1, b1, 2);
  229. cr[0] = RGB_TO_V_CCIR(r1, g1, b1, 2);
  230. cb++;
  231. cr++;
  232. p += -wrap3 + 2 * BPP;
  233. lum += -wrap + 2;
  234. }
  235. if (w) {
  236. RGB_IN(r, g, b, p);
  237. r1 = r;
  238. g1 = g;
  239. b1 = b;
  240. lum[0] = RGB_TO_Y_CCIR(r, g, b);
  241. p += wrap3;
  242. lum += wrap;
  243. RGB_IN(r, g, b, p);
  244. r1 += r;
  245. g1 += g;
  246. b1 += b;
  247. lum[0] = RGB_TO_Y_CCIR(r, g, b);
  248. cb[0] = RGB_TO_U_CCIR(r1, g1, b1, 1);
  249. cr[0] = RGB_TO_V_CCIR(r1, g1, b1, 1);
  250. cb++;
  251. cr++;
  252. p += -wrap3 + BPP;
  253. lum += -wrap + 1;
  254. }
  255. p += wrap3 + (wrap3 - width * BPP);
  256. lum += wrap + (wrap - width);
  257. cb += dst->linesize[1] - width2;
  258. cr += dst->linesize[2] - width2;
  259. }
  260. /* handle odd height */
  261. if (height) {
  262. for(w = width; w >= 2; w -= 2) {
  263. RGB_IN(r, g, b, p);
  264. r1 = r;
  265. g1 = g;
  266. b1 = b;
  267. lum[0] = RGB_TO_Y_CCIR(r, g, b);
  268. RGB_IN(r, g, b, p + BPP);
  269. r1 += r;
  270. g1 += g;
  271. b1 += b;
  272. lum[1] = RGB_TO_Y_CCIR(r, g, b);
  273. cb[0] = RGB_TO_U_CCIR(r1, g1, b1, 1);
  274. cr[0] = RGB_TO_V_CCIR(r1, g1, b1, 1);
  275. cb++;
  276. cr++;
  277. p += 2 * BPP;
  278. lum += 2;
  279. }
  280. if (w) {
  281. RGB_IN(r, g, b, p);
  282. lum[0] = RGB_TO_Y_CCIR(r, g, b);
  283. cb[0] = RGB_TO_U_CCIR(r, g, b, 0);
  284. cr[0] = RGB_TO_V_CCIR(r, g, b, 0);
  285. }
  286. }
  287. }
  288. static void glue(RGB_NAME, _to_gray)(AVPicture *dst, const AVPicture *src,
  289. int width, int height)
  290. {
  291. const unsigned char *p;
  292. unsigned char *q;
  293. int r, g, b, dst_wrap, src_wrap;
  294. int x, y;
  295. p = src->data[0];
  296. src_wrap = src->linesize[0] - BPP * width;
  297. q = dst->data[0];
  298. dst_wrap = dst->linesize[0] - width;
  299. for(y=0;y<height;y++) {
  300. for(x=0;x<width;x++) {
  301. RGB_IN(r, g, b, p);
  302. q[0] = RGB_TO_Y(r, g, b);
  303. q++;
  304. p += BPP;
  305. }
  306. p += src_wrap;
  307. q += dst_wrap;
  308. }
  309. }
  310. static void glue(gray_to_, RGB_NAME)(AVPicture *dst, const AVPicture *src,
  311. int width, int height)
  312. {
  313. const unsigned char *p;
  314. unsigned char *q;
  315. int r, dst_wrap, src_wrap;
  316. int x, y;
  317. p = src->data[0];
  318. src_wrap = src->linesize[0] - width;
  319. q = dst->data[0];
  320. dst_wrap = dst->linesize[0] - BPP * width;
  321. for(y=0;y<height;y++) {
  322. for(x=0;x<width;x++) {
  323. r = p[0];
  324. RGB_OUT(q, r, r, r);
  325. q += BPP;
  326. p ++;
  327. }
  328. p += src_wrap;
  329. q += dst_wrap;
  330. }
  331. }
  332. static void glue(pal8_to_, RGB_NAME)(AVPicture *dst, const AVPicture *src,
  333. int width, int height)
  334. {
  335. const unsigned char *p;
  336. unsigned char *q;
  337. int r, g, b, dst_wrap, src_wrap;
  338. int x, y;
  339. uint32_t v;
  340. const uint32_t *palette;
  341. p = src->data[0];
  342. src_wrap = src->linesize[0] - width;
  343. palette = (uint32_t *)src->data[1];
  344. q = dst->data[0];
  345. dst_wrap = dst->linesize[0] - BPP * width;
  346. for(y=0;y<height;y++) {
  347. for(x=0;x<width;x++) {
  348. v = palette[p[0]];
  349. r = (v >> 16) & 0xff;
  350. g = (v >> 8) & 0xff;
  351. b = (v) & 0xff;
  352. #ifdef RGBA_OUT
  353. {
  354. int a;
  355. a = (v >> 24) & 0xff;
  356. RGBA_OUT(q, r, g, b, a);
  357. }
  358. #else
  359. RGB_OUT(q, r, g, b);
  360. #endif
  361. q += BPP;
  362. p ++;
  363. }
  364. p += src_wrap;
  365. q += dst_wrap;
  366. }
  367. }
  368. // RGB24 has optimised routines
  369. #if !defined(FMT_RGB32) && !defined(FMT_RGB24)
  370. /* alpha support */
  371. static void glue(rgb32_to_, RGB_NAME)(AVPicture *dst, const AVPicture *src,
  372. int width, int height)
  373. {
  374. const uint8_t *s;
  375. uint8_t *d;
  376. int src_wrap, dst_wrap, j, y;
  377. unsigned int v, r, g, b;
  378. #ifdef RGBA_OUT
  379. unsigned int a;
  380. #endif
  381. s = src->data[0];
  382. src_wrap = src->linesize[0] - width * 4;
  383. d = dst->data[0];
  384. dst_wrap = dst->linesize[0] - width * BPP;
  385. for(y=0;y<height;y++) {
  386. for(j = 0;j < width; j++) {
  387. v = ((const uint32_t *)(s))[0];
  388. r = (v >> 16) & 0xff;
  389. g = (v >> 8) & 0xff;
  390. b = v & 0xff;
  391. #ifdef RGBA_OUT
  392. a = (v >> 24) & 0xff;
  393. RGBA_OUT(d, r, g, b, a);
  394. #else
  395. RGB_OUT(d, r, g, b);
  396. #endif
  397. s += 4;
  398. d += BPP;
  399. }
  400. s += src_wrap;
  401. d += dst_wrap;
  402. }
  403. }
  404. static void glue(RGB_NAME, _to_rgb32)(AVPicture *dst, const AVPicture *src,
  405. int width, int height)
  406. {
  407. const uint8_t *s;
  408. uint8_t *d;
  409. int src_wrap, dst_wrap, j, y;
  410. unsigned int r, g, b;
  411. #ifdef RGBA_IN
  412. unsigned int a;
  413. #endif
  414. s = src->data[0];
  415. src_wrap = src->linesize[0] - width * BPP;
  416. d = dst->data[0];
  417. dst_wrap = dst->linesize[0] - width * 4;
  418. for(y=0;y<height;y++) {
  419. for(j = 0;j < width; j++) {
  420. #ifdef RGBA_IN
  421. RGBA_IN(r, g, b, a, s);
  422. ((uint32_t *)(d))[0] = (a << 24) | (r << 16) | (g << 8) | b;
  423. #else
  424. RGB_IN(r, g, b, s);
  425. ((uint32_t *)(d))[0] = (0xff << 24) | (r << 16) | (g << 8) | b;
  426. #endif
  427. d += 4;
  428. s += BPP;
  429. }
  430. s += src_wrap;
  431. d += dst_wrap;
  432. }
  433. }
  434. #endif /* !defined(FMT_RGB32) */
  435. #ifndef FMT_RGB24
  436. static void glue(rgb24_to_, RGB_NAME)(AVPicture *dst, const AVPicture *src,
  437. int width, int height)
  438. {
  439. const uint8_t *s;
  440. uint8_t *d;
  441. int src_wrap, dst_wrap, j, y;
  442. unsigned int r, g, b;
  443. s = src->data[0];
  444. src_wrap = src->linesize[0] - width * 3;
  445. d = dst->data[0];
  446. dst_wrap = dst->linesize[0] - width * BPP;
  447. for(y=0;y<height;y++) {
  448. for(j = 0;j < width; j++) {
  449. r = s[0];
  450. g = s[1];
  451. b = s[2];
  452. RGB_OUT(d, r, g, b);
  453. s += 3;
  454. d += BPP;
  455. }
  456. s += src_wrap;
  457. d += dst_wrap;
  458. }
  459. }
  460. static void glue(RGB_NAME, _to_rgb24)(AVPicture *dst, const AVPicture *src,
  461. int width, int height)
  462. {
  463. const uint8_t *s;
  464. uint8_t *d;
  465. int src_wrap, dst_wrap, j, y;
  466. unsigned int r, g , b;
  467. s = src->data[0];
  468. src_wrap = src->linesize[0] - width * BPP;
  469. d = dst->data[0];
  470. dst_wrap = dst->linesize[0] - width * 3;
  471. for(y=0;y<height;y++) {
  472. for(j = 0;j < width; j++) {
  473. RGB_IN(r, g, b, s)
  474. d[0] = r;
  475. d[1] = g;
  476. d[2] = b;
  477. d += 3;
  478. s += BPP;
  479. }
  480. s += src_wrap;
  481. d += dst_wrap;
  482. }
  483. }
  484. #endif /* !FMT_RGB24 */
  485. #ifdef FMT_RGB24
  486. static void yuv444p_to_rgb24(AVPicture *dst, const AVPicture *src,
  487. int width, int height)
  488. {
  489. const uint8_t *y1_ptr, *cb_ptr, *cr_ptr;
  490. uint8_t *d, *d1;
  491. int w, y, cb, cr, r_add, g_add, b_add;
  492. uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
  493. unsigned int r, g, b;
  494. d = dst->data[0];
  495. y1_ptr = src->data[0];
  496. cb_ptr = src->data[1];
  497. cr_ptr = src->data[2];
  498. for(;height > 0; height --) {
  499. d1 = d;
  500. for(w = width; w > 0; w--) {
  501. YUV_TO_RGB1_CCIR(cb_ptr[0], cr_ptr[0]);
  502. YUV_TO_RGB2_CCIR(r, g, b, y1_ptr[0]);
  503. RGB_OUT(d1, r, g, b);
  504. d1 += BPP;
  505. y1_ptr++;
  506. cb_ptr++;
  507. cr_ptr++;
  508. }
  509. d += dst->linesize[0];
  510. y1_ptr += src->linesize[0] - width;
  511. cb_ptr += src->linesize[1] - width;
  512. cr_ptr += src->linesize[2] - width;
  513. }
  514. }
  515. static void yuvj444p_to_rgb24(AVPicture *dst, const AVPicture *src,
  516. int width, int height)
  517. {
  518. const uint8_t *y1_ptr, *cb_ptr, *cr_ptr;
  519. uint8_t *d, *d1;
  520. int w, y, cb, cr, r_add, g_add, b_add;
  521. uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
  522. unsigned int r, g, b;
  523. d = dst->data[0];
  524. y1_ptr = src->data[0];
  525. cb_ptr = src->data[1];
  526. cr_ptr = src->data[2];
  527. for(;height > 0; height --) {
  528. d1 = d;
  529. for(w = width; w > 0; w--) {
  530. YUV_TO_RGB1(cb_ptr[0], cr_ptr[0]);
  531. YUV_TO_RGB2(r, g, b, y1_ptr[0]);
  532. RGB_OUT(d1, r, g, b);
  533. d1 += BPP;
  534. y1_ptr++;
  535. cb_ptr++;
  536. cr_ptr++;
  537. }
  538. d += dst->linesize[0];
  539. y1_ptr += src->linesize[0] - width;
  540. cb_ptr += src->linesize[1] - width;
  541. cr_ptr += src->linesize[2] - width;
  542. }
  543. }
  544. static void rgb24_to_yuv444p(AVPicture *dst, const AVPicture *src,
  545. int width, int height)
  546. {
  547. int src_wrap, x, y;
  548. int r, g, b;
  549. uint8_t *lum, *cb, *cr;
  550. const uint8_t *p;
  551. lum = dst->data[0];
  552. cb = dst->data[1];
  553. cr = dst->data[2];
  554. src_wrap = src->linesize[0] - width * BPP;
  555. p = src->data[0];
  556. for(y=0;y<height;y++) {
  557. for(x=0;x<width;x++) {
  558. RGB_IN(r, g, b, p);
  559. lum[0] = RGB_TO_Y_CCIR(r, g, b);
  560. cb[0] = RGB_TO_U_CCIR(r, g, b, 0);
  561. cr[0] = RGB_TO_V_CCIR(r, g, b, 0);
  562. p += BPP;
  563. cb++;
  564. cr++;
  565. lum++;
  566. }
  567. p += src_wrap;
  568. lum += dst->linesize[0] - width;
  569. cb += dst->linesize[1] - width;
  570. cr += dst->linesize[2] - width;
  571. }
  572. }
  573. static void rgb24_to_yuvj420p(AVPicture *dst, const AVPicture *src,
  574. int width, int height)
  575. {
  576. int wrap, wrap3, width2;
  577. int r, g, b, r1, g1, b1, w;
  578. uint8_t *lum, *cb, *cr;
  579. const uint8_t *p;
  580. lum = dst->data[0];
  581. cb = dst->data[1];
  582. cr = dst->data[2];
  583. width2 = (width + 1) >> 1;
  584. wrap = dst->linesize[0];
  585. wrap3 = src->linesize[0];
  586. p = src->data[0];
  587. for(;height>=2;height -= 2) {
  588. for(w = width; w >= 2; w -= 2) {
  589. RGB_IN(r, g, b, p);
  590. r1 = r;
  591. g1 = g;
  592. b1 = b;
  593. lum[0] = RGB_TO_Y(r, g, b);
  594. RGB_IN(r, g, b, p + BPP);
  595. r1 += r;
  596. g1 += g;
  597. b1 += b;
  598. lum[1] = RGB_TO_Y(r, g, b);
  599. p += wrap3;
  600. lum += wrap;
  601. RGB_IN(r, g, b, p);
  602. r1 += r;
  603. g1 += g;
  604. b1 += b;
  605. lum[0] = RGB_TO_Y(r, g, b);
  606. RGB_IN(r, g, b, p + BPP);
  607. r1 += r;
  608. g1 += g;
  609. b1 += b;
  610. lum[1] = RGB_TO_Y(r, g, b);
  611. cb[0] = RGB_TO_U(r1, g1, b1, 2);
  612. cr[0] = RGB_TO_V(r1, g1, b1, 2);
  613. cb++;
  614. cr++;
  615. p += -wrap3 + 2 * BPP;
  616. lum += -wrap + 2;
  617. }
  618. if (w) {
  619. RGB_IN(r, g, b, p);
  620. r1 = r;
  621. g1 = g;
  622. b1 = b;
  623. lum[0] = RGB_TO_Y(r, g, b);
  624. p += wrap3;
  625. lum += wrap;
  626. RGB_IN(r, g, b, p);
  627. r1 += r;
  628. g1 += g;
  629. b1 += b;
  630. lum[0] = RGB_TO_Y(r, g, b);
  631. cb[0] = RGB_TO_U(r1, g1, b1, 1);
  632. cr[0] = RGB_TO_V(r1, g1, b1, 1);
  633. cb++;
  634. cr++;
  635. p += -wrap3 + BPP;
  636. lum += -wrap + 1;
  637. }
  638. p += wrap3 + (wrap3 - width * BPP);
  639. lum += wrap + (wrap - width);
  640. cb += dst->linesize[1] - width2;
  641. cr += dst->linesize[2] - width2;
  642. }
  643. /* handle odd height */
  644. if (height) {
  645. for(w = width; w >= 2; w -= 2) {
  646. RGB_IN(r, g, b, p);
  647. r1 = r;
  648. g1 = g;
  649. b1 = b;
  650. lum[0] = RGB_TO_Y(r, g, b);
  651. RGB_IN(r, g, b, p + BPP);
  652. r1 += r;
  653. g1 += g;
  654. b1 += b;
  655. lum[1] = RGB_TO_Y(r, g, b);
  656. cb[0] = RGB_TO_U(r1, g1, b1, 1);
  657. cr[0] = RGB_TO_V(r1, g1, b1, 1);
  658. cb++;
  659. cr++;
  660. p += 2 * BPP;
  661. lum += 2;
  662. }
  663. if (w) {
  664. RGB_IN(r, g, b, p);
  665. lum[0] = RGB_TO_Y(r, g, b);
  666. cb[0] = RGB_TO_U(r, g, b, 0);
  667. cr[0] = RGB_TO_V(r, g, b, 0);
  668. }
  669. }
  670. }
  671. static void rgb24_to_yuvj444p(AVPicture *dst, const AVPicture *src,
  672. int width, int height)
  673. {
  674. int src_wrap, x, y;
  675. int r, g, b;
  676. uint8_t *lum, *cb, *cr;
  677. const uint8_t *p;
  678. lum = dst->data[0];
  679. cb = dst->data[1];
  680. cr = dst->data[2];
  681. src_wrap = src->linesize[0] - width * BPP;
  682. p = src->data[0];
  683. for(y=0;y<height;y++) {
  684. for(x=0;x<width;x++) {
  685. RGB_IN(r, g, b, p);
  686. lum[0] = RGB_TO_Y(r, g, b);
  687. cb[0] = RGB_TO_U(r, g, b, 0);
  688. cr[0] = RGB_TO_V(r, g, b, 0);
  689. p += BPP;
  690. cb++;
  691. cr++;
  692. lum++;
  693. }
  694. p += src_wrap;
  695. lum += dst->linesize[0] - width;
  696. cb += dst->linesize[1] - width;
  697. cr += dst->linesize[2] - width;
  698. }
  699. }
  700. #endif /* FMT_RGB24 */
  701. #if defined(FMT_RGB24) || defined(FMT_RGB32)
  702. static void glue(RGB_NAME, _to_pal8)(AVPicture *dst, const AVPicture *src,
  703. int width, int height)
  704. {
  705. const unsigned char *p;
  706. unsigned char *q;
  707. int dst_wrap, src_wrap;
  708. int x, y, has_alpha;
  709. unsigned int r, g, b;
  710. p = src->data[0];
  711. src_wrap = src->linesize[0] - BPP * width;
  712. q = dst->data[0];
  713. dst_wrap = dst->linesize[0] - width;
  714. has_alpha = 0;
  715. for(y=0;y<height;y++) {
  716. for(x=0;x<width;x++) {
  717. #ifdef RGBA_IN
  718. {
  719. unsigned int a;
  720. RGBA_IN(r, g, b, a, p);
  721. /* crude approximation for alpha ! */
  722. if (a < 0x80) {
  723. has_alpha = 1;
  724. q[0] = TRANSP_INDEX;
  725. } else {
  726. q[0] = gif_clut_index(r, g, b);
  727. }
  728. }
  729. #else
  730. RGB_IN(r, g, b, p);
  731. q[0] = gif_clut_index(r, g, b);
  732. #endif
  733. q++;
  734. p += BPP;
  735. }
  736. p += src_wrap;
  737. q += dst_wrap;
  738. }
  739. build_rgb_palette(dst->data[1], has_alpha);
  740. }
  741. #endif /* defined(FMT_RGB24) || defined(FMT_RGB32) */
  742. #ifdef RGBA_IN
  743. static int glue(get_alpha_info_, RGB_NAME)(const AVPicture *src,
  744. int width, int height)
  745. {
  746. const unsigned char *p;
  747. int src_wrap, ret, x, y;
  748. unsigned int r, g, b, a;
  749. p = src->data[0];
  750. src_wrap = src->linesize[0] - BPP * width;
  751. ret = 0;
  752. for(y=0;y<height;y++) {
  753. for(x=0;x<width;x++) {
  754. RGBA_IN(r, g, b, a, p);
  755. if (a == 0x00) {
  756. ret |= FF_ALPHA_TRANSP;
  757. } else if (a != 0xff) {
  758. ret |= FF_ALPHA_SEMI_TRANSP;
  759. }
  760. p += BPP;
  761. }
  762. p += src_wrap;
  763. }
  764. return ret;
  765. }
  766. #endif /* RGBA_IN */
  767. #undef RGB_IN
  768. #undef RGBA_IN
  769. #undef RGB_OUT
  770. #undef RGBA_OUT
  771. #undef BPP
  772. #undef RGB_NAME
  773. #undef FMT_RGB24
  774. #undef FMT_RGB32