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