diff options
Diffstat (limited to 'libavcodec/truemotion1.c')
-rw-r--r-- | libavcodec/truemotion1.c | 35 |
1 files changed, 21 insertions, 14 deletions
diff --git a/libavcodec/truemotion1.c b/libavcodec/truemotion1.c index 3eab33a..da843c4 100644 --- a/libavcodec/truemotion1.c +++ b/libavcodec/truemotion1.c @@ -2,20 +2,20 @@ * Duck TrueMotion 1.0 Decoder * Copyright (C) 2003 Alex Beregszaszi & Mike Melanson * - * This file is part of Libav. + * This file is part of FFmpeg. * - * Libav is free software; you can redistribute it and/or + * FFmpeg is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * - * Libav is distributed in the hope that it will be useful, + * FFmpeg is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with Libav; if not, write to the Free Software + * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ @@ -215,7 +215,7 @@ static int make_cdt16_entry(int p1, int p2, int16_t *cdt) b = cdt[p2]; r = cdt[p1] << 11; lo = b + r; - return (lo + (lo << 16)) << 1; + return (lo + (lo * (1 << 16))) * 2; } static int make_ydt24_entry(int p1, int p2, int16_t *ydt) @@ -224,7 +224,7 @@ static int make_ydt24_entry(int p1, int p2, int16_t *ydt) lo = ydt[p1]; hi = ydt[p2]; - return (lo + (hi << 8) + (hi << 16)) << 1; + return (lo + (hi * (1 << 8)) + (hi * (1 << 16))) * 2; } static int make_cdt24_entry(int p1, int p2, int16_t *cdt) @@ -232,8 +232,8 @@ static int make_cdt24_entry(int p1, int p2, int16_t *cdt) int r, b; b = cdt[p2]; - r = cdt[p1]<<16; - return (b+r) << 1; + r = cdt[p1] * (1 << 16); + return (b+r) * 2; } static void gen_vector_table15(TrueMotion1Context *s, const uint8_t *sel_vector_table) @@ -396,12 +396,16 @@ static int truemotion1_decode_header(TrueMotion1Context *s) } if (compression_types[header.compression].algorithm == ALGO_RGB24H) { - new_pix_fmt = AV_PIX_FMT_RGB32; + new_pix_fmt = AV_PIX_FMT_0RGB32; width_shift = 1; } else new_pix_fmt = AV_PIX_FMT_RGB555; // RGB565 is supported as well s->w >>= width_shift; + if (s->w & 1) { + avpriv_request_sample(s->avctx, "Frame with odd width"); + return AVERROR_PATCHWELCOME; + } if (s->w != s->avctx->width || s->h != s->avctx->height || new_pix_fmt != s->avctx->pix_fmt) { @@ -415,6 +419,8 @@ static int truemotion1_decode_header(TrueMotion1Context *s) ff_set_sar(s->avctx, s->avctx->sample_aspect_ratio); av_fast_malloc(&s->vert_pred, &s->vert_pred_size, s->avctx->width * sizeof(unsigned int)); + if (!s->vert_pred) + return AVERROR(ENOMEM); } /* There is 1 change bit per 4 pixels, so each change byte represents @@ -483,6 +489,8 @@ static av_cold int truemotion1_decode_init(AVCodecContext *avctx) /* there is a vertical predictor for each pixel in a line; each vertical * predictor is 0 to start with */ av_fast_malloc(&s->vert_pred, &s->vert_pred_size, s->avctx->width * sizeof(unsigned int)); + if (!s->vert_pred) + return AVERROR(ENOMEM); return 0; } @@ -637,7 +645,8 @@ static void truemotion1_decode_16bit(TrueMotion1Context *s) current_pixel_pair = (unsigned int *)current_line; vert_pred = s->vert_pred; mb_change_index = 0; - mb_change_byte = mb_change_bits[mb_change_index++]; + if (!keyframe) + mb_change_byte = mb_change_bits[mb_change_index++]; mb_change_byte_mask = 0x01; pixels_left = s->avctx->width; @@ -871,10 +880,8 @@ static int truemotion1_decode_frame(AVCodecContext *avctx, if ((ret = truemotion1_decode_header(s)) < 0) return ret; - if ((ret = ff_reget_buffer(avctx, s->frame)) < 0) { - av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed\n"); + if ((ret = ff_reget_buffer(avctx, s->frame)) < 0) return ret; - } if (compression_types[s->compression].algorithm == ALGO_RGB24H) { truemotion1_decode_24bit(s); @@ -896,7 +903,7 @@ static av_cold int truemotion1_decode_end(AVCodecContext *avctx) TrueMotion1Context *s = avctx->priv_data; av_frame_free(&s->frame); - av_free(s->vert_pred); + av_freep(&s->vert_pred); return 0; } |