Esempio n. 1
0
bool TessdataManager::Init(const char *data_file_name, int debug_level) {
  int i;
  debug_level_ = debug_level;
  data_file_ = fopen(data_file_name, "rb");
  if (data_file_ == NULL) {
    tprintf("Error opening data file %s\n", data_file_name);
    tprintf("Please make sure the TESSDATA_PREFIX environment variable is set "
            "to the parent directory of your \"tessdata\" directory.\n");
    return false;
  }
  fread(&actual_tessdata_num_entries_, sizeof(inT32), 1, data_file_);
  swap_ = (actual_tessdata_num_entries_ > kMaxNumTessdataEntries);
  if (swap_) {
    actual_tessdata_num_entries_ = reverse32(actual_tessdata_num_entries_);
  }
  ASSERT_HOST(actual_tessdata_num_entries_ <= TESSDATA_NUM_ENTRIES);
  fread(offset_table_, sizeof(inT64),
        actual_tessdata_num_entries_, data_file_);
  if (swap_) {
    for (i = 0 ; i < actual_tessdata_num_entries_; ++i) {
      offset_table_[i] = reverse64(offset_table_[i]);
    }
  }
  if (debug_level_) {
    tprintf("TessdataManager loaded %d types of tesseract data files.\n",
            actual_tessdata_num_entries_);
    for (i = 0; i < actual_tessdata_num_entries_; ++i) {
      tprintf("Offset for type %d is %lld\n", i, offset_table_[i]);
    }
  }
  return true;
}
Esempio n. 2
0
bool TessdataManager::Init(const char *data_file_name, int debug_level) {
  int i;
  debug_level_ = debug_level;
  data_file_ = fopen(data_file_name, "rb");
  if (data_file_ == NULL) {
// WILLUS MOD:  Insert "if (debug_level_)" line below to avoid printing error msg.
    if (debug_level_)
        tprintf("Error opening data file %s\n", data_file_name);
    return false;
  }
  fread(&actual_tessdata_num_entries_, sizeof(inT32), 1, data_file_);
  bool swap = (actual_tessdata_num_entries_ > kMaxNumTessdataEntries);
  if (swap) {
    actual_tessdata_num_entries_ = reverse32(actual_tessdata_num_entries_);
  }
  ASSERT_HOST(actual_tessdata_num_entries_ <= TESSDATA_NUM_ENTRIES);
  fread(offset_table_, sizeof(inT64),
        actual_tessdata_num_entries_, data_file_);
  if (swap) {
    for (i = 0 ; i < actual_tessdata_num_entries_; ++i) {
      offset_table_[i] = reverse64(offset_table_[i]);
    }
  }
  if (debug_level_) {
    tprintf("TessdataManager loaded %d types of tesseract data files.\n",
            actual_tessdata_num_entries_);
    for (i = 0; i < actual_tessdata_num_entries_; ++i) {
      tprintf("Offset for type %d is %lld\n", i, offset_table_[i]);
    }
  }
  return true;
}
Esempio n. 3
0
void MessageBlock::reverseBlock()
{
  #if BYTE_ORDER == LITTLE_ENDIAN
  unsigned int i;
  for (i=0; i<16; ++i)
  {
    reverse64(words[i], words[i]);
  }
  #endif
}
Esempio n. 4
0
bool PMSource::getNextMessageBlock(MessageBlock& mBlock)
{
  std::streamsize bytesRead = 0;
  switch (m_Status)
  {
    case psUnpadded:
         m_BufStream.read((char*) &(mBlock.words[0]), 64);
         bytesRead = m_BufStream.gcount();
         if (bytesRead==64)
         {
           m_BitsRead += 512;
           mBlock.reverseBlock();
           return true;
         }
         //not full block read
         m_BitsRead += (bytesRead * 8);
         //close file, we are done here with reading from file anyway
         //m_BufStream.close(); // no close, since this will take care of itself in destructor
         //add 1-bit (start of message padding)
         ((uint8_t*) &(mBlock.words[0]))[bytesRead] = 0x80;
         //zero out rest of message block
         memset(&(((uint8_t*) &(mBlock.words[0]))[bytesRead+1]), 0, 64 - (bytesRead+1));
         //pad size value in there, too, if possible
         if (bytesRead+1<=56)
         {
           #if BYTE_ORDER == LITTLE_ENDIAN
           reverse64(m_BitsRead, m_BitsRead);
           #endif
           memcpy(&(mBlock.words[14]), &m_BitsRead, 8);
           m_Status = psPaddedAndAllRead;
           mBlock.reverseBlock();
           return true;
         }
         m_Status = psPadded1024And512Read;
         mBlock.reverseBlock();
         return true;
         break;
    case psPadded1024And512Read:
         //fill all with zeros (padding)
         memset(&(mBlock.words[0]), 0, 64);
         //pad size value in there, too
         #if BYTE_ORDER == LITTLE_ENDIAN
         reverse64(m_BitsRead, m_BitsRead);
         #endif
         memcpy(&(mBlock.words[14]), &m_BitsRead, 8);
         m_Status = psPaddedAndAllRead;
         mBlock.reverseBlock();
         return true;
         break;
    case psPaddedAndAllRead:
         return false;
         break;
    case psPadded512:
    case psPadded1024:
         //We should never get to this point!
         throw std::logic_error("PMSource::getNextMessageBlock(): Code execution should never get to this point!");
         return false;
         break;
  }//swi
  //We should never get to this point either!
  throw std::logic_error("PMSource::getNextMessageBlock(): Code execution should never get to this point either!");
  return false;
}