drop ppm and pbm support

the size of ppm is larger than the raw QImage, what uses such formats
anyway?

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2024-06-03 07:15:33 +03:00
parent 9e7e026f62
commit 57282fc808
11 changed files with 49 additions and 10873 deletions

View file

@ -285,7 +285,6 @@ set(GUI_HEADERS
${CMAKE_CURRENT_SOURCE_DIR}/image/qpixmap.h ${CMAKE_CURRENT_SOURCE_DIR}/image/qpixmap.h
${CMAKE_CURRENT_SOURCE_DIR}/image/qpixmapcache.h ${CMAKE_CURRENT_SOURCE_DIR}/image/qpixmapcache.h
${CMAKE_CURRENT_SOURCE_DIR}/image/qpixmapdata_p.h ${CMAKE_CURRENT_SOURCE_DIR}/image/qpixmapdata_p.h
${CMAKE_CURRENT_SOURCE_DIR}/image/qppmhandler_p.h
${CMAKE_CURRENT_SOURCE_DIR}/image/qxpmhandler_p.h ${CMAKE_CURRENT_SOURCE_DIR}/image/qxpmhandler_p.h
${CMAKE_CURRENT_SOURCE_DIR}/image/qpnghandler_p.h ${CMAKE_CURRENT_SOURCE_DIR}/image/qpnghandler_p.h
${CMAKE_CURRENT_SOURCE_DIR}/image/qkathandler_p.h ${CMAKE_CURRENT_SOURCE_DIR}/image/qkathandler_p.h
@ -620,7 +619,6 @@ set(GUI_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/image/qiconengine.cpp ${CMAKE_CURRENT_SOURCE_DIR}/image/qiconengine.cpp
${CMAKE_CURRENT_SOURCE_DIR}/image/qmovie.cpp ${CMAKE_CURRENT_SOURCE_DIR}/image/qmovie.cpp
# Built-in image format support # Built-in image format support
${CMAKE_CURRENT_SOURCE_DIR}/image/qppmhandler.cpp
${CMAKE_CURRENT_SOURCE_DIR}/image/qxpmhandler.cpp ${CMAKE_CURRENT_SOURCE_DIR}/image/qxpmhandler.cpp
${CMAKE_CURRENT_SOURCE_DIR}/image/qpnghandler.cpp ${CMAKE_CURRENT_SOURCE_DIR}/image/qpnghandler.cpp
${CMAKE_CURRENT_SOURCE_DIR}/image/qkathandler.cpp ${CMAKE_CURRENT_SOURCE_DIR}/image/qkathandler.cpp

View file

@ -296,8 +296,6 @@ bool QImageData::checkForAlphaPixels() const
\header \o Format \o Description \o Katie's support \header \o Format \o Description \o Katie's support
\row \o PNG \o Portable Network Graphics \o Read/write \row \o PNG \o Portable Network Graphics \o Read/write
\row \o KAT \o Katie Image \o Read/write \row \o KAT \o Katie Image \o Read/write
\row \o PBM \o Portable Bitmap \o Read
\row \o PPM \o Portable Pixmap \o Read/write
\row \o XPM \o X11 Pixmap \o Read \row \o XPM \o X11 Pixmap \o Read
\endtable \endtable
@ -3242,9 +3240,8 @@ qint64 QImage::cacheKey() const
\obsolete \obsolete
Sets the alpha channel of this image to the given \a alphaChannel. Sets the alpha channel of this image to the given \a alphaChannel.
If \a alphaChannel is an 8 bit grayscale image, the intensity values are \a alphaChannel is converted to 32 bit and the intensity of the RGB pixel
written into this buffer directly. Otherwise, \a alphaChannel is converted values is used.
to 32 bit and the intensity of the RGB pixel values is used.
Note that the image will be converted to the Format_ARGB32_Premultiplied Note that the image will be converted to the Format_ARGB32_Premultiplied
format if the function succeeds. format if the function succeeds.

View file

@ -109,7 +109,6 @@
#include "qguicommon_p.h" #include "qguicommon_p.h"
// image handlers // image handlers
#include "qppmhandler_p.h"
#include "qxpmhandler_p.h" #include "qxpmhandler_p.h"
#include "qkathandler_p.h" #include "qkathandler_p.h"
#include "qpnghandler_p.h" #include "qpnghandler_p.h"
@ -140,10 +139,6 @@ static QImageIOHandler *createReadHandlerHelper(QIODevice *device,
#ifndef QT_NO_IMAGEFORMAT_XPM #ifndef QT_NO_IMAGEFORMAT_XPM
} else if (form == "xpm") { } else if (form == "xpm") {
handler = new QXpmHandler(); handler = new QXpmHandler();
#endif
#ifndef QT_NO_IMAGEFORMAT_PPM
} else if (form == "pbm" || form == "pbmraw" || form == "ppm" || form == "ppmraw") {
handler = new QPpmHandler(form);
#endif #endif
} }
@ -173,12 +168,6 @@ static QImageIOHandler *createReadHandlerHelper(QIODevice *device,
if (!handler && QXpmHandler::canRead(device)) { if (!handler && QXpmHandler::canRead(device)) {
handler = new QXpmHandler(); handler = new QXpmHandler();
} }
#endif
#ifndef QT_NO_IMAGEFORMAT_PPM
QByteArray subType;
if (!handler && QPpmHandler::canRead(device, &subType)) {
handler = new QPpmHandler(subType);
}
#endif #endif
} }
#ifndef QT_NO_DEBUG #ifndef QT_NO_DEBUG
@ -853,8 +842,6 @@ QByteArray QImageReader::imageFormat(QIODevice *device)
\header \o Format \o Description \header \o Format \o Description
\row \o PNG \o Portable Network Graphics \row \o PNG \o Portable Network Graphics
\row \o KAT \o Katie Image \row \o KAT \o Katie Image
\row \o PBM \o Portable Bitmap
\row \o PPM \o Portable Pixmap
\row \o XPM \o X11 Pixmap \row \o XPM \o X11 Pixmap
\row \o SVG \o Scalable Vector Graphics \row \o SVG \o Scalable Vector Graphics
\endtable \endtable
@ -876,9 +863,6 @@ QList<QByteArray> QImageReader::supportedImageFormats()
#endif #endif
#ifndef QT_NO_IMAGEFORMAT_XPM #ifndef QT_NO_IMAGEFORMAT_XPM
<< "xpm" << "xpm"
#endif
#ifndef QT_NO_IMAGEFORMAT_PPM
<< "ppm" << "pbm"
#endif #endif
; ;
@ -917,13 +901,6 @@ QByteArray QImageReader::formatForMimeType(const QByteArray &mime)
return QByteArray("xpm"); return QByteArray("xpm");
} }
#endif #endif
#ifndef QT_NO_IMAGEFORMAT_PPM
if (mime == "image/x-portable-pixmap") {
return QByteArray("ppm");
} else if (mime == "image/x-portable-bitmap") {
return QByteArray("pbm");
}
#endif
#ifndef QT_NO_LIBRARY #ifndef QT_NO_LIBRARY
QFactoryLoader *l = imageloader(); QFactoryLoader *l = imageloader();
@ -956,9 +933,6 @@ QList<QByteArray> QImageReader::supportedMimeTypes()
#endif #endif
#ifndef QT_NO_IMAGEFORMAT_XPM #ifndef QT_NO_IMAGEFORMAT_XPM
<< "image/x-xpixmap" << "image/x-xpixmap"
#endif
#ifndef QT_NO_IMAGEFORMAT_PPM
<< "image/x-portable-pixmap" << "image/x-portable-bitmap"
#endif #endif
; ;

View file

@ -84,7 +84,6 @@
#include "qguicommon_p.h" #include "qguicommon_p.h"
// image handlers // image handlers
#include "qppmhandler_p.h"
#include "qkathandler_p.h" #include "qkathandler_p.h"
#include "qpnghandler_p.h" #include "qpnghandler_p.h"
@ -101,10 +100,6 @@ static QImageIOHandler *createWriteHandlerHelper(QIODevice *device, const QByteA
#ifndef QT_NO_IMAGEFORMAT_KAT #ifndef QT_NO_IMAGEFORMAT_KAT
} else if (form == "kat") { } else if (form == "kat") {
handler = new QKatHandler(); handler = new QKatHandler();
#endif
#ifndef QT_NO_IMAGEFORMAT_PPM
} else if (form == "pbm" || form == "pbmraw" || form == "ppm" || form == "ppmraw") {
handler = new QPpmHandler(form);
#endif #endif
} }
@ -486,7 +481,6 @@ QByteArray QImageWriter::defaultImageFormat()
\header \o Format \o Description \header \o Format \o Description
\row \o PNG \o Portable Network Graphics \row \o PNG \o Portable Network Graphics
\row \o KAT \o Katie Image \row \o KAT \o Katie Image
\row \o PPM \o Portable Pixmap
\endtable \endtable
Reading and writing SVG files is supported through Katie's Reading and writing SVG files is supported through Katie's
@ -505,9 +499,6 @@ QList<QByteArray> QImageWriter::supportedImageFormats()
#ifndef QT_NO_IMAGEFORMAT_KAT #ifndef QT_NO_IMAGEFORMAT_KAT
formats << "kat"; formats << "kat";
#endif #endif
#ifndef QT_NO_IMAGEFORMAT_PPM
formats << "ppm";
#endif
#ifndef QT_NO_LIBRARY #ifndef QT_NO_LIBRARY
QFactoryLoader *l = imageloader(); QFactoryLoader *l = imageloader();
@ -539,11 +530,6 @@ QByteArray QImageWriter::formatForMimeType(const QByteArray &mime)
return QByteArray("kat"); return QByteArray("kat");
} }
#endif #endif
#ifndef QT_NO_IMAGEFORMAT_PPM
if (mime == "image/x-portable-pixmap") {
return QByteArray("ppm");
}
#endif
#ifndef QT_NO_LIBRARY #ifndef QT_NO_LIBRARY
QFactoryLoader *l = imageloader(); QFactoryLoader *l = imageloader();
@ -573,9 +559,6 @@ QList<QByteArray> QImageWriter::supportedMimeTypes()
<< "image/png" << "image/png"
#ifndef QT_NO_IMAGEFORMAT_KAT #ifndef QT_NO_IMAGEFORMAT_KAT
<< "image/katie" << "image/katie"
#endif
#ifndef QT_NO_IMAGEFORMAT_PPM
<< "image/x-portable-pixmap"
#endif #endif
; ;

View file

@ -1123,8 +1123,6 @@ QPixmap QPixmap::transformed(const QMatrix &matrix, Qt::TransformationMode mode)
\header \o Format \o Description \o Katie's support \header \o Format \o Description \o Katie's support
\row \o PNG \o Portable Network Graphics \o Read/write \row \o PNG \o Portable Network Graphics \o Read/write
\row \o KAT \o Katie Image \o Read/write \row \o KAT \o Katie Image \o Read/write
\row \o PBM \o Portable Bitmap \o Read
\row \o PPM \o Portable Pixmap \o Read/write
\row \o XPM \o X11 Pixmap \o Read \row \o XPM \o X11 Pixmap \o Read
\endtable \endtable

View file

@ -1,403 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Copyright (C) 2016 Ivailo Monev
**
** This file is part of the QtGui module of the Katie Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
**
** GNU Lesser General Public License Usage
** This file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "qppmhandler_p.h"
#ifndef QT_NO_IMAGEFORMAT_PPM
#include "qimage.h"
#include "qvariant.h"
#include "qvector.h"
#include "qcorecommon_p.h"
#include "qguicommon_p.h"
#include <ctype.h>
QT_BEGIN_NAMESPACE
/*****************************************************************************
PBM/PPM (ASCII and RAW) image read/write functions
*****************************************************************************/
static int read_pbm_int(QIODevice *d)
{
char c;
int val = -1;
bool digit;
const int buflen = 100;
QSTACKARRAY(char, buf, buflen);
for (;;) {
if (!d->getChar(&c)) // end of file
break;
digit = isdigit((uchar) c);
if (val != -1) {
if (digit) {
val = 10*val + c - '0';
continue;
} else {
if (c == '#') // comment
d->readLine(buf, buflen);
break;
}
}
if (digit) // first digit
val = c - '0';
else if (isspace((uchar) c))
continue;
else if (c == '#')
(void)d->readLine(buf, buflen);
else
break;
}
return val;
}
static bool read_pbm_header(QIODevice *device, char& type, int& w, int& h, int& mcc)
{
QSTACKARRAY(char, buf, 3);
if (device->read(buf, 3) != 3) // read P[1-6]<white-space>
return false;
if (!(buf[0] == 'P' && isdigit((uchar) buf[1]) && isspace((uchar) buf[2])))
return false;
type = buf[1];
if (type < '1' || type > '6')
return false;
w = read_pbm_int(device); // get image width
h = read_pbm_int(device); // get image height
if (type == '1' || type == '4')
mcc = 1; // ignore max color component
else
mcc = read_pbm_int(device); // get max color component
if (w <= 0 || w > 32767 || h <= 0 || h > 32767 || mcc <= 0)
return false; // weird P.M image
return true;
}
static bool read_pbm_body(QIODevice *device, char type, int w, int h, int mcc, QImage *outImage)
{
int nbits, y;
int pbm_bpl;
bool raw;
QImage::Format format;
switch (type) {
case '1': // ascii PBM
case '4': // raw PBM
nbits = 1;
format = QImage::Format_Mono;
break;
case '3': // ascii PPM
case '6': // raw PPM
nbits = 32;
format = QImage::Format_RGB32;
break;
default:
return false;
}
raw = type >= '4';
int maxc = mcc;
if (maxc > 255)
maxc = 255;
if (outImage->size() != QSize(w, h) || outImage->format() != format) {
*outImage = QImage(w, h, format);
if (outImage->isNull())
return false;
}
pbm_bpl = (nbits*w+7)/8; // bytes per scanline in PBM
if (raw) { // read raw data
if (nbits == 32) { // type 6
pbm_bpl = mcc < 256 ? 3*w : 6*w;
QSTACKARRAY(uchar, buf24, pbm_bpl);
uchar *b;
QRgb *p;
QRgb *end;
for (y=0; y<h; y++) {
if (device->read((char *)buf24, pbm_bpl) != pbm_bpl) {
return false;
}
p = (QRgb *)outImage->scanLine(y);
end = p + w;
b = buf24;
while (p < end) {
if (mcc < 256) {
*p++ = qRgb(b[0],b[1],b[2]);
b += 3;
} else {
*p++ = qRgb(((int(b[0]) * 256 + int(b[1]) + 1) * 256) / (mcc + 1) - 1,
((int(b[2]) * 256 + int(b[3]) + 1) * 256) / (mcc + 1) - 1,
((int(b[4]) * 256 + int(b[5]) + 1) * 256) / (mcc + 1) - 1);
b += 6;
}
}
}
} else { // type 4,5
for (y=0; y<h; y++) {
if (device->read((char *)outImage->scanLine(y), pbm_bpl) != pbm_bpl)
return false;
}
}
} else { // read ascii data
uchar *p;
int n;
for (y=0; y<h; y++) {
p = outImage->scanLine(y);
n = pbm_bpl;
if (nbits == 1) {
int b;
int bitsLeft = w;
while (n--) {
b = 0;
for (int i=0; i<8; i++) {
if (i < bitsLeft)
b = (b << 1) | (read_pbm_int(device) & 1);
else
b = (b << 1) | (0 & 1); // pad it our self if we need to
}
bitsLeft -= 8;
*p++ = b;
}
} else { // 32 bits
n /= 4;
int r, g, b;
if (mcc == maxc) {
while (n--) {
r = read_pbm_int(device);
g = read_pbm_int(device);
b = read_pbm_int(device);
*((QRgb*)p) = qRgb(r, g, b);
p += 4;
}
} else {
while (n--) {
r = read_pbm_int(device) * maxc / mcc;
g = read_pbm_int(device) * maxc / mcc;
b = read_pbm_int(device) * maxc / mcc;
*((QRgb*)p) = qRgb(r, g, b);
p += 4;
}
}
}
}
}
if (nbits == 1) { // black/white bitmap
outImage->setColorTable(monoColorTable());
}
return true;
}
static bool write_pbm_image(QIODevice *out, const QImage &sourceImage, const QByteArray &sourceFormat)
{
QImage image = sourceImage;
const QByteArray format = sourceFormat.left(3); // ignore RAW part
if (format == "pbm") {
image = image.convertToFormat(QImage::Format_Mono);
} else if (format == "ppm") {
image = image.convertToFormat(QImage::Format_ARGB32);
} else {
return false;
}
if (image.depth() == 1) {
if (qGray(image.color(0)) < qGray(image.color(1))) {
// 0=dark/black, 1=light/white - invert
for (int y=0; y<image.height(); y++) {
uchar *p = image.scanLine(y);
uchar *end = p + image.bytesPerLine();
while (p < end)
*p++ ^= 0xff;
}
}
}
uint w = image.width();
uint h = image.height();
QByteArray str("P\n");
str += QByteArray::number(w);
str += ' ';
str += QByteArray::number(h);
str += '\n';
switch (image.depth()) {
case 1: {
str.insert(1, '4');
if (out->write(str, str.length()) != str.length())
return false;
w = (w+7)/8;
for (uint y=0; y<h; y++) {
uchar* line = image.scanLine(y);
if (w != (uint)out->write((char*)line, w))
return false;
}
break;
}
case 32: {
str.insert(1, '6');
str.append("255\n");
if (out->write(str, str.length()) != str.length())
return false;
uint bpl = w*3;
QSTACKARRAY(uchar, buf, bpl);
for (uint y=0; y<h; y++) {
QRgb *b = (QRgb*)image.scanLine(y);
uchar *p = buf;
uchar *end = buf+bpl;
while (p < end) {
QRgb rgb = *b++;
*p++ = qRed(rgb);
*p++ = qGreen(rgb);
*p++ = qBlue(rgb);
}
if (bpl != (uint)out->write((char*)buf, bpl))
return false;
}
break;
}
default:
return false;
}
return true;
}
QPpmHandler::QPpmHandler(const QByteArray &subtype)
: state(Ready),
subType(subtype)
{
}
bool QPpmHandler::readHeader()
{
state = Error;
if (!read_pbm_header(device(), type, width, height, mcc))
return false;
state = ReadHeader;
return true;
}
bool QPpmHandler::canRead() const
{
if (state == Ready && !canRead(device(), &subType))
return false;
if (state != Error) {
setFormat(subType);
return true;
}
return false;
}
bool QPpmHandler::read(QImage *image)
{
if (state == Error)
return false;
if (state == Ready && !readHeader()) {
state = Error;
return false;
}
if (!read_pbm_body(device(), type, width, height, mcc, image)) {
state = Error;
return false;
}
state = Ready;
return true;
}
bool QPpmHandler::write(const QImage &image)
{
return write_pbm_image(device(), image, subType);
}
bool QPpmHandler::supportsOption(QImageIOHandler::ImageOption option) const
{
return (option == QImageIOHandler::Size);
}
QVariant QPpmHandler::option(QImageIOHandler::ImageOption option) const
{
if (option == QImageIOHandler::Size) {
if (state == Error)
return QVariant();
if (state == Ready && !const_cast<QPpmHandler*>(this)->readHeader())
return QVariant();
return QSize(width, height);
}
return QVariant();
}
QByteArray QPpmHandler::name() const
{
return subType.isEmpty() ? QByteArray("ppm") : subType;
}
bool QPpmHandler::canRead(QIODevice *device, QByteArray *subType)
{
if (Q_UNLIKELY(!device)) {
qWarning("QPpmHandler::canRead() called with no device");
return false;
}
QSTACKARRAY(char, head, 2);
if (device->peek(head, sizeof(head)) != sizeof(head)) {
return false;
}
if (head[0] != 'P') {
return false;
}
if (head[1] == '1' || head[1] == '4') {
Q_ASSERT(subType);
*subType = "pbm";
return true;
} else if (head[1] == '3' || head[1] == '6') {
Q_ASSERT(subType);
*subType = "ppm";
return true;
}
return false;
}
QT_END_NAMESPACE
#endif // QT_NO_IMAGEFORMAT_PPM

View file

@ -1,78 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Copyright (C) 2016 Ivailo Monev
**
** This file is part of the QtGui module of the Katie Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
**
** GNU Lesser General Public License Usage
** This file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef QPPMHANDLER_P_H
#define QPPMHANDLER_P_H
//
// W A R N I N G
// -------------
//
// This file is not part of the Katie API. It exists for the convenience
// of the QLibrary class. This header file may change from
// version to version without notice, or even be removed.
//
// We mean it.
//
#include "QtGui/qimageiohandler.h"
#ifndef QT_NO_IMAGEFORMAT_PPM
QT_BEGIN_NAMESPACE
class QByteArray;
class QPpmHandler : public QImageIOHandler
{
public:
QPpmHandler(const QByteArray &subtype = QByteArray());
bool canRead() const final;
bool read(QImage *image) final;
bool write(const QImage &image) final;
QVariant option(QImageIOHandler::ImageOption option) const final;
bool supportsOption(QImageIOHandler::ImageOption option) const final;
QByteArray name() const final;
static bool canRead(QIODevice *device, QByteArray *subType);
private:
bool readHeader();
enum State {
Ready,
ReadHeader,
Error
};
State state;
char type;
int width;
int height;
int mcc;
mutable QByteArray subType;
};
QT_END_NAMESPACE
#endif // QT_NO_IMAGEFORMAT_PPM
#endif // QPPMHANDLER_P_H

View file

@ -369,10 +369,6 @@ QStringList QX11Data::xdndMimeFormatsForAtom(Atom a)
// special cases for uris // special cases for uris
if (atomName == QLatin1String("text/x-moz-url")) if (atomName == QLatin1String("text/x-moz-url"))
formats.append(QLatin1String("text/uri-list")); formats.append(QLatin1String("text/uri-list"));
// special case for images
if (a == XA_PIXMAP)
formats.append(QLatin1String("image/ppm"));
} }
return formats; return formats;
} }
@ -389,68 +385,56 @@ bool QX11Data::xdndMimeDataForAtom(Atom a, QMimeData *mimeData, QByteArray *data
if (atomName == QLatin1String("application/x-color")) if (atomName == QLatin1String("application/x-color"))
*dataFormat = 16; *dataFormat = 16;
ret = true; ret = true;
} else { } else if ((a == ATOM(UTF8_STRING) || a == XA_STRING
if ((a == ATOM(UTF8_STRING) || a == XA_STRING || a == ATOM(TEXT) || a == ATOM(COMPOUND_TEXT))
|| a == ATOM(TEXT) || a == ATOM(COMPOUND_TEXT)) && QInternalMimeData::hasFormatHelper(QLatin1String("text/plain"), mimeData)) {
&& QInternalMimeData::hasFormatHelper(QLatin1String("text/plain"), mimeData)) { if (a == ATOM(UTF8_STRING)){
if (a == ATOM(UTF8_STRING)){ *data = QInternalMimeData::renderDataHelper(QLatin1String("text/plain"), mimeData);
*data = QInternalMimeData::renderDataHelper(QLatin1String("text/plain"), mimeData);
ret = true;
} else if (a == XA_STRING) {
*data = QString::fromUtf8(QInternalMimeData::renderDataHelper(
QLatin1String("text/plain"), mimeData)).toLocal8Bit();
ret = true;
} else if (a == ATOM(TEXT) || a == ATOM(COMPOUND_TEXT)) {
// the ICCCM states that TEXT and COMPOUND_TEXT are in the
// encoding of choice, so we choose the encoding of the locale
QByteArray strData = QString::fromUtf8(QInternalMimeData::renderDataHelper(
QLatin1String("text/plain"), mimeData)).toLocal8Bit();
char *list[] = { strData.data(), NULL };
XICCEncodingStyle style = (a == ATOM(COMPOUND_TEXT))
? XCompoundTextStyle : XStdICCTextStyle;
XTextProperty textprop;
if (list[0] != NULL
&& XmbTextListToTextProperty(qt_x11Data->display, list, 1, style,
&textprop) == Success) {
*atomFormat = textprop.encoding;
*dataFormat = textprop.format;
*data = QByteArray((const char *) textprop.value, textprop.nitems * textprop.format / 8);
ret = true;
DEBUG(" textprop type %lx\n"
" textprop name '%s'\n"
" format %d\n"
" %ld items\n"
" %d bytes\n",
textprop.encoding,
qt_x11Data->xdndMimeAtomToString(textprop.encoding).toLatin1().data(),
textprop.format, textprop.nitems, data->size());
XFree(textprop.value);
}
}
} else if (atomName == QLatin1String("text/x-moz-url") &&
QInternalMimeData::hasFormatHelper(QLatin1String("text/uri-list"), mimeData)) {
QByteArray uri = QInternalMimeData::renderDataHelper(
QLatin1String("text/uri-list"), mimeData).split('\n').first();
QString mozUri = QString::fromLatin1(uri, uri.size());
mozUri += QLatin1Char('\n');
*data = QByteArray(reinterpret_cast<const char *>(mozUri.utf16()), mozUri.length() * 2);
ret = true; ret = true;
} else if ((a == XA_PIXMAP || a == XA_BITMAP) && mimeData->hasImage()) { } else if (a == XA_STRING) {
QPixmap pm = qvariant_cast<QPixmap>(mimeData->imageData()); *data = QString::fromUtf8(QInternalMimeData::renderDataHelper(
if (a == XA_BITMAP && pm.depth() != 1) { QLatin1String("text/plain"), mimeData)).toLocal8Bit();
QImage img = pm.toImage();
img = img.convertToFormat(QImage::Format_MonoLSB);
pm = QPixmap::fromImage(img);
}
Pixmap handle = pm.toX11Pixmap();
*data = QByteArray(reinterpret_cast<const char *>(&handle), sizeof(Pixmap));
ret = true; ret = true;
} else { } else if (a == ATOM(TEXT) || a == ATOM(COMPOUND_TEXT)) {
DEBUG("QClipboard: xdndMimeDataForAtom(): converting to type '%s' is not supported", qPrintable(atomName)); // the ICCCM states that TEXT and COMPOUND_TEXT are in the
// encoding of choice, so we choose the encoding of the locale
QByteArray strData = QString::fromUtf8(QInternalMimeData::renderDataHelper(
QLatin1String("text/plain"), mimeData)).toLocal8Bit();
char *list[] = { strData.data(), NULL };
XICCEncodingStyle style = (a == ATOM(COMPOUND_TEXT))
? XCompoundTextStyle : XStdICCTextStyle;
XTextProperty textprop;
if (list[0] != NULL
&& XmbTextListToTextProperty(qt_x11Data->display, list, 1, style,
&textprop) == Success) {
*atomFormat = textprop.encoding;
*dataFormat = textprop.format;
*data = QByteArray((const char *) textprop.value, textprop.nitems * textprop.format / 8);
ret = true;
DEBUG(" textprop type %lx\n"
" textprop name '%s'\n"
" format %d\n"
" %ld items\n"
" %d bytes\n",
textprop.encoding,
qt_x11Data->xdndMimeAtomToString(textprop.encoding).toLatin1().data(),
textprop.format, textprop.nitems, data->size());
XFree(textprop.value);
}
} }
} else if (atomName == QLatin1String("text/x-moz-url") &&
QInternalMimeData::hasFormatHelper(QLatin1String("text/uri-list"), mimeData)) {
QByteArray uri = QInternalMimeData::renderDataHelper(
QLatin1String("text/uri-list"), mimeData).split('\n').first();
QString mozUri = QString::fromLatin1(uri, uri.size());
mozUri += QLatin1Char('\n');
*data = QByteArray(reinterpret_cast<const char *>(mozUri.utf16()), mozUri.length() * 2);
ret = true;
} else {
DEBUG("QClipboard: xdndMimeDataForAtom(): converting to type '%s' is not supported", qPrintable(atomName));
} }
return ret && data != 0; return ret && data != 0;
} }
@ -470,11 +454,6 @@ QList<Atom> QX11Data::xdndMimeAtomsForFormat(const QString &format)
// special cases for uris // special cases for uris
} else if (format == QLatin1String("text/uri-list")) { } else if (format == QLatin1String("text/uri-list")) {
atoms.append(xdndMimeStringToAtom(QLatin1String("text/x-moz-url"))); atoms.append(xdndMimeStringToAtom(QLatin1String("text/x-moz-url")));
//special cases for images
} else if (format == QLatin1String("image/ppm")) {
atoms.append(XA_PIXMAP);
} else if (format == QLatin1String("image/pbm")) {
atoms.append(XA_BITMAP);
} }
return atoms; return atoms;
@ -523,24 +502,6 @@ QVariant QX11Data::xdndMimeConvertToFormat(Atom a, const QByteArray &data, const
} }
} }
// special case for images
if (format == QLatin1String("image/ppm")) {
if (a == XA_PIXMAP && data.size() == sizeof(Pixmap)) {
Pixmap xpm = *((Pixmap*)data.data());
if (!xpm)
return QByteArray();
QPixmap qpm = QPixmap::fromX11Pixmap(xpm);
XFreePixmap(qt_x11Data->display, xpm);
QImageWriter imageWriter;
imageWriter.setFormat("PPMRAW");
QImage imageToWrite = qpm.toImage();
QBuffer buf;
buf.open(QIODevice::WriteOnly);
imageWriter.setDevice(&buf);
imageWriter.write(imageToWrite);
return buf.buffer();
}
}
return QVariant(); return QVariant();
} }
@ -571,12 +532,6 @@ Atom QX11Data::xdndMimeAtomForFormat(const QString &format, QVariant::Type reque
return a; return a;
} }
// find match for image
if (format == QLatin1String("image/ppm")) {
if (atoms.contains(XA_PIXMAP))
return XA_PIXMAP;
}
// for string/text requests try to use a format with a well-defined charset // for string/text requests try to use a format with a well-defined charset
// first to avoid encoding problems // first to avoid encoding problems
if (requestedType == QVariant::String if (requestedType == QVariant::String

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long