Working with Floating Point Bitmaps

Bitmaps with floating point pixel values, usually GeoTIFF or TIFF, store float pixel values as 32-bit single precision float (L_FLOAT). LEADTOOLS supports L_AccessBitmap, L_CreateBitmap, and other operations on bitmaps with floating point pixel values.

Identify Bitmaps Containing Floating Point Values

A bitmap has floating point values if it has BITMAPHANDLE.Flags.Float set to 1.

To find out if a file has floating point pixels, call L_FileInfo or L_FileInfoMemory and examine whether the FILEINFO.Flags has the FILEINFO_FLOAT flag set.

Load or Create a Bitmap with Floating Point Values

Load or create a bitmap with floating point values as follows:

Alternatively, provide all the bitmap data by using L_CreateBitmap and pass the floating point data as the pData parameter. After calling L_CreateBitmap, manually set BITMAPHANDLE.Flags.Float = 1.

/* This sample code creates and allocates a floating point bitmap using an array of floats */ 
BITMAPHANDLE bitmap; 
L_INT nRet = L_CreateBitmap(&bitmap, sizeof(BITMAPHANDLE), TYPE_CONV, uWidth, uHeight, 32, 
      ORDER_GRAY, NULL, TOP_LEFT, pData, (L_SIZE_T)uWidth * uHeight * 4); 
if(nRet == SUCCESS) 
{ 
   bitmap.Flags.Float = 1;       
   /* use the bitmap and free it when done */ 
   L_FreeBitmap(&bitmap);  
} 

Formats Supporting Floating Point Data

The following formats support bitmap floating point data to load and save:

Operations Supported in Bitmap Floating Points

The supported operations below are guaranteed to work as specified. Besides those, other operations might work or fail and may return an error code or produce incorrect results.

  1. Allocate or free: L_AllocateBitmap and L_FreeBitmap.
  2. Access or release: L_AccessBitmap and L_ReleaseBitmap to use the GetRow or PutRow functionality.
  3. Get or put the bitmap row data: L_GetBitmapRow, L_PutBitmapRow, L_GetBitmapRowCol, and L_PutBitmapRowCol.
  4. Convert pixel values to integer: L_GrayScaleBitmap.

Note

The convertion of floating points to integer has side effects that need to be carefully considered before applying the operation.

> 1. This operation will convert and rescale the floating point values to unsigned integers.
> 2. The floating point values are rescaled so the maximum value for the bitmap is converted to white, the minimum values to black and the others to grayscale values. The maximum value will be converted to: 0xFF (8-bit bitmaps), 0xFFF (12-bit bitmaps), 0xFFFF (16-bit bitmaps), 0xFFFFFFFF (32-bit bitmaps).

Access to the Floating Point Values in the Bitmap

The example code below demonstrates the process of loading a bitmap with floating points data and accessing the values.

/* This sample code assumes pBitmap is not allocated. If successful, the function will  
   load a bitmap into the pBitmap parameter and assumes the caller will free it 
*/ 
L_INT TestLoadFloat(pBITMAPHANDLE pBitmap) 
{ 
   /* Init a LOADFILEOPTION structure and set the ELO2_NO_IMAGE_DATA_CONVERSION flag */ 
   LOADFILEOPTION loadFileOption; 
   L_GetDefaultLoadFileOption(&loadFileOption, sizeof(LOADFILEOPTION)); 
   loadFileOption.Flags2 |= ELO2_NO_IMAGE_DATA_CONVERSION; 
 
   BITMAPHANDLE bitmap; 
   L_TCHAR* pszFileName = L_TEXT("FloatingPoint.tif"); 
   FILEINFO fileInfo = { sizeof(FILEINFO) }; 
   L_INT nRet = L_LoadBitmap(pszFileName, pBitmap, sizeof(BITMAPHANDLE), 0, ORDER_BGRORGRAY, &loadFileOption, &fileInfo); 
   if(nRet == SUCCESS) 
   { 
      /* Something went wrong if these asserts are triggered */ 
      assert(fileInfo.Flags & FILEINFO_FLOAT); 
      assert(pBitmap->Flags.Float); 
 
      nRet = L_AccessBitmap(pBitmap); 
      if (nRet == SUCCESS) 
      { 
         L_FLOAT buf[600]; 
         nRet = L_GetBitmapRowCol(pBitmap, (L_UCHAR*)buf, 186, 0, sizeof(buf)); 
         L_ReleaseBitmap(pBitmap); 
         if (nRet != (L_INT)sizeof(buf)) 
            return nRet < 0 ? nRet : ERROR_INTERNAL; 
         printf("Line 186: [146] = %f, [421] = %f, [568] = %f\n", buf[146], buf[421], buf[568]); 
 
         /* Now do something with the bitmap: convert it to grayscale, modify it, resave it, etc */ 
#if 0 
         // Convert the bitmap to grayscale so I can use do image processing on it 
         nRet = L_GrayScaleBitmap(pBitmap, 8); 
#else 
         L_TCHAR* pszDstFileName = L_TEXT("out.tif"); 
         nRet = L_SaveBitmap(pszDstFileName, pBitmap, FILE_TIF_ZIP, 0, 0, NULL); 
#endif // #if 1 
      } 
   } 
   return nRet; 
} 

See Also

Structures

Functions

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

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