Question

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 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;...

This is only a preview of the solution. Please use the purchase button to see the entire solution

Assisting Tutor

Related Homework Solutions

Computer Graphics Questions
Homework Solution
$18.00
Computer Science
Computer Graphics
CMYK Color
Pantone Color
Adobe Illustrator
Raster Based Images
Printing
Production System
Coordinates
Pixels
Data
Grain
Distortion
Vector Based Image
LISP and PROLOG Questions
Homework Solution
$110.00
Programming
Computer Science
Lisp
Prolog
Lists
Numbers
Sort
Reverse
Algorithms
Variables
Statements
Codes
Dynamic Arrays in C++
Homework Solution
$8.00
Computer Science
C++ Programming
OOP
Dynamic Arrays
Functions
Donations
Codes
Loops
Statements
Variables
Pointers
Memory Allocation
Users
Constants
Input
Output
Integers
Checkers Game Using Socket Communication
Homework Solution
$40.00
Programming
Computer Science
Checkers Game
Moves
Players
Codes
Rules
Statements
Variables
Functions
Socket Communication
Managers
Threads
Parent Process
Child Process
Results
Winners
Database Management Questions
Homework Solution
$25.00
Database Management
MS Access
DB Programmer
DML
SQL
External Schema
Conceptual Schema
Logical Data Independence
Physical Data Independence
Client Server
Primary Key
Foreign Key
Integrity Rules
Traditional File System
ER Diagram
University D
Get help from a qualified tutor
Live Chats