• 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
ImageF.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 2013 Adrian Draghici <draghici.adrian.b@gmail.com>
9 
10 #include "ImageF.h"
11 
12 namespace Marble {
13 
14 ImageF::ImageF()
15 {
16 }
17 
18 uint ImageF::pixelF( const QImage& image, qreal x, qreal y )
19 {
20 
21  const QRgb& topLeftPixel = image.pixel( (int) x, (int) y );
22 
23  // Bilinear interpolation to determine the color of a subpixel
24 
25  int iX = int( x );
26  int iY = int( y );
27 
28  qreal fY = y - iY;
29 
30  // Interpolation in y-direction
31  if ( ( iY + 1 ) < image.height() ) {
32 
33  QRgb bottomLeftPixel = image.pixel( iX, iY + 1 );
34 
35  // Blending the color values of the top left and bottom left point
36  qreal ml_red = ( 1.0 - fY ) * qRed ( topLeftPixel ) + fY * qRed ( bottomLeftPixel );
37  qreal ml_green = ( 1.0 - fY ) * qGreen( topLeftPixel ) + fY * qGreen( bottomLeftPixel );
38  qreal ml_blue = ( 1.0 - fY ) * qBlue ( topLeftPixel ) + fY * qBlue ( bottomLeftPixel );
39 
40  // Interpolation in x-direction
41  if ( iX + 1 < image.width() ) {
42 
43  qreal fX = x - iX;
44 
45  QRgb topRightPixel = image.pixel( iX + 1, iY );
46  QRgb bottomRightPixel = image.pixel( iX + 1, iY + 1 );
47 
48  // Blending the color values of the top right and bottom right point
49  qreal mr_red = ( 1.0 - fY ) * qRed ( topRightPixel ) + fY * qRed ( bottomRightPixel );
50  qreal mr_green = ( 1.0 - fY ) * qGreen( topRightPixel ) + fY * qGreen( bottomRightPixel );
51  qreal mr_blue = ( 1.0 - fY ) * qBlue ( topRightPixel ) + fY * qBlue ( bottomRightPixel );
52 
53  // Blending the color values of the resulting middle left and middle right points
54  int mm_red = int( ( ( 1.0 - fX ) * ml_red + fX * mr_red ) );
55  int mm_green = int( ( ( 1.0 - fX ) * ml_green + fX * mr_green ) );
56  int mm_blue = int( ( ( 1.0 - fX ) * ml_blue + fX * mr_blue ) );
57 
58  return qRgb( mm_red, mm_green, mm_blue );
59  }
60  else {
61  return qRgb( ml_red, ml_green, ml_blue );
62  }
63  }
64  else {
65  // Interpolation in x-direction
66  if ( iX + 1 < image.width() ) {
67 
68  qreal fX = x - iX;
69 
70  if ( fX == 0.0 )
71  return topLeftPixel;
72 
73  QRgb topRightPixel = image.pixel( iX + 1, iY );
74 
75  // Blending the color values of the top left and top right point
76  int tm_red = int( ( ( 1.0 - fX ) * qRed ( topLeftPixel ) + fX * qRed ( topRightPixel ) ) );
77  int tm_green = int( ( ( 1.0 - fX ) * qGreen( topLeftPixel ) + fX * qGreen( topRightPixel ) ) );
78  int tm_blue = int( ( ( 1.0 - fX ) * qBlue ( topLeftPixel ) + fX * qBlue ( topRightPixel ) ) );
79 
80  return qRgb( tm_red, tm_green, tm_blue );
81  }
82  }
83 
84  return topLeftPixel;
85 }
86 
87 }
Marble::ImageF::pixelF
static uint pixelF(const QImage &image, qreal x, qreal y)
Returns the color value of the result tile at a given floating point position.
Definition: ImageF.cpp:18
QImage::pixel
QRgb pixel(int x, int y) const
QImage::width
int width() const
QImage
ImageF.h
QImage::height
int height() const
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:13:39 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