提交 8d0452ed 编写于 作者: A andrey.morozov

added test to save image with webp with alpha channel

上级 4f19216e
...@@ -143,7 +143,15 @@ bool WebPDecoder::readData(Mat &img) ...@@ -143,7 +143,15 @@ bool WebPDecoder::readData(Mat &img)
uchar* out_data = img.data; uchar* out_data = img.data;
unsigned int out_data_size = m_width * m_height * 3 * sizeof(uchar); unsigned int out_data_size = m_width * m_height * 3 * sizeof(uchar);
uchar *res_ptr = WebPDecodeBGRInto(data.data, data.total(), out_data, out_data_size, m_width * 3); uchar *res_ptr = 0;
if (channels == 3)
{
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);
}
if(res_ptr == out_data) if(res_ptr == out_data)
{ {
......
...@@ -391,7 +391,7 @@ TEST(Highgui_WebP, encode_decode_lossy_webp) ...@@ -391,7 +391,7 @@ TEST(Highgui_WebP, encode_decode_lossy_webp)
cv::Mat img = cv::imread(input); cv::Mat img = cv::imread(input);
ASSERT_FALSE(img.empty()); ASSERT_FALSE(img.empty());
for(int q = 100; q>=0; q-=10) for(int q = 100; q>=0; q-=20)
{ {
std::vector<int> params; std::vector<int> params;
params.push_back(IMWRITE_WEBP_QUALITY); params.push_back(IMWRITE_WEBP_QUALITY);
...@@ -405,4 +405,25 @@ TEST(Highgui_WebP, encode_decode_lossy_webp) ...@@ -405,4 +405,25 @@ TEST(Highgui_WebP, encode_decode_lossy_webp)
} }
} }
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";
cv::Mat img = cv::imread(input);
ASSERT_FALSE(img.empty());
std::vector<cv::Mat> imgs;
cv::split(img, imgs);
imgs.push_back(cv::Mat(imgs[0]));
imgs[imgs.size() - 1] = cv::Scalar::all(128);
cv::merge(imgs, img);
string output = cv::tempfile(".webp");
EXPECT_NO_THROW(cv::imwrite(output, img));
cv::Mat img_webp = cv::imread(output);
remove(output.c_str());
EXPECT_FALSE(img_webp.empty());
}
#endif #endif
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册