added test to save image with webp with alpha channel
This commit is contained in:
parent
4f19216e45
commit
8d0452ed59
@ -143,7 +143,15 @@ bool WebPDecoder::readData(Mat &img)
|
||||
uchar* out_data = img.data;
|
||||
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)
|
||||
{
|
||||
|
@ -391,7 +391,7 @@ TEST(Highgui_WebP, encode_decode_lossy_webp)
|
||||
cv::Mat img = cv::imread(input);
|
||||
ASSERT_FALSE(img.empty());
|
||||
|
||||
for(int q = 100; q>=0; q-=10)
|
||||
for(int q = 100; q>=0; q-=20)
|
||||
{
|
||||
std::vector<int> params;
|
||||
params.push_back(IMWRITE_WEBP_QUALITY);
|
||||
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user