Commit ba5ddd64 authored by Alexander Alekhin's avatar Alexander Alekhin Committed by Alexander Alekhin

imgcodecs(tiff): sanitize tiff decoder

- more checks
- drop separate branches for 32FC1/32FC3(read) handling
- added for 32F/64F non-compressed
- added tests for 32FC3 (RAW + hdr SGILOG compression)
- added test 64FC1
- dump tiff errors on stderr
parent d8b8c3b1
This diff is collapsed.
...@@ -106,10 +106,8 @@ public: ...@@ -106,10 +106,8 @@ public:
ImageDecoder newDecoder() const CV_OVERRIDE; ImageDecoder newDecoder() const CV_OVERRIDE;
protected: protected:
void* m_tif; cv::Ptr<void> m_tif;
int normalizeChannelsNumber(int channels) const; int normalizeChannelsNumber(int channels) const;
bool readData_32FC3(Mat& img);
bool readData_32FC1(Mat& img);
bool m_hdr; bool m_hdr;
size_t m_buf_pos; size_t m_buf_pos;
...@@ -139,8 +137,7 @@ protected: ...@@ -139,8 +137,7 @@ protected:
int count, int value ); int count, int value );
bool writeLibTiff( const std::vector<Mat>& img_vec, const std::vector<int>& params ); bool writeLibTiff( const std::vector<Mat>& img_vec, const std::vector<int>& params );
bool write_32FC3( const Mat& img ); bool write_32FC3_SGILOG(const Mat& img, void* tif);
bool write_32FC1( const Mat& img );
private: private:
TiffEncoder(const TiffEncoder &); // copy disabled TiffEncoder(const TiffEncoder &); // copy disabled
......
...@@ -42,6 +42,8 @@ ...@@ -42,6 +42,8 @@
#include "precomp.hpp" #include "precomp.hpp"
#include "utils.hpp" #include "utils.hpp"
namespace cv {
int validateToInt(size_t sz) int validateToInt(size_t sz)
{ {
int valueInt = (int)sz; int valueInt = (int)sz;
...@@ -56,7 +58,7 @@ int validateToInt(size_t sz) ...@@ -56,7 +58,7 @@ int validateToInt(size_t sz)
void icvCvt_BGR2Gray_8u_C3C1R( const uchar* rgb, int rgb_step, void icvCvt_BGR2Gray_8u_C3C1R( const uchar* rgb, int rgb_step,
uchar* gray, int gray_step, uchar* gray, int gray_step,
CvSize size, int _swap_rb ) Size size, int _swap_rb )
{ {
int i; int i;
int swap_rb = _swap_rb ? 2 : 0; int swap_rb = _swap_rb ? 2 : 0;
...@@ -75,7 +77,7 @@ void icvCvt_BGR2Gray_8u_C3C1R( const uchar* rgb, int rgb_step, ...@@ -75,7 +77,7 @@ void icvCvt_BGR2Gray_8u_C3C1R( const uchar* rgb, int rgb_step,
void icvCvt_BGRA2Gray_16u_CnC1R( const ushort* rgb, int rgb_step, void icvCvt_BGRA2Gray_16u_CnC1R( const ushort* rgb, int rgb_step,
ushort* gray, int gray_step, ushort* gray, int gray_step,
CvSize size, int ncn, int _swap_rb ) Size size, int ncn, int _swap_rb )
{ {
int i; int i;
int swap_rb = _swap_rb ? 2 : 0; int swap_rb = _swap_rb ? 2 : 0;
...@@ -94,7 +96,7 @@ void icvCvt_BGRA2Gray_16u_CnC1R( const ushort* rgb, int rgb_step, ...@@ -94,7 +96,7 @@ void icvCvt_BGRA2Gray_16u_CnC1R( const ushort* rgb, int rgb_step,
void icvCvt_BGRA2Gray_8u_C4C1R( const uchar* rgba, int rgba_step, void icvCvt_BGRA2Gray_8u_C4C1R( const uchar* rgba, int rgba_step,
uchar* gray, int gray_step, uchar* gray, int gray_step,
CvSize size, int _swap_rb ) Size size, int _swap_rb )
{ {
int i; int i;
int swap_rb = _swap_rb ? 2 : 0; int swap_rb = _swap_rb ? 2 : 0;
...@@ -112,7 +114,7 @@ void icvCvt_BGRA2Gray_8u_C4C1R( const uchar* rgba, int rgba_step, ...@@ -112,7 +114,7 @@ void icvCvt_BGRA2Gray_8u_C4C1R( const uchar* rgba, int rgba_step,
void icvCvt_Gray2BGR_8u_C1C3R( const uchar* gray, int gray_step, void icvCvt_Gray2BGR_8u_C1C3R( const uchar* gray, int gray_step,
uchar* bgr, int bgr_step, CvSize size ) uchar* bgr, int bgr_step, Size size )
{ {
int i; int i;
for( ; size.height--; gray += gray_step ) for( ; size.height--; gray += gray_step )
...@@ -127,7 +129,7 @@ void icvCvt_Gray2BGR_8u_C1C3R( const uchar* gray, int gray_step, ...@@ -127,7 +129,7 @@ void icvCvt_Gray2BGR_8u_C1C3R( const uchar* gray, int gray_step,
void icvCvt_Gray2BGR_16u_C1C3R( const ushort* gray, int gray_step, void icvCvt_Gray2BGR_16u_C1C3R( const ushort* gray, int gray_step,
ushort* bgr, int bgr_step, CvSize size ) ushort* bgr, int bgr_step, Size size )
{ {
int i; int i;
for( ; size.height--; gray += gray_step/sizeof(gray[0]) ) for( ; size.height--; gray += gray_step/sizeof(gray[0]) )
...@@ -143,7 +145,7 @@ void icvCvt_Gray2BGR_16u_C1C3R( const ushort* gray, int gray_step, ...@@ -143,7 +145,7 @@ void icvCvt_Gray2BGR_16u_C1C3R( const ushort* gray, int gray_step,
void icvCvt_BGRA2BGR_8u_C4C3R( const uchar* bgra, int bgra_step, void icvCvt_BGRA2BGR_8u_C4C3R( const uchar* bgra, int bgra_step,
uchar* bgr, int bgr_step, uchar* bgr, int bgr_step,
CvSize size, int _swap_rb ) Size size, int _swap_rb )
{ {
int i; int i;
int swap_rb = _swap_rb ? 2 : 0; int swap_rb = _swap_rb ? 2 : 0;
...@@ -163,7 +165,7 @@ void icvCvt_BGRA2BGR_8u_C4C3R( const uchar* bgra, int bgra_step, ...@@ -163,7 +165,7 @@ void icvCvt_BGRA2BGR_8u_C4C3R( const uchar* bgra, int bgra_step,
void icvCvt_BGRA2BGR_16u_C4C3R( const ushort* bgra, int bgra_step, void icvCvt_BGRA2BGR_16u_C4C3R( const ushort* bgra, int bgra_step,
ushort* bgr, int bgr_step, ushort* bgr, int bgr_step,
CvSize size, int _swap_rb ) Size size, int _swap_rb )
{ {
int i; int i;
int swap_rb = _swap_rb ? 2 : 0; int swap_rb = _swap_rb ? 2 : 0;
...@@ -182,7 +184,7 @@ void icvCvt_BGRA2BGR_16u_C4C3R( const ushort* bgra, int bgra_step, ...@@ -182,7 +184,7 @@ void icvCvt_BGRA2BGR_16u_C4C3R( const ushort* bgra, int bgra_step,
void icvCvt_BGRA2RGBA_8u_C4R( const uchar* bgra, int bgra_step, void icvCvt_BGRA2RGBA_8u_C4R( const uchar* bgra, int bgra_step,
uchar* rgba, int rgba_step, CvSize size ) uchar* rgba, int rgba_step, Size size )
{ {
int i; int i;
for( ; size.height--; ) for( ; size.height--; )
...@@ -200,7 +202,7 @@ void icvCvt_BGRA2RGBA_8u_C4R( const uchar* bgra, int bgra_step, ...@@ -200,7 +202,7 @@ void icvCvt_BGRA2RGBA_8u_C4R( const uchar* bgra, int bgra_step,
} }
void icvCvt_BGRA2RGBA_16u_C4R( const ushort* bgra, int bgra_step, void icvCvt_BGRA2RGBA_16u_C4R( const ushort* bgra, int bgra_step,
ushort* rgba, int rgba_step, CvSize size ) ushort* rgba, int rgba_step, Size size )
{ {
int i; int i;
for( ; size.height--; ) for( ; size.height--; )
...@@ -220,7 +222,7 @@ void icvCvt_BGRA2RGBA_16u_C4R( const ushort* bgra, int bgra_step, ...@@ -220,7 +222,7 @@ void icvCvt_BGRA2RGBA_16u_C4R( const ushort* bgra, int bgra_step,
void icvCvt_BGR2RGB_8u_C3R( const uchar* bgr, int bgr_step, void icvCvt_BGR2RGB_8u_C3R( const uchar* bgr, int bgr_step,
uchar* rgb, int rgb_step, CvSize size ) uchar* rgb, int rgb_step, Size size )
{ {
int i; int i;
for( ; size.height--; ) for( ; size.height--; )
...@@ -237,7 +239,7 @@ void icvCvt_BGR2RGB_8u_C3R( const uchar* bgr, int bgr_step, ...@@ -237,7 +239,7 @@ void icvCvt_BGR2RGB_8u_C3R( const uchar* bgr, int bgr_step,
void icvCvt_BGR2RGB_16u_C3R( const ushort* bgr, int bgr_step, void icvCvt_BGR2RGB_16u_C3R( const ushort* bgr, int bgr_step,
ushort* rgb, int rgb_step, CvSize size ) ushort* rgb, int rgb_step, Size size )
{ {
int i; int i;
for( ; size.height--; ) for( ; size.height--; )
...@@ -256,7 +258,7 @@ void icvCvt_BGR2RGB_16u_C3R( const ushort* bgr, int bgr_step, ...@@ -256,7 +258,7 @@ void icvCvt_BGR2RGB_16u_C3R( const ushort* bgr, int bgr_step,
typedef unsigned short ushort; typedef unsigned short ushort;
void icvCvt_BGR5552Gray_8u_C2C1R( const uchar* bgr555, int bgr555_step, void icvCvt_BGR5552Gray_8u_C2C1R( const uchar* bgr555, int bgr555_step,
uchar* gray, int gray_step, CvSize size ) uchar* gray, int gray_step, Size size )
{ {
int i; int i;
for( ; size.height--; gray += gray_step, bgr555 += bgr555_step ) for( ; size.height--; gray += gray_step, bgr555 += bgr555_step )
...@@ -273,7 +275,7 @@ void icvCvt_BGR5552Gray_8u_C2C1R( const uchar* bgr555, int bgr555_step, ...@@ -273,7 +275,7 @@ void icvCvt_BGR5552Gray_8u_C2C1R( const uchar* bgr555, int bgr555_step,
void icvCvt_BGR5652Gray_8u_C2C1R( const uchar* bgr565, int bgr565_step, void icvCvt_BGR5652Gray_8u_C2C1R( const uchar* bgr565, int bgr565_step,
uchar* gray, int gray_step, CvSize size ) uchar* gray, int gray_step, Size size )
{ {
int i; int i;
for( ; size.height--; gray += gray_step, bgr565 += bgr565_step ) for( ; size.height--; gray += gray_step, bgr565 += bgr565_step )
...@@ -290,7 +292,7 @@ void icvCvt_BGR5652Gray_8u_C2C1R( const uchar* bgr565, int bgr565_step, ...@@ -290,7 +292,7 @@ void icvCvt_BGR5652Gray_8u_C2C1R( const uchar* bgr565, int bgr565_step,
void icvCvt_BGR5552BGR_8u_C2C3R( const uchar* bgr555, int bgr555_step, void icvCvt_BGR5552BGR_8u_C2C3R( const uchar* bgr555, int bgr555_step,
uchar* bgr, int bgr_step, CvSize size ) uchar* bgr, int bgr_step, Size size )
{ {
int i; int i;
for( ; size.height--; bgr555 += bgr555_step ) for( ; size.height--; bgr555 += bgr555_step )
...@@ -308,7 +310,7 @@ void icvCvt_BGR5552BGR_8u_C2C3R( const uchar* bgr555, int bgr555_step, ...@@ -308,7 +310,7 @@ void icvCvt_BGR5552BGR_8u_C2C3R( const uchar* bgr555, int bgr555_step,
void icvCvt_BGR5652BGR_8u_C2C3R( const uchar* bgr565, int bgr565_step, void icvCvt_BGR5652BGR_8u_C2C3R( const uchar* bgr565, int bgr565_step,
uchar* bgr, int bgr_step, CvSize size ) uchar* bgr, int bgr_step, Size size )
{ {
int i; int i;
for( ; size.height--; bgr565 += bgr565_step ) for( ; size.height--; bgr565 += bgr565_step )
...@@ -326,7 +328,7 @@ void icvCvt_BGR5652BGR_8u_C2C3R( const uchar* bgr565, int bgr565_step, ...@@ -326,7 +328,7 @@ void icvCvt_BGR5652BGR_8u_C2C3R( const uchar* bgr565, int bgr565_step,
void icvCvt_CMYK2BGR_8u_C4C3R( const uchar* cmyk, int cmyk_step, void icvCvt_CMYK2BGR_8u_C4C3R( const uchar* cmyk, int cmyk_step,
uchar* bgr, int bgr_step, CvSize size ) uchar* bgr, int bgr_step, Size size )
{ {
int i; int i;
for( ; size.height--; ) for( ; size.height--; )
...@@ -346,7 +348,7 @@ void icvCvt_CMYK2BGR_8u_C4C3R( const uchar* cmyk, int cmyk_step, ...@@ -346,7 +348,7 @@ void icvCvt_CMYK2BGR_8u_C4C3R( const uchar* cmyk, int cmyk_step,
void icvCvt_CMYK2Gray_8u_C4C1R( const uchar* cmyk, int cmyk_step, void icvCvt_CMYK2Gray_8u_C4C1R( const uchar* cmyk, int cmyk_step,
uchar* gray, int gray_step, CvSize size ) uchar* gray, int gray_step, Size size )
{ {
int i; int i;
for( ; size.height--; ) for( ; size.height--; )
...@@ -371,7 +373,7 @@ void CvtPaletteToGray( const PaletteEntry* palette, uchar* grayPalette, int entr ...@@ -371,7 +373,7 @@ void CvtPaletteToGray( const PaletteEntry* palette, uchar* grayPalette, int entr
int i; int i;
for( i = 0; i < entries; i++ ) for( i = 0; i < entries; i++ )
{ {
icvCvt_BGR2Gray_8u_C3C1R( (uchar*)(palette + i), 0, grayPalette + i, 0, cvSize(1,1) ); icvCvt_BGR2Gray_8u_C3C1R( (uchar*)(palette + i), 0, grayPalette + i, 0, Size(1,1) );
} }
} }
...@@ -598,6 +600,9 @@ uchar* FillGrayRow1( uchar* data, uchar* indices, int len, uchar* palette ) ...@@ -598,6 +600,9 @@ uchar* FillGrayRow1( uchar* data, uchar* indices, int len, uchar* palette )
return data; return data;
} }
} // namespace
using namespace cv;
CV_IMPL void CV_IMPL void
cvConvertImage( const CvArr* srcarr, CvArr* dstarr, int flags ) cvConvertImage( const CvArr* srcarr, CvArr* dstarr, int flags )
...@@ -652,7 +657,7 @@ cvConvertImage( const CvArr* srcarr, CvArr* dstarr, int flags ) ...@@ -652,7 +657,7 @@ cvConvertImage( const CvArr* srcarr, CvArr* dstarr, int flags )
uchar *s = src->data.ptr, *d = dst->data.ptr; uchar *s = src->data.ptr, *d = dst->data.ptr;
int s_step = src->step, d_step = dst->step; int s_step = src->step, d_step = dst->step;
int code = src_cn*10 + dst_cn; int code = src_cn*10 + dst_cn;
CvSize size = {src->cols, src->rows}; Size size(src->cols, src->rows);
if( CV_IS_MAT_CONT(src->type & dst->type) ) if( CV_IS_MAT_CONT(src->type & dst->type) )
{ {
......
...@@ -42,6 +42,8 @@ ...@@ -42,6 +42,8 @@
#ifndef _UTILS_H_ #ifndef _UTILS_H_
#define _UTILS_H_ #define _UTILS_H_
namespace cv {
int validateToInt(size_t step); int validateToInt(size_t step);
template <typename _Tp> static inline template <typename _Tp> static inline
...@@ -68,53 +70,53 @@ struct PaletteEntry ...@@ -68,53 +70,53 @@ struct PaletteEntry
void icvCvt_BGR2Gray_8u_C3C1R( const uchar* bgr, int bgr_step, void icvCvt_BGR2Gray_8u_C3C1R( const uchar* bgr, int bgr_step,
uchar* gray, int gray_step, uchar* gray, int gray_step,
CvSize size, int swap_rb=0 ); Size size, int swap_rb=0 );
void icvCvt_BGRA2Gray_8u_C4C1R( const uchar* bgra, int bgra_step, void icvCvt_BGRA2Gray_8u_C4C1R( const uchar* bgra, int bgra_step,
uchar* gray, int gray_step, uchar* gray, int gray_step,
CvSize size, int swap_rb=0 ); Size size, int swap_rb=0 );
void icvCvt_BGRA2Gray_16u_CnC1R( const ushort* bgra, int bgra_step, void icvCvt_BGRA2Gray_16u_CnC1R( const ushort* bgra, int bgra_step,
ushort* gray, int gray_step, ushort* gray, int gray_step,
CvSize size, int ncn, int swap_rb=0 ); Size size, int ncn, int swap_rb=0 );
void icvCvt_Gray2BGR_8u_C1C3R( const uchar* gray, int gray_step, void icvCvt_Gray2BGR_8u_C1C3R( const uchar* gray, int gray_step,
uchar* bgr, int bgr_step, CvSize size ); uchar* bgr, int bgr_step, Size size );
void icvCvt_Gray2BGR_16u_C1C3R( const ushort* gray, int gray_step, void icvCvt_Gray2BGR_16u_C1C3R( const ushort* gray, int gray_step,
ushort* bgr, int bgr_step, CvSize size ); ushort* bgr, int bgr_step, Size size );
void icvCvt_BGRA2BGR_8u_C4C3R( const uchar* bgra, int bgra_step, void icvCvt_BGRA2BGR_8u_C4C3R( const uchar* bgra, int bgra_step,
uchar* bgr, int bgr_step, uchar* bgr, int bgr_step,
CvSize size, int swap_rb=0 ); Size size, int swap_rb=0 );
void icvCvt_BGRA2BGR_16u_C4C3R( const ushort* bgra, int bgra_step, void icvCvt_BGRA2BGR_16u_C4C3R( const ushort* bgra, int bgra_step,
ushort* bgr, int bgr_step, ushort* bgr, int bgr_step,
CvSize size, int _swap_rb ); Size size, int _swap_rb );
void icvCvt_BGR2RGB_8u_C3R( const uchar* bgr, int bgr_step, void icvCvt_BGR2RGB_8u_C3R( const uchar* bgr, int bgr_step,
uchar* rgb, int rgb_step, CvSize size ); uchar* rgb, int rgb_step, Size size );
#define icvCvt_RGB2BGR_8u_C3R icvCvt_BGR2RGB_8u_C3R #define icvCvt_RGB2BGR_8u_C3R icvCvt_BGR2RGB_8u_C3R
void icvCvt_BGR2RGB_16u_C3R( const ushort* bgr, int bgr_step, void icvCvt_BGR2RGB_16u_C3R( const ushort* bgr, int bgr_step,
ushort* rgb, int rgb_step, CvSize size ); ushort* rgb, int rgb_step, Size size );
#define icvCvt_RGB2BGR_16u_C3R icvCvt_BGR2RGB_16u_C3R #define icvCvt_RGB2BGR_16u_C3R icvCvt_BGR2RGB_16u_C3R
void icvCvt_BGRA2RGBA_8u_C4R( const uchar* bgra, int bgra_step, void icvCvt_BGRA2RGBA_8u_C4R( const uchar* bgra, int bgra_step,
uchar* rgba, int rgba_step, CvSize size ); uchar* rgba, int rgba_step, Size size );
#define icvCvt_RGBA2BGRA_8u_C4R icvCvt_BGRA2RGBA_8u_C4R #define icvCvt_RGBA2BGRA_8u_C4R icvCvt_BGRA2RGBA_8u_C4R
void icvCvt_BGRA2RGBA_16u_C4R( const ushort* bgra, int bgra_step, void icvCvt_BGRA2RGBA_16u_C4R( const ushort* bgra, int bgra_step,
ushort* rgba, int rgba_step, CvSize size ); ushort* rgba, int rgba_step, Size size );
#define icvCvt_RGBA2BGRA_16u_C4R icvCvt_BGRA2RGBA_16u_C4R #define icvCvt_RGBA2BGRA_16u_C4R icvCvt_BGRA2RGBA_16u_C4R
void icvCvt_BGR5552Gray_8u_C2C1R( const uchar* bgr555, int bgr555_step, void icvCvt_BGR5552Gray_8u_C2C1R( const uchar* bgr555, int bgr555_step,
uchar* gray, int gray_step, CvSize size ); uchar* gray, int gray_step, Size size );
void icvCvt_BGR5652Gray_8u_C2C1R( const uchar* bgr565, int bgr565_step, void icvCvt_BGR5652Gray_8u_C2C1R( const uchar* bgr565, int bgr565_step,
uchar* gray, int gray_step, CvSize size ); uchar* gray, int gray_step, Size size );
void icvCvt_BGR5552BGR_8u_C2C3R( const uchar* bgr555, int bgr555_step, void icvCvt_BGR5552BGR_8u_C2C3R( const uchar* bgr555, int bgr555_step,
uchar* bgr, int bgr_step, CvSize size ); uchar* bgr, int bgr_step, Size size );
void icvCvt_BGR5652BGR_8u_C2C3R( const uchar* bgr565, int bgr565_step, void icvCvt_BGR5652BGR_8u_C2C3R( const uchar* bgr565, int bgr565_step,
uchar* bgr, int bgr_step, CvSize size ); uchar* bgr, int bgr_step, Size size );
void icvCvt_CMYK2BGR_8u_C4C3R( const uchar* cmyk, int cmyk_step, void icvCvt_CMYK2BGR_8u_C4C3R( const uchar* cmyk, int cmyk_step,
uchar* bgr, int bgr_step, CvSize size ); uchar* bgr, int bgr_step, Size size );
void icvCvt_CMYK2Gray_8u_C4C1R( const uchar* ycck, int ycck_step, void icvCvt_CMYK2Gray_8u_C4C1R( const uchar* ycck, int ycck_step,
uchar* gray, int gray_step, CvSize size ); uchar* gray, int gray_step, Size size );
void FillGrayPalette( PaletteEntry* palette, int bpp, bool negative = false ); void FillGrayPalette( PaletteEntry* palette, int bpp, bool negative = false );
bool IsColorPalette( PaletteEntry* palette, int bpp ); bool IsColorPalette( PaletteEntry* palette, int bpp );
...@@ -136,4 +138,6 @@ CV_INLINE bool isBigEndian( void ) ...@@ -136,4 +138,6 @@ CV_INLINE bool isBigEndian( void )
return (((const int*)"\0\x1\x2\x3\x4\x5\x6\x7")[0] & 255) != 0; return (((const int*)"\0\x1\x2\x3\x4\x5\x6\x7")[0] & 255) != 0;
} }
} // namespace
#endif/*_UTILS_H_*/ #endif/*_UTILS_H_*/
...@@ -158,12 +158,68 @@ TEST(Imgcodecs_Tiff, readWrite_32FC1) ...@@ -158,12 +158,68 @@ TEST(Imgcodecs_Tiff, readWrite_32FC1)
ASSERT_TRUE(cv::imwrite(filenameOutput, img)); ASSERT_TRUE(cv::imwrite(filenameOutput, img));
const Mat img2 = cv::imread(filenameOutput, IMREAD_UNCHANGED); const Mat img2 = cv::imread(filenameOutput, IMREAD_UNCHANGED);
ASSERT_EQ(img2.type(),img.type()); ASSERT_EQ(img2.type(), img.type());
ASSERT_EQ(img2.size(),img.size()); ASSERT_EQ(img2.size(), img.size());
EXPECT_GE(1e-3, cvtest::norm(img, img2, NORM_INF | NORM_RELATIVE)); EXPECT_LE(cvtest::norm(img, img2, NORM_INF | NORM_RELATIVE), 1e-3);
EXPECT_EQ(0, remove(filenameOutput.c_str())); EXPECT_EQ(0, remove(filenameOutput.c_str()));
} }
TEST(Imgcodecs_Tiff, readWrite_64FC1)
{
const string root = cvtest::TS::ptr()->get_data_path();
const string filenameInput = root + "readwrite/test64FC1.tiff";
const string filenameOutput = cv::tempfile(".tiff");
const Mat img = cv::imread(filenameInput, IMREAD_UNCHANGED);
ASSERT_FALSE(img.empty());
ASSERT_EQ(CV_64FC1, img.type());
ASSERT_TRUE(cv::imwrite(filenameOutput, img));
const Mat img2 = cv::imread(filenameOutput, IMREAD_UNCHANGED);
ASSERT_EQ(img2.type(), img.type());
ASSERT_EQ(img2.size(), img.size());
EXPECT_LE(cvtest::norm(img, img2, NORM_INF | NORM_RELATIVE), 1e-3);
EXPECT_EQ(0, remove(filenameOutput.c_str()));
}
TEST(Imgcodecs_Tiff, readWrite_32FC3_SGILOG)
{
const string root = cvtest::TS::ptr()->get_data_path();
const string filenameInput = root + "readwrite/test32FC3_sgilog.tiff";
const string filenameOutput = cv::tempfile(".tiff");
const Mat img = cv::imread(filenameInput, IMREAD_UNCHANGED);
ASSERT_FALSE(img.empty());
ASSERT_EQ(CV_32FC3, img.type());
ASSERT_TRUE(cv::imwrite(filenameOutput, img));
const Mat img2 = cv::imread(filenameOutput, IMREAD_UNCHANGED);
ASSERT_EQ(img2.type(), img.type());
ASSERT_EQ(img2.size(), img.size());
EXPECT_LE(cvtest::norm(img, img2, NORM_INF | NORM_RELATIVE), 0.01);
EXPECT_EQ(0, remove(filenameOutput.c_str()));
}
TEST(Imgcodecs_Tiff, readWrite_32FC3_RAW)
{
const string root = cvtest::TS::ptr()->get_data_path();
const string filenameInput = root + "readwrite/test32FC3_raw.tiff";
const string filenameOutput = cv::tempfile(".tiff");
const Mat img = cv::imread(filenameInput, IMREAD_UNCHANGED);
ASSERT_FALSE(img.empty());
ASSERT_EQ(CV_32FC3, img.type());
std::vector<int> params;
params.push_back(IMWRITE_TIFF_COMPRESSION);
params.push_back(1/*COMPRESSION_NONE*/);
ASSERT_TRUE(cv::imwrite(filenameOutput, img, params));
const Mat img2 = cv::imread(filenameOutput, IMREAD_UNCHANGED);
ASSERT_EQ(img2.type(), img.type());
ASSERT_EQ(img2.size(), img.size());
EXPECT_LE(cvtest::norm(img, img2, NORM_INF | NORM_RELATIVE), 1e-3);
EXPECT_EQ(0, remove(filenameOutput.c_str()));
}
//================================================================================================== //==================================================================================================
typedef testing::TestWithParam<int> Imgcodecs_Tiff_Modes; typedef testing::TestWithParam<int> Imgcodecs_Tiff_Modes;
......
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