CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Thread: how can i calculate the gif file size?

  1. #1
    Join Date
    Apr 2009
    Posts
    1,293

    how can i calculate the gif file size?

    i'm trying getting the gif file size using the structures, but i don't understand the Image Data size
    http://www.matthewflickinger.com/lab...age_data_block
    can anyone advice me?

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    19,725

    Re: how can i calculate the gif file size?

    And what is your main goal in this context?
    Why do you need to know the gif file size? How are you going to use this value?
    Victor Nijegorodov

  3. #3
    Join Date
    Apr 2009
    Posts
    1,293

    Re: how can i calculate the gif file size?

    yes. is for read it for a stream on operator >> overloading

  4. #4
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,118

    Re: how can i calculate the gif file size?

    You don't need to calculate the gif file size in order to extract using operator >>. The link specified in post #1 describes the layout of the gif file format. For the extraction, if you read from the stream according to the gif format then when you find the trailer block you are at the end of the gif and the extraction from the stream terminates.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++17 Compiler: Microsoft VS2019 (16.6.1)

  5. #5
    Join Date
    Apr 2009
    Posts
    1,293

    Re: how can i calculate the gif file size?

    so why i only read the 1sy frame?
    Code:
    friend std::istream& operator >> (std::istream& lhs, image& rhs)
        {
            DebugText("reading....");
    
            int streamsize=0;
    
    
            //Getting the stream after 'G':
            char p[1];
            vector <char> chrStream;
            while(true)
            {
                static bool blnStarted=false;
                static bool blnFirstFrame=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]==EOF && blnFirstFrame==true)
                {
                    break;
                }
                else if(p[0]==',' && blnFirstFrame==true)
                {
                    chrStream.resize(chrStream.size()+1);
                    chrStream[chrStream.size()-1]=',';
                    blnFirstFrame=false;
                }
                else if(p[0]==';' && blnStarted==true) //testing if is the end of GIF file
                {
                    chrStream.resize(chrStream.size()+1);
                    chrStream[chrStream.size()-1]=';';
                    blnFirstFrame=true;
                }
                else if(blnStarted==true)//saving the file stream on vector
                {
                    chrStream.resize(chrStream.size()+1);
                    chrStream[chrStream.size()-1]=p[0];
                }
    
            }
            DebugText("stream size: " + to_string(chrStream.size()));
            return lhs;
    i thot the Trailler was ';' and the image separator ','

  6. #6
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,118

    Re: how can i calculate the gif file size?

    You might find 0x3b and 0x2c as part of a normal gif data stream in the sub blocks image data. Don't you need to read the data as per the gif file format?
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++17 Compiler: Microsoft VS2019 (16.6.1)

  7. #7
    Join Date
    Apr 2009
    Posts
    1,293

    Re: how can i calculate the gif file size?

    with that loop, i can get the stream in same time. but i only get the 1st frame

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)