home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Der Mediaplex Sampler - Die 6 von Plex
/
6_v_plex.zip
/
6_v_plex
/
DISK5
/
WIN_12
/
IDEPIX2.ZIP
/
TIFFACS.ZIP
/
READTAG.C
< prev
next >
Wrap
C/C++ Source or Header
|
1993-06-23
|
4KB
|
169 lines
/*-------------------------------------------------------
T I F F A C S : Unterstⁿtzungsroutinen fⁿr TIFF-Dateien
Ursprⁿnglich von Aldus, von mir auf dem
Walnut-Creek - Source-Code-ROM gefunden.
Der ursprⁿngliche Source ist TIFF 4.0 und
auch ansonsten ein ziemlicher Mⁿll.
Diese Version hat Funktionsprototypen und
ein paar Fehler weniger, aber im Grunde ist
sie auch ein ziemlicher Mⁿll.
Im Mircosoft System Journal 4/93 ist eine ganz
brauchbare TIF-Routine dabei, aber eben nicht PD
Bernd Herd
Rudolf Virchow Str. 8
6842 Bⁿrstadt
06206/79222
R E A D T A G : N÷tige Routinen um einen TAG-Eintrag
aus einer TIFF-Datei zu lesen
-------------------------------------------------------------*/
#include <io.h>
#include "tiff.h" // Header-Datei zur Verbindung mit Applikation
#include "tiffi.h" // Interne Header-Datei
/*-------------------------------------------------------------
read_tag : Daten eines TIFF-Tags lesen, anzahl der Bytes
je nach Datenformat...
Parameter: fhandle : Dateihandle der offenen TIF-Datei
fdtype : Subfile-Type
tagnum : TAG-Nummer
buffer : Ziel-Adresse fⁿr Daten
max_length : Gr÷▀e des Puffers in Bytes
ReturnVal: 0 : Tag nicht gefunden oder falscher Subfile
sonst : Anzahl gelesene EintrΣge (nicht : Bytes!)
-------------------------------------------------------------*/
SHORT read_tag( SHORT fhandle, // readtag.c
SHORT fdtype,
SHORT tagnum,
void far *ibuffer,
SHORT max_length)
{ LONGPTR buffer = (LONGPTR) ibuffer;
LONG ifd_offset = get_1st_ifd(fhandle);
LONG new_offset;
TIFF_DIR_ENTRY dirent;
SHORT entry_count;
LONG subfile_type;
/* go through IFD's ... stop at null IFD offset */
while(ifd_offset)
{
/* get pertinent IFD data */
if(access_ifd(fhandle, ifd_offset,
(TIFF_DIR_ENTRY far *)&dirent, &entry_count, &subfile_type,
&new_offset))
{
return(0);
}
/* match on subfile type? */
if(fdtype == subfile_type)
{
SHORT n = entry_count - 1;
/* go through each entry */
while(n-- > 0 && !read_dir(fhandle,
(TIFF_DIR_ENTRY far *)&dirent))
{
SHORT len;
/* only do it for the supplied tag number */
if(dirent.tag != tagnum)
{
continue;
}
/* get length of data to be copied */
len = type_length(dirent.type);
len *= (SHORT)dirent.length;
/* length overflow? */
if(len > max_length)
{
return(0);
}
if(len > LONG_SIZE)
{
/* read data into user's buffer */
if(lseek(fhandle, dirent.value_offset,
0) == (LONG)(-1))
{
return(0);
}
if(bigRead(fhandle, buffer,
(LONG)len) != (LONG)len)
{
return(0);
}
}
else
{
LONGPTR dp;
dp = (LONGPTR)&dirent.value_offset;
while(len-- > 0)
{
*buffer++ = *dp++;
}
}
/* we're done after reading one tag's worth */
return dirent.length;
}
/* matched subfile & unmatched tag => error */
return(0);
}
ifd_offset = new_offset;
}
return(0);
}
SHORT read_dirent(SHORT fhandle, SHORT fdtype, SHORT tagnum, TIFF_DIR_ENTRY far *dirent)
{
LONG ifd_offset = get_1st_ifd(fhandle);
LONG new_offset;
SHORT entry_count;
LONG subfile_type;
/* go through IFD's ... stop at null IFD offset */
while(ifd_offset)
{
/* get pertinent IFD data */
if(access_ifd(fhandle, ifd_offset, dirent, &entry_count,
&subfile_type, &new_offset))
{
return(0);
}
/* match on subfile type? */
if(fdtype == subfile_type)
{
SHORT n = entry_count - 1;
/* go through each entry */
while(n-- > 0 && !read_dir(fhandle, dirent))
{
/* only do it for the supplied tag number */
if(dirent->tag == tagnum)
{
return(1);
}
}
/* matched subfile & unmatched tag => error */
return(0);
}
ifd_offset = new_offset;
}
return(0);
}