📄 ezw3.h
字号:
/*--------------------------------------------------------------------------------------------*/
/* ezw3.h */
/*--------------------------------------------------------------------------------------------*/
/* EZW3 -
*
*/
/*--------------------------------------------------------------------------------------------*/
#ifndef __EZW_H__
#define __EZW_H__
/* disable unused variabled warning */
#pragma warning (disable : 4101)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <sys/stat.h>
/*--------------------------------------------------------------------------------------------*/
/* encoded stream filename extension */
#define ENC_EXT "ezw"
#define BUILD_STAMP "EZW v0.0.3"
/*--------------------------------------------------------------------------------------------*/
#include "arcode.h"
#include "dlist.h"
#include "dwt.h"
#include "global.h"
#include "img.h"
#include "memchk.h"
/*--------------------------------------------------------------------------------------------*/
/* Header bits */
#define ImageXSizeBits 12
#define ImageYSizeBits 12
#define WaveletIndexBits 2
#define ScaleBits 3
#define MaxBitPlaneBits 5
/*--------------------------------------------------------------------------------------------*/
/* default coding options */
#define DefaultScale 6
#define DefaultWaveletIndex 0
/*--------------------------------------------------------------------------------------------*/
/* external varaibles */
extern char *SubbandFilterName[3];
/*--------------------------------------------------------------------------------------------*/
#define _BIAS_DEQUANTIZE_ 0
#if _BIAS_DEQUANTIZE_
#define MSB_GAMMA 0.38
#define GAMMA 0.48
#else
#define MSB_GAMMA 0.5
#define GAMMA 0.5
#endif
/*--------------------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------------------*/
typedef struct NodeStruct{
int i; /* coeff linear location in the subband */
int x; /* coeff horizontal location in the subband */
int y; /* coeff vertical location in the subband */
char n; /* subband index */
} ListData;
/*--------------------------------------------------------------------------------------------*/
/* Codec mode options */
#define ENCODE 0
#define DECODE 1
typedef struct CoderStruct {
int Mode;
int ImageXSize;
int ImageYSize;
int NScale;
int nSubbands;
int WaveletIndex;
int CurrentThreshold;
int MaxThreshold;
int CurrentBitPlane;
int MaxBitPlane;
int mean;
DWTransform *dwt;
int *SubbandXSize;
int *SubbandYSize;
int *SubbandSize;
int **Magnitude;
int **MaxMagnitude;
unsigned int **State;
DListElement *RefinementMark[32];
/* List based */
DList LSP;
char *InputImageName;
char *EncodeImageName;
char InputImageFileName[_MAX_PATH];
char EncodeImageFileName[_MAX_PATH];
char DecodeImageFileName[_MAX_PATH];
char OriginalImageFileName[_MAX_PATH];
Boolean EncodeFileNameSpecify;
Boolean DecodeFileNameSpecify;
FImage *InputImage;
FImage *DecodeImage;
Boolean TestFullBitPlane;
int LastFullBitPlane;
double TargetBitRate;
int TargetBits;
int BitsCount;
AREncoder *Encoder;
ARDecoder *Decoder;
Histo ***SSigModel;
Histo ***RefiModel;
int nPS;
int nNG;
int nIZ;
int nZS;
int nRF;
int CodedSymbols;
} Coder;
/*--------------------------------------------------------------------------------------------*/
/* General interface */
int EncodeInterface(int argc, char **argv, char *ProgramName, Coder *coder);
int DecodeInterface(int argc, char **argv, char *ProgramName, Coder *coder);
int Encode(Coder *coder);
int Decode(Coder *coder);
void Usage(char *ProgramName);
void GetProgramName(char *NameOnly, char *FullPath);
/*--------------------------------------------------------------------------------------------*/
/* Structures setup */
void BuildCodingArrays(Coder *coder);
void DestroyCodingArrays(Coder *coder);
void ComputeMaxMagnitudeTree(Coder *coder);
/*--------------------------------------------------------------------------------------------*/
/* I/O */
void WriteHeader(Coder *coder);
void ReadHeader(Coder *coder);
int BytesCount(Coder *coder);
int WriteSymbol(Coder *coder, Histo *c, int symbol);
int ReadSymbol(Coder *coder, Histo *c, int *symbol);
/*--------------------------------------------------------------------------------------------*/
/* Main algorithms */
void MainCodingPass(Coder *coder);
int RefinementPass(Coder *coder);
int SortingPass(Coder *coder);
/*--------------------------------------------------------------------------------------------*/
/* List manupulations */
void DeleteData(void *data);
ListData *CreateData(int i, int x, int y, char n);
/*--------------------------------------------------------------------------------------------*/
void AllocModels(Coder *coder);
void DeallocModels(Coder *coder);
void ResetModels(Coder *coder);
/*--------------------------------------------------------------------------------------------*/
/* Scalar quantization */
/* At certain bitrate, uniform quantizer is better than deadzone.
* Note that the dequantization equation is for deadzone only. This is mathematically
* incorrect.
*/
/* EZW default : 1 */
#define _DEADZONE_ 1
#if _DEADZONE_
#define Quantize(Value, StepSize) SIGN((Value))*((int)(fabs((Value))/(StepSize)));
#else
#define Quantize(Value, StepSize) SIGN((Value))*(ROUND(fabs((Value))/(StepSize)));
#endif
#define Dequantize(index, StepSize, Gamma) \
((index)==0? 0 : SIGN((index))*(abs((index)) + (Gamma))*(StepSize));
/*--------------------------------------------------------------------------------------------*/
#define TEST_MALLOC(p) \
if (p==NULL){ \
Error("Memory allocation fail.\n"); \
}
/*--------------------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------------------*/
#define SCAN_CTX_BIT 0x00000008
#define CSIG_CTX_BIT 0x00000004
#define SIGN_CTX_BIT 0x00000002
#define PARE_CTX_BIT 0x00000001
/*--------------------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------------------*/
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -