19 using namespace Marble;
23 if ( img.depth() != 48 && img.depth() != 32 )
26 const int height = img.height();
27 const int bpl = img.bytesPerLine() / 4;
28 const uint *data =
reinterpret_cast<const QRgb*
>(img.bits());
29 const uint **jumpTable =
new const uint*[height];
31 for (
int y = 0; y < height; ++y ) {
32 jumpTable[ y ] = data;
42 if ( img.depth() != 8 && img.depth() != 1 )
45 const int height = img.height();
46 const int bpl = img.bytesPerLine();
47 const uchar *data = img.bits();
48 const uchar **jumpTable =
new const uchar*[height];
50 for (
int y = 0; y < height; ++y ) {
51 jumpTable[ y ] = data;
61 m_resultImage( resultImage ),
62 m_depth( resultImage.depth() ),
63 m_isGrayscale( resultImage.isGrayscale() ),
67 m_byteCount( calcByteCount( resultImage, tiles ) ),
70 Q_ASSERT( !
tiles.isEmpty() );
72 if ( jumpTable32 == 0 && jumpTable8 == 0 ) {
73 qWarning() <<
"Color depth" << m_depth <<
" is not supported.";
79 delete [] jumpTable32;
87 return (jumpTable8)[y][x];
89 return m_resultImage.color( (jumpTable8)[y][x] );
92 return (jumpTable32)[y][x];
94 if ( m_depth == 1 && !m_isGrayscale )
95 return m_resultImage.color((jumpTable8)[y][x/8] >> 7);
97 return m_resultImage.pixel( x, y );
110 if ( ( iY + 1 ) < m_resultImage.height() ) {
112 QRgb bottomLeftValue =
pixel( iX, iY + 1 );
117 leftValue = topLeftValue;
118 else if ( fY < 0.66 )
119 leftValue = (((bottomLeftValue ^ topLeftValue) & 0xfefefefeUL) >> 1)
120 + (bottomLeftValue & topLeftValue);
122 leftValue = bottomLeftValue;
125 qreal ml_red = ( 1.0 - fY ) * qRed ( topLeftValue ) + fY * qRed ( bottomLeftValue );
126 qreal ml_green = ( 1.0 - fY ) * qGreen( topLeftValue ) + fY * qGreen( bottomLeftValue );
127 qreal ml_blue = ( 1.0 - fY ) * qBlue ( topLeftValue ) + fY * qBlue ( bottomLeftValue );
130 if ( iX + 1 < m_resultImage.width() ) {
134 QRgb topRightValue =
pixel( iX + 1, iY );
135 QRgb bottomRightValue =
pixel( iX + 1, iY + 1 );
140 rightValue = topRightValue;
141 else if ( fY < 0.66 )
142 rightValue = (((bottomRightValue ^ topRightValue) & 0xfefefefeUL) >> 1)
143 + (bottomRightValue & topRightValue);
145 rightValue = bottomRightValue;
149 averageValue = leftValue;
150 else if ( fX < 0.66 )
151 averageValue = (((leftValue ^ rightValue) & 0xfefefefeUL) >> 1)
152 + (leftValue & rightValue);
154 averageValue = rightValue;
159 qreal mr_red = ( 1.0 - fY ) * qRed ( topRightValue ) + fY * qRed ( bottomRightValue );
160 qreal mr_green = ( 1.0 - fY ) * qGreen( topRightValue ) + fY * qGreen( bottomRightValue );
161 qreal mr_blue = ( 1.0 - fY ) * qBlue ( topRightValue ) + fY * qBlue ( bottomRightValue );
165 int mm_red = (int)( ( 1.0 - fX ) * ml_red + fX * mr_red );
166 int mm_green = (int)( ( 1.0 - fX ) * ml_green + fX * mr_green );
167 int mm_blue = (int)( ( 1.0 - fX ) * ml_blue + fX * mr_blue );
169 return qRgb( mm_red, mm_green, mm_blue );
176 return qRgb( ml_red, ml_green, ml_blue );
182 if ( iX + 1 < m_resultImage.width() ) {
189 QRgb topRightValue =
pixel( iX + 1, iY );
193 topValue = topLeftValue;
194 else if ( fX < 0.66 )
195 topValue = (((topLeftValue ^ topRightValue) & 0xfefefefeUL) >> 1)
196 + (topLeftValue & topRightValue);
198 topValue = topRightValue;
203 int tm_red = (int)( ( 1.0 - fX ) * qRed ( topLeftValue ) + fX * qRed ( topRightValue ) );
204 int tm_green = (int)( ( 1.0 - fX ) * qGreen( topLeftValue ) + fX * qGreen( topRightValue ) );
205 int tm_blue = (int)( ( 1.0 - fX ) * qBlue ( topLeftValue ) + fX * qBlue ( topRightValue ) );
207 return qRgb( tm_red, tm_green, tm_blue );
215 int StackedTile::calcByteCount(
const QImage &resultImage,
const QVector<QSharedPointer<TextureTile> > &tiles )
219 QVector<QSharedPointer<TextureTile> >::const_iterator pos =
tiles.constBegin();
220 QVector<QSharedPointer<TextureTile> >::const_iterator
const end =
tiles.constEnd();
221 for (; pos != end; ++pos )
222 byteCount += (*pos)->byteCount();
242 QRgb topLeftValue =
pixel( iX, iY );
244 return pixelF( x, y, topLeftValue );
264 return &m_resultImage;
static const uint ** jumpTableFromQImage32(const QImage &img)
StackedTile(TileId const &id, QImage const &resultImage, QVector< QSharedPointer< TextureTile > > const &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.
static const uchar ** jumpTableFromQImage8(const QImage &img)
uint pixel(int x, int y) const
Returns the color value of the result tile at the given integer position.
QVector< QSharedPointer< TextureTile > > tiles() const
Returns the stack of Tiles.
A class that resembles a tile (then it is extended to TextureTile or Vectortile). ...