Skip to content
/ images Public

a small collection of header only C++20 classes for representing and manipulating image files (.BMP, .PNG & .ICO) on Windows

License

Notifications You must be signed in to change notification settings

anoban/images

Repository files navigation

Caution: Images in this README.md are JPEG converts of the bitmap files used in and resulted from the image manipulations. This was done to minimize the repository size!

Usage:


Only the class canvas provides predefined image transformations routines. Other classes (bitmap, png & ico) support reading, parsing, decoding, encoding and serializing their respective file formats. These classes do provide a converting constructor to class canvas which can be used to manipulate these images (internally, the converting constructor will create a bitmap from these types which is the base class for canvas).

#include <canvas> // a class that uses the class bitmap as base
// read in a bitmap from disk as a canvas object
canvas image {LR"(./image.bmp)"};


// .copy() returns a deep copy so that the original stays as is during the transformation
image.copy(). // specify a preferred RGB to black and white mapping method
to_blacknwhite<rgb::BW_TRANSFORMATION::AVERAGE>().to_file(LR"(./average.bmp)");

image.copy().to_blacknwhite<rgb::BW_TRANSFORMATION::WEIGHTED_AVERAGE>().
to_file(LR"(./weighted_average.bmp)");

image.copy().to_blacknwhite<rgb::BW_TRANSFORMATION::BINARY>().to_file(LR"(./binary.bmp)");

image.copy().to_blacknwhite<rgb::BW_TRANSFORMATION::LUMINOSITY>().to_file(LR"(./luminosity.bmp)");


image.copy().remove_colour<rgb::RGB_TAG::BLUE>().to_file(LR"(.\redgreen.bmp)"); // remove blue

// remove red & blue
image.copy().remove_colour<rgb::RGB_TAG::REDBLUE>().to_file(LR"(.\green.bmp)");

image.copy().remove_colour<rgb::RGB_TAG::RED>().to_file(LR"(.\bluegreen.bmp)"); // remove red

// remove red & green
image.copy().remove_colour<rgb::RGB_TAG::REDGREEN>().to_file(LR"(.\blue.bmp)");

image.copy().remove_colour<rgb::RGB_TAG::GREEN>().to_file(LR"(.\redblue.bmp)"); // remove green

// remove green & blue
image.copy().remove_colour<rgb::RGB_TAG::GREENBLUE>().to_file(LR"(.\red.bmp)");


canvas image {LR"(./guitar.bmp)"};
image.copy().vflip().to_file(LR"(./vflipped.bmp)"); // vertical flip
image.hflip().to_file(LR"(./hflipped.bmp)"); // horizontal flip

std::mt19937_64 reng { static_cast<unsigned long long>(std::chrono::high_resolution_clock::now().
                       time_since_epoch().count()) };
canvas board { 1080 /* height */, 1920 /* width */};
board.fill(RGBQUAD { static_cast<unsigned char>(reng() % std::numeric_limits<unsigned char>::max()) /* B */,
                     static_cast<unsigned char>(reng() % std::numeric_limits<unsigned char>::max()) /* G */,
                     static_cast<unsigned char>(reng() % std::numeric_limits<unsigned char>::max()) /* R */,
                     0XFF });
board.to_file(LR"(colour.bmp)");


canvas board { 1080, 1920 };
board.waves();
board.to_file(LR"(waves.bmp)");

canvas board { 8640, 15360 };
board.mandelbrot(colourmaps::VGA);  // choose a colourmap of your liking, provided by <cmaps>
board.to_file(LR"(./mandelbrot.bmp)");


Warning:


Owing to the non-opt-in use of SSSE3, AVX1, AVX2 and AVX512 compiler (MSVC & LLVM) intrinsics, If compiles, will probably raise an illegal instruction hardware exception at runtime on unsupported CPU architectures (anything other than AMD64). Unfortunately my expertise is very Windows centric hence, I have no desire to accommodate the linux/g++ toolchain in this project.

Reference:


Compressed Image File Formats: JPEG, PNG, GIF, XBM, BMP - John Miano (1999) ACM Press/Addison-Wesley Publishing Co.

About

a small collection of header only C++20 classes for representing and manipulating image files (.BMP, .PNG & .ICO) on Windows

Topics

Resources

License

Stars

Watchers

Forks

Languages