| 37 | } |
| 38 | |
| 39 | BlackBorder BlackBorderDetector::process(const Image<ColorRgb>& image) const |
| 40 | { |
| 41 | // test centre and 33%, 66% of width/height |
| 42 | // 33 and 66 will check left and top |
| 43 | // centre will check right and bottom sides |
| 44 | int width = image.width(); |
| 45 | int height = image.height(); |
| 46 | int width33percent = width / 3; |
| 47 | int height33percent = height / 3; |
| 48 | int width66percent = width33percent * 2; |
| 49 | int height66percent = height33percent * 2; |
| 50 | int xCenter = width / 2; |
| 51 | int yCenter = height / 2; |
| 52 | |
| 53 | |
| 54 | int firstNonBlackXPixelIndex = -1; |
| 55 | int firstNonBlackYPixelIndex = -1; |
| 56 | |
| 57 | width--; // remove 1 pixel to get end pixel index |
| 58 | height--; |
| 59 | |
| 60 | // find first X pixel of the image |
| 61 | for (int x = 0; x < width33percent; ++x) |
| 62 | { |
| 63 | if (!isBlack(image((width - x), yCenter)) |
| 64 | || !isBlack(image(x, height33percent)) |
| 65 | || !isBlack(image(x, height66percent))) |
| 66 | { |
| 67 | firstNonBlackXPixelIndex = x; |
| 68 | break; |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | // find first Y pixel of the image |
| 73 | for (int y = 0; y < height33percent; ++y) |
| 74 | { |
| 75 | if (!isBlack(image(xCenter, (height - y))) |
| 76 | || !isBlack(image(width33percent, y)) |
| 77 | || !isBlack(image(width66percent, y))) |
| 78 | { |
| 79 | firstNonBlackYPixelIndex = y; |
| 80 | break; |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | // Construct result |
| 85 | BlackBorder detectedBorder{}; |
| 86 | |
| 87 | detectedBorder.unknown = firstNonBlackXPixelIndex == -1 || firstNonBlackYPixelIndex == -1; |
| 88 | detectedBorder.horizontalSize = firstNonBlackYPixelIndex; |
| 89 | detectedBorder.verticalSize = firstNonBlackXPixelIndex; |
| 90 | |
| 91 | return detectedBorder; |
| 92 | } |
| 93 | |
| 94 | |
| 95 | /// |
no test coverage detected