CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Jun 2012
    Posts
    3

    Suppress gd and libpng error output

    Using C++ on an ubuntu 10 machine, compiling with gcc.

    I have a function that takes several different image formats stream and converts them to a PNG using GD.

    The problem I'm having is when it comes across a corrupt image libpng and gd-png are outputting to std::cerr. Where i would just like them to return an error and move on.

    Is there a #define or a parameter i can use to suppress this output?

    Output: (there are at least 30 libpng warnings)
    libpng warning: Ignoring bad adaptive filter type
    ...
    libpng warning: Ignoring bad adaptive filter type
    gd-png: fatal libpng error: incorrect data check
    gd-png error: setjmp returns error condition 2
    My code:
    Code:
    bool convertImageToPng(void *source, size_t sourceSize, std::string &dest, int& width, int& height, double cropLeft, double cropTop, double cropRight, double cropBottom)
    {
    	bool retVal = false;
    	gdImagePtr gdInput = NULL;
    
    	const char* s = (const char*) source;
    	if (sourceSize > 5 && (s[1] == 'P') && (s[2] == 'N') && (s[3] == 'G'))
    		gdImagePtr gdInput = gdImageCreateFromPngPtr(sourceSize, source);
    	else if (sourceSize > 5 && (s[0] == 'G') && (s[1] == 'I'))
    		gdInput = gdImageCreateFromGifPtr(sourceSize, source);
    	else if (sourceSize > 5 && (s[0] == (char)'\xFF') && (s[1] == (char)'\xD8'))
    		gdInput = gdImageCreateFromJpegPtr(sourceSize, source);
    
    	if (gdInput)
    	{
    		.
    		.
    		.
    	}
    }

  2. #2
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Suppress gd and libpng error output

    You have the full source code to libpng. Debug and find out how, where, and why those messages are appearing.

    Regards,

    Paul McKenzie

  3. #3
    Join Date
    Jun 2012
    Posts
    3

    Re: Suppress gd and libpng error output

    I was hoping to not modify the source code directly as this is something we will be shipping out to customers. We have a shell script that downloads and builds the dependencies, but was didn't really want it to modify source.

    I found that if i add the preprocessor definition PNG_NO_CONSOLE_IO when I build libpng it suppresses it's warnings/error output for libpng.

    The only similar thing i could do with gd to stop the output was to define PNG_SETJMP_NOT_SUPPORTED, but this sends in a NULL error handler to libpng which in turn causes it to abort when it gets to the error. Which wasn't clean.

    Think i'm just going to have to live with the 2 gd-png error outputs.

  4. #4
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Suppress gd and libpng error output

    Quote Originally Posted by PerceptiveCam View Post
    I was hoping to not modify the source code directly as this is something we will be shipping out to customers. We have a shell script that downloads and builds the dependencies, but was didn't really want it to modify source.
    I asked that you debug the libpng code and see why those messages are appearing. Once you know why those messages are appearing, then you use that new knowledge to suppress the errors or direct them somewhere else. Never did I suggest modifying the source code -- I mentioned that you have the full source, therefore nothing stops you from debugging it.

    Regards,

    Paul McKenzie

  5. #5
    Join Date
    Jun 2012
    Posts
    3

    Re: Suppress gd and libpng error output

    The messages are appearing because the PNG file is corrupt. The file has been chopped off at the end and as its trying to read in the filter info it runs out of data.

    I was just trying to get it to let me handle the error instead of outputting to the console. But by using GD as a middle layer to libPNG, i cant seem to stop GD from outputting unless i define PNG_SETJMP_NOT_SUPPORTED, which in turn causes libPNG to abort. I can live with this, 2 error outputs are better than 30.

Tags for this Thread

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured