|
|
@ -15,7 +15,7 @@ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR I |
|
|
|
#define RWPNM |
|
|
|
#define RWPNM |
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
RWPNM v0.2 |
|
|
|
RWPNM v0.3 |
|
|
|
|
|
|
|
|
|
|
|
A drop-in library to work with PNM images |
|
|
|
A drop-in library to work with PNM images |
|
|
|
*/ |
|
|
|
*/ |
|
|
@ -23,17 +23,9 @@ A drop-in library to work with PNM images |
|
|
|
#include <vector> |
|
|
|
#include <vector> |
|
|
|
#include <fstream> |
|
|
|
#include <fstream> |
|
|
|
|
|
|
|
|
|
|
|
namespace pnm { |
|
|
|
namespace pnm {; |
|
|
|
|
|
|
|
|
|
|
|
class Color { |
|
|
|
class RGB { |
|
|
|
public: |
|
|
|
|
|
|
|
Color() {} |
|
|
|
|
|
|
|
~Color() {} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool operator==(const Color& other); |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class RGB : public Color { |
|
|
|
|
|
|
|
public: |
|
|
|
public: |
|
|
|
RGB(uint8_t r = 0, uint8_t g = 0, uint8_t b = 0) { |
|
|
|
RGB(uint8_t r = 0, uint8_t g = 0, uint8_t b = 0) { |
|
|
|
R = r; |
|
|
|
R = r; |
|
|
@ -48,15 +40,15 @@ public: |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool operator==(const RGB& other) { |
|
|
|
bool operator==(const RGB& other) { |
|
|
|
if (R != other.R || G != other.G || B != other.B) { |
|
|
|
if (R == other.R || G == other.G || B == other.B) { |
|
|
|
return false; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
class Grayscale : public Color { |
|
|
|
class Grayscale { |
|
|
|
public: |
|
|
|
public: |
|
|
|
Grayscale(uint8_t value = 0) { |
|
|
|
Grayscale(uint8_t value = 0) { |
|
|
|
intensity = value; |
|
|
|
intensity = value; |
|
|
@ -64,6 +56,14 @@ public: |
|
|
|
~Grayscale() {} |
|
|
|
~Grayscale() {} |
|
|
|
|
|
|
|
|
|
|
|
uint8_t intensity; |
|
|
|
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); |
|
|
|
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
|
|
|
|
// Return all captured comments of an image
|
|
|
|
std::vector<std::string> get_comments() { |
|
|
|
std::vector<std::string> get_comments() { |
|
|
|
return m_comments; |
|
|
|
return m_comments; |
|
|
@ -152,9 +160,11 @@ public: |
|
|
|
while(captured < 3) { |
|
|
|
while(captured < 3) { |
|
|
|
ppm_image_file >> entity; |
|
|
|
ppm_image_file >> entity; |
|
|
|
if (entity[0] == m_COMMENT_CHAR) { |
|
|
|
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); |
|
|
|
getline(ppm_image_file, entity); |
|
|
|
m_comments.push_back(entity); |
|
|
|
comment += entity; |
|
|
|
|
|
|
|
m_comments.push_back(comment); |
|
|
|
continue; |
|
|
|
continue; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|