Skip to main content
Code Review

Return to Question

added links to file formats
Source Link
user673679
  • 12.2k
  • 2
  • 34
  • 65

The image class will be used to create RGB images and export them to any of the netbpm image formats (pbm , pgm , ppm ). I may expand the class to export in other formats and maybe load images, but for the moment, I just need the basic functionality of editing and exporting.

The image class will be used to create RGB images and export them to any of the netbpm image formats. I may expand the class to export in other formats and maybe load images, but for the moment, I just need the basic functionality of editing and exporting.

The image class will be used to create RGB images and export them to any of the netbpm image formats (pbm , pgm , ppm ). I may expand the class to export in other formats and maybe load images, but for the moment, I just need the basic functionality of editing and exporting.

edited tags; edited title
Source Link
200_success
  • 145.5k
  • 22
  • 190
  • 478

Public enum type in Image pixel-editing class with an enum type in public and private function prototypesfor colors

AImage.cpp

Public enum type in class with enum type in public and private function prototypes

A.cpp

Image pixel-editing class with an enum for colors

Image.cpp

Post Reopened by Stephen Rauch, Sᴀᴍ Onᴇᴌᴀ , alecxe, Heslacher, t3chb0t
added 7359 characters in body; edited title
Source Link

Good style for public Public enum type in class with enum type in public and private function prototypes

I'm writing codecreating an image class that uses a public enumerated type as input to private and public functions. I havecan be used by other classes to declare the enum type before I use it in any function prototype so I can't place it with the restcreate visualizations of the public declarationsdata. I alsoThe class doesn't need to keep the public declarations afterbe complicated as the private ones to conform with a style guide.

I am wondering if there is a way to only have one public declaration section instead of two, or if there is a better way of organizingclasses will be editing the header fileimages pixel by pixel.


Here is my code:

main.cpp

#include "A.h"
int main() {
 const int WIDTH = 3;
 const int HEIGHT = 4;
 const int MAX_HEIGHT = 6;
 
 A a = A(MAX_HEIGHT, WIDTH, HEIGHT);
 
 for (int i = 0; i < HEIGHT; ++i) {
 a.SetValue(0, i, A::VALUE_2);
 a.SetValue(WIDTH - 1, i, A::VALUE_2);
 }
 for (int j = 0; j < WIDTH; ++j) {
 a.SetValue(j, 0, A::VALUE_3);
 a.SetValue(j, WIDTH - 1, A::VALUE_3);
 }
 
 for (int i = 0; i < HEIGHT - 2; ++i) {
 for (int j = 0; j < WIDTH - 2; ++j) {
 a.SetIntegers(j, i, i, j , i + j);
 }
 }
 
 return 0;
}

The image class will be used to create RGB images and export them to any of the netbpm image formats. I may expand the class to export in other formats and maybe load images, but for the moment, I just need the basic functionality of editing and exporting.

I'm mostly looking for feedback on the use of enum values.


AImage.h

#ifndef IMAGE_H
#define IMAGE_H
#include <string>
#include <vector>
#include <fstream>
#include <cctype>
#include <cmath>
using namespace std;
class AImage {
public:
 enum EnumerationEnum_Colors {VALUE_1WHITE, VALUE_2BLACK, VALUE_3GREY, RED, GREEN, BLUE, YELLOW, CYAN, MAGENTA};
 
private:
 const unsigned int NUM_PIXEL_VALUES = 3;
 const unsigned int FILE_EXTENSION_LENGTH = 4;
  struct ContainerPixel {
 unsigned int i;red;
 unsigned int j;green;
 unsigned int k;blue;
 };
 
 unsigned int maxValue;
 vector<vector<Container>>vector<vector<Pixel>> data;imageData;
 
 Container/**
 CreateContainer * Creates a pixel representing the given color.
 *
 * @param color an enumerated color
 * @return a pixel representing the given color
 **/
 Pixel ColorPixel(EnumerationEnum_Colors enumValuecolor) const;
 
 /**
 * Creates an image file from the image data.
 * 
 * The type of the created file is determined by the function name.
 *
 * @param fileName the name of the created file
 * @return false if an error occurred
 * @return true otherwise
 **/
 bool ExportPBM(string fileName);
 bool ExportPGM(string fileName);
 bool ExportPPM(string fileName);
 
public:
 AImage(unsigned int maxValuewidth, unsigned int xDimensionheight, unsigned int yDimensionmaxValue) : maxValue(maxValue),
 dataimageData(vector<vector<Container>>vector<vector<Pixel>>(yDimensionheight, vector<Container>vector<Pixel>(xDimensionwidth, CreateContainerColorPixel(VALUE_1WHITE)))) {};
 ~A~Image() {dataimageData.clear();}
 
 void/**
 SetValue * Returns the pixel width of the image.
 *
 * @return the pixel width of the image
 **/
 unsigned int Width();
 
 /**
 * Returns the pixel height of the image.
 *
 * @return the pixel height of the image
 **/
 unsigned int Height();
 
 /**
 * Returns the maximum intensity value of the image.
 *
 * @return the maximum intensity value of the image
 **/
 unsigned int MaxValue();
 
  /**
 * Sets the given pixel value to the given color.
 *
 * @param x the location along the width
 * @param y the location along the height
 * @param color the color to set the pixel to
 * 
 * @return false if the indices are out of bounds
 * @return true otherwise
 **/
 bool SetPixelColor(unsigned int x, unsigned int y, EnumerationEnum_Colors enumValuecolor);
 void SetIntegers /**
 * Sets the given pixel value to the given color.
 *
 * @param x the location along the width
 * @param y the location along the height
 * @param redVal the intensity of the red value to set the pixel to
 * @param greenVal the intensity of the green value to set the pixel to
 * @param blueVal the intensity of the blue value to set the pixel to
 * 
 * @return false if the indices are out of bounds or the color values
 are out of bounds
 * @return true otherwise
 **/
 bool SetPixelValue(unsigned int x, unsigned int y, unsigned int iredValue, unsigned int jgreenValue, unsigned int kblueValue);
 
 /**
 * Creates an image file from the image data.
 * 
 * The type of the created file is determined by the file name.
 * (Supported extensions: .pbm, .pgm, .ppm)
 *
 * @param fileName the name of the created file
 * @return false if the extension is not supported or an error occurred
 * @return true otherwise
 **/
 bool ExportImage(string fileName);
};
#endif
#include "A"Image.h"
A
Image::ContainerPixel AImage::CreateContainerColorPixel(EnumerationEnum_Colors enumValuecolor) const {
 ContainerPixel container;pixel;
 switch (enumValuecolor) {
 case VALUE_1WHITE:
 containerpixel.ired = 0;maxValue;
 containerpixel.jgreen = maxValue;
 containerpixel.kblue = maxValue;
 break;
 case VALUE_2BLACK:
 containerpixel.ired = 0;
 pixel.green = 0;
 pixel.blue = 0;
 break;
 case GREY:
 pixel.red = maxValue / 2;
 pixel.green = maxValue / 2;
  pixel.blue = maxValue / 2;
 break;
 case RED:
 pixel.red = maxValue;
 containerpixel.jgreen = 0;
 containerpixel.kblue = 0;
 break;
  case GREEN:
 pixel.red = 0;
 pixel.green = maxValue;
 pixel.blue = 0;
 break;
 case VALUE_3BLUE:
 containerpixel.ired = 0;
 pixel.green = 0;
  pixel.blue = maxValue;
 containerbreak;
 case YELLOW:
 pixel.jred = maxValue;
 containerpixel.kgreen = maxValue;
 pixel.blue = 0;
 break;
 case CYAN:
 pixel.red = 0;
 pixel.green = maxValue;
 pixel.blue = maxValue;
  break;
 case MAGENTA:
 pixel.red = maxValue;
  pixel.green = 0;
 pixel.blue = maxValue;
 break;
 default:
 pixel.red = maxValue;
 pixel.green = maxValue;
 pixel.blue = maxValue;
 break;
 };
 return container;pixel;
}
voidbool AImage::SetValueExportPBM(intstring xfileName) {
 ofstream fout;
 
 /* Attempt to create the file and check for errors */
 fout.open(fileName);
 if (fout.fail()) {
 return false;
 }
 
 /* Write heading */
 fout << "P1" << endl; // file type identifier
 fout << "# CREATOR: C++ Image Class, by Jacob Bischoff" << endl;
 fout << imageData.at(0).size() << " " << imageData.size() << endl; // width height
  
 /* Write body */
 for (unsigned int yi = 0; i < imageData.size(); i++) {
 /* Add end line in proper locations */
 if (i > 0) {
 fout << endl;
 }
 
 /* Output pixel values; 0 - White, Enumeration1 enumValue- Black */
 for (unsigned int j = 0; j < imageData.at(i).size(); j++) {
 data Pixel pixel = imageData.at(yi).at(xj);
 = CreateContainer if (enumValuej > 0) {
 fout << " ";
 }
 fout << 1 - (int)roundf((pixel.red + pixel.green + pixel.blue) / (double)NUM_PIXEL_VALUES / (double)maxValue);
 return; }
 }
 
 return true;
}
voidbool AImage::SetIntegersExportPGM(string fileName) {
 ofstream fout;
 
 /* Attempt to create the file and check for errors */
 fout.open(fileName);
 if (fout.fail()) {
 return false;
 }
 
 /* Write heading */
 fout << "P2" << endl; // file type identifier
 fout << "# CREATOR: C++ Image Class, by Jacob Bischoff" << endl;
 fout << imageData.at(0).size() << " " << imageData.size() << endl; // width height
 fout << maxValue << endl;
 
 /* Write body */
 for (unsigned int xi = 0; i < imageData.size(); i++) {
 /* Add end line in proper locations */
 if (i > 0) {
 fout << endl;
 }
 
 /* Output pixel values; 0 - black, maxValue - white */
  for (unsigned int yj = 0; j < imageData.at(i).size(); j++) {
 Pixel pixel = imageData.at(i).at(j);
 if (j > 0) {
 fout << " ";
 }
 fout << (int)roundf((pixel.red + pixel.green + pixel.blue) / (double)NUM_PIXEL_VALUES);
 }
 }
 
 return true;
}
bool Image::ExportPPM(string fileName) {
 ofstream fout;
 
 /* Attempt to create the file and check for errors */
 fout.open(fileName);
 if (fout.fail()) {
 return false;
 }
 
 /* Write heading */
 fout << "P3" << endl; // file type identifier
 fout << "# CREATOR: C++ Image Class, by Jacob Bischoff" << endl;
 fout << imageData.at(0).size() << " " << imageData.size() << endl; // width height
 fout << maxValue << endl;
 
 /* Write body */
 for (unsigned int i = 0; i < imageData.size(); i++) {
 /* Add end line in proper locations */
  if (i > 0) {
 fout << endl;
 }
 
 /* Output pixel values; 0 0 0 - black, maxValue maxValue maxValue - white */
 for (unsigned int j = 0; j < imageData.at(i).size(); j++) {
 Pixel pixel = imageData.at(i).at(j);
 if (j > 0) {
 fout << "\t";
 }
 fout << pixel.red << " " << pixel.green << " " << pixel.blue;
 }
 }
 
 return true;
}
unsigned int Image::Width() {
 /* prevent out of bounds error */
 if (imageData.size() == 0) {
 /* no second order elements */
 return 0;
 }
 else {
 /* return the second order size */
 return imageData.at(0).size();
 }
}
unsigned int Image::Height() {
 /* return the first order size */
 return imageData.size();
}
unsigned int Image::MaxValue() {
 /* return the maximum intensity value */
 return maxValue;
}
bool Image::SetPixelColor(unsigned int x, unsigned int ky, Enum_Colors color) {
 data/* check if indices are withing bounds */
 if ((y < imageData.size()) && (x < imageData.at(y).size())) {
 imageData.at(y).at(x) = ColorPixel(color);
 return true;
 }
 else {
 return false;
 }
}
bool Image::SetPixelValue(unsigned int x, unsigned int y, unsigned int redValue, unsigned int greenValue, unsigned int blueValue) {
 /* check if indices are withing bounds */
 if ((y < imageData.isize()) && (x < imageData.at(y).size())) {
 /* check if intensity values are larger than max */
 if ((redValue <= maxValue) || (greenValue <= maxValue) || (blueValue <= maxValue)) {
 imageData.at(y).at(x).red = i;redValue;
 data imageData.at(y).at(x).jgreen = j;greenValue;
 data imageData.at(y).at(x).kblue = k;blueValue;
 return; return true;
 }
 else {return false;}
 }
 else {return false;}
}
bool Image::ExportImage(string fileName) {
 string fileExtension = fileName.substr(fileName.size() - FILE_EXTENSION_LENGTH, FILE_EXTENSION_LENGTH);
 
 /* Make extension all lowercase for ease of comparison */
 for (unsigned int i = 0; i < fileExtension.size(); ++i) {
 fileExtension.at(i) = tolower(fileExtension.at(i));
 }
 
 /* Evaluate extension to determine which file type to create. */
 if (fileExtension == ".pbm") {
 return ExportPBM(fileName);
 }
 else if (fileExtension == ".pgm") {
 return ExportPGM(fileName);
 }
 else if (fileExtension == ".ppm") {
 return ExportPPM(fileName);
 }
 else {
 return false;
 }
}

Good style for public enum type in class with enum type in public and private function prototypes

I'm writing code that uses a public enumerated type as input to private and public functions. I have to declare the enum type before I use it in any function prototype so I can't place it with the rest of the public declarations. I also need to keep the public declarations after the private ones to conform with a style guide.

I am wondering if there is a way to only have one public declaration section instead of two, or if there is a better way of organizing the header file.


Here is my code:

main.cpp

#include "A.h"
int main() {
 const int WIDTH = 3;
 const int HEIGHT = 4;
 const int MAX_HEIGHT = 6;
 
 A a = A(MAX_HEIGHT, WIDTH, HEIGHT);
 
 for (int i = 0; i < HEIGHT; ++i) {
 a.SetValue(0, i, A::VALUE_2);
 a.SetValue(WIDTH - 1, i, A::VALUE_2);
 }
 for (int j = 0; j < WIDTH; ++j) {
 a.SetValue(j, 0, A::VALUE_3);
 a.SetValue(j, WIDTH - 1, A::VALUE_3);
 }
 
 for (int i = 0; i < HEIGHT - 2; ++i) {
 for (int j = 0; j < WIDTH - 2; ++j) {
 a.SetIntegers(j, i, i, j , i + j);
 }
 }
 
 return 0;
}

A.h

#include <vector>
using namespace std;
class A {
public:
 enum Enumeration {VALUE_1, VALUE_2, VALUE_3};
 
private: 
 struct Container {
 int i;
 int j;
 int k;
 };
 
 int maxValue;
 vector<vector<Container>> data;
 
 Container CreateContainer(Enumeration enumValue) const;
 
public:
 A(int maxValue, int xDimension, int yDimension) : maxValue(maxValue),
 data(vector<vector<Container>>(yDimension, vector<Container>(xDimension, CreateContainer(VALUE_1)))) {}
 ~A() {data.clear();}
 
 void SetValue(int x, int y, Enumeration enumValue);
 void SetIntegers(int x, int y, int i, int j, int k);
};
#include "A.h"
A::Container A::CreateContainer(Enumeration enumValue) const {
 Container container;
 switch (enumValue) {
 case VALUE_1:
 container.i = 0;
 container.j = maxValue;
 container.k = maxValue;
 case VALUE_2:
 container.i = maxValue;
 container.j = 0;
 container.k = maxValue;
 case VALUE_3:
 container.i = maxValue;
 container.j = maxValue;
 container.k = 0;
 };
 return container;
}
void A::SetValue(int x, int y, Enumeration enumValue) {
 data.at(y).at(x) = CreateContainer(enumValue);
 return;
}
void A::SetIntegers(int x, int y, int i, int j, int k) {
 data.at(y).at(x).i = i;
 data.at(y).at(x).j = j;
 data.at(y).at(x).k = k;
 return;
}

Public enum type in class with enum type in public and private function prototypes

I'm creating an image class that can be used by other classes to create visualizations of data. The class doesn't need to be complicated as the classes will be editing the images pixel by pixel.

The image class will be used to create RGB images and export them to any of the netbpm image formats. I may expand the class to export in other formats and maybe load images, but for the moment, I just need the basic functionality of editing and exporting.

I'm mostly looking for feedback on the use of enum values.


Image.h

#ifndef IMAGE_H
#define IMAGE_H
#include <string>
#include <vector>
#include <fstream>
#include <cctype>
#include <cmath>
using namespace std;
class Image {
public:
 enum Enum_Colors {WHITE, BLACK, GREY, RED, GREEN, BLUE, YELLOW, CYAN, MAGENTA};
 
private:
 const unsigned int NUM_PIXEL_VALUES = 3;
 const unsigned int FILE_EXTENSION_LENGTH = 4;
  struct Pixel {
 unsigned int red;
 unsigned int green;
 unsigned int blue;
 };
 
 unsigned int maxValue;
 vector<vector<Pixel>> imageData;
 
 /**
  * Creates a pixel representing the given color.
 *
 * @param color an enumerated color
 * @return a pixel representing the given color
 **/
 Pixel ColorPixel(Enum_Colors color) const;
 
 /**
 * Creates an image file from the image data.
 * 
 * The type of the created file is determined by the function name.
 *
 * @param fileName the name of the created file
 * @return false if an error occurred
 * @return true otherwise
 **/
 bool ExportPBM(string fileName);
 bool ExportPGM(string fileName);
 bool ExportPPM(string fileName);
 
public:
 Image(unsigned int width, unsigned int height, unsigned int maxValue) : maxValue(maxValue),
 imageData(vector<vector<Pixel>>(height, vector<Pixel>(width, ColorPixel(WHITE)))) {};
 ~Image() {imageData.clear();}
 
 /**
  * Returns the pixel width of the image.
 *
 * @return the pixel width of the image
 **/
 unsigned int Width();
 
 /**
 * Returns the pixel height of the image.
 *
 * @return the pixel height of the image
 **/
 unsigned int Height();
 
 /**
 * Returns the maximum intensity value of the image.
 *
 * @return the maximum intensity value of the image
 **/
 unsigned int MaxValue();
 
  /**
 * Sets the given pixel value to the given color.
 *
 * @param x the location along the width
 * @param y the location along the height
 * @param color the color to set the pixel to
 * 
 * @return false if the indices are out of bounds
 * @return true otherwise
 **/
 bool SetPixelColor(unsigned int x, unsigned int y, Enum_Colors color);
  /**
 * Sets the given pixel value to the given color.
 *
 * @param x the location along the width
 * @param y the location along the height
 * @param redVal the intensity of the red value to set the pixel to
 * @param greenVal the intensity of the green value to set the pixel to
 * @param blueVal the intensity of the blue value to set the pixel to
 * 
 * @return false if the indices are out of bounds or the color values
 are out of bounds
 * @return true otherwise
 **/
 bool SetPixelValue(unsigned int x, unsigned int y, unsigned int redValue, unsigned int greenValue, unsigned int blueValue);
 
 /**
 * Creates an image file from the image data.
 * 
 * The type of the created file is determined by the file name.
 * (Supported extensions: .pbm, .pgm, .ppm)
 *
 * @param fileName the name of the created file
 * @return false if the extension is not supported or an error occurred
 * @return true otherwise
 **/
 bool ExportImage(string fileName);
};
#endif
#include "Image.h"

Image::Pixel Image::ColorPixel(Enum_Colors color) const {
 Pixel pixel;
 switch (color) {
 case WHITE:
 pixel.red = maxValue;
 pixel.green = maxValue;
 pixel.blue = maxValue;
 break;
 case BLACK:
 pixel.red = 0;
 pixel.green = 0;
 pixel.blue = 0;
 break;
 case GREY:
 pixel.red = maxValue / 2;
 pixel.green = maxValue / 2;
  pixel.blue = maxValue / 2;
 break;
 case RED:
 pixel.red = maxValue;
 pixel.green = 0;
 pixel.blue = 0;
 break;
  case GREEN:
 pixel.red = 0;
 pixel.green = maxValue;
 pixel.blue = 0;
 break;
 case BLUE:
 pixel.red = 0;
 pixel.green = 0;
  pixel.blue = maxValue;
 break;
 case YELLOW:
 pixel.red = maxValue;
 pixel.green = maxValue;
 pixel.blue = 0;
 break;
 case CYAN:
 pixel.red = 0;
 pixel.green = maxValue;
 pixel.blue = maxValue;
  break;
 case MAGENTA:
 pixel.red = maxValue;
  pixel.green = 0;
 pixel.blue = maxValue;
 break;
 default:
 pixel.red = maxValue;
 pixel.green = maxValue;
 pixel.blue = maxValue;
 break;
 }
 return pixel;
}
bool Image::ExportPBM(string fileName) {
 ofstream fout;
 
 /* Attempt to create the file and check for errors */
 fout.open(fileName);
 if (fout.fail()) {
 return false;
 }
 
 /* Write heading */
 fout << "P1" << endl; // file type identifier
 fout << "# CREATOR: C++ Image Class, by Jacob Bischoff" << endl;
 fout << imageData.at(0).size() << " " << imageData.size() << endl; // width height
  
 /* Write body */
 for (unsigned int i = 0; i < imageData.size(); i++) {
 /* Add end line in proper locations */
 if (i > 0) {
 fout << endl;
 }
 
 /* Output pixel values; 0 - White, 1 - Black */
 for (unsigned int j = 0; j < imageData.at(i).size(); j++) {
  Pixel pixel = imageData.at(i).at(j);
  if (j > 0) {
 fout << " ";
 }
 fout << 1 - (int)roundf((pixel.red + pixel.green + pixel.blue) / (double)NUM_PIXEL_VALUES / (double)maxValue);
  }
 }
 
 return true;
}
bool Image::ExportPGM(string fileName) {
 ofstream fout;
 
 /* Attempt to create the file and check for errors */
 fout.open(fileName);
 if (fout.fail()) {
 return false;
 }
 
 /* Write heading */
 fout << "P2" << endl; // file type identifier
 fout << "# CREATOR: C++ Image Class, by Jacob Bischoff" << endl;
 fout << imageData.at(0).size() << " " << imageData.size() << endl; // width height
 fout << maxValue << endl;
 
 /* Write body */
 for (unsigned int i = 0; i < imageData.size(); i++) {
 /* Add end line in proper locations */
 if (i > 0) {
 fout << endl;
 }
 
 /* Output pixel values; 0 - black, maxValue - white */
  for (unsigned int j = 0; j < imageData.at(i).size(); j++) {
 Pixel pixel = imageData.at(i).at(j);
 if (j > 0) {
 fout << " ";
 }
 fout << (int)roundf((pixel.red + pixel.green + pixel.blue) / (double)NUM_PIXEL_VALUES);
 }
 }
 
 return true;
}
bool Image::ExportPPM(string fileName) {
 ofstream fout;
 
 /* Attempt to create the file and check for errors */
 fout.open(fileName);
 if (fout.fail()) {
 return false;
 }
 
 /* Write heading */
 fout << "P3" << endl; // file type identifier
 fout << "# CREATOR: C++ Image Class, by Jacob Bischoff" << endl;
 fout << imageData.at(0).size() << " " << imageData.size() << endl; // width height
 fout << maxValue << endl;
 
 /* Write body */
 for (unsigned int i = 0; i < imageData.size(); i++) {
 /* Add end line in proper locations */
  if (i > 0) {
 fout << endl;
 }
 
 /* Output pixel values; 0 0 0 - black, maxValue maxValue maxValue - white */
 for (unsigned int j = 0; j < imageData.at(i).size(); j++) {
 Pixel pixel = imageData.at(i).at(j);
 if (j > 0) {
 fout << "\t";
 }
 fout << pixel.red << " " << pixel.green << " " << pixel.blue;
 }
 }
 
 return true;
}
unsigned int Image::Width() {
 /* prevent out of bounds error */
 if (imageData.size() == 0) {
 /* no second order elements */
 return 0;
 }
 else {
 /* return the second order size */
 return imageData.at(0).size();
 }
}
unsigned int Image::Height() {
 /* return the first order size */
 return imageData.size();
}
unsigned int Image::MaxValue() {
 /* return the maximum intensity value */
 return maxValue;
}
bool Image::SetPixelColor(unsigned int x, unsigned int y, Enum_Colors color) {
 /* check if indices are withing bounds */
 if ((y < imageData.size()) && (x < imageData.at(y).size())) {
 imageData.at(y).at(x) = ColorPixel(color);
 return true;
 }
 else {
 return false;
 }
}
bool Image::SetPixelValue(unsigned int x, unsigned int y, unsigned int redValue, unsigned int greenValue, unsigned int blueValue) {
 /* check if indices are withing bounds */
 if ((y < imageData.size()) && (x < imageData.at(y).size())) {
 /* check if intensity values are larger than max */
 if ((redValue <= maxValue) || (greenValue <= maxValue) || (blueValue <= maxValue)) {
 imageData.at(y).at(x).red = redValue;
  imageData.at(y).at(x).green = greenValue;
  imageData.at(y).at(x).blue = blueValue;
  return true;
 }
 else {return false;}
 }
 else {return false;}
}
bool Image::ExportImage(string fileName) {
 string fileExtension = fileName.substr(fileName.size() - FILE_EXTENSION_LENGTH, FILE_EXTENSION_LENGTH);
 
 /* Make extension all lowercase for ease of comparison */
 for (unsigned int i = 0; i < fileExtension.size(); ++i) {
 fileExtension.at(i) = tolower(fileExtension.at(i));
 }
 
 /* Evaluate extension to determine which file type to create. */
 if (fileExtension == ".pbm") {
 return ExportPBM(fileName);
 }
 else if (fileExtension == ".pgm") {
 return ExportPGM(fileName);
 }
 else if (fileExtension == ".ppm") {
 return ExportPPM(fileName);
 }
 else {
 return false;
 }
}
Post Closed as "Not suitable for this site" by 200_success, πάντα ῥεῖ, Mast , Gerrit0, Jamal
Source Link
Loading
lang-cpp

AltStyle によって変換されたページ (->オリジナル) /