summaryrefslogtreecommitdiffstats
path: root/src/gui/image
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2022-04-12 11:04:12 +0200
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2022-05-14 01:00:05 +0200
commite69ebf93ca49d2c3de9fc723c744fbcb21709bb3 (patch)
tree547ac5f8acb77fde58eafb09f1e2662c52b743c2 /src/gui/image
parente33a44927132d3684748ad5236d5b7fc9da334d2 (diff)
Add floating point color space conversions
This allows color space conversions that produces values outside the 0.0->1.0 range, which is one of the intended functions of the floating point image formats. Change-Id: I63b37b0f6934d4382edafb4709486c785a637c67 Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io> Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
Diffstat (limited to 'src/gui/image')
-rw-r--r--src/gui/image/qimage.cpp32
1 files changed, 23 insertions, 9 deletions
diff --git a/src/gui/image/qimage.cpp b/src/gui/image/qimage.cpp
index 3a384660ba..9335c7b034 100644
--- a/src/gui/image/qimage.cpp
+++ b/src/gui/image/qimage.cpp
@@ -5048,30 +5048,37 @@ void QImage::applyColorTransform(const QColorTransform &transform)
return;
}
QImage::Format oldFormat = format();
- if (depth() > 32) {
- if (format() != QImage::Format_RGBX64 && format() != QImage::Format_RGBA64
- && format() != QImage::Format_RGBA64_Premultiplied)
- *this = std::move(*this).convertToFormat(QImage::Format_RGBA64);
- } else if (format() != QImage::Format_ARGB32 && format() != QImage::Format_RGB32
- && format() != QImage::Format_ARGB32_Premultiplied) {
+ if (qt_fpColorPrecision(oldFormat)) {
+ if (oldFormat != QImage::Format_RGBX32FPx4 && oldFormat != QImage::Format_RGBA32FPx4
+ && oldFormat != QImage::Format_RGBA32FPx4_Premultiplied)
+ convertTo(QImage::Format_RGBA32FPx4);
+ } else if (depth() > 32) {
+ if (oldFormat != QImage::Format_RGBX64 && oldFormat != QImage::Format_RGBA64
+ && oldFormat != QImage::Format_RGBA64_Premultiplied)
+ convertTo(QImage::Format_RGBA64);
+ } else if (oldFormat != QImage::Format_ARGB32 && oldFormat != QImage::Format_RGB32
+ && oldFormat != QImage::Format_ARGB32_Premultiplied) {
if (hasAlphaChannel())
- *this = std::move(*this).convertToFormat(QImage::Format_ARGB32);
+ convertTo(QImage::Format_ARGB32);
else
- *this = std::move(*this).convertToFormat(QImage::Format_RGB32);
+ convertTo(QImage::Format_RGB32);
}
QColorTransformPrivate::TransformFlags flags = QColorTransformPrivate::Unpremultiplied;
switch (format()) {
case Format_ARGB32_Premultiplied:
case Format_RGBA64_Premultiplied:
+ case Format_RGBA32FPx4_Premultiplied:
flags = QColorTransformPrivate::Premultiplied;
break;
case Format_RGB32:
case Format_RGBX64:
+ case Format_RGBX32FPx4:
flags = QColorTransformPrivate::InputOpaque;
break;
case Format_ARGB32:
case Format_RGBA64:
+ case Format_RGBA32FPx4:
break;
default:
Q_UNREACHABLE();
@@ -5079,7 +5086,14 @@ void QImage::applyColorTransform(const QColorTransform &transform)
std::function<void(int,int)> transformSegment;
- if (depth() > 32) {
+ if (qt_fpColorPrecision(format())) {
+ transformSegment = [&](int yStart, int yEnd) {
+ for (int y = yStart; y < yEnd; ++y) {
+ QRgbaFloat32 *scanline = reinterpret_cast<QRgbaFloat32 *>(d->data + y * d->bytes_per_line);
+ transform.d->apply(scanline, scanline, width(), flags);
+ }
+ };
+ } else if (depth() > 32) {
transformSegment = [&](int yStart, int yEnd) {
for (int y = yStart; y < yEnd; ++y) {
QRgba64 *scanline = reinterpret_cast<QRgba64 *>(d->data + y * d->bytes_per_line);