📄 arith_decoder_jpeg2000.asm
字号:
/*******************************************************************************
Copyright(c) 2000 - 2002 Analog Devices. All Rights Reserved.
Developed by Joint Development Software Application Team, IPDC, Bangalore, India
for Blackfin DSPs ( Micro Signal Architecture 1.0 specification).
By using this module you agree to the terms of the Analog Devices License
Agreement for DSP Software.
********************************************************************************
Module Name : arith_decoder_JPEG2000.asm
Label Name : __arith_decoder_JPEG2000
Version : 2.0
Change History :
Version Date Author Comments
2.0 01/09/2007 Arjun Tested with VDSP++4.5
Compiler 7.2.3.2
1.3 11/18/2002 Swarnalatha Tested with VDSP++ 3.0
compiler 6.2.2 on
ADSP-21535 Rev.0.2
1.2 11/13/2002 Swarnalatha Tested with VDSP++ 3.0
on ADSP-21535 Rev. 0.2
1.1 03/20/2002 Raghavendra Modified to match
silicon cycle count
1.0 08/29/2001 Raghavendra Original
Description : The compressed data CD and contexts are supplied to decoder
and output will be a decision bit D either 0 or 1. The encoder
and decoder must use same set of contexts to get proper
result.
Docoder decodes one binary decision at a time. After decoding
the decision, decoder subtracts any amount from the compressed
data that the encoder added.
The following structures are used for arithmetic decoding.
1.
struct mqdec
{
int A; -> interval register (range:0,75 <=A<1,5)
int C; -> code register
int CT; -> bit counter register
int B; -> byte value
unsigned char *input; -> array where compressed
data to be read
unsigned char *out; -> array where output is
stored
}dec_reg;
2. struct contexts
{
int index; -> index to probability estimation table
int mps; -> MPS value for particular context.
} contexts[18]; -> array of contexts( 18 for JPEG 2000)
3. struct mqstates
{
int Qe; -> value of probability of LPS
int NMPS; -> Next index when MPS is coded
int NLPS; -> Next index when LPS is coded
int SWITCH; -> To change mps value when LPS is coded
}mqstates_s[47];
Assumptions : 1. mqstate_s[47] table and struct mq_enc variable are in
different banks.
2. mqstates_s[47] is initialized with probability values as
specified in Table C-2 of Annex-C,ISO/IEC FCD15444-1:2000
(V1.0,16 March 2000)
3. Index and MPS values for each context is initialized before
starting encoder.
Note : Two 0xFF appended at the end of input bitstream for
testing purpose(refer Annex D, section D.4.1 of ISO/IEC
FCD15444-1:2000(V1.0,16 March 2000).
Prototypes : void arith_decode_init(struct mqdec *, unsigned char *input ,
unsigned char *output);
void arith_decoder_JPEG2000(unsigned char CX,struct mqdec *,
struct mqstates *,struct contexts*);
void arith_decode_renorme(struct mqdec*);
void arith_decode_bytein(struct mqdec*);
Calling sequence : Arith_decode_init function is called for initialization.
arith_decoder_JPEG2000 function is called for each context.
C implementation of calling sequence is explained below.
main() or func()
{
int i;
struct enc_reg mq_enc;
.
.
.
arith_decode_init(&mq_enc,&arrayOut[0]);
for(i=0;i<NUMBER_OF_CONTEXT;i++)
{
CX=context_input[i];
arith_decoder_JPEG2000(CX, *mq_enc, mqstates,contexts);
}
.
.
}
Performance :
Code Size :
arith_decode_init : 68 bytes
arith_decode_bytein : 104 bytes
arith_decode_renorme : 64 bytes
arith_decoder_JPEG2000 : 228 bytes
Best case Worst case
Cycle count : arith_decode_init : 46 46 cycles
arith_decoder_JPEG2000 : 42 201 cycles
Cycle count mentioned is for a particular input sequence.
As the algorithm is data dependant, Cycle count may vary.
For e.g ,Cycle count for 5760 output symbols which take
23 bytes as input is 288161 (i.e 46.61 cycles per output
symbol).
Reference : Annex - C Arithmetic entropy encoding (JPEG-2000)
ISO/IEC FCD15444-1:2000(V1.0,16 March 2000)
Registers used : R0-R3, R6, R7, I0, M0, L0, P0-P2, P5.
*******************************************************************************/
.section L1_code;
.global __arith_decoder_JPEG2000;
.align 8;
__arith_decoder_JPEG2000:
R0 = R0 << 3;
P2 = [SP+12];
P0 = R0; // Offset to fetch current context
// Address of contexts
L0 = 0;
I0 = R2; // address of mqstates values
[--SP] = P5;
P5 = R1; // address of structure mqdec
P0 = P2+P0; // Point to current context
R2 = [P0++]; // get index value from current context
R2 = R2 << 4;
R3 = [P0--];
// get MPS value of current context
M0 = R2;
[--SP] = (R7:6); // Push R7:6
P2 = R1;
[--SP] = RETS; // Push RETS reg
R2 = [P5];
R0 = [I0++M0];
// fetch A register, dummy fetch to increment the
// pointer
R1 = R2-R2(NS);
R7 = [I0++];
// clear R1 and fetch Qe value
R2 = R2-R7(NS);
R6 = [P5+4];
// do A-Qe and fetch C register
R1 = PACK(R1.H,R6.H);
NOP; // get C high register value
CC = R1<R7; // compare Chigh < Qe
IF CC JUMP LPS_EXCHANGE;// if true code as LPS-EXCHANGE
R1 = R1-R7(NS); // Chigh = Chigh - Qe
R1 = PACK(R1.L,R6.L);
[P5] = R2;
// store A register value
[P5+4] = R1; // store C register
P1 = [P5+20];
R0 = [I0++];
// address of output array
CC = BITTST(R2,15); // check if a> 0x8000
IF CC JUMP D_EQ_MPS; // if true jump to D_EQ_MPS
/************** MPS_EXCHANGE ********************/
CC = R2<R7; // compare A< QE
IF CC JUMP CHECK_SWITCH;// if true jump to CHECK_SWITCH
B[P1++] = R3; // store output D = = mps(CX)
[P5+20] = P1; // get value NMPS index
[P0++] = R0; // store next index as NMPS value for present
// context
JUMP CALL_RENORME;
CHECK_SWITCH:
R2 = R3 << 0;
R0 = [I0++];
// dummy fetch to increment I0
BITTGL(R2,0); // complement MPS value
R1 = [I0++];
[P0++] = R0;
// store NLPS and fetch SWITCH value
CC = R1 == 1; // check if SWITCH flag is set
R0 = CC;
B[P1++] = R2;
[P5+20] = P1;
R3 = R0^R3; // XOR the result to compliment MPS value if SWITCH
// flag is set
[P0] = R3; // store MPS value
JUMP CALL_RENORME;
D_EQ_MPS:
RETS = [SP++]; // pop RETS register
B[P1++] = R3; // store output bit = mps(CX)
[P5+20] = P1; // store address where next output to be stored
(R7:6) = [SP++];
P5 = [SP++]; // pop R7:6,P5
RTS;
NOP; // To remove stalls occurring on the board
/********************** LPS_EXCHANGE ****************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -