Leaked source code of windows server 2003
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.

251 lines
7.8 KiB

  1. /******************************Module*Header*******************************\
  2. * Module Name: CDIB.cpp
  3. *
  4. * This file contains the code to support the functionality test harness
  5. * for GDI+. This includes menu options and calling the appropriate
  6. * functions for execution.
  7. *
  8. * Created: 05-May-2000 - Jeff Vezina [t-jfvez]
  9. *
  10. * Copyright (c) 2000 Microsoft Corporation
  11. *
  12. \**************************************************************************/
  13. #include "CDIB.h"
  14. #include "CFuncTest.h"
  15. #include "CHalftone.h"
  16. extern CHalftone g_Halftone;
  17. extern CFuncTest g_FuncTest;
  18. CDIB::CDIB(BOOL bRegression,int nBits)
  19. {
  20. sprintf(m_szName,"DIB %d bit",nBits);
  21. if (nBits>1)
  22. strcat(m_szName,"s");
  23. m_nBits=nBits;
  24. m_hDC=NULL;
  25. m_hBM=NULL;
  26. m_hBMOld=NULL;
  27. m_hpal=NULL;
  28. m_hpalOld=NULL;
  29. InitPalettes();
  30. m_bRegression=bRegression;
  31. }
  32. CDIB::~CDIB()
  33. {
  34. }
  35. Graphics *CDIB::PreDraw(int &nOffsetX,int &nOffsetY)
  36. {
  37. Graphics *g=NULL;
  38. PVOID pvBits = NULL;
  39. HDC hdcWnd=GetDC(g_FuncTest.m_hWndMain);
  40. // these combined give BITMAPINFO structure.
  41. struct {
  42. BITMAPINFOHEADER bmih;
  43. union {
  44. RGBQUAD1 rgbquad1;
  45. RGBQUAD2 rgbquad2;
  46. RGBQUAD4 rgbquad4;
  47. RGBQUAD8 rgbquad8;
  48. RGBQUAD16 rgbquad16;
  49. RGBQUAD24 rgbquad24;
  50. RGBQUAD32 rgbquad32;
  51. };
  52. } bmi;
  53. bmi.bmih.biSize = sizeof(BITMAPINFOHEADER);
  54. bmi.bmih.biWidth = (int)TESTAREAWIDTH;
  55. bmi.bmih.biHeight = (int)TESTAREAHEIGHT;
  56. bmi.bmih.biPlanes = 1;
  57. bmi.bmih.biBitCount = (WORD)m_nBits;
  58. bmi.bmih.biCompression = BI_RGB;
  59. bmi.bmih.biSizeImage = 0;
  60. bmi.bmih.biXPelsPerMeter = 0;
  61. bmi.bmih.biYPelsPerMeter = 0;
  62. bmi.bmih.biClrUsed = 0; // only used for <= 16bpp
  63. bmi.bmih.biClrImportant = 0;
  64. // create appropriate rgb table.
  65. switch (m_nBits)
  66. {
  67. case 1: memcpy(bmi.rgbquad1, m_rgbQuad1, sizeof(m_rgbQuad1));
  68. break;
  69. case 2: memcpy(bmi.rgbquad2, m_rgbQuad2, sizeof(m_rgbQuad2));
  70. break;
  71. case 4: memcpy(bmi.rgbquad4, m_rgbQuad4, sizeof(m_rgbQuad4));
  72. break;
  73. case 8: memcpy(bmi.rgbquad8, m_rgbQuad8, sizeof(m_rgbQuad8));
  74. break;
  75. case 16: memcpy(bmi.rgbquad16, m_rgbQuad16, sizeof(m_rgbQuad16));
  76. break;
  77. case 24: memcpy(bmi.rgbquad24, m_rgbQuad24, sizeof(m_rgbQuad24));
  78. break;
  79. case 32: memcpy(bmi.rgbquad32, m_rgbQuad32, sizeof(m_rgbQuad32));
  80. break;
  81. }
  82. if ((m_nBits == 8) && g_Halftone.m_bUseSetting)
  83. {
  84. m_hpal = DllExports::GdipCreateHalftonePalette();
  85. BYTE aj[sizeof(PALETTEENTRY) * 256];
  86. LPPALETTEENTRY lppe = (LPPALETTEENTRY) aj;
  87. RGBQUAD *prgb = (RGBQUAD *) &bmi.rgbquad8;
  88. ULONG i;
  89. if (GetPaletteEntries(m_hpal, 0, 256, lppe))
  90. {
  91. UINT i;
  92. for (i = 0; i < 256; i++)
  93. {
  94. prgb[i].rgbRed = lppe[i].peRed;
  95. prgb[i].rgbGreen = lppe[i].peGreen;
  96. prgb[i].rgbBlue = lppe[i].peBlue;
  97. prgb[i].rgbReserved = 0;
  98. }
  99. }
  100. }
  101. m_hBM=CreateDIBSection(hdcWnd,(BITMAPINFO*)&bmi,DIB_RGB_COLORS,&pvBits,NULL,0);
  102. if (!m_hBM)
  103. {
  104. MessageBoxA(NULL,"Can't create DIB Section.","",MB_OK);
  105. return NULL;
  106. }
  107. // create DC for our DIB
  108. m_hDC=CreateCompatibleDC(hdcWnd);
  109. m_hBMOld=(HBITMAP)SelectObject(m_hDC,m_hBM);
  110. if (m_hpal)
  111. {
  112. m_hpalOld = SelectPalette(m_hDC, m_hpal, FALSE);
  113. }
  114. // Set the background to main window background
  115. BitBlt(m_hDC, 0, 0, (int)TESTAREAWIDTH, (int)TESTAREAHEIGHT, hdcWnd, nOffsetX, nOffsetY, SRCCOPY);
  116. // PatBlt(m_hDC, 0, 0, (int)TESTAREAWIDTH, (int)TESTAREAHEIGHT, WHITENESS);
  117. // if (m_nBits == 32)
  118. // g = Graphics::FromDib32(pvBits, rClient.right, rClient.bottom);
  119. // else
  120. g = Graphics::FromHDC(m_hDC);
  121. // Since we are doing the test on another surface
  122. nOffsetX=0;
  123. nOffsetY=0;
  124. ReleaseDC(g_FuncTest.m_hWndMain,hdcWnd);
  125. return g;
  126. }
  127. void CDIB::PostDraw(RECT rTestArea)
  128. {
  129. // blit from the DIB to screen so we see the results, we use
  130. // GDI for this.
  131. HDC hdcOrig = GetDC(g_FuncTest.m_hWndMain);
  132. HPALETTE hpalScreenOld = NULL;
  133. if (m_hpal)
  134. {
  135. hpalScreenOld = SelectPalette(hdcOrig, m_hpal, FALSE);
  136. RealizePalette(hdcOrig);
  137. }
  138. BitBlt(hdcOrig, rTestArea.left, rTestArea.top, (int)TESTAREAWIDTH, (int)TESTAREAHEIGHT, m_hDC, 0, 0, SRCCOPY);
  139. if (m_hpal)
  140. {
  141. SelectPalette(hdcOrig, hpalScreenOld, FALSE);
  142. }
  143. ReleaseDC(g_FuncTest.m_hWndMain,hdcOrig);
  144. SelectObject(m_hDC,m_hBMOld);
  145. if (m_hpal)
  146. {
  147. SelectPalette(m_hDC, m_hpalOld, FALSE);
  148. DeleteObject(m_hpal);
  149. m_hpal=NULL;
  150. }
  151. DeleteDC(m_hDC);
  152. DeleteObject(m_hBM);
  153. }
  154. void CDIB::InitPalettes()
  155. {
  156. BYTE red=0,green=0,blue=0;
  157. RGBQUAD1 rgbQuad1 = { { 0, 0, 0, 0 },
  158. { 0xff, 0xff, 0xff, 0 } };
  159. RGBQUAD2 rgbQuad2 = { { 0x80, 0x80, 0x80, 0 },
  160. { 0x80, 0, 0, 0 },
  161. { 0, 0x80, 0, 0 },
  162. { 0, 0, 0x80, 0 } };
  163. RGBQUAD4 rgbQuad4 = { // B G R
  164. { 0, 0, 0, 0 }, // 0
  165. { 0, 0, 0x80,0 }, // 1
  166. { 0, 0x80,0, 0 }, // 2
  167. { 0, 0x80,0x80,0 }, // 3
  168. { 0x80,0, 0, 0 }, // 4
  169. { 0x80,0, 0x80,0 }, // 5
  170. { 0x80,0x80,0, 0 }, // 6
  171. { 0x80,0x80,0x80,0 }, // 7
  172. { 0xC0,0xC0,0xC0,0 }, // 8
  173. { 0, 0, 0xFF,0 }, // 9
  174. { 0, 0xFF,0, 0 }, // 10
  175. { 0, 0xFF,0xFF,0 }, // 11
  176. { 0xFF,0, 0, 0 }, // 12
  177. { 0xFF,0, 0xFF,0 }, // 13
  178. { 0xFF,0xFF,0, 0 }, // 14
  179. { 0xFF,0xFF,0xFF,0 } }; // 15
  180. RGBQUAD16 rgbQuad16 = { { 0, 0x7c, 0, 0 }, { 0xe0, 03, 0, 0 }, { 0x1f, 0, 0, 0 } };
  181. RGBQUAD24 rgbQuad24 = { { 0, 0, 0xff, 0 }, { 0, 0xff, 0, 0 }, { 0xff, 0, 0, 0 } };
  182. RGBQUAD32 rgbQuad32 = { { 0, 0, 0xff, 0 }, { 0, 0xff, 0, 0 }, { 0xff, 0, 0 ,0 } };
  183. memcpy(m_rgbQuad1,rgbQuad1,sizeof(rgbQuad1));
  184. memcpy(m_rgbQuad2,rgbQuad2,sizeof(rgbQuad2));
  185. memcpy(m_rgbQuad4,rgbQuad4,sizeof(rgbQuad4));
  186. memcpy(m_rgbQuad16,rgbQuad16,sizeof(rgbQuad16));
  187. memcpy(m_rgbQuad24,rgbQuad24,sizeof(rgbQuad24));
  188. memcpy(m_rgbQuad32,rgbQuad32,sizeof(rgbQuad32));
  189. // This is a very arbitrary palette. Anyhoo, it's not the GDI+ halftone
  190. // palette, which I guess is all we want to test. It is kinda lucky that
  191. // the VGA colors are present, but that's all we need.
  192. ZeroMemory(m_rgbQuad8,sizeof(m_rgbQuad8));
  193. for (INT i=0; i<256; i++)
  194. {
  195. m_rgbQuad8[i].rgbRed=red;
  196. m_rgbQuad8[i].rgbGreen=green;
  197. m_rgbQuad8[i].rgbBlue=blue;
  198. if (!(red+=32))
  199. {
  200. if (!(green+=32))
  201. {
  202. blue+=64;
  203. }
  204. }
  205. }
  206. // for system colors (last 20), use those from 4 bpp palette table.
  207. for (INT j=248; j<256; j++)
  208. {
  209. m_rgbQuad8[j].rgbRed=m_rgbQuad4[j-240].rgbRed;
  210. m_rgbQuad8[j].rgbGreen=m_rgbQuad4[j-240].rgbGreen;
  211. m_rgbQuad8[j].rgbBlue=m_rgbQuad4[j-240].rgbBlue;
  212. }
  213. }