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.

315 lines
7.5 KiB

  1. /*++
  2. Copyright (c) 1996-1997 Microsoft Corporation.
  3. Copyright (c) 1996-1997 Cirrus Logic, Inc.,
  4. Module Name:
  5. C L G A M M A . C
  6. Abstract:
  7. This routine accesses Gamma correction information from the following
  8. NT 4.0 registry.
  9. Registry subdirectory : System\CurrentControlSet\Services\cirrus\Device0
  10. Keys : "G Gamma", and "G Contrast"
  11. Environment:
  12. Kernel mode only
  13. Notes:
  14. *
  15. * chu01 12-16-96 : Color correction start coding.
  16. *
  17. *
  18. --*/
  19. //---------------------------------------------------------------------------
  20. // HEADER FILES
  21. //---------------------------------------------------------------------------
  22. //#include <ntddk.h>
  23. #include <dderror.h>
  24. #include <devioctl.h>
  25. #include <miniport.h> // I added
  26. #include "clmini.h"
  27. #include <ntddvdeo.h>
  28. #include <video.h>
  29. #include "cirrus.h"
  30. //---------------------------------------------------------------------------
  31. // FUNCTION PROTOTYPE
  32. //---------------------------------------------------------------------------
  33. VP_STATUS
  34. VgaGetGammaFactor(
  35. PHW_DEVICE_EXTENSION HwDeviceExtension,
  36. PGAMMA_VALUE value,
  37. ULONG ValueLength,
  38. PULONG OutputSize
  39. );
  40. VP_STATUS
  41. VgaGetContrastFactor(
  42. PHW_DEVICE_EXTENSION HwDeviceExtension,
  43. PCONTRAST_VALUE value,
  44. ULONG ValueLength,
  45. PULONG OutputSize
  46. );
  47. VP_STATUS GetGammaKeyInfoFromReg(
  48. PHW_DEVICE_EXTENSION HwDeviceExtension
  49. ) ;
  50. VP_STATUS GetContrastKeyInfoFromReg(
  51. PHW_DEVICE_EXTENSION HwDeviceExtension
  52. ) ;
  53. VP_STATUS GetGammaCorrectInfoCallBack (
  54. PVOID HwDeviceExtension,
  55. PVOID Context,
  56. PWSTR ValueName,
  57. PVOID ValueData,
  58. ULONG ValueLength
  59. ) ;
  60. #if defined(ALLOC_PRAGMA)
  61. #pragma alloc_text(PAGE,GetGammaKeyInfoFromReg)
  62. #pragma alloc_text(PAGE,GetContrastKeyInfoFromReg)
  63. #pragma alloc_text(PAGE,GetGammaCorrectInfoCallBack)
  64. #pragma alloc_text(PAGE,VgaGetGammaFactor)
  65. #pragma alloc_text(PAGE,VgaGetContrastFactor)
  66. #endif
  67. UCHAR GammaInfo[4] ;
  68. //---------------------------------------------------------------------------
  69. //
  70. // Function: Get Gamma factor
  71. //
  72. // Input:
  73. // None
  74. //
  75. // Output:
  76. // NO_ERROR: successful; otherwise: fail
  77. //
  78. //---------------------------------------------------------------------------
  79. VP_STATUS VgaGetGammaFactor(
  80. PHW_DEVICE_EXTENSION HwDeviceExtension,
  81. PGAMMA_VALUE value,
  82. ULONG ValueLength,
  83. PULONG OutputSize
  84. )
  85. {
  86. VP_STATUS status ;
  87. int i ;
  88. VideoDebugPrint((2, "VgaGetGammaFactor\n")) ;
  89. if ( ValueLength < (*OutputSize = sizeof(PGAMMA_VALUE)) )
  90. return ERROR_INSUFFICIENT_BUFFER;
  91. status = GetGammaKeyInfoFromReg(HwDeviceExtension) ;
  92. if (status == NO_ERROR)
  93. {
  94. for (i = 0; i < 4; i++)
  95. value->value[i] = GammaInfo[i] ;
  96. }
  97. else if (status == ERROR_INVALID_PARAMETER)
  98. {
  99. //
  100. // If no subkey exists, we assign the default value. Otherwise the
  101. // system would fail.
  102. //
  103. for (i = 0; i < 4; i++)
  104. value->value[i] = 0x7f ;
  105. status = NO_ERROR ;
  106. }
  107. VideoDebugPrint((1, "Gamma value = %lx\n", *value)) ;
  108. return status ;
  109. } // VgaGetGammaFactor
  110. //---------------------------------------------------------------------------
  111. //
  112. // Function: Get Contrast factor
  113. //
  114. // Input:
  115. // None
  116. //
  117. // Output:
  118. // NO_ERROR: successful; otherwise: fail
  119. //
  120. //---------------------------------------------------------------------------
  121. VP_STATUS VgaGetContrastFactor(
  122. PHW_DEVICE_EXTENSION HwDeviceExtension,
  123. PCONTRAST_VALUE value,
  124. ULONG ValueLength,
  125. PULONG OutputSize
  126. )
  127. {
  128. VP_STATUS status ;
  129. int i ;
  130. VideoDebugPrint((2, "VgaGetContrastFactor\n")) ;
  131. if ( ValueLength < (*OutputSize = sizeof(PCONTRAST_VALUE)) ) {
  132. return ERROR_INSUFFICIENT_BUFFER;
  133. }
  134. status = GetContrastKeyInfoFromReg(HwDeviceExtension) ;
  135. if (status == NO_ERROR)
  136. {
  137. for (i = 0; i < 4; i++)
  138. value->value[i] = GammaInfo[i] ;
  139. }
  140. else if (status == ERROR_INVALID_PARAMETER)
  141. {
  142. //
  143. // If no subkey exists, we assign the default value. Otherwise the
  144. // system would fail.
  145. //
  146. for (i = 0; i < 4; i++)
  147. value->value[i] = 0x80 ;
  148. status = NO_ERROR ;
  149. }
  150. VideoDebugPrint((1, "Contrast value = %lx\n", *value)) ;
  151. return status ;
  152. } // VgaGetContrastFactor
  153. //---------------------------------------------------------------------------
  154. //
  155. // Function: Get Gamma Key information from data registry.
  156. //
  157. // Input:
  158. // None
  159. //
  160. // Output:
  161. // NO_ERROR: successful; otherwise: fail
  162. //
  163. //---------------------------------------------------------------------------
  164. VP_STATUS GetGammaKeyInfoFromReg(
  165. PHW_DEVICE_EXTENSION HwDeviceExtension
  166. )
  167. {
  168. VP_STATUS status ;
  169. VideoDebugPrint((2, "GetGammaKeyInfoFromReg\n")) ;
  170. status = VideoPortGetRegistryParameters(HwDeviceExtension,
  171. L"G Gamma",
  172. FALSE,
  173. GetGammaCorrectInfoCallBack,
  174. NULL) ;
  175. if (status != NO_ERROR)
  176. {
  177. VideoDebugPrint((1, "Fail to access Gamma key info from registry\n"));
  178. }
  179. return status ;
  180. } // GetGammaKeyInfoFromReg
  181. //---------------------------------------------------------------------------
  182. //
  183. // Function: Get Contrast Key information from data registry.
  184. //
  185. // Input:
  186. // None
  187. //
  188. // Output:
  189. // NO_ERROR: successful; otherwise: fail
  190. //
  191. //---------------------------------------------------------------------------
  192. VP_STATUS GetContrastKeyInfoFromReg(
  193. PHW_DEVICE_EXTENSION HwDeviceExtension
  194. )
  195. {
  196. VP_STATUS status ;
  197. VideoDebugPrint((2, "GetContrastKeyInfoFromReg\n")) ;
  198. status = VideoPortGetRegistryParameters(HwDeviceExtension,
  199. L"G Contrast",
  200. FALSE,
  201. GetGammaCorrectInfoCallBack,
  202. NULL) ;
  203. if (status != NO_ERROR)
  204. {
  205. VideoDebugPrint((1, "Fail to access Contrast key info from registry\n"));
  206. }
  207. return status ;
  208. } // GetContrastKeyInfoFromReg
  209. //---------------------------------------------------------------------------
  210. //
  211. // Function: Get Gamma coorrection information from data registry.
  212. //
  213. // Input:
  214. // None
  215. //
  216. // Output:
  217. // NO_ERROR: successful ; otherwise: fail
  218. //
  219. //---------------------------------------------------------------------------
  220. VP_STATUS
  221. GetGammaCorrectInfoCallBack (
  222. PVOID HwDeviceExtension,
  223. PVOID Context,
  224. PWSTR ValueName,
  225. PVOID ValueData,
  226. ULONG ValueLength
  227. )
  228. /*++
  229. Routine Description:
  230. This routine get the desired info from data registry.
  231. Arguments:
  232. HwDeviceExtension - Supplies a pointer to the miniport's device extension.
  233. Context - Context value passed to the get registry paramters routine.
  234. ValueName - Name of the value requested.
  235. ValueData - Pointer to the requested data.
  236. ValueLength - Length of the requested data.
  237. Return Value:
  238. returns NO_ERROR if the paramter was TRUE.
  239. returns ERROR_INVALID_PARAMETER otherwise.
  240. --*/
  241. {
  242. VideoDebugPrint((2, "GetGammaCorrectInfoCallBack\n"));
  243. if (ValueLength == 0x04)
  244. {
  245. VideoPortMoveMemory (GammaInfo, ValueData, ValueLength) ;
  246. return NO_ERROR ;
  247. }
  248. else
  249. {
  250. return ERROR_INVALID_PARAMETER ;
  251. }
  252. } // GetGammaCorrectInfoCallBack