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.

858 lines
22KB

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