Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(631)

Side by Side Diff: source/libvpx/y4minput.c

Issue 375983002: libvpx: Pull from upstream (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/deps/third_party/libvpx/
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « source/libvpx/y4minput.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved. 2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 * 9 *
10 * Based on code from the OggTheora software codec source code, 10 * Based on code from the OggTheora software codec source code,
(...skipping 719 matching lines...) Expand 10 before | Expand all | Expand 10 after
730 } 730 }
731 if (_y4m->interlace == '?') { 731 if (_y4m->interlace == '?') {
732 fprintf(stderr, "Warning: Input video interlacing format unknown; " 732 fprintf(stderr, "Warning: Input video interlacing format unknown; "
733 "assuming progressive scan.\n"); 733 "assuming progressive scan.\n");
734 } else if (_y4m->interlace != 'p') { 734 } else if (_y4m->interlace != 'p') {
735 fprintf(stderr, "Input video is interlaced; " 735 fprintf(stderr, "Input video is interlaced; "
736 "Only progressive scan handled.\n"); 736 "Only progressive scan handled.\n");
737 return -1; 737 return -1;
738 } 738 }
739 _y4m->vpx_fmt = VPX_IMG_FMT_I420; 739 _y4m->vpx_fmt = VPX_IMG_FMT_I420;
740 _y4m->vpx_bps = 12; 740 _y4m->bps = 12;
741 _y4m->bit_depth = 8;
741 if (strcmp(_y4m->chroma_type, "420") == 0 || 742 if (strcmp(_y4m->chroma_type, "420") == 0 ||
742 strcmp(_y4m->chroma_type, "420jpeg") == 0) { 743 strcmp(_y4m->chroma_type, "420jpeg") == 0) {
743 _y4m->src_c_dec_h = _y4m->dst_c_dec_h = _y4m->src_c_dec_v = _y4m->dst_c_dec_ v = 2; 744 _y4m->src_c_dec_h = _y4m->dst_c_dec_h = _y4m->src_c_dec_v = _y4m->dst_c_dec_ v = 2;
744 _y4m->dst_buf_read_sz = _y4m->pic_w * _y4m->pic_h 745 _y4m->dst_buf_read_sz = _y4m->pic_w * _y4m->pic_h
745 + 2 * ((_y4m->pic_w + 1) / 2) * ((_y4m->pic_h + 1) / 2); 746 + 2 * ((_y4m->pic_w + 1) / 2) * ((_y4m->pic_h + 1) / 2);
746 /*Natively supported: no conversion required.*/ 747 /* Natively supported: no conversion required. */
747 _y4m->aux_buf_sz = _y4m->aux_buf_read_sz = 0; 748 _y4m->aux_buf_sz = _y4m->aux_buf_read_sz = 0;
748 _y4m->convert = y4m_convert_null; 749 _y4m->convert = y4m_convert_null;
750 } else if (strcmp(_y4m->chroma_type, "420p10") == 0) {
751 _y4m->src_c_dec_h = 2;
752 _y4m->dst_c_dec_h = 2;
753 _y4m->src_c_dec_v = 2;
754 _y4m->dst_c_dec_v = 2;
755 _y4m->dst_buf_read_sz = 2 * (_y4m->pic_w * _y4m->pic_h +
756 2 * ((_y4m->pic_w + 1) / 2) *
757 ((_y4m->pic_h + 1) / 2));
758 /* Natively supported: no conversion required. */
759 _y4m->aux_buf_sz = _y4m->aux_buf_read_sz = 0;
760 _y4m->convert = y4m_convert_null;
761 _y4m->bit_depth = 10;
762 _y4m->bps = 15;
763 _y4m->vpx_fmt = VPX_IMG_FMT_I42016;
764 if (only_420) {
765 fprintf(stderr, "Unsupported conversion from 420p10 to 420jpeg\n");
766 return -1;
767 }
768 } else if (strcmp(_y4m->chroma_type, "420p12") == 0) {
769 _y4m->src_c_dec_h = 2;
770 _y4m->dst_c_dec_h = 2;
771 _y4m->src_c_dec_v = 2;
772 _y4m->dst_c_dec_v = 2;
773 _y4m->dst_buf_read_sz = 2 * (_y4m->pic_w * _y4m->pic_h +
774 2 * ((_y4m->pic_w + 1) / 2) *
775 ((_y4m->pic_h + 1) / 2));
776 /* Natively supported: no conversion required. */
777 _y4m->aux_buf_sz = _y4m->aux_buf_read_sz = 0;
778 _y4m->convert = y4m_convert_null;
779 _y4m->bit_depth = 12;
780 _y4m->bps = 18;
781 _y4m->vpx_fmt = VPX_IMG_FMT_I42016;
782 if (only_420) {
783 fprintf(stderr, "Unsupported conversion from 420p12 to 420jpeg\n");
784 return -1;
785 }
749 } else if (strcmp(_y4m->chroma_type, "420mpeg2") == 0) { 786 } else if (strcmp(_y4m->chroma_type, "420mpeg2") == 0) {
750 _y4m->src_c_dec_h = _y4m->dst_c_dec_h = _y4m->src_c_dec_v = _y4m->dst_c_dec_ v = 2; 787 _y4m->src_c_dec_h = _y4m->dst_c_dec_h = _y4m->src_c_dec_v = _y4m->dst_c_dec_ v = 2;
751 _y4m->dst_buf_read_sz = _y4m->pic_w * _y4m->pic_h; 788 _y4m->dst_buf_read_sz = _y4m->pic_w * _y4m->pic_h;
752 /*Chroma filter required: read into the aux buf first.*/ 789 /*Chroma filter required: read into the aux buf first.*/
753 _y4m->aux_buf_sz = _y4m->aux_buf_read_sz = 790 _y4m->aux_buf_sz = _y4m->aux_buf_read_sz =
754 2 * ((_y4m->pic_w + 1) / 2) * ((_y4m->pic_h + 1) / 2); 791 2 * ((_y4m->pic_w + 1) / 2) * ((_y4m->pic_h + 1) / 2);
755 _y4m->convert = y4m_convert_42xmpeg2_42xjpeg; 792 _y4m->convert = y4m_convert_42xmpeg2_42xjpeg;
756 } else if (strcmp(_y4m->chroma_type, "420paldv") == 0) { 793 } else if (strcmp(_y4m->chroma_type, "420paldv") == 0) {
757 _y4m->src_c_dec_h = _y4m->dst_c_dec_h = _y4m->src_c_dec_v = _y4m->dst_c_dec_ v = 2; 794 _y4m->src_c_dec_h = _y4m->dst_c_dec_h = _y4m->src_c_dec_v = _y4m->dst_c_dec_ v = 2;
758 _y4m->dst_buf_read_sz = _y4m->pic_w * _y4m->pic_h; 795 _y4m->dst_buf_read_sz = _y4m->pic_w * _y4m->pic_h;
(...skipping 20 matching lines...) Expand all
779 _y4m->dst_buf_read_sz = _y4m->pic_w * _y4m->pic_h; 816 _y4m->dst_buf_read_sz = _y4m->pic_w * _y4m->pic_h;
780 /*Chroma filter required: read into the aux buf first. 817 /*Chroma filter required: read into the aux buf first.
781 We need to make two filter passes, so we need some extra space in the 818 We need to make two filter passes, so we need some extra space in the
782 aux buffer.*/ 819 aux buffer.*/
783 _y4m->aux_buf_read_sz = 2 * ((_y4m->pic_w + 1) / 2) * _y4m->pic_h; 820 _y4m->aux_buf_read_sz = 2 * ((_y4m->pic_w + 1) / 2) * _y4m->pic_h;
784 _y4m->aux_buf_sz = _y4m->aux_buf_read_sz + 821 _y4m->aux_buf_sz = _y4m->aux_buf_read_sz +
785 ((_y4m->pic_w + 1) / 2) * _y4m->pic_h; 822 ((_y4m->pic_w + 1) / 2) * _y4m->pic_h;
786 _y4m->convert = y4m_convert_422_420jpeg; 823 _y4m->convert = y4m_convert_422_420jpeg;
787 } else { 824 } else {
788 _y4m->vpx_fmt = VPX_IMG_FMT_I422; 825 _y4m->vpx_fmt = VPX_IMG_FMT_I422;
789 _y4m->vpx_bps = 16; 826 _y4m->bps = 16;
790 _y4m->dst_c_dec_h = _y4m->src_c_dec_h; 827 _y4m->dst_c_dec_h = _y4m->src_c_dec_h;
791 _y4m->dst_c_dec_v = _y4m->src_c_dec_v; 828 _y4m->dst_c_dec_v = _y4m->src_c_dec_v;
792 _y4m->dst_buf_read_sz = _y4m->pic_w * _y4m->pic_h 829 _y4m->dst_buf_read_sz = _y4m->pic_w * _y4m->pic_h
793 + 2 * ((_y4m->pic_w + 1) / 2) * _y4m->pic_h; 830 + 2 * ((_y4m->pic_w + 1) / 2) * _y4m->pic_h;
794 /*Natively supported: no conversion required.*/ 831 /*Natively supported: no conversion required.*/
795 _y4m->aux_buf_sz = _y4m->aux_buf_read_sz = 0; 832 _y4m->aux_buf_sz = _y4m->aux_buf_read_sz = 0;
796 _y4m->convert = y4m_convert_null; 833 _y4m->convert = y4m_convert_null;
797 } 834 }
835 } else if (strcmp(_y4m->chroma_type, "422p10") == 0) {
836 _y4m->src_c_dec_h = 2;
837 _y4m->src_c_dec_v = 1;
838 _y4m->vpx_fmt = VPX_IMG_FMT_I42216;
839 _y4m->bps = 20;
840 _y4m->bit_depth = 10;
841 _y4m->dst_c_dec_h = _y4m->src_c_dec_h;
842 _y4m->dst_c_dec_v = _y4m->src_c_dec_v;
843 _y4m->dst_buf_read_sz = 2 * (_y4m->pic_w * _y4m->pic_h +
844 2 * ((_y4m->pic_w + 1) / 2) * _y4m->pic_h);
845 _y4m->aux_buf_sz = _y4m->aux_buf_read_sz = 0;
846 _y4m->convert = y4m_convert_null;
847 if (only_420) {
848 fprintf(stderr, "Unsupported conversion from 422p10 to 420jpeg\n");
849 return -1;
850 }
851 } else if (strcmp(_y4m->chroma_type, "422p12") == 0) {
852 _y4m->src_c_dec_h = 2;
853 _y4m->src_c_dec_v = 1;
854 _y4m->vpx_fmt = VPX_IMG_FMT_I42216;
855 _y4m->bps = 24;
856 _y4m->bit_depth = 12;
857 _y4m->dst_c_dec_h = _y4m->src_c_dec_h;
858 _y4m->dst_c_dec_v = _y4m->src_c_dec_v;
859 _y4m->dst_buf_read_sz = 2 * (_y4m->pic_w * _y4m->pic_h +
860 2 * ((_y4m->pic_w + 1) / 2) * _y4m->pic_h);
861 _y4m->aux_buf_sz = _y4m->aux_buf_read_sz = 0;
862 _y4m->convert = y4m_convert_null;
863 if (only_420) {
864 fprintf(stderr, "Unsupported conversion from 422p12 to 420jpeg\n");
865 return -1;
866 }
798 } else if (strcmp(_y4m->chroma_type, "411") == 0) { 867 } else if (strcmp(_y4m->chroma_type, "411") == 0) {
799 _y4m->src_c_dec_h = 4; 868 _y4m->src_c_dec_h = 4;
800 _y4m->dst_c_dec_h = 2; 869 _y4m->dst_c_dec_h = 2;
801 _y4m->src_c_dec_v = 1; 870 _y4m->src_c_dec_v = 1;
802 _y4m->dst_c_dec_v = 2; 871 _y4m->dst_c_dec_v = 2;
803 _y4m->dst_buf_read_sz = _y4m->pic_w * _y4m->pic_h; 872 _y4m->dst_buf_read_sz = _y4m->pic_w * _y4m->pic_h;
804 /*Chroma filter required: read into the aux buf first. 873 /*Chroma filter required: read into the aux buf first.
805 We need to make two filter passes, so we need some extra space in the 874 We need to make two filter passes, so we need some extra space in the
806 aux buffer.*/ 875 aux buffer.*/
807 _y4m->aux_buf_read_sz = 2 * ((_y4m->pic_w + 3) / 4) * _y4m->pic_h; 876 _y4m->aux_buf_read_sz = 2 * ((_y4m->pic_w + 3) / 4) * _y4m->pic_h;
808 _y4m->aux_buf_sz = _y4m->aux_buf_read_sz + ((_y4m->pic_w + 1) / 2) * _y4m->p ic_h; 877 _y4m->aux_buf_sz = _y4m->aux_buf_read_sz + ((_y4m->pic_w + 1) / 2) * _y4m->p ic_h;
809 _y4m->convert = y4m_convert_411_420jpeg; 878 _y4m->convert = y4m_convert_411_420jpeg;
810 } else if (strcmp(_y4m->chroma_type, "444") == 0) { 879 } else if (strcmp(_y4m->chroma_type, "444") == 0) {
811 _y4m->src_c_dec_h = 1; 880 _y4m->src_c_dec_h = 1;
812 _y4m->src_c_dec_v = 1; 881 _y4m->src_c_dec_v = 1;
813 if (only_420) { 882 if (only_420) {
814 _y4m->dst_c_dec_h = 2; 883 _y4m->dst_c_dec_h = 2;
815 _y4m->dst_c_dec_v = 2; 884 _y4m->dst_c_dec_v = 2;
816 _y4m->dst_buf_read_sz = _y4m->pic_w * _y4m->pic_h; 885 _y4m->dst_buf_read_sz = _y4m->pic_w * _y4m->pic_h;
817 /*Chroma filter required: read into the aux buf first. 886 /*Chroma filter required: read into the aux buf first.
818 We need to make two filter passes, so we need some extra space in the 887 We need to make two filter passes, so we need some extra space in the
819 aux buffer.*/ 888 aux buffer.*/
820 _y4m->aux_buf_read_sz = 2 * _y4m->pic_w * _y4m->pic_h; 889 _y4m->aux_buf_read_sz = 2 * _y4m->pic_w * _y4m->pic_h;
821 _y4m->aux_buf_sz = _y4m->aux_buf_read_sz + 890 _y4m->aux_buf_sz = _y4m->aux_buf_read_sz +
822 ((_y4m->pic_w + 1) / 2) * _y4m->pic_h; 891 ((_y4m->pic_w + 1) / 2) * _y4m->pic_h;
823 _y4m->convert = y4m_convert_444_420jpeg; 892 _y4m->convert = y4m_convert_444_420jpeg;
824 } else { 893 } else {
825 _y4m->vpx_fmt = VPX_IMG_FMT_I444; 894 _y4m->vpx_fmt = VPX_IMG_FMT_I444;
826 _y4m->vpx_bps = 24; 895 _y4m->bps = 24;
827 _y4m->dst_c_dec_h = _y4m->src_c_dec_h; 896 _y4m->dst_c_dec_h = _y4m->src_c_dec_h;
828 _y4m->dst_c_dec_v = _y4m->src_c_dec_v; 897 _y4m->dst_c_dec_v = _y4m->src_c_dec_v;
829 _y4m->dst_buf_read_sz = 3 * _y4m->pic_w * _y4m->pic_h; 898 _y4m->dst_buf_read_sz = 3 * _y4m->pic_w * _y4m->pic_h;
830 /*Natively supported: no conversion required.*/ 899 /*Natively supported: no conversion required.*/
831 _y4m->aux_buf_sz = _y4m->aux_buf_read_sz = 0; 900 _y4m->aux_buf_sz = _y4m->aux_buf_read_sz = 0;
832 _y4m->convert = y4m_convert_null; 901 _y4m->convert = y4m_convert_null;
833 } 902 }
903 } else if (strcmp(_y4m->chroma_type, "444p10") == 0) {
904 _y4m->src_c_dec_h = 1;
905 _y4m->src_c_dec_v = 1;
906 _y4m->vpx_fmt = VPX_IMG_FMT_I44416;
907 _y4m->bps = 30;
908 _y4m->bit_depth = 10;
909 _y4m->dst_c_dec_h = _y4m->src_c_dec_h;
910 _y4m->dst_c_dec_v = _y4m->src_c_dec_v;
911 _y4m->dst_buf_read_sz = 2 * 3 * _y4m->pic_w * _y4m->pic_h;
912 _y4m->aux_buf_sz = _y4m->aux_buf_read_sz = 0;
913 _y4m->convert = y4m_convert_null;
914 if (only_420) {
915 fprintf(stderr, "Unsupported conversion from 444p10 to 420jpeg\n");
916 return -1;
917 }
918 } else if (strcmp(_y4m->chroma_type, "444p12") == 0) {
919 _y4m->src_c_dec_h = 1;
920 _y4m->src_c_dec_v = 1;
921 _y4m->vpx_fmt = VPX_IMG_FMT_I44416;
922 _y4m->bps = 36;
923 _y4m->bit_depth = 12;
924 _y4m->dst_c_dec_h = _y4m->src_c_dec_h;
925 _y4m->dst_c_dec_v = _y4m->src_c_dec_v;
926 _y4m->dst_buf_read_sz = 2 * 3 * _y4m->pic_w * _y4m->pic_h;
927 _y4m->aux_buf_sz = _y4m->aux_buf_read_sz = 0;
928 _y4m->convert = y4m_convert_null;
929 if (only_420) {
930 fprintf(stderr, "Unsupported conversion from 444p12 to 420jpeg\n");
931 return -1;
932 }
834 } else if (strcmp(_y4m->chroma_type, "444alpha") == 0) { 933 } else if (strcmp(_y4m->chroma_type, "444alpha") == 0) {
835 _y4m->src_c_dec_h = 1; 934 _y4m->src_c_dec_h = 1;
836 _y4m->src_c_dec_v = 1; 935 _y4m->src_c_dec_v = 1;
837 if (only_420) { 936 if (only_420) {
838 _y4m->dst_c_dec_h = 2; 937 _y4m->dst_c_dec_h = 2;
839 _y4m->dst_c_dec_v = 2; 938 _y4m->dst_c_dec_v = 2;
840 _y4m->dst_buf_read_sz = _y4m->pic_w * _y4m->pic_h; 939 _y4m->dst_buf_read_sz = _y4m->pic_w * _y4m->pic_h;
841 /*Chroma filter required: read into the aux buf first. 940 /*Chroma filter required: read into the aux buf first.
842 We need to make two filter passes, so we need some extra space in the 941 We need to make two filter passes, so we need some extra space in the
843 aux buffer. 942 aux buffer.
844 The extra plane also gets read into the aux buf. 943 The extra plane also gets read into the aux buf.
845 It will be discarded.*/ 944 It will be discarded.*/
846 _y4m->aux_buf_sz = _y4m->aux_buf_read_sz = 3 * _y4m->pic_w * _y4m->pic_h; 945 _y4m->aux_buf_sz = _y4m->aux_buf_read_sz = 3 * _y4m->pic_w * _y4m->pic_h;
847 _y4m->convert = y4m_convert_444_420jpeg; 946 _y4m->convert = y4m_convert_444_420jpeg;
848 } else { 947 } else {
849 _y4m->vpx_fmt = VPX_IMG_FMT_444A; 948 _y4m->vpx_fmt = VPX_IMG_FMT_444A;
850 _y4m->vpx_bps = 32; 949 _y4m->bps = 32;
851 _y4m->dst_c_dec_h = _y4m->src_c_dec_h; 950 _y4m->dst_c_dec_h = _y4m->src_c_dec_h;
852 _y4m->dst_c_dec_v = _y4m->src_c_dec_v; 951 _y4m->dst_c_dec_v = _y4m->src_c_dec_v;
853 _y4m->dst_buf_read_sz = 4 * _y4m->pic_w * _y4m->pic_h; 952 _y4m->dst_buf_read_sz = 4 * _y4m->pic_w * _y4m->pic_h;
854 /*Natively supported: no conversion required.*/ 953 /*Natively supported: no conversion required.*/
855 _y4m->aux_buf_sz = _y4m->aux_buf_read_sz = 0; 954 _y4m->aux_buf_sz = _y4m->aux_buf_read_sz = 0;
856 _y4m->convert = y4m_convert_null; 955 _y4m->convert = y4m_convert_null;
857 } 956 }
858 } else if (strcmp(_y4m->chroma_type, "mono") == 0) { 957 } else if (strcmp(_y4m->chroma_type, "mono") == 0) {
859 _y4m->src_c_dec_h = _y4m->src_c_dec_v = 0; 958 _y4m->src_c_dec_h = _y4m->src_c_dec_v = 0;
860 _y4m->dst_c_dec_h = _y4m->dst_c_dec_v = 2; 959 _y4m->dst_c_dec_h = _y4m->dst_c_dec_v = 2;
861 _y4m->dst_buf_read_sz = _y4m->pic_w * _y4m->pic_h; 960 _y4m->dst_buf_read_sz = _y4m->pic_w * _y4m->pic_h;
862 /*No extra space required, but we need to clear the chroma planes.*/ 961 /*No extra space required, but we need to clear the chroma planes.*/
863 _y4m->aux_buf_sz = _y4m->aux_buf_read_sz = 0; 962 _y4m->aux_buf_sz = _y4m->aux_buf_read_sz = 0;
864 _y4m->convert = y4m_convert_mono_420jpeg; 963 _y4m->convert = y4m_convert_mono_420jpeg;
865 } else { 964 } else {
866 fprintf(stderr, "Unknown chroma sampling type: %s\n", _y4m->chroma_type); 965 fprintf(stderr, "Unknown chroma sampling type: %s\n", _y4m->chroma_type);
867 return -1; 966 return -1;
868 } 967 }
869 /*The size of the final frame buffers is always computed from the 968 /*The size of the final frame buffers is always computed from the
870 destination chroma decimation type.*/ 969 destination chroma decimation type.*/
871 _y4m->dst_buf_sz = _y4m->pic_w * _y4m->pic_h 970 _y4m->dst_buf_sz = _y4m->pic_w * _y4m->pic_h
872 + 2 * ((_y4m->pic_w + _y4m->dst_c_dec_h - 1) / _y4m->dst_c_ dec_h) * 971 + 2 * ((_y4m->pic_w + _y4m->dst_c_dec_h - 1) / _y4m->dst_c_ dec_h) *
873 ((_y4m->pic_h + _y4m->dst_c_dec_v - 1) / _y4m->dst_c_dec_v) ; 972 ((_y4m->pic_h + _y4m->dst_c_dec_v - 1) / _y4m->dst_c_dec_v) ;
874 _y4m->dst_buf = (unsigned char *)malloc(_y4m->dst_buf_sz); 973 if (_y4m->bit_depth == 8)
974 _y4m->dst_buf = (unsigned char *)malloc(_y4m->dst_buf_sz);
975 else
976 _y4m->dst_buf = (unsigned char *)malloc(2 * _y4m->dst_buf_sz);
875 _y4m->aux_buf = (unsigned char *)malloc(_y4m->aux_buf_sz); 977 _y4m->aux_buf = (unsigned char *)malloc(_y4m->aux_buf_sz);
876 return 0; 978 return 0;
877 } 979 }
878 980
879 void y4m_input_close(y4m_input *_y4m) { 981 void y4m_input_close(y4m_input *_y4m) {
880 free(_y4m->dst_buf); 982 free(_y4m->dst_buf);
881 free(_y4m->aux_buf); 983 free(_y4m->aux_buf);
882 } 984 }
883 985
884 int y4m_input_fetch_frame(y4m_input *_y4m, FILE *_fin, vpx_image_t *_img) { 986 int y4m_input_fetch_frame(y4m_input *_y4m, FILE *_fin, vpx_image_t *_img) {
885 char frame[6]; 987 char frame[6];
886 int pic_sz; 988 int pic_sz;
887 int c_w; 989 int c_w;
888 int c_h; 990 int c_h;
889 int c_sz; 991 int c_sz;
992 int bytes_per_sample = _y4m->bit_depth > 8 ? 2 : 1;
890 /*Read and skip the frame header.*/ 993 /*Read and skip the frame header.*/
891 if (!file_read(frame, 6, _fin)) return 0; 994 if (!file_read(frame, 6, _fin)) return 0;
892 if (memcmp(frame, "FRAME", 5)) { 995 if (memcmp(frame, "FRAME", 5)) {
893 fprintf(stderr, "Loss of framing in Y4M input data\n"); 996 fprintf(stderr, "Loss of framing in Y4M input data\n");
894 return -1; 997 return -1;
895 } 998 }
896 if (frame[5] != '\n') { 999 if (frame[5] != '\n') {
897 char c; 1000 char c;
898 int j; 1001 int j;
899 for (j = 0; j < 79 && file_read(&c, 1, _fin) && c != '\n'; j++) {} 1002 for (j = 0; j < 79 && file_read(&c, 1, _fin) && c != '\n'; j++) {}
(...skipping 17 matching lines...) Expand all
917 /*Fill in the frame buffer pointers. 1020 /*Fill in the frame buffer pointers.
918 We don't use vpx_img_wrap() because it forces padding for odd picture 1021 We don't use vpx_img_wrap() because it forces padding for odd picture
919 sizes, which would require a separate fread call for every row.*/ 1022 sizes, which would require a separate fread call for every row.*/
920 memset(_img, 0, sizeof(*_img)); 1023 memset(_img, 0, sizeof(*_img));
921 /*Y4M has the planes in Y'CbCr order, which libvpx calls Y, U, and V.*/ 1024 /*Y4M has the planes in Y'CbCr order, which libvpx calls Y, U, and V.*/
922 _img->fmt = _y4m->vpx_fmt; 1025 _img->fmt = _y4m->vpx_fmt;
923 _img->w = _img->d_w = _y4m->pic_w; 1026 _img->w = _img->d_w = _y4m->pic_w;
924 _img->h = _img->d_h = _y4m->pic_h; 1027 _img->h = _img->d_h = _y4m->pic_h;
925 _img->x_chroma_shift = _y4m->dst_c_dec_h >> 1; 1028 _img->x_chroma_shift = _y4m->dst_c_dec_h >> 1;
926 _img->y_chroma_shift = _y4m->dst_c_dec_v >> 1; 1029 _img->y_chroma_shift = _y4m->dst_c_dec_v >> 1;
927 _img->bps = _y4m->vpx_bps; 1030 _img->bps = _y4m->bps;
928 1031
929 /*Set up the buffer pointers.*/ 1032 /*Set up the buffer pointers.*/
930 pic_sz = _y4m->pic_w * _y4m->pic_h; 1033 pic_sz = _y4m->pic_w * _y4m->pic_h * bytes_per_sample;
931 c_w = (_y4m->pic_w + _y4m->dst_c_dec_h - 1) / _y4m->dst_c_dec_h; 1034 c_w = (_y4m->pic_w + _y4m->dst_c_dec_h - 1) / _y4m->dst_c_dec_h;
1035 c_w *= bytes_per_sample;
932 c_h = (_y4m->pic_h + _y4m->dst_c_dec_v - 1) / _y4m->dst_c_dec_v; 1036 c_h = (_y4m->pic_h + _y4m->dst_c_dec_v - 1) / _y4m->dst_c_dec_v;
933 c_sz = c_w * c_h; 1037 c_sz = c_w * c_h;
934 _img->stride[PLANE_Y] = _img->stride[PLANE_ALPHA] = _y4m->pic_w; 1038 _img->stride[PLANE_Y] = _img->stride[PLANE_ALPHA] =
1039 _y4m->pic_w * bytes_per_sample;
935 _img->stride[PLANE_U] = _img->stride[PLANE_V] = c_w; 1040 _img->stride[PLANE_U] = _img->stride[PLANE_V] = c_w;
936 _img->planes[PLANE_Y] = _y4m->dst_buf; 1041 _img->planes[PLANE_Y] = _y4m->dst_buf;
937 _img->planes[PLANE_U] = _y4m->dst_buf + pic_sz; 1042 _img->planes[PLANE_U] = _y4m->dst_buf + pic_sz;
938 _img->planes[PLANE_V] = _y4m->dst_buf + pic_sz + c_sz; 1043 _img->planes[PLANE_V] = _y4m->dst_buf + pic_sz + c_sz;
939 _img->planes[PLANE_ALPHA] = _y4m->dst_buf + pic_sz + 2 * c_sz; 1044 _img->planes[PLANE_ALPHA] = _y4m->dst_buf + pic_sz + 2 * c_sz;
940 return 1; 1045 return 1;
941 } 1046 }
OLDNEW
« no previous file with comments | « source/libvpx/y4minput.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698