【发布时间】:2015-01-21 19:39:29
【问题描述】:
我在 c++ 中使用 libwebp 从 webp 编码和解码时遇到问题。 我构建了这个测试应用程序,它采用我创建的 webp 文件(在 chrome 中看起来不错),并尝试将其解码为 rgb,然后返回到 webp,只是为了了解如何使用它,但输出错误:
//Code before reads the webp file, and assigning it to a uint8_t buffer called "pic" ///
WebPConfig config;
ASSERT(WebConfigIit(&config) == TRUE)
int width=0 height =0;
uint8_t * rgb = WebPDecodeRGB(pic, size, &width, &height)
ASSERT (rgb != NULL)
// At this point the width and the height is valid, and the rgb is assigned.
uint8_t* originalPic = null;
size_t size = WebPEncodeRGB(rgb, width, height, height, &originalPic);
// Didn't quite know what to put in the stride param..
/// Code after saves the originalPic buffer to a file ////
如您所见,我所做的只是设法对 webp 进行编码和解码,并尝试将其保存回文件,但是当我尝试打开文件时,它看起来已损坏。
你能帮我找出问题所在吗? 此外,我很乐意了解更多关于步幅参数、rgb 格式以及如何将图片转换为它以检查我的代码是否有效的信息。
非常感谢!
【问题讨论】:
-
stride参数对于RGB色彩空间应该是
width * 3,对于RGBA应该是width * 4,基本上就是存储一条扫描线或者一行需要多少字节。size_t size = WebPEncodeRGB(rgb, width, height, width * 3, &originalPic);
标签: c++ bitmap gdi+ webp image-formats