Marble

ImageF.cpp
1// SPDX-License-Identifier: LGPL-2.1-or-later
2//
3// SPDX-FileCopyrightText: 2013 Adrian Draghici <draghici.adrian.b@gmail.com>
4
5#include "ImageF.h"
6
7namespace Marble {
8
9ImageF::ImageF()
10{
11}
12
13uint ImageF::pixelF( const QImage& image, qreal x, qreal y )
14{
15
16 const QRgb& topLeftPixel = image.pixel( (int) x, (int) y );
17
18 // Bilinear interpolation to determine the color of a subpixel
19
20 int iX = int( x );
21 int iY = int( y );
22
23 qreal fY = y - iY;
24
25 // Interpolation in y-direction
26 if ( ( iY + 1 ) < image.height() ) {
27
28 QRgb bottomLeftPixel = image.pixel( iX, iY + 1 );
29
30 // Blending the color values of the top left and bottom left point
31 qreal ml_red = ( 1.0 - fY ) * qRed ( topLeftPixel ) + fY * qRed ( bottomLeftPixel );
32 qreal ml_green = ( 1.0 - fY ) * qGreen( topLeftPixel ) + fY * qGreen( bottomLeftPixel );
33 qreal ml_blue = ( 1.0 - fY ) * qBlue ( topLeftPixel ) + fY * qBlue ( bottomLeftPixel );
34
35 // Interpolation in x-direction
36 if ( iX + 1 < image.width() ) {
37
38 qreal fX = x - iX;
39
40 QRgb topRightPixel = image.pixel( iX + 1, iY );
41 QRgb bottomRightPixel = image.pixel( iX + 1, iY + 1 );
42
43 // Blending the color values of the top right and bottom right point
44 qreal mr_red = ( 1.0 - fY ) * qRed ( topRightPixel ) + fY * qRed ( bottomRightPixel );
45 qreal mr_green = ( 1.0 - fY ) * qGreen( topRightPixel ) + fY * qGreen( bottomRightPixel );
46 qreal mr_blue = ( 1.0 - fY ) * qBlue ( topRightPixel ) + fY * qBlue ( bottomRightPixel );
47
48 // Blending the color values of the resulting middle left and middle right points
49 int mm_red = int( ( ( 1.0 - fX ) * ml_red + fX * mr_red ) );
50 int mm_green = int( ( ( 1.0 - fX ) * ml_green + fX * mr_green ) );
51 int mm_blue = int( ( ( 1.0 - fX ) * ml_blue + fX * mr_blue ) );
52
53 return qRgb( mm_red, mm_green, mm_blue );
54 }
55 else {
56 return qRgb( ml_red, ml_green, ml_blue );
57 }
58 }
59 else {
60 // Interpolation in x-direction
61 if ( iX + 1 < image.width() ) {
62
63 qreal fX = x - iX;
64
65 if ( fX == 0.0 )
66 return topLeftPixel;
67
68 QRgb topRightPixel = image.pixel( iX + 1, iY );
69
70 // Blending the color values of the top left and top right point
71 int tm_red = int( ( ( 1.0 - fX ) * qRed ( topLeftPixel ) + fX * qRed ( topRightPixel ) ) );
72 int tm_green = int( ( ( 1.0 - fX ) * qGreen( topLeftPixel ) + fX * qGreen( topRightPixel ) ) );
73 int tm_blue = int( ( ( 1.0 - fX ) * qBlue ( topLeftPixel ) + fX * qBlue ( topRightPixel ) ) );
74
75 return qRgb( tm_red, tm_green, tm_blue );
76 }
77 }
78
79 return topLeftPixel;
80}
81
82}
Binds a QML item to a specific geodetic location in screen coordinates.
int height() const const
QRgb pixel(const QPoint &position) const const
int width() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Jun 7 2024 12:03:13 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.