#include #include #include #include using namespace std; const int XDIM{1000}; const int YDIM{400}; using ColorT = unsigned char; struct PixelT { ColorT color[3]; }; using ImageT = vector >; void WriteImage(string baseFileName, const ImageT & image); int main() { vector> image(XDIM,vector(YDIM)); // write a for loop to set each pixel value to a random value WriteImage("foo", image); return 0; } void WriteImage(string baseFileName, const ImageT & image){ string pngName {baseFileName + ".ppm"}; string jpegName{baseFileName + ".jpeg"}; // open a file for writing // write the PBM header // the magic number P6 (in ascii) followed by a newline // width space height newline in ascii // the maximum value (255) newline in ascii // write the rgb values row by row in binary format // close the file // run ppmtogif or ppmtojpeg string cmd { "ppmtojpeg < " + pngName + " > " + jpegName}; system(cmd.c_str()); unlink(pngName.c_str()); }