diff --git a/src/gui/image/qimage.cpp b/src/gui/image/qimage.cpp index b49b47989a..ff1894807d 100644 --- a/src/gui/image/qimage.cpp +++ b/src/gui/image/qimage.cpp @@ -4994,7 +4994,8 @@ void QImage::convertToColorSpace(const QColorSpace &colorSpace) qWarning() << "QImage::convertToColorSpace: Output colorspace is not valid"; return; } - detach(); + if (d->colorSpace == colorSpace) + return; applyColorTransform(d->colorSpace.transformationToColorSpace(colorSpace)); d->colorSpace = colorSpace; } @@ -5036,6 +5037,7 @@ QColorSpace QImage::colorSpace() const */ void QImage::applyColorTransform(const QColorTransform &transform) { + detach(); if (!d) return; if (pixelFormat().colorModel() == QPixelFormat::Indexed) { @@ -5078,14 +5080,14 @@ void QImage::applyColorTransform(const QColorTransform &transform) if (depth() > 32) { transformSegment = [&](int yStart, int yEnd) { for (int y = yStart; y < yEnd; ++y) { - QRgba64 *scanline = reinterpret_cast(scanLine(y)); + QRgba64 *scanline = reinterpret_cast(d->data + y * d->bytes_per_line); transform.d->apply(scanline, scanline, width(), flags); } }; } else { transformSegment = [&](int yStart, int yEnd) { for (int y = yStart; y < yEnd; ++y) { - QRgb *scanline = reinterpret_cast(scanLine(y)); + QRgb *scanline = reinterpret_cast(d->data + y * d->bytes_per_line); transform.d->apply(scanline, scanline, width(), flags); } };