Tesseract  3.02
tesseract-ocr/image/imgtiff.cpp File Reference
#include "mfcpch.h"
#include <stdio.h>
#include "imgtiff.h"
#include "helpers.h"

Go to the source code of this file.

Classes

struct  TIFFENTRY

Defines

#define INTEL   0x4949
#define MOTO   0x4d4d
#define ENTRIES   19
#define START   8

Functions

int CountTiffPages (FILE *fp)

Define Documentation

#define ENTRIES   19

Definition at line 64 of file imgtiff.cpp.

#define INTEL   0x4949

Definition at line 36 of file imgtiff.cpp.

#define MOTO   0x4d4d

Definition at line 37 of file imgtiff.cpp.

#define START   8

Definition at line 65 of file imgtiff.cpp.


Function Documentation

int CountTiffPages ( FILE *  fp)

Definition at line 80 of file imgtiff.cpp.

                             {
  if (fp == NULL) return 0;
  // Read header
  inT16 filetype = 0;
  if (fread(&filetype, sizeof(filetype), 1, fp) != 1 ||
      (filetype != INTEL && filetype != MOTO)) {
    return 0;
  }
  fseek(fp, 4L, SEEK_SET);
  int npages = 0;
  do {
    inT32 start;                   // Start of tiff directory.
    if (fread(&start, sizeof(start), 1, fp) != 1) {
      return npages;
    }
    if (filetype != __NATIVE__)
      ReverseN(&start, sizeof(start));
    if (start <= 0) {
      return npages;
    }
    fseek(fp, start, SEEK_SET);
    inT16 entries;                 // No of tiff entries.
    if (fread(&entries, sizeof(entries), 1, fp) != 1) {
      return npages;
    }
    if (filetype != __NATIVE__)
      ReverseN(&entries, sizeof(entries));
    // Skip the tags and get to the next start.
    fseek(fp, entries * sizeof(TIFFENTRY), SEEK_CUR);
    ++npages;
  } while (1);
  return 0;
}