Tesseract  3.02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
imgtiff.h File Reference
#include "host.h"

Go to the source code of this file.

Functions

int CountTiffPages (FILE *fp)
 

Function Documentation

int CountTiffPages ( FILE *  fp)

Definition at line 80 of file imgtiff.cpp.

80  {
81  if (fp == NULL) return 0;
82  // Read header
83  inT16 filetype = 0;
84  if (fread(&filetype, sizeof(filetype), 1, fp) != 1 ||
85  (filetype != INTEL && filetype != MOTO)) {
86  return 0;
87  }
88  fseek(fp, 4L, SEEK_SET);
89  int npages = 0;
90  do {
91  inT32 start; // Start of tiff directory.
92  if (fread(&start, sizeof(start), 1, fp) != 1) {
93  return npages;
94  }
95  if (filetype != __NATIVE__)
96  ReverseN(&start, sizeof(start));
97  if (start <= 0) {
98  return npages;
99  }
100  fseek(fp, start, SEEK_SET);
101  inT16 entries; // No of tiff entries.
102  if (fread(&entries, sizeof(entries), 1, fp) != 1) {
103  return npages;
104  }
105  if (filetype != __NATIVE__)
106  ReverseN(&entries, sizeof(entries));
107  // Skip the tags and get to the next start.
108  fseek(fp, entries * sizeof(TIFFENTRY), SEEK_CUR);
109  ++npages;
110  } while (1);
111  return 0;
112 }
#define __NATIVE__
Definition: host.h:92
void ReverseN(void *ptr, int num_bytes)
Definition: helpers.h:126
#define MOTO
Definition: imgtiff.cpp:37
#define NULL
Definition: host.h:144
int inT32
Definition: host.h:102
short inT16
Definition: host.h:100
#define INTEL
Definition: imgtiff.cpp:36