/* This file is part of TIFFViewer Copyright (C) 2002-6 Toby Thain, toby@telegraphics.com.au This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /* * TIFF Library Mac-specific Routines. */ #include #include #include "tiffiop.h" #include "file_compat.h" #include "str.h" #include "dbg.h" static tsize_t _tiffReadProc(thandle_t fd, tdata_t buf, tsize_t size) { long count = size; return FSRead((FILEREF)fd,&count,buf) ? -1 : count; } static tsize_t _tiffWriteProc(thandle_t fd, tdata_t buf, tsize_t size) { long count = size; return FSWrite((FILEREF)fd,&count,buf) ? -1 : count; } static toff_t _tiffSeekProc(thandle_t fd, toff_t off, int whence) { long pos,x; OSErr e; static int mode[] = {fsFromStart,fsFromMark,fsFromLEOF}; e = SetFPos((FILEREF)fd,mode[whence],off); if(e == eofErr){ //printf("SetFPos failed:%d",e); /* need to extend the file */ if(whence == SEEK_CUR){ GetFPos((FILEREF)fd,&x); off += x; }else if(whence == SEEK_END){ GetEOF((FILEREF)fd,&x); off += x; } if( !SetEOF((FILEREF)fd,off) && !SetFPos((FILEREF)fd,fsFromStart,off) ) return off; else dbg("SetEOF, or SetFPos to EOF, failed"); }else if(e == noErr){ GetFPos((FILEREF)fd,&pos); return pos; } return -1; } static int _tiffCloseProc(thandle_t fd) { return FSClose((FILEREF)fd); // do nothing } static toff_t _tiffSizeProc(thandle_t fd) { long eof; return GetEOF((FILEREF)fd,&eof) ? 0 : eof; } static int _tiffMapProc(thandle_t fd, tdata_t* pbase, toff_t* psize) { (void) fd; (void) pbase; (void) psize; return (0); } static void _tiffUnmapProc(thandle_t fd, tdata_t base, toff_t size) { (void) fd; (void) base; (void) size; } /* * Open a TIFF file descriptor for read/writing. */ TIFF* TIFFFdOpen(int fd, const char* name, const char* mode) { TIFF* tif; tif = TIFFClientOpen(name, mode, (thandle_t) fd, _tiffReadProc, _tiffWriteProc, _tiffSeekProc, _tiffCloseProc, _tiffSizeProc, _tiffMapProc, _tiffUnmapProc); if (tif) tif->tif_fd = fd; return (tif); } /* * Open a TIFF file for read/writing. */ /* not implemented TIFF* TIFFOpen(const char* name, const char* mode) { } */ void* _TIFFmalloc(tsize_t s) { return (malloc((size_t) s)); } void _TIFFfree(tdata_t p) { free(p); } void* _TIFFrealloc(tdata_t p, tsize_t s) { return (realloc(p, (size_t) s)); } void _TIFFmemset(tdata_t p, int v, tsize_t c) { memset(p, v, (size_t) c); } void _TIFFmemcpy(tdata_t d, const tdata_t s, tsize_t c) { memcpy(d, s, (size_t) c); } int _TIFFmemcmp(const tdata_t p1, const tdata_t p2, tsize_t c) { return (memcmp(p1, p2, (size_t) c)); } static void dbgHandler(const char* module, const char* fmt, va_list ap) { char s[0x200]; vsprintf(s,fmt,ap); dbg(s); } static void nullHandler(const char* module, const char* fmt, va_list ap) { } TIFFErrorHandler _TIFFwarningHandler = nullHandler, _TIFFerrorHandler = nullHandler;//dbgHandler;