File indexing completed on 2024-04-28 15:25:45

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 convertedScanLine
0047      * Convert the scanline \a y.
0048      * \note If the image format (and color space) is the same of converted format, it returns the image scan line.
0049      * \return The scan line converted.
0050      */
0051     const uchar *convertedScanLine(const QImage &image, qint32 y);
0052 
0053     /*!
0054      * \brief bytesPerLine
0055      * \return The size of the last converted scanline.
0056      */
0057     qsizetype bytesPerLine() const;
0058 
0059     /*!
0060      * \brief isColorSpaceConversionNeeded
0061      * Calculates if a color space conversion is needed.
0062      * \note Only 24 bit or grater images.
0063      * \param image The source image.
0064      * \param targetColorSpace The target color space.
0065      * \return True if the conversion should be done otherwise false.
0066      */
0067     bool isColorSpaceConversionNeeded(const QImage &image, const QColorSpace &targetColorSpace) const;
0068 
0069 private:
0070     // data
0071     QImage::Format _targetFormat;
0072     QColorSpace _colorSpace;
0073 
0074     // internal buffers
0075     QImage _tmpBuffer;
0076     QImage _convBuffer;
0077 };
0078 
0079 #endif // SCANLINECONVERTER_P_H