Advanced MFC Programming
Advanced MFC Programming Advanced MFC Programming
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
- Page 277 and 278: Chapter 9. Font …… } nKeyState=
- Page 279 and 280: Chapter 9. Font To check out if the
- Page 281 and 282: Chapter 9. Font the same, it indica
- Page 283 and 284: Chapter 9. Font } if(m_nSelIndexBgn
- Page 285 and 286: Chapter 9. Font GHND GPTR Same with
- Page 287 and 288: Chapter 9. Font …… } { Since th
- Page 289 and 290: Chapter 9. Font Function CDocument:
- Page 291 and 292: Chapter 9. Font …… void CGDIDoc
- Page 293 and 294: Chapter 9. Font …… { } UpdateAl
- Page 295 and 296: Chapter 9. Font …… …… case
- Page 297 and 298: Chapter 9. Font client window to be
- Page 299 and 300: Chapter 10. Bitmap ); DWORD dwRop T
- Page 301 and 302: Chapter 10. Bitmap Sample 10.1-2\GD
- Page 303 and 304: Chapter 10. Bitmap The next part of
- Page 305 and 306: Chapter 10. Bitmap Sample Sample 10
- Page 307 and 308: Chapter 10. Bitmap } pPalDraw=pDoc-
- Page 309 and 310: Chapter 10. Bitmap Member bfType mu
- Page 311 and 312: Chapter 10. Bitmap …… dwSize=bf
- Page 313 and 314: Chapter 10. Bitmap …… …… }
- Page 315 and 316: Chapter 10. Bitmap Now the size of
- Page 317 and 318: Chapter 10. Bitmap fuColorUse Speci
- Page 319 and 320: Chapter 10. Bitmap if(hData != NULL
- Page 321 and 322: Chapter 10. Bitmap …… …… cl
- Page 323 and 324: Chapter 10. Bitmap used as the orig
- Page 325 and 326: Chapter 10. Bitmap With the above i
- Page 327: Chapter 10. Bitmap …… …… if
- Page 331 and 332: Chapter 10. Bitmap …… } rgbQuad
- Page 333 and 334: Chapter 10. Bitmap DIB Section Both
- Page 335 and 336: Chapter 10. Bitmap } } if(m_pBmpMas
- Page 337 and 338: Chapter 10. Bitmap …… m_pBmpOld
- Page 339 and 340: Chapter 10. Bitmap BITMAP bm; …
- Page 341 and 342: Chapter 10. Bitmap Draw this portio
- Page 343 and 344: Chapter 10. Bitmap 1) Paint the des
- Page 345 and 346: Chapter 10. Bitmap color bitmap, bu
- Page 347 and 348: Chapter 10. Bitmap will destroy the
- Page 349 and 350: Chapter 10. Bitmap 10) The total im
- Page 351 and 352: Chapter 11. Sample: Simple Paint Af
- Page 353 and 354: Chapter 11. Sample: Simple Paint CG
- Page 355 and 356: Chapter 11. Sample: Simple Paint Th
- Page 357 and 358: Chapter 11. Sample: Simple Paint Co
- Page 359 and 360: Chapter 11. Sample: Simple Paint vo
- Page 361 and 362: Chapter 11. Sample: Simple Paint m_
- Page 363 and 364: Chapter 11. Sample: Simple Paint cu
- Page 365 and 366: Chapter 11. Sample: Simple Paint Te
- Page 367 and 368: Chapter 11. Sample: Simple Paint
- Page 369 and 370: Chapter 11. Sample: Simple Paint CS
- Page 371 and 372: Chapter 11. Sample: Simple Paint fu
- Page 373 and 374: Chapter 11. Sample: Simple Paint
- Page 375 and 376: Chapter 11. Sample: Simple Paint DW
- Page 377 and 378: Chapter 11. Sample: Simple Paint m_
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