To add to Tal's answer, what you should do is take a look at the implementation of the jpeg_stdio_src()
function in jdatasrc.c
. The purpose of that function is to initialize the data source object, namely cinfo->src
. So, what you should do is the following:
- Create a structure (similar to the
my_source_mgr
structure in jdatasrc.c
) which has as its first member an instance of struct jpeg_source_mgr
. Add any other members that you feel are necessary. Note that we're essentially doing manual inheritance -- in C++, we would define a class that derives from jpeg_source_mgr
, and the various function pointers declared in jpeg_source_mgr
would instead be virtual functions. But, we're using C, so we have to do inheritance and polymorphism the hard way.
- Allocate space for an instance of your structure, making sure to allocate the right number of bytes, and fill out your data members.
Implement the following five functions:
void init_source(j_decompress_ptr)
boolean fill_input_buffer(j_decompress_ptr)
void skip_input_data(j_decompress_ptr, long)
boolean resync_to_start(j_decompress_ptr, int)
void term_source(j_decompress_ptr)
Note that for an in-memory buffer, these functions will probably be very trivial.
- Finally, initialize the function pointers in your
jpeg_source_mgr
member to point to those functions.
With this in place, you can then use this instead of jpeg_stdio_src()
to initialize the data source manager, and then you should be good to go as if you were decoding a file from the file system.