summaryrefslogtreecommitdiff
path: root/libavcodec/hqx.c
diff options
context:
space:
mode:
Diffstat (limited to 'libavcodec/hqx.c')
-rw-r--r--libavcodec/hqx.c88
1 files changed, 46 insertions, 42 deletions
diff --git a/libavcodec/hqx.c b/libavcodec/hqx.c
index 2d1abf0cca..bc24ba91d1 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
*/
@@ -24,9 +24,10 @@
#include "libavutil/intreadwrite.h"
#include "avcodec.h"
-#include "bitstream.h"
#include "canopus.h"
+#include "get_bits.h"
#include "internal.h"
+#include "thread.h"
#include "hqx.h"
#include "hqxdsp.h"
@@ -95,23 +96,23 @@ static inline void put_blocks(HQXContext *ctx, int plane,
lsize * fields, block1, quant);
}
-static inline void hqx_get_ac(BitstreamContext *bc, const HQXAC *ac,
+static inline void hqx_get_ac(GetBitContext *gb, const HQXAC *ac,
int *run, int *lev)
{
int val;
- val = bitstream_peek(bc, ac->lut_bits);
+ val = show_bits(gb, ac->lut_bits);
if (ac->lut[val].bits == -1) {
- BitstreamContext bc2 = *bc;
- bitstream_skip(&bc2, ac->lut_bits);
- val = ac->lut[val].lev + bitstream_peek(&bc2, ac->extra_bits);
+ GetBitContext gb2 = *gb;
+ skip_bits(&gb2, ac->lut_bits);
+ val = ac->lut[val].lev + show_bits(&gb2, ac->extra_bits);
}
*run = ac->lut[val].run;
*lev = ac->lut[val].lev;
- bitstream_skip(bc, ac->lut[val].bits);
+ skip_bits(gb, ac->lut[val].bits);
}
-static int decode_block(BitstreamContext *bc, VLC *vlc,
+static int decode_block(GetBitContext *gb, VLC *vlc,
const int *quants, int dcb,
int16_t block[64], int *last_dc)
{
@@ -120,14 +121,14 @@ static int decode_block(BitstreamContext *bc, VLC *vlc,
int run, lev, pos = 1;
memset(block, 0, 64 * sizeof(*block));
- dc = bitstream_read_vlc(bc, vlc->table, HQX_DC_VLC_BITS, 2);
+ dc = get_vlc2(gb, vlc->table, HQX_DC_VLC_BITS, 2);
if (dc < 0)
return AVERROR_INVALIDDATA;
*last_dc += dc;
block[0] = sign_extend(*last_dc << (12 - dcb), 12);
- q = quants[bitstream_read(bc, 2)];
+ q = quants[get_bits(gb, 2)];
if (q >= 128)
ac_idx = HQX_AC_Q128;
else if (q >= 64)
@@ -142,7 +143,7 @@ static int decode_block(BitstreamContext *bc, VLC *vlc,
ac_idx = HQX_AC_Q0;
do {
- hqx_get_ac(bc, &ff_hqx_ac[ac_idx], &run, &lev);
+ hqx_get_ac(gb, &ff_hqx_ac[ac_idx], &run, &lev);
pos += run;
if (pos >= 64)
break;
@@ -155,24 +156,24 @@ static int decode_block(BitstreamContext *bc, VLC *vlc,
static int hqx_decode_422(HQXContext *ctx, int slice_no, int x, int y)
{
HQXSlice *slice = &ctx->slice[slice_no];
- BitstreamContext *bc = &slice->bc;
+ GetBitContext *gb = &slice->gb;
const int *quants;
int flag;
int last_dc;
int i, ret;
if (ctx->interlaced)
- flag = bitstream_read_bit(bc);
+ flag = get_bits1(gb);
else
flag = 0;
- quants = hqx_quants[bitstream_read(bc, 4)];
+ quants = hqx_quants[get_bits(gb, 4)];
for (i = 0; i < 8; i++) {
int vlc_index = ctx->dcb - 9;
if (i == 0 || i == 4 || i == 6)
last_dc = 0;
- ret = decode_block(bc, &ctx->dc_vlc[vlc_index], quants,
+ ret = decode_block(gb, &ctx->dc_vlc[vlc_index], quants,
ctx->dcb, slice->block[i], &last_dc);
if (ret < 0)
return ret;
@@ -189,14 +190,14 @@ static int hqx_decode_422(HQXContext *ctx, int slice_no, int x, int y)
static int hqx_decode_422a(HQXContext *ctx, int slice_no, int x, int y)
{
HQXSlice *slice = &ctx->slice[slice_no];
- BitstreamContext *bc = &slice->bc;
+ GetBitContext *gb = &slice->gb;
const int *quants;
int flag = 0;
int last_dc;
int i, ret;
int cbp;
- cbp = bitstream_read_vlc(bc, ctx->cbp_vlc.table, ctx->cbp_vlc.bits, 1);
+ cbp = get_vlc2(gb, ctx->cbp_vlc.table, ctx->cbp_vlc.bits, 1);
for (i = 0; i < 12; i++)
memset(slice->block[i], 0, sizeof(**slice->block) * 64);
@@ -204,9 +205,9 @@ static int hqx_decode_422a(HQXContext *ctx, int slice_no, int x, int y)
slice->block[i][0] = -0x800;
if (cbp) {
if (ctx->interlaced)
- flag = bitstream_read_bit(bc);
+ flag = get_bits1(gb);
- quants = hqx_quants[bitstream_read(bc, 4)];
+ quants = hqx_quants[get_bits(gb, 4)];
cbp |= cbp << 4; // alpha CBP
if (cbp & 0x3) // chroma CBP - top
@@ -218,7 +219,7 @@ static int hqx_decode_422a(HQXContext *ctx, int slice_no, int x, int y)
last_dc = 0;
if (cbp & (1 << i)) {
int vlc_index = ctx->dcb - 9;
- ret = decode_block(bc, &ctx->dc_vlc[vlc_index], quants,
+ ret = decode_block(gb, &ctx->dc_vlc[vlc_index], quants,
ctx->dcb, slice->block[i], &last_dc);
if (ret < 0)
return ret;
@@ -239,24 +240,24 @@ static int hqx_decode_422a(HQXContext *ctx, int slice_no, int x, int y)
static int hqx_decode_444(HQXContext *ctx, int slice_no, int x, int y)
{
HQXSlice *slice = &ctx->slice[slice_no];
- BitstreamContext *bc = &slice->bc;
+ GetBitContext *gb = &slice->gb;
const int *quants;
int flag;
int last_dc;
int i, ret;
if (ctx->interlaced)
- flag = bitstream_read_bit(bc);
+ flag = get_bits1(gb);
else
flag = 0;
- quants = hqx_quants[bitstream_read(bc, 4)];
+ quants = hqx_quants[get_bits(gb, 4)];
for (i = 0; i < 12; i++) {
int vlc_index = ctx->dcb - 9;
if (i == 0 || i == 4 || i == 8)
last_dc = 0;
- ret = decode_block(bc, &ctx->dc_vlc[vlc_index], quants,
+ ret = decode_block(gb, &ctx->dc_vlc[vlc_index], quants,
ctx->dcb, slice->block[i], &last_dc);
if (ret < 0)
return ret;
@@ -275,14 +276,14 @@ static int hqx_decode_444(HQXContext *ctx, int slice_no, int x, int y)
static int hqx_decode_444a(HQXContext *ctx, int slice_no, int x, int y)
{
HQXSlice *slice = &ctx->slice[slice_no];
- BitstreamContext *bc = &slice->bc;
+ GetBitContext *gb = &slice->gb;
const int *quants;
int flag = 0;
int last_dc;
int i, ret;
int cbp;
- cbp = bitstream_read_vlc(bc, ctx->cbp_vlc.table, ctx->cbp_vlc.bits, 1);
+ cbp = get_vlc2(gb, ctx->cbp_vlc.table, ctx->cbp_vlc.bits, 1);
for (i = 0; i < 16; i++)
memset(slice->block[i], 0, sizeof(**slice->block) * 64);
@@ -290,9 +291,9 @@ static int hqx_decode_444a(HQXContext *ctx, int slice_no, int x, int y)
slice->block[i][0] = -0x800;
if (cbp) {
if (ctx->interlaced)
- flag = bitstream_read_bit(bc);
+ flag = get_bits1(gb);
- quants = hqx_quants[bitstream_read(bc, 4)];
+ quants = hqx_quants[get_bits(gb, 4)];
cbp |= cbp << 4; // alpha CBP
cbp |= cbp << 8; // chroma CBP
@@ -301,7 +302,7 @@ static int hqx_decode_444a(HQXContext *ctx, int slice_no, int x, int y)
last_dc = 0;
if (cbp & (1 << i)) {
int vlc_index = ctx->dcb - 9;
- ret = decode_block(bc, &ctx->dc_vlc[vlc_index], quants,
+ ret = decode_block(gb, &ctx->dc_vlc[vlc_index], quants,
ctx->dcb, slice->block[i], &last_dc);
if (ret < 0)
return ret;
@@ -392,9 +393,9 @@ static int decode_slice_thread(AVCodecContext *avctx, void *arg,
return AVERROR_INVALIDDATA;
}
- ret = bitstream_init8(&ctx->slice[slice_no].bc,
- ctx->src + slice_off[slice_no],
- slice_off[slice_no + 1] - slice_off[slice_no]);
+ ret = init_get_bits8(&ctx->slice[slice_no].gb,
+ ctx->src + slice_off[slice_no],
+ slice_off[slice_no + 1] - slice_off[slice_no]);
if (ret < 0)
return ret;
@@ -405,6 +406,7 @@ static int hqx_decode_frame(AVCodecContext *avctx, void *data,
int *got_picture_ptr, AVPacket *avpkt)
{
HQXContext *ctx = avctx->priv_data;
+ ThreadFrame frame = { .f = data };
uint8_t *src = avpkt->data;
uint32_t info_tag;
int data_start;
@@ -458,7 +460,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;
}
@@ -491,11 +493,9 @@ static int hqx_decode_frame(AVCodecContext *avctx, void *data,
return AVERROR_INVALIDDATA;
}
- ret = ff_get_buffer(avctx, ctx->pic, 0);
- if (ret < 0) {
- av_log(avctx, AV_LOG_ERROR, "Could not allocate buffer.\n");
+ ret = ff_thread_get_buffer(avctx, &frame, 0);
+ if (ret < 0)
return ret;
- }
avctx->execute2(avctx, decode_slice_thread, NULL, NULL, 16);
@@ -512,6 +512,9 @@ static av_cold int hqx_decode_close(AVCodecContext *avctx)
int i;
HQXContext *ctx = avctx->priv_data;
+ if (avctx->internal->is_copy)
+ return 0;
+
ff_free_vlc(&ctx->cbp_vlc);
for (i = 0; i < 3; i++) {
ff_free_vlc(&ctx->dc_vlc[i]);
@@ -538,7 +541,8 @@ AVCodec ff_hqx_decoder = {
.init = hqx_decode_init,
.decode = hqx_decode_frame,
.close = hqx_decode_close,
- .capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_SLICE_THREADS,
+ .capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_SLICE_THREADS |
+ AV_CODEC_CAP_FRAME_THREADS,
.caps_internal = FF_CODEC_CAP_INIT_THREADSAFE |
FF_CODEC_CAP_INIT_CLEANUP,
};