From 9762c44796e5575782216b4c2d39d3bc55c869d6 Mon Sep 17 00:00:00 2001 From: Evgenij Titarenko Date: Wed, 3 Apr 2024 08:56:21 +0300 Subject: [PATCH] lab01_Ver0.1 --- main.cpp | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/main.cpp b/main.cpp index d0ba901..8444d6c 100644 --- a/main.cpp +++ b/main.cpp @@ -4,9 +4,32 @@ const std::string FILENAME = "../elef.bmp"; const std::string FILENAME_OUT = "../elef_out.bmp"; +void lab01() { + auto og_image = readBMPImage(FILENAME); + auto pixels = og_image.pixels_copy(); + for (int i = 0; i < og_image.height(); ++i) { + for (int j = 0; j < og_image.width(); ++j) { + uint8_t gray = pixels[i][j].r / 3 + pixels[i][j].g / 3 + pixels[i][j].b / 3; + pixels[i][j] = {gray, gray, gray}; + } + } + auto image1 = new BMPImage(og_image.fileHeader_copy(), og_image.infoHeader_copy(), pixels); + auto pixels2 = image1->pixels_copy(); + for (int i = 0; i < og_image.height(); ++i) { + for (int j = 0; j < og_image.width(); ++j) { + uint8_t gray = 0; + if (pixels2[i][j].r > 80) gray = 255; + pixels2[i][j] = {gray, gray, gray}; + } + } + auto image2 = new BMPImage(og_image.fileHeader_copy(), og_image.infoHeader_copy(), pixels2); + image1->write("../elef_gs.bmp"); + image2->write("../elef_bw.bmp"); + og_image.write("../elef_out.bmp"); +// image.write(FILENAME_OUT); +} int main() { - auto image = readBMPImage(FILENAME); - image.write(FILENAME_OUT); + lab01(); return 0; }