Krita Source Code Documentation
Loading...
Searching...
No Matches
KisTIFFYCbCrReader< T > Class Template Reference

#include <kis_tiff_ycbcr_reader.h>

+ Inheritance diagram for KisTIFFYCbCrReader< T >:

Public Types

using type = T
 

Public Member Functions

uint32_t copyDataToChannels (quint32 x, quint32 y, quint32 dataWidth, QSharedPointer< KisBufferStreamBase > tiffstream) override
 
void finalize () override
 
 KisTIFFYCbCrReader (KisPaintDeviceSP device, quint32 width, quint32 height, const std::array< quint8, 5 > &poses, int32_t alphapos, uint16_t sourceDepth, uint16_t sampleformat, uint16_t nbcolorssamples, uint16_t extrasamplescount, bool premultipliedAlpha, KoColorTransformation *transformProfile, QSharedPointer< KisTIFFPostProcessor > postprocessor, uint16_t hsub, uint16_t vsub)
 
 ~KisTIFFYCbCrReader () override=default
 
- Public Member Functions inherited from KisTIFFReaderBase
 KisTIFFReaderBase (KisPaintDeviceSP device, const std::array< quint8, 5 > &poses, int32_t alphapos, uint16_t sourceDepth, uint16_t sample_format, uint16_t nbcolorssamples, uint16_t extrasamplescount, bool premultipliedAlpha, KoColorTransformation *transformProfile, QSharedPointer< KisTIFFPostProcessor > postprocessor)
 
virtual ~KisTIFFReaderBase ()=default
 

Private Member Functions

template<typename U = T, typename std::enable_if<!std::numeric_limits< U >::is_integer, void >::type * = nullptr>
uint32_t copyDataToChannelsImpl (quint32 x, quint32 y, quint32 dataWidth, QSharedPointer< KisBufferStreamBase > tiffstream)
 
template<typename U = T, typename std::enable_if< std::numeric_limits< U >::is_integer, void >::type * = nullptr>
uint32_t copyDataToChannelsImpl (quint32 x, quint32 y, quint32 dataWidth, QSharedPointer< KisBufferStreamBase > tiffstream)
 
template<typename U = T, typename std::enable_if<!std::numeric_limits< U >::is_integer, void >::type * = nullptr>
void finalizeImpl ()
 
template<typename U = T, typename std::enable_if< std::numeric_limits< U >::is_integer, void >::type * = nullptr>
void finalizeImpl ()
 

Private Attributes

std::unique_ptr< T[]> m_bufferCb
 
std::unique_ptr< T[]> m_bufferCr
 
quint32 m_bufferHeight
 
quint32 m_bufferWidth
 
uint16_t m_hsub
 
quint32 m_imageHeight
 
quint32 m_imageWidth
 
uint16_t m_vsub
 

Additional Inherited Members

- Protected Member Functions inherited from KisTIFFReaderBase
qint32 alphaPos () const
 
bool hasPremultipliedAlpha () const
 
quint16 nbColorsSamples () const
 
quint16 nbExtraSamples () const
 
KisPaintDeviceSP paintDevice () const
 
const std::array< quint8, 5 > & poses () const
 
const KisTIFFPostProcessorpostProcessor () const
 
uint16_t sampleFormat () const
 
quint16 sourceDepth () const
 
KoColorTransformationtransform () const
 

Detailed Description

template<typename T>
class KisTIFFYCbCrReader< T >

Definition at line 29 of file kis_tiff_ycbcr_reader.h.

Member Typedef Documentation

◆ type

template<typename T >
using KisTIFFYCbCrReader< T >::type = T

Definition at line 32 of file kis_tiff_ycbcr_reader.h.

Constructor & Destructor Documentation

◆ KisTIFFYCbCrReader()

template<typename T >
KisTIFFYCbCrReader< T >::KisTIFFYCbCrReader ( KisPaintDeviceSP device,
quint32 width,
quint32 height,
const std::array< quint8, 5 > & poses,
int32_t alphapos,
uint16_t sourceDepth,
uint16_t sampleformat,
uint16_t nbcolorssamples,
uint16_t extrasamplescount,
bool premultipliedAlpha,
KoColorTransformation * transformProfile,
QSharedPointer< KisTIFFPostProcessor > postprocessor,
uint16_t hsub,
uint16_t vsub )
inline
Parameters
hsubhorizontal subsampling of Cb and Cr
hsubvertical subsampling of Cb and Cr

Definition at line 38 of file kis_tiff_ycbcr_reader.h.

52 : KisTIFFReaderBase(device,
53 poses,
54 alphapos,
56 sampleformat,
57 nbcolorssamples,
58 extrasamplescount,
59 premultipliedAlpha,
60 transformProfile,
61 postprocessor)
62 , m_hsub(hsub)
63 , m_vsub(vsub)
64 , m_imageWidth(width)
65 {
66 // Initialize the buffer
67 if (2 * (m_imageWidth / 2) != m_imageWidth)
70 m_imageHeight = height;
71 if (2 * (m_imageHeight / 2) != m_imageHeight)
74 m_bufferCb = std::make_unique<T[]>(m_bufferWidth * m_bufferHeight);
75 m_bufferCr = std::make_unique<T[]>(m_bufferWidth * m_bufferHeight);
76 }
const std::array< quint8, 5 > & poses() const
KisTIFFReaderBase(KisPaintDeviceSP device, const std::array< quint8, 5 > &poses, int32_t alphapos, uint16_t sourceDepth, uint16_t sample_format, uint16_t nbcolorssamples, uint16_t extrasamplescount, bool premultipliedAlpha, KoColorTransformation *transformProfile, QSharedPointer< KisTIFFPostProcessor > postprocessor)
quint16 sourceDepth() const
std::unique_ptr< T[]> m_bufferCr
std::unique_ptr< T[]> m_bufferCb

References KisTIFFYCbCrReader< T >::m_bufferCb, KisTIFFYCbCrReader< T >::m_bufferCr, KisTIFFYCbCrReader< T >::m_bufferHeight, KisTIFFYCbCrReader< T >::m_bufferWidth, KisTIFFYCbCrReader< T >::m_hsub, KisTIFFYCbCrReader< T >::m_imageHeight, KisTIFFYCbCrReader< T >::m_imageWidth, and KisTIFFYCbCrReader< T >::m_vsub.

◆ ~KisTIFFYCbCrReader()

template<typename T >
KisTIFFYCbCrReader< T >::~KisTIFFYCbCrReader ( )
overridedefault

Member Function Documentation

◆ copyDataToChannels()

template<typename T >
uint32_t KisTIFFYCbCrReader< T >::copyDataToChannels ( quint32 x,
quint32 y,
quint32 dataWidth,
QSharedPointer< KisBufferStreamBase > tiffstream )
inlineoverridevirtual

This function copy data from the tiff stream to the paint device starting at the given position.

Parameters
xhorizontal start position
yvertical start position
dataWidthwidth of the data to copy
tiffstreamsource of data
Returns
the number of line which were copied

Implements KisTIFFReaderBase.

Definition at line 81 of file kis_tiff_ycbcr_reader.h.

85 {
86 return copyDataToChannelsImpl(x, y, dataWidth, tiffstream);
87 }
uint32_t copyDataToChannelsImpl(quint32 x, quint32 y, quint32 dataWidth, QSharedPointer< KisBufferStreamBase > tiffstream)

References KisTIFFYCbCrReader< T >::copyDataToChannelsImpl().

◆ copyDataToChannelsImpl() [1/2]

template<typename T >
template<typename U = T, typename std::enable_if<!std::numeric_limits< U >::is_integer, void >::type * = nullptr>
uint32_t KisTIFFYCbCrReader< T >::copyDataToChannelsImpl ( quint32 x,
quint32 y,
quint32 dataWidth,
QSharedPointer< KisBufferStreamBase > tiffstream )
inlineprivate

Definition at line 99 of file kis_tiff_ycbcr_reader.h.

103 {
104 quint32 numcols = dataWidth / m_hsub;
105 quint32 buffPos = y / m_vsub * m_bufferWidth + x / m_hsub;
106 for (quint32 index = 0; index < numcols; index++) {
108 for (int vindex = 0; vindex < m_vsub; vindex++) {
109 do {
110 T *d = reinterpret_cast<T *>(it->rawData());
111 d[0] = static_cast<T>(tiffstream->nextValue());
112 d[3] = std::numeric_limits<T>::max();
113 for (int k = 0; k < nbExtraSamples(); k++) {
114 if (k == alphaPos())
115 d[3] = static_cast<T>(tiffstream->nextValue());
116 else
117 tiffstream->nextValue();
118 }
119 } while (it->nextPixel());
120 it->nextRow();
121 }
122 m_bufferCb[buffPos] = static_cast<T>(tiffstream->nextValue());
123 m_bufferCr[buffPos] = static_cast<T>(tiffstream->nextValue());
124 buffPos++;
125 }
126 return m_vsub;
127 }
KisHLineIteratorSP createHLineIteratorNG(qint32 x, qint32 y, qint32 w)
qint32 alphaPos() const
quint16 nbExtraSamples() const
KisPaintDeviceSP paintDevice() const

References KisTIFFReaderBase::alphaPos(), KisPaintDevice::createHLineIteratorNG(), KisTIFFYCbCrReader< T >::m_bufferCb, KisTIFFYCbCrReader< T >::m_bufferCr, KisTIFFYCbCrReader< T >::m_bufferWidth, KisTIFFYCbCrReader< T >::m_hsub, KisTIFFYCbCrReader< T >::m_vsub, KisTIFFReaderBase::nbExtraSamples(), and KisTIFFReaderBase::paintDevice().

◆ copyDataToChannelsImpl() [2/2]

template<typename T >
template<typename U = T, typename std::enable_if< std::numeric_limits< U >::is_integer, void >::type * = nullptr>
uint32_t KisTIFFYCbCrReader< T >::copyDataToChannelsImpl ( quint32 x,
quint32 y,
quint32 dataWidth,
QSharedPointer< KisBufferStreamBase > tiffstream )
inlineprivate

Definition at line 133 of file kis_tiff_ycbcr_reader.h.

137 {
138 quint32 numcols = dataWidth / m_hsub;
139 double coeff = std::numeric_limits<T>::max() / (double)(std::pow(2.0, this->sourceDepth()) - 1);
140 // dbgFile <<" depth expansion coefficient :" << coeff;
141 // dbgFile <<" y =" << y;
142 size_t buffPos = y / m_vsub * m_bufferWidth + x / m_hsub;
143 for (quint32 index = 0; index < numcols; index++) {
145 for (int vindex = 0; vindex < m_vsub; vindex++) {
146 do {
147 T *d = reinterpret_cast<T *>(it->rawData());
148 d[0] = static_cast<T>(tiffstream->nextValue() * coeff);
149 d[3] = std::numeric_limits<T>::max();
150 for (int k = 0; k < nbExtraSamples(); k++) {
151 if (k == alphaPos())
152 d[3] = static_cast<T>(tiffstream->nextValue() * coeff);
153 else
154 tiffstream->nextValue();
155 }
156 } while (it->nextPixel());
157 it->nextRow();
158 }
159 m_bufferCb[buffPos] = static_cast<T>(tiffstream->nextValue() * coeff);
160 m_bufferCr[buffPos] = static_cast<T>(tiffstream->nextValue() * coeff);
161 buffPos++;
162 }
163 return m_vsub;
164 }

References KisTIFFReaderBase::alphaPos(), KisPaintDevice::createHLineIteratorNG(), KisTIFFYCbCrReader< T >::m_bufferCb, KisTIFFYCbCrReader< T >::m_bufferCr, KisTIFFYCbCrReader< T >::m_bufferWidth, KisTIFFYCbCrReader< T >::m_hsub, KisTIFFYCbCrReader< T >::m_vsub, KisTIFFReaderBase::nbExtraSamples(), KisTIFFReaderBase::paintDevice(), and KisTIFFReaderBase::sourceDepth().

◆ finalize()

template<typename T >
void KisTIFFYCbCrReader< T >::finalize ( )
inlineoverridevirtual

This function is called when all data has been read and should be used for any postprocessing.

Reimplemented from KisTIFFReaderBase.

Definition at line 89 of file kis_tiff_ycbcr_reader.h.

90 {
91 return finalizeImpl();
92 }

References KisTIFFYCbCrReader< T >::finalizeImpl().

◆ finalizeImpl() [1/2]

template<typename T >
template<typename U = T, typename std::enable_if<!std::numeric_limits< U >::is_integer, void >::type * = nullptr>
void KisTIFFYCbCrReader< T >::finalizeImpl ( )
inlineprivate

Definition at line 166 of file kis_tiff_ycbcr_reader.h.

167 {
169 for (size_t y = 0; y < m_imageHeight; y++) {
170 size_t x = 0;
171 do {
172 T *d = reinterpret_cast<T *>(it->rawData());
173 size_t index = x / m_hsub + y / m_vsub * m_bufferWidth;
174 d[1] = m_bufferCb[index];
175 d[2] = m_bufferCr[index];
176 ++x;
177
178 if (this->hasPremultipliedAlpha()) {
179 auto unmultipliedColorsConsistent = [](T *d) { return !(std::abs(d[3]) < std::numeric_limits<T>::epsilon()); };
180
181 auto checkUnmultipliedColorsConsistent = [this](const T *d) {
182 const T alpha = std::abs(d[3]);
183
184 if (alpha >= static_cast<T>(0.01)) {
185 return true;
186 } else {
187 for (size_t i = 0; i < this->nbColorsSamples(); i++) {
188 if (!qFuzzyCompare(T(d[i] * alpha), d[i])) {
189 return false;
190 }
191 }
192 return true;
193 }
194 };
195
196 if (!unmultipliedColorsConsistent(d)) {
197 while (1) {
198 T newAlpha = d[3];
199
200 for (quint8 i = 0; i < this->nbColorsSamples(); i++) {
201 d[i] = std::lroundf(d[i] * newAlpha);
202 }
203
204 d[3] = newAlpha;
205
206 if (checkUnmultipliedColorsConsistent(d)) {
207 break;
208 }
209
210 newAlpha += std::numeric_limits<T>::epsilon();
211 }
212 } else {
213 const T alpha = d[3];
214 for (quint8 i = 0; i < this->nbColorsSamples(); i++) {
215 d[i] = std::lroundf(d[i] * alpha);
216 }
217 }
218 }
219 } while (it->nextPixel());
220 it->nextRow();
221 }
222 }
quint16 nbColorsSamples() const
bool hasPremultipliedAlpha() const
static bool qFuzzyCompare(half p1, half p2)

References KisPaintDevice::createHLineIteratorNG(), KisTIFFReaderBase::hasPremultipliedAlpha(), KisTIFFYCbCrReader< T >::m_bufferCb, KisTIFFYCbCrReader< T >::m_bufferCr, KisTIFFYCbCrReader< T >::m_bufferWidth, KisTIFFYCbCrReader< T >::m_hsub, KisTIFFYCbCrReader< T >::m_imageHeight, KisTIFFYCbCrReader< T >::m_imageWidth, KisTIFFYCbCrReader< T >::m_vsub, KisTIFFReaderBase::nbColorsSamples(), KisTIFFReaderBase::paintDevice(), and qFuzzyCompare().

◆ finalizeImpl() [2/2]

template<typename T >
template<typename U = T, typename std::enable_if< std::numeric_limits< U >::is_integer, void >::type * = nullptr>
void KisTIFFYCbCrReader< T >::finalizeImpl ( )
inlineprivate

Definition at line 224 of file kis_tiff_ycbcr_reader.h.

225 {
227 for (size_t y = 0; y < m_imageHeight; y++) {
228 size_t x = 0;
229 do {
230 T *d = reinterpret_cast<T *>(it->rawData());
231 size_t index = x / m_hsub + y / m_vsub * m_bufferWidth;
232 d[1] = m_bufferCb[index];
233 d[2] = m_bufferCr[index];
234 ++x;
235
236 if (this->hasPremultipliedAlpha()) {
237 const T alpha = d[3];
238 const float factor = alpha == 0 ? 0 : static_cast<float>(std::numeric_limits<T>::max()) / alpha;
239
240 for (quint8 i = 0; i < this->nbColorsSamples(); i++) {
241 d[i] = std::lroundf(d[i] * factor);
242 }
243 }
244 } while (it->nextPixel());
245 it->nextRow();
246 }
247 }

References KisPaintDevice::createHLineIteratorNG(), KisTIFFReaderBase::hasPremultipliedAlpha(), KisTIFFYCbCrReader< T >::m_bufferCb, KisTIFFYCbCrReader< T >::m_bufferCr, KisTIFFYCbCrReader< T >::m_bufferWidth, KisTIFFYCbCrReader< T >::m_hsub, KisTIFFYCbCrReader< T >::m_imageHeight, KisTIFFYCbCrReader< T >::m_imageWidth, KisTIFFYCbCrReader< T >::m_vsub, KisTIFFReaderBase::nbColorsSamples(), and KisTIFFReaderBase::paintDevice().

Member Data Documentation

◆ m_bufferCb

template<typename T >
std::unique_ptr<T[]> KisTIFFYCbCrReader< T >::m_bufferCb
private

Definition at line 250 of file kis_tiff_ycbcr_reader.h.

◆ m_bufferCr

template<typename T >
std::unique_ptr<T[]> KisTIFFYCbCrReader< T >::m_bufferCr
private

Definition at line 251 of file kis_tiff_ycbcr_reader.h.

◆ m_bufferHeight

template<typename T >
quint32 KisTIFFYCbCrReader< T >::m_bufferHeight
private

Definition at line 252 of file kis_tiff_ycbcr_reader.h.

◆ m_bufferWidth

template<typename T >
quint32 KisTIFFYCbCrReader< T >::m_bufferWidth
private

Definition at line 252 of file kis_tiff_ycbcr_reader.h.

◆ m_hsub

template<typename T >
uint16_t KisTIFFYCbCrReader< T >::m_hsub
private

Definition at line 253 of file kis_tiff_ycbcr_reader.h.

◆ m_imageHeight

template<typename T >
quint32 KisTIFFYCbCrReader< T >::m_imageHeight
private

Definition at line 255 of file kis_tiff_ycbcr_reader.h.

◆ m_imageWidth

template<typename T >
quint32 KisTIFFYCbCrReader< T >::m_imageWidth
private

Definition at line 255 of file kis_tiff_ycbcr_reader.h.

◆ m_vsub

template<typename T >
uint16_t KisTIFFYCbCrReader< T >::m_vsub
private

Definition at line 254 of file kis_tiff_ycbcr_reader.h.


The documentation for this class was generated from the following file: