avcodec/mqcdec: Support raw bypass and non reseting init

Some broken code that used the old mqc is removed

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
This commit is contained in:
Michael Niedermayer 2015-06-12 03:02:09 +02:00
parent b395fd3de7
commit eea92133a1
3 changed files with 21 additions and 9 deletions

View File

@ -1135,7 +1135,7 @@ static int decode_cblk(Jpeg2000DecoderContext *s, Jpeg2000CodingStyle *codsty,
cblk->data[cblk->length] = 0xff;
cblk->data[cblk->length+1] = 0xff;
ff_mqc_initdec(&t1->mqc, cblk->data);
ff_mqc_initdec(&t1->mqc, cblk->data, 0, 1);
while (passno--) {
switch(pass_t) {
@ -1146,16 +1146,11 @@ static int decode_cblk(Jpeg2000DecoderContext *s, Jpeg2000CodingStyle *codsty,
break;
case 1:
decode_refpass(t1, width, height, bpno + 1);
if (bpass_csty_symbol && clnpass_cnt >= 4)
ff_mqc_initdec(&t1->mqc, cblk->data);
break;
case 2:
decode_clnpass(s, t1, width, height, bpno + 1, bandpos,
codsty->cblk_style & JPEG2000_CBLK_SEGSYM,
vert_causal_ctx_csty_symbol);
clnpass_cnt = clnpass_cnt + 1;
if (bpass_csty_symbol && clnpass_cnt >= 4)
ff_mqc_initdec(&t1->mqc, cblk->data);
break;
}

View File

@ -43,6 +43,7 @@ typedef struct MqcState {
unsigned int c;
unsigned int ct;
uint8_t cx_states[19];
int raw;
} MqcState;
/* encoder */
@ -65,8 +66,10 @@ int ff_mqc_flush(MqcState *mqc);
* Initialize MQ-decoder.
* @param mqc MQ decoder state
* @param bp byte poiter
* @param raw raw mode
* @param reset reset states
*/
void ff_mqc_initdec(MqcState *mqc, uint8_t *bp);
void ff_mqc_initdec(MqcState *mqc, uint8_t *bp, int raw, int reset);
/**
* MQ decoder.

View File

@ -68,18 +68,32 @@ static int exchange(MqcState *mqc, uint8_t *cxstate, int lps)
return d;
}
void ff_mqc_initdec(MqcState *mqc, uint8_t *bp)
void ff_mqc_initdec(MqcState *mqc, uint8_t *bp, int raw, int reset)
{
if (reset)
ff_mqc_init_contexts(mqc);
mqc->bp = bp;
mqc->c = (*mqc->bp ^ 0xff) << 16;
bytein(mqc);
mqc->c = mqc->c << 7;
mqc->a = 0x8000;
mqc->raw = raw;
}
static int mqc_decode_bypass(MqcState *mqc) {
int bit = !(mqc->c & 0x40000000);
if (!(mqc->c & 0xff)) {
mqc->c -= 0x100;
bytein(mqc);
}
mqc->c += mqc->c;
return bit;
}
int ff_mqc_decode(MqcState *mqc, uint8_t *cxstate)
{
if (mqc->raw)
return mqc_decode_bypass(mqc);
mqc->a -= ff_mqc_qe[*cxstate];
if ((mqc->c >> 16) < mqc->a) {
if (mqc->a & 0x8000)