diff options
Diffstat (limited to 'libavcodec/dirac.c')
-rw-r--r-- | libavcodec/dirac.c | 44 |
1 files changed, 26 insertions, 18 deletions
diff --git a/libavcodec/dirac.c b/libavcodec/dirac.c index 5e13a84..07db919 100644 --- a/libavcodec/dirac.c +++ b/libavcodec/dirac.c @@ -1,28 +1,29 @@ /* * Copyright (C) 2007 Marco Gerards <marco@gnu.org> * Copyright (C) 2009 David Conrad + * Copyright (C) 2011 Jordi Ortiz * - * 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 */ /** * @file * Dirac Decoder - * @author Marco Gerards <marco@gnu.org> + * @author Marco Gerards <marco@gnu.org>, David Conrad, Jordi Ortiz <nenjordi@gmail.com> */ #include "libavutil/imgutils.h" @@ -33,7 +34,7 @@ #include "internal.h" #include "mpeg12data.h" -// defaults for source parameters +/* defaults for source parameters */ static const dirac_source_params dirac_source_parameters_defaults[] = { { 640, 480, 2, 0, 0, 1, 1, 640, 480, 0, 0, 1, 0 }, { 176, 120, 2, 0, 0, 9, 2, 176, 120, 0, 0, 1, 1 }, @@ -122,6 +123,7 @@ static int parse_source_parameters(AVCodecContext *avctx, GetBitContext *gb, AVRational frame_rate = { 0, 0 }; unsigned luma_depth = 8, luma_offset = 16; int idx; + int chroma_x_shift, chroma_y_shift; /* [DIRAC_STD] 10.3.2 Frame size. frame_size(video_params) */ /* [DIRAC_STD] custom_dimensions_flag */ @@ -136,7 +138,7 @@ static int parse_source_parameters(AVCodecContext *avctx, GetBitContext *gb, if (get_bits1(gb)) /* [DIRAC_STD] CHROMA_FORMAT_INDEX */ source->chroma_format = svq3_get_ue_golomb(gb); - if (source->chroma_format > 2) { + if (source->chroma_format > 2U) { av_log(avctx, AV_LOG_ERROR, "Unknown chroma format %d\n", source->chroma_format); return AVERROR_INVALIDDATA; @@ -147,14 +149,14 @@ static int parse_source_parameters(AVCodecContext *avctx, GetBitContext *gb, if (get_bits1(gb)) /* [DIRAC_STD] SOURCE_SAMPLING */ source->interlaced = svq3_get_ue_golomb(gb); - if (source->interlaced > 1) + if (source->interlaced > 1U) return AVERROR_INVALIDDATA; /* [DIRAC_STD] 10.3.5 Frame Rate. frame_rate(video_params) */ if (get_bits1(gb)) { /* [DIRAC_STD] custom_frame_rate_flag */ source->frame_rate_index = svq3_get_ue_golomb(gb); - if (source->frame_rate_index > 10) + if (source->frame_rate_index > 10U) return AVERROR_INVALIDDATA; if (!source->frame_rate_index) { @@ -180,7 +182,7 @@ static int parse_source_parameters(AVCodecContext *avctx, GetBitContext *gb, /* [DIRAC_STD] index */ source->aspect_ratio_index = svq3_get_ue_golomb(gb); - if (source->aspect_ratio_index > 6) + if (source->aspect_ratio_index > 6U) return AVERROR_INVALIDDATA; if (!source->aspect_ratio_index) { @@ -213,10 +215,10 @@ static int parse_source_parameters(AVCodecContext *avctx, GetBitContext *gb, /* [DIRAC_STD] index */ source->pixel_range_index = svq3_get_ue_golomb(gb); - if (source->pixel_range_index > 4) + if (source->pixel_range_index > 4U) return AVERROR_INVALIDDATA; - // This assumes either fullrange or MPEG levels only + /* This assumes either fullrange or MPEG levels only */ if (!source->pixel_range_index) { luma_offset = svq3_get_ue_golomb(gb); luma_depth = av_log2(svq3_get_ue_golomb(gb)) + 1; @@ -235,16 +237,22 @@ static int parse_source_parameters(AVCodecContext *avctx, GetBitContext *gb, } if (luma_depth > 8) - av_log(avctx, AV_LOG_WARNING, "Bitdepth greater than 8"); + av_log(avctx, AV_LOG_WARNING, "Bitdepth greater than 8\n"); avctx->pix_fmt = dirac_pix_fmt[!luma_offset][source->chroma_format]; + avcodec_get_chroma_sub_sample(avctx->pix_fmt, &chroma_x_shift, &chroma_y_shift); + if ((source->width % (1<<chroma_x_shift)) || (source->height % (1<<chroma_y_shift))) { + av_log(avctx, AV_LOG_ERROR, "Dimensions must be an integer multiple of the chroma subsampling\n"); + return AVERROR_INVALIDDATA; + } + /* [DIRAC_STD] 10.3.9 Colour specification. colour_spec(video_params) */ if (get_bits1(gb)) { /* [DIRAC_STD] custom_colour_spec_flag */ /* [DIRAC_STD] index */ idx = source->color_spec_index = svq3_get_ue_golomb(gb); - if (source->color_spec_index > 4) + if (source->color_spec_index > 4U) return AVERROR_INVALIDDATA; avctx->color_primaries = dirac_color_presets[idx].color_primaries; @@ -255,7 +263,7 @@ static int parse_source_parameters(AVCodecContext *avctx, GetBitContext *gb, /* [DIRAC_STD] 10.3.9.1 Colour primaries */ if (get_bits1(gb)) { idx = svq3_get_ue_golomb(gb); - if (idx < 3) + if (idx < 3U) avctx->color_primaries = dirac_primaries[idx]; } /* [DIRAC_STD] 10.3.9.2 Colour matrix */ @@ -302,10 +310,10 @@ int avpriv_dirac_parse_sequence_header(AVCodecContext *avctx, GetBitContext *gb, else if (version_major > 2) av_log(avctx, AV_LOG_WARNING, "Stream may have unhandled features\n"); - if (video_format > 20) + if (video_format > 20U) return AVERROR_INVALIDDATA; - // Fill in defaults for the source parameters. + /* Fill in defaults for the source parameters. */ *source = dirac_source_parameters_defaults[video_format]; /* [DIRAC_STD] 10.3 Source Parameters @@ -323,7 +331,7 @@ int avpriv_dirac_parse_sequence_header(AVCodecContext *avctx, GetBitContext *gb, * currently only used to signal field coding */ picture_coding_mode = svq3_get_ue_golomb(gb); if (picture_coding_mode != 0) { - av_log(avctx, AV_LOG_ERROR, "Unsupported picture coding mode %d", + av_log(avctx, AV_LOG_ERROR, "Unsupported picture coding mode %d\n", picture_coding_mode); return AVERROR_INVALIDDATA; } |