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.

853 lines
21KB

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