From d3e2c4e2f1dd26f4abb62622a1e3a2869d2f3dc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Reinhard=20Ni=C3=9Fl?= Date: Tue, 1 Jan 2008 00:01:29 +0100 Subject: Use signed data type for pan&scan center offset components. According to specification the center offset components are signed integers. --- src/libmpeg2/header.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'src/libmpeg2/header.c') diff --git a/src/libmpeg2/header.c b/src/libmpeg2/header.c index 7f1ef1fc8..c0df02c7f 100644 --- a/src/libmpeg2/header.c +++ b/src/libmpeg2/header.c @@ -101,6 +101,14 @@ static uint32_t get_bits(uint8_t *buffer, uint32_t count, uint32_t *bit_position return result; } +static int32_t get_bits_signed(uint8_t *buffer, uint32_t count, uint32_t *bit_position) { + uint32_t value = get_bits(buffer, count, bit_position); + uint32_t sign_mask = (uint32_t)(-1 << (count - 1)); + if (value & sign_mask) + value |= sign_mask; /* sign-extend value */ + return (int32_t)value; +} + void mpeg2_header_state_init (picture_t * picture) { picture->scan = mpeg2_scan_norm; @@ -291,13 +299,13 @@ static int picture_display_extension (picture_t * picture, uint8_t * buffer) { bit_position = 0; padding = get_bits(buffer, 4, &bit_position); - picture->frame_centre_horizontal_offset = get_bits(buffer, 16, &bit_position); + picture->frame_centre_horizontal_offset = get_bits_signed(buffer, 16, &bit_position); padding = get_bits(buffer, 1, &bit_position); - picture->frame_centre_vertical_offset = get_bits(buffer, 16, &bit_position); + picture->frame_centre_vertical_offset = get_bits_signed(buffer, 16, &bit_position); padding = get_bits(buffer, 1, &bit_position); #ifdef LOG_PAN_SCAN - printf("Pan & Scan centre (x,y) = (%u, %u)\n", + printf("Pan & Scan centre (x,y) = (%d, %d)\n", picture->frame_centre_horizontal_offset, picture->frame_centre_vertical_offset); #endif -- cgit v1.2.3