-
Notifications
You must be signed in to change notification settings - Fork 0
/
dwt2d_buffs_d.c
135 lines (108 loc) · 4.03 KB
/
dwt2d_buffs_d.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/*
* dwt2d.c
*
* Created on: Jan 31, 2011
* Author: mousomer
*/
#include "libxyn.h"
#define USG_STRING "[-v %:] [-out %s:outName] [-noScl %:] [-startHigh %:] [-nC %d:nC] %d:nR %s:waveName %s:inpName"
xynString waveName, inpName, outName, outNameLL, outNameLH, outNameHL, outNameHH;
int verbose=0, startHigh=0, noRescale=0, nC=0, nR=0;
#define PREPARE_DATA(_t_) { \
XYN_DPRINTF(DEBUG_PROCESS,"\npreparing data. Length %d/=%d\n", len, nBytes); \
_t_##Input = (_t_*) malloc(nBytes * len); \
_t_##Output = (_t_*) malloc(nBytes * len); \
assert(_t_##Input && _t_##Output ); \
fread(_t_##Input, nBytes, len, fpInp); \
memcpy(_t_##Output, _t_##Input, len*nBytes ); }
int main(int argc, char* argv[])
{
if (parseParameters(argc, argv, USG_STRING,
&verbose, outName, &noRescale, &startHigh, &nC, &nR, waveName, inpName))
return (FAIL);
/* transform types:
0: shuffled, non lift
1: inPlace, non lift
2: shuffled, lifting implementation
3: inPlace, lifting implementation */
//int transformType = 4*(dataType[0]=='f') + 2*(lifting>0) + (inPlace>0);
long len = getFileSize(inpName);
int nBytes = sizeof(double);
len /= nBytes;
if (nC == 0)
nC = len/nR;
if (verbose)
printf("%s - verb(d): %d out(s): %s type(s): double startHigh(d): %d length(%ld) = %d x %d\t wave(s): %s inp(s): %s\n",
argv[0], verbose, outName, startHigh, len, nC, nR, waveName, inpName);
if (nC != 0)
{
if ( nC * nR > len )
perror("nC*nR too large, or file too small\n");
len = nC * nR;
}
double *doubleInput=NULL, *doubleOutput=NULL;
if (verbose)
printf("%s - verb(d): %d out(s): %s type(s): double startHigh(d): %d length(%ld) = %d x %d\t wave(s): %s inp(s): %s\n",
argv[0], verbose, outName, startHigh, len, nC, nR, waveName, inpName);
if (stringNull(outName)) {
stringCopy(outName, inpName);
}
stringCopy(outNameLL, outName);
stringCopy(outNameLH, outName);
stringCopy(outNameHL, outName);
stringCopy(outNameHH, outName);
strcat(outNameLL, "_LL.fwd");
strcat(outNameLH, "_LH.fwd");
strcat(outNameHL, "_HL.fwd");
strcat(outNameHH, "_HH.fwd");
waveFilterPtr wfp = wavGetWaveletName (waveName);
waveLiftPtr wlp = wavGetLiftWaveName (waveName);
assert(wfp);
assert(wlp);
if (verbose)
printf("dwt1d %s: %s --> %s (type double)\n", waveName, inpName, outName);
FILE* fpInp = fopen(inpName, "r");
assert (fpInp);
PREPARE_DATA(double);
fclose(fpInp);
if (verbose) displayArrayNM_d( doubleOutput, nC, nR, stdout );
liftTransform2d_d(doubleInput, nC, nR, startHigh, startHigh, false, noRescale, wlp);
if (verbose) displayArrayNM_d(doubleInput, nC, nR, stdout );
double *outLL=NULL, *outLH=NULL, *outHL=NULL, *outHH=NULL;
long low_nC, low_nR, high_nC, high_nR;
wavPack_lineBuffers_d ( doubleInput, nC, nR, startHigh, startHigh, &outLL, &outHL, &outLH, &outHH, &low_nC, &low_nR, &high_nC, &high_nR);
if (verbose)
{
printf("\n sizes: low nC nR high nC nR \n %ld %ld %ld %ld \n pointers: %p %p %p %p\n", low_nC, low_nR, high_nC, high_nR, outLL, outHL, outLH, outHH);
printf("\n\n -------- LL band---------------\n");
displayArrayNM_d(outLL, low_nC, low_nR, stdout );
printf("\n\n -------- HL band---------------\n");
displayArrayNM_d(outHL, high_nC, low_nR, stdout );
printf("\n\n -------- LH band---------------\n");
displayArrayNM_d(outLH, low_nC, high_nR, stdout );
printf("\n\n -------- HH band---------------\n");
displayArrayNM_d(outHH, high_nC, high_nR, stdout );
}
FILE* fpOut = fopen(outNameLL, "w");
assert (fpOut);
fwrite(outLL, nBytes, low_nC*low_nR, fpOut);
fclose(fpOut);
fpOut = fopen(outNameHL, "w");
assert (fpOut);
fwrite(outHL, nBytes, high_nC*low_nR, fpOut);
fclose(fpOut);
fpOut = fopen(outNameLH, "w");
assert (fpOut);
fwrite(outLH, nBytes, low_nC*high_nR, fpOut);
fclose(fpOut);
fpOut = fopen(outNameHH, "w");
assert (fpOut);
fwrite(outHH, nBytes, high_nC*high_nR, fpOut);
fclose(fpOut);
XYN_DPRINTF(DEBUG_PROCESS,"closed files\n");
XynFree(doubleInput);
XynFree(doubleOutput);
XynFree(outLL);
XYN_DPRINTF(DEBUG_PROCESS,"memory freed\n");
return OK;
}