MCPcopy Create free account
hub / github.com/creatale/node-dv / FromCharDumpFile

Method FromCharDumpFile

deps/tesseract/cube/char_samp.cpp:82–172  ·  view source on GitHub ↗

creates a CharSamp object from file

Source from the content-addressed store, hash-verified

80
81// creates a CharSamp object from file
82CharSamp *CharSamp::FromCharDumpFile(CachedFile *fp) {
83 unsigned short left;
84 unsigned short top;
85 unsigned short page;
86 unsigned short first_char;
87 unsigned short last_char;
88 unsigned short norm_top;
89 unsigned short norm_bottom;
90 unsigned short norm_aspect_ratio;
91 unsigned int val32;
92
93 char_32 *label32;
94
95 // read and check 32 bit marker
96 if (fp->Read(&val32, sizeof(val32)) != sizeof(val32)) {
97 return NULL;
98 }
99 if (val32 != 0xabd0fefe) {
100 return NULL;
101 }
102 // read label length,
103 if (fp->Read(&val32, sizeof(val32)) != sizeof(val32)) {
104 return NULL;
105 }
106 // the label is not null terminated in the file
107 if (val32 > 0 && val32 < MAX_UINT32) {
108 label32 = new char_32[val32 + 1];
109 // read label
110 if (fp->Read(label32, val32 * sizeof(*label32)) !=
111 (val32 * sizeof(*label32))) {
112 delete [] label32;
113 return NULL;
114 }
115 // null terminate
116 label32[val32] = 0;
117 } else {
118 label32 = NULL;
119 }
120 // read coordinates
121 if (fp->Read(&page, sizeof(page)) != sizeof(page)) {
122 delete [] label32;
123 return NULL;
124 }
125 if (fp->Read(&left, sizeof(left)) != sizeof(left)) {
126 delete [] label32;
127 return NULL;
128 }
129 if (fp->Read(&top, sizeof(top)) != sizeof(top)) {
130 delete [] label32;
131 return NULL;
132 }
133 if (fp->Read(&first_char, sizeof(first_char)) != sizeof(first_char)) {
134 delete [] label32;
135 return NULL;
136 }
137 if (fp->Read(&last_char, sizeof(last_char)) != sizeof(last_char)) {
138 delete [] label32;
139 return NULL;

Callers

nothing calls this directly

Calls 2

LoadFromCharDumpFileMethod · 0.80
ReadMethod · 0.45

Tested by

no test coverage detected