FILEREADCALLBACK

#include "l_bitmap.h"

L_INT pEXT_CALLBACK YourFunction (pFileInfo, pBitmap, pBuffer, uFlags, nRow, nLines, pUserData)

Handles the output image data that the calling function has written to a buffer.

Parameters

pFILEINFO pFileInfo

The pointer to the FILEINFO structure that contains image information.

pBITMAPHANDLE pBitmap

The pointer to the bitmap handle referencing the bitmap that contains the image information.

L_UCHAR* pBuffer

A pointer to a buffer containing one or more lines of output image data that the calling function has already processed (read or decompressed).

L_UINT uFlags

Flags that describe whether this is the first or last call of the callback, and whether the buffer contains first or last row of image data. The following are possible flags:

Constant Meaning
FILEREAD_FIRSTPASS [0x0001] This is the first pass through a progressive JPEG or CMP file.
FILEREAD_LASTPASS [0x0002] This is the last pass through a progressive JPEG or CMP file.
FILEREAD_FIRSTROW [0x0004] The first row of the buffer is the first row of the bitmap.
FILEREAD_LASTROW [0x0008] The last row of the buffer is the last row of the bitmap.
FILEREAD_COMPRESSED [0x0010] The data in the buffer is 1-bit compressed data, which you can handle as explained in Speeding Up 1-Bit Documents.
FILEREAD_CLIPVERT [0x0020] Internal flag.
FILEREAD_CLIPHORZ [0x0040] Internal flag.
FILEREAD_UPDATELUT [0x0080] Internal flag.

L_INT nRow

The current bitmap row number of the first line in the buffer.

L_INT nLines

The number of lines in the pBuffer buffer.

L_VOID* pUserData

A void pointer that you can use to access a variable or structure containing data that your callback function needs. This gives you a way to receive data indirectly from the function that uses this callback function. (This is the same pointer that you pass in the pUserData parameter of the calling function.)

Keep in mind that this is a void pointer, which must be cast to the appropriate data type within your callback function.

Returns

Returns SUCCESS to indicate the function was successful.

Returns any other value to terminate the calling function. The calling function will pass this value along to its caller. For a list of error values you may want to use, refer to the Return Codes.

Comments

Several LEADTOOLS functions use this type of callback function. In some cases, The pBuffer buffer contains data that your callback function must output in order for the calling function to accomplish anything. In other cases, where the callback is optional, the callback gets a copy of the data, and the callback's output is in addition to the calling function's output. Refer to the description of the calling function to see how it uses the callback.

The FILEINFO structure that gets passed to the FILEREADCALLBACK function does not contain the total number of pages. To get the total number of pages, you should call L_FileInfo and set the FILEINFO_TOTALPAGES flag.

Required DLLs and Libraries

See Also

Functions

Example

This FILEREADCALLBACK function paints the image as it loads

/**************** Global declarations **************************************/ 
 
/* Structure used for the callback function's user data */ 
typedef struct tagIMAGECBPARM 
{ 
   HWND hwnd;        /* Current window */ 
   HDC hdc;          /* Device context for the current window */ 
   L_INT nRow;       /* First row in the input buffer */ 
   HPALETTE hpalPaint;  /* Paint palette handle */ 
   HINSTANCE hInst;     /* Current instance of the application, set by the InitInstance function */ 
   RECT rLeadDest;      /* Destination rectangle for painting */      
   RECT rLeadSource;    /* Source rectangle for painting */ 
} IMAGECBPARMEX; 
 
/*******************************************************************************/ 
 
L_INT EXT_CALLBACK LoadImageCB(pFILEINFO pFileInfo, 
                               pBITMAPHANDLE pBitmap, L_UCHAR  *pBuffer, 
                               L_UINT uFlags, L_INT nRow, L_INT nLines, IMAGECBPARMEX * pUserData ) 
{ 
   /* If this is the first call (row 0), select and realize the palette */ 
   if((uFlags & FILEREAD_FIRSTPASS) && (uFlags & FILEREAD_FIRSTROW) ) 
   { 
         /* Set the source rectangle to use the whole bitmap */ 
         SetRect(&pUserData->rLeadSource, 0, 0, pFileInfo->Width, pFileInfo->Height); 
         SendMessage (pUserData->hwnd, WM_QUERYNEWPALETTE, 0, 0L); 
         SelectPalette( pUserData->hdc, pUserData->hpalPaint, TRUE ); 
         RealizePalette(pUserData->hdc); 
   } 
 
   /* Paint the buffer to the specified device context */ 
 
   L_PaintDCBuffer( pUserData->hdc, /* Device context - from function parameter */ 
                    pBitmap, /* Bitmap handle - from function parameter */ 
                    &pUserData->rLeadSource, /* Source rect - set globally in WM_CREATE */ 
                    &pUserData->rLeadSource, /* Source clip rect - same as source rect */ 
                    &pUserData->rLeadDest, /* Destination rect - set globally in WM_CREATE */ 
                    &pUserData->rLeadDest, /* Destination clip rect - same as destination rect */ 
                    SRCCOPY, /* ROP code for normal painting */  
                    pBuffer, /* Input buffer - from function parameter */  
                    nRow, /* First row in the buffer - from function parameter */  
                   (uFlags & FILEREAD_COMPRESSED) ? -nLines : nLines ); 
   return( SUCCESS ); 
} 

Help Version 21.0.2023.2.15
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2021 LEAD Technologies, Inc. All Rights Reserved.

LEADTOOLS Raster Imaging C API Help
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2021 LEAD Technologies, Inc. All Rights Reserved.