Compare commits

..

No commits in common. "master" and "0.1.2" have entirely different histories.

34 changed files with 656 additions and 2060 deletions

View File

@ -1,211 +1,198 @@
# -*- fill-column: 1000 -*-
kind: pipeline
name: build x86_64
pipeline:
gcc5:
image: debian:stretch-slim
pull: true
when:
event: [push, pull_request]
environment:
- LANG=C.utf8
- CXX=g++-5
- CXXFLAGS=-pipe -O2
commands:
- rm /etc/apt/apt.conf.d/docker-clean
- apt-get update -q
- echo "APT::Default-Release \"stretch\";" >> /etc/apt/apt.conf.d/00default_release
- echo "deb http://ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu xenial main" >> /etc/apt/sources.list.d/ubuntu-toolchain-r.list
- apt-get install -qy gnupg
- gpg --keyserver hkp://keyserver.ubuntu.com --recv-keys 0x60c317803a41ba51845e371a1e9377a2ba9ef27f
- gpg --armor --export 0x60c317803a41ba51845e371a1e9377a2ba9ef27f | apt-key add -
- apt-get update -q
- apt-get install -qy -t xenial g++-5
- apt-get install -qy cmake pkg-config
- apt-get install -qy libmagick++-dev
- rm -rf build && mkdir -p build && cd build
- cmake -DCMAKE_INSTALL_PREFIX=/usr ..
- make VERBOSE=1
volumes:
- /var/cache/debian-package-cache:/var/cache/apt/archives
volumes:
- name: debian-package-cache
host:
path: /var/cache/debian-package-cache
gcc6:
image: debian:stretch-slim
pull: true
environment:
- LANG=C.utf8
- CXX=g++-6
- CXXFLAGS=-pipe -O2
commands:
- rm /etc/apt/apt.conf.d/docker-clean
- apt-get update -q
- apt-get install -qy g++-6 cmake pkg-config
- apt-get install -qy libmagick++-dev
- apt-get install -qy dpkg-dev d-shlibs rpm file wget
- gpg --no-tty --import /var/autosign_gpg.key
- rm -rf build && mkdir -p build && cd build
- cmake -DCMAKE_INSTALL_PREFIX=/usr ..
- make VERBOSE=1
- make install DESTDIR=install
- make package
- cmake -DWITH_DEB=ON ..
- make package
- cmake -DWITH_DEB=OFF -DWITH_RPM=ON ..
- make package
- gpg --verbose --detach-sign *.tar.gz
- gpg --verbose --detach-sign *.deb
- gpg --verbose --detach-sign *.rpm
volumes:
- /var/cache/debian-package-cache:/var/cache/apt/archives
- /home/tastytea/misc/autosign_gpg.key:/var/autosign_gpg.key
trigger:
event:
exclude:
- tag
gcc7:
image: debian:stretch-slim
pull: true
when:
event: [push, pull_request]
environment:
- LANG=C.utf8
- CXX=g++-7
- CXXFLAGS=-pipe -O2
commands:
- rm /etc/apt/apt.conf.d/docker-clean
- apt-get update -q
- echo "APT::Default-Release \"stretch\";" >> /etc/apt/apt.conf.d/00default_release
- echo "deb http://ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu xenial main" >> /etc/apt/sources.list.d/ubuntu-toolchain-r.list
- apt-get install -qy gnupg
- gpg --keyserver hkp://keyserver.ubuntu.com --recv-keys 0x60c317803a41ba51845e371a1e9377a2ba9ef27f
- gpg --armor --export 0x60c317803a41ba51845e371a1e9377a2ba9ef27f | apt-key add -
- apt-get update -q
- apt-get install -qy -t xenial g++-7
- apt-get install -qy cmake pkg-config
- apt-get install -qy libmagick++-dev
- rm -rf build && mkdir -p build && cd build
- cmake -DCMAKE_INSTALL_PREFIX=/usr ..
- make VERBOSE=1
volumes:
- /var/cache/debian-package-cache:/var/cache/apt/archives
steps:
- name: gcc6
image: debian:stretch-slim
pull: always
environment:
CXX: g++-6
CXXFLAGS: -pipe -O2
LANG: en_US.utf-8
commands:
- rm /etc/apt/apt.conf.d/docker-clean
- alias apt-get='rm -f /var/cache/apt/archives/lock && apt-get'
- apt-get update -q
- apt-get install -qy g++-6 cmake pkg-config libmagick++-dev catch
- rm -rf build && mkdir -p build && cd build
- cmake -DWITH_TESTS=YES ..
- cmake --build .
- make install DESTDIR=install
- cd tests && ctest -V
volumes:
- name: debian-package-cache
path: /var/cache/apt/archives
gcc8:
image: debian:stretch-slim
pull: true
when:
event: [push, pull_request]
environment:
- LANG=C.utf8
- CXX=g++-8
- CXXFLAGS=-pipe -O2
commands:
- rm /etc/apt/apt.conf.d/docker-clean
- apt-get update -q
- echo "APT::Default-Release \"stretch\";" >> /etc/apt/apt.conf.d/00default_release
- echo "deb http://ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu xenial main" >> /etc/apt/sources.list.d/ubuntu-toolchain-r.list
- apt-get install -qy gnupg
- gpg --keyserver hkp://keyserver.ubuntu.com --recv-keys 0x60c317803a41ba51845e371a1e9377a2ba9ef27f
- gpg --armor --export 0x60c317803a41ba51845e371a1e9377a2ba9ef27f | apt-key add -
- apt-get update -q
- apt-get install -qy -t xenial g++-8
- apt-get install -qy cmake pkg-config
- apt-get install -qy libmagick++-dev
- rm -rf build && mkdir -p build && cd build
- cmake -DCMAKE_INSTALL_PREFIX=/usr ..
- make VERBOSE=1
volumes:
- /var/cache/debian-package-cache:/var/cache/apt/archives
- name: gcc9
image: debian:stretch-slim
pull: always
environment:
CXX: g++-9
CXXFLAGS: -pipe -O2
LANG: en_US.utf-8
commands:
- rm /etc/apt/apt.conf.d/docker-clean
- alias apt-get='rm -f /var/cache/apt/archives/lock && apt-get'
- apt-get update -q
- echo "APT::Default-Release \"stretch\";" >> /etc/apt/apt.conf.d/00default_release
- echo "deb http://ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu xenial main" >> /etc/apt/sources.list.d/ubuntu-toolchain-r.list
- apt-get install -qy gnupg
- gpg --keyserver hkp://keyserver.ubuntu.com --recv-keys 0x60c317803a41ba51845e371a1e9377a2ba9ef27f
- gpg --armor --export 0x60c317803a41ba51845e371a1e9377a2ba9ef27f | apt-key add -
- apt-get update -q
- apt-get install -qy -t xenial g++-9
- apt-get install -qy cmake pkg-config libmagick++-dev
- rm -rf build && mkdir -p build && cd build
- cmake ..
- cmake --build .
volumes:
- name: debian-package-cache
path: /var/cache/apt/archives
clang5:
image: debian:stretch-slim
pull: true
when:
event: [push, pull_request]
environment:
- LANG=C.utf8
- CXX=clang++-5.0
- CXXFLAGS=-pipe -O2
commands:
- rm /etc/apt/apt.conf.d/docker-clean
- echo "APT::Default-Release \"stretch\";" >> /etc/apt/apt.conf.d/00default_release
- echo "deb http://deb.debian.org/debian stretch-backports main" >> /etc/apt/sources.list.d/stretch.list
- apt-get update -q
- apt-get install -qy -t stretch-backports clang-5.0
- apt-get install -qy cmake pkg-config
- apt-get install -qy libmagick++-dev
- rm -rf build && mkdir -p build && cd build
- cmake -DCMAKE_INSTALL_PREFIX=/usr ..
- make VERBOSE=1
volumes:
- /var/cache/debian-package-cache:/var/cache/apt/archives
- name: clang7
image: debian:buster-slim
pull: always
environment:
CXX: clang++
CXXFLAGS: -pipe -O2
LANG: en_US.utf-8
commands:
- rm /etc/apt/apt.conf.d/docker-clean
- alias apt-get='rm -f /var/cache/apt/archives/lock && apt-get'
- apt-get update -q
- apt-get install -qy clang cmake pkg-config libmagick++-dev
- rm -rf build && mkdir -p build && cd build
- cmake ..
- cmake --build .
volumes:
- name: debian-package-cache
path: /var/cache/apt/archives
clang6:
image: debian:stretch-slim
pull: true
when:
event: [push, pull_request]
environment:
- LANG=C.utf8
- CXX=clang++-6.0
- CXXFLAGS=-pipe -O2
commands:
- rm /etc/apt/apt.conf.d/docker-clean
- echo "APT::Default-Release \"stretch\";" >> /etc/apt/apt.conf.d/00default_release
- echo "deb http://deb.debian.org/debian stretch-backports main" >> /etc/apt/sources.list.d/stretch.list
- apt-get update -q
- apt-get install -qy -t stretch-backports clang-6.0
- apt-get install -qy cmake pkg-config
- apt-get install -qy libmagick++-dev
- rm -rf build && mkdir -p build && cd build
- cmake -DCMAKE_INSTALL_PREFIX=/usr ..
- make VERBOSE=1
volumes:
- /var/cache/debian-package-cache:/var/cache/apt/archives
---
kind: pipeline
name: packages x86_64
prepare_release:
image: debian:stretch-slim
pull: true
when:
event: tag
commands:
- cp -v build/identiconpp-${DRONE_TAG}_x86_64.tar.gz .
- cp -v build/identiconpp-${DRONE_TAG}_x86_64.tar.gz.sig .
- cp -v build/identiconpp_${DRONE_TAG}-0_amd64.deb .
- cp -v build/identiconpp_${DRONE_TAG}-0_amd64.deb.sig .
- cp -v build/identiconpp-${DRONE_TAG}-0.x86_64.rpm .
- cp -v build/identiconpp-${DRONE_TAG}-0.x86_64.rpm.sig .
volumes:
- name: debian-package-cache
host:
path: /var/cache/debian-package-cache
- name: centos-package-cache
host:
path: /var/cache/centos-package-cache
- name: gpg-key
host:
path: /home/tastytea/misc/autosign_gpg.key
trigger:
event:
- tag
steps:
- name: Debian stretch
image: debian:stretch-slim
pull: always
environment:
CXX: g++-6
CXXFLAGS: -pipe -O2
LANG: en_US.utf-8
commands:
- rm /etc/apt/apt.conf.d/docker-clean
- alias apt-get='rm -f /var/cache/apt/archives/lock && apt-get'
- apt-get update -q
- apt-get install -qy g++-6 cmake pkg-config libmagick++-dev gnupg dpkg-dev d-shlibs lsb-release
- rm -rf build && mkdir -p build && cd build
- cmake -DWITH_DEB=YES ..
- make package
- gpg --import /var/autosign_gpg.key
- gpg --verbose --detach-sign *.deb
- cp -v identiconpp_${DRONE_TAG}-0_amd64_stretch.deb ..
- cp -v identiconpp_${DRONE_TAG}-0_amd64_stretch.deb.sig ..
volumes:
- name: debian-package-cache
path: /var/cache/apt/archives
- name: gpg-key
path: /var/autosign_gpg.key
- name: Debian buster
image: debian:buster-slim
pull: always
environment:
CXX: g++-8
CXXFLAGS: -pipe -O2
LANG: en_US.utf-8
commands:
- rm /etc/apt/apt.conf.d/docker-clean
- alias apt-get='rm -f /var/cache/apt/archives/lock && apt-get'
- apt-get update -q
- apt-get install -qy build-essential cmake pkg-config libmagick++-dev gnupg dpkg-dev d-shlibs lsb-release
- rm -rf build && mkdir -p build && cd build
- cmake -DWITH_DEB=YES ..
- make package
- gpg --import /var/autosign_gpg.key
- gpg --verbose --detach-sign *.deb
- cp -v identiconpp_${DRONE_TAG}-0_amd64_buster.deb ..
- cp -v identiconpp_${DRONE_TAG}-0_amd64_buster.deb.sig ..
volumes:
- name: debian-package-cache
path: /var/cache/apt/archives
- name: gpg-key
path: /var/autosign_gpg.key
# - name: CentOS 7
# image: centos:7
# pull: always
# environment:
# CXX: /opt/rh/devtoolset-6/root/usr/bin/g++
# CXXFLAGS: -pipe -O2
# LANG: en_US.utf-8
# commands:
# - sed -i 's/keepcache=0/keepcache=1/' /etc/yum.conf
# - curl -s -o /var/cache/yum/epel-release-latest-7.noarch.rpm http://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
# - rpm -i /var/cache/yum/epel-release-latest-7.noarch.rpm
# - yum install -qy centos-release-scl
# - yum install -qy devtoolset-6
# - scl enable devtoolset-6 bash
# - yum install -qy rpm-build ImageMagick-c++-devel gnupg redhat-lsb-core
# - yum --enablerepo=epel install -qy cmake3
# - rm -rf build && mkdir -p build && cd build
# - cmake3 -DWITH_RPM=YES ..
# - make package
# - gpg --import /var/autosign_gpg.key
# - gpg --verbose --detach-sign *.rpm
# - cp -v identiconpp-${DRONE_TAG}-0.x86_64.centos7.rpm ..
# - cp -v identiconpp-${DRONE_TAG}-0.x86_64.centos7.rpm.sig ..
# volumes:
# - name: centos-package-cache
# path: /var/cache/yum
# - name: gpg-key
# path: /var/autosign_gpg.key
- name: release
image: plugins/gitea-release
pull: always
settings:
gitea_release:
image: plugins/gitea-release
pull: true
when:
event: tag
base_url: https://schlomp.space
api_key:
from_secret: gitea_token
secrets: [ gitea_token ]
title: ${DRONE_TAG}
prerelease: true
files:
- identiconpp_${DRONE_TAG}-0_amd64_stretch.deb
- identiconpp_${DRONE_TAG}-0_amd64_stretch.deb.sig
- identiconpp_${DRONE_TAG}-0_amd64_buster.deb
- identiconpp_${DRONE_TAG}-0_amd64_buster.deb.sig
# - identiconpp-${DRONE_TAG}-0.x86_64.centos7.rpm
# - identiconpp-${DRONE_TAG}-0.x86_64.centos7.rpm.sig
- identiconpp-${DRONE_TAG}_x86_64.tar.gz
- identiconpp-${DRONE_TAG}_x86_64.tar.gz.sig
- identiconpp_${DRONE_TAG}-0_amd64.deb
- identiconpp_${DRONE_TAG}-0_amd64.deb.sig
- identiconpp-${DRONE_TAG}-0.x86_64.rpm
- identiconpp-${DRONE_TAG}-0.x86_64.rpm.sig
checksum:
- sha512
- name: notify
image: drillster/drone-email
pull: always
settings:
notify:
image: drillster/drone-email
pull: true
host: cryptoparty-celle.de
secrets: [ email_username, email_password ]
from: drone@tzend.de
username:
from_secret: email_username
password:
from_secret: email_password
when:
status: [ changed, failure ]
when:
status: [ changed, failure ]

View File

@ -1,20 +0,0 @@
# Configuration file for EditorConfig.
# More information is available under <https://editorconfig.org/>.
root = true
[*]
indent_style = space
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
max_line_length = 80
[*.?pp]
indent_size = 4
tab_width = 4
[{CMakeLists.txt,*.cmake}]
indent_size = 2
tab_width = 2

View File

@ -1,57 +1,43 @@
# Support version 3.6 and above, but use policy settings up to 3.14.
# 3.6 is needed because of IMPORTED_TARGET in pkg_check_modules().
cmake_minimum_required(VERSION 3.6...3.14)
# Ranges are supported from 3.12, set policy to current for < 3.12.
if(${CMAKE_VERSION} VERSION_LESS 3.12)
cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION})
endif()
cmake_minimum_required (VERSION 3.2)
project(identiconpp
VERSION 0.7.3
LANGUAGES CXX)
# DESCRIPTION was introduced in version 3.9.
if(NOT (${CMAKE_VERSION} VERSION_LESS 3.9))
set(PROJECT_DESCRIPTION
"Library to generate identicons for C++.")
endif()
VERSION 0.1.2
LANGUAGES CXX
)
option(WITH_TESTS "Enable Tests" NO)
option(BUILD_SHARED_LIBS "Build shared libraries." YES)
include(GNUInstallDirs)
find_package(PkgConfig REQUIRED)
pkg_check_modules(MAGICPP REQUIRED Magick++)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(DEBUG_CXXFLAGS
"-Wall"
"-Wextra"
"-Wpedantic"
"-ftrapv"
"-fsanitize=undefined"
"-g"
"-Og"
"-fno-omit-frame-pointer")
set(DEBUG_LDFLAGS
"-fsanitize=undefined")
add_compile_options("$<$<CONFIG:Debug>:${DEBUG_CXXFLAGS}>")
# add_link_options was introduced in version 3.13.
if(${CMAKE_VERSION} VERSION_LESS 3.13)
set(CMAKE_SHARED_LINKER_FLAGS_DEBUG "${DEBUG_LDFLAGS}")
else()
add_link_options("$<$<CONFIG:Debug>:${DEBUG_LDFLAGS}>")
endif()
string(REPLACE ";" " " MAGICPP_CFLAGS_STRING "${MAGICPP_CFLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${MAGICPP_CFLAGS_STRING}")
set(CMAKE_CXX_FLAGS_DEBUG
"${CMAKE_CXX_FLAGS_DEBUG} -Wall -pedantic -Wextra -g -Og -fno-omit-frame-pointer")
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
add_definitions(-DDEBUG=1)
add_definitions(-DDEBUG=1)
endif()
add_subdirectory(src)
add_subdirectory(include)
add_subdirectory(cmake)
add_subdirectory(pkg-config)
include_directories(${PROJECT_SOURCE_DIR}/src)
include_directories(${PROJECT_BINARY_DIR})
include_directories(${MAGICPP_INCLUDE_DIRS})
if(WITH_TESTS)
add_subdirectory(tests)
endif()
link_directories(${MAGICPP_LIBRARY_DIRS})
file(GLOB sources src/*.cpp)
add_library(${CMAKE_PROJECT_NAME} SHARED "${sources}")
set_target_properties(${CMAKE_PROJECT_NAME} PROPERTIES
VERSION ${PROJECT_VERSION}
SOVERSION ${${CMAKE_PROJECT_NAME}_VERSION_MAJOR})
target_link_libraries(${CMAKE_PROJECT_NAME} "${MAGICPP_LDFLAGS}")
add_executable(example "example.cpp")
target_link_libraries(example ${CMAKE_PROJECT_NAME})
install(TARGETS ${CMAKE_PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR})
install(FILES src/${CMAKE_PROJECT_NAME}.hpp DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
install(FILES README.md DESTINATION ${CMAKE_INSTALL_DOCDIR})
include(packages.CMakeLists.txt)

View File

@ -1,49 +0,0 @@
:contact-coc: tastytea@tastytea.de
== Code of Conduct
In the interest of fostering an open and welcoming environment, we as
contributors and maintainers pledge to making participation in our project and
our community a harassment-free experience for everyone, regardless of age, body
size, disability, education, ethnicity, gender identity and expression, level of
experience, nationality, personal appearance, race, religion, sex
characteristics, sexual identity and orientation or socio-economic status.
=== Examples
Examples of behavior that contributes to creating a positive environment
include:
* Using welcoming and inclusive language.
* Being respectful of differing viewpoints and experiences.
* Gracefully accepting constructive criticism.
* Focusing on what is best for the community.
* Showing empathy towards other community members.
Examples of unacceptable behavior by participants include:
* The use of sexualized language or imagery and unwelcome sexual attention or
advances.
* Trolling, insulting/derogatory comments, and personal attacks.
* Public or private harassment.
* Publishing others private information, such as a physical or electronic
address, without explicit permission.
=== Enforcement
Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting the project team at {contact-coc}.
All complaints will be reviewed and investigated and will result in a response
that is deemed necessary and appropriate to the circumstances. The project team
is obligated to maintain confidentiality with regard to the reporter of an
incident.
=== Attribution
This Code of Conduct is adapted from the Contributor Covenant, version 1.4,
available at
https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
For answers to common questions about this code of conduct, see
https://www.contributor-covenant.org/faq

View File

@ -1,29 +0,0 @@
:project: identiconpp
:uri-base: https://schlomp.space/tastytea/{project}
:uri-coc: {uri-base}/src/branch/master/CODE_OF_CONDUCT.adoc
:contact-email: tastytea@tastytea.de
:contact-xmpp: {contact-email}
:contact-fediverse: https://likeable.space/users/tastytea
== How to contribute
Read the link:{uri-coc}[Code of Conduct].
=== Reporting bugs or suggesting enhancements
Before reporting a bug, please
https://schlomp.space/tastytea/{project}/issues[perform a search] to see if the
problem has already been reported. If it has, add a comment to the existing
issue instead of opening a new one. Same for enhancements.
You can also contact me via mailto:{contact-email}[E-Mail],
link:xmpp:{contact-xmpp}[XMPP] or the {contact-fediverse}[Fediverse] if you
don't want to open an account.
=== Pull requests
Please use similar coding conventions as the rest of the project. The basic rule
to remember is to write code in the same style as the existing/surrounding code.
You can also send me your patches via mailto:{contact-email}[E-Mail], ideally
using `git format-patch` or `git send-email`.

192
Doxyfile
View File

@ -1,28 +1,198 @@
# -*- mode: conf-unix -*-
DOXYFILE_ENCODING = UTF-8
PROJECT_NAME = "identiconpp"
PROJECT_NUMBER = 0.0.0
INPUT = README.md src/
USE_MDFILE_AS_MAINPAGE = README.md
EXAMPLE_PATH = ./
EXAMPLE_RECURSIVE = YES
GENERATE_HTML = YES
HTML_OUTPUT = doc/html
GENERATE_LATEX = NO
CREATE_SUBDIRS = NO
ALLOW_UNICODE_NAMES = YES
OUTPUT_LANGUAGE = English
BRIEF_MEMBER_DESC = YES
REPEAT_BRIEF = YES
ALWAYS_DETAILED_SEC = YES
ALWAYS_DETAILED_SEC = NO
INLINE_INHERITED_MEMB = NO
FULL_PATH_NAMES = YES
SHORT_NAMES = NO
JAVADOC_AUTOBRIEF = NO
QT_AUTOBRIEF = NO
MULTILINE_CPP_IS_BRIEF = NO
INHERIT_DOCS = YES
SEPARATE_MEMBER_PAGES = NO
TAB_SIZE = 4
OPTIMIZE_OUTPUT_FOR_C = NO
OPTIMIZE_OUTPUT_JAVA = NO
OPTIMIZE_FOR_FORTRAN = NO
OPTIMIZE_OUTPUT_VHDL = NO
MARKDOWN_SUPPORT = YES
AUTOLINK_SUPPORT = YES
BUILTIN_STL_SUPPORT = NO
CPP_CLI_SUPPORT = NO
SIP_SUPPORT = NO
IDL_PROPERTY_SUPPORT = YES
DISTRIBUTE_GROUP_DOC = NO
GROUP_NESTED_COMPOUNDS = NO
SUBGROUPING = YES
INLINE_GROUPED_CLASSES = NO
INLINE_SIMPLE_STRUCTS = NO
TYPEDEF_HIDES_STRUCT = NO
LOOKUP_CACHE_SIZE = 0
EXTRACT_ALL = NO
EXTRACT_PRIVATE = NO
EXTRACT_PACKAGE = NO
EXTRACT_STATIC = NO
EXTRACT_LOCAL_CLASSES = YES
EXTRACT_LOCAL_METHODS = NO
EXTRACT_ANON_NSPACES = NO
HIDE_UNDOC_MEMBERS = NO
HIDE_UNDOC_CLASSES = NO
HIDE_FRIEND_COMPOUNDS = NO
HIDE_IN_BODY_DOCS = NO
INTERNAL_DOCS = NO
CASE_SENSE_NAMES = YES
HIDE_SCOPE_NAMES = NO
HIDE_COMPOUND_REFERENCE= NO
SHOW_INCLUDE_FILES = YES
SHOW_GROUPED_MEMB_INC = NO
FORCE_LOCAL_INCLUDES = NO
INLINE_INFO = YES
SORT_MEMBER_DOCS = YES
SORT_BRIEF_DOCS = NO
SORT_MEMBERS_CTORS_1ST = NO
SORT_GROUP_NAMES = NO
SORT_BY_SCOPE_NAME = NO
STRICT_PROTO_MATCHING = NO
GENERATE_TODOLIST = YES
GENERATE_TESTLIST = YES
GENERATE_BUGLIST = YES
GENERATE_DEPRECATEDLIST= YES
MAX_INITIALIZER_LINES = 30
SHOW_USED_FILES = YES
SHOW_FILES = YES
SHOW_NAMESPACES = YES
QUIET = NO
WARNINGS = YES
BUILTIN_STL_SUPPORT = YES
VERBATIM_HEADERS = YES
WARN_IF_UNDOCUMENTED = YES
WARN_IF_DOC_ERROR = YES
WARN_NO_PARAMDOC = NO
WARN_FORMAT = "$file:$line: $text"
INPUT_ENCODING = UTF-8
RECURSIVE = NO
EXCLUDE_SYMLINKS = NO
EXAMPLE_PATH = examples
EXAMPLE_RECURSIVE = YES
FILTER_SOURCE_FILES = NO
SOURCE_BROWSER = NO
INLINE_SOURCES = YES
SEARCHENGINE = YES
SHOW_FILES = YES
STRIP_CODE_COMMENTS = YES
REFERENCED_BY_RELATION = NO
REFERENCES_RELATION = NO
REFERENCES_LINK_SOURCE = YES
SOURCE_TOOLTIPS = YES
USE_HTAGS = NO
VERBATIM_HEADERS = YES
CLANG_ASSISTED_PARSING = NO
ALPHABETICAL_INDEX = YES
COLS_IN_ALPHA_INDEX = 5
GENERATE_HTML = YES
HTML_OUTPUT = doc/html
HTML_FILE_EXTENSION = .html
HTML_COLORSTYLE_HUE = 220
HTML_COLORSTYLE_SAT = 100
HTML_COLORSTYLE_GAMMA = 80
HTML_TIMESTAMP = NO
HTML_DYNAMIC_SECTIONS = NO
HTML_INDEX_NUM_ENTRIES = 100
GENERATE_DOCSET = NO
DOCSET_FEEDNAME = "Doxygen generated docs"
DOCSET_BUNDLE_ID = org.doxygen.Project
DOCSET_PUBLISHER_ID = org.doxygen.Publisher
DOCSET_PUBLISHER_NAME = Publisher
GENERATE_HTMLHELP = NO
GENERATE_CHI = NO
BINARY_TOC = NO
TOC_EXPAND = NO
GENERATE_QHP = NO
QHP_NAMESPACE = org.doxygen.Project
QHP_VIRTUAL_FOLDER = doc
GENERATE_ECLIPSEHELP = NO
ECLIPSE_DOC_ID = org.doxygen.Project
DISABLE_INDEX = NO
GENERATE_TREEVIEW = NO
ENUM_VALUES_PER_LINE = 4
TREEVIEW_WIDTH = 250
EXT_LINKS_IN_WINDOW = NO
FORMULA_FONTSIZE = 10
FORMULA_TRANSPARENT = YES
USE_MATHJAX = NO
MATHJAX_FORMAT = HTML-CSS
MATHJAX_RELPATH = http://cdn.mathjax.org/mathjax/latest
SEARCHENGINE = NO
SERVER_BASED_SEARCH = NO
EXTERNAL_SEARCH = NO
SEARCHDATA_FILE = searchdata.xml
GENERATE_LATEX = NO
LATEX_OUTPUT = latex
LATEX_CMD_NAME = latex
MAKEINDEX_CMD_NAME = makeindex
COMPACT_LATEX = NO
PAPER_TYPE = a4
PDF_HYPERLINKS = YES
USE_PDFLATEX = YES
LATEX_BATCHMODE = NO
LATEX_HIDE_INDICES = NO
LATEX_SOURCE_CODE = NO
LATEX_BIB_STYLE = plain
GENERATE_RTF = NO
RTF_OUTPUT = rtf
COMPACT_RTF = NO
RTF_HYPERLINKS = NO
RTF_SOURCE_CODE = NO
GENERATE_MAN = NO
MAN_OUTPUT = man
MAN_EXTENSION = .3
MAN_SUBDIR =
MAN_LINKS = NO
GENERATE_XML = NO
XML_OUTPUT = xml
XML_PROGRAMLISTING = YES
GENERATE_DOCBOOK = NO
DOCBOOK_OUTPUT = docbook
DOCBOOK_PROGRAMLISTING = NO
GENERATE_AUTOGEN_DEF = NO
GENERATE_PERLMOD = NO
PERLMOD_LATEX = NO
PERLMOD_PRETTY = YES
ENABLE_PREPROCESSING = YES
MACRO_EXPANSION = NO
EXPAND_ONLY_PREDEF = NO
SEARCH_INCLUDES = YES
SKIP_FUNCTION_MACROS = YES
ALLEXTERNALS = NO
EXTERNAL_GROUPS = YES
EXTERNAL_PAGES = YES
PERL_PATH = /usr/bin/perl
CLASS_DIAGRAMS = YES
HIDE_UNDOC_RELATIONS = YES
HAVE_DOT = NO
DOT_NUM_THREADS = 0
DOT_FONTNAME = Helvetica
DOT_FONTSIZE = 10
CLASS_GRAPH = YES
COLLABORATION_GRAPH = YES
GROUP_GRAPHS = YES
UML_LOOK = NO
UML_LIMIT_NUM_FIELDS = 10
TEMPLATE_RELATIONS = NO
INCLUDE_GRAPH = YES
INCLUDED_BY_GRAPH = YES
CALL_GRAPH = NO
CALLER_GRAPH = NO
GRAPHICAL_HIERARCHY = YES
DIRECTORY_GRAPH = YES
DOT_IMAGE_FORMAT = png
INTERACTIVE_SVG = NO
DOT_GRAPH_MAX_NODES = 50
MAX_DOT_GRAPH_DEPTH = 0
DOT_TRANSPARENT = NO
DOT_MULTI_TARGETS = NO
GENERATE_LEGEND = YES
DOT_CLEANUP = YES

View File

@ -1,194 +0,0 @@
= identiconpp
:toc: preamble
:project: identiconpp
:uri-base: https://schlomp.space/tastytea/{project}
:uri-branch-master: {uri-base}/src/branch/master
:uri-reference-base: https://doc.schlomp.space/{project}
:uri-images-base: {uri-reference-base}
:uri-sigil: https://github.com/cupcake/sigil/
:uri-pydenticon: https://github.com/azaghal/pydenticon/
:uri-overlay: https://schlomp.space/tastytea/overlay
:uri-pgpkey: https://tastytea.de/tastytea_autosign.asc
:uri-gcc: https://gcc.gnu.org/
:uri-clang: https://clang.llvm.org/
:uri-cmake: https://cmake.org/
:uri-imagemagick: https://www.imagemagick.org/
:uri-asciidoc: http://asciidoc.org/
:uri-catch: https://github.com/catchorg/Catch2
*identiconpp* is a library to generate identicons for C++.
You get the images as `Magick::Image`. This allows you to make all kinds of
modifications.
.Used algorithms, left to right: 4x4 ltr_symmetric, 20px padding; 5x5 sigil; 5x5 ltr_asymmetric; 6x4 ltr_symmetric, 10px padding
====
image:{uri-images-base}/identicon1.png[]
image:{uri-images-base}/identicon2.png[]
image:{uri-images-base}/identicon3.png[]
image:{uri-images-base}/identicon4.png[]
The example images above are generated using
link:{uri-branch-master}/examples/example.cpp[example.cpp].
====
== Features
* [x] Symmetric identicons
* [x] sigil identicons
* [x] Asymmetric identicons
* [x] Padding
== Usage
The HTML reference can be generated with `build_doc.sh`, if doxygen is
installed. It is also available at
link:{uri-reference-base}/classIdenticonpp.html[doc.schlomp.space/identiconpp/].
You need to generate hashes yourself, any hexadecimal string will do. Make sure
to use a safe hashing algorithm for sensitive data (*not MD5*). You can select
as many columns and rows as you like, but make sure you have enough entropy.
If something seems to be wrong, exceptions will be thrown.
The "sigil" algorithm generates the same results as link:{uri-sigil}[sigil] and
link:{uri-pydenticon}[pydenticon].
=== Example
[source,c++]
----
// Compile with g++ $(pkg-config --libs --cflags identiconpp)
#include <iostream>
#include <identiconpp.hpp>
#include <Magick++/Image.h>
int main()
{
Identiconpp identicon(5, 5, Identiconpp::algorithm::ltr_symmetric,
"ffffff80", { "800000ff" }, { 10, 10 });
Magick::Image img;
img = identicon.generate("55502f40dc8b7c769880b10874abc9d0", 200);
img.write("identicon.png");
std::cout << identicon.generate_base64("png", "5550", 200) << std::endl;
}
----
== Install
=== Gentoo
Gentoo ebuilds are available via my link:{uri-overlay}[repository].
=== Automatically generated packages
Binary packages are generated automatically for each
link:{uri-base}/releases[release]. They are signed with my
link:{uri-pgpkey}[automatic signing key].
=== From source
==== Dependencies
* C++ compiler (tested: link:{uri-gcc}[gcc] 6/8/9, link:{uri-clang}[clang] 7)
* {uri-cmake}[cmake] (at least 3.6)
* link:{uri-imagemagick}[imagemagick] (tested: 7.0 / 6.7)
* Optional:
** Manpage: {uri-asciidoc}[asciidoc] (tested: 8.6)
** Tests: {uri-catch}[catch] (tested: 2.5 / 1.2)
On a Debian system, install the packages:
`build-essential cmake libmagick++-dev`.
==== Compile
[source,shell]
----
mkdir build
cd build
cmake ..
cmake --build .
make install
----
.cmake options:
* `-DCMAKE_BUILD_TYPE=Debug` for a debug build
* `-DWITH_TESTS=YES` to build tests
* One of:
** `-DWITH_DEB=YES` to generate a deb-package
** `-DWITH_RPM=YES` to generate an rpm-package
To generate a binary package, run `make package`.
include::{uri-base}/raw/branch/master/CONTRIBUTING.adoc[]
== Algorithms
=== ltr_symmetric
* Create image with width=columns, height=rows.
* Set background color.
* Select half of the columns, or half of the columns + 1 if uneven.
** `columns / 2 + columns % 2`
* Pixels are drawn from left to right, top to bottom.
* Use bits from digest to determine if a pixel is painted(1) or not(0).
* Mirror the pixels vertically.
* Use the following bits to pick the foreground color.
** You need `floor(log2(n_colors)) + 1` bits.
* Scale image proportionally to requested width.
----
0111 0011 1101 1100 […] 1111 0111 0101 0111
^ ^
+----------------------------+-------------->
| |
pixel matrix foreground color
----
Implemented in
link:{uri-branch-master}/src/ltr_symmetric.cpp[ltr_symmetric.cpp].
=== ltr_asymmetric
* Create image with width=columns, height=rows.
* Set background color.
* Pixels are drawn from left to right, top to bottom.
* Use bits from digest to determine if a pixel is painted(1) or not(0).
* Use the following bits to pick the foreground color.
** You need `floor(log2(n_colors)) + 1` bits.
* Scale image proportionally to requested width.
----
0111 0011 1101 1100 […] 1111 0111 0101 0111
^ ^
+----------------------------+-------------->
| |
pixel matrix foreground color
----
Implemented in
link:{uri-branch-master}/src/ltr_asymmetric.cpp[ltr_asymmetric.cpp].
=== sigil
* Create image with width=columns, height=rows.
* Set background color.
* Select half of the columns, or half of the columns + 1 if uneven.
** `columns / 2 + columns % 2`
* Pixels are drawn from top to bottom, left to right.
* Use the first 8 bits to pick the foreground color.
* Use the following bits to determine if a pixel is painted(1) or not(0).
* Mirror the pixels vertically.
* Scale image proportionally to requested width.
----
0111 0011 1101 1100
^ ^
+---------+--------->
| |
foreground color |
pixel matrix
----
Implemented in link:{uri-branch-master}/src/sigil.cpp[sigil.cpp].

101
README.md Normal file
View File

@ -0,0 +1,101 @@
**identiconpp** is a library to generate identicons. Written in C++.
You get the images as `Magick::Image`. This allows you to make all kinds of
modifications.
## Features
* [x] Simple identicons
* [ ] libravatar/sigil identicons
## Usage
The HTML reference can be generated with build_doc.sh, if doxygen is installed.
It is also available at [doc.schlomp.space/identiconpp/]
(https://doc.schlomp.space/identiconpp/classIdenticonpp.html).
### Example
```C++
// Compile with g++ $(Magick++-config --cppflags --ldflags) -lidenticonpp
#include <identiconpp.hpp>
#include <Magick++/Image.h>
int main()
{
Identiconpp identicon(5, 5, Identiconpp::identicon_type::simple,
"ffffff88", { "800000ff" });
Magick::Image img;
img = identicon.generate("55502f40dc8b7c769880b10874abc9d0", 200);
img.write("identicon.png");
}
```
## Install
### Gentoo
Gentoo ebuilds are available via my
[repository](https://schlomp.space/tastytea/overlay).
### Automatically generated packages
Binary packages are generated automatically for each
[release](https://schlomp.space/tastytea/identiconpp/releases) in the
formats:
* deb
* rpm
* tar.gz
They are generated on Debian Stretch 64 bit and signed with my
[automatic signing key](https://tastytea.de/tastytea_autosign.asc).
### From source
#### Dependencies
* C++ compiler (tested: [gcc](https://gcc.gnu.org/) 5/6/7/8,
[clang](https://llvm.org/) 5/6)
* [cmake](https://cmake.org/) (at least 3.2)
* [imagemagick](https://www.imagemagick.org/) (tested: 7.0 / 6.7)
On a Debian system, install the packages:
`build-essential cmake libmagick++-dev`.
#### Compile
```SH
mkdir build
cd build
cmake ..
make
make install
```
##### cmake options
* `-DCMAKE_BUILD_TYPE=Debug` for a debug build
* One of:
* `-DWITH_DEB=YES` to generate a deb-package
* `-DWITH_RPM=YES` to generate an rpm-package
To generate a binary package, execute `make package`
## Contributing
Contributions are always welcome. You can submit them as pull requests or via
email to `tastytea`@`tastytea.de`.
## Contact
See https://tastytea.de/
## License & Copyright
```PLAIN
Copyright © 2018 tastytea <tastytea@tastytea.de>.
License GPLv3: GNU GPL version 3 <https://www.gnu.org/licenses/gpl-3.0.html>.
This program comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to redistribute it under certain conditions.
```

View File

@ -1,7 +1,8 @@
#!/bin/bash
#!/bin/sh
if [[ -f Doxyfile ]]; then
if [ -f Doxyfile ]; then
mkdir -p doc
(doxygen -s -g - && cat Doxyfile && echo -n "PROJECT_NUMBER = " &&
grep -Eo '[0-9]+.[0-9]+.[0-9]+$' CMakeLists.txt) | doxygen -
(cat Doxyfile && echo -n "PROJECT_NUMBER = " &&
grep -Eo '[0-9]+.[0-9]+.[0-9]+$' CMakeLists.txt) \
| doxygen -
fi

View File

@ -1,19 +0,0 @@
include(CMakePackageConfigHelpers)
include(GNUInstallDirs)
write_basic_package_version_file("${PROJECT_NAME}ConfigVersion.cmake"
VERSION ${PACKAGE_VERSION}
COMPATIBILITY ExactVersion) # NOTE: Set to SameMajorVersion when stable.
install(EXPORT ${PROJECT_NAME}Targets
FILE "${PROJECT_NAME}Targets.cmake"
NAMESPACE "${PROJECT_NAME}::"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")
configure_file("${PROJECT_NAME}Config.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" @ONLY)
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")

View File

@ -1,7 +0,0 @@
include(CMakeFindDependencyMacro)
include(GNUInstallDirs)
find_dependency(PkgConfig REQUIRED)
pkg_check_modules(Magick++ REQUIRED IMPORTED_TARGET Magick++)
include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake")

53
example.cpp Normal file
View File

@ -0,0 +1,53 @@
/* This file is part of identiconpp.
* Public Domain / CC-0
*
* Compile with g++ $(Magick++-config --cppflags --ldflags) -lidenticonpp
*/
#include <string>
#include <Magick++/Image.h>
#include "identiconpp.hpp"
int main(int argc, char *argv[])
{
string digest =
"973dfe463ec85785f5f95af5ba3906eedb2d931c24e69824a89ea65dba4e813b";
Magick::Image img;
if (argc > 1)
{
digest = argv[1];
}
{
Identiconpp identicon(13, 10, Identiconpp::identicon_type::simple,
"ffffff88",
{
"000000ff",
"ff0000ff",
"ffff00ff",
"00ff00ff",
"00ffffff",
"0000ffff"
});
img = identicon.generate(digest, 500);
img.write("identicon_example_simple.png");
}
// {
// Identiconpp identicon(10, 10, Identiconpp::identicon_type::libravatar,
// "ffffffff",
// {
// "000000ff",
// "ff0000ff",
// "ffff00ff",
// "00ff00ff",
// "00ffffff",
// "0000ffff"
// });
// img = identicon.generate(digest, 500);
// img.write("identicon_example_libravatar.png");
// }
return 0;
}

View File

@ -1,4 +0,0 @@
# You need to install identiconpp first so that CMake can find it.
find_package(identiconpp REQUIRED CONFIG)
add_executable(example example.cpp)
target_link_libraries(example PRIVATE identiconpp::identiconpp)

View File

@ -1,62 +0,0 @@
/* This file is part of identiconpp.
* Public Domain / CC-0
*
* Compile with g++ $(pkg-config --libs --cflags identiconpp)
*/
#include <string>
#include <vector>
#include "identiconpp.hpp"
#include <Magick++/Image.h>
int main(int argc, char *argv[])
{
// sha256(test@example.com)
std::string digest = "973dfe463ec85785f5f95af5ba3906ee"
"db2d931c24e69824a89ea65dba4e813b";
const std::vector<std::string> colors =
{
"800000ff",
"008000ff",
"000080ff",
"808000ff",
"008080ff",
"800080ff"
};
Magick::Image img;
if (argc > 1)
{
digest = argv[1];
}
{
Identiconpp identicon(4, 4, Identiconpp::algorithm::ltr_symmetric,
"ffffffff", colors, { 20, 20 });
img = identicon.generate(digest , 200);
img.write("identicon1.png");
}
{
Identiconpp identicon(5, 5, Identiconpp::algorithm::sigil,
"00000080", colors);
img = identicon.generate(digest , 200);
img.write("identicon2.png");
}
{
Identiconpp identicon(5, 5, Identiconpp::algorithm::ltr_asymmetric,
"000000ff", colors);
img = identicon.generate(digest , 200);
img.write("identicon3.png");
}
{
Identiconpp identicon(6, 4, Identiconpp::algorithm::ltr_symmetric,
"000000c0", colors, { 10, 10 });
img = identicon.generate(digest , 200);
img.write("identicon4.png");
}
return 0;
}

View File

@ -1,4 +0,0 @@
include(GNUInstallDirs)
install(FILES "identiconpp.hpp"
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")

View File

@ -4,58 +4,42 @@ set(CPACK_PACKAGE_VERSION_MAJOR ${${CMAKE_PROJECT_NAME}_VERSION_MAJOR})
set(CPACK_PACKAGE_VERSION_MINOR ${${CMAKE_PROJECT_NAME}_VERSION_MINOR})
set(CPACK_PACKAGE_VERSION_PATCH ${${CMAKE_PROJECT_NAME}_VERSION_PATCH})
set(CPACK_PACKAGE_VERSION ${${CMAKE_PROJECT_NAME}_VERSION})
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY
"Library to generate identicons for C++ and C.")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Library to generate identicons. Written in C++.")
set(CPACK_PACKAGE_CONTACT "tastytea <tastytea@tastytea.de>")
set(CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/LICENSE")
set(CPACK_RESOURCE_FILE_README "${PROJECT_SOURCE_DIR}/README.adoc")
set(CPACK_RESOURCE_FILE_README "${PROJECT_SOURCE_DIR}/README.md")
list(APPEND CPACK_SOURCE_IGNORE_FILES "/\\\\.git"
"/.gitignore"
"/build/"
"/doc/"
"/.drone.yml"
"/.dir-locals.el")
"/.gitignore"
"/build/"
"/doc/"
"\\\\.sublime-"
"/.drone.yml")
execute_process(COMMAND uname -m
OUTPUT_VARIABLE CPACK_PACKAGE_ARCHITECTURE
OUTPUT_STRIP_TRAILING_WHITESPACE)
OUTPUT_VARIABLE CPACK_PACKAGE_ARCHITECTURE
OUTPUT_STRIP_TRAILING_WHITESPACE)
set(CPACK_PACKAGE_FILE_NAME
"${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}_${CPACK_PACKAGE_ARCHITECTURE}")
"${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}_${CPACK_PACKAGE_ARCHITECTURE}")
set(CPACK_GENERATOR "TGZ")
set(CPACK_SOURCE_GENERATOR "TGZ")
if (WITH_DEB)
set(CPACK_GENERATOR "DEB")
set(CPACK_DEBIAN_PACKAGE_HOMEPAGE
"https://schlomp.space/tastytea/${CMAKE_PROJECT_NAME}")
set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON)
execute_process(COMMAND dpkg --print-architecture
OUTPUT_VARIABLE CPACK_DEBIAN_PACKAGE_ARCHITECTURE
OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND lsb_release --codename --short
OUTPUT_VARIABLE DEBIAN_CODENAME
OUTPUT_STRIP_TRAILING_WHITESPACE)
set(CPACK_PACKAGE_FILE_NAME
"${CPACK_PACKAGE_NAME}_${CPACK_PACKAGE_VERSION}-0_${CPACK_DEBIAN_PACKAGE_ARCHITECTURE}_${DEBIAN_CODENAME}")
set(CPACK_GENERATOR "DEB")
set(CPACK_DEBIAN_PACKAGE_HOMEPAGE "https://schlomp.space/tastytea/${CMAKE_PROJECT_NAME}")
set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON)
execute_process(COMMAND dpkg --print-architecture
OUTPUT_VARIABLE CPACK_DEBIAN_PACKAGE_ARCHITECTURE
OUTPUT_STRIP_TRAILING_WHITESPACE)
set(CPACK_PACKAGE_FILE_NAME
"${CPACK_PACKAGE_NAME}_${CPACK_PACKAGE_VERSION}-0_${CPACK_DEBIAN_PACKAGE_ARCHITECTURE}")
endif()
if (WITH_RPM)
set(CPACK_GENERATOR "RPM")
set(CPACK_RPM_PACKAGE_LICENSE "GPL-3")
set(CPACK_RPM_PACKAGE_URL
"https://schlomp.space/tastytea/${CMAKE_PROJECT_NAME}")
set(CPACK_RPM_PACKAGE_REQUIRES "libMagick++")
set(CPACK_PACKAGE_FILE_NAME
"${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-0.${CPACK_PACKAGE_ARCHITECTURE}")
execute_process(COMMAND lsb_release --id --short
OUTPUT_VARIABLE OS
OUTPUT_STRIP_TRAILING_WHITESPACE)
if("${OS}" STREQUAL "CentOS")
execute_process(COMMAND rpm -E %{rhel}
OUTPUT_VARIABLE OS_RELEASE
OUTPUT_STRIP_TRAILING_WHITESPACE)
set(CPACK_GENERATOR "RPM")
set(CPACK_RPM_PACKAGE_LICENSE "GPL-3")
set(CPACK_RPM_PACKAGE_URL "https://schlomp.space/tastytea/${CMAKE_PROJECT_NAME}")
set(CPACK_RPM_PACKAGE_REQUIRES "libMagick++, libxdg-basedir >= 1.2.0")
set(CPACK_PACKAGE_FILE_NAME
"${CPACK_PACKAGE_FILE_NAME}.centos${OS_RELEASE}")
endif()
"${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-0.${CPACK_PACKAGE_ARCHITECTURE}")
endif()
include(CPack)

View File

@ -1,7 +0,0 @@
include(GNUInstallDirs)
configure_file("${PROJECT_NAME}.pc.in"
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc" @ONLY)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")

View File

@ -1,12 +0,0 @@
name=@PROJECT_NAME@
prefix=@CMAKE_INSTALL_PREFIX@
exec_prefix=${prefix}
libdir=${prefix}/@CMAKE_INSTALL_LIBDIR@
includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@
Name: ${name}
Description: @PROJECT_DESCRIPTION@
Version: @PROJECT_VERSION@
Libs: -L${libdir} -l${name}
Cflags: -I${includedir}
Requires: Magick++

View File

@ -1,25 +0,0 @@
include(GNUInstallDirs)
find_package(PkgConfig REQUIRED)
pkg_check_modules(Magick++ REQUIRED IMPORTED_TARGET Magick++)
file(GLOB sources *.cpp)
add_library(${PROJECT_NAME}
${sources} ${PROJECT_SOURCE_DIR}/include/${PROJECT_NAME}.hpp)
set_target_properties(${PROJECT_NAME} PROPERTIES
VERSION ${PROJECT_VERSION}
SOVERSION ${${PROJECT_NAME}_VERSION_MAJOR})
target_include_directories(${PROJECT_NAME}
PUBLIC
"$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>"
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>")
target_link_libraries(${PROJECT_NAME} PUBLIC PkgConfig::Magick++)
install(TARGETS ${PROJECT_NAME}
EXPORT "${PROJECT_NAME}Targets"
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})

View File

@ -17,49 +17,29 @@
#include <exception>
#include <stdexcept>
#include <algorithm>
#include <cmath>
#include "identiconpp.hpp"
#include "debug.hpp"
void Identiconpp::check_entropy(const string &digest, algorithm type)
void Identiconpp::check_entropy(const string &digest, identicon_type type)
{
if (std::any_of(digest.begin(), digest.end(), not_hex))
{
throw std::invalid_argument
(
"Digests must consist of hexadecimal digits (" + digest + ")."
);
}
uint16_t entropy_provided = 0;
uint16_t entropy_required = 0;
uint16_t entropy_provided;
uint16_t entropy_required;
switch (type)
{
case algorithm::ltr_symmetric:
case identicon_type::simple:
{
// Every char is 4 bit
entropy_provided = digest.length() * 4;
// We need bits for each field in half of the columns, +1 column if
// they are uneven. Then we need enough bits to pick a color.
entropy_required = (_columns / 2 + _columns % 2) * _rows
+ std::floor(std::log2(_foreground.size())) + 1;
+ (_foreground.size() / 2 + _foreground.size() % 2);
break;
}
case algorithm::ltr_asymmetric:
case identicon_type::libravatar:
case identicon_type::sigil:
{
entropy_provided = digest.length() * 4;
entropy_required = _columns * _rows
+ std::floor(std::log2(_foreground.size())) + 1;
break;
}
case algorithm::sigil:
{
if (_foreground.size() > 256)
{
throw std::invalid_argument(
"sigil algorithm does not support more than 256 colors.");
}
entropy_provided = digest.length() * 4;
entropy_provided = digest.length() / 2 * 8;
entropy_required = (_columns / 2 + _columns % 2) * _rows + 8;
break;
}
@ -81,10 +61,6 @@ bool Identiconpp::not_hex(const char c)
{ // a-f
return false;
}
if (c >= 0x41 && c <= 0x46)
{ // A-F
return false;
}
if (c >= 0x30 && c <= 0x39)
{ // 0-9
return false;

View File

@ -1,6 +1,6 @@
/* This file is part of identiconpp.
* Copyright © 2018 tastytea <tastytea@tastytea.de>
*
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
@ -18,6 +18,9 @@
#define DEBUG_HPP
#include <iostream>
#include <exception>
#include <stdexcept>
#include <sstream>
#ifdef DEBUG
#define ttdebug std::cerr << "[" << __FILE__ << ":" << __LINE__ << "] DEBUG: "

View File

@ -17,94 +17,47 @@
#include <exception>
#include <stdexcept>
#include <sstream>
#include <cmath>
#include <Magick++/Blob.h>
#include <bitset>
#include "identiconpp.hpp"
#include "debug.hpp"
Identiconpp::Identiconpp(const uint8_t columns, const uint8_t rows,
algorithm type,
Identiconpp::Identiconpp(const uint8_t rows, const uint8_t columns,
identicon_type type,
const string &background,
const vector<string> &foreground,
const array<uint8_t, 2> &padding)
const vector<string> &foreground)
: _rows(rows)
, _columns(columns)
, _type(type)
, _background(background)
, _foreground(foreground)
, _padding(padding)
{
check_color(_background);
check_color(background);
for (const string &color : _foreground)
for (const string &color : foreground)
{
check_color(color);
}
if (_foreground.size() == 0)
{
throw std::invalid_argument
(
"You must specify at least 1 foreground color."
);
}
}
Magick::Image Identiconpp::generate(const string &digest, const uint16_t width)
{
ttdebug << "Using digest: " << digest << '\n';
check_entropy(digest, _type);
const std::int16_t imgwidth = width - _padding[0] * 2;
const std::int16_t imgheight =
std::round(static_cast<float>(imgwidth) / _columns * _rows);
ttdebug << "width: " << std::to_string(imgwidth)
<< "+" << std::to_string(_padding[0] * 2)
<< ", height: " << std::to_string(imgheight)
<< "+" << std::to_string(_padding[1] * 2)
<< "\n";
if (imgwidth <= 0 || imgheight <= 0)
{
throw std::invalid_argument("Width or height is zero or less.");
}
Magick::Image img;
const uint16_t height = width / _columns * _rows;
ttdebug << "width: " << std::to_string(width)
<< ", height: " << std::to_string(height) << "\n";
switch (_type)
{
case algorithm::ltr_symmetric:
case identicon_type::simple:
{
img = generate_ltr_symmetric(digest);
break;
return generate_simple(digest, width, height);
}
case algorithm::ltr_asymmetric:
case identicon_type::libravatar:
case identicon_type::sigil:
{
img = generate_ltr_asymmetric(digest);
break;
}
case algorithm::sigil:
{
img = generate_sigil(digest);
break;
return generate_libravatar(digest, width, height);
}
}
img.scale(Magick::Geometry(imgwidth, imgheight));
// The CompositeOperator prevents the background color to be affected by the
// frame color. See https://github.com/ImageMagick/ImageMagick/issues/647
img.compose(Magick::CompositeOperator::CopyCompositeOp);
img.matteColor(Magick::Color('#' + _background));
img.frame(Magick::Geometry(_padding[0], _padding[1]));
return img;
}
const string Identiconpp::generate_base64(const string &magick,
const string &digest,
const uint16_t width)
{
Magick::Image img = generate(digest, width);
Magick::Blob blob;
img.magick(magick);
img.write(&blob);
return blob.base64();
}
bool Identiconpp::get_bit(const uint16_t bit, const string &digest)
@ -112,14 +65,14 @@ bool Identiconpp::get_bit(const uint16_t bit, const string &digest)
std::stringstream ss;
ss << std::hex << digest[bit / 4];
// std::stringstream does not support writing into uint8_t
unsigned short nibble;
ss >> nibble;
// Shift nibble to the right until the bit we want is on the right border.
// Then check if it is set.
if (nibble >> (3 - bit % 4) & 1)
unsigned short buf;
ss >> buf;
std::bitset<4> nibble(buf);
if (nibble[bit % 4])
{
ttdebug << "Bit " << std::to_string(bit + 1) << " is set.\n";
ttdebug << "Bit " << std::to_string(bit) << " is set in "
<< digest << ".\n";
return true;
}
@ -130,7 +83,7 @@ Magick::Color Identiconpp::get_color(const uint16_t firstbit,
const string &digest)
{
// Number of bits to use
const uint16_t colorbits = std::floor(std::log2(_foreground.size())) + 1;
const uint16_t colorbits = _foreground.size() / 2 + _foreground.size() % 2;
// Extract approximation
std::stringstream ss;
@ -142,23 +95,18 @@ Magick::Color Identiconpp::get_color(const uint16_t firstbit,
{
ss << std::hex << digest.substr(firstbit / 4, colorbits / 4 + 1);
}
// std::stringstream does not support writing into uint16_t
unsigned short bits;
ss >> bits;
// Get rid of excess bits
bits = bits & (1 << colorbits) - 1;
// Shift an one $colorbits times to the left, substract 1. This leaves us
// with $colorbits ones. Then AND bits and our ones to keep only as many
// bits as we need.
bits = bits & ((1 << colorbits) - 1);
// We may get a number that is slightly too big if _foreground.size() is not
// a power of 2.
if (bits > (_foreground.size() - 1))
if (bits > _foreground.size())
{
bits -= _foreground.size();
}
// Lookup und set color
ttdebug << "Color: #" << _foreground[bits] << '\n';
return Magick::Color("#" + _foreground[bits]);
ttdebug << "Color: #" << _foreground[bits - 1] << '\n';
return Magick::Color("#" + _foreground[bits - 1]);
}

View File

@ -1,5 +1,5 @@
/* This file is part of identiconpp.
* Copyright © 2018, 2019 tastytea <tastytea@tastytea.de>
* Copyright © 2018 tastytea <tastytea@tastytea.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -14,24 +14,15 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef IDENTICONPP_HPP
#define IDENTICONPP_HPP
#include <cstdint>
#include <string>
#include <vector>
#include <array>
#include <Magick++/Image.h>
using std::uint8_t;
using std::uint16_t;
using std::string;
using std::vector;
using std::array;
/*!
* @example example.cpp
*/
/*!
* @brief Base class for identiconpp.
@ -42,21 +33,15 @@ using std::array;
class Identiconpp
{
public:
friend class Testiconpp;
/*!
* @brief List of identicon algorithms
* @brief List of identicon types
*
* libravatar and sigil are synonymous.
*/
enum class algorithm
enum class identicon_type
{
//! Generates symmetric (vertically mirrored) identicons.
ltr_symmetric,
//! Generates asymmetric identicons.
ltr_asymmetric,
/*!
* Generates the same results as
* [sigil](https://github.com/cupcake/sigil/) and
* [pydenticon](https://github.com/azaghal/pydenticon/).
*/
simple,
libravatar,
sigil
};
@ -67,99 +52,59 @@ public:
* image formats and sizes. The colors must consist of exactly 8
* digits.
*
* @param columns Number of columns
* @param rows Number of rows
* @param type The algorithm to use
* @param columns Number of columns
* @param type The type of identicon
* @param background Background color, hexadecimal, rrggbbaa
* @param foreground vector of foreground colors
* @param padding Padding in pixels { left & right, top & down }
*
* @since before 0.5.0
*/
explicit Identiconpp(const uint8_t columns, const uint8_t rows,
algorithm type = algorithm::ltr_symmetric,
explicit Identiconpp(const uint8_t rows, const uint8_t columns,
identicon_type type = identicon_type::simple,
const string &background = "ffffffff",
const vector<string> &foreground = { "000000ff" },
const array<uint8_t, 2> &padding = { 0, 0 });
const vector<string> &foreground = { "000000ff" } );
/*!
* @brief Generates identicon from digest.
*
* @param digest The pre-computed digest
* @param width The width of the image in pixels
* @param width The width of the image
*
* @return The image as Magick::Image
*
* @since before 0.5.0
* @return The image
*/
Magick::Image generate(const string &digest, const uint16_t width = 100);
/*!
* @brief Generates identicon from digest.
*
* @param magick See http://imagemagick.org/script/formats.php
* @param digest The pre-computed digest
* @param width The width of the image in pixels
*
* @return The image as base64-string
*
* @since 0.5.0
*/
const string generate_base64(const string &magick, const string &digest,
const uint16_t width = 100);
private:
const uint8_t _rows;
const uint8_t _columns;
const algorithm _type;
const identicon_type _type;
const string _background;
const vector<string> _foreground;
const array<uint8_t, 2> _padding;
/*!
* @brief Generate ltr_symmetric identicon.
*
* Use bits 0 to (_columns / 2 + _columns % 2) * _rows, use the
* following bits to determine foreground color. Squares are drawn
* from left to right, top to bottom.
* @brief Generate simple identicon.
*
* @param digest The pre-computed digest
* @param width The width of the image
* @param height The height of the image
*
* @return The image
*
* @since before 0.5.0
*/
Magick::Image generate_ltr_symmetric(const string &digest);
Magick::Image generate_simple(const string &digest,
const uint16_t width,
const uint16_t height);
/*!
* @brief Generate ltr_asymmetric identicon.
*
* Use bits 0 to _columns * _rows, use the following bits to
* determine foreground color. Squares are drawn from left to
* right, top to bottom.
* @brief Generate libravatar-style / sigil identicon.
*
* @param digest The pre-computed digest
* @param width The width of the image
* @param height The height of the image
*
* @return The image
*
* @since before 0.5.0
*/
Magick::Image generate_ltr_asymmetric(const string &digest);
/*!
* @brief Generate sigil identicon.
*
* Use bits 9 to (_columns / 2 + _columns % 2) * _rows, use the
* first 8 bits to determine foreground color. Squares are drawn
* from top to bottom, left to right.
*
* @param digest The pre-computed digest
*
* @return The image
*
* @since before 0.5.0
*/
Magick::Image generate_sigil(const string &digest);
Magick::Image generate_libravatar(const string &digest,
const uint16_t width,
const uint16_t height);
/*!
* @brief Check if the digest contains enough entropy.
@ -168,10 +113,8 @@ private:
*
* @param digest The pre-computed digest
* @param type The type of identicon
*
* @since before 0.5.0
*/
void check_entropy(const string &digest, algorithm type);
void check_entropy(const string &digest, identicon_type type);
/*!
* @brief Determines if the n-th bit of passed digest is 1 or 0.
@ -180,8 +123,6 @@ private:
* @param digest The digest
*
* @return The bit.
*
* @since before 0.5.0
*/
bool get_bit(const uint16_t bit, const string &digest);
@ -194,8 +135,6 @@ private:
* @param digest The digest
*
* @return A foreground color.
*
* @since before 0.5.0
*/
Magick::Color get_color(const uint16_t firstbit, const string &digest);
@ -205,8 +144,6 @@ private:
* @param c Character to check
*
* @return true if not hex.
*
* @since before 0.5.0
*/
static bool not_hex(const char c);
@ -214,10 +151,6 @@ private:
* @brief Performs checks on a color definition in a string.
*
* @param color The color as string
*
* @since before 0.5.0
*/
void check_color(const string &color);
};
#endif // IDENTICONPP_HPP

View File

@ -17,24 +17,12 @@
#include "identiconpp.hpp"
#include "debug.hpp"
Magick::Image Identiconpp::generate_ltr_asymmetric(const string &digest)
Magick::Image Identiconpp::generate_libravatar(const string &digest,
const uint16_t width,
const uint16_t height)
{
throw "Not implemented.";
Magick::Image img(Magick::Geometry(_columns, _rows),
Magick::Color('#' + _background));
Magick::Color dotcolor = get_color(_columns * _rows + 1, digest);
for (uint8_t row = 0; row < _rows; ++row)
{
for (uint8_t column = 0; column < _columns; ++column)
{
if (get_bit(row * _columns + column, digest))
{
ttdebug << "col=" << std::to_string(column)
<< ", row=" << std::to_string(row) << '\n';
img.pixelColor(column, row, dotcolor);
}
}
}
Magick::Color("#" + _background));
return img;
}

View File

@ -1,42 +0,0 @@
/* This file is part of identiconpp.
* Copyright © 2018 tastytea <tastytea@tastytea.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "identiconpp.hpp"
#include "debug.hpp"
Magick::Image Identiconpp::generate_sigil(const string &digest)
{
Magick::Image img(Magick::Geometry(_columns, _rows),
Magick::Color('#' + _background));
Magick::Color dotcolor = get_color(0, digest);
uint8_t used_columns = _columns / 2 + _columns % 2;
uint8_t cells = _rows * used_columns;
for (uint8_t cur_cell = 0; cur_cell < cells; ++cur_cell)
{
if (get_bit(8 + cur_cell, digest))
{
const uint8_t column = cur_cell / _columns;
const uint8_t row = cur_cell % _rows;
ttdebug << "col=" << std::to_string(column)
<< ", row=" << std::to_string(row) << '\n';
img.pixelColor(column, row, dotcolor);
img.pixelColor(_columns - column - 1, row, dotcolor);
}
}
return img;
}

View File

@ -17,10 +17,12 @@
#include "identiconpp.hpp"
#include "debug.hpp"
Magick::Image Identiconpp::generate_ltr_symmetric(const string &digest)
Magick::Image Identiconpp::generate_simple(const string &digest,
const uint16_t width,
const uint16_t height)
{
Magick::Image img(Magick::Geometry(_columns, _rows),
Magick::Color('#' + _background));
Magick::Color("#" + _background));
uint8_t used_columns = _columns / 2 + _columns % 2;
Magick::Color dotcolor = get_color(used_columns * _rows + 1, digest);
@ -32,11 +34,15 @@ Magick::Image Identiconpp::generate_ltr_symmetric(const string &digest)
{
ttdebug << "col=" << std::to_string(column)
<< ", row=" << std::to_string(row) << '\n';
ttdebug << "col=" << std::to_string(used_columns - 1 + column)
<< ", row=" << std::to_string(_rows - 1 - row) << '\n';
img.pixelColor(column, row, dotcolor);
img.pixelColor(_columns - 1 - column, row, dotcolor);
}
}
}
img.scale(Magick::Geometry(width, height));
img.magick("png");
return img;
}

View File

@ -1,24 +0,0 @@
include(CTest)
file(GLOB sources_tests test_*.cpp)
find_package(Catch2)
if(Catch2_FOUND) # Catch 2.x
include(Catch)
add_executable(all_tests main.cpp ${sources_tests})
target_link_libraries(all_tests Catch2::Catch2 ${PROJECT_NAME})
target_include_directories(all_tests PRIVATE "/usr/include/catch2")
catch_discover_tests(all_tests EXTRA_ARGS "${EXTRA_TEST_ARGS}")
else() # Catch 1.x
if(EXISTS "/usr/include/catch.hpp")
message(STATUS "Catch 1.x found.")
foreach(src ${sources_tests})
get_filename_component(bin ${src} NAME_WE)
add_executable(${bin} main.cpp ${src})
target_link_libraries(${bin} ${PROJECT_NAME})
add_test(${bin} ${bin} "${EXTRA_TEST_ARGS}")
endforeach()
else()
message(FATAL_ERROR
"Neither Catch 2.x nor Catch 1.x could be found.")
endif()
endif()

View File

@ -1,2 +0,0 @@
#define CATCH_CONFIG_MAIN
#include <catch.hpp>

View File

@ -1,166 +0,0 @@
#include <catch.hpp>
#include <string>
#include <vector>
#include <exception>
#include "identiconpp.hpp"
using std::string;
class Testiconpp : private Identiconpp
{
public:
explicit Testiconpp(const uint8_t columns, const uint8_t rows,
const Identiconpp::algorithm &type,
const vector<string> &foreground = { "000000ff" })
: Identiconpp(columns, rows, type, "ffffffff", foreground) {};
bool test_check_entropy(const string &digest)
{
try
{
check_entropy(digest, _type);
}
catch (const std::exception &e)
{
return false;
}
return true;
}
};
SCENARIO("Entropy checks: ltr_symmetric", "[checks][ltr_symmetric]")
{
WHEN("An Identiconpp instance with 1x3 dots")
{
Testiconpp testicon(1, 3, Identiconpp::algorithm::ltr_symmetric);
THEN("Required entropy is <= 4")
{
REQUIRE(testicon.test_check_entropy("f"));
}
}
WHEN("An Identiconpp instance with 14x1 dots")
{
Testiconpp testicon(14, 1, Identiconpp::algorithm::ltr_symmetric);
THEN("Required entropy is <= 8")
{
REQUIRE(testicon.test_check_entropy("ff"));
}
}
WHEN("An Identiconpp instance with 255x255 dots")
{
Testiconpp testicon(255, 255, Identiconpp::algorithm::ltr_symmetric);
THEN("Required entropy is <= 32644")
{
string digest(8161, 'c');
REQUIRE(testicon.test_check_entropy(digest));
}
}
WHEN("An Identiconpp instance with 7 colors")
{
std::vector<string> colors(7, "000000ff");
Testiconpp testicon(1, 1, Identiconpp::algorithm::ltr_symmetric,
colors);
THEN("Required entropy is <= 4")
{
REQUIRE(testicon.test_check_entropy("f"));
}
}
WHEN("An Identiconpp instance with 524287 colors")
{
std::vector<string> colors(524287, "000000ff");
Testiconpp testicon(1, 1, Identiconpp::algorithm::ltr_symmetric,
colors);
THEN("Required entropy is <= 20")
{
REQUIRE(testicon.test_check_entropy("fffff"));
}
}
}
SCENARIO("Entropy checks: ltr_asymmetric", "[checks][ltr_asymmetric]")
{
WHEN("An Identiconpp instance with 3x1 dots")
{
Testiconpp testicon(3, 1, Identiconpp::algorithm::ltr_asymmetric);
THEN("Required entropy is <= 4")
{
REQUIRE(testicon.test_check_entropy("f"));
}
}
WHEN("An Identiconpp instance with 14x1 dots")
{
Testiconpp testicon(1, 7, Identiconpp::algorithm::ltr_asymmetric);
THEN("Required entropy is <= 8")
{
REQUIRE(testicon.test_check_entropy("ff"));
}
}
WHEN("An Identiconpp instance with 255x255 dots")
{
Testiconpp testicon(255, 255, Identiconpp::algorithm::ltr_asymmetric);
THEN("Required entropy is <= 65028")
{
string digest(16257, 'c');
REQUIRE(testicon.test_check_entropy(digest));
}
}
WHEN("An Identiconpp instance with 7 colors")
{
std::vector<string> colors(7, "000000ff");
Testiconpp testicon(1, 1, Identiconpp::algorithm::ltr_asymmetric,
colors);
THEN("Required entropy is <= 4")
{
REQUIRE(testicon.test_check_entropy("f"));
}
}
WHEN("An Identiconpp instance with 524287 colors")
{
std::vector<string> colors(524287, "000000ff");
Testiconpp testicon(1, 1, Identiconpp::algorithm::ltr_asymmetric,
colors);
THEN("Required entropy is <= 20")
{
REQUIRE(testicon.test_check_entropy("fffff"));
}
}
}
SCENARIO("Entropy checks: sigil", "[checks][sigil]")
{
WHEN("An Identiconpp instance with 4x2 dots")
{
Testiconpp testicon(4, 2, Identiconpp::algorithm::sigil);
THEN("Required entropy is <= 12")
{
REQUIRE(testicon.test_check_entropy("fff"));
}
}
WHEN("An Identiconpp instance with 4x4 dots")
{
Testiconpp testicon(4, 4, Identiconpp::algorithm::sigil);
THEN("Required entropy is <= 16")
{
REQUIRE(testicon.test_check_entropy("ffff"));
}
}
WHEN("An Identiconpp instance with 255x255 dots")
{
Testiconpp testicon(255, 255, Identiconpp::algorithm::sigil);
THEN("Required entropy is <= 32644")
{
string digest(8162, 'c');
REQUIRE(testicon.test_check_entropy(digest));
}
}
}

View File

@ -1,110 +0,0 @@
#include <catch.hpp>
#include <string>
#include <vector>
#include <exception>
#include "identiconpp.hpp"
using std::string;
class Testiconpp : private Identiconpp
{
public:
explicit Testiconpp()
: Identiconpp(1, 1) {};
bool test_check_not_hex(const char &c)
{
return not_hex(c);
}
};
SCENARIO("Hex checker check", "[checks][hex]")
{
GIVEN("Identiconpp instance")
{
Testiconpp testicon;
WHEN("digit is 0-9")
{
THEN("Return false")
{
for (char c = 0x30; c <= 0x39; ++c)
{
REQUIRE(testicon.test_check_not_hex(c) == false);
}
}
}
WHEN("digit is A-F")
{
THEN("Return false")
{
for (char c = 0x41; c <= 0x46; ++c)
{
REQUIRE(testicon.test_check_not_hex(c) == false);
}
}
}
WHEN("digit is a-f")
{
THEN("Return false")
{
for (char c = 0x61; c <= 0x66; ++c)
{
REQUIRE(testicon.test_check_not_hex(c) == false);
}
}
}
WHEN("digit is 0x00 - 0x29")
{
Testiconpp testicon;
THEN("Return true")
{
for (char c = 0x00; c <= 0x29; ++c)
{
REQUIRE(testicon.test_check_not_hex(c));
}
}
}
WHEN("digit is 0x3a - 0x40")
{
Testiconpp testicon;
THEN("Return true")
{
for (char c = 0x3a; c <= 0x40; ++c)
{
REQUIRE(testicon.test_check_not_hex(c));
}
}
}
WHEN("digit is 0x47 - 0x60")
{
Testiconpp testicon;
THEN("Return true")
{
for (char c = 0x47; c <= 0x60; ++c)
{
REQUIRE(testicon.test_check_not_hex(c));
}
}
}
WHEN("digit is 0x67 - 0x7f")
{
Testiconpp testicon;
THEN("Return true")
{
// We need to use an unsigned char to prevent overflowing
for (unsigned char c = 0x67; c <= 0x7f; ++c)
{
INFO("c=" << (int)c);
REQUIRE(testicon.test_check_not_hex(c));
}
}
}
}
}

View File

@ -1,272 +0,0 @@
#include <catch.hpp>
#include <string>
#include <exception>
#include <vector>
#include <Magick++/Image.h>
#include "identiconpp.hpp"
using std::string;
SCENARIO("Please do not crash")
{
GIVEN("The digest: sha256(test@example.com)")
{
string digest = "973dfe463ec85785f5f95af5ba3906ee"
"db2d931c24e69824a89ea65dba4e813b";
bool exception = false;
WHEN("256 bits of entropy is required")
{
try
{
Identiconpp identicon(18, 28,
Identiconpp::algorithm::ltr_symmetric,
"ffffffff",
{
"000000ff", "000000ff", "000000ff",
"000000ff", "000000ff", "000000ff",
"000000ff", "000000ff", "000000ff",
"000000ff", "000000ff", "000000ff",
"000000ff", "000000ff", "000000ff"
});
identicon.generate(digest);
}
catch (const std::exception &e)
{
exception = true;
}
THEN("Does not crash")
{
REQUIRE(exception == false);
}
}
WHEN("sigil is fed exactly 8 bit of colors")
{
try
{
std::vector<string> colors(256, "000000ff");
Identiconpp identicon(1, 1,
Identiconpp::algorithm::sigil,
"ffffffff", colors);
identicon.generate(digest);
}
catch (const std::exception &e)
{
exception = true;
}
THEN("Does not crash")
{
REQUIRE(exception == false);
}
}
WHEN("colors with uppercase hex digits")
{
try
{
Identiconpp identicon(1, 1, Identiconpp::algorithm::sigil,
"FF00FFFF");
identicon.generate(digest);
}
catch (const std::exception &e)
{
exception = true;
}
THEN("Does not crash")
{
REQUIRE(exception == false);
}
}
}
}
SCENARIO("Please crash")
{
GIVEN("The digest: sha256(test@example.com)")
{
string digest = "973dfe463ec85785f5f95af5ba3906ee"
"db2d931c24e69824a89ea65dba4e813b";
bool exception = false;
WHEN("257 bits of entropy is required")
{
try
{
Identiconpp identicon(18, 28,
Identiconpp::algorithm::ltr_symmetric,
"ffffffff",
{
"000000ff", "000000ff", "000000ff",
"000000ff", "000000ff", "000000ff",
"000000ff", "000000ff", "000000ff",
"000000ff", "000000ff", "000000ff",
"000000ff", "000000ff", "000000ff",
"000000ff"
});
identicon.generate(digest);
}
catch (const std::exception &e)
{
exception = true;
}
THEN("Crashes")
{
REQUIRE(exception == true);
}
}
WHEN("sigil is fed more than 8 bit of colors")
{
try
{
std::vector<string> colors(257, "000000ff");
Identiconpp identicon(1, 1,
Identiconpp::algorithm::sigil,
"ffffffff", colors);
identicon.generate(digest);
}
catch (const std::exception &e)
{
exception = true;
}
THEN("Crashes")
{
REQUIRE(exception == true);
}
}
WHEN("background color has too many digits")
{
try
{
Identiconpp identicon(1, 1,
Identiconpp::algorithm::ltr_symmetric,
"ffffffffa");
identicon.generate(digest);
}
catch (const std::exception &e)
{
exception = true;
}
THEN("Crashes")
{
REQUIRE(exception == true);
}
}
WHEN("background color has not enough digits")
{
try
{
Identiconpp identicon(1, 1,
Identiconpp::algorithm::ltr_symmetric,
"fffffff");
identicon.generate(digest);
}
catch (const std::exception &e)
{
exception = true;
}
THEN("Crashes")
{
REQUIRE(exception == true);
}
}
WHEN("Foreground color has too many digits")
{
try
{
Identiconpp identicon(1, 1,
Identiconpp::algorithm::ltr_symmetric,
"ffffffff", { "000000ffa"});
identicon.generate(digest);
}
catch (const std::exception &e)
{
exception = true;
}
THEN("Crashes")
{
REQUIRE(exception == true);
}
}
WHEN("Foreground color has not enough digits")
{
try
{
Identiconpp identicon(1, 1,
Identiconpp::algorithm::ltr_symmetric,
"ffffffff", { "000000f" });
identicon.generate(digest);
}
catch (const std::exception &e)
{
exception = true;
}
THEN("Crashes")
{
REQUIRE(exception == true);
}
}
WHEN("No foreground color")
{
try
{
Identiconpp identicon(1, 1,
Identiconpp::algorithm::ltr_symmetric,
"ffffffff", {});
identicon.generate(digest);
}
catch (const std::exception &e)
{
exception = true;
}
THEN("Crashes")
{
REQUIRE(exception == true);
}
}
WHEN("Non-hex digits in background color")
{
try
{
Identiconpp identicon(1, 1,
Identiconpp::algorithm::ltr_symmetric,
"ffffffgf");
identicon.generate(digest);
}
catch (const std::exception &e)
{
exception = true;
}
THEN("Crashes")
{
REQUIRE(exception == true);
}
}
WHEN("Non-hex digits in foreground color")
{
try
{
Identiconpp identicon(1, 1,
Identiconpp::algorithm::ltr_symmetric,
"ffffffff", { "g00000ff" });
identicon.generate(digest);
}
catch (const std::exception &e)
{
exception = true;
}
THEN("Crashes")
{
REQUIRE(exception == true);
}
}
}
}

View File

@ -1,164 +0,0 @@
#include <catch.hpp>
#include <string>
#include <Magick++/Image.h>
#include "identiconpp.hpp"
using std::string;
SCENARIO("ltr_asymmetric: Correct placement", "[ltr_asymmetric]")
{
GIVEN("An identiconpp instance with 2x2 dots")
{
Identiconpp identicon(2, 2, Identiconpp::algorithm::ltr_asymmetric);
Magick::Image img;
Magick::Color black("#000000ff");
Magick::Color white("#ffffffff");
WHEN("Digest is \"00\"")
{
img = identicon.generate("00", 2);
THEN("Is completely white")
{
REQUIRE(img.pixelColor(0, 0) == white);
REQUIRE(img.pixelColor(0, 1) == white);
REQUIRE(img.pixelColor(1, 0) == white);
REQUIRE(img.pixelColor(1, 1) == white);
}
}
WHEN("Digest is \"ff\"")
{
img = identicon.generate("ff", 2);
THEN("Is completely black")
{
REQUIRE(img.pixelColor(0, 0) == black);
REQUIRE(img.pixelColor(0, 1) == black);
REQUIRE(img.pixelColor(1, 0) == black);
REQUIRE(img.pixelColor(1, 1) == black);
}
}
WHEN("Digest is \"70\"")
{
// 0111 0000 = 01
// 11
img = identicon.generate("70", 2);
THEN("Produces white pixel at 0x0")
{
REQUIRE(img.pixelColor(0, 0) == white);
}
THEN("Produces black pixel at 1x0")
{
REQUIRE(img.pixelColor(1, 0) == black);
}
THEN("Produces black pixel at 1x0")
{
REQUIRE(img.pixelColor(0, 1) == black);
}
THEN("Produces black pixel at 1x1")
{
REQUIRE(img.pixelColor(1, 1) == black);
}
}
WHEN("Digest is \"80\"")
{
// 1000 0000 = 10
// 00
img = identicon.generate("80", 2);
THEN("Produces black pixel at 0x0")
{
REQUIRE(img.pixelColor(0, 0) == black);
}
THEN("Produces white pixel at 1x0")
{
REQUIRE(img.pixelColor(1, 0) == white);
}
THEN("Produces white pixel at 1x0")
{
REQUIRE(img.pixelColor(0, 1) == white);
}
THEN("Produces white pixel at 1x1")
{
REQUIRE(img.pixelColor(1, 1) == white);
}
}
}
}
SCENARIO("ltr_asymmetric: Correct color", "[ltr_asymmetric]")
{
GIVEN("An identiconpp instance with 5 foreground colors")
{
Identiconpp identicon(1, 1, Identiconpp::algorithm::ltr_asymmetric,
"ffffffff",
{
"ff0000ff",
"ffff00ff",
"00ff00ff",
"00ffffff",
"0000ffff"
});
Magick::Image img;
Magick::Color white("#ffffffff");
Magick::Color red("#ff0000ff");
Magick::Color yellow("#ffff00ff");
Magick::Color green("#00ff00ff");
Magick::Color cyan("#00ffffff");
Magick::Color blue("#0000ffff");
WHEN("Digest is \"0\"")
{ // 0000
img = identicon.generate("0", 1);
THEN("Is white")
{
REQUIRE(img.pixelColor(0, 0) == white);
}
}
WHEN("Digest is \"8\"")
{ // 1000
img = identicon.generate("8", 1);
THEN("Is red")
{
REQUIRE(img.pixelColor(0, 0) == red);
}
}
WHEN("Digest is \"9\"")
{ // 1001
img = identicon.generate("9", 1);
THEN("Is yellow")
{
REQUIRE(img.pixelColor(0, 0) == yellow);
}
}
WHEN("Digest is \"a\"")
{ // 1010
img = identicon.generate("a", 1);
THEN("Is green")
{
REQUIRE(img.pixelColor(0, 0) == green);
}
}
WHEN("Digest is \"b\"")
{ // 1011
img = identicon.generate("b", 1);
THEN("Is cyan")
{
REQUIRE(img.pixelColor(0, 0) == cyan);
}
}
WHEN("Digest is \"c\"")
{ // 1100
img = identicon.generate("c", 1);
THEN("Is blue")
{
REQUIRE(img.pixelColor(0, 0) == blue);
}
}
}
}

View File

@ -1,164 +0,0 @@
#include <catch.hpp>
#include <string>
#include <Magick++/Image.h>
#include "identiconpp.hpp"
using std::string;
SCENARIO("ltr_symmetric: Correct placement", "[ltr_symmetric]")
{
GIVEN("An identiconpp instance with 2x2 dots")
{
Identiconpp identicon(2, 2, Identiconpp::algorithm::ltr_symmetric);
Magick::Image img;
Magick::Color black("#000000ff");
Magick::Color white("#ffffffff");
WHEN("Digest is \"0\"")
{
img = identicon.generate("0", 2);
THEN("Is completely white")
{
REQUIRE(img.pixelColor(0, 0) == white);
REQUIRE(img.pixelColor(0, 1) == white);
REQUIRE(img.pixelColor(1, 0) == white);
REQUIRE(img.pixelColor(1, 1) == white);
}
}
WHEN("Digest is \"f\"")
{
img = identicon.generate("f", 2);
THEN("Is completely black")
{
REQUIRE(img.pixelColor(0, 0) == black);
REQUIRE(img.pixelColor(0, 1) == black);
REQUIRE(img.pixelColor(1, 0) == black);
REQUIRE(img.pixelColor(1, 1) == black);
}
}
WHEN("Digest is \"7\"")
{
// 0111 = 00
// 11
img = identicon.generate("7", 2);
THEN("Produces white pixel at 0x0")
{
REQUIRE(img.pixelColor(0, 0) == white);
}
THEN("Produces white pixel at 1x0")
{
REQUIRE(img.pixelColor(1, 0) == white);
}
THEN("Produces black pixel at 1x0")
{
REQUIRE(img.pixelColor(0, 1) == black);
}
THEN("Produces black pixel at 1x1")
{
REQUIRE(img.pixelColor(1, 1) == black);
}
}
WHEN("Digest is \"8\"")
{
// 1000 = 11
// 00
img = identicon.generate("8", 2);
THEN("Produces black pixel at 0x0")
{
REQUIRE(img.pixelColor(0, 0) == black);
}
THEN("Produces black pixel at 1x0")
{
REQUIRE(img.pixelColor(1, 0) == black);
}
THEN("Produces white pixel at 1x0")
{
REQUIRE(img.pixelColor(0, 1) == white);
}
THEN("Produces white pixel at 1x1")
{
REQUIRE(img.pixelColor(1, 1) == white);
}
}
}
}
SCENARIO("ltr_symmetric: Correct color", "[ltr_symmetric]")
{
GIVEN("An identiconpp instance with 5 foreground colors")
{
Identiconpp identicon(1, 1, Identiconpp::algorithm::ltr_symmetric,
"ffffffff",
{
"ff0000ff",
"ffff00ff",
"00ff00ff",
"00ffffff",
"0000ffff"
});
Magick::Image img;
Magick::Color white("#ffffffff");
Magick::Color red("#ff0000ff");
Magick::Color yellow("#ffff00ff");
Magick::Color green("#00ff00ff");
Magick::Color cyan("#00ffffff");
Magick::Color blue("#0000ffff");
WHEN("Digest is \"0\"")
{ // 0000
img = identicon.generate("0", 1);
THEN("Is white")
{
REQUIRE(img.pixelColor(0, 0) == white);
}
}
WHEN("Digest is \"8\"")
{ // 1000
img = identicon.generate("8", 1);
THEN("Is red")
{
REQUIRE(img.pixelColor(0, 0) == red);
}
}
WHEN("Digest is \"9\"")
{ // 1001
img = identicon.generate("9", 1);
THEN("Is yellow")
{
REQUIRE(img.pixelColor(0, 0) == yellow);
}
}
WHEN("Digest is \"a\"")
{ // 1010
img = identicon.generate("a", 1);
THEN("Is green")
{
REQUIRE(img.pixelColor(0, 0) == green);
}
}
WHEN("Digest is \"b\"")
{ // 1011
img = identicon.generate("b", 1);
THEN("Is cyan")
{
REQUIRE(img.pixelColor(0, 0) == cyan);
}
}
WHEN("Digest is \"c\"")
{ // 1100
img = identicon.generate("c", 1);
THEN("Is blue")
{
REQUIRE(img.pixelColor(0, 0) == blue);
}
}
}
}

View File

@ -1,164 +0,0 @@
#include <catch.hpp>
#include <string>
#include <Magick++/Image.h>
#include "identiconpp.hpp"
using std::string;
SCENARIO("sigil: Correct placement", "[sigil]")
{
GIVEN("An identiconpp instance with 2x2 dots")
{
Identiconpp identicon(2, 2, Identiconpp::algorithm::sigil);
Magick::Image img;
Magick::Color black("#000000ff");
Magick::Color white("#ffffffff");
WHEN("Digest is \"000\"")
{
img = identicon.generate("000", 2);
THEN("Is completely white")
{
REQUIRE(img.pixelColor(0, 0) == white);
REQUIRE(img.pixelColor(0, 1) == white);
REQUIRE(img.pixelColor(1, 0) == white);
REQUIRE(img.pixelColor(1, 1) == white);
}
}
WHEN("Digest is \"fff\"")
{
img = identicon.generate("fff", 2);
THEN("Is completely black")
{
REQUIRE(img.pixelColor(0, 0) == black);
REQUIRE(img.pixelColor(0, 1) == black);
REQUIRE(img.pixelColor(1, 0) == black);
REQUIRE(img.pixelColor(1, 1) == black);
}
}
WHEN("Digest is \"007\"")
{
// 0000 0000 0111 = 00
// 11
img = identicon.generate("007", 2);
THEN("Produces white pixel at 0x0")
{
REQUIRE(img.pixelColor(0, 0) == white);
}
THEN("Produces white pixel at 1x0")
{
REQUIRE(img.pixelColor(1, 0) == white);
}
THEN("Produces black pixel at 1x0")
{
REQUIRE(img.pixelColor(0, 1) == black);
}
THEN("Produces black pixel at 1x1")
{
REQUIRE(img.pixelColor(1, 1) == black);
}
}
WHEN("Digest is \"008\"")
{
// 0000 0000 1000 = 11
// 00
img = identicon.generate("008", 2);
THEN("Produces black pixel at 0x0")
{
REQUIRE(img.pixelColor(0, 0) == black);
}
THEN("Produces black pixel at 1x0")
{
REQUIRE(img.pixelColor(1, 0) == black);
}
THEN("Produces white pixel at 1x0")
{
REQUIRE(img.pixelColor(0, 1) == white);
}
THEN("Produces white pixel at 1x1")
{
REQUIRE(img.pixelColor(1, 1) == white);
}
}
}
}
SCENARIO("sigil: Correct color", "[sigil]")
{
GIVEN("An identiconpp instance with 5 foreground colors")
{
Identiconpp identicon(1, 1, Identiconpp::algorithm::sigil,
"ffffffff",
{
"ff0000ff",
"ffff00ff",
"00ff00ff",
"00ffffff",
"0000ffff"
});
Magick::Image img;
Magick::Color white("#ffffffff");
Magick::Color red("#ff0000ff");
Magick::Color yellow("#ffff00ff");
Magick::Color green("#00ff00ff");
Magick::Color cyan("#00ffffff");
Magick::Color blue("#0000ffff");
WHEN("Digest is \"000\"")
{ // 0000 0000 0000
img = identicon.generate("000", 1);
THEN("Is white")
{
REQUIRE(img.pixelColor(0, 0) == white);
}
}
WHEN("Digest is \"008\"")
{ // 0000 0000 1000
img = identicon.generate("008", 1);
THEN("Is red")
{
REQUIRE(img.pixelColor(0, 0) == red);
}
}
WHEN("Digest is \"108\"")
{ // 0001 0000 1000
img = identicon.generate("108", 1);
THEN("Is yellow")
{
REQUIRE(img.pixelColor(0, 0) == yellow);
}
}
WHEN("Digest is \"208\"")
{ // 0010 0000 1000
img = identicon.generate("208", 1);
THEN("Is green")
{
REQUIRE(img.pixelColor(0, 0) == green);
}
}
WHEN("Digest is \"308\"")
{ // 0011 0000 1000
img = identicon.generate("308", 1);
THEN("Is cyan")
{
REQUIRE(img.pixelColor(0, 0) == cyan);
}
}
WHEN("Digest is \"408\"")
{ // 0100 0000 1000
img = identicon.generate("408", 1);
THEN("Is blue")
{
REQUIRE(img.pixelColor(0, 0) == blue);
}
}
}
}