swift
Loading...
Searching...
No Matches
imageutils.cpp
1// SPDX-FileCopyrightText: Copyright (C) 2015 swift Project Community / Contributors
2// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3
4#include "misc/imageutils.h"
5
6#include <QBuffer>
7#include <QIODevice>
8
10{
11 QBuffer buffer(&array);
13 bool s = pixmap.save(&buffer, "PNG");
14 buffer.close();
15 return s;
16}
17
19{
20 if (array.isEmpty())
21 {
22 return {};
23 }
24 QPixmap p;
25 bool s = p.loadFromData(array, "PNG");
26 return s ? p : QPixmap();
27}
28
30{
31 if (array.isEmpty())
32 {
33 return false;
34 }
35 bool s = pixmap.loadFromData(array, "PNG");
36 return s;
37}
38
40{
41 QByteArray ba;
42 bool s = pixmapToPngByteArray(pixmap, ba);
43 if (!s)
44 {
45 return {};
46 }
47 return ba.toHex();
48}
49
51{
52 if (hexString.isEmpty())
53 {
54 return {};
55 }
57 return pngByteArrayToPixmap(ba);
58}
59
61{
62 if (hexString.isEmpty())
63 {
64 return false;
65 }
67 return pngByteArrayToPixmapRef(ba, pixmap);
68}
69
71{
72 if (icon.isNull())
73 {
74 return {};
75 }
76 const QList<QSize> sizes = icon.availableSizes();
77 if (!sizes.isEmpty())
78 {
79 return icon.pixmap(sizes.first());
80 }
81 return icon.pixmap(16, 16);
82}
SWIFT_MISC_EXPORT QString pixmapToPngHexString(const QPixmap &pixmap)
Pixmap as HEX string (for PNG image).
SWIFT_MISC_EXPORT QPixmap iconToPixmap(const QIcon &icon)
Icon to pixmap.
SWIFT_MISC_EXPORT bool pixmapToPngByteArray(const QPixmap &pixmap, QByteArray &array)
Pixmap to PNG byte array.
Definition imageutils.cpp:9
SWIFT_MISC_EXPORT QPixmap pngHexStringToPixmap(const QString &hexString)
Hex encoded pixmap string to Pixmap.
SWIFT_MISC_EXPORT bool pngHexStringToPixmapRef(const QString &hexString, QPixmap &pixmap)
Hex encoded pixmap string to Pixmap.
SWIFT_MISC_EXPORT bool pngByteArrayToPixmapRef(const QByteArray &array, QPixmap &pixmap)
Pixmap from PNG byte array.
SWIFT_MISC_EXPORT QPixmap pngByteArrayToPixmap(const QByteArray &array)
Pixmap from PNG byte array.
virtual void close() override
virtual bool open(QIODeviceBase::OpenMode mode) override
QByteArray fromHex(const QByteArray &hexEncoded)
bool isEmpty() const const
QByteArray toHex(char separator) const const
QPixmap pixmap(QWindow *window, const QSize &size, QIcon::Mode mode, QIcon::State state) const const
QList< QSize > availableSizes(QIcon::Mode mode, QIcon::State state) const const
bool isNull() const const
T & first()
bool isEmpty() const const
bool loadFromData(const QByteArray &data, const char *format, Qt::ImageConversionFlags flags)
bool save(QIODevice *device, const char *format, int quality) const const
bool isEmpty() const const
QByteArray toLatin1() const const