Added code for reading and writing pngs#14
Conversation
include/util/pngEncodeDecode.hpp
Outdated
| @@ -0,0 +1,78 @@ | |||
| #pragma once // wtf is this | |||
There was a problem hiding this comment.
This was a best practice I picked up from work, but after consulting cppcoreguidelines, #8 we should revert to the standard way until we're using C++120 modules
include/util/pngEncodeDecode.hpp
Outdated
| #pragma once // wtf is this | ||
|
|
||
| #include "util/lodepng.h" | ||
| // #include <Eigen/Dense> |
There was a problem hiding this comment.
Delete commented out code. Add #include <vector>
| Image(std::vector<unsigned char> image, unsigned width, unsigned height): imageData_(image), width_(width), height_(height) {}; | ||
|
|
||
| // Constructs an image object that reads a png file and updates the object fields with the information | ||
| Image(const char* filename){this->decode(filename);}; |
There was a problem hiding this comment.
Let's have the header be declaration only
|
|
||
| void decode(const char* filename); | ||
|
|
||
| std::vector<unsigned char> getImageData() {return this->imageData_;}; |
There was a problem hiding this comment.
We don't need the this-> style with underscored members
|
|
||
| //if there's an error, display it | ||
| if (error) { | ||
| std::cout << "encoder error " << error << ": "<< lodepng_error_text(error) << std::endl; |
There was a problem hiding this comment.
Remove logging statements. Result is observable through return value.
|
|
||
| //if there's an error, display it and return false | ||
| if (error) { | ||
| this->decodeFail_ = true; |
There was a problem hiding this comment.
We don't need to remember the result. Just return a bool as in with the encode function
| std::vector<unsigned char> imageData; | ||
| unsigned width = 2, height = 2; | ||
| imageData.resize(width * height); | ||
| for (unsigned y = 0; y < height; y++) { |
|
|
||
| // PREPARE by checking if the file exists, and if so deleting the file | ||
| struct stat buffer; | ||
| if (stat ("test.png", &buffer) == 0) {system("rm ./test.png");} |
There was a problem hiding this comment.
Let's use
https://en.cppreference.com/w/cpp/io/c/tmpfile
instead.
Do your best to adhere to RAII principles
|
@griswaldbrooks test |
|
@griswaldbrooks test |
Got some rough code for you boss. Sorry in advance for making your eyes bleed.