44 #include "config_auto.h"
59 TBOX all_together = bounds[start];
60 for (
int x = start + 1; x <= end; x++) {
61 all_together += bounds[x];
81 BLOB_CHOICE_LIST *choices;
86 for (blob = pieces, x = 0; x < start; x++) {
92 #ifndef GRAPHICS_DISABLED
107 template<
class BLOB_CHOICE>
115 template<
class BLOB_CHOICE>
139 BLOB_CHOICE_LIST *filtered_choices) {
140 BLOB_CHOICE_IT filtered_choices_it(filtered_choices);
141 BLOB_CHOICE_IT choices_it(choices);
143 for (choices_it.mark_cycle_pt(); !choices_it.cycled_list();
144 choices_it.forward()) {
145 UNICHAR_ID choice_unichar_id = choices_it.data()->unichar_id();
148 if (frag !=
NULL && frag->
get_pos() == fragment_pos &&
155 filtered_choices_it.add_to_end(b);
159 filtered_choices->sort(SortByUnicharID<BLOB_CHOICE>);
170 inT16 num_frag_parts,
171 BLOB_CHOICE_LIST *choice_lists,
173 BLOB_CHOICE_IT *choice_lists_it =
new BLOB_CHOICE_IT[num_frag_parts];
175 for (
int i = 0; i < num_frag_parts; i++) {
176 choice_lists_it[i].set_to_list(&choice_lists[i]);
177 choice_lists_it[i].mark_cycle_pt();
180 BLOB_CHOICE_LIST *merged_choice = ratings->
get(row, column);
181 if (merged_choice ==
NULL)
182 merged_choice =
new BLOB_CHOICE_LIST;
184 bool end_of_list =
false;
185 BLOB_CHOICE_IT merged_choice_it(merged_choice);
186 while (!end_of_list) {
189 UNICHAR_ID max_unichar_id = choice_lists_it[0].data()->unichar_id();
191 for (
int i = 0; i < num_frag_parts; i++) {
192 UNICHAR_ID unichar_id = choice_lists_it[i].data()->unichar_id();
193 if (max_unichar_id < unichar_id) {
194 max_unichar_id = unichar_id;
201 for (
int i = 0; i < num_frag_parts; i++) {
202 UNICHAR_ID unichar_id = choice_lists_it[i].data()->unichar_id();
203 while (!choice_lists_it[i].cycled_list() &&
204 unichar_id < max_unichar_id) {
205 choice_lists_it[i].forward();
206 unichar_id = choice_lists_it[i].data()->unichar_id();
208 if (choice_lists_it[i].cycled_list()) {
218 UNICHAR_ID first_unichar_id = choice_lists_it[0].data()->unichar_id();
219 bool same_unichar =
true;
220 for (
int i = 1; i < num_frag_parts; i++) {
221 UNICHAR_ID unichar_id = choice_lists_it[i].data()->unichar_id();
222 if (unichar_id != first_unichar_id) {
223 same_unichar =
false;
230 UNICHAR_ID merged_unichar_id = first_unichar_id;
231 inT16 merged_fontinfo_id = choice_lists_it[0].data()->fontinfo_id();
232 inT16 merged_fontinfo_id2 = choice_lists_it[0].data()->fontinfo_id2();
233 inT16 merged_min_xheight = choice_lists_it[0].data()->min_xheight();
234 inT16 merged_max_xheight = choice_lists_it[0].data()->max_xheight();
235 int merged_script_id = choice_lists_it[0].data()->script_id();
236 bool merged_adapted = choice_lists_it[0].data()->adapted();
238 float merged_rating = 0, merged_certainty = 0;
239 for (
int i = 0; i < num_frag_parts; i++) {
240 float rating = choice_lists_it[i].data()->rating();
241 float certainty = choice_lists_it[i].data()->certainty();
243 if (i == 0 || certainty < merged_certainty)
244 merged_certainty = certainty;
245 merged_rating += rating;
247 choice_lists_it[i].forward();
248 if (choice_lists_it[i].cycled_list())
251 choice_lists_it[i].data()->max_xheight(),
252 &merged_min_xheight, &merged_max_xheight);
255 merged_choice_it.add_to_end(
new BLOB_CHOICE(merged_unichar_id,
271 if (merged_choice->empty())
272 delete merged_choice;
274 ratings->
put(row, column, merged_choice);
276 delete [] choice_lists_it;
295 BLOB_CHOICE_LIST *choice_lists) {
296 if (current_frag == num_frag_parts) {
298 choice_lists, ratings);
302 for (
inT16 x = current_row; x < num_blobs; x++) {
303 BLOB_CHOICE_LIST *choices = ratings->
get(current_row, x);
308 &choice_lists[current_frag]);
309 if (!choice_lists[current_frag].empty()) {
311 num_blobs, ratings, choice_lists);
312 choice_lists[current_frag].clear();
326 for (
inT16 start = 0; start < num_blobs; start++) {
330 ratings, choice_lists);
335 for (
inT16 x = 0; x < num_blobs; x++) {
336 for (
inT16 y = x; y < num_blobs; y++) {
337 BLOB_CHOICE_LIST *choices = ratings->
get(x, y);
338 if (choices !=
NULL) {
339 BLOB_CHOICE_IT choices_it(choices);
340 for (choices_it.mark_cycle_pt(); !choices_it.cycled_list();
341 choices_it.forward()) {
342 UNICHAR_ID choice_unichar_id = choices_it.data()->unichar_id();
346 delete choices_it.extract();
369 BLOB_CHOICE_LIST *choices = ratings->
get(start, end);
377 ratings->
put(start, end, choices);
379 tprintf(
"get_piece_rating(): updated ratings matrix\n");
398 for (
TBLOB* blob = blobs; blob !=
NULL; blob = blob->next) {
399 bboxes[x] = blob->bounding_box();
419 for (
int x = 0; x < num_blobs; x++) {
420 for (
int y = x; y < num_blobs; y++) {
423 if (choices !=
NULL) {
424 ratings->
put(x, y, choices);