Openholo  v1.0
Open Source Digital Holographic Library
Openholo.cpp
Go to the documentation of this file.
1 /*M///////////////////////////////////////////////////////////////////////////////////////
2 //
3 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
4 //
5 // By downloading, copying, installing or using the software you agree to this license.
6 // If you do not agree to this license, do not download, install, copy or use the software.
7 //
8 //
9 // License Agreement
10 // For Open Source Digital Holographic Library
11 //
12 // Openholo library is free software;
13 // you can redistribute it and/or modify it under the terms of the BSD 2-Clause license.
14 //
15 // Copyright (C) 2017-2024, Korea Electronics Technology Institute. All rights reserved.
16 // E-mail : contact.openholo@gmail.com
17 // Web : http://www.openholo.org
18 //
19 // Redistribution and use in source and binary forms, with or without modification,
20 // are permitted provided that the following conditions are met:
21 //
22 // 1. Redistribution's of source code must retain the above copyright notice,
23 // this list of conditions and the following disclaimer.
24 //
25 // 2. Redistribution's in binary form must reproduce the above copyright notice,
26 // this list of conditions and the following disclaimer in the documentation
27 // and/or other materials provided with the distribution.
28 //
29 // This software is provided by the copyright holders and contributors "as is" and
30 // any express or implied warranties, including, but not limited to, the implied
31 // warranties of merchantability and fitness for a particular purpose are disclaimed.
32 // In no event shall the copyright holder or contributors be liable for any direct,
33 // indirect, incidental, special, exemplary, or consequential damages
34 // (including, but not limited to, procurement of substitute goods or services;
35 // loss of use, data, or profits; or business interruption) however caused
36 // and on any theory of liability, whether in contract, strict liability,
37 // or tort (including negligence or otherwise) arising in any way out of
38 // the use of this software, even if advised of the possibility of such damage.
39 //
40 // This software contains opensource software released under GNU Generic Public License,
41 // NVDIA Software License Agreement, or CUDA supplement to Software License Agreement.
42 // Check whether software you use contains licensed software.
43 //
44 //M*/
45 
46 #include "Openholo.h"
47 
48 #include <windows.h>
49 #include <fileapi.h>
50 
51 #include "sys.h"
52 
53 #include "ImgCodecOhc.h"
54 #include "ImgEncoder.h"
55 
57  : Base()
58  , plan_fwd(nullptr)
59  , plan_bwd(nullptr)
60  , fft_in(nullptr)
61  , fft_out(nullptr)
62  , pnx(1)
63  , pny(1)
64  , pnz(1)
65  , fft_sign(OPH_FORWARD)
66  , OHC_encoder(nullptr)
67  , OHC_decoder(nullptr)
68  , complex_H(nullptr)
69 {
70  context_ = { 0 };
71 
74 }
75 
77 {
78 }
79 
80 bool Openholo::checkExtension(const char * fname, const char * ext)
81 {
82  string filename(fname);
83  string fext(ext);
84  if (0 == filename.substr(filename.find_last_of(".") + 1).compare(fext))
85  return true;
86  else
87  return false;
88 }
89 
90 bool Openholo::saveAsImg(const char * fname, uint8_t bitsperpixel, uchar* src, int width, int height)
91 {
92  LOG("Saving...%s...", fname);
93  bool bOK = true;
94  auto start = CUR_TIME;
95  int _width = width, _height = height;
96 
97  int _pixelbytesize = _height * _width * bitsperpixel / 8;
98  int _filesize = _pixelbytesize;
99  bool hasColorTable = (bitsperpixel <= 8) ? true : false;
100  int _headersize = sizeof(bitmap);
101  int _iColor = (hasColorTable) ? 256 : 0;
102 
103  if (hasColorTable)
104  _headersize += _iColor * sizeof(rgbquad);
105  _filesize += _headersize;
106 
107  rgbquad *table = nullptr;
108 
109  if (hasColorTable) {
110  table = new rgbquad[_iColor];
111  memset(table, 0, sizeof(rgbquad) * _iColor);
112  for (int i = 0; i < _iColor; i++) {
113  table[i].rgbBlue = i;
114  table[i].rgbGreen = i;
115  table[i].rgbRed = i;
116  }
117  }
118 
119  bool bConvert = false;
120  if (checkExtension(fname, ".jpg") ||
121  checkExtension(fname, ".jpeg") ||
122  checkExtension(fname, ".png") ||
123  checkExtension(fname, ".gif")) {
124  bConvert = true;
125  }
126 
127  unsigned char *pBitmap = new unsigned char[_filesize];
128  memset(pBitmap, 0x00, _filesize);
129 
130  bitmap bitmap;
131  memset(&bitmap, 0, sizeof(bitmap));
132  int iCur = 0;
133 
134  bitmap.fileheader.signature[0] = 'B';
135  bitmap.fileheader.signature[1] = 'M';
136  bitmap.fileheader.filesize = _filesize;
138 
140  bitmap.bitmapinfoheader.width = _width;
141  bitmap.bitmapinfoheader.height = _height;
143  bitmap.bitmapinfoheader.bitsperpixel = bitsperpixel;
145  bitmap.bitmapinfoheader.imagesize = _pixelbytesize;
149 
150  memcpy(&pBitmap[iCur], &bitmap.fileheader, sizeof(fileheader));
151  iCur += sizeof(fileheader);
152  memcpy(&pBitmap[iCur], &bitmap.bitmapinfoheader, sizeof(bitmapinfoheader));
153  iCur += sizeof(bitmapinfoheader);
154 
155  if (hasColorTable) {
156  memcpy(&pBitmap[iCur], table, sizeof(rgbquad) * _iColor);
157  iCur += sizeof(rgbquad) * _iColor;
158  }
159 
160  memcpy(&pBitmap[iCur], src, _pixelbytesize);
161  iCur += _pixelbytesize;
162 
163 
164  if (!bConvert) {
165  if (iCur != _filesize)
166  bOK = false;
167  else {
168  FILE *fp;
169  fopen_s(&fp, fname, "wb");
170  if (fp == nullptr)
171  bOK = false;
172  else {
173  fwrite(pBitmap, 1, _filesize, fp);
174  fclose(fp);
175  }
176  }
177  }
178  else {
179  if (checkExtension(fname, ".jpg") ||
180  checkExtension(fname, ".jpeg"))
181  ImgEncoder::getInstance()->SaveJPG(fname, pBitmap, _filesize);
182  else if(checkExtension(fname, ".png"))
183  ImgEncoder::getInstance()->SavePNG(fname, pBitmap, _filesize);
184  else if (checkExtension(fname, ".gif"))
185  ImgEncoder::getInstance()->SaveGIF(fname, pBitmap, _filesize);
186  }
187 
188  if(hasColorTable && table) delete[] table;
189  delete[] pBitmap;
190  auto end = CUR_TIME;
191 
192  auto during = ((std::chrono::duration<Real>)(end - start)).count();
193 
194  LOG("%.5lfsec...done\n", during);
195 
196  return bOK;
197 }
198 
199 uchar * Openholo::loadAsImg(const char * fname)
200 {
201  FILE *infile;
202  fopen_s(&infile, fname, "rb");
203  if (infile == nullptr) { LOG("No such file"); return 0; }
204 
205  // BMP Header Information
206  fileheader hf;
207  bitmapinfoheader hInfo;
208  fread(&hf, sizeof(fileheader), 1, infile);
209  if (hf.signature[0] != 'B' || hf.signature[1] != 'M') { LOG("Not BMP File"); return 0; }
210 
211  fread(&hInfo, sizeof(bitmapinfoheader), 1, infile);
212  fseek(infile, hf.fileoffset_to_pixelarray, SEEK_SET);
213 
214  oph::uchar *img_tmp;
215  if (hInfo.imagesize == 0) {
216  img_tmp = new uchar[hInfo.width*hInfo.height*(hInfo.bitsperpixel / 8)];
217  fread(img_tmp, sizeof(oph::uchar), hInfo.width*hInfo.height*(hInfo.bitsperpixel / 8), infile);
218  }
219  else {
220  img_tmp = new uchar[hInfo.imagesize];
221  fread(img_tmp, sizeof(oph::uchar), hInfo.imagesize, infile);
222  }
223  fclose(infile);
224 
225  return img_tmp;
226 }
227 
228 bool Openholo::saveAsOhc(const char * fname)
229 {
230  std::string fullname = fname;
231  if (!checkExtension(fname, ".ohc")) fullname.append(".ohc");
232  OHC_encoder->setFileName(fullname.c_str());
233 
234  // Clear vector
236 
237  ohcHeader header;
238  OHC_encoder->getOHCheader(header);
239  auto wavelength_num = header.fieldInfo.wavlenNum;
240 
241  for (uint i = 0; i < wavelength_num; i++)
243 
244  if (!OHC_encoder->save()) return false;
245 
246  return true;
247 }
248 
249 bool Openholo::loadAsOhc(const char * fname)
250 {
251  std::string fullname = fname;
252  if (!checkExtension(fname, ".ohc")) fullname.append(".ohc");
253  OHC_decoder->setFileName(fullname.c_str());
254  if (!OHC_decoder->load()) return false;
255 
258 
259  vector<Real> wavelengthArray;
260  OHC_decoder->getWavelength(wavelengthArray);
261  context_.wave_length = new Real[wavelengthArray.size()];
262  for (int i = 0; i < wavelengthArray.size(); i++)
263  context_.wave_length[i] = wavelengthArray[i];
264 
266 
267  context_.k = (2 * M_PI) / context_.wave_length[0];
270 
271  return true;
272 }
273 
274 bool Openholo::loadAsImgUpSideDown(const char * fname, uchar* dst)
275 {
276  FILE *infile;
277  fopen_s(&infile, fname, "rb");
278  if (infile == nullptr) { LOG("No such file"); return false; }
279 
280  // BMP Header Information
281  fileheader hf;
282  bitmapinfoheader hInfo;
283  fread(&hf, sizeof(fileheader), 1, infile);
284  if (hf.signature[0] != 'B' || hf.signature[1] != 'M') { LOG("Not BMP File"); return false; }
285 
286  fread(&hInfo, sizeof(bitmapinfoheader), 1, infile);
287  fseek(infile, hf.fileoffset_to_pixelarray, SEEK_SET);
288 
289  oph::uchar* img_tmp;
290  if (hInfo.imagesize == 0) {
291  img_tmp = new oph::uchar[hInfo.width*hInfo.height*(hInfo.bitsperpixel / 8)];
292  fread(img_tmp, sizeof(oph::uchar), hInfo.width*hInfo.height*(hInfo.bitsperpixel / 8), infile);
293  }
294  else {
295  img_tmp = new oph::uchar[hInfo.imagesize];
296  fread(img_tmp, sizeof(oph::uchar), hInfo.imagesize, infile);
297  }
298  fclose(infile);
299 
300  // data upside down
301  int bytesperpixel = hInfo.bitsperpixel / 8;
302  int rowsz = bytesperpixel * hInfo.width;
303 
304  for (oph::uint k = 0; k < hInfo.height*rowsz; k++) {
305  int r = k / rowsz;
306  int c = k % rowsz;
307  ((oph::uchar*)dst)[(hInfo.height - r - 1)*rowsz + c] = img_tmp[r*rowsz + c];
308  }
309 
310  delete[] img_tmp;
311 
312  return true;
313 }
314 
315 bool Openholo::getImgSize(int & w, int & h, int & bytesperpixel, const char * fname)
316 {
317  char bmpFile[256];
318  sprintf_s(bmpFile, "%s", fname);
319  FILE *infile;
320  fopen_s(&infile, bmpFile, "rb");
321  if (infile == NULL) { LOG("No Image File"); return false; }
322 
323  // BMP Header Information
324  fileheader hf;
325  bitmapinfoheader hInfo;
326  fread(&hf, sizeof(fileheader), 1, infile);
327  if (hf.signature[0] != 'B' || hf.signature[1] != 'M') return false;
328  fread(&hInfo, sizeof(bitmapinfoheader), 1, infile);
329  //if (hInfo.bitsperpixel != 8) { printf("Bad File Format!!"); return 0; }
330 
331  w = hInfo.width;
332  h = hInfo.height;
333  bytesperpixel = hInfo.bitsperpixel / 8;
334 
335  fclose(infile);
336 
337  return true;
338 }
339 
340 void Openholo::imgScaleBilnear(uchar* src, uchar* dst, int w, int h, int neww, int newh)
341 {
342  for (int y = 0; y < newh; y++)
343  {
344  for (int x = 0; x < neww; x++)
345  {
346  float gx = (x / (float)neww) * (w - 1);
347  float gy = (y / (float)newh) * (h - 1);
348 
349  int gxi = (int)gx;
350  int gyi = (int)gy;
351 
352  uint32_t a00 = src[gxi + 0 + gyi * w];
353  uint32_t a01 = src[gxi + 1 + gyi * w];
354  uint32_t a10 = src[gxi + 0 + (gyi + 1)*w];
355  uint32_t a11 = src[gxi + 1 + (gyi + 1)*w];
356 
357  float dx = gx - gxi;
358  float dy = gy - gyi;
359 
360  dst[x + y * neww] = int(a00 * (1 - dx)*(1 - dy) + a01 * dx*(1 - dy) + a10 * (1 - dx)*dy + a11 * dx*dy);
361 
362  }
363  }
364  LOG("Scaled img size: (%d/%d) => (%d/%d)\n", w, h, neww, newh);
365 }
366 
367 void Openholo::convertToFormatGray8(unsigned char * src, unsigned char * dst, int w, int h, int bytesperpixel)
368 {
369  int idx = 0;
370  unsigned int r = 0, g = 0, b = 0;
371  for (int i = 0; i < w*h*bytesperpixel; i++)
372  {
373  unsigned int r = src[i + 0];
374  unsigned int g = src[i + 1];
375  unsigned int b = src[i + 2];
376  dst[idx++] = (r + g + b) / 3;
377  i += bytesperpixel - 1;
378  }
379 }
380 
381 void Openholo::fft1(int n, Complex<Real>* in, int sign, uint flag)
382 {
383  pnx = n;
384  bool bIn = true;
385 
386  if (fft_in == nullptr)
387  fft_in = (fftw_complex*)fftw_malloc(sizeof(fftw_complex) * n);
388  if (fft_out == nullptr)
389  fft_out = (fftw_complex*)fftw_malloc(sizeof(fftw_complex) * n);
390 
391  if (!in){
392  in = new Complex<Real>[pnx];
393  bIn = false;
394  }
395 
396  for (int i = 0; i < n; i++) {
397  fft_in[i][_RE] = in[i].real();
398  fft_in[i][_IM] = in[i].imag();
399  }
400 
401  fft_sign = sign;
402 
403  if (!bIn) delete[] in;
404 
405  if (sign == OPH_FORWARD)
406  plan_fwd = fftw_plan_dft_1d(n, fft_in, fft_out, sign, flag);
407  else if (sign == OPH_BACKWARD)
408  plan_bwd = fftw_plan_dft_1d(n, fft_in, fft_out, sign, flag);
409  else {
410  LOG("failed fftw : wrong sign");
411  fftFree();
412  return;
413  }
414 }
415 
416 void Openholo::fft2(oph::ivec2 n, Complex<Real>* in, int sign, uint flag)
417 {
418  pnx = n[_X], pny = n[_Y];
419  bool bIn = true;
420  if(fft_in == nullptr)
421  fft_in = (fftw_complex*)fftw_malloc(sizeof(fftw_complex) * pnx * pny);
422  if(fft_out == nullptr)
423  fft_out = (fftw_complex*)fftw_malloc(sizeof(fftw_complex) * pnx * pny);
424 
425  if (!in) {
426  in = new Complex<Real>[pnx * pny];
427  bIn = false;
428  }
429  int i;
430 #ifdef _OPENMP
431 #pragma omp parallel for private(i)
432 #endif
433  for (i = 0; i < pnx * pny; i++) {
434  fft_in[i][_RE] = in[i].real();
435  fft_in[i][_IM] = in[i].imag();
436  }
437 
438  fft_sign = sign;
439 
440  if (!bIn) delete[] in;
441 
442  if (sign == OPH_FORWARD)
443  plan_fwd = fftw_plan_dft_2d(pny, pnx, fft_in, fft_out, sign, flag);
444  else if (sign == OPH_BACKWARD)
445  plan_bwd = fftw_plan_dft_2d(pny, pnx, fft_in, fft_out, sign, flag);
446  else {
447  LOG("failed fftw : wrong sign");
448  fftFree();
449  return;
450  }
451 }
452 
453 void Openholo::fft3(oph::ivec3 n, Complex<Real>* in, int sign, uint flag)
454 {
455  pnx = n[_X], pny = n[_Y], pnz = n[_Z];
456  bool bIn = true;
457  if (fft_in == nullptr)
458  fft_in = (fftw_complex*)fftw_malloc(sizeof(fftw_complex) * pnx * pny * pnz);
459  if (fft_out == nullptr)
460  fft_out = (fftw_complex*)fftw_malloc(sizeof(fftw_complex) * pnx * pny * pnz);
461 
462  if (!in) {
463  in = new Complex<Real>[pnx * pny * pnz];
464  bIn = false;
465  }
466 
467  for (int i = 0; i < pnx * pny * pnz; i++) {
468  fft_in[i][_RE] = in[i].real();
469  fft_in[i][_IM] = in[i].imag();
470  }
471 
472  fft_sign = sign;
473 
474  if (!bIn) delete[] in;
475 
476  if (sign == OPH_FORWARD)
477  plan_fwd = fftw_plan_dft_3d(pnz, pny, pnx, fft_in, fft_out, sign, flag);
478  else if (sign == OPH_BACKWARD)
479  plan_bwd = fftw_plan_dft_3d(pnz, pny, pnx, fft_in, fft_out, sign, flag);
480  else {
481  LOG("failed fftw : wrong sign");
482  fftFree();
483  return;
484  }
485 }
486 
487 void Openholo::fftExecute(Complex<Real>* out)
488 {
489  if (fft_sign == OPH_FORWARD)
490  fftw_execute(plan_fwd);
491  else if (fft_sign == OPH_BACKWARD)
492  fftw_execute(plan_bwd);
493  else {
494  LOG("failed fftw : wrong sign");
495  out = nullptr;
496  fftFree();
497  return;
498  }
499 
500  for (int i = 0; i < pnx * pny * pnz; i++) {
501  out[i][_RE] = fft_out[i][_RE];
502  out[i][_IM] = fft_out[i][_IM];
503  }
504 
505  fftFree();
506 }
507 
509 {
510  if (plan_fwd) {
511  fftw_destroy_plan(plan_fwd);
512  plan_fwd = nullptr;
513  }
514  if (plan_bwd) {
515  fftw_destroy_plan(plan_bwd);
516  plan_fwd = nullptr;
517  }
518  fftw_free(fft_in);
519  fftw_free(fft_out);
520 
521  plan_bwd = nullptr;
522  fft_in = nullptr;
523  fft_out = nullptr;
524 
525  pnx = 1;
526  pny = 1;
527  pnz = 1;
528 }
529 
530 void Openholo::fftwShift(Complex<Real>* src, Complex<Real>* dst, int nx, int ny, int type, bool bNormalized)
531 {
532  Complex<Real>* tmp = new Complex<Real>[nx*ny];
533  memset(tmp, 0., sizeof(Complex<Real>)*nx*ny);
534  fftShift(nx, ny, src, tmp);
535 
536  fftw_complex *in = (fftw_complex*)fftw_malloc(sizeof(fftw_complex) * nx * ny);
537  fftw_complex *out = (fftw_complex*)fftw_malloc(sizeof(fftw_complex) * nx * ny);
538 
539  for (int i = 0; i < nx*ny; i++) {
540  in[i][_RE] = tmp[i][_RE];
541  in[i][_IM] = tmp[i][_IM];
542  }
543 
544  fftw_plan plan = nullptr;
545  if (!plan_fwd && !plan_bwd) {
546  plan = fftw_plan_dft_2d(ny, nx, in, out, type, OPH_ESTIMATE);
547  fftw_execute(plan);
548  }
549  else {
550  if (type == OPH_FORWARD)
551  fftw_execute_dft(plan_fwd, in, out);
552  else if (type == OPH_BACKWARD)
553  fftw_execute_dft(plan_bwd, in, out);
554  }
555 
556  Real normalF = 1;
557  if (bNormalized) normalF = nx * ny;
558  memset(tmp, 0, sizeof(Complex<Real>)*nx*ny);
559 
560  for (int k = 0; k < nx*ny; k++) {
561  tmp[k][_RE] = out[k][_RE] / normalF;
562  tmp[k][_IM] = out[k][_IM] / normalF;
563  }
564 
565  fftw_free(in);
566  fftw_free(out);
567  if (plan)
568  fftw_destroy_plan(plan);
569 
570  memset(dst, 0, sizeof(Complex<Real>)*nx*ny);
571  fftShift(nx, ny, tmp, dst);
572  delete[] tmp;
573 }
574 
575 void Openholo::fftShift(int nx, int ny, Complex<Real>* input, Complex<Real>* output)
576 {
577  for (int i = 0; i < nx; i++)
578  {
579  for (int j = 0; j < ny; j++)
580  {
581  int ti = i - nx / 2; if (ti < 0) ti += nx;
582  int tj = j - ny / 2; if (tj < 0) tj += ny;
583 
584  output[ti + tj * nx] = input[i + j * nx];
585  }
586  }
587 }
588 
590 {
591  LOG("\n%s\n\n", __FUNCTION__);
592  ohcHeader header;
593  OHC_encoder->getOHCheader(header);
594  auto wavelength_num = header.fieldInfo.wavlenNum;
595  for (uint i = 0; i < wavelength_num; i++) {
596  if (complex_H[i])
597  delete[] complex_H[i];
598  }
599  if (complex_H) delete[] complex_H;
600 
602 
603  delete OHC_encoder;
604  delete OHC_decoder;
605 }
fileheader fileheader
Definition: struct.h:76
#define OPH_BACKWARD
Definition: define.h:67
uint32_t dibheadersize
Definition: struct.h:57
virtual bool saveAsImg(const char *fname, uint8_t bitsperpixel, uchar *src, int width, int height)
Function for creating image files.
Definition: Openholo.cpp:90
Real k
Definition: Openholo.h:66
Definition: Base.h:55
void fftFree(void)
Definition: Openholo.cpp:508
Real * wave_length
Definition: Openholo.h:69
unsigned char uchar
Definition: typedef.h:64
void fftShift(int nx, int ny, Complex< Real > *input, Complex< Real > *output)
Swap the top-left quadrant of data with the bottom-right , and the top-right quadrant with the bottom...
Definition: Openholo.cpp:575
ohcFieldInfoHeader fieldInfo
float Real
Definition: typedef.h:55
#define X_PIXEL_PER_METER
Definition: define.h:147
#define CUR_TIME
Definition: function.h:58
static ImgEncoder * getInstance()
Definition: ImgEncoder.h:13
void fft3(ivec3 n, Complex< Real > *in, int sign=OPH_FORWARD, uint flag=OPH_ESTIMATE)
Functions for performing fftw 3-dimension operations inside Openholo.
Definition: Openholo.cpp:453
vec2 ss
Definition: Openholo.h:67
bool checkExtension(const char *fname, const char *ext)
Functions for extension checking.
Definition: Openholo.cpp:80
#define OPH_ESTIMATE
Definition: define.h:76
void getOHCheader(ohcHeader &_Header)
#define _Y
Definition: define.h:84
#define _IM
Definition: complex.h:57
#define Y_PIXEL_PER_METER
Definition: define.h:148
ImgEncoderOhc * OHC_encoder
OHC file format Variables for read and write.
Definition: Openholo.h:304
uint32_t imagesize
Definition: struct.h:63
void getComplexFieldData(OphComplexField &cmplx_field, uint wavelen_idx)
Definition: ImgCodecOhc.h:81
ImgDecoderOhc * OHC_decoder
Definition: Openholo.h:305
#define _X
Definition: define.h:80
Definition: struct.h:69
Definition: struct.h:75
virtual void releaseFldData()
void addComplexFieldData(const OphComplexField &data)
uint8_t rgbGreen
Definition: struct.h:71
bool getImgSize(int &w, int &h, int &bytesperpixel, const char *fname)
Function for getting the image size.
Definition: Openholo.cpp:315
uint16_t bitsperpixel
Definition: struct.h:61
bool SaveGIF(const char *path, BYTE *pBuf, UINT len)
Definition: ImgEncoder.cpp:71
oph::ivec2 pixel_number
Definition: Openholo.h:63
#define _RE
Definition: complex.h:54
void fft2(ivec2 n, Complex< Real > *in, int sign=OPH_FORWARD, uint flag=OPH_ESTIMATE)
Functions for performing fftw 2-dimension operations inside Openholo.
Definition: Openholo.cpp:416
uint8_t rgbBlue
Definition: struct.h:70
void convertToFormatGray8(uchar *src, uchar *dst, int w, int h, int bytesperpixel)
Function for convert image format to gray8.
Definition: Openholo.cpp:367
virtual ~Openholo(void)=0
Destructor.
Definition: Openholo.cpp:76
bool SavePNG(const char *path, BYTE *pBuf, UINT len)
Definition: ImgEncoder.cpp:45
bitmapinfoheader bitmapinfoheader
Definition: struct.h:77
uint32_t ypixelpermeter
Definition: struct.h:64
uint32_t numcolorspallette
Definition: struct.h:66
bool setFileName(const std::string &_fname)
Definition: ImgCodecOhc.cpp:90
bool SaveJPG(const char *path, BYTE *pBuf, UINT len)
Definition: ImgEncoder.cpp:18
void imgScaleBilnear(uchar *src, uchar *dst, int w, int h, int neww, int newh)
Function for change image size.
Definition: Openholo.cpp:340
virtual bool loadAsOhc(const char *fname)
Function to read OHC file.
Definition: Openholo.cpp:249
uint32_t filesize
Definition: struct.h:52
Openholo(void)
Constructor.
Definition: Openholo.cpp:56
void fftExecute(Complex< Real > *out)
Execution functions to be called after fft1, fft2, and fft3.
Definition: Openholo.cpp:487
uint32_t fileoffset_to_pixelarray
Definition: struct.h:54
uint8_t rgbRed
Definition: struct.h:72
uint32_t width
Definition: struct.h:58
virtual uchar * loadAsImg(const char *fname)
Function for loading image files.
Definition: Openholo.cpp:199
uint32_t height
Definition: struct.h:59
virtual bool saveAsOhc(const char *fname)
Function to write OHC file
Definition: Openholo.cpp:228
uint16_t planes
Definition: struct.h:60
#define OPH_COMPRESSION
Definition: define.h:146
void fftwShift(Complex< Real > *src, Complex< Real > *dst, int nx, int ny, int type, bool bNormalized=false)
Convert data from the spatial domain to the frequency domain using 2D FFT on CPU. ...
Definition: Openholo.cpp:530
OphConfig context_
Definition: Openholo.h:297
#define OPH_FORWARD
Definition: define.h:66
Complex< Real > ** complex_H
Definition: Openholo.h:298
uint8_t signature[2]
Definition: struct.h:51
#define OPH_PLANES
Definition: define.h:145
#define _Z
Definition: define.h:88
void fft1(int n, Complex< Real > *in, int sign=OPH_FORWARD, uint flag=OPH_ESTIMATE)
Functions for performing fftw 1-dimension operations inside Openholo.
Definition: Openholo.cpp:381
bool loadAsImgUpSideDown(const char *fname, uchar *dst)
Function for loading image files | Output image data upside down.
Definition: Openholo.cpp:274
void getWavelength(std::vector< double_t > &wavlen_array)
uint32_t compression
Definition: struct.h:62
unsigned int uint
Definition: typedef.h:62
virtual void ophFree(void)
Pure virtual function for override in child classes.
Definition: Openholo.cpp:589
uint32_t xpixelpermeter
Definition: struct.h:65
#define M_PI
Definition: define.h:52
oph::vec2 pixel_pitch
Definition: Openholo.h:64