📄 mq_code.c
字号:
/******************************************************************************
功能描述:
Implements mq 编码解码
函数是对EBCOT的编码出的上下文数据算术编码和解码
******************************************************************************/
/*****************************************************************************/
// 程序: ebcot 编码
// 版本: V0.0
// 作者: 胡运平
// 最后修改时间 : 30, 6, 2005
/****************************************************************************/
#include <stdio.h>
#include<stdlib.h>
//#include<math.h>
//#include<assert.h>
//#include"fdwt.h"
//#include"block_encode.h"
#include"mq_code.h"
#define WRITE_BYTES
//#define WRITE_BITS
//MQ输出的数据存放在此数组中
unsigned char arrayOut[130];
//跟踪所写入的字符个数
static long int bytesWritten = 0;
/*****************************************************************************
功能描述:
MQ编码函数
输入:以文件形式输入的是EBCOT编码后的上下文数据
输出:二进制数据输出,或者是转换成字节形式输出
******************************************************************************/
void mq_code()
{
int m=0,CX,D;
FILE *context;
if ((context = fopen("context.raw","rb+")) == NULL)
{
printf("cannot open file\n");
return;
}
rewind(context);
ArithEncInit();
printf("\nThe mq indata is:");
while(!feof(context))
{
fscanf(context,"%d %d ",&CX,&D);
printf("%d,%d,",CX,D);
}
rewind(context);
while(!feof(context))
{
fscanf(context,"%d %d ",&CX,&D);
ArithEncEncode(D, CX);
}
ArithEncFlush();
rewind(context);
/*
//2005,05,01 添加输出
printf("The arithemtic bytes is :\n");
for(i=0;i<130;i++)
printf("%x ",arrayOut[i]);
printf("\n");
//When including "tile5-symbols.h", the
//correct results in arrayOut[] should be
//11 50 54 af
*/
fclose(context);
}
/*****************************************************************************
功能描述:
MQ解码函数
将压缩数据CD和由系数位建模所确定的上下文输入到算术解码器,输出0或者1的
二进判决D.
输入: 压缩数据CD,和CX
输出: D二进判决
******************************************************************************/
//mq_decode();
/*
{
int m=0,CX,CD,byte;
FILE *context,*fp;
if ((context = fopen("context.raw","rb+")) == NULL)
{
printf("cannot open file\n");
return;
}
if ((fp = fopen("arithmetic_out.raw","ab+")) == NULL)
{
printf("cannot open file\n");
return;
}
printf("\nThe mq outdata is:");
while(!feof(fp))
{
byte = fgetc(fp);
printf("%d ",byte);
}
rewind(fp);
rewind(context);
ArithDecInit();
while(!feof(fp))
{
byte = fgetc(fp);
while(!feof(context))
{
fscanf(context,"%d %d ",&CX,&D);
ArithDecEncode(byte, CX);
}
}
ArithDecFlush();
rewind(fp);
rewind(context);
fclose(context);
fclose(fp);
}
*/
/*****************************************************************************
函数功能:
brief Write a byte of data.For this testing code, this function just
prints out the binary patternfor the bytes (most significant bit first)
to standard output.parameter: byte - The byte to write out.
******************************************************************************/
void TransmitByte(unsigned char byte)
{
FILE *fp;
if ((fp = fopen("arithmetic_out.raw","ab+")) == NULL)
{
printf("cannot open file\n");
return;
}
#ifdef WRITE_BYTES
fputc(byte,fp);
#endif
}
/*****************************************************************************
函数功能: 从文件中读取上下文数据,每次读取一个数据。按照输入的数据格式读取
返回读取的数据
******************************************************************************/
unsigned char ReceiveByte(FILE *context)
{
unsigned char byte = 0;
/*#ifdef WRITE_BITS
int i;
for (i = 0; i < 8; i++)
{
byte <<= 1;
if (getc(inFile) == ’1’)
byte |= 0x01;
//If reading past the end of the file, read in 1 bits
if (feof(inFile))
byte |= 0x01;
}
#endif
*/
fscanf(context,"%d ",&byte);
if(feof(context))
byte = 0xFF;
return byte;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -