7#ifndef _KIS_TIFF_READER_H_
8#define _KIS_TIFF_READER_H_
86 template<
typename U = T,
87 typename std::enable_if<std::numeric_limits<U>::is_signed,
88 void>::type * =
nullptr>
96 template<
typename U = T,
97 typename std::enable_if<!std::numeric_limits<U>::is_signed,
98 void>::type * =
nullptr>
102 data[i] = std::numeric_limits<T>::max() - data[i];
123 template<
typename U = T,
124 typename std::enable_if<!std::numeric_limits<U>::is_integer,
125 void>::type * =
nullptr>
133 template<
typename U = T,
134 typename std::enable_if<std::numeric_limits<U>::is_integer,
135 void>::type * =
nullptr>
139 data[i] += std::numeric_limits<T>::max() / 2;
148 const std::array<quint8, 5> &
poses,
151 uint16_t sample_format,
152 uint16_t nbcolorssamples,
153 uint16_t extrasamplescount,
154 bool premultipliedAlpha,
229 inline const std::array<quint8, 5> &
poses()
const
263 const std::array<quint8, 5> &
poses,
266 uint16_t sample_format,
267 uint16_t nbcolorssamples,
268 uint16_t extrasamplescount,
269 bool premultipliedAlpha,
297 template<
typename U = T,
298 typename std::enable_if<!std::numeric_limits<U>::is_integer,
307 T *d =
reinterpret_cast<T *
>(it->rawData());
311 const uint32_t
v = tiffstream->nextValue();
312 std::memcpy(&d[this->
poses()[i]], &
v,
sizeof(T));
316 this->
transform()->
transform(
reinterpret_cast<quint8 *
>(d),
reinterpret_cast<quint8 *
>(d), 1);
321 const uint32_t
v = tiffstream->nextValue();
322 std::memcpy(&d[this->
poses()[i]], &
v,
sizeof(T));
324 (
void)tiffstream->nextValue();
329 auto unmultipliedColorsConsistent = [
this, i](T *d) {
return !(std::abs(d[this->
poses()[i]]) < std::numeric_limits<T>::epsilon()); };
331 auto checkUnmultipliedColorsConsistent = [
this, i](
const T *d) {
332 const T alpha = std::abs(d[this->
poses()[i]]);
334 if (alpha >=
static_cast<T
>(0.01)) {
346 if (!unmultipliedColorsConsistent(d)) {
348 T newAlpha = d[this->
poses()[i]];
351 d[i] = std::lroundf(d[i] * newAlpha);
354 d[this->
poses()[i]] = newAlpha;
356 if (checkUnmultipliedColorsConsistent(d)) {
360 newAlpha += std::numeric_limits<T>::epsilon();
363 const T alpha = d[this->
poses()[i]];
365 d[i] = std::lroundf(d[i] * alpha);
369 }
while (it->nextPixel());
373 template<
typename U = T,
374 typename std::enable_if<std::numeric_limits<U>::is_integer,
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;
386 T *d =
reinterpret_cast<T *
>(it->rawData());
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;
398 d[this->
poses()[i]] =
static_cast<T
>(
value * coeff);
402 d[this->
poses()[i]] =
static_cast<T
>(tiffstream->nextValue());
404 d[this->
poses()[i]] =
static_cast<T
>(tiffstream->nextValue() * coeff);
410 this->
transform()->
transform(
reinterpret_cast<quint8 *
>(d),
reinterpret_cast<quint8 *
>(d), 1);
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;
424 d[this->
poses()[i]] =
static_cast<T
>(
value * coeff);
428 d[this->
poses()[i]] =
static_cast<T
>(tiffstream->nextValue());
430 d[this->
poses()[i]] =
static_cast<T
>(tiffstream->nextValue() * coeff);
434 tiffstream->nextValue();
439 const T alpha = d[
poses()[i]];
440 const float factor = alpha == 0 ? 0 :
static_cast<float>(std::numeric_limits<T>::max()) / alpha;
443 d[i] = std::lroundf(d[i] * factor);
446 }
while (it->nextPixel());
463 const std::array<quint8, 5> &
poses,
466 uint16_t sample_format,
467 uint16_t nbcolorssamples,
468 bool premultipliedAlpha,
469 uint8_t extrasamplescount,
499 uint32_t index = tiffstream->nextValue();
503 d[3] = std::numeric_limits<KisTIFFReaderFromPalette::type>::max();
505 }
while (it->nextPixel());
float value(const T *src, size_t ch)
KisHLineIteratorSP createHLineIteratorNG(qint32 x, qint32 y, qint32 w)
KisTIFFPostProcessorCIELABtoICCLAB(uint32_t nbcolorssamples)
~KisTIFFPostProcessorCIELABtoICCLAB() override=default
void postProcess(void *data) const override
void postProcessImpl(T *data) const
void postProcess(void *) const override
~KisTIFFPostProcessorDummy() override=default
KisTIFFPostProcessorDummy(uint32_t nbcolorssamples)
~KisTIFFPostProcessorInvert() override=default
void postProcessImpl(T *data) const
KisTIFFPostProcessorInvert(uint32_t nbcolorssamples)
void postProcess(void *data) const override
uint32_t nbColorsSamples() const
virtual void postProcess(void *) const =0
KisTIFFPostProcessor(uint32_t nbcolorssamples)
virtual ~KisTIFFPostProcessor()=default
uint32_t m_nbcolorssamples
QSharedPointer< KisTIFFPostProcessor > mpostProcessImpl
const std::array< quint8, 5 > & poses() const
KisPaintDeviceSP m_device
KoColorTransformation * m_transformProfile
std::array< quint8, 5 > m_poses
quint16 nbExtraSamples() const
bool m_premultipliedAlpha
KoColorTransformation * transform() const
quint16 nbColorsSamples() const
KisPaintDeviceSP paintDevice() const
quint16 m_nbcolorssamples
uint16_t sampleFormat() const
virtual ~KisTIFFReaderBase()=default
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)
bool hasPremultipliedAlpha() const
virtual uint32_t copyDataToChannels(quint32 x, quint32 y, quint32 dataWidth, QSharedPointer< KisBufferStreamBase > tiffstream)=0
const KisTIFFPostProcessor * postProcessor() const
quint16 sourceDepth() const
uint32_t copyDataToChannels(quint32 x, quint32 y, quint32 dataWidth, QSharedPointer< KisBufferStreamBase > tiffstream) override
KisTIFFReaderFromPalette(KisPaintDeviceSP device, uint16_t *red, uint16_t *green, uint16_t *blue, const std::array< quint8, 5 > &poses, int32_t alphapos, uint16_t sourceDepth, uint16_t sample_format, uint16_t nbcolorssamples, bool premultipliedAlpha, uint8_t extrasamplescount, KoColorTransformation *transformProfile, QSharedPointer< KisTIFFPostProcessor > postprocessor)
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)
uint32_t _copyDataToChannels(quint32 x, quint32 y, quint32 dataWidth, QSharedPointer< KisBufferStreamBase > tiffstream)
uint32_t copyDataToChannels(quint32 x, quint32 y, quint32 dataWidth, QSharedPointer< KisBufferStreamBase > tiffstream) override
static bool qFuzzyCompare(half p1, half p2)
typedef void(QOPENGLF_APIENTRYP PFNGLINVALIDATEBUFFERDATAPROC)(GLuint buffer)