tuned-switcher 1.1.0
Performance profile manager
Loading...
Searching...
No Matches
dbusconverters.h
Go to the documentation of this file.
1
8#ifndef DBUSCONVERTERS_H
9#define DBUSCONVERTERS_H
10
20#include <QDBusArgument>
21#include <QImage>
22
28QDBusArgument& operator <<(QDBusArgument& argument, const QImage& image)
29{
30 if (image.isNull())
31 {
32 argument.beginStructure();
33 argument << 0 << 0 << 0 << false << 0 << 0 << QByteArray();
34 argument.endStructure();
35 return argument;
36 }
37
38 QImage scaled = image.scaledToHeight(100, Qt::SmoothTransformation);
39 scaled = scaled.convertToFormat(QImage::Format_ARGB32);
40
41#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN
42 // ABGR -> ARGB
43 QImage i = scaled.rgbSwapped();
44#else
45 // ABGR -> GBAR
46 QImage i(scaled.size(), scaled.format());
47 for (int y = 0; y < i.height(); ++y)
48 {
49 QRgb* p = (QRgb*)scaled.scanLine(y);
50 QRgb* q = (QRgb*)i.scanLine(y);
51 QRgb* end = p + scaled.width();
52 while (p < end)
53 {
54 *q = qRgba(qGreen(*p), qBlue(*p), qAlpha(*p), qRed(*p));
55 p++;
56 q++;
57 }
58 }
59#endif
60
61 argument.beginStructure();
62 argument << i.width();
63 argument << i.height();
64 argument << static_cast<int>(i.bytesPerLine());
65 argument << i.hasAlphaChannel();
66 int channels = i.isGrayscale() ? 1 : (i.hasAlphaChannel() ? 4 : 3);
67 argument << i.depth() / channels;
68 argument << channels;
69 argument << QByteArray(reinterpret_cast<const char*>(i.bits()), i.sizeInBytes());
70 argument.endStructure();
71 return argument;
72}
73
78const QDBusArgument& operator >>(const QDBusArgument& argument, QImage&)
79{
80 Q_ASSERT(0);
81 return argument;
82}
83
84#endif // DBUSCONVERTERS_H
QDBusArgument & operator<<(QDBusArgument &argument, const QImage &image)
Definition dbusconverters.h:28
const QDBusArgument & operator>>(const QDBusArgument &argument, QImage &)
Definition dbusconverters.h:78