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.

275 lines
8.7 KiB

  1. //==========================================================================;
  2. //
  3. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
  4. // KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  5. // IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
  6. // PURPOSE.
  7. //
  8. // Copyright (c) 1992 - 1997 Microsoft Corporation. All Rights Reserved.
  9. //
  10. //==========================================================================;
  11. #include "strmini.h"
  12. #include "ksmedia.h"
  13. #include "capmain.h"
  14. #include "capdebug.h"
  15. #include "capxfer.h"
  16. //
  17. // EIA-189-A Standard color bar definitions
  18. //
  19. // 75% Amplitude, 100% Saturation
  20. const static UCHAR NTSCColorBars75Amp100SatRGB24 [3][8] =
  21. {
  22. // Whi Yel Cya Grn Mag Red Blu Blk
  23. 191, 0,191, 0,191, 0,191, 0, // Blue
  24. 191,191,191,191, 0, 0, 0, 0, // Green
  25. 191,191, 0, 0,191,191, 0, 0, // Red
  26. };
  27. // 100% Amplitude, 100% Saturation
  28. const static UCHAR NTSCColorBars100Amp100SatRGB24 [3][8] =
  29. {
  30. // Whi Yel Cya Grn Mag Red Blu Blk
  31. 255, 0,255, 0,255, 0,255, 0, // Blue
  32. 255,255,255,255, 0, 0, 0, 0, // Green
  33. 255,255, 0, 0,255,255, 0, 0, // Red
  34. };
  35. const static UCHAR NTSCColorBars100Amp100SatYUV [4][8] =
  36. {
  37. // Whi Yel Cya Grn Mag Red Blu Blk
  38. 128, 16,166, 54,202, 90,240,128, // U
  39. 235,211,170,145,106, 81, 41, 16, // Y
  40. 128,146, 16, 34,222,240,109,128, // V
  41. 235,211,170,145,106, 81, 41, 16 // Y
  42. };
  43. /*
  44. ** ImageSynth()
  45. **
  46. ** Synthesizes NTSC color bars, white, black, and grayscale images
  47. **
  48. ** Arguments:
  49. **
  50. ** pSrb - The stream request block for the Video stream
  51. ** ImageXferCommands - Index specifying the image to generate
  52. **
  53. ** Returns:
  54. **
  55. ** Nothing
  56. **
  57. ** Side Effects: none
  58. */
  59. void ImageSynth (
  60. IN OUT PHW_STREAM_REQUEST_BLOCK pSrb,
  61. IN ImageXferCommands Command,
  62. IN BOOL FlipHorizontal
  63. )
  64. {
  65. PSTREAMEX pStrmEx = (PSTREAMEX)pSrb->StreamObject->HwStreamExtension;
  66. PHW_DEVICE_EXTENSION pHwDevExt = ((PHW_DEVICE_EXTENSION)pSrb->HwDeviceExtension);
  67. int StreamNumber = pSrb->StreamObject->StreamNumber;
  68. UINT Line;
  69. PUCHAR pLineBuffer;
  70. PKSSTREAM_HEADER pDataPacket = pSrb->CommandData.DataBufferArray;
  71. PUCHAR pImage = pDataPacket->Data;
  72. KS_VIDEOINFOHEADER *pVideoInfoHdr;
  73. UINT biWidth;
  74. UINT biHeight;
  75. UINT biSizeImage;
  76. UINT biWidthBytes;
  77. UINT biBitCount;
  78. UINT LinesToCopy;
  79. DWORD biCompression;
  80. KIRQL oldIrql;
  81. //
  82. // Take the lock to avoid race from Set format property that could
  83. // from other processor in an MP system
  84. //
  85. KeAcquireSpinLock( &pStrmEx->lockVideoInfoHeader, &oldIrql );
  86. pVideoInfoHdr = pStrmEx->pVideoInfoHeader;
  87. biWidth = pVideoInfoHdr->bmiHeader.biWidth;
  88. biHeight = pVideoInfoHdr->bmiHeader.biHeight;
  89. biSizeImage = pVideoInfoHdr->bmiHeader.biSizeImage;
  90. biWidthBytes = KS_DIBWIDTHBYTES (pVideoInfoHdr->bmiHeader);
  91. biBitCount = pVideoInfoHdr->bmiHeader.biBitCount;
  92. LinesToCopy = abs (biHeight);
  93. biCompression = pVideoInfoHdr->bmiHeader.biCompression;
  94. //
  95. // release the lock
  96. //
  97. KeReleaseSpinLock( &pStrmEx->lockVideoInfoHeader, oldIrql );
  98. DEBUG_ASSERT (pSrb->NumberOfBuffers == 1);
  99. if (pDataPacket->FrameExtent < biSizeImage) {
  100. DbgLogError(("testcap: video output pin handed buffer size %d, need %d\n",
  101. pDataPacket->FrameExtent,
  102. biSizeImage));
  103. TRAP;
  104. return;
  105. }
  106. #if 0
  107. // Note: set "ulInDebug = 1" in a debugger to view this output with .ntkern
  108. DbgLogTrace(("\'TestCap: ImageSynthBegin\n"));
  109. DbgLogTrace(("\'TestCap: biSizeImage=%d, DataPacketLength=%d\n",
  110. biSizeImage, pDataPacket->DataPacketLength));
  111. DbgLogTrace(("\'TestCap: biWidth=%d biHeight=%d WidthBytes=%d bpp=%d\n",
  112. biWidth, biHeight, biWidthBytes, biBitCount));
  113. DbgLogTrace(("\'TestCap: pImage=%x\n", pImage));
  114. #endif
  115. //
  116. // Synthesize a single line of image data, which will then be replicated
  117. //
  118. pLineBuffer = &pStrmEx->LineBuffer[0];
  119. if ((biBitCount == 24) && (biCompression == KS_BI_RGB)) {
  120. switch (Command) {
  121. case IMAGE_XFER_NTSC_EIA_100AMP_100SAT:
  122. // 100% saturation
  123. {
  124. UINT x, col;
  125. PUCHAR pT = pLineBuffer;
  126. for (x = 0; x < biWidth; x++) {
  127. col = (x * 8) / biWidth;
  128. col = FlipHorizontal ? (7 - col) : col;
  129. *pT++ = NTSCColorBars100Amp100SatRGB24[0][col]; // Red
  130. *pT++ = NTSCColorBars100Amp100SatRGB24[1][col]; // Green
  131. *pT++ = NTSCColorBars100Amp100SatRGB24[2][col]; // Blue
  132. }
  133. }
  134. break;
  135. case IMAGE_XFER_NTSC_EIA_75AMP_100SAT:
  136. // 75% Saturation
  137. {
  138. UINT x, col;
  139. PUCHAR pT = pLineBuffer;
  140. for (x = 0; x < biWidth; x++) {
  141. col = (x * 8) / biWidth;
  142. col = FlipHorizontal ? (7 - col) : col;
  143. *pT++ = NTSCColorBars75Amp100SatRGB24[0][col]; // Red
  144. *pT++ = NTSCColorBars75Amp100SatRGB24[1][col]; // Green
  145. *pT++ = NTSCColorBars75Amp100SatRGB24[2][col]; // Blue
  146. }
  147. }
  148. break;
  149. case IMAGE_XFER_BLACK:
  150. // Camma corrected Grayscale ramp
  151. {
  152. UINT x, col;
  153. PUCHAR pT = pLineBuffer;
  154. for (x = 0; x < biWidth; x++) {
  155. col = (255 * (x * 10) / biWidth) / 10;
  156. col = FlipHorizontal ? (255 - col) : col;
  157. *pT++ = (BYTE) col; // Red
  158. *pT++ = (BYTE) col; // Green
  159. *pT++ = (BYTE) col; // Blue
  160. }
  161. }
  162. break;
  163. case IMAGE_XFER_WHITE:
  164. // All white
  165. RtlFillMemory(
  166. pLineBuffer,
  167. biWidthBytes,
  168. (UCHAR) 255);
  169. break;
  170. case IMAGE_XFER_GRAY_INCREASING:
  171. // grayscale increasing with each image captured
  172. RtlFillMemory(
  173. pLineBuffer,
  174. biWidthBytes,
  175. (UCHAR) (pStrmEx->FrameInfo.PictureNumber * 8));
  176. break;
  177. default:
  178. break;
  179. }
  180. } // endif RGB24
  181. else if ((biBitCount == 16) && (biCompression == FOURCC_YUV422)) {
  182. switch (Command) {
  183. case IMAGE_XFER_NTSC_EIA_100AMP_100SAT:
  184. default:
  185. {
  186. UINT x, col;
  187. PUCHAR pT = pLineBuffer;
  188. for (x = 0; x < (biWidth / 2); x++) {
  189. col = (x * 8) / (biWidth / 2);
  190. col = FlipHorizontal ? (7 - col) : col;
  191. *pT++ = NTSCColorBars100Amp100SatYUV[0][col]; // U
  192. *pT++ = NTSCColorBars100Amp100SatYUV[1][col]; // Y
  193. *pT++ = NTSCColorBars100Amp100SatYUV[2][col]; // V
  194. *pT++ = NTSCColorBars100Amp100SatYUV[3][col]; // Y
  195. }
  196. }
  197. break;
  198. }
  199. }
  200. else {
  201. DbgLogError(("\'TestCap: Unknown format in ImageSynth!!!\n"));
  202. TRAP;
  203. }
  204. //
  205. // Copy the single line synthesized to all rows of the image
  206. //
  207. for (Line = 0; Line < LinesToCopy; Line++, pImage += biWidthBytes) {
  208. // Show some action on an otherwise static image
  209. // This will be a changing grayscale horizontal band
  210. // at the bottom of an RGB image and a changing color band at the
  211. // top of a YUV image
  212. if (Line >= 3 && Line <= 6) {
  213. UINT j;
  214. for (j = 0; j < biWidthBytes; j++) {
  215. *(pImage + j) = (UCHAR) pStrmEx->FrameInfo.PictureNumber;
  216. }
  217. continue;
  218. }
  219. // Copy the synthesized line
  220. RtlCopyMemory(
  221. pImage,
  222. pLineBuffer,
  223. biWidthBytes);
  224. }
  225. //
  226. // Report back the actual number of bytes copied to the destination buffer
  227. // (This can be smaller than the allocated buffer for compressed images)
  228. //
  229. pDataPacket->DataUsed = biSizeImage;
  230. }