|
|
|
@ -32,31 +32,37 @@ |
|
|
|
|
#include "mathops.h" |
|
|
|
|
#include "mpeg12data.h" |
|
|
|
|
|
|
|
|
|
static inline void asv2_put_bits(PutBitContext *pb, int n, int v){ |
|
|
|
|
static inline void asv2_put_bits(PutBitContext *pb, int n, int v) |
|
|
|
|
{ |
|
|
|
|
put_bits(pb, n, ff_reverse[v << (8 - n)]); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static inline void asv1_put_level(PutBitContext *pb, int level){ |
|
|
|
|
static inline void asv1_put_level(PutBitContext *pb, int level) |
|
|
|
|
{ |
|
|
|
|
unsigned int index = level + 3; |
|
|
|
|
|
|
|
|
|
if(index <= 6) put_bits(pb, ff_asv_level_tab[index][1], ff_asv_level_tab[index][0]); |
|
|
|
|
else{ |
|
|
|
|
if (index <= 6) { |
|
|
|
|
put_bits(pb, ff_asv_level_tab[index][1], ff_asv_level_tab[index][0]); |
|
|
|
|
} else { |
|
|
|
|
put_bits(pb, ff_asv_level_tab[3][1], ff_asv_level_tab[3][0]); |
|
|
|
|
put_sbits(pb, 8, level); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static inline void asv2_put_level(PutBitContext *pb, int level){ |
|
|
|
|
static inline void asv2_put_level(PutBitContext *pb, int level) |
|
|
|
|
{ |
|
|
|
|
unsigned int index = level + 31; |
|
|
|
|
|
|
|
|
|
if(index <= 62) put_bits(pb, ff_asv2_level_tab[index][1], ff_asv2_level_tab[index][0]); |
|
|
|
|
else{ |
|
|
|
|
if (index <= 62) { |
|
|
|
|
put_bits(pb, ff_asv2_level_tab[index][1], ff_asv2_level_tab[index][0]); |
|
|
|
|
} else { |
|
|
|
|
put_bits(pb, ff_asv2_level_tab[31][1], ff_asv2_level_tab[31][0]); |
|
|
|
|
asv2_put_bits(pb, 8, level & 0xFF); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static inline void asv1_encode_block(ASV1Context *a, int16_t block[64]){ |
|
|
|
|
static inline void asv1_encode_block(ASV1Context *a, int16_t block[64]) |
|
|
|
|
{ |
|
|
|
|
int i; |
|
|
|
|
int nc_count = 0; |
|
|
|
|
|
|
|
|
@ -67,10 +73,18 @@ static inline void asv1_encode_block(ASV1Context *a, int16_t block[64]){ |
|
|
|
|
const int index = ff_asv_scantab[4 * i]; |
|
|
|
|
int ccp = 0; |
|
|
|
|
|
|
|
|
|
if( (block[index + 0] = (block[index + 0]*a->q_intra_matrix[index + 0] + (1<<15))>>16) ) ccp |= 8; |
|
|
|
|
if( (block[index + 8] = (block[index + 8]*a->q_intra_matrix[index + 8] + (1<<15))>>16) ) ccp |= 4; |
|
|
|
|
if( (block[index + 1] = (block[index + 1]*a->q_intra_matrix[index + 1] + (1<<15))>>16) ) ccp |= 2; |
|
|
|
|
if( (block[index + 9] = (block[index + 9]*a->q_intra_matrix[index + 9] + (1<<15))>>16) ) ccp |= 1; |
|
|
|
|
if ((block[index + 0] = (block[index + 0] * |
|
|
|
|
a->q_intra_matrix[index + 0] + (1 << 15)) >> 16)) |
|
|
|
|
ccp |= 8; |
|
|
|
|
if ((block[index + 8] = (block[index + 8] * |
|
|
|
|
a->q_intra_matrix[index + 8] + (1 << 15)) >> 16)) |
|
|
|
|
ccp |= 4; |
|
|
|
|
if ((block[index + 1] = (block[index + 1] * |
|
|
|
|
a->q_intra_matrix[index + 1] + (1 << 15)) >> 16)) |
|
|
|
|
ccp |= 2; |
|
|
|
|
if ((block[index + 9] = (block[index + 9] * |
|
|
|
|
a->q_intra_matrix[index + 9] + (1 << 15)) >> 16)) |
|
|
|
|
ccp |= 1; |
|
|
|
|
|
|
|
|
|
if (ccp) { |
|
|
|
|
for (; nc_count; nc_count--) |
|
|
|
@ -78,10 +92,14 @@ static inline void asv1_encode_block(ASV1Context *a, int16_t block[64]){ |
|
|
|
|
|
|
|
|
|
put_bits(&a->pb, ff_asv_ccp_tab[ccp][1], ff_asv_ccp_tab[ccp][0]); |
|
|
|
|
|
|
|
|
|
if(ccp&8) asv1_put_level(&a->pb, block[index + 0]); |
|
|
|
|
if(ccp&4) asv1_put_level(&a->pb, block[index + 8]); |
|
|
|
|
if(ccp&2) asv1_put_level(&a->pb, block[index + 1]); |
|
|
|
|
if(ccp&1) asv1_put_level(&a->pb, block[index + 9]); |
|
|
|
|
if (ccp & 8) |
|
|
|
|
asv1_put_level(&a->pb, block[index + 0]); |
|
|
|
|
if (ccp & 4) |
|
|
|
|
asv1_put_level(&a->pb, block[index + 8]); |
|
|
|
|
if (ccp & 2) |
|
|
|
|
asv1_put_level(&a->pb, block[index + 1]); |
|
|
|
|
if (ccp & 1) |
|
|
|
|
asv1_put_level(&a->pb, block[index + 9]); |
|
|
|
|
} else { |
|
|
|
|
nc_count++; |
|
|
|
|
} |
|
|
|
@ -89,13 +107,13 @@ static inline void asv1_encode_block(ASV1Context *a, int16_t block[64]){ |
|
|
|
|
put_bits(&a->pb, ff_asv_ccp_tab[16][1], ff_asv_ccp_tab[16][0]); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static inline void asv2_encode_block(ASV1Context *a, int16_t block[64]){ |
|
|
|
|
static inline void asv2_encode_block(ASV1Context *a, int16_t block[64]) |
|
|
|
|
{ |
|
|
|
|
int i; |
|
|
|
|
int count = 0; |
|
|
|
|
|
|
|
|
|
for (count = 63; count > 3; count--) { |
|
|
|
|
const int index = ff_asv_scantab[count]; |
|
|
|
|
|
|
|
|
|
if ((block[index] * a->q_intra_matrix[index] + (1 << 15)) >> 16) |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
@ -110,27 +128,42 @@ static inline void asv2_encode_block(ASV1Context *a, int16_t block[64]){ |
|
|
|
|
const int index = ff_asv_scantab[4 * i]; |
|
|
|
|
int ccp = 0; |
|
|
|
|
|
|
|
|
|
if( (block[index + 0] = (block[index + 0]*a->q_intra_matrix[index + 0] + (1<<15))>>16) ) ccp |= 8; |
|
|
|
|
if( (block[index + 8] = (block[index + 8]*a->q_intra_matrix[index + 8] + (1<<15))>>16) ) ccp |= 4; |
|
|
|
|
if( (block[index + 1] = (block[index + 1]*a->q_intra_matrix[index + 1] + (1<<15))>>16) ) ccp |= 2; |
|
|
|
|
if( (block[index + 9] = (block[index + 9]*a->q_intra_matrix[index + 9] + (1<<15))>>16) ) ccp |= 1; |
|
|
|
|
if ((block[index + 0] = (block[index + 0] * |
|
|
|
|
a->q_intra_matrix[index + 0] + (1 << 15)) >> 16)) |
|
|
|
|
ccp |= 8; |
|
|
|
|
if ((block[index + 8] = (block[index + 8] * |
|
|
|
|
a->q_intra_matrix[index + 8] + (1 << 15)) >> 16)) |
|
|
|
|
ccp |= 4; |
|
|
|
|
if ((block[index + 1] = (block[index + 1] * |
|
|
|
|
a->q_intra_matrix[index + 1] + (1 << 15)) >> 16)) |
|
|
|
|
ccp |= 2; |
|
|
|
|
if ((block[index + 9] = (block[index + 9] * |
|
|
|
|
a->q_intra_matrix[index + 9] + (1 << 15)) >> 16)) |
|
|
|
|
ccp |= 1; |
|
|
|
|
|
|
|
|
|
assert(i || ccp < 8); |
|
|
|
|
if(i) put_bits(&a->pb, ff_asv_ac_ccp_tab[ccp][1], ff_asv_ac_ccp_tab[ccp][0]); |
|
|
|
|
else put_bits(&a->pb, ff_asv_dc_ccp_tab[ccp][1], ff_asv_dc_ccp_tab[ccp][0]); |
|
|
|
|
if (i) |
|
|
|
|
put_bits(&a->pb, ff_asv_ac_ccp_tab[ccp][1], ff_asv_ac_ccp_tab[ccp][0]); |
|
|
|
|
else |
|
|
|
|
put_bits(&a->pb, ff_asv_dc_ccp_tab[ccp][1], ff_asv_dc_ccp_tab[ccp][0]); |
|
|
|
|
|
|
|
|
|
if (ccp) { |
|
|
|
|
if(ccp&8) asv2_put_level(&a->pb, block[index + 0]); |
|
|
|
|
if(ccp&4) asv2_put_level(&a->pb, block[index + 8]); |
|
|
|
|
if(ccp&2) asv2_put_level(&a->pb, block[index + 1]); |
|
|
|
|
if(ccp&1) asv2_put_level(&a->pb, block[index + 9]); |
|
|
|
|
if (ccp & 8) |
|
|
|
|
asv2_put_level(&a->pb, block[index + 0]); |
|
|
|
|
if (ccp & 4) |
|
|
|
|
asv2_put_level(&a->pb, block[index + 8]); |
|
|
|
|
if (ccp & 2) |
|
|
|
|
asv2_put_level(&a->pb, block[index + 1]); |
|
|
|
|
if (ccp & 1) |
|
|
|
|
asv2_put_level(&a->pb, block[index + 9]); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#define MAX_MB_SIZE (30 * 16 * 16 * 3 / 2 / 8) |
|
|
|
|
|
|
|
|
|
static inline int encode_mb(ASV1Context *a, int16_t block[6][64]){ |
|
|
|
|
static inline int encode_mb(ASV1Context *a, int16_t block[6][64]) |
|
|
|
|
{ |
|
|
|
|
int i; |
|
|
|
|
|
|
|
|
|
if (a->pb.buf_end - a->pb.buf - (put_bits_count(&a->pb) >> 3) < MAX_MB_SIZE) { |
|
|
|
@ -220,10 +253,10 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, |
|
|
|
|
|
|
|
|
|
size = put_bits_count(&a->pb) / 32; |
|
|
|
|
|
|
|
|
|
if(avctx->codec_id == AV_CODEC_ID_ASV1) |
|
|
|
|
if (avctx->codec_id == AV_CODEC_ID_ASV1) { |
|
|
|
|
a->bbdsp.bswap_buf((uint32_t *) pkt->data, |
|
|
|
|
(uint32_t *) pkt->data, size); |
|
|
|
|
else{ |
|
|
|
|
} else { |
|
|
|
|
int i; |
|
|
|
|
for (i = 0; i < 4 * size; i++) |
|
|
|
|
pkt->data[i] = ff_reverse[pkt->data[i]]; |
|
|
|
@ -236,7 +269,8 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, |
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static av_cold int encode_init(AVCodecContext *avctx){ |
|
|
|
|
static av_cold int encode_init(AVCodecContext *avctx) |
|
|
|
|
{ |
|
|
|
|
ASV1Context *const a = avctx->priv_data; |
|
|
|
|
int i; |
|
|
|
|
const int scale = avctx->codec_id == AV_CODEC_ID_ASV1 ? 1 : 2; |
|
|
|
@ -251,9 +285,11 @@ static av_cold int encode_init(AVCodecContext *avctx){ |
|
|
|
|
ff_fdctdsp_init(&a->fdsp, avctx); |
|
|
|
|
ff_pixblockdsp_init(&a->pdsp, avctx); |
|
|
|
|
|
|
|
|
|
if(avctx->global_quality == 0) avctx->global_quality= 4*FF_QUALITY_SCALE; |
|
|
|
|
if (avctx->global_quality == 0) |
|
|
|
|
avctx->global_quality = 4 * FF_QUALITY_SCALE; |
|
|
|
|
|
|
|
|
|
a->inv_qscale= (32*scale*FF_QUALITY_SCALE + avctx->global_quality/2) / avctx->global_quality; |
|
|
|
|
a->inv_qscale = (32 * scale * FF_QUALITY_SCALE + |
|
|
|
|
avctx->global_quality / 2) / avctx->global_quality; |
|
|
|
|
|
|
|
|
|
avctx->extradata = av_mallocz(8); |
|
|
|
|
avctx->extradata_size = 8; |
|
|
|
@ -267,6 +303,7 @@ static av_cold int encode_init(AVCodecContext *avctx){ |
|
|
|
|
|
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static av_cold int asv_encode_close(AVCodecContext *avctx) |
|
|
|
|
{ |
|
|
|
|
av_frame_free(&avctx->coded_frame); |
|
|
|
|