ICF 3.1.1.10
Technical documentation of ICF Libraries
TImagePixelInterpolator.h
Go to the documentation of this file.
1/********************************************************************************
2** This file is part of the ICF Framework. Copyright (C) Witold Gantzke & Kirill Lepskiy
3** ICF Framework may be used under the terms of the LGPL License v. 2.1 by the Free Software Foundation.
4********************************************************************************/
5
6#ifndef iipr_TImagePixelInterpolator_included
7#define iipr_TImagePixelInterpolator_included
8
9
10// Qt includes
11#include <QtCore/QtGlobal>
12#include <QtCore/QtMath>
13
14// ICF includes
15#include <istd/istd.h>
17
18
19namespace iimg
20{
21 class IBitmap;
22}
23
24
25namespace iipr
26{
27
28
29template <typename PixelComponentType>
31{
32public:
33 typedef PixelComponentType PixelComponent;
34
35 TImagePixelInterpolator(const iimg::IBitmap& image, int interpolationMode);
36
37 PixelComponentType GetInterpolatedValue(float x, float y, int componentIndex) const;
38
39private:
40 PixelComponentType GetBilinearInterpolated(float x, float y, int componentIndex) const;
41 PixelComponentType GetBitmapPixelValue(int x, int y, int componentIndex) const;
42
43private:
44 PixelComponentType* m_imageBufferPtr;
45 int m_imageLineDifference;
46 int m_imageHeight;
47 int m_imageWidth;
48 int m_interpolationMode;
49 int m_pixelBytesCount;
50 int m_maxValue;
51};
52
53
54// public methods
55
56template <typename PixelComponentType>
58{
59 m_imageBufferPtr = (PixelComponentType*)bitmap.GetLinePtr(0);
60 m_imageLineDifference = bitmap.GetLinesDifference();
61 m_imageHeight = bitmap.GetImageSize().GetY();
62 m_imageWidth = bitmap.GetImageSize().GetX();
63 m_pixelBytesCount = bitmap.GetPixelBitsCount() / 8;
64 m_interpolationMode = interpolationMode;
65 m_maxValue = int(qPow(2.0, double(sizeof(PixelComponentType) * 8)) - 1);
66}
67
68
69template <typename PixelComponentType>
71{
72 switch (m_interpolationMode){
74 return GetBitmapPixelValue(int(x), int(y), componentIndex);
75
77 return GetBilinearInterpolated(x, y, componentIndex);
78
79 default:
80 qFatal("TImagePixelInterpolator: Unknown interpolation mode");
81 }
82
83 return GetBitmapPixelValue(int(x), int(y), componentIndex);
84}
85
86
87// private methods
88
89template <typename PixelComponentType>
91{
92 int px = qFloor(x);
93 int py = qFloor(y);
94
95 // Calculate the weights for each pixel:
96 float fx = x - px;
97 float fy = y - py;
98 float fx1 = 1.0f - fx;
99 float fy1 = 1.0f - fy;
100
101 float w1 = fx1 * fy1;
102 float w2 = fx * fy1;
103 float w3 = fx1 * fy;
104 float w4 = fx * fy;
105
106 float v1 = w1 * GetBitmapPixelValue(px, py, componentIndex);
107 float v2 = w2 * GetBitmapPixelValue(px + 1, py, componentIndex);
108 float v3 = w3 * GetBitmapPixelValue(px, py + 1, componentIndex);
109 float v4 = w4 * GetBitmapPixelValue(px + 1, py + 1, componentIndex);
110
111 float retVal = v1 + v2 + v3 + v4;
112 if (retVal > m_maxValue){
113 retVal = m_maxValue;
114 }
115
116 return PixelComponentType(retVal);
117}
118
119
120template <typename PixelComponentType>
121typename TImagePixelInterpolator<PixelComponentType>::PixelComponent TImagePixelInterpolator<PixelComponentType>::GetBitmapPixelValue(int x, int y, int componentIndex) const
122{
123 if (x < 0 || x >= m_imageWidth || y < 0 || y >= m_imageHeight){
124 return 0;
125 }
126
127 return *(m_imageBufferPtr + x * m_pixelBytesCount + componentIndex + m_imageLineDifference * y);
128}
129
130
131} // namespace iipr
132
133
134#endif // !iipr_TImagePixelInterpolator_included
135
136
Definition of single plane bitmap.
Definition IBitmap.h:24
virtual int GetPixelBitsCount() const =0
Get total number of bits per single pixel.
virtual int GetLinesDifference() const =0
Get address difference between next and previous line.
virtual const void * GetLinePtr(int positionY) const =0
Get pointer to buffer for single line.
virtual istd::CIndex2d GetImageSize() const =0
Get size of this raster image.
PixelComponentType GetInterpolatedValue(float x, float y, int componentIndex) const
TImagePixelInterpolator(const iimg::IBitmap &image, int interpolationMode)
int GetX() const
Definition CIndex2d.h:105
int GetY() const
Definition CIndex2d.h:117
Contains the system indenendent definitions of image and related themes.
Definition CBitmap.h:21
Contains the image processing classes.

© Witold Gantzke and Kirill Lepskiy