Added pixel printing to terminal
This commit is contained in:
parent
8dd297434b
commit
7d9e250c68
22
main.cpp
22
main.cpp
@ -1,5 +1,6 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
#define STB_IMAGE_IMPLEMENTATION
|
#define STB_IMAGE_IMPLEMENTATION
|
||||||
#include "stb_image.h"
|
#include "stb_image.h"
|
||||||
@ -18,6 +19,15 @@ void usage(char *name)
|
|||||||
cout << "Image must have 3 or more channels" << endl;
|
cout << "Image must have 3 or more channels" << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void print_pixel(ColourRGB rgb)
|
||||||
|
{
|
||||||
|
uint8_t r = static_cast<uint8_t>(round(rgb.r * 255));
|
||||||
|
uint8_t g = static_cast<uint8_t>(round(rgb.g * 255));
|
||||||
|
uint8_t b = static_cast<uint8_t>(round(rgb.b * 255));
|
||||||
|
|
||||||
|
printf("#%02x%02x%02x - %3d %3d %3d", r, g ,b, r, g, b);
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
int x_size;
|
int x_size;
|
||||||
@ -75,7 +85,6 @@ int main(int argc, char **argv)
|
|||||||
// TODO: Handle alpha here
|
// TODO: Handle alpha here
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Add pixel to evaluator here
|
|
||||||
pixel_hsv = RGBtoHSV(pixel);
|
pixel_hsv = RGBtoHSV(pixel);
|
||||||
main_extractor.add_pixel(pixel_hsv);
|
main_extractor.add_pixel(pixel_hsv);
|
||||||
comp_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);
|
pixel = HSVtoRGB(pixel_hsv);
|
||||||
pixel2 = HSVtoRGB(comp_extractor.extract_colour());
|
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;
|
x_size = 16;
|
||||||
y_size = 16;
|
y_size = 16;
|
||||||
@ -106,7 +120,7 @@ int main(int argc, char **argv)
|
|||||||
image[i * channels + 2] = static_cast<unsigned char>(round(pixel.b * 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);
|
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)
|
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<unsigned char>(round(pixel2.b * 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);
|
stbi_write_png("1 - comp.png", x_size, y_size, channels, image, x_size * channels);
|
||||||
|
|
||||||
delete[] image;
|
delete[] image;
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user