comparison imgconvert.c @ 1488:766a2f4edbea libavcodec

avcodec const correctness patch by (Drew Hess <dhess at ilm dot com>)
author michaelni
date Mon, 29 Sep 2003 15:44:59 +0000
parents f53d31c5eac9
children 5a43bc31c2eb
comparison
equal deleted inserted replaced
1487:dfd69e00951c 1488:766a2f4edbea
234 return i; 234 return i;
235 } 235 }
236 236
237 /* Picture field are filled with 'ptr' addresses. Also return size */ 237 /* Picture field are filled with 'ptr' addresses. Also return size */
238 int avpicture_fill(AVPicture *picture, uint8_t *ptr, 238 int avpicture_fill(AVPicture *picture, uint8_t *ptr,
239 int pix_fmt, int width, int height) 239 int pix_fmt, int width, int height)
240 { 240 {
241 int size, w2, h2, size2; 241 int size, w2, h2, size2;
242 PixFmtInfo *pinfo; 242 PixFmtInfo *pinfo;
243 243
244 pinfo = &pix_fmt_info[pix_fmt]; 244 pinfo = &pix_fmt_info[pix_fmt];
311 picture->data[3] = NULL; 311 picture->data[3] = NULL;
312 return -1; 312 return -1;
313 } 313 }
314 } 314 }
315 315
316 int avpicture_layout(AVPicture* src, int pix_fmt, int width, int height, 316 int avpicture_layout(const AVPicture* src, int pix_fmt, int width, int height,
317 unsigned char *dest, int dest_size) 317 unsigned char *dest, int dest_size)
318 { 318 {
319 PixFmtInfo* pf = &pix_fmt_info[pix_fmt]; 319 PixFmtInfo* pf = &pix_fmt_info[pix_fmt];
320 int i, j, w, h, data_planes; 320 int i, j, w, h, data_planes;
321 unsigned char* s; 321 const unsigned char* s;
322 int size = avpicture_get_size(pix_fmt, width, height); 322 int size = avpicture_get_size(pix_fmt, width, height);
323 323
324 if (size > dest_size) 324 if (size > dest_size)
325 return -1; 325 return -1;
326 326
533 } 533 }
534 534
535 /** 535 /**
536 * Copy image 'src' to 'dst'. 536 * Copy image 'src' to 'dst'.
537 */ 537 */
538 void img_copy(AVPicture *dst, AVPicture *src, 538 void img_copy(AVPicture *dst, const AVPicture *src,
539 int pix_fmt, int width, int height) 539 int pix_fmt, int width, int height)
540 { 540 {
541 int bwidth, bits, i; 541 int bwidth, bits, i;
542 PixFmtInfo *pf = &pix_fmt_info[pix_fmt]; 542 PixFmtInfo *pf = &pix_fmt_info[pix_fmt];
543 543
586 } 586 }
587 } 587 }
588 588
589 /* XXX: totally non optimized */ 589 /* XXX: totally non optimized */
590 590
591 static void yuv422_to_yuv420p(AVPicture *dst, AVPicture *src, 591 static void yuv422_to_yuv420p(AVPicture *dst, const AVPicture *src,
592 int width, int height) 592 int width, int height)
593 { 593 {
594 const uint8_t *p, *p1; 594 const uint8_t *p, *p1;
595 uint8_t *lum, *cr, *cb, *lum1, *cr1, *cb1; 595 uint8_t *lum, *cr, *cb, *lum1, *cr1, *cb1;
596 int w; 596 int w;
642 cb1 += dst->linesize[1]; 642 cb1 += dst->linesize[1];
643 cr1 += dst->linesize[2]; 643 cr1 += dst->linesize[2];
644 } 644 }
645 } 645 }
646 646
647 static void yuv422_to_yuv422p(AVPicture *dst, AVPicture *src, 647 static void yuv422_to_yuv422p(AVPicture *dst, const AVPicture *src,
648 int width, int height) 648 int width, int height)
649 { 649 {
650 const uint8_t *p, *p1; 650 const uint8_t *p, *p1;
651 uint8_t *lum, *cr, *cb, *lum1, *cr1, *cb1; 651 uint8_t *lum, *cr, *cb, *lum1, *cr1, *cb1;
652 int w; 652 int w;
675 cb1 += dst->linesize[1]; 675 cb1 += dst->linesize[1];
676 cr1 += dst->linesize[2]; 676 cr1 += dst->linesize[2];
677 } 677 }
678 } 678 }
679 679
680 static void yuv422p_to_yuv422(AVPicture *dst, AVPicture *src, 680 static void yuv422p_to_yuv422(AVPicture *dst, const AVPicture *src,
681 int width, int height) 681 int width, int height)
682 { 682 {
683 uint8_t *p, *p1; 683 uint8_t *p, *p1;
684 const uint8_t *lum, *cr, *cb, *lum1, *cr1, *cb1; 684 const uint8_t *lum, *cr, *cb, *lum1, *cr1, *cb1;
685 int w; 685 int w;
1284 1284
1285 #define BPP 4 1285 #define BPP 4
1286 1286
1287 #include "imgconvert_template.h" 1287 #include "imgconvert_template.h"
1288 1288
1289 static void mono_to_gray(AVPicture *dst, AVPicture *src, 1289 static void mono_to_gray(AVPicture *dst, const AVPicture *src,
1290 int width, int height, int xor_mask) 1290 int width, int height, int xor_mask)
1291 { 1291 {
1292 const unsigned char *p; 1292 const unsigned char *p;
1293 unsigned char *q; 1293 unsigned char *q;
1294 int v, dst_wrap, src_wrap; 1294 int v, dst_wrap, src_wrap;
1325 p += src_wrap; 1325 p += src_wrap;
1326 q += dst_wrap; 1326 q += dst_wrap;
1327 } 1327 }
1328 } 1328 }
1329 1329
1330 static void monowhite_to_gray(AVPicture *dst, AVPicture *src, 1330 static void monowhite_to_gray(AVPicture *dst, const AVPicture *src,
1331 int width, int height) 1331 int width, int height)
1332 { 1332 {
1333 mono_to_gray(dst, src, width, height, 0xff); 1333 mono_to_gray(dst, src, width, height, 0xff);
1334 } 1334 }
1335 1335
1336 static void monoblack_to_gray(AVPicture *dst, AVPicture *src, 1336 static void monoblack_to_gray(AVPicture *dst, const AVPicture *src,
1337 int width, int height) 1337 int width, int height)
1338 { 1338 {
1339 mono_to_gray(dst, src, width, height, 0x00); 1339 mono_to_gray(dst, src, width, height, 0x00);
1340 } 1340 }
1341 1341
1342 static void gray_to_mono(AVPicture *dst, AVPicture *src, 1342 static void gray_to_mono(AVPicture *dst, const AVPicture *src,
1343 int width, int height, int xor_mask) 1343 int width, int height, int xor_mask)
1344 { 1344 {
1345 int n; 1345 int n;
1346 const uint8_t *s; 1346 const uint8_t *s;
1347 uint8_t *d; 1347 uint8_t *d;
1381 s += src_wrap; 1381 s += src_wrap;
1382 d += dst_wrap; 1382 d += dst_wrap;
1383 } 1383 }
1384 } 1384 }
1385 1385
1386 static void gray_to_monowhite(AVPicture *dst, AVPicture *src, 1386 static void gray_to_monowhite(AVPicture *dst, const AVPicture *src,
1387 int width, int height) 1387 int width, int height)
1388 { 1388 {
1389 gray_to_mono(dst, src, width, height, 0xff); 1389 gray_to_mono(dst, src, width, height, 0xff);
1390 } 1390 }
1391 1391
1392 static void gray_to_monoblack(AVPicture *dst, AVPicture *src, 1392 static void gray_to_monoblack(AVPicture *dst, const AVPicture *src,
1393 int width, int height) 1393 int width, int height)
1394 { 1394 {
1395 gray_to_mono(dst, src, width, height, 0x00); 1395 gray_to_mono(dst, src, width, height, 0x00);
1396 } 1396 }
1397 1397
1398 typedef struct ConvertEntry { 1398 typedef struct ConvertEntry {
1399 void (*convert)(AVPicture *dst, AVPicture *src, int width, int height); 1399 void (*convert)(AVPicture *dst,
1400 const AVPicture *src, int width, int height);
1400 } ConvertEntry; 1401 } ConvertEntry;
1401 1402
1402 /* Add each new convertion function in this table. In order to be able 1403 /* Add each new convertion function in this table. In order to be able
1403 to convert from any format to any format, the following constraints 1404 to convert from any format to any format, the following constraints
1404 must be satisfied: 1405 must be satisfied:
1642 ps->pixel_type == FF_PIXEL_PLANAR; 1643 ps->pixel_type == FF_PIXEL_PLANAR;
1643 } 1644 }
1644 1645
1645 /* XXX: always use linesize. Return -1 if not supported */ 1646 /* XXX: always use linesize. Return -1 if not supported */
1646 int img_convert(AVPicture *dst, int dst_pix_fmt, 1647 int img_convert(AVPicture *dst, int dst_pix_fmt,
1647 AVPicture *src, int src_pix_fmt, 1648 const AVPicture *src, int src_pix_fmt,
1648 int src_width, int src_height) 1649 int src_width, int src_height)
1649 { 1650 {
1650 static int inited; 1651 static int inited;
1651 int i, ret, dst_width, dst_height, int_pix_fmt; 1652 int i, ret, dst_width, dst_height, int_pix_fmt;
1652 PixFmtInfo *src_pix, *dst_pix; 1653 PixFmtInfo *src_pix, *dst_pix;
1875 avpicture_free(tmp); 1876 avpicture_free(tmp);
1876 return ret; 1877 return ret;
1877 } 1878 }
1878 1879
1879 /* NOTE: we scan all the pixels to have an exact information */ 1880 /* NOTE: we scan all the pixels to have an exact information */
1880 static int get_alpha_info_pal8(AVPicture *src, int width, int height) 1881 static int get_alpha_info_pal8(const AVPicture *src, int width, int height)
1881 { 1882 {
1882 const unsigned char *p; 1883 const unsigned char *p;
1883 int src_wrap, ret, x, y; 1884 int src_wrap, ret, x, y;
1884 unsigned int a; 1885 unsigned int a;
1885 uint32_t *palette = (uint32_t *)src->data[1]; 1886 uint32_t *palette = (uint32_t *)src->data[1];
1904 1905
1905 /** 1906 /**
1906 * Tell if an image really has transparent alpha values. 1907 * Tell if an image really has transparent alpha values.
1907 * @return ored mask of FF_ALPHA_xxx constants 1908 * @return ored mask of FF_ALPHA_xxx constants
1908 */ 1909 */
1909 int img_get_alpha_info(AVPicture *src, int pix_fmt, int width, int height) 1910 int img_get_alpha_info(const AVPicture *src,
1911 int pix_fmt, int width, int height)
1910 { 1912 {
1911 PixFmtInfo *pf = &pix_fmt_info[pix_fmt]; 1913 PixFmtInfo *pf = &pix_fmt_info[pix_fmt];
1912 int ret; 1914 int ret;
1913 1915
1914 pf = &pix_fmt_info[pix_fmt]; 1916 pf = &pix_fmt_info[pix_fmt];
1979 packuswb_r2r(mm7,mm1);\ 1981 packuswb_r2r(mm7,mm1);\
1980 movd_r2m(mm1,dst[0]); 1982 movd_r2m(mm1,dst[0]);
1981 #endif 1983 #endif
1982 1984
1983 /* filter parameters: [-1 4 2 4 -1] // 8 */ 1985 /* filter parameters: [-1 4 2 4 -1] // 8 */
1984 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, 1986 static void deinterlace_line(uint8_t *dst,
1985 int size) 1987 const uint8_t *lum_m4, const uint8_t *lum_m3,
1988 const uint8_t *lum_m2, const uint8_t *lum_m1,
1989 const uint8_t *lum,
1990 int size)
1986 { 1991 {
1987 #ifndef HAVE_MMX 1992 #ifndef HAVE_MMX
1988 uint8_t *cm = cropTbl + MAX_NEG_CROP; 1993 uint8_t *cm = cropTbl + MAX_NEG_CROP;
1989 int sum; 1994 int sum;
1990 1995
2069 2074
2070 /* deinterlacing : 2 temporal taps, 3 spatial taps linear filter. The 2075 /* deinterlacing : 2 temporal taps, 3 spatial taps linear filter. The
2071 top field is copied as is, but the bottom field is deinterlaced 2076 top field is copied as is, but the bottom field is deinterlaced
2072 against the top field. */ 2077 against the top field. */
2073 static void deinterlace_bottom_field(uint8_t *dst, int dst_wrap, 2078 static void deinterlace_bottom_field(uint8_t *dst, int dst_wrap,
2074 uint8_t *src1, int src_wrap, 2079 const uint8_t *src1, int src_wrap,
2075 int width, int height) 2080 int width, int height)
2076 { 2081 {
2077 uint8_t *src_m2, *src_m1, *src_0, *src_p1, *src_p2; 2082 const uint8_t *src_m2, *src_m1, *src_0, *src_p1, *src_p2;
2078 int y; 2083 int y;
2079 2084
2080 src_m2 = src1; 2085 src_m2 = src1;
2081 src_m1 = src1; 2086 src_m1 = src1;
2082 src_0=&src_m1[src_wrap]; 2087 src_0=&src_m1[src_wrap];
2098 /* do last line */ 2103 /* do last line */
2099 deinterlace_line(dst,src_m2,src_m1,src_0,src_0,src_0,width); 2104 deinterlace_line(dst,src_m2,src_m1,src_0,src_0,src_0,width);
2100 } 2105 }
2101 2106
2102 static void deinterlace_bottom_field_inplace(uint8_t *src1, int src_wrap, 2107 static void deinterlace_bottom_field_inplace(uint8_t *src1, int src_wrap,
2103 int width, int height) 2108 int width, int height)
2104 { 2109 {
2105 uint8_t *src_m1, *src_0, *src_p1, *src_p2; 2110 uint8_t *src_m1, *src_0, *src_p1, *src_p2;
2106 int y; 2111 int y;
2107 uint8_t *buf; 2112 uint8_t *buf;
2108 buf = (uint8_t*)av_malloc(width); 2113 buf = (uint8_t*)av_malloc(width);
2124 av_free(buf); 2129 av_free(buf);
2125 } 2130 }
2126 2131
2127 2132
2128 /* deinterlace - if not supported return -1 */ 2133 /* deinterlace - if not supported return -1 */
2129 int avpicture_deinterlace(AVPicture *dst, AVPicture *src, 2134 int avpicture_deinterlace(AVPicture *dst, const AVPicture *src,
2130 int pix_fmt, int width, int height) 2135 int pix_fmt, int width, int height)
2131 { 2136 {
2132 int i; 2137 int i;
2133 2138
2134 if (pix_fmt != PIX_FMT_YUV420P && 2139 if (pix_fmt != PIX_FMT_YUV420P &&
2155 default: 2160 default:
2156 break; 2161 break;
2157 } 2162 }
2158 } 2163 }
2159 if (src == dst) { 2164 if (src == dst) {
2160 deinterlace_bottom_field_inplace(src->data[i], src->linesize[i], 2165 deinterlace_bottom_field_inplace(dst->data[i], dst->linesize[i],
2161 width, height); 2166 width, height);
2162 } else { 2167 } else {
2163 deinterlace_bottom_field(dst->data[i],dst->linesize[i], 2168 deinterlace_bottom_field(dst->data[i],dst->linesize[i],
2164 src->data[i], src->linesize[i], 2169 src->data[i], src->linesize[i],
2165 width, height); 2170 width, height);