如何用纯 C 语言将 RGB 缓冲区转换(编码)为 JPEG?
我希望有某种库可以以这种方式使用:
int* buffer[720*480]; // read in from file/memory/network stream
raw_params params;
params.depth = 16;
params.width = 720;
params.height = 480;
params.map = "rgb";
params.interleave = JPEG_RAW_INTERLEAVE_OFF;
jpeg_encode(buffer, params)
但我似乎找不到它。
澄清
我也在寻找一个如何使用这样的库的简单示例。像 netpbm
和 magick
的源代码一样强大的代码对于我的理解水平来说太复杂了。
I would expect that there's some sort of library that I can use in this fashion:
int* buffer[720*480]; // read in from file/memory/network stream
raw_params params;
params.depth = 16;
params.width = 720;
params.height = 480;
params.map = "rgb";
params.interleave = JPEG_RAW_INTERLEAVE_OFF;
jpeg_encode(buffer, params)
But I can't seem to find it.
Clarification
I'm looking for a simple example of how to use such a library as well. Code as robust as the source of netpbm
and magick
are too complex for my level of understanding.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
是的,有一个库可以实现这一点(幸运的是!): http://freshmeat.net/projects/libjpeg/< /a> 等于 (?) 到 http://sourceforge.net/projects/libjpeg/
Yes, there is a library for this (luckily!): http://freshmeat.net/projects/libjpeg/ equal (?) to http://sourceforge.net/projects/libjpeg/
来自 Independent JPEG Group 的 libjpeg 库是 JPEG 标准的参考实现,由过去和现在的人们编写参与标准的制定。它坚固、稳定且高度便携。
它作为源工具包提供,其中包括大量文档和示例。
它对源图像的首选表示是作为指向像素数组的数组指针,而不是如您所示的单个整体数组。但是,您可以轻松创建指向行的指针数组来寻址图像缓冲区。
它具有高度可配置性和可扩展性。具体来说,它允许通过回调配置数据源和目标。这给第一次使用增加了一些复杂性,但并不难处理。
当然也有可用的商业库,而且我知道有商业可用的 IP 用于在硬件中实现 JPEG。商业图书馆可能会更快,但永远不会更便宜。
The libjpeg library from the Independent JPEG Group is the reference implementation of the JPEG standard, written by folks who were and are involved in the creation of the standard. It is robust, stable, and highly portable.
It comes as a source kit, which includes extensive documentation and samples.
Its preferred representation for a source image is as an array pointers to of arrays of pixels, not as a single monolithic array as you show. You can easily create the array of pointers to rows to address your image buffer, however.
It is highly configurable and extensible. Specifically, it allows both the data source and the destination to be configured through call backs. This adds some complexity to a first use, but it isn't all that hard to deal with.
There are certainly commercial libraries available as well, and I know that there is commercially available IP for implementation of JPEG in hardware. A commercial library is likely to be faster, but will never be cheaper.
这是一个相当简单的示例,已在网络上的多个位置复制:
文档的这个特定页面与理解所需结构相关:
Here's a fairly simple example that's copied in a number of places on the web:
And this particular page of the documentation is relevant to understanding the require structs: