Visualization Library 2.0.0-b5

A lightweight C++ OpenGL middleware for 2D/3D graphics

VL     Star     Watch     Fork     Issue

[Download] [Tutorials] [All Classes] [Grouped Classes]
tif_atari.c
Go to the documentation of this file.
1 /* "$Header: /cvs/maptools/cvsroot/libtiff/libtiff/tif_atari.c,v 1.2 2005/12/21 12:23:13 joris Exp $" */
2 
3 /*
4  * Copyright (c) 1988-1997 Sam Leffler
5  * Copyright (c) 1991-1997 Silicon Graphics, Inc.
6  *
7  * Permission to use, copy, modify, distribute, and sell this software and
8  * its documentation for any purpose is hereby granted without fee, provided
9  * that (i) the above copyright notices and this permission notice appear in
10  * all copies of the software and related documentation, and (ii) the names of
11  * Sam Leffler and Silicon Graphics may not be used in any advertising or
12  * publicity relating to the software without the specific, prior written
13  * permission of Sam Leffler and Silicon Graphics.
14  *
15  * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
16  * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
17  * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
18  *
19  * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
20  * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
21  * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
22  * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
23  * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
24  * OF THIS SOFTWARE.
25  */
26 
27 /*
28  * TIFF Library ATARI-specific Routines.
29  */
30 #include "tiffiop.h"
31 #if defined(__TURBOC__)
32 #include <tos.h>
33 #include <stdio.h>
34 #else
35 #include <osbind.h>
36 #include <fcntl.h>
37 #endif
38 
39 #ifndef O_ACCMODE
40 #define O_ACCMODE 3
41 #endif
42 
43 #include <errno.h>
44 
45 #define AEFILNF -33
46 
47 static tsize_t
48 _tiffReadProc(thandle_t fd, tdata_t buf, tsize_t size)
49 {
50  long r;
51 
52  r = Fread((int) fd, size, buf);
53  if (r < 0) {
54  errno = (int)-r;
55  r = -1;
56  }
57  return r;
58 }
59 
60 static tsize_t
61 _tiffWriteProc(thandle_t fd, tdata_t buf, tsize_t size)
62 {
63  long r;
64 
65  r = Fwrite((int) fd, size, buf);
66  if (r < 0) {
67  errno = (int)-r;
68  r = -1;
69  }
70  return r;
71 }
72 
73 static toff_t
74 _tiffSeekProc(thandle_t fd, off_t off, int whence)
75 {
76  char buf[256];
77  long current_off, expected_off, new_off;
78 
79  if (whence == SEEK_END || off <= 0)
80  return Fseek(off, (int) fd, whence);
81  current_off = Fseek(0, (int) fd, SEEK_CUR); /* find out where we are */
82  if (whence == SEEK_SET)
83  expected_off = off;
84  else
85  expected_off = off + current_off;
86  new_off = Fseek(off, (int) fd, whence);
87  if (new_off == expected_off)
88  return new_off;
89  /* otherwise extend file -- zero filling the hole */
90  if (new_off < 0) /* error? */
91  new_off = Fseek(0, (int) fd, SEEK_END); /* go to eof */
92  _TIFFmemset(buf, 0, sizeof(buf));
93  while (expected_off > new_off) {
94  off = expected_off - new_off;
95  if (off > sizeof(buf))
96  off = sizeof(buf);
97  if ((current_off = Fwrite((int) fd, off, buf)) != off)
98  return (current_off > 0) ?
99  new_off + current_off : new_off;
100  new_off += off;
101  }
102  return new_off;
103 }
104 
105 static int
106 _tiffCloseProc(thandle_t fd)
107 {
108  long r;
109 
110  r = Fclose((int) fd);
111  if (r < 0) {
112  errno = (int)-r;
113  r = -1;
114  }
115  return (int)r;
116 }
117 
118 static toff_t
119 _tiffSizeProc(thandle_t fd)
120 {
121  long pos, eof;
122 
123  pos = Fseek(0, (int) fd, SEEK_CUR);
124  eof = Fseek(0, (int) fd, SEEK_END);
125  Fseek(pos, (int) fd, SEEK_SET);
126  return eof;
127 }
128 
129 static int
130 _tiffMapProc(thandle_t fd, tdata_t* pbase, toff_t* psize)
131 {
132  return (0);
133 }
134 
135 static void
136 _tiffUnmapProc(thandle_t fd, tdata_t base, toff_t size)
137 {
138 }
139 
140 /*
141 * Open a TIFF file descriptor for read/writing.
142 */
143 TIFF*
144 TIFFFdOpen(int fd, const char* name, const char* mode)
145 {
146  TIFF* tif;
147 
148  tif = TIFFClientOpen(name, mode,
149  (thandle_t) fd,
150  _tiffReadProc, _tiffWriteProc, _tiffSeekProc, _tiffCloseProc,
151  _tiffSizeProc, _tiffMapProc, _tiffUnmapProc);
152  if (tif)
153  tif->tif_fd = fd;
154  return (tif);
155 }
156 
157 /*
158 * Open a TIFF file for read/writing.
159 */
160 TIFF*
161 TIFFOpen(const char* name, const char* mode)
162 {
163  static const char module[] = "TIFFOpen";
164  int m;
165  long fd;
166 
167  m = _TIFFgetMode(mode, module);
168  if (m == -1)
169  return ((TIFF*)0);
170  if (m & O_TRUNC) {
171  fd = Fcreate(name, 0);
172  } else {
173  fd = Fopen(name, m & O_ACCMODE);
174  if (fd == AEFILNF && m & O_CREAT)
175  fd = Fcreate(name, 0);
176  }
177  if (fd < 0)
178  errno = (int)fd;
179  if (fd < 0) {
180  TIFFErrorExt(0, module, "%s: Cannot open", name);
181  return ((TIFF*)0);
182  }
183  return (TIFFFdOpen(fd, name, mode));
184 }
185 
186 #include <stdlib.h>
187 
188 tdata_t
190 {
191  return (malloc((size_t) s));
192 }
193 
194 void
196 {
197  free(p);
198 }
199 
200 tdata_t
202 {
203  return (realloc(p, (size_t) s));
204 }
205 
206 void
207 _TIFFmemset(tdata_t p, int v, size_t c)
208 {
209  memset(p, v, (size_t) c);
210 }
211 
212 void
213 _TIFFmemcpy(tdata_t d, const tdata_t s, size_t c)
214 {
215  memcpy(d, s, (size_t) c);
216 }
217 
218 int
219 _TIFFmemcmp(const tdata_t p1, const tdata_t p2, tsize_t c)
220 {
221  return (memcmp(p1, p2, (size_t) c));
222 }
223 
224 static void
225 atariWarningHandler(const char* module, const char* fmt, va_list ap)
226 {
227  if (module != NULL)
228  fprintf(stderr, "%s: ", module);
229  fprintf(stderr, "Warning, ");
230  vfprintf(stderr, fmt, ap);
231  fprintf(stderr, ".\n");
232 }
233 TIFFErrorHandler _TIFFwarningHandler = atariWarningHandler;
234 
235 static void
236 atariErrorHandler(const char* module, const char* fmt, va_list ap)
237 {
238  if (module != NULL)
239  fprintf(stderr, "%s: ", module);
240  vfprintf(stderr, fmt, ap);
241  fprintf(stderr, ".\n");
242 }
int32 tsize_t
Definition: tiffio.h:66
void * tdata_t
Definition: tiffio.h:67
GLfloat GLfloat p
#define NULL
Definition: ftobjs.h:61
TIFFErrorHandler _TIFFerrorHandler
Definition: tif_atari.c:243
char * malloc()
void(* TIFFErrorHandler)(const char *, const char *, va_list)
Definition: tiffio.h:259
#define SEEK_END
Definition: zconf.h:251
Definition: tiffiop.h:95
int tif_fd
Definition: tiffiop.h:97
GLenum GLuint GLenum GLsizei const GLchar * buf
#define SEEK_CUR
Definition: zconf.h:250
TIFF * TIFFClientOpen(const char *name, const char *mode, thandle_t clientdata, TIFFReadWriteProc readproc, TIFFReadWriteProc writeproc, TIFFSeekProc seekproc, TIFFCloseProc closeproc, TIFFSizeProc sizeproc, TIFFMapFileProc mapproc, TIFFUnmapFileProc unmapproc)
Definition: tif_open.c:141
#define O_ACCMODE
Definition: tif_atari.c:40
TIFFErrorHandler _TIFFwarningHandler
Definition: tif_atari.c:233
int _TIFFmemcmp(const tdata_t p1, const tdata_t p2, tsize_t c)
Definition: tif_atari.c:219
GLenum mode
const GLdouble * v
GLdouble GLdouble GLdouble r
const GLubyte * c
int free()
tdata_t _TIFFrealloc(tdata_t p, tsize_t s)
Definition: tif_atari.c:201
void TIFFErrorExt(thandle_t fd, const char *module, const char *fmt,...)
Definition: tif_error.c:63
const GLfloat * m
TIFF * TIFFOpen(const char *name, const char *mode)
Definition: tif_atari.c:161
tdata_t _TIFFmalloc(tsize_t s)
Definition: tif_atari.c:189
GLuint const GLchar * name
void _TIFFmemset(tdata_t p, int v, size_t c)
Definition: tif_atari.c:207
void _TIFFmemcpy(tdata_t d, const tdata_t s, size_t c)
Definition: tif_atari.c:213
typedef int
Definition: png.h:978
int _TIFFgetMode(const char *mode, const char *module)
Definition: tif_open.c:117
uint32 toff_t
Definition: tiffio.h:68
GLdouble s
TIFF * TIFFFdOpen(int fd, const char *name, const char *mode)
Definition: tif_atari.c:144
#define AEFILNF
Definition: tif_atari.c:45
GLsizeiptr size
void _TIFFfree(tdata_t p)
Definition: tif_atari.c:195
void * thandle_t
Definition: tiffio.h:96
#define SEEK_SET
Definition: zconf.h:249