Browse Source

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

master
Unbewohnte 3 years ago
parent
commit
75b91d5474
  1. 6
      README.txt
  2. 61
      src/ppm.cpp
  3. 20
      tests/test.cpp

6
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: Current version:
v0.4 v0.4
Remove '#' from comments when read
Status: Status:
v0.4
Remove '#' from comments when read
v0.3 v0.3
Comments are now read correctly; remove all comments at once Comments are now read correctly; remove all comments at once

61
src/pnm.cpp → src/ppm.cpp

@ -11,19 +11,19 @@ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR I
*/ */
#ifndef RWPNM #ifndef RWPPM
#define RWPNM #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 <vector> #include <vector>
#include <fstream> #include <fstream>
namespace pnm {; namespace ppm {;
class RGB { class RGB {
public: 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 T>
// 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<std::string> m_comments;
// // actual pixel data
// std::vector<T> 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 // PPM image file format reader/writer
class PPM { class PPM {
protected: protected:
@ -284,14 +241,6 @@ public:
} }
}; };
// TODO
// class PBM {
// protected:
// public:
// PBM() {}
// ~PBM() {}
// };
} }
#endif #endif

20
tests/test.cpp

@ -1,17 +1,17 @@
#include <iostream> #include <iostream>
#include "../src/pnm.cpp" #include "../src/ppm.cpp"
void make_test_img() { void make_test_img() {
try { try {
pnm::PPM image; ppm::PPM image;
const uint32_t width = 512; const uint32_t width = 512;
const uint32_t height = 512; const uint32_t height = 512;
for (uint32_t y = 0; y < height; y++) { for (uint32_t y = 0; y < height; y++) {
for (uint32_t x = 0; x < width; x++) { 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() { void green_rectangle_on_top_of_existing_image() {
try { try {
pnm::PPM image; ppm::PPM image;
image.read("test_img512x512.ppm"); image.read("test_img512x512.ppm");
// image.read("img.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 y = 0; y < rec_height; y++) {
for (uint32_t x = 0; x < rec_width; x++) { 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() { void no_pixel_assign() {
try { try {
pnm::PPM image; ppm::PPM image;
image.save("result_image.ppm"); image.save("result_image.ppm");
std::string error_message("no_pixel_assign: should`ve gotten an error, but there weren`t any thrown"); 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() { void write_comment() {
try { try {
pnm::PPM image; ppm::PPM image;
const uint32_t width = 512; const uint32_t width = 512;
const uint32_t height = 512; const uint32_t height = 512;
for (uint32_t y = 0; y < height; y++) { for (uint32_t y = 0; y < height; y++) {
for (uint32_t x = 0; x < width; x++) { 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() { void remove_comments() {
try { try {
pnm::PPM image; ppm::PPM image;
image.read("result_image.ppm"); image.read("result_image.ppm");
image.remove_last_comment(); image.remove_last_comment();
@ -99,7 +99,7 @@ void read_comment(bool print) {
try { try {
write_comment(); write_comment();
pnm::PPM image; ppm::PPM image;
image.read("result_image.ppm"); image.read("result_image.ppm");
std::vector<std::string> comments = image.get_comments(); std::vector<std::string> comments = image.get_comments();

Loading…
Cancel
Save