Mercurial > libavcodec.hg
comparison imgconvert.c @ 9221:a15ec86bf752 libavcodec
Globally prefer enum PixelFormat over int when it makes sense.
author | stefano |
---|---|
date | Sat, 21 Mar 2009 22:24:44 +0000 |
parents | 53ec03e7ba40 |
children | e314914641bc |
comparison
equal
deleted
inserted
replaced
9220:cb62e27e2c07 | 9221:a15ec86bf752 |
---|---|
441 .is_hwaccel = 1, | 441 .is_hwaccel = 1, |
442 .x_chroma_shift = 1, .y_chroma_shift = 1, | 442 .x_chroma_shift = 1, .y_chroma_shift = 1, |
443 }, | 443 }, |
444 }; | 444 }; |
445 | 445 |
446 void avcodec_get_chroma_sub_sample(int pix_fmt, int *h_shift, int *v_shift) | 446 void avcodec_get_chroma_sub_sample(enum PixelFormat pix_fmt, int *h_shift, int *v_shift) |
447 { | 447 { |
448 *h_shift = pix_fmt_info[pix_fmt].x_chroma_shift; | 448 *h_shift = pix_fmt_info[pix_fmt].x_chroma_shift; |
449 *v_shift = pix_fmt_info[pix_fmt].y_chroma_shift; | 449 *v_shift = pix_fmt_info[pix_fmt].y_chroma_shift; |
450 } | 450 } |
451 | 451 |
452 const char *avcodec_get_pix_fmt_name(int pix_fmt) | 452 const char *avcodec_get_pix_fmt_name(enum PixelFormat pix_fmt) |
453 { | 453 { |
454 if (pix_fmt < 0 || pix_fmt >= PIX_FMT_NB) | 454 if (pix_fmt < 0 || pix_fmt >= PIX_FMT_NB) |
455 return NULL; | 455 return NULL; |
456 else | 456 else |
457 return pix_fmt_info[pix_fmt].name; | 457 return pix_fmt_info[pix_fmt].name; |
465 if (!strcmp(pix_fmt_info[i].name, name)) | 465 if (!strcmp(pix_fmt_info[i].name, name)) |
466 return i; | 466 return i; |
467 return PIX_FMT_NONE; | 467 return PIX_FMT_NONE; |
468 } | 468 } |
469 | 469 |
470 void avcodec_pix_fmt_string (char *buf, int buf_size, int pix_fmt) | 470 void avcodec_pix_fmt_string (char *buf, int buf_size, enum PixelFormat pix_fmt) |
471 { | 471 { |
472 /* print header */ | 472 /* print header */ |
473 if (pix_fmt < 0) | 473 if (pix_fmt < 0) |
474 snprintf (buf, buf_size, | 474 snprintf (buf, buf_size, |
475 "name " " nb_channels" " depth" " is_alpha" | 475 "name " " nb_channels" " depth" " is_alpha" |
531 } | 531 } |
532 | 532 |
533 return 0; | 533 return 0; |
534 } | 534 } |
535 | 535 |
536 int ff_fill_linesize(AVPicture *picture, int pix_fmt, int width) | 536 int ff_fill_linesize(AVPicture *picture, enum PixelFormat pix_fmt, int width) |
537 { | 537 { |
538 int w2; | 538 int w2; |
539 const PixFmtInfo *pinfo; | 539 const PixFmtInfo *pinfo; |
540 | 540 |
541 memset(picture->linesize, 0, sizeof(picture->linesize)); | 541 memset(picture->linesize, 0, sizeof(picture->linesize)); |
619 return -1; | 619 return -1; |
620 } | 620 } |
621 return 0; | 621 return 0; |
622 } | 622 } |
623 | 623 |
624 int ff_fill_pointer(AVPicture *picture, uint8_t *ptr, int pix_fmt, | 624 int ff_fill_pointer(AVPicture *picture, uint8_t *ptr, enum PixelFormat pix_fmt, |
625 int height) | 625 int height) |
626 { | 626 { |
627 int size, h2, size2; | 627 int size, h2, size2; |
628 const PixFmtInfo *pinfo; | 628 const PixFmtInfo *pinfo; |
629 | 629 |
710 return -1; | 710 return -1; |
711 } | 711 } |
712 } | 712 } |
713 | 713 |
714 int avpicture_fill(AVPicture *picture, uint8_t *ptr, | 714 int avpicture_fill(AVPicture *picture, uint8_t *ptr, |
715 int pix_fmt, int width, int height) | 715 enum PixelFormat pix_fmt, int width, int height) |
716 { | 716 { |
717 | 717 |
718 if(avcodec_check_dimensions(NULL, width, height)) | 718 if(avcodec_check_dimensions(NULL, width, height)) |
719 return -1; | 719 return -1; |
720 | 720 |
722 return -1; | 722 return -1; |
723 | 723 |
724 return ff_fill_pointer(picture, ptr, pix_fmt, height); | 724 return ff_fill_pointer(picture, ptr, pix_fmt, height); |
725 } | 725 } |
726 | 726 |
727 int avpicture_layout(const AVPicture* src, int pix_fmt, int width, int height, | 727 int avpicture_layout(const AVPicture* src, enum PixelFormat pix_fmt, int width, int height, |
728 unsigned char *dest, int dest_size) | 728 unsigned char *dest, int dest_size) |
729 { | 729 { |
730 const PixFmtInfo* pf = &pix_fmt_info[pix_fmt]; | 730 const PixFmtInfo* pf = &pix_fmt_info[pix_fmt]; |
731 int i, j, w, ow, h, oh, data_planes; | 731 int i, j, w, ow, h, oh, data_planes; |
732 const unsigned char* s; | 732 const unsigned char* s; |
781 memcpy((unsigned char *)(((size_t)dest + 3) & ~3), src->data[1], 256 * 4); | 781 memcpy((unsigned char *)(((size_t)dest + 3) & ~3), src->data[1], 256 * 4); |
782 | 782 |
783 return size; | 783 return size; |
784 } | 784 } |
785 | 785 |
786 int avpicture_get_size(int pix_fmt, int width, int height) | 786 int avpicture_get_size(enum PixelFormat pix_fmt, int width, int height) |
787 { | 787 { |
788 AVPicture dummy_pict; | 788 AVPicture dummy_pict; |
789 if(avcodec_check_dimensions(NULL, width, height)) | 789 if(avcodec_check_dimensions(NULL, width, height)) |
790 return -1; | 790 return -1; |
791 switch (pix_fmt) { | 791 switch (pix_fmt) { |
798 return width * height; | 798 return width * height; |
799 } | 799 } |
800 return avpicture_fill(&dummy_pict, NULL, pix_fmt, width, height); | 800 return avpicture_fill(&dummy_pict, NULL, pix_fmt, width, height); |
801 } | 801 } |
802 | 802 |
803 int avcodec_get_pix_fmt_loss(int dst_pix_fmt, int src_pix_fmt, | 803 int avcodec_get_pix_fmt_loss(enum PixelFormat dst_pix_fmt, enum PixelFormat src_pix_fmt, |
804 int has_alpha) | 804 int has_alpha) |
805 { | 805 { |
806 const PixFmtInfo *pf, *ps; | 806 const PixFmtInfo *pf, *ps; |
807 int loss; | 807 int loss; |
808 | 808 |
853 (ps->pixel_type != FF_PIXEL_PALETTE && ps->color_type != FF_COLOR_GRAY)) | 853 (ps->pixel_type != FF_PIXEL_PALETTE && ps->color_type != FF_COLOR_GRAY)) |
854 loss |= FF_LOSS_COLORQUANT; | 854 loss |= FF_LOSS_COLORQUANT; |
855 return loss; | 855 return loss; |
856 } | 856 } |
857 | 857 |
858 static int avg_bits_per_pixel(int pix_fmt) | 858 static int avg_bits_per_pixel(enum PixelFormat pix_fmt) |
859 { | 859 { |
860 int bits; | 860 int bits; |
861 const PixFmtInfo *pf; | 861 const PixFmtInfo *pf; |
862 | 862 |
863 pf = &pix_fmt_info[pix_fmt]; | 863 pf = &pix_fmt_info[pix_fmt]; |
896 break; | 896 break; |
897 } | 897 } |
898 return bits; | 898 return bits; |
899 } | 899 } |
900 | 900 |
901 static int avcodec_find_best_pix_fmt1(int64_t pix_fmt_mask, | 901 static enum PixelFormat avcodec_find_best_pix_fmt1(int64_t pix_fmt_mask, |
902 int src_pix_fmt, | 902 enum PixelFormat src_pix_fmt, |
903 int has_alpha, | 903 int has_alpha, |
904 int loss_mask) | 904 int loss_mask) |
905 { | 905 { |
906 int dist, i, loss, min_dist, dst_pix_fmt; | 906 int dist, i, loss, min_dist; |
907 enum PixelFormat dst_pix_fmt; | |
907 | 908 |
908 /* find exact color match with smallest size */ | 909 /* find exact color match with smallest size */ |
909 dst_pix_fmt = -1; | 910 dst_pix_fmt = -1; |
910 min_dist = 0x7fffffff; | 911 min_dist = 0x7fffffff; |
911 for(i = 0;i < PIX_FMT_NB; i++) { | 912 for(i = 0;i < PIX_FMT_NB; i++) { |
921 } | 922 } |
922 } | 923 } |
923 return dst_pix_fmt; | 924 return dst_pix_fmt; |
924 } | 925 } |
925 | 926 |
926 int avcodec_find_best_pix_fmt(int64_t pix_fmt_mask, int src_pix_fmt, | 927 enum PixelFormat avcodec_find_best_pix_fmt(int64_t pix_fmt_mask, enum PixelFormat src_pix_fmt, |
927 int has_alpha, int *loss_ptr) | 928 int has_alpha, int *loss_ptr) |
928 { | 929 { |
929 int dst_pix_fmt, loss_mask, i; | 930 enum PixelFormat dst_pix_fmt; |
931 int loss_mask, i; | |
930 static const int loss_mask_order[] = { | 932 static const int loss_mask_order[] = { |
931 ~0, /* no loss first */ | 933 ~0, /* no loss first */ |
932 ~FF_LOSS_ALPHA, | 934 ~FF_LOSS_ALPHA, |
933 ~FF_LOSS_RESOLUTION, | 935 ~FF_LOSS_RESOLUTION, |
934 ~(FF_LOSS_COLORSPACE | FF_LOSS_RESOLUTION), | 936 ~(FF_LOSS_COLORSPACE | FF_LOSS_RESOLUTION), |
1008 | 1010 |
1009 return -1; | 1011 return -1; |
1010 } | 1012 } |
1011 | 1013 |
1012 void av_picture_copy(AVPicture *dst, const AVPicture *src, | 1014 void av_picture_copy(AVPicture *dst, const AVPicture *src, |
1013 int pix_fmt, int width, int height) | 1015 enum PixelFormat pix_fmt, int width, int height) |
1014 { | 1016 { |
1015 int i; | 1017 int i; |
1016 const PixFmtInfo *pf = &pix_fmt_info[pix_fmt]; | 1018 const PixFmtInfo *pf = &pix_fmt_info[pix_fmt]; |
1017 | 1019 |
1018 pf = &pix_fmt_info[pix_fmt]; | 1020 pf = &pix_fmt_info[pix_fmt]; |
1129 } | 1131 } |
1130 } | 1132 } |
1131 | 1133 |
1132 | 1134 |
1133 int avpicture_alloc(AVPicture *picture, | 1135 int avpicture_alloc(AVPicture *picture, |
1134 int pix_fmt, int width, int height) | 1136 enum PixelFormat pix_fmt, int width, int height) |
1135 { | 1137 { |
1136 int size; | 1138 int size; |
1137 void *ptr; | 1139 void *ptr; |
1138 | 1140 |
1139 size = avpicture_fill(picture, NULL, pix_fmt, width, height); | 1141 size = avpicture_fill(picture, NULL, pix_fmt, width, height); |
1186 dst->linesize[2] = src->linesize[2]; | 1188 dst->linesize[2] = src->linesize[2]; |
1187 return 0; | 1189 return 0; |
1188 } | 1190 } |
1189 | 1191 |
1190 int av_picture_pad(AVPicture *dst, const AVPicture *src, int height, int width, | 1192 int av_picture_pad(AVPicture *dst, const AVPicture *src, int height, int width, |
1191 int pix_fmt, int padtop, int padbottom, int padleft, int padright, | 1193 enum PixelFormat pix_fmt, int padtop, int padbottom, int padleft, int padright, |
1192 int *color) | 1194 int *color) |
1193 { | 1195 { |
1194 uint8_t *optr; | 1196 uint8_t *optr; |
1195 int y_shift; | 1197 int y_shift; |
1196 int x_shift; | 1198 int x_shift; |
1272 } | 1274 } |
1273 return ret; | 1275 return ret; |
1274 } | 1276 } |
1275 | 1277 |
1276 int img_get_alpha_info(const AVPicture *src, | 1278 int img_get_alpha_info(const AVPicture *src, |
1277 int pix_fmt, int width, int height) | 1279 enum PixelFormat pix_fmt, int width, int height) |
1278 { | 1280 { |
1279 const PixFmtInfo *pf = &pix_fmt_info[pix_fmt]; | 1281 const PixFmtInfo *pf = &pix_fmt_info[pix_fmt]; |
1280 int ret; | 1282 int ret; |
1281 | 1283 |
1282 pf = &pix_fmt_info[pix_fmt]; | 1284 pf = &pix_fmt_info[pix_fmt]; |
1478 deinterlace_line_inplace(buf,src_m1,src_0,src_0,src_0,width); | 1480 deinterlace_line_inplace(buf,src_m1,src_0,src_0,src_0,width); |
1479 av_free(buf); | 1481 av_free(buf); |
1480 } | 1482 } |
1481 | 1483 |
1482 int avpicture_deinterlace(AVPicture *dst, const AVPicture *src, | 1484 int avpicture_deinterlace(AVPicture *dst, const AVPicture *src, |
1483 int pix_fmt, int width, int height) | 1485 enum PixelFormat pix_fmt, int width, int height) |
1484 { | 1486 { |
1485 int i; | 1487 int i; |
1486 | 1488 |
1487 if (pix_fmt != PIX_FMT_YUV420P && | 1489 if (pix_fmt != PIX_FMT_YUV420P && |
1488 pix_fmt != PIX_FMT_YUV422P && | 1490 pix_fmt != PIX_FMT_YUV422P && |