-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestIPPResize.cpp
More file actions
321 lines (246 loc) · 8.78 KB
/
testIPPResize.cpp
File metadata and controls
321 lines (246 loc) · 8.78 KB
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
#include <ipp.h>
#include <math.h>
#include <fstream> // ifstream
#include <iostream> // cout, cerr
#include <sstream> // stringstream
using namespace std;
IppStatus resizeExample_C1R(Ipp8u *pSrc, IppiSize srcSize, Ipp32s srcStep,
Ipp8u *pDst, IppiSize dstSize, Ipp32s dstStep);
IppStatus Resize8u(Ipp8u *pSrc, IppiSize srcSize, Ipp32s srcStep, Ipp8u *pDst,
IppiSize dstSize, Ipp32s dstStep);
IppStatus Resize32f(Ipp32f *pSrc, IppiSize srcSize, Ipp32s srcStep,
Ipp32f *pDst, IppiSize dstSize, Ipp32s dstStep);
int main() {
int x = 0, y = 0, width = 0, height = 0, maxval = 0;
string inputLine = "";
std::string filename = "zero.pgm";
std::ifstream pgm_file(filename, std::ios::out | std::ios::binary);
getline(pgm_file, inputLine);
if (inputLine.compare("P5") != 0)
cerr << "Version error" << endl;
else
cout << "Version : " << inputLine << endl;
// Second line : comment
getline(pgm_file, inputLine);
cout << "Comment : " << inputLine << endl;
pgm_file >> width >> height >> maxval;
cout << width << " x " << height << " maxval: " << maxval << endl;
size_t img_size = width * height;
uint8_t array[img_size];
pgm_file.read((char*)array, img_size);
pgm_file.close();
{
// export luma to a PGM file for a cross-check
std::string filename = "zero_src.pgm";
std::fstream pgm_file(filename, std::ios::out | std::ios::binary);
pgm_file << "P5" << std::endl;
pgm_file << width << " " << height << " 255" << std::endl;
pgm_file.write((const char *)array, img_size);
pgm_file.close();
}
// prepare the source arrays
Ipp32f *pix32f = ippsMalloc_32f_L(img_size);
Ipp8u *pix8u = ippsMalloc_8u_L(img_size);
for(size_t i=0; i<img_size; i++) {
pix8u[i] = array[i];
pix32f[i] = (float)array[i];
}
// the resize part
int img_width = width / 2;
int img_height = height / 2;
size_t plane_size = img_width * img_height;
Ipp32f *dstPix32f = ippsMalloc_32f_L(plane_size);
Ipp8u *dstPix8u = ippsMalloc_8u_L(plane_size);
// 8-bit unsigned integer pixels
{
IppiSize srcSize;
srcSize.width = width;
srcSize.height = height;
Ipp32s srcStep = srcSize.width;
IppiSize dstSize;
dstSize.width = img_width;
dstSize.height = img_height;
Ipp32s dstStep = dstSize.width;
//resizeExample_C1R(pix8u, srcSize, srcStep, dstPix8u, dstSize, dstStep);
Resize8u(pix8u, srcSize, srcStep, dstPix8u, dstSize, dstStep);
// export luma to a PGM file for a cross-check
std::string filename = "zero_half.pgm";
std::fstream pgm_file(filename, std::ios::out | std::ios::binary);
pgm_file << "P5" << std::endl;
pgm_file << img_width << " " << img_height << " 255" << std::endl;
pgm_file.write((const char *)dstPix8u, plane_size);
pgm_file.close();
}
// 32-bit floating-point pixels
{
IppiSize srcSize;
srcSize.width = width;
srcSize.height = height;
Ipp32s srcStep = srcSize.width * sizeof(Ipp32f);
IppiSize dstSize;
dstSize.width = img_width;
dstSize.height = img_height;
Ipp32s dstStep = dstSize.width * sizeof(Ipp32f);
Resize32f(pix32f, srcSize, srcStep, dstPix32f, dstSize, dstStep);
for(size_t i=0; i<plane_size; i++)
dstPix8u[i] = roundf(dstPix32f[i]) ;
// export luma to a PGM file for a cross-check
std::string filename = "zero_half_float.pgm";
std::fstream pgm_file(filename, std::ios::out | std::ios::binary);
pgm_file << "P5" << std::endl;
pgm_file << img_width << " " << img_height << " 255" << std::endl;
pgm_file.write((const char *)dstPix8u, plane_size);
pgm_file.close();
}
// release the memory
ippsFree(pix32f);
ippsFree(pix8u);
ippsFree(dstPix32f);
ippsFree(dstPix8u);
}
IppStatus Resize8u(Ipp8u *pSrc, IppiSize srcSize, Ipp32s srcStep, Ipp8u *pDst,
IppiSize dstSize, Ipp32s dstStep) {
IppStatus status;
// IppiPoint srcOffset = {0, 0};
IppiPoint dstOffset = {0, 0};
IppiBorderSize borderSize = {0, 0, 0, 0};
IppiBorderType border = ippBorderRepl;
const Ipp8u *pBorderValue = NULL;
IppiResizeSpec_32f *pSpec = 0;
int specSize = 0, initSize = 0, bufSize = 0;
Ipp8u *pBuffer = 0;
Ipp8u *pInitBuf = 0;
/* Spec and init buffer sizes */
status = ippiResizeGetSize_8u(srcSize, dstSize, ippLanczos, 0, &specSize,
&initSize);
if (status != ippStsNoErr)
return status;
/* Memory allocation */
pInitBuf = ippsMalloc_8u(initSize);
pSpec = (IppiResizeSpec_32f *)ippsMalloc_8u(specSize);
if (pInitBuf == NULL || pSpec == NULL) {
ippsFree(pInitBuf);
ippsFree(pSpec);
return ippStsNoMemErr;
}
/* Filter initialization */
status = ippiResizeLanczosInit_8u(srcSize, dstSize, 3, pSpec, pInitBuf);
ippsFree(pInitBuf);
if (status != ippStsNoErr) {
ippsFree(pSpec);
return status;
}
status = ippiResizeGetBorderSize_8u(pSpec, &borderSize);
if (status != ippStsNoErr) {
ippsFree(pSpec);
return status;
}
std::cout << "borderSize: {" << borderSize.borderLeft << ","
<< borderSize.borderTop << "," << borderSize.borderRight << ","
<< borderSize.borderBottom << "}" << std::endl;
ippiResizeGetBufferSize_8u(pSpec, dstSize, ippC1, &bufSize);
pBuffer = ippsMalloc_8u(bufSize);
status =
ippiResizeLanczos_8u_C1R(pSrc, srcStep, pDst, dstStep, dstOffset, dstSize,
border, pBorderValue, pSpec, pBuffer);
ippsFree(pBuffer);
ippsFree(pSpec);
return status;
}
IppStatus resizeExample_C1R(Ipp8u *pSrc, IppiSize srcSize, Ipp32s srcStep,
Ipp8u *pDst, IppiSize dstSize, Ipp32s dstStep) {
IppiResizeSpec_32f *pSpec = 0;
int specSize = 0, initSize = 0, bufSize = 0;
Ipp8u *pBuffer = 0;
Ipp8u *pInitBuf = 0;
Ipp32u numChannels = ippC1;
IppiPoint dstOffset = {0, 0};
IppStatus status = ippStsNoErr;
IppiBorderType border = ippBorderRepl;
/* Spec and init buffer sizes */
status = ippiResizeGetSize_8u(srcSize, dstSize, ippLanczos, 0, &specSize,
&initSize);
if (status != ippStsNoErr)
return status;
/* Memory allocation */
pInitBuf = ippsMalloc_8u(initSize);
pSpec = (IppiResizeSpec_32f *)ippsMalloc_8u(specSize);
if (pInitBuf == NULL || pSpec == NULL) {
ippsFree(pInitBuf);
ippsFree(pSpec);
return ippStsNoMemErr;
}
/* Filter initialization */
status = ippiResizeLanczosInit_8u(srcSize, dstSize, 3, pSpec, pInitBuf);
ippsFree(pInitBuf);
if (status != ippStsNoErr) {
ippsFree(pSpec);
return status;
}
/* work buffer size */
status = ippiResizeGetBufferSize_8u(pSpec, dstSize, numChannels, &bufSize);
if (status != ippStsNoErr) {
ippsFree(pSpec);
return status;
}
pBuffer = ippsMalloc_8u(bufSize);
if (pBuffer == NULL) {
ippsFree(pSpec);
return ippStsNoMemErr;
}
/* Resize processing */
status = ippiResizeLanczos_8u_C1R(pSrc, srcStep, pDst, dstStep, dstOffset,
dstSize, border, 0, pSpec, pBuffer);
ippsFree(pSpec);
ippsFree(pBuffer);
return status;
}
IppStatus Resize32f(Ipp32f *pSrc, IppiSize srcSize, Ipp32s srcStep,
Ipp32f *pDst, IppiSize dstSize, Ipp32s dstStep) {
IppStatus status;
// IppiPoint srcOffset = {0, 0};
IppiPoint dstOffset = {0, 0};
IppiBorderSize borderSize = {0, 0, 0, 0};
IppiBorderType border = ippBorderRepl;
const Ipp32f *pBorderValue = NULL;
IppiResizeSpec_32f *pSpec = 0;
int specSize = 0, initSize = 0, bufSize = 0;
Ipp8u *pBuffer = 0;
Ipp8u *pInitBuf = 0;
/* Spec and init buffer sizes */
status = ippiResizeGetSize_32f(srcSize, dstSize, ippLanczos, 0, &specSize,
&initSize);
if (status != ippStsNoErr)
return status;
/* Memory allocation */
pInitBuf = ippsMalloc_8u(initSize);
pSpec = (IppiResizeSpec_32f *)ippsMalloc_8u(specSize);
if (pInitBuf == NULL || pSpec == NULL) {
ippsFree(pInitBuf);
ippsFree(pSpec);
return ippStsNoMemErr;
}
/* Filter initialization */
status = ippiResizeLanczosInit_32f(srcSize, dstSize, 3, pSpec, pInitBuf);
ippsFree(pInitBuf);
if (status != ippStsNoErr) {
ippsFree(pSpec);
return status;
}
status = ippiResizeGetBorderSize_32f(pSpec, &borderSize);
if (status != ippStsNoErr) {
ippsFree(pSpec);
return status;
}
std::cout << "borderSize: {" << borderSize.borderLeft << ","
<< borderSize.borderTop << "," << borderSize.borderRight << ","
<< borderSize.borderBottom << "}" << std::endl;
ippiResizeGetBufferSize_32f(pSpec, dstSize, ippC1, &bufSize);
pBuffer = ippsMalloc_8u(bufSize);
status =
ippiResizeLanczos_32f_C1R(pSrc, srcStep, pDst, dstStep, dstOffset, dstSize,
border, pBorderValue, pSpec, pBuffer);
ippsFree(pBuffer);
ippsFree(pSpec);
return status;
}