Testing new color configuration -- Refactored ColorGenerator and added HSV15.

This commit is contained in:
Iron Prando da Silva
2021-11-23 12:11:15 +01:00
parent cb26ac5a74
commit f5cbaea0a5
6 changed files with 299 additions and 86 deletions

View File

@@ -76,6 +76,7 @@ add_executable(TraceAnalyzer
data/tracedb.cpp
presentation/tracenavigator.cpp
presentation/util/colorgenerator.cpp
presentation/util/colorobject.cpp
presentation/tracedrawing.cpp
presentation/traceplotitem.cpp
gototimedialog.cpp

View File

@@ -177,16 +177,20 @@ void Phase::drawPhaseDependencies(traceTime begin, traceTime end, double y,
QColor Phase::getColor(const TraceDrawingProperties &drawingProperties) const
{
switch (drawingProperties.colorGrouping)
{
case ColorGrouping::PhaseType:
return getPhaseColor();
case ColorGrouping::Thread:
return ColorGenerator::getColor(static_cast<unsigned int>(transaction.lock()->thread));
case ColorGrouping::AlphaTransaction:
return ColorGenerator::getAlphaColored(transaction.lock()->id);
case ColorGrouping::Transaction: default:
return ColorGenerator::getColor(transaction.lock()->id);
switch (drawingProperties.colorGrouping) {
case ColorGrouping::PhaseType:
return getPhaseColor();
break;
case ColorGrouping::Thread:
return ColorGenerator::getColor(static_cast<unsigned int>(transaction.lock()->thread));
break;
case ColorGrouping::AlphaTransaction:
return ColorGenerator::getAlphaColored(transaction.lock()->id, ColorName::HSV15);
break;
case ColorGrouping::Transaction:
default:
return ColorGenerator::getColor(transaction.lock()->id);
}
}

View File

@@ -38,79 +38,30 @@
#include "colorgenerator.h"
#include <exception>
ColorGenerator::ColorGenerator()
QColor ColorGenerator::getColor(unsigned int i, ColorName color)
{
r[0] = 0xFF;
r[1] = 0x00;
r[2] = 0x00;
r[3] = 0xFF;
g[0] = 0x00;
g[1] = 0xFF;
g[2] = 0x00;
g[3] = 0xFF;
b[0] = 0x00;
b[1] = 0x00;
b[2] = 0xFF;
b[3] = 0x00;
r[4] = 0xFF;
r[5] = 0x00;
r[6] = 0xFF;
r[7] = 0x6B;
g[4] = 0x00;
g[5] = 0xFF;
g[6] = 0xA5;
g[7] = 0x8E;
b[4] = 0xFF;
b[5] = 0xFF;
b[6] = 0x00;
b[7] = 0x23;
r[8] = 0x8A;
r[9] = 0xFF;
r[10] = 0x7C;
r[11] = 0x00;
g[8] = 0x2B;
g[9] = 0xD7;
g[10] = 0xFC;
g[11] = 0x00;
b[8] = 0xE2;
b[9] = 0x00;
b[10] = 0x00;
b[11] = 0x80;
r[12] = 0x80;
r[13] = 0x00;
r[14] = 0xEE;
r[15] = 0xFF;
g[12] = 0x00;
g[13] = 0x80;
g[14] = 0x82;
g[15] = 0x45;
b[12] = 0x00;
b[13] = 0x00;
b[14] = 0xEE;
b[15] = 0x00;
switch(color) {
case ColorName::Default:
return cDefault.getColor(i);
case ColorName::HSV15:
return cHSV15.getColor(i);
}
return {0, 0, 0};
}
QColor ColorGenerator::getColor(unsigned int i)
QColor ColorGenerator::getAlphaColored(unsigned int i, ColorName color)
{
static ColorGenerator gen;
i = i % 16;
QColor result(gen.r[i], gen.g[i], gen.b[i]);
result.setAlpha(130);
return result;
switch(color) {
case ColorName::Default:
return cDefault.getAlphaColored(i);
case ColorName::HSV15:
return cHSV15.getAlphaColored(i);
}
return {0, 0, 0};
}
QColor ColorGenerator::getAlphaColored(unsigned int i)
{
static ColorGenerator gen;
const int minAlpha = 25;
const int alphaLevels = 40 - 255 / minAlpha;
int alpha = minAlpha + (int)(((255. - minAlpha) / alphaLevels) * (i % alphaLevels));
i = (i / alphaLevels) % 16;
QColor result(gen.r[i], gen.g[i], gen.b[i]);
result.setAlpha(alpha);
return result;
}
ColorDefault ColorGenerator::cDefault;
ColorHSV15 ColorGenerator::cHSV15;

View File

@@ -39,21 +39,28 @@
#ifndef COLORGENERATOR_H
#define COLORGENERATOR_H
#include "colorobject.h"
#include <stdint.h>
#include <QColor>
enum ColorName
{
Default,
HSV15
};
class ColorGenerator
{
private:
static constexpr int NumberOfColors = 16;
int r[NumberOfColors];
int g[NumberOfColors];
int b[NumberOfColors];
ColorGenerator();
ColorGenerator() = delete;
static ColorDefault cDefault;
static ColorHSV15 cHSV15;
public:
static QColor getColor(unsigned int i);
static QColor getAlphaColored(unsigned int i);
static QColor getColor(unsigned int i, ColorName color = ColorName::Default);
static QColor getAlphaColored(unsigned int i, ColorName color = ColorName::Default);
};

View File

@@ -0,0 +1,179 @@
/*
* Copyright (c) 2015, Technische Universität Kaiserslautern
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Authors:
* Janik Schlemminger
* Robert Gernhardt
* Matthias Jung
* Iron Prando da Silva
*/
#include "colorobject.h"
QColor ColorObject::getColor(unsigned int i)
{
i = i % numberOfColors;
QColor result(r[i], g[i], b[i]);
result.setAlpha(130);
return result;
}
QColor ColorObject::getAlphaColored(unsigned int i)
{
const int minAlpha = 50;
const int alphaLevels = 20 - 255 / minAlpha;
int alpha = minAlpha + (int)(((255. - minAlpha) / alphaLevels) * (i % alphaLevels));
i = (i / alphaLevels) % numberOfColors;
QColor result(r[i], g[i], b[i]);
result.setAlpha(alpha);
return result;
}
ColorDefault::ColorDefault()
{
numberOfColors = 16;
r.resize(numberOfColors);
g.resize(numberOfColors);
b.resize(numberOfColors);
r[0] = 0xFF;
r[1] = 0x00;
r[2] = 0x00;
r[3] = 0xFF;
g[0] = 0x00;
g[1] = 0xFF;
g[2] = 0x00;
g[3] = 0xFF;
b[0] = 0x00;
b[1] = 0x00;
b[2] = 0xFF;
b[3] = 0x00;
r[4] = 0xFF;
r[5] = 0x00;
r[6] = 0xFF;
r[7] = 0x6B;
g[4] = 0x00;
g[5] = 0xFF;
g[6] = 0xA5;
g[7] = 0x8E;
b[4] = 0xFF;
b[5] = 0xFF;
b[6] = 0x00;
b[7] = 0x23;
r[8] = 0x8A;
r[9] = 0xFF;
r[10] = 0x7C;
r[11] = 0x00;
g[8] = 0x2B;
g[9] = 0xD7;
g[10] = 0xFC;
g[11] = 0x00;
b[8] = 0xE2;
b[9] = 0x00;
b[10] = 0x00;
b[11] = 0x80;
r[12] = 0x80;
r[13] = 0x00;
r[14] = 0xEE;
r[15] = 0xFF;
g[12] = 0x00;
g[13] = 0x80;
g[14] = 0x82;
g[15] = 0x45;
b[12] = 0x00;
b[13] = 0x00;
b[14] = 0xEE;
b[15] = 0x00;
}
ColorHSV15::ColorHSV15()
{
numberOfColors = 15;
r.resize(numberOfColors);
g.resize(numberOfColors);
b.resize(numberOfColors);
r[0] = 0XFF;
r[1] = 0XFF;
r[2] = 0XFF;
r[3] = 0XD1;
r[4] = 0X6C;
r[5] = 0X08;
r[6] = 0X00;
r[7] = 0X00;
r[8] = 0X00;
r[9] = 0X00;
r[10] = 0X00;
r[11] = 0X54;
r[12] = 0XB9;
r[13] = 0XFF;
r[14] = 0XFF;
g[0] = 0X00;
g[1] = 0X64;
g[2] = 0XC9;
g[3] = 0XFF;
g[4] = 0XFF;
g[5] = 0XFF;
g[6] = 0XFF;
g[7] = 0XFF;
g[8] = 0XD9;
g[9] = 0X74;
g[10] = 0X10;
g[11] = 0X00;
g[12] = 0X00;
g[13] = 0X00;
g[14] = 0X00;
b[0] = 0X00;
b[1] = 0X00;
b[2] = 0X00;
b[3] = 0X00;
b[4] = 0X00;
b[5] = 0X00;
b[6] = 0X5C;
b[7] = 0XC1;
b[8] = 0XFF;
b[9] = 0XFF;
b[10] = 0XFF;
b[11] = 0XFF;
b[12] = 0XFF;
b[13] = 0XE1;
b[14] = 0X7C;
}

View File

@@ -0,0 +1,71 @@
/*
* Copyright (c) 2015, Technische Universität Kaiserslautern
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Authors:
* Janik Schlemminger
* Robert Gernhardt
* Matthias Jung
* Iron Prando da Silva
*/
#pragma once
#include <QColor>
class ColorObject
{
protected:
int numberOfColors = 0;
std::vector<int> r;
std::vector<int> g;
std::vector<int> b;
// std::vector<int> a;
ColorObject() {};
public:
virtual QColor getColor(unsigned int i);
virtual QColor getAlphaColored(unsigned int i);
};
class ColorDefault : public ColorObject
{
public:
ColorDefault();
};
class ColorHSV15 : public ColorObject
{
public:
ColorHSV15();
};