--- decoder.c 2003/11/30 16:13:15 1.49.2.20 +++ decoder.c 2003/12/21 19:41:53 1.49.2.28 @@ -20,7 +20,7 @@ * along with this program ; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * $Id: decoder.c,v 1.49.2.20 2003/11/30 16:13:15 edgomez Exp $ + * $Id: decoder.c,v 1.49.2.28 2003/12/21 19:41:53 Isibaar Exp $ * ****************************************************************************/ @@ -58,6 +58,7 @@ #include "image/image.h" #include "image/colorspace.h" +#include "image/postprocessing.h" #include "utils/mem_align.h" static int @@ -204,6 +205,7 @@ dec->last_mbs = NULL; init_timer(); + init_postproc(&dec->postproc); init_mpeg_matrix(dec->mpeg_quant_matrices); /* For B-frame support (used to save reference frame's time */ @@ -1314,8 +1316,22 @@ /* perform post processing if necessary, and output the image */ void decoder_output(DECODER * dec, IMAGE * img, MACROBLOCK * mbs, - xvid_dec_frame_t * frame, xvid_dec_stats_t * stats, int coding_type) + xvid_dec_frame_t * frame, xvid_dec_stats_t * stats, + int coding_type, int quant) { + if (dec->cartoon_mode) + frame->general &= ~XVID_FILMEFFECT; + + if (frame->general & (XVID_DEBLOCKY|XVID_DEBLOCKUV|XVID_FILMEFFECT) && mbs != NULL) /* post process */ + { + /* note: image is stored to tmp */ + image_copy(&dec->tmp, img, dec->edged_width, dec->height); + image_postproc(&dec->postproc, &dec->tmp, dec->edged_width, + mbs, dec->mb_width, dec->mb_height, dec->mb_width, + frame->general, dec->frames, (coding_type == B_VOP)); + img = &dec->tmp; + } + image_output(img, dec->width, dec->height, dec->edged_width, (uint8_t**)frame->output.plane, frame->output.stride, frame->output.csp, dec->interlacing); @@ -1359,7 +1375,7 @@ /* if not decoding "low_delay/packed", and this isn't low_delay and we have a reference frame, then outout the reference frame */ if (!(dec->low_delay_default && dec->packed_mode) && !dec->low_delay && dec->frames>0) { - decoder_output(dec, &dec->refn[0], dec->last_mbs, frame, stats, dec->last_coding_type); + decoder_output(dec, &dec->refn[0], dec->last_mbs, frame, stats, dec->last_coding_type, quant); dec->frames = 0; ret = 0; } else { @@ -1429,7 +1445,7 @@ /* packed_mode: special-N_VOP treament */ if (dec->packed_mode && coding_type == N_VOP) { if (dec->low_delay_default && dec->frames > 0) { - decoder_output(dec, &dec->refn[0], dec->last_mbs, frame, stats, dec->last_coding_type); + decoder_output(dec, &dec->refn[0], dec->last_mbs, frame, stats, dec->last_coding_type, quant); output = 1; } /* ignore otherwise */ @@ -1450,6 +1466,7 @@ /* XXX: not_coded vops are not used for forward prediction */ /* we should not swap(last_mbs,mbs) */ image_copy(&dec->cur, &dec->refn[0], dec->edged_width, dec->height); + SWAP(MACROBLOCK *, dec->mbs, dec->last_mbs); /* it will be swapped back */ break; } @@ -1462,11 +1479,11 @@ /* note: for packed_mode, output is performed when the special-N_VOP is decoded */ if (!(dec->low_delay_default && dec->packed_mode)) { if (dec->low_delay) { - decoder_output(dec, &dec->cur, dec->mbs, frame, stats, coding_type); + decoder_output(dec, &dec->cur, dec->mbs, frame, stats, coding_type, quant); output = 1; } else if (dec->frames > 0) { /* is the reference frame valid? */ /* output the reference frame */ - decoder_output(dec, &dec->refn[0], dec->last_mbs, frame, stats, dec->last_coding_type); + decoder_output(dec, &dec->refn[0], dec->last_mbs, frame, stats, dec->last_coding_type, quant); output = 1; } } @@ -1491,16 +1508,18 @@ /* attemping to decode a bvop without atleast 2 reference frames */ image_printf(&dec->cur, dec->edged_width, dec->height, 16, 16, "broken b-frame, mising ref frames"); + stats->type = XVID_TYPE_NOTHING; } else if (dec->time_pp <= dec->time_bp) { /* this occurs when dx50_bvop_compatibility==0 sequences are decoded in vfw. */ image_printf(&dec->cur, dec->edged_width, dec->height, 16, 16, "broken b-frame, tpp=%i tbp=%i", dec->time_pp, dec->time_bp); + stats->type = XVID_TYPE_NOTHING; } else { decoder_bframe(dec, &bs, quant, fcode_forward, fcode_backward); + decoder_output(dec, &dec->cur, dec->mbs, frame, stats, coding_type, quant); } - decoder_output(dec, &dec->cur, dec->mbs, frame, stats, coding_type); output = 1; dec->frames++; } @@ -1520,7 +1539,7 @@ if (dec->low_delay_default && output == 0) { if (dec->packed_mode && seen_something) { /* output the recently decoded frame */ - decoder_output(dec, &dec->refn[0], dec->last_mbs, frame, stats, dec->last_coding_type); + decoder_output(dec, &dec->refn[0], dec->last_mbs, frame, stats, dec->last_coding_type, quant); } else { image_clear(&dec->cur, dec->width, dec->height, dec->edged_width, 0, 128, 128); image_printf(&dec->cur, dec->edged_width, dec->height, 16, 16, @@ -1528,7 +1547,7 @@ image_printf(&dec->cur, dec->edged_width, dec->height, 16, 64, "bframe decoder lag"); - decoder_output(dec, &dec->cur, NULL, frame, stats, P_VOP); + decoder_output(dec, &dec->cur, NULL, frame, stats, P_VOP, quant); if (stats) stats->type = XVID_TYPE_NOTHING; } }