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 ) {
27 jumpTable[ y ] = data;
35static const uchar **jumpTableFromQImage8(
const QImage &img )
40 const int height = img.
height();
42 const uchar *data = img.
bits();
43 const uchar **jumpTable =
new const uchar*[height];
45 for (
int y = 0; y < height; ++y ) {
46 jumpTable[ y ] = data;
54static inline uint colorMix50(uint c1, uint c2)
56 return (((c1 ^ c2) & 0xfefefefeUL) >> 1) + (c1 & c2);
59static inline uint colorMix75(uint c1, uint c2)
61 return colorMix50(c1, colorMix50(c1, c2));
64static inline uint colorMix25(uint c1, uint c2)
66 return colorMix50(colorMix50(c1, c2), c2 );
71 m_resultImage( resultImage ),
72 m_depth( resultImage.depth() ),
73 m_isGrayscale( resultImage.isGrayscale() ),
75 jumpTable8( jumpTableFromQImage8( m_resultImage ) ),
76 jumpTable32( jumpTableFromQImage32( m_resultImage ) ),
77 m_byteCount( calcByteCount( resultImage, tiles ) ),
80 Q_ASSERT( !tiles.isEmpty() );
82 if ( jumpTable32 ==
nullptr && jumpTable8 ==
nullptr ) {
83 qWarning() <<
"Color depth" << m_depth <<
" is not supported.";
87StackedTile::~StackedTile()
89 delete [] jumpTable32;
95 if ( m_depth == 32 && !m_isGrayscale )
96 return (jumpTable32)[y][x];
100 return (jumpTable8)[y][x];
102 return m_resultImage.
color( (jumpTable8)[y][x] );
105 if ( m_depth == 1 && !m_isGrayscale )
106 return m_resultImage.
color((jumpTable8)[y][x/8] >> 7);
108 return m_resultImage.
pixel( x, y );
120 qreal fY = 8 * (y - iY);
123 if ((iY + 1) < m_resultImage.
height())
125 QRgb bottomLeftValue =
pixel(iX, iY + 1);
129 leftValue = topLeftValue;
131 leftValue = colorMix75( topLeftValue, bottomLeftValue);
133 leftValue = colorMix50( topLeftValue, bottomLeftValue);
135 leftValue = colorMix25( topLeftValue, bottomLeftValue);
137 leftValue = bottomLeftValue;
140 if (iX + 1 < m_resultImage.
width())
142 qreal fX = 8 * (x - iX);
144 QRgb topRightValue =
pixel(iX + 1, iY);
145 QRgb bottomRightValue =
pixel(iX + 1, iY + 1);
149 rightValue = topRightValue;
151 rightValue = colorMix75( topRightValue, bottomRightValue);
153 rightValue = colorMix50( topRightValue, bottomRightValue);
155 rightValue = colorMix25( topRightValue, bottomRightValue);
157 rightValue = bottomRightValue;
163 averageValue = leftValue;
165 averageValue = colorMix75( leftValue, rightValue);
167 averageValue = colorMix50( leftValue, rightValue);
169 averageValue = colorMix25( leftValue, rightValue);
171 averageValue = rightValue;
181 if ( iX + 1 < m_resultImage.
width() ) {
183 qreal fX = 8 * (x - iX);
188 QRgb topRightValue =
pixel( iX + 1, iY );
192 topValue = topLeftValue;
194 topValue = colorMix75( topLeftValue, topRightValue);
196 topValue = colorMix50( topLeftValue, topRightValue);
198 topValue = colorMix25( topLeftValue, topRightValue);
200 topValue = topRightValue;
221 if ( ( iY + 1 ) < m_resultImage.
height() ) {
223 QRgb bottomLeftValue =
pixel( iX, iY + 1 );
225 qreal ml_red = ( 1.0 - fY ) * qRed ( topLeftValue ) + fY * qRed ( bottomLeftValue );
226 qreal ml_green = ( 1.0 - fY ) * qGreen( topLeftValue ) + fY * qGreen( bottomLeftValue );
227 qreal ml_blue = ( 1.0 - fY ) * qBlue ( topLeftValue ) + fY * qBlue ( bottomLeftValue );
230 if ( iX + 1 < m_resultImage.
width() ) {
234 QRgb topRightValue =
pixel( iX + 1, iY );
235 QRgb bottomRightValue =
pixel( iX + 1, iY + 1 );
238 qreal mr_red = ( 1.0 - fY ) * qRed ( topRightValue ) + fY * qRed ( bottomRightValue );
239 qreal mr_green = ( 1.0 - fY ) * qGreen( topRightValue ) + fY * qGreen( bottomRightValue );
240 qreal mr_blue = ( 1.0 - fY ) * qBlue ( topRightValue ) + fY * qBlue ( bottomRightValue );
244 int mm_red = (int)( ( 1.0 - fX ) * ml_red + fX * mr_red );
245 int mm_green = (int)( ( 1.0 - fX ) * ml_green + fX * mr_green );
246 int mm_blue = (int)( ( 1.0 - fX ) * ml_blue + fX * mr_blue );
248 return qRgb( mm_red, mm_green, mm_blue );
251 return qRgb( ml_red, ml_green, ml_blue );
256 if ( iX + 1 < m_resultImage.
width() ) {
263 QRgb topRightValue =
pixel( iX + 1, iY );
265 int tm_red = (int)( ( 1.0 - fX ) * qRed ( topLeftValue ) + fX * qRed ( topRightValue ) );
266 int tm_green = (int)( ( 1.0 - fX ) * qGreen( topLeftValue ) + fX * qGreen( topRightValue ) );
267 int tm_blue = (int)( ( 1.0 - fX ) * qBlue ( topLeftValue ) + fX * qBlue ( topRightValue ) );
269 return qRgb( tm_red, tm_green, tm_blue );
284 for (; pos !=
end; ++pos )
285 byteCount += (*pos)->byteCount();
290void StackedTile::setUsed(
bool used )
295bool StackedTile::used()
const
305 QRgb topLeftValue =
pixel( iX, iY );
307 return pixelF( x, y, topLeftValue );
310int StackedTile::depth()
const
315int StackedTile::byteCount()
const
327 return &m_resultImage;
QVector< QSharedPointer< TextureTile > > tiles() const
Returns the stack of Tiles.
uint pixelF(qreal x, qreal y) const
Returns the color value of the result tile at a given floating point position.
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