Commit 68bb317c authored by Andrey Kamaev's avatar Andrey Kamaev Committed by OpenCV Buildbot

Merge pull request #462 from kobigurk:master

parents d620ef0d 18a5b8df
...@@ -101,6 +101,11 @@ bool TiffDecoder::checkSignature( const std::string& signature ) const ...@@ -101,6 +101,11 @@ bool TiffDecoder::checkSignature( const std::string& signature ) const
memcmp(signature.c_str(), fmtSignTiffMM, 4) == 0); memcmp(signature.c_str(), fmtSignTiffMM, 4) == 0);
} }
int TiffDecoder::normalizeChannelsNumber(int channels) const
{
return channels > 4 ? 4 : channels;
}
ImageDecoder TiffDecoder::newDecoder() const ImageDecoder TiffDecoder::newDecoder() const
{ {
return new TiffDecoder; return new TiffDecoder;
...@@ -133,10 +138,11 @@ bool TiffDecoder::readHeader() ...@@ -133,10 +138,11 @@ bool TiffDecoder::readHeader()
(ncn != 1 && ncn != 3 && ncn != 4))) (ncn != 1 && ncn != 3 && ncn != 4)))
bpp = 8; bpp = 8;
int wanted_channels = normalizeChannelsNumber(ncn);
switch(bpp) switch(bpp)
{ {
case 8: case 8:
m_type = CV_MAKETYPE(CV_8U, photometric > 1 ? 3 : 1); m_type = CV_MAKETYPE(CV_8U, photometric > 1 ? wanted_channels : 1);
break; break;
case 16: case 16:
m_type = CV_MAKETYPE(CV_16U, photometric > 1 ? 3 : 1); m_type = CV_MAKETYPE(CV_16U, photometric > 1 ? 3 : 1);
...@@ -185,6 +191,7 @@ bool TiffDecoder::readData( Mat& img ) ...@@ -185,6 +191,7 @@ bool TiffDecoder::readData( Mat& img )
TIFFGetField( tif, TIFFTAG_SAMPLESPERPIXEL, &ncn ); TIFFGetField( tif, TIFFTAG_SAMPLESPERPIXEL, &ncn );
const int bitsPerByte = 8; const int bitsPerByte = 8;
int dst_bpp = (int)(img.elemSize1() * bitsPerByte); int dst_bpp = (int)(img.elemSize1() * bitsPerByte);
int wanted_channels = normalizeChannelsNumber(img.channels());
if(dst_bpp == 8) if(dst_bpp == 8)
{ {
...@@ -248,9 +255,20 @@ bool TiffDecoder::readData( Mat& img ) ...@@ -248,9 +255,20 @@ bool TiffDecoder::readData( Mat& img )
for( i = 0; i < tile_height; i++ ) for( i = 0; i < tile_height; i++ )
if( color ) if( color )
icvCvt_BGRA2BGR_8u_C4C3R( buffer + i*tile_width*4, 0, {
if (wanted_channels == 4)
{
icvCvt_BGRA2RGBA_8u_C4R( buffer + i*tile_width*4, 0,
data + x*4 + img.step*(tile_height - i - 1), 0,
cvSize(tile_width,1) );
}
else
{
icvCvt_BGRA2BGR_8u_C4C3R( buffer + i*tile_width*4, 0,
data + x*3 + img.step*(tile_height - i - 1), 0, data + x*3 + img.step*(tile_height - i - 1), 0,
cvSize(tile_width,1), 2 ); cvSize(tile_width,1), 2 );
}
}
else else
icvCvt_BGRA2Gray_8u_C4C1R( buffer + i*tile_width*4, 0, icvCvt_BGRA2Gray_8u_C4C1R( buffer + i*tile_width*4, 0,
data + x + img.step*(tile_height - i - 1), 0, data + x + img.step*(tile_height - i - 1), 0,
......
...@@ -107,6 +107,7 @@ public: ...@@ -107,6 +107,7 @@ public:
protected: protected:
void* m_tif; void* m_tif;
int normalizeChannelsNumber(int channels) const;
}; };
#endif #endif
......
...@@ -99,8 +99,11 @@ public: ...@@ -99,8 +99,11 @@ public:
{ {
if(ext_from_int(ext).empty()) if(ext_from_int(ext).empty())
continue; continue;
for (int num_channels = 1; num_channels <= 3; num_channels+=2) for (int num_channels = 1; num_channels <= 4; num_channels++)
{ {
if (num_channels == 2) continue;
if (num_channels == 4 && ext!=3 /*TIFF*/) continue;
ts->printf(ts->LOG, "image type depth:%d channels:%d ext: %s\n", CV_8U, num_channels, ext_from_int(ext).c_str()); ts->printf(ts->LOG, "image type depth:%d channels:%d ext: %s\n", CV_8U, num_channels, ext_from_int(ext).c_str());
Mat img(img_r * k, img_c * k, CV_MAKETYPE(CV_8U, num_channels), Scalar::all(0)); Mat img(img_r * k, img_c * k, CV_MAKETYPE(CV_8U, num_channels), Scalar::all(0));
circle(img, Point2i((img_c * k) / 2, (img_r * k) / 2), std::min((img_r * k), (img_c * k)) / 4 , Scalar::all(255)); circle(img, Point2i((img_c * k) / 2, (img_r * k) / 2), std::min((img_r * k), (img_c * k)) / 4 , Scalar::all(255));
...@@ -116,6 +119,7 @@ public: ...@@ -116,6 +119,7 @@ public:
CV_Assert(img.size() == img_test.size()); CV_Assert(img.size() == img_test.size());
CV_Assert(img.type() == img_test.type()); CV_Assert(img.type() == img_test.type());
CV_Assert(num_channels == img_test.channels());
double n = norm(img, img_test); double n = norm(img, img_test);
if ( n > 1.0) if ( n > 1.0)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment