Mercurial > libavcodec.hg
comparison mpegvideo.c @ 244:3860331a1ecb libavcodec
* eliminating duplicated code from MPV_common_end
* simplified indexing
author | kabi |
---|---|
date | Mon, 18 Feb 2002 09:31:37 +0000 |
parents | 16cd8a9c4da4 |
children | 56ee684c48bb |
comparison
equal
deleted
inserted
replaced
243:a6519f773064 | 244:3860331a1ecb |
---|---|
226 } | 226 } |
227 | 227 |
228 s->context_initialized = 1; | 228 s->context_initialized = 1; |
229 return 0; | 229 return 0; |
230 fail: | 230 fail: |
231 MPV_common_end(s); | |
232 return -1; | |
233 } | |
234 | |
235 /* init common structure for both encoder and decoder */ | |
236 void MPV_common_end(MpegEncContext *s) | |
237 { | |
238 int i; | |
239 | |
231 if (s->mb_type) | 240 if (s->mb_type) |
232 free(s->mb_type); | 241 free(s->mb_type); |
233 if (s->mb_var) | 242 if (s->mb_var) |
234 free(s->mb_var); | 243 free(s->mb_var); |
235 if (s->mv_table[0]) | 244 if (s->mv_table[0]) |
244 free(s->ac_val[0]); | 253 free(s->ac_val[0]); |
245 if (s->coded_block) | 254 if (s->coded_block) |
246 free(s->coded_block); | 255 free(s->coded_block); |
247 if (s->mbintra_table) | 256 if (s->mbintra_table) |
248 free(s->mbintra_table); | 257 free(s->mbintra_table); |
258 | |
249 if (s->mbskip_table) | 259 if (s->mbskip_table) |
250 free(s->mbskip_table); | 260 free(s->mbskip_table); |
251 for(i=0;i<3;i++) { | 261 for(i=0;i<3;i++) { |
252 if (s->last_picture_base[i]) | 262 if (s->last_picture_base[i]) |
253 free(s->last_picture_base[i]); | 263 free(s->last_picture_base[i]); |
254 if (s->next_picture_base[i]) | 264 if (s->next_picture_base[i]) |
255 free(s->next_picture_base[i]); | 265 free(s->next_picture_base[i]); |
256 if (s->aux_picture_base[i]) | |
257 free(s->aux_picture_base[i]); | |
258 } | |
259 return -1; | |
260 } | |
261 | |
262 /* init common structure for both encoder and decoder */ | |
263 void MPV_common_end(MpegEncContext *s) | |
264 { | |
265 int i; | |
266 | |
267 if (s->mb_type) | |
268 free(s->mb_type); | |
269 if (s->mb_var) | |
270 free(s->mb_var); | |
271 if (s->mv_table[0]) | |
272 free(s->mv_table[0]); | |
273 if (s->mv_table[1]) | |
274 free(s->mv_table[1]); | |
275 if (s->motion_val) | |
276 free(s->motion_val); | |
277 if (s->h263_pred) { | |
278 free(s->dc_val[0]); | |
279 free(s->ac_val[0]); | |
280 free(s->coded_block); | |
281 free(s->mbintra_table); | |
282 } | |
283 if (s->mbskip_table) | |
284 free(s->mbskip_table); | |
285 for(i=0;i<3;i++) { | |
286 free(s->last_picture_base[i]); | |
287 free(s->next_picture_base[i]); | |
288 if (s->has_b_frames) | 266 if (s->has_b_frames) |
289 free(s->aux_picture_base[i]); | 267 free(s->aux_picture_base[i]); |
290 } | 268 } |
291 s->context_initialized = 0; | 269 s->context_initialized = 0; |
292 } | 270 } |
751 s->mv : motion vector | 729 s->mv : motion vector |
752 s->interlaced_dct : true if interlaced dct used (mpeg2) | 730 s->interlaced_dct : true if interlaced dct used (mpeg2) |
753 */ | 731 */ |
754 void MPV_decode_mb(MpegEncContext *s, DCTELEM block[6][64]) | 732 void MPV_decode_mb(MpegEncContext *s, DCTELEM block[6][64]) |
755 { | 733 { |
756 int mb_x, mb_y, motion_x, motion_y; | 734 int mb_x, mb_y; |
757 int dct_linesize, dct_offset; | 735 int dct_linesize, dct_offset; |
758 op_pixels_func *op_pix; | 736 op_pixels_func *op_pix; |
759 | 737 |
760 mb_x = s->mb_x; | 738 mb_x = s->mb_x; |
761 mb_y = s->mb_y; | 739 mb_y = s->mb_y; |
768 /* update DC predictors for P macroblocks */ | 746 /* update DC predictors for P macroblocks */ |
769 if (!s->mb_intra) { | 747 if (!s->mb_intra) { |
770 if (s->h263_pred) { | 748 if (s->h263_pred) { |
771 if(s->mbintra_table[mb_x + mb_y*s->mb_width]) | 749 if(s->mbintra_table[mb_x + mb_y*s->mb_width]) |
772 { | 750 { |
773 int wrap, x, y, v; | 751 int wrap, xy, v; |
774 s->mbintra_table[mb_x + mb_y*s->mb_width]=0; | 752 s->mbintra_table[mb_x + mb_y*s->mb_width]=0; |
775 | |
776 wrap = 2 * s->mb_width + 2; | 753 wrap = 2 * s->mb_width + 2; |
754 xy = 2 * mb_x + 1 + (2 * mb_y + 1) * wrap; | |
777 v = 1024; | 755 v = 1024; |
778 x = 2 * mb_x + 1; | |
779 y = 2 * mb_y + 1; | |
780 | 756 |
781 s->dc_val[0][(x) + (y) * wrap] = v; | 757 s->dc_val[0][xy] = v; |
782 s->dc_val[0][(x + 1) + (y) * wrap] = v; | 758 s->dc_val[0][xy + 1] = v; |
783 s->dc_val[0][(x) + (y + 1) * wrap] = v; | 759 s->dc_val[0][xy + wrap] = v; |
784 s->dc_val[0][(x + 1) + (y + 1) * wrap] = v; | 760 s->dc_val[0][xy + 1 + wrap] = v; |
785 /* ac pred */ | 761 /* ac pred */ |
786 memset(s->ac_val[0][(x) + (y) * wrap], 0, 16 * sizeof(INT16)); | 762 memset(s->ac_val[0][xy], 0, 16 * sizeof(INT16)); |
787 memset(s->ac_val[0][(x + 1) + (y) * wrap], 0, 16 * sizeof(INT16)); | 763 memset(s->ac_val[0][xy + 1], 0, 16 * sizeof(INT16)); |
788 memset(s->ac_val[0][(x) + (y + 1) * wrap], 0, 16 * sizeof(INT16)); | 764 memset(s->ac_val[0][xy + wrap], 0, 16 * sizeof(INT16)); |
789 memset(s->ac_val[0][(x + 1) + (y + 1) * wrap], 0, 16 * sizeof(INT16)); | 765 memset(s->ac_val[0][xy + 1 + wrap], 0, 16 * sizeof(INT16)); |
790 if (s->h263_msmpeg4) { | 766 if (s->h263_msmpeg4) { |
791 s->coded_block[(x) + (y) * wrap] = 0; | 767 s->coded_block[xy] = 0; |
792 s->coded_block[(x + 1) + (y) * wrap] = 0; | 768 s->coded_block[xy + 1] = 0; |
793 s->coded_block[(x) + (y + 1) * wrap] = 0; | 769 s->coded_block[xy + wrap] = 0; |
794 s->coded_block[(x + 1) + (y + 1) * wrap] = 0; | 770 s->coded_block[xy + 1 + wrap] = 0; |
795 } | 771 } |
796 /* chroma */ | 772 /* chroma */ |
797 wrap = s->mb_width + 2; | 773 wrap = s->mb_width + 2; |
798 x = mb_x + 1; | 774 xy = mb_x + 1 + (mb_y + 1) * wrap; |
799 y = mb_y + 1; | 775 s->dc_val[1][xy] = v; |
800 s->dc_val[1][(x) + (y) * wrap] = v; | 776 s->dc_val[2][xy] = v; |
801 s->dc_val[2][(x) + (y) * wrap] = v; | |
802 /* ac pred */ | 777 /* ac pred */ |
803 memset(s->ac_val[1][(x) + (y) * wrap], 0, 16 * sizeof(INT16)); | 778 memset(s->ac_val[1][xy], 0, 16 * sizeof(INT16)); |
804 memset(s->ac_val[2][(x) + (y) * wrap], 0, 16 * sizeof(INT16)); | 779 memset(s->ac_val[2][xy], 0, 16 * sizeof(INT16)); |
805 } | 780 } |
806 } else { | 781 } else { |
807 s->last_dc[0] = 128 << s->intra_dc_precision; | 782 s->last_dc[0] = 128 << s->intra_dc_precision; |
808 s->last_dc[1] = 128 << s->intra_dc_precision; | 783 s->last_dc[1] = 128 << s->intra_dc_precision; |
809 s->last_dc[2] = 128 << s->intra_dc_precision; | 784 s->last_dc[2] = 128 << s->intra_dc_precision; |
812 else if (s->h263_pred) | 787 else if (s->h263_pred) |
813 s->mbintra_table[mb_x + mb_y*s->mb_width]=1; | 788 s->mbintra_table[mb_x + mb_y*s->mb_width]=1; |
814 | 789 |
815 /* update motion predictor */ | 790 /* update motion predictor */ |
816 if (s->out_format == FMT_H263) { | 791 if (s->out_format == FMT_H263) { |
817 int x, y, wrap; | 792 int xy, wrap, motion_x, motion_y; |
818 | 793 |
819 x = 2 * mb_x + 1; | |
820 y = 2 * mb_y + 1; | |
821 wrap = 2 * s->mb_width + 2; | 794 wrap = 2 * s->mb_width + 2; |
795 xy = 2 * mb_x + 1 + (2 * mb_y + 1) * wrap; | |
822 if (s->mb_intra) { | 796 if (s->mb_intra) { |
823 motion_x = 0; | 797 motion_x = 0; |
824 motion_y = 0; | 798 motion_y = 0; |
825 goto motion_init; | 799 goto motion_init; |
826 } else if (s->mv_type == MV_TYPE_16X16) { | 800 } else if (s->mv_type == MV_TYPE_16X16) { |
827 motion_x = s->mv[0][0][0]; | 801 motion_x = s->mv[0][0][0]; |
828 motion_y = s->mv[0][0][1]; | 802 motion_y = s->mv[0][0][1]; |
829 motion_init: | 803 motion_init: |
830 /* no update if 8X8 because it has been done during parsing */ | 804 /* no update if 8X8 because it has been done during parsing */ |
831 s->motion_val[(x) + (y) * wrap][0] = motion_x; | 805 s->motion_val[xy][0] = motion_x; |
832 s->motion_val[(x) + (y) * wrap][1] = motion_y; | 806 s->motion_val[xy][1] = motion_y; |
833 s->motion_val[(x + 1) + (y) * wrap][0] = motion_x; | 807 s->motion_val[xy + 1][0] = motion_x; |
834 s->motion_val[(x + 1) + (y) * wrap][1] = motion_y; | 808 s->motion_val[xy + 1][1] = motion_y; |
835 s->motion_val[(x) + (y + 1) * wrap][0] = motion_x; | 809 s->motion_val[xy + wrap][0] = motion_x; |
836 s->motion_val[(x) + (y + 1) * wrap][1] = motion_y; | 810 s->motion_val[xy + wrap][1] = motion_y; |
837 s->motion_val[(x + 1) + (y + 1) * wrap][0] = motion_x; | 811 s->motion_val[xy + 1 + wrap][0] = motion_x; |
838 s->motion_val[(x + 1) + (y + 1) * wrap][1] = motion_y; | 812 s->motion_val[xy + 1 + wrap][1] = motion_y; |
839 } | 813 } |
840 } | 814 } |
841 | 815 |
842 if (!s->intra_only) { | 816 if (!s->intra_only) { |
843 UINT8 *dest_y, *dest_cb, *dest_cr; | 817 UINT8 *dest_y, *dest_cb, *dest_cr; |