QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
PatchTextureData.cc
Go to the documentation of this file.
1/****************************************************************************
2 *
3 * (c) 2009-2024 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
4 *
5 * QGroundControl is licensed according to the terms in the file
6 * COPYING.md in the root of the source code directory.
7 *
8 ****************************************************************************/
9
10#include "PatchTextureData.h"
11
12PatchTextureData::PatchTextureData(QQuick3DObject* parent) : QQuick3DTextureData(parent) {}
13
14void PatchTextureData::setImage(const QImage& image)
15{
16 if (image == _image) {
17 return;
18 }
19 _image = image;
20 emit imageChanged();
21 _rebuild();
22}
23
24void PatchTextureData::_rebuild()
25{
26 if (_image.isNull()) {
27 setSize(QSize());
28 setTextureData(QByteArray());
29 return;
30 }
31
32 const QImage converted = _image.convertToFormat(QImage::Format_RGBA8888);
33 setSize(converted.size());
34 setFormat(QQuick3DTextureData::RGBA8);
35 // The conversion always yields an alpha channel; only the source knows opacity
36 setHasTransparency(_image.hasAlphaChannel());
37 // Deep copy: the converted image's buffer dies with this scope
38 setTextureData(QByteArray(reinterpret_cast<const char*>(converted.constBits()), converted.sizeInBytes()));
39}
PatchTextureData(QQuick3DObject *parent=nullptr)
void setImage(const QImage &image)
QImage image() const