2
* Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies)
4
* This library is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU Library General Public
6
* License as published by the Free Software Foundation; either
7
* version 2 of the License, or (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
* Library General Public License for more details.
14
* You should have received a copy of the GNU Library General Public License
15
* along with this program; see the file COPYING.LIB. If not, write to
16
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17
* Boston, MA 02110-1301, USA.
22
#include "QtX11ImageConversion.h"
26
QImage qimageFromXImage(XImage* xi)
28
QImage::Format format = QImage::Format_ARGB32_Premultiplied;
30
format = QImage::Format_RGB32;
31
else if (xi->depth == 16)
32
format = QImage::Format_RGB16;
34
QImage image = QImage(reinterpret_cast<uchar*>(xi->data), xi->width, xi->height, xi->bytes_per_line, format).copy();
36
// we may have to swap the byte order
37
if ((QSysInfo::ByteOrder == QSysInfo::LittleEndian && xi->byte_order == MSBFirst)
38
|| (QSysInfo::ByteOrder == QSysInfo::BigEndian && xi->byte_order == LSBFirst)) {
40
for (int i = 0; i < image.height(); i++) {
41
if (xi->depth == 16) {
42
ushort* p = reinterpret_cast<ushort*>(image.scanLine(i));
43
ushort* end = p + image.width();
45
*p = ((*p << 8) & 0xff00) | ((*p >> 8) & 0x00ff);
49
uint* p = reinterpret_cast<uint*>(image.scanLine(i));
50
uint* end = p + image.width();
52
*p = ((*p << 24) & 0xff000000) | ((*p << 8) & 0x00ff0000)
53
| ((*p >> 8) & 0x0000ff00) | ((*p >> 24) & 0x000000ff);
60
// fix-up alpha channel
61
if (format == QImage::Format_RGB32) {
62
QRgb* p = reinterpret_cast<QRgb*>(image.bits());
63
for (int y = 0; y < xi->height; ++y) {
64
for (int x = 0; x < xi->width; ++x)
66
p += xi->bytes_per_line / 4;