Changeset 19058 for trunk/psLib/src/fft/psImageFFT.c
- Timestamp:
- Aug 13, 2008, 5:23:13 PM (18 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/fft/psImageFFT.c (modified) (16 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/fft/psImageFFT.c
r17377 r19058 6 6 /// @author Robert DeSonia, MHPCC 7 7 /// 8 /// @version $Revision: 1.2 6$ $Name: not supported by cvs2svn $9 /// @date $Date: 2008-0 4-08 01:25:42$8 /// @version $Revision: 1.27 $ $Name: not supported by cvs2svn $ 9 /// @date $Date: 2008-08-14 03:23:13 $ 10 10 /// 11 11 /// Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 20 20 #include <complex.h> 21 21 #include <fftw3.h> 22 #include <pthread.h> 22 23 23 24 #include "psAssert.h" … … 28 29 #include "psImageStructManip.h" 29 30 #include "psImageConvolve.h" 31 #include "psThread.h" 32 #include "psFFT.h" 30 33 #include "psImageFFT.h" 31 34 35 // Lock FFTW access 36 #define FFTW_LOCK \ 37 if (threaded) { \ 38 psFFTLock(); \ 39 } 40 // Unlock FFTW access 41 #define FFTW_UNLOCK \ 42 if (threaded) { \ 43 psFFTUnlock(); \ 44 } 32 45 33 46 #define FFTW_PLAN_RIGOR FFTW_ESTIMATE // How rigorous the FFTW planning is … … 42 55 PS_ASSERT_PTR_NON_NULL(imag, false); 43 56 57 bool threaded = psThreadPoolSize(); // Are we running threaded? 58 44 59 // Make sure the system-level wisdom information is imported. 60 FFTW_LOCK; 45 61 if (!fftwWisdomImported) { 46 62 fftwf_import_system_wisdom(); 47 63 fftwWisdomImported = true; 48 64 } 65 FFTW_UNLOCK; 49 66 50 67 int numCols = in->numCols; // Number of columns … … 64 81 65 82 // Do the FFT 83 84 FFTW_LOCK; 66 85 fftwf_complex *out = fftwf_malloc((numCols/2 + 1) * numRows * sizeof(fftwf_complex)); // Output data 67 86 fftwf_plan plan = fftwf_plan_dft_r2c_2d(numRows, numCols, input, out, FFTW_PLAN_RIGOR); 87 FFTW_UNLOCK; 88 68 89 fftwf_execute(plan); 90 91 FFTW_LOCK; 69 92 fftwf_destroy_plan(plan); 93 FFTW_UNLOCK; 94 70 95 psFree(input); 71 96 … … 87 112 } 88 113 } 114 115 FFTW_LOCK; 89 116 fftwf_free(out); 117 FFTW_UNLOCK; 90 118 91 119 return true; … … 101 129 PS_ASSERT_PTR_NON_NULL(out, false); 102 130 131 bool threaded = psThreadPoolSize(); // Are we running threaded? 132 103 133 int numCols = real->numCols; // Number of columns 104 134 int numRows = real->numRows; // Number of rows … … 120 150 } 121 151 122 123 152 // Make sure the system-level wisdom information is imported. 153 FFTW_LOCK; 124 154 if (!fftwWisdomImported) { 125 155 fftwf_import_system_wisdom(); 126 156 fftwWisdomImported = true; 127 157 } 158 FFTW_UNLOCK; 128 159 129 160 // Stuff the real and imaginary parts in 130 161 psF32 *target = psAlloc(2 * numCols * numRows * PSELEMTYPE_SIZEOF(PS_TYPE_F32)); // Target for FFTW 162 FFTW_LOCK; 131 163 fftwf_complex *in = fftwf_malloc(numCols * numRows * sizeof(fftwf_complex)); // Input data 164 FFTW_UNLOCK; 132 165 133 166 for (int y = 0, index = 0; y < numRows; y++) { … … 145 178 146 179 // Do the FFT 180 FFTW_LOCK; 147 181 fftwf_plan plan = fftwf_plan_dft_c2r_2d(numRows, origCols, in, target, FFTW_PLAN_RIGOR); 182 FFTW_UNLOCK; 183 148 184 fftwf_execute(plan); 185 186 FFTW_LOCK; 149 187 fftwf_destroy_plan(plan); 150 188 fftwf_free(in); 189 FFTW_UNLOCK; 151 190 152 191 // Copy the target pixels into the output … … 288 327 } 289 328 329 bool threaded = psThreadPoolSize(); // Are we running threaded? 330 290 331 int numCols = in->numCols, numRows = in->numRows; // Size of image 291 332 int xMin = kernel->xMin, xMax = kernel->xMax, yMin = kernel->yMin, yMax = kernel->yMax; // Kernel sizes … … 304 345 305 346 // Create data array containing the padded image and padded kernel 347 FFTW_LOCK; 306 348 psF32 *data = fftwf_malloc(2 * numPadded * PSELEMTYPE_SIZEOF(PS_TYPE_F32)); // Data for FFTW 349 FFTW_UNLOCK; 307 350 psF32 *dataPtr = data; // Pointer into FFTW data 308 351 psF32 **imageData = in->data.F32; // Pointer into image data … … 317 360 memset(dataPtr, 0, (paddedRows - numRows) * paddedCols * PSELEMTYPE_SIZEOF(PS_TYPE_F32)); 318 361 319 #if 1362 #if 0 320 363 { 321 364 // Use this for inspecting the result of copying the image … … 379 422 } 380 423 381 #if 1424 #if 0 382 425 { 383 426 // Use this for inspecting the result of copying the kernel … … 409 452 // Do the forward FFT 410 453 // Note that the FFT images have different size from the input 454 FFTW_LOCK; 411 455 fftwf_complex *fft = fftwf_malloc(2 * (paddedCols/2 + 1) * paddedRows * sizeof(fftwf_complex)); // FFT 456 FFTW_UNLOCK; 412 457 int size[] = { paddedRows, paddedCols }; // Size of transforms 413 458 int fftCols = paddedCols/2 + 1, fftRows = paddedRows; // Size of FFT images 414 459 int fftPixels = fftCols * fftRows; // Number of pixels in FFT image 460 461 FFTW_LOCK; 415 462 fftwf_plan forward = fftwf_plan_many_dft_r2c(2, size, 2, data, NULL, 1, paddedCols * paddedRows, 416 463 fft, NULL, 1, fftPixels, FFTW_PLAN_RIGOR); 464 FFTW_UNLOCK; 465 417 466 fftwf_execute(forward); 467 468 FFTW_LOCK; 418 469 fftwf_destroy_plan(forward); 470 FFTW_UNLOCK; 419 471 420 472 // Multiply the two transforms … … 434 486 435 487 // Do the backward FFT 488 FFTW_LOCK; 436 489 fftwf_plan backward = fftwf_plan_dft_c2r_2d(paddedRows, paddedCols, fft, data, FFTW_PLAN_RIGOR); 490 FFTW_UNLOCK; 491 437 492 fftwf_execute(backward); 493 494 FFTW_LOCK; 438 495 fftwf_destroy_plan(backward); 439 496 fftwf_free(fft); 497 FFTW_UNLOCK; 440 498 441 499 // Copy into the target, without the padding … … 446 504 memcpy(*outData, dataPtr, goodBytes); 447 505 } 506 507 FFTW_LOCK; 448 508 fftwf_free(data); 509 FFTW_UNLOCK; 449 510 450 511 return out;
Note:
See TracChangeset
for help on using the changeset viewer.
