ReactOS 0.4.16-dev-2574-g474348f
tif_stream.cxx File Reference
#include "tiffiop.h"
#include <iostream>
Include dependency graph for tif_stream.cxx:

Go to the source code of this file.

Classes

struct  tiffis_data
 
struct  tiffos_data
 

Functions

static tmsize_t _tiffosReadProc (thandle_t, void *, tmsize_t)
 
static tmsize_t _tiffisReadProc (thandle_t fd, void *buf, tmsize_t size)
 
static tmsize_t _tiffosWriteProc (thandle_t fd, void *buf, tmsize_t size)
 
static tmsize_t _tiffisWriteProc (thandle_t, void *, tmsize_t)
 
static uint64_t _tiffosSeekProc (thandle_t fd, uint64_t off, int whence)
 
static uint64_t _tiffisSeekProc (thandle_t fd, uint64_t off, int whence)
 
static uint64_t _tiffosSizeProc (thandle_t fd)
 
static uint64_t _tiffisSizeProc (thandle_t fd)
 
static int _tiffosCloseProc (thandle_t fd)
 
static int _tiffisCloseProc (thandle_t fd)
 
static int _tiffDummyMapProcCxx (thandle_t, void **base, toff_t *size)
 
static void _tiffDummyUnmapProcCxx (thandle_t, void *base, toff_t size)
 
static TIFF_tiffStreamOpen (const char *name, const char *mode, void *fd)
 
TIFFTIFFStreamOpen (const char *name, ostream *os)
 
TIFFTIFFStreamOpen (const char *name, istream *is)
 

Function Documentation

◆ _tiffDummyMapProcCxx()

static int _tiffDummyMapProcCxx ( thandle_t  ,
void **  base,
toff_t size 
)
static

Definition at line 327 of file tif_stream.cxx.

328 {
329 (void)base;
330 (void)size;
331 return (0);
332 }
GLsizeiptr size
Definition: glext.h:5919

Referenced by _tiffStreamOpen().

◆ _tiffDummyUnmapProcCxx()

static void _tiffDummyUnmapProcCxx ( thandle_t  ,
void base,
toff_t  size 
)
static

Definition at line 334 of file tif_stream.cxx.

335 {
336 (void)base;
337 (void)size;
338 }

Referenced by _tiffStreamOpen().

◆ _tiffisCloseProc()

static int _tiffisCloseProc ( thandle_t  fd)
static

Definition at line 320 of file tif_stream.cxx.

321 {
322 // Our stream was not allocated by us, so it shouldn't be closed by us.
323 delete reinterpret_cast<tiffis_data *>(fd);
324 return 0;
325 }
static int fd
Definition: io.c:51

Referenced by _tiffStreamOpen().

◆ _tiffisReadProc()

static tmsize_t _tiffisReadProc ( thandle_t  fd,
void buf,
tmsize_t  size 
)
static

Definition at line 108 of file tif_stream.cxx.

109 {
110 tiffis_data *data = reinterpret_cast<tiffis_data *>(fd);
111
112 // Verify that type does not overflow.
113 streamsize request_size = size;
114 if (static_cast<tmsize_t>(request_size) != size)
115 return static_cast<tmsize_t>(-1);
116
117 data->stream->read((char *)buf, request_size);
118
119 return static_cast<tmsize_t>(data->stream->gcount());
120 }
ptrdiff_t streamsize
Definition: char_traits.h:81
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
TIFF_SSIZE_T tmsize_t
Definition: tiffio.h:67

Referenced by _tiffStreamOpen().

◆ _tiffisSeekProc()

static uint64_t _tiffisSeekProc ( thandle_t  fd,
uint64_t  off,
int  whence 
)
static

Definition at line 241 of file tif_stream.cxx.

242 {
243 tiffis_data *data = reinterpret_cast<tiffis_data *>(fd);
244
245 switch (whence)
246 {
247 case SEEK_SET:
248 {
249 // Compute 64-bit offset
250 uint64_t new_offset =
251 static_cast<uint64_t>(data->start_pos) + off;
252
253 // Verify that value does not overflow
254 ios::off_type offset = static_cast<ios::off_type>(new_offset);
255 if (static_cast<uint64_t>(offset) != new_offset)
256 return static_cast<uint64_t>(-1);
257
258 data->stream->seekg(offset, ios::beg);
259 break;
260 }
261 case SEEK_CUR:
262 {
263 // Verify that value does not overflow
264 ios::off_type offset = static_cast<ios::off_type>(off);
265 if (static_cast<uint64_t>(offset) != off)
266 return static_cast<uint64_t>(-1);
267
268 data->stream->seekg(offset, ios::cur);
269 break;
270 }
271 case SEEK_END:
272 {
273 // Verify that value does not overflow
274 ios::off_type offset = static_cast<ios::off_type>(off);
275 if (static_cast<uint64_t>(offset) != off)
276 return static_cast<uint64_t>(-1);
277
278 data->stream->seekg(offset, ios::end);
279 break;
280 }
281 }
282
283 return (uint64_t)(data->stream->tellg() - data->start_pos);
284 }
#define SEEK_END
Definition: cabinet.c:29
_Traits::off_type off_type
Definition: _ios.h:54
UINT64 uint64_t
Definition: types.h:77
#define SEEK_CUR
Definition: stdio.h:44
GLintptr offset
Definition: glext.h:5920
#define SEEK_SET
Definition: jmemansi.c:26

Referenced by _tiffStreamOpen().

◆ _tiffisSizeProc()

static uint64_t _tiffisSizeProc ( thandle_t  fd)
static

Definition at line 300 of file tif_stream.cxx.

301 {
302 tiffis_data *data = reinterpret_cast<tiffis_data *>(fd);
303 ios::pos_type pos = data->stream->tellg();
305
306 data->stream->seekg(0, ios::end);
307 len = data->stream->tellg();
308 data->stream->seekg(pos);
309
310 return (uint64_t)len;
311 }
_Traits::pos_type pos_type
Definition: _ios.h:53
GLenum GLsizei len
Definition: glext.h:6722

Referenced by _tiffStreamOpen().

◆ _tiffisWriteProc()

static tmsize_t _tiffisWriteProc ( thandle_t  ,
void ,
tmsize_t   
)
static

Definition at line 138 of file tif_stream.cxx.

138{ return 0; }

Referenced by _tiffStreamOpen().

◆ _tiffosCloseProc()

static int _tiffosCloseProc ( thandle_t  fd)
static

Definition at line 313 of file tif_stream.cxx.

314 {
315 // Our stream was not allocated by us, so it shouldn't be closed by us.
316 delete reinterpret_cast<tiffos_data *>(fd);
317 return 0;
318 }

Referenced by _tiffStreamOpen().

◆ _tiffosReadProc()

static tmsize_t _tiffosReadProc ( thandle_t  ,
void ,
tmsize_t   
)
static

Definition at line 106 of file tif_stream.cxx.

106{ return 0; }

Referenced by _tiffStreamOpen().

◆ _tiffosSeekProc()

static uint64_t _tiffosSeekProc ( thandle_t  fd,
uint64_t  off,
int  whence 
)
static

Definition at line 140 of file tif_stream.cxx.

141 {
142 tiffos_data *data = reinterpret_cast<tiffos_data *>(fd);
143 ostream *os = data->stream;
144
145 // if the stream has already failed, don't do anything
146 if (os->fail())
147 return static_cast<uint64_t>(-1);
148
149 switch (whence)
150 {
151 case SEEK_SET:
152 {
153 // Compute 64-bit offset
154 uint64_t new_offset =
155 static_cast<uint64_t>(data->start_pos) + off;
156
157 // Verify that value does not overflow
158 ios::off_type offset = static_cast<ios::off_type>(new_offset);
159 if (static_cast<uint64_t>(offset) != new_offset)
160 return static_cast<uint64_t>(-1);
161
162 os->seekp(offset, ios::beg);
163 break;
164 }
165 case SEEK_CUR:
166 {
167 // Verify that value does not overflow
168 ios::off_type offset = static_cast<ios::off_type>(off);
169 if (static_cast<uint64_t>(offset) != off)
170 return static_cast<uint64_t>(-1);
171
172 os->seekp(offset, ios::cur);
173 break;
174 }
175 case SEEK_END:
176 {
177 // Verify that value does not overflow
178 ios::off_type offset = static_cast<ios::off_type>(off);
179 if (static_cast<uint64_t>(offset) != off)
180 return static_cast<uint64_t>(-1);
181
182 os->seekp(offset, ios::end);
183 break;
184 }
185 }
186
187 // Attempt to workaround problems with seeking past the end of the
188 // stream. ofstream doesn't have a problem with this but
189 // ostrstream/ostringstream does. In that situation, add intermediate
190 // '\0' characters.
191 if (os->fail())
192 {
193 ios::iostate old_state;
195
196 old_state = os->rdstate();
197 // reset the fail bit or else tellp() won't work below
198 os->clear(os->rdstate() & ~ios::failbit);
199 switch (whence)
200 {
201 case SEEK_SET:
202 default:
203 origin = data->start_pos;
204 break;
205 case SEEK_CUR:
206 origin = os->tellp();
207 break;
208 case SEEK_END:
209 os->seekp(0, ios::end);
210 origin = os->tellp();
211 break;
212 }
213 // restore original stream state
214 os->clear(old_state);
215
216 // only do something if desired seek position is valid
217 if ((static_cast<uint64_t>(origin) + off) >
218 static_cast<uint64_t>(data->start_pos))
219 {
220 uint64_t num_fill;
221
222 // clear the fail bit
223 os->clear(os->rdstate() & ~ios::failbit);
224
225 // extend the stream to the expected size
226 os->seekp(0, ios::end);
227 num_fill = (static_cast<uint64_t>(origin)) + off - os->tellp();
228 for (uint64_t i = 0; i < num_fill; i++)
229 os->put('\0');
230
231 // retry the seek
232 os->seekp(static_cast<ios::off_type>(
233 static_cast<uint64_t>(origin) + off),
234 ios::beg);
235 }
236 }
237
238 return static_cast<uint64_t>(os->tellp());
239 }
void clear(iostate __state=goodbit)
Definition: _ios.h:91
_Self & seekp(pos_type __pos)
Definition: _ostream.h:147
pos_type tellp()
Definition: _ostream.h:141
_Self & put(char_type __c)
Definition: _ostream.c:408
iostate rdstate() const
Definition: _ios_base.h:170
bool fail() const
Definition: _ios_base.h:174
int iostate
Definition: _ios_base.h:58
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
voidpf uLong int origin
Definition: ioapi.h:144

Referenced by _tiffStreamOpen().

◆ _tiffosSizeProc()

static uint64_t _tiffosSizeProc ( thandle_t  fd)
static

Definition at line 286 of file tif_stream.cxx.

287 {
288 tiffos_data *data = reinterpret_cast<tiffos_data *>(fd);
289 ostream *os = data->stream;
290 ios::pos_type pos = os->tellp();
292
293 os->seekp(0, ios::end);
294 len = os->tellp();
295 os->seekp(pos);
296
297 return (uint64_t)len;
298 }

Referenced by _tiffStreamOpen().

◆ _tiffosWriteProc()

static tmsize_t _tiffosWriteProc ( thandle_t  fd,
void buf,
tmsize_t  size 
)
static

Definition at line 122 of file tif_stream.cxx.

123 {
124 tiffos_data *data = reinterpret_cast<tiffos_data *>(fd);
125 ostream *os = data->stream;
126 ios::pos_type pos = os->tellp();
127
128 // Verify that type does not overflow.
129 streamsize request_size = size;
130 if (static_cast<tmsize_t>(request_size) != size)
131 return static_cast<tmsize_t>(-1);
132
133 os->write(reinterpret_cast<const char *>(buf), request_size);
134
135 return static_cast<tmsize_t>(os->tellp() - pos);
136 }
_Self & write(const char_type *__s, streamsize __n)
Definition: _ostream.c:430

Referenced by _tiffStreamOpen().

◆ _tiffStreamOpen()

static TIFF * _tiffStreamOpen ( const char name,
const char mode,
void fd 
)
static

Definition at line 343 of file tif_stream.cxx.

344 {
345 TIFF *tif;
346
347 if (strchr(mode, 'w'))
348 {
350 data->stream = reinterpret_cast<ostream *>(fd);
351 data->start_pos = data->stream->tellp();
352
353 // Open for writing.
354 tif = TIFFClientOpen(
355 name, mode, reinterpret_cast<thandle_t>(data), _tiffosReadProc,
358 if (!tif)
359 {
360 delete data;
361 }
362 }
363 else
364 {
366 data->stream = reinterpret_cast<istream *>(fd);
367 data->start_pos = data->stream->tellg();
368 // Open for reading.
369 tif = TIFFClientOpen(
370 name, mode, reinterpret_cast<thandle_t>(data), _tiffisReadProc,
373 if (!tif)
374 {
375 delete data;
376 }
377 }
378
379 return (tif);
380 }
pos_type tellg()
Definition: _istream.c:494
_ACRTIMP char *__cdecl strchr(const char *, int)
Definition: string.c:3286
GLenum mode
Definition: glext.h:6217
Definition: name.c:39
Definition: tiffiop.h:113
istream * stream
Definition: tif_stream.cxx:96
ostream * stream
Definition: tif_stream.cxx:102
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:289
static int _tiffDummyMapProcCxx(thandle_t, void **base, toff_t *size)
Definition: tif_stream.cxx:327
static uint64_t _tiffisSeekProc(thandle_t fd, uint64_t off, int whence)
Definition: tif_stream.cxx:241
static int _tiffisCloseProc(thandle_t fd)
Definition: tif_stream.cxx:320
static uint64_t _tiffosSeekProc(thandle_t fd, uint64_t off, int whence)
Definition: tif_stream.cxx:140
static tmsize_t _tiffisWriteProc(thandle_t, void *, tmsize_t)
Definition: tif_stream.cxx:138
static uint64_t _tiffisSizeProc(thandle_t fd)
Definition: tif_stream.cxx:300
static tmsize_t _tiffosWriteProc(thandle_t fd, void *buf, tmsize_t size)
Definition: tif_stream.cxx:122
static tmsize_t _tiffisReadProc(thandle_t fd, void *buf, tmsize_t size)
Definition: tif_stream.cxx:108
static void _tiffDummyUnmapProcCxx(thandle_t, void *base, toff_t size)
Definition: tif_stream.cxx:334
static tmsize_t _tiffosReadProc(thandle_t, void *, tmsize_t)
Definition: tif_stream.cxx:106
static int _tiffosCloseProc(thandle_t fd)
Definition: tif_stream.cxx:313
static uint64_t _tiffosSizeProc(thandle_t fd)
Definition: tif_stream.cxx:286

Referenced by TIFFStreamOpen().

◆ TIFFStreamOpen() [1/2]

TIFF * TIFFStreamOpen ( const char name,
istream is 
)

Definition at line 400 of file tif_stream.cxx.

401{
402 // NB: We don't support mapped files with streams so add 'm'
403 return _tiffStreamOpen(name, "rm", is);
404}
static TIFF * _tiffStreamOpen(const char *name, const char *mode, void *fd)
Definition: tif_stream.cxx:343

◆ TIFFStreamOpen() [2/2]

TIFF * TIFFStreamOpen ( const char name,
ostream os 
)

Definition at line 384 of file tif_stream.cxx.

385{
386 // If os is either a ostrstream or ostringstream, and has no data
387 // written to it yet, then tellp() will return -1 which will break us.
388 // We workaround this by writing out a dummy character and
389 // then seek back to the beginning.
390 if (!os->fail() && static_cast<int>(os->tellp()) < 0)
391 {
392 *os << '\0';
393 os->seekp(0);
394 }
395
396 // NB: We don't support mapped files with streams so add 'm'
397 return _tiffStreamOpen(name, "wm", os);
398}