jdk/src/share/native/sun/awt/libpng/pngerror.c
author ohair
Tue, 25 May 2010 15:58:33 -0700
changeset 5506 202f599c92aa
parent 2 90ce3da70b43
child 10576 db3409425573
permissions -rw-r--r--
6943119: Rebrand source copyright notices Reviewed-by: darcy, weijun
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     6
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     8
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    20
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 * THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
/* pngerror.c - stub functions for i/o and memory allocation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * This file is available under and governed by the GNU General Public
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * License version 2 only, as published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * However, the following notice accompanied the original version of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * file and, per its terms, should not be removed:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * Last changed in libpng 1.2.13 November 13, 2006
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * For conditions of distribution and use, see copyright notice in png.h
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * Copyright (c) 1998-2006 Glenn Randers-Pehrson
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * This file provides a location for all error handling.  Users who
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * need special error handling are expected to write replacement functions
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * and use png_set_error_fn() to use those functions.  See the instructions
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * at each function.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
#define PNG_INTERNAL
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
#include "png.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
static void /* PRIVATE */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
png_default_error PNGARG((png_structp png_ptr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
  png_const_charp error_message));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
static void /* PRIVATE */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
png_default_warning PNGARG((png_structp png_ptr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
  png_const_charp warning_message));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
/* This function is called whenever there is a fatal error.  This function
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * should not be changed.  If there is a need to handle errors differently,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * you should supply a replacement error function and use png_set_error_fn()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * to replace the error function at run-time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
void PNGAPI
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
png_error(png_structp png_ptr, png_const_charp error_message)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
#ifdef PNG_ERROR_NUMBERS_SUPPORTED
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
   char msg[16];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
   if (png_ptr != NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     if (png_ptr->flags&
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
       (PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
       if (*error_message == '#')
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
       {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
           int offset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
           for (offset=1; offset<15; offset++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
              if (*(error_message+offset) == ' ')
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
           if (png_ptr->flags&PNG_FLAG_STRIP_ERROR_TEXT)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
           {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
              int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
              for (i=0; i<offset-1; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
                 msg[i]=error_message[i+1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
              msg[i]='\0';
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
              error_message=msg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
           }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
           else
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
              error_message+=offset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
       }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
       else
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
       {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
           if (png_ptr->flags&PNG_FLAG_STRIP_ERROR_TEXT)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
           {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
              msg[0]='0';
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
              msg[1]='\0';
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
              error_message=msg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
           }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
       }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
   if (png_ptr != NULL && png_ptr->error_fn != NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
      (*(png_ptr->error_fn))(png_ptr, error_message);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
   /* If the custom handler doesn't exist, or if it returns,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
      use the default handler, which will not return. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
   png_default_error(png_ptr, error_message);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
/* This function is called whenever there is a non-fatal error.  This function
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
 * should not be changed.  If there is a need to handle warnings differently,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
 * you should supply a replacement warning function and use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
 * png_set_error_fn() to replace the warning function at run-time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
void PNGAPI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
png_warning(png_structp png_ptr, png_const_charp warning_message)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
   int offset = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
   if (png_ptr != NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
#ifdef PNG_ERROR_NUMBERS_SUPPORTED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
   if (png_ptr->flags&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     (PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
       if (*warning_message == '#')
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
       {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
           for (offset=1; offset<15; offset++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
              if (*(warning_message+offset) == ' ')
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
       }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     if (png_ptr != NULL && png_ptr->warning_fn != NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        (*(png_ptr->warning_fn))(png_ptr, warning_message+offset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
   else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
      png_default_warning(png_ptr, warning_message+offset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
/* These utilities are used internally to build an error message that relates
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
 * to the current chunk.  The chunk name comes from png_ptr->chunk_name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
 * this is used to prefix the message.  The message is limited in length
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
 * to 63 bytes, the name characters are output as hex digits wrapped in []
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
 * if the character is invalid.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
#define isnonalpha(c) ((c) < 65 || (c) > 122 || ((c) > 90 && (c) < 97))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
static PNG_CONST char png_digit[16] = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
   '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
   'A', 'B', 'C', 'D', 'E', 'F'
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
static void /* PRIVATE */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
png_format_buffer(png_structp png_ptr, png_charp buffer, png_const_charp
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
   error_message)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
   int iout = 0, iin = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
   while (iin < 4)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
      int c = png_ptr->chunk_name[iin++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
      if (isnonalpha(c))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
         buffer[iout++] = '[';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
         buffer[iout++] = png_digit[(c & 0xf0) >> 4];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
         buffer[iout++] = png_digit[c & 0x0f];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
         buffer[iout++] = ']';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
      else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
         buffer[iout++] = (png_byte)c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
   if (error_message == NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
      buffer[iout] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
   else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
      buffer[iout++] = ':';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
      buffer[iout++] = ' ';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
      png_strncpy(buffer+iout, error_message, 63);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
      buffer[iout+63] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
void PNGAPI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
png_chunk_error(png_structp png_ptr, png_const_charp error_message)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
   char msg[18+64];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
   if (png_ptr == NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     png_error(png_ptr, error_message);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
   else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     png_format_buffer(png_ptr, msg, error_message);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     png_error(png_ptr, msg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
void PNGAPI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
png_chunk_warning(png_structp png_ptr, png_const_charp warning_message)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
   char msg[18+64];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
   if (png_ptr == NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     png_warning(png_ptr, warning_message);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
   else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     png_format_buffer(png_ptr, msg, warning_message);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     png_warning(png_ptr, msg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
/* This is the default error handling function.  Note that replacements for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
 * this function MUST NOT RETURN, or the program will likely crash.  This
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
 * function is used by default, or if the program supplies NULL for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
 * error function pointer in png_set_error_fn().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
static void /* PRIVATE */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
png_default_error(png_structp png_ptr, png_const_charp error_message)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
#ifndef PNG_NO_CONSOLE_IO
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
#ifdef PNG_ERROR_NUMBERS_SUPPORTED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
   if (*error_message == '#')
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     int offset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     char error_number[16];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     for (offset=0; offset<15; offset++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
         error_number[offset] = *(error_message+offset+1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
         if (*(error_message+offset) == ' ')
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
             break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     if((offset > 1) && (offset < 15))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
       error_number[offset-1]='\0';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
       fprintf(stderr, "libpng error no. %s: %s\n", error_number,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
          error_message+offset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
       fprintf(stderr, "libpng error: %s, offset=%d\n", error_message,offset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
   else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
   fprintf(stderr, "libpng error: %s\n", error_message);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
#ifdef PNG_SETJMP_SUPPORTED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
   if (png_ptr)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
#  ifdef USE_FAR_KEYWORD
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
      jmp_buf jmpbuf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
      png_memcpy(jmpbuf,png_ptr->jmpbuf,png_sizeof(jmp_buf));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
      longjmp(jmpbuf, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
#  else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
   longjmp(png_ptr->jmpbuf, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
#  endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
   PNG_ABORT();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
#ifdef PNG_NO_CONSOLE_IO
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
   /* make compiler happy */ ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
   if (&error_message != NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
      return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
/* This function is called when there is a warning, but the library thinks
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
 * it can continue anyway.  Replacement functions don't have to do anything
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
 * here if you don't want them to.  In the default configuration, png_ptr is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
 * not used, but it is passed in case it may be useful.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
static void /* PRIVATE */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
png_default_warning(png_structp png_ptr, png_const_charp warning_message)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
#ifndef PNG_NO_CONSOLE_IO
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
#  ifdef PNG_ERROR_NUMBERS_SUPPORTED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
   if (*warning_message == '#')
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     int offset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     char warning_number[16];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     for (offset=0; offset<15; offset++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        warning_number[offset]=*(warning_message+offset+1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        if (*(warning_message+offset) == ' ')
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     if((offset > 1) && (offset < 15))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
       warning_number[offset-1]='\0';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
       fprintf(stderr, "libpng warning no. %s: %s\n", warning_number,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
          warning_message+offset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
       fprintf(stderr, "libpng warning: %s\n", warning_message);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
   else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
#  endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     fprintf(stderr, "libpng warning: %s\n", warning_message);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
   /* make compiler happy */ ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
   if (warning_message)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
   /* make compiler happy */ ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
   if (png_ptr)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
      return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
/* This function is called when the application wants to use another method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
 * of handling errors and warnings.  Note that the error function MUST NOT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
 * return to the calling routine or serious problems will occur.  The return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
 * method used in the default routine calls longjmp(png_ptr->jmpbuf, 1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
void PNGAPI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
png_set_error_fn(png_structp png_ptr, png_voidp error_ptr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
   png_error_ptr error_fn, png_error_ptr warning_fn)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
   if (png_ptr == NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
      return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
   png_ptr->error_ptr = error_ptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
   png_ptr->error_fn = error_fn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
   png_ptr->warning_fn = warning_fn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
/* This function returns a pointer to the error_ptr associated with the user
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
 * functions.  The application should free any memory associated with this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
 * pointer before png_write_destroy and png_read_destroy are called.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
png_voidp PNGAPI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
png_get_error_ptr(png_structp png_ptr)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
   if (png_ptr == NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
      return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
   return ((png_voidp)png_ptr->error_ptr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
#ifdef PNG_ERROR_NUMBERS_SUPPORTED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
void PNGAPI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
png_set_strip_error_numbers(png_structp png_ptr, png_uint_32 strip_mode)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
   if(png_ptr != NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     png_ptr->flags &=
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
       ((~(PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))&strip_mode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
#endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */