Singe file drop-in read/write PPM library for C and C++
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

72 lines
1.9 KiB

3 years ago
#include <iostream>
#include "../src/pnm.cpp"
void make_test_img() {
3 years ago
try {
pnm::PPM image;
3 years ago
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));
}
}
3 years ago
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));
3 years ago
}
}
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();
3 years ago
} catch(const std::exception& e) {
std::cout << "[ERROR] " << e.what() << "\n";
return 1;
}
std::cout << "[ALL TESTS WERE COMPLETED SUCCESSFULLY]\n";
3 years ago
return 0;
}