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.

452 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. if(IsBadWritePtr((LPVOID)lpInst, sizeof(DECINSTINFO)))
  118. {
  119. DBOUT("ERROR :: LockLCTables :: ICERR_BADPARAM");
  120. return(ICERR_BADPARAM);
  121. }
  122. DC = (T_H263DecoderCatalog *) ((((U32) lpInst->pDecoderInst) + 31) & ~0x1F);
  123. lpPixData->LumaTable = (LPBYTE)(DC->p16InstPostProcess +
  124. DC->X16_LumaAdjustment);
  125. lpPixData->ChromaTable = (LPBYTE)(DC->p16InstPostProcess +
  126. DC->X16_ChromaAdjustment);
  127. lpPixData->LumaFlag = (LPBOOL)&(DC->bAdjustLuma);
  128. lpPixData->ChromaFlag = (LPBOOL)&(DC->bAdjustChroma);
  129. lpPixData->Brightness = (LPBYTE)&(DC->BrightnessSetting);
  130. lpPixData->Contrast = (LPBYTE)&(DC->ContrastSetting);
  131. lpPixData->Saturation = (LPBYTE)&(DC->SaturationSetting);
  132. return(ICERR_OK);
  133. }
  134. /*********************************************************************
  135. * static LRESULT UnlockLCTables(LPDECINST, LPPIXDAT);
  136. * Description: This funtion unlocks
  137. * History: 06/30/94 -BEN-
  138. **********************************************************************/
  139. static LRESULT UnlockLCTables(LPDECINST lpInst, LPPIXDAT lpPixData)
  140. {
  141. T_H263DecoderCatalog *DC;
  142. DC = (T_H263DecoderCatalog *) ((((U32) lpInst->pDecoderInst) + 31) & ~0x1F);
  143. lpPixData->LumaTable = (LPBYTE)NULL;
  144. lpPixData->ChromaTable = (LPBYTE)NULL;
  145. lpPixData->LumaFlag = (LPBOOL)NULL;
  146. lpPixData->ChromaFlag = (LPBOOL)NULL;
  147. return(ICERR_OK);
  148. }
  149. /**********************************************************************
  150. * static VOID MassageContrast(BYTE, PBYTE);
  151. * Description: input is 0 to 255, 1/SCALE to 256/SCALE inclusive
  152. * 0 = 1/SCALE
  153. * 1 = 2/SCALE
  154. * n = (n + 1) / SCALE
  155. * SCALE - 1 = 1 yields no change
  156. * 255 = 256/SCALE
  157. * if the response is too coarse, SCALE can be increased
  158. * if the response is too fine, SCALE can be decreased
  159. *
  160. * History: 02/22/94 -BEN- Added header.
  161. **********************************************************************/
  162. static VOID MassageContrast(BYTE offsetfactor, LPBYTE table)
  163. {
  164. int i;
  165. long temp, contrastfactor;
  166. contrastfactor = ((long)((DWORD)offsetfactor)) + 1; // 1 - 256
  167. contrastfactor = (contrastfactor * ACTIVE_RANGE) / 256L;
  168. for(i = 0; i < 256; i++)
  169. {
  170. temp = (long)((DWORD)table[i]);
  171. temp -= (ACTIVE_RANGE / 2L); // add centering
  172. temp *= contrastfactor;
  173. temp /= SCALE;
  174. temp += (ACTIVE_RANGE / 2L); // remove centering
  175. if(temp < 0) // and clamp
  176. table[i] = 0;
  177. else if(temp <= 255)
  178. table[i] = (unsigned char) temp;
  179. else
  180. table[i] = 255;
  181. table[i+OFFSET_TABLE_COPY] = table[i];
  182. }
  183. return;
  184. }
  185. ;////////////////////////////////////////////////////////////////////////////
  186. ;// Function: LRESULT CustomChangeBrightness(LPDECINST, BYTE);
  187. ;//
  188. ;// Description: Added header.
  189. ;//
  190. ;// History: 02/22/94 -BEN-
  191. ;////////////////////////////////////////////////////////////////////////////
  192. LRESULT CustomChangeBrightness(LPDECINST lpInst, BYTE offsetdelta)
  193. {
  194. LRESULT lRes;
  195. int delta, temp, i;
  196. PIXDAT PixData;
  197. lRes = LockLCTables(lpInst, &PixData);
  198. if(lRes == ICERR_OK)
  199. {
  200. CustomResetBrightness(lpInst);
  201. if(offsetdelta != H26X_DEFAULT_BRIGHTNESS)
  202. {
  203. delta = ((offsetdelta - 128) * ACTIVE_RANGE) / 256; // -128 to 127
  204. for(i = 0; i < 256; i++)
  205. {
  206. temp = (int)PixData.LumaTable[i] + delta;
  207. if(temp < 0) PixData.LumaTable[i] = 0;
  208. else if(temp <= 255) PixData.LumaTable[i] = (BYTE)temp;
  209. else PixData.LumaTable[i] = 255;
  210. PixData.LumaTable[i+OFFSET_TABLE_COPY] = PixData.LumaTable[i];
  211. }
  212. *(PixData.Brightness) = offsetdelta;
  213. *(PixData.LumaFlag) = TRUE;
  214. }
  215. lRes = UnlockLCTables(lpInst, &PixData);
  216. }
  217. return(lRes);
  218. }
  219. ;////////////////////////////////////////////////////////////////////////////
  220. ;// Function: LRESULT CustomChangeContrast(LPDECINST, BYTE);
  221. ;//
  222. ;// Description: Added header.
  223. ;//
  224. ;// History: 02/22/94 -BEN-
  225. ;////////////////////////////////////////////////////////////////////////////
  226. LRESULT CustomChangeContrast(LPDECINST lpInst, BYTE offsetfactor)
  227. {
  228. LRESULT lRes;
  229. PIXDAT PixData;
  230. lRes = LockLCTables(lpInst, &PixData);
  231. if(lRes == ICERR_OK)
  232. {
  233. CustomResetContrast(lpInst);
  234. if(offsetfactor != H26X_DEFAULT_CONTRAST)
  235. {
  236. MassageContrast(offsetfactor, PixData.LumaTable);
  237. *(PixData.Contrast) = offsetfactor;
  238. *(PixData.LumaFlag) = TRUE;
  239. }
  240. lRes = UnlockLCTables(lpInst, &PixData);
  241. }
  242. return(lRes);
  243. }
  244. ;////////////////////////////////////////////////////////////////////////////
  245. ;// Function: LRESULT CustomChangeSaturation(LPDECINST, BYTE);
  246. ;//
  247. ;// Description: Added header.
  248. ;//
  249. ;// History: 02/22/94 -BEN-
  250. ;////////////////////////////////////////////////////////////////////////////
  251. LRESULT CustomChangeSaturation(LPDECINST lpInst, BYTE offsetfactor)
  252. {
  253. LRESULT lRes;
  254. PIXDAT PixData;
  255. lRes = LockLCTables(lpInst, &PixData);
  256. if(lRes == ICERR_OK)
  257. {
  258. CustomResetSaturation(lpInst);
  259. if(offsetfactor != H26X_DEFAULT_SATURATION)
  260. {
  261. MassageContrast(offsetfactor, PixData.ChromaTable);
  262. *(PixData.Saturation) = offsetfactor;
  263. *(PixData.ChromaFlag) = TRUE;
  264. }
  265. lRes = UnlockLCTables(lpInst, &PixData);
  266. }
  267. return(lRes);
  268. }
  269. #ifdef QUARTZ
  270. /************************************************************************
  271. * CustomGetBrightness
  272. *
  273. * Gets the current brightness value
  274. ***********************************************************************/
  275. LRESULT CustomGetBrightness(
  276. LPDECINST lpInst,
  277. BYTE * pValue)
  278. {
  279. LRESULT lResult = ICERR_ERROR;
  280. T_H263DecoderCatalog *DC;
  281. DC = (T_H263DecoderCatalog *) ((((U32) lpInst->pDecoderInst) + 31) & ~0x1F);
  282. *pValue = (BYTE) DC->BrightnessSetting;
  283. lResult = ICERR_OK;
  284. return lResult;
  285. } /* end CustomGetBrightness() */
  286. /************************************************************************
  287. * CustomGetContrast
  288. *
  289. * Gets the current contrast value
  290. ***********************************************************************/
  291. LRESULT CustomGetContrast(
  292. LPDECINST lpInst,
  293. BYTE * pValue)
  294. {
  295. LRESULT lResult = ICERR_ERROR;
  296. T_H263DecoderCatalog *DC;
  297. DC = (T_H263DecoderCatalog *) ((((U32) lpInst->pDecoderInst) + 31) & ~0x1F);
  298. *pValue = (BYTE) DC->ContrastSetting;
  299. lResult = ICERR_OK;
  300. return lResult;
  301. } /* end CustomGetContrast() */
  302. /************************************************************************
  303. *
  304. * CustomGetSaturation
  305. *
  306. * Gets the current saturation value
  307. ***********************************************************************/
  308. LRESULT CustomGetSaturation(
  309. LPDECINST lpInst,
  310. BYTE * pValue)
  311. {
  312. LRESULT lResult = ICERR_ERROR;
  313. T_H263DecoderCatalog *DC;
  314. DC = (T_H263DecoderCatalog *) ((((U32) lpInst->pDecoderInst) + 31) & ~0x1F);
  315. *pValue = (BYTE) DC->SaturationSetting;
  316. lResult = ICERR_OK;
  317. return lResult;
  318. } /* end CustomGetSaturation() */
  319. #endif /* QUARTZ */
  320. ;////////////////////////////////////////////////////////////////////////////
  321. ;// Function: LRESULT CustomResetBrightness(LPDECINST lpInst);
  322. ;//
  323. ;// Description: Sets the luminance table to identity, and resets
  324. ;// flag indicating need to use.
  325. ;//
  326. ;// History: 02/22/94 -BEN-
  327. ;////////////////////////////////////////////////////////////////////////////
  328. LRESULT CustomResetBrightness(LPDECINST lpInst)
  329. {
  330. LRESULT lRes;
  331. int i;
  332. PIXDAT PixData;
  333. lRes = LockLCTables(lpInst, &PixData);
  334. if(lRes == ICERR_OK)
  335. {
  336. for(i = 0; i < 256; i++)
  337. {
  338. PixData.LumaTable[i] = i;
  339. PixData.LumaTable[i+OFFSET_TABLE_COPY] = i;
  340. }
  341. *(PixData.LumaFlag) = FALSE;
  342. *(PixData.Brightness) = H26X_DEFAULT_BRIGHTNESS;
  343. if(*(PixData.Contrast) != H26X_DEFAULT_CONTRAST)
  344. CustomChangeContrast(lpInst, *(PixData.Contrast));
  345. lRes = UnlockLCTables(lpInst, &PixData);
  346. }
  347. return(lRes);
  348. }
  349. ;////////////////////////////////////////////////////////////////////////////
  350. ;// Function: LRESULT CustomResetContrast(LPDECINST lpInst);
  351. ;//
  352. ;// Description: Sets the luminance table to identity, and resets
  353. ;// flag indicating need to use.
  354. ;//
  355. ;// History: 02/22/94 -BEN-
  356. ;////////////////////////////////////////////////////////////////////////////
  357. LRESULT CustomResetContrast(LPDECINST lpInst)
  358. {
  359. LRESULT lRes;
  360. int i;
  361. PIXDAT PixData;
  362. lRes = LockLCTables(lpInst, &PixData);
  363. if(lRes == ICERR_OK)
  364. {
  365. for(i = 0; i < 256; i++)
  366. {
  367. PixData.LumaTable[i] = i;
  368. PixData.LumaTable[i+OFFSET_TABLE_COPY] = i;
  369. }
  370. *(PixData.LumaFlag) = FALSE;
  371. *(PixData.Contrast) = H26X_DEFAULT_CONTRAST;
  372. if(*(PixData.Brightness) != H26X_DEFAULT_BRIGHTNESS)
  373. CustomChangeBrightness(lpInst, *(PixData.Brightness));
  374. lRes = UnlockLCTables(lpInst, &PixData);
  375. }
  376. return(lRes);
  377. }
  378. ;////////////////////////////////////////////////////////////////////////////
  379. ;// Function: LRESULT CustomResetSaturation(LPDECINST);
  380. ;//
  381. ;// Description: Sets chroma tables to identity, and resets
  382. ;// flag indicating need to use.
  383. ;//
  384. ;// History: 02/22/94 -BEN-
  385. ;////////////////////////////////////////////////////////////////////////////
  386. LRESULT CustomResetSaturation(LPDECINST lpInst)
  387. {
  388. LRESULT lRes;
  389. int i;
  390. PIXDAT PixData;
  391. lRes = LockLCTables(lpInst, &PixData);
  392. if(lRes == ICERR_OK)
  393. {
  394. for(i = 0; i < 256; i++)
  395. {
  396. PixData.ChromaTable[i] = i;
  397. PixData.ChromaTable[i+OFFSET_TABLE_COPY] = i;
  398. }
  399. *(PixData.ChromaFlag) = FALSE;
  400. *(PixData.Saturation) = H26X_DEFAULT_SATURATION;
  401. lRes = UnlockLCTables(lpInst, &PixData);
  402. }
  403. return(lRes);
  404. }