diff --git a/README.txt b/README.txt index df26a93..c3b5aae 100644 --- a/README.txt +++ b/README.txt @@ -1,5 +1,9 @@ RWPNM - a one-file drop-in C++ library for working with PPM, PGM and PBM image formats. + +-------------------------------------------------------------------------------------------- + + How to use: Either: 1) Copy src/pnm.cpp to your project, #include and you`re done ! No @@ -9,16 +13,27 @@ or 2) Create a dynamic library and use it instead. -Version: -v0.2 + +-------------------------------------------------------------------------------------------- + + +Current version: +v0.3 Status: +v0.3 +Comments are now read correctly; remove all comments at once + v0.2 PPM comments writing/reading support -v0.1.0 +v0.1 PPM reading, writing + +-------------------------------------------------------------------------------------------- + + License: MIT Licese, you are free to do anything, just don`t forget to include the notice. diff --git a/src/pnm.cpp b/src/pnm.cpp index 53573b5..0606859 100644 --- a/src/pnm.cpp +++ b/src/pnm.cpp @@ -15,7 +15,7 @@ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR I #define RWPNM /* -RWPNM v0.2 +RWPNM v0.3 A drop-in library to work with PNM images */ @@ -23,17 +23,9 @@ A drop-in library to work with PNM images #include #include -namespace pnm { +namespace pnm {; -class Color { -public: - Color() {} - ~Color() {} - - bool operator==(const Color& other); -}; - -class RGB : public Color { +class RGB { public: RGB(uint8_t r = 0, uint8_t g = 0, uint8_t b = 0) { R = r; @@ -48,15 +40,15 @@ public: bool operator==(const RGB& other) { - if (R != other.R || G != other.G || B != other.B) { - return false; + if (R == other.R || G == other.G || B == other.B) { + return true; } - return true; + return false; } }; -class Grayscale : public Color { +class Grayscale { public: Grayscale(uint8_t value = 0) { intensity = value; @@ -64,6 +56,14 @@ public: ~Grayscale() {} uint8_t intensity; + + bool operator==(const Grayscale& other) { + if (intensity == other.intensity) { + return true; + } + + return false; + } }; @@ -126,6 +126,14 @@ public: m_comments.push_back(comment); } + void remove_last_comment() { + m_comments.pop_back(); + } + + void remove_all_comments() { + m_comments.clear(); + } + // Return all captured comments of an image std::vector get_comments() { return m_comments; @@ -152,9 +160,11 @@ public: while(captured < 3) { ppm_image_file >> entity; if (entity[0] == m_COMMENT_CHAR) { - // this is a comment, skip this line + // this is a comment + std::string comment = entity; getline(ppm_image_file, entity); - m_comments.push_back(entity); + comment += entity; + m_comments.push_back(comment); continue; } diff --git a/tests/test.cpp b/tests/test.cpp index 1c7027d..5241216 100644 --- a/tests/test.cpp +++ b/tests/test.cpp @@ -69,7 +69,7 @@ void write_comment() { image.add_comment("comment 1"); image.add_comment("comment 2"); - image.add_comment("comment \n\n\n"); + image.add_comment("comment 3\n\n\n"); image.save("result_image.ppm"); @@ -79,6 +79,22 @@ void write_comment() { } } +void remove_comments() { + try { + pnm::PPM image; + image.read("result_image.ppm"); + + image.remove_last_comment(); + image.remove_all_comments(); + + image.save("result_image.ppm"); + + } catch(const std::exception& e) { + std::string error_message("remove_comment: ", e.what()); + throw std::runtime_error(error_message); + } +} + void read_comment() { try { write_comment(); @@ -105,6 +121,7 @@ int main() { no_pixel_assign(); write_comment(); read_comment(); + remove_comments(); } catch(const std::exception& e) { std::cout << "[ERROR] " << e.what() << "\n";