100#ifdef QIMAGEREADER_DEBUG
115#include <private/qfactoryloader_p.h>
116#include <QtCore/private/qlocking_p.h>
119#include <private/qimage_p.h>
122#include <private/qbmphandler_p.h>
123#include <private/qppmhandler_p.h>
124#include <private/qxbmhandler_p.h>
125#include <private/qxpmhandler_p.h>
126#ifndef QT_NO_IMAGEFORMAT_PNG
127#include <private/qpnghandler_p.h>
130#include <private/qimagereaderwriterhelpers_p.h>
131#include <qtgui_tracepoints_p.h>
145 bool autoDetectImageFormat,
146 bool ignoresFormatAndExtension)
148 if (!autoDetectImageFormat &&
format.isEmpty())
155#ifndef QT_NO_IMAGEFORMATPLUGIN
157 const auto locker = qt_scoped_lock(
mutex);
163 const PluginKeyMap
keyMap = l->keyMap();
165#ifdef QIMAGEREADER_DEBUG
166 qDebug() <<
"QImageReader::createReadHandler( device =" << (
void *)
device <<
", format =" <<
format <<
"),"
167 <<
keyMap.uniqueKeys().size() <<
"plugins available: " <<
keyMap;
170 int suffixPluginIndex = -1;
173 if (
device &&
format.isEmpty() && autoDetectImageFormat && !ignoresFormatAndExtension) {
178#ifdef QIMAGEREADER_DEBUG
182#ifndef QT_NO_IMAGEFORMATPLUGIN
185#ifdef QIMAGEREADER_DEBUG
186 qDebug() <<
"QImageReader::createReadHandler: suffix recognized; the"
187 << suffix <<
"plugin might be able to read this";
189 suffixPluginIndex =
index;
198 if (ignoresFormatAndExtension)
201#ifndef QT_NO_IMAGEFORMATPLUGIN
202 if (suffixPluginIndex != -1) {
211#ifdef QIMAGEREADER_DEBUG
212 qDebug() <<
"QImageReader::createReadHandler: using the" << suffix
221 if (!handler && !testFormat.
isEmpty() && !ignoresFormatAndExtension) {
226 if (autoDetectImageFormat) {
227 const int keyCount =
keyMap.size();
228 for (
int i = 0;
i < keyCount; ++
i) {
229 if (
i != suffixPluginIndex) {
232#ifdef QIMAGEREADER_DEBUG
233 qDebug() <<
"QImageReader::createReadHandler: the" <<
keyMap.keys().at(
i) <<
"plugin can read this format";
242 if (testIndex != -1) {
245#ifdef QIMAGEREADER_DEBUG
246 qDebug() <<
"QImageReader::createReadHandler: the" << testFormat <<
"plugin can read this format";
260 if (!handler && !testFormat.
isEmpty()) {
262#ifndef QT_NO_IMAGEFORMAT_PNG
263 }
else if (testFormat ==
"png") {
266#ifndef QT_NO_IMAGEFORMAT_BMP
267 }
else if (testFormat ==
"bmp") {
269 }
else if (testFormat ==
"dib") {
272#ifndef QT_NO_IMAGEFORMAT_XPM
273 }
else if (testFormat ==
"xpm") {
276#ifndef QT_NO_IMAGEFORMAT_XBM
277 }
else if (testFormat ==
"xbm") {
281#ifndef QT_NO_IMAGEFORMAT_PPM
282 }
else if (testFormat ==
"pbm" || testFormat ==
"pbmraw" || testFormat ==
"pgm"
283 || testFormat ==
"pgmraw" || testFormat ==
"ppm" || testFormat ==
"ppmraw") {
289#ifdef QIMAGEREADER_DEBUG
291 qDebug() <<
"QImageReader::createReadHandler: using the built-in handler for" << testFormat;
303 bool canRead = handler->
canRead();
309#ifdef QIMAGEREADER_DEBUG
310 qDebug() <<
"QImageReader::createReadHandler: the" << suffix <<
"handler can not read this file";
318#ifndef QT_NO_IMAGEFORMATPLUGIN
319 if (!handler && (autoDetectImageFormat || ignoresFormatAndExtension)) {
322 const int keyCount =
keyMap.size();
323 for (
int i = 0;
i < keyCount; ++
i) {
324 if (
i != suffixPluginIndex) {
328#ifdef QIMAGEREADER_DEBUG
329 qDebug() <<
"QImageReader::createReadHandler: the" <<
keyMap.value(
i) <<
"plugin can read this data";
340 if (!handler && (autoDetectImageFormat || ignoresFormatAndExtension)) {
343 int currentFormat = 0;
357 while (
device && numFormats >= 0) {
359 switch (currentFormat) {
360#ifndef QT_NO_IMAGEFORMAT_PNG
366#ifndef QT_NO_IMAGEFORMAT_BMP
372#ifndef QT_NO_IMAGEFORMAT_XPM
378#ifndef QT_NO_IMAGEFORMAT_PPM
388#ifndef QT_NO_IMAGEFORMAT_XBM
397 if (!
device->isSequential())
401#ifdef QIMAGEREADER_DEBUG
402 qDebug(
"QImageReader::createReadHandler: the %s built-in handler can read this data",
416#ifdef QIMAGEREADER_DEBUG
417 qDebug(
"QImageReader::createReadHandler: no handlers found. giving up.");
472 : autoDetectImageFormat(true), ignoresFormatAndExtension(
false)
524 int currentFormatIndex = extensions.
indexOf(
format.toLower());
525 if (currentFormatIndex > 0)
529 int currentExtension = 0;
537 }
while (!
file->
isOpen() && currentExtension < extensions.
size());
550 errorString = QImageReader::tr(
"Unsupported image format");
1083 return QImageIOHandler::Transformations(
option);
1192 qWarning(
"QImageReader::read: cannot read into null pointer");
1218 Q_TRACE(QImageReader_read_before_reading,
this, filename.
isEmpty() ? u
"unknown"_s : filename);
1227 d->
errorString = QImageReader::tr(
"Unable to read image data");
1284 if (!disableNxImageLoading) {
1286 if (suffix.
size() == 3 && suffix[0] ==
'@' && suffix[1] >=
'2' && suffix[1] <=
'9' && suffix[2] ==
'x')
1287 image->setDevicePixelRatio(suffix[1] -
'0');
1424 return QImageReader::tr(
"Unknown error");
1555 static int envLimit = []() {
1558 return ok ?
res : -1;
IOBluetoothDevice * device
bool canRead() const override
Returns true if an image can be read from the device (i.e., the image format is supported,...
qsizetype size() const noexcept
Returns the number of bytes in this byte array.
bool isEmpty() const noexcept
Returns true if the byte array has size 0; otherwise returns false.
The QColor class provides colors based on RGB, HSV or CMYK values.
FileError error() const
Returns the file error status.
\inmodule QtCore \reentrant
QString baseName() const
Returns the base name of the file without the path.
QString suffix() const
Returns the suffix (extension) of the file.
bool open(OpenMode flags) override
Opens the file using OpenMode mode, returning true if successful; otherwise false.
void setFileName(const QString &name)
Sets the name of the file.
QString fileName() const override
Returns the name set by setFileName() or to the QFile constructors.
virtual bool isEmpty() const
\inmodule QtCore \reentrant
virtual bool open(QIODeviceBase::OpenMode mode)
Opens the device and sets its OpenMode to mode.
bool isOpen() const
Returns true if the device is open; otherwise returns false.
QString errorString() const
Returns a human-readable description of the last device error that occurred.
The QImageIOHandler class defines the common image I/O interface for all image formats in Qt.
virtual QRect currentImageRect() const
Returns the rect of the current image.
virtual int nextImageDelay() const
For image formats that support animation, this function returns the number of milliseconds to wait un...
virtual int imageCount() const
For image formats that support animation, this function returns the number of images in the animation...
ImageOption
This enum describes the different options supported by QImageIOHandler.
virtual bool jumpToNextImage()
For image formats that support animation, this function jumps to the next image.
virtual int currentImageNumber() const
For image formats that support animation, this function returns the sequence number of the current im...
virtual bool canRead() const =0
Returns true if an image can be read from the device (i.e., the image format is supported,...
virtual void setOption(ImageOption option, const QVariant &value)
Sets the option option with the value value.
QByteArray format() const
Returns the format that is currently assigned to QImageIOHandler.
virtual bool supportsOption(ImageOption option) const
Returns true if the QImageIOHandler supports the option option; otherwise returns false.
virtual QVariant option(ImageOption option) const
Returns the value assigned to option as a QVariant.
void setDevice(QIODevice *device)
Sets the device of the QImageIOHandler to device.
virtual bool jumpToImage(int imageNumber)
For image formats that support animation, this function jumps to the image whose sequence number is i...
virtual int loopCount() const
For image formats that support animation, this function returns the number of times the animation sho...
virtual bool read(QImage *image)=0
Read an image from the device, and stores it in image.
void setFormat(const QByteArray &format)
Sets the format of the QImageIOHandler to format.
virtual QImageIOHandler * create(QIODevice *device, const QByteArray &format=QByteArray()) const =0
Creates and returns a QImageIOHandler subclass, with device and format set.
virtual Capabilities capabilities(QIODevice *device, const QByteArray &format) const =0
Returns the capabilities of the plugin, based on the data in device and the format format.
QImageReaderPrivate(QImageReader *qq)
enum QImageReaderPrivate::@197 autoTransform
QImageReader::ImageReaderError imageReaderError
bool ignoresFormatAndExtension
QMap< QString, QString > text
bool autoDetectImageFormat
QImageIOHandler * handler
The QImageReader class provides a format independent interface for reading images from files or other...
void setScaledClipRect(const QRect &rect)
Sets the scaled clip rect to rect.
QString errorString() const
Returns a human readable description of the last error that occurred.
~QImageReader()
Destructs the QImageReader object.
bool decideFormatFromContent() const
Returns whether the image reader should decide which plugin to use only based on the contents of the ...
int imageCount() const
For image formats that support animation, this function returns the total number of images in the ani...
void setDevice(QIODevice *device)
Sets QImageReader's device to device.
bool autoTransform() const
bool autoDetectImageFormat() const
Returns true if image format autodetection is enabled on this image reader; otherwise returns false.
static QList< QByteArray > supportedMimeTypes()
Returns the list of MIME types supported by QImageReader.
QSize scaledSize() const
Returns the scaled size of the image.
QString fileName() const
If the currently assigned device is a QFile, or if setFileName() has been called, this function retur...
void setFileName(const QString &fileName)
Sets the file name of QImageReader to fileName.
void setScaledSize(const QSize &size)
Sets the scaled size of the image to size.
ImageReaderError
This enum describes the different types of errors that can occur when reading images with QImageReade...
QImageIOHandler::Transformations transformation() const
QIODevice * device() const
Returns the device currently assigned to QImageReader, or \nullptr if no device has been assigned.
QByteArray subType() const
QColor backgroundColor() const
static void setAllocationLimit(int mbLimit)
QRect currentImageRect() const
For image formats that support animation, this function returns the rect for the current frame.
bool supportsAnimation() const
void setDecideFormatFromContent(bool ignored)
If ignored is set to true, then the image reader will ignore specified formats or file extensions and...
void setAutoTransform(bool enabled)
QString text(const QString &key) const
bool jumpToImage(int imageNumber)
For image formats that support animation, this function skips to the image whose sequence number is i...
QRect clipRect() const
Returns the clip rect (also known as the ROI, or Region Of Interest) of the image.
QImageReader()
Constructs an empty QImageReader object.
bool supportsOption(QImageIOHandler::ImageOption option) const
static int allocationLimit()
QList< QByteArray > supportedSubTypes() const
static QList< QByteArray > imageFormatsForMimeType(const QByteArray &mimeType)
QByteArray format() const
Returns the format QImageReader uses for reading images.
bool canRead() const
Returns true if an image can be read for the device (i.e., the image format is supported,...
static QList< QByteArray > supportedImageFormats()
Returns the list of image formats supported by QImageReader.
void setQuality(int quality)
void setBackgroundColor(const QColor &color)
bool jumpToNextImage()
For image formats that support animation, this function steps over the current image,...
void setFormat(const QByteArray &format)
Sets the format QImageReader will use when reading images, to format.
QSize size() const
Returns the size of the image, without actually reading the image contents.
void setClipRect(const QRect &rect)
Sets the image clip rect (also known as the ROI, or Region Of Interest) to rect.
void setAutoDetectImageFormat(bool enabled)
If enabled is true, image format autodetection is enabled; otherwise, it is disabled.
int currentImageNumber() const
For image formats that support animation, this function returns the sequence number of the current fr...
ImageReaderError error() const
Returns the type of error that occurred last.
QRect scaledClipRect() const
Returns the scaled clip rect of the image.
int nextImageDelay() const
For image formats that support animation, this function returns the number of milliseconds to wait un...
QStringList textKeys() const
int loopCount() const
For image formats that support animation, this function returns the number of times the animation sho...
QImage::Format imageFormat() const
QImage read()
Reads an image from the device.
Format
The following image formats are available in Qt.
qsizetype size() const noexcept
void swapItemsAt(qsizetype i, qsizetype j)
const_reference at(qsizetype i) const noexcept
T value(const Key &key, const T &defaultValue=T()) const
QList< Key > keys() const
bool canRead() const override
Returns true if an image can be read from the device (i.e., the image format is supported,...
bool canRead() const override
Returns true if an image can be read from the device (i.e., the image format is supported,...
\inmodule QtCore\reentrant
constexpr bool isValid() const noexcept
Returns true if the rectangle is valid, otherwise returns false.
constexpr bool isNull() const noexcept
Returns true if the rectangle is a null rectangle, otherwise returns false.
constexpr bool isValid() const noexcept
Returns true if both the width and height is equal to or greater than 0; otherwise returns false.
\macro QT_RESTRICTED_CAST_FROM_ASCII
QString right(qsizetype n) const
Returns a substring that contains the n rightmost characters of the string.
QByteArray toLatin1() const &
static QString fromLatin1(QByteArrayView ba)
This is an overloaded member function, provided for convenience. It differs from the above function o...
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
QString toLower() const &
int toInt(bool *ok=nullptr) const
Returns the variant as an int if the variant has userType() \l QMetaType::Int, \l QMetaType::Bool,...
QSize toSize() const
Returns the variant as a QSize if the variant has userType() \l QMetaType::QSize; otherwise returns a...
QString toString() const
Returns the variant as a QString if the variant has a userType() including, but not limited to:
bool toBool() const
Returns the variant as a bool if the variant has userType() Bool.
QByteArray toByteArray() const
Returns the variant as a QByteArray if the variant has userType() \l QMetaType::QByteArray or \l QMet...
bool canRead() const override
Returns true if an image can be read from the device (i.e., the image format is supported,...
bool canRead() const override
Returns true if an image can be read from the device (i.e., the image format is supported,...
QList< QByteArray > imageFormatsForMimeType(const QByteArray &mimeType, Capability cap)
const PluginKeyMap keyMap
QSharedPointer< QFactoryLoader > pluginLoader()
QList< QByteArray > supportedImageFormats(Capability cap)
static const _qt_BuiltInFormatStruct _qt_BuiltInFormats[]
QList< QByteArray > supportedMimeTypes(Capability cap)
Combined button and popup list for selecting options.
Q_GUI_EXPORT void qt_imageTransform(QImage &src, QImageIOHandler::Transformations orient)
QMap< QString, QString > qt_getImageTextFromDescription(const QString &description)
void qt_imageTransform(QImage &src, QImageIOHandler::Transformations orient)
static QImageIOHandler * createReadHandlerHelper(QIODevice *device, const QByteArray &format, bool autoDetectImageFormat, bool ignoresFormatAndExtension)
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLenum GLenum GLsizei const GLuint GLboolean enabled
GLint GLsizei GLsizei GLenum format
GLdouble GLdouble GLdouble GLdouble q
Q_CORE_EXPORT bool qEnvironmentVariableIsEmpty(const char *varName) noexcept
Q_CORE_EXPORT int qEnvironmentVariableIntValue(const char *varName, bool *ok=nullptr) noexcept
#define Q_TRACE_ENABLED(x)
#define Q_TRACE_POINT(provider, tracepoint,...)
qsizetype indexOf(const AT &t, qsizetype from=0) const noexcept