2 * TIFF file IO, using CxFile.
12 #if CXIMAGE_SUPPORT_TIF
14 #include "../tiff/tiffiop.h"
19 _tiffReadProcEx(thandle_t fd, tdata_t buf, tsize_t size)
21 return (tsize_t)((CxFile*)fd)->Read(buf, 1, size);
25 _tiffWriteProcEx(thandle_t fd, tdata_t buf, tsize_t size)
27 return (tsize_t)((CxFile*)fd)->Write(buf, 1, size);
31 _tiffSeekProcEx(thandle_t fd, toff_t off, int whence)
33 if ( off == 0xFFFFFFFF )
35 if (!((CxFile*)fd)->Seek(off, whence))
37 if (whence == SEEK_SET)
40 return (toff_t)((CxFile*)fd)->Tell();
43 // Return nonzero if error
45 _tiffCloseProcEx(thandle_t /*fd*/)
47 // return !((CxFile*)fd)->Close(); // "//" needed for memory files <DP>
54 _tiffSizeProcEx(thandle_t fd)
56 return ((CxFile*)fd)->Size();
60 _tiffMapProcEx(thandle_t /*fd*/, tdata_t* /*pbase*/, toff_t* /*psize*/)
66 _tiffUnmapProcEx(thandle_t /*fd*/, tdata_t /*base*/, toff_t /*size*/)
70 // Open a TIFF file descriptor for read/writing.
73 TIFFOpen(const char* name, const char* mode)
75 static const char module[] = "TIFFOpen";
76 FILE* stream = fopen(name, mode);
79 TIFFError(module, "%s: Cannot open", name);
82 return (TIFFFdOpen((int)stream, name, mode));
87 _TIFFFdOpen(void* fd, const char* name, const char* mode)
91 tif = TIFFClientOpen(name, mode,
93 _tiffReadProcEx, _tiffWriteProcEx, _tiffSeekProcEx, _tiffCloseProcEx,
94 _tiffSizeProcEx, _tiffMapProcEx, _tiffUnmapProcEx);
100 extern "C" TIFF* _TIFFOpenEx(CxFile* stream, const char* mode)
102 return (_TIFFFdOpen(stream, "TIFF IMAGE", mode));
106 extern char* malloc();
107 extern char* realloc();
113 _TIFFmalloc(tsize_t s)
115 return (malloc((size_t) s));
125 _TIFFrealloc(tdata_t p, tsize_t s)
127 return (realloc(p, (size_t) s));
131 _TIFFmemset(tdata_t p, int v, tsize_t c)
133 memset(p, v, (size_t) c);
137 _TIFFmemcpy(tdata_t d, const tdata_t s, tsize_t c)
139 memcpy(d, s, (size_t) c);
143 _TIFFmemcmp(const tdata_t p1, const tdata_t p2, tsize_t c)
145 return (memcmp(p1, p2, (size_t) c));
149 #define DbgPrint wvsprintf
150 #define DbgPrint2 wsprintf
151 #define DbgMsgBox MessageBox
153 #define DbgPrint wvsprintfA
154 #define DbgPrint2 wsprintfA
155 #define DbgMsgBox MessageBoxA
159 Win32WarningHandler(const char* module, const char* fmt, va_list ap)
162 #if (!defined(_CONSOLE) && !defined(_WIN32_WCE) && defined(WIN32))
165 LPCSTR szTitleText = "%s Warning";
166 LPCSTR szDefaultModule = "TIFFLIB";
167 szTmp = (module == NULL) ? (LPSTR)szDefaultModule : (LPSTR)module;
168 if ((szTitle = (LPSTR)LocalAlloc(LMEM_FIXED, (strlen(szTmp) +
169 strlen(szTitleText) + strlen(fmt) + 128))) == NULL)
171 DbgPrint2(szTitle, szTitleText, szTmp);
172 szTmp = szTitle + (strlen(szTitle)+2);
173 DbgPrint(szTmp, fmt, ap);
174 DbgMsgBox(GetFocus(), szTmp, szTitle, MB_OK | MB_ICONINFORMATION);
179 fprintf(stderr, "%s: ", module);
180 fprintf(stderr, "Warning, ");
181 vfprintf(stderr, fmt, ap);
182 fprintf(stderr, ".\n");
186 TIFFErrorHandler _TIFFwarningHandler = Win32WarningHandler;
189 Win32ErrorHandler(const char* module, const char* fmt, va_list ap)
192 #if (!defined(_CONSOLE) && !defined(_WIN32_WCE) && defined(WIN32))
195 LPCSTR szTitleText = "%s Error";
196 LPCSTR szDefaultModule = "TIFFLIB";
197 szTmp = (module == NULL) ? (LPSTR)szDefaultModule : (LPSTR)module;
198 if ((szTitle = (LPSTR)LocalAlloc(LMEM_FIXED, (strlen(szTmp) +
199 strlen(szTitleText) + strlen(fmt) + 128))) == NULL)
201 DbgPrint2(szTitle, szTitleText, szTmp);
202 szTmp = szTitle + (strlen(szTitle)+2);
203 DbgPrint(szTmp, fmt, ap);
204 DbgMsgBox(GetFocus(), szTmp, szTitle, MB_OK | MB_ICONEXCLAMATION);
209 fprintf(stderr, "%s: ", module);
210 vfprintf(stderr, fmt, ap);
211 fprintf(stderr, ".\n");
215 TIFFErrorHandler _TIFFerrorHandler = Win32ErrorHandler;