~random-stuff/libpng/libpng-1.6.x

« back to all changes in this revision

Viewing changes to contrib/gregbook/writepng.c

  • Committer: Sérgio Benjamim
  • Date: 2015-10-10 23:00:20 UTC
  • Revision ID: sergio_br2@yahoo.com.br-20151010230020-gdtmmv30zn25396n
Update to 1.6.18.

Show diffs side-by-side

added added

removed removed

Lines of Context:
55
55
 
56
56
 
57
57
#include <stdlib.h>     /* for exit() prototype */
 
58
#include <zlib.h>
58
59
 
59
 
#include "png.h"        /* libpng header; includes zlib.h and setjmp.h */
 
60
#include "png.h"        /* libpng header, includes setjmp.h */
60
61
#include "writepng.h"   /* typedefs, common macros, public prototypes */
61
62
 
62
63
 
89
90
 
90
91
    /* could also replace libpng warning-handler (final NULL), but no need: */
91
92
 
92
 
    png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, mainprog_ptr,
 
93
    png_ptr = png_create_write_struct(png_get_libpng_ver(NULL), mainprog_ptr,
93
94
      writepng_error_handler, NULL);
94
95
    if (!png_ptr)
95
96
        return 4;   /* out of memory */
104
105
    /* setjmp() must be called in every function that calls a PNG-writing
105
106
     * libpng function, unless an alternate error handler was installed--
106
107
     * but compatible error handlers must either use longjmp() themselves
107
 
     * (as in this program) or exit immediately, so here we go: */
 
108
     * (as in this program) or some other method to return control to
 
109
     * application code, so here we go: */
108
110
 
109
111
    if (setjmp(mainprog_ptr->jmpbuf)) {
110
112
        png_destroy_write_struct(&png_ptr, &info_ptr);
388
390
        exit(99);
389
391
    }
390
392
 
 
393
    /* Now we have our data structure we can use the information in it
 
394
     * to return control to our own higher level code (all the points
 
395
     * where 'setjmp' is called in this file.)  This will work with other
 
396
     * error handling mechanisms as well - libpng always calls png_error
 
397
     * when it can proceed no further, thus, so long as the error handler
 
398
     * is intercepted, application code can do its own error recovery.
 
399
     */
391
400
    longjmp(mainprog_ptr->jmpbuf, 1);
392
401
}