remove XPM-specialized QImage and QPixmap constructors

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2022-10-20 21:09:27 +03:00
parent 9271472f96
commit 681102cb8e
6 changed files with 9 additions and 104 deletions

View file

@ -850,37 +850,6 @@ QImage::QImage(const char *fileName, const char *format)
}
#endif
#ifndef QT_NO_IMAGEFORMAT_XPM
extern bool qt_read_xpm_array(const char* const *source, QImage &image);
/*!
Constructs an image from the given \a xpm image.
Make sure that the image is a valid XPM image. Errors are silently
ignored.
Note that it's possible to squeeze the XPM variable a little bit
by using an unusual declaration:
\snippet doc/src/snippets/code/src_gui_image_qimage.cpp 2
The extra \c const makes the entire definition read-only, which is
slightly more efficient (e.g., when the code is in a shared
library) and able to be stored in ROM with the application.
*/
QImage::QImage(const char * const xpm[])
: QPaintDevice(),
d(nullptr)
{
if (Q_UNLIKELY(!xpm))
return;
if (Q_UNLIKELY(!qt_read_xpm_array(xpm, *this)))
// Issue: Warning because the constructor may be ambigious
qWarning("QImage::QImage(), XPM is not supported");
}
#endif // QT_NO_IMAGEFORMAT_XPM
/*!
\fn QImage::QImage(const QByteArray &data)

View file

@ -63,9 +63,6 @@ public:
QImage(uchar *data, int width, int height, int bytesPerLine, Format format);
QImage(const uchar *data, int width, int height, int bytesPerLine, Format format);
#ifndef QT_NO_IMAGEFORMAT_XPM
explicit QImage(const char * const xpm[]);
#endif
explicit QImage(const QString &fileName, const char *format = nullptr);
#ifndef QT_NO_CAST_FROM_ASCII
explicit QImage(const char *fileName, const char *format = nullptr);

View file

@ -231,37 +231,6 @@ QPixmap::QPixmap(const QPixmap &pixmap)
}
}
/*!
Constructs a pixmap from the given \a xpm data, which must be a
valid XPM image.
Errors are silently ignored.
Note that it's possible to squeeze the XPM variable a little bit
by using an unusual declaration:
\snippet doc/src/snippets/code/src_gui_image_qpixmap.cpp 0
The extra \c const makes the entire definition read-only, which is
slightly more efficient (for example, when the code is in a shared
library) and ROMable when the application is to be stored in ROM.
*/
#ifndef QT_NO_IMAGEFORMAT_XPM
QPixmap::QPixmap(const char * const xpm[])
: QPaintDevice()
{
init(0, 0, QPixmapData::PixmapType);
if (!xpm)
return;
QImage image(xpm);
if (!image.isNull()) {
*this = fromImage(image);
}
}
#endif
/*!
Destroys the pixmap.
*/

View file

@ -50,9 +50,6 @@ public:
QPixmap(int w, int h);
QPixmap(const QSize &);
QPixmap(const QString& fileName, const char *format = nullptr, Qt::ImageConversionFlags flags = Qt::AutoColor);
#ifndef QT_NO_IMAGEFORMAT_XPM
QPixmap(const char * const xpm[]);
#endif
QPixmap(const QPixmap &);
~QPixmap();

View file

@ -46,14 +46,8 @@ static quint64 xpmHash(const char *str)
// Skip until ", read until the next ", return the rest in *buf
// Returns false on error, true on success
static bool read_xpm_string(QByteArray &buf, QIODevice *d, const char * const *source, int &index,
QByteArray &state)
static bool read_xpm_string(QByteArray &buf, QIODevice *d, QByteArray &state)
{
if (source) {
buf = source[index++];
return true;
}
buf = "";
bool gotQuote = false;
int offset = 0;
@ -93,12 +87,12 @@ static bool is_xpm_color_spec_prefix(const QByteArray& prefix)
// Reads XPM header.
static bool read_xpm_header(
QIODevice *device, const char * const * source, int& index, QByteArray &state,
QIODevice *device, QByteArray &state,
int *cpp, int *ncols, int *w, int *h)
{
QByteArray buf(200, 0);
if (!read_xpm_string(buf, device, source, index, state))
if (!read_xpm_string(buf, device, state))
return false;
if (sscanf(buf, "%d %d %d %d", w, h, ncols, cpp) < 4)
@ -109,7 +103,7 @@ static bool read_xpm_header(
// Reads XPM body (color information & pixels).
static bool read_xpm_body(
QIODevice *device, const char * const * source, int& index, QByteArray& state,
QIODevice *device, QByteArray& state,
int cpp, int ncols, int w, int h, QImage& image)
{
if (cpp < 0 || cpp > 15)
@ -120,7 +114,7 @@ static bool read_xpm_body(
QByteArray buf(200, 0);
for(int currentColor=0; currentColor < ncols; ++currentColor) {
if (Q_UNLIKELY(!read_xpm_string(buf, device, source, index, state))) {
if (Q_UNLIKELY(!read_xpm_string(buf, device, state))) {
qWarning("QImage: XPM color specification missing");
return false;
}
@ -178,7 +172,7 @@ static bool read_xpm_body(
// Read pixels
QSTACKARRAY(char, b, 16);
for(int y=0; y<h; y++) {
if (!read_xpm_string(buf, device, source, index, state)) {
if (!read_xpm_string(buf, device, state)) {
qWarning("QImage: XPM pixels missing on image line %d", y);
return false;
}
@ -209,35 +203,15 @@ static bool read_xpm_body(
return true;
}
//
// INTERNAL
//
// Reads an .xpm from characters array
//
bool qt_read_xpm_array(const char * const * source, QImage &image)
{
if (!source)
return true;
QByteArray state;
int cpp, ncols, w, h, index = 0;
if (!read_xpm_header(nullptr, source, index, state, &cpp, &ncols, &w, &h))
return false;
return read_xpm_body(nullptr, source, index, state, cpp, ncols, w, h, image);
}
QXpmHandler::QXpmHandler()
: state(Ready), index(0)
: state(Ready)
{
}
bool QXpmHandler::readHeader()
{
state = Error;
if (!read_xpm_header(device(), nullptr, index, buffer, &cpp, &ncols, &width, &height))
if (!read_xpm_header(device(), buffer, &cpp, &ncols, &width, &height))
return false;
state = ReadHeader;
return true;
@ -269,7 +243,7 @@ bool QXpmHandler::read(QImage *image)
return false;
}
if (!read_xpm_body(device(), nullptr, index, buffer, cpp, ncols, width, height, *image)) {
if (!read_xpm_body(device(), buffer, cpp, ncols, width, height, *image)) {
state = Error;
return false;
}

View file

@ -66,7 +66,6 @@ private:
int ncols;
int cpp;
QByteArray buffer;
int index;
QString fileName;
};