| 91 | } |
| 92 | |
| 93 | void GetImageDiffRect(ImageRect& rect, const uint8_t* preImage, const uint8_t* curImage, int width, |
| 94 | int height, int stride) { |
| 95 | if (preImage == nullptr || curImage == nullptr) { |
| 96 | return; |
| 97 | } |
| 98 | int minX = width - 1; |
| 99 | int minY = height - 1; |
| 100 | int maxX = 0; |
| 101 | int maxY = 0; |
| 102 | |
| 103 | for (int y = 0; y < height; y++) { |
| 104 | const auto preData = |
| 105 | reinterpret_cast<const uint32_t*>(static_cast<const void*>(preImage + y * stride)); |
| 106 | const auto curData = |
| 107 | reinterpret_cast<const uint32_t*>(static_cast<const void*>(curImage + y * stride)); |
| 108 | |
| 109 | for (int x = 0; x < width; x++) { |
| 110 | if (preData[x] == curData[x]) { |
| 111 | continue; |
| 112 | } |
| 113 | minX = std::min(minX, x); |
| 114 | minY = std::min(minY, y); |
| 115 | maxX = std::max(maxX, x); |
| 116 | maxY = std::max(maxY, y); |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | if (minX < maxX) { |
| 121 | rect.xPos = minX; |
| 122 | rect.yPos = minY; |
| 123 | rect.width = maxX - minX + 1; |
| 124 | rect.height = maxY - minY + 1; |
| 125 | } else { |
| 126 | rect.xPos = 0; |
| 127 | rect.yPos = 0; |
| 128 | rect.width = 0; |
| 129 | rect.height = 0; |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | static bool InRange(int val, int pos, int width) { |
| 134 | return val >= pos && val <= pos + width; |