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.

sigil.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_sigil(const string &digest)
  19. {
  20. Magick::Image img(Magick::Geometry(_columns, _rows),
  21. Magick::Color('#' + _background));
  22. Magick::Color dotcolor = get_color(0, digest);
  23. uint8_t used_columns = _columns / 2 + _columns % 2;
  24. uint8_t cells = _rows * used_columns;
  25. for (uint8_t cur_cell = 0; cur_cell < cells; ++cur_cell)
  26. {
  27. if (get_bit(8 + cur_cell, digest))
  28. {
  29. const uint8_t column = cur_cell / _columns;
  30. const uint8_t row = cur_cell % _rows;
  31. ttdebug << "col=" << std::to_string(column)
  32. << ", row=" << std::to_string(row) << '\n';
  33. img.pixelColor(column, row, dotcolor);
  34. img.pixelColor(_columns - column - 1, row, dotcolor);
  35. }
  36. }
  37. return img;
  38. }