-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added code for reading and writing pngs #14
base: master
Are you sure you want to change the base?
Conversation
include/util/pngEncodeDecode.hpp
Outdated
@@ -0,0 +1,78 @@ | |||
#pragma once // wtf is this |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fill with zeros
|
||
// 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.