Herd Software Development
DaVinci Graphics Library
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.
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:
All functions exported by DaVinci and Leonardo at least make shure the higher 8 bits are processed correctly.
#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, hpBitsMSB); wGreen = MAKEWORD(hpBitsLSB, hpBitsMSB); wRed = MAKEWORD(hpBitsLSB, hpBitsMSB); (+++ // nächstes Pixel) hpBitsLSB += lpbmi->biBitCount/8; hpBitsMSB = hpBitsLSB + lpbmi->biSizeImage/2; wBlue = MAKEWORD(hpBitsLSB, hpBitsMSB); wGreen = MAKEWORD(hpBitsLSB, hpBitsMSB); wRed = MAKEWORD(hpBitsLSB, hpBitsMSB);