Advanced MFC Programming

Advanced MFC Programming Advanced MFC Programming

math.hcmuns.edu.vn
from math.hcmuns.edu.vn More from this publisher
11.04.2014 Views

Chapter 10. Bitmap dwSize= ( sizeof(BITMAPINFOHEADER)+ nSizeCT*sizeof(RGBQUAD)+ WIDTHBYTES(8*lpBi24->bmiHeader.biWidth)*lpBi24->bmiHeader.biHeight ); hDIB=::GlobalAlloc(GHND, dwSize); ASSERT(hDIB); lpBi=(LPBITMAPINFO)::GlobalLock(hDIB); ASSERT(lpBi); *lpBi=*lpBi24; lpBi->bmiHeader.biBitCount=8; lpBi->bmiHeader.biSizeImage=WIDTHBYTES ( 8*lpBi->bmiHeader.biWidth )*lpBi->bmiHeader.biHeight; lpBi->bmiHeader.biClrUsed=0; …… for(n=0; nbmiColors[n]=*(LPRGBQUAD)arRgbQuad[n]; } The differences between the new and old bitmap information headers are member bitBitCount (8 for 256-color format), biSizeImage, and biClrUsed (Member biClrUsed can be used to indicate the color usage. For simplicity, it is set to zero). Next we need to convert explicit RGB values to color table indices. As mentioned before, there are two situations. If the color table is extracted directly from the bitmap, we must compare each pixel with every entry of the color table, find the index, and use it as the bitmap bit value. Otherwise the index can be formed by omitting the lower 5 bits of red and green colors, the lower 6 bits of blue color then combining them together. This eleminates the procedure of looking up the color table. It is possible for us to do so because the color table is created in a way that if we implement the above operation on any color contained in the table, the result will become the index of the corresponding entry. For example, entry 1 contains color (32, 0, 0), which is (0x20, 0x00, 0x00). After bit omission, it becomes (0x01, 0x00, 0x00). The followng calculation will result in the index of this entry: red | (green bmiHeader.biWidth)*j ); lpRowSrc= ( (LPSTR)lpBi24+ sizeof(BITMAPINFOHEADER)+ WIDTHBYTES(lpBi24->bmiHeader.biBitCount*lpBi24->bmiHeader.biWidth)*j ); for(i=0; ibmiHeader.biWidth; i++) { rgbQuad.rgbBlue=*lpRowSrc; rgbQuad.rgbGreen=*(lpRowSrc+1); rgbQuad.rgbRed=*(lpRowSrc+2); rgbQuad.rgbReserved=0; if(bStandardPal == TRUE) 312

Chapter 10. Bitmap …… } } { if(rgbQuad.rgbBlue >5) ); } else { for(n=0; nIsKindOf(RUNTIME_CLASS(CGDIView))); ptrView->LoadBitmap(m_hDIB); AfxGetApp()->DoWaitCursor(FALSE); With this application, we can convert between 256-color and 24-bit bitmap formats back and forth. If the application is executed on a palette device with 256-color configuration, we may experience color distortion after converting a 256-color format bitmap to 24-bit format bitmap. This is because for this kind of bitmap, no logical palette is implemented in the application, so the color approximation method is applied by the OS. 313

Chapter 10. Bitmap<br />

……<br />

}<br />

}<br />

{<br />

if(rgbQuad.rgbBlue >5)<br />

);<br />

}<br />

else<br />

{<br />

for(n=0; nIsKindOf(RUNTIME_CLASS(CGDIView)));<br />

ptrView->LoadBitmap(m_hDIB);<br />

AfxGetApp()->DoWaitCursor(FALSE);<br />

With this application, we can convert between 256-color and 24-bit bitmap formats back and forth. If<br />

the application is executed on a palette device with 256-color configuration, we may experience color<br />

distortion after converting a 256-color format bitmap to 24-bit format bitmap. This is because for this kind<br />

of bitmap, no logical palette is implemented in the application, so the color approximation method is<br />

applied by the OS.<br />

313

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!