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.

224 lines
5.0 KiB

4 years ago
  1. /*
  2. * config.c
  3. *
  4. * 32-bit Video Capture driver
  5. * configuration callback support
  6. *
  7. * Geraint Davies, Feb 93
  8. */
  9. #include <vckernel.h>
  10. #include <bravado.h>
  11. #include "hardware.h"
  12. #include "vidcio.h"
  13. /*
  14. * Configure the destination format - the size, bitdepth of the
  15. * destination dib, and set any necessary translation table to
  16. * translate from YUV to the specified format.
  17. */
  18. BOOLEAN
  19. HW_ConfigFormat(PDEVICE_INFO pDevInfo, PCONFIG_INFO pGeneric)
  20. {
  21. PCONFIG_FORMAT pConfig;
  22. PHWINFO pHw;
  23. int ImageSize;
  24. pConfig = (PCONFIG_FORMAT) pGeneric;
  25. if (pConfig->ulSize != sizeof(CONFIG_FORMAT)) {
  26. return(FALSE);
  27. }
  28. pHw = (PHWINFO) VC_GetHWInfo(pDevInfo);
  29. ImageSize = pConfig->ulWidth * pConfig->ulHeight;
  30. switch(pConfig->Format) {
  31. case FmtYUV:
  32. case FmtRGB24:
  33. if(pHw->pXlate) {
  34. VC_FreeMem(pDevInfo, pHw->pXlate, pHw->ulSizeXlate);
  35. pHw->pXlate = NULL;
  36. }
  37. ImageSize *= (pConfig->Format == FmtYUV ? 2 : 3);
  38. break;
  39. case FmtRGB555:
  40. /*
  41. * build yuv->rgb555 xlate if format is not already FmtRGB555
  42. */
  43. if (pHw->Format != FmtRGB555) {
  44. if (pHw->pXlate != NULL) {
  45. VC_FreeMem(pDevInfo, pHw->pXlate, pHw->ulSizeXlate);
  46. pHw->pXlate = NULL;
  47. }
  48. if (!HW_BuildYUVToRGB555(pDevInfo, pHw)) {
  49. pHw->Format = FmtInvalid;
  50. return(FALSE);
  51. }
  52. }
  53. ImageSize *= 2;
  54. break;
  55. case FmtPal8:
  56. /*
  57. * we are passed xlate table - free up any existing table
  58. */
  59. if (pHw->pXlate) {
  60. VC_FreeMem(pDevInfo, pHw->pXlate, pHw->ulSizeXlate);
  61. pHw->pXlate = NULL;
  62. }
  63. /*
  64. * if no xlate table is passed, then build a default translation
  65. * (for a 64-level grey scale palette)
  66. */
  67. if (pConfig->pXlate == NULL) {
  68. dprintf2(("building default xlate"));
  69. if (!HW_BuildDefaultXlate(pDevInfo, pHw)) {
  70. pHw->Format = FmtInvalid;
  71. return(FALSE);
  72. }
  73. break;
  74. }
  75. /*
  76. * check that the xlate passed is the right size
  77. */
  78. if (pConfig->ulSizeXlate != PAL_TO_RGB555_SIZE) {
  79. dprintf(("bad xlate table passed"));
  80. return(FALSE);
  81. }
  82. /* we need to wrap the access to the table in a call
  83. * to VC_AccessData in order to ensure valid kernel-mode
  84. * access to the data
  85. */
  86. if (!VC_AccessData(pDevInfo, pConfig->pXlate, pConfig->ulSizeXlate,
  87. HW_BuildYuvToPal, NULL)) {
  88. dprintf(("xlate access failed"));
  89. pHw->Format = FmtInvalid;
  90. return(FALSE);
  91. }
  92. break;
  93. default:
  94. dprintf(("bad dib format requested"));
  95. return(FALSE);
  96. }
  97. pHw->Format = pConfig->Format;
  98. pHw->dwWidth = (DWORD) pConfig->ulWidth;
  99. pHw->dwHeight = (DWORD) pConfig->ulHeight;
  100. dprintf2(("dest format %d, %d x %d", pHw->Format, pHw->dwWidth, pHw->dwHeight));
  101. HW_SetScale(pDevInfo, pHw->dwWidth, pHw->dwHeight);
  102. VC_SetImageSize(pDevInfo, ImageSize);
  103. return(TRUE);
  104. }
  105. /*
  106. * Configure the adjustable parameters of the overlay or
  107. * external monitor display. Changing these variables will not
  108. * change the captured image.
  109. */
  110. BOOLEAN
  111. HW_ConfigDisplay(PDEVICE_INFO pDevInfo, PCONFIG_INFO pGeneric)
  112. {
  113. PCONFIG_DISPLAY pConfig;
  114. PHWINFO pHw;
  115. if (pGeneric->ulSize != sizeof(CONFIG_DISPLAY)) {
  116. dprintf(("bad config struct"));
  117. return(FALSE);
  118. }
  119. pConfig = (PCONFIG_DISPLAY) pGeneric;
  120. pHw = (PHWINFO) VC_GetHWInfo(pDevInfo);
  121. HW_Set4680Reg(pDevInfo, 0, (BYTE) (pConfig->ulBrightness & 0x3f));
  122. HW_Set4680Reg(pDevInfo, 1, (BYTE) (pConfig->ulSaturation & 0x3f));
  123. HW_Set4680Reg(pDevInfo, 2, (BYTE) (pConfig->ulContrast & 0x3f));
  124. HW_Set4680Reg(pDevInfo, 4, (BYTE) (pConfig->ulRed & 0x3f));
  125. HW_Set4680Reg(pDevInfo, 5, (BYTE) (pConfig->ulGreen & 0x3f));
  126. HW_Set4680Reg(pDevInfo, 6, (BYTE) (pConfig->ulBlue & 0x3f));
  127. return(TRUE);
  128. }
  129. /*
  130. * configure the source parameters - this controls the acquisition
  131. * of the source image, and will thus affect both the overlay/monitor output,
  132. * and the captured data.
  133. */
  134. BOOLEAN
  135. HW_ConfigSource(PDEVICE_INFO pDevInfo, PCONFIG_INFO pGeneric)
  136. {
  137. PCONFIG_SOURCE pConfig;
  138. PHWINFO pHw;
  139. int RegA, Reg6;
  140. if (pGeneric->ulSize != sizeof(CONFIG_SOURCE)) {
  141. dprintf(("bad config struct"));
  142. return(FALSE);
  143. }
  144. pConfig = (PCONFIG_SOURCE) pGeneric;
  145. pHw = (PHWINFO) VC_GetHWInfo(pDevInfo);
  146. /* set the HUE register - this is 0..3F like all the other
  147. * colour settings: we need to convert this to 0..FF before
  148. * outputing the data.
  149. */
  150. HW_Set9051Reg(pDevInfo, 7, (BYTE) ((pConfig->ulHue & 0xff) * 4));
  151. /* select pal/ntsc video standard */
  152. pHw->VideoStd = pConfig->VideoStd;
  153. HW_SetVideoStd(pDevInfo, pHw);
  154. /* set the cable format and source connector */
  155. RegA = HW_Get9051Reg(pDevInfo, 0xa);
  156. Reg6 = HW_Get9051Reg(pDevInfo, 0x6);
  157. /* strip out source select and composite/svideo bits */
  158. RegA &= 0xC7;
  159. Reg6 &= 0x7f;
  160. /* add back in source connector number */
  161. RegA |= ((pConfig->ulConnector & 0x3) << 3);
  162. /* add back in composite/svideo bits */
  163. if (pConfig->CableFormat == SVideo) {
  164. RegA |= 0x20;
  165. Reg6 |= 0x80;
  166. }
  167. /* set the new values */
  168. HW_Set9051Reg(pDevInfo, 0xa, (BYTE) RegA);
  169. HW_Set9051Reg(pDevInfo, 0x6, (BYTE) Reg6);
  170. return(TRUE);
  171. }