diff options
Diffstat (limited to 'src/gui/image')
-rw-r--r-- | src/gui/image/qicon.cpp | 4 | ||||
-rw-r--r-- | src/gui/image/qiconloader.cpp | 1 | ||||
-rw-r--r-- | src/gui/image/qimage.cpp | 117 | ||||
-rw-r--r-- | src/gui/image/qimage.h | 13 | ||||
-rw-r--r-- | src/gui/image/qimagereader.cpp | 33 | ||||
-rw-r--r-- | src/gui/image/qimagereader.h | 3 | ||||
-rw-r--r-- | src/gui/image/qpaintengine_pic.cpp | 1 | ||||
-rw-r--r-- | src/gui/image/qpicture.cpp | 4 | ||||
-rw-r--r-- | src/gui/image/qpicture_p.h | 5 | ||||
-rw-r--r-- | src/gui/image/qpixmapcache.cpp | 38 | ||||
-rw-r--r-- | src/gui/image/qpixmapcache.h | 11 | ||||
-rw-r--r-- | src/gui/image/qpnghandler.cpp | 22 |
12 files changed, 201 insertions, 51 deletions
diff --git a/src/gui/image/qicon.cpp b/src/gui/image/qicon.cpp index cafc966fbb..f115707500 100644 --- a/src/gui/image/qicon.cpp +++ b/src/gui/image/qicon.cpp @@ -362,7 +362,7 @@ static inline int origIcoDepth(const QImage &image) return s.isEmpty() ? 32 : s.toInt(); } -static inline int findBySize(const QList<QImage> &images, const QSize &size) +static inline int findBySize(const QVector<QImage> &images, const QSize &size) { for (int i = 0; i < images.size(); ++i) { if (images.at(i).size() == size) @@ -426,7 +426,7 @@ void QPixmapIconEngine::addFile(const QString &fileName, const QSize &size, QIco // these files may contain low-resolution images. As this information is lost, // ICOReader sets the original format as an image text key value. Read all matching // images into a list trying to find the highest quality per size. - QList<QImage> icoImages; + QVector<QImage> icoImages; while (imageReader.read(&image)) { if (ignoreSize || image.size() == size) { const int position = findBySize(icoImages, image.size()); diff --git a/src/gui/image/qiconloader.cpp b/src/gui/image/qiconloader.cpp index fa14c84e83..d3553f28be 100644 --- a/src/gui/image/qiconloader.cpp +++ b/src/gui/image/qiconloader.cpp @@ -42,7 +42,6 @@ #include <QtGui/QIconEngine> #include <QtGui/QPalette> #include <QtCore/QList> -#include <QtCore/QHash> #include <QtCore/QDir> #include <QtCore/QSettings> #include <QtGui/QPainter> diff --git a/src/gui/image/qimage.cpp b/src/gui/image/qimage.cpp index cd0cbf7f49..3c192a237e 100644 --- a/src/gui/image/qimage.cpp +++ b/src/gui/image/qimage.cpp @@ -476,6 +476,10 @@ bool QImageData::checkForAlphaPixels() const \snippet code/src_gui_image_qimage.cpp 1 \endtable + For images with more than 8-bit per color-channel. The methods + setPixelColor() and pixelColor() can be used to set and get + with QColor values. + QImage also provide the scanLine() function which returns a pointer to the pixel data at the scanline with the given index, and the bits() function which returns a pointer to the first pixel @@ -1769,11 +1773,11 @@ void QImage::fill(const QColor &color) break; case QImage::Format_BGR30: case QImage::Format_A2BGR30_Premultiplied: - fill(qConvertArgb32ToA2rgb30<PixelOrderBGR>(color.rgba())); + fill(qConvertRgb64ToRgb30<PixelOrderBGR>(color.rgba64())); break; case QImage::Format_RGB30: case QImage::Format_A2RGB30_Premultiplied: - fill(qConvertArgb32ToA2rgb30<PixelOrderRGB>(color.rgba())); + fill(qConvertRgb64ToRgb30<PixelOrderRGB>(color.rgba64())); break; case QImage::Format_RGB16: fill((uint) qConvertRgb32To16(color.rgba())); @@ -2190,9 +2194,10 @@ int QImage::pixelIndex(int x, int y) const If the \a position is not valid, the results are undefined. \warning This function is expensive when used for massive pixel - manipulations. + manipulations. Use constBits() or constScanLine() when many + pixels needs to be read. - \sa setPixel(), valid(), {QImage#Pixel Manipulation}{Pixel + \sa setPixel(), valid(), constBits(), constScanLine(), {QImage#Pixel Manipulation}{Pixel Manipulation} */ @@ -2242,25 +2247,23 @@ QRgb QImage::pixel(int x, int y) const return *layout->convertToARGB32PM(&result, ptr, 1, layout, 0); } - /*! \fn void QImage::setPixel(const QPoint &position, uint index_or_rgb) Sets the pixel index or color at the given \a position to \a index_or_rgb. - If the image's format is either monochrome or 8-bit, the given \a + If the image's format is either monochrome or paletted, the given \a index_or_rgb value must be an index in the image's color table, otherwise the parameter must be a QRgb value. If \a position is not a valid coordinate pair in the image, or if \a index_or_rgb >= colorCount() in the case of monochrome and - 8-bit images, the result is undefined. + paletted images, the result is undefined. \warning This function is expensive due to the call of the internal \c{detach()} function called within; if performance is a concern, we - recommend the use of \l{QImage::}{scanLine()} to access pixel data - directly. + recommend the use of scanLine() or bits() to access pixel data directly. \sa pixel(), {QImage#Pixel Manipulation}{Pixel Manipulation} */ @@ -2348,6 +2351,102 @@ void QImage::setPixel(int x, int y, uint index_or_rgb) } /*! + \fn QColor QImage::pixelColor(const QPoint &position) const + \since 5.6 + + Returns the color of the pixel at the given \a position as a QColor. + + If the \a position is not valid, an invalid QColor is returned. + + \warning This function is expensive when used for massive pixel + manipulations. Use constBits() or constScanLine() when many + pixels needs to be read. + + \sa setPixel(), valid(), constBits(), constScanLine(), {QImage#Pixel Manipulation}{Pixel + Manipulation} +*/ + +/*! + \overload + \since 5.6 + + Returns the color of the pixel at coordinates (\a x, \a y) as a QColor. +*/ +QColor QImage::pixelColor(int x, int y) const +{ + if (!d || x < 0 || x >= d->width || y < 0 || y >= height()) { + qWarning("QImage::pixelColor: coordinate (%d,%d) out of range", x, y); + return QColor(); + } + + const uchar * s = constScanLine(y); + switch (d->format) { + case Format_BGR30: + case Format_A2BGR30_Premultiplied: + return QColor(qConvertA2rgb30ToRgb64<PixelOrderBGR>(reinterpret_cast<const quint32 *>(s)[x])); + case Format_RGB30: + case Format_A2RGB30_Premultiplied: + return QColor(qConvertA2rgb30ToRgb64<PixelOrderRGB>(reinterpret_cast<const quint32 *>(s)[x])); + default: + return QColor(pixel(x, y)); + } +} + +/*! + \fn void QImage::setPixelColor(const QPoint &position, const QColor &color) + \since 5.6 + + Sets the color at the given \a position to \a color. + + If \a position is not a valid coordinate pair in the image, or + the image's format is either monochrome or paletted, the result is undefined. + + \warning This function is expensive due to the call of the internal + \c{detach()} function called within; if performance is a concern, we + recommend the use of scanLine() or bits() to access pixel data directly. + + \sa pixel(), bits(), scanLine(), {QImage#Pixel Manipulation}{Pixel Manipulation} +*/ + +/*! + \overload + \since 5.6 + + Sets the pixel color at (\a x, \a y) to \a color. +*/ +void QImage::setPixelColor(int x, int y, const QColor &color) +{ + if (!d || x < 0 || x >= width() || y < 0 || y >= height() || !color.isValid()) { + qWarning("QImage::setPixelColor: coordinate (%d,%d) out of range", x, y); + return; + } + // detach is called from within scanLine + uchar * s = scanLine(y); + switch (d->format) { + case Format_Mono: + case Format_MonoLSB: + case Format_Indexed8: + qWarning("QImage::setPixelColor: called on monochrome or indexed format"); + return; + case Format_BGR30: + ((uint *)s)[x] = qConvertRgb64ToRgb30<PixelOrderBGR>(color.rgba64()) | 0xc0000000; + return; + case Format_A2BGR30_Premultiplied: + ((uint *)s)[x] = qConvertRgb64ToRgb30<PixelOrderBGR>(color.rgba64()); + return; + case Format_RGB30: + ((uint *)s)[x] = qConvertRgb64ToRgb30<PixelOrderRGB>(color.rgba64()) | 0xc0000000; + return; + case Format_A2RGB30_Premultiplied: + ((uint *)s)[x] = qConvertRgb64ToRgb30<PixelOrderRGB>(color.rgba64()); + return; + default: + setPixel(x, y, color.rgba()); + return; + } +} + +/*! Returns \c true if all the colors in the image are shades of gray (i.e. their red, green and blue components are equal); otherwise false. diff --git a/src/gui/image/qimage.h b/src/gui/image/qimage.h index 26057f366c..26707021ea 100644 --- a/src/gui/image/qimage.h +++ b/src/gui/image/qimage.h @@ -34,10 +34,11 @@ #ifndef QIMAGE_H #define QIMAGE_H -#include <QtGui/qtransform.h> -#include <QtGui/qpaintdevice.h> +#include <QtGui/qcolor.h> #include <QtGui/qrgb.h> +#include <QtGui/qpaintdevice.h> #include <QtGui/qpixelformat.h> +#include <QtGui/qtransform.h> #include <QtCore/qbytearray.h> #include <QtCore/qrect.h> #include <QtCore/qstring.h> @@ -220,6 +221,12 @@ public: void setPixel(int x, int y, uint index_or_rgb); void setPixel(const QPoint &pt, uint index_or_rgb); + QColor pixelColor(int x, int y) const; + QColor pixelColor(const QPoint &pt) const; + + void setPixelColor(int x, int y, const QColor &c); + void setPixelColor(const QPoint &pt, const QColor &c); + QVector<QRgb> colorTable() const; #if QT_VERSION >= QT_VERSION_CHECK(6,0,0) void setColorTable(const QVector<QRgb> &colors); @@ -352,6 +359,8 @@ inline bool QImage::valid(const QPoint &pt) const { return valid(pt.x(), pt.y()) inline int QImage::pixelIndex(const QPoint &pt) const { return pixelIndex(pt.x(), pt.y());} inline QRgb QImage::pixel(const QPoint &pt) const { return pixel(pt.x(), pt.y()); } inline void QImage::setPixel(const QPoint &pt, uint index_or_rgb) { setPixel(pt.x(), pt.y(), index_or_rgb); } +inline QColor QImage::pixelColor(const QPoint &pt) const { return pixelColor(pt.x(), pt.y()); } +inline void QImage::setPixelColor(const QPoint &pt, const QColor &c) { setPixelColor(pt.x(), pt.y(), c); } #if QT_DEPRECATED_SINCE(5, 0) diff --git a/src/gui/image/qimagereader.cpp b/src/gui/image/qimagereader.cpp index ba79bf40e5..83ec91bb40 100644 --- a/src/gui/image/qimagereader.cpp +++ b/src/gui/image/qimagereader.cpp @@ -1203,6 +1203,39 @@ bool QImageReader::autoTransform() const } /*! + \since 5.6 + + This is an image format specific function that forces images with + gamma information to be gamma corrected to \a gamma. For image formats + that do not support gamma correction, this value is ignored. + + To gamma correct to a standard PC color-space, set gamma to \c 1/2.2. + + \sa gamma() +*/ +void QImageReader::setGamma(float gamma) +{ + if (d->initHandler() && d->handler->supportsOption(QImageIOHandler::Gamma)) + d->handler->setOption(QImageIOHandler::Gamma, gamma); +} + +/*! + \since 5.6 + + Returns the gamma level of the decoded image. If setGamma() has been + called and gamma correction is supported it will return the gamma set. + If gamma level is not supported by the image format, \c 0.0 is returned. + + \sa setGamma() +*/ +float QImageReader::gamma() const +{ + if (d->initHandler() && d->handler->supportsOption(QImageIOHandler::Gamma)) + return d->handler->option(QImageIOHandler::Gamma).toFloat(); + return 0.0; +} + +/*! Returns \c true if an image can be read for the device (i.e., the image format is supported, and the device seems to contain valid data); otherwise returns \c false. diff --git a/src/gui/image/qimagereader.h b/src/gui/image/qimagereader.h index 27a29bed49..6745c55b97 100644 --- a/src/gui/image/qimagereader.h +++ b/src/gui/image/qimagereader.h @@ -110,6 +110,9 @@ public: void setAutoTransform(bool enabled); bool autoTransform() const; + void setGamma(float gamma); + float gamma() const; + QByteArray subType() const; QList<QByteArray> supportedSubTypes() const; diff --git a/src/gui/image/qpaintengine_pic.cpp b/src/gui/image/qpaintengine_pic.cpp index 9ab1e2c30b..47480ebbae 100644 --- a/src/gui/image/qpaintengine_pic.cpp +++ b/src/gui/image/qpaintengine_pic.cpp @@ -398,6 +398,7 @@ void QPicturePaintEngine::drawPolygon(const QPointF *points, int numPoints, Poly int pos; QPolygonF polygon; + polygon.reserve(numPoints); for (int i=0; i<numPoints; ++i) polygon << points[i]; diff --git a/src/gui/image/qpicture.cpp b/src/gui/image/qpicture.cpp index b63be19153..4a1e65b20a 100644 --- a/src/gui/image/qpicture.cpp +++ b/src/gui/image/qpicture.cpp @@ -1216,7 +1216,9 @@ QList<QByteArray> QPicture::inputFormats() static QStringList qToStringList(const QList<QByteArray> &arr) { QStringList list; - for (int i = 0; i < arr.count(); ++i) + const int count = arr.count(); + list.reserve(count); + for (int i = 0; i < count; ++i) list.append(QString::fromLatin1(arr.at(i))); return list; } diff --git a/src/gui/image/qpicture_p.h b/src/gui/image/qpicture_p.h index 56e6e1249c..a414a122f1 100644 --- a/src/gui/image/qpicture_p.h +++ b/src/gui/image/qpicture_p.h @@ -48,6 +48,7 @@ #include "QtCore/qatomic.h" #include "QtCore/qbuffer.h" #include "QtCore/qobjectdefs.h" +#include "QtCore/qvector.h" #include "QtGui/qpicture.h" #include "QtGui/qpixmap.h" #include "QtGui/qpen.h" @@ -150,8 +151,8 @@ public: QRect override_rect; QScopedPointer<QPaintEngine> paintEngine; bool in_memory_only; - QList<QImage> image_list; - QList<QPixmap> pixmap_list; + QVector<QImage> image_list; + QVector<QPixmap> pixmap_list; QList<QBrush> brush_list; QList<QPen> pen_list; }; diff --git a/src/gui/image/qpixmapcache.cpp b/src/gui/image/qpixmapcache.cpp index f9c362e194..0fefa1f7ea 100644 --- a/src/gui/image/qpixmapcache.cpp +++ b/src/gui/image/qpixmapcache.cpp @@ -138,6 +138,24 @@ bool QPixmapCache::Key::operator ==(const Key &key) const */ /*! + \fn QPixmapCache::Key::Key(Key &&) + \internal + \since 5.6 +*/ + +/*! + \fn QPixmapCache::Key &QPixmapCache::Key::operator=(Key &&) + \internal + \since 5.6 +*/ + +/*! + \fn void QPixmapCache::Key::swap(Key &) + \internal + \since 5.6 +*/ + +/*! \internal */ QPixmapCache::Key &QPixmapCache::Key::operator =(const Key &other) @@ -179,7 +197,6 @@ public: static QPixmapCache::KeyData* getKeyData(QPixmapCache::Key *key); - QList< QPair<QString,QPixmap> > allPixmaps() const; bool flushDetachedPixmaps(bool nt); private: @@ -423,20 +440,6 @@ QPixmapCache::KeyData* QPMCache::getKeyData(QPixmapCache::Key *key) return key->d; } -QList< QPair<QString,QPixmap> > QPMCache::allPixmaps() const -{ - QList< QPair<QString,QPixmap> > r; - QHash<QString, QPixmapCache::Key>::const_iterator it = cacheKeys.begin(); - while (it != cacheKeys.end()) { - QPixmap *ptr = QCache<QPixmapCache::Key, QPixmapCacheEntry>::object(it.value()); - if (ptr) - r.append(QPair<QString,QPixmap>(it.key(),*ptr)); - ++it; - } - return r; -} - - Q_GLOBAL_STATIC(QPMCache, pm_cache) int Q_AUTOTEST_EXPORT q_QPixmapCache_keyHashSize() @@ -656,9 +659,4 @@ int QPixmapCache::totalUsed() return (pm_cache()->totalCost()+1023) / 1024; } -QList< QPair<QString,QPixmap> > QPixmapCache::allPixmaps() -{ - return pm_cache()->allPixmaps(); -} - QT_END_NAMESPACE diff --git a/src/gui/image/qpixmapcache.h b/src/gui/image/qpixmapcache.h index 345389e987..03311345a2 100644 --- a/src/gui/image/qpixmapcache.h +++ b/src/gui/image/qpixmapcache.h @@ -36,10 +36,6 @@ #include <QtGui/qpixmap.h> -#ifdef Q_TEST_QPIXMAPCACHE -#include <QtCore/qpair.h> -#endif - QT_BEGIN_NAMESPACE @@ -52,12 +48,18 @@ public: public: Key(); Key(const Key &other); +#ifdef Q_COMPILER_RVALUE_REFS + Key(Key &&other) Q_DECL_NOTHROW : d(other.d) { other.d = Q_NULLPTR; } + Key &operator =(Key &&other) Q_DECL_NOTHROW { swap(other); return *this; } +#endif ~Key(); bool operator ==(const Key &key) const; inline bool operator !=(const Key &key) const { return !operator==(key); } Key &operator =(const Key &other); + void swap(Key &other) Q_DECL_NOTHROW { qSwap(d, other.d); } + private: KeyData *d; friend class QPMCache; @@ -80,7 +82,6 @@ public: #ifdef Q_TEST_QPIXMAPCACHE static void flushDetachedPixmaps(); static int totalUsed(); - static QList< QPair<QString,QPixmap> > allPixmaps(); #endif }; diff --git a/src/gui/image/qpnghandler.cpp b/src/gui/image/qpnghandler.cpp index 7fbd24787e..776a61d8fe 100644 --- a/src/gui/image/qpnghandler.cpp +++ b/src/gui/image/qpnghandler.cpp @@ -108,10 +108,11 @@ public: }; QPngHandlerPrivate(QPngHandler *qq) - : gamma(0.0), quality(2), png_ptr(0), info_ptr(0), end_info(0), state(Ready), q(qq) + : gamma(0.0), fileGamma(0.0), quality(2), png_ptr(0), info_ptr(0), end_info(0), state(Ready), q(qq) { } float gamma; + float fileGamma; int quality; QString description; QSize scaledSize; @@ -234,13 +235,10 @@ void CALLBACK_CALL_TYPE qpiw_flush_fn(png_structp /* png_ptr */) } static -void setup_qt(QImage& image, png_structp png_ptr, png_infop info_ptr, QSize scaledSize, bool *doScaledRead, float screen_gamma=0.0) +void setup_qt(QImage& image, png_structp png_ptr, png_infop info_ptr, QSize scaledSize, bool *doScaledRead, float screen_gamma=0.0, float file_gamma=0.0) { - if (screen_gamma != 0.0 && png_get_valid(png_ptr, info_ptr, PNG_INFO_gAMA)) { - double file_gamma; - png_get_gAMA(png_ptr, info_ptr, &file_gamma); - png_set_gamma(png_ptr, screen_gamma, file_gamma); - } + if (screen_gamma != 0.0 && file_gamma != 0.0) + png_set_gamma(png_ptr, 1.0f / screen_gamma, file_gamma); png_uint_32 width; png_uint_32 height; @@ -557,6 +555,12 @@ bool Q_INTERNAL_WIN_NO_THROW QPngHandlerPrivate::readPngHeader() readPngTexts(info_ptr); + if (png_get_valid(png_ptr, info_ptr, PNG_INFO_gAMA)) { + double file_gamma = 0.0; + png_get_gAMA(png_ptr, info_ptr, &file_gamma); + fileGamma = file_gamma; + } + state = ReadHeader; return true; } @@ -580,7 +584,7 @@ bool Q_INTERNAL_WIN_NO_THROW QPngHandlerPrivate::readPngImage(QImage *outImage) } bool doScaledRead = false; - setup_qt(*outImage, png_ptr, info_ptr, scaledSize, &doScaledRead, gamma); + setup_qt(*outImage, png_ptr, info_ptr, scaledSize, &doScaledRead, gamma, fileGamma); if (outImage->isNull()) { png_destroy_read_struct(&png_ptr, &info_ptr, &end_info); @@ -1063,7 +1067,7 @@ QVariant QPngHandler::option(ImageOption option) const return QVariant(); if (option == Gamma) - return d->gamma; + return d->gamma == 0.0 ? d->fileGamma : d->gamma; else if (option == Quality) return d->quality; else if (option == Description) |