L_PicturizeBitmap

#include "l_bitmap.h"

L_LTIMGEFX_API L_INT L_PicturizeBitmap(pBitmap, pszDirName, uFlags, nCellWidth, nCellHeight, pfnCallback, pUserData)

pBITMAPHANDLE pBitmap;

pointer to the bitmap handle

L_TCHAR *pszDirName;

specific directory

L_UINT uFlags;

flags

L_INT nCellWidth;

width of the rectangles

L_INT nCellHeight;

height of the rectangles

PICTURIZECALLBACK pfnCallback;

notification callback function

L_VOID *pUserData;

pointer to more parameters for the callback

Replaces the current image with an image created using images present in the specified directory.

Parameter Description
pBitmap Pointer to the bitmap handle referencing the bitmap to which the process will be applied.
pszDirName Character string containing the directory that contains the images. Only images from this directory will be used. Images in any subdirectories will NOT be used.
uFlags Flags that control the behavior of the process. Possible values are given below. These values can be combined using OR (|) or +.
  Value Meaning
  PICTURIZE_LOADALL [0x0001] Load all files in memory. This causes a big improvement in the speed of the process. It is recommended to use it if you have enough memory to hold all the images
  PICTURIZE_RESIZE [0x0002] Resize the images that are not the required size (nCellWidth x nCellHeight).
  PICTURIZE_RESAMPLE [0x0004] Resample the images that are not the required size (nCellWidth x nCellHeight). (slower process, better quality)
  PICTURIZE_ONCE [0x0010] Use the image only once throughout the process.
  PICTURIZE_EQUALUSAGE [0x0020] Use all images equally. That is, before an image will be used twice, all other images must be used at least once.
  PICTURIZE_BESTFIT [0x0040] Images will be resized to fit the image if the bitmap width or height is not a multiple of nCellWidth/nCellHeight.
  0 The picturize process will not use any of the above flags. It will: reload all the files each time you look for a rectangle to substitute and ignore all the images present in pszDirectory if their size is not nCellWidth x nCellHeight
nCellWidth Width of the images used to reconstruct the image.
nCellHeight Height of the images used to reconstruct the image.
pfnCallback Callback function which can be used for keeping track of the process, in addition to the status callback function.
pUserData Void pointer that you can use to pass one or more additional parameters that the callback function needs.
  To use this feature, assign a value to a variable or create a structure that contains as many fields as you need. Then, in this parameter, pass the address of the variable or structure, casting it to L_VOID  *. The callback function, which receives the address in its own pUserData parameter, can cast it to a pointer of the appropriate data type to access your variable or structure.
  If the additional parameters are not needed, you can pass NULL in this parameter.

Returns

SUCCESS

The function was successful.

< 1

An error occurred. Refer to Return Codes.

Comments

This function does not support signed data images. It returns the error code ERROR_SIGNED_DATA_NOT_SUPPORTED if a signed data image is passed to this function.

The image, or selected region, is broken down into rectangles of size nCellWidth x nCellHeight. For each rectangle, the image in the directory that is best suited to replace that rectangle is inserted into the original image.

pBitmap is updated only once for every row of lines, where each line has a height dimension of nCellHeight. Therefore, the pfnCallback can be used to show the progress of every cell. For more information, refer to the PICTURIZECALLBACK callback function.

If a region is selected, only the selected region will be changed by this function. If no region is selected, the whole image will be processed.

On an 8 BPP display, it is recommended that you create a fixed palette before you start the picturize process and use it to paint all the bitmaps. All the bitmaps which will be passed to the picturize callback will be 24BPP so a fixed palette is best. It is faster to create the palette before you start painting rather than creating it every time you paint a little square.

If PICTURIZE_BESTFIT is set, then nCellWidth and nCellHeight are used as a starting point for the actual cell size. The cell sizes are modified so that the size of the last rectangle in a row or column differs from the other rectangles by one. Note that the cell width and height are chosen to be smaller than nCellWidth and nCellHeight. For example, if the bitmap is 101x131 and you pass 32 for the cell width and height and set PICTURIZE_BESTFIT, then the actual cell size will be 25x32. The widths of the cells will be 26, 25, 25, 25 (for a total of 101). The heights of the rows will be 33, 33, 33, 32 (for a total of 131). This option should be used if the bitmap width and height are not multiples of nCellWidth and nCellHeight.

If the bitmap width and height are not multiples of nCellWidth and nCellHeight and PICTURIZE_BESTFIT is not passed, then the last rectangle in a row or column might be very small. Using the example given above, if PICTURIZE_BESTFIT is not set, the widths of the cells would be 32, 32, 32, 5 and the heights would be 32, 32, 32, 32, 3.

PICTURIZE_EQUALUSAGE and PICTURIZE_ONCE will reduce the number of times a bitmap is used by this function.

When PICTURIZE_ONCE is set, the function will try not to use the same bitmap twice. Note that if there arent enough images, the function will return the ERROR_NOT_ENOUGH_IMAGES code if this flag is set.

When PICTURIZE_EQUALUSAGE is set, the function will use the same image more than once only if it is necessary to successfully complete the picturize process. If PICTURIZE_EQUALUSAGE is set, then for any bitmap, the number of times it is used differs from the number of times another bitmap is used by at most one. Therefore, most bitmaps will be used n times, but some bitmaps that will be used n+1 times.

This function supports 12 and 16-bit grayscale and 48 and 64-bit color images. Supportfor 12 and 16-bit grayscale and 48 and 64-bit color images is available in the Document and Medical Imaging toolkits.

This function does not support 32-bit grayscale images. It returns the error code ERROR_GRAY32_UNSUPPORTED if a 32-bit grayscale image is passed to this function.

Required DLLs and Libraries

LTIMGEFX

For a listing of the exact DLLs and Libraries needed, based on the toolkit version, refer to Files To Be Included With Your Application.

Platforms

Win32, x64.

See Also

Functions:

PICTURIZECALLBACK, L_BricksTextureBitmap, L_CanvasBitmap, L_DisplaceMapBitmap, L_FragmentBitmap, L_VignetteBitmap

Topics:

Raster Image Functions: Processing an Image

Example

This example will assume that the original bitmap was painted at 100% zoom factor and that there are no scroll bars. It also assumes that we are painting on a display that doesn't need palettes. We imposed all the above limitations for simplicity and to make the code easier to understand.

#define MAKE_IMAGE_PATH(pFileName) TEXT("C:\\Users\\Public\\Documents\\LEADTOOLS Images\\")pFileName 
L_INT EXT_CALLBACK UpdateRectCallback(pBITMAPHANDLE pThumb, 
L_UINT        x, 
L_UINT        y, 
L_VOID      * pUserData) 
{ 
   HWND  hWnd = (HWND)pUserData; 
   RECT  rcDest; 
   HDC   hdc = GetDC(hWnd); 
   // assume that the original bitmap was viewed at 100% zoom factor. 
   // Also assume that we are painting on a 24BPP display. 
   SetRect(&rcDest, x, y, x + pThumb->Width, y + pThumb->Height); 
   // paint the bitmap at (x,y) coordinates 
   L_PaintDC(hdc, pThumb, NULL, NULL, &rcDest, NULL, SRCCOPY); 
   ReleaseDC(hWnd, hdc); 
   // return an error code if you want to abort the process 
   return SUCCESS; 
} 
L_INT  PicturizeBitmapExample(HWND hWnd,pBITMAPHANDLE pBitmap) 
{ 
   L_INT nRet; 
   // Picturize the bitmap in pBitmap 
   //    - use all the images in c:\thumbs directory 
   //    - load all images and resize the ones that are not the desired size 
   //    - use 32x32 images 
   //    - use UpdateRectCallback callback to show the progress 
   nRet = L_PicturizeBitmap(pBitmap, 
   MAKE_IMAGE_PATH(TEXT("ImageProcessingDemo")), 
   PICTURIZE_LOADALL|PICTURIZE_RESIZE, 
   32, 32, 
   (PICTURIZECALLBACK)UpdateRectCallback, 
   (L_VOID *)hWnd); 
   if(nRet != SUCCESS ) 
      return nRet; 
   return SUCCESS; 
} 

Help Version 19.0.2017.10.27
Products | Support | Contact Us | Copyright Notices
© 1991-2017 LEAD Technologies, Inc. All Rights Reserved.
LEADTOOLS Raster Imaging C API Help