From 7d9e250c68a772c5e7f38afcb490aef4c0aceaf7 Mon Sep 17 00:00:00 2001 From: nedko Date: Wed, 7 Dec 2022 14:49:02 +0200 Subject: [PATCH] Added pixel printing to terminal --- main.cpp | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/main.cpp b/main.cpp index 5788556..4c0b7a4 100644 --- a/main.cpp +++ b/main.cpp @@ -1,5 +1,6 @@ #include #include +#include #define STB_IMAGE_IMPLEMENTATION #include "stb_image.h" @@ -18,6 +19,15 @@ void usage(char *name) cout << "Image must have 3 or more channels" << endl; } +void print_pixel(ColourRGB rgb) +{ + uint8_t r = static_cast(round(rgb.r * 255)); + uint8_t g = static_cast(round(rgb.g * 255)); + uint8_t b = static_cast(round(rgb.b * 255)); + + printf("#%02x%02x%02x - %3d %3d %3d", r, g ,b, r, g, b); +} + int main(int argc, char **argv) { int x_size; @@ -75,7 +85,6 @@ int main(int argc, char **argv) // 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); @@ -87,7 +96,12 @@ int main(int argc, char **argv) pixel = HSVtoRGB(pixel_hsv); pixel2 = HSVtoRGB(comp_extractor.extract_colour()); - // TODO: Print them to console + cout << "Main - "; + print_pixel(pixel); + cout << endl; + cout << "Comp - "; + print_pixel(pixel2); + cout << endl; x_size = 16; y_size = 16; @@ -106,7 +120,7 @@ int main(int argc, char **argv) image[i * channels + 2] = static_cast(round(pixel.b * 255)); } - stbi_write_png("main.png", x_size, y_size, channels, image, x_size * channels); + stbi_write_png("0 - main.png", x_size, y_size, channels, image, x_size * channels); for (int i = 0; i < x_size * y_size; ++i) { @@ -115,7 +129,7 @@ int main(int argc, char **argv) image[i * channels + 2] = static_cast(round(pixel2.b * 255)); } - stbi_write_png("comp.png", x_size, y_size, channels, image, x_size * channels); + stbi_write_png("1 - comp.png", x_size, y_size, channels, image, x_size * channels); delete[] image;