L_PutBitmapRowColCompressed

#include "l_bitmap.h"

L_LTKRN_API L_SSIZE_T L_PutBitmapRowColCompressed(pBitmap, pWorkBuffer, pRunBuffer, nRow, nCol, uWidth)

pBITMAPHANDLE pBitmap;

/* pointer to the bitmap handle */

L_UCHAR* pWorkBuffer;

/* pointer to a work buffer */

L_UINT16* pRunBuffer;

/* pointer to the source buffer */

L_INT nRow;

/* number of the row to update */

L_INT nCol;

/* column offset within the row to update */

L_UINT uWidth;

/* number of pixels to update */

Puts a row (or part of a row) of 1-bit compressed data from a buffer to a bitmap that is maintained in its compressed format.

Parameter

Description

pBitmap

Pointer to the bitmap handle referencing the bitmap to be updated.

pWorkBuffer

NULL or a pointer to an optional work buffer. Allocating the work buffer speeds processing if you call this function more than once, because if you do not allocate a work buffer, the function allocates and frees a temporary buffer each time it is called. The size of this buffer should be the same as the bitmap handle's BytesPerLine field.

pRunBuffer

Pointer to the input buffer, which contains 1-bit compressed image data.

nRow

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

nCol

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

uWidth

The number of pixels to retrieve.

Returns

> 0

The number of pixels processed.

< 1

An error occurred. Refer to Return Codes.

Comments

This function is useful for working with 1-bit images that are loaded in their compressed formats for faster loading and display. For more information, refer to Speeding Up 1-Bit Documents.

Required DLLs and Libraries

LTKRN

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:

L_ExpandRow, L_CompressRow, L_GetBitmapRowColCompressed, L_GetBitmapRowCompressed, L_PutBitmapRowCompressed

Topics:

Speeding Up 1-Bit Documents

Example

This example demonstrates the low-level functions for accessing 1-bit compressed bitmap data. It demonstrates the ability to get and put partial rows, and the ability to process partial rows in buffer-to-buffer processing. The result of the function is an inverted rectangle in the middle of the image.

 L_INT PutBitmapRowColCompressedExample(L_TCHAR*      pszFilename,
                                                       HWND          hWnd,
                                                       pBITMAPHANDLE pLeadBitmap)
{
   L_INT nRet;
   L_INT     XOffset;      /* Column offset of the rectangle to process */
   L_INT     XSize;        /* Pixel width of the rectangle to process */
   L_INT     YOffset;      /* Row offset of the rectangle to process */
   L_INT     YSize;        /* Pixel height of the rectangle to process */
   L_UCHAR*  pBuffer;      /* Buffer to hold the expanded row */
   L_UINT16* pRunBuffer;   /* Buffer to hold the compressed row */
   L_UCHAR*  pWorkBuffer;  /* Work buffer */
   HGLOBAL   hBuffer;      /* Handle to the pBuffer */
   HGLOBAL   hRunBuffer;   /* Handle to the pRunBuffer */
   HGLOBAL   hWorkBuffer;  /* Handle to the pWorkBuffer */
   L_INT     i, n;         /* Counters */

   /* Load the bitmap, at 1 bit per pixel */
   if(pLeadBitmap->Flags.Allocated)
      L_FreeBitmap(pLeadBitmap);
   nRet = L_LoadFile( pszFilename, pLeadBitmap, sizeof(BITMAPHANDLE),1,0,
                     LOADFILE_COMPRESSED | LOADFILE_ALLOCATE | LOADFILE_STORE,
                     NULL, NULL, NULL, NULL);
   if(nRet != SUCCESS)
      return nRet;
   /* This example does not work with rotated view perspectives */
   if ( (pLeadBitmap->ViewPerspective != TOP_LEFT) || (pLeadBitmap->ViewPerspective != BOTTOM_LEFT) )
   {
      nRet = L_ChangeBitmapViewPerspective ( NULL, pLeadBitmap, sizeof(BITMAPHANDLE), TOP_LEFT );
      if(nRet != SUCCESS)
      {
         L_FreeBitmap(pLeadBitmap);
         return nRet;
      }
   }
   /* Specify a rectangle in the middle right part of the displayed image */
   XOffset = pLeadBitmap->Width / 3;
   XSize = pLeadBitmap->Width * 2 / 3;
   YOffset = pLeadBitmap->Height / 3;
   YSize = pLeadBitmap->Height / 3;
   /* Adjust the YOffset if the view perspective is bottom left */
   if (pLeadBitmap->ViewPerspective == BOTTOM_LEFT)
   {
      YOffset = pLeadBitmap->Height - YOffset - YSize;
   }
   /* Allocate the buffers */
   hBuffer = GlobalAlloc(GMEM_MOVEABLE, ( XSize + 7) / 8);
   pBuffer = (L_UCHAR*)GlobalLock( hBuffer );
   hRunBuffer = GlobalAlloc(GMEM_MOVEABLE, (XSize + 3) * 2);
   pRunBuffer = (L_UINT16*)GlobalLock( hRunBuffer );
   hWorkBuffer = GlobalAlloc(GMEM_MOVEABLE, pLeadBitmap->BytesPerLine);
   pWorkBuffer = (L_UCHAR* )GlobalLock( hWorkBuffer );
   /* Invert the colors of pixels in the left half of the rectangle. */
   /* Notice that we get the whole rectangle, but process only half of it. */
   L_AccessBitmap(pLeadBitmap);
   for(i=YOffset; i < (YOffset + YSize); i++)
   {
      nRet = (L_INT)L_GetBitmapRowColCompressed(pLeadBitmap, pWorkBuffer,
                                          pRunBuffer, i, XOffset, XSize);
      if(nRet < 1)
      {
         L_FreeBitmap(pLeadBitmap);
         return nRet;
      }
      nRet = L_ExpandRow(pRunBuffer, pBuffer, 0, XSize/2);
      if(nRet != SUCCESS)
      {
         L_FreeBitmap(pLeadBitmap);
         return nRet;
      }
      for(n=0; n < (XSize /16); n++)
         pBuffer[n] = pBuffer[n] ^ 0xFF;
      nRet = L_CompressRow(pRunBuffer, pBuffer, 0, XSize/2);
      if(nRet < 1 )
      {
         L_FreeBitmap(pLeadBitmap);
         return nRet;
      }
      nRet =(L_INT)L_PutBitmapRowColCompressed(pLeadBitmap, pWorkBuffer, pRunBuffer, i, 
                                                XOffset, XSize/ 2);
      if(nRet < 1)
      {
         L_FreeBitmap(pLeadBitmap);
         return nRet;
      }
   }
   L_ReleaseBitmap(pLeadBitmap);
   /* Free memory that we no longer need */
   GlobalFree(hBuffer);
   GlobalFree(hRunBuffer);
   GlobalFree(hWorkBuffer);
   /* Update the paint palette to force a repaint */
   SendMessage (hWnd, WM_QUERYNEWPALETTE, 0, 0L);
   return SUCCESS;
}