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
604c53a0
Commit
604c53a0
authored
Apr 21, 2011
by
Vladislav Vinogradov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added 16-bit support to TiffEncoder
parent
f385bb97
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
52 additions
and
9 deletions
+52
-9
grfmt_tiff.cpp
modules/highgui/src/grfmt_tiff.cpp
+27
-9
grfmt_tiff.hpp
modules/highgui/src/grfmt_tiff.hpp
+2
-0
utils.cpp
modules/highgui/src/utils.cpp
+19
-0
utils.hpp
modules/highgui/src/utils.hpp
+4
-0
No files found.
modules/highgui/src/grfmt_tiff.cpp
View file @
604c53a0
...
...
@@ -301,6 +301,11 @@ TiffEncoder::~TiffEncoder()
{
}
bool
TiffEncoder
::
isFormatSupported
(
int
depth
)
const
{
return
depth
==
CV_8U
||
depth
==
CV_16U
;
}
ImageEncoder
TiffEncoder
::
newEncoder
()
const
{
return
new
TiffEncoder
;
...
...
@@ -321,7 +326,13 @@ bool TiffEncoder::write( const Mat& img, const vector<int>& )
{
int
channels
=
img
.
channels
();
int
width
=
img
.
cols
,
height
=
img
.
rows
;
int
fileStep
=
width
*
channels
;
int
depth
=
img
.
depth
();
if
(
depth
!=
CV_8U
&&
depth
!=
CV_16U
)
return
false
;
int
bytesPerChannel
=
depth
==
CV_8U
?
1
:
2
;
int
fileStep
=
width
*
channels
*
bytesPerChannel
;
WLByteStream
strm
;
if
(
m_buf
)
...
...
@@ -356,7 +367,7 @@ bool TiffEncoder::write( const Mat& img, const vector<int>& )
uchar
*
buffer
=
_buffer
;
int
stripOffsetsOffset
=
0
;
int
stripCountsOffset
=
0
;
int
bitsPerSample
=
8
;
// TODO support 16 bit
int
bitsPerSample
=
8
*
bytesPerChannel
;
int
y
=
0
;
strm
.
putBytes
(
fmtSignTiffII
,
4
);
...
...
@@ -376,9 +387,15 @@ bool TiffEncoder::write( const Mat& img, const vector<int>& )
for
(
;
y
<
limit
;
y
++
)
{
if
(
channels
==
3
)
icvCvt_BGR2RGB_8u_C3R
(
img
.
data
+
img
.
step
*
y
,
0
,
buffer
,
0
,
cvSize
(
width
,
1
)
);
if
(
depth
==
CV_8U
)
icvCvt_BGR2RGB_8u_C3R
(
img
.
data
+
img
.
step
*
y
,
0
,
buffer
,
0
,
cvSize
(
width
,
1
)
);
else
icvCvt_BGR2RGB_16u_C3R
(
(
const
ushort
*
)(
img
.
data
+
img
.
step
*
y
),
0
,
(
ushort
*
)
buffer
,
0
,
cvSize
(
width
,
1
)
);
else
if
(
channels
==
4
)
icvCvt_BGRA2RGBA_8u_C4R
(
img
.
data
+
img
.
step
*
y
,
0
,
buffer
,
0
,
cvSize
(
width
,
1
)
);
if
(
depth
==
CV_8U
)
icvCvt_BGRA2RGBA_8u_C4R
(
img
.
data
+
img
.
step
*
y
,
0
,
buffer
,
0
,
cvSize
(
width
,
1
)
);
else
icvCvt_BGRA2RGBA_16u_C4R
(
(
const
ushort
*
)(
img
.
data
+
img
.
step
*
y
),
0
,
(
ushort
*
)
buffer
,
0
,
cvSize
(
width
,
1
)
);
strm
.
putBytes
(
channels
>
1
?
buffer
:
img
.
data
+
img
.
step
*
y
,
fileStep
);
}
...
...
@@ -416,12 +433,13 @@ bool TiffEncoder::write( const Mat& img, const vector<int>& )
if
(
channels
>
1
)
{
bitsPerSample
=
strm
.
getPos
();
strm
.
putWord
(
8
);
strm
.
putWord
(
8
);
strm
.
putWord
(
8
);
int
bitsPerSamplePos
=
strm
.
getPos
();
strm
.
putWord
(
bitsPerSample
);
strm
.
putWord
(
bitsPerSample
);
strm
.
putWord
(
bitsPerSample
);
if
(
channels
==
4
)
strm
.
putWord
(
8
);
strm
.
putWord
(
bitsPerSample
);
bitsPerSample
=
bitsPerSamplePos
;
}
directoryOffset
=
strm
.
getPos
();
...
...
modules/highgui/src/grfmt_tiff.hpp
View file @
604c53a0
...
...
@@ -118,6 +118,8 @@ public:
TiffEncoder
();
virtual
~
TiffEncoder
();
bool
isFormatSupported
(
int
depth
)
const
;
bool
write
(
const
Mat
&
img
,
const
vector
<
int
>&
params
);
ImageEncoder
newEncoder
()
const
;
...
...
modules/highgui/src/utils.cpp
View file @
604c53a0
...
...
@@ -192,6 +192,25 @@ 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
,
CvSize
size
)
{
int
i
;
for
(
;
size
.
height
--
;
)
{
for
(
i
=
0
;
i
<
size
.
width
;
i
++
,
bgra
+=
4
,
rgba
+=
4
)
{
ushort
t0
=
bgra
[
0
],
t1
=
bgra
[
1
];
ushort
t2
=
bgra
[
2
],
t3
=
bgra
[
3
];
rgba
[
0
]
=
t2
;
rgba
[
1
]
=
t1
;
rgba
[
2
]
=
t0
;
rgba
[
3
]
=
t3
;
}
bgra
+=
bgra_step
/
sizeof
(
bgra
[
0
])
-
size
.
width
*
4
;
rgba
+=
rgba_step
/
sizeof
(
rgba
[
0
])
-
size
.
width
*
4
;
}
}
void
icvCvt_BGR2RGB_8u_C3R
(
const
uchar
*
bgr
,
int
bgr_step
,
uchar
*
rgb
,
int
rgb_step
,
CvSize
size
)
...
...
modules/highgui/src/utils.hpp
View file @
604c53a0
...
...
@@ -88,6 +88,10 @@ void icvCvt_BGRA2RGBA_8u_C4R( const uchar* bgra, int bgra_step,
uchar
*
rgba
,
int
rgba_step
,
CvSize
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
,
CvSize
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
,
CvSize
size
);
void
icvCvt_BGR5652Gray_8u_C2C1R
(
const
uchar
*
bgr565
,
int
bgr565_step
,
...
...
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