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.

300 lines
20 KiB

  1. /****************************************************************************/
  2. /* abdapi.h */
  3. /* */
  4. /* Bitmap Decompression API header file */
  5. /* */
  6. /* Copyright(C) Microsoft Corporation 1997-1999 */
  7. /****************************************************************************/
  8. #ifndef _H_ABDAPI
  9. #define _H_ABDAPI
  10. /****************************************************************************/
  11. /* RLE codes */
  12. /****************************************************************************/
  13. /* */
  14. /* The following codes fill a full single byte address space. The approach */
  15. /* is to use the high order bits to identify the code type and the low */
  16. /* order bits to encode the length of the associated run. There are two */
  17. /* forms of order */
  18. /* - regular orders which have a 5 bit length field (31 bytes of data) */
  19. /* - "lite" orders with a 4 bit length */
  20. /* */
  21. /* A value of 0 in the length field indicates an extended length, where */
  22. /* the following byte contains the length of the data. There is also a */
  23. /* "mega mega" form which has a two byte length field. (See end of */
  24. /* codespace of the codes that define the megamega form). */
  25. /* */
  26. /* A set of codes at the high end of the address space is used to encode */
  27. /* commonly occuring short sequences, in particular */
  28. /* - certain single byte FGBG codings */
  29. /* - single bytes of BLACK and WHITE */
  30. /* */
  31. /* */
  32. /* SUMMARY */
  33. /* ******* */
  34. /* 7 6 5 4 3 2 1 0 76543210 76543210 76543210 */
  35. /* */
  36. /* MEGA_BG_RUN 0 0 0 0 0 0 0 0 <length> */
  37. /* */
  38. /* BG_RUN 0 0 0 <length-> */
  39. /* */
  40. /* MEGA_FG_RUN 0 0 1 0 0 0 0 0 <length> */
  41. /* */
  42. /* FG_RUN 0 0 1 <length-> */
  43. /* */
  44. /* MEGA_FG_BG_IMAGE 0 1 0 0 0 0 0 0 <length> <-data-> ... */
  45. /* */
  46. /* FG_BG_IMAGE 0 1 0 <length-> <-data-> ... */
  47. /* */
  48. /* MEGA_COLOR_RUN 0 1 1 0 0 0 0 0 <length> <-color> */
  49. /* */
  50. /* COLOR_RUN 0 1 1 <length-> <color-> */
  51. /* */
  52. /* MEGA_COLOR_IMAGE 1 0 0 0 0 0 0 0 <length> <-data-> ... */
  53. /* */
  54. /* COLOR_IMAGE 1 0 0 <length-> <-data-> ... */
  55. /* */
  56. /* MEGA_PACKED_CLR_IMG 1 0 1 0 0 0 0 0 <length> <-data-> ... */
  57. /* */
  58. /* PACKED COLOR IMAGE 1 0 1 <length-> <-data-> ... */
  59. /* */
  60. /* SET_FG_MEGA_FG_RUN 1 1 0 0 0 0 0 0 <length> <-color> */
  61. /* */
  62. /* SET_FG_FG_RUN 1 1 0 0 <-len-> <color-> */
  63. /* */
  64. /* SET_FG_MEGA_FG_BG 1 1 0 1 0 0 0 0 <length> <-color> <-data-> ... */
  65. /* */
  66. /* SET_FG_FG_BG 1 1 0 1 <-len-> <color-> <-data-> ... */
  67. /* */
  68. /* MEGA_DITHERED_RUN 1 1 1 0 0 0 0 0 <length> <-data-> <-data-> */
  69. /* */
  70. /* DITHERED_RUN 1 1 1 0 <-len-> <-data-> <-data-> */
  71. /* */
  72. /* MEGA_MEGA_BG_RUN 1 1 1 1 0 0 0 0 */
  73. /* */
  74. /* MEGA_MEGA_FG_RUN 1 1 1 1 0 0 0 1 */
  75. /* */
  76. /* MEGA_MEGA_FGBG 1 1 1 1 0 0 1 0 */
  77. /* */
  78. /* MEGA_MEGA_COLOR_RUN 1 1 1 1 0 0 1 1 */
  79. /* */
  80. /* MEGA_MEGA_CLR_IMG 1 1 1 1 0 1 0 0 */
  81. /* */
  82. /* MEGA_MEGA_PACKED_CLR 1 1 1 1 0 1 0 1 */
  83. /* */
  84. /* MEGA_MEGA_SET_FG_RUN 1 1 1 1 0 1 1 0 */
  85. /* */
  86. /* MEGA_MEGA_SET_FGBG 1 1 1 1 0 1 1 1 */
  87. /* */
  88. /* MEGA_MEGA_DITHER 1 1 1 1 1 0 0 0 */
  89. /* */
  90. /* Special FGBG code 1 1 1 1 1 1 0 0 1 FGBG code 0x03 = 11000000 */
  91. /* (Note that 0x01 will generally handled by the single pel insertion code) */
  92. /* */
  93. /* Special FBBG code 2 1 1 1 1 1 0 1 0 FGBG code 0x05 = 10100000 */
  94. /* */
  95. /* Special FBBG code 3 1 1 1 1 1 0 1 1 FGBG code 0x07 = 11100000 */
  96. /* */
  97. /* Special FBBG code 4 1 1 1 1 1 1 0 0 FGBG code 0x0F = 11110000 */
  98. /* */
  99. /* BLACK 1 1 1 1 1 1 0 1 */
  100. /* */
  101. /* WHITE 1 1 1 1 1 1 1 0 */
  102. /* */
  103. /* START_LOSSY 1 1 1 1 1 1 1 1 */
  104. /* */
  105. /* */
  106. /****************************************************************************/
  107. /* GENERAL NOTES */
  108. /****************************************************************************/
  109. /* */
  110. /* - For MEGA runs the length encoded is the length of the run minus the */
  111. /* maximum length of the non-mega form. */
  112. /* In the mega-mega form we encode the plain 16 bit length, to keep */
  113. /* encoding/deconding simple. */
  114. /* */
  115. /* - The sequence BG_RUN,BG_RUN is not exactly what it appears. We */
  116. /* use the fact that this is not generated in normal encoding to */
  117. /* encode <n background><1 foreground><n background>. The same pel */
  118. /* insertion convention applies to any combination of MEGA_BG run and */
  119. /* BG_RUN */
  120. /* */
  121. /* - A packed image is encoded when we find that all the color fields in a */
  122. /* run have 0 in the high order nibble. We do not currently use this code */
  123. /* for 8 bit compression, but it is supported by the V2 decoder. */
  124. /* */
  125. /* - The set fg color code (Used to exist in V1) has been retired in favor */
  126. /* of separate commands for those codes that may embed a color. Generally*/
  127. /* This saves one byte for every foreground color transition for 8bpp. */
  128. /* */
  129. /* - The color run code is new for V2. It indicates a color run where the */
  130. /* XOR is not performed. This applies to, for example, the line of bits */
  131. /* immediately below a text line. (There is no special case for runs of */
  132. /* the bg color - these are treated as any other color run.) */
  133. /* */
  134. /* - Observation shows a high occurrence of BG runs split by single FGBG */
  135. /* codes. In decreasing probability these are 3,5,7,9,f,11,1f,3f (1 is */
  136. /* handled by the implicit BG run break). Save 1 byte by encoding as */
  137. /* single codes */
  138. /* */
  139. /* - There is a relatively high occurrence of single pel color codes ff and */
  140. /* 00. Save 1 byte by encoding as special characters */
  141. /* */
  142. /* - The length in a FGBG run is slightly strange. Because they generally */
  143. /* occur in multiples of 8 bytes we get a big saving if we encode the */
  144. /* length of a short run as length/8. However, for those special */
  145. /* cases where the length is not a multiple of 8 we encode a long run. */
  146. /* Therefore the long form can only cover the range 1-256 bytes. */
  147. /* beyond that we use the mega-mega form. */
  148. /* */
  149. /****************************************************************************/
  150. /* DETAILS OF COMPRESSION CODES */
  151. /****************************************************************************/
  152. /* */
  153. /* BG_RUN */
  154. /* */
  155. /* Represents a background run (black:0) of the specified length. */
  156. /* */
  157. /****************************************************************************/
  158. /* */
  159. /* FG_BG_IMAGE/SET_FG_FG_BG_IMAGE */
  160. /* */
  161. /* Represents a binary image containing only the current foreground(1) and */
  162. /* background(0) colors. */
  163. /* */
  164. /****************************************************************************/
  165. /* */
  166. /* FG_RUN/SET_FG_FG_RUN */
  167. /* */
  168. /* Represents a continuous foreground run of the specified length. */
  169. /* The foreground color is white by default, and is changed by the */
  170. /* SET_FG_FG_RUN version of this code. */
  171. /* */
  172. /****************************************************************************/
  173. /* */
  174. /* DITHERED_RUN */
  175. /* */
  176. /* Represents a run of alternating colors of the specified length. */
  177. /* */
  178. /****************************************************************************/
  179. /* */
  180. /* COLOR_IMAGE */
  181. /* */
  182. /* Represents a color image of the specified length. No XOR is performed. */
  183. /* This data is uncompressed, so we hope that we won't see */
  184. /* many of these codes! */
  185. /* */
  186. /****************************************************************************/
  187. /* */
  188. /* COLOR_RUN */
  189. /* */
  190. /* Represents a color run of the specified length. No XOR is performed. */
  191. /* Since the color is not XORed, it is unlikely to match the running */
  192. /* foreground color information. Therefore this code always carries a */
  193. /* color byte and there is no SET_FG_COLOR_RUN form of the code. */
  194. /* */
  195. /****************************************************************************/
  196. /* */
  197. /* PACKED_COLOR_IMAGE */
  198. /* */
  199. /* Represents a color image of the specified length, with pairs of colors */
  200. /* packed into a single byte. (This can only be done when the color info */
  201. /* is zero in the high order nibble.) */
  202. /* */
  203. /****************************************************************************/
  204. /* */
  205. /* START_LOSSY */
  206. /* */
  207. /* Informs the decoder that lossy mode has been established and any of the */
  208. /* following color runs will need pixel doubling performing. */
  209. /* RLE decoding will remain in this mode until the end of this block */
  210. /* */
  211. /****************************************************************************/
  212. #define CODE_MASK 0xE0
  213. #define CODE_MASK_LITE 0xF0
  214. #define CODE_BG_RUN 0x00 /* 20 */
  215. #define CODE_FG_RUN 0x20 /* 20 */
  216. #define CODE_FG_BG_IMAGE 0x40 /* 20 */
  217. #define CODE_COLOR_RUN 0x60 /* 20 */
  218. #define CODE_COLOR_IMAGE 0x80 /* 20 */
  219. #ifndef DC_HICOLOR
  220. #define CODE_PACKED_COLOR_IMAGE 0xA0 /* 20 */
  221. #endif
  222. #define CODE_SET_FG_FG_RUN 0xC0 /* 10 */
  223. #define CODE_SET_FG_FG_BG 0xD0 /* 10 */
  224. #define CODE_DITHERED_RUN 0xE0 /* 10 */
  225. #define CODE_MEGA_MEGA_BG_RUN 0xF0
  226. #define CODE_MEGA_MEGA_FG_RUN 0xF1
  227. #define CODE_MEGA_MEGA_FGBG 0xF2
  228. #define CODE_MEGA_MEGA_COLOR_RUN 0xF3
  229. #define CODE_MEGA_MEGA_CLR_IMG 0xF4
  230. #ifndef DC_HICOLOR
  231. #define CODE_MEGA_MEGA_PACKED_CLR 0xF5
  232. #endif
  233. #define CODE_MEGA_MEGA_SET_FG_RUN 0xF6
  234. #define CODE_MEGA_MEGA_SET_FGBG 0xF7
  235. #define CODE_MEGA_MEGA_DITHER 0xF8
  236. #define CODE_SPECIAL_FGBG_1 0xF9
  237. #define CODE_SPECIAL_FGBG_2 0xFA
  238. #ifndef DC_HICOLOR
  239. #define CODE_SPECIAL_FGBG_3 0xFB
  240. #define CODE_SPECIAL_FGBG_4 0xFC
  241. #endif
  242. #define CODE_WHITE 0xFD
  243. #define CODE_BLACK 0xFE
  244. #define CODE_START_LOSSY 0xFF
  245. #define MAX_LENGTH_ORDER 31
  246. #define MAX_LENGTH_LONG_ORDER 287
  247. #define MAX_LENGTH_ORDER_LITE 15
  248. #define MAX_LENGTH_LONG_ORDER_LITE 271
  249. #define MAX_LENGTH_FGBG_ORDER (31*8)
  250. #define MAX_LENGTH_FGBG_ORDER_LITE (15*8)
  251. #define MAX_LENGTH_LONG_FGBG_ORDER 255
  252. /****************************************************************************/
  253. /* The special FGBG codes that correspond to codes F0-F7 */
  254. /****************************************************************************/
  255. #define SPECIAL_FGBG_CODE_1 0x03
  256. #define SPECIAL_FGBG_CODE_2 0x05
  257. #define SPECIAL_FGBG_CODE_3 0x07
  258. #define SPECIAL_FGBG_CODE_4 0x0F
  259. /****************************************************************************/
  260. /* */
  261. /* TYPES */
  262. /* */
  263. /****************************************************************************/
  264. /****************************************************************************/
  265. /* The Compressed Data header structure. */
  266. /****************************************************************************/
  267. typedef struct _CD_HEADER
  268. {
  269. DCUINT16 cbCompFirstRowSize;
  270. DCUINT16 cbCompMainBodySize;
  271. DCUINT16 cbScanWidth;
  272. DCUINT16 cbUncompressedSize;
  273. } CD_HEADER;
  274. typedef CD_HEADER *PCD_HEADER;
  275. /****************************************************************************/
  276. /* */
  277. /* FUNCTIONS */
  278. /* */
  279. /****************************************************************************/
  280. HRESULT DCAPI BD_DecompressBitmap( PDCUINT8 pCompressedData,
  281. PDCUINT8 pDstBitmap,
  282. DCUINT srcDataSize,
  283. DCUINT dstBufferSize,
  284. DCUINT noBCHeader,
  285. DCUINT8 bitmapBitsPerPel,
  286. DCUINT16 bitmapWidth,
  287. DCUINT16 bitmapHeight );
  288. #endif /* H_ABDAPI */