12345678910111213
#include <cstdlib> #include <iostream> #include <string> #include <fstream> #include <tr1/array> #include "Imagen.hpp" using namespace std; using namespace Jose; int main() { imagen prueba,aux;
bool ok; prueba.leer("a1.ppm",ok); system ("pause"); }
12345678910111213141516171819202122232425262728
#ifndef _Imagen_hpp_ #define _Imagen_hpp_ #include <string> #include <tr1/array> #include <cassert> #include <iostream> namespace Jose { class imagen { static const unsigned MaxTam = 500; struct RGB { short r; short g; short b; }; typedef std::tr1::array <RGB, MaxTam> TFila; typedef std::tr1::array <TFila, MaxTam> TMatriz; std::string tipo; unsigned columnas; unsigned filas; short MaxRGB; TMatriz dato; public: imagen (); void leer (const std::string & nombrefich, bool & ok); }; } #endif
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
#include <string> #include <tr1/array> #include <cassert> #include <iostream> #include <fstream> #include "Imagen.hpp" namespace Jose { imagen::imagen () { columnas=0; filas=0; MaxRGB=0; for (unsigned i=0;i<filas;i++) { for (unsigned j=0;i<columnas;i++) { dato[i][j].r=0; dato[i][j].g=0; dato[i][j].b=0; } } } void imagen::leer (const std::string & nombrefich, bool & ok) { std::ifstream f_ent; unsigned num_cuenta; float saldo_cuenta; std::string nombre_cuenta; f_ent.open(nombrefich.c_str()); if (f_ent.fail()) { ok=false; } else { ok=true; f_ent>>tipo>>columnas>>filas>>MaxRGB; for (unsigned i=0;i<filas;i++) { for (unsigned j=0;j<columnas;j++) { f_ent>>dato[i][j].r; f_ent>>dato[i][j].g; f_ent>>dato[i][j].b; } } ok=!f_ent.fail(); f_ent.close(); } } }