Normalizes the blob for classification only if needed. (Normally this means a non-zero classify rotation.) If no Normalization is needed, then NULL is returned, and the input blob can be used directly. Otherwise a new TBLOB is returned which must be deleted after use.
| 361 | // can be used directly. Otherwise a new TBLOB is returned which must be |
| 362 | // deleted after use. |
| 363 | TBLOB* TBLOB::ClassifyNormalizeIfNeeded() const { |
| 364 | TBLOB* rotated_blob = NULL; |
| 365 | // If necessary, copy the blob and rotate it. The rotation is always |
| 366 | // +/- 90 degrees, as 180 was already taken care of. |
| 367 | if (denorm_.block() != NULL && |
| 368 | denorm_.block()->classify_rotation().y() != 0.0) { |
| 369 | TBOX box = bounding_box(); |
| 370 | int x_middle = (box.left() + box.right()) / 2; |
| 371 | int y_middle = (box.top() + box.bottom()) / 2; |
| 372 | rotated_blob = new TBLOB(*this); |
| 373 | const FCOORD& rotation = denorm_.block()->classify_rotation(); |
| 374 | // Move the rotated blob back to the same y-position so that we |
| 375 | // can still distinguish similar glyphs with differeny y-position. |
| 376 | float target_y = kBlnBaselineOffset + |
| 377 | (rotation.y() > 0 ? x_middle - box.left() : box.right() - x_middle); |
| 378 | rotated_blob->Normalize(NULL, &rotation, &denorm_, x_middle, y_middle, |
| 379 | 1.0f, 1.0f, 0.0f, target_y, |
| 380 | denorm_.inverse(), denorm_.pix()); |
| 381 | } |
| 382 | return rotated_blob; |
| 383 | } |
| 384 | |
| 385 | // Copies the data and the outline, but leaves next untouched. |
| 386 | void TBLOB::CopyFrom(const TBLOB& src) { |
no test coverage detected