App

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List
- File Members

TTransform.cpp
Go to the documentation of this file.
1 /*
2 * TTRansform.cpp
3 *
4 * Created on: Apr 5, 2013
5 * Author: xxx
6 */
7
8 #include "TTransform.hpp"
9
10 namespace app {
11
12 template class TTransform<px_1x8bit, px_1x8bit, TNearestFInt<px_1x8bit, px_1x8bit>>;
13 template class TTransform<px_4x8bit, px_1x8bit, TNearestFInt<px_4x8bit, px_1x8bit>>;
14
15 template class TTransform<px_1x8bit, px_1x8bit, TLinearFInt<px_1x8bit, px_1x8bit>>;
16 template class TTransform<px_4x8bit, px_1x8bit, TLinearFInt<px_4x8bit, px_1x8bit>>;
17
18 template class TTransform<px_1x8bit, px_1x8bit, TCubicFInt<px_1x8bit, px_1x8bit>>;
19 template class TTransform<px_4x8bit, px_1x8bit, TCubicFInt<px_4x8bit, px_1x8bit>>;
20
21 template <typename TPIXEL, typename TCHANNEL, typename TINTERPOLATOR>
22 TTransform<TPIXEL, TCHANNEL, TINTERPOLATOR>::~TTransform() {
23
24 }
25
26 template <typename TPIXEL, typename TCHANNEL, typename TINTERPOLATOR>
27 int TTransform<TPIXEL, TCHANNEL, TINTERPOLATOR>::applyMatrix(TBitmap<TPIXEL, TCHANNEL> &dst, const TBitmap<TPIXEL, TCHANNEL> & src, const Matrix3x3 &m) {
28
29 TPIXEL * const srcData = src.getData();
30 if (srcData == NULL) {
31 return 1;
32 }
33
34 TPIXEL * const dstData = dst.getData();
35 if (dstData == NULL) {
36 return 2;
37 }
38
39
40 TINTERPOLATOR i(src);
41
42 if (!i.isInitOk()) {
43 return 3;
44 }
45
46 TPIXEL * dPtr = dstData;
47 int dstWidth = dst.getWidth();
48 int dstHeight = dst.getHeight();
49 TPIXEL * dPtrRowEnd = dstData + dstWidth;
50 TPIXEL * dPtrEnd = dstData + dstWidth * dstHeight;
51
52 Matrix3x3 T = Matrix3x3::inverseOf(m);
53
54 double x = 0;
55 double y = 0;
56
57 double factor;
58
59 // Potencionalni optimalizace - deleni neni v nekterych pripadech nutne...
60 y = 0.5;
61 while (dPtr < dPtrEnd) {
62 x = 0.5;
63 while (dPtr < dPtrRowEnd) {
64 factor = 1 / (T.a13 * x + T.a23 * y + T.a33);
65 *dPtr = i.getAt((x * T.a11 + y * T.a21 + T.a31) * factor, (x * T.a12 + y * T.a22 + T.a32) * factor);
66 dPtr++;
67 x += 1;
68 }
69 dPtrRowEnd += dstWidth;
70 y += 1;
71 }
72
73 return 0;
74 }
75
76 } /* namespace app */