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.

1358 lines
48 KiB

  1. //==========================================================================;
  2. //
  3. // Decoder - Main decoder implementation
  4. //
  5. // $Date: 21 Aug 1998 21:46:26 $
  6. // $Revision: 1.1 $
  7. // $Author: Tashjian $
  8. //
  9. // $Copyright: (c) 1997 - 1998 ATI Technologies Inc. All Rights Reserved. $
  10. //
  11. //==========================================================================;
  12. #include "mytypes.h"
  13. #include "Scaler.h"
  14. #include "decoder.h"
  15. #include "dcdrvals.h"
  16. #include "capmain.h"
  17. #define CON_vs_BRI // HW does contrast incorrectly, try to adjust in SW
  18. //===========================================================================
  19. // Bt848 Decoder Class Implementation
  20. //===========================================================================
  21. #define REGALIGNMENT 1
  22. /////////////////////////////////////////////////////////////////////////////
  23. // Constructor
  24. /////////////////////////////////////////////////////////////////////////////
  25. Decoder::Decoder(PDEVICE_PARMS pDeviceParms) :
  26. // init register min, max, default
  27. m_regHue(HueMin, HueMax, HueDef),
  28. m_regSaturationNTSC(SatMinNTSC, SatMaxNTSC, SatDefNTSC),
  29. m_regSaturationSECAM(SatMinSECAM, SatMaxSECAM, SatDefSECAM),
  30. m_regContrast(ConMin, ConMax, ConDef),
  31. m_regBrightness(BrtMin, BrtMax, BrtDef),
  32. m_param(ParamMin, ParamMax, ParamDef),
  33. decRegSTATUS (((0x00 + 0) * REGALIGNMENT) + 0, RW, pDeviceParms) ,
  34. decFieldHLOC(decRegSTATUS, 6, 1, RW) ,
  35. decFieldNUML(decRegSTATUS, 4, 1, RW) ,
  36. decFieldCSEL(decRegSTATUS, 3, 1, RW) ,
  37. decFieldSTATUS_RES(decRegSTATUS, 2, 1, RW) ,
  38. decFieldLOF(decRegSTATUS, 1, 1, RW) ,
  39. decFieldCOF(decRegSTATUS, 0, 1, RW) ,
  40. decRegIFORM (((0x01 + 0) * REGALIGNMENT) + 0, RW, pDeviceParms) ,
  41. decFieldHACTIVE(decRegIFORM, 7, 1, RW) ,
  42. decFieldMUXSEL(decRegIFORM, 5, 2, RW) ,
  43. decFieldXTSEL(decRegIFORM, 3, 2, RW) ,
  44. decFieldFORMAT(decRegIFORM, 0, 3, RW) ,
  45. decRegTDEC (((0x02 + 0) * REGALIGNMENT) + 0, RW, pDeviceParms) ,
  46. decFieldDEC_FIELD(decRegTDEC, 7, 1, RW) ,
  47. decFieldDEC_FIELDALIGN(decRegTDEC, 6, 1, RW) ,
  48. decFieldDEC_RAT(decRegTDEC, 0, 6, RW) ,
  49. decRegBRIGHT (((0x0A + 0) * REGALIGNMENT) + 0, RW, pDeviceParms) ,
  50. decRegMISCCONTROL (((0x0B + 0) * REGALIGNMENT) + 0, RW, pDeviceParms) ,
  51. decFieldLNOTCH(decRegMISCCONTROL, 7, 1, RW) ,
  52. decFieldCOMP(decRegMISCCONTROL, 6, 1, RW) ,
  53. decFieldLDEC(decRegMISCCONTROL, 5, 1, RW) ,
  54. decFieldMISCCONTROL_RES(decRegMISCCONTROL, 3, 1, RW) ,
  55. decFieldCON_MSB(decRegMISCCONTROL, 2, 1, RW) ,
  56. decFieldSAT_U_MSB(decRegMISCCONTROL, 1, 1, RW) ,
  57. decFieldSAT_V_MSB(decRegMISCCONTROL, 0, 1, RW) ,
  58. decRegCONTRAST_LO (((0x0C + 0) * REGALIGNMENT) + 0, RW, pDeviceParms) ,
  59. decRegSAT_U_LO (((0x0D + 0) * REGALIGNMENT) + 0, RW, pDeviceParms) ,
  60. decRegSAT_V_LO (((0x0E + 0) * REGALIGNMENT) + 0, RW, pDeviceParms) ,
  61. decRegHUE (((0x0F + 0) * REGALIGNMENT) + 0, RW, pDeviceParms) ,
  62. decRegSCLOOP (((0x10 + 0) * REGALIGNMENT) + 0, RW, pDeviceParms) ,
  63. decFieldCAGC(decRegSCLOOP, 6, 1, RW) ,
  64. decFieldCKILL(decRegSCLOOP, 5, 1, RW) ,
  65. decRegWC_UP(((0x11 + 0) * REGALIGNMENT) + 0, RW, pDeviceParms) ,
  66. decRegOFORM (((0x12 + 0) * REGALIGNMENT) + 0, RW, pDeviceParms) ,
  67. decFieldVBI_FRAME(decRegOFORM, 4, 1, RW) ,
  68. decFieldCODE(decRegOFORM, 3, 1, RW) ,
  69. decFieldLEN(decRegOFORM, 2, 1, RW) ,
  70. decRegVSCALE_HI (((0x13 + 0) * REGALIGNMENT) + 0, RW, pDeviceParms) ,
  71. decFieldYCOMB(decRegVSCALE_HI, 7, 1, RW) ,
  72. decFieldCOMB(decRegVSCALE_HI, 6, 1, RW) ,
  73. decFieldINT(decRegVSCALE_HI, 5, 1, RW) ,
  74. decRegTEST (((0x15 + 0) * REGALIGNMENT) + 0, RW, pDeviceParms) ,
  75. decRegVPOLE (((0x16 + 0) * REGALIGNMENT) + 0, RW, pDeviceParms) ,
  76. decFieldOUT_EN (decRegVPOLE, 7, 1, RW),
  77. decFieldDVALID (decRegVPOLE, 6, 1, RW),
  78. decFieldVACTIVE (decRegVPOLE, 5, 1, RW),
  79. decFieldCBFLAG (decRegVPOLE, 4, 1, RW),
  80. decFieldFIELD (decRegVPOLE, 3, 1, RW),
  81. decFieldACTIVE (decRegVPOLE, 2, 1, RW),
  82. decFieldHRESET (decRegVPOLE, 1, 1, RW),
  83. decFieldVRESET (decRegVPOLE, 0, 1, RW),
  84. decRegADELAY (((0x18 + 0) * REGALIGNMENT) + 0, RW, pDeviceParms) ,
  85. decRegBDELAY (((0x19 + 0) * REGALIGNMENT) + 0, RW, pDeviceParms) ,
  86. decRegADC (((0x1A + 0) * REGALIGNMENT) + 0, RW, pDeviceParms) ,
  87. decFieldCLK_SLEEP(decRegADC, 3, 1, RW) ,
  88. decFieldC_SLEEP(decRegADC, 1, 1, RW) ,
  89. decFieldCRUSH(decRegADC, 0, 1, RW),
  90. decRegVTC (((0x1B + 0) * REGALIGNMENT) + 0, RW, pDeviceParms) ,
  91. decFieldHSFMT(decRegVTC, 7, 1, RW) ,
  92. decRegWC_DN(((0x1E + 0) * REGALIGNMENT) + 0, RW, pDeviceParms) ,
  93. decRegSRESET (((0x1F + 0) * REGALIGNMENT) + 0, RW, pDeviceParms),
  94. decRegODD_MISCCONTROL (((0x0B + -0x03) * REGALIGNMENT) + 0x8C, RW, pDeviceParms) ,
  95. decFieldODD_LNOTCH(decRegODD_MISCCONTROL, 7, 1, RW) ,
  96. decFieldODD_COMP(decRegODD_MISCCONTROL, 6, 1, RW) ,
  97. decFieldODD_LDEC(decRegODD_MISCCONTROL, 5, 1, RW) ,
  98. decFieldODD_CBSENSE(decRegODD_MISCCONTROL, 4, 1, RW) ,
  99. decFieldODD_MISCCONTROL_RES(decRegODD_MISCCONTROL, 3, 1, RW) ,
  100. decFieldODD_CON_MSB(decRegODD_MISCCONTROL, 2, 1, RW) ,
  101. decFieldODD_SAT_U_MSB(decRegODD_MISCCONTROL, 1, 1, RW) ,
  102. decFieldODD_SAT_V_MSB(decRegODD_MISCCONTROL, 0, 1, RW) ,
  103. decRegODD_SCLOOP (((0x10 + -0x03) * REGALIGNMENT) + 0x8C, RW, pDeviceParms) ,
  104. decFieldODD_CAGC(decRegODD_SCLOOP, 6, 1, RW) ,
  105. decFieldODD_CKILL(decRegODD_SCLOOP, 5, 1, RW) ,
  106. decFieldODD_HFILT(decRegODD_SCLOOP, 3, 2, RW) ,
  107. decRegODD_VSCALE_HI (((0x13 + -0x03) * REGALIGNMENT) + 0x8C, RW, pDeviceParms) ,
  108. decFieldODD_YCOMB(decRegODD_VSCALE_HI, 7, 1, RW) ,
  109. decFieldODD_COMB(decRegODD_VSCALE_HI, 6, 1, RW) ,
  110. decFieldODD_INT(decRegODD_VSCALE_HI, 5, 1, RW) ,
  111. decRegODD_VTC (((0x1B + -0x03) * REGALIGNMENT) + 0x8C, RW, pDeviceParms) ,
  112. decFieldODD_HSFMT(decRegODD_VTC, 7, 1, RW)
  113. {
  114. if(!(pDeviceParms->chipRev < 4))
  115. {
  116. // need to set this to 0x4F
  117. decRegWC_UP = 0x4F;
  118. // and this one to 0x7F to make sure CRUSH bit works for not plain vanila BT829
  119. decRegWC_DN = 0x7F;
  120. }
  121. // HACTIVE should always be 0
  122. decFieldHACTIVE = 0;
  123. decFieldHSFMT = 0;
  124. // The following lines were commented out in an attempt to
  125. // have a picture which closely matches what an ordinary TV would
  126. // show. However, it should be noted that Brooktree recommended to
  127. // comment out only the 'SetLowColorAutoRemoval' line. Probably the
  128. // best solution of all would be to somehow expose these options
  129. // to the application.
  130. // Instead of using default values, set some registers fields to optimum values
  131. /*
  132. SetLumaDecimation(TRUE);
  133. SetChromaAGC(TRUE);
  134. SetLowColorAutoRemoval(FALSE);
  135. SetAdaptiveAGC(FALSE);
  136. */
  137. // for contrast adjustment purpose
  138. regBright = 0x00; // brightness register value before adjustment
  139. regContrast = 0xD8; // contrast register value before adjustment
  140. m_supportedVideoStandards = KS_AnalogVideo_NTSC_M |
  141. KS_AnalogVideo_NTSC_M_J |
  142. KS_AnalogVideo_PAL_B |
  143. KS_AnalogVideo_PAL_D |
  144. KS_AnalogVideo_PAL_G |
  145. KS_AnalogVideo_PAL_H |
  146. KS_AnalogVideo_PAL_I |
  147. KS_AnalogVideo_PAL_M |
  148. KS_AnalogVideo_PAL_N; //Paul: what BT 829 can support (from L829A_A functional Description)
  149. if(!(pDeviceParms->chipRev < 4))
  150. m_supportedVideoStandards |= KS_AnalogVideo_SECAM_B |
  151. KS_AnalogVideo_SECAM_D |
  152. KS_AnalogVideo_SECAM_G |
  153. KS_AnalogVideo_SECAM_H |
  154. KS_AnalogVideo_SECAM_K |
  155. KS_AnalogVideo_SECAM_K1 |
  156. KS_AnalogVideo_SECAM_L |
  157. KS_AnalogVideo_SECAM_L1;
  158. m_supportedVideoStandards &= pDeviceParms->ulVideoInStandardsSupportedByCrystal; //Paul: AND with whatever supported by the onboard crystal
  159. // jaybo
  160. // loop until we find a supported TV standard, and use that to init
  161. UINT k;
  162. for (k = 1; k; k += k) {
  163. if (k & m_supportedVideoStandards) {
  164. SetVideoDecoderStandard(k);
  165. break;
  166. }
  167. }
  168. // end jaybo
  169. }
  170. /////////////////////////////////////////////////////////////////////////////
  171. // Destructor
  172. /////////////////////////////////////////////////////////////////////////////
  173. Decoder::~Decoder()
  174. {
  175. }
  176. void Decoder::GetVideoDecoderCaps(PKSPROPERTY_VIDEODECODER_CAPS_S pS)
  177. {
  178. pS->StandardsSupported = m_supportedVideoStandards;
  179. pS->Capabilities = KS_VIDEODECODER_FLAGS_CAN_DISABLE_OUTPUT |
  180. KS_VIDEODECODER_FLAGS_CAN_INDICATE_LOCKED ;
  181. // How long (ms) til locked indicator is valid.
  182. // 31 line periods * 63.5uS per line.
  183. pS->SettlingTime = 2;
  184. // Not sure about this
  185. // HSync per VSync
  186. pS->HSyncPerVSync = 6;
  187. }
  188. void Decoder::GetVideoDecoderStatus(PKSPROPERTY_VIDEODECODER_STATUS_S pS)
  189. {
  190. pS->NumberOfLines = Is525LinesVideo() ? 525 : 625;
  191. pS->SignalLocked = decFieldHLOC == 1;
  192. }
  193. DWORD Decoder::GetVideoDecoderStandard()
  194. {
  195. return m_videoStandard; //Paul
  196. }
  197. BOOL Decoder::SetVideoDecoderStandard(DWORD standard)
  198. {
  199. if (m_supportedVideoStandards & standard) //Paul: standard must be a supported standard
  200. {
  201. m_videoStandard = standard;
  202. switch ( m_videoStandard )
  203. {
  204. case KS_AnalogVideo_NTSC_M:
  205. Decoder::SetVideoFormat(VFormat_NTSC);
  206. break;
  207. case KS_AnalogVideo_NTSC_M_J:
  208. Decoder::SetVideoFormat(VFormat_NTSC_J);
  209. break;
  210. case KS_AnalogVideo_PAL_B:
  211. case KS_AnalogVideo_PAL_D:
  212. case KS_AnalogVideo_PAL_G:
  213. case KS_AnalogVideo_PAL_H:
  214. case KS_AnalogVideo_PAL_I:
  215. Decoder::SetVideoFormat(VFormat_PAL_BDGHI); // PAL_BDGHI covers most areas
  216. break;
  217. case KS_AnalogVideo_PAL_M:
  218. Decoder::SetVideoFormat(VFormat_PAL_M);
  219. break;
  220. case KS_AnalogVideo_PAL_N:
  221. Decoder::SetVideoFormat(VFormat_PAL_N_COMB);
  222. break;
  223. default: //Paul: SECAM
  224. Decoder::SetVideoFormat(VFormat_SECAM);
  225. }
  226. return TRUE;
  227. }
  228. else
  229. return FALSE;
  230. }
  231. //===== Device Status register ==============================================
  232. /////////////////////////////////////////////////////////////////////////////
  233. // Method: BOOL Decoder::Is525LinesVideo()
  234. // Purpose: Check to see if we are dealing with 525 lines video signal
  235. // Input: None
  236. // Output: None
  237. // Return: TRUE if 525 lines detected; else FALSE (assume 625 lines)
  238. /////////////////////////////////////////////////////////////////////////////
  239. BOOL Decoder::Is525LinesVideo()
  240. {
  241. return (BOOL) (decFieldNUML == 0); //525
  242. }
  243. /////////////////////////////////////////////////////////////////////////////
  244. // Method: BOOL Decoder::IsCrystal0Selected()
  245. // Purpose: Reflect whether XTAL0 or XTAL1 is selected
  246. // Input: None
  247. // Output: None
  248. // Return: TRUE if XTAL0 selected; else FALSE (XTAL1 selected)
  249. /////////////////////////////////////////////////////////////////////////////
  250. BOOL Decoder::IsCrystal0Selected()
  251. {
  252. return (BOOL) (decFieldCSEL == 0);
  253. }
  254. /////////////////////////////////////////////////////////////////////////////
  255. // Method: BOOL Decoder::IsLumaOverflow()
  256. // Purpose: Indicates if luma ADC overflow
  257. // Input: None
  258. // Output: None
  259. // Return: TRUE if luma ADC overflow; else FALSE
  260. /////////////////////////////////////////////////////////////////////////////
  261. BOOL Decoder::IsLumaOverflow()
  262. {
  263. return (BOOL) (decFieldLOF == 1);
  264. }
  265. /////////////////////////////////////////////////////////////////////////////
  266. // Method: void Decoder::ResetLumaOverflow()
  267. // Purpose: Reset luma ADC overflow bit
  268. // Input: None
  269. // Output: None
  270. // Return: None
  271. /////////////////////////////////////////////////////////////////////////////
  272. void Decoder::ResetLumaOverflow()
  273. {
  274. decFieldLOF = 0; // write to it will reset the bit
  275. }
  276. /////////////////////////////////////////////////////////////////////////////
  277. // Method: BOOL Decoder::IsChromaOverflow()
  278. // Purpose: Indicates if chroma ADC overflow
  279. // Input: None
  280. // Output: None
  281. // Return: TRUE if chroma ADC overflow; else FALSE
  282. /////////////////////////////////////////////////////////////////////////////
  283. BOOL Decoder::IsChromaOverflow()
  284. {
  285. return (BOOL) (decFieldCOF == 1);
  286. }
  287. /////////////////////////////////////////////////////////////////////////////
  288. // Method: void Decoder::ResetChromaOverflow()
  289. // Purpose: Reset chroma ADC overflow bit
  290. // Input: None
  291. // Output: None
  292. // Return: None
  293. /////////////////////////////////////////////////////////////////////////////
  294. void Decoder::ResetChromaOverflow()
  295. {
  296. decFieldCOF = 0; // write to it will reset the bit
  297. }
  298. //===== Input Format register ===============================================
  299. /////////////////////////////////////////////////////////////////////////////
  300. // Method: ErrorCode Decoder::SetVideoInput(Connector source)
  301. // Purpose: Select which connector as input
  302. // Input: Connector source - SVideo, Tuner, Composite
  303. // Output: None
  304. // Return: Fail if error in parameter, else Success
  305. /////////////////////////////////////////////////////////////////////////////
  306. ErrorCode Decoder::SetVideoInput(Connector source)
  307. {
  308. if ((source != ConSVideo) &&
  309. (source != ConTuner) &&
  310. (source != ConComposite))
  311. return Fail;
  312. decFieldMUXSEL = (ULONG)source + 1;
  313. // set to composite or Y/C component video depends on video source
  314. SetCompositeVideo((source == ConSVideo) ? FALSE : TRUE);
  315. return Success;
  316. }
  317. /////////////////////////////////////////////////////////////////////////////
  318. // Method: Connector Decoder::GetVideoInput()
  319. // Purpose: Get which connector is input
  320. // Input: None
  321. // Output: None
  322. // Return: Video source - SVideo, Tuner, Composite
  323. /////////////////////////////////////////////////////////////////////////////
  324. Connector Decoder::GetVideoInput()
  325. {
  326. return ((Connector)(decFieldMUXSEL-1));
  327. }
  328. /////////////////////////////////////////////////////////////////////////////
  329. // Method: ErrorCode Decoder::SetCrystal(Crystal crystalNo)
  330. // Purpose: Select which crystal as input
  331. // Input: Crystal crystalNo:
  332. // XT0 - Crystal_XT0
  333. // XT1 - Crystal_XT1
  334. // Auto select - Crystal_AutoSelect
  335. // Output: None
  336. // Return: Fail if error in parameter, else Success
  337. /////////////////////////////////////////////////////////////////////////////
  338. ErrorCode Decoder::SetCrystal(Crystal crystalNo)
  339. {
  340. if ((crystalNo < Crystal_XT0) || (crystalNo > Crystal_AutoSelect))
  341. return Fail;
  342. decFieldXTSEL = crystalNo;
  343. return Success;
  344. }
  345. /////////////////////////////////////////////////////////////////////////////
  346. // Method: int Decoder::GetCrystal()
  347. // Purpose: Get which crystal is input
  348. // Input: None
  349. // Output: None
  350. // Return: Crystal Number:
  351. // XT0 - Crystal_XT0
  352. // XT1 - Crystal_XT1
  353. // Auto select - Crystal_AutoSelect
  354. /////////////////////////////////////////////////////////////////////////////
  355. int Decoder::GetCrystal()
  356. {
  357. return ((int)decFieldXTSEL);
  358. }
  359. /////////////////////////////////////////////////////////////////////////////
  360. // Method: ErrorCode Decoder::SetVideoFormat(VideoFormat format)
  361. // Purpose: Set video format
  362. // Input: Video format -
  363. // Auto format: VFormat_AutoDetect
  364. // NTSC (M): VFormat_NTSC
  365. // NTSC Japan: VFormat_NTSC_J
  366. // PAL (B, D, G, H, I): VFormat_PAL_BDGHI
  367. // PAL (M): VFormat_PAL_M
  368. // PAL(N): VFormat_PAL_N
  369. // SECAM: VFormat_SECAM
  370. // PAN(N Combo) VFormat_PAL_N_COMB
  371. // Output: None
  372. // Return: Fail if error in parameter, else Success
  373. // Notes: Available video formats are: NTSC, PAL(B, D, G, H, I), PAL(M),
  374. // PAL(N), SECAM
  375. // This function also sets the AGCDelay (ADELAY) and BrustDelay
  376. // (BDELAY) registers
  377. /////////////////////////////////////////////////////////////////////////////
  378. ErrorCode Decoder::SetVideoFormat(VideoFormat format)
  379. {
  380. if ((format < VFormat_AutoDetect) ||
  381. (format > VFormat_PAL_N_COMB))
  382. return Fail;
  383. switch (format)
  384. {
  385. case VFormat_PAL_M:
  386. case VFormat_NTSC:
  387. case VFormat_NTSC_J:
  388. decFieldFORMAT = format;
  389. decRegADELAY = 0x68;
  390. decRegBDELAY = 0x5D;
  391. SetChromaComb(TRUE); // enable chroma comb
  392. SelectCrystal('N'); // select NTSC crystal
  393. break;
  394. case VFormat_PAL_BDGHI:
  395. case VFormat_PAL_N:
  396. decFieldFORMAT = format;
  397. decRegADELAY = 0x7F;
  398. decRegBDELAY = 0x72;
  399. SetChromaComb(TRUE); // enable chroma comb
  400. SelectCrystal('P'); // select PAL crystal
  401. break;
  402. case VFormat_PAL_N_COMB:
  403. decFieldFORMAT = format;
  404. decRegADELAY = 0x7F;
  405. decRegBDELAY = 0x72;
  406. SetChromaComb(TRUE); // enable chroma comb
  407. SelectCrystal('N'); // select NTSC crystal
  408. break;
  409. case VFormat_SECAM:
  410. decFieldFORMAT = format;
  411. decRegADELAY = 0x7F;
  412. decRegBDELAY = 0xA0;
  413. SetChromaComb(FALSE); // disable chroma comb
  414. SelectCrystal('P'); // select PAL crystal
  415. break;
  416. default: // VFormat_AutoDetect
  417. // auto format detect by examining the number of lines
  418. if (Decoder::Is525LinesVideo()) // lines == 525 -> NTSC
  419. Decoder::SetVideoFormat(VFormat_NTSC);
  420. else // lines == 625 -> PAL/SECAM
  421. Decoder::SetVideoFormat(VFormat_PAL_BDGHI); // PAL_BDGHI covers most areas
  422. }
  423. SetSaturation(m_satParam);
  424. return Success;
  425. }
  426. /////////////////////////////////////////////////////////////////////////////
  427. // Method: int Decoder::GetVideoFormat()
  428. // Purpose: Obtain video format
  429. // Input: None
  430. // Output: None
  431. // Return: Video format
  432. // Auto format: VFormat_AutoDetect
  433. // NTSC (M): VFormat_NTSC
  434. // PAL (B, D, G, H, I): VFormat_PAL_BDGHI
  435. // PAL (M): VFormat_PAL_M
  436. // PAL(N): VFormat_PAL_N
  437. // SECAM: VFormat_SECAM
  438. // PAN(N Combo) VFormat_PAL_N_COMB
  439. /////////////////////////////////////////////////////////////////////////////
  440. int Decoder::GetVideoFormat()
  441. {
  442. BYTE bFormat = (BYTE)decFieldFORMAT;
  443. if (!bFormat) // autodetection enabled
  444. return Is525LinesVideo() ? VFormat_NTSC : VFormat_SECAM;
  445. else
  446. return bFormat;
  447. }
  448. //===== Temporal Decimation register ========================================
  449. /////////////////////////////////////////////////////////////////////////////
  450. // Method: ErrorCode Decoder::SetRate(BOOL fields, VidField even, int rate)
  451. // Purpose: Set frames or fields rate
  452. // Input: BOOL fields - TRUE for fields, FALSE for frames
  453. // VidField even - TRUE to start decimation with even field, FALSE odd
  454. // int rate - decimation rate: frames (1-50/60); fields(1-25/30)
  455. // Output: None
  456. // Return: Fail if error in parameter, else Success
  457. /////////////////////////////////////////////////////////////////////////////
  458. ErrorCode Decoder::SetRate(BOOL fields, VidField vf, int rate)
  459. {
  460. int nMax;
  461. if (Is525LinesVideo() == TRUE)
  462. nMax = 30; // NTSC
  463. else
  464. nMax = 25; // PAL/SECAM
  465. // if setting frame rate, double the max value
  466. if (fields == FALSE)
  467. nMax *= 2;
  468. if (rate < 0 || rate > nMax)
  469. return Fail;
  470. decFieldDEC_FIELD = (fields == FALSE) ? Off : On;
  471. decFieldDEC_FIELDALIGN = (vf == VF_Even) ? On : Off;
  472. int nDrop = (BYTE) nMax - rate;
  473. decFieldDEC_RAT = (BYTE) (fields == FALSE) ? nDrop : nDrop * 2;
  474. return Success;
  475. }
  476. //===== Brightness Control register =========================================
  477. /////////////////////////////////////////////////////////////////////////////
  478. // Method: ErrorCode Decoder::SetBrightness(int param)
  479. // Purpose: Set video brightness
  480. // Input: int param - parameter value (0-255; default 128)
  481. // Output: None
  482. // Return: Fail if error in parameter, else Success
  483. // Note: See IsAdjustContrast() for detailed description of the contrast
  484. // adjustment calculation
  485. /////////////////////////////////////////////////////////////////////////////
  486. ErrorCode Decoder::SetBrightness(int param)
  487. {
  488. if(m_param.OutOfRange(param))
  489. return Fail;
  490. // perform mapping to our range
  491. int mapped;
  492. if (Mapping(param, m_param, &mapped, m_regBrightness) == Fail)
  493. return Fail;
  494. m_briParam = (WORD)param;
  495. // calculate brightness value
  496. int value = (128 * mapped) / m_regBrightness.Max() ;
  497. // need to limit the value to 0x7F (+50%) because 0x80 is -50%!
  498. if ((mapped > 0) && (value == 0x80))
  499. value = 0x7F;
  500. // perform adjustment of brightness register if adjustment is needed
  501. if (IsAdjustContrast())
  502. {
  503. regBright = value; // brightness value before adjustment
  504. long A = (long)regBright * (long)0xD8;
  505. long B = 64 * ((long)0xD8 - (long)regContrast);
  506. long temp = 0x00;
  507. if (regContrast != 0) // already limit contrast > zero; just in case here
  508. temp = ((A + B) / (long)regContrast);
  509. temp = (temp < -128) ? -128 : ((temp > 127) ? 127 : temp);
  510. value = (BYTE)temp;
  511. }
  512. decRegBRIGHT = (BYTE)value;
  513. return Success;
  514. }
  515. /////////////////////////////////////////////////////////////////////////////
  516. // Method: int Decoder::GetBrightness()
  517. // Purpose: Obtain brightness value
  518. // Input: None
  519. // Output: None
  520. // Return: Brightness parameter (0-255)
  521. /////////////////////////////////////////////////////////////////////////////
  522. int Decoder::GetBrightness()
  523. {
  524. return m_briParam;
  525. }
  526. //===== Miscellaneous Control register (E_CONTROL, O_CONTROL) ===============
  527. /////////////////////////////////////////////////////////////////////////////
  528. // Method: void Decoder::SetLumaNotchFilter(BOOL mode)
  529. // Purpose: Enable/Disable luma notch filter
  530. // Input: BOOL mode - TRUE = Enable; FALSE = Disable
  531. // Output: None
  532. // Return: None
  533. /////////////////////////////////////////////////////////////////////////////
  534. void Decoder::SetLumaNotchFilter(BOOL mode)
  535. {
  536. decFieldLNOTCH = (mode == FALSE) ? On : Off; // reverse
  537. }
  538. /////////////////////////////////////////////////////////////////////////////
  539. // Method: BOOL Decoder::IsLumaNotchFilter()
  540. // Purpose: Check if luma notch filter is enable or disable
  541. // Input: None
  542. // Output: None
  543. // Return: TRUE = Enable; FALSE = Disable
  544. /////////////////////////////////////////////////////////////////////////////
  545. BOOL Decoder::IsLumaNotchFilter()
  546. {
  547. return (decFieldLNOTCH == Off) ? TRUE : FALSE; // reverse
  548. }
  549. /////////////////////////////////////////////////////////////////////////////
  550. // Method: void Decoder::SetCompositeVideo(BOOL mode)
  551. // Purpose: Select composite or Y/C component video
  552. // Input: BOOL mode - TRUE = Composite; FALSE = Y/C Component
  553. // Output: None
  554. // Return: None
  555. /////////////////////////////////////////////////////////////////////////////
  556. void Decoder::SetCompositeVideo(BOOL mode)
  557. {
  558. if (mode == TRUE)
  559. {
  560. // composite video
  561. decFieldCOMP = Off;
  562. Decoder::SetChromaADC(FALSE); // disable chroma ADC
  563. Decoder::SetLumaNotchFilter(TRUE); // enable luma notch filter
  564. }
  565. else
  566. {
  567. // Y/C Component video
  568. decFieldCOMP = On;
  569. Decoder::SetChromaADC(TRUE); // enable chroma ADC
  570. Decoder::SetLumaNotchFilter(FALSE); // disable luma notch filter
  571. }
  572. }
  573. /////////////////////////////////////////////////////////////////////////////
  574. // Method: void Decoder::SetLumaDecimation(BOOL mode)
  575. // Purpose: Enable/Disable luma decimation filter
  576. // Input: BOOL mode - TRUE = Enable; FALSE = Disable
  577. // Output: None
  578. // Return: None
  579. /////////////////////////////////////////////////////////////////////////////
  580. void Decoder::SetLumaDecimation(BOOL mode)
  581. {
  582. // value of 0 turns the decimation on
  583. decFieldLDEC = (mode == TRUE) ? 0 : 1;
  584. }
  585. //===== Luma Gain register (CON_MSB, CONTRAST_LO) ===========================
  586. /////////////////////////////////////////////////////////////////////////////
  587. // Method: ErrorCode Decoder::SetContrast(int param)
  588. // Purpose: Set video contrast
  589. // Input: int param - parameter value (0-255; default 128)
  590. // Output: None
  591. // Return: Fail if error in parameter, else Success
  592. // Note: See IsAdjustContrast() for detailed description of the contrast
  593. // adjustment calculation
  594. /////////////////////////////////////////////////////////////////////////////
  595. ErrorCode Decoder::SetContrast(int param)
  596. {
  597. if(m_param.OutOfRange(param))
  598. return Fail;
  599. BOOL adjustContrast = IsAdjustContrast(); // is contrast need to be adjusted
  600. // if adjust contrast is needed, make sure contrast reg value != 0
  601. if (adjustContrast)
  602. m_regContrast = CRegInfo(1, ConMax, ConDef);
  603. // perform mapping to our range
  604. int mapped;
  605. if (Mapping(param, m_param, &mapped, m_regContrast) == Fail)
  606. return Fail;
  607. m_conParam = (WORD)param;
  608. // calculate contrast
  609. DWORD value = (DWORD)0x1FF * (DWORD)mapped;
  610. value /= (DWORD)m_regContrast.Max();
  611. if (value > 0x1FF)
  612. value = 0x1FF;
  613. // contrast is set by a 9 bit value; set LSB first
  614. decRegCONTRAST_LO = value;
  615. // now set the Miscellaneous Control Register CON_V_MSB to the 9th bit value
  616. decFieldCON_MSB = ((value & 0x0100) ? On : Off);
  617. // perform adjustment of brightness register if adjustment is needed
  618. if (adjustContrast)
  619. {
  620. regContrast = (WORD)value; // contrast value
  621. long A = (long)regBright * (long)0xD8;
  622. long B = 64 * ((long)0xD8 - (long)regContrast);
  623. long temp = 0x00;
  624. if (regContrast != 0) // already limit contrast > zero; just in case here
  625. temp = ((A + B) / (long)regContrast);
  626. temp = (temp < -128) ? -128 : ((temp > 127) ? 127 : temp);
  627. decRegBRIGHT = (BYTE)temp;
  628. }
  629. return Success;
  630. }
  631. /////////////////////////////////////////////////////////////////////////////
  632. // Method: int Decoder::GetContrast()
  633. // Purpose: Obtain contrast value
  634. // Input: None
  635. // Output: None
  636. // Return: Contrast parameter (0-255)
  637. /////////////////////////////////////////////////////////////////////////////
  638. int Decoder::GetContrast()
  639. {
  640. return m_conParam;
  641. }
  642. //===== Chroma Gain register (SAT_U_MSB, SAT_V_MSB, SAT_U_LO, SAT_V_LO) =====
  643. /////////////////////////////////////////////////////////////////////////////
  644. // Method: ErrorCode Decoder::SetSaturation(int param)
  645. // Purpose: Set color saturation by modifying U and V values
  646. // Input: int param - parameter value (0-255; default 128)
  647. // Output: None
  648. // Return: Fail if error in parameter, else Success
  649. /////////////////////////////////////////////////////////////////////////////
  650. ErrorCode Decoder::SetSaturation(int param)
  651. {
  652. if(m_param.OutOfRange(param))
  653. return Fail;
  654. // color saturation is controlled by two nine bit values:
  655. // ChromaU & ChromaV
  656. // To maintain normal color balance, the ratio between the 2 register
  657. // values should be kept at the power-up default ratio
  658. // Note that U & V values for NTSC and PAL are the same, SECAM is different
  659. WORD nominalNTSC_U = 0xFE; // nominal value (i.e. 100%) for NTSC/PAL
  660. WORD nominalNTSC_V = 0xB4;
  661. WORD nominalSECAM_U = 0x87; // nominal value (i.e. 100%) for SECAM
  662. WORD nominalSECAM_V = 0x85;
  663. CRegInfo regSat; // selected saturation register; NTSC/PAL or SECAM
  664. WORD nominal_U, nominal_V; // selected nominal U and V value; NTSC/PAL or SECAM
  665. // select U & V values of either NTSC/PAL or SECAM to be used for calculation
  666. if (GetVideoFormat() == VFormat_SECAM)
  667. {
  668. nominal_U = nominalSECAM_U;
  669. nominal_V = nominalSECAM_V;
  670. regSat = m_regSaturationSECAM;
  671. }
  672. else
  673. {
  674. nominal_U = nominalNTSC_U;
  675. nominal_V = nominalNTSC_V;
  676. regSat = m_regSaturationNTSC;
  677. }
  678. // perform mapping to our range
  679. int mapped;
  680. if (Mapping(param, m_param, &mapped, regSat) == Fail)
  681. return Fail;
  682. m_satParam = (WORD)param;
  683. WORD max_nominal = max(nominal_U, nominal_V);
  684. // calculate U and V values
  685. WORD Uvalue = (WORD) ((DWORD)mapped * (DWORD)nominal_U / (DWORD)max_nominal);
  686. WORD Vvalue = (WORD) ((DWORD)mapped * (DWORD)nominal_V / (DWORD)max_nominal);
  687. // set U
  688. decRegSAT_U_LO = Uvalue;
  689. // now set the Miscellaneous Control Register SAT_U_MSB to the 9th bit value
  690. decFieldSAT_U_MSB = ((Uvalue & 0x0100) ? On : Off);
  691. // set V
  692. decRegSAT_V_LO = Vvalue;
  693. // now set the Miscellaneous Control Register SAT_V_MSB to the 9th bit value
  694. decFieldSAT_V_MSB = ((Vvalue & 0x0100) ? On : Off);
  695. return Success;
  696. }
  697. /////////////////////////////////////////////////////////////////////////////
  698. // Method: int Decoder::GetSaturation()
  699. // Purpose: Obtain saturation value
  700. // Input: None
  701. // Output: None
  702. // Return: Saturation parameter (0-255)
  703. /////////////////////////////////////////////////////////////////////////////
  704. int Decoder::GetSaturation()
  705. {
  706. return m_satParam;
  707. }
  708. //===== Hue Control register (HUE) ==========================================
  709. /////////////////////////////////////////////////////////////////////////////
  710. // Method: ErrorCode Decoder::SetHue(int param)
  711. // Purpose: Set video hue
  712. // Input: int param - parameter value (0-255; default 128)
  713. // Output: None
  714. // Return: Fail if error in parameter, else Success
  715. /////////////////////////////////////////////////////////////////////////////
  716. ErrorCode Decoder::SetHue(int param)
  717. {
  718. if(m_param.OutOfRange(param))
  719. return Fail;
  720. // perform mapping to our range
  721. int mapped;
  722. if (Mapping(param, m_param, &mapped, m_regHue) == Fail)
  723. return Fail;
  724. m_hueParam = (WORD)param;
  725. int value = (-128 * mapped) / m_regHue.Max();
  726. if (value > 127)
  727. value = 127;
  728. else if (value < -128)
  729. value = -128;
  730. decRegHUE = value;
  731. return Success;
  732. }
  733. /////////////////////////////////////////////////////////////////////////////
  734. // Method: int Decoder::GetHue()
  735. // Purpose: Obtain hue value
  736. // Input: None
  737. // Output: None
  738. // Return: Hue parameter (0-255)
  739. /////////////////////////////////////////////////////////////////////////////
  740. int Decoder::GetHue()
  741. {
  742. return m_hueParam;
  743. }
  744. //===== SC Loop Control register (E_SCLOOP, O_SCLOOP) =======================
  745. /////////////////////////////////////////////////////////////////////////////
  746. // Method: void Decoder::SetChromaAGC(BOOL mode)
  747. // Purpose: Enable/Disable Chroma AGC compensation
  748. // Input: BOOL mode - TRUE = Enable, FALSE = Disable
  749. // Output: None
  750. // Return: None
  751. /////////////////////////////////////////////////////////////////////////////
  752. void Decoder::SetChromaAGC(BOOL mode)
  753. {
  754. decFieldCAGC = (mode == FALSE) ? Off : On;
  755. }
  756. /////////////////////////////////////////////////////////////////////////////
  757. // Method: BOOL Decoder::IsChromaAGC()
  758. // Purpose: Check if Chroma AGC compensation is enable or disable
  759. // Input: None
  760. // Output: None
  761. // Return: TRUE = Enable, FALSE = Disable
  762. /////////////////////////////////////////////////////////////////////////////
  763. BOOL Decoder::IsChromaAGC()
  764. {
  765. return (decFieldCAGC == On) ? TRUE : FALSE;
  766. }
  767. /////////////////////////////////////////////////////////////////////////////
  768. // Method: void Decoder::SetLowColorAutoRemoval(BOOL mode)
  769. // Purpose: Enable/Disable low color detection and removal
  770. // Input: BOOL mode - TRUE = Enable, FALSE = Disable
  771. // Output: None
  772. // Return: None
  773. /////////////////////////////////////////////////////////////////////////////
  774. void Decoder::SetLowColorAutoRemoval(BOOL mode)
  775. {
  776. decFieldCKILL = (mode == FALSE) ? Off : On;
  777. }
  778. //===== Output Format register (OFORM) ======================================
  779. /////////////////////////////////////////////////////////////////////////////
  780. // Method: void Decoder::SetVBIFrameMode(BOOL mode)
  781. // Purpose: Enable/Disable VBI frame output mode
  782. // Input: BOOL mode - TRUE = Enable, FALSE = Disable
  783. // Output: None
  784. // Return: None
  785. /////////////////////////////////////////////////////////////////////////////
  786. void Decoder::SetVBIFrameMode(BOOL mode)
  787. {
  788. decFieldVBI_FRAME = (mode == FALSE) ? Off : On;
  789. }
  790. /////////////////////////////////////////////////////////////////////////////
  791. // Method: BOOL Decoder::IsVBIFrameMode()
  792. // Purpose: Check if VBI frame output mode is enabled
  793. // Input: None
  794. // Output: None
  795. // Return: TRUE = Enable, FALSE = Disable
  796. /////////////////////////////////////////////////////////////////////////////
  797. BOOL Decoder::IsVBIFrameMode()
  798. {
  799. return (decFieldVBI_FRAME == On) ? TRUE : FALSE;
  800. }
  801. /////////////////////////////////////////////////////////////////////////////
  802. // Method: void Decoder::SetCodeInsertionEnabled(BOOL mode)
  803. // Purpose:
  804. // Input: BOOL mode - TRUE = Disabled, FALSE = Enabled
  805. // Output: None
  806. // Return: None
  807. /////////////////////////////////////////////////////////////////////////////
  808. void Decoder::SetCodeInsertionEnabled(BOOL mode)
  809. {
  810. decFieldCODE = (mode == TRUE) ? On : Off;
  811. }
  812. /////////////////////////////////////////////////////////////////////////////
  813. // Method: BOOL Decoder::IsCodeInsertionEnabled()
  814. // Purpose: Check if code insertion in data stream is enabled
  815. // Input: None
  816. // Output: None
  817. // Return: TRUE = enabled, FALSE = disabled
  818. /////////////////////////////////////////////////////////////////////////////
  819. BOOL Decoder::IsCodeInsertionEnabled()
  820. {
  821. return (decFieldCODE == On) ? TRUE : FALSE;
  822. }
  823. /////////////////////////////////////////////////////////////////////////////
  824. // Method: void Decoder::Set16BitDataStream(BOOL mode)
  825. // Purpose: 8 or 16 bit data stream
  826. // Input: BOOL mode - TRUE = 16, FALSE = 8
  827. // Output: None
  828. // Return: None
  829. /////////////////////////////////////////////////////////////////////////////
  830. void Decoder::Set16BitDataStream(BOOL mode)
  831. {
  832. decFieldLEN = (mode == TRUE) ? On : Off;
  833. }
  834. /////////////////////////////////////////////////////////////////////////////
  835. // Method: BOOL Decoder::Is16BitDatastream()
  836. // Purpose: Check if 16 bit data stream
  837. // Input: None
  838. // Output: None
  839. // Return: TRUE = 16, FALSE = 8
  840. /////////////////////////////////////////////////////////////////////////////
  841. BOOL Decoder::Is16BitDataStream()
  842. {
  843. return (decFieldLEN == On) ? TRUE : FALSE;
  844. }
  845. //===== Vertical Scaling register (E_VSCALE_HI, O_VSCALE_HI) ================
  846. /////////////////////////////////////////////////////////////////////////////
  847. // Method: void Decoder::SetChromaComb(BOOL mode)
  848. // Purpose: Enable/Disable chroma comb
  849. // Input: BOOL mode - TRUE = Enable, FALSE = Disable
  850. // Output: None
  851. // Return: None
  852. /////////////////////////////////////////////////////////////////////////////
  853. void Decoder::SetChromaComb(BOOL mode)
  854. {
  855. decFieldCOMB = (mode == FALSE) ? Off : On;
  856. }
  857. /////////////////////////////////////////////////////////////////////////////
  858. // Method: BOOL Decoder::IsChromaComb()
  859. // Purpose: Check if chroma comb is enable or disable
  860. // Input: None
  861. // Output: None
  862. // Return: TRUE = Enable, FALSE = Disable
  863. /////////////////////////////////////////////////////////////////////////////
  864. BOOL Decoder::IsChromaComb()
  865. {
  866. return (decFieldCOMB == On) ? TRUE : FALSE;
  867. }
  868. /////////////////////////////////////////////////////////////////////////////
  869. // Method: void Decoder::SetInterlaced(BOOL mode)
  870. // Purpose: Enable/Disable Interlace
  871. // Input: BOOL mode - TRUE = Interlaced
  872. // Output: None
  873. // Return: None
  874. /////////////////////////////////////////////////////////////////////////////
  875. void Decoder::SetInterlaced(BOOL mode)
  876. {
  877. decFieldINT = (mode == FALSE) ? Off : On;
  878. }
  879. /////////////////////////////////////////////////////////////////////////////
  880. // Method: BOOL Decoder::IsInterlaced()
  881. // Purpose: Check if interlaced or non-interlaced
  882. // Input: None
  883. // Output: None
  884. // Return: TRUE = Interlaced
  885. /////////////////////////////////////////////////////////////////////////////
  886. BOOL Decoder::IsInterlaced()
  887. {
  888. return (decFieldINT == On) ? TRUE : FALSE;
  889. }
  890. //===== VPOLE register ==================================================
  891. BOOL Decoder::IsOutputEnabled ()
  892. {
  893. return (decFieldOUT_EN == m_outputEnablePolarity);
  894. }
  895. void Decoder::SetOutputEnabled (BOOL mode)
  896. {
  897. decFieldOUT_EN = (mode == TRUE) ? m_outputEnablePolarity : !m_outputEnablePolarity;
  898. }
  899. BOOL Decoder::IsHighOdd ()
  900. {
  901. return (decFieldFIELD == 0); // 0 enabled; 1 even
  902. }
  903. void Decoder::SetHighOdd (BOOL mode)
  904. {
  905. decFieldFIELD = (mode == TRUE) ? 0 : 1; // 0 enabled; 1 even
  906. }
  907. //===== ADC Interface register (ADC) =========================================
  908. /////////////////////////////////////////////////////////////////////////////
  909. // Method: void Decoder::PowerDown(BOOL mode)
  910. // Purpose: Select normal or shut down clock operation
  911. // Input: BOOL mode - TRUE = shut down, FALSE = normal operation
  912. // Output: None
  913. // Return: None
  914. /////////////////////////////////////////////////////////////////////////////
  915. void Decoder::PowerDown(BOOL mode)
  916. {
  917. decFieldCLK_SLEEP = (mode == FALSE) ? Off : On;
  918. }
  919. /////////////////////////////////////////////////////////////////////////////
  920. // Method: BOOL Decoder::IsPowerDown()
  921. // Purpose: Check if clock operation has been shut down
  922. // Input: None
  923. // Output: None
  924. // Return: TRUE = shut down, FALSE = normal operation
  925. /////////////////////////////////////////////////////////////////////////////
  926. BOOL Decoder::IsPowerDown()
  927. {
  928. return (decFieldCLK_SLEEP == On) ? TRUE : FALSE;
  929. }
  930. /////////////////////////////////////////////////////////////////////////////
  931. // Method: void Decoder::SetChromaADC(BOOL mode)
  932. // Purpose: Select normal or sleep C ADC operation
  933. // Input: BOOL mode - TRUE = normal, FALSE = sleep
  934. // Output: None
  935. // Return: None
  936. /////////////////////////////////////////////////////////////////////////////
  937. void Decoder::SetChromaADC(BOOL mode)
  938. {
  939. decFieldC_SLEEP = (mode == FALSE) ? On : Off; // reverse
  940. }
  941. /*^^////////////////////////////////////////////////////////////////////////////
  942. // Method: void Decoder::SetAdaptiveAGC(BOOL mode)
  943. // Purpose: Set adaptive or non-adaptive AGC operation
  944. // Input: BOOL mode - TRUE = Adaptive, FALSE = Non-adaptive
  945. // Output: None
  946. // Return: None
  947. *////////////////////////////////////////////////////////////////////////////
  948. void Decoder::SetAdaptiveAGC(BOOL mode)
  949. {
  950. decFieldCRUSH = (mode == FALSE) ? Off : On;
  951. }
  952. /////////////////////////////////////////////////////////////////////////////
  953. // Method: BOOL Decoder::IsAdaptiveAGC()
  954. // Purpose: Check if adaptive or non-adaptive AGC operation is selected
  955. // Input: None
  956. // Output: None
  957. // Return: TRUE = Adaptive, FALSE = Non-adaptive
  958. /////////////////////////////////////////////////////////////////////////////
  959. BOOL Decoder::IsAdaptiveAGC()
  960. {
  961. return (decFieldCRUSH == On) ? TRUE : FALSE;
  962. }
  963. //===== Software Reset register (SRESET) ====================================
  964. /////////////////////////////////////////////////////////////////////////////
  965. // Method: void Decoder::SoftwareReset()
  966. // Purpose: Perform software reset; all registers set to default values
  967. // Input: None
  968. // Output: None
  969. // Return: None
  970. /////////////////////////////////////////////////////////////////////////////
  971. void Decoder::SoftwareReset()
  972. {
  973. decRegSRESET = 0x00; // write any value will do
  974. }
  975. //===== Test Control register (TEST) ========================================
  976. /////////////////////////////////////////////////////////////////////////////
  977. // Method: void Decoder::AdjustInertialDampener(BOOL mode)
  978. // Purpose: for factory diagnostics only
  979. // Input: TRUE or FALSE
  980. // Output: None
  981. // Return: None
  982. // NOTE: For factory diagnostics only!!!!!!!
  983. // John Welch's dirty little secret
  984. /////////////////////////////////////////////////////////////////////////////
  985. void Decoder::AdjustInertialDampener(BOOL mode)
  986. {
  987. #pragma message ("FOR TEST DIAGNOSTICS ONLY! ")
  988. decRegTEST = (mode == FALSE) ? 0x00 : 0x01;
  989. }
  990. /////////////////////////////////////////////////////////////////////////////
  991. // Method: void Decoder::SelectCrystal(char useCrystal)
  992. // Purpose: Select correct crystal for NTSC or PAL
  993. // Input: char useCrystal - 'N' for NTSC; 'P' for PAL
  994. // Output: None
  995. // Return: None
  996. // NOTE: Assume at most 2 crystals installed in hardware. i.e. 1 for NTSC
  997. // and the other for PAL/SECAM.
  998. // If there is only 1 crystal exists (which must be crystal XT0),
  999. // do nothing since it is already selected.
  1000. /////////////////////////////////////////////////////////////////////////////
  1001. void Decoder::SelectCrystal(char useCrystal)
  1002. {
  1003. #pragma message("do something about registry")
  1004. /*
  1005. // locate crystal information in the registry
  1006. // the keys to look for in registry are:
  1007. // 1. Bt848\NumXTAL - number of crystal installed
  1008. // possible values are "1" or "2"
  1009. // 2. Bt848\XT0 - what crystal type is for crystal 0
  1010. // possible values are "NTSC", "PAL"
  1011. // There is another key exist which may be useful in the future:
  1012. // Bt848\XT1 - what crystal type is for crystal 1
  1013. // possible values are "NTSC", "PAL", and "NONE"
  1014. VRegistryKey vkey(PRK_CLASSES_ROOT, "Bt848");
  1015. // make sure the key exists
  1016. if (vkey.lastError() == ERROR_SUCCESS)
  1017. {
  1018. char * numCrystalKey = "NumXTAL";
  1019. char nCrystal[5];
  1020. DWORD nCrystalLen = 2; // need only first char; '1' or '2'
  1021. // get number of crystal exists
  1022. if (vkey.getSubkeyValue(numCrystalKey, nCrystal, (DWORD *)&nCrystalLen))
  1023. {
  1024. // if there is only 1 crystal, no other crystal to change to
  1025. if (nCrystal[0] == '2')
  1026. {
  1027. char * crystalTypeKey = "XT0"; // crystal 0 type
  1028. char crystalType[10];
  1029. DWORD crystalTypeLen = 6; // need only first char: 'N' or 'P'
  1030. // get the crystal 0 information
  1031. if (vkey.getSubkeyValue(crystalTypeKey, crystalType, (DWORD *)&crystalTypeLen))
  1032. // compare with what we want to use
  1033. if ((IsCrystal0Selected() && (crystalType[0] != useCrystal)) ||
  1034. (!IsCrystal0Selected() && (crystalType[0] == useCrystal)))
  1035. // need to change crystal
  1036. SetCrystal(IsCrystal0Selected() ? Crystal_XT1 : Crystal_XT0);
  1037. }
  1038. }
  1039. }
  1040. */
  1041. }
  1042. /////////////////////////////////////////////////////////////////////////////
  1043. // Method: ErrorCode Decoder::Mapping(int fromValue, CRegInfo fromRange,
  1044. // int * toValue, CRegInfo toRange)
  1045. // Purpose: Map a value in certain range to a value in another range
  1046. // Input: int fromValue - value to be mapped from
  1047. // CRegInfo fromRange - range of value mapping from
  1048. // CRegInfo toRange - range of value mapping to
  1049. // Output: int * toValue - mapped value
  1050. // Return: Fail if error in parameter, else Success
  1051. // Comment: No range checking is performed here. Assume parameters are in
  1052. // valid ranges.
  1053. // The mapping function does not assume default is always the mid
  1054. // point of the whole range. It only assumes default values of the
  1055. // two ranges correspond to each other.
  1056. //
  1057. // The mapping formula is:
  1058. //
  1059. // For fromRange.Min() <= fromValue <= fromRange.Default():
  1060. //
  1061. // fromValue (fromRange.Default() - fromRange.Min())
  1062. // ------------------------------------------------ + fromRange.Min()
  1063. // toRange.Default() - toRange.Min()
  1064. //
  1065. // For fromRange.Default() < fromValue <= fromRange.Max():
  1066. //
  1067. // (fromValue - fromRange.Default()) (toRange.Max() - toRange.Default())
  1068. // --------------------------------------------------------------------- + toRange.Default()
  1069. // toRange.Max() - toRange.Default()
  1070. //
  1071. ////////////////////////////////////////////////////////////////////////////
  1072. ErrorCode Decoder::Mapping(int fromValue, CRegInfo fromRange,
  1073. int * toValue, CRegInfo toRange)
  1074. {
  1075. // calculate intermediate values
  1076. DWORD a = toRange.Default() - toRange.Min();
  1077. DWORD b = fromRange.Default() - fromRange.Min();
  1078. DWORD c = toRange.Max() - toRange.Default();
  1079. DWORD d = fromRange.Max() - fromRange.Default();
  1080. // prevent divide by zero
  1081. if ((b == 0) || (d == 0))
  1082. return (Fail);
  1083. // perform mapping
  1084. if (fromValue <= fromRange.Default())
  1085. *toValue = (int) (DWORD)fromValue * a / b + (DWORD)toRange.Min();
  1086. else
  1087. *toValue = (int) ((DWORD)fromValue - (DWORD)fromRange.Default()) * c / d
  1088. + (DWORD)toRange.Default();
  1089. return (Success);
  1090. }
  1091. /////////////////////////////////////////////////////////////////////////////
  1092. // Method: BOOL Decoder::IsAdjustContrast()
  1093. // Purpose: Check registry key whether adjust contrast is needed
  1094. // Input: None
  1095. // Output: None
  1096. // Return: TRUE = adjust contrast, FALSE = don't adjust contrast
  1097. // Note: If adjust contrast is turn on, brightness register value will be
  1098. // adjusted such that it remains a constant after the calculation
  1099. // performed by the hardware.
  1100. //
  1101. // The formula is:
  1102. // To keep brightness constant (i.e. not affect by changing contrast)
  1103. // set brightness to B/(C/C0)
  1104. // where B is value of brightness before adjustment
  1105. // C is contrast value
  1106. // C0 is nominal contrast value (0xD8)
  1107. //
  1108. // To adjust the contrast level such that it is at the middle of
  1109. // black and white: set brightness to (B * C0 + 64 * (C0 - C))/C
  1110. // (this is what Intel wants)
  1111. //
  1112. // Currently there is still limitation of how much adjustment
  1113. // can be performed. For example, if brightness is already high,
  1114. // (i.e. brightness reg value close to 0x7F), lowering contrast
  1115. // until a certain level will have no adjustment effect on brightness.
  1116. // In fact, it would even bring down brightness to darkness.
  1117. //
  1118. // Example 1: if brightness is at nominal value (0x00), contrast can
  1119. // only go down to 0x47 (brightness adjustment is already
  1120. // at max of 0x7F) before it starts affecting brightness
  1121. // which takes it darkness.
  1122. // Example 2: if brightness is at nominal value (0x00), contrast can
  1123. // go all the way up with brightness adjusted correctly.
  1124. // However, the max adjustment used is only 0xDC and
  1125. // the max adjustment we can use is 0x&F.
  1126. // Example 3: if brightness is at max (0x7F), lowering contrast
  1127. // cannot be compensated by adjusting brightness anymore.
  1128. // The result is gradually taking brightness to darkness.
  1129. // Example 4: if brightness is at min (0x80), lowering contrast has
  1130. // no visual effect. Bringing contrast to max is using
  1131. // 0xA5 in brightness for compensation.
  1132. //
  1133. // One last note, the center is defined as the middle of the
  1134. // gamma adjusted luminance level. Changing it to use the middle of
  1135. // the linear (RGB) luminance level is possible.
  1136. /////////////////////////////////////////////////////////////////////////////
  1137. BOOL Decoder::IsAdjustContrast()
  1138. {
  1139. return FALSE;
  1140. /*
  1141. // locate adjust contrast information in the registry
  1142. // the key to look for in registry is:
  1143. // Bt848\AdjustContrast - 0 = don't adjust contrast
  1144. // 1 = adjust contrast
  1145. VRegistryKey vkey(PRK_CLASSES_ROOT, "Bt848");
  1146. // make sure the key exists
  1147. if (vkey.lastError() == ERROR_SUCCESS)
  1148. {
  1149. char * adjustContrastKey = "AdjustContrast";
  1150. char key[3];
  1151. DWORD keyLen = 2; // need only first char; '0' or '1'
  1152. // get the registry value and check it, if exist
  1153. if ((vkey.getSubkeyValue(adjustContrastKey, key, (DWORD *)&keyLen)) &&
  1154. (key[0] == '1'))
  1155. return (TRUE);
  1156. }
  1157. return (FALSE);
  1158. */
  1159. }