diff options
Diffstat (limited to 'src/gui/image')
-rw-r--r-- | src/gui/image/qimage.cpp | 12 | ||||
-rw-r--r-- | src/gui/image/qpixmap.cpp | 15 | ||||
-rw-r--r-- | src/gui/image/qpixmap.h | 6 | ||||
-rw-r--r-- | src/gui/image/qpixmap_mac.cpp | 5 | ||||
-rw-r--r-- | src/gui/image/qpixmap_mac_p.h | 1 | ||||
-rw-r--r-- | src/gui/image/qpixmap_raster.cpp | 14 | ||||
-rw-r--r-- | src/gui/image/qpixmap_x11.cpp | 10 | ||||
-rw-r--r-- | src/gui/image/qpixmap_x11_p.h | 2 | ||||
-rw-r--r-- | src/gui/image/qpixmapdata.cpp | 12 | ||||
-rw-r--r-- | src/gui/image/qpixmapdata_p.h | 13 |
10 files changed, 56 insertions, 34 deletions
diff --git a/src/gui/image/qimage.cpp b/src/gui/image/qimage.cpp index ca2b782..fa1ce29 100644 --- a/src/gui/image/qimage.cpp +++ b/src/gui/image/qimage.cpp @@ -3951,10 +3951,8 @@ QImage QImage::scaled(const QSize& s, Qt::AspectRatioMode aspectMode, Qt::Transf if (newSize == size()) return copy(); - QImage img; - QTransform wm; - wm.scale((qreal)newSize.width() / width(), (qreal)newSize.height() / height()); - img = transformed(wm, mode); + QTransform wm = QTransform::fromScale((qreal)newSize.width() / width(), (qreal)newSize.height() / height()); + QImage img = transformed(wm, mode); return img; } @@ -3981,9 +3979,8 @@ QImage QImage::scaledToWidth(int w, Qt::TransformationMode mode) const if (w <= 0) return QImage(); - QTransform wm; qreal factor = (qreal) w / width(); - wm.scale(factor, factor); + QTransform wm = QTransform::fromScale(factor, factor); return transformed(wm, mode); } @@ -4010,9 +4007,8 @@ QImage QImage::scaledToHeight(int h, Qt::TransformationMode mode) const if (h <= 0) return QImage(); - QTransform wm; qreal factor = (qreal) h / height(); - wm.scale(factor, factor); + QTransform wm = QTransform::fromScale(factor, factor); return transformed(wm, mode); } diff --git a/src/gui/image/qpixmap.cpp b/src/gui/image/qpixmap.cpp index 6da291c..61be832 100644 --- a/src/gui/image/qpixmap.cpp +++ b/src/gui/image/qpixmap.cpp @@ -552,7 +552,7 @@ bool QPixmap::isQBitmap() const */ bool QPixmap::isNull() const { - return data->width() == 0; + return data->isNull(); } /*! @@ -1446,10 +1446,9 @@ QPixmap QPixmap::scaled(const QSize& s, Qt::AspectRatioMode aspectMode, Qt::Tran if (newSize == size()) return *this; - QPixmap pix; - QTransform wm; - wm.scale((qreal)newSize.width() / width(), (qreal)newSize.height() / height()); - pix = transformed(wm, mode); + QTransform wm = QTransform::fromScale((qreal)newSize.width() / width(), + (qreal)newSize.height() / height()); + QPixmap pix = transformed(wm, mode); return pix; } @@ -1476,9 +1475,8 @@ QPixmap QPixmap::scaledToWidth(int w, Qt::TransformationMode mode) const if (w <= 0) return QPixmap(); - QTransform wm; qreal factor = (qreal) w / width(); - wm.scale(factor, factor); + QTransform wm = QTransform::fromScale(factor, factor); return transformed(wm, mode); } @@ -1505,9 +1503,8 @@ QPixmap QPixmap::scaledToHeight(int h, Qt::TransformationMode mode) const if (h <= 0) return QPixmap(); - QTransform wm; qreal factor = (qreal) h / height(); - wm.scale(factor, factor); + QTransform wm = QTransform::fromScale(factor, factor); return transformed(wm, mode); } diff --git a/src/gui/image/qpixmap.h b/src/gui/image/qpixmap.h index e4faebd..d1e2ecb 100644 --- a/src/gui/image/qpixmap.h +++ b/src/gui/image/qpixmap.h @@ -79,11 +79,11 @@ public: QPixmap &operator=(const QPixmap &); operator QVariant() const; - bool isNull() const; + bool isNull() const; // ### Qt 5: make inline int devType() const; - int width() const; - int height() const; + int width() const; // ### Qt 5: make inline + int height() const; // ### Qt 5: make inline QSize size() const; QRect rect() const; int depth() const; diff --git a/src/gui/image/qpixmap_mac.cpp b/src/gui/image/qpixmap_mac.cpp index ca9d497..b40694a 100644 --- a/src/gui/image/qpixmap_mac.cpp +++ b/src/gui/image/qpixmap_mac.cpp @@ -168,7 +168,7 @@ static inline QRgb qt_conv16ToRgb(ushort c) { QSet<QMacPixmapData*> QMacPixmapData::validDataPointers; QMacPixmapData::QMacPixmapData(PixelType type) - : QPixmapData(type, MacClass), w(0), h(0), d(0), has_alpha(0), has_mask(0), + : QPixmapData(type, MacClass), has_alpha(0), has_mask(0), uninit(true), pixels(0), pixelsToFree(0), bytesPerRow(0), cg_data(0), cg_dataBeingReleased(0), cg_mask(0), #ifndef QT_MAC_NO_QUICKDRAW @@ -188,11 +188,13 @@ void QMacPixmapData::resize(int width, int height) w = width; h = height; + is_null = (w <= 0 || h <= 0); d = (pixelType() == BitmapType ? 1 : 32); bool make_null = w <= 0 || h <= 0; // create null pixmap if (make_null || d == 0) { w = 0; h = 0; + is_null = true; d = 0; if (!make_null) qWarning("Qt: QPixmap: Invalid pixmap parameters"); @@ -231,6 +233,7 @@ void QMacPixmapData::fromImage(const QImage &img, w = img.width(); h = img.height(); + is_null = (w <= 0 || h <= 0); d = (pixelType() == BitmapType ? 1 : img.depth()); QImage image = img; diff --git a/src/gui/image/qpixmap_mac_p.h b/src/gui/image/qpixmap_mac_p.h index 66797ed..a3ff0d3 100644 --- a/src/gui/image/qpixmap_mac_p.h +++ b/src/gui/image/qpixmap_mac_p.h @@ -83,7 +83,6 @@ public: QPaintEngine* paintEngine() const; private: - int w, h, d; uint has_alpha : 1, has_mask : 1, uninit : 1; diff --git a/src/gui/image/qpixmap_raster.cpp b/src/gui/image/qpixmap_raster.cpp index 2c57ede..9cc896b 100644 --- a/src/gui/image/qpixmap_raster.cpp +++ b/src/gui/image/qpixmap_raster.cpp @@ -85,6 +85,10 @@ void QRasterPixmapData::resize(int width, int height) #endif image = QImage(width, height, format); + w = width; + h = height; + d = image.depth(); + is_null = (w <= 0 || h <= 0); if (pixelType() == BitmapType && !image.isNull()) { image.setNumColors(2); @@ -168,6 +172,10 @@ void QRasterPixmapData::fromImage(const QImage &sourceImage, } } #endif + w = image.d->width; + h = image.d->height; + d = image.d->depth; + is_null = (w <= 0 || h <= 0); setSerialNumber(image.serialNumber()); } @@ -329,9 +337,9 @@ int QRasterPixmapData::metric(QPaintDevice::PaintDeviceMetric metric) const // override the image dpi with the screen dpi when rendering to a pixmap switch (metric) { case QPaintDevice::PdmWidth: - return d->width; + return w; case QPaintDevice::PdmHeight: - return d->height; + return h; case QPaintDevice::PdmWidthMM: return qRound(d->width * 25.4 / qt_defaultDpiX()); case QPaintDevice::PdmHeightMM: @@ -339,7 +347,7 @@ int QRasterPixmapData::metric(QPaintDevice::PaintDeviceMetric metric) const case QPaintDevice::PdmNumColors: return d->colortable.size(); case QPaintDevice::PdmDepth: - return d->depth; + return this->d; case QPaintDevice::PdmDpiX: // fall-through case QPaintDevice::PdmPhysicalDpiX: return qt_defaultDpiX(); diff --git a/src/gui/image/qpixmap_x11.cpp b/src/gui/image/qpixmap_x11.cpp index b7fe92a..86cf515 100644 --- a/src/gui/image/qpixmap_x11.cpp +++ b/src/gui/image/qpixmap_x11.cpp @@ -312,7 +312,7 @@ static int qt_pixmap_serial = 0; int Q_GUI_EXPORT qt_x11_preferred_pixmap_depth = 0; QX11PixmapData::QX11PixmapData(PixelType type) - : QPixmapData(type, X11Class), hd(0), w(0), h(0), d(0), + : QPixmapData(type, X11Class), hd(0), uninit(true), read_only(false), x11_mask(0), picture(0), mask_picture(0), hd2(0), share_mode(QPixmap::ImplicitlyShared), pengine(0) { @@ -324,6 +324,7 @@ void QX11PixmapData::resize(int width, int height) w = width; h = height; + is_null = (w <= 0 || h <= 0); if (defaultScreen >= 0 && defaultScreen != xinfo.screen()) { QX11InfoData* xd = xinfo.getX11Data(true); @@ -347,6 +348,7 @@ void QX11PixmapData::resize(int width, int height) if (make_null || d == 0) { w = 0; h = 0; + is_null = true; hd = 0; picture = 0; d = 0; @@ -375,6 +377,7 @@ void QX11PixmapData::fromImage(const QImage &img, w = img.width(); h = img.height(); d = img.depth(); + is_null = (w <= 0 || h <= 0); if (defaultScreen >= 0 && defaultScreen != xinfo.screen()) { QX11InfoData* xd = xinfo.getX11Data(true); @@ -395,6 +398,7 @@ void QX11PixmapData::fromImage(const QImage &img, if (uint(w) >= 32768 || uint(h) >= 32768) { w = h = 0; + is_null = true; return; } @@ -1109,6 +1113,7 @@ void QX11PixmapData::bitmapFromImage(const QImage &image) w = img.width(); h = img.height(); d = 1; + is_null = (w <= 0 || h <= 0); int bpl = (w + 7) / 8; int ibpl = img.bytesPerLine(); if (bpl != ibpl) { @@ -1876,6 +1881,7 @@ QPixmap QX11PixmapData::transformed(const QTransform &transform, x11Data->d = d; x11Data->w = w; x11Data->h = h; + x11Data->is_null = (w <= 0 || h <= 0); x11Data->hd = (Qt::HANDLE)XCreatePixmap(X11->display, RootWindow(X11->display, xinfo.screen()), w, h, d); @@ -2132,6 +2138,7 @@ void QX11PixmapData::copy(const QPixmapData *data, const QRect &rect) d = x11Data->d; w = rect.width(); h = rect.height(); + is_null = (w <= 0 || h <= 0); hd = (Qt::HANDLE)XCreatePixmap(X11->display, RootWindow(X11->display, x11Data->xinfo.screen()), w, h, d); @@ -2250,6 +2257,7 @@ QPixmap QPixmap::fromX11Pixmap(Qt::HANDLE pixmap, QPixmap::ShareMode mode) data->uninit = false; data->w = width; data->h = height; + data->is_null = (width <= 0 || height <= 0); data->d = depth; data->hd = pixmap; diff --git a/src/gui/image/qpixmap_x11_p.h b/src/gui/image/qpixmap_x11_p.h index addcc7c..3de9a0f 100644 --- a/src/gui/image/qpixmap_x11_p.h +++ b/src/gui/image/qpixmap_x11_p.h @@ -108,8 +108,6 @@ private: Qt::HANDLE hd; - int w, h; - short d; uint uninit : 1; uint read_only : 1; diff --git a/src/gui/image/qpixmapdata.cpp b/src/gui/image/qpixmapdata.cpp index 094d7e4..b50d664 100644 --- a/src/gui/image/qpixmapdata.cpp +++ b/src/gui/image/qpixmapdata.cpp @@ -49,9 +49,17 @@ const uchar qt_pixmap_bit_mask[] = { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 }; QPixmapData::QPixmapData(PixelType pixelType, int objectId) - : ref(0), detach_no(0), type(pixelType), id(objectId), ser_no(0), is_cached(false) + : w(0), + h(0), + d(0), + is_null(true), + ref(0), + detach_no(0), + type(pixelType), + id(objectId), + ser_no(0), + is_cached(false) { - } QPixmapData::~QPixmapData() diff --git a/src/gui/image/qpixmapdata_p.h b/src/gui/image/qpixmapdata_p.h index 4c49dd2..29dafaf 100644 --- a/src/gui/image/qpixmapdata_p.h +++ b/src/gui/image/qpixmapdata_p.h @@ -99,13 +99,18 @@ public: virtual QImage* buffer(); - int width() const { return metric(QPaintDevice::PdmWidth); } - int height() const { return metric(QPaintDevice::PdmHeight); } - int numColors() const { return metric(QPaintDevice::PdmNumColors); } - int depth() const { return metric(QPaintDevice::PdmDepth); } + inline int width() const { return w; } + inline int height() const { return h; } + inline int numColors() const { return metric(QPaintDevice::PdmNumColors); } + inline int depth() const { return d; } + inline bool isNull() const { return is_null; } protected: void setSerialNumber(int serNo); + int w; + int h; + int d; + bool is_null; private: friend class QPixmap; |