mirror of
https://invent.kde.org/frameworks/kimageformats.git
synced 2025-06-03 17:08:08 -04:00
psd: LAB conversion speed improved
Using an approximated pow function improves the conversion speed of LAB images by more than 50% without an appreciable visual difference.
This commit is contained in:
parent
5cc7a2b45c
commit
21211cd63b
Binary file not shown.
Before Width: | Height: | Size: 189 KiB After Width: | Height: | Size: 191 KiB |
Binary file not shown.
Before Width: | Height: | Size: 117 KiB After Width: | Height: | Size: 115 KiB |
35
src/imageformats/fastmath_p.h
Normal file
35
src/imageformats/fastmath_p.h
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
/*
|
||||||
|
Approximated math functions used into conversions.
|
||||||
|
|
||||||
|
SPDX-FileCopyrightText: Edward Kmett
|
||||||
|
SPDX-FileCopyrightText: 2023 Mirco Miranda <mircomir@outlook.com>
|
||||||
|
|
||||||
|
SPDX-License-Identifier: BSD-3-Clause
|
||||||
|
*/
|
||||||
|
#ifndef FASTMATH_P_H
|
||||||
|
#define FASTMATH_P_H
|
||||||
|
|
||||||
|
#include <QtGlobal>
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief fastPow
|
||||||
|
* Based on Edward Kmett code released into the public domain.
|
||||||
|
* See also: https://github.com/ekmett/approximate
|
||||||
|
*/
|
||||||
|
inline double fastPow(double x, double y)
|
||||||
|
{
|
||||||
|
union {
|
||||||
|
double d;
|
||||||
|
qint32 i[2];
|
||||||
|
} u = {x};
|
||||||
|
#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN
|
||||||
|
u.i[1] = qint32(y * (u.i[1] - 1072632447) + 1072632447);
|
||||||
|
u.i[0] = 0;
|
||||||
|
#else // never tested
|
||||||
|
u.i[0] = qint32(y * (u.i[0] - 1072632447) + 1072632447);
|
||||||
|
u.i[1] = 0;
|
||||||
|
#endif
|
||||||
|
return u.d;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // FASTMATH_P_H
|
@ -32,6 +32,7 @@
|
|||||||
* color management engine (e.g. LittleCMS).
|
* color management engine (e.g. LittleCMS).
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "fastmath_p.h"
|
||||||
#include "psd_p.h"
|
#include "psd_p.h"
|
||||||
#include "util_p.h"
|
#include "util_p.h"
|
||||||
|
|
||||||
@ -50,7 +51,7 @@ typedef quint8 uchar;
|
|||||||
* This should not be a problem because the Qt's QColorSpace supports the linear
|
* This should not be a problem because the Qt's QColorSpace supports the linear
|
||||||
* sRgb colorspace.
|
* sRgb colorspace.
|
||||||
*
|
*
|
||||||
* Using linear conversion, the loading speed is improved by 4x. Anyway, if you are using
|
* Using linear conversion, the loading speed is slightly improved. Anyway, if you are using
|
||||||
* an software that discard color info, you should comment it.
|
* an software that discard color info, you should comment it.
|
||||||
*
|
*
|
||||||
* At the time I'm writing (07/2022), Gwenview and Krita supports linear sRgb but KDE
|
* At the time I'm writing (07/2022), Gwenview and Krita supports linear sRgb but KDE
|
||||||
@ -898,8 +899,9 @@ inline double gammaCorrection(double linear)
|
|||||||
#ifdef PSD_FAST_LAB_CONVERSION
|
#ifdef PSD_FAST_LAB_CONVERSION
|
||||||
return linear;
|
return linear;
|
||||||
#else
|
#else
|
||||||
// NOTE: pow() slow down the performance by a 4 factor :(
|
// Replacing fastPow with std::pow the conversion time is 2/3 times longer: using fastPow
|
||||||
return (linear > 0.0031308 ? 1.055 * std::pow(linear, 1.0 / 2.4) - 0.055 : 12.92 * linear);
|
// there are minimal differences in the conversion that are not visually noticeable.
|
||||||
|
return (linear > 0.0031308 ? 1.055 * fastPow(linear, 1.0 / 2.4) - 0.055 : 12.92 * linear);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user