App
TFInterpolator.cpp
Go to the documentation of this file.
1 #include "TFInterpolator.hpp"
2 
3 namespace app {
4 
7 
8 template<typename TPIXEL, typename TCHANNEL>
10 }
11 
12 template<typename TPIXEL, typename TCHANNEL>
14  if (chCount == 1) {
15  return resampleTo_1ch(dst);
16  } else if (chCount == 4) {
17  return resampleTo_4ch(dst);
18  } else {
19  return 100;
20  }
21 }
22 
23 template<typename TPIXEL, typename TCHANNEL>
25  if (getSrcData() == NULL) {
26  return 1;
27  }
28 
29  TPIXEL * const dstData = dst.getData();
30  if (dstData == NULL) {
31  return 2;
32  }
33 
34  if (!isInitOk()) {
35  return 3;
36  }
37 
38  unsigned origWidth = getSrcWidth();
39  unsigned origHeight = getSrcHeight();
40  unsigned dstWidth = dst.getWidth();
41  unsigned dstHeight = dst.getHeight();
42 
43  // Jako sigmu bereme poloměr pixeli, pokud tento po násobení sílou je větší než hraniční, provede se filtrace, ta je ale možná zbytečně agresivní
44  // a vztah pro určení sigmy je jen od oka... Každopádně filtruje se pro zmenšní o více než 1%, filtrace ale nenaskakuje na nejmenší míře (ta je 0.35, nikoliv 0.505
45  double xSigma = force * origWidth / (2.0 * dstWidth);
46  double ySigma = force * origHeight / (2.0 * dstHeight);
47  xSigma = (xSigma < 0.505) ? 0 : xSigma;
48  ySigma = (ySigma < 0.505) ? 0 : ySigma;
49 
50  if (xSigma > 0.35 || ySigma > 0.35) {
51  TBitmap<TPIXEL, TCHANNEL> * source = new TBitmap<TPIXEL, TCHANNEL>(getSrcData(), getSrcWidth(), getSrcHeight(), dst.getType(), false); // Wrapper
52  if (source == NULL) {
53  return 4;
54  }
55 
56  TBitmap<TPIXEL, TCHANNEL> * preBlurred = new TBitmap<TPIXEL, TCHANNEL>(*source);
57  if (preBlurred == NULL) {
58  delete source;
59  return 5;
60  }
61 
62  TGaussianBlur<TPIXEL, TCHANNEL> preBlur(xSigma, ySigma);
63 
64  preBlur.applyTo(*preBlurred, preBlurred->getRect());
65 
66  TFInterpolator<TPIXEL, TCHANNEL> * i = newInstance(*preBlurred);
67  if (i == NULL) {
68  delete source;
69  delete preBlurred;
70  return 6;
71  }
72 
73  int retVal = 7;
74  if (i->isInitOk()) {
75  retVal = i->resampleTo(dst);
76  }
77 
78  delete source;
79  delete preBlurred;
80  delete i;
81 
82  return retVal;
83  } else {
84  return resampleTo(dst);
85  }
86 }
87 
88 } /* namespace app */