Example: AVI Creation

The 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.

C/C++ version

C++Builder version

Delphi version

Visual Basic version

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++:

BYTE hcBitmap[320*240*2];
BYTE tcBitmap[320*240*3];
while (...)
{
   fg_getdcb(hcBitmap,320,240);
   fg_transdcb(hcBitmap,tcBitmap,16,24,320*240);
   fg_aviframe(ContextAVI,tcBitmap);
}

Delphi:

hcBitmap : array [1..320*240*2] of byte;
tcBitmap : array [1..320*240*3] of byte;
while ... do
begin
  fg_getdcb(hcBitmap,320,240);
  fg_transdcb(hcBitmap,tcBitmap,16,24,320*240);
  fg_aviframe(ContextAVI,tcBitmap);
end;

Visual Basic:

Dim hcBitmap(CLng(320) * CLng(240) * 2) As Byte
Dim tcBitmap(CLng(320) * CLng(240) * 3) As Byte
While ...
   Call fg_getimage(hcBitmap(0), 320, 240)
   Call fg_transdcb(hcBitmap(0), tcBitmap(0), 16, 24,
      CLng(320) * CLng(240))
   Call fg_aviframe(ContextAVI(0), tcBitmap(0))
Wend

<< Prev

Next >>

Contents
Fastgraph Home Page

 

copyright 2001 Ted Gruber Software, Inc.