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
fb9c083a
Commit
fb9c083a
authored
May 23, 2019
by
Jan Starzynski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
handle all orientations properly
parent
def8fa22
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
75 additions
and
2 deletions
+75
-2
grfmt_tiff.cpp
modules/imgcodecs/src/grfmt_tiff.cpp
+75
-2
No files found.
modules/imgcodecs/src/grfmt_tiff.cpp
View file @
fb9c083a
...
...
@@ -334,6 +334,77 @@ bool TiffDecoder::nextPage()
readHeader
();
}
static
void
fixOrientationPartial
(
Mat
&
img
,
uint16
orientation
)
{
switch
(
orientation
)
{
case
ORIENTATION_RIGHTTOP
:
case
ORIENTATION_LEFTBOT
:
flip
(
img
,
img
,
-
1
);
/* fall through */
case
ORIENTATION_LEFTTOP
:
case
ORIENTATION_RIGHTBOT
:
transpose
(
img
,
img
);
break
;
}
}
static
void
fixOrientationFull
(
Mat
&
img
,
int
orientation
)
{
switch
(
orientation
)
{
case
ORIENTATION_TOPRIGHT
:
flip
(
img
,
img
,
1
);
break
;
case
ORIENTATION_BOTRIGHT
:
flip
(
img
,
img
,
-
1
);
break
;
case
ORIENTATION_BOTLEFT
:
flip
(
img
,
img
,
0
);
break
;
case
ORIENTATION_LEFTTOP
:
transpose
(
img
,
img
);
break
;
case
ORIENTATION_RIGHTTOP
:
transpose
(
img
,
img
);
flip
(
img
,
img
,
1
);
break
;
case
ORIENTATION_RIGHTBOT
:
transpose
(
img
,
img
);
flip
(
img
,
img
,
-
1
);
break
;
case
ORIENTATION_LEFTBOT
:
transpose
(
img
,
img
);
flip
(
img
,
img
,
0
);
break
;
}
}
/**
* Fix orientation defined in tag 274.
* For 8 bit some corrections are done by TIFFReadRGBAStrip/Tile already.
* Not so for 16/32/64 bit.
*/
static
void
fixOrientation
(
Mat
&
img
,
uint16
orientation
,
int
dst_bpp
)
{
switch
(
dst_bpp
)
{
case
8
:
fixOrientationPartial
(
img
,
orientation
);
break
;
case
16
:
case
32
:
case
64
:
fixOrientationFull
(
img
,
orientation
);
break
;
}
}
bool
TiffDecoder
::
readData
(
Mat
&
img
)
{
int
type_
=
img
.
type
();
...
...
@@ -363,10 +434,11 @@ bool TiffDecoder::readData( Mat& img )
CV_TIFF_CHECK_CALL_DEBUG
(
TIFFGetField
(
tif
,
TIFFTAG_SAMPLESPERPIXEL
,
&
ncn
));
uint16
img_orientation
=
ORIENTATION_TOPLEFT
;
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
;
int
dst_bpp
=
(
int
)(
img
.
elemSize1
()
*
bitsPerByte
);
bool
vert_flip
=
dst_bpp
==
8
&&
(
img_orientation
==
ORIENTATION_BOTRIGHT
||
img_orientation
==
ORIENTATION_RIGHTBOT
||
img_orientation
==
ORIENTATION_BOTLEFT
||
img_orientation
==
ORIENTATION_LEFTBOT
);
int
wanted_channels
=
normalizeChannelsNumber
(
img
.
channels
());
if
(
dst_bpp
==
8
)
...
...
@@ -579,6 +651,7 @@ bool TiffDecoder::readData( Mat& img )
}
// for x
}
// for y
}
fixOrientation
(
img
,
img_orientation
,
dst_bpp
);
}
if
(
m_hdr
&&
depth
>=
CV_32F
)
...
...
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