Herd Software Development
DaVinci Graphics Library
DaVinci Documentation
The RWxxxx function group in Leonardo provides you with an easy way to read, write and work pixel-by-pixel with DIB data. Leonardo is particularly well-suited to, and recommended for, working with 48 bit and CMYK image formats.
HDIB hDIB; HDIBRW hRW = RWOpenDIB(hDIB);
The calling application can now address the pixels in the DIB. The following functions are available for access to DIBs at the pixel level:
COLORREF cr; RGBQUAD16 rgbq16; // Example: Invert a Pixel cr = RWGetPixel(hRW, x, y); cr = RGB( 255 - GetRValue (cr),
255 - GetGValue (cr),
255 - GetBValue (cr) ); RWSetPixel(hRW, x, y, cr); // The same with RGBQ16 RWGetPixelRGB16 (hRW, x, y, &rgbq16);
rgbq.rgb16Red = 65535 - rgbq.rgb16Red; rgbq.rgb16Green = 65535 - rgbq.rgb16Green; rgbq.rgb16Blue = 65535 - rgbq.rgb16Blue; RWSetPixelRGB16(hRW, x, y, &rgbq16);
#define BLOCK_SIZE 256 RGBQUAD16 argbq[BLOCK_SIZE]; BITMAPINFOHEADER bmi; UINT x, i; DIBInfo(hDib, &bmi, sizeof(bmi)); for (x=0; x<bmi.biWidth; ++x) { RWGetLineRGB16(hRW, x, y, BLOCK_SIZE, argbq); for (i=0; i<BLOCK_SIZE; ++i) { argbq[i].rgbq16Red = 65535 - argbq[i].rgbq16Red argbq[i].rgbq16Green = 65535 - argbq[i].rgbq16Green argbq[i].rgbq16Blue = 65535 - argbq[i].rgbq16Blue } RWSetLineRGB16(hRW, x, y, BLOCK_SIZE, argbq); }
When no further access to the DIB is required, the calling application must free the DIB access handle obtained by the call to RWOpenDIB by calling the function RWClose
Routines in the RWxxxx function group are optimized for speed, but they can't achieve the same performance as direct memory access by the application.
Especially slow functions are setting of pixels by RGB values if the DIB has a color palette (biBitCount=4 or biBitCount=8 or biBitCount=1 with colors not beeing black and white). In this case, the function RWSetPixelRGB16 first has to determine the best color palette index for the RGB value, a very time-consuming process. Once the index value for a RGB-Color has been determined, it is cached in a 256 KByte memory block.
For two especially important cases Leonardo contains optimized code to speed up processing: