Question
• Input : PPM filename – the file will be used for file open in the program.
• Output : 3-dimensional array integer [][][] – width BY height BY 3 (RGB) :
Display (0, 0) --> (100, 101, 102) (0, 1) --> (100, 102, 95) (0, 2) --> (45, 104, 100) . . . (1, 0) --> (100, 99, 104) . . .
• Others : This program will be used for sub-program (class, object or function) of another program.
Do not specify the file format (ASCII, or BINARY), nor size of image.
The program should be able to recognize different magic number (P3 and P6).
In case of ‘P6’, return an error message.
Solution Preview
This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.
/** File: ppmreader.cpp
*
*
*
*/
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cctype>
#include <locale>
#include<sstream>
using namespace std;
/*
*
*/
string <rim(std::string &s) {
s.erase(s.begin(), find_if(s.begin(), s.end(), std::not1(std::ptr_fun<int, int>(std::isspace))));
return s;
}
string &rtrim(std::string &s) {
s.erase(std::find_if(s.rbegin(), s.rend(), std::not1(std::ptr_fun<int, int>(std::isspace))).base(), s.end());
return s;
}
string &trim(std::string &s) {
return ltrim(rtrim(s));
}
int main(int argc, char** argv) {
vector<string> v;
string sLine = "";
ifstream infile;...