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.

295 lines
7.9 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. test.c
  5. Abstract:
  6. This file contains the main entrypooint
  7. for the TIFF library test program.
  8. Environment:
  9. WIN32 User Mode
  10. Author:
  11. Wesley Witt (wesw) 17-Feb-1996
  12. --*/
  13. #include "test.h"
  14. #pragma hdrstop
  15. BOOL
  16. TiffPreProcess(
  17. LPTSTR FileName,
  18. DWORD tiffCompression
  19. )
  20. {
  21. BOOL NegotHiRes = TRUE;
  22. BOOL SrcHiRes = TRUE;
  23. WCHAR OutFileName[_MAX_FNAME];
  24. HANDLE OutFileHandle;
  25. HANDLE SrcHandle;
  26. DWORD *lpdwOutputBuffer;
  27. //DWORD dwBytesWritten;
  28. DWORD dwSizeOutputBuffer = 500000;
  29. DWORD dwUsedSizeOutputBuffer;
  30. DWORD MaxNeedOutSize;
  31. DWORD StripDataSize;
  32. DWORD RetCode = FALSE;
  33. TIFF_INFO TiffInfo;
  34. BOOL fOutFileNeedsBeClosed = 0;
  35. BOOL fOutBufferNeedsBeFreed = 0;
  36. DWORD CurrentOut = 0;
  37. DWORD FirstOut = 0;
  38. DWORD LastOut = 0;
  39. BOOL fTiffPageDone = FALSE;
  40. BOOL fTiffDocumentDone = FALSE;
  41. LPTSTR p;
  42. lpdwOutputBuffer = (DWORD *) VirtualAlloc(
  43. NULL,
  44. dwSizeOutputBuffer,
  45. MEM_COMMIT,
  46. PAGE_READWRITE
  47. );
  48. if (! lpdwOutputBuffer) {
  49. _tprintf( L"ERROR TIFF_TX: lpdwOutputBuffer can'r VirtualAlloc \n");
  50. goto l_exit;
  51. }
  52. fOutBufferNeedsBeFreed = 1;
  53. _tprintf (L"TIFF_TX: NegotHiRes=%d SrcHiRes=%d Started at %ld \n",
  54. NegotHiRes, SrcHiRes, GetTickCount() );
  55. SrcHandle = TiffOpen( FileName,
  56. &TiffInfo,
  57. TRUE,
  58. FILLORDER_LSB2MSB
  59. );
  60. if (!SrcHandle) {
  61. goto l_exit;
  62. }
  63. CurrentOut = 1;
  64. //
  65. // loop thru all pages
  66. //
  67. p = wcsrchr(FileName,'.');
  68. *p = (TCHAR) 0;
  69. wsprintf( OutFileName, L"%snew.tif", FileName );
  70. *p = '.';
  71. if (!( OutFileHandle = TiffCreate(OutFileName,
  72. tiffCompression,
  73. 1728,
  74. FILLORDER_LSB2MSB,
  75. NegotHiRes) ) ) {
  76. _tprintf( L"TIFF_TX: ERROR: %lx CREATING file %s \n", GetLastError(), OutFileName);
  77. goto l_exit;
  78. }
  79. fOutFileNeedsBeClosed = 1;
  80. do {
  81. fTiffPageDone = 0;
  82. _tprintf( L"TIFF_TX: Page %d started at %ld\n", CurrentOut, GetTickCount() );
  83. if (! TiffSeekToPage( (HANDLE) SrcHandle, CurrentOut, FILLORDER_LSB2MSB ) ) {
  84. _tprintf( L"ERROR: seeking to page \n");
  85. goto l_exit;
  86. }
  87. else {
  88. _tprintf( L"TIFF_TX: Tiff seeking to page -OK time=%ld\n", GetTickCount() );
  89. }
  90. __try {
  91. //
  92. // check the current page dimensions. Add memory if needed.
  93. //
  94. TiffGetCurrentPageData( (HANDLE) SrcHandle,
  95. NULL,
  96. &StripDataSize,
  97. NULL,
  98. NULL
  99. );
  100. if ( (StripDataSize < 0) || (StripDataSize > 1500000) ) {
  101. _tprintf( L"ERROR: Tiff CONVERTING %d page StripSize = %d \n", CurrentOut, StripDataSize);
  102. goto l_exit;
  103. }
  104. if (tiffCompression == TIFF_COMPRESSION_MR) {
  105. MaxNeedOutSize = StripDataSize * 3 / 2;
  106. }
  107. else {
  108. MaxNeedOutSize = StripDataSize * 2;
  109. }
  110. if (MaxNeedOutSize > dwSizeOutputBuffer) {
  111. if (MaxNeedOutSize > 1000000) {
  112. dwSizeOutputBuffer = 1500000;
  113. }
  114. else {
  115. dwSizeOutputBuffer = 1000000;
  116. }
  117. VirtualFree(lpdwOutputBuffer, 0 , MEM_RELEASE);
  118. lpdwOutputBuffer = (DWORD *) VirtualAlloc(
  119. NULL,
  120. dwSizeOutputBuffer,
  121. MEM_COMMIT,
  122. PAGE_READWRITE
  123. );
  124. if (! lpdwOutputBuffer) {
  125. _tprintf( L"ERROR TIFF_TX: lpdwOutputBuffer can't VirtualAlloc %d \n", dwSizeOutputBuffer);
  126. goto l_exit;
  127. }
  128. fOutBufferNeedsBeFreed = 1;
  129. }
  130. dwUsedSizeOutputBuffer = dwSizeOutputBuffer;
  131. if (tiffCompression == TIFF_COMPRESSION_MR) {
  132. if (NegotHiRes == SrcHiRes) {
  133. if (! ConvMmrPageToMrSameRes ( (HANDLE) SrcHandle,
  134. lpdwOutputBuffer,
  135. &dwUsedSizeOutputBuffer,
  136. NegotHiRes) ) {
  137. _tprintf( L"ERROR: Tiff CONVERTING %d page \n", CurrentOut);
  138. goto l_exit;
  139. }
  140. }
  141. else {
  142. if (! ConvMmrPageHiResToMrLoRes ( (HANDLE) SrcHandle,
  143. lpdwOutputBuffer,
  144. &dwUsedSizeOutputBuffer) ) {
  145. _tprintf( L"ERROR: Tiff CONVERTING %d page \n", CurrentOut);
  146. goto l_exit;
  147. }
  148. }
  149. }
  150. else {
  151. if (! ConvMmrPageToMh ( (HANDLE) SrcHandle,
  152. lpdwOutputBuffer,
  153. &dwUsedSizeOutputBuffer,
  154. NegotHiRes,
  155. SrcHiRes) ) {
  156. _tprintf( L"ERROR: Tiff CONVERTING %d page \n", CurrentOut);
  157. goto l_exit;
  158. }
  159. }
  160. } __except (EXCEPTION_EXECUTE_HANDLER) {
  161. if (fOutBufferNeedsBeFreed) {
  162. VirtualFree(lpdwOutputBuffer, 0 , MEM_RELEASE);
  163. }
  164. CloseHandle(OutFileHandle);
  165. return (FALSE);
  166. }
  167. TiffStartPage( OutFileHandle );
  168. if ( ! TiffWriteRaw( OutFileHandle, (LPBYTE) lpdwOutputBuffer, dwUsedSizeOutputBuffer) ) {
  169. _tprintf( L"ERROR: Tiff writing file %s \n", OutFileName);
  170. goto l_exit;
  171. }
  172. TiffEndPage( OutFileHandle );
  173. fTiffPageDone = 1;
  174. _tprintf( L"TIFF_TX: Done page %d size=%d at %ld \n", CurrentOut, dwUsedSizeOutputBuffer, GetTickCount() );
  175. if (!FirstOut) {
  176. FirstOut = 1;
  177. }
  178. LastOut++;
  179. //
  180. // check to see if we are done
  181. //
  182. if (LastOut >= TiffInfo.PageCount) {
  183. _tprintf( L"TIFF_TX: Done whole document Last page %d size=%d at %ld \n", CurrentOut, dwUsedSizeOutputBuffer, GetTickCount() );
  184. fTiffDocumentDone = 1;
  185. goto good_exit;
  186. }
  187. //
  188. // we want to maintain 2 pages ahead
  189. //
  190. CurrentOut++;
  191. _tprintf( L"TIFF_TX: Start page %d at %ld \n", CurrentOut, GetTickCount() );
  192. } while (1);
  193. good_exit:
  194. if (SrcHandle) {
  195. TiffClose( (HANDLE) SrcHandle);
  196. }
  197. RetCode = TRUE;
  198. l_exit:
  199. if (fOutFileNeedsBeClosed) {
  200. TiffClose( (HANDLE) OutFileHandle);
  201. }
  202. if (fOutBufferNeedsBeFreed) {
  203. VirtualFree(lpdwOutputBuffer, 0 , MEM_RELEASE);
  204. }
  205. _tprintf( L"TIFF_TX: TiffConvertThread EXITs at %ld \n", GetTickCount() );
  206. return (RetCode);
  207. }