summaryrefslogtreecommitdiff
path: root/libavcodec/hqx.c
diff options
context:
space:
mode:
Diffstat (limited to 'libavcodec/hqx.c')
-rw-r--r--libavcodec/hqx.c139
1 files changed, 75 insertions, 64 deletions
diff --git a/libavcodec/hqx.c b/libavcodec/hqx.c
index 0e11cdb55b..96c246b36b 100644
--- a/libavcodec/hqx.c
+++ b/libavcodec/hqx.c
@@ -1,20 +1,20 @@
/*
* Canopus HQX decoder
*
- * 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
*/
@@ -151,7 +151,8 @@ static int decode_block(GetBitContext *gb, VLC *vlc,
return 0;
}
-static int hqx_decode_422(HQXContext *ctx, GetBitContext *gb, int x, int y)
+static int hqx_decode_422(HQXContext *ctx, HQXSliceData * slice_data,
+ GetBitContext *gb, int x, int y)
{
const int *quants;
int flag;
@@ -170,20 +171,21 @@ static int hqx_decode_422(HQXContext *ctx, GetBitContext *gb, int x, int y)
if (i == 0 || i == 4 || i == 6)
last_dc = 0;
ret = decode_block(gb, &ctx->dc_vlc[vlc_index], quants,
- ctx->dcb, ctx->block[i], &last_dc);
+ ctx->dcb, slice_data->block[i], &last_dc);
if (ret < 0)
return ret;
}
- put_blocks(ctx, 0, x, y, flag, ctx->block[0], ctx->block[2], hqx_quant_luma);
- put_blocks(ctx, 0, x + 8, y, flag, ctx->block[1], ctx->block[3], hqx_quant_luma);
- put_blocks(ctx, 2, x >> 1, y, flag, ctx->block[4], ctx->block[5], hqx_quant_chroma);
- put_blocks(ctx, 1, x >> 1, y, flag, ctx->block[6], ctx->block[7], hqx_quant_chroma);
+ put_blocks(ctx, 0, x , y, flag, slice_data->block[0], slice_data->block[2], hqx_quant_luma);
+ put_blocks(ctx, 0, x + 8 , y, flag, slice_data->block[1], slice_data->block[3], hqx_quant_luma);
+ put_blocks(ctx, 2, x >> 1, y, flag, slice_data->block[4], slice_data->block[5], hqx_quant_chroma);
+ put_blocks(ctx, 1, x >> 1, y, flag, slice_data->block[6], slice_data->block[7], hqx_quant_chroma);
return 0;
}
-static int hqx_decode_422a(HQXContext *ctx, GetBitContext *gb, int x, int y)
+static int hqx_decode_422a(HQXContext *ctx, HQXSliceData * slice_data,
+ GetBitContext *gb, int x, int y)
{
const int *quants;
int flag = 0;
@@ -194,9 +196,9 @@ static int hqx_decode_422a(HQXContext *ctx, GetBitContext *gb, int x, int y)
cbp = get_vlc2(gb, ctx->cbp_vlc.table, ctx->cbp_vlc.bits, 1);
for (i = 0; i < 12; i++)
- memset(ctx->block[i], 0, sizeof(**ctx->block) * 64);
+ memset(slice_data->block[i], 0, sizeof(**slice_data->block) * 64);
for (i = 0; i < 12; i++)
- ctx->block[i][0] = -0x800;
+ slice_data->block[i][0] = -0x800;
if (cbp) {
if (ctx->interlaced)
flag = get_bits1(gb);
@@ -214,24 +216,25 @@ static int hqx_decode_422a(HQXContext *ctx, GetBitContext *gb, int x, int y)
if (cbp & (1 << i)) {
int vlc_index = ctx->dcb - 9;
ret = decode_block(gb, &ctx->dc_vlc[vlc_index], quants,
- ctx->dcb, ctx->block[i], &last_dc);
+ ctx->dcb, slice_data->block[i], &last_dc);
if (ret < 0)
return ret;
}
}
}
- put_blocks(ctx, 3, x, y, flag, ctx->block[ 0], ctx->block[ 2], hqx_quant_luma);
- put_blocks(ctx, 3, x + 8, y, flag, ctx->block[ 1], ctx->block[ 3], hqx_quant_luma);
- put_blocks(ctx, 0, x, y, flag, ctx->block[ 4], ctx->block[ 6], hqx_quant_luma);
- put_blocks(ctx, 0, x + 8, y, flag, ctx->block[ 5], ctx->block[ 7], hqx_quant_luma);
- put_blocks(ctx, 2, x >> 1, y, flag, ctx->block[ 8], ctx->block[ 9], hqx_quant_chroma);
- put_blocks(ctx, 1, x >> 1, y, flag, ctx->block[10], ctx->block[11], hqx_quant_chroma);
+ put_blocks(ctx, 3, x, y, flag, slice_data->block[ 0], slice_data->block[ 2], hqx_quant_luma);
+ put_blocks(ctx, 3, x + 8, y, flag, slice_data->block[ 1], slice_data->block[ 3], hqx_quant_luma);
+ put_blocks(ctx, 0, x, y, flag, slice_data->block[ 4], slice_data->block[ 6], hqx_quant_luma);
+ put_blocks(ctx, 0, x + 8, y, flag, slice_data->block[ 5], slice_data->block[ 7], hqx_quant_luma);
+ put_blocks(ctx, 2, x >> 1, y, flag, slice_data->block[ 8], slice_data->block[ 9], hqx_quant_chroma);
+ put_blocks(ctx, 1, x >> 1, y, flag, slice_data->block[10], slice_data->block[11], hqx_quant_chroma);
return 0;
}
-static int hqx_decode_444(HQXContext *ctx, GetBitContext *gb, int x, int y)
+static int hqx_decode_444(HQXContext *ctx, HQXSliceData * slice_data,
+ GetBitContext *gb, int x, int y)
{
const int *quants;
int flag;
@@ -250,22 +253,24 @@ static int hqx_decode_444(HQXContext *ctx, GetBitContext *gb, int x, int y)
if (i == 0 || i == 4 || i == 8)
last_dc = 0;
ret = decode_block(gb, &ctx->dc_vlc[vlc_index], quants,
- ctx->dcb, ctx->block[i], &last_dc);
+ ctx->dcb, slice_data->block[i], &last_dc);
if (ret < 0)
return ret;
}
- put_blocks(ctx, 0, x, y, flag, ctx->block[0], ctx->block[ 2], hqx_quant_luma);
- put_blocks(ctx, 0, x + 8, y, flag, ctx->block[1], ctx->block[ 3], hqx_quant_luma);
- put_blocks(ctx, 2, x, y, flag, ctx->block[4], ctx->block[ 6], hqx_quant_chroma);
- put_blocks(ctx, 2, x + 8, y, flag, ctx->block[5], ctx->block[ 7], hqx_quant_chroma);
- put_blocks(ctx, 1, x, y, flag, ctx->block[8], ctx->block[10], hqx_quant_chroma);
- put_blocks(ctx, 1, x + 8, y, flag, ctx->block[9], ctx->block[11], hqx_quant_chroma);
+ put_blocks(ctx, 0, x, y, flag, slice_data->block[0], slice_data->block[ 2], hqx_quant_luma);
+ put_blocks(ctx, 0, x + 8, y, flag, slice_data->block[1], slice_data->block[ 3], hqx_quant_luma);
+ put_blocks(ctx, 2, x, y, flag, slice_data->block[4], slice_data->block[ 6], hqx_quant_chroma);
+ put_blocks(ctx, 2, x + 8, y, flag, slice_data->block[5], slice_data->block[ 7], hqx_quant_chroma);
+ put_blocks(ctx, 1, x, y, flag, slice_data->block[8], slice_data->block[10], hqx_quant_chroma);
+ put_blocks(ctx, 1, x + 8, y, flag, slice_data->block[9], slice_data->block[11], hqx_quant_chroma);
return 0;
}
-static int hqx_decode_444a(HQXContext *ctx, GetBitContext *gb, int x, int y)
+
+static int hqx_decode_444a(HQXContext *ctx, HQXSliceData * slice_data,
+ GetBitContext *gb, int x, int y)
{
const int *quants;
int flag = 0;
@@ -276,9 +281,9 @@ static int hqx_decode_444a(HQXContext *ctx, GetBitContext *gb, int x, int y)
cbp = get_vlc2(gb, ctx->cbp_vlc.table, ctx->cbp_vlc.bits, 1);
for (i = 0; i < 16; i++)
- memset(ctx->block[i], 0, sizeof(**ctx->block) * 64);
+ memset(slice_data->block[i], 0, sizeof(**slice_data->block) * 64);
for (i = 0; i < 16; i++)
- ctx->block[i][0] = -0x800;
+ slice_data->block[i][0] = -0x800;
if (cbp) {
if (ctx->interlaced)
flag = get_bits1(gb);
@@ -293,21 +298,21 @@ static int hqx_decode_444a(HQXContext *ctx, GetBitContext *gb, int x, int y)
if (cbp & (1 << i)) {
int vlc_index = ctx->dcb - 9;
ret = decode_block(gb, &ctx->dc_vlc[vlc_index], quants,
- ctx->dcb, ctx->block[i], &last_dc);
+ ctx->dcb, slice_data->block[i], &last_dc);
if (ret < 0)
return ret;
}
}
}
- put_blocks(ctx, 3, x, y, flag, ctx->block[ 0], ctx->block[ 2], hqx_quant_luma);
- put_blocks(ctx, 3, x + 8, y, flag, ctx->block[ 1], ctx->block[ 3], hqx_quant_luma);
- put_blocks(ctx, 0, x, y, flag, ctx->block[ 4], ctx->block[ 6], hqx_quant_luma);
- put_blocks(ctx, 0, x + 8, y, flag, ctx->block[ 5], ctx->block[ 7], hqx_quant_luma);
- put_blocks(ctx, 2, x, y, flag, ctx->block[ 8], ctx->block[10], hqx_quant_chroma);
- put_blocks(ctx, 2, x + 8, y, flag, ctx->block[ 9], ctx->block[11], hqx_quant_chroma);
- put_blocks(ctx, 1, x, y, flag, ctx->block[12], ctx->block[14], hqx_quant_chroma);
- put_blocks(ctx, 1, x + 8, y, flag, ctx->block[13], ctx->block[15], hqx_quant_chroma);
+ put_blocks(ctx, 3, x, y, flag, slice_data->block[ 0], slice_data->block[ 2], hqx_quant_luma);
+ put_blocks(ctx, 3, x + 8, y, flag, slice_data->block[ 1], slice_data->block[ 3], hqx_quant_luma);
+ put_blocks(ctx, 0, x, y, flag, slice_data->block[ 4], slice_data->block[ 6], hqx_quant_luma);
+ put_blocks(ctx, 0, x + 8, y, flag, slice_data->block[ 5], slice_data->block[ 7], hqx_quant_luma);
+ put_blocks(ctx, 2, x, y, flag, slice_data->block[ 8], slice_data->block[10], hqx_quant_chroma);
+ put_blocks(ctx, 2, x + 8, y, flag, slice_data->block[ 9], slice_data->block[11], hqx_quant_chroma);
+ put_blocks(ctx, 1, x, y, flag, slice_data->block[12], slice_data->block[14], hqx_quant_chroma);
+ put_blocks(ctx, 1, x + 8, y, flag, slice_data->block[13], slice_data->block[15], hqx_quant_chroma);
return 0;
}
@@ -362,13 +367,38 @@ static int decode_slice(HQXContext *ctx, GetBitContext *gb, int slice_no)
mb_x += pos % grp_w;
mb_y = loc_row + (pos / grp_w);
}
- ctx->decode_func(ctx, gb, mb_x * 16, mb_y * 16);
+ ctx->decode_func(ctx, &ctx->slice[slice_no], gb, mb_x * 16, mb_y * 16);
}
}
return 0;
}
+static int decode_slice_thread(AVCodecContext *avctx, void *arg, int slice, int threadnr)
+{
+ HQXContext *ctx = avctx->priv_data;
+ uint32_t * slice_off = ctx->slice_off;
+ unsigned data_size = ctx->data_size;
+ int ret;
+
+ if (slice_off[slice] < HQX_HEADER_SIZE ||
+ slice_off[slice] >= slice_off[slice + 1] ||
+ slice_off[slice + 1] > data_size) {
+ av_log(avctx, AV_LOG_ERROR, "Invalid slice size.\n");
+ return AVERROR_INVALIDDATA;
+ }
+
+ ret = init_get_bits8(&ctx->slice[slice].gb, ctx->src + slice_off[slice], slice_off[slice + 1] - slice_off[slice]);
+ if (ret < 0)
+ return ret;
+
+ ret = decode_slice(ctx, &ctx->slice[slice].gb, slice);
+ if (ret < 0) {
+ av_log(avctx, AV_LOG_ERROR, "Error decoding slice %d.\n", slice);
+ }
+ return ret;
+}
+
static int hqx_decode_frame(AVCodecContext *avctx, void *data,
int *got_picture_ptr, AVPacket *avpkt)
{
@@ -376,9 +406,7 @@ static int hqx_decode_frame(AVCodecContext *avctx, void *data,
uint8_t *src = avpkt->data;
uint32_t info_tag, info_offset;
int data_start;
- GetBitContext gb;
int i, ret;
- int slice;
if (avpkt->size < 8)
return AVERROR_INVALIDDATA;
@@ -429,7 +457,7 @@ static int hqx_decode_frame(AVCodecContext *avctx, void *data,
}
ret = av_image_check_size(ctx->width, ctx->height, 0, avctx);
if (ret < 0) {
- av_log(avctx, AV_LOG_ERROR, "Invalid stored dimenstions %dx%d.\n",
+ av_log(avctx, AV_LOG_ERROR, "Invalid stored dimensions %dx%d.\n",
ctx->width, ctx->height);
return AVERROR_INVALIDDATA;
}
@@ -463,27 +491,10 @@ static int hqx_decode_frame(AVCodecContext *avctx, void *data,
}
ret = ff_get_buffer(avctx, ctx->pic, 0);
- if (ret < 0) {
- av_log(avctx, AV_LOG_ERROR, "Could not allocate buffer.\n");
+ if (ret < 0)
return ret;
- }
- for (slice = 0; slice < 16; slice++) {
- if (ctx->slice_off[slice] < HQX_HEADER_SIZE ||
- ctx->slice_off[slice] >= ctx->slice_off[slice + 1] ||
- ctx->slice_off[slice + 1] > ctx->data_size) {
- av_log(avctx, AV_LOG_ERROR, "Invalid slice size.\n");
- break;
- }
- ret = init_get_bits(&gb, src + ctx->slice_off[slice],
- (ctx->slice_off[slice + 1] - ctx->slice_off[slice]) * 8);
- if (ret < 0)
- return ret;
- ret = decode_slice(ctx, &gb, slice);
- if (ret < 0) {
- av_log(avctx, AV_LOG_ERROR, "Error decoding slice %d.\n", slice);
- }
- }
+ avctx->execute2(avctx, decode_slice_thread, NULL, NULL, 16);
ctx->pic->key_frame = 1;
ctx->pic->pict_type = AV_PICTURE_TYPE_I;
@@ -527,5 +538,5 @@ AVCodec ff_hqx_decoder = {
.init = hqx_decode_init,
.decode = hqx_decode_frame,
.close = hqx_decode_close,
- .capabilities = CODEC_CAP_DR1,
+ .capabilities = CODEC_CAP_DR1 | CODEC_CAP_SLICE_THREADS,
};