#ifndef FUNCTIONS_H
#define FUNCTIONS_H
#include
#include "functions.h"
struct Pixel {
int r; // red
int g; // green
int b; // blue
};
// Implemented for you
Pixel** createImage(int width, int height);
void deleteImage(Pixel** image, int width);
// Implement
int* createSeam(int length);
void deleteSeam(int* seam);
bool loadImage(std::string filename, Pixel** image, int width, int height);
bool outputImage(std::string filename, Pixel** image, int width, int height);
int energy(Pixel** image, int x, int y, int width, int height);
#endif
functions.cpp
#include
#include
#include
#include
#include
#include "functions.h"
using namespace std;
Pixel** createImage(int width, int height) {
cout << "Start createImage... " << endl;
// Create a one dimensional array on the heap of pointers to Pixels
// that has width elements (i.e. the number of columns)
Pixel** image = new Pixel*[width];
bool fail = false;
for (int i=0; i < width; ++i) { // loop through each column
// assign that column to a one dimensional array on the heap of Pixels
// that has height elements (i.e. the number of rows)
image[i] = new Pixel[height];
if (image[i] == nullptr) { // failed to allocate
fail = true;
}
}
if (fail) { // if any allocation fails, clean up and avoid memory leak
// deallocate any arrays created in for loop
for (int i=0; i < width; ++i) {
delete [] image[i]; // deleting nullptr is not a problem
}
delete [] image; // dlete array of pointers
return nullptr;
}
// initialize cells
//cout << "Initializing cells..." << endl;
for (int row=0; row for (int col=0; col //cout << "(" << col << ", " << row << ")" << endl;
image[col][row] = { 0, 0, 0 };
}
}
cout << "End createImage... " << endl;
return image;
}
void deleteImage(Pixel** image, int width) {
cout << "Start deleteImage..." << endl;
// avoid memory leak by deleting the array
for (int i=0; i delete [] image[i]; // delete each individual array placed on the heap
}
delete [] image;
image = nullptr;
}
/////////////// IMPLEMENT HERE ///////////////
int* createSeam(int length) {
return nullptr;
}
void deleteSeam(int* seam) {
}
bool loadImage(string filename, Pixel** image, int width, int height) {
return true;
}
bool outputImage(string filename, Pixel** image, int width, int height) {
return true;
}
int energy(Pixel** image, int x, int y, int width, int height) {
return 0;
}
Answers
Answered by
0
Answer:
WHAT SHOULD WE DO IN THIS BRO?
Explanation:
Answered by
0
Answer:
abe ye kaisa q hai
q is wrong
Similar questions