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.

455 lines
14 KiB

  1. /* *************************************************************************
  2. ** INTEL Corporation Proprietary Information
  3. **
  4. ** This listing is supplied under the terms of a license
  5. ** agreement with INTEL Corporation and may not be copied
  6. ** nor disclosed except in accordance with the terms of
  7. ** that agreement.
  8. **
  9. ** Copyright (c) 1995,1996 Intel Corporation.
  10. ** All Rights Reserved.
  11. **
  12. ** *************************************************************************
  13. */
  14. ;//
  15. ;// Description: This module implements the following functions.
  16. ;// CustomChangeBrightness();
  17. ;// CustomChangeContrast();
  18. ;// CustomChangeSaturation();
  19. ;// CustomResetBrightness();
  20. ;// CustomResetContrast();
  21. ;// CustomResetSaturation();
  22. ;// CustomGetBrightness();
  23. ;// CustomGetContrast();
  24. ;// CustomGetSaturation();
  25. ;//
  26. ;// $Author: BECHOLS $
  27. ;// $Date: 09 Dec 1996 08:51:44 $
  28. ;// $Archive: S:\h26x\src\dec\dxctrls.cpv $
  29. ;// $Header: S:\h26x\src\dec\dxctrls.cpv 1.14 09 Dec 1996 08:51:44 BECHOLS $
  30. ;// $Log: S:\h26x\src\dec\dxctrls.cpv $
  31. //
  32. // Rev 1.14 09 Dec 1996 08:51:44 BECHOLS
  33. // Fixed reset saturation, so that it modified chroma table, not luma.
  34. //
  35. // Rev 1.13 20 Oct 1996 13:33:32 AGUPTA2
  36. // Changed DBOUT into DbgLog. ASSERT is not changed to DbgAssert.
  37. //
  38. //
  39. // Rev 1.12 10 Sep 1996 10:31:38 KLILLEVO
  40. // changed all GlobalAlloc/GlobalLock calls to HeapAlloc
  41. //
  42. // Rev 1.11 11 Jul 1996 14:09:18 SCDAY
  43. // Added comments re: CustomGetB/C/S functions
  44. //
  45. // Rev 1.10 10 Jul 1996 08:21:26 SCDAY
  46. // Added functions for CustomGetBrightness/Contrast/Saturation (DBrucks)
  47. //
  48. // Rev 1.9 04 Jun 1996 09:04:00 AKASAI
  49. // Fixed bug in CustomResetSaturation where it was reseting the LumaTable
  50. // instead of the ChromaTable. This was discovered in Quartz testing.
  51. //
  52. // Rev 1.8 01 Feb 1996 10:16:24 BNICKERS
  53. // Fix the "knobs".
  54. //
  55. // Rev 1.7 22 Dec 1995 13:53:06 KMILLS
  56. //
  57. // added new copyright notice
  58. //
  59. // Rev 1.6 17 Nov 1995 15:22:12 BECHOLS
  60. //
  61. // Added ring 0 stuff.
  62. //
  63. // Rev 1.5 01 Nov 1995 16:52:24 TRGARDOS
  64. // Fixed unmatched GlobalUnlocks.
  65. //
  66. // Rev 1.4 25 Oct 1995 18:14:02 BNICKERS
  67. //
  68. // Clean up archive stuff.
  69. //
  70. // Rev 1.3 20 Sep 1995 09:23:52 SCDAY
  71. //
  72. // added #ifdef for #include d?dec.h
  73. //
  74. // Rev 1.2 01 Sep 1995 09:49:36 DBRUCKS
  75. // checkin partial ajdust pels changes
  76. //
  77. // Rev 1.1 23 Aug 1995 12:24:04 DBRUCKS
  78. // change to H26X_DEFAULT_* from H263_ as these are shared values.
  79. //
  80. // Rev 1.0 31 Jul 1995 13:00:14 DBRUCKS
  81. // Initial revision.
  82. //
  83. // Rev 1.1 24 Jul 1995 15:00:40 CZHU
  84. //
  85. // Adjust the changes to the decoder catalog structure
  86. //
  87. // Rev 1.0 17 Jul 1995 14:46:18 CZHU
  88. // Initial revision.
  89. //
  90. // Rev 1.0 17 Jul 1995 14:14:22 CZHU
  91. // Initial revision.
  92. ;////////////////////////////////////////////////////////////////////////////
  93. #include "precomp.h"
  94. #define SCALE 128
  95. #define ACTIVE_RANGE 256
  96. #define OFFSET_TABLE_COPY 256 + 16
  97. typedef BOOL FAR *LPBOOL;
  98. typedef struct {
  99. LPBYTE LumaTable;
  100. LPBOOL LumaFlag;
  101. LPBYTE ChromaTable;
  102. LPBOOL ChromaFlag;
  103. LPBYTE Brightness;
  104. LPBYTE Contrast;
  105. LPBYTE Saturation;
  106. } PIXDAT, FAR *LPPIXDAT;
  107. /**********************************************************************
  108. * static WORD LockLCTables(LPDECINST, LPPIXDAT);
  109. * Description: This function locks the memory and fills the Pixel Data
  110. * Structure with valid pointers to the tables that I need
  111. * to adjust.
  112. * History: 06/29/94 -BEN-
  113. **********************************************************************/
  114. static LRESULT LockLCTables(LPDECINST lpInst, LPPIXDAT lpPixData)
  115. {
  116. T_H263DecoderCatalog *DC;
  117. FX_ENTRY("LockLCTables")
  118. if(IsBadWritePtr((LPVOID)lpInst, sizeof(DECINSTINFO)))
  119. {
  120. ERRORMESSAGE(("%s: ICERR_BADPARAM\r\n", _fx_));
  121. return(ICERR_BADPARAM);
  122. }
  123. DC = (T_H263DecoderCatalog *) ((((U32) lpInst->pDecoderInst) + 31) & ~0x1F);
  124. lpPixData->LumaTable = (LPBYTE)(DC->p16InstPostProcess +
  125. DC->X16_LumaAdjustment);
  126. lpPixData->ChromaTable = (LPBYTE)(DC->p16InstPostProcess +
  127. DC->X16_ChromaAdjustment);
  128. lpPixData->LumaFlag = (LPBOOL)&(DC->bAdjustLuma);
  129. lpPixData->ChromaFlag = (LPBOOL)&(DC->bAdjustChroma);
  130. lpPixData->Brightness = (LPBYTE)&(DC->BrightnessSetting);
  131. lpPixData->Contrast = (LPBYTE)&(DC->ContrastSetting);
  132. lpPixData->Saturation = (LPBYTE)&(DC->SaturationSetting);
  133. return(ICERR_OK);
  134. }
  135. /*********************************************************************
  136. * static LRESULT UnlockLCTables(LPDECINST, LPPIXDAT);
  137. * Description: This funtion unlocks
  138. * History: 06/30/94 -BEN-
  139. **********************************************************************/
  140. static LRESULT UnlockLCTables(LPDECINST lpInst, LPPIXDAT lpPixData)
  141. {
  142. T_H263DecoderCatalog *DC;
  143. DC = (T_H263DecoderCatalog *) ((((U32) lpInst->pDecoderInst) + 31) & ~0x1F);
  144. lpPixData->LumaTable = (LPBYTE)NULL;
  145. lpPixData->ChromaTable = (LPBYTE)NULL;
  146. lpPixData->LumaFlag = (LPBOOL)NULL;
  147. lpPixData->ChromaFlag = (LPBOOL)NULL;
  148. return(ICERR_OK);
  149. }
  150. /**********************************************************************
  151. * static VOID MassageContrast(BYTE, PBYTE);
  152. * Description: input is 0 to 255, 1/SCALE to 256/SCALE inclusive
  153. * 0 = 1/SCALE
  154. * 1 = 2/SCALE
  155. * n = (n + 1) / SCALE
  156. * SCALE - 1 = 1 yields no change
  157. * 255 = 256/SCALE
  158. * if the response is too coarse, SCALE can be increased
  159. * if the response is too fine, SCALE can be decreased
  160. *
  161. * History: 02/22/94 -BEN- Added header.
  162. **********************************************************************/
  163. static VOID MassageContrast(BYTE offsetfactor, LPBYTE table)
  164. {
  165. int i;
  166. long temp, contrastfactor;
  167. contrastfactor = ((long)((DWORD)offsetfactor)) + 1; // 1 - 256
  168. contrastfactor = (contrastfactor * ACTIVE_RANGE) / 256L;
  169. for(i = 0; i < 256; i++)
  170. {
  171. temp = (long)((DWORD)table[i]);
  172. temp -= (ACTIVE_RANGE / 2L); // add centering
  173. temp *= contrastfactor;
  174. temp /= SCALE;
  175. temp += (ACTIVE_RANGE / 2L); // remove centering
  176. if(temp < 0) // and clamp
  177. table[i] = 0;
  178. else if(temp <= 255)
  179. table[i] = (unsigned char) temp;
  180. else
  181. table[i] = 255;
  182. table[i+OFFSET_TABLE_COPY] = table[i];
  183. }
  184. return;
  185. }
  186. ;////////////////////////////////////////////////////////////////////////////
  187. ;// Function: LRESULT CustomChangeBrightness(LPDECINST, BYTE);
  188. ;//
  189. ;// Description: Added header.
  190. ;//
  191. ;// History: 02/22/94 -BEN-
  192. ;////////////////////////////////////////////////////////////////////////////
  193. LRESULT CustomChangeBrightness(LPDECINST lpInst, BYTE offsetdelta)
  194. {
  195. LRESULT lRes;
  196. int delta, temp, i;
  197. PIXDAT PixData;
  198. lRes = LockLCTables(lpInst, &PixData);
  199. if(lRes == ICERR_OK)
  200. {
  201. CustomResetBrightness(lpInst);
  202. if(offsetdelta != H26X_DEFAULT_BRIGHTNESS)
  203. {
  204. delta = ((offsetdelta - 128) * ACTIVE_RANGE) / 256; // -128 to 127
  205. for(i = 0; i < 256; i++)
  206. {
  207. temp = (int)PixData.LumaTable[i] + delta;
  208. if(temp < 0) PixData.LumaTable[i] = 0;
  209. else if(temp <= 255) PixData.LumaTable[i] = (BYTE)temp;
  210. else PixData.LumaTable[i] = 255;
  211. PixData.LumaTable[i+OFFSET_TABLE_COPY] = PixData.LumaTable[i];
  212. }
  213. *(PixData.Brightness) = offsetdelta;
  214. *(PixData.LumaFlag) = TRUE;
  215. }
  216. lRes = UnlockLCTables(lpInst, &PixData);
  217. }
  218. return(lRes);
  219. }
  220. ;////////////////////////////////////////////////////////////////////////////
  221. ;// Function: LRESULT CustomChangeContrast(LPDECINST, BYTE);
  222. ;//
  223. ;// Description: Added header.
  224. ;//
  225. ;// History: 02/22/94 -BEN-
  226. ;////////////////////////////////////////////////////////////////////////////
  227. LRESULT CustomChangeContrast(LPDECINST lpInst, BYTE offsetfactor)
  228. {
  229. LRESULT lRes;
  230. PIXDAT PixData;
  231. lRes = LockLCTables(lpInst, &PixData);
  232. if(lRes == ICERR_OK)
  233. {
  234. CustomResetContrast(lpInst);
  235. if(offsetfactor != H26X_DEFAULT_CONTRAST)
  236. {
  237. MassageContrast(offsetfactor, PixData.LumaTable);
  238. *(PixData.Contrast) = offsetfactor;
  239. *(PixData.LumaFlag) = TRUE;
  240. }
  241. lRes = UnlockLCTables(lpInst, &PixData);
  242. }
  243. return(lRes);
  244. }
  245. ;////////////////////////////////////////////////////////////////////////////
  246. ;// Function: LRESULT CustomChangeSaturation(LPDECINST, BYTE);
  247. ;//
  248. ;// Description: Added header.
  249. ;//
  250. ;// History: 02/22/94 -BEN-
  251. ;////////////////////////////////////////////////////////////////////////////
  252. LRESULT CustomChangeSaturation(LPDECINST lpInst, BYTE offsetfactor)
  253. {
  254. LRESULT lRes;
  255. PIXDAT PixData;
  256. lRes = LockLCTables(lpInst, &PixData);
  257. if(lRes == ICERR_OK)
  258. {
  259. CustomResetSaturation(lpInst);
  260. if(offsetfactor != H26X_DEFAULT_SATURATION)
  261. {
  262. MassageContrast(offsetfactor, PixData.ChromaTable);
  263. *(PixData.Saturation) = offsetfactor;
  264. *(PixData.ChromaFlag) = TRUE;
  265. }
  266. lRes = UnlockLCTables(lpInst, &PixData);
  267. }
  268. return(lRes);
  269. }
  270. #ifdef QUARTZ
  271. /************************************************************************
  272. * CustomGetBrightness
  273. *
  274. * Gets the current brightness value
  275. ***********************************************************************/
  276. LRESULT CustomGetBrightness(
  277. LPDECINST lpInst,
  278. BYTE * pValue)
  279. {
  280. LRESULT lResult = ICERR_ERROR;
  281. T_H263DecoderCatalog *DC;
  282. DC = (T_H263DecoderCatalog *) ((((U32) lpInst->pDecoderInst) + 31) & ~0x1F);
  283. *pValue = (BYTE) DC->BrightnessSetting;
  284. lResult = ICERR_OK;
  285. return lResult;
  286. } /* end CustomGetBrightness() */
  287. /************************************************************************
  288. * CustomGetContrast
  289. *
  290. * Gets the current contrast value
  291. ***********************************************************************/
  292. LRESULT CustomGetContrast(
  293. LPDECINST lpInst,
  294. BYTE * pValue)
  295. {
  296. LRESULT lResult = ICERR_ERROR;
  297. T_H263DecoderCatalog *DC;
  298. DC = (T_H263DecoderCatalog *) ((((U32) lpInst->pDecoderInst) + 31) & ~0x1F);
  299. *pValue = (BYTE) DC->ContrastSetting;
  300. lResult = ICERR_OK;
  301. return lResult;
  302. } /* end CustomGetContrast() */
  303. /************************************************************************
  304. *
  305. * CustomGetSaturation
  306. *
  307. * Gets the current saturation value
  308. ***********************************************************************/
  309. LRESULT CustomGetSaturation(
  310. LPDECINST lpInst,
  311. BYTE * pValue)
  312. {
  313. LRESULT lResult = ICERR_ERROR;
  314. T_H263DecoderCatalog *DC;
  315. DC = (T_H263DecoderCatalog *) ((((U32) lpInst->pDecoderInst) + 31) & ~0x1F);
  316. *pValue = (BYTE) DC->SaturationSetting;
  317. lResult = ICERR_OK;
  318. return lResult;
  319. } /* end CustomGetSaturation() */
  320. #endif /* QUARTZ */
  321. ;////////////////////////////////////////////////////////////////////////////
  322. ;// Function: LRESULT CustomResetBrightness(LPDECINST lpInst);
  323. ;//
  324. ;// Description: Sets the luminance table to identity, and resets
  325. ;// flag indicating need to use.
  326. ;//
  327. ;// History: 02/22/94 -BEN-
  328. ;////////////////////////////////////////////////////////////////////////////
  329. LRESULT CustomResetBrightness(LPDECINST lpInst)
  330. {
  331. LRESULT lRes;
  332. int i;
  333. PIXDAT PixData;
  334. lRes = LockLCTables(lpInst, &PixData);
  335. if(lRes == ICERR_OK)
  336. {
  337. for(i = 0; i < 256; i++)
  338. {
  339. PixData.LumaTable[i] = i;
  340. PixData.LumaTable[i+OFFSET_TABLE_COPY] = i;
  341. }
  342. *(PixData.LumaFlag) = FALSE;
  343. *(PixData.Brightness) = H26X_DEFAULT_BRIGHTNESS;
  344. if(*(PixData.Contrast) != H26X_DEFAULT_CONTRAST)
  345. CustomChangeContrast(lpInst, *(PixData.Contrast));
  346. lRes = UnlockLCTables(lpInst, &PixData);
  347. }
  348. return(lRes);
  349. }
  350. ;////////////////////////////////////////////////////////////////////////////
  351. ;// Function: LRESULT CustomResetContrast(LPDECINST lpInst);
  352. ;//
  353. ;// Description: Sets the luminance table to identity, and resets
  354. ;// flag indicating need to use.
  355. ;//
  356. ;// History: 02/22/94 -BEN-
  357. ;////////////////////////////////////////////////////////////////////////////
  358. LRESULT CustomResetContrast(LPDECINST lpInst)
  359. {
  360. LRESULT lRes;
  361. int i;
  362. PIXDAT PixData;
  363. lRes = LockLCTables(lpInst, &PixData);
  364. if(lRes == ICERR_OK)
  365. {
  366. for(i = 0; i < 256; i++)
  367. {
  368. PixData.LumaTable[i] = i;
  369. PixData.LumaTable[i+OFFSET_TABLE_COPY] = i;
  370. }
  371. *(PixData.LumaFlag) = FALSE;
  372. *(PixData.Contrast) = H26X_DEFAULT_CONTRAST;
  373. if(*(PixData.Brightness) != H26X_DEFAULT_BRIGHTNESS)
  374. CustomChangeBrightness(lpInst, *(PixData.Brightness));
  375. lRes = UnlockLCTables(lpInst, &PixData);
  376. }
  377. return(lRes);
  378. }
  379. ;////////////////////////////////////////////////////////////////////////////
  380. ;// Function: LRESULT CustomResetSaturation(LPDECINST);
  381. ;//
  382. ;// Description: Sets chroma tables to identity, and resets
  383. ;// flag indicating need to use.
  384. ;//
  385. ;// History: 02/22/94 -BEN-
  386. ;////////////////////////////////////////////////////////////////////////////
  387. LRESULT CustomResetSaturation(LPDECINST lpInst)
  388. {
  389. LRESULT lRes;
  390. int i;
  391. PIXDAT PixData;
  392. lRes = LockLCTables(lpInst, &PixData);
  393. if(lRes == ICERR_OK)
  394. {
  395. for(i = 0; i < 256; i++)
  396. {
  397. PixData.ChromaTable[i] = i;
  398. PixData.ChromaTable[i+OFFSET_TABLE_COPY] = i;
  399. }
  400. *(PixData.ChromaFlag) = FALSE;
  401. *(PixData.Saturation) = H26X_DEFAULT_SATURATION;
  402. lRes = UnlockLCTables(lpInst, &PixData);
  403. }
  404. return(lRes);
  405. }