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