Source code of Windows XP (NT5)
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.

248 lines
7.6 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. KS_VIDEOINFOHEADER *pVideoInfoHdr = pStrmEx->pVideoInfoHeader;
  69. UINT biWidth = pVideoInfoHdr->bmiHeader.biWidth;
  70. UINT biHeight = pVideoInfoHdr->bmiHeader.biHeight;
  71. UINT biSizeImage = pVideoInfoHdr->bmiHeader.biSizeImage;
  72. UINT biWidthBytes = KS_DIBWIDTHBYTES (pVideoInfoHdr->bmiHeader);
  73. UINT biBitCount = pVideoInfoHdr->bmiHeader.biBitCount;
  74. UINT LinesToCopy = abs (biHeight);
  75. DWORD biCompression = pVideoInfoHdr->bmiHeader.biCompression;
  76. UINT Line;
  77. PUCHAR pLineBuffer;
  78. PKSSTREAM_HEADER pDataPacket = pSrb->CommandData.DataBufferArray;
  79. PUCHAR pImage = pDataPacket->Data;
  80. DEBUG_ASSERT (pSrb->NumberOfBuffers == 1);
  81. #if 0
  82. // Note: set "ulInDebug = 1" in a debugger to view this output with .ntkern
  83. DbgLogTrace(("\'TestCap: ImageSynthBegin\n"));
  84. DbgLogTrace(("\'TestCap: biSizeImage=%d, DataPacketLength=%d\n",
  85. biSizeImage, pDataPacket->DataPacketLength));
  86. DbgLogTrace(("\'TestCap: biWidth=%d biHeight=%d WidthBytes=%d bpp=%d\n",
  87. biWidth, biHeight, biWidthBytes, biBitCount));
  88. DbgLogTrace(("\'TestCap: pImage=%x\n", pImage));
  89. #endif
  90. //
  91. // Synthesize a single line of image data, which will then be replicated
  92. //
  93. pLineBuffer = &pStrmEx->LineBuffer[0];
  94. if ((biBitCount == 24) && (biCompression == KS_BI_RGB)) {
  95. switch (Command) {
  96. case IMAGE_XFER_NTSC_EIA_100AMP_100SAT:
  97. // 100% saturation
  98. {
  99. UINT x, col;
  100. PUCHAR pT = pLineBuffer;
  101. for (x = 0; x < biWidth; x++) {
  102. col = (x * 8) / biWidth;
  103. col = FlipHorizontal ? (7 - col) : col;
  104. *pT++ = NTSCColorBars100Amp100SatRGB24[0][col]; // Red
  105. *pT++ = NTSCColorBars100Amp100SatRGB24[1][col]; // Green
  106. *pT++ = NTSCColorBars100Amp100SatRGB24[2][col]; // Blue
  107. }
  108. }
  109. break;
  110. case IMAGE_XFER_NTSC_EIA_75AMP_100SAT:
  111. // 75% Saturation
  112. {
  113. UINT x, col;
  114. PUCHAR pT = pLineBuffer;
  115. for (x = 0; x < biWidth; x++) {
  116. col = (x * 8) / biWidth;
  117. col = FlipHorizontal ? (7 - col) : col;
  118. *pT++ = NTSCColorBars75Amp100SatRGB24[0][col]; // Red
  119. *pT++ = NTSCColorBars75Amp100SatRGB24[1][col]; // Green
  120. *pT++ = NTSCColorBars75Amp100SatRGB24[2][col]; // Blue
  121. }
  122. }
  123. break;
  124. case IMAGE_XFER_BLACK:
  125. // Camma corrected Grayscale ramp
  126. {
  127. UINT x, col;
  128. PUCHAR pT = pLineBuffer;
  129. for (x = 0; x < biWidth; x++) {
  130. col = (255 * (x * 10) / biWidth) / 10;
  131. col = FlipHorizontal ? (255 - col) : col;
  132. *pT++ = (BYTE) col; // Red
  133. *pT++ = (BYTE) col; // Green
  134. *pT++ = (BYTE) col; // Blue
  135. }
  136. }
  137. break;
  138. case IMAGE_XFER_WHITE:
  139. // All white
  140. RtlFillMemory(
  141. pLineBuffer,
  142. biWidthBytes,
  143. (UCHAR) 255);
  144. break;
  145. case IMAGE_XFER_GRAY_INCREASING:
  146. // grayscale increasing with each image captured
  147. RtlFillMemory(
  148. pLineBuffer,
  149. biWidthBytes,
  150. (UCHAR) (pStrmEx->FrameInfo.PictureNumber * 8));
  151. break;
  152. default:
  153. break;
  154. }
  155. } // endif RGB24
  156. else if ((biBitCount == 16) && (biCompression == FOURCC_YUV422)) {
  157. switch (Command) {
  158. case IMAGE_XFER_NTSC_EIA_100AMP_100SAT:
  159. default:
  160. {
  161. UINT x, col;
  162. PUCHAR pT = pLineBuffer;
  163. for (x = 0; x < (biWidth / 2); x++) {
  164. col = (x * 8) / (biWidth / 2);
  165. col = FlipHorizontal ? (7 - col) : col;
  166. *pT++ = NTSCColorBars100Amp100SatYUV[0][col]; // U
  167. *pT++ = NTSCColorBars100Amp100SatYUV[1][col]; // Y
  168. *pT++ = NTSCColorBars100Amp100SatYUV[2][col]; // V
  169. *pT++ = NTSCColorBars100Amp100SatYUV[3][col]; // Y
  170. }
  171. }
  172. break;
  173. }
  174. }
  175. else {
  176. DbgLogError(("\'TestCap: Unknown format in ImageSynth!!!\n"));
  177. TRAP;
  178. }
  179. //
  180. // Copy the single line synthesized to all rows of the image
  181. //
  182. for (Line = 0; Line < LinesToCopy; Line++, pImage += biWidthBytes) {
  183. // Show some action on an otherwise static image
  184. // This will be a changing grayscale horizontal band
  185. // at the bottom of an RGB image and a changing color band at the
  186. // top of a YUV image
  187. if (Line >= 3 && Line <= 6) {
  188. UINT j;
  189. for (j = 0; j < biWidthBytes; j++) {
  190. *(pImage + j) = (UCHAR) pStrmEx->FrameInfo.PictureNumber;
  191. }
  192. continue;
  193. }
  194. // Copy the synthesized line
  195. RtlCopyMemory(
  196. pImage,
  197. pLineBuffer,
  198. biWidthBytes);
  199. }
  200. //
  201. // Report back the actual number of bytes copied to the destination buffer
  202. // (This can be smaller than the allocated buffer for compressed images)
  203. //
  204. pDataPacket->DataUsed = biSizeImage;
  205. }