From feb6711a7962c210a2c88f416200e266fb30597a Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Mon, 1 Feb 2021 10:24:35 +0100 Subject: [PATCH] Segment qimage conversion block irrelevant of depth Always try segments from 64k to 128k pixels, this matches qimagescale logic, and gives a one percent speedup locally. Change-Id: I3ef468eac9dca4b84f04850e970f3d15a4f16255 Reviewed-by: Eirik Aavitsland --- src/gui/image/qimage.cpp | 2 +- src/gui/image/qimage_conversions.cpp | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/gui/image/qimage.cpp b/src/gui/image/qimage.cpp index cced1d99427..8d8245525ae 100644 --- a/src/gui/image/qimage.cpp +++ b/src/gui/image/qimage.cpp @@ -4826,7 +4826,7 @@ void QImage::applyColorTransform(const QColorTransform &transform) } #if QT_CONFIG(thread) && !defined(Q_OS_WASM) - int segments = sizeInBytes() / (1<<16); + int segments = (qsizetype(width()) * height()) >> 16; segments = std::min(segments, height()); QThreadPool *threadPool = QThreadPool::globalInstance(); if (segments > 1 && threadPool && !threadPool->contains(QThread::currentThread())) { diff --git a/src/gui/image/qimage_conversions.cpp b/src/gui/image/qimage_conversions.cpp index 3f9eb08fdf1..ffb018f09f5 100644 --- a/src/gui/image/qimage_conversions.cpp +++ b/src/gui/image/qimage_conversions.cpp @@ -234,7 +234,7 @@ void convert_generic(QImageData *dest, const QImageData *src, Qt::ImageConversio }; #ifdef QT_USE_THREAD_PARALLEL_IMAGE_CONVERSIONS - int segments = src->nbytes / (1<<16); + int segments = (qsizetype(src->width) * src->height) >> 16; segments = std::min(segments, src->height); QThreadPool *threadPool = QThreadPool::globalInstance(); @@ -289,7 +289,7 @@ void convert_generic_over_rgb64(QImageData *dest, const QImageData *src, Qt::Ima } }; #ifdef QT_USE_THREAD_PARALLEL_IMAGE_CONVERSIONS - int segments = src->nbytes / (1<<16); + int segments = (qsizetype(src->width) * src->height) >> 16; segments = std::min(segments, src->height); QThreadPool *threadPool = QThreadPool::globalInstance(); @@ -396,7 +396,7 @@ bool convert_generic_inplace(QImageData *data, QImage::Format dst_format, Qt::Im } }; #ifdef QT_USE_THREAD_PARALLEL_IMAGE_CONVERSIONS - int segments = data->nbytes / (1<<16); + int segments = (qsizetype(data->width) * data->height) >> 16; segments = std::min(segments, data->height); QThreadPool *threadPool = QThreadPool::globalInstance(); if (segments > 1 && threadPool && !threadPool->contains(QThread::currentThread())) { @@ -490,7 +490,7 @@ bool convert_generic_inplace_over_rgb64(QImageData *data, QImage::Format dst_for } }; #ifdef QT_USE_THREAD_PARALLEL_IMAGE_CONVERSIONS - int segments = data->nbytes / (1<<16); + int segments = (qsizetype(data->width) * data->height) >> 16; segments = std::min(segments, data->height); QThreadPool *threadPool = QThreadPool::globalInstance(); if (segments > 1 && threadPool && !threadPool->contains(QThread::currentThread())) {