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.

311 lines
7.3 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. faxtiff.h
  5. Abstract:
  6. Declarations for Group3 2D compression and generating TIFF files
  7. Environment:
  8. Windows XP Fax driver, kernel mode
  9. Revision History:
  10. 01/23/96 -davidx-
  11. Created it.
  12. dd-mm-yy -author-
  13. description
  14. NOTE:
  15. Structure of the TIFF output file from the driver:
  16. 4949 II
  17. 002a 42
  18. 00000008 Offset to the first IFD
  19. IFD for the first page
  20. Number of directory entries
  21. NEWSUBFILETYPE LONG 1 2 - Page in a multi-page document
  22. PAGENUMBER SHORT 2 PageNumber 0000
  23. IMAGEWIDTH LONG 1 ImageWidth
  24. IMAGEHEIGHT LONG 1 ImageHeight
  25. BITSPERSAMPLE SHORT 1 1
  26. SAMPLESPERPIXEL SHORT 1 1
  27. COMPRESSION SHORT 1 4 - G4Fax
  28. GROUP4OPTIONS SHORT 1 0
  29. CLEANFAXDATA SHORT 1 0
  30. FILLORDER SHORT 1 2
  31. PHOTOMETRIC SHORT 1 0 - WhiteIsZero
  32. RESOLUTIONUNIT SHORT 1 2 - Inch
  33. XRESOLUTION RATIONAL 1 Xdpi
  34. YRESOLUTION RATIONAL 1 Ydpi
  35. ROWSPERSTRIP LONG 1 ImageHeight
  36. STRIPBYTECOUNTS LONG 1 Compressed data byte count
  37. STRIPOFFSETS LONG 1 Offset to compressed data
  38. Next IFD offset
  39. Compressed data for the first page
  40. IFD for the second page
  41. Compressed data for the second page
  42. ...
  43. Last IFD
  44. 0001
  45. SOFTWARE ASCII n "Microsoft Shared Fax Driver"
  46. 00000000
  47. 00000000
  48. --*/
  49. #ifndef _FAXTIFF_H_
  50. #define _FAXTIFF_H_
  51. //
  52. // TIFF field tag and type constants
  53. //
  54. #define TIFFTYPE_ASCII 2
  55. #define TIFFTYPE_SHORT 3
  56. #define TIFFTYPE_LONG 4
  57. #define TIFFTYPE_RATIONAL 5
  58. #define TIFFTAG_NEWSUBFILETYPE 254
  59. #define SUBFILETYPE_PAGE 2
  60. #define TIFFTAG_IMAGEWIDTH 256
  61. #define TIFFTAG_IMAGEHEIGHT 257
  62. #define TIFFTAG_BITSPERSAMPLE 258
  63. #define TIFFTAG_COMPRESSION 259
  64. #define COMPRESSION_G3FAX 3
  65. #define COMPRESSION_G4FAX 4
  66. #define TIFFTAG_PHOTOMETRIC 262
  67. #define PHOTOMETRIC_WHITEIS0 0
  68. #define PHOTOMETRIC_BLACKIS0 1
  69. #define TIFFTAG_FILLORDER 266
  70. #define FILLORDER_MSB 1
  71. #define FILLORDER_LSB 2
  72. #define TIFFTAG_STRIPOFFSETS 273
  73. #define TIFFTAG_SAMPLESPERPIXEL 277
  74. #define TIFFTAG_ROWSPERSTRIP 278
  75. #define TIFFTAG_STRIPBYTECOUNTS 279
  76. #define TIFFTAG_XRESOLUTION 282
  77. #define TIFFF_RES_X 204
  78. #define TIFFTAG_YRESOLUTION 283
  79. #define TIFFF_RES_Y 196
  80. #define TIFFF_RES_Y_DRAFT 98
  81. #define TIFFTAG_G3OPTIONS 292
  82. #define G3_2D 1
  83. #define G3_ALIGNEOL 4
  84. #define TIFFTAG_G4OPTIONS 293
  85. #define TIFFTAG_RESUNIT 296
  86. #define RESUNIT_INCH 2
  87. #define TIFFTAG_PAGENUMBER 297
  88. #define TIFFTAG_SOFTWARE 305
  89. #define TIFFTAG_CLEANFAXDATA 327
  90. //
  91. // Data structure for representing our TIFF output file header information
  92. //
  93. typedef struct {
  94. WORD magic1; // II
  95. WORD magic2; // 42
  96. LONG firstIFD; // offset to first IFD
  97. DWORD signature; // driver private signature
  98. } TIFFFILEHEADER;
  99. #define TIFF_MAGIC1 'II'
  100. #define TIFF_MAGIC2 42
  101. //
  102. // Data structure for representing a single IFD entry
  103. //
  104. typedef struct {
  105. WORD tag; // field tag
  106. WORD type; // field type
  107. DWORD count; // number of values
  108. DWORD value; // value or value offset
  109. } IFDENTRY, *PIFDENTRY;
  110. //
  111. // IFD entries we generate for each page
  112. //
  113. enum {
  114. IFD_NEWSUBFILETYPE,
  115. IFD_IMAGEWIDTH,
  116. IFD_IMAGEHEIGHT,
  117. IFD_BITSPERSAMPLE,
  118. IFD_COMPRESSION,
  119. IFD_PHOTOMETRIC,
  120. IFD_FILLORDER,
  121. IFD_STRIPOFFSETS,
  122. IFD_SAMPLESPERPIXEL,
  123. IFD_ROWSPERSTRIP,
  124. IFD_STRIPBYTECOUNTS,
  125. IFD_XRESOLUTION,
  126. IFD_YRESOLUTION,
  127. IFD_G3G4OPTIONS,
  128. IFD_RESUNIT,
  129. IFD_PAGENUMBER,
  130. IFD_SOFTWARE,
  131. IFD_CLEANFAXDATA,
  132. NUM_IFD_ENTRIES
  133. };
  134. typedef struct {
  135. WORD reserved;
  136. WORD wIFDEntries;
  137. IFDENTRY ifd[NUM_IFD_ENTRIES];
  138. DWORD nextIFDOffset;
  139. DWORD filler;
  140. DWORD xresNum;
  141. DWORD xresDenom;
  142. DWORD yresNum;
  143. DWORD yresDenom;
  144. CHAR software[32];
  145. } FAXIFD, *PFAXIFD;
  146. //
  147. // Output compressed data bytes in correct fill order
  148. //
  149. #ifdef USELSB
  150. #define OutputByte(n) BitReverseTable[(BYTE) (n)]
  151. #else
  152. #define OutputByte(n) ((BYTE) (n))
  153. #endif
  154. //
  155. // Output a sequence of compressed bits
  156. //
  157. #define OutputBits(pdev, length, code) { \
  158. (pdev)->bitdata |= (code) << ((pdev)->bitcnt - (length)); \
  159. if (((pdev)->bitcnt -= (length)) <= 2*BYTEBITS) { \
  160. *(pdev)->pCompBufPtr++ = OutputByte(((pdev)->bitdata >> 3*BYTEBITS)); \
  161. *(pdev)->pCompBufPtr++ = OutputByte(((pdev)->bitdata >> 2*BYTEBITS)); \
  162. (pdev)->bitdata <<= 2*BYTEBITS; \
  163. (pdev)->bitcnt += 2*BYTEBITS; \
  164. } \
  165. }
  166. //
  167. // Flush any leftover bits into the compressed bitmap buffer
  168. //
  169. #define FlushBits(pdev) { \
  170. while ((pdev)->bitcnt < DWORDBITS) { \
  171. (pdev)->bitcnt += BYTEBITS; \
  172. *(pdev)->pCompBufPtr++ = OutputByte(((pdev)->bitdata >> 3*BYTEBITS)); \
  173. (pdev)->bitdata <<= BYTEBITS; \
  174. } \
  175. (pdev)->bitdata = 0; \
  176. (pdev)->bitcnt = DWORDBITS; \
  177. }
  178. //
  179. // Find the next pixel on the scanline whose color is opposite of
  180. // the specified color, starting from the specified starting point
  181. //
  182. #define NextChangingElement(pbuf, startBit, stopBit, isBlack) \
  183. ((startBit) + ((isBlack) ? FindBlackRun((pbuf), (startBit), (stopBit)) : \
  184. FindWhiteRun((pbuf), (startBit), (stopBit))))
  185. //
  186. // Check if the specified pixel on the scanline is black or white
  187. // 1 - the specified pixel is black
  188. // 0 - the specified pixel is white
  189. //
  190. #define GetBit(pbuf, bit) (((pbuf)[(bit) >> 3] >> (((bit) ^ 7) & 7)) & 1)
  191. //
  192. // Compress the specified number of scanlines
  193. //
  194. BOOL
  195. EncodeFaxData(
  196. PDEVDATA pdev,
  197. PBYTE plinebuf,
  198. INT lineWidth,
  199. INT lineCount
  200. );
  201. //
  202. // Output TIFF IFD for the current page
  203. //
  204. BOOL
  205. WriteTiffIFD(
  206. PDEVDATA pdev,
  207. LONG bmpWidth,
  208. LONG bmpHeight,
  209. DWORD compressedBits
  210. );
  211. //
  212. // Output the compressed bitmap data for the current page
  213. //
  214. BOOL
  215. WriteTiffBits(
  216. PDEVDATA pdev,
  217. PBYTE pCompBits,
  218. DWORD compressedBits
  219. );
  220. //
  221. // Enlarge the buffer for holding the compressed bitmap data
  222. //
  223. BOOL
  224. GrowCompBitsBuffer(
  225. PDEVDATA pdev,
  226. LONG scanlineSize
  227. );
  228. //
  229. // Free the buffer for holding the compressed bitmap data
  230. //
  231. VOID
  232. FreeCompBitsBuffer(
  233. PDEVDATA pdev
  234. );
  235. //
  236. // Initialize the fax encoder
  237. //
  238. BOOL
  239. InitFaxEncoder(
  240. PDEVDATA pdev,
  241. LONG bmpWidth,
  242. LONG bmpHeight
  243. );
  244. #endif // !_FAXTIFF_H_