1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-11-26 19:01:44 +02:00

asv: K&R formatting cosmetics

Signed-off-by: Diego Biurrun <diego@biurrun.de>
This commit is contained in:
Gabriel Dume 2014-09-01 15:18:58 -04:00 committed by Diego Biurrun
parent 74512f7e36
commit f61e47dd68
4 changed files with 202 additions and 165 deletions

View File

@ -80,7 +80,8 @@ const uint8_t ff_asv2_level_tab[63][2] = {
{ 0x22, 10 }, { 0x32, 10 }, { 0x2A, 10 }, { 0x3A, 10 }, { 0x26, 10 }, { 0x36, 10 }, { 0x2E, 10 }, { 0x3E, 10 },
};
av_cold void ff_asv_common_init(AVCodecContext *avctx) {
av_cold void ff_asv_common_init(AVCodecContext *avctx)
{
ASV1Context *const a = avctx->priv_data;
ff_bswapdsp_init(&a->bbdsp);

View File

@ -202,8 +202,7 @@ static inline void idct_put(ASV1Context *a, AVFrame *frame, int mb_x, int mb_y)
}
}
static int decode_frame(AVCodecContext *avctx,
void *data, int *got_frame,
static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
AVPacket *avpkt)
{
ASV1Context *const a = avctx->priv_data;
@ -224,10 +223,10 @@ static int decode_frame(AVCodecContext *avctx,
if (!a->bitstream_buffer)
return AVERROR(ENOMEM);
if (avctx->codec_id == AV_CODEC_ID_ASV1)
if (avctx->codec_id == AV_CODEC_ID_ASV1) {
a->bbdsp.bswap_buf((uint32_t *) a->bitstream_buffer,
(const uint32_t *) buf, buf_size / 4);
else {
} else {
int i;
for (i = 0; i < buf_size; i++)
a->bitstream_buffer[i] = ff_reverse[buf[i]];
@ -301,7 +300,8 @@ static av_cold int decode_init(AVCodecContext *avctx)
for (i = 0; i < 64; i++) {
int index = ff_asv_scantab[i];
a->intra_matrix[i] = 64 * scale * ff_mpeg1_default_intra_matrix[index] / a->inv_qscale;
a->intra_matrix[i] = 64 * scale * ff_mpeg1_default_intra_matrix[index] /
a->inv_qscale;
}
return 0;
@ -340,4 +340,3 @@ AVCodec ff_asv2_decoder = {
.decode = decode_frame,
.capabilities = CODEC_CAP_DR1,
};

View File

@ -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);