#include "OCR.h"
#include "ChipMonkUtilities.h"

#ifdef __USE_SERVER_OCR__

typedef struct                   /*single character */
{
  unsigned short char_code;              /*character itself */
  short left;                    /*of char (-1) */
  short right;                   /*of char (-1) */
  short top;                     /*of char (-1) */
  short bottom;                  /*of char (-1) */
  short font_index;              /*what font (0) */
  unsigned char confidence;              /*0=perfect, 100=reject (0/100) */
  unsigned char point_size;              /*of char, 72=i inch, (10) */
  char blanks;                   /*no of spaces before this char (1) */
  unsigned char formatting;              /*char formatting (0) */
} EANYCODE_CHAR;                 /*single character */




bool AddToTextPage(int nCount, const EANYCODE_CHAR *pChars, COcrTextPage & textPage){
	if(nCount < 1) {
		return false;
	}
	textPage.AddRegion(CRect(0, 0, 0, 0));
	textPage.AddLineToLastRegion(CRect(0, 0, 0, 0));
	textPage.AddWordToLastLine(CRect(0, 0, 0, 0));
	int nRight = 0;
	UINT nFeatures(0);
	for (int i = 0; i < nCount; ++i) {
		const EANYCODE_CHAR* ch = pChars + i;
		if(ch->right < nRight) {
			textPage.AddLineToLastRegion(CRect(0, 0, 0, 0));
			textPage.AddWordToLastLine(CRect(0, 0, 0, 0));
		}
		else if(ch->blanks > 0) {
			textPage.AddWordToLastLine(CRect(0, 0, 0, 0));
		}
		textPage.AddCharacterToTheLastWord(ch->char_code, 
				CRect(ch->left, ch->top, ch->right, ch->bottom),
				ch->confidence,
				nFeatures);
		nRight = ch->right;
	}
	return true;
}


#endif

COCR::COCR()
{
}

COCR::~COCR()
{
}

BOOL COCR::Init() {
	return m_GoogleOcr.Init() == true;
}

BOOL COCR::Recognize(UCHAR* imgBuffer, int nWidth, int nHeight, COcrTextPage& textPage, bool bDegraded) {
	return m_GoogleOcr.Recognize(imgBuffer, nWidth, nHeight,
		textPage)
		== true;
}
