📄 tif_open.c
字号:
}
/*
* Setup the byte order handling.
*/
TIFFInitOrder(tif, tif->tif_header.tiff_magic, bigendian);
/*
* Setup default directory.
*/
if (!TIFFDefaultDirectory(tif))
goto bad;
tif->tif_diroff = 0;
tif->tif_dirlist = NULL;
tif->tif_dirnumber = 0;
return (tif);
}
/*
* Setup the byte order handling.
*/
if (tif->tif_header.tiff_magic != TIFF_BIGENDIAN &&
tif->tif_header.tiff_magic != TIFF_LITTLEENDIAN) {
TIFFError(name, "Not a TIFF file, bad magic number %d (0x%x)",
tif->tif_header.tiff_magic,
tif->tif_header.tiff_magic);
goto bad;
}
TIFFInitOrder(tif, tif->tif_header.tiff_magic, bigendian);
/*
* Swap header if required.
*/
if (tif->tif_flags & TIFF_SWAB) {
TIFFSwabShort(&tif->tif_header.tiff_version);
TIFFSwabLong(&tif->tif_header.tiff_diroff);
}
/*
* Now check version (if needed, it's been byte-swapped).
* Note that this isn't actually a version number, it's a
* magic number that doesn't change (stupid).
*/
if (tif->tif_header.tiff_version == TIFF_BIGTIFF_VERSION) {
TIFFError(name,
"This is a BigTIFF file. This format not supported\n"
"by this version of libtiff." );
goto bad;
}
if (tif->tif_header.tiff_version != TIFF_VERSION) {
TIFFError(name,
"Not a TIFF file, bad version number %d (0x%x)",
tif->tif_header.tiff_version,
tif->tif_header.tiff_version);
goto bad;
}
tif->tif_flags |= TIFF_MYBUFFER;
tif->tif_rawcp = tif->tif_rawdata = 0;
tif->tif_rawdatasize = 0;
/*
* Setup initial directory.
*/
switch (mode[0]) {
case 'r':
tif->tif_nextdiroff = tif->tif_header.tiff_diroff;
/*
* Try to use a memory-mapped file if the client
* has not explicitly suppressed usage with the
* 'm' flag in the open mode (see above).
*/
if ((tif->tif_flags & TIFF_MAPPED) &&
!TIFFMapFileContents(tif, (tdata_t*) &tif->tif_base, &tif->tif_size))
tif->tif_flags &= ~TIFF_MAPPED;
if (TIFFReadDirectory(tif)) {
tif->tif_rawcc = -1;
tif->tif_flags |= TIFF_BUFFERSETUP;
return (tif);
}
break;
case 'a':
/*
* New directories are automatically append
* to the end of the directory chain when they
* are written out (see TIFFWriteDirectory).
*/
if (!TIFFDefaultDirectory(tif))
goto bad;
return (tif);
}
bad:
tif->tif_mode = O_RDONLY; /* XXX avoid flush */
TIFFCleanup(tif);
bad2:
(void) (*closeproc)(clientdata);
return ((TIFF*)0);
}
/*
* Query functions to access private data.
*/
/*
* Return open file's name.
*/
const char *
TIFFFileName(TIFF* tif)
{
return (tif->tif_name);
}
/*
* Set the file name.
*/
const char *
TIFFSetFileName(TIFF* tif, const char *name)
{
const char* old_name = tif->tif_name;
tif->tif_name = (char *)name;
return (old_name);
}
/*
* Return open file's I/O descriptor.
*/
int
TIFFFileno(TIFF* tif)
{
return (tif->tif_fd);
}
/*
* Set open file's I/O descriptor, and return previous value.
*/
int
TIFFSetFileno(TIFF* tif, int fd)
{
int old_fd = tif->tif_fd;
tif->tif_fd = fd;
return old_fd;
}
/*
* Return open file's clientdata.
*/
thandle_t
TIFFClientdata(TIFF* tif)
{
return (tif->tif_clientdata);
}
/*
* Set open file's clientdata, and return previous value.
*/
thandle_t
TIFFSetClientdata(TIFF* tif, thandle_t newvalue)
{
thandle_t m = tif->tif_clientdata;
tif->tif_clientdata = newvalue;
return m;
}
/*
* Return read/write mode.
*/
int
TIFFGetMode(TIFF* tif)
{
return (tif->tif_mode);
}
/*
* Return read/write mode.
*/
int
TIFFSetMode(TIFF* tif, int mode)
{
int old_mode = tif->tif_mode;
tif->tif_mode = mode;
return (old_mode);
}
/*
* Return nonzero if file is organized in
* tiles; zero if organized as strips.
*/
int
TIFFIsTiled(TIFF* tif)
{
return (isTiled(tif));
}
/*
* Return current row being read/written.
*/
uint32
TIFFCurrentRow(TIFF* tif)
{
return (tif->tif_row);
}
/*
* Return index of the current directory.
*/
tdir_t
TIFFCurrentDirectory(TIFF* tif)
{
return (tif->tif_curdir);
}
/*
* Return current strip.
*/
tstrip_t
TIFFCurrentStrip(TIFF* tif)
{
return (tif->tif_curstrip);
}
/*
* Return current tile.
*/
ttile_t
TIFFCurrentTile(TIFF* tif)
{
return (tif->tif_curtile);
}
/*
* Return nonzero if the file has byte-swapped data.
*/
int
TIFFIsByteSwapped(TIFF* tif)
{
return ((tif->tif_flags & TIFF_SWAB) != 0);
}
/*
* Return nonzero if the data is returned up-sampled.
*/
int
TIFFIsUpSampled(TIFF* tif)
{
return (isUpSampled(tif));
}
/*
* Return nonzero if the data is returned in MSB-to-LSB bit order.
*/
int
TIFFIsMSB2LSB(TIFF* tif)
{
return (isFillOrder(tif, FILLORDER_MSB2LSB));
}
/*
* Return nonzero if given file was written in big-endian order.
*/
int
TIFFIsBigEndian(TIFF* tif)
{
return (tif->tif_header.tiff_magic == TIFF_BIGENDIAN);
}
/*
* Return pointer to file read method.
*/
TIFFReadWriteProc
TIFFGetReadProc(TIFF* tif)
{
return (tif->tif_readproc);
}
/*
* Return pointer to file write method.
*/
TIFFReadWriteProc
TIFFGetWriteProc(TIFF* tif)
{
return (tif->tif_writeproc);
}
/*
* Return pointer to file seek method.
*/
TIFFSeekProc
TIFFGetSeekProc(TIFF* tif)
{
return (tif->tif_seekproc);
}
/*
* Return pointer to file close method.
*/
TIFFCloseProc
TIFFGetCloseProc(TIFF* tif)
{
return (tif->tif_closeproc);
}
/*
* Return pointer to file size requesting method.
*/
TIFFSizeProc
TIFFGetSizeProc(TIFF* tif)
{
return (tif->tif_sizeproc);
}
/*
* Return pointer to memory mapping method.
*/
TIFFMapFileProc
TIFFGetMapFileProc(TIFF* tif)
{
return (tif->tif_mapproc);
}
/*
* Return pointer to memory unmapping method.
*/
TIFFUnmapFileProc
TIFFGetUnmapFileProc(TIFF* tif)
{
return (tif->tif_unmapproc);
}
/* vim: set ts=8 sts=8 sw=8 noet: */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -