bool TiffDecoder::readData( Mat& img )
{
- if(m_hdr && img.type() == CV_32FC3)
- {
- return readData_32FC3(img);
- }
- if(img.type() == CV_32FC1)
- int type_ = img.type();
- int depth = CV_MAT_DEPTH(type_);
++ int type = img.type();
++ int depth = CV_MAT_DEPTH(type);
+
+ CV_Assert(!m_tif.empty());
+ TIFF* tif = (TIFF*)m_tif.get();
+
+ uint16 photometric = (uint16)-1;
+ CV_TIFF_CHECK_CALL(TIFFGetField(tif, TIFFTAG_PHOTOMETRIC, &photometric));
+
+ if (m_hdr && depth >= CV_32F)
{
- return readData_32FC1(img);
+ CV_TIFF_CHECK_CALL(TIFFSetField(tif, TIFFTAG_SGILOGDATAFMT, SGILOGDATAFMT_FLOAT));
}
- bool result = false;
+
bool color = img.channels() > 1;
- if( img.depth() != CV_8U && img.depth() != CV_16U && img.depth() != CV_32F && img.depth() != CV_64F )
- return false;
- CV_CheckType(type_, depth == CV_8U || depth == CV_16U || depth == CV_32F || depth == CV_64F, "");
++ CV_CheckType(type, depth == CV_8U || depth == CV_16U || depth == CV_32F || depth == CV_64F, "");
- if( m_tif && m_width && m_height )
+ if (m_width && m_height)
{
- TIFF* tif = (TIFF*)m_tif;
- uint32 tile_width0 = m_width, tile_height0 = 0;
- int x, y, i;
- int is_tiled = TIFFIsTiled(tif);
- uint16 photometric;
- TIFFGetField( tif, TIFFTAG_PHOTOMETRIC, &photometric );
- uint16 bpp = 8, ncn = photometric > 1 ? 3 : 1;
- TIFFGetField( tif, TIFFTAG_BITSPERSAMPLE, &bpp );
- TIFFGetField( tif, TIFFTAG_SAMPLESPERPIXEL, &ncn );
+ int is_tiled = TIFFIsTiled(tif) != 0;
+ bool isGrayScale = photometric == PHOTOMETRIC_MINISWHITE || photometric == PHOTOMETRIC_MINISBLACK;
+ uint16 bpp = 8, ncn = isGrayScale ? 1 : 3;
+ CV_TIFF_CHECK_CALL(TIFFGetField(tif, TIFFTAG_BITSPERSAMPLE, &bpp));
+ CV_TIFF_CHECK_CALL_DEBUG(TIFFGetField(tif, TIFFTAG_SAMPLESPERPIXEL, &ncn));
uint16 img_orientation = ORIENTATION_TOPLEFT;
- TIFFGetField( tif, TIFFTAG_ORIENTATION, &img_orientation);
+ CV_TIFF_CHECK_CALL_DEBUG(TIFFGetField(tif, TIFFTAG_ORIENTATION, &img_orientation));
bool vert_flip = (img_orientation == ORIENTATION_BOTRIGHT) || (img_orientation == ORIENTATION_RIGHTBOT) ||
(img_orientation == ORIENTATION_BOTLEFT) || (img_orientation == ORIENTATION_LEFTBOT);
const int bitsPerByte = 8;
return data;
}
- }
+ } // namespace
-
-using namespace cv;
-
-CV_IMPL void
-cvConvertImage( const CvArr* srcarr, CvArr* dstarr, int flags )
-{
- CvMat* temp = 0;
-
- CV_FUNCNAME( "cvConvertImage" );
-
- __BEGIN__;
-
- CvMat srcstub, *src;
- CvMat dststub, *dst;
- int src_cn, dst_cn, swap_rb = flags & CV_CVTIMG_SWAP_RB;
-
- CV_CALL( src = cvGetMat( srcarr, &srcstub ));
- CV_CALL( dst = cvGetMat( dstarr, &dststub ));
-
- src_cn = CV_MAT_CN( src->type );
- dst_cn = CV_MAT_CN( dst->type );
-
- if( src_cn != 1 && src_cn != 3 && src_cn != 4 )
- CV_ERROR( CV_BadNumChannels, "Source image must have 1, 3 or 4 channels" );
-
- if( CV_MAT_DEPTH( dst->type ) != CV_8U )
- CV_ERROR( CV_BadDepth, "Destination image must be 8u" );
-
- if( CV_MAT_CN(dst->type) != 1 && CV_MAT_CN(dst->type) != 3 )
- CV_ERROR( CV_BadNumChannels, "Destination image must have 1 or 3 channels" );
-
- if( !CV_ARE_DEPTHS_EQ( src, dst ))
- {
- int src_depth = CV_MAT_DEPTH(src->type);
- double scale = src_depth <= CV_8S ? 1 : src_depth <= CV_32S ? 1./256 : 255;
- double shift = src_depth == CV_8S || src_depth == CV_16S ? 128 : 0;
-
- if( !CV_ARE_CNS_EQ( src, dst ))
- {
- temp = cvCreateMat( src->height, src->width,
- (src->type & CV_MAT_CN_MASK)|(dst->type & CV_MAT_DEPTH_MASK));
- cvConvertScale( src, temp, scale, shift );
- src = temp;
- }
- else
- {
- cvConvertScale( src, dst, scale, shift );
- src = dst;
- }
- }
-
- if( src_cn != dst_cn || (src_cn == 3 && swap_rb) )
- {
- uchar *s = src->data.ptr, *d = dst->data.ptr;
- int s_step = src->step, d_step = dst->step;
- int code = src_cn*10 + dst_cn;
- Size size(src->cols, src->rows);
-
- if( CV_IS_MAT_CONT(src->type & dst->type) )
- {
- size.width *= size.height;
- size.height = 1;
- s_step = d_step = /*CV_STUB_STEP*/ (1 << 30);
- }
-
- switch( code )
- {
- case 13:
- icvCvt_Gray2BGR_8u_C1C3R( s, s_step, d, d_step, size );
- break;
- case 31:
- icvCvt_BGR2Gray_8u_C3C1R( s, s_step, d, d_step, size, swap_rb );
- break;
- case 33:
- CV_Assert(swap_rb);
- icvCvt_RGB2BGR_8u_C3R( s, s_step, d, d_step, size );
- break;
- case 41:
- icvCvt_BGRA2Gray_8u_C4C1R( s, s_step, d, d_step, size, swap_rb );
- break;
- case 43:
- icvCvt_BGRA2BGR_8u_C4C3R( s, s_step, d, d_step, size, swap_rb );
- break;
- default:
- CV_ERROR( CV_StsUnsupportedFormat, "Unsupported combination of input/output formats" );
- }
- src = dst;
- }
-
- if( flags & CV_CVTIMG_FLIP )
- {
- CV_CALL( cvFlip( src, dst, 0 ));
- }
- else if( src != dst )
- {
- CV_CALL( cvCopy( src, dst ));
- }
-
- __END__;
-
- cvReleaseMat( &temp );
-}