identiconpp is a library to generate identicons for C++ and C.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ltr_symmetric.cpp 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /* This file is part of identiconpp.
  2. * Copyright © 2018 tastytea <tastytea@tastytea.de>
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, version 3.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #include "identiconpp.hpp"
  17. #include "debug.hpp"
  18. Magick::Image Identiconpp::generate_ltr_symmetric(const string &digest)
  19. {
  20. Magick::Image img(Magick::Geometry(_columns, _rows),
  21. Magick::Color('#' + _background));
  22. uint8_t used_columns = _columns / 2 + _columns % 2;
  23. Magick::Color dotcolor = get_color(used_columns * _rows + 1, digest);
  24. for (uint8_t row = 0; row < _rows; ++row)
  25. {
  26. for (uint8_t column = 0; column < used_columns; ++column)
  27. {
  28. if (get_bit(row * used_columns + column, digest))
  29. {
  30. ttdebug << "col=" << std::to_string(column)
  31. << ", row=" << std::to_string(row) << '\n';
  32. img.pixelColor(column, row, dotcolor);
  33. img.pixelColor(_columns - 1 - column, row, dotcolor);
  34. }
  35. }
  36. }
  37. return img;
  38. }