From 75b91d547422f6720558429a7d91f26994ffad47 Mon Sep 17 00:00:00 2001 From: Unbewohnte Date: Mon, 7 Mar 2022 08:46:26 +0300 Subject: [PATCH] I have lost my will to implement all PNM file formats. I don`t want to work on this anymore. Not giving up, just tactically retreating untill a better time --- README.txt | 6 ++-- src/{pnm.cpp => ppm.cpp} | 61 ++++------------------------------------ tests/test.cpp | 20 ++++++------- 3 files changed, 19 insertions(+), 68 deletions(-) rename src/{pnm.cpp => ppm.cpp} (86%) diff --git a/README.txt b/README.txt index 3f6f9b1..19b150e 100644 --- a/README.txt +++ b/README.txt @@ -1,4 +1,4 @@ -RWPNM - a one-file drop-in C++ library for working with PPM, PGM and PBM image formats. +RWPPM - a one-file drop-in C++ library for working with PPM image format. -------------------------------------------------------------------------------------------- @@ -19,9 +19,11 @@ or Current version: v0.4 -Remove '#' from comments when read Status: +v0.4 +Remove '#' from comments when read + v0.3 Comments are now read correctly; remove all comments at once diff --git a/src/pnm.cpp b/src/ppm.cpp similarity index 86% rename from src/pnm.cpp rename to src/ppm.cpp index 198d2d0..ecb2c9d 100644 --- a/src/pnm.cpp +++ b/src/ppm.cpp @@ -11,19 +11,19 @@ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR I */ -#ifndef RWPNM -#define RWPNM +#ifndef RWPPM +#define RWPPM /* -RWPNM v0.4 +RWPPM v0.4 -A drop-in library to work with PNM images +A drop-in library to work with PPM images */ #include #include -namespace pnm {; +namespace ppm {; class RGB { public: @@ -48,49 +48,6 @@ public: } }; -class Grayscale { -public: - Grayscale(uint8_t value = 0) { - intensity = value; - } - ~Grayscale() {} - - uint8_t intensity; - - bool operator==(const Grayscale& other) { - if (intensity == other.intensity) { - return true; - } - - return false; - } -}; - - -// TODO -// template -// class PNM_image { -// protected: -// std::string m_MAGIC_NUMBER; -// const char m_COMMENT_CHAR = '#'; - -// // image width and height -// uint32_t m_width; -// uint32_t m_height; - -// // stored comments -// std::vector m_comments; - -// // actual pixel data -// std::vector m_pixel_data; - -// // returns 1-dimensional array index as if it was 2-dimensional array -// uint64_t index_at(uint32_t x, uint32_t y) { -// return m_width * y + x; -// } -// public: -// }; - // PPM image file format reader/writer class PPM { protected: @@ -284,14 +241,6 @@ public: } }; -// TODO -// class PBM { -// protected: -// public: -// PBM() {} -// ~PBM() {} -// }; - } #endif \ No newline at end of file diff --git a/tests/test.cpp b/tests/test.cpp index 2c46652..d011536 100644 --- a/tests/test.cpp +++ b/tests/test.cpp @@ -1,17 +1,17 @@ #include -#include "../src/pnm.cpp" +#include "../src/ppm.cpp" void make_test_img() { try { - pnm::PPM image; + ppm::PPM image; 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)); + image.put_pixel(x, y, ppm::RGB(x / 2, y / 2, x / 2 + y / 2)); } } @@ -24,7 +24,7 @@ void make_test_img() { void green_rectangle_on_top_of_existing_image() { try { - pnm::PPM image; + ppm::PPM image; image.read("test_img512x512.ppm"); // image.read("img.ppm"); @@ -33,7 +33,7 @@ void green_rectangle_on_top_of_existing_image() { 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)); + image.put_pixel(x, y, ppm::RGB(0, 255, 0)); } } @@ -46,7 +46,7 @@ void green_rectangle_on_top_of_existing_image() { void no_pixel_assign() { try { - pnm::PPM image; + ppm::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"); @@ -56,14 +56,14 @@ void no_pixel_assign() { void write_comment() { try { - pnm::PPM image; + ppm::PPM image; 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)); + image.put_pixel(x, y, ppm::RGB(x / 2, y / 2, x / 2 + y / 2)); } } @@ -81,7 +81,7 @@ void write_comment() { void remove_comments() { try { - pnm::PPM image; + ppm::PPM image; image.read("result_image.ppm"); image.remove_last_comment(); @@ -99,7 +99,7 @@ void read_comment(bool print) { try { write_comment(); - pnm::PPM image; + ppm::PPM image; image.read("result_image.ppm"); std::vector comments = image.get_comments();