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 / READFLD.C < prev    next >
C/C++ Source or Header  |  1993-06-22  |  2KB  |  103 lines

  1. #include "tiff.h"
  2. #include "tiffi.h"
  3. #include "io.h"
  4.  
  5. extern LONG bigRead();
  6. extern LONG get_1st_ifd();
  7. extern BOOL access_ifd();
  8. extern BOOL read_dir();
  9.  
  10. SHORT
  11. read_fields(fhandle, fdtype, buffer, max_length)
  12. SHORT fhandle;
  13. SHORT fdtype;
  14. LONGPTR buffer;
  15. LONG max_length;
  16. {
  17.     LONG         ifd_offset = get_1st_ifd(fhandle);
  18.     LONG         new_offset;
  19.     TIFF_DIR_ENTRY  dirent;
  20.     SHORT         entry_count;
  21.     LONG         subfile_type;
  22.  
  23.     /* go through IFD's ... stop at null IFD offset */
  24.     while(ifd_offset)
  25.     {
  26.         /* get pertinent IFD data */
  27.         if(access_ifd(fhandle, ifd_offset,
  28.           (TIFF_DIR_ENTRY far *)&dirent, &entry_count, &subfile_type,
  29.           &new_offset))
  30.         {
  31.             return(0);
  32.         }
  33.  
  34.         /* match on subfile type? */
  35.         if(fdtype == subfile_type)
  36.         {
  37.             SHORT n = entry_count - 1;
  38.             /* go through each entry */
  39.             while(n-- > 0 && !read_dir(fhandle,
  40.               (TIFF_DIR_ENTRY far *)&dirent))
  41.             {
  42.                 LONG tot_len;
  43.                 LONG len;
  44. debug("    tag %d, type %d, length %ld, offset %ld\n", dirent.tag,
  45.  dirent.type, dirent.length, dirent.value_offset);
  46.                 /* get length of data to be copied */
  47.                 len = (LONG)type_length(dirent.type);
  48.                 len *= dirent.length;
  49.                 tot_len = len + SHORT_SIZE + SHORT_SIZE;
  50.  
  51.                 /* length overflow? */
  52.                 max_length -= tot_len;
  53.                 if(max_length < 0)
  54.                 {
  55.                     return(0);
  56.                 }
  57.                 *((SHORT far *)buffer) = dirent.tag;
  58.                 buffer += SHORT_SIZE;
  59.                 *((SHORT far *)buffer) = LOWORD(len);
  60.                 buffer += SHORT_SIZE;
  61.                 if(len > LONG_SIZE)
  62.                 {
  63.                     LONG cur_pos = lseek(fhandle, 0L, 1);
  64.  
  65.                     /* read data into user's buffer */
  66.                     if(lseek(fhandle, dirent.value_offset,
  67.                       0) != dirent.value_offset)
  68.                     {
  69.                         return(0);
  70.                     }
  71.                     if(bigRead(fhandle, buffer, len) !=
  72.                       len)
  73.                     {
  74.                         return(0);
  75.                     }
  76.                     buffer += len;
  77.                     lseek(fhandle, cur_pos, 0);
  78.                 }
  79.                 else
  80.                 {
  81.                     LONGPTR dp =
  82.                       (LONGPTR)&(dirent.value_offset);
  83.                     while(len-- > 0)
  84.                     {
  85.                         *buffer++ = *dp++;
  86.                     }
  87.                 }
  88.             }
  89.  
  90.             /* if we bombed out early, error exit */
  91.             if(n > 0)
  92.             {
  93.                 return(0);
  94.             }
  95.  
  96.             /* since we matched, we can now go bye-bye */
  97.             return(entry_count);
  98.         }
  99.         ifd_offset = new_offset;
  100.     }
  101.     return(0);
  102. }
  103.