summaryrefslogtreecommitdiff
path: root/Source/WebCore/plugins
diff options
context:
space:
mode:
authorKonstantin Tokarev <annulen@yandex.ru>2017-04-24 22:40:03 +0300
committerKonstantin Tokarev <annulen@yandex.ru>2017-04-25 18:29:55 +0000
commit4bd713d56aa9bb86bc96ea9cb0c64cbf94bf43d4 (patch)
tree02bd448d49627f059df0d8036fbdb9d9ee883a50 /Source/WebCore/plugins
parentbd3f57b00bee3088971209a0ebc513eb1ef4ba14 (diff)
downloadqtwebkit-4bd713d56aa9bb86bc96ea9cb0c64cbf94bf43d4.tar.gz
Import WebKit commit 3040e0455efecd271f1aeef53cf287e75486a70d
Change-Id: I7df106cef8ce93ce33e49ad6fb0d202cd066d87c Reviewed-by: Konstantin Tokarev <annulen@yandex.ru>
Diffstat (limited to 'Source/WebCore/plugins')
-rw-r--r--Source/WebCore/plugins/qt/QtX11ImageConversion.cpp73
-rw-r--r--Source/WebCore/plugins/qt/QtX11ImageConversion.h33
2 files changed, 106 insertions, 0 deletions
diff --git a/Source/WebCore/plugins/qt/QtX11ImageConversion.cpp b/Source/WebCore/plugins/qt/QtX11ImageConversion.cpp
new file mode 100644
index 000000000..0a76fe239
--- /dev/null
+++ b/Source/WebCore/plugins/qt/QtX11ImageConversion.cpp
@@ -0,0 +1,73 @@
+/*
+ * Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this program; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include "config.h"
+#include "QtX11ImageConversion.h"
+
+namespace WebCore {
+
+QImage qimageFromXImage(XImage* xi)
+{
+ QImage::Format format = QImage::Format_ARGB32_Premultiplied;
+ if (xi->depth == 24)
+ format = QImage::Format_RGB32;
+ else if (xi->depth == 16)
+ format = QImage::Format_RGB16;
+
+ QImage image = QImage(reinterpret_cast<uchar*>(xi->data), xi->width, xi->height, xi->bytes_per_line, format).copy();
+
+ // we may have to swap the byte order
+ if ((QSysInfo::ByteOrder == QSysInfo::LittleEndian && xi->byte_order == MSBFirst)
+ || (QSysInfo::ByteOrder == QSysInfo::BigEndian && xi->byte_order == LSBFirst)) {
+
+ for (int i = 0; i < image.height(); i++) {
+ if (xi->depth == 16) {
+ ushort* p = reinterpret_cast<ushort*>(image.scanLine(i));
+ ushort* end = p + image.width();
+ while (p < end) {
+ *p = ((*p << 8) & 0xff00) | ((*p >> 8) & 0x00ff);
+ p++;
+ }
+ } else {
+ uint* p = reinterpret_cast<uint*>(image.scanLine(i));
+ uint* end = p + image.width();
+ while (p < end) {
+ *p = ((*p << 24) & 0xff000000) | ((*p << 8) & 0x00ff0000)
+ | ((*p >> 8) & 0x0000ff00) | ((*p >> 24) & 0x000000ff);
+ p++;
+ }
+ }
+ }
+ }
+
+ // fix-up alpha channel
+ if (format == QImage::Format_RGB32) {
+ QRgb* p = reinterpret_cast<QRgb*>(image.bits());
+ for (int y = 0; y < xi->height; ++y) {
+ for (int x = 0; x < xi->width; ++x)
+ p[x] |= 0xff000000;
+ p += xi->bytes_per_line / 4;
+ }
+ }
+
+ return image;
+}
+
+} // namespace WebKit
diff --git a/Source/WebCore/plugins/qt/QtX11ImageConversion.h b/Source/WebCore/plugins/qt/QtX11ImageConversion.h
new file mode 100644
index 000000000..1a999a4ca
--- /dev/null
+++ b/Source/WebCore/plugins/qt/QtX11ImageConversion.h
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this program; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ */
+
+#ifndef QtX11ImageConversion_h
+#define QtX11ImageConversion_h
+
+#include <QImage>
+#include <X11/Xlib.h>
+
+namespace WebCore {
+
+QImage qimageFromXImage(XImage*);
+
+}
+
+#endif