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

#include <kis_tiff_reader.h>

+ Inheritance diagram for KisTIFFReaderTarget< T >:

Public Types

using type = T
 

Public Member Functions

uint32_t copyDataToChannels (quint32 x, quint32 y, quint32 dataWidth, QSharedPointer< KisBufferStreamBase > tiffstream) override
 
 KisTIFFReaderTarget (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, T alphaValue)
 
- Public Member Functions inherited from KisTIFFReaderBase
virtual void finalize ()
 
 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 _copyDataToChannels (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 _copyDataToChannels (quint32 x, quint32 y, quint32 dataWidth, QSharedPointer< KisBufferStreamBase > tiffstream)
 

Private Attributes

m_alphaValue
 

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 KisTIFFReaderTarget< T >

Definition at line 257 of file kis_tiff_reader.h.

Member Typedef Documentation

◆ type

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

Definition at line 260 of file kis_tiff_reader.h.

Constructor & Destructor Documentation

◆ KisTIFFReaderTarget()

template<typename T >
KisTIFFReaderTarget< T >::KisTIFFReaderTarget ( 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,
T alphaValue )
inline

Definition at line 262 of file kis_tiff_reader.h.

273 : KisTIFFReaderBase(device,
274 poses,
275 alphapos,
277 sample_format,
278 nbcolorssamples,
279 extrasamplescount,
280 premultipliedAlpha,
281 transformProfile,
282 postprocessor)
283 , m_alphaValue(alphaValue)
284 {
285 }
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

Member Function Documentation

◆ _copyDataToChannels() [1/2]

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

Definition at line 300 of file kis_tiff_reader.h.

304 {
305 KisHLineIteratorSP it = this->paintDevice()->createHLineIteratorNG(x, y, dataWidth);
306 do {
307 T *d = reinterpret_cast<T *>(it->rawData());
308 quint8 i = 0;
309 for (i = 0; i < this->nbColorsSamples(); i++) {
310 // XXX: for half this should use the bit constructor (plus downcast to uint16_t) (same as in the rest accesses)
311 const uint32_t v = tiffstream->nextValue();
312 std::memcpy(&d[this->poses()[i]], &v, sizeof(T));
313 }
314 this->postProcessor()->postProcess(d);
315 if (this->transform()) {
316 this->transform()->transform(reinterpret_cast<quint8 *>(d), reinterpret_cast<quint8 *>(d), 1);
317 }
318 d[this->poses()[i]] = m_alphaValue;
319 for (quint8 k = 0; k < this->nbExtraSamples(); k++) {
320 if (k == this->alphaPos()) {
321 const uint32_t v = tiffstream->nextValue();
322 std::memcpy(&d[this->poses()[i]], &v, sizeof(T));
323 } else {
324 (void)tiffstream->nextValue();
325 }
326 }
327
328 if (this->hasPremultipliedAlpha()) {
329 auto unmultipliedColorsConsistent = [this, i](T *d) { return !(std::abs(d[this->poses()[i]]) < std::numeric_limits<T>::epsilon()); };
330
331 auto checkUnmultipliedColorsConsistent = [this, i](const T *d) {
332 const T alpha = std::abs(d[this->poses()[i]]);
333
334 if (alpha >= static_cast<T>(0.01)) {
335 return true;
336 } else {
337 for (size_t i = 0; i < this->nbColorsSamples(); i++) {
338 if (!qFuzzyCompare(T(d[i] * alpha), d[i])) {
339 return false;
340 }
341 }
342 return true;
343 }
344 };
345
346 if (!unmultipliedColorsConsistent(d)) {
347 while (true) {
348 T newAlpha = d[this->poses()[i]];
349
350 for (quint8 i = 0; i < this->nbColorsSamples(); i++) {
351 d[i] = std::lroundf(d[i] * newAlpha);
352 }
353
354 d[this->poses()[i]] = newAlpha;
355
356 if (checkUnmultipliedColorsConsistent(d)) {
357 break;
358 }
359
360 newAlpha += std::numeric_limits<T>::epsilon();
361 }
362 } else {
363 const T alpha = d[this->poses()[i]];
364 for (quint8 i = 0; i < this->nbColorsSamples(); i++) {
365 d[i] = std::lroundf(d[i] * alpha);
366 }
367 }
368 }
369 } while (it->nextPixel());
370 return 1;
371 }
qreal v
KisHLineIteratorSP createHLineIteratorNG(qint32 x, qint32 y, qint32 w)
virtual void postProcess(void *) const =0
qint32 alphaPos() const
quint16 nbExtraSamples() const
KoColorTransformation * transform() const
quint16 nbColorsSamples() const
KisPaintDeviceSP paintDevice() const
bool hasPremultipliedAlpha() const
const KisTIFFPostProcessor * postProcessor() const
virtual void transform(const quint8 *src, quint8 *dst, qint32 nPixels) const =0
static bool qFuzzyCompare(half p1, half p2)
typedef void(QOPENGLF_APIENTRYP PFNGLINVALIDATEBUFFERDATAPROC)(GLuint buffer)

References KisTIFFReaderBase::alphaPos(), KisPaintDevice::createHLineIteratorNG(), KisTIFFReaderBase::hasPremultipliedAlpha(), KisTIFFReaderTarget< T >::m_alphaValue, KisTIFFReaderBase::nbColorsSamples(), KisTIFFReaderBase::nbExtraSamples(), KisTIFFReaderBase::paintDevice(), KisTIFFReaderBase::poses(), KisTIFFPostProcessor::postProcess(), KisTIFFReaderBase::postProcessor(), qFuzzyCompare(), KisTIFFReaderBase::transform(), KoColorTransformation::transform(), v, and void().

◆ _copyDataToChannels() [2/2]

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

Definition at line 376 of file kis_tiff_reader.h.

380 {
381 KisHLineIteratorSP it = this->paintDevice()->createHLineIteratorNG(x, y, dataWidth);
382 const double coeff = std::numeric_limits<T>::max() / static_cast<double>(std::pow(2.0, this->sourceDepth()) - 1);
383 const bool no_coeff = !std::is_same<T, uint8_t>::value && this->sourceDepth() == sizeof(T) * CHAR_BIT;
384 // dbgFile <<" depth expansion coefficient :" << coeff;
385 do {
386 T *d = reinterpret_cast<T *>(it->rawData());
387 quint8 i;
388 for (i = 0; i < this->nbColorsSamples(); i++) {
389 if (sampleFormat() == SAMPLEFORMAT_INT) {
390 T value;
391 const typename std::make_signed<T>::type v =
392 static_cast<typename std::make_signed<T>::type>(
393 tiffstream->nextValue());
394 value = v + (std::numeric_limits<T>::max() / 2) + 1;
395 if (no_coeff) {
396 d[this->poses()[i]] = static_cast<T>(value);
397 } else {
398 d[this->poses()[i]] = static_cast<T>(value * coeff);
399 }
400 } else {
401 if (no_coeff) {
402 d[this->poses()[i]] = static_cast<T>(tiffstream->nextValue());
403 } else {
404 d[this->poses()[i]] = static_cast<T>(tiffstream->nextValue() * coeff);
405 }
406 }
407 }
408 this->postProcessor()->postProcess(d);
409 if (this->transform()) {
410 this->transform()->transform(reinterpret_cast<quint8 *>(d), reinterpret_cast<quint8 *>(d), 1);
411 }
412 d[this->poses()[i]] = m_alphaValue;
413 for (quint8 k = 0; k < this->nbExtraSamples(); k++) {
414 if (k == this->alphaPos()) {
415 if (sampleFormat() == SAMPLEFORMAT_INT) {
416 T value;
417 const typename std::make_signed<T>::type v =
418 static_cast<typename std::make_signed<T>::type>(
419 tiffstream->nextValue());
420 value = v + (std::numeric_limits<T>::max() / 2) + 1;
421 if (no_coeff) {
422 d[this->poses()[i]] = static_cast<T>(value);
423 } else {
424 d[this->poses()[i]] = static_cast<T>(value * coeff);
425 }
426 } else {
427 if (no_coeff) {
428 d[this->poses()[i]] = static_cast<T>(tiffstream->nextValue());
429 } else {
430 d[this->poses()[i]] = static_cast<T>(tiffstream->nextValue() * coeff);
431 }
432 }
433 } else {
434 tiffstream->nextValue();
435 }
436 }
437
438 if (hasPremultipliedAlpha()) {
439 const T alpha = d[poses()[i]];
440 const float factor = alpha == 0 ? 0 : static_cast<float>(std::numeric_limits<T>::max()) / alpha;
441
442 for (quint8 i = 0; i < nbColorsSamples(); i++) {
443 d[i] = std::lroundf(d[i] * factor);
444 }
445 }
446 } while (it->nextPixel());
447 return 1;
448 }
float value(const T *src, size_t ch)
uint16_t sampleFormat() const

References KisTIFFReaderBase::alphaPos(), KisPaintDevice::createHLineIteratorNG(), KisTIFFReaderBase::hasPremultipliedAlpha(), KisTIFFReaderTarget< T >::m_alphaValue, KisTIFFReaderBase::nbColorsSamples(), KisTIFFReaderBase::nbExtraSamples(), KisTIFFReaderBase::paintDevice(), KisTIFFReaderBase::poses(), KisTIFFPostProcessor::postProcess(), KisTIFFReaderBase::postProcessor(), KisTIFFReaderBase::sampleFormat(), KisTIFFReaderBase::sourceDepth(), KisTIFFReaderBase::transform(), KoColorTransformation::transform(), v, and value().

◆ copyDataToChannels()

template<typename T >
uint32_t KisTIFFReaderTarget< 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 288 of file kis_tiff_reader.h.

292 {
293 return _copyDataToChannels(x, y, dataWidth, tiffstream);
294 }
uint32_t _copyDataToChannels(quint32 x, quint32 y, quint32 dataWidth, QSharedPointer< KisBufferStreamBase > tiffstream)

References KisTIFFReaderTarget< T >::_copyDataToChannels().

Member Data Documentation

◆ m_alphaValue

template<typename T >
T KisTIFFReaderTarget< T >::m_alphaValue
private

Definition at line 451 of file kis_tiff_reader.h.


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