This section of the archives stores flipcode's complete Developer Toolbox collection,
featuring a variety of mini-articles and source code contributions from our readers.

Jpeg Animstream Dumper
Submitted by

I've been using this for quite some time, and people who went to S&V 2001 wanted the
code... so I figured I might as well put it up here if not elsewhere.
Basically, this is what I used to dump a stream of Jpeg's to disk. School machines didn't
have VFW api headers, and obviously, undergrads don't have admin privileges to install
anything... *sigh*... So I had to resort to this.
Anyway, I used the Jpeg wrapper class that showed up in an older COTD (albeit before it
actually showed up on COTD). I have a feeling that the code I grabbed was a little older
than the code that the poster was actually using. It had this annoying memory leak that
caused 2 copies of every compressed Jpeg image... Pretty harmless if you're just doing
a snap or two, but it causes some nice overflow problems after dumping about 1300 frames
at 85% quality... ^__^ So that was a simple fix to deal with... and I just wrote the
following function.
The other things you'll need to use it are included in the zip.
Add this to your little demo. The main reason for using globals is just because of the
fact that memory blocks would otherwise keep being allocated and deallocated as they fell
out of scope. This way, at least, there's one and only one copy of the pixmaps and file
pointer., and memory doesn't end up all fragmented.

I also used routines in my demos that were frametime based, and for stream renderings, I
hardcode a value for the frametimes so I can fake a constant framerate for animations.
Anyway, if you want to see some results made with it --

The piece by me is the only one that was actually realtime, so that's the only one that
used this code. Granted, the stuff on the website are low-quality divx dumps and the
sound on my animation is somehow 10 seconds out of sync (first few patterns getting
cut off), but oh well...

/*D*
////////////////////////////////////////////////////////////////////////////
// Name: ENTROPYSTRUCT
//
// Purpose: Stores the decoder state information necessary to "jump"
// to a particular MCU row in a compressed entropy stream.
//
// Context: Used to persist the decoder state within Decode_Scan when
// decoding using ROIs.
//
// Fields:
// offset Offset (in bytes) into the entropy stream
// from the beginning.
// dcval1 DC val at the beginning of the MCU row
// for component 1.
// dcval2 DC val at the beginning of the MCU row
// for component 2.
// dcval3 DC val at the beginning of the MCU row
// for component 3.
// dcval4 DC val at the beginning of the MCU row
// for component 4.
// bit_buffer_64 64-bit Huffman bit buffer. Stores current
// bit buffer at the start of a MCU row.
// Also used as a 32-bit buffer on 32-bit
// architectures.
// bitbuf_bits_valid Number of valid bits in the above bit buffer.
// unread_marker Have any markers been decoded but not
// processed at the beginning of a MCU row?
// This entry holds the unprocessed marker, or
// 0 if none.
//
////////////////////////////////////////////////////////////////////////////
*D*/

/*D*
////////////////////////////////////////////////////////////////////////////
// Name: STATE
//
// Purpose: Stores the active state of the IJL.
//
// Context: Used by all low-level routines to store pseudo-global or
// state variables.
//
// Fields:
// bit_buffer_64 64-bit bitbuffer utilized by Huffman
// encoder/decoder algorithms utilizing routines
// designed for MMX(TM) technology.
// bit_buffer_32 32-bit bitbuffer for all other Huffman
// encoder/decoder algorithms.
// bitbuf_bits_valid Number of bits in the above two fields that
// are valid.
//
// cur_entropy_ptr Current position (absolute address) in
// the entropy buffer.
// start_entropy_ptr Starting position (absolute address) of
// the entropy buffer.
// end_entropy_ptr Ending position (absolute address) of
// the entropy buffer.
// entropy_bytes_processed Number of bytes actually processed
// (passed over) in the entropy buffer.
// entropy_buf_maxsize Max size of the entropy buffer.
// entropy_bytes_left Number of bytes left in the entropy buffer.
// Prog_EndOfBlock_Run Progressive block run counter.
//
// DIB_ptr Temporary offset into the input/output DIB.
//
// unread_marker If a marker has been read but not processed,
// stick it in this field.
// processor_type (0, 1, or 2) == current processor does not
// support MMX(TM) instructions.
// (3 or 4) == current processor does
// support MMX(TM) instructions.
// cur_scan_comp On which component of the scan are we working?
// file Process file handle, or
// 0x00000000 if no file is defined.
// JPGBuffer Entropy buffer (~4K).
//
//
////////////////////////////////////////////////////////////////////////////
*D*/