Merge commit '6647aa0426e73839b9b1d1c9d86188f469167531'

* commit '6647aa0426e73839b9b1d1c9d86188f469167531':
  indeo4: add missing Haar and slanted transforms
  dxtory v2 support

Conflicts:
	libavcodec/indeo4.c
	libavcodec/ivi_dsp.c
	libavcodec/version.h

Merged-by: Michael Niedermayer <michaelni@gmx.at>
This commit is contained in:
Michael Niedermayer 2013-05-29 03:52:16 +02:00
commit ca90ca8ce3
5 changed files with 421 additions and 60 deletions

View File

@ -20,44 +20,31 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#define BITSTREAM_READER_LE
#include "avcodec.h"
#include "bytestream.h"
#include "get_bits.h"
#include "internal.h"
#include "unary.h"
#include "libavutil/common.h"
#include "libavutil/intreadwrite.h"
static av_cold int decode_init(AVCodecContext *avctx)
{
avctx->pix_fmt = AV_PIX_FMT_YUV420P;
return 0;
}
static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
AVPacket *avpkt)
static int dxtory_decode_v1(AVCodecContext *avctx, AVFrame *pic,
const uint8_t *src, int src_size)
{
int h, w;
AVFrame *pic = data;
const uint8_t *src = avpkt->data;
uint8_t *Y1, *Y2, *U, *V;
int ret;
if (avpkt->size < avctx->width * avctx->height * 3 / 2 + 16) {
if (src_size < avctx->width * avctx->height * 3 / 2) {
av_log(avctx, AV_LOG_ERROR, "packet too small\n");
return AVERROR_INVALIDDATA;
}
avctx->pix_fmt = AV_PIX_FMT_YUV420P;
if ((ret = ff_get_buffer(avctx, pic, 0)) < 0)
return ret;
pic->pict_type = AV_PICTURE_TYPE_I;
pic->key_frame = 1;
if (AV_RL32(src) != 0x01000002) {
avpriv_request_sample(avctx, "Frame header %X", AV_RL32(src));
return AVERROR_PATCHWELCOME;
}
src += 16;
Y1 = pic->data[0];
Y2 = pic->data[0] + pic->linesize[0];
U = pic->data[1];
@ -76,6 +63,154 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
V += pic->linesize[2];
}
return 0;
}
const uint8_t def_lru[8] = { 0x00, 0x20, 0x40, 0x60, 0x80, 0xA0, 0xC0, 0xFF };
static inline uint8_t decode_sym(GetBitContext *gb, uint8_t lru[8])
{
uint8_t c, val;
c = get_unary(gb, 0, 8);
if (!c) {
val = get_bits(gb, 8);
memmove(lru + 1, lru, sizeof(*lru) * (8 - 1));
} else {
val = lru[c - 1];
memmove(lru + 1, lru, sizeof(*lru) * (c - 1));
}
lru[0] = val;
return val;
}
static int dx2_decode_slice(GetBitContext *gb, int width, int height,
uint8_t *Y, uint8_t *U, uint8_t *V,
int ystride, int ustride, int vstride)
{
int x, y, i;
uint8_t lru[3][8];
for (i = 0; i < 3; i++)
memcpy(lru[i], def_lru, 8 * sizeof(*def_lru));
for (y = 0; y < height; y+=2) {
for (x = 0; x < width; x += 2) {
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;
U += ustride;
V += vstride;
}
return 0;
}
static int dxtory_decode_v2(AVCodecContext *avctx, AVFrame *pic,
const uint8_t *src, int src_size)
{
GetByteContext gb;
GetBitContext gb2;
int nslices, slice, slice_height;
uint32_t off, slice_size;
uint8_t *Y, *U, *V;
int ret;
bytestream2_init(&gb, src, src_size);
nslices = bytestream2_get_le16(&gb);
off = FFALIGN(nslices * 4 + 2, 16);
if (src_size < off) {
av_log(avctx, AV_LOG_ERROR, "no slice data\n");
return AVERROR_INVALIDDATA;
}
if (!nslices || avctx->height % nslices) {
avpriv_request_sample(avctx, "%d slices for %dx%d", nslices,
avctx->width, avctx->height);
return AVERROR(ENOSYS);
}
slice_height = avctx->height / nslices;
if ((avctx->width & 1) || (slice_height & 1)) {
avpriv_request_sample(avctx, "slice dimensions %dx%d",
avctx->width, slice_height);
}
avctx->pix_fmt = AV_PIX_FMT_YUV420P;
if ((ret = ff_get_buffer(avctx, pic, 0)) < 0)
return ret;
Y = pic->data[0];
U = pic->data[1];
V = pic->data[2];
for (slice = 0; slice < nslices; slice++) {
slice_size = bytestream2_get_le32(&gb);
if (slice_size > src_size - off) {
av_log(avctx, AV_LOG_ERROR,
"invalid slice size %d (only %d bytes left)\n",
slice_size, src_size - off);
return AVERROR_INVALIDDATA;
}
if (slice_size <= 16) {
av_log(avctx, AV_LOG_ERROR, "invalid slice size %d\n", slice_size);
return AVERROR_INVALIDDATA;
}
if (AV_RL32(src + off) != slice_size - 16) {
av_log(avctx, AV_LOG_ERROR,
"Slice sizes mismatch: got %d instead of %d\n",
AV_RL32(src + off), slice_size - 16);
}
init_get_bits(&gb2, src + off + 16, (slice_size - 16) * 8);
dx2_decode_slice(&gb2, avctx->width, slice_height, Y, U, V,
pic->linesize[0], pic->linesize[1], pic->linesize[2]);
Y += pic->linesize[0] * slice_height;
U += pic->linesize[1] * (slice_height >> 1);
V += pic->linesize[2] * (slice_height >> 1);
off += slice_size;
}
return 0;
}
static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
AVPacket *avpkt)
{
AVFrame *pic = data;
const uint8_t *src = avpkt->data;
int ret;
if (avpkt->size < 16) {
av_log(avctx, AV_LOG_ERROR, "packet too small\n");
return AVERROR_INVALIDDATA;
}
switch (AV_RB32(src)) {
case 0x02000001:
ret = dxtory_decode_v1(avctx, pic, src + 16, avpkt->size - 16);
break;
case 0x02000009:
ret = dxtory_decode_v2(avctx, pic, src + 16, avpkt->size - 16);
break;
default:
avpriv_request_sample(avctx, "Frame header %X", AV_RB32(src));
return AVERROR_PATCHWELCOME;
}
if (ret)
return ret;
pic->pict_type = AV_PICTURE_TYPE_I;
pic->key_frame = 1;
*got_frame = 1;
return avpkt->size;
@ -86,7 +221,6 @@ AVCodec ff_dxtory_decoder = {
.long_name = NULL_IF_CONFIG_SMALL("Dxtory"),
.type = AVMEDIA_TYPE_VIDEO,
.id = AV_CODEC_ID_DXTORY,
.init = decode_init,
.decode = decode_frame,
.capabilities = CODEC_CAP_DR1,
};

View File

@ -56,8 +56,8 @@ static const struct {
int is_2d_trans;
} transforms[18] = {
{ ff_ivi_inverse_haar_8x8, ff_ivi_dc_haar_2d, 1 },
{ ff_ivi_inverse_haar_8x1, ff_ivi_dc_haar_2d, 1 },
{ ff_ivi_inverse_haar_1x8, ff_ivi_dc_haar_2d, 1 },
{ ff_ivi_row_haar8, ff_ivi_dc_haar_2d, 0 },
{ ff_ivi_col_haar8, ff_ivi_dc_haar_2d, 0 },
{ ff_ivi_put_pixels_8x8, ff_ivi_put_dc_pixel_8x8, 1 },
{ ff_ivi_inverse_slant_8x8, ff_ivi_dc_slant_2d, 1 },
{ ff_ivi_row_slant8, ff_ivi_dc_row_slant, 1 },
@ -65,13 +65,13 @@ static const struct {
{ NULL, NULL, 0 }, /* inverse DCT 8x8 */
{ NULL, NULL, 0 }, /* inverse DCT 8x1 */
{ NULL, NULL, 0 }, /* inverse DCT 1x8 */
{ NULL, NULL, 0 }, /* inverse Haar 4x4 */
{ ff_ivi_inverse_haar_4x4, ff_ivi_dc_haar_2d, 1 },
{ ff_ivi_inverse_slant_4x4, ff_ivi_dc_slant_2d, 1 },
{ NULL, NULL, 0 }, /* no transform 4x4 */
{ NULL, NULL, 0 }, /* inverse Haar 1x4 */
{ NULL, NULL, 0 }, /* inverse Haar 4x1 */
{ NULL, NULL, 0 }, /* inverse slant 1x4 */
{ NULL, NULL, 0 }, /* inverse slant 4x1 */
{ ff_ivi_row_haar4, ff_ivi_dc_haar_2d, 0 },
{ ff_ivi_col_haar4, ff_ivi_dc_haar_2d, 0 },
{ ff_ivi_row_slant4, ff_ivi_dc_row_slant, 0 },
{ ff_ivi_col_slant4, ff_ivi_dc_col_slant, 0 },
{ NULL, NULL, 0 }, /* inverse DCT 4x4 */
};

View File

@ -258,12 +258,14 @@ void ff_ivi_recompose_haar(const IVIPlaneDesc *plane, uint8_t *dst,
d8 = COMPENSATE(t8); }
/** inverse 4-point Haar transform */
#define INV_HAAR4(s1, s3, s5, s7) {\
HAAR_BFLY(s1, s5); HAAR_BFLY(s1, s3); HAAR_BFLY(s5, s7);\
s1 = COMPENSATE(s1);\
s3 = COMPENSATE(s3);\
s5 = COMPENSATE(s5);\
s7 = COMPENSATE(s7); }
#define INV_HAAR4(s1, s3, s5, s7, d1, d2, d3, d4, t0, t1, t2, t3, t4) {\
IVI_HAAR_BFLY(s1, s3, t0, t1, t4);\
IVI_HAAR_BFLY(t0, s5, t2, t3, t4);\
d1 = COMPENSATE(t2);\
d2 = COMPENSATE(t3);\
IVI_HAAR_BFLY(t1, s7, t2, t3, t4);\
d3 = COMPENSATE(t2);\
d4 = COMPENSATE(t3); }
void ff_ivi_inverse_haar_8x8(const int32_t *in, int16_t *out, uint32_t pitch,
const uint8_t *flags)
@ -320,60 +322,153 @@ void ff_ivi_inverse_haar_8x8(const int32_t *in, int16_t *out, uint32_t pitch,
#undef COMPENSATE
}
void ff_ivi_inverse_haar_1x8(const int32_t *in, int16_t *out, uint32_t pitch,
const uint8_t *flags)
void ff_ivi_row_haar8(const int32_t *in, int16_t *out, uint32_t pitch,
const uint8_t *flags)
{
int i;
int t0, t1, t2, t3, t4, t5, t6, t7, t8;
/* apply the InvHaar8 to all rows */
#define COMPENSATE(x) (x)
for (i = 0; i < 8; i++) {
if ( !in[0] && !in[1] && !in[2] && !in[3]
&& !in[4] && !in[5] && !in[6] && !in[7]) {
memset(out, 0, 8 * sizeof(out[0]));
} else {
INV_HAAR8(in[0], in[1], in[2], in[3],
in[4], in[5], in[6], in[7],
out[0], out[1], out[2], out[3],
out[4], out[5], out[6], out[7],
t0, t1, t2, t3, t4, t5, t6, t7, t8);
}
in += 8;
out += pitch;
}
#undef COMPENSATE
}
void ff_ivi_col_haar8(const int32_t *in, int16_t *out, uint32_t pitch,
const uint8_t *flags)
{
int i;
const int32_t *src;
int t0, t1, t2, t3, t4, t5, t6, t7, t8;
/* apply the InvHaar8 to all columns */
#define COMPENSATE(x) (x)
src = in;
for (i = 0; i < 8; i++) {
if (flags[i]) {
INV_HAAR8(src[ 0], src[ 8], src[16], src[24],
src[32], src[40], src[48], src[56],
out[ 0], out[pitch], out[2*pitch], out[3*pitch],
out[4*pitch], out[5*pitch], out[6*pitch], out[7*pitch],
INV_HAAR8(in[ 0], in[ 8], in[16], in[24],
in[32], in[40], in[48], in[56],
out[0 * pitch], out[1 * pitch],
out[2 * pitch], out[3 * pitch],
out[4 * pitch], out[5 * pitch],
out[6 * pitch], out[7 * pitch],
t0, t1, t2, t3, t4, t5, t6, t7, t8);
} else
out[ 0]= out[ pitch]= out[2*pitch]= out[3*pitch]=
out[4*pitch]= out[5*pitch]= out[6*pitch]= out[7*pitch]= 0;
out[0 * pitch] = out[1 * pitch] =
out[2 * pitch] = out[3 * pitch] =
out[4 * pitch] = out[5 * pitch] =
out[6 * pitch] = out[7 * pitch] = 0;
src++;
in++;
out++;
}
#undef COMPENSATE
}
void ff_ivi_inverse_haar_8x1(const int32_t *in, int16_t *out, uint32_t pitch,
void ff_ivi_inverse_haar_4x4(const int32_t *in, int16_t *out, uint32_t pitch,
const uint8_t *flags)
{
int i;
int i, shift, sp1, sp2;
const int32_t *src;
int t0, t1, t2, t3, t4, t5, t6, t7, t8;
int32_t *dst;
int tmp[16];
int t0, t1, t2, t3, t4;
/* apply the InvHaar4 to all columns */
#define COMPENSATE(x) (x)
src = in;
dst = tmp;
for (i = 0; i < 4; i++) {
if (flags[i]) {
/* pre-scaling */
shift = !(i & 2);
sp1 = src[0] << shift;
sp2 = src[4] << shift;
INV_HAAR4( sp1, sp2, src[8], src[12],
dst[0], dst[4], dst[8], dst[12],
t0, t1, t2, t3, t4);
} else
dst[0] = dst[4] = dst[8] = dst[12] = 0;
src++;
dst++;
}
#undef COMPENSATE
/* apply the InvHaar8 to all rows */
#define COMPENSATE(x) (x)
src = in;
for (i = 0; i < 8; i++) {
if ( !src[0] && !src[1] && !src[2] && !src[3]
&& !src[4] && !src[5] && !src[6] && !src[7]) {
memset(out, 0, 8 * sizeof(out[0]));
src = tmp;
for (i = 0; i < 4; i++) {
if (!src[0] && !src[1] && !src[2] && !src[3]) {
memset(out, 0, 4 * sizeof(out[0]));
} else {
INV_HAAR8(src[0], src[1], src[2], src[3],
src[4], src[5], src[6], src[7],
INV_HAAR4(src[0], src[1], src[2], src[3],
out[0], out[1], out[2], out[3],
out[4], out[5], out[6], out[7],
t0, t1, t2, t3, t4, t5, t6, t7, t8);
t0, t1, t2, t3, t4);
}
src += 8;
src += 4;
out += pitch;
}
#undef COMPENSATE
}
void ff_ivi_row_haar4(const int32_t *in, int16_t *out, uint32_t pitch,
const uint8_t *flags)
{
int i;
int t0, t1, t2, t3, t4;
/* apply the InvHaar4 to all rows */
#define COMPENSATE(x) (x)
for (i = 0; i < 4; i++) {
if (!in[0] && !in[1] && !in[2] && !in[3]) {
memset(out, 0, 4 * sizeof(out[0]));
} else {
INV_HAAR4(in[0], in[1], in[2], in[3],
out[0], out[1], out[2], out[3],
t0, t1, t2, t3, t4);
}
in += 4;
out += pitch;
}
#undef COMPENSATE
}
void ff_ivi_col_haar4(const int32_t *in, int16_t *out, uint32_t pitch,
const uint8_t *flags)
{
int i;
int t0, t1, t2, t3, t4;
/* apply the InvHaar8 to all columns */
#define COMPENSATE(x) (x)
for (i = 0; i < 4; i++) {
if (flags[i]) {
INV_HAAR4(in[0], in[4], in[8], in[12],
out[0 * pitch], out[1 * pitch],
out[2 * pitch], out[3 * pitch],
t0, t1, t2, t3, t4);
} else
out[0 * pitch] = out[1 * pitch] =
out[2 * pitch] = out[3 * pitch] = 0;
in++;
out++;
}
#undef COMPENSATE
}
void ff_ivi_dc_haar_2d(const int32_t *in, int16_t *out, uint32_t pitch,
int blk_size)
{
@ -610,6 +705,49 @@ void ff_ivi_dc_col_slant(const int32_t *in, int16_t *out, uint32_t pitch, int bl
}
}
void ff_ivi_row_slant4(const int32_t *in, int16_t *out, uint32_t pitch, const uint8_t *flags)
{
int i;
int t0, t1, t2, t3, t4;
#define COMPENSATE(x) ((x + 1)>>1)
for (i = 0; i < 4; i++) {
if (!in[0] && !in[1] && !in[2] && !in[3]) {
memset(out, 0, 4*sizeof(out[0]));
} else {
IVI_INV_SLANT4( in[0], in[1], in[2], in[3],
out[0], out[1], out[2], out[3],
t0, t1, t2, t3, t4);
}
in += 4;
out += pitch;
}
#undef COMPENSATE
}
void ff_ivi_col_slant4(const int32_t *in, int16_t *out, uint32_t pitch, const uint8_t *flags)
{
int i, row2;
int t0, t1, t2, t3, t4;
row2 = pitch << 1;
#define COMPENSATE(x) ((x + 1)>>1)
for (i = 0; i < 4; i++) {
if (flags[i]) {
IVI_INV_SLANT4(in[0], in[4], in[8], in[12],
out[0], out[pitch], out[row2], out[row2 + pitch],
t0, t1, t2, t3, t4);
} else {
out[0] = out[pitch] = out[row2] = out[row2 + pitch] = 0;
}
in++;
out++;
}
#undef COMPENSATE
}
void ff_ivi_put_pixels_8x8(const int32_t *in, int16_t *out, uint32_t pitch,
const uint8_t *flags)
{

View File

@ -69,6 +69,71 @@ void ff_ivi_inverse_haar_8x1(const int32_t *in, int16_t *out, uint32_t pitch,
void ff_ivi_inverse_haar_1x8(const int32_t *in, int16_t *out, uint32_t pitch,
const uint8_t *flags);
/**
* one-dimensional inverse 8-point Haar transform on rows for Indeo 4
*
* @param[in] in pointer to the vector of transform coefficients
* @param[out] out pointer to the output buffer (frame)
* @param[in] pitch pitch to move to the next y line
* @param[in] flags pointer to the array of column flags:
* != 0 - non_empty column, 0 - empty one
* (this array must be filled by caller)
*/
void ff_ivi_row_haar8(const int32_t *in, int16_t *out, uint32_t pitch,
const uint8_t *flags);
/**
* one-dimensional inverse 8-point Haar transform on columns for Indeo 4
*
* @param[in] in pointer to the vector of transform coefficients
* @param[out] out pointer to the output buffer (frame)
* @param[in] pitch pitch to move to the next y line
* @param[in] flags pointer to the array of column flags:
* != 0 - non_empty column, 0 - empty one
* (this array must be filled by caller)
*/
void ff_ivi_col_haar8(const int32_t *in, int16_t *out, uint32_t pitch,
const uint8_t *flags);
/**
* two-dimensional inverse Haar 4x4 transform for Indeo 4
*
* @param[in] in pointer to the vector of transform coefficients
* @param[out] out pointer to the output buffer (frame)
* @param[in] pitch pitch to move to the next y line
* @param[in] flags pointer to the array of column flags:
* != 0 - non_empty column, 0 - empty one
* (this array must be filled by caller)
*/
void ff_ivi_inverse_haar_4x4(const int32_t *in, int16_t *out, uint32_t pitch,
const uint8_t *flags);
/**
* one-dimensional inverse 4-point Haar transform on rows for Indeo 4
*
* @param[in] in pointer to the vector of transform coefficients
* @param[out] out pointer to the output buffer (frame)
* @param[in] pitch pitch to move to the next y line
* @param[in] flags pointer to the array of column flags:
* != 0 - non_empty column, 0 - empty one
* (this array must be filled by caller)
*/
void ff_ivi_row_haar4(const int32_t *in, int16_t *out, uint32_t pitch,
const uint8_t *flags);
/**
* one-dimensional inverse 4-point Haar transform on columns for Indeo 4
*
* @param[in] in pointer to the vector of transform coefficients
* @param[out] out pointer to the output buffer (frame)
* @param[in] pitch pitch to move to the next y line
* @param[in] flags pointer to the array of column flags:
* != 0 - non_empty column, 0 - empty one
* (this array must be filled by caller)
*/
void ff_ivi_col_haar4(const int32_t *in, int16_t *out, uint32_t pitch,
const uint8_t *flags);
/**
* DC-only two-dimensional inverse Haar transform for Indeo 4.
* Performing the inverse transform in this case is equivalent to
@ -145,6 +210,30 @@ void ff_ivi_row_slant8(const int32_t *in, int16_t *out, uint32_t pitch,
void ff_ivi_col_slant8(const int32_t *in, int16_t *out, uint32_t pitch,
const uint8_t *flags);
/**
* inverse 1D row slant transform
*
* @param[in] in pointer to the vector of transform coefficients
* @param[out] out pointer to the output buffer (frame)
* @param[in] pitch pitch to move to the next y line
* @param[in] flags pointer to the array of column flags (unused here)
*/
void ff_ivi_row_slant4(const int32_t *in, int16_t *out, uint32_t pitch,
const uint8_t *flags);
/**
* inverse 1D column slant transform
*
* @param[in] in pointer to the vector of transform coefficients
* @param[out] out pointer to the output buffer (frame)
* @param[in] pitch pitch to move to the next y line
* @param[in] flags pointer to the array of column flags:
* != 0 - non_empty column, 0 - empty one
* (this array must be filled by caller)
*/
void ff_ivi_col_slant4(const int32_t *in, int16_t *out, uint32_t pitch,
const uint8_t *flags);
/**
* DC-only inverse row slant transform
*/

View File

@ -30,7 +30,7 @@
#define LIBAVCODEC_VERSION_MAJOR 55
#define LIBAVCODEC_VERSION_MINOR 12
#define LIBAVCODEC_VERSION_MICRO 101
#define LIBAVCODEC_VERSION_MICRO 102
#define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
LIBAVCODEC_VERSION_MINOR, \