7#include "scanlineconverter_p.h"
10ScanLineConverter::ScanLineConverter(
const QImage::Format &targetFormat)
11 : _targetFormat(targetFormat)
15ScanLineConverter::ScanLineConverter(
const ScanLineConverter &other)
16 : _targetFormat(other._targetFormat)
17 , _colorSpace(other._colorSpace)
18 , _defaultColorSpace(other._defaultColorSpace)
22ScanLineConverter &ScanLineConverter::operator=(
const ScanLineConverter &other)
24 _targetFormat = other._targetFormat;
25 _colorSpace = other._colorSpace;
26 _defaultColorSpace = other._defaultColorSpace;
35void ScanLineConverter::setTargetColorSpace(
const QColorSpace &colorSpace)
37 _colorSpace = colorSpace;
40QColorSpace ScanLineConverter::targetColorSpace()
const
45void ScanLineConverter::setDefaultSourceColorSpace(
const QColorSpace &colorSpace)
47 _defaultColorSpace = colorSpace;
50QColorSpace ScanLineConverter::defaultSourceColorSpace()
const
52 return _defaultColorSpace;
55const uchar *ScanLineConverter::convertedScanLine(
const QImage &image, qint32 y)
57 auto colorSpaceConversion = isColorSpaceConversionNeeded(image);
58 if (image.
format() == _targetFormat && !colorSpaceConversion) {
61 if (image.
width() != _tmpBuffer.width() || image.
format() != _tmpBuffer.format()) {
65 if (_tmpBuffer.isNull()) {
69 auto tmp = _tmpBuffer;
70 if (colorSpaceConversion) {
73 cs = _defaultColorSpace;
75#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0)
76 if (tmp.depth() < 8 && cs.colorModel() == QColorSpace::ColorModel::Gray) {
79 else if (tmp.depth() < 24 && cs.colorModel() == QColorSpace::ColorModel::Rgb) {
83 if (tmp.depth() < 24) {
87 tmp.setColorSpace(cs);
88 tmp.convertToColorSpace(_colorSpace);
96 tmp.convertTo(_targetFormat);
99 if (_convBuffer.isNull()) {
102 return _convBuffer.constBits();
105qsizetype ScanLineConverter::bytesPerLine()
const
107 if (_convBuffer.isNull()) {
110 return _convBuffer.bytesPerLine();
113bool ScanLineConverter::isColorSpaceConversionNeeded(
const QImage &image,
const QColorSpace &targetColorSpace,
const QColorSpace &defaultColorSpace)
116 if (!sourceColorSpace.isValid()) {
117 sourceColorSpace = defaultColorSpace;
119 if (!sourceColorSpace.isValid() || !targetColorSpace.
isValid()) {
124 auto spr = sourceColorSpace.primaries();
128 if (stf == QColorSpace::TransferFunction::Custom ||
129 ttf == QColorSpace::TransferFunction::Custom ||
130 spr == QColorSpace::Primaries::Custom ||
131 tpr == QColorSpace::Primaries::Custom) {
135 if (stf == ttf && spr == tpr) {
bool isValid() const const
Primaries primaries() const const
TransferFunction transferFunction() const const
qsizetype bytesPerLine() const const
QColorSpace colorSpace() const const
QList< QRgb > colorTable() const const
const uchar * constScanLine(int i) const const