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{
9
10ImageF::ImageF() = default;
11
12uint ImageF::pixelF(const QImage &image, qreal x, qreal y)
13{
14 const QRgb &topLeftPixel = image.pixel((int)x, (int)y);
15
16 // Bilinear interpolation to determine the color of a subpixel
17
18 int iX = int(x);
19 int iY = int(y);
20
21 qreal fY = y - iY;
22
23 // Interpolation in y-direction
24 if ((iY + 1) < image.height()) {
25 QRgb bottomLeftPixel = image.pixel(iX, iY + 1);
26
27 // Blending the color values of the top left and bottom left point
28 qreal ml_red = (1.0 - fY) * qRed(topLeftPixel) + fY * qRed(bottomLeftPixel);
29 qreal ml_green = (1.0 - fY) * qGreen(topLeftPixel) + fY * qGreen(bottomLeftPixel);
30 qreal ml_blue = (1.0 - fY) * qBlue(topLeftPixel) + fY * qBlue(bottomLeftPixel);
31
32 // Interpolation in x-direction
33 if (iX + 1 < image.width()) {
34 qreal fX = x - iX;
35
36 QRgb topRightPixel = image.pixel(iX + 1, iY);
37 QRgb bottomRightPixel = image.pixel(iX + 1, iY + 1);
38
39 // Blending the color values of the top right and bottom right point
40 qreal mr_red = (1.0 - fY) * qRed(topRightPixel) + fY * qRed(bottomRightPixel);
41 qreal mr_green = (1.0 - fY) * qGreen(topRightPixel) + fY * qGreen(bottomRightPixel);
42 qreal mr_blue = (1.0 - fY) * qBlue(topRightPixel) + fY * qBlue(bottomRightPixel);
43
44 // Blending the color values of the resulting middle left and middle right points
45 int mm_red = int(((1.0 - fX) * ml_red + fX * mr_red));
46 int mm_green = int(((1.0 - fX) * ml_green + fX * mr_green));
47 int mm_blue = int(((1.0 - fX) * ml_blue + fX * mr_blue));
48
49 return qRgb(mm_red, mm_green, mm_blue);
50 } else {
51 return qRgb(ml_red, ml_green, ml_blue);
52 }
53 } else {
54 // Interpolation in x-direction
55 if (iX + 1 < image.width()) {
56 qreal fX = x - iX;
57
58 if (fX == 0.0)
59 return topLeftPixel;
60
61 QRgb topRightPixel = image.pixel(iX + 1, iY);
62
63 // Blending the color values of the top left and top right point
64 int tm_red = int(((1.0 - fX) * qRed(topLeftPixel) + fX * qRed(topRightPixel)));
65 int tm_green = int(((1.0 - fX) * qGreen(topLeftPixel) + fX * qGreen(topRightPixel)));
66 int tm_blue = int(((1.0 - fX) * qBlue(topLeftPixel) + fX * qBlue(topRightPixel)));
67
68 return qRgb(tm_red, tm_green, tm_blue);
69 }
70 }
71
72 return topLeftPixel;
73}
74
75}
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 Sat Dec 21 2024 17:04:14 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.