generates a deslanted bitmap from the passed bitmap.
| 750 | |
| 751 | // generates a deslanted bitmap from the passed bitmap. |
| 752 | bool Bmp8::Deslant() { |
| 753 | int x; |
| 754 | int y; |
| 755 | int des_x; |
| 756 | int des_y; |
| 757 | int ang_idx; |
| 758 | int best_ang; |
| 759 | int min_des_x; |
| 760 | int max_des_x; |
| 761 | int des_wid; |
| 762 | |
| 763 | // only do deslanting if bitmap is wide enough |
| 764 | // otherwise it slant estimate might not be reliable |
| 765 | if (wid_ < (hgt_ * 2)) { |
| 766 | return true; |
| 767 | } |
| 768 | |
| 769 | // compute tan table if needed |
| 770 | if (tan_table_ == NULL && !ComputeTanTable()) { |
| 771 | return false; |
| 772 | } |
| 773 | |
| 774 | // compute min and max values for x after deslant |
| 775 | min_des_x = static_cast<int>(0.5f + (hgt_ - 1) * tan_table_[0]); |
| 776 | max_des_x = (wid_ - 1) + |
| 777 | static_cast<int>(0.5f + (hgt_ - 1) * tan_table_[kDeslantAngleCount - 1]); |
| 778 | |
| 779 | des_wid = max_des_x - min_des_x + 1; |
| 780 | |
| 781 | // alloc memory for histograms |
| 782 | int **angle_hist = new int*[kDeslantAngleCount]; |
| 783 | for (ang_idx = 0; ang_idx < kDeslantAngleCount; ang_idx++) { |
| 784 | angle_hist[ang_idx] = new int[des_wid]; |
| 785 | memset(angle_hist[ang_idx], 0, des_wid * sizeof(*angle_hist[ang_idx])); |
| 786 | } |
| 787 | |
| 788 | // compute histograms |
| 789 | for (y = 0; y < hgt_; y++) { |
| 790 | for (x = 0; x < wid_; x++) { |
| 791 | // find a non-bkgrnd pixel |
| 792 | if (line_buff_[y][x] != 0xff) { |
| 793 | des_y = hgt_ - y - 1; |
| 794 | // stamp all histograms |
| 795 | for (ang_idx = 0; ang_idx < kDeslantAngleCount; ang_idx++) { |
| 796 | des_x = x + static_cast<int>(0.5f + (des_y * tan_table_[ang_idx])); |
| 797 | if (des_x >= min_des_x && des_x <= max_des_x) { |
| 798 | angle_hist[ang_idx][des_x - min_des_x]++; |
| 799 | } |
| 800 | } |
| 801 | } |
| 802 | } |
| 803 | } |
| 804 | |
| 805 | // find the histogram with the lowest entropy |
| 806 | float entropy; |
| 807 | double best_entropy = 0.0f; |
| 808 | double norm_val; |
| 809 |