00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "kis_tiff_ycbcr_reader.h"
00021
00022 #include <kis_iterators_pixel.h>
00023 #include <kis_paint_device.h>
00024
00025 #include "kis_tiff_stream.h"
00026
00027
00028 KisTIFFYCbCrReaderTarget8Bit::KisTIFFYCbCrReaderTarget8Bit( KisPaintDeviceSP device, Q_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)
00029 {
00030
00031 Q_INT32 imagewidth = device->image()->width();
00032 if(2*(imagewidth / 2) != imagewidth) imagewidth++;
00033 m_bufferWidth = imagewidth / m_hsub;
00034 Q_INT32 imageheight = device->image()->height();
00035 if(2*(imageheight / 2) != imageheight) imageheight++;
00036 m_bufferHeight = imageheight / m_vsub;
00037 m_bufferCb = new Q_UINT8[ m_bufferWidth * m_bufferHeight ];
00038 m_bufferCr = new Q_UINT8[ m_bufferWidth * m_bufferHeight ];
00039 }
00040
00041 KisTIFFYCbCrReaderTarget8Bit::~KisTIFFYCbCrReaderTarget8Bit()
00042 {
00043 delete[] m_bufferCb;
00044 delete[] m_bufferCr;
00045 }
00046
00047 uint KisTIFFYCbCrReaderTarget8Bit::copyDataToChannels( Q_UINT32 x, Q_UINT32 y, Q_UINT32 dataWidth, TIFFStreamBase* tiffstream)
00048 {
00049 int numcols = dataWidth / m_hsub;
00050 double coeff = Q_UINT8_MAX / (double)( pow(2, sourceDepth() ) - 1 );
00051
00052
00053 uint buffPos = y / m_vsub * m_bufferWidth + x / m_hsub ;
00054 for(int index = 0; index < numcols; index++)
00055 {
00056 KisHLineIterator it = paintDevice() -> createHLineIterator(x + m_hsub * index, y, m_hsub, true);
00057 for( int vindex = 0; vindex < m_vsub; vindex++)
00058 {
00059 while( !it.isDone() )
00060 {
00061 Q_UINT8 *d = it.rawData();
00062 d[0] = (Q_UINT8)( tiffstream->nextValue() * coeff );
00063 d[3] = Q_UINT8_MAX;
00064 for(int k = 0; k < nbExtraSamples(); k++)
00065 {
00066 if(k == alphaPos())
00067 d[3] = (Q_UINT32) ( tiffstream->nextValue() * coeff );
00068 else
00069 tiffstream->nextValue();
00070 }
00071 ++it;
00072 }
00073 it.nextRow();
00074 }
00075 m_bufferCb[ buffPos ] = (Q_UINT8)(tiffstream->nextValue() * coeff);
00076 m_bufferCr[ buffPos ] = (Q_UINT8)(tiffstream->nextValue() * coeff);
00077 buffPos ++;
00078 }
00079 return m_vsub;
00080 }
00081
00082 void KisTIFFYCbCrReaderTarget8Bit::finalize()
00083 {
00084 KisHLineIterator it = paintDevice() -> createHLineIterator(0, 0, paintDevice()->image()->width(), true);
00085 for(int y = 0; y < paintDevice()->image()->height(); y++)
00086 {
00087 int x = 0;
00088 while(!it.isDone())
00089 {
00090 Q_UINT8 *d = it.rawData();
00091 int index = x/m_hsub + y/m_vsub * m_bufferWidth;
00092 d[1] = m_bufferCb[ index ];
00093 d[2] = m_bufferCr[ index ];
00094 ++it; ++x;
00095 }
00096 it.nextRow();
00097 }
00098 }
00099
00100 KisTIFFYCbCrReaderTarget16Bit::KisTIFFYCbCrReaderTarget16Bit( KisPaintDeviceSP device, Q_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)
00101 {
00102
00103 Q_INT32 imagewidth = device->image()->width();
00104 if(2*(imagewidth / 2) != imagewidth) imagewidth++;
00105 m_bufferWidth = imagewidth / m_hsub;
00106 Q_INT32 imageheight = device->image()->height();
00107 if(2*(imageheight / 2) != imageheight) imageheight++;
00108 m_bufferHeight = imageheight / m_vsub;
00109 m_bufferCb = new Q_UINT16[ m_bufferWidth * m_bufferHeight ];
00110 m_bufferCr = new Q_UINT16[ m_bufferWidth * m_bufferHeight ];
00111 }
00112
00113 KisTIFFYCbCrReaderTarget16Bit::~KisTIFFYCbCrReaderTarget16Bit()
00114 {
00115 delete[] m_bufferCb;
00116 delete[] m_bufferCr;
00117 }
00118
00119 uint KisTIFFYCbCrReaderTarget16Bit::copyDataToChannels( Q_UINT32 x, Q_UINT32 y, Q_UINT32 dataWidth, TIFFStreamBase* tiffstream)
00120 {
00121 int numcols = dataWidth / m_hsub;
00122 double coeff = Q_UINT16_MAX / (double)( pow(2, sourceDepth() ) - 1 );
00123
00124
00125 uint buffPos = y / m_vsub * m_bufferWidth + x / m_hsub ;
00126 for(int index = 0; index < numcols; index++)
00127 {
00128 KisHLineIterator it = paintDevice() -> createHLineIterator(x + m_hsub * index, y, m_hsub, true);
00129 for( int vindex = 0; vindex < m_vsub; vindex++)
00130 {
00131 while( !it.isDone() )
00132 {
00133 Q_UINT16 *d = reinterpret_cast<Q_UINT16 *>(it.rawData());
00134 d[0] = (Q_UINT16)( tiffstream->nextValue() * coeff );
00135 d[3] = Q_UINT16_MAX;
00136 for(int k = 0; k < nbExtraSamples(); k++)
00137 {
00138 if(k == alphaPos())
00139 d[3] = (Q_UINT32) ( tiffstream->nextValue() * coeff );
00140 else
00141 tiffstream->nextValue();
00142 }
00143 ++it;
00144 }
00145 it.nextRow();
00146 }
00147 m_bufferCb[ buffPos ] = (Q_UINT16)(tiffstream->nextValue() * coeff);
00148 m_bufferCr[ buffPos ] = (Q_UINT16)(tiffstream->nextValue() * coeff);
00149 buffPos ++;
00150 }
00151 return m_vsub;
00152 }
00153
00154 void KisTIFFYCbCrReaderTarget16Bit::finalize()
00155 {
00156 KisHLineIterator it = paintDevice() -> createHLineIterator(0, 0, paintDevice()->image()->width(), true);
00157 for(int y = 0; y < paintDevice()->image()->height(); y++)
00158 {
00159 int x = 0;
00160 while(!it.isDone())
00161 {
00162 Q_UINT16 *d = reinterpret_cast<Q_UINT16 *>(it.rawData());
00163 int index = x/m_hsub + y/m_vsub * m_bufferWidth;
00164 d[1] = m_bufferCb[ index ];
00165 d[2] = m_bufferCr[ index ];
00166 ++it; ++x;
00167 }
00168 it.nextRow();
00169 }
00170 }