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.

324 lines
12 KiB

  1. /**************************************************************************
  2. DRAWDIBI.H - internal DrawDib include file
  3. **************************************************************************/
  4. // This stuff is not going to work for win64
  5. #pragma warning(disable:4312)
  6. #ifndef _WIN32
  7. #define VFWAPI FAR PASCAL _loadds
  8. #define VFWAPIV FAR CDECL _loadds
  9. #endif
  10. //#define MEASURE_PERFORMANCE
  11. #if defined(MEASURE_PERFORMANCE) && defined(_WIN32) && defined(DEBUG)
  12. #include <nt.h>
  13. #include <ntrtl.h>
  14. #include <nturtl.h>
  15. #endif
  16. /**************************************************************************
  17. includes
  18. **************************************************************************/
  19. #include <win32.h> // for Win32 and Win16
  20. #include <memory.h> // for _fmemcmp
  21. #include <vfw.h>
  22. #include "dither.h"
  23. #include "stretch.h"
  24. #include "lockbm.h"
  25. #include "setdi.h"
  26. #include "dciman.h"
  27. /**************************************************************************
  28. **************************************************************************/
  29. #define DDF_OURFLAGS 0xFFFFC000l /* internal flags */
  30. #define DDF_MEMORYDC 0x00008000l /* drawing to a memory DC */
  31. #define DDF_WANTKEY 0x00004000l /* wait for a key frame */
  32. #define DDF_STRETCH 0x00010000l /* we need to stretch */
  33. #define DDF_DITHER 0x00020000l /* we need to dither */
  34. #define DDF_BITMAP 0x00040000l /* Display driver isn't very good */
  35. #define DDF_X 0x00080000l /* */
  36. #define DDF_IDENTITYPAL 0x00100000l /* 1:1 palette mapping */
  37. #define DDF_CANBITMAPX 0x00200000l /* can decompress to bitmap */
  38. #define DDF_CANSCREENX 0x00400000l /* we can decompress/draw to screen */
  39. #define DDF_Y 0x00800000l /* */
  40. #define DDF_DIRTY 0x01000000l /* decompress buffer is dirty (not valid) */
  41. #define DDF_HUGEBITMAP 0x02000000l /* decompressing to a HUGE bitmap */
  42. #define DDF_XLATSOURCE 0x04000000l /* need to xlat source cord. */
  43. #define DDF_CLIPPED 0x08000000l /* currently clipped */
  44. #define DDF_NEWPALETTE 0x10000000l /* palette needs mapped */
  45. #define DDF_CLIPCHECK 0x20000000l /* we care about clipping */
  46. #define DDF_CANDRAWX 0x40000000l /* we can draw direct to screen */
  47. #define DDF_CANSETPAL 0x80000000l /* codec supports ICM_SETPALETTE */
  48. #define DDF_USERFLAGS 0x00003FFFl /* the user/called gives these, see .h */
  49. /* these flags change what DrawDibBegin does */
  50. #define DDF_BEGINFLAGS (DDF_JUSTDRAWIT | DDF_BUFFER | DDF_ANIMATE | DDF_FULLSCREEN | DDF_HALFTONE)
  51. /**************************************************************************
  52. flags, a little more info for people who are not me
  53. DDF_OURFLAGS these are internal state flags, not passed in by
  54. the user.
  55. DDF_STRETCH the current draw requires us to stretch, if GDI
  56. is stretching this bit is clear.
  57. DDF_DITHER the current draw requires a format conversion
  58. note a 16->24 32->24 conversion is also called
  59. a dither, again if GDI is taking care of it this
  60. bit is clear.
  61. DDF_BITMAP the display driver isn't very good and we are converting
  62. DIB to BMPs before drawing
  63. DDF_CANBITMAPX we can decompress to bitmaps.
  64. DDF_BITMAPX we are decompressing directly into a bitmap
  65. DDF_IDENTITYPAL the palette is a identity palette.
  66. DDF_CANSCREENX we can decompress to screen with the current draw
  67. params.
  68. DDF_SCREENX we are currently decompressing to the screen.
  69. DDF_DIRTY the decompress buffer is dirty, ie does not
  70. match what *should* be on the screen.
  71. DDF_HUGEBITMAP we are decompressing into a huge bitmap, and
  72. then calling FlatToHuge...
  73. DDF_XLATSOURCE the source cordinates need remapping after
  74. decompression, (basicly the decompressor is
  75. doing a stretch...)
  76. DDF_UPDATE the buffer is valid but needs drawn to the screen.
  77. this will get set when DDF_DONTDRAW is passed, and
  78. we are decompressing to memory
  79. another way to put it is, if DDF_UPDATE is set
  80. the screen is out of sync with our internal
  81. buffer (the internal buffer is more correct)
  82. DDF_CLIPPED we are clipped
  83. DDF_NEWPALETTE we need to build new palette map
  84. DDF_CLIPCHECK please check for clipping changes.
  85. DDF_W
  86. DDF_Q
  87. DDF_USERFLAGS these flags are defined in the API, the user will pass
  88. these to us.
  89. DDF_BEGINFLAGS these flags will effect what DrawDibBegin() does
  90. **************************************************************************/
  91. /**************************************************************************
  92. **************************************************************************/
  93. #ifdef DEBUG
  94. #define DPF0( x ) { \
  95. int fSave = fDebug; \
  96. fDebug = 1; \
  97. ddprintf x ; \
  98. fDebug = fSave; \
  99. }
  100. #define DPF2( x ) if (fDebug >= 2 ){ \
  101. ddprintf x ; \
  102. }
  103. #define DPF( x ) ddprintf x
  104. #define DEBUG_RETAIL
  105. #else
  106. #define DPF2(x)
  107. #define DPF0(x)
  108. #define DPF(x)
  109. #endif
  110. #ifdef DEBUG_RETAIL
  111. #define MODNAME "DRAWDIB"
  112. extern void FAR cdecl ddprintf(LPSTR szFormat, ...);
  113. #define RPF( x ) ddprintf x
  114. #else
  115. #define RPF(X)
  116. #endif
  117. /**************************************************************************
  118. * The biXXXXX elements are grouped at the end to minimise the chance of
  119. * overwriting non bitmap data (i.e. pointers). IF the code was totally
  120. * clean this would be irrelevant, however it does increase robustness.
  121. **************************************************************************/
  122. typedef struct {
  123. UINT wSize; /* MANDATORY: this MUST be the first field */
  124. ULONG ulFlags;
  125. UINT wError;
  126. #define DECOMPRESS_NONE 0
  127. #define DECOMPRESS_BITMAP 1
  128. #define DECOMPRESS_SCREEN 2
  129. #define DECOMPRESS_BUFFER 3
  130. int iDecompress;
  131. int dxSrc;
  132. int dySrc;
  133. int dxDst;
  134. int dyDst;
  135. HPALETTE hpal;
  136. HPALETTE hpalCopy;
  137. HPALETTE hpalDraw;
  138. HPALETTE hpalDrawLast; /* hpalDraw for last DrawDibBegin */
  139. int ClrUsed; /* number of colors used! */
  140. int iAnimateStart; /* colors we can change */
  141. int iAnimateLen;
  142. int iAnimateEnd;
  143. int iPuntFrame; /* how many frames we blew off */
  144. /*
  145. * set to DIB_RGB_COLORS, DIB_PAL_COLORS, or if on Win32 and 1:1 palette
  146. * DIB_PAL_INDICES (see DrawdibCheckPalette())
  147. *
  148. */
  149. UINT uiPalUse;
  150. DITHERPROC DitherProc;
  151. LPBYTE pbBuffer; /* decompress buffer */
  152. LPBYTE pbStretch; /* stretched bits. */
  153. //
  154. // note we alias the stretch buffer for bitmaps too.
  155. //
  156. #define biBitmap biStretch
  157. #define pbBitmap pbStretch
  158. SETDI sd; /* for SetBitmap */
  159. HBITMAP hbmDraw; /* for drawing DIBs on the VGA!!! */
  160. HDC hdcDraw;
  161. HDC hdcLast; /* hdc last call to DrawDibBegin */
  162. LPVOID lpDIBSection; /* pointer to dib section bits */
  163. LPBYTE pbDither; /* bits we will dither to */
  164. LPVOID lpDitherTable; /* for dithering */
  165. HIC hic; /* decompressor */
  166. #ifdef DEBUG_RETAIL
  167. DRAWDIBTIME ddtime;
  168. #endif
  169. LPBITMAPINFOHEADER lpbi; /* source dib format */
  170. RGBQUAD (FAR *lpargbqIn)[256];/* source dib colors */
  171. BITMAPINFOHEADER biBuffer; /* decompress format */
  172. RGBQUAD argbq[256]; /* drawdib colors */
  173. BITMAPINFOHEADER biStretch; /* stretched DIB */
  174. DWORD smag[3]; /* room for masks */
  175. BITMAPINFOHEADER biDraw; /* DIB we will draw */
  176. WORD aw[512]; /* either index's or RGBQs */
  177. BYTE ab[256]; /* pallete mapping (!!!needed?) */
  178. #ifndef _WIN32
  179. HTASK htask;
  180. #endif
  181. } DRAWDIB_STRUCT, *PDD;
  182. /**************************************************************************
  183. **************************************************************************/
  184. extern DRAWDIB_STRUCT gdd;
  185. extern WORD gwScreenBitDepth;
  186. #ifndef _WIN32
  187. extern BOOL gf286;
  188. #endif
  189. /**************************************************************************
  190. **************************************************************************/
  191. // flags for <wFlags> parameter of DisplayDib()
  192. #define DISPLAYDIB_NOPALETTE 0x0010 // don't set palette
  193. #define DISPLAYDIB_NOCENTER 0x0020 // don't center image
  194. #define DISPLAYDIB_NOWAIT 0x0040 // don't wait before returning
  195. #define DISPLAYDIB_NOIMAGE 0x0080 // don't draw image
  196. #define DISPLAYDIB_ZOOM2 0x0100 // stretch by 2
  197. #define DISPLAYDIB_DONTLOCKTASK 0x0200 // don't lock current task
  198. #define DISPLAYDIB_TEST 0x0400 // testing the command
  199. #define DISPLAYDIB_BEGIN 0x8000 // start of multiple calls
  200. #define DISPLAYDIB_END 0x4000 // end of multiple calls
  201. #define DISPLAYDIB_MODE_DEFAULT 0x0000
  202. UINT (FAR PASCAL *DisplayDib)(LPBITMAPINFOHEADER lpbi, LPSTR lpBits, UINT wFlags);
  203. UINT (FAR PASCAL *DisplayDibEx)(LPBITMAPINFOHEADER lpbi, int x, int y, LPSTR lpBits, UINT wFlags);
  204. /**************************************************************************
  205. **************************************************************************/
  206. #ifdef DEBUG_RETAIL
  207. #define TIMEINC() pdd->ddtime.timeCount++
  208. #define TIMESTART(time) pdd->ddtime.time -= timeGetTime()
  209. #define TIMEEND(time) pdd->ddtime.time += timeGetTime()
  210. #else
  211. #define TIMEINC()
  212. #define TIMESTART(time)
  213. #define TIMEEND(time)
  214. #endif
  215. /**************************************************************************
  216. **************************************************************************/
  217. #define WIDTHBYTES(i) ((unsigned)((i+31)&(~31))/8) /* ULONG aligned ! */
  218. #define DIBWIDTHBYTES(bi) (UINT)WIDTHBYTES((int)(bi).biWidth * (int)(bi).biBitCount)
  219. #define DIBSIZEIMAGE(bi) ((DWORD)(UINT)(bi).biHeight * (DWORD)(UINT)DIBWIDTHBYTES(bi))
  220. #define PUSHBI(bi) (int)(bi).biWidth, (int)(bi).biHeight, (int)(bi).biBitCount
  221. /**************************************************************************
  222. **************************************************************************/
  223. #if defined(MEASURE_PERFORMANCE) && defined(_WIN32) && defined(DEBUG)
  224. static LARGE_INTEGER PC1; /* current counter value */
  225. static LARGE_INTEGER PC2; /* current counter value */
  226. static LARGE_INTEGER PC3; /* current counter value */
  227. #define abs(x) ((x) < 0 ? -(x) : (x))
  228. static VOID StartCounting(VOID)
  229. {
  230. QueryPerformanceCounter(&PC1);
  231. return;
  232. }
  233. static VOID EndCounting(LPSTR szId)
  234. {
  235. QueryPerformanceCounter(&PC2);
  236. PC3.QuadPart = PC2.QuadPart - PC1.QuadPart;
  237. DPF(("%s: %d ticks", szId, PC3.LowPart));
  238. return;
  239. }
  240. #else
  241. #define StartCounting()
  242. #define EndCounting(x)
  243. #endif