1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// clang-format off
// SPDX-FileCopyrightText: 2023 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
// clang-format on
// SPDX-FileContributor: Leon Matthes <leon.matthes@kdab.com>
//
// SPDX-License-Identifier: MIT OR Apache-2.0
#include "cxx-qt-lib/qimage.h"
#include <cxx-qt-lib/assertion_utils.h>
#include <string>
// A QImage inherits from QPaintDevice.
// QPaintDevice in Qt5 contains two things:
// 1. ushort painters; (due to the following field this has padding to make it
// 64-bit long)
// 2. QPaintDevicePrivate *reserved;
// Then QImage adds an additional field:
// 3. QImageData *d;
// For a total of 3 pointers in length.
// Because of the added v-table, it's a total of 4 pointers in size.
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
assert_alignment_and_size(QImage, {
::std::uint16_t a0;
::std::size_t a1;
::std::size_t a2;
::std::size_t a3;
});
#else
// In Qt6 the QPaintDevice doesn't contain the `reserved` pointer, making it 1
// pointer smaller
assert_alignment_and_size(QImage, {
::std::uint16_t a0;
::std::size_t a1;
::std::size_t a2;
});
#endif
static_assert(std::is_same_v<QImageCleanupFunction, void (*)(void*)>);
namespace rust {
namespace cxxqtlib1 {
QImage
qimageInitFromData(const rust::Slice<std::uint8_t const> data, rust::Str format)
{
std::string formatString(format);
return QImage::fromData(static_cast<const unsigned char*>(data.data()),
static_cast<int>(data.size()),
formatString.empty() ? nullptr : formatString.data());
}
QImage
qimageInitFromRawParts(const std::uint8_t* data,
int width,
int height,
QImageFormat format,
QImageCleanupFunction cleanupFunction,
void* cleanupInfo)
{
return QImage(static_cast<const unsigned char*>(data),
width,
height,
format,
cleanupFunction,
cleanupInfo);
}
QImage
qimageInitFromRawParts(std::uint8_t* data,
int width,
int height,
QImageFormat format,
QImageCleanupFunction cleanupFunction,
void* cleanupInfo)
{
return QImage(static_cast<unsigned char*>(data),
width,
height,
format,
cleanupFunction,
cleanupInfo);
}
::std::int64_t
qimageCacheKey(const QImage& image)
{
return static_cast<::std::int64_t>(image.cacheKey());
}
}
}