| 157 | } |
| 158 | |
| 159 | bool parseBoard(Logger* _log, const Image<ColorRgb>& yuvImage, int& boardIndex, CapturedColors& allColors, bool multiFrame) |
| 160 | { |
| 161 | bool exit = (multiFrame) ? false : true; |
| 162 | |
| 163 | int line = 0; |
| 164 | CapturedColor white, black; |
| 165 | |
| 166 | try |
| 167 | { |
| 168 | getWhiteBlackColorLevels(yuvImage, white, black, line); |
| 169 | } |
| 170 | catch (std::exception& ex) |
| 171 | { |
| 172 | Error(_log, "Too much noice or too low resolution"); |
| 173 | return false; |
| 174 | } |
| 175 | |
| 176 | if (!verifyBlackColorPattern(yuvImage, (line == 0), black)) |
| 177 | { |
| 178 | Error(_log, "The black color pattern failed, too much noice or too low resolution"); |
| 179 | return false; |
| 180 | } |
| 181 | |
| 182 | try |
| 183 | { |
| 184 | boardIndex = readCrc(yuvImage, line, white); |
| 185 | if (boardIndex > SCREEN_LAST_BOARD_INDEX) |
| 186 | throw std::runtime_error("Unexpected board"); |
| 187 | |
| 188 | } |
| 189 | catch (std::exception& ex) |
| 190 | { |
| 191 | Error(_log, "Too much noice or too low resolution"); |
| 192 | return false; |
| 193 | } |
| 194 | |
| 195 | if (allColors.isCaptured(boardIndex)) |
| 196 | { |
| 197 | return true; |
| 198 | } |
| 199 | |
| 200 | int max1 = (boardIndex + 1) * SCREEN_SAMPLES_PER_BOARD; |
| 201 | int max2 = std::pow(SCREEN_COLOR_DIMENSION, 3); |
| 202 | for (int currentIndex = boardIndex * SCREEN_SAMPLES_PER_BOARD; currentIndex < max1 && currentIndex < max2; currentIndex++) |
| 203 | { |
| 204 | byte3 color; |
| 205 | int2 position; |
| 206 | indexToColorAndPos(currentIndex, color, position); |
| 207 | |
| 208 | int B = (currentIndex % SCREEN_COLOR_DIMENSION); |
| 209 | int G = ((currentIndex / (SCREEN_COLOR_DIMENSION)) % SCREEN_COLOR_DIMENSION); |
| 210 | int R = (currentIndex / (SCREEN_COLOR_DIMENSION * SCREEN_COLOR_DIMENSION)); |
| 211 | |
| 212 | try |
| 213 | { |
| 214 | auto capturedColor = readBlock(yuvImage, position, &color); |
| 215 | if (allColors.all[R][G][B].hasAnySample()) |
| 216 | { |
no test coverage detected