From: Michel L. <wa...@us...> - 2002-07-08 05:28:21
|
Update of /cvsroot/libmpeg2/mpeg2dec/libmpeg2 In directory usw-pr-cvs1:/tmp/cvs-serv15823/libmpeg2 Modified Files: decode.c header.c mpeg2_internal.h Log Message: simplify aspect ratio calculation code - now it is all grouped in one single routine Index: decode.c =================================================================== RCS file: /cvsroot/libmpeg2/mpeg2dec/libmpeg2/decode.c,v retrieving revision 1.36 retrieving revision 1.37 diff -u -d -r1.36 -r1.37 --- decode.c 5 Jul 2002 09:07:35 -0000 1.36 +++ decode.c 8 Jul 2002 05:28:14 -0000 1.37 @@ -219,6 +219,7 @@ /* state transition after a sequence header */ case RECEIVED (0x00, STATE_SEQUENCE): case RECEIVED (0xb8, STATE_SEQUENCE): + mpeg2_header_sequence_finalize (mpeg2dec); if (!repeated_sequence(&(mpeg2dec->last_sequence), &(mpeg2dec->sequence))) { mpeg2dec->last_sequence = mpeg2dec->sequence; Index: header.c =================================================================== RCS file: /cvsroot/libmpeg2/mpeg2dec/libmpeg2/header.c,v retrieving revision 1.29 retrieving revision 1.30 diff -u -d -r1.29 -r1.30 --- header.c 23 Jun 2002 23:38:27 -0000 1.29 +++ header.c 8 Jul 2002 05:28:14 -0000 1.30 @@ -81,21 +81,6 @@ mpeg2dec->first = 1; } -static void simplify (unsigned int * num, unsigned int * denum) -{ - int a, b, tmp; - - a = *num; - b = *denum; - while (a) { - tmp = a; - a = b % tmp; - b = tmp; - } - *num /= b; - *denum /= b; -} - static void reset_info (mpeg2_info_t * info) { info->current_picture = info->current_picture_2nd = NULL; @@ -127,24 +112,7 @@ sequence->flags = SEQ_FLAG_PROGRESSIVE_SEQUENCE; - switch (buffer[3] >> 4) { - case 0: case 15: /* illegal */ - sequence->pixel_width = sequence->pixel_height = 0; break; - case 1: /* square pixels */ - sequence->flags |= SEQ_FLAG_SQUARE_PIXEL; - sequence->pixel_width = sequence->pixel_height = 1; break; - case 3: /* 720x576 16:9 */ - sequence->pixel_width = 64; sequence->pixel_height = 45; break; - case 6: /* 720x480 16:9 */ - sequence->pixel_width = 32; sequence->pixel_height = 27; break; - case 12: /* 720*480 4:3 */ - sequence->pixel_width = 8; sequence->pixel_height = 9; break; - default: - sequence->pixel_width = 2000; - sequence->pixel_height = 88 * (buffer[3] >> 4) + 1171; - simplify (&(sequence->pixel_width), &(sequence->pixel_height)); - } - + sequence->pixel_width = buffer[3] >> 4; /* aspect ratio */ sequence->frame_period = 0; if ((buffer[3] & 15) < 9) sequence->frame_period = frame_period[buffer[3] & 15]; @@ -217,28 +185,6 @@ ((buffer[1] << 13) | (buffer[2] << 5)) & 0x3000; height = sequence->display_height = sequence->picture_height += (buffer[2] << 7) & 0x3000; - do { - switch (sequence->pixel_height) { - case 1: /* square pixels */ - continue; - case 1347: /* 4:3 aspect ratio */ - sequence->pixel_width = 4 * height; - sequence->pixel_height = 3 * width; - break; - case 45: /* 16:9 aspect ratio */ - sequence->pixel_width = 16 * height; - sequence->pixel_height = 9 * width; - break; - case 1523: /* 2.21:1 aspect ratio */ - sequence->pixel_width = 221 * height; - sequence->pixel_height = 100 * width; - break; - default: - sequence->pixel_width = sequence->pixel_height = 0; - continue; - } - simplify (&(sequence->pixel_width), &(sequence->pixel_height)); - } while (0); flags = sequence->flags | SEQ_FLAG_MPEG2; decoder->progressive_sequence = buffer[1] >> 3; if (!(decoder->progressive_sequence)) { @@ -304,16 +250,66 @@ sequence->display_height = ((buffer[2]& 1 ) << 13) | (buffer[3] << 5) | (buffer[4] >> 3); - if (!(sequence->flags & SEQ_FLAG_SQUARE_PIXEL)) { - sequence->pixel_width *= sequence->picture_width; - sequence->pixel_height *= sequence->picture_height; - simplify (&(sequence->pixel_width), &(sequence->pixel_height)); - sequence->pixel_width *= sequence->display_height; - sequence->pixel_height *= sequence->display_width; - simplify (&(sequence->pixel_width), &(sequence->pixel_height)); + return 0; +} + +static void simplify (unsigned int * num, unsigned int * denum) +{ + int a, b, tmp; + + a = *num; + b = *denum; + while (a) { + tmp = a; + a = b % tmp; + b = tmp; } + *num /= b; + *denum /= b; +} - return 0; +void mpeg2_header_sequence_finalize (mpeg2dec_t * mpeg2dec) +{ + sequence_t * sequence = &(mpeg2dec->sequence); + + if (sequence->flags & SEQ_FLAG_MPEG2) { + int width; + int height; + switch (sequence->pixel_width) { + case 1: /* square pixels */ + sequence->pixel_width = sequence->pixel_height = 1; + return; + case 2: /* 4:3 aspect ratio */ + width = 4; height = 3; + break; + case 3: /* 16:9 aspect ratio */ + width = 16; height = 9; + break; + case 4: /* 2.21:1 aspect ratio */ + width = 221; height = 100; + break; + default: /* illegal */ + sequence->pixel_width = sequence->pixel_height = 0; + return; + } + sequence->pixel_width = width * sequence->display_height; + sequence->pixel_height = height * sequence->display_width; + } else switch (sequence->pixel_width) { + case 0: case 15: /* illegal */ + sequence->pixel_width = sequence->pixel_height = 0; break; + case 1: /* square pixels */ + sequence->pixel_width = sequence->pixel_height = 1; break; + case 3: /* 720x576 16:9 */ + sequence->pixel_width = 64; sequence->pixel_height = 45; break; + case 6: /* 720x480 16:9 */ + sequence->pixel_width = 32; sequence->pixel_height = 27; break; + case 12: /* 720*480 4:3 */ + sequence->pixel_width = 8; sequence->pixel_height = 9; break; + default: + sequence->pixel_width = 2000; + sequence->pixel_height = 88 * sequence->pixel_width + 1171; + } + simplify (&(sequence->pixel_width), &(sequence->pixel_height)); } int mpeg2_header_gop (mpeg2dec_t * mpeg2dec) Index: mpeg2_internal.h =================================================================== RCS file: /cvsroot/libmpeg2/mpeg2dec/libmpeg2/mpeg2_internal.h,v retrieving revision 1.36 retrieving revision 1.37 diff -u -d -r1.36 -r1.37 --- mpeg2_internal.h 29 Jun 2002 02:03:06 -0000 1.36 +++ mpeg2_internal.h 8 Jul 2002 05:28:14 -0000 1.37 @@ -214,6 +214,7 @@ int mpeg2_header_picture (mpeg2dec_t * mpeg2dec); int mpeg2_header_extension (mpeg2dec_t * mpeg2dec); int mpeg2_header_user_data (mpeg2dec_t * mpeg2dec); +void mpeg2_header_sequence_finalize (mpeg2dec_t * mpeg2dec); void mpeg2_header_slice (mpeg2dec_t * mpeg2dec); void mpeg2_header_end (mpeg2dec_t * mpeg2dec); |