📄 adjustoutput.c
字号:
/*
Implementation of CCSDS 122.0-B-1 Recommended Standard
Please note:
(1) Before you download and use the program, you must read and agree the license agreement carefully.
(2) We supply the source code and program WITHOUT ANY WARRANTIES. The users will be responsible
for any loses or damages caused by the use of the source code and the program.
Author:
Hongqiang Wang
Department of Electrical Engineering
University of Nebraska-Lincoln
Email: hqwang@bigred.unl.edu, hqwang@eecomm.unl.edu
Your comment and suggestions are welcome. Please report bugs to me via email and I would greatly appreciate it.
Jan. 21, 2007
*/
#include <math.h>
#include "global.h"
extern long DeConvTwosComp(DWORD32 complement, short leftmost);
void AdjustOutPut(StructCodingPara * PtrCoding, BitPlaneBits * BlockCodingInfo)// need to adjust the output
{
int i = 0;
int m = 0;
int n = 0;
int b_DC= 0;
short beta_1 = 0;
short beta_2 = 0;
float refinement = 0;
DWORD32 BitPlaneCheck = 0; // to check if a bit plane has bit 1.
int TotalBlocks = (int)PtrCoding->PtrHeader->Header.Part3.S_20Bits;
// determine the stages to do the decoding process.
if (PtrCoding->PtrHeader->Header.Part4.DWTType != INTEGER_WAVELET)
{
for ( i = 0; i < TotalBlocks; i ++)
for ( m = 0; m < 8; m++)
for ( n = 0; n < 8; n ++)
BlockCodingInfo[i].PtrBlockAddressFloating[m][n] = (float) BlockCodingInfo[i].PtrBlockAddress[m][n] ;
}
for ( i = 0; i < TotalBlocks; i ++)
{
*(*BlockCodingInfo[i].PtrBlockAddress) = DeConvTwosComp((DWORD32)(BlockCodingInfo[i].ShiftedDC + BlockCodingInfo[i].DecodingDCRemainder),
PtrCoding->PtrHeader->Header.Part1.BitDepthDC_5Bits);
*(*BlockCodingInfo[i].PtrBlockAddressFloating) = (float) (*(*BlockCodingInfo[i].PtrBlockAddress));
}
if((PtrCoding->RateReached == TRUE) &&
(PtrCoding->DecodingStopLocations.BlockNoStopDecoding != -1)
&&(PtrCoding->DecodingStopLocations.BitPlaneStopDecoding != -1))
{
// adjust DC and AC componets.
// integer and floating wavelet, we have two differenet strategies.
// decoder up to the block.
if (PtrCoding->DecodingStopLocations.BitPlaneStopDecoding <= PtrCoding->QuantizationFactorQ)
b_DC = PtrCoding->DecodingStopLocations.BitPlaneStopDecoding;
else
b_DC = PtrCoding->QuantizationFactorQ;
if (PtrCoding->PtrHeader->Header.Part4.DWTType == INTEGER_WAVELET)
// first adjust DC component.
{
if (b_DC >= 1)
for( i = 0; i < TotalBlocks; i ++)
*(*BlockCodingInfo[i].PtrBlockAddress) += (1 << (b_DC - 1));
if(PtrCoding->DecodingStopLocations.BitPlaneStopDecoding >= 1)
{
beta_1 = (1 << ( PtrCoding->DecodingStopLocations.BitPlaneStopDecoding - 1)) - 1;
beta_2 = (1 << ( PtrCoding->DecodingStopLocations.BitPlaneStopDecoding )) - 1;
}
else
{
beta_1 = 0;
beta_2 = 0;
}
BitPlaneCheck = 1 << PtrCoding->DecodingStopLocations.BitPlaneStopDecoding;
if (PtrCoding->DecodingStopLocations.stoppedstage == 1) // only stopped at parents. using beta_2 for all children and grandchildren.
{
for (i = 0; i < TotalBlocks; i ++)
{
if (i < PtrCoding->DecodingStopLocations.BlockNoStopDecoding)
{
refinement = beta_1;
}
else if (i > PtrCoding->DecodingStopLocations.BlockNoStopDecoding)
{
refinement = beta_2;
}
for(m = 0; m < 8; m++)
for(n = 0; n < 8; n++)
{
if ((m == 0 && n == 0) || (BlockCodingInfo[i].PtrBlockAddress[m][n] == 0))
continue;
if (m > 1 || n > 1) //grandchildren and grandchildren
{
if(BlockCodingInfo[i].PtrBlockAddress[m][n] > 0)
BlockCodingInfo[i].PtrBlockAddress[m][n] += beta_2;
else if(BlockCodingInfo[i].PtrBlockAddress[m][n] < 0)
BlockCodingInfo[i].PtrBlockAddress[m][n] -= beta_2;
if(BlockCodingInfo[i].PtrBlockAddressFloating[m][n] > 0)
BlockCodingInfo[i].PtrBlockAddressFloating[m][n] += beta_2;
else if(BlockCodingInfo[i].PtrBlockAddressFloating[m][n] < 0)
BlockCodingInfo[i].PtrBlockAddressFloating[m][n] -= beta_2;
}
else //parent
{
if (i < PtrCoding->DecodingStopLocations.BlockNoStopDecoding)
{
// have to make a decision if the pixels is newly selected at this stage.
// If it is, then add the beta1,
// else because the refinement bits have not yet decoded, add beta2
if ((DWORD32) abs(BlockCodingInfo[i].PtrBlockAddress[m][n]) > BitPlaneCheck) // not newly selected.
refinement = beta_2;
else
refinement = beta_1;
if(BlockCodingInfo[i].PtrBlockAddress[m][n] > 0)
BlockCodingInfo[i].PtrBlockAddress[m][n] += (int) refinement;
else if(BlockCodingInfo[i].PtrBlockAddress[m][n] < 0)
BlockCodingInfo[i].PtrBlockAddress[m][n] -= (int) refinement;
if(BlockCodingInfo[i].PtrBlockAddressFloating[m][n] > 0)
BlockCodingInfo[i].PtrBlockAddressFloating[m][n] += refinement;
else if(BlockCodingInfo[i].PtrBlockAddressFloating[m][n] < 0)
BlockCodingInfo[i].PtrBlockAddressFloating[m][n] -= refinement;
}
else if (i > PtrCoding->DecodingStopLocations.BlockNoStopDecoding)
{
// have to make a decision if the pixels is newly selected at this stage.
// If it is, then add the beta1,
// else because the refinement bits have not yet decoded, add beta2
refinement = beta_2;
if(BlockCodingInfo[i].PtrBlockAddress[m][n] > 0)
BlockCodingInfo[i].PtrBlockAddress[m][n] += (int) refinement;
else if(BlockCodingInfo[i].PtrBlockAddress[m][n] < 0)
BlockCodingInfo[i].PtrBlockAddress[m][n] -= (int) refinement;
if(BlockCodingInfo[i].PtrBlockAddressFloating[m][n] > 0)
BlockCodingInfo[i].PtrBlockAddressFloating[m][n] += refinement;
else if(BlockCodingInfo[i].PtrBlockAddressFloating[m][n] < 0)
BlockCodingInfo[i].PtrBlockAddressFloating[m][n] -= refinement;
}
else // current block
{
if((m <= PtrCoding->DecodingStopLocations.X_LocationStopDecoding) &&
(n <= PtrCoding->DecodingStopLocations.Y_LocationStopDecoding ))
{
if ((DWORD32) abs(BlockCodingInfo[i].PtrBlockAddress[m][n]) > BitPlaneCheck) // not newly selected.
refinement = beta_2;
else
refinement = beta_1;
if(BlockCodingInfo[i].PtrBlockAddress[m][n] > 0)
BlockCodingInfo[i].PtrBlockAddress[m][n] += (int) refinement;
else if(BlockCodingInfo[i].PtrBlockAddress[m][n] < 0)
BlockCodingInfo[i].PtrBlockAddress[m][n] -= (int) refinement;
if(BlockCodingInfo[i].PtrBlockAddressFloating[m][n] > 0)
BlockCodingInfo[i].PtrBlockAddressFloating[m][n] += refinement;
else if(BlockCodingInfo[i].PtrBlockAddressFloating[m][n] < 0)
BlockCodingInfo[i].PtrBlockAddressFloating[m][n] -= refinement;
}
else if (( PtrCoding->DecodingStopLocations.X_LocationStopDecoding == 1)
&& ( PtrCoding->DecodingStopLocations.Y_LocationStopDecoding == 0))
{
if ((DWORD32) abs(BlockCodingInfo[i].PtrBlockAddress[m][n]) > BitPlaneCheck) // not newly selected.
refinement = beta_2;
else
refinement = beta_1;
if(BlockCodingInfo[i].PtrBlockAddress[m][n] > 0)
BlockCodingInfo[i].PtrBlockAddress[m][n] += (int) refinement;
else if(BlockCodingInfo[i].PtrBlockAddress[m][n] < 0)
BlockCodingInfo[i].PtrBlockAddress[m][n] -= (int) refinement;
if(BlockCodingInfo[i].PtrBlockAddressFloating[m][n] > 0)
BlockCodingInfo[i].PtrBlockAddressFloating[m][n] += refinement;
else if(BlockCodingInfo[i].PtrBlockAddressFloating[m][n] < 0)
BlockCodingInfo[i].PtrBlockAddressFloating[m][n] -= refinement;
}
else
{
if(BlockCodingInfo[i].PtrBlockAddress[m][n] > 0)
BlockCodingInfo[i].PtrBlockAddress[m][n] += beta_2;
else if(BlockCodingInfo[i].PtrBlockAddress[m][n] < 0)
BlockCodingInfo[i].PtrBlockAddress[m][n] -= beta_2;
if(BlockCodingInfo[i].PtrBlockAddressFloating[m][n] > 0)
BlockCodingInfo[i].PtrBlockAddressFloating[m][n] += beta_2;
else if(BlockCodingInfo[i].PtrBlockAddressFloating[m][n] < 0)
BlockCodingInfo[i].PtrBlockAddressFloating[m][n] -= beta_2;
}
}
}
}
}
}
else if (PtrCoding->DecodingStopLocations.stoppedstage == 2) // only stopped at children. using beta2 for all and grandchildren and beta 1
// for all parents.
{
for (i = 0; i < TotalBlocks; i ++)
{
for(m = 0; m < 8; m++)
for(n = 0; n < 8; n++)
{
if ((m == 0 && n == 0) || (BlockCodingInfo[i].PtrBlockAddress[m][n] == 0))
continue;
if ((m > 3 || n >3))
{
if(BlockCodingInfo[i].PtrBlockAddress[m][n] > 0)
BlockCodingInfo[i].PtrBlockAddress[m][n] += beta_2;
else if(BlockCodingInfo[i].PtrBlockAddress[m][n] < 0)
BlockCodingInfo[i].PtrBlockAddress[m][n] -= beta_2;
if(BlockCodingInfo[i].PtrBlockAddressFloating[m][n] > 0)
BlockCodingInfo[i].PtrBlockAddressFloating[m][n] += beta_2;
else if(BlockCodingInfo[i].PtrBlockAddressFloating[m][n] < 0)
BlockCodingInfo[i].PtrBlockAddressFloating[m][n] -= beta_2;
}
else if ((m <= 1) && (n <= 1)) //parent and grandchildren //parent
{
if ((DWORD32) abs(BlockCodingInfo[i].PtrBlockAddress[m][n]) > BitPlaneCheck) // not newly selected.
refinement = beta_2;
else
refinement = beta_1;
if(BlockCodingInfo[i].PtrBlockAddress[m][n] > 0)
BlockCodingInfo[i].PtrBlockAddress[m][n] += (int) refinement;
else if(BlockCodingInfo[i].PtrBlockAddress[m][n] < 0)
BlockCodingInfo[i].PtrBlockAddress[m][n] -= (int) refinement;
if(BlockCodingInfo[i].PtrBlockAddressFloating[m][n] > 0)
BlockCodingInfo[i].PtrBlockAddressFloating[m][n] += refinement;
else if(BlockCodingInfo[i].PtrBlockAddressFloating[m][n] < 0)
BlockCodingInfo[i].PtrBlockAddressFloating[m][n] -= refinement;
}
else
{
if (i< PtrCoding->DecodingStopLocations.BlockNoStopDecoding)
{
if ((DWORD32) abs(BlockCodingInfo[i].PtrBlockAddress[m][n]) > BitPlaneCheck) // not newly selected.
refinement = beta_2;
else
refinement = beta_1;
if(BlockCodingInfo[i].PtrBlockAddress[m][n] > 0)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -