Add meaningful warnings when trying to create 0 width/height CGImages.
This way it is easier to track down the place where valid size is not
used.
Change-Id: Id261ddf72d5487afcdb1a2a6d0d9079700888545
Reviewed-by: Morten Johan Sørvig <morten.sorvig@digia.com>
CGImageRef qt_mac_image_to_cgimage(const QImage &img)
{
+ if (img.width() <= 0 || img.height() <= 0) {
+ qWarning() << Q_FUNC_INFO <<
+ "trying to set" << img.width() << "x" << img.height() << "size for CGImage";
+ return 0;
+ }
+
QImage *image;
if (img.depth() != 32)
image = new QImage(img.convertToFormat(QImage::Format_ARGB32_Premultiplied));
{
CGImageRelease(m_cgImage);
+ int width = image->width();
+ int height = image->height();
+
+ if (width <= 0 || height <= 0) {
+ qWarning() << Q_FUNC_INFO <<
+ "setting invalid size" << width << "x" << height << "for qnsview image";
+ m_cgImage = 0;
+ return;
+ }
+
const uchar *imageData = image->bits();
int bitDepth = image->depth();
int colorBufferSize = 8;
int bytesPrLine = image->bytesPerLine();
- int width = image->width();
- int height = image->height();
CGColorSpaceRef cgColourSpaceRef = CGColorSpaceCreateDeviceRGB();
image = qt_mac_create_imagemask(pm, sr);
} else if (differentSize) {
QCFType<CGImageRef> img = qt_mac_image_to_cgimage(pm.toImage());
- image = CGImageCreateWithImageInRect(img, CGRectMake(qRound(sr.x()), qRound(sr.y()), qRound(sr.width()), qRound(sr.height())));
+ if (img)
+ image = CGImageCreateWithImageInRect(img, CGRectMake(qRound(sr.x()), qRound(sr.y()), qRound(sr.width()), qRound(sr.height())));
} else {
image = qt_mac_image_to_cgimage(pm.toImage());
}