Windows NT 4.0 source code leak
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

107 lines
2.1 KiB

4 years ago
  1. /************************************************************************
  2. * *
  3. * CBMPINFO.CPP *
  4. * *
  5. * Copyright (C) Microsoft Corporation 1993-1994 *
  6. * All Rights reserved. *
  7. * *
  8. ************************************************************************/
  9. #include "stdafx.h"
  10. #pragma hdrstop
  11. #include "cbmpinfo.h"
  12. #ifndef WIDTHBYTES
  13. #define WIDTHBYTES(i) ((i + 31) / 32 * 4)
  14. #endif
  15. static char txtDisplay[] = "DISPLAY";
  16. CBmpInfo::CBmpInfo(HBITMAP hbmpOrg, int cColors)
  17. {
  18. hbmp = hbmpOrg; // save the bitmap handle
  19. BITMAP bmp;
  20. GetObject(hbmp, sizeof(BITMAP), &bmp);
  21. if (cColors == -1) {
  22. // 24-bit images don't have a color palette
  23. if (bmp.bmBitsPixel == 24)
  24. cColors = 0;
  25. else
  26. cColors =
  27. 1 << (UINT) (bmp.bmPlanes * bmp.bmBitsPixel);
  28. }
  29. cclrs = cColors;
  30. pbmi = (PBITMAPINFO) lcCalloc(sizeof(BITMAPINFOHEADER) +
  31. sizeof(RGBQUAD) * cColors);
  32. pbih = (PBITMAPINFOHEADER) pbmi;
  33. pbih->biPlanes = 1;
  34. pbih->biBitCount = GetBitCount(cColors);
  35. pbih->biSizeImage = WIDTHBYTES((DWORD) bmp.bmWidth *
  36. pbih->biBitCount) * bmp.bmHeight;
  37. pbih->biSize = sizeof(BITMAPINFOHEADER);
  38. pbih->biWidth = bmp.bmWidth;
  39. pbih->biHeight = bmp.bmHeight;
  40. pbih->biCompression = BI_RGB;
  41. // REVIEW: do we need this?
  42. HDC hdcScreen = CreateIC(txtDisplay, NULL, NULL, NULL);
  43. ASSERT(hdcScreen);
  44. // Fill in the screen resolution
  45. pbih->biYPelsPerMeter = (DWORD) GetDeviceCaps(hdcScreen, LOGPIXELSY);
  46. pbih->biXPelsPerMeter = (DWORD) GetDeviceCaps(hdcScreen, LOGPIXELSX);
  47. DeleteDC(hdcScreen);
  48. // Leave everything else zero'd out
  49. }
  50. CBmpInfo::~CBmpInfo(void)
  51. {
  52. lcFree(pbmi);
  53. }
  54. /***************************************************************************
  55. FUNCTION: GetBitCount
  56. PURPOSE: Get number of bits per pixel
  57. PARAMETERS:
  58. cColors
  59. RETURNS:
  60. COMMENTS:
  61. MODIFICATION DATES:
  62. 26-Apr-1993 [ralphw]
  63. ***************************************************************************/
  64. int STDCALL GetBitCount(int cColors)
  65. {
  66. switch (cColors) {
  67. case 2:
  68. return 1;
  69. case 16:
  70. return 4;
  71. case 256:
  72. return 8;
  73. case 0:
  74. return 24;
  75. }
  76. return -1;
  77. }