File indexing completed on 2024-12-22 04:15:56
0001 /* 0002 * SPDX-FileCopyrightText: 2005-2006 Cyrille Berger <cberger@cberger.net> 0003 * SPDX-FileCopyrightText: 2022 L. E. Segovia <amy@amyspark.me> 0004 * 0005 * SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 0008 #ifndef _KIS_BUFFER_STREAM_H_ 0009 #define _KIS_BUFFER_STREAM_H_ 0010 0011 #include <cstdint> 0012 0013 #include <QSharedPointer> 0014 #include <QVector> 0015 0016 #include <tiffio.h> 0017 0018 class KisBufferStreamBase 0019 { 0020 public: 0021 KisBufferStreamBase(uint16_t depth) : m_depth(depth) {} 0022 virtual ~KisBufferStreamBase() = default; 0023 virtual uint32_t nextValue() = 0; 0024 virtual void restart() = 0; 0025 virtual void moveToLine(tsize_t lineNumber) = 0; 0026 virtual void moveToPos(tsize_t x, tsize_t y) = 0; 0027 virtual tsize_t x() const = 0; 0028 virtual tsize_t y() const = 0; 0029 virtual tsize_t width() const = 0; 0030 0031 protected: 0032 uint16_t m_depth; 0033 }; 0034 0035 class KisBufferStreamContigBase : public KisBufferStreamBase 0036 { 0037 public: 0038 KisBufferStreamContigBase(uint8_t *src, uint16_t depth, tsize_t lineSize); 0039 0040 ~KisBufferStreamContigBase() override = default; 0041 0042 void restart() override; 0043 0044 void moveToLine(tsize_t lineNumber) override; 0045 0046 void moveToPos(tsize_t x, tsize_t y) override; 0047 0048 tsize_t x() const override; 0049 0050 tsize_t y() const override; 0051 0052 tsize_t width() const override; 0053 0054 protected: 0055 uint8_t *const m_src; 0056 uint8_t *m_srcIt; 0057 uint16_t m_posinc = 0; 0058 const tsize_t m_lineSize; 0059 tsize_t m_lineNumber = 0; 0060 tsize_t m_lineOffset = 0; 0061 }; 0062 0063 class KisBufferStreamContigBelow16 : public KisBufferStreamContigBase 0064 { 0065 public: 0066 KisBufferStreamContigBelow16(uint8_t *src, uint16_t depth, tsize_t lineSize) 0067 : KisBufferStreamContigBase(src, depth, lineSize) 0068 { 0069 } 0070 ~KisBufferStreamContigBelow16() override = default; 0071 uint32_t nextValue() override; 0072 }; 0073 0074 class KisBufferStreamContigBelow32 : public KisBufferStreamContigBase 0075 { 0076 public: 0077 KisBufferStreamContigBelow32(uint8_t *src, uint16_t depth, tsize_t lineSize) 0078 : KisBufferStreamContigBase(src, depth, lineSize) 0079 { 0080 } 0081 0082 public: 0083 ~KisBufferStreamContigBelow32() override = default; 0084 uint32_t nextValue() override; 0085 }; 0086 0087 class KisBufferStreamContigAbove32 : public KisBufferStreamContigBase 0088 { 0089 public: 0090 KisBufferStreamContigAbove32(uint8_t *src, uint16_t depth, tsize_t lineSize) 0091 : KisBufferStreamContigBase(src, depth, lineSize) 0092 { 0093 } 0094 0095 public: 0096 ~KisBufferStreamContigAbove32() override = default; 0097 uint32_t nextValue() override; 0098 }; 0099 0100 class KisBufferStreamSeparate : public KisBufferStreamBase 0101 { 0102 public: 0103 KisBufferStreamSeparate(uint8_t **srcs, 0104 uint16_t nb_samples, 0105 uint16_t depth, 0106 tsize_t *lineSize); 0107 ~KisBufferStreamSeparate() override = default; 0108 0109 uint32_t nextValue() override; 0110 0111 void restart() override; 0112 0113 void moveToLine(tsize_t lineNumber) override; 0114 0115 void moveToPos(tsize_t x, tsize_t y) override; 0116 0117 tsize_t x() const override; 0118 0119 tsize_t y() const override; 0120 0121 tsize_t width() const override; 0122 0123 protected: 0124 QVector<QSharedPointer<KisBufferStreamBase>> streams; 0125 uint16_t m_current_sample = 0; 0126 uint16_t m_nb_samples; 0127 }; 0128 0129 class KisBufferStreamInterleaveUpsample : public KisBufferStreamSeparate 0130 { 0131 public: 0132 KisBufferStreamInterleaveUpsample(uint8_t **srcs, 0133 uint16_t nb_samples, 0134 uint16_t depth, 0135 tsize_t *lineSize, 0136 uint16_t hsubsample, 0137 uint16_t vsubsample); 0138 0139 uint32_t nextValue() override; 0140 0141 void moveToPos(tsize_t x, tsize_t y) override; 0142 0143 tsize_t x() const override; 0144 0145 tsize_t y() const override; 0146 0147 tsize_t width() const override 0148 { 0149 return streams[0]->width(); 0150 } 0151 0152 void restart() override 0153 { 0154 KisBufferStreamSeparate::restart(); 0155 m_currentPlane = 0; 0156 } 0157 0158 protected: 0159 uint16_t m_hsubsample, m_vsubsample; 0160 uint16_t m_currentPlane = 0; 0161 }; 0162 0163 #endif