20#include "kis_tiff_ycbcr_reader.h"
22#include <kis_iterators_pixel.h>
23#include <kis_paint_device.h>
25#include "kis_tiff_stream.h"
28KisTIFFYCbCrReaderTarget8Bit::KisTIFFYCbCrReaderTarget8Bit( KisPaintDeviceSP device, TQ_UINT8* poses, int8 alphapos, uint8 sourceDepth, uint8 nbcolorssamples, uint8 extrasamplescount, cmsHTRANSFORM transformProfile, KisTIFFPostProcessor* postprocessor, uint16 hsub, uint16 vsub, KisTIFFYCbCr::Position position ) : KisTIFFReaderBase(device, poses, alphapos, sourceDepth, nbcolorssamples, extrasamplescount, transformProfile, postprocessor), m_hsub(hsub), m_vsub(vsub), m_position(position)
31 TQ_INT32 imagewidth = device->image()->width();
32 if(2*(imagewidth / 2) != imagewidth) imagewidth++;
33 m_bufferWidth = imagewidth / m_hsub;
34 TQ_INT32 imageheight = device->image()->height();
35 if(2*(imageheight / 2) != imageheight) imageheight++;
36 m_bufferHeight = imageheight / m_vsub;
37 m_bufferCb =
new TQ_UINT8[ m_bufferWidth * m_bufferHeight ];
38 m_bufferCr =
new TQ_UINT8[ m_bufferWidth * m_bufferHeight ];
41KisTIFFYCbCrReaderTarget8Bit::~KisTIFFYCbCrReaderTarget8Bit()
47uint KisTIFFYCbCrReaderTarget8Bit::copyDataToChannels( TQ_UINT32 x, TQ_UINT32 y, TQ_UINT32 dataWidth, TIFFStreamBase* tiffstream)
49 int numcols = dataWidth / m_hsub;
50 double coeff = TQ_UINT8_MAX / (double)( pow(2, sourceDepth() ) - 1 );
53 uint buffPos = y / m_vsub * m_bufferWidth + x / m_hsub ;
54 for(
int index = 0; index < numcols; index++)
56 KisHLineIterator it = paintDevice() -> createHLineIterator(x + m_hsub * index, y, m_hsub,
true);
57 for(
int vindex = 0; vindex < m_vsub; vindex++)
61 TQ_UINT8 *d = it.rawData();
62 d[0] = (TQ_UINT8)( tiffstream->nextValue() * coeff );
64 for(
int k = 0; k < nbExtraSamples(); k++)
67 d[3] = (TQ_UINT32) ( tiffstream->nextValue() * coeff );
69 tiffstream->nextValue();
75 m_bufferCb[ buffPos ] = (TQ_UINT8)(tiffstream->nextValue() * coeff);
76 m_bufferCr[ buffPos ] = (TQ_UINT8)(tiffstream->nextValue() * coeff);
82void KisTIFFYCbCrReaderTarget8Bit::finalize()
84 KisHLineIterator it = paintDevice() -> createHLineIterator(0, 0, paintDevice()->image()->width(),
true);
85 for(
int y = 0; y < paintDevice()->image()->height(); y++)
90 TQ_UINT8 *d = it.rawData();
91 int index = x/m_hsub + y/m_vsub * m_bufferWidth;
92 d[1] = m_bufferCb[ index ];
93 d[2] = m_bufferCr[ index ];
100KisTIFFYCbCrReaderTarget16Bit::KisTIFFYCbCrReaderTarget16Bit( KisPaintDeviceSP device, TQ_UINT8* poses, int8 alphapos, uint8 sourceDepth, uint8 nbcolorssamples, uint8 extrasamplescount, cmsHTRANSFORM transformProfile, KisTIFFPostProcessor* postprocessor, uint16 hsub, uint16 vsub, KisTIFFYCbCr::Position position ) : KisTIFFReaderBase(device, poses, alphapos, sourceDepth, nbcolorssamples, extrasamplescount, transformProfile, postprocessor), m_hsub(hsub), m_vsub(vsub), m_position(position)
103 TQ_INT32 imagewidth = device->image()->width();
104 if(2*(imagewidth / 2) != imagewidth) imagewidth++;
105 m_bufferWidth = imagewidth / m_hsub;
106 TQ_INT32 imageheight = device->image()->height();
107 if(2*(imageheight / 2) != imageheight) imageheight++;
108 m_bufferHeight = imageheight / m_vsub;
109 m_bufferCb =
new TQ_UINT16[ m_bufferWidth * m_bufferHeight ];
110 m_bufferCr =
new TQ_UINT16[ m_bufferWidth * m_bufferHeight ];
113KisTIFFYCbCrReaderTarget16Bit::~KisTIFFYCbCrReaderTarget16Bit()
119uint KisTIFFYCbCrReaderTarget16Bit::copyDataToChannels( TQ_UINT32 x, TQ_UINT32 y, TQ_UINT32 dataWidth, TIFFStreamBase* tiffstream)
121 int numcols = dataWidth / m_hsub;
122 double coeff = TQ_UINT16_MAX / (double)( pow(2, sourceDepth() ) - 1 );
125 uint buffPos = y / m_vsub * m_bufferWidth + x / m_hsub ;
126 for(
int index = 0; index < numcols; index++)
128 KisHLineIterator it = paintDevice() -> createHLineIterator(x + m_hsub * index, y, m_hsub,
true);
129 for(
int vindex = 0; vindex < m_vsub; vindex++)
131 while( !it.isDone() )
133 TQ_UINT16 *d =
reinterpret_cast<TQ_UINT16 *
>(it.rawData());
134 d[0] = (TQ_UINT16)( tiffstream->nextValue() * coeff );
135 d[3] = TQ_UINT16_MAX;
136 for(
int k = 0; k < nbExtraSamples(); k++)
139 d[3] = (TQ_UINT32) ( tiffstream->nextValue() * coeff );
141 tiffstream->nextValue();
147 m_bufferCb[ buffPos ] = (TQ_UINT16)(tiffstream->nextValue() * coeff);
148 m_bufferCr[ buffPos ] = (TQ_UINT16)(tiffstream->nextValue() * coeff);
154void KisTIFFYCbCrReaderTarget16Bit::finalize()
156 KisHLineIterator it = paintDevice() -> createHLineIterator(0, 0, paintDevice()->image()->width(),
true);
157 for(
int y = 0; y < paintDevice()->image()->height(); y++)
162 TQ_UINT16 *d =
reinterpret_cast<TQ_UINT16 *
>(it.rawData());
163 int index = x/m_hsub + y/m_vsub * m_bufferWidth;
164 d[1] = m_bufferCb[ index ];
165 d[2] = m_bufferCr[ index ];