Openholo  beta 2.0
Open Source Digital Holographic Library
Openholo Class Referenceabstract

Abstract class Top class of Openholo library. Common functions required by subclasses are implemented. More...

Inheritance diagram for Openholo:
Inheritance graph

Public Member Functions

 Openholo (void)
 Constructor. More...
 
virtual int saveAsImg (const char *fname, uint8_t bitsperpixel, uchar *src, int pic_width, int pic_height)
 Function for creating image files. More...
 
virtual uchar * loadAsImg (const char *fname)
 Function for loading image files. More...
 
virtual int saveAsOhc (const char *fname)
 Function to write OHC file. More...
 
virtual int loadAsOhc (const char *fname)
 Function to read OHC file. More...
 
 Openholo (void)
 Constructor. More...
 
virtual int saveAsImg (const char *fname, uint8_t bitsperpixel, uchar *src, int pic_width, int pic_height)
 Function for creating image files. More...
 
virtual uchar * loadAsImg (const char *fname)
 Function for loading image files. More...
 
virtual int saveAsOhc (const char *fname)
 Function to write OHC file. More...
 
virtual int loadAsOhc (const char *fname)
 Function to read OHC file. More...
 
unsigned long addRef (void)
 If referenced this(Base's child, not abstract class) instance, must call this method. More...
 
unsigned long addRef (void)
 If referenced this(Base's child, not abstract class) instance, must call this method. More...
 
unsigned long release (void)
 Call release() when reference is finished. More...
 
unsigned long release (void)
 Call release() when reference is finished. More...
 

Protected Member Functions

virtual ~Openholo (void)=0
 Destructor Pure virtual function for class abstraction. More...
 
int checkExtension (const char *fname, const char *ext)
 Functions for extension checking. More...
 
int loadAsImgUpSideDown (const char *fname, uchar *dst)
 Function for loading image files | Output image data upside down. More...
 
int getImgSize (int &w, int &h, int &bytesperpixel, const char *file_name)
 Function for getting the image size. More...
 
void imgScaleBilnear (unsigned char *src, unsigned char *dst, int w, int h, int neww, int newh)
 Function for change image size. More...
 
void convertToFormatGray8 (unsigned char *src, unsigned char *dst, int w, int h, int bytesperpixel)
 Function for convert image format to gray8. More...
 
void fft1 (int n, Complex< Real > *in, int sign=OPH_FORWARD, uint flag=OPH_ESTIMATE)
 Functions for performing fftw 1-dimension operations inside Openholo. More...
 
void fft2 (oph::ivec2 n, Complex< Real > *in, int sign=OPH_FORWARD, uint flag=OPH_ESTIMATE)
 Functions for performing fftw 2-dimension operations inside Openholo. More...
 
void fft3 (oph::ivec3 n, Complex< Real > *in, int sign=OPH_FORWARD, uint flag=OPH_ESTIMATE)
 Functions for performing fftw 3-dimension operations inside Openholo. More...
 
void fftExecute (Complex< Real > *out)
 Execution functions to be called after fft1, fft2, and fft3. More...
 
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. More...
 
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-left. More...
 
virtual void ophFree (void)
 Pure virtual function for override in child classes. More...
 
void setPixelNumberOHC (const ivec2 pixel_number)
 getter/setter for OHC file read and write More...
 
void addWaveLengthNComplexFieldDataOHC (const Real wavelength, const OphComplexField &complex_field)
 Function to add ComplexField when adding wavelength data. More...
 
virtual ~Openholo (void)=0
 Destructor Pure virtual function for class abstraction. More...
 
int checkExtension (const char *fname, const char *ext)
 Functions for extension checking. More...
 
int loadAsImgUpSideDown (const char *fname, uchar *dst)
 Function for loading image files | Output image data upside down. More...
 
int getImgSize (int &w, int &h, int &bytesperpixel, const char *file_name)
 Function for getting the image size. More...
 
void imgScaleBilnear (unsigned char *src, unsigned char *dst, int w, int h, int neww, int newh)
 Function for change image size. More...
 
void convertToFormatGray8 (unsigned char *src, unsigned char *dst, int w, int h, int bytesperpixel)
 Function for convert image format to gray8. More...
 
void fft1 (int n, Complex< Real > *in, int sign=OPH_FORWARD, uint flag=OPH_ESTIMATE)
 Functions for performing fftw 1-dimension operations inside Openholo. More...
 
void fft2 (oph::ivec2 n, Complex< Real > *in, int sign=OPH_FORWARD, uint flag=OPH_ESTIMATE)
 Functions for performing fftw 2-dimension operations inside Openholo. More...
 
void fft3 (oph::ivec3 n, Complex< Real > *in, int sign=OPH_FORWARD, uint flag=OPH_ESTIMATE)
 Functions for performing fftw 3-dimension operations inside Openholo. More...
 
void fftExecute (Complex< Real > *out)
 Execution functions to be called after fft1, fft2, and fft3. More...
 
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. More...
 
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-left. More...
 
virtual void ophFree (void)
 Pure virtual function for override in child classes. More...
 
void setPixelNumberOHC (const ivec2 pixel_number)
 getter/setter for OHC file read and write More...
 
void addWaveLengthNComplexFieldDataOHC (const Real wavelength, const OphComplexField &complex_field)
 Function to add ComplexField when adding wavelength data. More...
 

Protected Attributes

ImgEncoderOhc * OHC_encoder
 OHC file format Variables for read and write. More...
 

Detailed Description

Abstract class Top class of Openholo library. Common functions required by subclasses are implemented.

Author
Kim Ryeon-woo

Definition at line 83 of file openholo/src/Openholo.h.

Constructor & Destructor Documentation

◆ Openholo() [1/2]

Openholo::Openholo ( void  )
explicit

Constructor.

Definition at line 55 of file Openholo.cpp.

56  : Base()
57  , plan_fwd(nullptr)
58  , plan_bwd(nullptr)
59  , fft_in(nullptr)
60  , fft_out(nullptr)
61  , pnx(1)
62  , pny(1)
63  , pnz(1)
64  , fft_sign(OPH_FORWARD)
65  , OHC_encoder(nullptr)
66  , OHC_decoder(nullptr)
67  , complex_H(nullptr)
68 {
69  context_ = { 0 };
70 
71  OHC_encoder = new oph::ImgEncoderOhc;
72  OHC_decoder = new oph::ImgDecoderOhc;
73 }
ImgEncoderOhc * OHC_encoder
OHC file format Variables for read and write.

◆ ~Openholo() [1/2]

Openholo::~Openholo ( void  )
protectedpure virtual

Destructor Pure virtual function for class abstraction.

Definition at line 75 of file Openholo.cpp.

76 {
77 }

◆ Openholo() [2/2]

Openholo::Openholo ( void  )
explicit

Constructor.

◆ ~Openholo() [2/2]

virtual Openholo::~Openholo ( void  )
protectedpure virtual

Destructor Pure virtual function for class abstraction.

Member Function Documentation

◆ addRef() [1/2]

unsigned long Base::addRef ( void  )
inlineinherited

If referenced this(Base's child, not abstract class) instance, must call this method.

Definition at line 75 of file openholo/src/Base.h.

75 { return ++refCnt; }

◆ addRef() [2/2]

unsigned long Base::addRef ( void  )
inlineinherited

If referenced this(Base's child, not abstract class) instance, must call this method.

Definition at line 75 of file Reference/include/Base.h.

75 { return ++refCnt; }

◆ addWaveLengthNComplexFieldDataOHC() [1/2]

void Openholo::addWaveLengthNComplexFieldDataOHC ( const Real  wavelength,
const OphComplexField &  complex_field 
)
inlineprotected

Function to add ComplexField when adding wavelength data.

Definition at line 297 of file openholo/src/Openholo.h.

298  { OHC_encoder->addWavelengthNComplexFieldData(wavelength, complex_field); }
ImgEncoderOhc * OHC_encoder
OHC file format Variables for read and write.

◆ addWaveLengthNComplexFieldDataOHC() [2/2]

void Openholo::addWaveLengthNComplexFieldDataOHC ( const Real  wavelength,
const OphComplexField &  complex_field 
)
inlineprotected

Function to add ComplexField when adding wavelength data.

Definition at line 297 of file Reference/include/Openholo.h.

298  { OHC_encoder->addWavelengthNComplexFieldData(wavelength, complex_field); }
ImgEncoderOhc * OHC_encoder
OHC file format Variables for read and write.

◆ checkExtension() [1/2]

int Openholo::checkExtension ( const char *  fname,
const char *  ext 
)
protected

Functions for extension checking.

Parameters
constchar* File name
constchar* File extension
Returns
int return 0 : The extension of "fname" and "ext" is the same return 1 : The extension of "fname" and "ext" is not the same

Definition at line 79 of file Openholo.cpp.

80 {
81  //return 1 : the extension of "fname" and "ext" is the same
82  // 0 : the extension of "fname" and "ext" is not the same
83 
84  std::string filename(fname);
85  size_t pos = filename.find(ext);
86  if (pos == std::string::npos)
87  //when there is no search string
88  return 0;
89  else
90  return 1;
91 }

◆ checkExtension() [2/2]

int Openholo::checkExtension ( const char *  fname,
const char *  ext 
)
protected

Functions for extension checking.

Parameters
constchar* File name
constchar* File extension
Returns
int return 0 : The extension of "fname" and "ext" is the same return 1 : The extension of "fname" and "ext" is not the same

◆ convertToFormatGray8() [1/2]

void Openholo::convertToFormatGray8 ( unsigned char *  src,
unsigned char *  dst,
int  w,
int  h,
int  bytesperpixel 
)
protected

Function for convert image format to gray8.

Parameters
unsignedchar* Source image data
unsignedchar* Dest image data
intImage size, width
intImage size, Height
intBytes per pixel

Definition at line 310 of file Openholo.cpp.

311 {
312  int idx = 0;
313  unsigned int r = 0, g = 0, b = 0;
314  for (int i = 0; i < w*h*bytesperpixel; i++)
315  {
316  unsigned int r = src[i + 0];
317  unsigned int g = src[i + 1];
318  unsigned int b = src[i + 2];
319  dst[idx++] = (r + g + b) / 3;
320  i += bytesperpixel - 1;
321  }
322 }

◆ convertToFormatGray8() [2/2]

void Openholo::convertToFormatGray8 ( unsigned char *  src,
unsigned char *  dst,
int  w,
int  h,
int  bytesperpixel 
)
protected

Function for convert image format to gray8.

Parameters
unsignedchar* Source image data
unsignedchar* Dest image data
intImage size, width
intImage size, Height
intBytes per pixel

◆ fft1() [1/2]

void Openholo::fft1 ( int  n,
Complex< Real > *  in,
int  sign = OPH_FORWARD,
uint  flag = OPH_ESTIMATE 
)
protected

Functions for performing fftw 1-dimension operations inside Openholo.

Parameters
intNumber of data
Complex<Real>*Source of data
intSign of FFTW(FORWARD or BACKWARD)
unsignedint Flag of FFTW(MEASURE, DESTROY_INPUT, UNALIGNED, CONSERVE_MEMORY, EXHAUSTIVE, PRESERVE_INPUT, PATIENT, ESTIMATE, WISDOM_ONLY)

Definition at line 324 of file Openholo.cpp.

325 {
326  pnx = n;
327  bool bIn = true;
328 
329  fft_in = (fftw_complex*)fftw_malloc(sizeof(fftw_complex) * n);
330  fft_out = (fftw_complex*)fftw_malloc(sizeof(fftw_complex) * n);
331 
332  if (!in){
333  in = new Complex<Real>[pnx];
334  bIn = false;
335  }
336 
337  for (int i = 0; i < n; i++) {
338  fft_in[i][_RE] = in[i].real();
339  fft_in[i][_IM] = in[i].imag();
340  }
341 
342  fft_sign = sign;
343 
344  if (!bIn) delete[] in;
345 
346  if (sign == OPH_FORWARD)
347  plan_fwd = fftw_plan_dft_1d(n, fft_in, fft_out, sign, flag);
348  else if (sign == OPH_BACKWARD)
349  plan_bwd = fftw_plan_dft_1d(n, fft_in, fft_out, sign, flag);
350  else {
351  LOG("failed fftw : wrong sign");
352  fftFree();
353  return;
354  }
355 }

◆ fft1() [2/2]

void Openholo::fft1 ( int  n,
Complex< Real > *  in,
int  sign = OPH_FORWARD,
uint  flag = OPH_ESTIMATE 
)
protected

Functions for performing fftw 1-dimension operations inside Openholo.

Parameters
intNumber of data
Complex<Real>*Source of data
intSign of FFTW(FORWARD or BACKWARD)
unsignedint Flag of FFTW(MEASURE, DESTROY_INPUT, UNALIGNED, CONSERVE_MEMORY, EXHAUSTIVE, PRESERVE_INPUT, PATIENT, ESTIMATE, WISDOM_ONLY)

◆ fft2() [1/2]

void Openholo::fft2 ( oph::ivec2  n,
Complex< Real > *  in,
int  sign = OPH_FORWARD,
uint  flag = OPH_ESTIMATE 
)
protected

Functions for performing fftw 2-dimension operations inside Openholo.

Parameters
oph::ivec2Number of data(int x, int y)
Complex<Real>*Source of data
intSign of FFTW(FORWARD or BACKWARD)
unsignedint Flag of FFTW(MEASURE, DESTROY_INPUT, UNALIGNED, CONSERVE_MEMORY, EXHAUSTIVE, PRESERVE_INPUT, PATIENT, ESTIMATE, WISDOM_ONLY)

Definition at line 357 of file Openholo.cpp.

358 {
359  pnx = n[_X], pny = n[_Y];
360  bool bIn = true;
361 
362  fft_in = (fftw_complex*)fftw_malloc(sizeof(fftw_complex) * pnx * pny);
363  fft_out = (fftw_complex*)fftw_malloc(sizeof(fftw_complex) * pnx * pny);
364 
365  if (!in) {
366  in = new Complex<Real>[pnx * pny];
367  bIn = false;
368  }
369 
370  for (int i = 0; i < pnx * pny; i++) {
371  fft_in[i][_RE] = in[i].real();
372  fft_in[i][_IM] = in[i].imag();
373  }
374 
375  fft_sign = sign;
376 
377  if (!bIn) delete[] in;
378 
379  if (sign == OPH_FORWARD)
380  plan_fwd = fftw_plan_dft_2d(pny, pnx, fft_in, fft_out, sign, flag);
381  else if (sign == OPH_BACKWARD)
382  plan_bwd = fftw_plan_dft_2d(pny, pnx, fft_in, fft_out, sign, flag);
383  else {
384  LOG("failed fftw : wrong sign");
385  fftFree();
386  return;
387  }
388 }

◆ fft2() [2/2]

void Openholo::fft2 ( oph::ivec2  n,
Complex< Real > *  in,
int  sign = OPH_FORWARD,
uint  flag = OPH_ESTIMATE 
)
protected

Functions for performing fftw 2-dimension operations inside Openholo.

Parameters
oph::ivec2Number of data(int x, int y)
Complex<Real>*Source of data
intSign of FFTW(FORWARD or BACKWARD)
unsignedint Flag of FFTW(MEASURE, DESTROY_INPUT, UNALIGNED, CONSERVE_MEMORY, EXHAUSTIVE, PRESERVE_INPUT, PATIENT, ESTIMATE, WISDOM_ONLY)

◆ fft3() [1/2]

void Openholo::fft3 ( oph::ivec3  n,
Complex< Real > *  in,
int  sign = OPH_FORWARD,
uint  flag = OPH_ESTIMATE 
)
protected

Functions for performing fftw 3-dimension operations inside Openholo.

Parameters
oph::ivec3Number of data(int x, int y, int z)
Complex<Real>*Source of data
intSign of FFTW(FORWARD or BACKWARD)
unsignedint Flag of FFTW(MEASURE, DESTROY_INPUT, UNALIGNED, CONSERVE_MEMORY, EXHAUSTIVE, PRESERVE_INPUT, PATIENT, ESTIMATE, WISDOM_ONLY)

Definition at line 390 of file Openholo.cpp.

391 {
392  pnx = n[_X], pny = n[_Y], pnz = n[_Z];
393  bool bIn = true;
394 
395  fft_in = (fftw_complex*)fftw_malloc(sizeof(fftw_complex) * pnx * pny * pnz);
396  fft_out = (fftw_complex*)fftw_malloc(sizeof(fftw_complex) * pnx * pny * pnz);
397 
398  if (!in) {
399  in = new Complex<Real>[pnx * pny * pnz];
400  bIn = false;
401  }
402 
403  for (int i = 0; i < pnx * pny * pnz; i++) {
404  fft_in[i][_RE] = in[i].real();
405  fft_in[i][_IM] = in[i].imag();
406  }
407 
408  fft_sign = sign;
409 
410  if (!bIn) delete[] in;
411 
412  if (sign == OPH_FORWARD)
413  plan_fwd = fftw_plan_dft_3d(pnz, pny, pnx, fft_in, fft_out, sign, flag);
414  else if (sign == OPH_BACKWARD)
415  plan_bwd = fftw_plan_dft_3d(pnz, pny, pnx, fft_in, fft_out, sign, flag);
416  else {
417  LOG("failed fftw : wrong sign");
418  fftFree();
419  return;
420  }
421 }

◆ fft3() [2/2]

void Openholo::fft3 ( oph::ivec3  n,
Complex< Real > *  in,
int  sign = OPH_FORWARD,
uint  flag = OPH_ESTIMATE 
)
protected

Functions for performing fftw 3-dimension operations inside Openholo.

Parameters
oph::ivec3Number of data(int x, int y, int z)
Complex<Real>*Source of data
intSign of FFTW(FORWARD or BACKWARD)
unsignedint Flag of FFTW(MEASURE, DESTROY_INPUT, UNALIGNED, CONSERVE_MEMORY, EXHAUSTIVE, PRESERVE_INPUT, PATIENT, ESTIMATE, WISDOM_ONLY)

◆ fftExecute() [1/2]

void Openholo::fftExecute ( Complex< Real > *  out)
protected

Execution functions to be called after fft1, fft2, and fft3.

Parameters
Complex<Real>*Dest of data

Definition at line 423 of file Openholo.cpp.

424 {
425  if (fft_sign == OPH_FORWARD)
426  fftw_execute(plan_fwd);
427  else if (fft_sign == OPH_BACKWARD)
428  fftw_execute(plan_bwd);
429  else {
430  LOG("failed fftw : wrong sign");
431  out = nullptr;
432  fftFree();
433  return;
434  }
435 
436  for (int i = 0; i < pnx * pny * pnz; i++) {
437  out[i][_RE] = fft_out[i][_RE];
438  out[i][_IM] = fft_out[i][_IM];
439  }
440 
441  fftFree();
442 }

◆ fftExecute() [2/2]

void Openholo::fftExecute ( Complex< Real > *  out)
protected

Execution functions to be called after fft1, fft2, and fft3.

Parameters
Complex<Real>*Dest of data

◆ fftShift() [1/2]

void Openholo::fftShift ( int  nx,
int  ny,
Complex< Real > *  input,
Complex< Real > *  output 
)
protected

Swap the top-left quadrant of data with the bottom-right , and the top-right quadrant with the bottom-left.

Parameters
intthe number of column of the input data
intthe number of row of the input data
Complex<Real>*input data variable
Complex<Real>*output data variable

◆ fftShift() [2/2]

void Openholo::fftShift ( int  nx,
int  ny,
Complex< Real > *  input,
Complex< Real > *  output 
)
protected

Swap the top-left quadrant of data with the bottom-right , and the top-right quadrant with the bottom-left.

Parameters
intthe number of column of the input data
intthe number of row of the input data
Complex<Real>*input data variable
Complex<Real>*output data variable

Definition at line 511 of file Openholo.cpp.

512 {
513  for (int i = 0; i < nx; i++)
514  {
515  for (int j = 0; j < ny; j++)
516  {
517  int ti = i - nx / 2; if (ti < 0) ti += nx;
518  int tj = j - ny / 2; if (tj < 0) tj += ny;
519 
520  output[ti + tj * nx] = input[i + j * nx];
521  }
522  }
523 }

◆ fftwShift() [1/2]

void Openholo::fftwShift ( Complex< Real > *  src,
Complex< Real > *  dst,
int  nx,
int  ny,
int  type,
bool  bNormalized = false 
)
protected

Convert data from the spatial domain to the frequency domain using 2D FFT on CPU.

Parameters
Complex<Real>*Input data variable
Complex<Real>*Output data variable
intthe number of column of the input data
intthe number of row of the input data
intIf type == 1, forward FFT, if type == -1, backward FFT.
boolIf bNomarlized == true, normalize the result after FFT.

Definition at line 466 of file Openholo.cpp.

467 {
468  Complex<Real>* tmp = new Complex<Real>[nx*ny];
469  memset(tmp, 0, sizeof(Complex<Real>)*nx*ny);
470  fftShift(nx, ny, src, tmp);
471 
472  fftw_complex *in = (fftw_complex*)fftw_malloc(sizeof(fftw_complex) * nx * ny);
473  fftw_complex *out = (fftw_complex*)fftw_malloc(sizeof(fftw_complex) * nx * ny);
474 
475  for (int i = 0; i < nx*ny; i++) {
476  in[i][_RE] = tmp[i][_RE];
477  in[i][_IM] = tmp[i][_IM];
478  }
479 
480  fftw_plan plan = nullptr;
481  if (!plan_fwd && !plan_bwd) {
482  plan = fftw_plan_dft_2d(ny, nx, in, out, type, OPH_ESTIMATE);
483  fftw_execute(plan);
484  }
485  else {
486  if (type == OPH_FORWARD)
487  fftw_execute_dft(plan_fwd, in, out);
488  else if (type == OPH_BACKWARD)
489  fftw_execute_dft(plan_bwd, in, out);
490  }
491 
492  int normalF = 1;
493  if (bNormalized) normalF = nx * ny;
494  memset(tmp, 0, sizeof(Complex<Real>)*nx*ny);
495 
496  for (int k = 0; k < nx*ny; k++) {
497  tmp[k][_RE] = out[k][_RE] / normalF;
498  tmp[k][_IM] = out[k][_IM] / normalF;
499  }
500 
501  fftw_free(in);
502  fftw_free(out);
503  if (plan)
504  fftw_destroy_plan(plan);
505 
506  memset(dst, 0, sizeof(Complex<Real>)*nx*ny);
507  fftShift(nx, ny, tmp, dst);
508  delete[] tmp;
509 }
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:511

◆ fftwShift() [2/2]

void Openholo::fftwShift ( Complex< Real > *  src,
Complex< Real > *  dst,
int  nx,
int  ny,
int  type,
bool  bNormalized = false 
)
protected

Convert data from the spatial domain to the frequency domain using 2D FFT on CPU.

Parameters
Complex<Real>*Input data variable
Complex<Real>*Output data variable
intthe number of column of the input data
intthe number of row of the input data
intIf type == 1, forward FFT, if type == -1, backward FFT.
boolIf bNomarlized == true, normalize the result after FFT.

◆ getImgSize() [1/2]

int Openholo::getImgSize ( int &  w,
int &  h,
int &  bytesperpixel,
const char *  file_name 
)
protected

Function for getting the image size.

Parameters
int&Image size - width
int&Image size - Height
int&Bytes per pixel
constchar* Input file name

Definition at line 259 of file Openholo.cpp.

260 {
261  char bmpFile[256];
262  sprintf_s(bmpFile, "%s", file_name);
263  FILE *infile;
264  fopen_s(&infile, bmpFile, "rb");
265  if (infile == NULL) { LOG("No Image File"); return 0; }
266 
267  // BMP Header Information
268  fileheader hf;
269  bitmapinfoheader hInfo;
270  fread(&hf, sizeof(fileheader), 1, infile);
271  if (hf.signature[0] != 'B' || hf.signature[1] != 'M') return 0;
272  fread(&hInfo, sizeof(bitmapinfoheader), 1, infile);
273  //if (hInfo.bitsperpixel != 8) { printf("Bad File Format!!"); return 0; }
274 
275  w = hInfo.width;
276  h = hInfo.height;
277  bytesperpixel = hInfo.bitsperpixel / 8;
278 
279  fclose(infile);
280 
281  return 1;
282 }

◆ getImgSize() [2/2]

int Openholo::getImgSize ( int &  w,
int &  h,
int &  bytesperpixel,
const char *  file_name 
)
protected

Function for getting the image size.

Parameters
int&Image size - width
int&Image size - Height
int&Bytes per pixel
constchar* Input file name

◆ imgScaleBilnear() [1/2]

void Openholo::imgScaleBilnear ( unsigned char *  src,
unsigned char *  dst,
int  w,
int  h,
int  neww,
int  newh 
)
protected

Function for change image size.

Parameters
unsignedchar* Source image data
unsignedchar* Dest image data
intOriginal width
intOriginal height
intWidth to replace
intHeight to replace

Definition at line 284 of file Openholo.cpp.

285 {
286  for (int y = 0; y < newh; y++)
287  {
288  for (int x = 0; x < neww; x++)
289  {
290  float gx = (x / (float)neww) * (w - 1);
291  float gy = (y / (float)newh) * (h - 1);
292 
293  int gxi = (int)gx;
294  int gyi = (int)gy;
295 
296  uint32_t a00 = src[gxi + 0 + gyi * w];
297  uint32_t a01 = src[gxi + 1 + gyi * w];
298  uint32_t a10 = src[gxi + 0 + (gyi + 1)*w];
299  uint32_t a11 = src[gxi + 1 + (gyi + 1)*w];
300 
301  float dx = gx - gxi;
302  float dy = gy - gyi;
303 
304  dst[x + y * neww] = int(a00 * (1 - dx)*(1 - dy) + a01 * dx*(1 - dy) + a10 * (1 - dx)*dy + a11 * dx*dy);
305 
306  }
307  }
308 }

◆ imgScaleBilnear() [2/2]

void Openholo::imgScaleBilnear ( unsigned char *  src,
unsigned char *  dst,
int  w,
int  h,
int  neww,
int  newh 
)
protected

Function for change image size.

Parameters
unsignedchar* Source image data
unsignedchar* Dest image data
intOriginal width
intOriginal height
intWidth to replace
intHeight to replace

◆ loadAsImg() [1/2]

virtual uchar* Openholo::loadAsImg ( const char *  fname)
virtual

Function for loading image files.

Parameters
constchar* Input file name
Returns
unsigned char* Image file's data

◆ loadAsImg() [2/2]

uchar * Openholo::loadAsImg ( const char *  fname)
virtual

Function for loading image files.

Parameters
constchar* Input file name
Returns
unsigned char* Image file's data

Definition at line 146 of file Openholo.cpp.

147 {
148  FILE *infile;
149  fopen_s(&infile, fname, "rb");
150  if (infile == nullptr) { LOG("No such file"); return 0; }
151 
152  // BMP Header Information
153  fileheader hf;
154  bitmapinfoheader hInfo;
155  fread(&hf, sizeof(fileheader), 1, infile);
156  if (hf.signature[0] != 'B' || hf.signature[1] != 'M') { LOG("Not BMP File"); return 0; }
157 
158  fread(&hInfo, sizeof(bitmapinfoheader), 1, infile);
159  fseek(infile, hf.fileoffset_to_pixelarray, SEEK_SET);
160 
161  oph::uchar *img_tmp;
162  if (hInfo.imagesize == 0) {
163  img_tmp = new uchar[hInfo.width*hInfo.height*(hInfo.bitsperpixel / 8)];
164  fread(img_tmp, sizeof(oph::uchar), hInfo.width*hInfo.height*(hInfo.bitsperpixel / 8), infile);
165  }
166  else {
167  img_tmp = new uchar[hInfo.imagesize];
168  fread(img_tmp, sizeof(oph::uchar), hInfo.imagesize, infile);
169  }
170  fclose(infile);
171 
172  return img_tmp;
173 }

◆ loadAsImgUpSideDown() [1/2]

int Openholo::loadAsImgUpSideDown ( const char *  fname,
uchar *  dst 
)
protected

Function for loading image files | Output image data upside down.

Parameters
constchar* Input file name
Returns
unsigned char* Image file's data

Definition at line 218 of file Openholo.cpp.

219 {
220  FILE *infile;
221  fopen_s(&infile, fname, "rb");
222  if (infile == nullptr) { LOG("No such file"); return 0; }
223 
224  // BMP Header Information
225  fileheader hf;
226  bitmapinfoheader hInfo;
227  fread(&hf, sizeof(fileheader), 1, infile);
228  if (hf.signature[0] != 'B' || hf.signature[1] != 'M') { LOG("Not BMP File"); return 0; }
229 
230  fread(&hInfo, sizeof(bitmapinfoheader), 1, infile);
231  fseek(infile, hf.fileoffset_to_pixelarray, SEEK_SET);
232 
233  oph::uchar* img_tmp;
234  if (hInfo.imagesize == 0) {
235  img_tmp = new oph::uchar[hInfo.width*hInfo.height*(hInfo.bitsperpixel / 8)];
236  fread(img_tmp, sizeof(oph::uchar), hInfo.width*hInfo.height*(hInfo.bitsperpixel / 8), infile);
237  }
238  else {
239  img_tmp = new oph::uchar[hInfo.imagesize];
240  fread(img_tmp, sizeof(oph::uchar), hInfo.imagesize, infile);
241  }
242  fclose(infile);
243 
244  // data upside down
245  int bytesperpixel = hInfo.bitsperpixel / 8;
246  int rowsz = bytesperpixel * hInfo.width;
247 
248  for (oph::uint k = 0; k < hInfo.height*rowsz; k++) {
249  int r = k / rowsz;
250  int c = k % rowsz;
251  ((oph::uchar*)dst)[(hInfo.height - r - 1)*rowsz + c] = img_tmp[r*rowsz + c];
252  }
253 
254  delete[] img_tmp;
255 
256  return 1;
257 }

◆ loadAsImgUpSideDown() [2/2]

int Openholo::loadAsImgUpSideDown ( const char *  fname,
uchar *  dst 
)
protected

Function for loading image files | Output image data upside down.

Parameters
constchar* Input file name
Returns
unsigned char* Image file's data

◆ loadAsOhc() [1/2]

int Openholo::loadAsOhc ( const char *  fname)
virtual

Function to read OHC file.

Reimplemented in ophCascadedPropagation, ophCascadedPropagation, ophGen, ophGen, ophSig, and ophSig.

Definition at line 193 of file Openholo.cpp.

194 {
195  std::string fullname = fname;
196  if (checkExtension(fname, ".ohc") == 0) fullname.append(".ohc");
197  OHC_decoder->setFileName(fullname.c_str());
198  if (!OHC_decoder->load()) return -1;
199 
200  context_.pixel_number = OHC_decoder->getNumOfPixel();
201  context_.pixel_pitch = OHC_decoder->getPixelPitch();
202 
203  vector<Real> wavelengthArray;
204  OHC_decoder->getWavelength(wavelengthArray);
205  context_.wave_length = new Real[wavelengthArray.size()];
206  for (int i = 0; i < wavelengthArray.size(); i++)
207  context_.wave_length[i] = wavelengthArray[i];
208 
209  OHC_decoder->getComplexFieldData(&complex_H);
210 
211  context_.k = (2 * M_PI) / context_.wave_length[0];
212  context_.ss[_X] = context_.pixel_number[_X] * context_.pixel_pitch[_X];
213  context_.ss[_Y] = context_.pixel_number[_Y] * context_.pixel_pitch[_Y];
214 
215  return 1;
216 }
int checkExtension(const char *fname, const char *ext)
Functions for extension checking.
Definition: Openholo.cpp:79

◆ loadAsOhc() [2/2]

virtual int Openholo::loadAsOhc ( const char *  fname)
virtual

Function to read OHC file.

Reimplemented in ophCascadedPropagation, ophCascadedPropagation, ophGen, ophGen, ophSig, and ophSig.

◆ ophFree() [1/2]

void Openholo::ophFree ( void  )
protectedvirtual

Pure virtual function for override in child classes.

Reimplemented in ophSig, ophSig, ophCascadedPropagation, ophCascadedPropagation, ophGen, ophGen, ophWaveAberration, ophWaveAberration, ophDepthMap, ophDepthMap, ophRec, and ophRec.

Definition at line 525 of file Openholo.cpp.

526 {
527  if ((*complex_H)) delete[](*complex_H);
528  if (complex_H) delete[] complex_H;
529  if (context_.wave_length) delete[] context_.wave_length;
530 
531  delete OHC_encoder;
532  delete OHC_decoder;
533 }
ImgEncoderOhc * OHC_encoder
OHC file format Variables for read and write.

◆ ophFree() [2/2]

virtual void Openholo::ophFree ( void  )
protectedvirtual

Pure virtual function for override in child classes.

Reimplemented in ophSig, ophSig, ophCascadedPropagation, ophCascadedPropagation, ophGen, ophGen, ophWaveAberration, ophWaveAberration, ophDepthMap, ophDepthMap, ophRec, and ophRec.

◆ release() [1/2]

unsigned long Base::release ( void  )
inlineinherited

Call release() when reference is finished.

Definition at line 80 of file Reference/include/Base.h.

80  {
81  if (!refCnt) {
82  ophFree();
83  delete this;
84  return 0;
85  }
86  return refCnt--;
87  }

◆ release() [2/2]

unsigned long Base::release ( void  )
inlineinherited

Call release() when reference is finished.

Definition at line 80 of file openholo/src/Base.h.

80  {
81  if (!refCnt) {
82  ophFree();
83  delete this;
84  return 0;
85  }
86  return refCnt--;
87  }

◆ saveAsImg() [1/2]

virtual int Openholo::saveAsImg ( const char *  fname,
uint8_t  bitsperpixel,
uchar *  src,
int  pic_width,
int  pic_height 
)
virtual

Function for creating image files.

Parameters
constchar* Output file name
uint8_tBit per pixel
unsignedchar* Source of Image file's data
intNumber of pixel - width
intNumber of pixel - height
Returns
int return -1 : Failed to save image file return 1 : Success to save image file

◆ saveAsImg() [2/2]

int Openholo::saveAsImg ( const char *  fname,
uint8_t  bitsperpixel,
uchar *  src,
int  pic_width,
int  pic_height 
)
virtual

Function for creating image files.

Parameters
constchar* Output file name
uint8_tBit per pixel
unsignedchar* Source of Image file's data
intNumber of pixel - width
intNumber of pixel - height
Returns
int return -1 : Failed to save image file return 1 : Success to save image file

Definition at line 93 of file Openholo.cpp.

94 {
95  LOG("Saving...%s...", fname);
96  auto start = CUR_TIME;
97 
98  int _width = pic_width, _height = pic_height;
99 
100  int _pixelbytesize = _height * _width * bitsperpixel / 8;
101  int _filesize = _pixelbytesize + sizeof(bitmap);
102 
103  FILE *fp;
104  fopen_s(&fp, fname, "wb");
105  if (fp == nullptr) return -1;
106 
107  bitmap *pbitmap = (bitmap*)calloc(1, sizeof(bitmap));
108  memset(pbitmap, 0x00, sizeof(bitmap));
109 
110  pbitmap->fileheader.signature[0] = 'B';
111  pbitmap->fileheader.signature[1] = 'M';
112  pbitmap->fileheader.filesize = _filesize;
113  pbitmap->fileheader.fileoffset_to_pixelarray = sizeof(bitmap);
114 
115  for (int i = 0; i < 256; i++) {
116  pbitmap->rgbquad[i].rgbBlue = i;
117  pbitmap->rgbquad[i].rgbGreen = i;
118  pbitmap->rgbquad[i].rgbRed = i;
119  }
120 
121  pbitmap->bitmapinfoheader.dibheadersize = sizeof(bitmapinfoheader);
122  pbitmap->bitmapinfoheader.width = _width;
123  pbitmap->bitmapinfoheader.height = _height;
124  pbitmap->bitmapinfoheader.planes = OPH_PLANES;
125  pbitmap->bitmapinfoheader.bitsperpixel = bitsperpixel;
126  pbitmap->bitmapinfoheader.compression = OPH_COMPRESSION;
127  pbitmap->bitmapinfoheader.imagesize = _pixelbytesize;
128  pbitmap->bitmapinfoheader.ypixelpermeter = Y_PIXEL_PER_METER;
129  pbitmap->bitmapinfoheader.xpixelpermeter = X_PIXEL_PER_METER;
130  pbitmap->bitmapinfoheader.numcolorspallette = 256;
131  fwrite(pbitmap, 1, sizeof(bitmap), fp);
132 
133  fwrite(src, 1, _pixelbytesize, fp);
134  fclose(fp);
135  free(pbitmap);
136 
137  auto end = CUR_TIME;
138 
139  auto during = ((std::chrono::duration<Real>)(end - start)).count();
140 
141  LOG("%.5lfsec...done\n", during);
142 
143  return 1;
144 }

◆ saveAsOhc() [1/2]

virtual int Openholo::saveAsOhc ( const char *  fname)
virtual

Function to write OHC file.

Reimplemented in ophCascadedPropagation, ophCascadedPropagation, ophSig, and ophSig.

◆ saveAsOhc() [2/2]

int Openholo::saveAsOhc ( const char *  fname)
virtual

Function to write OHC file.

Reimplemented in ophCascadedPropagation, ophCascadedPropagation, ophSig, and ophSig.

Definition at line 175 of file Openholo.cpp.

176 {
177  std::string fullname = fname;
178  if (checkExtension(fname, ".ohc") == 0) fullname.append(".ohc");
179  OHC_encoder->setFileName(fullname.c_str());
180 
181  ohcHeader header;
182  OHC_encoder->getOHCheader(header);
183  auto wavelength_num = header.fieldInfo.wavlenNum;
184 
185  for (int i = 0; i < wavelength_num; i++)
186  OHC_encoder->addComplexFieldData(complex_H[i]);
187 
188  if (!OHC_encoder->save()) return -1;
189 
190  return 1;
191 }
int checkExtension(const char *fname, const char *ext)
Functions for extension checking.
Definition: Openholo.cpp:79
ImgEncoderOhc * OHC_encoder
OHC file format Variables for read and write.

◆ setPixelNumberOHC() [1/2]

void Openholo::setPixelNumberOHC ( const ivec2  pixel_number)
inlineprotected

getter/setter for OHC file read and write

Definition at line 264 of file Reference/include/Openholo.h.

265  { OHC_encoder->setNumOfPixel(pixel_number); }
ImgEncoderOhc * OHC_encoder
OHC file format Variables for read and write.

◆ setPixelNumberOHC() [2/2]

void Openholo::setPixelNumberOHC ( const ivec2  pixel_number)
inlineprotected

getter/setter for OHC file read and write

Definition at line 264 of file openholo/src/Openholo.h.

265  { OHC_encoder->setNumOfPixel(pixel_number); }
ImgEncoderOhc * OHC_encoder
OHC file format Variables for read and write.

Member Data Documentation

◆ OHC_encoder

ImgEncoderOhc * Openholo::OHC_encoder
protected

OHC file format Variables for read and write.

Definition at line 257 of file openholo/src/Openholo.h.


The documentation for this class was generated from the following files: