summaryrefslogtreecommitdiff
path: root/libavcodec/dirac.c
diff options
context:
space:
mode:
Diffstat (limited to 'libavcodec/dirac.c')
-rw-r--r--libavcodec/dirac.c79
1 files changed, 45 insertions, 34 deletions
diff --git a/libavcodec/dirac.c b/libavcodec/dirac.c
index 142af20579..027ce79a2e 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"
@@ -55,7 +56,7 @@ typedef struct dirac_source_params {
uint8_t color_spec_index; ///< index into dirac_color_spec_presets[]
} dirac_source_params;
-// 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 },
@@ -130,10 +131,11 @@ static const struct {
{ AVCOL_PRI_BT709, AVCOL_SPC_BT709, AVCOL_TRC_UNSPECIFIED /* DCinema */ },
};
-/* [DIRAC_STD] Table 10.2 Supported chroma sampling formats + luma Offset */
-static const enum AVPixelFormat dirac_pix_fmt[2][3] = {
- { AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUV420P },
- { AV_PIX_FMT_YUVJ444P, AV_PIX_FMT_YUVJ422P, AV_PIX_FMT_YUVJ420P },
+/* [DIRAC_STD] Table 10.2 Supported chroma sampling formats */
+static const enum AVPixelFormat dirac_pix_fmt[][3] = {
+ {AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUV444P10, AV_PIX_FMT_YUV444P12},
+ {AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUV422P10, AV_PIX_FMT_YUV422P12},
+ {AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUV420P10, AV_PIX_FMT_YUV420P12},
};
/* [DIRAC_STD] 10.3 Parse Source Parameters.
@@ -144,6 +146,7 @@ static int parse_source_parameters(AVDiracSeqHeader *dsh, 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 */
@@ -158,7 +161,7 @@ static int parse_source_parameters(AVDiracSeqHeader *dsh, GetBitContext *gb,
if (get_bits1(gb))
/* [DIRAC_STD] CHROMA_FORMAT_INDEX */
dsh->chroma_format = get_interleaved_ue_golomb(gb);
- if (dsh->chroma_format > 2) {
+ if (dsh->chroma_format > 2U) {
if (log_ctx)
av_log(log_ctx, AV_LOG_ERROR, "Unknown chroma format %d\n",
dsh->chroma_format);
@@ -170,14 +173,14 @@ static int parse_source_parameters(AVDiracSeqHeader *dsh, GetBitContext *gb,
if (get_bits1(gb))
/* [DIRAC_STD] SOURCE_SAMPLING */
dsh->interlaced = get_interleaved_ue_golomb(gb);
- if (dsh->interlaced > 1)
+ if (dsh->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 */
dsh->frame_rate_index = get_interleaved_ue_golomb(gb);
- if (dsh->frame_rate_index > 10)
+ if (dsh->frame_rate_index > 10U)
return AVERROR_INVALIDDATA;
if (!dsh->frame_rate_index) {
@@ -203,7 +206,7 @@ static int parse_source_parameters(AVDiracSeqHeader *dsh, GetBitContext *gb,
/* [DIRAC_STD] index */
dsh->aspect_ratio_index = get_interleaved_ue_golomb(gb);
- if (dsh->aspect_ratio_index > 6)
+ if (dsh->aspect_ratio_index > 6U)
return AVERROR_INVALIDDATA;
if (!dsh->aspect_ratio_index) {
@@ -236,10 +239,10 @@ static int parse_source_parameters(AVDiracSeqHeader *dsh, GetBitContext *gb,
/* [DIRAC_STD] index */
dsh->pixel_range_index = get_interleaved_ue_golomb(gb);
- if (dsh->pixel_range_index > 4)
+ if (dsh->pixel_range_index > 4U)
return AVERROR_INVALIDDATA;
- // This assumes either fullrange or MPEG levels only
+ /* This assumes either fullrange or MPEG levels only */
if (!dsh->pixel_range_index) {
luma_offset = get_interleaved_ue_golomb(gb);
luma_depth = av_log2(get_interleaved_ue_golomb(gb)) + 1;
@@ -257,17 +260,28 @@ static int parse_source_parameters(AVDiracSeqHeader *dsh, GetBitContext *gb,
dsh->color_range = pixel_range_presets[idx].color_range;
}
- if (luma_depth > 8 && log_ctx)
- av_log(log_ctx, AV_LOG_WARNING, "Bitdepth greater than 8");
+ dsh->bit_depth = luma_depth;
- dsh->pix_fmt = dirac_pix_fmt[!luma_offset][dsh->chroma_format];
+ /* Full range 8 bts uses the same pix_fmts as limited range 8 bits */
+ dsh->pixel_range_index += dsh->pixel_range_index == 1;
+
+ if (dsh->pixel_range_index < 2U)
+ return AVERROR_INVALIDDATA;
+
+ dsh->pix_fmt = dirac_pix_fmt[dsh->chroma_format][dsh->pixel_range_index-2];
+ avcodec_get_chroma_sub_sample(dsh->pix_fmt, &chroma_x_shift, &chroma_y_shift);
+ if ((dsh->width % (1<<chroma_x_shift)) || (dsh->height % (1<<chroma_y_shift))) {
+ if (log_ctx)
+ av_log(log_ctx, 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 = dsh->color_spec_index = get_interleaved_ue_golomb(gb);
- if (dsh->color_spec_index > 4)
+ if (dsh->color_spec_index > 4U)
return AVERROR_INVALIDDATA;
dsh->color_primaries = dirac_color_presets[idx].color_primaries;
@@ -278,7 +292,7 @@ static int parse_source_parameters(AVDiracSeqHeader *dsh, GetBitContext *gb,
/* [DIRAC_STD] 10.3.9.1 Colour primaries */
if (get_bits1(gb)) {
idx = get_interleaved_ue_golomb(gb);
- if (idx < 3)
+ if (idx < 3U)
dsh->color_primaries = dirac_primaries[idx];
}
/* [DIRAC_STD] 10.3.9.2 Colour matrix */
@@ -310,7 +324,6 @@ int av_dirac_parse_sequence_header(AVDiracSeqHeader **pdsh,
{
AVDiracSeqHeader *dsh;
GetBitContext gb;
- unsigned version_major;
unsigned video_format, picture_coding_mode;
int ret;
@@ -323,27 +336,25 @@ int av_dirac_parse_sequence_header(AVDiracSeqHeader **pdsh,
goto fail;
/* [DIRAC_SPEC] 10.1 Parse Parameters. parse_parameters() */
- version_major = get_interleaved_ue_golomb(&gb);
- get_interleaved_ue_golomb(&gb); /* version_minor */
- dsh->profile = get_interleaved_ue_golomb(&gb);
- dsh->level = get_interleaved_ue_golomb(&gb);
+ dsh->version.major = get_interleaved_ue_golomb(&gb);
+ dsh->version.minor = get_interleaved_ue_golomb(&gb);
+ dsh->profile = get_interleaved_ue_golomb(&gb);
+ dsh->level = get_interleaved_ue_golomb(&gb);
/* [DIRAC_SPEC] sequence_header() -> base_video_format as defined in
* 10.2 Base Video Format, table 10.1 Dirac predefined video formats */
video_format = get_interleaved_ue_golomb(&gb);
- if (log_ctx) {
- if (version_major < 2)
- av_log(log_ctx, AV_LOG_WARNING, "Stream is old and may not work\n");
- else if (version_major > 2)
- av_log(log_ctx, AV_LOG_WARNING, "Stream may have unhandled features\n");
- }
+ if (dsh->version.major < 2 && log_ctx)
+ av_log(log_ctx, AV_LOG_WARNING, "Stream is old and may not work\n");
+ else if (dsh->version.major > 2 && log_ctx)
+ av_log(log_ctx, AV_LOG_WARNING, "Stream may have unhandled features\n");
- if (video_format > 20) {
+ if (video_format > 20U) {
ret = AVERROR_INVALIDDATA;
goto fail;
}
- // Fill in defaults for the source parameters.
+ /* Fill in defaults for the source parameters. */
dsh->width = dirac_source_parameters_defaults[video_format].width;
dsh->height = dirac_source_parameters_defaults[video_format].height;
dsh->chroma_format = dirac_source_parameters_defaults[video_format].chroma_format;