Compressing Data

The following example compresses image data for use in an AVI file. It assumes the compressor does not support the VIDCF_CRUNCH or VIDCF_TEMPORAL flags, but it does support VIDCF_QUALITY. The example uses the ICCompressBegin1126X71 macro, the ICCompress1JVGS24 function, and the ICCompressEnd1PTKMBW macro.

DWORD dwCkID;

DWORD dwCompFlags;

DWORD dwQuality;

LONG  lNumFrames, lFrameNum;

// Assume dwNumFrames is initialized to the total number of frames.

// Assume dwQuality holds the proper quality value (0-10000).

// Assume lpbiOut, lpOut, lpbiIn, and lpIn are initialized properly.

 

// If OK to start, compress each frame.

if (ICCompressBegin(hIC, lpbiIn, lpbiOut) == ICERR_OK)

    for ( lFrameNum = 0; lFrameNum < lNumFrames; lFrameNum++)

   

        if (ICCompress(hIC, 0, lpbiOut, lpOut, lpbiIn, lpIn,

            &dwCkID, &dwCompFlags, lFrameNum,

            0, dwQuality, NULL, NULL) == ICERR_OK)

       

            // Write compressed data to the AVI file.

            

            // Set lpIn to the next frame in the sequence.

            

        }

        else

       

            // Handle compressor error.

        }

    }

    ICCompressEnd(hIC);    // terminate compression

}

else

    // Handle the error identifying the unsupported format.

}