3dphotoshoot

diff libs/libpng/pngerror.c @ 14:06dc8b9b4f89

added libimago, libjpeg and libpng
author John Tsiombikas <nuclear@member.fsf.org>
date Sun, 07 Jun 2015 17:25:49 +0300
parents
children
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/libs/libpng/pngerror.c	Sun Jun 07 17:25:49 2015 +0300
     1.3 @@ -0,0 +1,345 @@
     1.4 +
     1.5 +/* pngerror.c - stub functions for i/o and memory allocation
     1.6 + *
     1.7 + * Last changed in libpng 1.2.30 [August 15, 2008]
     1.8 + * For conditions of distribution and use, see copyright notice in png.h
     1.9 + * Copyright (c) 1998-2008 Glenn Randers-Pehrson
    1.10 + * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
    1.11 + * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
    1.12 + *
    1.13 + * This file provides a location for all error handling.  Users who
    1.14 + * need special error handling are expected to write replacement functions
    1.15 + * and use png_set_error_fn() to use those functions.  See the instructions
    1.16 + * at each function.
    1.17 + */
    1.18 +
    1.19 +#define PNG_INTERNAL
    1.20 +#include "png.h"
    1.21 +#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
    1.22 +
    1.23 +static void /* PRIVATE */
    1.24 +png_default_error PNGARG((png_structp png_ptr,
    1.25 +  png_const_charp error_message));
    1.26 +#ifndef PNG_NO_WARNINGS
    1.27 +static void /* PRIVATE */
    1.28 +png_default_warning PNGARG((png_structp png_ptr,
    1.29 +  png_const_charp warning_message));
    1.30 +#endif /* PNG_NO_WARNINGS */
    1.31 +
    1.32 +/* This function is called whenever there is a fatal error.  This function
    1.33 + * should not be changed.  If there is a need to handle errors differently,
    1.34 + * you should supply a replacement error function and use png_set_error_fn()
    1.35 + * to replace the error function at run-time.
    1.36 + */
    1.37 +#ifndef PNG_NO_ERROR_TEXT
    1.38 +void PNGAPI
    1.39 +png_error(png_structp png_ptr, png_const_charp error_message)
    1.40 +{
    1.41 +#ifdef PNG_ERROR_NUMBERS_SUPPORTED
    1.42 +   char msg[16];
    1.43 +   if (png_ptr != NULL)
    1.44 +   {
    1.45 +     if (png_ptr->flags&
    1.46 +       (PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))
    1.47 +     {
    1.48 +       if (*error_message == '#')
    1.49 +       {
    1.50 +         /* Strip "#nnnn " from beginning of error message. */
    1.51 +           int offset;
    1.52 +           for (offset = 1; offset<15; offset++)
    1.53 +              if (error_message[offset] == ' ')
    1.54 +                  break;
    1.55 +           if (png_ptr->flags&PNG_FLAG_STRIP_ERROR_TEXT)
    1.56 +           {
    1.57 +              int i;
    1.58 +              for (i = 0; i < offset - 1; i++)
    1.59 +                 msg[i] = error_message[i + 1];
    1.60 +              msg[i - 1] = '\0';
    1.61 +              error_message = msg;
    1.62 +           }
    1.63 +           else
    1.64 +              error_message += offset;
    1.65 +       }
    1.66 +       else
    1.67 +       {
    1.68 +           if (png_ptr->flags&PNG_FLAG_STRIP_ERROR_TEXT)
    1.69 +           {
    1.70 +              msg[0] = '0';
    1.71 +              msg[1] = '\0';
    1.72 +              error_message = msg;
    1.73 +           }
    1.74 +       }
    1.75 +     }
    1.76 +   }
    1.77 +#endif
    1.78 +   if (png_ptr != NULL && png_ptr->error_fn != NULL)
    1.79 +      (*(png_ptr->error_fn))(png_ptr, error_message);
    1.80 +
    1.81 +   /* If the custom handler doesn't exist, or if it returns,
    1.82 +      use the default handler, which will not return. */
    1.83 +   png_default_error(png_ptr, error_message);
    1.84 +}
    1.85 +#else
    1.86 +void PNGAPI
    1.87 +png_err(png_structp png_ptr)
    1.88 +{
    1.89 +   if (png_ptr != NULL && png_ptr->error_fn != NULL)
    1.90 +      (*(png_ptr->error_fn))(png_ptr, '\0');
    1.91 +
    1.92 +   /* If the custom handler doesn't exist, or if it returns,
    1.93 +      use the default handler, which will not return. */
    1.94 +   png_default_error(png_ptr, '\0');
    1.95 +}
    1.96 +#endif /* PNG_NO_ERROR_TEXT */
    1.97 +
    1.98 +#ifndef PNG_NO_WARNINGS
    1.99 +/* This function is called whenever there is a non-fatal error.  This function
   1.100 + * should not be changed.  If there is a need to handle warnings differently,
   1.101 + * you should supply a replacement warning function and use
   1.102 + * png_set_error_fn() to replace the warning function at run-time.
   1.103 + */
   1.104 +void PNGAPI
   1.105 +png_warning(png_structp png_ptr, png_const_charp warning_message)
   1.106 +{
   1.107 +   int offset = 0;
   1.108 +   if (png_ptr != NULL)
   1.109 +   {
   1.110 +#ifdef PNG_ERROR_NUMBERS_SUPPORTED
   1.111 +   if (png_ptr->flags&
   1.112 +     (PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))
   1.113 +#endif
   1.114 +     {
   1.115 +       if (*warning_message == '#')
   1.116 +       {
   1.117 +           for (offset = 1; offset < 15; offset++)
   1.118 +              if (warning_message[offset] == ' ')
   1.119 +                  break;
   1.120 +       }
   1.121 +     }
   1.122 +     if (png_ptr != NULL && png_ptr->warning_fn != NULL)
   1.123 +        (*(png_ptr->warning_fn))(png_ptr, warning_message + offset);
   1.124 +   }
   1.125 +   else
   1.126 +      png_default_warning(png_ptr, warning_message + offset);
   1.127 +}
   1.128 +#endif /* PNG_NO_WARNINGS */
   1.129 +
   1.130 +
   1.131 +/* These utilities are used internally to build an error message that relates
   1.132 + * to the current chunk.  The chunk name comes from png_ptr->chunk_name,
   1.133 + * this is used to prefix the message.  The message is limited in length
   1.134 + * to 63 bytes, the name characters are output as hex digits wrapped in []
   1.135 + * if the character is invalid.
   1.136 + */
   1.137 +#define isnonalpha(c) ((c) < 65 || (c) > 122 || ((c) > 90 && (c) < 97))
   1.138 +static PNG_CONST char png_digit[16] = {
   1.139 +   '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
   1.140 +   'A', 'B', 'C', 'D', 'E', 'F'
   1.141 +};
   1.142 +
   1.143 +#define PNG_MAX_ERROR_TEXT 64
   1.144 +
   1.145 +#if !defined(PNG_NO_WARNINGS) || !defined(PNG_NO_ERROR_TEXT)
   1.146 +static void /* PRIVATE */
   1.147 +png_format_buffer(png_structp png_ptr, png_charp buffer, png_const_charp
   1.148 +   error_message)
   1.149 +{
   1.150 +   int iout = 0, iin = 0;
   1.151 +
   1.152 +   while (iin < 4)
   1.153 +   {
   1.154 +      int c = png_ptr->chunk_name[iin++];
   1.155 +      if (isnonalpha(c))
   1.156 +      {
   1.157 +         buffer[iout++] = '[';
   1.158 +         buffer[iout++] = png_digit[(c & 0xf0) >> 4];
   1.159 +         buffer[iout++] = png_digit[c & 0x0f];
   1.160 +         buffer[iout++] = ']';
   1.161 +      }
   1.162 +      else
   1.163 +      {
   1.164 +         buffer[iout++] = (png_byte)c;
   1.165 +      }
   1.166 +   }
   1.167 +
   1.168 +   if (error_message == NULL)
   1.169 +      buffer[iout] = '\0';
   1.170 +   else
   1.171 +   {
   1.172 +      buffer[iout++] = ':';
   1.173 +      buffer[iout++] = ' ';
   1.174 +      png_memcpy(buffer + iout, error_message, PNG_MAX_ERROR_TEXT);
   1.175 +      buffer[iout + PNG_MAX_ERROR_TEXT - 1] = '\0';
   1.176 +   }
   1.177 +}
   1.178 +
   1.179 +#ifdef PNG_READ_SUPPORTED
   1.180 +void PNGAPI
   1.181 +png_chunk_error(png_structp png_ptr, png_const_charp error_message)
   1.182 +{
   1.183 +   char msg[18+PNG_MAX_ERROR_TEXT];
   1.184 +   if (png_ptr == NULL)
   1.185 +     png_error(png_ptr, error_message);
   1.186 +   else
   1.187 +   {
   1.188 +     png_format_buffer(png_ptr, msg, error_message);
   1.189 +     png_error(png_ptr, msg);
   1.190 +   }
   1.191 +}
   1.192 +#endif /* PNG_READ_SUPPORTED */
   1.193 +#endif /* !defined(PNG_NO_WARNINGS) || !defined(PNG_NO_ERROR_TEXT) */
   1.194 +
   1.195 +#ifndef PNG_NO_WARNINGS
   1.196 +void PNGAPI
   1.197 +png_chunk_warning(png_structp png_ptr, png_const_charp warning_message)
   1.198 +{
   1.199 +   char msg[18+PNG_MAX_ERROR_TEXT];
   1.200 +   if (png_ptr == NULL)
   1.201 +     png_warning(png_ptr, warning_message);
   1.202 +   else
   1.203 +   {
   1.204 +     png_format_buffer(png_ptr, msg, warning_message);
   1.205 +     png_warning(png_ptr, msg);
   1.206 +   }
   1.207 +}
   1.208 +#endif /* PNG_NO_WARNINGS */
   1.209 +
   1.210 +
   1.211 +/* This is the default error handling function.  Note that replacements for
   1.212 + * this function MUST NOT RETURN, or the program will likely crash.  This
   1.213 + * function is used by default, or if the program supplies NULL for the
   1.214 + * error function pointer in png_set_error_fn().
   1.215 + */
   1.216 +static void /* PRIVATE */
   1.217 +png_default_error(png_structp png_ptr, png_const_charp error_message)
   1.218 +{
   1.219 +#ifndef PNG_NO_CONSOLE_IO
   1.220 +#ifdef PNG_ERROR_NUMBERS_SUPPORTED
   1.221 +   if (*error_message == '#')
   1.222 +   {
   1.223 +     /* Strip "#nnnn " from beginning of warning message. */
   1.224 +     int offset;
   1.225 +     char error_number[16];
   1.226 +     for (offset = 0; offset<15; offset++)
   1.227 +     {
   1.228 +         error_number[offset] = error_message[offset + 1];
   1.229 +         if (error_message[offset] == ' ')
   1.230 +             break;
   1.231 +     }
   1.232 +     if ((offset > 1) && (offset < 15))
   1.233 +     {
   1.234 +       error_number[offset - 1] = '\0';
   1.235 +       fprintf(stderr, "libpng error no. %s: %s\n", error_number,
   1.236 +          error_message + offset + 1);
   1.237 +     }
   1.238 +     else
   1.239 +       fprintf(stderr, "libpng error: %s, offset=%d\n", error_message, offset);
   1.240 +   }
   1.241 +   else
   1.242 +#endif
   1.243 +   fprintf(stderr, "libpng error: %s\n", error_message);
   1.244 +#endif
   1.245 +
   1.246 +#ifdef PNG_SETJMP_SUPPORTED
   1.247 +   if (png_ptr)
   1.248 +   {
   1.249 +#  ifdef USE_FAR_KEYWORD
   1.250 +   {
   1.251 +      jmp_buf jmpbuf;
   1.252 +      png_memcpy(jmpbuf, png_ptr->jmpbuf, png_sizeof(jmp_buf));
   1.253 +      longjmp(jmpbuf, 1);
   1.254 +   }
   1.255 +#  else
   1.256 +   longjmp(png_ptr->jmpbuf, 1);
   1.257 +#  endif
   1.258 +   }
   1.259 +#else
   1.260 +   PNG_ABORT();
   1.261 +#endif
   1.262 +#ifdef PNG_NO_CONSOLE_IO
   1.263 +   error_message = error_message; /* make compiler happy */
   1.264 +#endif
   1.265 +}
   1.266 +
   1.267 +#ifndef PNG_NO_WARNINGS
   1.268 +/* This function is called when there is a warning, but the library thinks
   1.269 + * it can continue anyway.  Replacement functions don't have to do anything
   1.270 + * here if you don't want them to.  In the default configuration, png_ptr is
   1.271 + * not used, but it is passed in case it may be useful.
   1.272 + */
   1.273 +static void /* PRIVATE */
   1.274 +png_default_warning(png_structp png_ptr, png_const_charp warning_message)
   1.275 +{
   1.276 +#ifndef PNG_NO_CONSOLE_IO
   1.277 +#  ifdef PNG_ERROR_NUMBERS_SUPPORTED
   1.278 +   if (*warning_message == '#')
   1.279 +   {
   1.280 +     int offset;
   1.281 +     char warning_number[16];
   1.282 +     for (offset = 0; offset < 15; offset++)
   1.283 +     {
   1.284 +        warning_number[offset] = warning_message[offset + 1];
   1.285 +        if (warning_message[offset] == ' ')
   1.286 +            break;
   1.287 +     }
   1.288 +     if ((offset > 1) && (offset < 15))
   1.289 +     {
   1.290 +       warning_number[offset + 1] = '\0';
   1.291 +       fprintf(stderr, "libpng warning no. %s: %s\n", warning_number,
   1.292 +          warning_message + offset);
   1.293 +     }
   1.294 +     else
   1.295 +       fprintf(stderr, "libpng warning: %s\n", warning_message);
   1.296 +   }
   1.297 +   else
   1.298 +#  endif
   1.299 +     fprintf(stderr, "libpng warning: %s\n", warning_message);
   1.300 +#else
   1.301 +   warning_message = warning_message; /* make compiler happy */
   1.302 +#endif
   1.303 +   png_ptr = png_ptr; /* make compiler happy */
   1.304 +}
   1.305 +#endif /* PNG_NO_WARNINGS */
   1.306 +
   1.307 +/* This function is called when the application wants to use another method
   1.308 + * of handling errors and warnings.  Note that the error function MUST NOT
   1.309 + * return to the calling routine or serious problems will occur.  The return
   1.310 + * method used in the default routine calls longjmp(png_ptr->jmpbuf, 1)
   1.311 + */
   1.312 +void PNGAPI
   1.313 +png_set_error_fn(png_structp png_ptr, png_voidp error_ptr,
   1.314 +   png_error_ptr error_fn, png_error_ptr warning_fn)
   1.315 +{
   1.316 +   if (png_ptr == NULL)
   1.317 +      return;
   1.318 +   png_ptr->error_ptr = error_ptr;
   1.319 +   png_ptr->error_fn = error_fn;
   1.320 +   png_ptr->warning_fn = warning_fn;
   1.321 +}
   1.322 +
   1.323 +
   1.324 +/* This function returns a pointer to the error_ptr associated with the user
   1.325 + * functions.  The application should free any memory associated with this
   1.326 + * pointer before png_write_destroy and png_read_destroy are called.
   1.327 + */
   1.328 +png_voidp PNGAPI
   1.329 +png_get_error_ptr(png_structp png_ptr)
   1.330 +{
   1.331 +   if (png_ptr == NULL)
   1.332 +      return NULL;
   1.333 +   return ((png_voidp)png_ptr->error_ptr);
   1.334 +}
   1.335 +
   1.336 +
   1.337 +#ifdef PNG_ERROR_NUMBERS_SUPPORTED
   1.338 +void PNGAPI
   1.339 +png_set_strip_error_numbers(png_structp png_ptr, png_uint_32 strip_mode)
   1.340 +{
   1.341 +   if (png_ptr != NULL)
   1.342 +   {
   1.343 +     png_ptr->flags &=
   1.344 +       ((~(PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))&strip_mode);
   1.345 +   }
   1.346 +}
   1.347 +#endif
   1.348 +#endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */