Unbewohnte
3 years ago
3 changed files with 138 additions and 54 deletions
@ -1,2 +1,4 @@
|
||||
image.ppm |
||||
result_image.ppm |
||||
img.ppm |
||||
test_img512x512.ppm |
||||
test |
@ -1,29 +1,71 @@
|
||||
#include <iostream> |
||||
#include "../src/pnm.cpp" |
||||
|
||||
using namespace pnm; |
||||
|
||||
int main() { |
||||
void make_test_img() { |
||||
try { |
||||
PPM_writer ppm_image(800, 800); |
||||
pnm::PPM image; |
||||
|
||||
uint8_t cc = 0; |
||||
for (uint32_t y = 0; y < 800; y++) { |
||||
for (uint32_t x = 0; x < 800; x++) { |
||||
ppm_image.put_pixel(x, y, RGB(cc, cc, cc)); |
||||
const uint32_t width = 512; |
||||
const uint32_t height = 512; |
||||
|
||||
for (uint32_t y = 0; y < height; y++) { |
||||
for (uint32_t x = 0; x < width; x++) {
|
||||
image.put_pixel(x, y, pnm::RGB(x / 2, y / 2, x / 2 + y / 2)); |
||||
} |
||||
} |
||||
|
||||
cc++; |
||||
image.save("test_img512x512.ppm"); |
||||
} catch(const std::exception& e) { |
||||
std::string error_message("make_test_img: ", e.what()); |
||||
throw std::runtime_error(error_message); |
||||
} |
||||
} |
||||
|
||||
void green_rectangle_on_top_of_existing_image() { |
||||
try { |
||||
pnm::PPM image; |
||||
image.read("test_img512x512.ppm"); |
||||
// image.read("img.ppm");
|
||||
|
||||
uint32_t rec_width = 100; |
||||
uint32_t rec_height = 100; |
||||
|
||||
for (uint32_t y = 0; y < rec_height; y++) { |
||||
for (uint32_t x = 0; x < rec_width; x++) { |
||||
image.put_pixel(x, y, pnm::RGB(0, 255, 0)); |
||||
} |
||||
cc--; |
||||
} |
||||
ppm_image.save("image.ppm"); |
||||
|
||||
image.save("result_image.ppm"); |
||||
} catch(const std::exception& e) { |
||||
std::string error_message("green_rectangle_on_top_of_existing_image: ", e.what()); |
||||
throw std::runtime_error(error_message); |
||||
} |
||||
} |
||||
|
||||
void no_pixel_assign() { |
||||
try { |
||||
pnm::PPM image; |
||||
image.save("result_image.ppm"); |
||||
|
||||
std::string error_message("no_pixel_assign: should`ve gotten an error, but there weren`t any thrown"); |
||||
throw std::runtime_error(error_message); |
||||
} catch(const std::exception& e) {} |
||||
} |
||||
|
||||
int main() { |
||||
try { |
||||
make_test_img(); |
||||
green_rectangle_on_top_of_existing_image(); |
||||
no_pixel_assign(); |
||||
|
||||
} catch(const std::exception& e) { |
||||
std::cout << "[ERROR] " << e.what() << "\n"; |
||||
return 1; |
||||
} |
||||
|
||||
std::cout << "[SUCCESS]\n"; |
||||
std::cout << "[ALL TESTS WERE COMPLETED SUCCESSFULLY]\n"; |
||||
|
||||
return 0; |
||||
} |
||||
|
Loading…
Reference in new issue