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