104 lines
2.0 KiB
C++
104 lines
2.0 KiB
C++
#include <iostream>
|
|
#include <string>
|
|
|
|
#define STB_IMAGE_IMPLEMENTATION
|
|
#include "stb_image.h"
|
|
#define STB_IMAGE_WRITE_IMPLEMENTATION
|
|
#include "stb_image_write.h"
|
|
|
|
#include "Extractor.h"
|
|
|
|
using namespace std;
|
|
|
|
void usage(char *name)
|
|
{
|
|
cout << "Usage: " << name << " [input image]" << endl;
|
|
cout << "Supported image formats: JPG, PNG, TGA, BMP, GIF" << endl;
|
|
cout << "Image must have 3 or more channels" << endl;
|
|
}
|
|
|
|
int main(int argc, char **argv)
|
|
{
|
|
int x_size;
|
|
int y_size;
|
|
int channels;
|
|
int error;
|
|
unsigned char *image = nullptr;
|
|
PixelRGB pixel;
|
|
|
|
if (argc < 2)
|
|
{
|
|
cout << "Not enough arguments" << endl;
|
|
usage(argv[0]);
|
|
return -1;
|
|
}
|
|
|
|
error = stbi_info("argv", &x_size, &y_size, &channels);
|
|
if (1 != error)
|
|
{
|
|
cout << "Image type is not supported" << endl;
|
|
usage(argv[0]);
|
|
return -1;
|
|
}
|
|
|
|
if (channels < 3)
|
|
{
|
|
cout << "This image is in grayscale (it has no colour)" << endl;
|
|
usage(argv[0]);
|
|
return -1;
|
|
}
|
|
|
|
image = stbi_load("argv", &x_size, &y_size, &channels, 0);
|
|
if (nullptr == image)
|
|
{
|
|
cout << "Could not open image" << endl;
|
|
return -1;
|
|
}
|
|
|
|
for (int i = 0; i < x_size * y_size * channels; i += channels)
|
|
{
|
|
pixel.r = image[i + 0];
|
|
pixel.g = image[i + 1];
|
|
pixel.b = image[i + 2];
|
|
|
|
if (channels > 3)
|
|
{
|
|
// TODO: Handle alpha here
|
|
}
|
|
|
|
// TODO: Add pixel to evaluator here
|
|
}
|
|
stbi_image_free(image);
|
|
|
|
// TODO: Get main and comp colours here
|
|
// TODO: Print them to console
|
|
|
|
x_size = 16;
|
|
y_size = 16;
|
|
channels = 3;
|
|
image = new unsigned char[x_size * y_size * channels];
|
|
if (nullptr == image)
|
|
{
|
|
cout << "Could not allocate space for image" << endl;
|
|
return -1;
|
|
}
|
|
|
|
for (int i = 0; i < x_size * y_size; ++i)
|
|
{
|
|
// TODO: Fill image with pixel data here
|
|
}
|
|
|
|
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
|
|
}
|
|
|
|
stbi_write_png("comp.png", x_size, y_size, channels, image, x_size * channels);
|
|
|
|
delete[] image;
|
|
|
|
return 0;
|
|
}
|