The LEAD and JPEG (JFIF) file formats can be extended to support progressive loading and saving of images. Progressive loading is useful for transmitting images, because the first part of the file contains the full dimensions of the image. Therefore, in a paint-while-load routine, you can display the whole image, then progressively clarify it as the rest of the file loads.
Since the progressive formats are newer, some existing applications do not support them. Therefore, especially when saving a file that may be read by another application, you must pay attention to the Passes field in the SAVEFILEOPTION structure.
All of the class library save functions take a pSAVEFILEOPTION argument, which defaults to NULL.
When NULL is passed for this argument, the Passes field of the SAVEFILEOPTION structure defaults to 0, which means the file saved will not be progressive. Alternatively, you can do the following:
//Set any of the SaveOption fields
//pass &SaveOption to any of the Save member functions
Since the default for Passes=0, the saved file will not be progressive.
Technically, only files with more than three passes are progressive files. They include full color in the low-resolution first pass; subsequent passes improve the resolution. Files that contain two or three passes are multiscan files. They include grayscale information in the first pass, and color information in the subsequent pass or passes.
If you want to save a progressive file or take advantage of this feature when loading a progressive file, you can control the number of passes that are required to complete the image. For more information, refer to the Passes field in the SAVEFILEOPTION structure.
NOTE: 4:1:1 and 4:2:2 formats use subsampling for the color components. In the case of 4:1:1, the color components for 4 pixels are averaged during compression. This will cause a color shift, but the shift is tolerable for low compression ratios. If you have high compression and repeated savings, then the color shift will increase. Due to this characteristic of the JPEG algorithm, the only ways to avoid this are to: (a) use 4:4:4 (which has no subsampling), or (b) avoid repeated load and resave.
JBIG also supports progressive loading of an image. For more information on this, refer to Implementing JBIG Features.
JPEG 2000 also supports progressive loading of images. For more information on this, refer to Compression Using LEAD and JPEG Formats.
The following example shows how to save a progressive LEAD then implement a progressive paint-while-load:
class LProgressiveFile : public LFile
virtual L_INT LoadFileCallBack(pFILEINFO pFileInfo, LBitmapBase * pLBitmap, LBuffer * pLBuffer, L_UINT uFlags, L_INT nRow, L_INT nLines);
L_VOID SetDisplayWnd(HWND hWnd);
L_INT LoadFile(L_INT nBitsPerPixel=0, L_INT nOrder=ORDER_BGRORGRAY, L_UINT uFlags=LOADFILE_ALLOCATE | LOADFILE_STORE, pLOADFILEOPTION pLoadFileOption = NULL);
L_INT SaveBitmap(L_INT nFormat, L_INT nBitsPerPixel=0, L_INT nQFactor=2, L_UINT uFlags=SAVE_OVERWRITE, pSAVEFILEOPTION pSaveFileOption = NULL);
Now, implement the class member functions as follows:
L_VOID LProgressiveFile::SetDisplayWnd(HWND hWnd)
L_INT LProgressiveFile::LoadFile(L_INT nBitsPerPixel, L_INT nOrder, L_UINT uFlags, pLOADFILEOPTION pLoadFileOption)
if (pLoadFileOption == NULL)
pLoadFileOption = &LoadFileOption;
iOldPasses = pLoadFileOption->Passes;
pLoadFileOption->Passes = iOldPasses;
L_INT LProgressiveFile::SaveBitmap(L_INT nFormat, L_INT nBitsPerPixel, L_INT nQFactor, L_UINT uFlags, pSAVEFILEOPTION pSaveFileOption)
if (pSaveFileOption == NULL)
pSaveFileOption = &SaveFileOption;
iOldPasses = pSaveFileOption->Passes;
L_INT nRet = LFile::Save(nFormat,nBitsPerPixel,nQFactor,uFlags,pSaveFileOption);
pSaveFileOption->Passes = iOldPasses;
L_INT LProgressiveFile::LoadFileCallBack(pFILEINFO pFileInfo, LBitmapBase * pLBitmap, LBuffer * pLBuffer, L_UINT uFlags, L_INT nRow, L_INT nLines)
pLBitmap->Paint()->PaintDCBuffer((uFlags&FILEREAD_COMPRESSED) ? LBufferExp : *pLBuffer, nRow, nLines);
Now, you can use the new class as follows:
L_VOID Example54(HWND hWnd, L_TCHAR * szFilename)
//load the image
//save the image in progressive format (8 passes)
//set the window to be used for displaying the progressive image
//load the progressive file