📄 integerdwt_testedok.c
字号:
//#include <stdio.h>#include <math.h>
////These are from the test.c file for serial communication ///////////
///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
#include<cdefBF533.h>
//#include "UART_Library.h"
//section("SDRAM0") unsigned char a[16]={
//#include "exp.dat"};
section("sdram0")
unsigned char im[64][64];
//#include "Inputimage.h"
//#include "test.h"
section ("L1_code") int UART_detectAutobaud(void) {
int period = 0;
// Activate Loopback mode in order the receive channel is disconnected
// from RX pin during autobaud detection.
*pUART_MCR = LOOP_ENA;
// Setup Timer 2 Controller to do the autobaud detection. Timer captures
// duration between two falling edges. It expects a '@' (ASCII 0x40)
// character. 8-bit, no parity assumed.
// Disable Timer 2 first, in case there was an unexpected history.
*pTIMER_DISABLE = TIMDIS2;
*pTIMER_STATUS = TRUN2 | TOVL_ERR2 | TIMIL2;
// Capture from UART RxD pin. Select period capture from falling edge to
// falling edge. Enable IRQ_ENA, but don't enable the interrupt at system
// level (SIC).
*pTIMER2_CONFIG = TIN_SEL | IRQ_ENA | PERIOD_CNT | WDTH_CAP;
// Start the timer and wait until the according interrupt latch bit TIMIL2
// in the TIMER_STATUS register is set. Then, two falling edges on the RxD
// pin have been detected.
*pTIMER_ENABLE = TIMEN2;
// Enable the UART
*pUART_GCTL = UCEN;
while (!(*pTIMER_STATUS & TIMIL2)) {
// wait
};
// Disable Timer 2 again
*pTIMER_DISABLE = TIMDIS2;
*pTIMER_STATUS = TRUN2 | TOVL_ERR2 | TIMIL2;
// Save period value
period = *pTIMER2_PERIOD;
// In order to support also half-duplex connections, we need to delay any
// transmission, in order the sent character does not overlap the autobaud
// pattern.
// Use Timer 2 to perform this delay. Note that the Period Register still
// contains the proper value and the Width Register is not used.
*pTIMER2_CONFIG = OUT_DIS | IRQ_ENA | PERIOD_CNT | PWM_OUT;
*pTIMER_ENABLE = TIMEN2;
while (!(*pTIMER_STATUS & TIMIL2)) {
// wait
};
// Disable Timer 2 again
*pTIMER_DISABLE = TIMDIS2;
*pTIMER_STATUS = TRUN2 | TOVL_ERR2 | TIMIL2;
// Deactive Loopback mode again
*pUART_MCR = 0;
// done !
return period;
}
section ("L1_code") void UART_init(int divisor) {
// First of all, enable UART clock.
*pUART_GCTL = UCEN;
// Read period value and apply formula: divisor = period/16/8
// Write result to the two 8-bit DL registers (DLH:DLL).
*pUART_LCR = DLAB;
*pUART_DLL = divisor;
*pUART_DLH = divisor>>8;
// Clear DLAB again and set UART frame to 8 bits, no parity, 1 stop bit.
// This may differ in other scenarious.
*pUART_LCR = WLS(8);
}
section ("L1_code") void UART_putc(char c) {
while (!(*pUART_LSR & THRE)) {
// wait
};
*pUART_THR = c;
}
section ("L1_code") char UART_getc(void) {
char c;
while (!(*pUART_LSR & DR)) {
}
// read Data
c = *pUART_RBR;
return c;
}
section("sdram0")
#include "data.h"
void integerdwt();void reversedwt();int cSPIHT();int checkSignificance();void getChildren();void dSPIHT(int);int checkSignificance(int aA,int bB,int cC,int dD,int F,int xDim ,int yDim ,int level){ int scaling,significance,magnitude; int x,i,j,y,LL,CC; int TMP1; int TMP2; int xDimscal; int yDimscal; int newX; int newY; int checkit; int firsttime; int significant; int A1,B1,A2,B2; int Lx,Ly; int BITANDX; int BITANDY; int tmp[1][3]; int result[4][3]; int aa,sizea; scaling = 2; currSet[0][0]=aA; currSet[0][1]=bB; currSet[0][2]=cC; currSet[0][3]=dD; max1=-1; newX = currSet[0][0]; newY = currSet[0][1]; xDimscal = floor(xDim / scaling); yDimscal = floor(yDim / scaling); firsttime = true1; significance = false1; checkit = false1; LL = currSet[0][3]; if (LL == D) { checkit = true1; } i=0; sizea=0;//printf(" length of arr %d ", sizeof(t)/sizeof(int)); if ((newX <= xDim/2)&&(newY <= yDim/2)) { if ((newX <= xDimscal/2)&&(newY <= yDimscal/2)) { BITANDX=(newX&1); BITANDY=(newY&1); if (BITANDX == 0) { Lx = xDimscal-3+newX; } else { Lx = (newX-1); } if (BITANDY == 0) { Ly = yDimscal-3+newY; } else { Ly = (newY-1); } } else { Lx = (newX - 1); Ly = (newY - 1); } Lx=Lx-1;
Ly=Ly-1;
A1=(newX + Lx); B1=(newY + Ly); A2=(newX + Lx + 1); B2=(newY + Ly + 1); /*tmp[0][0]=A1; tmp[0][1]=B1; tmp[0][2]=D; TMP1=tmp[0][0]; TMP2=tmp[0][1]; TMP1=TMP1-1; TMP2=TMP2-1;*/ CC=Ad[newX + Lx][newY + Ly]; magnitude = abs(CC); if (magnitude >= T) { significance = true1; } if (magnitude > max1) { max1 = magnitude; } result[0][0] = newX + Lx; result[0][1] = newY + Ly; //////////////////////////////////// /*tmp[1][0]=A1; tmp[1][1]=B2; tmp[1][2]=D; TMP1=tmp[1][0]; TMP2=tmp[1][1]; TMP1=TMP1-1; TMP2=TMP2-1;*/ magnitude = abs(Ad[newX + Lx][newY + Ly+1]); if (magnitude >= T) { significance = true1; } if (magnitude > max1) { max1 = magnitude; } result[1][0] = newX + Lx; result[1][1] = newY + Ly+1; //////////////////////////////////// /*tmp[2][0]=A2; tmp[2][1]=B1; tmp[2][2]=D; TMP1=tmp[2][0]; TMP2=tmp[2][1]; TMP1=TMP1-1; TMP2=TMP2-1;*/ magnitude = abs(Ad[newX + Lx+1][newY + Ly]); if (magnitude >= T) { significance = true1; } if (magnitude > max1) { max1 = magnitude; } result[2][0] = newX + Lx+1; result[2][1] = newY + Ly; /////////////////////////////////// /*tmp[3][0]=A2; tmp[3][1]=B2; tmp[3][2]=D; TMP1=tmp[3][0]; TMP2=tmp[3][1]; TMP1=TMP1-1; TMP2=TMP2-1;*/ magnitude = abs(Ad[newX + Lx+1][newY + Ly+1]); if (magnitude >= T) { significance = true1; } if (magnitude > max1) { max1 = magnitude; } result[3][0] = newX + Lx+1; result[3][1] = newY + Ly+1; significance = significance & checkit; }
if(significance)
{ descArrS.desc1[0]=A1; descArrS.desc1[1]=A1; descArrS.desc1[2]=A2; descArrS.desc1[3]=A2; descArrS.desc2[0]=B1; descArrS.desc2[1]=B2; descArrS.desc2[2]=B1; descArrS.desc2[3]=B2; descArrS.desc3[0]=D; descArrS.desc3[1]=D; descArrS.desc3[2]=D; descArrS.desc3[3]=D; }
return max1; }//end of function/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////get childrenvoid getChildren(int aA,int bB,int cC,int dD,int xDim ,int yDim ,int level){ int scaling; int x; int y; int xDimscal; int yDimscal; int D=0; int A1,B1,A2,B2; int Lx,Ly; int BITANDX=1; int BITANDY=1; level=1; scaling = 2; currSet[0][0]=aA; currSet[0][1]=bB; currSet[0][2]=cC; currSet[0][3]=dD; x = currSet[0][0]; y = currSet[0][1]; xDimscal = floor(xDim / scaling); yDimscal = floor(yDim / scaling); if ((x <= xDim/2)&&(y <= yDim/2)) { if ((x <= xDimscal/2)&&(y <= yDimscal/2)) { BITANDX=(x & 1); BITANDY = (y & 1); if (BITANDX == 0) { Lx = xDimscal-3+x; } else { Lx = (x-1); } if (BITANDY == 0) { Ly = yDimscal-3+y; } else { Ly = (y-1); } } else { Lx = (x - 1); Ly = (y - 1); }
Lx=Lx-1;
Ly=Ly-1;
A1=(x + Lx); B1=(y + Ly); A2=(x + Lx + 1); B2=(y + Ly + 1); descArrS.desc1[0]=A1; descArrS.desc1[1]=A1; descArrS.desc1[2]=A2; descArrS.desc1[3]=A2; descArrS.desc2[0]=B1; descArrS.desc2[1]=B2; descArrS.desc2[2]=B1; descArrS.desc2[3]=B2; descArrS.desc3[0]=D; descArrS.desc3[1]=D; descArrS.desc3[2]=D; descArrS.desc3[3]=D; } }/////////////////////////////////////////////////int cSPIHT(){ int AAA,BBB,CCC,DDD; int Refinement; int Coeff; //int LIP11,LIP22;
unsigned char LIP11,LIP22; int L=1; int A,B,BB,CC; // int xDim=4; // int yDim=4; int level=1; int rows; int columns; int l; int m; int i,k,k1,k2; int Val; int LSPcount = 0,OldLSPCount = -1,LSPinc = 50,LSPsize = -1; int scaling; int LISsize = 0,LIScount = 0,LISinc = 50; int currCoeff; int tmpLIPcount = 0; int tmpLIScount =0; int LIPsize = 0,LIPcount = 0,LIPinc = 50; int notDone =0; int index_st; int currSet,Tact; int bitCount=10; int bitbudget = 100000;
unsigned char LIP_1,LIP_2,LSP1_1,LSP1_2;
int coeffMax; int sign; int mM; int lL; float temp;
int AAAA; int desc1a,desc2a,desc3a,desc4a,cnty;
xDim=yDim=64; scaling = 2; rows=yDim/scaling; columns=xDim/scaling; //rows = yDim>>1;
//colomns=xDim>>1; for(l=0;l<rows;l++) { for(m=0;m<columns;m++) { LIP1[LIPcount]=l; LIP2[LIPcount]=m; LIP11=m; LIP22=l; LIPcount = LIPcount + 1; mM=m+1; lL=l+1; AAAA=((lL & 1) && (mM & 1)); if(AAAA != 1) { LIS1[LIScount]=l; LIS2[LIScount]=m; LIS3[LIScount]=D; LIS4[LIScount]=-1; LIScount = LIScount + 1; } } }LIPsize = LIPcount;LISsize = LIScount;/////////////////
//////////////////////////////////////////////////////
///Finding the threshold of the Waveletencodd image/// mM=Ad[0][0];
///finding the maximum of the wavelet encoded image///
for(i=0;i<64;i++)
for(m=0;m<64;m++)
if (Ad[i][m] > mM) mM=Ad[i][m];
////////////////////////////////////////////////////m=log10(mM);
m=2;
while(m < mM)
m=m<<1;
m=m>>1;
T=m;
Tact = T;
/////////////////////////////////////////////////////
/////////////////////////////////////////////////////
//Please Note : Modified
/**As st is of unsigned char when T >= 256 it is 0
*************/st[0] = T;st[1] = xDim;st[2] = yDim;st[3] = level;st[4] = 0;st[5] = 0;st[6] = 0;st[7] = 0;st[8] = 0;st[9] = 0;
while (bitCount < bitbudget){//////////////////////////////////////////// LIP for (k=0;k<LIPsize;k++) { LIP_1=LIP1[k]; LIP_2=LIP2[k]; currCoeff = Ad[LIP_1][LIP_2]; if (abs(currCoeff) >= T) { st[bitCount]= 1; bitCount = bitCount + 1; if (currCoeff >= 0) { st[bitCount]= 1; bitCount = bitCount + 1; } else { st[bitCount]= 0; bitCount = bitCount + 1; } LSP1[LSPcount]=LIP1[k];
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -