|
|
@ -52,7 +52,10 @@ static void mpeg1_encode_block(MpegEncContext *s, |
|
|
|
int component); |
|
|
|
int component); |
|
|
|
static void mpeg1_encode_motion(MpegEncContext *s, int val); |
|
|
|
static void mpeg1_encode_motion(MpegEncContext *s, int val); |
|
|
|
static void mpeg1_skip_picture(MpegEncContext *s, int pict_num); |
|
|
|
static void mpeg1_skip_picture(MpegEncContext *s, int pict_num); |
|
|
|
static int mpeg1_decode_block(MpegEncContext *s,
|
|
|
|
static inline int mpeg1_decode_block_inter(MpegEncContext *s,
|
|
|
|
|
|
|
|
DCTELEM *block,
|
|
|
|
|
|
|
|
int n); |
|
|
|
|
|
|
|
static inline int mpeg1_decode_block_intra(MpegEncContext *s,
|
|
|
|
DCTELEM *block,
|
|
|
|
DCTELEM *block,
|
|
|
|
int n); |
|
|
|
int n); |
|
|
|
static int mpeg2_decode_block_non_intra(MpegEncContext *s,
|
|
|
|
static int mpeg2_decode_block_non_intra(MpegEncContext *s,
|
|
|
@ -92,8 +95,8 @@ static void init_2d_vlc_rl(RLTable *rl) |
|
|
|
run= 65; |
|
|
|
run= 65; |
|
|
|
level= 0; |
|
|
|
level= 0; |
|
|
|
}else if(code==rl->n+1){ //eob
|
|
|
|
}else if(code==rl->n+1){ //eob
|
|
|
|
run= 192; |
|
|
|
run= 0; |
|
|
|
level= 1; |
|
|
|
level= 127; |
|
|
|
}else{ |
|
|
|
}else{ |
|
|
|
run= rl->table_run [code] + 1; |
|
|
|
run= rl->table_run [code] + 1; |
|
|
|
level= rl->table_level[code]; |
|
|
|
level= rl->table_level[code]; |
|
|
@ -932,31 +935,36 @@ static int mpeg_decode_mb(MpegEncContext *s, |
|
|
|
if (s->mpeg2) { |
|
|
|
if (s->mpeg2) { |
|
|
|
if (s->mb_intra) { |
|
|
|
if (s->mb_intra) { |
|
|
|
for(i=0;i<6;i++) { |
|
|
|
for(i=0;i<6;i++) { |
|
|
|
if (cbp & (1 << (5 - i))) { |
|
|
|
|
|
|
|
if (mpeg2_decode_block_intra(s, block[i], i) < 0) |
|
|
|
if (mpeg2_decode_block_intra(s, block[i], i) < 0) |
|
|
|
return -1; |
|
|
|
return -1; |
|
|
|
} else { |
|
|
|
|
|
|
|
s->block_last_index[i] = -1; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
for(i=0;i<6;i++) { |
|
|
|
for(i=0;i<6;i++) { |
|
|
|
if (cbp & (1 << (5 - i))) { |
|
|
|
if (cbp & 32) { |
|
|
|
if (mpeg2_decode_block_non_intra(s, block[i], i) < 0) |
|
|
|
if (mpeg2_decode_block_non_intra(s, block[i], i) < 0) |
|
|
|
return -1; |
|
|
|
return -1; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
s->block_last_index[i] = -1; |
|
|
|
s->block_last_index[i] = -1; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
cbp+=cbp; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
|
|
|
|
if (s->mb_intra) { |
|
|
|
for(i=0;i<6;i++) { |
|
|
|
for(i=0;i<6;i++) { |
|
|
|
if (cbp & (1 << (5 - i))) { |
|
|
|
if (mpeg1_decode_block_intra(s, block[i], i) < 0) |
|
|
|
if (mpeg1_decode_block(s, block[i], i) < 0) |
|
|
|
return -1; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}else{ |
|
|
|
|
|
|
|
for(i=0;i<6;i++) { |
|
|
|
|
|
|
|
if (cbp & 32) { |
|
|
|
|
|
|
|
if (mpeg1_decode_block_inter(s, block[i], i) < 0) |
|
|
|
return -1; |
|
|
|
return -1; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
s->block_last_index[i] = -1; |
|
|
|
s->block_last_index[i] = -1; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
cbp+=cbp; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return 0; |
|
|
|
return 0; |
|
|
@ -1018,16 +1026,17 @@ static inline int decode_dc(MpegEncContext *s, int component) |
|
|
|
return diff; |
|
|
|
return diff; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static int mpeg1_decode_block(MpegEncContext *s,
|
|
|
|
static inline int mpeg1_decode_block_intra(MpegEncContext *s,
|
|
|
|
DCTELEM *block,
|
|
|
|
DCTELEM *block,
|
|
|
|
int n) |
|
|
|
int n) |
|
|
|
{ |
|
|
|
{ |
|
|
|
int level, dc, diff, i, j, run; |
|
|
|
int level, dc, diff, i, j, run; |
|
|
|
int code, component; |
|
|
|
int component; |
|
|
|
RLTable *rl = &rl_mpeg1; |
|
|
|
RLTable *rl = &rl_mpeg1; |
|
|
|
UINT8 * const scantable= s->intra_scantable.permutated; |
|
|
|
UINT8 * const scantable= s->intra_scantable.permutated; |
|
|
|
|
|
|
|
const UINT16 *quant_matrix= s->intra_matrix; |
|
|
|
|
|
|
|
const int qscale= s->qscale; |
|
|
|
|
|
|
|
|
|
|
|
if (s->mb_intra) { |
|
|
|
|
|
|
|
/* DC coef */ |
|
|
|
/* DC coef */ |
|
|
|
component = (n <= 3 ? 0 : n - 4 + 1); |
|
|
|
component = (n <= 3 ? 0 : n - 4 + 1); |
|
|
|
diff = decode_dc(s, component); |
|
|
|
diff = decode_dc(s, component); |
|
|
@ -1036,60 +1045,136 @@ static int mpeg1_decode_block(MpegEncContext *s, |
|
|
|
dc = s->last_dc[component]; |
|
|
|
dc = s->last_dc[component]; |
|
|
|
dc += diff; |
|
|
|
dc += diff; |
|
|
|
s->last_dc[component] = dc; |
|
|
|
s->last_dc[component] = dc; |
|
|
|
block[0] = dc; |
|
|
|
block[0] = dc<<3; |
|
|
|
dprintf("dc=%d diff=%d\n", dc, diff); |
|
|
|
dprintf("dc=%d diff=%d\n", dc, diff); |
|
|
|
i = 1; |
|
|
|
i = 0; |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
OPEN_READER(re, &s->gb);
|
|
|
|
|
|
|
|
/* now quantify & encode AC coefs */ |
|
|
|
|
|
|
|
for(;;) { |
|
|
|
|
|
|
|
UPDATE_CACHE(re, &s->gb); |
|
|
|
|
|
|
|
GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(level == 127){ |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} else if(level != 0) { |
|
|
|
|
|
|
|
i += run; |
|
|
|
|
|
|
|
j = scantable[i]; |
|
|
|
|
|
|
|
level= (level*qscale*quant_matrix[j])>>3; |
|
|
|
|
|
|
|
level= (level-1)|1; |
|
|
|
|
|
|
|
level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1); |
|
|
|
|
|
|
|
LAST_SKIP_BITS(re, &s->gb, 1); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
|
|
|
|
/* escape */ |
|
|
|
|
|
|
|
run = SHOW_UBITS(re, &s->gb, 6)+1; LAST_SKIP_BITS(re, &s->gb, 6); |
|
|
|
|
|
|
|
UPDATE_CACHE(re, &s->gb); |
|
|
|
|
|
|
|
level = SHOW_SBITS(re, &s->gb, 8); SKIP_BITS(re, &s->gb, 8); |
|
|
|
|
|
|
|
if (level == -128) { |
|
|
|
|
|
|
|
level = SHOW_UBITS(re, &s->gb, 8) - 256; LAST_SKIP_BITS(re, &s->gb, 8); |
|
|
|
|
|
|
|
} else if (level == 0) { |
|
|
|
|
|
|
|
level = SHOW_UBITS(re, &s->gb, 8) ; LAST_SKIP_BITS(re, &s->gb, 8); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
i += run; |
|
|
|
|
|
|
|
j = scantable[i]; |
|
|
|
|
|
|
|
if(level<0){ |
|
|
|
|
|
|
|
level= -level; |
|
|
|
|
|
|
|
level= (level*qscale*quant_matrix[j])>>3; |
|
|
|
|
|
|
|
level= (level-1)|1; |
|
|
|
|
|
|
|
level= -level; |
|
|
|
|
|
|
|
}else{ |
|
|
|
|
|
|
|
level= (level*qscale*quant_matrix[j])>>3; |
|
|
|
|
|
|
|
level= (level-1)|1; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (i > 63){ |
|
|
|
|
|
|
|
fprintf(stderr, "ac-tex damaged at %d %d\n", s->mb_x, s->mb_y); |
|
|
|
|
|
|
|
return -1; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
block[j] = level; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
CLOSE_READER(re, &s->gb); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
s->block_last_index[n] = i; |
|
|
|
|
|
|
|
return 0; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static inline int mpeg1_decode_block_inter(MpegEncContext *s,
|
|
|
|
|
|
|
|
DCTELEM *block,
|
|
|
|
|
|
|
|
int n) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
int level, i, j, run; |
|
|
|
|
|
|
|
RLTable *rl = &rl_mpeg1; |
|
|
|
|
|
|
|
UINT8 * const scantable= s->intra_scantable.permutated; |
|
|
|
|
|
|
|
const UINT16 *quant_matrix= s->inter_matrix; |
|
|
|
|
|
|
|
const int qscale= s->qscale; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
{ |
|
|
|
int v; |
|
|
|
int v; |
|
|
|
OPEN_READER(re, &s->gb); |
|
|
|
OPEN_READER(re, &s->gb); |
|
|
|
i = 0; |
|
|
|
i = -1; |
|
|
|
/* special case for the first coef. no need to add a second vlc table */ |
|
|
|
/* special case for the first coef. no need to add a second vlc table */ |
|
|
|
UPDATE_CACHE(re, &s->gb); |
|
|
|
UPDATE_CACHE(re, &s->gb); |
|
|
|
v= SHOW_UBITS(re, &s->gb, 2); |
|
|
|
v= SHOW_UBITS(re, &s->gb, 2); |
|
|
|
if (v & 2) { |
|
|
|
if (v & 2) { |
|
|
|
run = 0; |
|
|
|
|
|
|
|
level = 1 - ((v & 1) << 1); |
|
|
|
|
|
|
|
SKIP_BITS(re, &s->gb, 2); |
|
|
|
SKIP_BITS(re, &s->gb, 2); |
|
|
|
CLOSE_READER(re, &s->gb); |
|
|
|
level= (3*qscale*quant_matrix[0])>>4; |
|
|
|
goto add_coef; |
|
|
|
level= (level-1)|1; |
|
|
|
|
|
|
|
if(v&1) |
|
|
|
|
|
|
|
level= -level; |
|
|
|
|
|
|
|
block[ scantable[0] ] = level; |
|
|
|
|
|
|
|
i++; |
|
|
|
} |
|
|
|
} |
|
|
|
CLOSE_READER(re, &s->gb); |
|
|
|
CLOSE_READER(re, &s->gb); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
OPEN_READER(re, &s->gb);
|
|
|
|
/* now quantify & encode AC coefs */ |
|
|
|
/* now quantify & encode AC coefs */ |
|
|
|
for(;;) { |
|
|
|
for(;;) { |
|
|
|
code = get_vlc2(&s->gb, rl->vlc.table, TEX_VLC_BITS, 2); |
|
|
|
UPDATE_CACHE(re, &s->gb); |
|
|
|
if (code < 0) { |
|
|
|
GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2); |
|
|
|
return -1; |
|
|
|
|
|
|
|
} |
|
|
|
if(level == 127){ |
|
|
|
if (code == 112) { |
|
|
|
|
|
|
|
break; |
|
|
|
break; |
|
|
|
} else if (code == 111) { |
|
|
|
} else if(level != 0) { |
|
|
|
|
|
|
|
i += run; |
|
|
|
|
|
|
|
j = scantable[i]; |
|
|
|
|
|
|
|
level= ((level*2+1)*qscale*quant_matrix[j])>>4; |
|
|
|
|
|
|
|
level= (level-1)|1; |
|
|
|
|
|
|
|
level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1); |
|
|
|
|
|
|
|
LAST_SKIP_BITS(re, &s->gb, 1); |
|
|
|
|
|
|
|
} else { |
|
|
|
/* escape */ |
|
|
|
/* escape */ |
|
|
|
run = get_bits(&s->gb, 6); |
|
|
|
run = SHOW_UBITS(re, &s->gb, 6)+1; LAST_SKIP_BITS(re, &s->gb, 6); |
|
|
|
level = get_bits(&s->gb, 8); |
|
|
|
UPDATE_CACHE(re, &s->gb); |
|
|
|
level= (level + ((-1)<<7)) ^ ((-1)<<7); //sign extension
|
|
|
|
level = SHOW_SBITS(re, &s->gb, 8); SKIP_BITS(re, &s->gb, 8); |
|
|
|
if (level == -128) { |
|
|
|
if (level == -128) { |
|
|
|
level = get_bits(&s->gb, 8) - 256; |
|
|
|
level = SHOW_UBITS(re, &s->gb, 8) - 256; LAST_SKIP_BITS(re, &s->gb, 8); |
|
|
|
} else if (level == 0) { |
|
|
|
} else if (level == 0) { |
|
|
|
level = get_bits(&s->gb, 8); |
|
|
|
level = SHOW_UBITS(re, &s->gb, 8) ; LAST_SKIP_BITS(re, &s->gb, 8); |
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
run = rl->table_run[code]; |
|
|
|
|
|
|
|
level = rl->table_level[code]; |
|
|
|
|
|
|
|
if (get_bits1(&s->gb)) |
|
|
|
|
|
|
|
level = -level; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
i += run; |
|
|
|
i += run; |
|
|
|
if (i >= 64) |
|
|
|
|
|
|
|
return -1; |
|
|
|
|
|
|
|
add_coef: |
|
|
|
|
|
|
|
dprintf("%d: run=%d level=%d\n", n, run, level); |
|
|
|
|
|
|
|
j = scantable[i]; |
|
|
|
j = scantable[i]; |
|
|
|
|
|
|
|
if(level<0){ |
|
|
|
|
|
|
|
level= -level; |
|
|
|
|
|
|
|
level= ((level*2+1)*qscale*quant_matrix[j])>>4; |
|
|
|
|
|
|
|
level= (level-1)|1; |
|
|
|
|
|
|
|
level= -level; |
|
|
|
|
|
|
|
}else{ |
|
|
|
|
|
|
|
level= ((level*2+1)*qscale*quant_matrix[j])>>4; |
|
|
|
|
|
|
|
level= (level-1)|1; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (i > 63){ |
|
|
|
|
|
|
|
fprintf(stderr, "ac-tex damaged at %d %d\n", s->mb_x, s->mb_y); |
|
|
|
|
|
|
|
return -1; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
block[j] = level; |
|
|
|
block[j] = level; |
|
|
|
i++; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
s->block_last_index[n] = i-1; |
|
|
|
CLOSE_READER(re, &s->gb); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
s->block_last_index[n] = i; |
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|