|
|
@ -301,6 +301,11 @@ TiffEncoder::~TiffEncoder() |
|
|
|
{ |
|
|
|
{ |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool TiffEncoder::isFormatSupported( int depth ) const |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return depth == CV_8U || depth == CV_16U; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
ImageEncoder TiffEncoder::newEncoder() const |
|
|
|
ImageEncoder TiffEncoder::newEncoder() const |
|
|
|
{ |
|
|
|
{ |
|
|
|
return new TiffEncoder; |
|
|
|
return new TiffEncoder; |
|
|
@ -321,7 +326,13 @@ bool TiffEncoder::write( const Mat& img, const vector<int>& ) |
|
|
|
{ |
|
|
|
{ |
|
|
|
int channels = img.channels(); |
|
|
|
int channels = img.channels(); |
|
|
|
int width = img.cols, height = img.rows; |
|
|
|
int width = img.cols, height = img.rows; |
|
|
|
int fileStep = width*channels; |
|
|
|
int depth = img.depth(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (depth != CV_8U && depth != CV_16U) |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int bytesPerChannel = depth == CV_8U ? 1 : 2; |
|
|
|
|
|
|
|
int fileStep = width * channels * bytesPerChannel; |
|
|
|
WLByteStream strm; |
|
|
|
WLByteStream strm; |
|
|
|
|
|
|
|
|
|
|
|
if( m_buf ) |
|
|
|
if( m_buf ) |
|
|
@ -356,7 +367,7 @@ bool TiffEncoder::write( const Mat& img, const vector<int>& ) |
|
|
|
uchar* buffer = _buffer; |
|
|
|
uchar* buffer = _buffer; |
|
|
|
int stripOffsetsOffset = 0; |
|
|
|
int stripOffsetsOffset = 0; |
|
|
|
int stripCountsOffset = 0; |
|
|
|
int stripCountsOffset = 0; |
|
|
|
int bitsPerSample = 8; // TODO support 16 bit
|
|
|
|
int bitsPerSample = 8 * bytesPerChannel; |
|
|
|
int y = 0; |
|
|
|
int y = 0; |
|
|
|
|
|
|
|
|
|
|
|
strm.putBytes( fmtSignTiffII, 4 ); |
|
|
|
strm.putBytes( fmtSignTiffII, 4 ); |
|
|
@ -376,9 +387,15 @@ bool TiffEncoder::write( const Mat& img, const vector<int>& ) |
|
|
|
for( ; y < limit; y++ ) |
|
|
|
for( ; y < limit; y++ ) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if( channels == 3 ) |
|
|
|
if( channels == 3 ) |
|
|
|
icvCvt_BGR2RGB_8u_C3R( img.data + img.step*y, 0, buffer, 0, cvSize(width,1) ); |
|
|
|
if (depth == CV_8U) |
|
|
|
|
|
|
|
icvCvt_BGR2RGB_8u_C3R( img.data + img.step*y, 0, buffer, 0, cvSize(width,1) ); |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
icvCvt_BGR2RGB_16u_C3R( (const ushort*)(img.data + img.step*y), 0, (ushort*)buffer, 0, cvSize(width,1) ); |
|
|
|
else if( channels == 4 ) |
|
|
|
else if( channels == 4 ) |
|
|
|
icvCvt_BGRA2RGBA_8u_C4R( img.data + img.step*y, 0, buffer, 0, cvSize(width,1) ); |
|
|
|
if (depth == CV_8U) |
|
|
|
|
|
|
|
icvCvt_BGRA2RGBA_8u_C4R( img.data + img.step*y, 0, buffer, 0, cvSize(width,1) ); |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
icvCvt_BGRA2RGBA_16u_C4R( (const ushort*)(img.data + img.step*y), 0, (ushort*)buffer, 0, cvSize(width,1) ); |
|
|
|
|
|
|
|
|
|
|
|
strm.putBytes( channels > 1 ? buffer : img.data + img.step*y, fileStep ); |
|
|
|
strm.putBytes( channels > 1 ? buffer : img.data + img.step*y, fileStep ); |
|
|
|
} |
|
|
|
} |
|
|
@ -416,12 +433,13 @@ bool TiffEncoder::write( const Mat& img, const vector<int>& ) |
|
|
|
|
|
|
|
|
|
|
|
if( channels > 1 ) |
|
|
|
if( channels > 1 ) |
|
|
|
{ |
|
|
|
{ |
|
|
|
bitsPerSample = strm.getPos(); |
|
|
|
int bitsPerSamplePos = strm.getPos(); |
|
|
|
strm.putWord(8); |
|
|
|
strm.putWord(bitsPerSample); |
|
|
|
strm.putWord(8); |
|
|
|
strm.putWord(bitsPerSample); |
|
|
|
strm.putWord(8); |
|
|
|
strm.putWord(bitsPerSample); |
|
|
|
if( channels == 4 ) |
|
|
|
if( channels == 4 ) |
|
|
|
strm.putWord(8); |
|
|
|
strm.putWord(bitsPerSample); |
|
|
|
|
|
|
|
bitsPerSample = bitsPerSamplePos; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
directoryOffset = strm.getPos(); |
|
|
|
directoryOffset = strm.getPos(); |
|
|
|