File indexing completed on 2024-12-22 04:10:29

0001 /*
0002  *  SPDX-FileCopyrightText: 2010 Dmitry Kazakov <dimula73@gmail.com>
0003  *
0004  *  SPDX-License-Identifier: GPL-2.0-or-later
0005  */
0006 
0007 #ifndef __KIS_ABSTRACT_COMPRESSION_H
0008 #define __KIS_ABSTRACT_COMPRESSION_H
0009 
0010 #include "kritaimage_export.h"
0011 #include <QtGlobal>
0012 
0013 /**
0014  * Base class for compression operations
0015  */
0016 
0017 class KRITAIMAGE_EXPORT KisAbstractCompression
0018 {
0019 public:
0020     KisAbstractCompression();
0021     virtual ~KisAbstractCompression();
0022 
0023     /**
0024      * Compresses \p input buffer into \p output buffer.
0025      * WARNING: Be careful, output buffer must be at least
0026      * outputBufferSize(inputLength) size!
0027      * \param input the input
0028      * \param inputLength the input length
0029      * \param output the output
0030      * \param outputLength is not used!
0031      * \return number of bytes written to the output buffer
0032      * and 0 if error occurred.
0033      *
0034      * \see outputBufferSize()
0035      */
0036     virtual qint32 compress(const quint8* input, qint32 inputLength, quint8* output, qint32 outputLength) = 0;
0037 
0038     /**
0039      * Decompresses \p input buffer into \p output buffer.
0040      * WARNING: output buffer must be able to fit the input data
0041      * \param input the input
0042      * \param inputLength the input length
0043      * \param output the output
0044      * \param outputLength is not used!
0045      * \return number of bytes written to the output buffer
0046      * and 0 if error occurred.
0047      */
0048     virtual qint32 decompress(const quint8* input, qint32 inputLength, quint8* output, qint32 outputLength) = 0;
0049 
0050     /**
0051      * Returns minimal allowed size of output buffer for compression
0052      */
0053     virtual qint32 outputBufferSize(qint32 dataSize) = 0;
0054 
0055     /**
0056      * Some algorithms may decide to optimize them work depending on
0057      * the usual size of the data.
0058      * Default implementation of KisAbstractCompression class does nothing.
0059      */
0060     virtual void adjustForDataSize(qint32 dataSize);
0061 
0062 public:
0063     /**
0064      * Additional interface for jumbling color channels order
0065      */
0066 
0067     /**
0068      * e.g. RGBARGBARGBA -> RRRGGGBBBAAA
0069      * NOTE: performs mixing of bytes, not channels!
0070      */
0071     static void linearizeColors(quint8 *input, quint8 *output,
0072                                 qint32 dataSize, qint32 pixelSize);
0073     /**
0074      * e.g. RRRGGGBBBAAA -> RGBARGBARGBA
0075      * NOTE: performs mixing of bytes, not channels!
0076      */
0077     static void delinearizeColors(quint8 *input, quint8 *output,
0078                                   qint32 dataSize, qint32 pixelSize);
0079 };
0080 
0081 #endif /* __KIS_ABSTRACT_COMPRESSION_H */
0082