File indexing completed on 2024-05-12 07:49:42
0001 /* 0002 SPDX-FileCopyrightText: 2023 Mirco Miranda <mircomir@outlook.com> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #ifndef SCANLINECONVERTER_P_H 0008 #define SCANLINECONVERTER_P_H 0009 0010 #include <QColorSpace> 0011 #include <QImage> 0012 0013 /*! 0014 * \brief The scanlineFormatConversion class 0015 * A class to convert an image scan line. It introduces some overhead on small images 0016 * but performs better on large images. :) 0017 */ 0018 class ScanLineConverter 0019 { 0020 public: 0021 ScanLineConverter(const QImage::Format &targetFormat); 0022 ScanLineConverter(const ScanLineConverter &other); 0023 ScanLineConverter &operator=(const ScanLineConverter &other); 0024 0025 /*! 0026 * \brief targetFormat 0027 * \return The target format set in the constructor. 0028 */ 0029 QImage::Format targetFormat() const; 0030 0031 /*! 0032 * \brief setTargetColorSpace 0033 * Set the colorspace conversion. 0034 * 0035 * In addition to format conversion, it is also possible to convert the color 0036 * space if the source image has a different one set. 0037 * The conversion is done on the source format if and only if the image 0038 * has a color depth greater than 24 bit and the color profile set is different 0039 * from that of the image itself. 0040 * \param colorSpace 0041 */ 0042 void setTargetColorSpace(const QColorSpace &colorSpace); 0043 QColorSpace targetColorSpace() const; 0044 0045 /*! 0046 * \brief setDefaultSourceColorSpace 0047 * Set the source color space to use when the image does not have a color space. 0048 * \param colorSpace 0049 */ 0050 void setDefaultSourceColorSpace(const QColorSpace &colorSpace); 0051 QColorSpace defaultSourceColorSpace() const; 0052 0053 /*! 0054 * \brief convertedScanLine 0055 * Convert the scanline \a y. 0056 * \note If the image format (and color space) is the same of converted format, it returns the image scan line. 0057 * \return The scan line converted. 0058 */ 0059 const uchar *convertedScanLine(const QImage &image, qint32 y); 0060 0061 /*! 0062 * \brief bytesPerLine 0063 * \return The size of the last converted scanline. 0064 */ 0065 qsizetype bytesPerLine() const; 0066 0067 /*! 0068 * \brief isColorSpaceConversionNeeded 0069 * Calculates if a color space conversion is needed. 0070 * \note Only 24 bit or grater images. 0071 * \param image The source image. 0072 * \param targetColorSpace The target color space. 0073 * \param defaultColorSpace The default color space to use it image does not contains one. 0074 * \return True if the conversion should be done otherwise false. 0075 */ 0076 static bool isColorSpaceConversionNeeded(const QImage &image, const QColorSpace &targetColorSpace, const QColorSpace &defaultColorSpace = QColorSpace()); 0077 0078 /*! 0079 * \brief isColorSpaceConversionNeeded 0080 */ 0081 inline bool isColorSpaceConversionNeeded(const QImage &image) const 0082 { 0083 return isColorSpaceConversionNeeded(image, _colorSpace, _defaultColorSpace); 0084 } 0085 0086 private: 0087 // data 0088 QImage::Format _targetFormat; 0089 QColorSpace _colorSpace; 0090 QColorSpace _defaultColorSpace; 0091 0092 // internal buffers 0093 QImage _tmpBuffer; 0094 QImage _convBuffer; 0095 }; 0096 0097 #endif // SCANLINECONVERTER_P_H