Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

243 lines
7.1 KiB

  1. /**************************************************************************\
  2. * FILE: zillatool.h
  3. *
  4. * Lists functions Zilla exports to its tools but nothing else.
  5. \**************************************************************************/
  6. #ifndef ZILLATOOL_H
  7. #define ZILLATOOL_H
  8. #include "runnet.h"
  9. #ifdef __cplusplus
  10. extern "C" {
  11. #endif
  12. // Version of primitive with x and y values stored in bytes, not nibbles.
  13. #pragma pack(1)
  14. typedef struct tagBIGPRIM
  15. {
  16. BYTE code; /* 0-15 stroke fpendown, 4 unused bits. */
  17. BYTE x1;
  18. BYTE x2;
  19. BYTE y1;
  20. BYTE y2;
  21. } BIGPRIM, *PBIGPRIM;
  22. #pragma pack()
  23. #ifdef ZTRAIN
  24. typedef struct tagTRAININFO
  25. {
  26. WORD wclass;
  27. BYTE rgfInfo;
  28. BYTE cstrokes;
  29. int chits; // How many times this guy appeared in the top10 correctly
  30. int cmishits; // How many times this guy appeared incorrectly top1
  31. int cattempts; // How many times this guy appeared in the top10 list
  32. float eHits; // How many times this guy appeared in the top10 correctly
  33. float eMishits; // How many times this guy appeared incorrectly top1
  34. float eAttempts; // How many times this guy appeared in the top10 list before the correct answer
  35. } TRAININFO;
  36. #endif
  37. typedef struct tagGEOMETRIC
  38. {
  39. BYTE x1:4; /* start x-coord */
  40. BYTE x2:4; /* end x */
  41. BYTE y1:4; /* start y-coord */
  42. BYTE y2:4; /* end y */
  43. } GEOMETRIC;
  44. #pragma pack(1)
  45. typedef struct tagPRIMITIVE
  46. {
  47. BYTE code;
  48. union
  49. {
  50. struct
  51. {
  52. BYTE x1:4; /* start x-coord */
  53. BYTE x2:4; /* end x */
  54. BYTE y1:4; /* start y-coord */
  55. BYTE y2:4; /* end y */
  56. };
  57. char rgch[2];
  58. };
  59. } PRIMITIVE, *PPRIMITIVE;
  60. #pragma pack()
  61. typedef struct tagPROTOHEADER
  62. {
  63. DWORD cprotoRom;
  64. WORD *rgdbcRom;
  65. BYTE *rgfeatRom;
  66. GEOMETRIC *rggeomRom;
  67. #ifdef ZTRAIN
  68. DWORD cprotoDynamic;
  69. WORD *rgdbcDynamic;
  70. PRIMITIVE *rgprimDynamic;
  71. TRAININFO **rgptraininfo;
  72. #endif // ZTRAIN
  73. } PROTOHEADER;
  74. typedef struct tagMATCH
  75. {
  76. SYM sym;
  77. WORD dist;
  78. #ifdef ZTRAIN
  79. TRAININFO *ptraininfo;
  80. #endif // ZTRAIN
  81. } MATCH;
  82. typedef struct tagPROTOTYPE
  83. {
  84. WORD dbc;
  85. GEOMETRIC *rggeom;
  86. BYTE *rgfeat;
  87. BOOL nybble;
  88. RECMASK recmask;
  89. #ifdef ZTRAIN
  90. PRIMITIVE *rgprim;
  91. TRAININFO *ptraininfo;
  92. #endif // ZTRAIN
  93. } PROTOTYPE;
  94. typedef struct tagBIGPROTOTYPE
  95. {
  96. WORD dbc;
  97. PBIGPRIM rgprim;
  98. ALC recmask;
  99. #ifdef ZTRAIN
  100. TRAININFO *ptraininfo;
  101. #endif // ZTRAIN
  102. } BIGPROTOTYPE;
  103. // Internal constants needed by the tools.
  104. #define CMATCHMAX 20
  105. #define CPRIM_DIFF 18 // number of different primitives
  106. #define CPRIMMAX 30 // max primitives per character.
  107. #define GEOM_DIST_MAX 900 // maximum geometric distance for 1 prim
  108. // Internal declerations needed by tools.
  109. typedef BYTE **COST_TABLE;
  110. // Featurize ink
  111. int ZillaFeaturize(GLYPH **glyph, BIGPRIM *rgprim, BYTE *pHoundFeat);
  112. // Globals to hold pointers to loaded data.
  113. extern PROTOHEADER mpcfeatproto[CPRIMMAX];
  114. extern int g_iCostTableSize;
  115. extern COST_TABLE g_ppCostTable;
  116. extern BYTE *pGeomCost;
  117. // Magic key the identifies the NN bin file
  118. #define ZILLA_HOUND_FILE_TYPE 0x31142253
  119. // Version information for file.
  120. #define ZILLA_HOUND_MIN_FILE_VERSION 0 // First version of code that can read this file
  121. #define ZILLA_HOUND_OLD_FILE_VERSION 0 // Oldest file version this code can read.
  122. #define ZILLA_HOUND_CUR_FILE_VERSION 0 // Current version of code.
  123. // Load info for Zilla-Hound
  124. typedef struct tagZILLA_HOUND_LOAD_INFO
  125. {
  126. LOAD_INFO info;
  127. LOCAL_NET net;
  128. int iNetSize;
  129. } ZILLA_HOUND_LOAD_INFO;
  130. // Feature count information for Zilla/Hound combiner net
  131. #define NUM_ZILLA_HOUND_ALTERNATES 4
  132. #define NUM_ZILLA_HOUND_FEATURES 9
  133. // Load the Zilla-Hound combining net.
  134. BOOL ZillaHoundLoadFile(wchar_t *wszPath);
  135. // Unload the Zilla-Hound combining net.
  136. BOOL ZillaHoundUnloadFile();
  137. // Load from a resource.
  138. BOOL ZillaHoundLoadRes(HINSTANCE hInst, int nResID, int nType);
  139. // Given Zilla results run Hound and combine the results.
  140. void ZillaHoundMatch(MATCH *pMatch, int cPrim, BYTE *pSampleVector, LOCRUN_INFO *pLocRunInfo);
  141. // Generate features used by Zilla/Hound combiner net.
  142. RREAL *ZillaHoundFeat(
  143. MATCH *pMatch, int cPrim, BYTE *pSampleVector, RREAL *pZillaHoundNetMemory, LOCRUN_INFO *pLocRunInfo
  144. );
  145. // Train time only stuff
  146. #ifdef ZTRAIN
  147. // Flags set per prototype during training.
  148. #define MASK_INFO_IN 0x01 // Prototype has been added to database
  149. #define MASK_INFO_NOISY 0x04 // Don't match against this prototype
  150. #define IsInsertedLPTRAININFO(lptraininfoIn) (lptraininfoIn->rgfInfo & MASK_INFO_IN)
  151. #define MarkInsertedLPTRAININFO(lptraininfoIn) (lptraininfoIn->rgfInfo |= MASK_INFO_IN)
  152. #define MarkNoisyLPTRAININFO(lptraininfoIn) (lptraininfoIn->rgfInfo |= MASK_INFO_NOISY)
  153. #define MarkNotNoisyLPTRAININFO(lptraininfoIn) (lptraininfoIn->rgfInfo &= ~MASK_INFO_NOISY)
  154. #define IsNoisyLPTRAININFO(lptraininfoIn) (lptraininfoIn->rgfInfo & MASK_INFO_NOISY)
  155. #define ProtoheaderFromMpcfeatproto(cprim) &(mpcfeatproto[cprim])
  156. #define GetCprotoDynamicPROTOHEADER(pprotohdr) \
  157. ((pprotohdr)->cprotoDynamic)
  158. #define SetCprotoDynamicPROTOHEADER(pprotohdr, cproto) \
  159. ((pprotohdr)->cprotoDynamic = (cproto))
  160. #define PrototypeFromPROTOHEADER(pprotohdr, cprim, iproto, proto) { \
  161. if ((iproto) < (pprotohdr)->cprotoRom) { \
  162. ASSERT(0); \
  163. } else { \
  164. UINT iprotoD = (iproto) - (pprotohdr)->cprotoRom; \
  165. ASSERT(iprotoD < (pprotohdr)->cprotoDynamic); \
  166. (proto).dbc = (pprotohdr)->rgdbcDynamic[iprotoD]; \
  167. (proto).rgprim = &((pprotohdr)->rgprimDynamic[(cprim) * (iprotoD)]);\
  168. } \
  169. (proto).recmask = LocRun2ALC(&g_locRunInfo, (proto).dbc); \
  170. SetTraininfoPROTO(proto, (pprotohdr), iproto); \
  171. }
  172. #define SetTraininfoPROTO(proto, pphdr, iproto) \
  173. (proto).ptraininfo = (pphdr)->rgptraininfo[iproto]
  174. // Write out the cost calc table.
  175. BOOL CostCalcWriteFile(COST_TABLE ppCostTable, int iCostTableSize, FILE *pFile, wchar_t *pLocale);
  176. // Write out the geostats table.
  177. BOOL GeoStatWriteFile(BYTE *pGeomCost, FILE *pFile, wchar_t *pLocale);
  178. // Match primitives with extra stuff for training.
  179. extern VOID MatchPrimitivesTrain(
  180. const BIGPRIM * const pprim, // Featurized Query
  181. const UINT cprim, // Number of features in query (aka feature space)
  182. MATCH * const rgmatch, // Output: ranked list of characters and distances
  183. const UINT cmatchmax, // size of rgmatch array
  184. const CHARSET * const cs, // Allowed character set
  185. const FLOAT zillaGeo // How important geometrics are vs. features.
  186. );
  187. BOOL AddPrototypeToDatabase(BIGPRIM *pprim, int cprim, WORD wTrain, VOID *pti);
  188. BOOL TrimDatabase(VOID);
  189. BOOL WriteTextDatabase(FILE *fpText, FILE *fpLog);
  190. BOOL WriteZillaDat(LOCRUN_INFO *pLocRunInfo, FILE *cp, wchar_t *pLocale, BOOL bNibbleFeat);
  191. VOID FreeDynamicMpcfeatproto(VOID);
  192. int ComputeZillaSize(void);
  193. void GetDynamicProto(PROTOHEADER *pphdr, UINT cprim, UINT iproto, BIGPROTOTYPE *proto);
  194. int CountPrototypes(void);
  195. #endif
  196. #ifdef __cplusplus
  197. };
  198. #endif
  199. #endif // ZILLATOOL_H