How can I convert (encode) RGB buffer to JPEG in plain C?
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.
Yes, there is a library for this (luckily!): http://freshmeat.net/projects/libjpeg/ equal (?) to http://sourceforge.net/projects/libjpeg/
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:
- http://oaf.mutualads.org/svn/code/renderer/tr_image_jpg.c
- http://www.torquepowered.com/community/forums/viewthread/45455
And this particular page of the documentation is relevant to understanding the require structs:
- http://apodeline.free.fr/DOC/libjpeg/libjpeg-2.html
精彩评论