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.

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