* Helper computes the local 2-D gradient (dx, dy) from the 2x2 cell centered * on the given (x,y). If the cell would go outside the image, it is padded * with white. */
| 649 | * with white. |
| 650 | */ |
| 651 | static void ComputeGradient(const l_uint32* data, int wpl, |
| 652 | int x, int y, int width, int height, |
| 653 | ICOORD* gradient) { |
| 654 | const l_uint32* line = data + y * wpl; |
| 655 | int pix_x_y = |
| 656 | x < width && y < height |
| 657 | ? GET_DATA_BYTE( |
| 658 | const_cast<void*>(reinterpret_cast<const void*>(line)), x) |
| 659 | : 255; |
| 660 | int pix_x_prevy = |
| 661 | x < width && y > 0 |
| 662 | ? GET_DATA_BYTE( |
| 663 | const_cast<void*>(reinterpret_cast<const void*>(line - wpl)), x) |
| 664 | : 255; |
| 665 | int pix_prevx_prevy = |
| 666 | x > 0 && y > 0 |
| 667 | ? GET_DATA_BYTE( |
| 668 | const_cast<void*>(reinterpret_cast<void const*>(line - wpl)), |
| 669 | x - 1) |
| 670 | : 255; |
| 671 | int pix_prevx_y = |
| 672 | x > 0 && y < height |
| 673 | ? GET_DATA_BYTE( |
| 674 | const_cast<void*>(reinterpret_cast<const void*>(line)), x - 1) |
| 675 | : 255; |
| 676 | gradient->set_x(pix_x_y + pix_x_prevy - (pix_prevx_y + pix_prevx_prevy)); |
| 677 | gradient->set_y(pix_x_prevy + pix_prevx_prevy - (pix_x_y + pix_prevx_y)); |
| 678 | } |
| 679 | |
| 680 | /** |
| 681 | * Helper evaluates a vertical difference, (x,y) - (x,y-1), returning true if |
no test coverage detected