📄 stagescodinggaggles.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 "global.h"
#include <stdlib.h>
#include <stdio.h>
extern void RiceCoding(short InputVal,
short BitLength,
UCHAR8 *Option,
StructCodingPara *PtrCoding );
extern void BitPlaneSymbolReset(StrSymbolDetails *SymbolStr);
void StagesEnCodingGaggles1(StructCodingPara *PtrCoding,
BitPlaneBits *BlockInfo,
UCHAR8 BlocksInGaggles,
UCHAR8 Option[],
BOOL FlagCodeOptionOutput[] )
{
UCHAR8 SymbolIndex = 0;
DWORD32 BlockSeq = 0;
short i;
short counter= 0;
for ( BlockSeq = 0; BlockSeq <BlocksInGaggles; BlockSeq ++)
{
if (BlockInfo[BlockSeq].BitMaxAC < PtrCoding->BitPlane)
continue;
for(SymbolIndex = 0; SymbolIndex < MAX_SYMBOLS_IN_BLOCK; SymbolIndex ++)
{
if(BlockInfo[BlockSeq].SymbolsBlock[SymbolIndex].type == ENUM_TYPE_P)
{
switch(BlockInfo[BlockSeq].SymbolsBlock[SymbolIndex].sym_len)
{
case 1:
case 2:
case 3:
if (BlockInfo[BlockSeq].SymbolsBlock[SymbolIndex].sym_len > 1)
if(FlagCodeOptionOutput[BlockInfo[BlockSeq].SymbolsBlock[SymbolIndex].sym_len - 2] == FALSE)
{
FlagCodeOptionOutput[BlockInfo[BlockSeq].SymbolsBlock[SymbolIndex].sym_len - 2] = TRUE;
if(BlockInfo[BlockSeq].SymbolsBlock[SymbolIndex].sym_len == 2)
BitsOutput(PtrCoding, Option[0], 1);
else if(BlockInfo[BlockSeq].SymbolsBlock[SymbolIndex].sym_len == 3)
BitsOutput(PtrCoding, Option[1], 2);
else if(BlockInfo[BlockSeq].SymbolsBlock[SymbolIndex].sym_len == 4)
BitsOutput(PtrCoding, Option[2], 2);
else
ErrorMsg(BPE_STAGE_CODING_ERROR);
}
RiceCoding(BlockInfo[BlockSeq].SymbolsBlock[SymbolIndex].sym_mapped_pattern,
BlockInfo[BlockSeq].SymbolsBlock[SymbolIndex].sym_len, Option,
PtrCoding);
counter = 0;
for(i = 0; i < BlockInfo[BlockSeq].SymbolsBlock[SymbolIndex].sym_len; i++)
{
if ((BlockInfo[BlockSeq].SymbolsBlock[SymbolIndex].sym_val & (1 << i)) >0)
counter ++;
}
BitsOutput(PtrCoding, BlockInfo[BlockSeq].SymbolsBlock[SymbolIndex].sign, counter);
BitPlaneSymbolReset(&(BlockInfo[BlockSeq].SymbolsBlock[SymbolIndex])) ;
//reset the entry to zero.
break;
default: ErrorMsg(BPE_STAGE_CODING_ERROR);//"invalid length");
}
}
}
}
if((PtrCoding->PtrHeader->Header.Part1.Part2Flag == TRUE)
&&(PtrCoding->PtrHeader->Header.Part2.StageStop_2Bits == 00))
return;
}
// begin the encoding of TranB+TranD+TypeCi
void StagesEnCodingGaggles2(StructCodingPara *PtrCoding,
BitPlaneBits *BlockInfo,
UCHAR8 BlocksInGaggles,
UCHAR8 Option[],
BOOL FlagCodeOptionOutput[])
{
UCHAR8 SymbolIndex = 0;
DWORD32 BlockSeq = 0;
short i;
short counter= 0;
for ( BlockSeq = 0; BlockSeq < BlocksInGaggles; BlockSeq ++)
{
if (BlockInfo[BlockSeq].BitMaxAC < PtrCoding->BitPlane)
continue;
for(SymbolIndex = 0; SymbolIndex < MAX_SYMBOLS_IN_BLOCK; SymbolIndex ++)
{
switch(BlockInfo[BlockSeq].SymbolsBlock[SymbolIndex].type)
{
case ENUM_TRAN_B:
case ENUM_TRAN_D:
case ENUM_TYPE_CI:
if(BlockInfo[BlockSeq].SymbolsBlock[SymbolIndex].sym_len > 1)
if(FlagCodeOptionOutput[BlockInfo[BlockSeq].SymbolsBlock[SymbolIndex].sym_len - 2] == FALSE)
{
FlagCodeOptionOutput[BlockInfo[BlockSeq].SymbolsBlock[SymbolIndex].sym_len - 2] = TRUE;
if(BlockInfo[BlockSeq].SymbolsBlock[SymbolIndex].sym_len == 2)
BitsOutput(PtrCoding, Option[0], 1);
else if(BlockInfo[BlockSeq].SymbolsBlock[SymbolIndex].sym_len == 3)
BitsOutput(PtrCoding, Option[1], 2);
else if(BlockInfo[BlockSeq].SymbolsBlock[SymbolIndex].sym_len == 4)
BitsOutput(PtrCoding, Option[2], 2);
else
ErrorMsg(BPE_STAGE_CODING_ERROR);
}
RiceCoding(BlockInfo[BlockSeq].SymbolsBlock[SymbolIndex].sym_mapped_pattern ,
BlockInfo[BlockSeq].SymbolsBlock[SymbolIndex].sym_len, Option, PtrCoding);
if (BlockInfo[BlockSeq].SymbolsBlock[SymbolIndex].type == ENUM_TYPE_CI)
{
counter = 0;
for(i = 0; i < BlockInfo[BlockSeq].SymbolsBlock[SymbolIndex].sym_len; i++)
if ((BlockInfo[BlockSeq].SymbolsBlock[SymbolIndex].sym_val & (1 << i)) >0)
counter ++;
BitsOutput(PtrCoding, BlockInfo[BlockSeq].SymbolsBlock[SymbolIndex].sign, counter);
}
BitPlaneSymbolReset(&(BlockInfo[BlockSeq].SymbolsBlock[SymbolIndex])) ;
break;
}
}
}
}
void StagesEnCodingGaggles3(StructCodingPara *PtrCoding,
BitPlaneBits *BlockInfo,
UCHAR8 BlocksInGaggles,
UCHAR8 Option[],
BOOL FlagCodeOptionOutput[])
{
UCHAR8 SymbolIndex = 0;
DWORD32 BlockSeq = 0;
short i;
short counter= 0;
if((PtrCoding->PtrHeader->Header.Part1.Part2Flag == TRUE)
&&(PtrCoding->PtrHeader->Header.Part2.StageStop_2Bits == 01))
return;
for ( BlockSeq = 0; BlockSeq < BlocksInGaggles; BlockSeq ++)
{
if (BlockInfo[BlockSeq].BitMaxAC < PtrCoding->BitPlane)
continue;
for(SymbolIndex = 0; SymbolIndex < MAX_SYMBOLS_IN_BLOCK; SymbolIndex ++)
{
switch(BlockInfo[BlockSeq].SymbolsBlock[SymbolIndex].type)
{ // TranGi+TranHi+TypeHij
case ENUM_TRAN_GI:
case ENUM_TRAN_HI:
case ENUM_TYPE_HIJ:
if (BlockInfo[BlockSeq].SymbolsBlock[SymbolIndex].sym_len > 1)
if(FlagCodeOptionOutput[BlockInfo[BlockSeq].SymbolsBlock[SymbolIndex].sym_len - 2] == FALSE)
{
FlagCodeOptionOutput[BlockInfo[BlockSeq].SymbolsBlock[SymbolIndex].sym_len - 2] = TRUE;
if(BlockInfo[BlockSeq].SymbolsBlock[SymbolIndex].sym_len == 2)
BitsOutput(PtrCoding, Option[0], 1);
else if(BlockInfo[BlockSeq].SymbolsBlock[SymbolIndex].sym_len == 3)
BitsOutput(PtrCoding, Option[1], 2);
else if(BlockInfo[BlockSeq].SymbolsBlock[SymbolIndex].sym_len == 4)
BitsOutput(PtrCoding, Option[2], 2);
else
ErrorMsg(BPE_STAGE_CODING_ERROR);
}
RiceCoding(BlockInfo[BlockSeq].SymbolsBlock[SymbolIndex].sym_mapped_pattern , BlockInfo[BlockSeq].SymbolsBlock[SymbolIndex].sym_len, Option, PtrCoding);
if(BlockInfo[BlockSeq].SymbolsBlock[SymbolIndex].type == ENUM_TYPE_HIJ)
{
counter = 0;
for(i = 0; i < BlockInfo[BlockSeq].SymbolsBlock[SymbolIndex].sym_len; i++)
if ((BlockInfo[BlockSeq].SymbolsBlock[SymbolIndex].sym_val & (1 << i)) >0)
counter ++;
BitsOutput(PtrCoding, BlockInfo[BlockSeq].SymbolsBlock[SymbolIndex].sign, counter);
}
BitPlaneSymbolReset(&(BlockInfo[BlockSeq].SymbolsBlock[SymbolIndex])) ;
break;
}
}
}
}
extern void RiceDecoding(DWORD32 *decoded,
short BitLength,
UCHAR8 *splitOption,
StructCodingPara *Ptr);
extern void DeMappingPattern(StrSymbolDetails *StrSymbol);
void StagesDeCodingGaggles1(StructCodingPara *PtrCoding,
BitPlaneBits *BlockCodingInfo,
UCHAR8 BlocksInGaggles,
UCHAR8 *CodeOptionsAllGaggles,
BOOL *FlagCodeOptionOutput)
{
UCHAR8 temp_x;
UCHAR8 temp_y;
UCHAR8 counter;
UCHAR8 BlockSeq;
UCHAR8 RefCounter = 0;
short temp = 1;
int i;
UCHAR8 BitPlane = PtrCoding->BitPlane;
StrSymbolDetails StrSymbol;
for ( BlockSeq = 0; BlockSeq < BlocksInGaggles; BlockSeq ++)
{
if (BlockCodingInfo[BlockSeq].BitMaxAC < BitPlane)
continue;
counter = 0;
RefCounter = 0;
for(i = 0; i < 3; i++)
{
if((PtrCoding->PtrHeader->Header.Part4).DWTType == INTEGER_WAVELET)
{
if(((i == 0) && (PtrCoding->PtrHeader->Header.Part4.CustomWtHL3_2bits >= BitPlane)) || // HL3 band.
((i == 1) && (PtrCoding->PtrHeader->Header.Part4.CustomWtLH3_2bits >= BitPlane)) ||// HL3 band.
((i == 2) && (PtrCoding->PtrHeader->Header.Part4.CustomWtHH3_2bits >= BitPlane))) // HL3 band.
continue;
}
RefCounter ++;
if((BlockCodingInfo[BlockSeq].StrPlaneHitHistory.TypeP & (1 << (2 - i))) == 0)
counter ++;
}
if(RefCounter != 0)
{
if(counter != 0)
{
DWORD32 temp_DWORD;
if(counter != 1)
{
if(FlagCodeOptionOutput[counter - 2] == FALSE)
{
FlagCodeOptionOutput[counter - 2] = TRUE;
if(counter == 2)
{
BitsRead(PtrCoding, &temp_DWORD, 1);
}
else
{
BitsRead(PtrCoding, &temp_DWORD, 2);
}
CodeOptionsAllGaggles[counter - 2] = (UCHAR8) temp_DWORD;
if ((PtrCoding->DecodingStopLocations.BitPlaneStopDecoding != -1)
&& PtrCoding->RateReached == TRUE && !PtrCoding->DecodingStopLocations.LocationFind)
{
PtrCoding->DecodingStopLocations.BlockNoStopDecoding = BlockSeq;
PtrCoding->DecodingStopLocations.X_LocationStopDecoding = 0;
PtrCoding->DecodingStopLocations.Y_LocationStopDecoding = 1;
PtrCoding->DecodingStopLocations.LocationFind = TRUE;
return;
}
}
}
RiceDecoding(&temp_DWORD, counter, CodeOptionsAllGaggles, PtrCoding);
if ((PtrCoding->DecodingStopLocations.BitPlaneStopDecoding != -1)
&& PtrCoding->RateReached == TRUE && !PtrCoding->DecodingStopLocations.LocationFind)
{
PtrCoding->DecodingStopLocations.BlockNoStopDecoding = BlockSeq;
PtrCoding->DecodingStopLocations.X_LocationStopDecoding = 0;
PtrCoding->DecodingStopLocations.Y_LocationStopDecoding = 1;
PtrCoding->DecodingStopLocations.LocationFind = TRUE;
return;
}
StrSymbol.sym_mapped_pattern= (UCHAR8)temp_DWORD;
StrSymbol.sym_len = counter;
StrSymbol.type = ENUM_TYPE_P;
DeMappingPattern(&StrSymbol);
for(i = 0; i < 3; i++)
{
if((PtrCoding->PtrHeader->Header.Part4).DWTType == INTEGER_WAVELET)
{
if(((i == 0) && (PtrCoding->PtrHeader->Header.Part4.CustomWtHL3_2bits >= BitPlane)) || // HL3 band.
((i == 1) && (PtrCoding->PtrHeader->Header.Part4.CustomWtLH3_2bits >= BitPlane)) ||// HL3 band.
((i == 2) && (PtrCoding->PtrHeader->Header.Part4.CustomWtHH3_2bits >= BitPlane))) // HL3 band.
continue;
}
temp_x = (i >= 1 ? 1 : 0);
temp_y = (i != 1 ? 1 : 0);
if ((BlockCodingInfo[BlockSeq].StrPlaneHitHistory.TypeP & (1 << (2 - i))) == 0)
{
temp_DWORD = (StrSymbol.sym_val & (1 << (counter - 1)));
counter --;
if(temp_DWORD > 0)
{
temp_DWORD = (1 << (BitPlane -1));
BlockCodingInfo[BlockSeq].PtrBlockAddress[temp_x][temp_y] += temp_DWORD;
BlockCodingInfo[BlockSeq].StrPlaneHitHistory.TypeP += (1 << (2 - i));
BitsRead(PtrCoding, &temp_DWORD, 1);
if (temp_DWORD == NEGATIVE_SIGN)
BlockCodingInfo[BlockSeq].PtrBlockAddress[temp_x][temp_y] =
-BlockCodingInfo[BlockSeq].PtrBlockAddress[temp_x][temp_y];
if ((PtrCoding->DecodingStopLocations.BitPlaneStopDecoding != -1)
&& PtrCoding->RateReached == TRUE && !PtrCoding->DecodingStopLocations.LocationFind)
{
PtrCoding->DecodingStopLocations.BlockNoStopDecoding = BlockSeq;
PtrCoding->DecodingStopLocations.X_LocationStopDecoding = temp_x;
PtrCoding->DecodingStopLocations.Y_LocationStopDecoding = temp_y;
PtrCoding->DecodingStopLocations.LocationFind = TRUE;
return;
}
}
}
else
{
BlockCodingInfo[BlockSeq].RefineBits.RefineParent.ParentRefSymbol += ( 1 << (2 - i) );
BlockCodingInfo[BlockSeq].RefineBits.RefineParent.ParentSymbolLength ++;
}
if ((PtrCoding->DecodingStopLocations.BitPlaneStopDecoding != -1)
&& PtrCoding->RateReached == TRUE && !PtrCoding->DecodingStopLocations.LocationFind)
{
PtrCoding->DecodingStopLocations.BlockNoStopDecoding = BlockSeq;
PtrCoding->DecodingStopLocations.X_LocationStopDecoding = temp_x;
PtrCoding->DecodingStopLocations.Y_LocationStopDecoding = temp_y;
PtrCoding->DecodingStopLocations.LocationFind = TRUE;
return;
}
}
}
else
{
BlockCodingInfo[BlockSeq].RefineBits.RefineParent.ParentSymbolLength = RefCounter;
BlockCodingInfo[BlockSeq].RefineBits.RefineParent.ParentRefSymbol = 0;
if((PtrCoding->PtrHeader->Header.Part4).DWTType == INTEGER_WAVELET)
{
for( i = 0; i < 3; i++)
{
if((i == 0) && (PtrCoding->PtrHeader->Header.Part4.CustomWtHL3_2bits < BitPlane)) // HL3 band.
BlockCodingInfo[BlockSeq].RefineBits.RefineParent.ParentRefSymbol += 0x4;
if((i == 1) && (PtrCoding->PtrHeader->Header.Part4.CustomWtLH3_2bits < BitPlane)) //|| HL3 band.
BlockCodingInfo[BlockSeq].RefineBits.RefineParent.ParentRefSymbol += 0x2;
if((i == 2) && (PtrCoding->PtrHeader->Header.Part4.CustomWtHH3_2bits < BitPlane))
BlockCodingInfo[BlockSeq].RefineBits.RefineParent.ParentRefSymbol += 0x1;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -