9#include "StackedTile.h"
11#include "MarbleDebug.h"
12#include "TextureTile.h"
16static const uint **jumpTableFromQImage32(
const QImage &img)
21 const int height = img.
height();
23 const uint *data =
reinterpret_cast<const QRgb *
>(img.
bits());
24 const uint **jumpTable =
new const uint *[height];
26 for (
int y = 0; y < height; ++y) {
34static const uchar **jumpTableFromQImage8(
const QImage &img)
39 const int height = img.
height();
41 const uchar *data = img.
bits();
42 const uchar **jumpTable =
new const uchar *[height];
44 for (
int y = 0; y < height; ++y) {
53static inline uint colorMix50(uint c1, uint c2)
55 return (((c1 ^ c2) & 0xfefefefeUL) >> 1) + (c1 & c2);
58static inline uint colorMix75(uint c1, uint c2)
60 return colorMix50(c1, colorMix50(c1, c2));
63static inline uint colorMix25(uint c1, uint c2)
65 return colorMix50(colorMix50(c1, c2), c2);
70 , m_resultImage(resultImage)
71 , m_depth(resultImage.depth())
72 , m_isGrayscale(resultImage.isGrayscale())
74 , jumpTable8(jumpTableFromQImage8(m_resultImage))
75 , jumpTable32(jumpTableFromQImage32(m_resultImage))
76 , m_byteCount(calcByteCount(resultImage, tiles))
79 Q_ASSERT(!tiles.isEmpty());
81 if (jumpTable32 ==
nullptr && jumpTable8 ==
nullptr) {
82 qWarning() <<
"Color depth" << m_depth <<
" is not supported.";
86StackedTile::~StackedTile()
94 if (m_depth == 32 && !m_isGrayscale)
95 return (jumpTable32)[y][x];
99 return (jumpTable8)[y][x];
101 return m_resultImage.
color((jumpTable8)[y][x]);
104 if (m_depth == 1 && !m_isGrayscale)
105 return m_resultImage.
color((jumpTable8)[y][x / 8] >> 7);
107 return m_resultImage.
pixel(x, y);
119 qreal fY = 8 * (y - iY);
122 if ((iY + 1) < m_resultImage.
height()) {
123 QRgb bottomLeftValue =
pixel(iX, iY + 1);
127 leftValue = topLeftValue;
129 leftValue = colorMix75(topLeftValue, bottomLeftValue);
131 leftValue = colorMix50(topLeftValue, bottomLeftValue);
133 leftValue = colorMix25(topLeftValue, bottomLeftValue);
135 leftValue = bottomLeftValue;
138 if (iX + 1 < m_resultImage.
width()) {
139 qreal fX = 8 * (x - iX);
141 QRgb topRightValue =
pixel(iX + 1, iY);
142 QRgb bottomRightValue =
pixel(iX + 1, iY + 1);
146 rightValue = topRightValue;
148 rightValue = colorMix75(topRightValue, bottomRightValue);
150 rightValue = colorMix50(topRightValue, bottomRightValue);
152 rightValue = colorMix25(topRightValue, bottomRightValue);
154 rightValue = bottomRightValue;
159 averageValue = leftValue;
161 averageValue = colorMix75(leftValue, rightValue);
163 averageValue = colorMix50(leftValue, rightValue);
165 averageValue = colorMix25(leftValue, rightValue);
167 averageValue = rightValue;
175 if (iX + 1 < m_resultImage.
width()) {
176 qreal fX = 8 * (x - iX);
181 QRgb topRightValue =
pixel(iX + 1, iY);
185 topValue = topLeftValue;
187 topValue = colorMix75(topLeftValue, topRightValue);
189 topValue = colorMix50(topLeftValue, topRightValue);
191 topValue = colorMix25(topLeftValue, topRightValue);
193 topValue = topRightValue;
214 if ((iY + 1) < m_resultImage.
height()) {
215 QRgb bottomLeftValue =
pixel(iX, iY + 1);
217 qreal ml_red = (1.0 - fY) * qRed(topLeftValue) + fY * qRed(bottomLeftValue);
218 qreal ml_green = (1.0 - fY) * qGreen(topLeftValue) + fY * qGreen(bottomLeftValue);
219 qreal ml_blue = (1.0 - fY) * qBlue(topLeftValue) + fY * qBlue(bottomLeftValue);
222 if (iX + 1 < m_resultImage.
width()) {
225 QRgb topRightValue =
pixel(iX + 1, iY);
226 QRgb bottomRightValue =
pixel(iX + 1, iY + 1);
229 qreal mr_red = (1.0 - fY) * qRed(topRightValue) + fY * qRed(bottomRightValue);
230 qreal mr_green = (1.0 - fY) * qGreen(topRightValue) + fY * qGreen(bottomRightValue);
231 qreal mr_blue = (1.0 - fY) * qBlue(topRightValue) + fY * qBlue(bottomRightValue);
235 int mm_red = (int)((1.0 - fX) * ml_red + fX * mr_red);
236 int mm_green = (int)((1.0 - fX) * ml_green + fX * mr_green);
237 int mm_blue = (int)((1.0 - fX) * ml_blue + fX * mr_blue);
239 return qRgb(mm_red, mm_green, mm_blue);
241 return qRgb(ml_red, ml_green, ml_blue);
245 if (iX + 1 < m_resultImage.
width()) {
251 QRgb topRightValue =
pixel(iX + 1, iY);
253 int tm_red = (int)((1.0 - fX) * qRed(topLeftValue) + fX * qRed(topRightValue));
254 int tm_green = (int)((1.0 - fX) * qGreen(topLeftValue) + fX * qGreen(topRightValue));
255 int tm_blue = (int)((1.0 - fX) * qBlue(topLeftValue) + fX * qBlue(topRightValue));
257 return qRgb(tm_red, tm_green, tm_blue);
272 for (; pos !=
end; ++pos)
273 byteCount += (*pos)->byteCount();
278void StackedTile::setUsed(
bool used)
283bool StackedTile::used()
const
293 QRgb topLeftValue =
pixel(iX, iY);
295 return pixelF(x, y, topLeftValue);
298int StackedTile::depth()
const
303int StackedTile::byteCount()
const
315 return &m_resultImage;
uint pixelF(qreal x, qreal y) const
Returns the color value of the result tile at a given floating point position.
QList< QSharedPointer< TextureTile > > tiles() const
Returns the stack of Tiles.
QImage const * resultImage() const
Returns the QImage that describes the merged stack of Tiles.
uint pixel(int x, int y) const
Returns the color value of the result tile at the given integer position.
A class that resembles a tile (then it is extended to TextureTile or Vectortile).
const QList< QKeySequence > & end()
Binds a QML item to a specific geodetic location in screen coordinates.
qsizetype bytesPerLine() const const
QRgb color(int i) const const
QRgb pixel(const QPoint &position) const const
qsizetype sizeInBytes() const const
const_iterator constBegin() const const