• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

marble

  • sources
  • kde-4.14
  • kdeedu
  • marble
  • src
  • lib
  • marble
StackedTile.cpp
Go to the documentation of this file.
1 //
2 // This file is part of the Marble Virtual Globe.
3 //
4 // This program is free software licensed under the GNU LGPL. You can
5 // find a copy of this license in LICENSE.txt in the top directory of
6 // the source code.
7 //
8 // Copyright 2006-2010 Torsten Rahn <tackat@kde.org>
9 // Copyright 2007 Inge Wallin <ingwa@kde.org>
10 // Copyright 2008-2010 Jens-Michael Hoffmann <jensmh@gmx.de>
11 // Copyright 2010-2013 Bernhard Beschow <bbeschow@cs.tu-berlin.de>
12 //
13 
14 #include "StackedTile.h"
15 
16 #include "MarbleDebug.h"
17 #include "TextureTile.h"
18 
19 using namespace Marble;
20 
21 static const uint **jumpTableFromQImage32( const QImage &img )
22 {
23  if ( img.depth() != 48 && img.depth() != 32 )
24  return 0;
25 
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];
30 
31  for ( int y = 0; y < height; ++y ) {
32  jumpTable[ y ] = data;
33  data += bpl;
34  }
35 
36  return jumpTable;
37 }
38 
39 
40 static const uchar **jumpTableFromQImage8( const QImage &img )
41 {
42  if ( img.depth() != 8 && img.depth() != 1 )
43  return 0;
44 
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];
49 
50  for ( int y = 0; y < height; ++y ) {
51  jumpTable[ y ] = data;
52  data += bpl;
53  }
54 
55  return jumpTable;
56 }
57 
58 
59 StackedTile::StackedTile( const TileId &id, const QImage &resultImage, QVector<QSharedPointer<TextureTile> > const &tiles ) :
60  Tile( id ),
61  m_resultImage( resultImage ),
62  m_depth( resultImage.depth() ),
63  m_isGrayscale( resultImage.isGrayscale() ),
64  m_tiles( tiles ),
65  jumpTable8( jumpTableFromQImage8( m_resultImage ) ),
66  jumpTable32( jumpTableFromQImage32( m_resultImage ) ),
67  m_byteCount( calcByteCount( resultImage, tiles ) ),
68  m_isUsed( false )
69 {
70  Q_ASSERT( !tiles.isEmpty() );
71 
72  if ( jumpTable32 == 0 && jumpTable8 == 0 ) {
73  qWarning() << "Color depth" << m_depth << " is not supported.";
74  }
75 }
76 
77 StackedTile::~StackedTile()
78 {
79  delete [] jumpTable32;
80  delete [] jumpTable8;
81 }
82 
83 uint StackedTile::pixel( int x, int y ) const
84 {
85  if ( m_depth == 8 ) {
86  if ( m_isGrayscale )
87  return (jumpTable8)[y][x];
88  else
89  return m_resultImage.color( (jumpTable8)[y][x] );
90  }
91  if ( m_depth == 32 )
92  return (jumpTable32)[y][x];
93 
94  if ( m_depth == 1 && !m_isGrayscale )
95  return m_resultImage.color((jumpTable8)[y][x/8] >> 7);
96 
97  return m_resultImage.pixel( x, y );
98 }
99 
100 uint StackedTile::pixelF( qreal x, qreal y, const QRgb& topLeftValue ) const
101 {
102  // Bilinear interpolation to determine the color of a subpixel
103 
104  int iX = (int)(x);
105  int iY = (int)(y);
106 
107  qreal fY = y - iY;
108 
109  // Interpolation in y-direction
110  if ( ( iY + 1 ) < m_resultImage.height() ) {
111 
112  QRgb bottomLeftValue = pixel( iX, iY + 1 );
113 // #define CHEAPHIGH
114 #ifdef CHEAPHIGH
115  QRgb leftValue;
116  if ( fY < 0.33 )
117  leftValue = topLeftValue;
118  else if ( fY < 0.66 )
119  leftValue = (((bottomLeftValue ^ topLeftValue) & 0xfefefefeUL) >> 1)
120  + (bottomLeftValue & topLeftValue);
121  else
122  leftValue = bottomLeftValue;
123 #else
124  // blending the color values of the top left and bottom left point
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 );
128 #endif
129  // Interpolation in x-direction
130  if ( iX + 1 < m_resultImage.width() ) {
131 
132  qreal fX = x - iX;
133 
134  QRgb topRightValue = pixel( iX + 1, iY );
135  QRgb bottomRightValue = pixel( iX + 1, iY + 1 );
136 
137 #ifdef CHEAPHIGH
138  QRgb rightValue;
139  if ( fY < 0.33 )
140  rightValue = topRightValue;
141  else if ( fY < 0.66 )
142  rightValue = (((bottomRightValue ^ topRightValue) & 0xfefefefeUL) >> 1)
143  + (bottomRightValue & topRightValue);
144  else
145  rightValue = bottomRightValue;
146 
147  QRgb averageValue;
148  if ( fX < 0.33 )
149  averageValue = leftValue;
150  else if ( fX < 0.66 )
151  averageValue = (((leftValue ^ rightValue) & 0xfefefefeUL) >> 1)
152  + (leftValue & rightValue);
153  else
154  averageValue = rightValue;
155 
156  return averageValue;
157 #else
158  // blending the color values of the top right and bottom right point
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 );
162 
163  // blending the color values of the resulting middle left
164  // and middle right points
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 );
168 
169  return qRgb( mm_red, mm_green, mm_blue );
170 #endif
171  }
172  else {
173 #ifdef CHEAPHIGH
174  return leftValue;
175 #else
176  return qRgb( ml_red, ml_green, ml_blue );
177 #endif
178  }
179  }
180  else {
181  // Interpolation in x-direction
182  if ( iX + 1 < m_resultImage.width() ) {
183 
184  qreal fX = x - iX;
185 
186  if ( fX == 0.0 )
187  return topLeftValue;
188 
189  QRgb topRightValue = pixel( iX + 1, iY );
190 #ifdef CHEAPHIGH
191  QRgb topValue;
192  if ( fX < 0.33 )
193  topValue = topLeftValue;
194  else if ( fX < 0.66 )
195  topValue = (((topLeftValue ^ topRightValue) & 0xfefefefeUL) >> 1)
196  + (topLeftValue & topRightValue);
197  else
198  topValue = topRightValue;
199 
200  return topValue;
201 #else
202  // blending the color values of the top left and top right point
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 ) );
206 
207  return qRgb( tm_red, tm_green, tm_blue );
208 #endif
209  }
210  }
211 
212  return topLeftValue;
213 }
214 
215 int StackedTile::calcByteCount( const QImage &resultImage, const QVector<QSharedPointer<TextureTile> > &tiles )
216 {
217  int byteCount = resultImage.byteCount();
218 
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();
223 
224  return byteCount;
225 }
226 
227 void StackedTile::setUsed( bool used )
228 {
229  m_isUsed = used;
230 }
231 
232 bool StackedTile::used() const
233 {
234  return m_isUsed;
235 }
236 
237 uint StackedTile::pixelF( qreal x, qreal y ) const
238 {
239  int iX = (int)(x);
240  int iY = (int)(y);
241 
242  QRgb topLeftValue = pixel( iX, iY );
243 
244  return pixelF( x, y, topLeftValue );
245 }
246 
247 int StackedTile::depth() const
248 {
249  return m_depth;
250 }
251 
252 int StackedTile::byteCount() const
253 {
254  return m_byteCount;
255 }
256 
257 QVector<QSharedPointer<TextureTile> > StackedTile::tiles() const
258 {
259  return m_tiles;
260 }
261 
262 QImage const * StackedTile::resultImage() const
263 {
264  return &m_resultImage;
265 }
266 
jumpTableFromQImage32
static const uint ** jumpTableFromQImage32(const QImage &img)
Definition: StackedTile.cpp:21
TextureTile.h
Marble::StackedTile::byteCount
int byteCount() const
Definition: StackedTile.cpp:252
Marble::StackedTile::StackedTile
StackedTile(TileId const &id, QImage const &resultImage, QVector< QSharedPointer< TextureTile > > const &tiles)
Definition: StackedTile.cpp:59
QImage::depth
int depth() const
Marble::StackedTile::~StackedTile
virtual ~StackedTile()
Definition: StackedTile.cpp:77
Marble::StackedTile::pixelF
uint pixelF(qreal x, qreal y) const
Returns the color value of the result tile at a given floating point position.
Definition: StackedTile.cpp:237
QImage::color
QRgb color(int i) const
MarbleDebug.h
Marble::StackedTile::depth
int depth() const
Definition: StackedTile.cpp:247
QImage::pixel
QRgb pixel(int x, int y) const
Marble::StackedTile::used
bool used() const
Definition: StackedTile.cpp:232
QSharedPointer
QImage::width
int width() const
Marble::StackedTile::setUsed
void setUsed(bool used)
Definition: StackedTile.cpp:227
Marble::StackedTile::resultImage
QImage const * resultImage() const
Returns the QImage that describes the merged stack of Tiles.
Definition: StackedTile.cpp:262
QImage
QImage::bytesPerLine
int bytesPerLine() const
Marble::TileId
Definition: TileId.h:27
jumpTableFromQImage8
static const uchar ** jumpTableFromQImage8(const QImage &img)
Definition: StackedTile.cpp:40
QVector
Marble::StackedTile::pixel
uint pixel(int x, int y) const
Returns the color value of the result tile at the given integer position.
Definition: StackedTile.cpp:83
StackedTile.h
QImage::bits
uchar * bits()
QImage::height
int height() const
QImage::byteCount
int byteCount() const
Marble::StackedTile::tiles
QVector< QSharedPointer< TextureTile > > tiles() const
Returns the stack of Tiles.
Definition: StackedTile.cpp:257
Marble::Tile
A class that resembles a tile (then it is extended to TextureTile or Vectortile). ...
Definition: Tile.h:53
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:13:42 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

marble

Skip menu "marble"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal