how can i read a gif file byte a byte?

heres what i know about the gif files:
1 - the 0x2C(',') is the Image Separator;
2 - the 0X3B(';') is the Image Terminator and the Trailler.
knowing that, i did these loop for read the gif file\stream byte a byte:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
friend std::istream& operator >> (std::istream& lhs, image& rhs)
    {
        DebugText("reading....");

        int streamsize=0;
        char *p=new char[1];
        vector <char> chrStream;
        while(true)
        {
            static bool blnStarted=false;
            lhs.read(reinterpret_cast<char*>(p),1);
            if(p[0]=='G' && blnStarted==false)//testing if is the start of file
            {
                blnStarted=true;
                chrStream.resize(1);
                chrStream[0]='G';
            }
            else if(p[0]==',' && blnStarted==false) //testing if is the end of GIF file
            {
                chrStream.resize(chrStream.size()+1);
                chrStream[chrStream.size()-1]=',';
                blnStarted=true;
            }
            else if(p[0]!=',' && blnStarted==false) //testing if is the end of GIF file
            {
                break;
            }
            else if(p[0]==';' && blnStarted==true) //testing if is the end of GIF file
            {
                chrStream.resize(chrStream.size()+1);
                chrStream[chrStream.size()-1]=';';
                blnStarted=false;
            }
            else //saving the file stream on vector
            {
                chrStream.resize(chrStream.size()+1);
                chrStream[chrStream.size()-1]=p[0];
            }
        }
        streamsize=chrStream.size();

but the output:
stream size: 19066
reading....
reading: stream size: 1604

it's a big diference. can anyone tell me what i'm doing wrong with my loop?
Make sure you opened the file in binary mode.
Topic archived. No new replies allowed.