4xm, timefilter: K&R formatting cosmetics
Signed-off-by: Diego Biurrun <diego@biurrun.de>
This commit is contained in:
parent
ba83ac4c27
commit
0c5d78a898
234
libavcodec/4xm.c
234
libavcodec/4xm.c
@ -26,9 +26,9 @@
|
|||||||
|
|
||||||
#include "libavutil/intreadwrite.h"
|
#include "libavutil/intreadwrite.h"
|
||||||
#include "avcodec.h"
|
#include "avcodec.h"
|
||||||
|
#include "bytestream.h"
|
||||||
#include "dsputil.h"
|
#include "dsputil.h"
|
||||||
#include "get_bits.h"
|
#include "get_bits.h"
|
||||||
#include "bytestream.h"
|
|
||||||
|
|
||||||
//#undef NDEBUG
|
//#undef NDEBUG
|
||||||
//#include <assert.h>
|
//#include <assert.h>
|
||||||
@ -104,7 +104,8 @@ static const int8_t mv[256][2]={
|
|||||||
{ -29, 18 }, { -16, -31 }, { -28, -22 }, { 21, -30 }, { -25, 28 }, { 26, -29 }, { 25, -32 }, { -32, -32 }
|
{ -29, 18 }, { -16, -31 }, { -28, -22 }, { 21, -30 }, { -25, 28 }, { 26, -29 }, { 25, -32 }, { -32, -32 }
|
||||||
};
|
};
|
||||||
|
|
||||||
// this is simply the scaled down elementwise product of the standard jpeg quantizer table and the AAN premul table
|
/* This is simply the scaled down elementwise product of the standard JPEG
|
||||||
|
* quantizer table and the AAN premul table. */
|
||||||
static const uint8_t dequant_table[64] = {
|
static const uint8_t dequant_table[64] = {
|
||||||
16, 15, 13, 19, 24, 31, 28, 17,
|
16, 15, 13, 19, 24, 31, 28, 17,
|
||||||
17, 23, 25, 31, 36, 63, 45, 21,
|
17, 23, 25, 31, 36, 63, 45, 21,
|
||||||
@ -152,7 +153,8 @@ typedef struct FourXContext{
|
|||||||
|
|
||||||
#define MULTIPLY(var, const) (((var) * (const)) >> 16)
|
#define MULTIPLY(var, const) (((var) * (const)) >> 16)
|
||||||
|
|
||||||
static void idct(DCTELEM block[64]){
|
static void idct(DCTELEM block[64])
|
||||||
|
{
|
||||||
int tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
|
int tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
|
||||||
int tmp10, tmp11, tmp12, tmp13;
|
int tmp10, tmp11, tmp12, tmp13;
|
||||||
int z5, z10, z11, z12, z13;
|
int z5, z10, z11, z12, z13;
|
||||||
@ -236,7 +238,8 @@ static void idct(DCTELEM block[64]){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static av_cold void init_vlcs(FourXContext *f){
|
static av_cold void init_vlcs(FourXContext *f)
|
||||||
|
{
|
||||||
static VLC_TYPE table[8][32][2];
|
static VLC_TYPE table[8][32][2];
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
@ -249,7 +252,8 @@ static av_cold void init_vlcs(FourXContext *f){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void init_mv(FourXContext *f){
|
static void init_mv(FourXContext *f)
|
||||||
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < 256; i++) {
|
for (i = 0; i < 256; i++) {
|
||||||
@ -277,7 +281,9 @@ static void init_mv(FourXContext *f){
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static inline void mcdc(uint16_t *dst, uint16_t *src, int log2w, int h, int stride, int scale, unsigned dc){
|
static inline void mcdc(uint16_t *dst, uint16_t *src, int log2w,
|
||||||
|
int h, int stride, int scale, unsigned dc)
|
||||||
|
{
|
||||||
int i;
|
int i;
|
||||||
dc *= 0x10001;
|
dc *= 0x10001;
|
||||||
|
|
||||||
@ -285,14 +291,16 @@ static inline void mcdc(uint16_t *dst, uint16_t *src, int log2w, int h, int stri
|
|||||||
case 0:
|
case 0:
|
||||||
for (i = 0; i < h; i++) {
|
for (i = 0; i < h; i++) {
|
||||||
dst[0] = scale * src[0] + dc;
|
dst[0] = scale * src[0] + dc;
|
||||||
if(scale) src += stride;
|
if (scale)
|
||||||
|
src += stride;
|
||||||
dst += stride;
|
dst += stride;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
for (i = 0; i < h; i++) {
|
for (i = 0; i < h; i++) {
|
||||||
LE_CENTRIC_MUL(dst, src, scale, dc);
|
LE_CENTRIC_MUL(dst, src, scale, dc);
|
||||||
if(scale) src += stride;
|
if (scale)
|
||||||
|
src += stride;
|
||||||
dst += stride;
|
dst += stride;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -300,7 +308,8 @@ static inline void mcdc(uint16_t *dst, uint16_t *src, int log2w, int h, int stri
|
|||||||
for (i = 0; i < h; i++) {
|
for (i = 0; i < h; i++) {
|
||||||
LE_CENTRIC_MUL(dst, src, scale, dc);
|
LE_CENTRIC_MUL(dst, src, scale, dc);
|
||||||
LE_CENTRIC_MUL(dst + 2, src + 2, scale, dc);
|
LE_CENTRIC_MUL(dst + 2, src + 2, scale, dc);
|
||||||
if(scale) src += stride;
|
if (scale)
|
||||||
|
src += stride;
|
||||||
dst += stride;
|
dst += stride;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -310,18 +319,24 @@ static inline void mcdc(uint16_t *dst, uint16_t *src, int log2w, int h, int stri
|
|||||||
LE_CENTRIC_MUL(dst + 2, src + 2, scale, dc);
|
LE_CENTRIC_MUL(dst + 2, src + 2, scale, dc);
|
||||||
LE_CENTRIC_MUL(dst + 4, src + 4, scale, dc);
|
LE_CENTRIC_MUL(dst + 4, src + 4, scale, dc);
|
||||||
LE_CENTRIC_MUL(dst + 6, src + 6, scale, dc);
|
LE_CENTRIC_MUL(dst + 6, src + 6, scale, dc);
|
||||||
if(scale) src += stride;
|
if (scale)
|
||||||
|
src += stride;
|
||||||
dst += stride;
|
dst += stride;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default: assert(0);
|
default:
|
||||||
|
assert(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void decode_p_block(FourXContext *f, uint16_t *dst, uint16_t *src, int log2w, int log2h, int stride){
|
static void decode_p_block(FourXContext *f, uint16_t *dst, uint16_t *src,
|
||||||
|
int log2w, int log2h, int stride)
|
||||||
|
{
|
||||||
const int index = size2index[log2h][log2w];
|
const int index = size2index[log2h][log2w];
|
||||||
const int h = 1 << log2h;
|
const int h = 1 << log2h;
|
||||||
int code= get_vlc2(&f->gb, block_type_vlc[1-(f->version>1)][index].table, BLOCK_TYPE_VLC_BITS, 1);
|
int code = get_vlc2(&f->gb,
|
||||||
|
block_type_vlc[1 - (f->version > 1)][index].table,
|
||||||
|
BLOCK_TYPE_VLC_BITS, 1);
|
||||||
uint16_t *start = (uint16_t *)f->last_picture.data[0];
|
uint16_t *start = (uint16_t *)f->last_picture.data[0];
|
||||||
uint16_t *end = start + stride * (f->avctx->height - h + 1) - (1 << log2w);
|
uint16_t *end = start + stride * (f->avctx->height - h + 1) - (1 << log2w);
|
||||||
|
|
||||||
@ -337,11 +352,13 @@ static void decode_p_block(FourXContext *f, uint16_t *dst, uint16_t *src, int lo
|
|||||||
} else if (code == 1) {
|
} else if (code == 1) {
|
||||||
log2h--;
|
log2h--;
|
||||||
decode_p_block(f, dst, src, log2w, log2h, stride);
|
decode_p_block(f, dst, src, log2w, log2h, stride);
|
||||||
decode_p_block(f, dst + (stride<<log2h), src + (stride<<log2h), log2w, log2h, stride);
|
decode_p_block(f, dst + (stride << log2h),
|
||||||
|
src + (stride << log2h), log2w, log2h, stride);
|
||||||
} else if (code == 2) {
|
} else if (code == 2) {
|
||||||
log2w--;
|
log2w--;
|
||||||
decode_p_block(f, dst , src, log2w, log2h, stride);
|
decode_p_block(f, dst , src, log2w, log2h, stride);
|
||||||
decode_p_block(f, dst + (1<<log2w), src + (1<<log2w), log2w, log2h, stride);
|
decode_p_block(f, dst + (1 << log2w),
|
||||||
|
src + (1 << log2w), log2w, log2h, stride);
|
||||||
} else if (code == 3 && f->version < 2) {
|
} else if (code == 3 && f->version < 2) {
|
||||||
mcdc(dst, src, log2w, h, stride, 1, 0);
|
mcdc(dst, src, log2w, h, stride, 1, 0);
|
||||||
} else if (code == 4) {
|
} else if (code == 4) {
|
||||||
@ -364,14 +381,16 @@ static void decode_p_block(FourXContext *f, uint16_t *dst, uint16_t *src, int lo
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int decode_p_frame(FourXContext *f, const uint8_t *buf, int length){
|
static int decode_p_frame(FourXContext *f, const uint8_t *buf, int length)
|
||||||
|
{
|
||||||
int x, y;
|
int x, y;
|
||||||
const int width = f->avctx->width;
|
const int width = f->avctx->width;
|
||||||
const int height = f->avctx->height;
|
const int height = f->avctx->height;
|
||||||
uint16_t *src = (uint16_t *)f->last_picture.data[0];
|
uint16_t *src = (uint16_t *)f->last_picture.data[0];
|
||||||
uint16_t *dst = (uint16_t *)f->current_picture.data[0];
|
uint16_t *dst = (uint16_t *)f->current_picture.data[0];
|
||||||
const int stride = f->current_picture.linesize[0] >> 1;
|
const int stride = f->current_picture.linesize[0] >> 1;
|
||||||
unsigned int bitstream_size, bytestream_size, wordstream_size, extra, bytestream_offset, wordstream_offset;
|
unsigned int bitstream_size, bytestream_size, wordstream_size, extra,
|
||||||
|
bytestream_offset, wordstream_offset;
|
||||||
|
|
||||||
if (f->version > 1) {
|
if (f->version > 1) {
|
||||||
extra = 20;
|
extra = 20;
|
||||||
@ -388,31 +407,35 @@ static int decode_p_frame(FourXContext *f, const uint8_t *buf, int length){
|
|||||||
if (bitstream_size + bytestream_size + wordstream_size + extra != length
|
if (bitstream_size + bytestream_size + wordstream_size + extra != length
|
||||||
|| bitstream_size > (1 << 26)
|
|| bitstream_size > (1 << 26)
|
||||||
|| bytestream_size > (1 << 26)
|
|| bytestream_size > (1 << 26)
|
||||||
|| wordstream_size > (1<<26)
|
|| wordstream_size > (1 << 26)) {
|
||||||
){
|
av_log(f->avctx, AV_LOG_ERROR, "lengths %d %d %d %d\n",
|
||||||
av_log(f->avctx, AV_LOG_ERROR, "lengths %d %d %d %d\n", bitstream_size, bytestream_size, wordstream_size,
|
bitstream_size, bytestream_size, wordstream_size,
|
||||||
bitstream_size + bytestream_size + wordstream_size - length);
|
bitstream_size + bytestream_size + wordstream_size - length);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
av_fast_malloc(&f->bitstream_buffer, &f->bitstream_buffer_size, bitstream_size + FF_INPUT_BUFFER_PADDING_SIZE);
|
av_fast_malloc(&f->bitstream_buffer, &f->bitstream_buffer_size,
|
||||||
|
bitstream_size + FF_INPUT_BUFFER_PADDING_SIZE);
|
||||||
if (!f->bitstream_buffer)
|
if (!f->bitstream_buffer)
|
||||||
return AVERROR(ENOMEM);
|
return AVERROR(ENOMEM);
|
||||||
f->dsp.bswap_buf(f->bitstream_buffer, (const uint32_t*)(buf + extra), bitstream_size/4);
|
f->dsp.bswap_buf(f->bitstream_buffer, (const uint32_t*)(buf + extra),
|
||||||
memset((uint8_t*)f->bitstream_buffer + bitstream_size, 0, FF_INPUT_BUFFER_PADDING_SIZE);
|
bitstream_size / 4);
|
||||||
|
memset((uint8_t*)f->bitstream_buffer + bitstream_size,
|
||||||
|
0, FF_INPUT_BUFFER_PADDING_SIZE);
|
||||||
init_get_bits(&f->gb, f->bitstream_buffer, 8 * bitstream_size);
|
init_get_bits(&f->gb, f->bitstream_buffer, 8 * bitstream_size);
|
||||||
|
|
||||||
wordstream_offset = extra + bitstream_size;
|
wordstream_offset = extra + bitstream_size;
|
||||||
bytestream_offset = extra + bitstream_size + wordstream_size;
|
bytestream_offset = extra + bitstream_size + wordstream_size;
|
||||||
bytestream2_init(&f->g2, buf + wordstream_offset, length - wordstream_offset);
|
bytestream2_init(&f->g2, buf + wordstream_offset,
|
||||||
bytestream2_init(&f->g, buf + bytestream_offset, length - bytestream_offset);
|
length - wordstream_offset);
|
||||||
|
bytestream2_init(&f->g, buf + bytestream_offset,
|
||||||
|
length - bytestream_offset);
|
||||||
|
|
||||||
init_mv(f);
|
init_mv(f);
|
||||||
|
|
||||||
for (y = 0; y < height; y += 8) {
|
for (y = 0; y < height; y += 8) {
|
||||||
for(x=0; x<width; x+=8){
|
for (x = 0; x < width; x += 8)
|
||||||
decode_p_block(f, dst + x, src + x, 3, 3, stride);
|
decode_p_block(f, dst + x, src + x, 3, 3, stride);
|
||||||
}
|
|
||||||
src += 8 * stride;
|
src += 8 * stride;
|
||||||
dst += 8 * stride;
|
dst += 8 * stride;
|
||||||
}
|
}
|
||||||
@ -424,21 +447,20 @@ static int decode_p_frame(FourXContext *f, const uint8_t *buf, int length){
|
|||||||
* decode block and dequantize.
|
* decode block and dequantize.
|
||||||
* Note this is almost identical to MJPEG.
|
* Note this is almost identical to MJPEG.
|
||||||
*/
|
*/
|
||||||
static int decode_i_block(FourXContext *f, DCTELEM *block){
|
static int decode_i_block(FourXContext *f, DCTELEM *block)
|
||||||
|
{
|
||||||
int code, i, j, level, val;
|
int code, i, j, level, val;
|
||||||
|
|
||||||
/* DC coef */
|
/* DC coef */
|
||||||
val = get_vlc2(&f->pre_gb, f->pre_vlc.table, ACDC_VLC_BITS, 3);
|
val = get_vlc2(&f->pre_gb, f->pre_vlc.table, ACDC_VLC_BITS, 3);
|
||||||
if (val>>4){
|
if (val >> 4)
|
||||||
av_log(f->avctx, AV_LOG_ERROR, "error dc run != 0\n");
|
av_log(f->avctx, AV_LOG_ERROR, "error dc run != 0\n");
|
||||||
}
|
|
||||||
|
|
||||||
if (val)
|
if (val)
|
||||||
val = get_xbits(&f->gb, val);
|
val = get_xbits(&f->gb, val);
|
||||||
|
|
||||||
val = val * dequant_table[0] + f->last_dc;
|
val = val * dequant_table[0] + f->last_dc;
|
||||||
f->last_dc =
|
f->last_dc = block[0] = val;
|
||||||
block[0] = val;
|
|
||||||
/* AC coefs */
|
/* AC coefs */
|
||||||
i = 1;
|
i = 1;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
@ -468,7 +490,8 @@ static int decode_i_block(FourXContext *f, DCTELEM *block){
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void idct_put(FourXContext *f, int x, int y){
|
static inline void idct_put(FourXContext *f, int x, int y)
|
||||||
|
{
|
||||||
DCTELEM (*block)[64] = f->block;
|
DCTELEM (*block)[64] = f->block;
|
||||||
int stride = f->current_picture.linesize[0] >> 1;
|
int stride = f->current_picture.linesize[0] >> 1;
|
||||||
int i;
|
int i;
|
||||||
@ -480,17 +503,18 @@ static inline void idct_put(FourXContext *f, int x, int y){
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!(f->avctx->flags & CODEC_FLAG_GRAY)) {
|
if (!(f->avctx->flags & CODEC_FLAG_GRAY)) {
|
||||||
for(i=4; i<6; i++) idct(block[i]);
|
for (i = 4; i < 6; i++)
|
||||||
|
idct(block[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Note transform is:
|
/* Note transform is:
|
||||||
y= ( 1b + 4g + 2r)/14
|
* y = ( 1b + 4g + 2r) / 14
|
||||||
cb=( 3b - 2g - 1r)/14
|
* cb = ( 3b - 2g - 1r) / 14
|
||||||
cr=(-1b - 4g + 5r)/14
|
* cr = (-1b - 4g + 5r) / 14 */
|
||||||
*/
|
|
||||||
for (y = 0; y < 8; y++) {
|
for (y = 0; y < 8; y++) {
|
||||||
for (x = 0; x < 8; x++) {
|
for (x = 0; x < 8; x++) {
|
||||||
DCTELEM *temp= block[(x>>2) + 2*(y>>2)] + 2*(x&3) + 2*8*(y&3); //FIXME optimize
|
DCTELEM *temp = block[(x >> 2) + 2 * (y >> 2)] +
|
||||||
|
2 * (x & 3) + 2 * 8 * (y & 3); // FIXME optimize
|
||||||
int cb = block[4][x + 8 * y];
|
int cb = block[4][x + 8 * y];
|
||||||
int cr = block[5][x + 8 * y];
|
int cr = block[5][x + 8 * y];
|
||||||
int cg = (cb + cr) >> 1;
|
int cg = (cb + cr) >> 1;
|
||||||
@ -512,20 +536,22 @@ cr=(-1b - 4g + 5r)/14
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int decode_i_mb(FourXContext *f){
|
static int decode_i_mb(FourXContext *f)
|
||||||
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
f->dsp.clear_blocks(f->block[0]);
|
f->dsp.clear_blocks(f->block[0]);
|
||||||
|
|
||||||
for(i=0; i<6; i++){
|
for (i = 0; i < 6; i++)
|
||||||
if (decode_i_block(f, f->block[i]) < 0)
|
if (decode_i_block(f, f->block[i]) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const uint8_t *read_huffman_tables(FourXContext *f, const uint8_t * const buf){
|
static const uint8_t *read_huffman_tables(FourXContext *f,
|
||||||
|
const uint8_t * const buf)
|
||||||
|
{
|
||||||
int frequency[512];
|
int frequency[512];
|
||||||
uint8_t flag[512];
|
uint8_t flag[512];
|
||||||
int up[512];
|
int up[512];
|
||||||
@ -543,34 +569,40 @@ static const uint8_t *read_huffman_tables(FourXContext *f, const uint8_t * const
|
|||||||
for (;;) {
|
for (;;) {
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for(i=start; i<=end; i++){
|
for (i = start; i <= end; i++)
|
||||||
frequency[i] = *ptr++;
|
frequency[i] = *ptr++;
|
||||||
}
|
|
||||||
start = *ptr++;
|
start = *ptr++;
|
||||||
if(start==0) break;
|
if (start == 0)
|
||||||
|
break;
|
||||||
|
|
||||||
end = *ptr++;
|
end = *ptr++;
|
||||||
}
|
}
|
||||||
frequency[256] = 1;
|
frequency[256] = 1;
|
||||||
|
|
||||||
while((ptr - buf)&3) ptr++; // 4byte align
|
while ((ptr - buf) & 3)
|
||||||
|
ptr++; // 4byte align
|
||||||
|
|
||||||
for (j = 257; j < 512; j++) {
|
for (j = 257; j < 512; j++) {
|
||||||
int min_freq[2] = { 256 * 256, 256 * 256 };
|
int min_freq[2] = { 256 * 256, 256 * 256 };
|
||||||
int smallest[2] = { 0, 0 };
|
int smallest[2] = { 0, 0 };
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < j; i++) {
|
for (i = 0; i < j; i++) {
|
||||||
if(frequency[i] == 0) continue;
|
if (frequency[i] == 0)
|
||||||
|
continue;
|
||||||
if (frequency[i] < min_freq[1]) {
|
if (frequency[i] < min_freq[1]) {
|
||||||
if (frequency[i] < min_freq[0]) {
|
if (frequency[i] < min_freq[0]) {
|
||||||
min_freq[1]= min_freq[0]; smallest[1]= smallest[0];
|
min_freq[1] = min_freq[0];
|
||||||
min_freq[0]= frequency[i];smallest[0]= i;
|
smallest[1] = smallest[0];
|
||||||
|
min_freq[0] = frequency[i];
|
||||||
|
smallest[0] = i;
|
||||||
} else {
|
} else {
|
||||||
min_freq[1]= frequency[i];smallest[1]= i;
|
min_freq[1] = frequency[i];
|
||||||
|
smallest[1] = i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(min_freq[1] == 256*256) break;
|
if (min_freq[1] == 256 * 256)
|
||||||
|
break;
|
||||||
|
|
||||||
frequency[j] = min_freq[0] + min_freq[1];
|
frequency[j] = min_freq[0] + min_freq[1];
|
||||||
flag[smallest[0]] = 0;
|
flag[smallest[0]] = 0;
|
||||||
@ -581,36 +613,38 @@ static const uint8_t *read_huffman_tables(FourXContext *f, const uint8_t * const
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (j = 0; j < 257; j++) {
|
for (j = 0; j < 257; j++) {
|
||||||
int node;
|
int node, len = 0, bits = 0;
|
||||||
int len=0;
|
|
||||||
int bits=0;
|
|
||||||
|
|
||||||
for (node = j; up[node] != -1; node = up[node]) {
|
for (node = j; up[node] != -1; node = up[node]) {
|
||||||
bits += flag[node] << len;
|
bits += flag[node] << len;
|
||||||
len++;
|
len++;
|
||||||
if(len > 31) av_log(f->avctx, AV_LOG_ERROR, "vlc length overflow\n"); //can this happen at all ?
|
if (len > 31)
|
||||||
|
// can this happen at all ?
|
||||||
|
av_log(f->avctx, AV_LOG_ERROR,
|
||||||
|
"vlc length overflow\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
bits_tab[j] = bits;
|
bits_tab[j] = bits;
|
||||||
len_tab[j] = len;
|
len_tab[j] = len;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (init_vlc(&f->pre_vlc, ACDC_VLC_BITS, 257,
|
if (init_vlc(&f->pre_vlc, ACDC_VLC_BITS, 257, len_tab, 1, 1,
|
||||||
len_tab , 1, 1,
|
|
||||||
bits_tab, 4, 4, 0))
|
bits_tab, 4, 4, 0))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int mix(int c0, int c1){
|
static int mix(int c0, int c1)
|
||||||
|
{
|
||||||
int blue = 2 * (c0 & 0x001F) + (c1 & 0x001F);
|
int blue = 2 * (c0 & 0x001F) + (c1 & 0x001F);
|
||||||
int green = (2 * (c0 & 0x03E0) + (c1 & 0x03E0)) >> 5;
|
int green = (2 * (c0 & 0x03E0) + (c1 & 0x03E0)) >> 5;
|
||||||
int red = 2 * (c0 >> 10) + (c1 >> 10);
|
int red = 2 * (c0 >> 10) + (c1 >> 10);
|
||||||
return red / 3 * 1024 + green / 3 * 32 + blue / 3;
|
return red / 3 * 1024 + green / 3 * 32 + blue / 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int decode_i2_frame(FourXContext *f, const uint8_t *buf, int length){
|
static int decode_i2_frame(FourXContext *f, const uint8_t *buf, int length)
|
||||||
|
{
|
||||||
int x, y, x2, y2;
|
int x, y, x2, y2;
|
||||||
const int width = f->avctx->width;
|
const int width = f->avctx->width;
|
||||||
const int height = f->avctx->height;
|
const int height = f->avctx->height;
|
||||||
@ -633,8 +667,10 @@ static int decode_i2_frame(FourXContext *f, const uint8_t *buf, int length){
|
|||||||
color[0] = bytestream2_get_le16u(&g3);
|
color[0] = bytestream2_get_le16u(&g3);
|
||||||
color[1] = bytestream2_get_le16u(&g3);
|
color[1] = bytestream2_get_le16u(&g3);
|
||||||
|
|
||||||
if(color[0]&0x8000) av_log(NULL, AV_LOG_ERROR, "unk bit 1\n");
|
if (color[0] & 0x8000)
|
||||||
if(color[1]&0x8000) av_log(NULL, AV_LOG_ERROR, "unk bit 2\n");
|
av_log(NULL, AV_LOG_ERROR, "unk bit 1\n");
|
||||||
|
if (color[1] & 0x8000)
|
||||||
|
av_log(NULL, AV_LOG_ERROR, "unk bit 2\n");
|
||||||
|
|
||||||
color[2] = mix(color[0], color[1]);
|
color[2] = mix(color[0], color[1]);
|
||||||
color[3] = mix(color[1], color[0]);
|
color[3] = mix(color[1], color[0]);
|
||||||
@ -654,7 +690,8 @@ static int decode_i2_frame(FourXContext *f, const uint8_t *buf, int length){
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int decode_i_frame(FourXContext *f, const uint8_t *buf, int length){
|
static int decode_i_frame(FourXContext *f, const uint8_t *buf, int length)
|
||||||
|
{
|
||||||
int x, y;
|
int x, y;
|
||||||
const int width = f->avctx->width;
|
const int width = f->avctx->width;
|
||||||
const int height = f->avctx->height;
|
const int height = f->avctx->height;
|
||||||
@ -675,7 +712,8 @@ static int decode_i_frame(FourXContext *f, const uint8_t *buf, int length){
|
|||||||
if (prestream_size + bitstream_size + 12 != length
|
if (prestream_size + bitstream_size + 12 != length
|
||||||
|| bitstream_size > (1 << 26)
|
|| bitstream_size > (1 << 26)
|
||||||
|| prestream_size > (1 << 26)) {
|
|| prestream_size > (1 << 26)) {
|
||||||
av_log(f->avctx, AV_LOG_ERROR, "size mismatch %d %d %d\n", prestream_size, bitstream_size, length);
|
av_log(f->avctx, AV_LOG_ERROR, "size mismatch %d %d %d\n",
|
||||||
|
prestream_size, bitstream_size, length);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -685,11 +723,14 @@ static int decode_i_frame(FourXContext *f, const uint8_t *buf, int length){
|
|||||||
|
|
||||||
prestream_size = length + buf - prestream;
|
prestream_size = length + buf - prestream;
|
||||||
|
|
||||||
av_fast_malloc(&f->bitstream_buffer, &f->bitstream_buffer_size, prestream_size + FF_INPUT_BUFFER_PADDING_SIZE);
|
av_fast_malloc(&f->bitstream_buffer, &f->bitstream_buffer_size,
|
||||||
|
prestream_size + FF_INPUT_BUFFER_PADDING_SIZE);
|
||||||
if (!f->bitstream_buffer)
|
if (!f->bitstream_buffer)
|
||||||
return AVERROR(ENOMEM);
|
return AVERROR(ENOMEM);
|
||||||
f->dsp.bswap_buf(f->bitstream_buffer, (const uint32_t*)prestream, prestream_size/4);
|
f->dsp.bswap_buf(f->bitstream_buffer, (const uint32_t*)prestream,
|
||||||
memset((uint8_t*)f->bitstream_buffer + prestream_size, 0, FF_INPUT_BUFFER_PADDING_SIZE);
|
prestream_size / 4);
|
||||||
|
memset((uint8_t*)f->bitstream_buffer + prestream_size,
|
||||||
|
0, FF_INPUT_BUFFER_PADDING_SIZE);
|
||||||
init_get_bits(&f->pre_gb, f->bitstream_buffer, 8 * prestream_size);
|
init_get_bits(&f->pre_gb, f->bitstream_buffer, 8 * prestream_size);
|
||||||
|
|
||||||
f->last_dc = 0 * 128 * 8 * 8;
|
f->last_dc = 0 * 128 * 8 * 8;
|
||||||
@ -709,9 +750,8 @@ static int decode_i_frame(FourXContext *f, const uint8_t *buf, int length){
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int decode_frame(AVCodecContext *avctx,
|
static int decode_frame(AVCodecContext *avctx, void *data,
|
||||||
void *data, int *data_size,
|
int *data_size, AVPacket *avpkt)
|
||||||
AVPacket *avpkt)
|
|
||||||
{
|
{
|
||||||
const uint8_t *buf = avpkt->data;
|
const uint8_t *buf = avpkt->data;
|
||||||
int buf_size = avpkt->size;
|
int buf_size = avpkt->size;
|
||||||
@ -721,9 +761,9 @@ static int decode_frame(AVCodecContext *avctx,
|
|||||||
int i, frame_4cc, frame_size;
|
int i, frame_4cc, frame_size;
|
||||||
|
|
||||||
frame_4cc = AV_RL32(buf);
|
frame_4cc = AV_RL32(buf);
|
||||||
if(buf_size != AV_RL32(buf+4)+8 || buf_size < 20){
|
if (buf_size != AV_RL32(buf + 4) + 8 || buf_size < 20)
|
||||||
av_log(f->avctx, AV_LOG_ERROR, "size mismatch %d %d\n", buf_size, AV_RL32(buf+4));
|
av_log(f->avctx, AV_LOG_ERROR, "size mismatch %d %d\n",
|
||||||
}
|
buf_size, AV_RL32(buf + 4));
|
||||||
|
|
||||||
if (frame_4cc == AV_RL32("cfrm")) {
|
if (frame_4cc == AV_RL32("cfrm")) {
|
||||||
int free_index = -1;
|
int free_index = -1;
|
||||||
@ -732,14 +772,16 @@ static int decode_frame(AVCodecContext *avctx,
|
|||||||
const int whole_size = AV_RL32(buf + 16);
|
const int whole_size = AV_RL32(buf + 16);
|
||||||
CFrameBuffer *cfrm;
|
CFrameBuffer *cfrm;
|
||||||
|
|
||||||
for(i=0; i<CFRAME_BUFFER_COUNT; i++){
|
for (i = 0; i < CFRAME_BUFFER_COUNT; i++)
|
||||||
if (f->cfrm[i].id && f->cfrm[i].id < avctx->frame_number)
|
if (f->cfrm[i].id && f->cfrm[i].id < avctx->frame_number)
|
||||||
av_log(f->avctx, AV_LOG_ERROR, "lost c frame %d\n", f->cfrm[i].id);
|
av_log(f->avctx, AV_LOG_ERROR, "lost c frame %d\n",
|
||||||
}
|
f->cfrm[i].id);
|
||||||
|
|
||||||
for (i = 0; i < CFRAME_BUFFER_COUNT; i++) {
|
for (i = 0; i < CFRAME_BUFFER_COUNT; i++) {
|
||||||
if(f->cfrm[i].id == id) break;
|
if (f->cfrm[i].id == id)
|
||||||
if(f->cfrm[i].size == 0 ) free_index= i;
|
break;
|
||||||
|
if (f->cfrm[i].size == 0)
|
||||||
|
free_index = i;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i >= CFRAME_BUFFER_COUNT) {
|
if (i >= CFRAME_BUFFER_COUNT) {
|
||||||
@ -748,8 +790,10 @@ static int decode_frame(AVCodecContext *avctx,
|
|||||||
}
|
}
|
||||||
cfrm = &f->cfrm[i];
|
cfrm = &f->cfrm[i];
|
||||||
|
|
||||||
cfrm->data= av_fast_realloc(cfrm->data, &cfrm->allocated_size, cfrm->size + data_size + FF_INPUT_BUFFER_PADDING_SIZE);
|
cfrm->data = av_fast_realloc(cfrm->data, &cfrm->allocated_size,
|
||||||
if(!cfrm->data){ //explicit check needed as memcpy below might not catch a NULL
|
cfrm->size + data_size + FF_INPUT_BUFFER_PADDING_SIZE);
|
||||||
|
// explicit check needed as memcpy below might not catch a NULL
|
||||||
|
if (!cfrm->data) {
|
||||||
av_log(f->avctx, AV_LOG_ERROR, "realloc falure");
|
av_log(f->avctx, AV_LOG_ERROR, "realloc falure");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -761,9 +805,9 @@ static int decode_frame(AVCodecContext *avctx,
|
|||||||
buf = cfrm->data;
|
buf = cfrm->data;
|
||||||
frame_size = cfrm->size;
|
frame_size = cfrm->size;
|
||||||
|
|
||||||
if(id != avctx->frame_number){
|
if (id != avctx->frame_number)
|
||||||
av_log(f->avctx, AV_LOG_ERROR, "cframe id mismatch %d %d\n", id, avctx->frame_number);
|
av_log(f->avctx, AV_LOG_ERROR, "cframe id mismatch %d %d\n",
|
||||||
}
|
id, avctx->frame_number);
|
||||||
|
|
||||||
cfrm->size = cfrm->id = 0;
|
cfrm->size = cfrm->id = 0;
|
||||||
frame_4cc = AV_RL32("pfrm");
|
frame_4cc = AV_RL32("pfrm");
|
||||||
@ -781,7 +825,8 @@ static int decode_frame(AVCodecContext *avctx,
|
|||||||
p = &f->current_picture;
|
p = &f->current_picture;
|
||||||
avctx->coded_frame = p;
|
avctx->coded_frame = p;
|
||||||
|
|
||||||
avctx->flags |= CODEC_FLAG_EMU_EDGE; // alternatively we would have to use our own buffer management
|
// alternatively we would have to use our own buffer management
|
||||||
|
avctx->flags |= CODEC_FLAG_EMU_EDGE;
|
||||||
|
|
||||||
if (p->data[0])
|
if (p->data[0])
|
||||||
avctx->release_buffer(avctx, p);
|
avctx->release_buffer(avctx, p);
|
||||||
@ -813,9 +858,11 @@ static int decode_frame(AVCodecContext *avctx,
|
|||||||
if (decode_p_frame(f, buf, frame_size) < 0)
|
if (decode_p_frame(f, buf, frame_size) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
} else if (frame_4cc == AV_RL32("snd_")) {
|
} else if (frame_4cc == AV_RL32("snd_")) {
|
||||||
av_log(avctx, AV_LOG_ERROR, "ignoring snd_ chunk length:%d\n", buf_size);
|
av_log(avctx, AV_LOG_ERROR, "ignoring snd_ chunk length:%d\n",
|
||||||
|
buf_size);
|
||||||
} else {
|
} else {
|
||||||
av_log(avctx, AV_LOG_ERROR, "ignoring unknown chunk length:%d\n", buf_size);
|
av_log(avctx, AV_LOG_ERROR, "ignoring unknown chunk length:%d\n",
|
||||||
|
buf_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
p->key_frame = p->pict_type == AV_PICTURE_TYPE_I;
|
p->key_frame = p->pict_type == AV_PICTURE_TYPE_I;
|
||||||
@ -829,7 +876,8 @@ static int decode_frame(AVCodecContext *avctx,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static av_cold void common_init(AVCodecContext *avctx){
|
static av_cold void common_init(AVCodecContext *avctx)
|
||||||
|
{
|
||||||
FourXContext * const f = avctx->priv_data;
|
FourXContext * const f = avctx->priv_data;
|
||||||
|
|
||||||
dsputil_init(&f->dsp, avctx);
|
dsputil_init(&f->dsp, avctx);
|
||||||
@ -837,7 +885,8 @@ static av_cold void common_init(AVCodecContext *avctx){
|
|||||||
f->avctx = avctx;
|
f->avctx = avctx;
|
||||||
}
|
}
|
||||||
|
|
||||||
static av_cold int decode_init(AVCodecContext *avctx){
|
static av_cold int decode_init(AVCodecContext *avctx)
|
||||||
|
{
|
||||||
FourXContext * const f = avctx->priv_data;
|
FourXContext * const f = avctx->priv_data;
|
||||||
|
|
||||||
if (avctx->extradata_size != 4 || !avctx->extradata) {
|
if (avctx->extradata_size != 4 || !avctx->extradata) {
|
||||||
@ -849,14 +898,17 @@ static av_cold int decode_init(AVCodecContext *avctx){
|
|||||||
common_init(avctx);
|
common_init(avctx);
|
||||||
init_vlcs(f);
|
init_vlcs(f);
|
||||||
|
|
||||||
if(f->version>2) avctx->pix_fmt= PIX_FMT_RGB565;
|
if (f->version > 2)
|
||||||
else avctx->pix_fmt= PIX_FMT_BGR555;
|
avctx->pix_fmt = PIX_FMT_RGB565;
|
||||||
|
else
|
||||||
|
avctx->pix_fmt = PIX_FMT_BGR555;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static av_cold int decode_end(AVCodecContext *avctx){
|
static av_cold int decode_end(AVCodecContext *avctx)
|
||||||
|
{
|
||||||
FourXContext * const f = avctx->priv_data;
|
FourXContext * const f = avctx->priv_data;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
@ -22,10 +22,9 @@
|
|||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "libavutil/mem.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "timefilter.h"
|
#include "timefilter.h"
|
||||||
#include "libavutil/mem.h"
|
|
||||||
|
|
||||||
struct TimeFilter {
|
struct TimeFilter {
|
||||||
/// Delay Locked Loop data. These variables refer to mathematical
|
/// Delay Locked Loop data. These variables refer to mathematical
|
||||||
@ -37,7 +36,9 @@ struct TimeFilter {
|
|||||||
int count;
|
int count;
|
||||||
};
|
};
|
||||||
|
|
||||||
TimeFilter * ff_timefilter_new(double clock_period, double feedback2_factor, double feedback3_factor)
|
TimeFilter *ff_timefilter_new(double clock_period,
|
||||||
|
double feedback2_factor,
|
||||||
|
double feedback3_factor)
|
||||||
{
|
{
|
||||||
TimeFilter *self = av_mallocz(sizeof(TimeFilter));
|
TimeFilter *self = av_mallocz(sizeof(TimeFilter));
|
||||||
self->clock_period = clock_period;
|
self->clock_period = clock_period;
|
||||||
@ -92,7 +93,8 @@ int main(void)
|
|||||||
for (n0 = 0; n0 < 40; n0 = 2 * n0 + 1) {
|
for (n0 = 0; n0 < 40; n0 = 2 * n0 + 1) {
|
||||||
for (n1 = 0; n1 < 10; n1 = 2 * n1 + 1) {
|
for (n1 = 0; n1 < 10; n1 = 2 * n1 + 1) {
|
||||||
#else
|
#else
|
||||||
{{
|
{
|
||||||
|
{
|
||||||
n0 = 7;
|
n0 = 7;
|
||||||
n1 = 1;
|
n1 = 1;
|
||||||
#endif
|
#endif
|
||||||
@ -104,8 +106,7 @@ int main(void)
|
|||||||
av_lfg_init(&prng, 123);
|
av_lfg_init(&prng, 123);
|
||||||
for (i = 0; i < SAMPLES; i++) {
|
for (i = 0; i < SAMPLES; i++) {
|
||||||
ideal[i] = 10 + i + n1 * i / (1000);
|
ideal[i] = 10 + i + n1 * i / (1000);
|
||||||
samples[i] = ideal[i] + n0 * (av_lfg_get(&prng) - LFG_MAX / 2)
|
samples[i] = ideal[i] + n0 * (av_lfg_get(&prng) - LFG_MAX / 2) / (LFG_MAX * 10LL);
|
||||||
/ (LFG_MAX * 10LL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
do {
|
do {
|
||||||
@ -136,7 +137,8 @@ int main(void)
|
|||||||
for (i = 0; i < SAMPLES; i++) {
|
for (i = 0; i < SAMPLES; i++) {
|
||||||
double filtered;
|
double filtered;
|
||||||
filtered = ff_timefilter_update(tf, samples[i], 1);
|
filtered = ff_timefilter_update(tf, samples[i], 1);
|
||||||
printf("%f %f %f %f\n", i - samples[i] + 10, filtered - samples[i], samples[FFMAX(i, 1)] - samples[FFMAX(i-1, 0)], filtered - lastfil);
|
printf("%f %f %f %f\n", i - samples[i] + 10, filtered - samples[i],
|
||||||
|
samples[FFMAX(i, 1)] - samples[FFMAX(i - 1, 0)], filtered - lastfil);
|
||||||
lastfil = filtered;
|
lastfil = filtered;
|
||||||
}
|
}
|
||||||
ff_timefilter_destroy(tf);
|
ff_timefilter_destroy(tf);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user