summaryrefslogtreecommitdiffstats
path: root/libavcodec/dxtory.c
diff options
context:
space:
mode:
Diffstat (limited to 'libavcodec/dxtory.c')
-rw-r--r--libavcodec/dxtory.c117
1 files changed, 57 insertions, 60 deletions
diff --git a/libavcodec/dxtory.c b/libavcodec/dxtory.c
index 05de4ac..285ca38 100644
--- a/libavcodec/dxtory.c
+++ b/libavcodec/dxtory.c
@@ -3,20 +3,20 @@
*
* Copyright (c) 2011 Konstantin Shishkov
*
- * 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
*/
@@ -27,8 +27,8 @@
#define BITSTREAM_READER_LE
#include "avcodec.h"
-#include "bitstream.h"
#include "bytestream.h"
+#include "get_bits.h"
#include "internal.h"
#include "unary.h"
@@ -40,7 +40,7 @@ static int dxtory_decode_v1_rgb(AVCodecContext *avctx, AVFrame *pic,
uint8_t *dst;
int ret;
- if (src_size < avctx->width * avctx->height * bpp) {
+ if (src_size < avctx->width * avctx->height * (int64_t)bpp) {
av_log(avctx, AV_LOG_ERROR, "packet too small\n");
return AVERROR_INVALIDDATA;
}
@@ -66,7 +66,7 @@ static int dxtory_decode_v1_410(AVCodecContext *avctx, AVFrame *pic,
uint8_t *Y1, *Y2, *Y3, *Y4, *U, *V;
int ret;
- if (src_size < avctx->width * avctx->height * 18 / 16) {
+ if (src_size < FFALIGN(avctx->width, 4) * FFALIGN(avctx->height, 4) * 9LL / 8) {
av_log(avctx, AV_LOG_ERROR, "packet too small\n");
return AVERROR_INVALIDDATA;
}
@@ -83,10 +83,10 @@ static int dxtory_decode_v1_410(AVCodecContext *avctx, AVFrame *pic,
V = pic->data[2];
for (h = 0; h < avctx->height; h += 4) {
for (w = 0; w < avctx->width; w += 4) {
- AV_COPY32(Y1 + w, src);
- AV_COPY32(Y2 + w, src + 4);
- AV_COPY32(Y3 + w, src + 8);
- AV_COPY32(Y4 + w, src + 12);
+ AV_COPY32U(Y1 + w, src);
+ AV_COPY32U(Y2 + w, src + 4);
+ AV_COPY32U(Y3 + w, src + 8);
+ AV_COPY32U(Y4 + w, src + 12);
U[w >> 2] = src[16] + 0x80;
V[w >> 2] = src[17] + 0x80;
src += 18;
@@ -109,7 +109,7 @@ static int dxtory_decode_v1_420(AVCodecContext *avctx, AVFrame *pic,
uint8_t *Y1, *Y2, *U, *V;
int ret;
- if (src_size < avctx->width * avctx->height * 3 / 2) {
+ if (src_size < FFALIGN(avctx->width, 2) * FFALIGN(avctx->height, 2) * 3LL / 2) {
av_log(avctx, AV_LOG_ERROR, "packet too small\n");
return AVERROR_INVALIDDATA;
}
@@ -146,7 +146,7 @@ static int dxtory_decode_v1_444(AVCodecContext *avctx, AVFrame *pic,
uint8_t *Y, *U, *V;
int ret;
- if (src_size < avctx->width * avctx->height * 3) {
+ if (src_size < avctx->width * avctx->height * 3LL) {
av_log(avctx, AV_LOG_ERROR, "packet too small\n");
return AVERROR_INVALIDDATA;
}
@@ -176,13 +176,13 @@ static const uint8_t def_lru[8] = { 0x00, 0x20, 0x40, 0x60, 0x80, 0xA0, 0xC0, 0x
static const uint8_t def_lru_555[8] = { 0x00, 0x08, 0x10, 0x18, 0x1F };
static const uint8_t def_lru_565[8] = { 0x00, 0x08, 0x10, 0x20, 0x30, 0x3F };
-static inline uint8_t decode_sym(BitstreamContext *bc, uint8_t lru[8])
+static inline uint8_t decode_sym(GetBitContext *gb, uint8_t lru[8])
{
uint8_t c, val;
- c = get_unary(bc, 0, 8);
+ c = get_unary(gb, 0, 8);
if (!c) {
- val = bitstream_read(bc, 8);
+ val = get_bits(gb, 8);
memmove(lru + 1, lru, sizeof(*lru) * (8 - 1));
} else {
val = lru[c - 1];
@@ -243,14 +243,14 @@ static int load_buffer(AVCodecContext *avctx,
return 0;
}
-static inline uint8_t decode_sym_565(BitstreamContext *bc, uint8_t lru[8],
+static inline uint8_t decode_sym_565(GetBitContext *gb, uint8_t lru[8],
int bits)
{
uint8_t c, val;
- c = get_unary(bc, 0, bits);
+ c = get_unary(gb, 0, bits);
if (!c) {
- val = bitstream_read(bc, bits);
+ val = get_bits(gb, bits);
memmove(lru + 1, lru, sizeof(*lru) * (6 - 1));
} else {
val = lru[c - 1];
@@ -261,7 +261,7 @@ static inline uint8_t decode_sym_565(BitstreamContext *bc, uint8_t lru[8],
return val;
}
-typedef int (*decode_slice_func)(BitstreamContext *bc, AVFrame *frame,
+typedef int (*decode_slice_func)(GetBitContext *gb, AVFrame *frame,
int line, int height, uint8_t lru[3][8]);
typedef void (*setup_lru_func)(uint8_t lru[3][8]);
@@ -273,7 +273,7 @@ static int dxtory_decode_v2(AVCodecContext *avctx, AVFrame *pic,
enum AVPixelFormat fmt)
{
GetByteContext gb;
- BitstreamContext bc;
+ GetBitContext gb2;
int nslices, slice, line = 0;
uint32_t off, slice_size;
uint8_t lru[3][8];
@@ -296,26 +296,23 @@ static int dxtory_decode_v2(AVCodecContext *avctx, AVFrame *pic,
if (ret < 0)
return ret;
- bitstream_init8(&bc, src + off + 16, slice_size - 16);
+ if ((ret = init_get_bits8(&gb2, src + off + 16, slice_size - 16)) < 0)
+ return ret;
- line += decode_slice(&bc, pic, line, avctx->height - line, lru);
+ line += decode_slice(&gb2, pic, line, avctx->height - line, lru);
off += slice_size;
}
if (avctx->height - line) {
- av_log(avctx, AV_LOG_VERBOSE,
- "Not enough slice data available, "
- "cropping the frame by %d pixels\n",
- avctx->height - line);
- avctx->height = line;
+ avpriv_request_sample(avctx, "Not enough slice data available");
}
return 0;
}
av_always_inline
-static int dx2_decode_slice_5x5(BitstreamContext *bc, AVFrame *frame,
+static int dx2_decode_slice_5x5(GetBitContext *gb, AVFrame *frame,
int line, int left, uint8_t lru[3][8],
int is_565)
{
@@ -325,11 +322,11 @@ static int dx2_decode_slice_5x5(BitstreamContext *bc, AVFrame *frame,
int stride = frame->linesize[0];
uint8_t *dst = frame->data[0] + stride * line;
- for (y = 0; y < left && bitstream_bits_left(bc) > 16; y++) {
+ for (y = 0; y < left && get_bits_left(gb) > 6 * width; y++) {
for (x = 0; x < width; x++) {
- b = decode_sym_565(bc, lru[0], 5);
- g = decode_sym_565(bc, lru[1], is_565 ? 6 : 5);
- r = decode_sym_565(bc, lru[2], 5);
+ b = decode_sym_565(gb, lru[0], 5);
+ g = decode_sym_565(gb, lru[1], is_565 ? 6 : 5);
+ r = decode_sym_565(gb, lru[2], 5);
dst[x * 3 + 0] = (r << 3) | (r >> 2);
dst[x * 3 + 1] = is_565 ? (g << 2) | (g >> 4) : (g << 3) | (g >> 2);
dst[x * 3 + 2] = (b << 3) | (b >> 2);
@@ -355,16 +352,16 @@ static void setup_lru_565(uint8_t lru[3][8])
memcpy(lru[2], def_lru_555, 8 * sizeof(*def_lru));
}
-static int dx2_decode_slice_555(BitstreamContext *bc, AVFrame *frame,
+static int dx2_decode_slice_555(GetBitContext *gb, AVFrame *frame,
int line, int left, uint8_t lru[3][8])
{
- return dx2_decode_slice_5x5(bc, frame, line, left, lru, 0);
+ return dx2_decode_slice_5x5(gb, frame, line, left, lru, 0);
}
-static int dx2_decode_slice_565(BitstreamContext *bc, AVFrame *frame,
+static int dx2_decode_slice_565(GetBitContext *gb, AVFrame *frame,
int line, int left, uint8_t lru[3][8])
{
- return dx2_decode_slice_5x5(bc, frame, line, left, lru, 1);
+ return dx2_decode_slice_5x5(gb, frame, line, left, lru, 1);
}
static int dxtory_decode_v2_565(AVCodecContext *avctx, AVFrame *pic,
@@ -383,7 +380,7 @@ static int dxtory_decode_v2_565(AVCodecContext *avctx, AVFrame *pic,
fmt);
}
-static int dx2_decode_slice_rgb(BitstreamContext *bc, AVFrame *frame,
+static int dx2_decode_slice_rgb(GetBitContext *gb, AVFrame *frame,
int line, int left, uint8_t lru[3][8])
{
int x, y;
@@ -391,11 +388,11 @@ static int dx2_decode_slice_rgb(BitstreamContext *bc, AVFrame *frame,
int stride = frame->linesize[0];
uint8_t *dst = frame->data[0] + stride * line;
- for (y = 0; y < left && bitstream_bits_left(bc) > 16; y++) {
+ for (y = 0; y < left && get_bits_left(gb) > 6 * width; y++) {
for (x = 0; x < width; x++) {
- dst[x * 3 + 0] = decode_sym(bc, lru[0]);
- dst[x * 3 + 1] = decode_sym(bc, lru[1]);
- dst[x * 3 + 2] = decode_sym(bc, lru[2]);
+ dst[x * 3 + 0] = decode_sym(gb, lru[0]);
+ dst[x * 3 + 1] = decode_sym(gb, lru[1]);
+ dst[x * 3 + 2] = decode_sym(gb, lru[2]);
}
dst += stride;
@@ -421,7 +418,7 @@ static int dxtory_decode_v2_rgb(AVCodecContext *avctx, AVFrame *pic,
AV_PIX_FMT_BGR24);
}
-static int dx2_decode_slice_410(BitstreamContext *bc, AVFrame *frame,
+static int dx2_decode_slice_410(GetBitContext *gb, AVFrame *frame,
int line, int left,
uint8_t lru[3][8])
{
@@ -436,13 +433,13 @@ static int dx2_decode_slice_410(BitstreamContext *bc, AVFrame *frame,
uint8_t *U = frame->data[1] + (ustride >> 2) * line;
uint8_t *V = frame->data[2] + (vstride >> 2) * line;
- for (y = 0; y < left - 3 && bitstream_bits_left(bc) > 16; y += 4) {
+ for (y = 0; y < left - 3 && get_bits_left(gb) > 9 * width; y += 4) {
for (x = 0; x < width; x += 4) {
for (j = 0; j < 4; j++)
for (i = 0; i < 4; i++)
- Y[x + i + j * ystride] = decode_sym(bc, lru[0]);
- U[x >> 2] = decode_sym(bc, lru[1]) ^ 0x80;
- V[x >> 2] = decode_sym(bc, lru[2]) ^ 0x80;
+ Y[x + i + j * ystride] = decode_sym(gb, lru[0]);
+ U[x >> 2] = decode_sym(gb, lru[1]) ^ 0x80;
+ V[x >> 2] = decode_sym(gb, lru[2]) ^ 0x80;
}
Y += ystride << 2;
@@ -463,7 +460,7 @@ static int dxtory_decode_v2_410(AVCodecContext *avctx, AVFrame *pic,
AV_PIX_FMT_YUV410P);
}
-static int dx2_decode_slice_420(BitstreamContext *bc, AVFrame *frame,
+static int dx2_decode_slice_420(GetBitContext *gb, AVFrame *frame,
int line, int left,
uint8_t lru[3][8])
{
@@ -480,14 +477,14 @@ static int dx2_decode_slice_420(BitstreamContext *bc, AVFrame *frame,
uint8_t *V = frame->data[2] + (vstride >> 1) * line;
- for (y = 0; y < left - 1 && bitstream_bits_left(bc) > 16; y += 2) {
+ for (y = 0; y < left - 1 && get_bits_left(gb) > 6 * width; y += 2) {
for (x = 0; x < width; x += 2) {
- Y[x + 0 + 0 * ystride] = decode_sym(bc, lru[0]);
- Y[x + 1 + 0 * ystride] = decode_sym(bc, lru[0]);
- Y[x + 0 + 1 * ystride] = decode_sym(bc, lru[0]);
- Y[x + 1 + 1 * ystride] = decode_sym(bc, lru[0]);
- U[x >> 1] = decode_sym(bc, lru[1]) ^ 0x80;
- V[x >> 1] = decode_sym(bc, lru[2]) ^ 0x80;
+ Y[x + 0 + 0 * ystride] = decode_sym(gb, lru[0]);
+ Y[x + 1 + 0 * ystride] = decode_sym(gb, lru[0]);
+ Y[x + 0 + 1 * ystride] = decode_sym(gb, lru[0]);
+ Y[x + 1 + 1 * ystride] = decode_sym(gb, lru[0]);
+ U[x >> 1] = decode_sym(gb, lru[1]) ^ 0x80;
+ V[x >> 1] = decode_sym(gb, lru[2]) ^ 0x80;
}
Y += ystride << 1;
@@ -507,7 +504,7 @@ static int dxtory_decode_v2_420(AVCodecContext *avctx, AVFrame *pic,
AV_PIX_FMT_YUV420P);
}
-static int dx2_decode_slice_444(BitstreamContext *bc, AVFrame *frame,
+static int dx2_decode_slice_444(GetBitContext *gb, AVFrame *frame,
int line, int left,
uint8_t lru[3][8])
{
@@ -523,11 +520,11 @@ static int dx2_decode_slice_444(BitstreamContext *bc, AVFrame *frame,
uint8_t *U = frame->data[1] + ustride * line;
uint8_t *V = frame->data[2] + vstride * line;
- for (y = 0; y < left && bitstream_bits_left(bc) > 16; y++) {
+ for (y = 0; y < left && get_bits_left(gb) > 6 * width; y++) {
for (x = 0; x < width; x++) {
- Y[x] = decode_sym(bc, lru[0]);
- U[x] = decode_sym(bc, lru[1]) ^ 0x80;
- V[x] = decode_sym(bc, lru[2]) ^ 0x80;
+ Y[x] = decode_sym(gb, lru[0]);
+ U[x] = decode_sym(gb, lru[1]) ^ 0x80;
+ V[x] = decode_sym(gb, lru[2]) ^ 0x80;
}
Y += ystride;
OpenPOWER on IntegriCloud