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.

1359 lines
41 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 Intel Corporation.
  10. ** All Rights Reserved.
  11. **
  12. ** *************************************************************************
  13. */
  14. //
  15. // $Author: CLORD $
  16. // $Date: 17 Apr 1997 16:50:04 $
  17. // $Archive: S:\h26x\src\dec\dxbase.cpv $
  18. // $Header: S:\h26x\src\dec\dxbase.cpv 1.48 17 Apr 1997 16:50:04 CLORD $
  19. // $Log: S:\h26x\src\dec\dxbase.cpv $
  20. //
  21. // Rev 1.48 17 Apr 1997 16:50:04 CLORD
  22. // moved updating xres and yres from DecompressQuery to DecompressBegin,
  23. // this fixes VPhone frame dimension changes, when a Query was sent after the
  24. // DecompressEnd and before the DecompressBegin
  25. //
  26. // Rev 1.47 27 Mar 1997 12:32:48 MDUDA
  27. // No longer checking input compression in Decompress. This change
  28. // is to fix problem where DVP nulls out compression field between
  29. // calls to DecompressBegin and Decompress.
  30. //
  31. // Rev 1.46 24 Mar 1997 15:00:34 mbodart
  32. // Fix PVCS tracker bug 150 in the H.263 bug base: allow a change of
  33. // dimensions in "redundant" DecompressBegin's.
  34. //
  35. // Rev 1.45 18 Mar 1997 16:21:10 MDUDA
  36. // Commented out call to H263TermColorConvertor in DecompressEnd.
  37. // This fixes a Graphedt problem where starts and stops cause a hang.
  38. //
  39. // Rev 1.44 18 Mar 1997 10:43:28 mbodart
  40. // Quick one-line fix to previous change. Note that there are still problems
  41. // in graphedt, when trying a bunch of play-pause-stop-play... combinations.
  42. // We need to re-evaluate how DecompressBegin/DecompressEnd deal with
  43. // memory allocation and initialization.
  44. //
  45. // Also rearranged some DbgLog messages in DecompressQuery to give more
  46. // condensed information.
  47. //
  48. // Rev 1.43 14 Mar 1997 19:01:36 JMCVEIGH
  49. // Removed H263TermDecoderInstance from DecompressEnd. Some apps.
  50. // send a DecompressEnd, but then restart decompressing at the
  51. // middle of the sequence (i.e., not a the previous keyframe). We
  52. // therefore need to retain the reference frame. The instance is
  53. // free in DrvClose.
  54. //
  55. // Rev 1.42 07 Mar 1997 09:07:42 mbodart
  56. // Added a missing '#ifndef H261' in DecompressQuery.
  57. // Added a call to _clearfp() in the Decompress exception handler, so that
  58. // the exception will not reoccur in the caller's code.
  59. //
  60. // Rev 1.41 14 Jan 1997 11:16:22 JMCVEIGH
  61. // Put flag for old still-frame mode backward compatibility under
  62. // #ifdef H263P
  63. //
  64. // Rev 1.40 13 Jan 1997 10:51:14 JMCVEIGH
  65. // Added NULL pointer checks in all functions that interface with
  66. // application.
  67. //
  68. // Rev 1.39 10 Jan 1997 18:30:24 BECHOLS
  69. // Changed decompress query so that it will accept negative heights.
  70. //
  71. // Rev 1.38 06 Jan 1997 17:40:24 JMCVEIGH
  72. // Added support to ensure backward compatibility with old
  73. // still-frame mode (crop CIF image to 320x240). Since 320x240 size
  74. // is valid with arbitrary frame size support in H.263+, we check
  75. // for this case by either comparing the source/destination header
  76. // sizes or the source header size and the size contained in the
  77. // picture header of the bitstream.
  78. //
  79. // Rev 1.37 03 Jan 1997 15:05:16 JMCVEIGH
  80. // Re-inserted check in DecompressQuery that allows a H263 bitstream
  81. // with frame dimensions 320x240 in non-prime decoder to be
  82. // supported. This undos the elimination of this check in rev. 1.33.
  83. //
  84. // Rev 1.36 11 Dec 1996 16:02:34 MBODART
  85. //
  86. // In Decompress, catch any exceptions and return an error code. This gives
  87. // upstream active movie filters a chance to recover gracefully.
  88. //
  89. // Rev 1.35 09 Dec 1996 18:02:10 JMCVEIGH
  90. // Added support for arbitrary frame sizes.
  91. //
  92. // Rev 1.34 27 Nov 1996 13:55:18 MBODART
  93. // Added a comment to DecompressQuery that explicitly enumerates the
  94. // formats and transformations that H.261 supports.
  95. //
  96. // Rev 1.33 21 Nov 1996 17:27:18 MDUDA
  97. // Disables YUV12 output zoom by 2 and removed 160x120, 240x180,
  98. // and 320x240 acceptance of H263 input.
  99. //
  100. // Rev 1.32 15 Nov 1996 08:39:56 MDUDA
  101. // Added 640x480 frame size for H263 and FOURCC_YUV12.
  102. //
  103. // Rev 1.31 14 Nov 1996 09:22:34 MBODART
  104. // Disable the ability to select a DCI color convertor, they don't exist!
  105. // However, DCI col. conv. initialization does exist, and differs from
  106. // non-DCI initialization.
  107. //
  108. // Rev 1.30 13 Nov 1996 10:58:32 RHAZRA
  109. // H.261 YUV12 decoder now accepts CIF, QCIF, 160x120, 320x240 and 640x480
  110. //
  111. // Rev 1.29 12 Nov 1996 08:47:12 JMCVEIGH
  112. // Removed initial arbitrary frame size support, i.e., reverted back
  113. // to rev 1.27. Will hold off on custom picture format support until
  114. // branch for release candidate for PS 3.0.
  115. //
  116. // Rev 1.28 11 Nov 1996 11:51:14 JMCVEIGH
  117. // Added initial support for arbitrary frame sizes (H.263+ draft,
  118. // document LBC-96-263). Define H263P to allow frame sizes from
  119. // 4 <= width <= 352 and 4 <= height <= 288, where both width and
  120. // height are multiples of 4.
  121. //
  122. // Rev 1.27 20 Oct 1996 13:31:46 AGUPTA2
  123. // Changed DBOUT into DbgLog. ASSERT is not changed to DbgAssert.
  124. //
  125. //
  126. // Rev 1.26 26 Sep 1996 09:46:00 BECHOLS
  127. //
  128. // Turned on Snapshot for H263. This code merely sets up for the Snapshot
  129. // copy, and waits on an event for the decoder to do the copy. When the
  130. // event is signaled, the Snapshot trigger wakes up and returns the status
  131. // of the copy to the caller.
  132. //
  133. // Rev 1.25 25 Sep 1996 17:30:32 BECHOLS
  134. // changed the snapshot code to wait on an event while the decoder
  135. // does the snapshot copy.
  136. //
  137. // Rev 1.24 24 Sep 1996 13:51:42 BECHOLS
  138. //
  139. // Added Snapshot() implementation.
  140. //
  141. // Rev 1.23 03 Sep 1996 16:29:22 CZHU
  142. // enable DDRAW, removed define
  143. //
  144. // Rev 1.22 18 Jul 1996 09:24:36 KLILLEVO
  145. // implemented YUV12 color convertor (pitch changer) in assembly
  146. // and added it as a normal color convertor function, via the
  147. // ColorConvertorCatalog() call.
  148. //
  149. // Rev 1.21 01 Jul 1996 10:05:10 RHAZRA
  150. //
  151. // Turn off aspect ratio correction for YUY2 color conversion.
  152. //
  153. // Rev 1.20 19 Jun 1996 16:38:54 RHAZRA
  154. //
  155. // Added a #ifdef to coditionally disable DDRAW (YUY2) support
  156. //
  157. // Rev 1.19 19 Jun 1996 14:26:28 RHAZRA
  158. // Added code to (i) accept YUY2 as a valid output format (ii) select
  159. // YUY2 color convertor in SelectColorConvertor()
  160. //
  161. // Rev 1.18 30 May 1996 17:08:52 RHAZRA
  162. // Added SQCIF support for H263.
  163. //
  164. // Rev 1.17 30 May 1996 15:16:38 KLILLEVO
  165. // added YUV12 output
  166. //
  167. // Rev 1.16 30 May 1996 10:13:00 KLILLEVO
  168. //
  169. // removed one cluttering debug statement
  170. //
  171. // Rev 1.15 01 Apr 1996 10:26:34 BNICKERS
  172. // Add YUV12 to RGB32 color convertors. Disable IF09.
  173. //
  174. // Rev 1.14 09 Feb 1996 10:09:22 AKASAI
  175. // Added ifndef RING0 around code in DecompressGetPalette to eliminate
  176. // warning in building RING0 release version of codec.
  177. //
  178. // Rev 1.13 11 Jan 1996 16:59:14 DBRUCKS
  179. //
  180. // cleaned up DecompressQuery
  181. // added setting of bProposedCorrectAspectRatio (in Query) and
  182. // bCorrectAspectRatio (in Begin) if the source dimensions are SQCIF,
  183. // QCIF, or CIF and the destination dimensions are the aspect ratio
  184. // sizes with a possible zoom by two.
  185. //
  186. // Rev 1.12 18 Dec 1995 12:51:38 RMCKENZX
  187. // added copyright notice
  188. //
  189. // Rev 1.11 13 Dec 1995 13:22:54 DBRUCKS
  190. //
  191. // Add assertions to verify that the source size is not changing on
  192. // a begin.
  193. //
  194. // Rev 1.10 07 Dec 1995 13:02:52 DBRUCKS
  195. // fix spx release build
  196. //
  197. // Rev 1.9 17 Nov 1995 15:22:30 BECHOLS
  198. //
  199. // Added ring 0 stuff.
  200. //
  201. // Rev 1.8 15 Nov 1995 15:57:24 AKASAI
  202. // Remove YVU9 from decompress and decompress_query.
  203. // (Integration point)
  204. //
  205. // Rev 1.7 25 Oct 1995 18:12:36 BNICKERS
  206. // Add YUV12 color convertors. Eliminate YUV9 looking glass support.
  207. //
  208. // Rev 1.6 17 Oct 1995 17:31:24 CZHU
  209. //
  210. // Fixed a bug in DecompressQuery related to YUV12
  211. //
  212. // Rev 1.5 18 Sep 1995 08:40:50 CZHU
  213. //
  214. // Added support for YUV12
  215. //
  216. // Rev 1.4 08 Sep 1995 12:11:12 CZHU
  217. // Output compressed size for debugging
  218. //
  219. // Rev 1.3 25 Aug 1995 13:58:06 DBRUCKS
  220. // integrate MRV R9 changes
  221. //
  222. // Rev 1.2 23 Aug 1995 12:25:12 DBRUCKS
  223. // Turn on the color converters
  224. //
  225. // Rev 1.1 01 Aug 1995 12:27:38 DBRUCKS
  226. // add PSC parsing
  227. //
  228. // Rev 1.0 31 Jul 1995 13:00:12 DBRUCKS
  229. // Initial revision.
  230. //
  231. // Rev 1.0 17 Jul 1995 14:46:14 CZHU
  232. // Initial revision.
  233. //
  234. // Rev 1.0 17 Jul 1995 14:14:26 CZHU
  235. // Initial revision.
  236. ;////////////////////////////////////////////////////////////////////////////
  237. #include "precomp.h"
  238. extern BYTE PalTable[236*4];
  239. #define WIDTHBYTES(bits) (((bits) + 31) / 32 * 4)
  240. /***************************************************************************
  241. *
  242. * Build16bitModeID().
  243. *
  244. * given red, green and blue values showing their maximum value,
  245. * count the bits standing and then form a decimal digit which lists
  246. * the number of red bits in the hundreds position, green in the tens
  247. * position and blue in the ones position.
  248. *
  249. * This code is used when the RGB16 table is built so the correct
  250. * field size will be used.
  251. *
  252. * returns the 16 bit mode ID
  253. *
  254. * Prototype in rgb16cct.h
  255. *
  256. ***************************************************************************/
  257. int Build16bitModeID(I32 red, I32 green, I32 blue)
  258. {
  259. int rval;
  260. int Rbits, Gbits, Bbits;
  261. U32 i;
  262. for (Rbits = 0,i = 1; i < (1L << 30); i = i << 1)
  263. Rbits += (red & i) ? 1 : 0;
  264. for (Gbits = 0,i = 1; i < (1L << 30); i = i << 1)
  265. Gbits += (green & i) ? 1 : 0;
  266. for (Bbits = 0,i = 1; i < (1L << 30); i = i << 1)
  267. Bbits += (blue & i) ? 1 : 0;
  268. rval = Rbits * 100 + Gbits * 10 + Bbits;
  269. return(rval);
  270. }
  271. /***********************************************************************
  272. * SelectConvertor(LPDECINST, BOOL);
  273. * History: 03/18/94 -BEN-
  274. ***********************************************************************/
  275. static UINT SelectConvertor(
  276. LPDECINST lpInst,
  277. LPBITMAPINFOHEADER lpbiDst,
  278. BOOL bIsDCI)
  279. {
  280. UINT uiCnvtr = 0xFFFF;
  281. DWORD FAR * pDW = (DWORD FAR *)((LPBYTE)lpbiDst+sizeof(BITMAPINFOHEADER));
  282. int RequestedMode;
  283. FX_ENTRY("SelectConvertor")
  284. /* Force off the DCI color converters because we can not be sure that the
  285. * archive data has not changed.
  286. * Also, we have no DCI color convertors, so don't select one!
  287. */
  288. bIsDCI = 0;
  289. switch(lpInst->outputDepth)
  290. {
  291. case 12:
  292. if ((lpbiDst->biCompression == FOURCC_YUV12) || (lpbiDst->biCompression == FOURCC_IYUV))
  293. {
  294. DEBUGMSG(ZONE_INIT, ("%s: Selected 12 bits color convertor: raw YUV12 output\r\n", _fx_));
  295. uiCnvtr = YUV12NOPITCH; // YUV12 output
  296. }
  297. break;
  298. case 8:
  299. DEBUGMSG(ZONE_INIT, ("%s: Selected 8 bits color convertor\r\n", _fx_));
  300. if (lpInst->UseActivePalette==0)
  301. {
  302. switch(lpInst->XScale)
  303. {
  304. case 1:
  305. if(bIsDCI == TRUE)
  306. {
  307. uiCnvtr = CLUT8DCI;
  308. DEBUGMSG(ZONE_INIT, ("%s: CLUT8DCI convertors selected\r\n", _fx_));
  309. }
  310. else
  311. {
  312. DEBUGMSG(ZONE_INIT, ("%s: CLUT8 convertors selected\r\n", _fx_));
  313. uiCnvtr = CLUT8;
  314. }
  315. break;
  316. case 2:
  317. if(bIsDCI == TRUE)
  318. {
  319. DEBUGMSG(ZONE_INIT, ("%s: CLUT8ZoomBy2DCI convertors selected\r\n", _fx_));
  320. uiCnvtr = CLUT8ZoomBy2DCI;
  321. }
  322. else
  323. {
  324. DEBUGMSG(ZONE_INIT, ("%s: CLUT8ZoomBy2 convertors selected\r\n", _fx_));
  325. uiCnvtr = CLUT8ZoomBy2;
  326. }
  327. break;
  328. }
  329. }
  330. else
  331. {
  332. switch(lpInst->XScale)
  333. {
  334. case 1:
  335. if(bIsDCI == TRUE)
  336. {
  337. DEBUGMSG(ZONE_INIT, ("%s: CLUTAPDCI is selected\r\n", _fx_));
  338. uiCnvtr = CLUT8APDCI;
  339. }
  340. else
  341. {
  342. DEBUGMSG(ZONE_INIT, ("%s: CLUTAPDCI is selected\r\n", _fx_));
  343. uiCnvtr = CLUT8APDCI;
  344. }
  345. break;
  346. case 2:
  347. if(bIsDCI == TRUE)
  348. {
  349. DEBUGMSG(ZONE_INIT, ("%s: CLUT8APZoomBy2DCI is selected\r\n", _fx_));
  350. uiCnvtr = CLUT8APZoomBy2DCI;
  351. }
  352. else
  353. {
  354. DEBUGMSG(ZONE_INIT, ("%s: CLUT8APZoomBy2DCI is selected\r\n", _fx_));
  355. uiCnvtr = CLUT8APZoomBy2DCI;
  356. }
  357. break;
  358. }
  359. }
  360. break;
  361. case 16:
  362. // check which mode is
  363. if (lpbiDst->biCompression == FOURCC_YUY2)
  364. {
  365. DEBUGMSG(ZONE_INIT, ("%s: Selected 16 bits YUY2 color convertor\r\n", _fx_));
  366. uiCnvtr = YUY2DDRAW;
  367. break;
  368. }
  369. else
  370. {
  371. if (lpbiDst->biCompression == BI_RGB)
  372. RequestedMode = 555; /* default rgb16 mode */
  373. else //if (lpbiDst->biCompression == BI_BITFIELDS)
  374. RequestedMode = Build16bitModeID(pDW[0], pDW[1], pDW[2]);
  375. switch (RequestedMode)
  376. {
  377. case 555:
  378. switch(lpInst->XScale)
  379. {
  380. case 1:
  381. DEBUGMSG(ZONE_INIT, ("%s: RGB16 in 555 color convertor\r\n", _fx_));
  382. if(bIsDCI == TRUE)
  383. uiCnvtr = RGB16555DCI;
  384. else
  385. uiCnvtr = RGB16555;
  386. break;
  387. case 2:
  388. DEBUGMSG(ZONE_INIT, ("%s: RGB16x2 in 555 color convertor\r\n", _fx_));
  389. if(bIsDCI == TRUE)
  390. uiCnvtr = RGB16555ZoomBy2DCI;
  391. else
  392. uiCnvtr = RGB16555ZoomBy2;
  393. break;
  394. } //end of 555
  395. break;
  396. case 664:
  397. switch(lpInst->XScale)
  398. {
  399. case 1:
  400. DEBUGMSG(ZONE_INIT, ("%s: RGB16 in 664 color convertor\r\n", _fx_));
  401. if(bIsDCI == TRUE)
  402. uiCnvtr = RGB16664DCI;
  403. else
  404. uiCnvtr = RGB16664;
  405. break;
  406. case 2:
  407. DEBUGMSG(ZONE_INIT, ("%s: RGB16x2 in 664 color convertor\r\n", _fx_));
  408. if(bIsDCI == TRUE)
  409. uiCnvtr = RGB16664ZoomBy2DCI;
  410. else
  411. uiCnvtr = RGB16664ZoomBy2;
  412. break;
  413. } //end of 664
  414. break;
  415. case 565:
  416. switch(lpInst->XScale)
  417. {
  418. case 1:
  419. DEBUGMSG(ZONE_INIT, ("%s: RGB16 in 565 color convertor\r\n", _fx_));
  420. if(bIsDCI == TRUE)
  421. uiCnvtr = RGB16565DCI;
  422. else
  423. uiCnvtr = RGB16565;
  424. break;
  425. case 2:
  426. DEBUGMSG(ZONE_INIT, ("%s: RGB16x2 in 565 color convertor\r\n", _fx_));
  427. if(bIsDCI == TRUE)
  428. uiCnvtr = RGB16565ZoomBy2DCI;
  429. else
  430. uiCnvtr = RGB16565ZoomBy2;
  431. break;
  432. } //end of 565
  433. break;
  434. case 655:
  435. switch(lpInst->XScale)
  436. {
  437. case 1:
  438. DEBUGMSG(ZONE_INIT, ("%s: RGB16 in 655 color convertor\r\n", _fx_));
  439. if(bIsDCI == TRUE)
  440. uiCnvtr = RGB16655DCI;
  441. else
  442. uiCnvtr = RGB16655;
  443. break;
  444. case 2:
  445. DEBUGMSG(ZONE_INIT, ("%s: RGB16x2 in 655 color convertor\r\n", _fx_));
  446. if(bIsDCI == TRUE)
  447. uiCnvtr = RGB16655ZoomBy2DCI;
  448. else
  449. uiCnvtr = RGB16655ZoomBy2;
  450. break;
  451. } //end of 655
  452. break;
  453. default:
  454. break;
  455. } // switch
  456. } // else
  457. break;
  458. case 24:
  459. switch(lpInst->XScale)
  460. {
  461. case 1:
  462. DEBUGMSG(ZONE_INIT, ("%s: Selected 24 bits color convertor\r\n", _fx_));
  463. if(bIsDCI == TRUE)
  464. uiCnvtr = RGB24DCI;
  465. else
  466. uiCnvtr = RGB24;
  467. break;
  468. case 2:
  469. DEBUGMSG(ZONE_INIT, ("%s: Selected 24 bits color convertor, x2\r\n", _fx_));
  470. if(bIsDCI == TRUE)
  471. uiCnvtr = RGB24ZoomBy2DCI;
  472. else
  473. uiCnvtr = RGB24ZoomBy2;
  474. break;
  475. }
  476. break;
  477. case 32:
  478. switch(lpInst->XScale)
  479. {
  480. case 1:
  481. DEBUGMSG(ZONE_INIT, ("%s: Selected 32 bits color convertor\r\n", _fx_));
  482. if(bIsDCI == TRUE)
  483. uiCnvtr = RGB32DCI;
  484. else
  485. uiCnvtr = RGB32;
  486. break;
  487. case 2:
  488. DEBUGMSG(ZONE_INIT, ("%s: Selected 32 bits color convertor, x2\r\n", _fx_));
  489. if(bIsDCI == TRUE)
  490. uiCnvtr = RGB32ZoomBy2DCI;
  491. else
  492. uiCnvtr = RGB32ZoomBy2;
  493. break;
  494. }
  495. break;
  496. }
  497. return(uiCnvtr);
  498. }
  499. /***********************************************************************
  500. * DWORD PASCAL DecompressQuery(LPDECINST, ICDECOMPRESSEX FAR *, BOOL);
  501. * History: 02/18/94 -BEN-
  502. *
  503. * The following table summarizes the transformations that the H.261 decoder
  504. * and I420 color convertor support.
  505. *
  506. * H.261 Decoder Inputs and Outputs
  507. *
  508. +--------------------------+-------------------------------------------------+
  509. | Input Format | Supported Output Formats for this Input Format |
  510. +--------------------------+-------------------------------------------------+
  511. | H.261 FCIF (352 x 288) | 352 x 288 RGBnn, YUV12 or YUY2 |
  512. | or | 352 x 264 RGBnn (aspect ratio correction) |
  513. | YUV12 FCIF (352 x 288) | 704 x 576 RGBnn (zoom by 2) |
  514. | | 704 x 528 RGBnn (zoom by 2, aspect ratio corr.) |
  515. +--------------------------+-------------------------------------------------+
  516. | H.261 QCIF (176 x 144) | 176 x 144 RGBnn, YUV12 or YUY2 |
  517. | or | 176 x 132 RGBnn (aspect ratio correction) |
  518. | YUV12 QCIF (176 x 144) | 352 x 288 RGBnn (zoom by 2) |
  519. | | 352 x 264 RGBnn (zoom by 2, aspect ratio corr.) |
  520. +--------------------------+-------------------------------------------------+
  521. | YUV12 640 x 480 | 640 x 480 RGBnn, YUV12 or YUY2 |
  522. | | 1280 x 960 RGBnn (zoom by 2) |
  523. +--------------------------+-------------------------------------------------+
  524. | YUV12 320 x 240 | 320 x 240 RGBnn, YUV12 or YUY2 |
  525. | | 640 x 480 RGBnn (zoom by 2) |
  526. +--------------------------+-------------------------------------------------+
  527. | YUV12 160 x 120 | 160 x 120 RGBnn, YUV12 or YUY2 |
  528. | | 320 x 240 RGBnn (zoom by 2) |
  529. +--------------------------+-------------------------------------------------+
  530. *
  531. * Notes:
  532. * o RGBnn represents RGB8, RGB16, RGB24 and RGB32.
  533. * o Zoom by 2 and aspect ratio correction are not supported with YUY2 and
  534. * YUV12 *output*.
  535. * o Aspect ratio correction on output is only supported
  536. * when the *input* resolution is exactly QCIF or FCIF.
  537. *
  538. ***********************************************************************/
  539. DWORD PASCAL DecompressQuery(
  540. LPDECINST lpInst,
  541. ICDECOMPRESSEX FAR * lpicDecEx,
  542. BOOL bIsDCI)
  543. {
  544. LPBITMAPINFOHEADER lpbiSrc;
  545. LPBITMAPINFOHEADER lpbiDst;
  546. int iSrcWidth;
  547. int iSrcHeight;
  548. int iDstWidth;
  549. int iDstHeight;
  550. BOOL bSupportedSrcDimensions;
  551. FX_ENTRY("DecompressQuery")
  552. // Check for NULL pointers
  553. if ((lpicDecEx == NULL) || (lpicDecEx->lpbiSrc == NULL))
  554. return (DWORD)ICERR_ERROR;
  555. // Set source and destination bitmap info headers
  556. lpbiSrc = lpicDecEx->lpbiSrc;
  557. lpbiDst = lpicDecEx->lpbiDst;
  558. // Check the source dimensions
  559. iSrcWidth = lpbiSrc->biWidth;
  560. iSrcHeight = lpbiSrc->biHeight;
  561. bSupportedSrcDimensions = FALSE;
  562. if (lpbiSrc->biCompression == FOURCC_H263)
  563. {
  564. /* H261 supports CIF and QCIF
  565. * H263 supports CIF, SQCIF, and QCIF.
  566. * H263 also may need 160x120, 240x180, and 320x240 as Tom put special
  567. * code into exbase to accept these.
  568. */
  569. #ifdef H263P
  570. /* H.263+ supports custom picture format with width [4,...,352],
  571. * height [4,...,288], and both a multiple of 4.
  572. */
  573. if ((iSrcWidth <= 352 && iSrcHeight <= 288) &&
  574. (iSrcWidth >= 4 && iSrcHeight >= 4) &&
  575. (iSrcWidth & ~3) == iSrcWidth &&
  576. (iSrcHeight & ~3) == iSrcHeight)
  577. bSupportedSrcDimensions = TRUE;
  578. #else
  579. if ((iSrcWidth == 352 && iSrcHeight == 288) ||
  580. #ifndef H261
  581. #ifdef USE_BILINEAR_MSH26X
  582. (iSrcWidth == 80 && iSrcHeight == 64) ||
  583. #endif
  584. (iSrcWidth == 128 && iSrcHeight == 96) ||
  585. (iSrcWidth == 160 && iSrcHeight == 120) ||
  586. (iSrcWidth == 240 && iSrcHeight == 180) ||
  587. (iSrcWidth == 320 && iSrcHeight == 240) ||
  588. #endif
  589. (iSrcWidth == 176 && iSrcHeight == 144))
  590. bSupportedSrcDimensions = TRUE;
  591. #endif // H263P
  592. }
  593. #ifdef USE_BILINEAR_MSH26X
  594. else if (lpbiSrc->biCompression == FOURCC_H26X)
  595. {
  596. /* H.263+ supports custom picture format with width [4,...,352],
  597. * height [4,...,288], and both a multiple of 4.
  598. */
  599. if ((iSrcWidth <= 352 && iSrcHeight <= 288) &&
  600. (iSrcWidth >= 4 && iSrcHeight >= 4) &&
  601. (iSrcWidth & ~3) == iSrcWidth &&
  602. (iSrcHeight & ~3) == iSrcHeight)
  603. bSupportedSrcDimensions = TRUE;
  604. }
  605. #endif
  606. else if ((lpbiSrc->biCompression == FOURCC_YUV12) || (lpbiSrc->biCompression == FOURCC_IYUV))
  607. {
  608. #ifndef H261
  609. if (((iSrcWidth <= 352 && iSrcHeight <= 288) &&
  610. (iSrcWidth >= 4 && iSrcHeight >= 4) &&
  611. ((iSrcWidth & ~3) == iSrcWidth) &&
  612. ((iSrcHeight & ~3) == iSrcHeight)) ||
  613. (iSrcWidth == 640 && iSrcHeight == 480))
  614. #else
  615. if ((iSrcWidth == 352 && iSrcHeight == 288) ||
  616. (iSrcWidth == 176 && iSrcHeight == 144) ||
  617. (iSrcWidth == 160 && iSrcHeight == 120) ||
  618. (iSrcWidth == 320 && iSrcHeight == 240) ||
  619. (iSrcWidth == 640 && iSrcHeight == 480))
  620. #endif
  621. bSupportedSrcDimensions = TRUE;
  622. }
  623. if (! bSupportedSrcDimensions )
  624. {
  625. ERRORMESSAGE(("%s: Unsupported source dimensions in query\r\n", _fx_));
  626. return (DWORD)ICERR_UNSUPPORTED;
  627. }
  628. /* Stop if just querying input
  629. */
  630. if (lpbiDst == NULL)
  631. return ICERR_OK;
  632. /* Check the bit depth
  633. */
  634. switch (lpbiDst->biBitCount)
  635. {
  636. case 8:
  637. DEBUGMSG(ZONE_INIT, ("%s: Checking 8 bits\r\n", _fx_));
  638. if (lpbiDst->biCompression != BI_RGB)
  639. return((DWORD)ICERR_BADFORMAT);
  640. break;
  641. case 12:
  642. DEBUGMSG(ZONE_INIT, ("%s: Checking 12 bits\r\n", _fx_));
  643. if ((lpbiDst->biCompression != FOURCC_YUV12) && (lpbiDst->biCompression != FOURCC_IYUV))
  644. return((DWORD)ICERR_BADFORMAT);
  645. break;
  646. case 16:
  647. DEBUGMSG(ZONE_INIT, ("%s: Checking 16 bits\r\n", _fx_));
  648. switch (lpicDecEx->lpbiDst->biCompression)
  649. {
  650. case BI_RGB:
  651. DEBUGMSG(ZONE_INIT, ("%s: BI_RGB\r\n", _fx_));
  652. break;
  653. case BI_BITFIELDS:
  654. DEBUGMSG(ZONE_INIT, ("%s: BI_BITFIELDS\r\n", _fx_));
  655. break;
  656. /*
  657. * This definition of BI_BITMAP is here because MS has not provided
  658. * a "standard" definition. When MS does provide it, it will likely be
  659. * in compddk.h. At that time this definition should be removed.
  660. */
  661. #define BI_BITMAP mmioFOURCC('B', 'I', 'T', 'M')
  662. case BI_BITMAP:
  663. DEBUGMSG(ZONE_INIT, ("%s: Checking BI_BITMAP\r\n", _fx_));
  664. if (lpicDecEx->lpbiDst->biYPelsPerMeter != 0)
  665. {
  666. // output shouldn't cross a segment boundary in a scan line.
  667. return((DWORD)ICERR_BADFORMAT);
  668. }
  669. break;
  670. case FOURCC_YUY2:
  671. DEBUGMSG(ZONE_INIT, ("%s: Checking YUY2 for DirectDraw\r\n", _fx_));
  672. break;
  673. default:
  674. return((DWORD)ICERR_BADFORMAT);
  675. } // switch biCompression
  676. break;
  677. case 24:
  678. DEBUGMSG(ZONE_INIT, ("%s: Checking 24 bits\r\n", _fx_));
  679. if (lpbiDst->biCompression != BI_RGB)
  680. {
  681. return((DWORD)ICERR_BADFORMAT);
  682. }
  683. break;
  684. case 32:
  685. DEBUGMSG(ZONE_INIT, ("%s: Checking 32 bits\r\n", _fx_));
  686. if (lpbiDst->biCompression != BI_RGB)
  687. {
  688. return((DWORD)ICERR_BADFORMAT);
  689. }
  690. break;
  691. default:
  692. return((DWORD)ICERR_BADFORMAT);
  693. break;
  694. }
  695. /*
  696. if(lpbiDst->biCompression != BI_RGB && lpbiDst->biCompression != FOURCC_IF09) // check color space
  697. {
  698. #define BI_BITMAP mmioFOURCC('B', 'I', 'T', 'M')
  699. if(lpbiDst->biCompression != BI_BITMAP)
  700. return (DWORD)ICERR_UNSUPPORTED;
  701. if(lpbiDst->biYPelsPerMeter != 0)
  702. {
  703. return (DWORD)ICERR_UNSUPPORTED;
  704. }
  705. }
  706. */
  707. // Find the destination dimensions
  708. if (bIsDCI == TRUE)
  709. {
  710. iDstWidth = lpicDecEx->dxDst;
  711. iDstHeight = lpicDecEx->dyDst;
  712. }
  713. else
  714. {
  715. iDstWidth = lpbiDst->biWidth;
  716. iDstHeight = lpbiDst->biHeight;
  717. }
  718. DEBUGMSG(ZONE_INIT, ("%s: Query destination %d,%d\r\n", _fx_, iDstWidth, iDstHeight));
  719. // For the sake of the checks below, we need to take the absolute value
  720. // of the destination height.
  721. if(iDstHeight < 0)
  722. {
  723. iDstHeight = -iDstHeight;
  724. }
  725. // Check out the instance pointer
  726. if (!lpInst)
  727. return ICERR_ERROR;
  728. // Check the destination dimensions
  729. if ((iSrcWidth == iDstWidth) && (iSrcHeight == iDstHeight))
  730. {
  731. lpInst->pXScale = lpInst->pYScale = 1;
  732. lpInst->bProposedCorrectAspectRatio = FALSE;
  733. }
  734. else if ( ((iSrcWidth<<1) == iDstWidth) && ((iSrcHeight<<1) == iDstHeight) )
  735. {
  736. lpInst->pXScale = lpInst->pYScale = 2;
  737. lpInst->bProposedCorrectAspectRatio = FALSE;
  738. }
  739. else if (
  740. #ifndef H261
  741. ((iSrcWidth == 128) && (iSrcHeight == 96)) ||
  742. #endif
  743. ((iSrcWidth == 176) && (iSrcHeight == 144)) ||
  744. ((iSrcWidth == 352) && (iSrcHeight == 288))
  745. )
  746. {
  747. /* Support aspect ratio correction for SQCIF, QCIF, and CIF
  748. */
  749. if ( (iSrcWidth == iDstWidth) && ((iSrcHeight*11/12) == iDstHeight) )
  750. {
  751. lpInst->pXScale = lpInst->pYScale = 1;
  752. lpInst->bProposedCorrectAspectRatio = TRUE;
  753. }
  754. else if ( ((iSrcWidth<<1) == iDstWidth) &&
  755. (((iSrcHeight<<1)*11/12) == iDstHeight) )
  756. {
  757. lpInst->pXScale = lpInst->pYScale = 2;
  758. lpInst->bProposedCorrectAspectRatio = TRUE;
  759. }
  760. else
  761. {
  762. return(DWORD)ICERR_UNSUPPORTED;
  763. }
  764. }
  765. else
  766. {
  767. return(DWORD)ICERR_UNSUPPORTED;
  768. }
  769. /* check color depth
  770. */
  771. if(lpbiDst->biBitCount != 8 &&
  772. lpbiDst->biBitCount != 16 &&
  773. lpbiDst->biBitCount != 12 && // raw YUV12 output
  774. lpbiDst->biBitCount != 24 &&
  775. lpbiDst->biBitCount != 32)
  776. {
  777. return(DWORD)ICERR_UNSUPPORTED;
  778. }
  779. lpInst->xres = (WORD)lpbiSrc->biWidth;
  780. lpInst->yres = (WORD)lpbiSrc->biHeight;
  781. /* aspect ratio correction with YUV12 is not supported
  782. */
  783. if (lpInst->bProposedCorrectAspectRatio &&
  784. ((lpbiDst->biCompression == FOURCC_YUV12) || (lpbiDst->biCompression == FOURCC_IYUV)))
  785. {
  786. return (DWORD)ICERR_UNSUPPORTED;
  787. }
  788. /* No driver zooming in DirectDraw */
  789. if ( ((lpInst->pXScale == 2) && (lpInst->pYScale == 2)) &&
  790. (lpbiDst->biCompression == FOURCC_YUY2) )
  791. {
  792. return (DWORD)ICERR_UNSUPPORTED;
  793. }
  794. /* No driver zooming for YUV12 */
  795. if ( ((lpInst->pXScale == 2) && (lpInst->pYScale == 2)) &&
  796. ((lpbiDst->biCompression == FOURCC_YUV12) || (lpbiDst->biCompression == FOURCC_IYUV)) )
  797. {
  798. return (DWORD)ICERR_UNSUPPORTED;
  799. }
  800. return (DWORD)ICERR_OK;
  801. }
  802. ;////////////////////////////////////////////////////////////////////////////
  803. ;// Function: DWORD PASCAL DecompressGetPalette(LPDECINST, LPBITMAPINFOHEADER, LPBITMAPINFOHEADER);
  804. ;//
  805. ;// Description: Added header.
  806. ;//
  807. ;// History: 02/18/94 -BEN-
  808. ;////////////////////////////////////////////////////////////////////////////
  809. DWORD PASCAL DecompressGetPalette(
  810. LPDECINST lpInst,
  811. LPBITMAPINFOHEADER lpbiSrc,
  812. LPBITMAPINFOHEADER lpbiDst)
  813. {
  814. DWORD dw;
  815. LPBYTE lpPalArea, PalStart;
  816. #ifndef RING0
  817. HDC hDC;
  818. #endif
  819. BYTE tmp;
  820. int i;
  821. // int iUseActivePalette;
  822. ICDECOMPRESSEX icDecEx;
  823. FX_ENTRY("DecompressGetPalette")
  824. icDecEx.lpbiSrc = lpbiSrc;
  825. icDecEx.lpbiDst = lpbiDst;
  826. if(dw = DecompressQuery(lpInst, &icDecEx, FALSE))
  827. return dw;
  828. if (lpbiDst == NULL)
  829. {
  830. ERRORMESSAGE(("%s: NULL parameter\r\n", _fx_));
  831. return (DWORD)ICERR_ERROR;
  832. }
  833. if(lpbiDst->biBitCount != 8)
  834. {
  835. ERRORMESSAGE(("%s: called with biBitCount != 8\r\n", _fx_));
  836. return (DWORD)ICERR_ERROR;
  837. }
  838. lpbiDst->biClrUsed = 256; /* specify all used */
  839. lpbiDst->biClrImportant = 0;
  840. #ifndef RING0
  841. /* copy system palette entries (valid entries are 0-9 and 246-255) */
  842. hDC = GetDC(NULL);
  843. lpPalArea = (unsigned char FAR *)lpbiDst + (int)lpbiDst->biSize;
  844. GetSystemPaletteEntries(hDC, 0, 256, (PALETTEENTRY FAR *)lpPalArea);
  845. ReleaseDC(NULL, hDC);
  846. #endif
  847. /*
  848. #ifdef DEBUG
  849. iUseActivePalette = GetPrivateProfileInt("indeo", "UseActivePalette", 0, "system.ini");
  850. if (iUseActivePalette) {
  851. for (i = 0; i < 256; i++) {
  852. tmp = *lpPalArea;
  853. *lpPalArea = *(lpPalArea+2);
  854. *(lpPalArea+2) = tmp;
  855. lpPalArea += 4;
  856. }
  857. lpPalArea = (unsigned char FAR *)lpbiDst + (int)lpbiDst->biSize;
  858. _fmemcpy(lpInst->ActivePalette, lpPalArea, sizeof(lpInst->ActivePalette));
  859. lpInst->UseActivePalette = 1;
  860. }
  861. #endif
  862. */
  863. if (!lpInst)
  864. return ICERR_ERROR;
  865. #ifndef RING0
  866. if (lpInst->UseActivePalette == 1)
  867. {
  868. #ifdef WIN32
  869. memcpy(lpPalArea,lpInst->ActivePalette, sizeof(lpInst->ActivePalette));
  870. #else
  871. _fmemcpy(lpPalArea,lpInst->ActivePalette, sizeof(lpInst->ActivePalette));
  872. #endif
  873. DEBUGMSG(ZONE_INIT, ("%s: Return the current active palette saved...\r\n", _fx_));
  874. }
  875. else
  876. {
  877. #endif
  878. DEBUGMSG(ZONE_INIT, ("%s: return the fixed palette...\r\n", _fx_));
  879. PalStart = (LPBYTE)lpbiDst + (int)lpbiDst->biSize;
  880. lpPalArea = PalStart + 40; // fill in starting from the 10th
  881. for(i = 0; i < (236 << 2); i++)
  882. *lpPalArea++ = PalTable[i];
  883. lpPalArea = PalStart; // reverse r&b: dealing with DIBs
  884. for(i = 0; i < 256; i++)// for all the entries,from PALENTRY to RGBQUAD
  885. // fixed by CZHU, 1/23/95
  886. {
  887. tmp = *lpPalArea;
  888. *lpPalArea = *(lpPalArea+2);
  889. *(lpPalArea+2) = tmp;
  890. lpPalArea+=4;
  891. }
  892. #ifndef RING0
  893. }
  894. #endif
  895. return (DWORD)ICERR_OK;
  896. }
  897. /***********************************************************************
  898. * DWORD PASCAL DecompressGetFormat(LPDECINST, LPBITMAPINFOHEADER,
  899. * LPBITMAPINFOHEADER);
  900. * Description: This allows us to suggest a good format to decompress to.
  901. *
  902. * History: 02/18/94 -BEN-
  903. ***********************************************************************/
  904. DWORD PASCAL DecompressGetFormat(
  905. #ifdef USE_BILINEAR_MSH26X
  906. LPINST pi,
  907. #else
  908. LPDECINST lpInst,
  909. #endif
  910. LPBITMAPINFOHEADER lpbiSrc,
  911. LPBITMAPINFOHEADER lpbiDst)
  912. {
  913. #ifdef USE_BILINEAR_MSH26X
  914. LPDECINST lpInst = (LPDECINST)pi->DecompPtr;
  915. #endif
  916. DWORD dw;
  917. ICDECOMPRESSEX icDecEx;
  918. LPBYTE lpPalArea;
  919. int i;
  920. BYTE tmp;
  921. HDC hDC;
  922. BOOL f8Bit;
  923. FX_ENTRY("DecompressGetFormat")
  924. // check input format - dont check output: being asked to give one back
  925. icDecEx.lpbiSrc = lpbiSrc;
  926. icDecEx.lpbiDst = NULL;
  927. if(dw = DecompressQuery(lpInst, &icDecEx, FALSE))
  928. return dw;
  929. // If the current disply mode is 8 bit return a size large enough
  930. // to hold a 256 palette after the BMIh
  931. hDC = GetDC(NULL);
  932. f8Bit = (8 == GetDeviceCaps(hDC, BITSPIXEL) * GetDeviceCaps(hDC, PLANES));
  933. ReleaseDC(NULL, hDC);
  934. #ifdef FORCE_8BIT_OUTPUT // { FORCE_8BIT_OUTPUT
  935. f8Bit = TRUE;
  936. #endif // } FORCE_8BIT_OUTPUT
  937. #if defined(FORCE_16BIT_OUTPUT) || defined(FORCE_24BIT_OUTPUT) // { if defined(FORCE_16BIT_OUTPUT) || defined(FORCE_24BIT_OUTPUT)
  938. f8Bit = FALSE;
  939. #endif // } if defined(FORCE_16BIT_OUTPUT) || defined(FORCE_24BIT_OUTPUT)
  940. // if lpbiDst == NULL return size required to hold a output format
  941. // (add palette size)
  942. if (lpbiDst == NULL)
  943. return(sizeof(BITMAPINFOHEADER) + (int)(f8Bit ? 1024 : 0));
  944. // check for NULL parameter
  945. if (lpbiSrc == NULL)
  946. {
  947. // This was probably verified in DecompressQuery, but just to be safe...
  948. ERRORMESSAGE(("%s: NULL parameter\r\n", _fx_));
  949. return (DWORD)ICERR_ERROR;
  950. }
  951. lpbiDst->biSize = sizeof(BITMAPINFOHEADER);
  952. #ifdef USE_BILINEAR_MSH26X
  953. if (pi->fccHandler == FOURCC_H26X)
  954. {
  955. lpbiDst->biWidth = lpbiSrc->biWidth << 1;
  956. lpbiDst->biHeight = lpbiSrc->biHeight << 1;
  957. }
  958. else
  959. {
  960. #endif
  961. #ifdef FORCE_ZOOM_BY_2 // { FORCE_ZOOM_BY_2
  962. lpbiDst->biWidth = lpbiSrc->biWidth << 1;
  963. lpbiDst->biHeight = lpbiSrc->biHeight << 1;
  964. #else // }{ FORCE_ZOOM_BY_2
  965. lpbiDst->biWidth = lpbiSrc->biWidth;
  966. lpbiDst->biHeight = lpbiSrc->biHeight;
  967. #endif // } FORCE_ZOOM_BY_2
  968. #ifdef USE_BILINEAR_MSH26X
  969. }
  970. #endif
  971. #ifdef FORCE_16BIT_OUTPUT // { FORCE_16BIT_OUTPUT
  972. lpbiDst->biBitCount = 16;
  973. #else // }{ FORCE_16BIT_OUTPUT
  974. lpbiDst->biBitCount = (int)(f8Bit ? 8 : 24);
  975. #endif // } FORCE_16BIT_OUTPUT
  976. lpbiDst->biPlanes = 1;
  977. lpbiDst->biCompression = BI_RGB;
  978. lpbiDst->biXPelsPerMeter = 0;
  979. lpbiDst->biYPelsPerMeter = 0;
  980. lpbiDst->biSizeImage = (DWORD) WIDTHBYTES(lpbiDst->biWidth * lpbiDst->biBitCount) * lpbiDst->biHeight;
  981. lpbiDst->biClrUsed = lpbiDst->biClrImportant = 0;
  982. if (f8Bit)
  983. {
  984. // Copy the palette
  985. lpPalArea = (LPBYTE)lpbiDst + sizeof(BITMAPINFOHEADER) + 40; // fill in starting from the 10th
  986. for(i = 0; i < (236 << 2); i++)
  987. *lpPalArea++ = PalTable[i];
  988. lpPalArea = (LPBYTE)lpbiDst + sizeof(BITMAPINFOHEADER); // reverse r&b: dealing with DIBs
  989. for(i = 0; i < 256; i++)// for all the entries,from PALENTRY to RGBQUAD
  990. // fixed by CZHU, 1/23/95
  991. {
  992. tmp = *lpPalArea;
  993. *lpPalArea = *(lpPalArea+2);
  994. *(lpPalArea+2) = tmp;
  995. lpPalArea+=4;
  996. }
  997. }
  998. return ICERR_OK;
  999. }
  1000. /**********************************************************************
  1001. * DWORD PASCAL DecompressBegin(LPDECINST, ICDECOMPRESSEX FAR *, BOOL)
  1002. * Description: Provides codec indication to prepare to receive
  1003. * decompress requests for a particular input to output
  1004. * conversion. Begins arrive asynchronously, and should
  1005. * result in the codec adapting to the changes specified,
  1006. * if any.
  1007. *
  1008. * History: 02/18/94 -BEN-
  1009. **********************************************************************/
  1010. DWORD PASCAL DecompressBegin(
  1011. LPDECINST lpInst,
  1012. ICDECOMPRESSEX FAR *lpicDecEx,
  1013. BOOL bIsDCI)
  1014. {
  1015. int CodecID;
  1016. DWORD dw;
  1017. UINT ClrCnvtr;
  1018. LPBITMAPINFOHEADER lpbiSrc;
  1019. LPBITMAPINFOHEADER lpbiDst;
  1020. FX_ENTRY("DecompressBegin")
  1021. // Check for NULL parameters
  1022. if (lpInst == NULL || lpicDecEx == NULL)
  1023. {
  1024. ERRORMESSAGE(("%s: NULL parameter\r\n", _fx_));
  1025. return (DWORD)ICERR_ERROR;
  1026. }
  1027. // Set source and destination pointers
  1028. lpbiSrc = lpicDecEx->lpbiSrc;
  1029. lpbiDst = lpicDecEx->lpbiDst;
  1030. // at begin need to know input and output sizes
  1031. if (lpbiSrc == NULL || lpbiDst == NULL)
  1032. {
  1033. ERRORMESSAGE(("%s: NULL parameter\r\n", _fx_));
  1034. return((DWORD)ICERR_BADFORMAT);
  1035. }
  1036. if(lpInst->Initialized == TRUE)
  1037. {
  1038. /* We assume the source dimensions never change. If they do change
  1039. * we should terminate the instance because the allocations are
  1040. * based on dimensions. Until we add code to do that we need this
  1041. * assertion.
  1042. */
  1043. ASSERT(lpInst->xres == (WORD)lpbiSrc->biWidth);
  1044. ASSERT(lpInst->yres == (WORD)lpbiSrc->biHeight);
  1045. if(lpbiDst != NULL)
  1046. {
  1047. if(dw = DecompressQuery(lpInst, lpicDecEx, bIsDCI))
  1048. {
  1049. return(dw); // error
  1050. }
  1051. else
  1052. { // apply changes
  1053. lpInst->XScale = lpInst->pXScale;
  1054. lpInst->YScale = lpInst->pYScale;
  1055. lpInst->bCorrectAspectRatio = lpInst->bProposedCorrectAspectRatio;
  1056. lpInst->outputDepth = lpbiDst->biBitCount;
  1057. ClrCnvtr = SelectConvertor(lpInst,lpbiDst, bIsDCI);
  1058. if (ClrCnvtr != lpInst->uColorConvertor )
  1059. {
  1060. if((dw = H263TermColorConvertor(lpInst)) == ICERR_OK)
  1061. dw = H263InitColorConvertor(lpInst, ClrCnvtr);
  1062. lpInst->uColorConvertor=ClrCnvtr;
  1063. }
  1064. return(dw);
  1065. }
  1066. }
  1067. }
  1068. // first time begin - check if this is a format I like
  1069. if(dw = DecompressQuery(lpInst, lpicDecEx, bIsDCI))
  1070. {
  1071. return(dw); // error
  1072. }
  1073. else
  1074. { // apply proposed format to 'current' format
  1075. lpInst->XScale = lpInst->pXScale;
  1076. lpInst->YScale = lpInst->pYScale;
  1077. lpInst->bCorrectAspectRatio = lpInst->bProposedCorrectAspectRatio;
  1078. lpInst->outputDepth = lpbiDst->biBitCount;
  1079. }
  1080. #ifdef USE_BILINEAR_MSH26X
  1081. if ((lpbiSrc->biCompression == FOURCC_H263) || (lpbiSrc->biCompression == FOURCC_H26X))
  1082. #else
  1083. if (lpbiSrc->biCompression == FOURCC_H263)
  1084. #endif
  1085. {
  1086. CodecID = H263_CODEC;
  1087. }
  1088. else if ((lpbiSrc->biCompression == FOURCC_YUV12) || (lpbiSrc->biCompression == FOURCC_IYUV))
  1089. {
  1090. CodecID = YUV12_CODEC;
  1091. }
  1092. if(dw = H263InitDecoderInstance(lpInst, CodecID))
  1093. {
  1094. return(dw);
  1095. }
  1096. ClrCnvtr = SelectConvertor(lpInst, lpbiDst, bIsDCI);
  1097. dw = H263InitColorConvertor(lpInst, ClrCnvtr);
  1098. return(dw);
  1099. }
  1100. /**********************************************************************
  1101. * DWORD PASCAL Decompress(LPDECINST, ICDECOMPRESS FAR *, DWORD);
  1102. * History: 02/18/94 -BEN-
  1103. **********************************************************************/
  1104. DWORD PASCAL Decompress(
  1105. LPDECINST lpInst,
  1106. ICDECOMPRESSEX FAR *lpicDecEx,
  1107. DWORD dwSize,
  1108. BOOL bIsDCI)
  1109. {
  1110. DWORD ret = (DWORD) ICERR_ERROR;
  1111. FX_ENTRY("Decompress")
  1112. // Check for NULL parameters
  1113. if ((lpInst == NULL) || (lpInst->Initialized != TRUE) || (lpicDecEx == NULL) ||
  1114. (lpicDecEx->lpbiSrc == NULL) || (lpicDecEx->lpbiDst == NULL))
  1115. {
  1116. ret = (DWORD) ICERR_ERROR;
  1117. goto done;
  1118. }
  1119. #ifdef USE_BILINEAR_MSH26X
  1120. if ((lpicDecEx->lpbiSrc->biCompression == FOURCC_H263) || (lpicDecEx->lpbiSrc->biCompression == FOURCC_H26X)
  1121. #else
  1122. if ((lpicDecEx->lpbiSrc->biCompression == FOURCC_H263)
  1123. #endif
  1124. || (lpicDecEx->lpbiSrc->biCompression == FOURCC_YUV12)
  1125. || (lpicDecEx->lpbiSrc->biCompression == FOURCC_IYUV) )
  1126. {
  1127. try
  1128. {
  1129. #if defined(DECODE_TIMINGS_ON) || defined(DETAILED_DECODE_TIMINGS_ON) // { #if defined(DECODE_TIMINGS_ON) || defined(DETAILED_DECODE_TIMINGS_ON)
  1130. ret = H263Decompress(lpInst, lpicDecEx, bIsDCI, TRUE);
  1131. #else // }{ #if defined(DECODE_TIMINGS_ON) || defined(DETAILED_DECODE_TIMINGS_ON)
  1132. ret = H263Decompress(lpInst, lpicDecEx, bIsDCI);
  1133. #endif // } #if defined(DECODE_TIMINGS_ON) || defined(DETAILED_DECODE_TIMINGS_ON)
  1134. }
  1135. catch (...)
  1136. {
  1137. // For a DEBUG build, display a message and pass the exception up.
  1138. // For a release build, stop the exception here and return an error
  1139. // code. This gives upstream code a chance to gracefully recover.
  1140. // We also need to clear the floating point control word, otherwise
  1141. // the upstream code may incur an exception the next time it tries
  1142. // a floating point operation (presuming this exception was due
  1143. // to a floating point problem).
  1144. #if defined(DEBUG) || defined(_DEBUG)
  1145. ERRORMESSAGE(("%s: Exception during H263Decompress!!!\r\n", _fx_));
  1146. throw;
  1147. #else
  1148. _clearfp();
  1149. ret = (DWORD) ICERR_ERROR;
  1150. #endif
  1151. }
  1152. }
  1153. done:
  1154. return ret;
  1155. }
  1156. /**********************************************************************
  1157. * DWORD PASCAL DecompressEnd(LPDECINST);
  1158. * History: 02/18/94 -BEN-
  1159. **********************************************************************/
  1160. DWORD PASCAL DecompressEnd(LPDECINST lpInst)
  1161. {
  1162. if(lpInst && lpInst->Initialized == TRUE)
  1163. {
  1164. H263TermColorConvertor(lpInst);
  1165. #if defined(DECODE_TIMINGS_ON) || defined(DETAILED_DECODE_TIMINGS_ON) // { #if defined(DECODE_TIMINGS_ON) || defined(DETAILED_DECODE_TIMINGS_ON)
  1166. H263TermDecoderInstance(lpInst, TRUE);
  1167. #else // }{ #if defined(DECODE_TIMINGS_ON) || defined(DETAILED_DECODE_TIMINGS_ON)
  1168. H263TermDecoderInstance(lpInst);
  1169. #endif // } #if defined(DECODE_TIMINGS_ON) || defined(DETAILED_DECODE_TIMINGS_ON)
  1170. }
  1171. return ICERR_OK;
  1172. }
  1173. /*****************************************************************************
  1174. *
  1175. * DecompressSetPalette() is called from the ICM_DECOMPRESS_SET_PALETTE
  1176. * message.
  1177. *
  1178. * Fill in the palette using lpParam1.
  1179. *
  1180. ****************************************************************************/
  1181. DWORD PASCAL DecompressSetPalette(LPDECINST pinst,
  1182. LPBITMAPINFOHEADER lpbi,
  1183. LPBITMAPINFOHEADER unused)
  1184. {
  1185. int i;
  1186. unsigned char FAR * palette;
  1187. RGBQUAD FAR *palptr;
  1188. FX_ENTRY("DecompressSetPalette")
  1189. // Check for NULL parameter
  1190. if (pinst == NULL)
  1191. {
  1192. return (DWORD)ICERR_ERROR;
  1193. }
  1194. pinst->InitActivePalette = 0; /* must re-init AP at Begin */
  1195. pinst->UseActivePalette = 0; /* must re-init AP at Begin */
  1196. if (lpbi && (lpbi->biBitCount == 8 && lpbi->biCompression == 0))
  1197. {
  1198. palette = (unsigned char FAR *)lpbi + (int)lpbi->biSize;
  1199. // Check if palette passed is identity
  1200. for (i = 0*4, palptr = (RGBQUAD FAR *)PalTable; i < 236*4;
  1201. i += 4, palptr++)
  1202. {
  1203. if (palette[i+40] != palptr->rgbRed ||
  1204. palette[i+41] != palptr->rgbGreen ||
  1205. palette[i+42] != palptr->rgbBlue
  1206. )
  1207. break;
  1208. }
  1209. if (i < 236*4)
  1210. { /* broke early - not the identity palette */
  1211. /* Actually RGBQUAD (BGR) format. */
  1212. if (
  1213. #ifdef WIN32
  1214. memcmp((unsigned char FAR *)pinst->ActivePalette, (unsigned char FAR *)lpbi + (int)lpbi->biSize, (int)lpbi->biClrUsed * sizeof(RGBQUAD)) == 0
  1215. #else
  1216. _fmemcmp((unsigned char FAR *)pinst->ActivePalette, (unsigned char FAR *)lpbi + (int)lpbi->biSize, (int)lpbi->biClrUsed * sizeof(RGBQUAD)) == 0
  1217. #endif
  1218. )
  1219. { /* same as last palette - don't re-init AP */
  1220. DEBUGMSG(ZONE_INIT, ("%s: Use current active palette\r\n", _fx_));
  1221. pinst->UseActivePalette = 1;
  1222. pinst->InitActivePalette = 1;
  1223. }
  1224. else
  1225. {
  1226. DEBUGMSG(ZONE_INIT, ("%s: Use new active palette\r\n", _fx_));
  1227. #ifdef WIN32
  1228. memcpy((unsigned char FAR *)pinst->ActivePalette, (unsigned char FAR *)lpbi + (int)lpbi->biSize, (int)lpbi->biClrUsed * sizeof(RGBQUAD));
  1229. #else
  1230. _fmemcpy((unsigned char FAR *)pinst->ActivePalette, (unsigned char FAR *)lpbi + (int)lpbi->biSize, (int)lpbi->biClrUsed * sizeof(RGBQUAD));
  1231. #endif
  1232. pinst->UseActivePalette = 1;
  1233. }
  1234. }
  1235. else
  1236. {
  1237. DEBUGMSG(ZONE_INIT, ("%s: Use fixed palette\r\n", _fx_));
  1238. }
  1239. }
  1240. else
  1241. {
  1242. DEBUGMSG(ZONE_INIT, ("%s: Use NULL (fixed) palette\r\n", _fx_));
  1243. }
  1244. return ICERR_OK;
  1245. }