Moved Line Endings To Unix
This commit is contained in:
parent
0c6a998be6
commit
4b7c8f266f
@ -1,195 +1,195 @@
|
|||||||
#include "colour_extractor.h"
|
#include "colour_extractor.h"
|
||||||
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
// CONSTRUCTORS
|
// CONSTRUCTORS
|
||||||
ColourExtractor::ColourExtractor(size_t h_levels, size_t s_levels,
|
ColourExtractor::ColourExtractor(size_t h_levels, size_t s_levels,
|
||||||
size_t v_levels)
|
size_t v_levels)
|
||||||
:m_pixels(NULL), m_max_colour_count(0), m_h_levels(h_levels),
|
:m_pixels(NULL), m_max_colour_count(0), m_h_levels(h_levels),
|
||||||
m_s_levels(s_levels), m_v_levels(v_levels)
|
m_s_levels(s_levels), m_v_levels(v_levels)
|
||||||
{
|
{
|
||||||
m_pixels = new size_t[m_h_levels * m_s_levels * m_v_levels];
|
m_pixels = new size_t[m_h_levels * m_s_levels * m_v_levels];
|
||||||
memset(m_pixels, 0, m_h_levels * m_s_levels * m_v_levels * sizeof(size_t));
|
memset(m_pixels, 0, m_h_levels * m_s_levels * m_v_levels * sizeof(size_t));
|
||||||
}
|
}
|
||||||
|
|
||||||
// PROTECTED FUNCS
|
// PROTECTED FUNCS
|
||||||
size_t ColourExtractor::quantize(struct ColourHSV hsv) const
|
size_t ColourExtractor::quantize(struct ColourHSV hsv) const
|
||||||
{
|
{
|
||||||
size_t result = 0;
|
size_t result = 0;
|
||||||
|
|
||||||
size_t h_quant = 0;
|
size_t h_quant = 0;
|
||||||
size_t s_quant = 0;
|
size_t s_quant = 0;
|
||||||
size_t v_quant = 0;
|
size_t v_quant = 0;
|
||||||
|
|
||||||
v_quant = static_cast<size_t>(round(hsv.v * (m_v_levels - 1)));
|
v_quant = static_cast<size_t>(round(hsv.v * (m_v_levels - 1)));
|
||||||
if (0 == v_quant)
|
if (0 == v_quant)
|
||||||
{
|
{
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
s_quant = static_cast<size_t>(round(hsv.s * (m_s_levels - 1)));
|
s_quant = static_cast<size_t>(round(hsv.s * (m_s_levels - 1)));
|
||||||
if (0 == s_quant)
|
if (0 == s_quant)
|
||||||
{
|
{
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
h_quant = static_cast<size_t>(round(hsv.h / 360.0 * (m_h_levels - 1)));
|
h_quant = static_cast<size_t>(round(hsv.h / 360.0 * (m_h_levels - 1)));
|
||||||
|
|
||||||
end:
|
end:
|
||||||
result += h_quant;
|
result += h_quant;
|
||||||
|
|
||||||
result *= m_s_levels;
|
result *= m_s_levels;
|
||||||
result += s_quant;
|
result += s_quant;
|
||||||
|
|
||||||
result *= m_v_levels;
|
result *= m_v_levels;
|
||||||
result += v_quant;
|
result += v_quant;
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ColourHSV ColourExtractor::dequantize(size_t colour) const
|
struct ColourHSV ColourExtractor::dequantize(size_t colour) const
|
||||||
{
|
{
|
||||||
struct ColourHSV result;
|
struct ColourHSV result;
|
||||||
size_t h_quant;
|
size_t h_quant;
|
||||||
size_t s_quant;
|
size_t s_quant;
|
||||||
size_t v_quant;
|
size_t v_quant;
|
||||||
|
|
||||||
v_quant = colour % m_v_levels;
|
v_quant = colour % m_v_levels;
|
||||||
colour /= m_v_levels;
|
colour /= m_v_levels;
|
||||||
|
|
||||||
s_quant = colour % m_s_levels;
|
s_quant = colour % m_s_levels;
|
||||||
colour /= m_s_levels;
|
colour /= m_s_levels;
|
||||||
|
|
||||||
h_quant = colour % m_h_levels;
|
h_quant = colour % m_h_levels;
|
||||||
|
|
||||||
result.h = static_cast<double>(h_quant) * 360.0 / (m_h_levels - 1);
|
result.h = static_cast<double>(h_quant) * 360.0 / (m_h_levels - 1);
|
||||||
result.s = static_cast<double>(s_quant) / (m_s_levels - 1);
|
result.s = static_cast<double>(s_quant) / (m_s_levels - 1);
|
||||||
result.v = static_cast<double>(v_quant) / (m_v_levels - 1);
|
result.v = static_cast<double>(v_quant) / (m_v_levels - 1);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// PUBLIC FUNCS
|
// PUBLIC FUNCS
|
||||||
void ColourExtractor::get_quantization_levels(size_t& h_levels,
|
void ColourExtractor::get_quantization_levels(size_t& h_levels,
|
||||||
size_t& s_levels, size_t& v_levels) const
|
size_t& s_levels, size_t& v_levels) const
|
||||||
{
|
{
|
||||||
h_levels = m_h_levels;
|
h_levels = m_h_levels;
|
||||||
s_levels = m_s_levels;
|
s_levels = m_s_levels;
|
||||||
v_levels = m_v_levels;
|
v_levels = m_v_levels;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ColourExtractor::set_quantization_levels(size_t h_levels, size_t s_levels,
|
void ColourExtractor::set_quantization_levels(size_t h_levels, size_t s_levels,
|
||||||
size_t v_levels)
|
size_t v_levels)
|
||||||
{
|
{
|
||||||
delete[] m_pixels;
|
delete[] m_pixels;
|
||||||
|
|
||||||
m_h_levels = h_levels;
|
m_h_levels = h_levels;
|
||||||
m_s_levels = s_levels;
|
m_s_levels = s_levels;
|
||||||
m_v_levels = v_levels;
|
m_v_levels = v_levels;
|
||||||
|
|
||||||
m_pixels = new size_t[m_h_levels * m_s_levels * m_v_levels];
|
m_pixels = new size_t[m_h_levels * m_s_levels * m_v_levels];
|
||||||
memset(m_pixels, 0, m_h_levels * m_s_levels * m_v_levels * sizeof(size_t));
|
memset(m_pixels, 0, m_h_levels * m_s_levels * m_v_levels * sizeof(size_t));
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t ColourExtractor::get_h_quantization_levels() const
|
size_t ColourExtractor::get_h_quantization_levels() const
|
||||||
{
|
{
|
||||||
return m_h_levels;
|
return m_h_levels;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ColourExtractor::set_h_quantization_levels(size_t h_levels)
|
void ColourExtractor::set_h_quantization_levels(size_t h_levels)
|
||||||
{
|
{
|
||||||
delete[] m_pixels;
|
delete[] m_pixels;
|
||||||
|
|
||||||
m_h_levels = h_levels;
|
m_h_levels = h_levels;
|
||||||
|
|
||||||
m_pixels = new size_t[m_h_levels * m_s_levels * m_v_levels];
|
m_pixels = new size_t[m_h_levels * m_s_levels * m_v_levels];
|
||||||
memset(m_pixels, 0, m_h_levels * m_s_levels * m_v_levels * sizeof(size_t));
|
memset(m_pixels, 0, m_h_levels * m_s_levels * m_v_levels * sizeof(size_t));
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t ColourExtractor::get_s_quantization_levels() const
|
size_t ColourExtractor::get_s_quantization_levels() const
|
||||||
{
|
{
|
||||||
return m_s_levels;
|
return m_s_levels;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ColourExtractor::set_s_quantization_levels(size_t s_levels)
|
void ColourExtractor::set_s_quantization_levels(size_t s_levels)
|
||||||
{
|
{
|
||||||
delete[] m_pixels;
|
delete[] m_pixels;
|
||||||
|
|
||||||
m_s_levels = s_levels;
|
m_s_levels = s_levels;
|
||||||
|
|
||||||
m_pixels = new size_t[m_h_levels * m_s_levels * m_v_levels];
|
m_pixels = new size_t[m_h_levels * m_s_levels * m_v_levels];
|
||||||
memset(m_pixels, 0, m_h_levels * m_s_levels * m_v_levels * sizeof(size_t));
|
memset(m_pixels, 0, m_h_levels * m_s_levels * m_v_levels * sizeof(size_t));
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t ColourExtractor::get_v_quantization_levels() const
|
size_t ColourExtractor::get_v_quantization_levels() const
|
||||||
{
|
{
|
||||||
return m_v_levels;
|
return m_v_levels;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ColourExtractor::set_v_quantization_levels(size_t v_levels)
|
void ColourExtractor::set_v_quantization_levels(size_t v_levels)
|
||||||
{
|
{
|
||||||
delete[] m_pixels;
|
delete[] m_pixels;
|
||||||
|
|
||||||
m_v_levels = v_levels;
|
m_v_levels = v_levels;
|
||||||
|
|
||||||
m_pixels = new size_t[m_h_levels * m_s_levels * m_v_levels];
|
m_pixels = new size_t[m_h_levels * m_s_levels * m_v_levels];
|
||||||
memset(m_pixels, 0, m_h_levels * m_s_levels * m_v_levels * sizeof(size_t));
|
memset(m_pixels, 0, m_h_levels * m_s_levels * m_v_levels * sizeof(size_t));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ColourExtractor::add_pixel(struct ColourHSV hsv)
|
void ColourExtractor::add_pixel(struct ColourHSV hsv)
|
||||||
{
|
{
|
||||||
size_t colour_quant;
|
size_t colour_quant;
|
||||||
|
|
||||||
colour_quant = quantize(hsv);
|
colour_quant = quantize(hsv);
|
||||||
m_pixels[colour_quant] += 1;
|
m_pixels[colour_quant] += 1;
|
||||||
|
|
||||||
if (m_max_colour_count < m_pixels[colour_quant])
|
if (m_max_colour_count < m_pixels[colour_quant])
|
||||||
{
|
{
|
||||||
m_max_colour_count = m_pixels[colour_quant];
|
m_max_colour_count = m_pixels[colour_quant];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ColourExtractor::clear_pixels()
|
void ColourExtractor::clear_pixels()
|
||||||
{
|
{
|
||||||
for (size_t i = 0; i < m_h_levels * m_s_levels * m_v_levels; ++i)
|
for (size_t i = 0; i < m_h_levels * m_s_levels * m_v_levels; ++i)
|
||||||
{
|
{
|
||||||
m_pixels[i] = 0;
|
m_pixels[i] = 0;
|
||||||
}
|
}
|
||||||
m_max_colour_count = 0;
|
m_max_colour_count = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ColourHSV ColourExtractor::extract_colour() const
|
struct ColourHSV ColourExtractor::extract_colour() const
|
||||||
{
|
{
|
||||||
struct ColourHSV result = {0.0, 0.0, 0.0};
|
struct ColourHSV result = {0.0, 0.0, 0.0};
|
||||||
struct ColourHSV temp_colour;
|
struct ColourHSV temp_colour;
|
||||||
size_t max_colour_value = 0;
|
size_t max_colour_value = 0;
|
||||||
size_t temp_colour_value;
|
size_t temp_colour_value;
|
||||||
double temp_colour_weight;
|
double temp_colour_weight;
|
||||||
|
|
||||||
for (size_t i = 0; i < m_h_levels * m_s_levels * m_v_levels; ++i)
|
for (size_t i = 0; i < m_h_levels * m_s_levels * m_v_levels; ++i)
|
||||||
{
|
{
|
||||||
if (0 == m_pixels[i])
|
if (0 == m_pixels[i])
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
temp_colour = dequantize(i);
|
temp_colour = dequantize(i);
|
||||||
temp_colour_weight = static_cast<double>(m_pixels[i]);
|
temp_colour_weight = static_cast<double>(m_pixels[i]);
|
||||||
temp_colour_weight /= m_max_colour_count;
|
temp_colour_weight /= m_max_colour_count;
|
||||||
|
|
||||||
temp_colour_value = evaluate_colour(temp_colour, temp_colour_weight);
|
temp_colour_value = evaluate_colour(temp_colour, temp_colour_weight);
|
||||||
if (temp_colour_value > max_colour_value)
|
if (temp_colour_value > max_colour_value)
|
||||||
{
|
{
|
||||||
result = temp_colour;
|
result = temp_colour;
|
||||||
max_colour_value = temp_colour_value;
|
max_colour_value = temp_colour_value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
ColourExtractor::~ColourExtractor()
|
ColourExtractor::~ColourExtractor()
|
||||||
{
|
{
|
||||||
delete[] m_pixels;
|
delete[] m_pixels;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,72 +1,72 @@
|
|||||||
#ifndef COLOUR_EXTRACTOR_H_
|
#ifndef COLOUR_EXTRACTOR_H_
|
||||||
#define COLOUR_EXTRACTOR_H_
|
#define COLOUR_EXTRACTOR_H_
|
||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
#include "colours.h"
|
#include "colours.h"
|
||||||
|
|
||||||
class ColourExtractor
|
class ColourExtractor
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
// Holds all quantized pixels
|
// Holds all quantized pixels
|
||||||
size_t* m_pixels;
|
size_t* m_pixels;
|
||||||
|
|
||||||
// Holds the ammount of the colour that appears the most
|
// Holds the ammount of the colour that appears the most
|
||||||
size_t m_max_colour_count;
|
size_t m_max_colour_count;
|
||||||
|
|
||||||
// Quantization levels for the HSV colours
|
// Quantization levels for the HSV colours
|
||||||
size_t m_h_levels;
|
size_t m_h_levels;
|
||||||
size_t m_s_levels;
|
size_t m_s_levels;
|
||||||
size_t m_v_levels;
|
size_t m_v_levels;
|
||||||
|
|
||||||
// Quantizes the colour
|
// Quantizes the colour
|
||||||
size_t quantize(struct ColourHSV hsv) const;
|
size_t quantize(struct ColourHSV hsv) const;
|
||||||
|
|
||||||
// Dequantizes the colour
|
// Dequantizes the colour
|
||||||
struct ColourHSV dequantize(size_t colour) const;
|
struct ColourHSV dequantize(size_t colour) const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// Evaluates the given colour based on its weight
|
// Evaluates the given colour based on its weight
|
||||||
virtual size_t evaluate_colour(struct ColourHSV hsv, double weight)
|
virtual size_t evaluate_colour(struct ColourHSV hsv, double weight)
|
||||||
const = 0;
|
const = 0;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Params: HSV quantization levels
|
// Params: HSV quantization levels
|
||||||
ColourExtractor(size_t h_levels = 36, size_t s_levels = 10,
|
ColourExtractor(size_t h_levels = 36, size_t s_levels = 10,
|
||||||
size_t v_levels = 10);
|
size_t v_levels = 10);
|
||||||
|
|
||||||
void get_quantization_levels(size_t& h_levels, size_t& s_levels,
|
void get_quantization_levels(size_t& h_levels, size_t& s_levels,
|
||||||
size_t& v_levels) const;
|
size_t& v_levels) const;
|
||||||
|
|
||||||
// Note: clears all pixels
|
// Note: clears all pixels
|
||||||
void set_quantization_levels(size_t h_levels, size_t s_levels,
|
void set_quantization_levels(size_t h_levels, size_t s_levels,
|
||||||
size_t v_levels);
|
size_t v_levels);
|
||||||
|
|
||||||
size_t get_h_quantization_levels() const;
|
size_t get_h_quantization_levels() const;
|
||||||
|
|
||||||
// Note: clears all pixels
|
// Note: clears all pixels
|
||||||
void set_h_quantization_levels(size_t h_levels);
|
void set_h_quantization_levels(size_t h_levels);
|
||||||
|
|
||||||
size_t get_s_quantization_levels() const;
|
size_t get_s_quantization_levels() const;
|
||||||
|
|
||||||
// Note: clears all pixels
|
// Note: clears all pixels
|
||||||
void set_s_quantization_levels(size_t s_levels);
|
void set_s_quantization_levels(size_t s_levels);
|
||||||
|
|
||||||
size_t get_v_quantization_levels() const;
|
size_t get_v_quantization_levels() const;
|
||||||
|
|
||||||
// Note: clears all pixels
|
// Note: clears all pixels
|
||||||
void set_v_quantization_levels(size_t v_levels);
|
void set_v_quantization_levels(size_t v_levels);
|
||||||
|
|
||||||
// Adds a pixel to be considered for extraction
|
// Adds a pixel to be considered for extraction
|
||||||
void add_pixel(struct ColourHSV hsv);
|
void add_pixel(struct ColourHSV hsv);
|
||||||
|
|
||||||
// Clears all pixels
|
// Clears all pixels
|
||||||
void clear_pixels();
|
void clear_pixels();
|
||||||
|
|
||||||
// Extracts a single colour from all added pixels
|
// Extracts a single colour from all added pixels
|
||||||
struct ColourHSV extract_colour() const;
|
struct ColourHSV extract_colour() const;
|
||||||
|
|
||||||
~ColourExtractor();
|
~ColourExtractor();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // COLOUR_EXTRACTOR_H_
|
#endif // COLOUR_EXTRACTOR_H_
|
||||||
|
|||||||
98
colours.h
98
colours.h
@ -1,49 +1,49 @@
|
|||||||
#ifndef COLOURS_H_
|
#ifndef COLOURS_H_
|
||||||
#define COLOURS_H_
|
#define COLOURS_H_
|
||||||
|
|
||||||
struct ColourRGB
|
struct ColourRGB
|
||||||
{
|
{
|
||||||
double r;
|
double r;
|
||||||
double g;
|
double g;
|
||||||
double b;
|
double b;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ColourCMYK
|
struct ColourCMYK
|
||||||
{
|
{
|
||||||
double c;
|
double c;
|
||||||
double m;
|
double m;
|
||||||
double y;
|
double y;
|
||||||
double k;
|
double k;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ColourHSV
|
struct ColourHSV
|
||||||
{
|
{
|
||||||
double h;
|
double h;
|
||||||
double s;
|
double s;
|
||||||
double v;
|
double v;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ColourHSL
|
struct ColourHSL
|
||||||
{
|
{
|
||||||
double h;
|
double h;
|
||||||
double s;
|
double s;
|
||||||
double l;
|
double l;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ColourRGB CMYKtoRGB(struct ColourCMYK cmyk);
|
struct ColourRGB CMYKtoRGB(struct ColourCMYK cmyk);
|
||||||
struct ColourRGB HSVtoRGB(struct ColourHSV hsv);
|
struct ColourRGB HSVtoRGB(struct ColourHSV hsv);
|
||||||
struct ColourRGB HSLtoRGB(struct ColourHSL hsl);
|
struct ColourRGB HSLtoRGB(struct ColourHSL hsl);
|
||||||
|
|
||||||
struct ColourCMYK RGBtoCMYK(struct ColourRGB rgb);
|
struct ColourCMYK RGBtoCMYK(struct ColourRGB rgb);
|
||||||
struct ColourCMYK HSVtoCMYK(struct ColourHSV hsv);
|
struct ColourCMYK HSVtoCMYK(struct ColourHSV hsv);
|
||||||
struct ColourCMYK HSLtoCMYK(struct ColourHSL hsl);
|
struct ColourCMYK HSLtoCMYK(struct ColourHSL hsl);
|
||||||
|
|
||||||
struct ColourHSV RGBtoHSV(struct ColourRGB rgb);
|
struct ColourHSV RGBtoHSV(struct ColourRGB rgb);
|
||||||
struct ColourHSV CMYKtoHSV(struct ColourCMYK cmyk);
|
struct ColourHSV CMYKtoHSV(struct ColourCMYK cmyk);
|
||||||
struct ColourHSV HSLtoHSV(struct ColourHSL hsl);
|
struct ColourHSV HSLtoHSV(struct ColourHSL hsl);
|
||||||
|
|
||||||
struct ColourHSL RGBtoHSL(struct ColourRGB rgb);
|
struct ColourHSL RGBtoHSL(struct ColourRGB rgb);
|
||||||
struct ColourHSL CMYKtoHSL(struct ColourCMYK cmyk);
|
struct ColourHSL CMYKtoHSL(struct ColourCMYK cmyk);
|
||||||
struct ColourHSL HSVtoHSL(struct ColourHSV hsv);
|
struct ColourHSL HSVtoHSL(struct ColourHSV hsv);
|
||||||
|
|
||||||
#endif // COLOURS_H_
|
#endif // COLOURS_H_
|
||||||
|
|||||||
@ -1,55 +1,55 @@
|
|||||||
#include "complimentary_colour_extractor.h"
|
#include "complimentary_colour_extractor.h"
|
||||||
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
// CONSTRUCTORS
|
// CONSTRUCTORS
|
||||||
ComplimentaryColourExtractor::ComplimentaryColourExtractor(struct ColourHSV hsv,
|
ComplimentaryColourExtractor::ComplimentaryColourExtractor(struct ColourHSV hsv,
|
||||||
size_t h_levels, size_t s_levels, size_t v_levels)
|
size_t h_levels, size_t s_levels, size_t v_levels)
|
||||||
:ColourExtractor(h_levels, s_levels, v_levels), m_main_colour(hsv)
|
:ColourExtractor(h_levels, s_levels, v_levels), m_main_colour(hsv)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
// PROTECTED FUNCS
|
// PROTECTED FUNCS
|
||||||
size_t ComplimentaryColourExtractor::evaluate_colour(struct ColourHSV hsv,
|
size_t ComplimentaryColourExtractor::evaluate_colour(struct ColourHSV hsv,
|
||||||
double weight) const
|
double weight) const
|
||||||
{
|
{
|
||||||
size_t result = 0;
|
size_t result = 0;
|
||||||
double angle_delta;
|
double angle_delta;
|
||||||
double additional_colour_weight;
|
double additional_colour_weight;
|
||||||
|
|
||||||
if ((0.0 == hsv.s) || (0.0 == m_main_colour.s))
|
if ((0.0 == hsv.s) || (0.0 == m_main_colour.s))
|
||||||
{
|
{
|
||||||
angle_delta = 180.0;
|
angle_delta = 180.0;
|
||||||
additional_colour_weight = 0.5;
|
additional_colour_weight = 0.5;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
additional_colour_weight = 1.0;
|
additional_colour_weight = 1.0;
|
||||||
/* SECTION BEGIN */
|
/* SECTION BEGIN */
|
||||||
angle_delta = fabs(hsv.h - m_main_colour.h);
|
angle_delta = fabs(hsv.h - m_main_colour.h);
|
||||||
if (angle_delta > 180.0F)
|
if (angle_delta > 180.0F)
|
||||||
{
|
{
|
||||||
angle_delta = 360.0F - angle_delta;
|
angle_delta = 360.0F - angle_delta;
|
||||||
}
|
}
|
||||||
/* SECTION END */
|
/* SECTION END */
|
||||||
}
|
}
|
||||||
|
|
||||||
// result = static_cast<size_t>(round(1000.0 * pow(weight, 0.3) * hsv.v *
|
// result = static_cast<size_t>(round(1000.0 * pow(weight, 0.3) * hsv.v *
|
||||||
// fmin(1.0, hsv.v + hsv.s) * additional_colour_weight * angle_delta));
|
// fmin(1.0, hsv.v + hsv.s) * additional_colour_weight * angle_delta));
|
||||||
|
|
||||||
result = static_cast<size_t>(round(1000.0 * pow(weight, 0.3) * hsv.v *
|
result = static_cast<size_t>(round(1000.0 * pow(weight, 0.3) * hsv.v *
|
||||||
additional_colour_weight * angle_delta));
|
additional_colour_weight * angle_delta));
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// PUBLIC FUNCS
|
// PUBLIC FUNCS
|
||||||
struct ColourHSV ComplimentaryColourExtractor::get_main_colour() const
|
struct ColourHSV ComplimentaryColourExtractor::get_main_colour() const
|
||||||
{
|
{
|
||||||
return m_main_colour;
|
return m_main_colour;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ComplimentaryColourExtractor::set_main_colour(struct ColourHSV hsv)
|
void ComplimentaryColourExtractor::set_main_colour(struct ColourHSV hsv)
|
||||||
{
|
{
|
||||||
m_main_colour = hsv;
|
m_main_colour = hsv;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,24 +1,24 @@
|
|||||||
#ifndef COMPLIMENTARY_COLOUR_EXTRACTOR_H_
|
#ifndef COMPLIMENTARY_COLOUR_EXTRACTOR_H_
|
||||||
#define COMPLIMENTARY_COLOUR_EXTRACTOR_H_
|
#define COMPLIMENTARY_COLOUR_EXTRACTOR_H_
|
||||||
|
|
||||||
#include "colour_extractor.h"
|
#include "colour_extractor.h"
|
||||||
|
|
||||||
class ComplimentaryColourExtractor : public ColourExtractor
|
class ComplimentaryColourExtractor : public ColourExtractor
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
// Main colour against which we are finding the complimentary
|
// Main colour against which we are finding the complimentary
|
||||||
struct ColourHSV m_main_colour;
|
struct ColourHSV m_main_colour;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// Implemented - Evaluates the given colour based on its weight
|
// Implemented - Evaluates the given colour based on its weight
|
||||||
virtual size_t evaluate_colour(struct ColourHSV hsv, double weight) const;
|
virtual size_t evaluate_colour(struct ColourHSV hsv, double weight) const;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ComplimentaryColourExtractor(struct ColourHSV hsv, size_t h_levels = 36,
|
ComplimentaryColourExtractor(struct ColourHSV hsv, size_t h_levels = 36,
|
||||||
size_t s_levels = 10, size_t v_levels = 10);
|
size_t s_levels = 10, size_t v_levels = 10);
|
||||||
|
|
||||||
struct ColourHSV get_main_colour() const;
|
struct ColourHSV get_main_colour() const;
|
||||||
void set_main_colour(struct ColourHSV hsv);
|
void set_main_colour(struct ColourHSV hsv);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // COMPLIMENTARY_COLOUR_EXTRACTOR_H_
|
#endif // COMPLIMENTARY_COLOUR_EXTRACTOR_H_
|
||||||
|
|||||||
@ -1,51 +1,51 @@
|
|||||||
#include "main_colour_extractor.h"
|
#include "main_colour_extractor.h"
|
||||||
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
// CONSTRUCTORS
|
// CONSTRUCTORS
|
||||||
MainColourExtractor::MainColourExtractor(double lightness_threshold,
|
MainColourExtractor::MainColourExtractor(double lightness_threshold,
|
||||||
size_t h_levels, size_t s_levels, size_t v_levels)
|
size_t h_levels, size_t s_levels, size_t v_levels)
|
||||||
:ColourExtractor(h_levels, s_levels, v_levels),
|
:ColourExtractor(h_levels, s_levels, v_levels),
|
||||||
m_lightness_threshold(lightness_threshold)
|
m_lightness_threshold(lightness_threshold)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
// PRIVATE FUNCS
|
// PRIVATE FUNCS
|
||||||
double MainColourExtractor::calculate_lightness(struct ColourHSV hsv) const
|
double MainColourExtractor::calculate_lightness(struct ColourHSV hsv) const
|
||||||
{
|
{
|
||||||
double result = 0.0;
|
double result = 0.0;
|
||||||
struct ColourRGB rgb;
|
struct ColourRGB rgb;
|
||||||
|
|
||||||
rgb = HSVtoRGB(hsv);
|
rgb = HSVtoRGB(hsv);
|
||||||
result = 0.299F * rgb.r + 0.587F * rgb.g + 0.114F * rgb.b;
|
result = 0.299F * rgb.r + 0.587F * rgb.g + 0.114F * rgb.b;
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// PROTECTED FUNCS
|
// PROTECTED FUNCS
|
||||||
size_t MainColourExtractor::evaluate_colour(struct ColourHSV hsv, double weight)
|
size_t MainColourExtractor::evaluate_colour(struct ColourHSV hsv, double weight)
|
||||||
const
|
const
|
||||||
{
|
{
|
||||||
size_t result = 0;
|
size_t result = 0;
|
||||||
double lightness;
|
double lightness;
|
||||||
|
|
||||||
lightness = calculate_lightness(hsv);
|
lightness = calculate_lightness(hsv);
|
||||||
if (lightness >= m_lightness_threshold)
|
if (lightness >= m_lightness_threshold)
|
||||||
{
|
{
|
||||||
result = static_cast<size_t>(round(1000.0 * (pow(weight, 0.3) +
|
result = static_cast<size_t>(round(1000.0 * (pow(weight, 0.3) +
|
||||||
0.009999999776482582) * hsv.v * (hsv.s + 0.1)));
|
0.009999999776482582) * hsv.v * (hsv.s + 0.1)));
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// PUBLIC FUNCS
|
// PUBLIC FUNCS
|
||||||
double MainColourExtractor::get_lightness_threshold() const
|
double MainColourExtractor::get_lightness_threshold() const
|
||||||
{
|
{
|
||||||
return m_lightness_threshold;
|
return m_lightness_threshold;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainColourExtractor::set_lightness_threshold(double value)
|
void MainColourExtractor::set_lightness_threshold(double value)
|
||||||
{
|
{
|
||||||
m_lightness_threshold = value;
|
m_lightness_threshold = value;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,28 +1,28 @@
|
|||||||
#ifndef MAIN_COLOUR_EXTRACTOR_H_
|
#ifndef MAIN_COLOUR_EXTRACTOR_H_
|
||||||
#define MAIN_COLOUR_EXTRACTOR_H_
|
#define MAIN_COLOUR_EXTRACTOR_H_
|
||||||
|
|
||||||
#include "colour_extractor.h"
|
#include "colour_extractor.h"
|
||||||
|
|
||||||
class MainColourExtractor : public ColourExtractor
|
class MainColourExtractor : public ColourExtractor
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
// The minimum lightness a colour needs to have to be considered for
|
// The minimum lightness a colour needs to have to be considered for
|
||||||
// evaluation
|
// evaluation
|
||||||
double m_lightness_threshold;
|
double m_lightness_threshold;
|
||||||
|
|
||||||
// Calculates the lightness of a colour
|
// Calculates the lightness of a colour
|
||||||
double calculate_lightness(struct ColourHSV hsv) const;
|
double calculate_lightness(struct ColourHSV hsv) const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// Implemented - Evaluates the given colour based on its weight
|
// Implemented - Evaluates the given colour based on its weight
|
||||||
virtual size_t evaluate_colour(struct ColourHSV hsv, double weight) const;
|
virtual size_t evaluate_colour(struct ColourHSV hsv, double weight) const;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MainColourExtractor(double lightness_threshold = 0.2, size_t h_levels = 36,
|
MainColourExtractor(double lightness_threshold = 0.2, size_t h_levels = 36,
|
||||||
size_t s_levels = 10, size_t v_levels = 10);
|
size_t s_levels = 10, size_t v_levels = 10);
|
||||||
|
|
||||||
double get_lightness_threshold() const;
|
double get_lightness_threshold() const;
|
||||||
void set_lightness_threshold(double value);
|
void set_lightness_threshold(double value);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MAIN_COLOUR_EXTRACTOR_H_
|
#endif // MAIN_COLOUR_EXTRACTOR_H_
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user