/* Copyright (C) 2009 Canonical Author: Aurélien Gâteau This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 2 or 3 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this program. If not, see . */ #include "imageconverter.h" #include #include #include namespace ImageConverter { /** * A structure representing an image which can be marshalled to fit the * notification spec. */ struct SpecImage { int width, height, rowStride; bool hasAlpha; int bitsPerSample, channels; QByteArray data; }; QDBusArgument &operator<<(QDBusArgument &argument, const SpecImage &image) { argument.beginStructure(); argument << image.width << image.height << image.rowStride << image.hasAlpha; argument << image.bitsPerSample << image.channels << image.data; argument.endStructure(); return argument; } const QDBusArgument &operator>>(const QDBusArgument &argument, SpecImage &image) { argument.beginStructure(); argument >> image.width >> image.height >> image.rowStride >> image.hasAlpha; argument >> image.bitsPerSample >> image.channels >> image.data; argument.endStructure(); return argument; } } // namespace // This must be before the QVariant::fromValue below (#211726) Q_DECLARE_METATYPE(ImageConverter::SpecImage) namespace ImageConverter { QVariant variantForImage(const QImage &_image) { qDBusRegisterMetaType(); const QImage image = _image.convertToFormat(QImage::Format_ARGB32); int rowStride = image.width() * 4; // Notification spec stores pixels in R,G,B,A order, regardless of // endianess // Qt represents pixels as 32 bit unsigned int. So the order depend on // endianess: // - In big endian the order is A,R,G,B // - In little endian the order is B,G,R,A QByteArray data(rowStride * image.height(), 0); char* dst = data.data(); for (int y=0; y