| Herd Software Development
|=
DaVinci Graphics Library
|==
DaVinci Documentation Home Search Order


Working with 48 bit DIBs

TIFF and PNG formats both officially support bitmaps with 16 bit resolution for each color value (red, green and blue in color case or brightness in grayscale case). The professional release of DaVinci can import and export RGB or grayscale TIFF and PNG files without data loss. The DIB generated will have biBitCount of the BITMAPINFOHEADER structre = 24 (color) or 8 (grayscale), with biPlanes = 2, thus there are up to 48 bits per pixel.

To easify the use of 48-Bit DIBs with Microsoft Windows API calls, DaVinci stores the upper 8 Bits and the lower 8 bits for every color value in a different location. The first half of the DIB memory block contains only the upper 8 bits of the DIB data thus the DIB can easily be transferred to API calls. The lower 8 bits are stored seamlessly behind the data of the last line of the upper 8 bits half. To identify, that further DIB data are available, the field biPlanes of the BITMAPINFOHEADER-structure is set to 2.

DIBs formatted in this fashion fall outside of Microsoft's specification for DIBs and are intended primarily for use with DaVinci applications.

Before these DIBs can be used with API functions such as SetDIBits or CreateDIBSection, the application must first reset the DIB's biPlanes member to 1. It may also be necessary in some cases to divide the biSizeImage value by 2. Since these changes are made directly to the BITMAPINFOHEADER, and not the pixel data, these changes will have a negligible effect on performance.

When importing 16 bit grayscale TIFFs with biBitCount = 8 and biPlanes =2, applications must check the first color in the DIBs color palette for black in order to find whether 0 or 65535 marks a white pixel.

Fully 48-bit-compatible DaVinci functions

The following functions can process the full 16 bit of information per color value, taking into account the lower 8 bits stored behind the API-Compatible DIB:

DaVinci functions with limited 48 bit compatibility

All functions exported by DaVinci and Leonardo at least make shure the higher 8 bits are processed correctly.

Addressing DIB data

In DIBs whose biPlanes = 2, the biSizeImage member of the BITMAPINFOHEADER specifies the size of the data area for both the higher 8 bit half and the lower 8 bit half in total so that biSizeImage is always evenly divisible by 2. The biSizeImage member can never be 0. Therefore, the distance between the top 8 bits and the lower 8 bits can be computed by division of biSizeImage by two.
#ifdef __WIN32__
# define HUGE
#else
# define HUGE huge
#endif

typedef BYTE HUGE *HPBYTE;

#ifndef MAKEWORD
#define MAKEWORD(lo, hi) ((lo)|((hi)<<8)
#endif

WORD	wRed, wGreen, wBlue;

LPBITMAPINFOHEADER    lpbmi = (LPBITMAPINFOHEADER) GlobalLock(hDIB);
HPBYTE                hpBitsLSB= (HPBYTE)DIBBITS(lpbmi),
                      hpBitsMSB= hpBitsLSB + lpbmi->biSizeImage/2;
wBlue  = MAKEWORD(hpBitsLSB[0], hpBitsMSB[0]);
wGreen = MAKEWORD(hpBitsLSB[1], hpBitsMSB[1]);
wRed   = MAKEWORD(hpBitsLSB[2], hpBitsMSB[2]);

(+++ // nächstes Pixel)
hpBitsLSB += lpbmi->biBitCount/8;
hpBitsMSB  = hpBitsLSB + lpbmi->biSizeImage/2;
wBlue  = MAKEWORD(hpBitsLSB[0], hpBitsMSB[0]);
wGreen = MAKEWORD(hpBitsLSB[1], hpBitsMSB[1]);
wRed   = MAKEWORD(hpBitsLSB[2], hpBitsMSB[2]);