Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
opencv
Commits
1fb93b62
Commit
1fb93b62
authored
Apr 04, 2019
by
Alexander Alekhin
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #14249 from alalek:imgcodecs_tiff_update_3.4
parents
ab21dc6d
ba5ddd64
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
106 additions
and
44 deletions
+106
-44
grfmt_tiff.cpp
modules/imgcodecs/src/grfmt_tiff.cpp
+0
-0
grfmt_tiff.hpp
modules/imgcodecs/src/grfmt_tiff.hpp
+2
-5
utils.cpp
modules/imgcodecs/src/utils.cpp
+24
-19
utils.hpp
modules/imgcodecs/src/utils.hpp
+21
-17
test_tiff.cpp
modules/imgcodecs/test/test_tiff.cpp
+59
-3
No files found.
modules/imgcodecs/src/grfmt_tiff.cpp
View file @
1fb93b62
This diff is collapsed.
Click to expand it.
modules/imgcodecs/src/grfmt_tiff.hpp
View file @
1fb93b62
...
...
@@ -106,10 +106,8 @@ public:
ImageDecoder
newDecoder
()
const
CV_OVERRIDE
;
protected
:
void
*
m_tif
;
cv
::
Ptr
<
void
>
m_tif
;
int
normalizeChannelsNumber
(
int
channels
)
const
;
bool
readData_32FC3
(
Mat
&
img
);
bool
readData_32FC1
(
Mat
&
img
);
bool
m_hdr
;
size_t
m_buf_pos
;
...
...
@@ -139,8 +137,7 @@ protected:
int
count
,
int
value
);
bool
writeLibTiff
(
const
std
::
vector
<
Mat
>&
img_vec
,
const
std
::
vector
<
int
>&
params
);
bool
write_32FC3
(
const
Mat
&
img
);
bool
write_32FC1
(
const
Mat
&
img
);
bool
write_32FC3_SGILOG
(
const
Mat
&
img
,
void
*
tif
);
private
:
TiffEncoder
(
const
TiffEncoder
&
);
// copy disabled
...
...
modules/imgcodecs/src/utils.cpp
View file @
1fb93b62
...
...
@@ -42,6 +42,8 @@
#include "precomp.hpp"
#include "utils.hpp"
namespace
cv
{
int
validateToInt
(
size_t
sz
)
{
int
valueInt
=
(
int
)
sz
;
...
...
@@ -56,7 +58,7 @@ int validateToInt(size_t sz)
void
icvCvt_BGR2Gray_8u_C3C1R
(
const
uchar
*
rgb
,
int
rgb_step
,
uchar
*
gray
,
int
gray_step
,
Cv
Size
size
,
int
_swap_rb
)
Size
size
,
int
_swap_rb
)
{
int
i
;
int
swap_rb
=
_swap_rb
?
2
:
0
;
...
...
@@ -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
,
ushort
*
gray
,
int
gray_step
,
Cv
Size
size
,
int
ncn
,
int
_swap_rb
)
Size
size
,
int
ncn
,
int
_swap_rb
)
{
int
i
;
int
swap_rb
=
_swap_rb
?
2
:
0
;
...
...
@@ -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
,
uchar
*
gray
,
int
gray_step
,
Cv
Size
size
,
int
_swap_rb
)
Size
size
,
int
_swap_rb
)
{
int
i
;
int
swap_rb
=
_swap_rb
?
2
:
0
;
...
...
@@ -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
,
uchar
*
bgr
,
int
bgr_step
,
Cv
Size
size
)
uchar
*
bgr
,
int
bgr_step
,
Size
size
)
{
int
i
;
for
(
;
size
.
height
--
;
gray
+=
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
,
ushort
*
bgr
,
int
bgr_step
,
Cv
Size
size
)
ushort
*
bgr
,
int
bgr_step
,
Size
size
)
{
int
i
;
for
(
;
size
.
height
--
;
gray
+=
gray_step
/
sizeof
(
gray
[
0
])
)
...
...
@@ -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
,
uchar
*
bgr
,
int
bgr_step
,
Cv
Size
size
,
int
_swap_rb
)
Size
size
,
int
_swap_rb
)
{
int
i
;
int
swap_rb
=
_swap_rb
?
2
:
0
;
...
...
@@ -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
,
ushort
*
bgr
,
int
bgr_step
,
Cv
Size
size
,
int
_swap_rb
)
Size
size
,
int
_swap_rb
)
{
int
i
;
int
swap_rb
=
_swap_rb
?
2
:
0
;
...
...
@@ -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
,
uchar
*
rgba
,
int
rgba_step
,
Cv
Size
size
)
uchar
*
rgba
,
int
rgba_step
,
Size
size
)
{
int
i
;
for
(
;
size
.
height
--
;
)
...
...
@@ -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
,
ushort
*
rgba
,
int
rgba_step
,
Cv
Size
size
)
ushort
*
rgba
,
int
rgba_step
,
Size
size
)
{
int
i
;
for
(
;
size
.
height
--
;
)
...
...
@@ -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
,
uchar
*
rgb
,
int
rgb_step
,
Cv
Size
size
)
uchar
*
rgb
,
int
rgb_step
,
Size
size
)
{
int
i
;
for
(
;
size
.
height
--
;
)
...
...
@@ -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
,
ushort
*
rgb
,
int
rgb_step
,
Cv
Size
size
)
ushort
*
rgb
,
int
rgb_step
,
Size
size
)
{
int
i
;
for
(
;
size
.
height
--
;
)
...
...
@@ -256,7 +258,7 @@ void icvCvt_BGR2RGB_16u_C3R( const ushort* bgr, int bgr_step,
typedef
unsigned
short
ushort
;
void
icvCvt_BGR5552Gray_8u_C2C1R
(
const
uchar
*
bgr555
,
int
bgr555_step
,
uchar
*
gray
,
int
gray_step
,
Cv
Size
size
)
uchar
*
gray
,
int
gray_step
,
Size
size
)
{
int
i
;
for
(
;
size
.
height
--
;
gray
+=
gray_step
,
bgr555
+=
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
,
uchar
*
gray
,
int
gray_step
,
Cv
Size
size
)
uchar
*
gray
,
int
gray_step
,
Size
size
)
{
int
i
;
for
(
;
size
.
height
--
;
gray
+=
gray_step
,
bgr565
+=
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
,
uchar
*
bgr
,
int
bgr_step
,
Cv
Size
size
)
uchar
*
bgr
,
int
bgr_step
,
Size
size
)
{
int
i
;
for
(
;
size
.
height
--
;
bgr555
+=
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
,
uchar
*
bgr
,
int
bgr_step
,
Cv
Size
size
)
uchar
*
bgr
,
int
bgr_step
,
Size
size
)
{
int
i
;
for
(
;
size
.
height
--
;
bgr565
+=
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
,
uchar
*
bgr
,
int
bgr_step
,
Cv
Size
size
)
uchar
*
bgr
,
int
bgr_step
,
Size
size
)
{
int
i
;
for
(
;
size
.
height
--
;
)
...
...
@@ -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
,
uchar
*
gray
,
int
gray_step
,
Cv
Size
size
)
uchar
*
gray
,
int
gray_step
,
Size
size
)
{
int
i
;
for
(
;
size
.
height
--
;
)
...
...
@@ -371,7 +373,7 @@ void CvtPaletteToGray( const PaletteEntry* palette, uchar* grayPalette, int entr
int
i
;
for
(
i
=
0
;
i
<
entries
;
i
++
)
{
icvCvt_BGR2Gray_8u_C3C1R
(
(
uchar
*
)(
palette
+
i
),
0
,
grayPalette
+
i
,
0
,
cv
Size
(
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 )
return
data
;
}
}
// namespace
using
namespace
cv
;
CV_IMPL
void
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
;
int
s_step
=
src
->
step
,
d_step
=
dst
->
step
;
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
)
)
{
...
...
modules/imgcodecs/src/utils.hpp
View file @
1fb93b62
...
...
@@ -42,6 +42,8 @@
#ifndef _UTILS_H_
#define _UTILS_H_
namespace
cv
{
int
validateToInt
(
size_t
step
);
template
<
typename
_Tp
>
static
inline
...
...
@@ -68,53 +70,53 @@ struct PaletteEntry
void
icvCvt_BGR2Gray_8u_C3C1R
(
const
uchar
*
bgr
,
int
bgr_step
,
uchar
*
gray
,
int
gray_step
,
Cv
Size
size
,
int
swap_rb
=
0
);
Size
size
,
int
swap_rb
=
0
);
void
icvCvt_BGRA2Gray_8u_C4C1R
(
const
uchar
*
bgra
,
int
bgra_step
,
uchar
*
gray
,
int
gray_step
,
Cv
Size
size
,
int
swap_rb
=
0
);
Size
size
,
int
swap_rb
=
0
);
void
icvCvt_BGRA2Gray_16u_CnC1R
(
const
ushort
*
bgra
,
int
bgra_step
,
ushort
*
gray
,
int
gray_step
,
Cv
Size
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
,
uchar
*
bgr
,
int
bgr_step
,
Cv
Size
size
);
uchar
*
bgr
,
int
bgr_step
,
Size
size
);
void
icvCvt_Gray2BGR_16u_C1C3R
(
const
ushort
*
gray
,
int
gray_step
,
ushort
*
bgr
,
int
bgr_step
,
Cv
Size
size
);
ushort
*
bgr
,
int
bgr_step
,
Size
size
);
void
icvCvt_BGRA2BGR_8u_C4C3R
(
const
uchar
*
bgra
,
int
bgra_step
,
uchar
*
bgr
,
int
bgr_step
,
Cv
Size
size
,
int
swap_rb
=
0
);
Size
size
,
int
swap_rb
=
0
);
void
icvCvt_BGRA2BGR_16u_C4C3R
(
const
ushort
*
bgra
,
int
bgra_step
,
ushort
*
bgr
,
int
bgr_step
,
Cv
Size
size
,
int
_swap_rb
);
Size
size
,
int
_swap_rb
);
void
icvCvt_BGR2RGB_8u_C3R
(
const
uchar
*
bgr
,
int
bgr_step
,
uchar
*
rgb
,
int
rgb_step
,
Cv
Size
size
);
uchar
*
rgb
,
int
rgb_step
,
Size
size
);
#define icvCvt_RGB2BGR_8u_C3R icvCvt_BGR2RGB_8u_C3R
void
icvCvt_BGR2RGB_16u_C3R
(
const
ushort
*
bgr
,
int
bgr_step
,
ushort
*
rgb
,
int
rgb_step
,
Cv
Size
size
);
ushort
*
rgb
,
int
rgb_step
,
Size
size
);
#define icvCvt_RGB2BGR_16u_C3R icvCvt_BGR2RGB_16u_C3R
void
icvCvt_BGRA2RGBA_8u_C4R
(
const
uchar
*
bgra
,
int
bgra_step
,
uchar
*
rgba
,
int
rgba_step
,
Cv
Size
size
);
uchar
*
rgba
,
int
rgba_step
,
Size
size
);
#define icvCvt_RGBA2BGRA_8u_C4R icvCvt_BGRA2RGBA_8u_C4R
void
icvCvt_BGRA2RGBA_16u_C4R
(
const
ushort
*
bgra
,
int
bgra_step
,
ushort
*
rgba
,
int
rgba_step
,
Cv
Size
size
);
ushort
*
rgba
,
int
rgba_step
,
Size
size
);
#define icvCvt_RGBA2BGRA_16u_C4R icvCvt_BGRA2RGBA_16u_C4R
void
icvCvt_BGR5552Gray_8u_C2C1R
(
const
uchar
*
bgr555
,
int
bgr555_step
,
uchar
*
gray
,
int
gray_step
,
Cv
Size
size
);
uchar
*
gray
,
int
gray_step
,
Size
size
);
void
icvCvt_BGR5652Gray_8u_C2C1R
(
const
uchar
*
bgr565
,
int
bgr565_step
,
uchar
*
gray
,
int
gray_step
,
Cv
Size
size
);
uchar
*
gray
,
int
gray_step
,
Size
size
);
void
icvCvt_BGR5552BGR_8u_C2C3R
(
const
uchar
*
bgr555
,
int
bgr555_step
,
uchar
*
bgr
,
int
bgr_step
,
Cv
Size
size
);
uchar
*
bgr
,
int
bgr_step
,
Size
size
);
void
icvCvt_BGR5652BGR_8u_C2C3R
(
const
uchar
*
bgr565
,
int
bgr565_step
,
uchar
*
bgr
,
int
bgr_step
,
Cv
Size
size
);
uchar
*
bgr
,
int
bgr_step
,
Size
size
);
void
icvCvt_CMYK2BGR_8u_C4C3R
(
const
uchar
*
cmyk
,
int
cmyk_step
,
uchar
*
bgr
,
int
bgr_step
,
Cv
Size
size
);
uchar
*
bgr
,
int
bgr_step
,
Size
size
);
void
icvCvt_CMYK2Gray_8u_C4C1R
(
const
uchar
*
ycck
,
int
ycck_step
,
uchar
*
gray
,
int
gray_step
,
Cv
Size
size
);
uchar
*
gray
,
int
gray_step
,
Size
size
);
void
FillGrayPalette
(
PaletteEntry
*
palette
,
int
bpp
,
bool
negative
=
false
);
bool
IsColorPalette
(
PaletteEntry
*
palette
,
int
bpp
);
...
...
@@ -136,4 +138,6 @@ CV_INLINE bool isBigEndian( void )
return
(((
const
int
*
)
"
\0
\x1\x2\x3\x4\x5\x6\x7"
)[
0
]
&
255
)
!=
0
;
}
}
// namespace
#endif
/*_UTILS_H_*/
modules/imgcodecs/test/test_tiff.cpp
View file @
1fb93b62
...
...
@@ -158,12 +158,68 @@ TEST(Imgcodecs_Tiff, readWrite_32FC1)
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_
GE
(
1e-3
,
cvtest
::
norm
(
img
,
img2
,
NORM_INF
|
NORM_RELATIVE
)
);
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_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
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment