📄 stream.cpp
字号:
#include "stdafx.h"
#include "stream.h"
//#include "reconstruct.h"
//#include <stdio.h> //for test
codeListStruct *symbolStream(btype Q[][8][8], blstype n, symbolStreamStruct **streamHead, cltype &codeNo, unsigned long &acStreamLength){
//This function scans the quantified coefficient map and records events in sequence while
//accumulates the times of appearance of each symbol.
//The first symbol recorded is EOB!
symbolStreamStruct *stream=NULL;
unsigned long acsl=0;
codeListStruct *listHead, *list;
eventStruct *EOB;
EOB=new struct eventStruct;
EOB->level=0;
EOB->run=0;
list=new struct codeListStruct;
list->ep=EOB;
list->times=0;
list->code="0";
list->next=NULL;
listHead=list;
codeNo=1;
bool notfound;
blstype bp;
int i,x,y;
unsigned short int run=0;
initZigZag(8);
for (bp=0;bp<n;bp++)
for (i=0;i<63;i++){
fastZigZag(i,x,y);
if (Q[bp][x][y]==0) {
if (i<62)
run++;
else{ //EOB
if (stream) {
stream->next=new struct symbolStreamStruct; acsl++;
stream=stream->next;
//printf("*******EOB:"); //for test
}
else {
stream=new struct symbolStreamStruct; acsl++;
*streamHead=stream;
//printf("Stream starts as EOB for the "); //for test
}
stream->e=*EOB;
stream->next=NULL;
listHead->times++;
//printf("%d************\n",listHead->times); //for test
run=0;
}
}
else{ //we got an event!
if (stream) {
stream->next=new struct symbolStreamStruct; acsl++;
stream=stream->next;
//printf("Get new symbol "); //for test
}
else {
stream=new struct symbolStreamStruct; acsl++;
*streamHead=stream;
//printf("Stream starts normally ");//for test
}
stream->e.level=Q[bp][x][y];
stream->e.run=run;
stream->next=NULL;
//printf("<%d,%d>",run,Q[bp][x][y]); //for test
//check if this symbol has appeared
//printf(". Now check appearance...\n");
list=listHead;
notfound=1;
while(list->next && notfound){
list=list->next;
//printf("Checking at <%d,%d>...\n",list->ep->run,list->ep->level); //for test
if (list->ep->run==run && list->ep->level==Q[bp][x][y]) {//appeared
list->times++;
//printf("found, now times:%d\n",list->times); //for test
notfound=0;
//printf("(+)");
//break;
}
//printf("<%d,%d>:%d\t",list->ep->run,list->ep->level,list->times);
}
if (notfound) {//new symbol
//printf("not found, new symbol!\n"); //for test
list->next=new struct codeListStruct;
list=list->next;
list->ep=&stream->e;
list->times=1;
list->code="0";
list->next=NULL;
codeNo++;
//printf("At block%d found new symbol <%d,%d>\n",bp,list->ep->run,list->ep->level);
}
//printf("\n");
run=0;
}
}
acStreamLength=acsl;
return listHead;
}
void DCProcess(short int afq[][8][8], short **Diff, blstype n, List &list1)
{
short *dcDiff;
dcDiff=new short [n];
*Diff=dcDiff;
dcDiff[0]=afq[0][0][0];
for(unsigned int i=1;i<n;i++)
{
dcDiff[i]=afq[i][0][0]-afq[i-1][0][0];
}
//void main(){
// short int dcDiff[20]={1,3,5,7,9,11,2,4,6,7,5,3,6,8,1,12,17,3,19,8};
DCDiffCount *p;
//short int diffValueTemp;
//unsigned short countTemp;
p=list1.CreatNode(dcDiff[0]);
p->IncreCount();
list1.InsertRear(p);
for(unsigned int i=1;i<n;i++)
{
if(p=list1.Find(dcDiff[i])){
p->IncreCount();
}
else {
p=list1.CreatNode(dcDiff[i]);
p->IncreCount();
list1.InsertRear(p);
}
}
}
// list1.PrintList();
// ofstream distfile("DCDiffCount.txt");
// p=list1.head->link;
// for(i=0;i<list1.Length();i++)
// {
// distfile<<endl<<p->diffValue<<'\t'<<p->count;
// p=p->link;
// }
// //distfile<<endl<<list1.Length();
// distfile.close();
// ifstream srcfile("DCDiffCount.txt");
// //char ch,buf[20];
// do{
// srcfile>>diffValueTemp>>countTemp;
// cout<<diffValueTemp<<'\t'<<countTemp<<endl;
// //srcfile.get();
// }while(!srcfile.eof());
// srcfile.close();
//}
dcCodeList * List2dcCode(List &l, cltype &m){
DCDiffCount *p=l.head->link;
cltype n=0;
dcCodeList *t,*h;
t=new struct dcCodeList;
t->next=NULL;
h=t;
while (p) {
n++;
t->next=new struct dcCodeList;
t=t->next;
t->diffValue=p->diffValue;
t->code=NULL;
t->count=p->count;
t->next=NULL;
p=p->link;
}
t=h->next;
delete h;
m=n;
return t;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -