Animated GIF quality varies from Visual studio 2008 and 2012

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
dhana
Earned a small fee
Earned a small fee
Posts: 15
Joined: Tue Dec 02, 2014 7:25 am

Animated GIF quality varies from Visual studio 2008 and 2012

Post by dhana » Wed Aug 12, 2015 10:12 am

In the below code,Creating GIF Animation by list of images using wxGIFHandler class.

CODE:

Code: Select all

// For compilers that support precompilation, includes "wx/wx.h".
#include "wx/wxprec.h"

#ifdef __BORLANDC__
    #pragma hdrstop
#endif

// for all others, include the necessary headers (this file is usually all you
// need because it includes almost all "standard" wxWidgets headers)
#ifndef WX_PRECOMP
    #include "wx/wx.h"
#endif

#include <wx/app.h>
#include <wx/image.h>
#include <wx/imaggif.h>
#include <wx/anidecod.h>
#include <wx/quantize.h>
#include <wx/wfstream.h>
#include <wx/dir.h>
#include <wx/filefn.h>
#include<map>
#include <wx/filename.h>
using namespace std;
// ============================================================================
// implementation
// ============================================================================

int main(int argc, char **argv)
{
    wxApp::CheckBuildOptions(WX_BUILD_OPTIONS_SIGNATURE, "program");

    wxInitializer initializer;
    if ( !initializer )
    {
        fprintf(stderr, "Failed to initialize the wxWidgets library, aborting.");
        return -1;
    }

     argv[1] = "C:\\Path\\To\\Folder\\Containing\\Images";
     argv[2] = "C:\\Output\\Gif_file_name.gif";
     
     	wxString imagePath = argv[1];	
	wxString giffile   = argv[2];	
	wxString fpsvalue =  "5";	

	if(!wxDir::Exists(imagePath))
		return -1;
	 
	wxArrayString files;
	if(!wxDir::GetAllFiles(imagePath,&files,"*.png"))
		return -1;

	wxInitAllImageHandlers();

	wxImageArray imgArray;
	imgArray.Clear( );

	wxString strFileName ,strFileID;
	map<int ,wxString>mapFileSequ_FileName;
	int iFileNo;
	for(int i=0;i<files.size();i++)
	{
		
		wxFileName FileName = wxFileName::FileName (files.Item(i));
		strFileName = FileName.GetName();
		strFileName.StartsWith("image",&strFileID);
		iFileNo = atoi(strFileID.c_str());
		mapFileSequ_FileName[iFileNo] = files.Item(i);		
	}
	
	map<int ,wxString>::iterator Itr = mapFileSequ_FileName.begin();
	int i= 0;
	while (Itr != mapFileSequ_FileName.end())
	{
		wxImage pic, pic_;
		pic.LoadFile(Itr->second, wxBITMAP_TYPE_PNG );	
		wxQuantize::Quantize( pic, pic_ );		
		imgArray.Add( pic_ );
		Itr++;
	}

	wxFileOutputStream fstream(giffile);

	int fps  = wxAtoi(fpsvalue.c_str());

	int delayinmilisec = 1000/fps;
   
	wxGIFHandler* gif = new wxGIFHandler();
	bool ret = gif->SaveAnimation( imgArray, &fstream , false, delayinmilisec);

    return 0;
}
Issue:

The above code when used in visual studio 2008,the quality of animated GIF looking good,but in visual studio 2012 quality looking poor.

Here attached the images for quality variation.
Attachments
2012.png
Visual Studio 2012
2008.png
Visual Studio 2008
Last edited by dhana on Mon Aug 17, 2015 7:49 am, edited 2 times in total.

User avatar
doublemax
Moderator
Moderator
Posts: 15263
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Animated GIF quality varies from Visual studio 2008 and 2012

Post by doublemax » Wed Aug 12, 2015 10:38 am

It's very unlikely that the Visual Studio version makes that kind of difference. Are there any other differences?
Use the source, Luke!

dhana
Earned a small fee
Earned a small fee
Posts: 15
Joined: Tue Dec 02, 2014 7:25 am

Re: Animated GIF quality varies from Visual studio 2008 and 2012

Post by dhana » Mon Aug 17, 2015 7:45 am

METHOD 1:
we have built libaries and samples of wxWidgets 3.0.2 in visual studio 2008 and modified the console sample with the above mentioned code.

METHOD 2:
we have built libaries and samples of wxWidgets 3.0.2 in visual studio 2012 and modified the console sample with the above mentioned code.


Platform: Windows 7.

you can try it yourself.

User avatar
doublemax
Moderator
Moderator
Posts: 15263
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Animated GIF quality varies from Visual studio 2008 and 2012

Post by doublemax » Mon Aug 17, 2015 8:22 am

Can you reproduce this with a single image that you could upload for testing?
Use the source, Luke!

dhana
Earned a small fee
Earned a small fee
Posts: 15
Joined: Tue Dec 02, 2014 7:25 am

Re: Animated GIF quality varies from Visual studio 2008 and 2012

Post by dhana » Mon Aug 24, 2015 10:54 am

I attached multiple images in a zip.Try these images for testing
Attachments
images.zip
(760.53 KiB) Downloaded 35 times

User avatar
doublemax
Moderator
Moderator
Posts: 15263
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Animated GIF quality varies from Visual studio 2008 and 2012

Post by doublemax » Mon Aug 24, 2015 3:01 pm

I tried with VS2010 and VS2012. The resulting gif was byte-identical and looked fine as far as i can tell:
https://www.sendspace.com/file/s4ly8x
Use the source, Luke!

User avatar
doublemax
Moderator
Moderator
Posts: 15263
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Animated GIF quality varies from Visual studio 2008 and 2012

Post by doublemax » Mon Aug 24, 2015 3:53 pm

Addition: I just noticed that in debug mode the GIF looks fine, in release mode it's broken. But i have no explanation for this. I have the latest service pack for my version of VS2010 installed, it's hard to believe that this would be caused by a compiler error that has been undetected by now, but of course it's not 100% impossible.
Use the source, Luke!

dhana
Earned a small fee
Earned a small fee
Posts: 15
Joined: Tue Dec 02, 2014 7:25 am

Re: Animated GIF quality varies from Visual studio 2008 and 2012

Post by dhana » Wed Sep 02, 2015 10:47 am

Yes,i accept .In 2012,I also tried in debug mode the output GIF seems fine,in release mode only it's broken.

User avatar
doublemax
Moderator
Moderator
Posts: 15263
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Animated GIF quality varies from Visual studio 2008 and 2012

Post by doublemax » Thu Jan 02, 2020 4:22 pm

For future reference: This was in fact caused by a compiler error. Should be fixed now: http://trac.wxwidgets.org/ticket/17764
Use the source, Luke!

Post Reply