-
Notifications
You must be signed in to change notification settings - Fork 0
/
dwt2d.c
121 lines (101 loc) · 3.68 KB
/
dwt2d.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
/*
* dwt2d.c
*
* Created on: Jan 31, 2011
* Author: mousomer
*/
#include "libxyn.h"
#define USG_STRING "[-v %:] [-out %s:outName] [-type %s:dataType] [-lift %:] [-inPlace %:] [-noScl %:] [-startHigh %:] [-nC %d:nC] %d:nR %s:waveName %s:inpName"
xynString waveName, inpName, outName, dataType;
int verbose=0, lifting=0, inPlace=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, dataType, &lifting, &inPlace, &noRescale, &startHigh, &nC, &nR, waveName, inpName))
return (FAIL);
bool startHigh_b = (startHigh>0);
/* 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 = (dataType[0]=='f') ? sizeof(float) : sizeof(int);
len /= nBytes;
if (nC == 0)
nC = len/nR;
printf(startHigh ? "SH true\n" : "SH false\n");
if (verbose)
printf("%s - verb(d): %d out(s): %s type(s): %s startHigh(d): %d length(%ld) = %d x %d\t wave(s): %s inp(s): %s\n",
argv[0], verbose, outName, dataType, 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;
}
int *intInput=NULL, *intOutput=NULL;
float *floatInput=NULL, *floatOutput=NULL;
if (verbose)
printf("%s - verb(d): %d out(s): %s type(s): %s startHigh_b(d): %d length(%ld) = %d x %d\t wave(s): %s inp(s): %s\n",
argv[0], verbose, outName, dataType, startHigh_b, len, nC, nR, waveName, inpName);
if (stringNull(outName)) {
stringCopy(outName, inpName);
strcat(outName, ".fwd");
}
if (stringNull(dataType))
stringCopy(dataType, "d");
waveFilterPtr wfp = wavGetWaveletName (waveName);
waveLiftPtr wlp = wavGetLiftWaveName (waveName);
assert(wfp);
assert(wlp);
if (verbose)
printf("dwt1d %s: %s --> %s (type %c)\n", waveName, inpName, outName, dataType[0]);
FILE* fpInp = fopen(inpName, "r");
assert (fpInp);
FILE* fpOut = fopen(outName, "w");
assert (fpOut);
if ( dataType[0] == 'd' ) {
PREPARE_DATA(int);
if (verbose) displayArrayNM_i( intOutput, nC, nR, stdout );
if ( lifting )
perror ("not implemented. try float\n");
//liftTransform_i(intInput, len, startHigh_b, inPlace, wlp);
else
perror ("not implemented. try lifting\n");
//wavTransform_i(intInput, intOutput, len, startHigh_b, wfp);
if (verbose) displayArrayNM_i(intOutput, nC, nR, stdout );
fwrite(intOutput, nBytes, len, fpOut);
}
else {
PREPARE_DATA(float);
if (verbose) displayArrayNM_f( floatOutput, nC, nR, stdout );
if ( lifting )
{
liftTransform2d_f(floatInput, nC, nR, startHigh_b, startHigh_b, inPlace, noRescale, wlp);
if (verbose) displayArrayNM_f(floatInput, nC, nR, stdout );
fwrite(floatInput, nBytes, len, fpOut);
}
else
{
perror ("not implemented. try lifting\n");
//wavTransform_f(floatInput, floatOutput, len, startHigh_b, wfp);
if (verbose) displayArrayNM_f(floatOutput, nC, nR, stdout );
fwrite(floatOutput, nBytes, len, fpOut);
}
}
fclose(fpInp);fclose(fpOut);
XYN_DPRINTF(DEBUG_PROCESS,"closed files\n");
XynFree(intInput); XynFree(floatInput);
XynFree(intOutput); XynFree(floatOutput);
XYN_DPRINTF(DEBUG_PROCESS,"memory freed\n");
return OK;
}