Note that there are some explanatory texts on larger screens.

plurals
  1. POPNM Reader: Can't read some files in binary mode
    primarykey
    data
    text
    <p>I'm having some troubles with pnm files (which is kinda obvious or else I wouldn't be posting here XD). Thing is, my teacher asked us to develop a simple pnm reader in binary mode then print it to the screen. I'm using libEGL (a framework avaliable <a href="https://github.com/farlei/libEGL/tree/master/libEGL" rel="nofollow">here</a>). My problem is that it works only with these two images and fails with any other one.</p> <p>With birch.pnm and checkers.pnm it works, but cathedral.pnm, cotton.pnm and fish_tile.pnm it just simple enters an infinite loop or throws and error.</p> <p>The images are avaliable <a href="http://orion.math.iastate.edu/burkardt/data/pnm/pnm.html" rel="nofollow">here</a></p> <p>My code is as follows:</p> <pre><code>#include &lt;iostream&gt; #include &lt;string&gt; #include &lt;sstream&gt; #include &lt;fstream&gt; #include "engcomp_glib.h" using namespace std; struct RGB{ char red, green, blue; }; int main(int argc, char* argv[]){ RGB **image; RGB pixel; //ifstream _file("..\\bin\\birch.pnm"); ifstream _file("..\\bin\\checkers.pnm"); //ifstream _file("..\\bin\\cotton.pnm"); //ifstream _file("..\\bin\\cathedral.pnm"); //ifstream _file("..\\bin\\fish_tile.pnm"); string type, maxColor; int width, height; if(_file){ _file &gt;&gt; type; if(type != "P6") cout &lt;&lt; "Error! File type is not allowed." &lt;&lt; endl; _file &gt;&gt; width &gt;&gt; height &gt;&gt; maxColor; _file.close(); egl_inicializar(width, height, true); image = new RGB *[height]; for(int row = 0; row &lt; height; row++) image[row] = new RGB[width]; //Working 8D //_file.open("..\\bin\\birch.pnm", ios::binary); _file.open("..\\bin\\checkers.pnm", ios::binary); //Not working D:&lt; //_file.open("..\\bin\\cathedral.pnm", ios::binary); //_file.open("..\\bin\\fish_tile.pnm", ios::binary); //_file.open("..\\bin\\cotton.pnm", ios::binary); //imagem img; img.carregar("..\\bin\\birch.pnm"); _file.seekg(0, _file.end); int size = _file.tellg(); int currentSize = 0, counter = 0; char byte; _file.seekg(0, _file.beg); do{ _file.read(reinterpret_cast&lt;char *&gt; (&amp;byte), sizeof(char)); if(byte == 10 || byte == 13) counter++; }while(counter &lt; 3); int rows = 0, columns = 0; while(size != currentSize){ _file.read(reinterpret_cast&lt;char *&gt; (&amp;pixel), sizeof(RGB)); if(rows &lt; height &amp;&amp; columns &lt; width){ image[rows][columns] = pixel; rows++; } else if(rows == height){ rows = 0; columns++; image[rows][columns] = pixel; rows++; } //else if(columns &gt;= width) //currentSize = size; currentSize = _file.tellg(); } _file.close(); while(!key[SDLK_ESCAPE]){ for(int row = 0; row &lt; height; row++) for(int column = 0; column &lt; width; column++) //egl_pixel(row, column, image[row][column].red, image[row][column].green, image[row][column].blue); egl_pixel(column, row, image[column][row].red, image[column][row].green, image[column][row].blue); //img.desenha(0, 0); egl_desenha_frame(false); } } egl_finalizar(); return 0; } </code></pre> <p>It doesn't make sense, as it works for two of them, should work form them all I opened them all in a text editor and they have the header, so the problem is not there. What am I doing wrong? My colleague wrote a code that stores the pixels into an array with size [height * width] and can read almost all of the images but cathedral.pnm.</p> <p>Thanks for the patience and help :)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload