comparison imgconvert.c @ 1064:b32afefe7d33 libavcodec

* UINTX -> uintx_t INTX -> intx_t
author kabi
date Tue, 11 Feb 2003 16:35:48 +0000
parents bb5de8a59da8
children 4bc02fcf4d8c
comparison
equal deleted inserted replaced
1063:fdeac9642346 1064:b32afefe7d33
27 #include "i386/mmx.h" 27 #include "i386/mmx.h"
28 #endif 28 #endif
29 29
30 typedef struct PixFmtInfo { 30 typedef struct PixFmtInfo {
31 const char *name; 31 const char *name;
32 UINT8 nb_components; /* number of components in AVPicture array */ 32 uint8_t nb_components; /* number of components in AVPicture array */
33 UINT8 is_yuv : 1; /* true if YUV instead of RGB color space */ 33 uint8_t is_yuv : 1; /* true if YUV instead of RGB color space */
34 UINT8 is_packed : 1; /* true if multiple components in same word */ 34 uint8_t is_packed : 1; /* true if multiple components in same word */
35 UINT8 is_paletted : 1; /* true if paletted */ 35 uint8_t is_paletted : 1; /* true if paletted */
36 UINT8 is_alpha : 1; /* true if alpha can be specified */ 36 uint8_t is_alpha : 1; /* true if alpha can be specified */
37 UINT8 is_gray : 1; /* true if gray or monochrome format */ 37 uint8_t is_gray : 1; /* true if gray or monochrome format */
38 UINT8 x_chroma_shift; /* X chroma subsampling factor is 2 ^ shift */ 38 uint8_t x_chroma_shift; /* X chroma subsampling factor is 2 ^ shift */
39 UINT8 y_chroma_shift; /* Y chroma subsampling factor is 2 ^ shift */ 39 uint8_t y_chroma_shift; /* Y chroma subsampling factor is 2 ^ shift */
40 } PixFmtInfo; 40 } PixFmtInfo;
41 41
42 /* this table gives more information about formats */ 42 /* this table gives more information about formats */
43 static PixFmtInfo pix_fmt_info[PIX_FMT_NB] = { 43 static PixFmtInfo pix_fmt_info[PIX_FMT_NB] = {
44 /* YUV formats */ 44 /* YUV formats */
134 else 134 else
135 return pix_fmt_info[pix_fmt].name; 135 return pix_fmt_info[pix_fmt].name;
136 } 136 }
137 137
138 /* Picture field are filled with 'ptr' addresses. Also return size */ 138 /* Picture field are filled with 'ptr' addresses. Also return size */
139 int avpicture_fill(AVPicture *picture, UINT8 *ptr, 139 int avpicture_fill(AVPicture *picture, uint8_t *ptr,
140 int pix_fmt, int width, int height) 140 int pix_fmt, int width, int height)
141 { 141 {
142 int size, w2, h2, size2; 142 int size, w2, h2, size2;
143 PixFmtInfo *pinfo; 143 PixFmtInfo *pinfo;
144 144
221 /* XXX: totally non optimized */ 221 /* XXX: totally non optimized */
222 222
223 static void yuv422_to_yuv420p(AVPicture *dst, AVPicture *src, 223 static void yuv422_to_yuv420p(AVPicture *dst, AVPicture *src,
224 int width, int height) 224 int width, int height)
225 { 225 {
226 UINT8 *lum, *cb, *cr; 226 uint8_t *lum, *cb, *cr;
227 int x, y; 227 int x, y;
228 const UINT8 *p; 228 const uint8_t *p;
229 229
230 lum = dst->data[0]; 230 lum = dst->data[0];
231 cb = dst->data[1]; 231 cb = dst->data[1];
232 cr = dst->data[2]; 232 cr = dst->data[2];
233 p = src->data[0]; 233 p = src->data[0];
256 #define ONE_HALF (1 << (SCALEBITS - 1)) 256 #define ONE_HALF (1 << (SCALEBITS - 1))
257 #define FIX(x) ((int) ((x) * (1L<<SCALEBITS) + 0.5)) 257 #define FIX(x) ((int) ((x) * (1L<<SCALEBITS) + 0.5))
258 258
259 /* XXX: use generic filter ? */ 259 /* XXX: use generic filter ? */
260 /* 1x2 -> 1x1 */ 260 /* 1x2 -> 1x1 */
261 static void shrink2(UINT8 *dst, int dst_wrap, 261 static void shrink2(uint8_t *dst, int dst_wrap,
262 UINT8 *src, int src_wrap, 262 uint8_t *src, int src_wrap,
263 int width, int height) 263 int width, int height)
264 { 264 {
265 int w; 265 int w;
266 UINT8 *s1, *s2, *d; 266 uint8_t *s1, *s2, *d;
267 267
268 for(;height > 0; height--) { 268 for(;height > 0; height--) {
269 s1 = src; 269 s1 = src;
270 s2 = s1 + src_wrap; 270 s2 = s1 + src_wrap;
271 d = dst; 271 d = dst;
288 dst += dst_wrap; 288 dst += dst_wrap;
289 } 289 }
290 } 290 }
291 291
292 /* 2x2 -> 1x1 */ 292 /* 2x2 -> 1x1 */
293 static void shrink22(UINT8 *dst, int dst_wrap, 293 static void shrink22(uint8_t *dst, int dst_wrap,
294 UINT8 *src, int src_wrap, 294 uint8_t *src, int src_wrap,
295 int width, int height) 295 int width, int height)
296 { 296 {
297 int w; 297 int w;
298 UINT8 *s1, *s2, *d; 298 uint8_t *s1, *s2, *d;
299 299
300 for(;height > 0; height--) { 300 for(;height > 0; height--) {
301 s1 = src; 301 s1 = src;
302 s2 = s1 + src_wrap; 302 s2 = s1 + src_wrap;
303 d = dst; 303 d = dst;
320 dst += dst_wrap; 320 dst += dst_wrap;
321 } 321 }
322 } 322 }
323 323
324 /* 1x1 -> 2x2 */ 324 /* 1x1 -> 2x2 */
325 static void grow22(UINT8 *dst, int dst_wrap, 325 static void grow22(uint8_t *dst, int dst_wrap,
326 UINT8 *src, int src_wrap, 326 uint8_t *src, int src_wrap,
327 int width, int height) 327 int width, int height)
328 { 328 {
329 int w; 329 int w;
330 UINT8 *s1, *d; 330 uint8_t *s1, *d;
331 331
332 for(;height > 0; height--) { 332 for(;height > 0; height--) {
333 s1 = src; 333 s1 = src;
334 d = dst; 334 d = dst;
335 for(w = width;w >= 4; w-=4) { 335 for(w = width;w >= 4; w-=4) {
348 dst += dst_wrap; 348 dst += dst_wrap;
349 } 349 }
350 } 350 }
351 351
352 /* 1x2 -> 2x1 */ 352 /* 1x2 -> 2x1 */
353 static void conv411(UINT8 *dst, int dst_wrap, 353 static void conv411(uint8_t *dst, int dst_wrap,
354 UINT8 *src, int src_wrap, 354 uint8_t *src, int src_wrap,
355 int width, int height) 355 int width, int height)
356 { 356 {
357 int w, c; 357 int w, c;
358 UINT8 *s1, *s2, *d; 358 uint8_t *s1, *s2, *d;
359 359
360 for(;height > 0; height--) { 360 for(;height > 0; height--) {
361 s1 = src; 361 s1 = src;
362 s2 = src + src_wrap; 362 s2 = src + src_wrap;
363 d = dst; 363 d = dst;
372 src += src_wrap * 2; 372 src += src_wrap * 2;
373 dst += dst_wrap; 373 dst += dst_wrap;
374 } 374 }
375 } 375 }
376 376
377 static void img_copy(UINT8 *dst, int dst_wrap, 377 static void img_copy(uint8_t *dst, int dst_wrap,
378 UINT8 *src, int src_wrap, 378 uint8_t *src, int src_wrap,
379 int width, int height) 379 int width, int height)
380 { 380 {
381 for(;height > 0; height--) { 381 for(;height > 0; height--) {
382 memcpy(dst, src, width); 382 memcpy(dst, src, width);
383 dst += dst_wrap; 383 dst += dst_wrap;
405 #define RGB_FUNCTIONS(rgb_name) \ 405 #define RGB_FUNCTIONS(rgb_name) \
406 \ 406 \
407 static void yuv420p_to_ ## rgb_name (AVPicture *dst, AVPicture *src, \ 407 static void yuv420p_to_ ## rgb_name (AVPicture *dst, AVPicture *src, \
408 int width, int height) \ 408 int width, int height) \
409 { \ 409 { \
410 UINT8 *y1_ptr, *y2_ptr, *cb_ptr, *cr_ptr, *d, *d1, *d2; \ 410 uint8_t *y1_ptr, *y2_ptr, *cb_ptr, *cr_ptr, *d, *d1, *d2; \
411 int w, y, cb, cr, r_add, g_add, b_add, width2; \ 411 int w, y, cb, cr, r_add, g_add, b_add, width2; \
412 UINT8 *cm = cropTbl + MAX_NEG_CROP; \ 412 uint8_t *cm = cropTbl + MAX_NEG_CROP; \
413 unsigned int r, g, b; \ 413 unsigned int r, g, b; \
414 \ 414 \
415 d = dst->data[0]; \ 415 d = dst->data[0]; \
416 y1_ptr = src->data[0]; \ 416 y1_ptr = src->data[0]; \
417 cb_ptr = src->data[1]; \ 417 cb_ptr = src->data[1]; \
519 \ 519 \
520 /* XXX: no chroma interpolating is done */ \ 520 /* XXX: no chroma interpolating is done */ \
521 static void yuv422p_to_ ## rgb_name (AVPicture *dst, AVPicture *src, \ 521 static void yuv422p_to_ ## rgb_name (AVPicture *dst, AVPicture *src, \
522 int width, int height) \ 522 int width, int height) \
523 { \ 523 { \
524 UINT8 *y1_ptr, *cb_ptr, *cr_ptr, *d, *d1; \ 524 uint8_t *y1_ptr, *cb_ptr, *cr_ptr, *d, *d1; \
525 int w, y, cb, cr, r_add, g_add, b_add, width2; \ 525 int w, y, cb, cr, r_add, g_add, b_add, width2; \
526 UINT8 *cm = cropTbl + MAX_NEG_CROP; \ 526 uint8_t *cm = cropTbl + MAX_NEG_CROP; \
527 unsigned int r, g, b; \ 527 unsigned int r, g, b; \
528 \ 528 \
529 d = dst->data[0]; \ 529 d = dst->data[0]; \
530 y1_ptr = src->data[0]; \ 530 y1_ptr = src->data[0]; \
531 cb_ptr = src->data[1]; \ 531 cb_ptr = src->data[1]; \
580 static void rgb_name ## _to_yuv420p(AVPicture *dst, AVPicture *src, \ 580 static void rgb_name ## _to_yuv420p(AVPicture *dst, AVPicture *src, \
581 int width, int height) \ 581 int width, int height) \
582 { \ 582 { \
583 int wrap, wrap3, x, y; \ 583 int wrap, wrap3, x, y; \
584 int r, g, b, r1, g1, b1; \ 584 int r, g, b, r1, g1, b1; \
585 UINT8 *lum, *cb, *cr; \ 585 uint8_t *lum, *cb, *cr; \
586 const UINT8 *p; \ 586 const uint8_t *p; \
587 \ 587 \
588 lum = dst->data[0]; \ 588 lum = dst->data[0]; \
589 cb = dst->data[1]; \ 589 cb = dst->data[1]; \
590 cr = dst->data[2]; \ 590 cr = dst->data[2]; \
591 \ 591 \
737 737
738 /* rgb555 handling */ 738 /* rgb555 handling */
739 739
740 #define RGB_IN(r, g, b, s)\ 740 #define RGB_IN(r, g, b, s)\
741 {\ 741 {\
742 unsigned int v = ((const UINT16 *)(s))[0];\ 742 unsigned int v = ((const uint16_t *)(s))[0];\
743 r = bitcopy_n(v >> (10 - 3), 3);\ 743 r = bitcopy_n(v >> (10 - 3), 3);\
744 g = bitcopy_n(v >> (5 - 3), 3);\ 744 g = bitcopy_n(v >> (5 - 3), 3);\
745 b = bitcopy_n(v << 3, 3);\ 745 b = bitcopy_n(v << 3, 3);\
746 } 746 }
747 747
748 #define RGB_OUT(d, r, g, b)\ 748 #define RGB_OUT(d, r, g, b)\
749 {\ 749 {\
750 ((UINT16 *)(d))[0] = ((r >> 3) << 10) | ((g >> 3) << 5) | (b >> 3) | 0x8000;\ 750 ((uint16_t *)(d))[0] = ((r >> 3) << 10) | ((g >> 3) << 5) | (b >> 3) | 0x8000;\
751 } 751 }
752 752
753 #define BPP 2 753 #define BPP 2
754 754
755 RGB_FUNCTIONS(rgb555) 755 RGB_FUNCTIONS(rgb555)
760 760
761 /* rgb565 handling */ 761 /* rgb565 handling */
762 762
763 #define RGB_IN(r, g, b, s)\ 763 #define RGB_IN(r, g, b, s)\
764 {\ 764 {\
765 unsigned int v = ((const UINT16 *)(s))[0];\ 765 unsigned int v = ((const uint16_t *)(s))[0];\
766 r = bitcopy_n(v >> (11 - 3), 3);\ 766 r = bitcopy_n(v >> (11 - 3), 3);\
767 g = bitcopy_n(v >> (5 - 2), 2);\ 767 g = bitcopy_n(v >> (5 - 2), 2);\
768 b = bitcopy_n(v << 3, 3);\ 768 b = bitcopy_n(v << 3, 3);\
769 } 769 }
770 770
771 #define RGB_OUT(d, r, g, b)\ 771 #define RGB_OUT(d, r, g, b)\
772 {\ 772 {\
773 ((UINT16 *)(d))[0] = ((r >> 3) << 11) | ((g >> 2) << 5) | (b >> 3);\ 773 ((uint16_t *)(d))[0] = ((r >> 3) << 11) | ((g >> 2) << 5) | (b >> 3);\
774 } 774 }
775 775
776 #define BPP 2 776 #define BPP 2
777 777
778 RGB_FUNCTIONS(rgb565) 778 RGB_FUNCTIONS(rgb565)
831 831
832 /* rgba32 handling */ 832 /* rgba32 handling */
833 833
834 #define RGB_IN(r, g, b, s)\ 834 #define RGB_IN(r, g, b, s)\
835 {\ 835 {\
836 unsigned int v = ((const UINT32 *)(s))[0];\ 836 unsigned int v = ((const uint32_t *)(s))[0];\
837 r = (v >> 16) & 0xff;\ 837 r = (v >> 16) & 0xff;\
838 g = (v >> 8) & 0xff;\ 838 g = (v >> 8) & 0xff;\
839 b = v & 0xff;\ 839 b = v & 0xff;\
840 } 840 }
841 841
842 #define RGB_OUT(d, r, g, b)\ 842 #define RGB_OUT(d, r, g, b)\
843 {\ 843 {\
844 ((UINT32 *)(d))[0] = (0xff << 24) | (r << 16) | (g << 8) | b;\ 844 ((uint32_t *)(d))[0] = (0xff << 24) | (r << 16) | (g << 8) | b;\
845 } 845 }
846 846
847 #define BPP 4 847 #define BPP 4
848 848
849 RGB_FUNCTIONS(rgba32) 849 RGB_FUNCTIONS(rgba32)
969 969
970 static void gray_to_mono(AVPicture *dst, AVPicture *src, 970 static void gray_to_mono(AVPicture *dst, AVPicture *src,
971 int width, int height, int xor_mask) 971 int width, int height, int xor_mask)
972 { 972 {
973 int n; 973 int n;
974 const UINT8 *s; 974 const uint8_t *s;
975 UINT8 *d; 975 uint8_t *d;
976 int j, b, v, n1, src_wrap, dst_wrap, y; 976 int j, b, v, n1, src_wrap, dst_wrap, y;
977 977
978 s = src->data[0]; 978 s = src->data[0];
979 src_wrap = src->linesize[0] - width; 979 src_wrap = src->linesize[0] - width;
980 980
1023 { 1023 {
1024 gray_to_mono(dst, src, width, height, 0x00); 1024 gray_to_mono(dst, src, width, height, 0x00);
1025 } 1025 }
1026 1026
1027 /* this is maybe slow, but allows for extensions */ 1027 /* this is maybe slow, but allows for extensions */
1028 static inline unsigned char gif_clut_index(UINT8 r, UINT8 g, UINT8 b) 1028 static inline unsigned char gif_clut_index(uint8_t r, uint8_t g, uint8_t b)
1029 { 1029 {
1030 return ((((r)/47)%6)*6*6+(((g)/47)%6)*6+(((b)/47)%6)); 1030 return ((((r)/47)%6)*6*6+(((g)/47)%6)*6+(((b)/47)%6));
1031 } 1031 }
1032 1032
1033 /* XXX: put jpeg quantize code instead */ 1033 /* XXX: put jpeg quantize code instead */
1328 } 1328 }
1329 1329
1330 /* YUV to YUV */ 1330 /* YUV to YUV */
1331 if (dst_pix->is_yuv && src_pix->is_yuv) { 1331 if (dst_pix->is_yuv && src_pix->is_yuv) {
1332 int x_shift, y_shift, w, h; 1332 int x_shift, y_shift, w, h;
1333 void (*resize_func)(UINT8 *dst, int dst_wrap, 1333 void (*resize_func)(uint8_t *dst, int dst_wrap,
1334 UINT8 *src, int src_wrap, 1334 uint8_t *src, int src_wrap,
1335 int width, int height); 1335 int width, int height);
1336 1336
1337 /* compute chroma size of the smallest dimensions */ 1337 /* compute chroma size of the smallest dimensions */
1338 w = dst_width; 1338 w = dst_width;
1339 h = dst_height; 1339 h = dst_height;
1445 packuswb_r2r(mm7,mm1);\ 1445 packuswb_r2r(mm7,mm1);\
1446 movd_r2m(mm1,dst[0]); 1446 movd_r2m(mm1,dst[0]);
1447 #endif 1447 #endif
1448 1448
1449 /* filter parameters: [-1 4 2 4 -1] // 8 */ 1449 /* filter parameters: [-1 4 2 4 -1] // 8 */
1450 static void deinterlace_line(UINT8 *dst, UINT8 *lum_m4, UINT8 *lum_m3, UINT8 *lum_m2, UINT8 *lum_m1, UINT8 *lum, 1450 static void deinterlace_line(uint8_t *dst, uint8_t *lum_m4, uint8_t *lum_m3, uint8_t *lum_m2, uint8_t *lum_m1, uint8_t *lum,
1451 int size) 1451 int size)
1452 { 1452 {
1453 #ifndef HAVE_MMX 1453 #ifndef HAVE_MMX
1454 UINT8 *cm = cropTbl + MAX_NEG_CROP; 1454 uint8_t *cm = cropTbl + MAX_NEG_CROP;
1455 int sum; 1455 int sum;
1456 1456
1457 for(;size > 0;size--) { 1457 for(;size > 0;size--) {
1458 sum = -lum_m4[0]; 1458 sum = -lum_m4[0];
1459 sum += lum_m3[0] << 2; 1459 sum += lum_m3[0] << 2;
1488 lum+=4; 1488 lum+=4;
1489 dst+=4; 1489 dst+=4;
1490 } 1490 }
1491 #endif 1491 #endif
1492 } 1492 }
1493 static void deinterlace_line_inplace(UINT8 *lum_m4, UINT8 *lum_m3, UINT8 *lum_m2, UINT8 *lum_m1, UINT8 *lum, 1493 static void deinterlace_line_inplace(uint8_t *lum_m4, uint8_t *lum_m3, uint8_t *lum_m2, uint8_t *lum_m1, uint8_t *lum,
1494 int size) 1494 int size)
1495 { 1495 {
1496 #ifndef HAVE_MMX 1496 #ifndef HAVE_MMX
1497 UINT8 *cm = cropTbl + MAX_NEG_CROP; 1497 uint8_t *cm = cropTbl + MAX_NEG_CROP;
1498 int sum; 1498 int sum;
1499 1499
1500 for(;size > 0;size--) { 1500 for(;size > 0;size--) {
1501 sum = -lum_m4[0]; 1501 sum = -lum_m4[0];
1502 sum += lum_m3[0] << 2; 1502 sum += lum_m3[0] << 2;
1534 } 1534 }
1535 1535
1536 /* deinterlacing : 2 temporal taps, 3 spatial taps linear filter. The 1536 /* deinterlacing : 2 temporal taps, 3 spatial taps linear filter. The
1537 top field is copied as is, but the bottom field is deinterlaced 1537 top field is copied as is, but the bottom field is deinterlaced
1538 against the top field. */ 1538 against the top field. */
1539 static void deinterlace_bottom_field(UINT8 *dst, int dst_wrap, 1539 static void deinterlace_bottom_field(uint8_t *dst, int dst_wrap,
1540 UINT8 *src1, int src_wrap, 1540 uint8_t *src1, int src_wrap,
1541 int width, int height) 1541 int width, int height)
1542 { 1542 {
1543 UINT8 *src_m2, *src_m1, *src_0, *src_p1, *src_p2; 1543 uint8_t *src_m2, *src_m1, *src_0, *src_p1, *src_p2;
1544 int y; 1544 int y;
1545 1545
1546 src_m2 = src1; 1546 src_m2 = src1;
1547 src_m1 = src1; 1547 src_m1 = src1;
1548 src_0=&src_m1[src_wrap]; 1548 src_0=&src_m1[src_wrap];
1563 dst += dst_wrap; 1563 dst += dst_wrap;
1564 /* do last line */ 1564 /* do last line */
1565 deinterlace_line(dst,src_m2,src_m1,src_0,src_0,src_0,width); 1565 deinterlace_line(dst,src_m2,src_m1,src_0,src_0,src_0,width);
1566 } 1566 }
1567 1567
1568 static void deinterlace_bottom_field_inplace(UINT8 *src1, int src_wrap, 1568 static void deinterlace_bottom_field_inplace(uint8_t *src1, int src_wrap,
1569 int width, int height) 1569 int width, int height)
1570 { 1570 {
1571 UINT8 *src_m1, *src_0, *src_p1, *src_p2; 1571 uint8_t *src_m1, *src_0, *src_p1, *src_p2;
1572 int y; 1572 int y;
1573 UINT8 *buf; 1573 uint8_t *buf;
1574 buf = (UINT8*)av_malloc(width); 1574 buf = (uint8_t*)av_malloc(width);
1575 1575
1576 src_m1 = src1; 1576 src_m1 = src1;
1577 memcpy(buf,src_m1,width); 1577 memcpy(buf,src_m1,width);
1578 src_0=&src_m1[src_wrap]; 1578 src_0=&src_m1[src_wrap];
1579 src_p1=&src_0[src_wrap]; 1579 src_p1=&src_0[src_wrap];