Write a simple program that is able to read PPM image files.
• 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 PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

* File:   ppmreader.cpp

#include <cstdlib>
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cctype>
#include <locale>
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;...

By purchasing this solution you'll be able to access the following files:

for this solution

or FREE if you
register a new account!

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available 3D Graphics Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Upload a file
Continue without uploading

We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats