Source code of Windows XP (NT5)
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.

306 lines
11 KiB

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