qTox  Version: nightly | Commit: bc751c8e1cac455f9690654fcfe0f560d2d7dfdd
identicon.h
Go to the documentation of this file.
1 /*
2  Copyright © 2019 by The qTox Project Contributors
3 
4  This file is part of qTox, a Qt-based graphical interface for Tox.
5 
6  qTox is libre software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  qTox is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with qTox. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #pragma once
21 
22 #include <QColor>
23 #include <QImage>
24 
25 class Identicon
26 {
27 public:
28  Identicon(const QByteArray& data);
29  QImage toImage(int scaleFactor = 1);
30  static float bytesToColor(QByteArray bytes);
31 
32 public:
33  static constexpr int IDENTICON_ROWS = 5;
34  static constexpr int IDENTICON_COLOR_BYTES = 6;
35 
36 private:
37  static constexpr int COLORS = 2;
38  static constexpr int ACTIVE_COLS = (IDENTICON_ROWS + 1) / 2;
39  static constexpr int HASH_MIN_LEN = ACTIVE_COLS * IDENTICON_ROWS
41 
43  QColor colors[COLORS];
44 };
Identicon::colors
QColor colors[COLORS]
Definition: identicon.h:43
Identicon::bytesToColor
static float bytesToColor(QByteArray bytes)
Converts a series of IDENTICON_COLOR_BYTES bytes to a value in the range 0.0..1.0.
Definition: identicon.cpp:95
Identicon::HASH_MIN_LEN
static constexpr int HASH_MIN_LEN
Definition: identicon.h:39
Identicon::Identicon
Identicon(const QByteArray &data)
Creates an Identicon, that visualizes a hash in graphical form.
Definition: identicon.cpp:63
Identicon::IDENTICON_ROWS
static constexpr int IDENTICON_ROWS
Definition: identicon.h:33
Identicon::COLORS
static constexpr int COLORS
Definition: identicon.h:37
Identicon::toImage
QImage toImage(int scaleFactor=1)
Writes the Identicon to a QImage.
Definition: identicon.cpp:121
Identicon::identiconColors
uint8_t identiconColors[IDENTICON_ROWS][ACTIVE_COLS]
Definition: identicon.h:42
Identicon
Definition: identicon.h:25
Identicon::ACTIVE_COLS
static constexpr int ACTIVE_COLS
Definition: identicon.h:38
Identicon::IDENTICON_COLOR_BYTES
static constexpr int IDENTICON_COLOR_BYTES
Definition: identicon.h:34