imgconvert_template.h 22 KB

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