KNotifications

imageconverter.cpp
1/*
2 SPDX-FileCopyrightText: 2009 Canonical
3 SPDX-FileContributor: Aurélien Gâteau <aurelien.gateau@canonical.com>
4
5 SPDX-License-Identifier: LGPL-2.0-only OR LGPL-3.0-only
6*/
7
8#include "imageconverter.h"
9
10#include <QDBusArgument>
11#include <QDBusMetaType>
12#include <QImage>
13
14namespace ImageConverter
15{
16/**
17 * A structure representing an image which can be marshalled to fit the
18 * notification spec.
19 */
20struct SpecImage {
21 int width, height, rowStride;
22 bool hasAlpha;
23 int bitsPerSample, channels;
24 QByteArray data;
25};
26
27QDBusArgument &operator<<(QDBusArgument &argument, const SpecImage &image)
28{
29 argument.beginStructure();
30 argument << image.width << image.height << image.rowStride << image.hasAlpha;
31 argument << image.bitsPerSample << image.channels << image.data;
32 argument.endStructure();
33 return argument;
34}
35
36const QDBusArgument &operator>>(const QDBusArgument &argument, SpecImage &image)
37{
38 argument.beginStructure();
39 argument >> image.width >> image.height >> image.rowStride >> image.hasAlpha;
40 argument >> image.bitsPerSample >> image.channels >> image.data;
41 argument.endStructure();
42 return argument;
43}
44
45} // namespace
46
47// This must be before the QVariant::fromValue below (#211726)
48Q_DECLARE_METATYPE(ImageConverter::SpecImage)
49
50namespace ImageConverter
51{
52QVariant variantForImage(const QImage &_image)
53{
54 qDBusRegisterMetaType<SpecImage>();
55
56 const bool hasAlpha = _image.hasAlphaChannel();
57 QImage image;
58 if (hasAlpha) {
60 } else {
62 }
63
64 QByteArray data((const char *)image.constBits(), image.sizeInBytes());
65
66 SpecImage specImage;
67 specImage.width = image.width();
68 specImage.height = image.height();
69 specImage.rowStride = image.bytesPerLine();
70 specImage.hasAlpha = hasAlpha;
71 specImage.bitsPerSample = 8;
72 specImage.channels = hasAlpha ? 4 : 3;
73 specImage.data = data;
74
75 return QVariant::fromValue(specImage);
76}
77
78} // namespace
KCALENDARCORE_EXPORT QDataStream & operator>>(QDataStream &in, const KCalendarCore::Alarm::Ptr &)
QDebug operator<<(QDebug dbg, const PerceptualColor::MultiSpinBoxSection &value)
void beginStructure()
void endStructure()
qsizetype bytesPerLine() const const
const uchar * constBits() const const
QImage convertToFormat(Format format, Qt::ImageConversionFlags flags) &&
bool hasAlphaChannel() const const
int height() const const
qsizetype sizeInBytes() const const
int width() const const
QVariant fromValue(T &&value)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:12:53 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.