Added old code

This commit is contained in:
nedko 2022-11-23 22:59:30 +02:00
parent 99aa3ab2b8
commit d1cfc1e606
4 changed files with 41 additions and 15 deletions

View File

@ -1,2 +1,8 @@
SRCS += main.cpp
SRCS += colours.c
SRCS += colour_extractor.cpp
SRCS += main_colour_extractor.cpp
SRCS += complimentary_colour_extractor.cpp
all:
g++ main.cpp -o image_colours
g++ -o image_colours $(SRCS)

View File

@ -79,10 +79,10 @@ struct ColourRGB HSVtoRGB(struct ColourHSV hsv)
return result;
}
struct ColourRGB HSLtoRGB(struct ColourHSL hsl)
{
// struct ColourRGB HSLtoRGB(struct ColourHSL hsl)
// {
}
// }
struct ColourCMYK RGBtoCMYK(struct ColourRGB rgb)
{

View File

@ -32,18 +32,18 @@ struct ColourHSL
struct ColourRGB CMYKtoRGB(struct ColourCMYK cmyk);
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 HSVtoCMYK(struct ColourHSV hsv);
struct ColourCMYK HSLtoCMYK(struct ColourHSL hsl);
// 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 ColourHSV HSLtoHSV(struct ColourHSL hsl);
struct ColourHSL RGBtoHSL(struct ColourRGB rgb);
struct ColourHSL CMYKtoHSL(struct ColourCMYK cmyk);
struct ColourHSL HSLtoHSL(struct ColourHSV hsv);
// struct ColourHSL HSVtoHSL(struct ColourHSV hsv);
#endif // COLOURS_H_

View File

@ -6,7 +6,8 @@
#define STB_IMAGE_WRITE_IMPLEMENTATION
#include "stb_image_write.h"
#include "Extractor.h"
#include "main_colour_extractor.h"
#include "complimentary_colour_extractor.h"
using namespace std;
@ -24,7 +25,11 @@ int main(int argc, char **argv)
int channels;
int error;
unsigned char *image = nullptr;
PixelRGB pixel;
ColourRGB pixel;
ColourRGB pixel2;
ColourHSV pixel_hsv;
MainColourExtractor main_extractor(0.2, 36, 10, 10);
ComplimentaryColourExtractor comp_extractor({0, 0, 0}, 36, 10, 10);
if (argc < 2)
{
@ -33,7 +38,7 @@ int main(int argc, char **argv)
return -1;
}
error = stbi_info("argv", &x_size, &y_size, &channels);
error = stbi_info(argv[1], &x_size, &y_size, &channels);
if (1 != error)
{
cout << "Image type is not supported" << endl;
@ -48,7 +53,7 @@ int main(int argc, char **argv)
return -1;
}
image = stbi_load("argv", &x_size, &y_size, &channels, 0);
image = stbi_load(argv[1], &x_size, &y_size, &channels, 0);
if (nullptr == image)
{
cout << "Could not open image" << endl;
@ -61,16 +66,27 @@ int main(int argc, char **argv)
pixel.g = image[i + 1];
pixel.b = image[i + 2];
pixel.r /= 255;
pixel.g /= 255;
pixel.b /= 255;
if (channels > 3)
{
// TODO: Handle alpha here
}
// TODO: Add pixel to evaluator here
pixel_hsv = RGBtoHSV(pixel);
main_extractor.add_pixel(pixel_hsv);
comp_extractor.add_pixel(pixel_hsv);
}
stbi_image_free(image);
// TODO: Get main and comp colours here
pixel_hsv = main_extractor.extract_colour();
comp_extractor.set_main_colour(pixel_hsv);
pixel = HSVtoRGB(pixel_hsv);
pixel2 = HSVtoRGB(comp_extractor.extract_colour());
// TODO: Print them to console
x_size = 16;
@ -85,14 +101,18 @@ int main(int argc, char **argv)
for (int i = 0; i < x_size * y_size; ++i)
{
// TODO: Fill image with pixel data here
image[i * channels + 0] = static_cast<unsigned char>(round(pixel.r * 255));
image[i * channels + 1] = static_cast<unsigned char>(round(pixel.g * 255));
image[i * channels + 2] = static_cast<unsigned char>(round(pixel.b * 255));
}
stbi_write_png("main.png", x_size, y_size, channels, image, x_size * channels);
for (int i = 0; i < x_size * y_size; ++i)
{
// TODO: Fill image with pixel data here
image[i * channels + 0] = static_cast<unsigned char>(round(pixel2.r * 255));
image[i * channels + 1] = static_cast<unsigned char>(round(pixel2.g * 255));
image[i * channels + 2] = static_cast<unsigned char>(round(pixel2.b * 255));
}
stbi_write_png("comp.png", x_size, y_size, channels, image, x_size * channels);