Example: AVI CreationThe AVImake example converts a flic file to an equivalent AVI file. The conversion takes place in the program's ConvertClick() function, which first gets a flic file name through an Open File dialog box. After confirming that this file really is a flic file, we create a 256-color virtual buffer with the same dimensions as the flic file. Next, we open the flic file with fg_flicopen() and play its first frame with fg_flicplay(). We then build the AVI file name string and call fg_avimake() to create an empty 256-color AVI file with a playback rate of 30 frames per second. Because we pass a codec value of -1, fg_avimake() will display a dialog box to let the user select the AVI compression options. Next we allocate memory for 256-color bitmap whose size is equal to the flic resolution. We then write the AVI frames by playing the flic frames, one at a time, into the active virtual buffer. In this loop, we retrieve the current flic frame as a 256-color bitmap with fg_getimage(), and then write the AVI frame with fg_aviframe(), compressing it in the process. After we've converted all frames, we close both files and release the bitmap memory. AVImake uses a 256-color virtual buffer and a 256-color bitmap because flic files are always 256 colors. But what if we want to save a high color or true color animation sequence in an AVI file? To do this, we must increase the size of the Bitmap array and retrieve the bitmap with fg_getdcb() instead of fg_getimage(). If we're using a true color virtual buffer, that's all we need to change. However, if we're using a high color virtual buffer, we must also translate the direct color bitmap retrieved by fg_getdcb() from high color to true color format with fg_transdcb(). This is necessary because fg_aviframe() always expects a 24-bit direct color bitmap for the frame data when creating a high color or true color AVI. Assuming we have a 5/6/5 high color virtual buffer active, here's how the AVImake frame writing loop might look:
C/C++:
Delphi:
Visual Basic:
|
 
copyright 2001 Ted Gruber Software, Inc.