📄 ezw3.c
字号:
CSigContextUpdate(coder, i, x, y, n);
}
*LastScanSig = 1;
}
}
if (s==_PS_ || s==_NG_){
// send to LSP
Data = CreateData(i, x, y, (char)n);
DListAppend(&coder->LSP, Data);
}
//-----------------------------------------
// update the counts
if (s==_PS_){
coder->nPS++;
}
else if (s==_NG_){
coder->nNG++;
}
else if (s==_IZ_){
coder->nIZ++;
}
else{
coder->nZS++;
}
//-----------------------------------------
}
else{
*LastScanSig = sig;
}
return 0;
}
/*--------------------------------------------------------------------------------------------*/
int SortingPassVerticalScan(Coder *coder, int n)
{
int x, y;
int LastScanSig;
LastScanSig = 0;
for (x=0; x<coder->SubbandXSize[n]; x++){
if (x%2){
for (y=coder->SubbandYSize[n]-1; y>=0; y--){
if (ProcessNode(coder, n, x, y, &LastScanSig)){
return 1;
}
}
}
else{
for (y=0; y<coder->SubbandYSize[n]; y++){
if (ProcessNode(coder, n, x, y, &LastScanSig)){
return 1;
}
}
}
}
return 0;
}
/*--------------------------------------------------------------------------------------------*/
int SortingPassHorizontalScan(Coder *coder, int n)
{
int x, y;
int LastScanSig;
LastScanSig = 0;
for (y=0; y<coder->SubbandYSize[n]; y++){
if (y%2){
for (x=coder->SubbandXSize[n]-1; x>=0; x--){
if (ProcessNode(coder, n, x, y, &LastScanSig)){
return 1;
}
}
}
else{
for (x=0; x<coder->SubbandXSize[n]; x++){
if (ProcessNode(coder, n, x, y, &LastScanSig)){
return 1;
}
}
}
}
return 0;
}
/*--------------------------------------------------------------------------------------------*/
int HilbertScan(Coder *coder, int level, int scan, int n,
int *x, int *y, int *LastScanSig)
{
switch (scan){
case RS:
if (level<2){
if (ProcessNode(coder, n, *x, *y, LastScanSig)){
return 1;
}
MoveRight(x, y);
if (ProcessNode(coder, n, *x, *y, LastScanSig)){
return 1;
}
MoveDown(x, y);
if (ProcessNode(coder, n, *x, *y, LastScanSig)){
return 1;
}
MoveLeft(x, y);
if (ProcessNode(coder, n, *x, *y, LastScanSig)){
return 1;
}
}
else{
if (HilbertScan(coder, level-1, DS, n, x, y, LastScanSig)){
return 1;
}
MoveRight(x, y);
if (HilbertScan(coder, level-1, RS, n, x, y, LastScanSig)){
return 1;
}
MoveDown(x, y);
if (HilbertScan(coder, level-1, RS, n, x, y, LastScanSig)){
return 1;
}
MoveLeft(x, y);
if (HilbertScan(coder, level-1, US, n, x, y, LastScanSig)){
return 1;
}
}
break;
case LS:
if (level<2){
if (ProcessNode(coder, n, *x, *y, LastScanSig)){
return 1;
}
MoveLeft(x, y);
if (ProcessNode(coder, n, *x, *y, LastScanSig)){
return 1;
}
MoveUp(x, y);
if (ProcessNode(coder, n, *x, *y, LastScanSig)){
return 1;
}
MoveRight(x, y);
if (ProcessNode(coder, n, *x, *y, LastScanSig)){
return 1;
}
}
else{
if (HilbertScan(coder, level-1, US, n, x, y, LastScanSig)){
return 1;
}
MoveLeft(x, y);
if (HilbertScan(coder, level-1, LS, n, x, y, LastScanSig)){
return 1;
}
MoveUp(x, y);
if (HilbertScan(coder, level-1, LS, n, x, y, LastScanSig)){
return 1;
}
MoveRight(x, y);
if (HilbertScan(coder, level-1, DS, n, x, y, LastScanSig)){
return 1;
}
}
break;
case US:
if (level<2){
if (ProcessNode(coder, n, *x, *y, LastScanSig)){
return 1;
}
MoveUp(x, y);
if (ProcessNode(coder, n, *x, *y, LastScanSig)){
return 1;
}
MoveLeft(x, y);
if (ProcessNode(coder, n, *x, *y, LastScanSig)){
return 1;
}
MoveDown(x, y);
if (ProcessNode(coder, n, *x, *y, LastScanSig)){
return 1;
}
}
else{
if (HilbertScan(coder, level-1, LS, n, x, y, LastScanSig)){
return 1;
}
MoveUp(x, y);
if (HilbertScan(coder, level-1, US, n, x, y, LastScanSig)){
return 1;
}
MoveLeft(x, y);
if (HilbertScan(coder, level-1, US, n, x, y, LastScanSig)){
return 1;
}
MoveDown(x, y);
if (HilbertScan(coder, level-1, RS, n, x, y, LastScanSig)){
return 1;
}
}
break;
case DS:
if (level<2){
if (ProcessNode(coder, n, *x, *y, LastScanSig)){
return 1;
}
MoveDown(x, y);
if (ProcessNode(coder, n, *x, *y, LastScanSig)){
return 1;
}
MoveRight(x, y);
if (ProcessNode(coder, n, *x, *y, LastScanSig)){
return 1;
}
MoveUp(x, y);
if (ProcessNode(coder, n, *x, *y, LastScanSig)){
return 1;
}
}
else{
if (HilbertScan(coder, level-1, RS, n, x, y, LastScanSig)){
return 1;
}
MoveDown(x, y);
if (HilbertScan(coder, level-1, DS, n, x, y, LastScanSig)){
return 1;
}
MoveRight(x, y);
if (HilbertScan(coder, level-1, DS, n, x, y, LastScanSig)){
return 1;
}
MoveUp(x, y);
if (HilbertScan(coder, level-1, LS, n, x, y, LastScanSig)){
return 1;
}
}
break;
default:
Error("Scan direction is not defined.\n");
}
return 0;
}
/*--------------------------------------------------------------------------------------------*/
int SortingPassHilbertScan(Coder *coder, int n)
{
int x, y, level;
int LastScanSig;
LastScanSig = 0;
// determine the level
level = Log2((coder->SubbandXSize[n] >= coder->SubbandYSize[n] ?
coder->SubbandXSize[n]-1 : coder->SubbandYSize[n]-1))+1;
// first point
x = 0;
y = 0;
LastScanSig = 0;
HilbertScan(coder, level, ((level%2)? RS : DS), n, &x, &y, &LastScanSig);
return 0;
}
/*--------------------------------------------------------------------------------------------*/
int SortingPass(Coder *coder)
{
int n, c[nSSigModel], i;
int (*LLScan)(Coder *, int);
int (*HLScan)(Coder *, int);
int (*LHScan)(Coder *, int);
int (*HHScan)(Coder *, int);
//---------------------------------------------------------------------
LLScan = SortingPassHilbertScan;
HLScan = SortingPassVerticalScan;
LHScan = SortingPassHorizontalScan;
HHScan = SortingPassHilbertScan;
// LL
if (LLScan(coder, 0)){
return 1;
}
for (n=1; n<coder->nSubbands; n+=3){
#if (_MERGE_NODE_CONTEXT_)
if (n==coder->nSubbands-3){
// combine the IZ and SZ symbols count
for (i=0; i<nSSigModel; i++){
c[i] = HistoGetProb(coder->SSigModel[0][i], _IZ_);
HistoPutValue(coder->SSigModel[0][i], -c[i], _IZ_);
}
}
#endif
// HL
if (HLScan(coder, n)){
return 1;
}
// LH
if (LHScan(coder, n+1)){
return 1;
}
// HH
if (HHScan(coder, n+2)){
return 1;
}
}
#if (_MERGE_NODE_CONTEXT_)
// combine the IZ and SZ symbols count
for (i=0; i<nSSigModel; i++){
HistoPutValue(coder->SSigModel[0][i], c[i], _IZ_);
}
#endif
return 0;
}
/*--------------------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------------------*/
#if _REFINEMENT_SAME_PASS_
/*--------------------------------------------------------------------------------------------*/
/* The newly significant coefficients are refined in this pass */
int RefinementPass(Coder *coder)
{
ListData *Data;
DListElement *current, *next;
int bitn, sign;
int Thres = coder->CurrentThreshold>>1;
if (coder->CurrentThreshold==0){
// no code, as the last bit has been coded in SortingPass
return 0;
}
if (coder->TestFullBitPlane && (coder->CurrentBitPlane==coder->LastFullBitPlane)){
return 0;
}
current = DListHead(&coder->LSP);
while(current != NULL){
Data = (ListData *)current->data;
assert(CHKBIT(coder->State[Data->n][Data->i], CSIG_CTX_BIT));
if (coder->Mode == ENCODE){
bitn = (coder->Magnitude[Data->n][Data->i] & Thres);
bitn = (bitn == 0? 0 : 1);
#if _MERGE_REFI_CONTEXT_
if (WriteSymbol(coder, coder->RefiModel[0][0], bitn)){
return 1;
}
#else
if (WriteSymbol(coder, coder->RefiModel[Data->n][0], bitn)){
return 1;
}
#endif
coder->nRF++;
}
else{
#if _MERGE_REFI_CONTEXT_
if(ReadSymbol(coder, coder->RefiModel[0][0], &bitn)){
return 1;
}
#else
if(ReadSymbol(coder, coder->RefiModel[Data->n][0], &bitn)){
return 1;
}
#endif
coder->nRF++;
/* compute the refined index */
coder->Magnitude[Data->n][Data->i] <<= 1;
coder->Magnitude[Data->n][Data->i] += bitn;
sign = (CHKBIT(coder->State[Data->n][Data->i], SIGN_CTX_BIT) ? 1 : -1);
coder->dwt->SubbandPtr[Data->n][Data->i]
= sign*(Real)Dequantize(coder->Magnitude[Data->n][Data->i],
Thres, GAMMA);
}
current = current->next; /* move on to next node */
}
return 0;
}
/*--------------------------------------------------------------------------------------------*/
#else
/*--------------------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------------------*/
int RefinementPass(Coder *coder)
{
ListData *Data;
DListElement *current, *next;
int bitn, sign;
int p, lp;
current = DListHead(&coder->LSP);
lp = coder->MaxBitPlane - coder->CurrentBitPlane;
for (p=0; p<lp; p++){
while(current != coder->RefinementMark[p]->next){
Data = (ListData *)current->data;
assert(CHKBIT(coder->State[Data->n][Data->i], CSIG_CTX_BIT));
if (coder->Mode == ENCODE){
bitn = (coder->Magnitude[Data->n][Data->i] & coder->CurrentThreshold);
bitn = (bitn == 0? 0 : 1);
#if _MERGE_REFI_CONTEXT_
if (WriteSymbol(coder, coder->RefiModel[0][0], bitn)){
return 1;
}
#else
if (WriteSymbol(coder, coder->RefiModel[Data->n][0], bitn)){
return 1;
}
#endif
}
else{
#if _MERGE_REFI_CONTEXT_
if(ReadSymbol(coder, coder->RefiModel[0][0], &bitn)){
return 1;
}
#else
if(ReadSymbol(coder, coder->RefiModel[Data->n][0], &bitn)){
return 1;
}
#endif
/* compute the refined index */
coder->Magnitude[Data->n][Data->i] <<= 1;
coder->Magnitude[Data->n][Data->i] += bitn;
sign = (CHKBIT(coder->State[Data->n][Data->i], SIGN_CTX_BIT) ? 1 : -1);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -