mirror of
https://invent.kde.org/frameworks/kimageformats.git
synced 2026-02-20 15:23:01 -05:00
qoi: write support
As a base I used the reference implementation found on the official site at https://qoiformat.org/ (MIT license). I added a class to convert scan lines in scanlineconverter.cpp. The class takes advantage of the QImage conversion and contrary to what one might expect, with large images it improves performance (compared to converting the whole image) 😄 In progressive mode, for each line, the following conversions (only if needed) are made before saving: 1. If the icc profile is set, the line is converted to sRGB or sRGB Linear. 2. The line is scaled to 8 bits with RGBA order.
This commit is contained in:
committed by
Daniel Novomeský
parent
4bd9d5baec
commit
8dc685df26
79
src/imageformats/scanlineconverter_p.h
Normal file
79
src/imageformats/scanlineconverter_p.h
Normal file
@ -0,0 +1,79 @@
|
||||
/*
|
||||
SPDX-FileCopyrightText: 2023 Mirco Miranda <mircomir@outlook.com>
|
||||
|
||||
SPDX-License-Identifier: LGPL-2.0-or-later
|
||||
*/
|
||||
|
||||
#ifndef SCANLINECONVERTER_P_H
|
||||
#define SCANLINECONVERTER_P_H
|
||||
|
||||
#include <QColorSpace>
|
||||
#include <QImage>
|
||||
|
||||
/*!
|
||||
* \brief The scanlineFormatConversion class
|
||||
* A class to convert an image scan line. It introduces some overhead on small images
|
||||
* but performs better on large images. :)
|
||||
*/
|
||||
class ScanLineConverter
|
||||
{
|
||||
public:
|
||||
ScanLineConverter(const QImage::Format &targetFormat);
|
||||
ScanLineConverter(const ScanLineConverter &other);
|
||||
ScanLineConverter &operator=(const ScanLineConverter &other);
|
||||
|
||||
/*!
|
||||
* \brief targetFormat
|
||||
* \return The target format set in the constructor.
|
||||
*/
|
||||
QImage::Format targetFormat() const;
|
||||
|
||||
/*!
|
||||
* \brief setTargetColorSpace
|
||||
* Set the colorspace conversion.
|
||||
*
|
||||
* In addition to format conversion, it is also possible to convert the color
|
||||
* space if the source image has a different one set.
|
||||
* The conversion is done on the source format if and only if the image
|
||||
* has a color depth greater than 24 bit and the color profile set is different
|
||||
* from that of the image itself.
|
||||
* \param colorSpace
|
||||
*/
|
||||
void setTargetColorSpace(const QColorSpace &colorSpace);
|
||||
QColorSpace targetColorSpace() const;
|
||||
|
||||
/*!
|
||||
* \brief convertedScanLine
|
||||
* Convert the scanline \a y.
|
||||
* \note If the image format (and color space) is the same of converted format, it returns the image scan line.
|
||||
* \return The scan line converted.
|
||||
*/
|
||||
const uchar *convertedScanLine(const QImage &image, qint32 y);
|
||||
|
||||
/*!
|
||||
* \brief bytesPerLine
|
||||
* \return The size of the last converted scanline.
|
||||
*/
|
||||
qsizetype bytesPerLine() const;
|
||||
|
||||
/*!
|
||||
* \brief isColorSpaceConversionNeeded
|
||||
* Calculates if a color space conversion is needed.
|
||||
* \note Only 24 bit or grater images.
|
||||
* \param image The source image.
|
||||
* \param targetColorSpace The target color space.
|
||||
* \return True if the conversion should be done otherwise false.
|
||||
*/
|
||||
bool isColorSpaceConversionNeeded(const QImage &image, const QColorSpace &targetColorSpace) const;
|
||||
|
||||
private:
|
||||
// data
|
||||
QImage::Format _targetFormat;
|
||||
QColorSpace _colorSpace;
|
||||
|
||||
// internal buffers
|
||||
QImage _tmpBuffer;
|
||||
QImage _convBuffer;
|
||||
};
|
||||
|
||||
#endif // SCANLINECONVERTER_P_H
|
||||
Reference in New Issue
Block a user