Skip to content
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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

bgill92
Copy link
Contributor

@bgill92 bgill92 commented Dec 15, 2020

Got some rough code for you boss. Sorry in advance for making your eyes bleed.

@bgill92 bgill92 self-assigned this Dec 15, 2020
@@ -0,0 +1,78 @@
#pragma once // wtf is this
Copy link
Member

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

#pragma once // wtf is this

#include "util/lodepng.h"
// #include <Eigen/Dense>
Copy link
Member

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);};
Copy link
Member

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_;};
Copy link
Member

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;
Copy link
Member

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;
Copy link
Member

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++) {
Copy link
Member

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");}
Copy link
Member

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 griswaldbrooks assigned bgill92 and unassigned bgill92 Jan 31, 2021
@griswaldbrooks
Copy link
Member

@griswaldbrooks test

@griswaldbrooks
Copy link
Member

@griswaldbrooks test

@bgill92
Copy link
Contributor Author

bgill92 commented Feb 16, 2021

@griswaldbrooks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants