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.
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 as follows:
To load a file which contains floating point pixel data, set the ELO2_NO_IMAGE_DATA_CONVERSION flag to the LOADFILEOPTION.Flags2 field.
To create a file which contains floating point pixel data, set BITMAPHANDLE.Flags.Float = 1
after creating it, BITMAPHANDLE.BitsPerPixel = 32
, and BITMAPHANDLE.Order = ORDER_GRAY
. After that, fill the bitmap data using L_PutBitmapRow, or L_PutBitmapRowCol.
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);
}
The following formats support bitmap floating point data to load and save:
FILE_TIF_JBIG
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.
GetRow
or PutRow
functionality.
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).
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;
}
Help Collections
Raster .NET | C API | C++ Class Library | HTML5 JavaScript
Document .NET | C API | C++ Class Library | HTML5 JavaScript
Medical .NET | C API | C++ Class Library | HTML5 JavaScript
Medical Web Viewer .NET
Multimedia
Direct Show .NET | C API | Filters
Media Foundation .NET | C API | Transforms
Supported Platforms
.NET, Java, Android, and iOS/macOS Assemblies
Imaging, Medical, and Document
C API/C++ Class Libraries
Imaging, Medical, and Document
HTML5 JavaScript Libraries
Imaging, Medical, and Document