diff --git a/colorchecker.h b/colorchecker.h index 8188cf6..79540e6 100644 --- a/colorchecker.h +++ b/colorchecker.h @@ -103,11 +103,11 @@ std::unique_ptr> HighlightClosest(const Image& image) { for (int32_t cc = 0; cc < kColorCheckerSrgb.ssize(); ++cc) { const auto& coord = closest.at(cc); const auto& color = kColorCheckerSrgb.at(cc); - out->DrawSquare({{{{std::max(5, coord.at(0)) - 5, std::max(5, coord.at(1)) - 5}}}}, kBlack, 10); - out->DrawSquare({{{{std::max(6, coord.at(0)) - 6, std::max(6, coord.at(1)) - 6}}}}, color, 12); - out->DrawSquare({{{{std::max(7, coord.at(0)) - 7, std::max(7, coord.at(1)) - 7}}}}, color, 14); - out->DrawSquare({{{{std::max(8, coord.at(0)) - 8, std::max(8, coord.at(1)) - 8}}}}, color, 16); - out->DrawSquare({{{{std::max(9, coord.at(0)) - 9, std::max(9, coord.at(1)) - 9}}}}, kWhite, 18); + out->DrawSquare({{{{coord.at(0) - 5, coord.at(1) - 5}}}}, kBlack, 10); + out->DrawSquare({{{{coord.at(0) - 6, coord.at(1) - 6}}}}, color, 12); + out->DrawSquare({{{{coord.at(0) - 7, coord.at(1) - 7}}}}, color, 14); + out->DrawSquare({{{{coord.at(0) - 8, coord.at(1) - 8}}}}, color, 16); + out->DrawSquare({{{{coord.at(0) - 9, coord.at(1) - 9}}}}, kWhite, 18); } return out; } diff --git a/image.h b/image.h index d084742..234f392 100644 --- a/image.h +++ b/image.h @@ -30,21 +30,22 @@ constexpr const Color& Image::GetPixel(const Coord<2>& coord) const template void Image::SetPixel(const Coord<2>& coord, const Color& color) { + if (coord.at(0) >= X || coord.at(1) >= Y) { + return; + } this->at(coord.at(1)).at(coord.at(0)) = color; } template void Image::DrawXLine(const Coord<2>& coord, const Color& color, int32_t length) { - auto& row = this->at(coord.at(1)); - - for (int32_t x = coord.at(0); x < std::min(X - 1, coord.at(0) + length); ++x) { - row.at(x) = color; + for (int32_t x = coord.at(0); x <= coord.at(0) + length; ++x) { + SetPixel({{{{x, coord.at(1)}}}}, color); } } template void Image::DrawYLine(const Coord<2>& coord, const Color& color, int32_t length) { - for (int32_t y = coord.at(1); y <= std::min(Y - 1, coord.at(1) + length); ++y) { + for (int32_t y = coord.at(1); y <= coord.at(1) + length; ++y) { SetPixel({{{{coord.at(0), y}}}}, color); } }