Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Greenplum
Opencv
提交
e4e0862c
O
Opencv
项目概览
Greenplum
/
Opencv
11 个月 前同步成功
通知
7
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
O
Opencv
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
e4e0862c
编写于
6月 29, 2013
作者:
A
andrey.morozov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
added support image with alpha channel
上级
8d0452ed
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
89 addition
and
33 deletion
+89
-33
modules/highgui/src/grfmt_webp.cpp
modules/highgui/src/grfmt_webp.cpp
+75
-30
modules/highgui/src/grfmt_webp.hpp
modules/highgui/src/grfmt_webp.hpp
+6
-1
modules/highgui/test/test_grfmt.cpp
modules/highgui/test/test_grfmt.cpp
+8
-2
未找到文件。
modules/highgui/src/grfmt_webp.cpp
浏览文件 @
e4e0862c
...
...
@@ -46,6 +46,7 @@
#include <webp/decode.h>
#include <webp/encode.h>
#include <stdio.h>
#include <limits.h>
...
...
@@ -53,38 +54,45 @@
#include "opencv2/imgproc.hpp"
const
size_t
WEBP_HEADER_SIZE
=
32
;
namespace
cv
{
WebPDecoder
::
WebPDecoder
()
{
m_signature
=
"RIFF....WEBPVP8 "
;
m_buf_supported
=
true
;
}
WebPDecoder
::~
WebPDecoder
()
{
}
WebPDecoder
::~
WebPDecoder
()
{}
ImageDecoder
WebPDecoder
::
newDecoder
()
const
size_t
WebPDecoder
::
signatureLength
()
const
{
return
new
WebPDecoder
;
return
WEBP_HEADER_SIZE
;
}
bool
WebPDecoder
::
checkSignature
(
const
String
&
signature
)
const
bool
WebPDecoder
::
checkSignature
(
const
String
&
signature
)
const
{
size_t
len
=
signatureLength
();
bool
ret
=
false
;
if
(
signature
.
size
()
>=
len
)
if
(
signature
.
size
()
>=
WEBP_HEADER_SIZE
)
{
ret
=
(
(
memcmp
(
signature
.
c_str
(),
m_signature
.
c_str
(),
4
)
==
0
)
&&
(
memcmp
(
signature
.
c_str
()
+
8
,
m_signature
.
c_str
()
+
8
,
4
)
==
0
)
);
WebPBitstreamFeatures
features
;
if
(
VP8_STATUS_OK
==
WebPGetFeatures
((
uint8_t
*
)
signature
.
c_str
(),
WEBP_HEADER_SIZE
,
&
features
))
{
ret
=
true
;
}
}
return
ret
;
}
ImageDecoder
WebPDecoder
::
newDecoder
()
const
{
return
new
WebPDecoder
;
}
bool
WebPDecoder
::
readHeader
()
{
if
(
m_buf
.
empty
())
...
...
@@ -99,16 +107,16 @@ bool WebPDecoder::readHeader()
}
fseek
(
wfile
,
0
,
SEEK_END
);
size_
t
wfile_size
=
ftell
(
wfile
);
long
in
t
wfile_size
=
ftell
(
wfile
);
fseek
(
wfile
,
0
,
SEEK_SET
);
if
(
wfile_size
>
(
size_t
)
INT_MAX
)
if
(
wfile_size
>
static_cast
<
long
int
>
(
INT_MAX
)
)
{
fclose
(
wfile
);
return
false
;
}
data
.
create
(
1
,
(
int
)
wfile_size
,
CV_8U
);
data
.
create
(
1
,
wfile_size
,
CV_8U
);
size_t
data_size
=
fread
(
data
.
data
,
1
,
wfile_size
,
wfile
);
...
...
@@ -117,7 +125,7 @@ bool WebPDecoder::readHeader()
fclose
(
wfile
);
}
if
(
data_size
<
wfile_size
)
if
(
static_cast
<
long
int
>
(
data_size
)
!=
wfile_size
)
{
return
false
;
}
...
...
@@ -127,9 +135,23 @@ bool WebPDecoder::readHeader()
data
=
m_buf
;
}
if
(
WebPGetInfo
(
data
.
data
,
data
.
total
(),
&
m_width
,
&
m_height
)
==
1
)
WebPBitstreamFeatures
features
;
if
(
VP8_STATUS_OK
==
WebPGetFeatures
(
data
.
data
,
WEBP_HEADER_SIZE
,
&
features
))
{
m_type
=
CV_8UC3
;
m_width
=
features
.
width
;
m_height
=
features
.
height
;
if
(
features
.
has_alpha
)
{
m_type
=
CV_8UC4
;
channels
=
4
;
}
else
{
m_type
=
CV_8UC3
;
channels
=
3
;
}
return
true
;
}
...
...
@@ -140,17 +162,24 @@ bool WebPDecoder::readData(Mat &img)
{
if
(
m_width
>
0
&&
m_height
>
0
)
{
if
(
img
.
cols
!=
m_width
||
img
.
rows
!=
m_height
||
img
.
type
()
!=
m_type
)
{
img
.
create
(
m_height
,
m_width
,
m_type
);
}
uchar
*
out_data
=
img
.
data
;
unsigned
int
out_data_size
=
m_width
*
m_height
*
3
*
sizeof
(
uchar
);
size_t
out_data_size
=
img
.
cols
*
img
.
rows
*
img
.
elemSize
(
);
uchar
*
res_ptr
=
0
;
if
(
channels
==
3
)
{
res_ptr
=
WebPDecodeBGRInto
(
data
.
data
,
data
.
total
(),
out_data
,
out_data_size
,
img
.
step
);
res_ptr
=
WebPDecodeBGRInto
(
data
.
data
,
data
.
total
(),
out_data
,
out_data_size
,
img
.
step
);
}
else
if
(
channels
==
4
)
{
res_ptr
=
WebPDecodeBGRAInto
(
data
.
data
,
data
.
total
(),
out_data
,
out_data_size
,
img
.
step
);
res_ptr
=
WebPDecodeBGRAInto
(
data
.
data
,
data
.
total
(),
out_data
,
out_data_size
,
img
.
step
);
}
if
(
res_ptr
==
out_data
)
...
...
@@ -168,9 +197,7 @@ WebPEncoder::WebPEncoder()
m_buf_supported
=
true
;
}
WebPEncoder
::~
WebPEncoder
()
{
}
WebPEncoder
::~
WebPEncoder
()
{
}
ImageEncoder
WebPEncoder
::
newEncoder
()
const
{
...
...
@@ -187,19 +214,19 @@ bool WebPEncoder::write(const Mat& img, const std::vector<int>& params)
size_t
size
=
0
;
bool
comp_lossless
=
true
;
int
quality
=
100
;
float
quality
=
100.0
f
;
if
(
params
.
size
()
>
1
)
{
if
(
params
[
0
]
==
CV_IMWRITE_WEBP_QUALITY
)
{
comp_lossless
=
false
;
quality
=
params
[
1
]
;
if
(
quality
<
1
)
quality
=
static_cast
<
float
>
(
params
[
1
])
;
if
(
quality
<
1
.0
f
)
{
quality
=
1
;
quality
=
1
.0
f
;
}
if
(
quality
>
100
)
if
(
quality
>
100
.0
f
)
{
comp_lossless
=
true
;
}
...
...
@@ -219,14 +246,32 @@ bool WebPEncoder::write(const Mat& img, const std::vector<int>& params)
image
=
&
temp
;
channels
=
3
;
}
else
if
(
channels
==
2
)
{
return
false
;
}
if
(
comp_lossless
)
{
size
=
WebPEncodeLosslessBGR
(
image
->
data
,
width
,
height
,
((
width
*
3
+
3
)
&
~
3
),
&
out
);
if
(
channels
==
3
)
{
size
=
WebPEncodeLosslessBGR
(
image
->
data
,
width
,
height
,
image
->
step
,
&
out
);
}
else
if
(
channels
==
4
)
{
size
=
WebPEncodeLosslessBGRA
(
image
->
data
,
width
,
height
,
image
->
step
,
&
out
);
}
}
else
{
size
=
WebPEncodeBGR
(
image
->
data
,
width
,
height
,
((
width
*
3
+
3
)
&
~
3
),
(
float
)
quality
,
&
out
);
if
(
channels
==
3
)
{
size
=
WebPEncodeBGR
(
image
->
data
,
width
,
height
,
image
->
step
,
quality
,
&
out
);
}
else
if
(
channels
==
4
)
{
size
=
WebPEncodeBGRA
(
image
->
data
,
width
,
height
,
image
->
step
,
quality
,
&
out
);
}
}
if
(
size
>
0
)
...
...
modules/highgui/src/grfmt_webp.hpp
浏览文件 @
e4e0862c
...
...
@@ -47,6 +47,8 @@
#ifdef HAVE_WEBP
namespace
cv
{
...
...
@@ -60,12 +62,15 @@ public:
bool
readData
(
Mat
&
img
);
bool
readHeader
();
void
close
();
bool
checkSignature
(
const
String
&
signature
)
const
;
size_t
signatureLength
()
const
;
bool
checkSignature
(
const
String
&
signature
)
const
;
ImageDecoder
newDecoder
()
const
;
protected:
Mat
data
;
int
channels
;
};
class
WebPEncoder
:
public
BaseImageEncoder
...
...
modules/highgui/test/test_grfmt.cpp
浏览文件 @
e4e0862c
...
...
@@ -387,7 +387,7 @@ TEST(Highgui_WebP, encode_decode_lossless_webp)
TEST
(
Highgui_WebP
,
encode_decode_lossy_webp
)
{
cvtest
::
TS
&
ts
=
*
cvtest
::
TS
::
ptr
();
std
::
string
input
=
std
::
string
(
ts
.
get_data_path
())
+
"
/
../cv/shared/lena.png"
;
std
::
string
input
=
std
::
string
(
ts
.
get_data_path
())
+
"../cv/shared/lena.png"
;
cv
::
Mat
img
=
cv
::
imread
(
input
);
ASSERT_FALSE
(
img
.
empty
());
...
...
@@ -402,13 +402,16 @@ TEST(Highgui_WebP, encode_decode_lossy_webp)
cv
::
Mat
img_webp
=
cv
::
imread
(
output
);
remove
(
output
.
c_str
());
EXPECT_FALSE
(
img_webp
.
empty
());
EXPECT_EQ
(
3
,
img_webp
.
channels
());
EXPECT_EQ
(
512
,
img_webp
.
cols
);
EXPECT_EQ
(
512
,
img_webp
.
rows
);
}
}
TEST
(
Highgui_WebP
,
encode_decode_with_alpha_webp
)
{
cvtest
::
TS
&
ts
=
*
cvtest
::
TS
::
ptr
();
std
::
string
input
=
std
::
string
(
ts
.
get_data_path
())
+
"
/
../cv/shared/lena.png"
;
std
::
string
input
=
std
::
string
(
ts
.
get_data_path
())
+
"../cv/shared/lena.png"
;
cv
::
Mat
img
=
cv
::
imread
(
input
);
ASSERT_FALSE
(
img
.
empty
());
...
...
@@ -424,6 +427,9 @@ TEST(Highgui_WebP, encode_decode_with_alpha_webp)
cv
::
Mat
img_webp
=
cv
::
imread
(
output
);
remove
(
output
.
c_str
());
EXPECT_FALSE
(
img_webp
.
empty
());
EXPECT_EQ
(
4
,
img_webp
.
channels
());
EXPECT_EQ
(
512
,
img_webp
.
cols
);
EXPECT_EQ
(
512
,
img_webp
.
rows
);
}
#endif
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录