RESIZECALLBACK Callback Function

#include "l_bitmap.h"

L_INT pEXT_CALLBACK YourFunction(pBitmap, pBuffer, nRow, nCol, uBytes, pUserData)

pBITMAPHANDLE pBitmap;

/* bitmap handle */

L_UCHAR L_FAR *pBuffer;

/* buffer for data */

L_INT nRow;

/* number of the row to retrieve*/

L_INT nCol;

/* column offset within the row to retrieve */

L_UINT32 uBytes;

/* number of bytes to retrieve */

L_VOID L_FAR *pUserData;

/* pointer to additional parameters */

Replaces the normal LEADTOOLS function for writing a file.

Parameter

Description

pBitmap

Pointer to a bitmap handle.

pBuffer

Buffer that contains image data.

nRow

The number of the row to retrieve. The first row is 0, and the last row is 1 less than the bitmap height.

nCol

The column offset within the row to retrieve. The first column offset is 0, and the last column offset is 1 less than the bitmap width.

uBytes

The number of bytes to retrieve. Consider the bits per pixel, and avoid specifying a number that goes past the end of the row.

 

For a 1-bit bitmap, each byte represents 8 pixels. For a 4-bit bitmap, each byte represents 2 pixels. For an 8-bit bitmap, each byte represents 1 pixel. For a 16-bit bitmap, every 2 bytes represents one pixel. For 24-bit images, every three bytes represents one pixel. For a 32-bit bitmap, every four bytes represents one pixel. For 48-bit images, every six bytes represents one pixel. For 64-bit images, every eight bytes represents one pixel.

 

You can use the bitmap handle’s BitsPerPixel field with integer math to calculate the number of bytes needed for a particular number of pixels. For example:

 

NumberOfBytes = (Bitmap.BitsPerPixel * NumberOfPixels) / 8;

 

if ((Bitmap.BitsPerPixel * NumberOfPixels) % 8)

 

      ++NumberOfBytes; /* Round up if necessary for a 1- or 4-bit image */

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

>0

The number of bytes that the function wrote to the file.

-1

The function failed.

Comments

This is an optional callback function used by the L_StartResizeBitmap function. It is called by L_StartResizeBitmap to get the data from the bitmap. One possible use of this is to resize bitmaps that are too large to fit into memory. You can use the callback to feed to the resizing engine one line at a time.

This serves as a replacement for L_GetBitmapRowCol, which may be unable to retrieve certain images, such as extremely large images. This callback allows you to retrieve portions of an image for resizing.

Example

L_INT pEXT_CALLBACK RESIZECALLBACK (
   pBITMAPHANDLE pBitmap, 
   L_UCHAR L_FAR *pBuffer, 
   L_INT nRow, 
   L_INT nCol,
   L_UINT32 uBytes, 
   L_VOID L_FAR *pUserData)
{

   L_INT32 uBytesRead = L_GetBitmapRowCol(pBitmap, pBuffer, nRow, nCol, uBytes);
   return uBytesRead == uBytes ? SUCCESS : FAILURE; 
}