png.c
Go to the documentation of this file.
00001 
00002 /* png.c - location for general purpose libpng functions
00003  *
00004  * Last changed in libpng 1.2.30 [August 15, 2008]
00005  * For conditions of distribution and use, see copyright notice in png.h
00006  * Copyright (c) 1998-2008 Glenn Randers-Pehrson
00007  * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
00008  * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
00009  */
00010 
00011 #define PNG_INTERNAL
00012 #define PNG_NO_EXTERN
00013 #include "png.h"
00014 
00015 /* Generate a compiler error if there is an old png.h in the search path. */
00016 typedef version_1_2_32 Your_png_h_is_not_version_1_2_32;
00017 
00018 /* Version information for C files.  This had better match the version
00019  * string defined in png.h.  */
00020 
00021 #ifdef PNG_USE_GLOBAL_ARRAYS
00022 /* png_libpng_ver was changed to a function in version 1.0.5c */
00023 PNG_CONST char png_libpng_ver[18] = PNG_LIBPNG_VER_STRING;
00024 
00025 #ifdef PNG_READ_SUPPORTED
00026 
00027 /* png_sig was changed to a function in version 1.0.5c */
00028 /* Place to hold the signature string for a PNG file. */
00029 PNG_CONST png_byte FARDATA png_sig[8] = {137, 80, 78, 71, 13, 10, 26, 10};
00030 #endif /* PNG_READ_SUPPORTED */
00031 
00032 /* Invoke global declarations for constant strings for known chunk types */
00033 PNG_IHDR;
00034 PNG_IDAT;
00035 PNG_IEND;
00036 PNG_PLTE;
00037 PNG_bKGD;
00038 PNG_cHRM;
00039 PNG_gAMA;
00040 PNG_hIST;
00041 PNG_iCCP;
00042 PNG_iTXt;
00043 PNG_oFFs;
00044 PNG_pCAL;
00045 PNG_sCAL;
00046 PNG_pHYs;
00047 PNG_sBIT;
00048 PNG_sPLT;
00049 PNG_sRGB;
00050 PNG_tEXt;
00051 PNG_tIME;
00052 PNG_tRNS;
00053 PNG_zTXt;
00054 
00055 #ifdef PNG_READ_SUPPORTED
00056 /* arrays to facilitate easy interlacing - use pass (0 - 6) as index */
00057 
00058 /* start of interlace block */
00059 PNG_CONST int FARDATA png_pass_start[] = {0, 4, 0, 2, 0, 1, 0};
00060 
00061 /* offset to next interlace block */
00062 PNG_CONST int FARDATA png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1};
00063 
00064 /* start of interlace block in the y direction */
00065 PNG_CONST int FARDATA png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1};
00066 
00067 /* offset to next interlace block in the y direction */
00068 PNG_CONST int FARDATA png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2};
00069 
00070 /* Height of interlace block.  This is not currently used - if you need
00071  * it, uncomment it here and in png.h
00072 PNG_CONST int FARDATA png_pass_height[] = {8, 8, 4, 4, 2, 2, 1};
00073 */
00074 
00075 /* Mask to determine which pixels are valid in a pass */
00076 PNG_CONST int FARDATA png_pass_mask[] = {0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xff};
00077 
00078 /* Mask to determine which pixels to overwrite while displaying */
00079 PNG_CONST int FARDATA png_pass_dsp_mask[]
00080    = {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff};
00081 
00082 #endif /* PNG_READ_SUPPORTED */
00083 #endif /* PNG_USE_GLOBAL_ARRAYS */
00084 
00085 /* Tells libpng that we have already handled the first "num_bytes" bytes
00086  * of the PNG file signature.  If the PNG data is embedded into another
00087  * stream we can set num_bytes = 8 so that libpng will not attempt to read
00088  * or write any of the magic bytes before it starts on the IHDR.
00089  */
00090 
00091 #ifdef PNG_READ_SUPPORTED
00092 void PNGAPI
00093 png_set_sig_bytes(png_structp png_ptr, int num_bytes)
00094 {
00095    if (png_ptr == NULL) return;
00096    png_debug(1, "in png_set_sig_bytes\n");
00097    if (num_bytes > 8)
00098       png_error(png_ptr, "Too many bytes for PNG signature.");
00099 
00100    png_ptr->sig_bytes = (png_byte)(num_bytes < 0 ? 0 : num_bytes);
00101 }
00102 
00103 /* Checks whether the supplied bytes match the PNG signature.  We allow
00104  * checking less than the full 8-byte signature so that those apps that
00105  * already read the first few bytes of a file to determine the file type
00106  * can simply check the remaining bytes for extra assurance.  Returns
00107  * an integer less than, equal to, or greater than zero if sig is found,
00108  * respectively, to be less than, to match, or be greater than the correct
00109  * PNG signature (this is the same behaviour as strcmp, memcmp, etc).
00110  */
00111 int PNGAPI
00112 png_sig_cmp(png_bytep sig, png_size_t start, png_size_t num_to_check)
00113 {
00114    png_byte png_signature[8] = {137, 80, 78, 71, 13, 10, 26, 10};
00115    if (num_to_check > 8)
00116       num_to_check = 8;
00117    else if (num_to_check < 1)
00118       return (-1);
00119 
00120    if (start > 7)
00121       return (-1);
00122 
00123    if (start + num_to_check > 8)
00124       num_to_check = 8 - start;
00125 
00126    return ((int)(png_memcmp(&sig[start], &png_signature[start], num_to_check)));
00127 }
00128 
00129 #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
00130 /* (Obsolete) function to check signature bytes.  It does not allow one
00131  * to check a partial signature.  This function might be removed in the
00132  * future - use png_sig_cmp().  Returns true (nonzero) if the file is PNG.
00133  */
00134 int PNGAPI
00135 png_check_sig(png_bytep sig, int num)
00136 {
00137   return ((int)!png_sig_cmp(sig, (png_size_t)0, (png_size_t)num));
00138 }
00139 #endif
00140 #endif /* PNG_READ_SUPPORTED */
00141 
00142 #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
00143 /* Function to allocate memory for zlib and clear it to 0. */
00144 #ifdef PNG_1_0_X
00145 voidpf PNGAPI
00146 #else
00147 voidpf /* private */
00148 #endif
00149 png_zalloc(voidpf png_ptr, uInt items, uInt size)
00150 {
00151    png_voidp ptr;
00152    png_structp p=(png_structp)png_ptr;
00153    png_uint_32 save_flags=p->flags;
00154    png_uint_32 num_bytes;
00155 
00156    if (png_ptr == NULL) return (NULL);
00157    if (items > PNG_UINT_32_MAX/size)
00158    {
00159      png_warning (p, "Potential overflow in png_zalloc()");
00160      return (NULL);
00161    }
00162    num_bytes = (png_uint_32)items * size;
00163 
00164    p->flags|=PNG_FLAG_MALLOC_NULL_MEM_OK;
00165    ptr = (png_voidp)png_malloc((png_structp)png_ptr, num_bytes);
00166    p->flags=save_flags;
00167 
00168 #if defined(PNG_1_0_X) && !defined(PNG_NO_ZALLOC_ZERO)
00169    if (ptr == NULL)
00170        return ((voidpf)ptr);
00171 
00172    if (num_bytes > (png_uint_32)0x8000L)
00173    {
00174       png_memset(ptr, 0, (png_size_t)0x8000L);
00175       png_memset((png_bytep)ptr + (png_size_t)0x8000L, 0,
00176          (png_size_t)(num_bytes - (png_uint_32)0x8000L));
00177    }
00178    else
00179    {
00180       png_memset(ptr, 0, (png_size_t)num_bytes);
00181    }
00182 #endif
00183    return ((voidpf)ptr);
00184 }
00185 
00186 /* function to free memory for zlib */
00187 #ifdef PNG_1_0_X
00188 void PNGAPI
00189 #else
00190 void /* private */
00191 #endif
00192 png_zfree(voidpf png_ptr, voidpf ptr)
00193 {
00194    png_free((png_structp)png_ptr, (png_voidp)ptr);
00195 }
00196 
00197 /* Reset the CRC variable to 32 bits of 1's.  Care must be taken
00198  * in case CRC is > 32 bits to leave the top bits 0.
00199  */
00200 void /* PRIVATE */
00201 png_reset_crc(png_structp png_ptr)
00202 {
00203    png_ptr->crc = crc32(0, Z_NULL, 0);
00204 }
00205 
00206 /* Calculate the CRC over a section of data.  We can only pass as
00207  * much data to this routine as the largest single buffer size.  We
00208  * also check that this data will actually be used before going to the
00209  * trouble of calculating it.
00210  */
00211 void /* PRIVATE */
00212 png_calculate_crc(png_structp png_ptr, png_bytep ptr, png_size_t length)
00213 {
00214    int need_crc = 1;
00215 
00216    if (png_ptr->chunk_name[0] & 0x20)                     /* ancillary */
00217    {
00218       if ((png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_MASK) ==
00219           (PNG_FLAG_CRC_ANCILLARY_USE | PNG_FLAG_CRC_ANCILLARY_NOWARN))
00220          need_crc = 0;
00221    }
00222    else                                                    /* critical */
00223    {
00224       if (png_ptr->flags & PNG_FLAG_CRC_CRITICAL_IGNORE)
00225          need_crc = 0;
00226    }
00227 
00228    if (need_crc)
00229       png_ptr->crc = crc32(png_ptr->crc, ptr, (uInt)length);
00230 }
00231 
00232 /* Allocate the memory for an info_struct for the application.  We don't
00233  * really need the png_ptr, but it could potentially be useful in the
00234  * future.  This should be used in favour of malloc(png_sizeof(png_info))
00235  * and png_info_init() so that applications that want to use a shared
00236  * libpng don't have to be recompiled if png_info changes size.
00237  */
00238 png_infop PNGAPI
00239 png_create_info_struct(png_structp png_ptr)
00240 {
00241    png_infop info_ptr;
00242 
00243    png_debug(1, "in png_create_info_struct\n");
00244    if (png_ptr == NULL) return (NULL);
00245 #ifdef PNG_USER_MEM_SUPPORTED
00246    info_ptr = (png_infop)png_create_struct_2(PNG_STRUCT_INFO,
00247       png_ptr->malloc_fn, png_ptr->mem_ptr);
00248 #else
00249    info_ptr = (png_infop)png_create_struct(PNG_STRUCT_INFO);
00250 #endif
00251    if (info_ptr != NULL)
00252       png_info_init_3(&info_ptr, png_sizeof(png_info));
00253 
00254    return (info_ptr);
00255 }
00256 
00257 /* This function frees the memory associated with a single info struct.
00258  * Normally, one would use either png_destroy_read_struct() or
00259  * png_destroy_write_struct() to free an info struct, but this may be
00260  * useful for some applications.
00261  */
00262 void PNGAPI
00263 png_destroy_info_struct(png_structp png_ptr, png_infopp info_ptr_ptr)
00264 {
00265    png_infop info_ptr = NULL;
00266    if (png_ptr == NULL) return;
00267 
00268    png_debug(1, "in png_destroy_info_struct\n");
00269    if (info_ptr_ptr != NULL)
00270       info_ptr = *info_ptr_ptr;
00271 
00272    if (info_ptr != NULL)
00273    {
00274       png_info_destroy(png_ptr, info_ptr);
00275 
00276 #ifdef PNG_USER_MEM_SUPPORTED
00277       png_destroy_struct_2((png_voidp)info_ptr, png_ptr->free_fn,
00278           png_ptr->mem_ptr);
00279 #else
00280       png_destroy_struct((png_voidp)info_ptr);
00281 #endif
00282       *info_ptr_ptr = NULL;
00283    }
00284 }
00285 
00286 /* Initialize the info structure.  This is now an internal function (0.89)
00287  * and applications using it are urged to use png_create_info_struct()
00288  * instead.
00289  */
00290 #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
00291 #undef png_info_init
00292 void PNGAPI
00293 png_info_init(png_infop info_ptr)
00294 {
00295    /* We only come here via pre-1.0.12-compiled applications */
00296    png_info_init_3(&info_ptr, 0);
00297 }
00298 #endif
00299 
00300 void PNGAPI
00301 png_info_init_3(png_infopp ptr_ptr, png_size_t png_info_struct_size)
00302 {
00303    png_infop info_ptr = *ptr_ptr;
00304 
00305    if (info_ptr == NULL) return;
00306 
00307    png_debug(1, "in png_info_init_3\n");
00308 
00309    if (png_sizeof(png_info) > png_info_struct_size)
00310      {
00311        png_destroy_struct(info_ptr);
00312        info_ptr = (png_infop)png_create_struct(PNG_STRUCT_INFO);
00313        *ptr_ptr = info_ptr;
00314      }
00315 
00316    /* set everything to 0 */
00317    png_memset(info_ptr, 0, png_sizeof(png_info));
00318 }
00319 
00320 #ifdef PNG_FREE_ME_SUPPORTED
00321 void PNGAPI
00322 png_data_freer(png_structp png_ptr, png_infop info_ptr,
00323    int freer, png_uint_32 mask)
00324 {
00325    png_debug(1, "in png_data_freer\n");
00326    if (png_ptr == NULL || info_ptr == NULL)
00327       return;
00328    if (freer == PNG_DESTROY_WILL_FREE_DATA)
00329       info_ptr->free_me |= mask;
00330    else if (freer == PNG_USER_WILL_FREE_DATA)
00331       info_ptr->free_me &= ~mask;
00332    else
00333       png_warning(png_ptr,
00334          "Unknown freer parameter in png_data_freer.");
00335 }
00336 #endif
00337 
00338 void PNGAPI
00339 png_free_data(png_structp png_ptr, png_infop info_ptr, png_uint_32 mask,
00340    int num)
00341 {
00342    png_debug(1, "in png_free_data\n");
00343    if (png_ptr == NULL || info_ptr == NULL)
00344       return;
00345 
00346 #if defined(PNG_TEXT_SUPPORTED)
00347 /* free text item num or (if num == -1) all text items */
00348 #ifdef PNG_FREE_ME_SUPPORTED
00349 if ((mask & PNG_FREE_TEXT) & info_ptr->free_me)
00350 #else
00351 if (mask & PNG_FREE_TEXT)
00352 #endif
00353 {
00354    if (num != -1)
00355    {
00356      if (info_ptr->text && info_ptr->text[num].key)
00357      {
00358          png_free(png_ptr, info_ptr->text[num].key);
00359          info_ptr->text[num].key = NULL;
00360      }
00361    }
00362    else
00363    {
00364        int i;
00365        for (i = 0; i < info_ptr->num_text; i++)
00366            png_free_data(png_ptr, info_ptr, PNG_FREE_TEXT, i);
00367        png_free(png_ptr, info_ptr->text);
00368        info_ptr->text = NULL;
00369        info_ptr->num_text=0;
00370    }
00371 }
00372 #endif
00373 
00374 #if defined(PNG_tRNS_SUPPORTED)
00375 /* free any tRNS entry */
00376 #ifdef PNG_FREE_ME_SUPPORTED
00377 if ((mask & PNG_FREE_TRNS) & info_ptr->free_me)
00378 #else
00379 if ((mask & PNG_FREE_TRNS) && (png_ptr->flags & PNG_FLAG_FREE_TRNS))
00380 #endif
00381 {
00382     png_free(png_ptr, info_ptr->trans);
00383     info_ptr->trans = NULL;
00384     info_ptr->valid &= ~PNG_INFO_tRNS;
00385 #ifndef PNG_FREE_ME_SUPPORTED
00386     png_ptr->flags &= ~PNG_FLAG_FREE_TRNS;
00387 #endif
00388 }
00389 #endif
00390 
00391 #if defined(PNG_sCAL_SUPPORTED)
00392 /* free any sCAL entry */
00393 #ifdef PNG_FREE_ME_SUPPORTED
00394 if ((mask & PNG_FREE_SCAL) & info_ptr->free_me)
00395 #else
00396 if (mask & PNG_FREE_SCAL)
00397 #endif
00398 {
00399 #if defined(PNG_FIXED_POINT_SUPPORTED) && !defined(PNG_FLOATING_POINT_SUPPORTED)
00400     png_free(png_ptr, info_ptr->scal_s_width);
00401     png_free(png_ptr, info_ptr->scal_s_height);
00402     info_ptr->scal_s_width = NULL;
00403     info_ptr->scal_s_height = NULL;
00404 #endif
00405     info_ptr->valid &= ~PNG_INFO_sCAL;
00406 }
00407 #endif
00408 
00409 #if defined(PNG_pCAL_SUPPORTED)
00410 /* free any pCAL entry */
00411 #ifdef PNG_FREE_ME_SUPPORTED
00412 if ((mask & PNG_FREE_PCAL) & info_ptr->free_me)
00413 #else
00414 if (mask & PNG_FREE_PCAL)
00415 #endif
00416 {
00417     png_free(png_ptr, info_ptr->pcal_purpose);
00418     png_free(png_ptr, info_ptr->pcal_units);
00419     info_ptr->pcal_purpose = NULL;
00420     info_ptr->pcal_units = NULL;
00421     if (info_ptr->pcal_params != NULL)
00422     {
00423         int i;
00424         for (i = 0; i < (int)info_ptr->pcal_nparams; i++)
00425         {
00426           png_free(png_ptr, info_ptr->pcal_params[i]);
00427           info_ptr->pcal_params[i]=NULL;
00428         }
00429         png_free(png_ptr, info_ptr->pcal_params);
00430         info_ptr->pcal_params = NULL;
00431     }
00432     info_ptr->valid &= ~PNG_INFO_pCAL;
00433 }
00434 #endif
00435 
00436 #if defined(PNG_iCCP_SUPPORTED)
00437 /* free any iCCP entry */
00438 #ifdef PNG_FREE_ME_SUPPORTED
00439 if ((mask & PNG_FREE_ICCP) & info_ptr->free_me)
00440 #else
00441 if (mask & PNG_FREE_ICCP)
00442 #endif
00443 {
00444     png_free(png_ptr, info_ptr->iccp_name);
00445     png_free(png_ptr, info_ptr->iccp_profile);
00446     info_ptr->iccp_name = NULL;
00447     info_ptr->iccp_profile = NULL;
00448     info_ptr->valid &= ~PNG_INFO_iCCP;
00449 }
00450 #endif
00451 
00452 #if defined(PNG_sPLT_SUPPORTED)
00453 /* free a given sPLT entry, or (if num == -1) all sPLT entries */
00454 #ifdef PNG_FREE_ME_SUPPORTED
00455 if ((mask & PNG_FREE_SPLT) & info_ptr->free_me)
00456 #else
00457 if (mask & PNG_FREE_SPLT)
00458 #endif
00459 {
00460    if (num != -1)
00461    {
00462       if (info_ptr->splt_palettes)
00463       {
00464           png_free(png_ptr, info_ptr->splt_palettes[num].name);
00465           png_free(png_ptr, info_ptr->splt_palettes[num].entries);
00466           info_ptr->splt_palettes[num].name = NULL;
00467           info_ptr->splt_palettes[num].entries = NULL;
00468       }
00469    }
00470    else
00471    {
00472        if (info_ptr->splt_palettes_num)
00473        {
00474          int i;
00475          for (i = 0; i < (int)info_ptr->splt_palettes_num; i++)
00476             png_free_data(png_ptr, info_ptr, PNG_FREE_SPLT, i);
00477 
00478          png_free(png_ptr, info_ptr->splt_palettes);
00479          info_ptr->splt_palettes = NULL;
00480          info_ptr->splt_palettes_num = 0;
00481        }
00482        info_ptr->valid &= ~PNG_INFO_sPLT;
00483    }
00484 }
00485 #endif
00486 
00487 #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
00488   if (png_ptr->unknown_chunk.data)
00489   {
00490     png_free(png_ptr, png_ptr->unknown_chunk.data);
00491     png_ptr->unknown_chunk.data = NULL;
00492   }
00493 
00494 #ifdef PNG_FREE_ME_SUPPORTED
00495 if ((mask & PNG_FREE_UNKN) & info_ptr->free_me)
00496 #else
00497 if (mask & PNG_FREE_UNKN)
00498 #endif
00499 {
00500    if (num != -1)
00501    {
00502        if (info_ptr->unknown_chunks)
00503        {
00504           png_free(png_ptr, info_ptr->unknown_chunks[num].data);
00505           info_ptr->unknown_chunks[num].data = NULL;
00506        }
00507    }
00508    else
00509    {
00510        int i;
00511 
00512        if (info_ptr->unknown_chunks_num)
00513        {
00514          for (i = 0; i < (int)info_ptr->unknown_chunks_num; i++)
00515             png_free_data(png_ptr, info_ptr, PNG_FREE_UNKN, i);
00516 
00517          png_free(png_ptr, info_ptr->unknown_chunks);
00518          info_ptr->unknown_chunks = NULL;
00519          info_ptr->unknown_chunks_num = 0;
00520        }
00521    }
00522 }
00523 #endif
00524 
00525 #if defined(PNG_hIST_SUPPORTED)
00526 /* free any hIST entry */
00527 #ifdef PNG_FREE_ME_SUPPORTED
00528 if ((mask & PNG_FREE_HIST)  & info_ptr->free_me)
00529 #else
00530 if ((mask & PNG_FREE_HIST) && (png_ptr->flags & PNG_FLAG_FREE_HIST))
00531 #endif
00532 {
00533     png_free(png_ptr, info_ptr->hist);
00534     info_ptr->hist = NULL;
00535     info_ptr->valid &= ~PNG_INFO_hIST;
00536 #ifndef PNG_FREE_ME_SUPPORTED
00537     png_ptr->flags &= ~PNG_FLAG_FREE_HIST;
00538 #endif
00539 }
00540 #endif
00541 
00542 /* free any PLTE entry that was internally allocated */
00543 #ifdef PNG_FREE_ME_SUPPORTED
00544 if ((mask & PNG_FREE_PLTE) & info_ptr->free_me)
00545 #else
00546 if ((mask & PNG_FREE_PLTE) && (png_ptr->flags & PNG_FLAG_FREE_PLTE))
00547 #endif
00548 {
00549     png_zfree(png_ptr, info_ptr->palette);
00550     info_ptr->palette = NULL;
00551     info_ptr->valid &= ~PNG_INFO_PLTE;
00552 #ifndef PNG_FREE_ME_SUPPORTED
00553     png_ptr->flags &= ~PNG_FLAG_FREE_PLTE;
00554 #endif
00555     info_ptr->num_palette = 0;
00556 }
00557 
00558 #if defined(PNG_INFO_IMAGE_SUPPORTED)
00559 /* free any image bits attached to the info structure */
00560 #ifdef PNG_FREE_ME_SUPPORTED
00561 if ((mask & PNG_FREE_ROWS) & info_ptr->free_me)
00562 #else
00563 if (mask & PNG_FREE_ROWS)
00564 #endif
00565 {
00566     if (info_ptr->row_pointers)
00567     {
00568        int row;
00569        for (row = 0; row < (int)info_ptr->height; row++)
00570        {
00571           png_free(png_ptr, info_ptr->row_pointers[row]);
00572           info_ptr->row_pointers[row]=NULL;
00573        }
00574        png_free(png_ptr, info_ptr->row_pointers);
00575        info_ptr->row_pointers=NULL;
00576     }
00577     info_ptr->valid &= ~PNG_INFO_IDAT;
00578 }
00579 #endif
00580 
00581 #ifdef PNG_FREE_ME_SUPPORTED
00582    if (num == -1)
00583      info_ptr->free_me &= ~mask;
00584    else
00585      info_ptr->free_me &= ~(mask & ~PNG_FREE_MUL);
00586 #endif
00587 }
00588 
00589 /* This is an internal routine to free any memory that the info struct is
00590  * pointing to before re-using it or freeing the struct itself.  Recall
00591  * that png_free() checks for NULL pointers for us.
00592  */
00593 void /* PRIVATE */
00594 png_info_destroy(png_structp png_ptr, png_infop info_ptr)
00595 {
00596    png_debug(1, "in png_info_destroy\n");
00597 
00598    png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1);
00599 
00600 #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
00601    if (png_ptr->num_chunk_list)
00602    {
00603        png_free(png_ptr, png_ptr->chunk_list);
00604        png_ptr->chunk_list=NULL;
00605        png_ptr->num_chunk_list = 0;
00606    }
00607 #endif
00608 
00609    png_info_init_3(&info_ptr, png_sizeof(png_info));
00610 }
00611 #endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */
00612 
00613 /* This function returns a pointer to the io_ptr associated with the user
00614  * functions.  The application should free any memory associated with this
00615  * pointer before png_write_destroy() or png_read_destroy() are called.
00616  */
00617 png_voidp PNGAPI
00618 png_get_io_ptr(png_structp png_ptr)
00619 {
00620    if (png_ptr == NULL) return (NULL);
00621    return (png_ptr->io_ptr);
00622 }
00623 
00624 #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
00625 #if !defined(PNG_NO_STDIO)
00626 /* Initialize the default input/output functions for the PNG file.  If you
00627  * use your own read or write routines, you can call either png_set_read_fn()
00628  * or png_set_write_fn() instead of png_init_io().  If you have defined
00629  * PNG_NO_STDIO, you must use a function of your own because "FILE *" isn't
00630  * necessarily available.
00631  */
00632 void PNGAPI
00633 png_init_io(png_structp png_ptr, png_FILE_p fp)
00634 {
00635    png_debug(1, "in png_init_io\n");
00636    if (png_ptr == NULL) return;
00637    png_ptr->io_ptr = (png_voidp)fp;
00638 }
00639 #endif
00640 
00641 #if defined(PNG_TIME_RFC1123_SUPPORTED)
00642 /* Convert the supplied time into an RFC 1123 string suitable for use in
00643  * a "Creation Time" or other text-based time string.
00644  */
00645 png_charp PNGAPI
00646 png_convert_to_rfc1123(png_structp png_ptr, png_timep ptime)
00647 {
00648    static PNG_CONST char short_months[12][4] =
00649         {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
00650          "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
00651 
00652    if (png_ptr == NULL) return (NULL);
00653    if (png_ptr->time_buffer == NULL)
00654    {
00655       png_ptr->time_buffer = (png_charp)png_malloc(png_ptr, (png_uint_32)(29*
00656          png_sizeof(char)));
00657    }
00658 
00659 #if defined(_WIN32_WCE)
00660    {
00661       wchar_t time_buf[29];
00662       wsprintf(time_buf, TEXT("%d %S %d %02d:%02d:%02d +0000"),
00663           ptime->day % 32, short_months[(ptime->month - 1) % 12],
00664         ptime->year, ptime->hour % 24, ptime->minute % 60,
00665           ptime->second % 61);
00666       WideCharToMultiByte(CP_ACP, 0, time_buf, -1, png_ptr->time_buffer, 29,
00667           NULL, NULL);
00668    }
00669 #else
00670 #ifdef USE_FAR_KEYWORD
00671    {
00672       char near_time_buf[29];
00673       png_snprintf6(near_time_buf, 29, "%d %s %d %02d:%02d:%02d +0000",
00674           ptime->day % 32, short_months[(ptime->month - 1) % 12],
00675           ptime->year, ptime->hour % 24, ptime->minute % 60,
00676           ptime->second % 61);
00677       png_memcpy(png_ptr->time_buffer, near_time_buf,
00678           29*png_sizeof(char));
00679    }
00680 #else
00681    png_snprintf6(png_ptr->time_buffer, 29, "%d %s %d %02d:%02d:%02d +0000",
00682        ptime->day % 32, short_months[(ptime->month - 1) % 12],
00683        ptime->year, ptime->hour % 24, ptime->minute % 60,
00684        ptime->second % 61);
00685 #endif
00686 #endif /* _WIN32_WCE */
00687    return ((png_charp)png_ptr->time_buffer);
00688 }
00689 #endif /* PNG_TIME_RFC1123_SUPPORTED */
00690 
00691 #endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */
00692 
00693 png_charp PNGAPI
00694 png_get_copyright(png_structp png_ptr)
00695 {
00696    png_ptr = png_ptr;  /* silence compiler warning about unused png_ptr */
00697    return ((png_charp) "\n libpng version 1.2.32 - September 18, 2008\n\
00698    Copyright (c) 1998-2008 Glenn Randers-Pehrson\n\
00699    Copyright (c) 1996-1997 Andreas Dilger\n\
00700    Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.\n");
00701 }
00702 
00703 /* The following return the library version as a short string in the
00704  * format 1.0.0 through 99.99.99zz.  To get the version of *.h files
00705  * used with your application, print out PNG_LIBPNG_VER_STRING, which
00706  * is defined in png.h.
00707  * Note: now there is no difference between png_get_libpng_ver() and
00708  * png_get_header_ver().  Due to the version_nn_nn_nn typedef guard,
00709  * it is guaranteed that png.c uses the correct version of png.h.
00710  */
00711 png_charp PNGAPI
00712 png_get_libpng_ver(png_structp png_ptr)
00713 {
00714    /* Version of *.c files used when building libpng */
00715    png_ptr = png_ptr;  /* silence compiler warning about unused png_ptr */
00716    return ((png_charp) PNG_LIBPNG_VER_STRING);
00717 }
00718 
00719 png_charp PNGAPI
00720 png_get_header_ver(png_structp png_ptr)
00721 {
00722    /* Version of *.h files used when building libpng */
00723    png_ptr = png_ptr;  /* silence compiler warning about unused png_ptr */
00724    return ((png_charp) PNG_LIBPNG_VER_STRING);
00725 }
00726 
00727 png_charp PNGAPI
00728 png_get_header_version(png_structp png_ptr)
00729 {
00730    /* Returns longer string containing both version and date */
00731    png_ptr = png_ptr;  /* silence compiler warning about unused png_ptr */
00732    return ((png_charp) PNG_HEADER_VERSION_STRING
00733 #ifndef PNG_READ_SUPPORTED
00734    "     (NO READ SUPPORT)"
00735 #endif
00736    "\n");
00737 }
00738 
00739 #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
00740 #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
00741 int PNGAPI
00742 png_handle_as_unknown(png_structp png_ptr, png_bytep chunk_name)
00743 {
00744    /* check chunk_name and return "keep" value if it's on the list, else 0 */
00745    int i;
00746    png_bytep p;
00747    if (png_ptr == NULL || chunk_name == NULL || png_ptr->num_chunk_list<=0)
00748       return 0;
00749    p = png_ptr->chunk_list + png_ptr->num_chunk_list*5 - 5;
00750    for (i = png_ptr->num_chunk_list; i; i--, p -= 5)
00751       if (!png_memcmp(chunk_name, p, 4))
00752         return ((int)*(p + 4));
00753    return 0;
00754 }
00755 #endif
00756 
00757 /* This function, added to libpng-1.0.6g, is untested. */
00758 int PNGAPI
00759 png_reset_zstream(png_structp png_ptr)
00760 {
00761    if (png_ptr == NULL) return Z_STREAM_ERROR;
00762    return (inflateReset(&png_ptr->zstream));
00763 }
00764 #endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */
00765 
00766 /* This function was added to libpng-1.0.7 */
00767 png_uint_32 PNGAPI
00768 png_access_version_number(void)
00769 {
00770    /* Version of *.c files used when building libpng */
00771    return((png_uint_32) PNG_LIBPNG_VER);
00772 }
00773 
00774 
00775 #if defined(PNG_READ_SUPPORTED) && defined(PNG_ASSEMBLER_CODE_SUPPORTED)
00776 #if !defined(PNG_1_0_X)
00777 /* this function was added to libpng 1.2.0 */
00778 int PNGAPI
00779 png_mmx_support(void)
00780 {
00781    /* obsolete, to be removed from libpng-1.4.0 */
00782     return -1;
00783 }
00784 #endif /* PNG_1_0_X */
00785 #endif /* PNG_READ_SUPPORTED && PNG_ASSEMBLER_CODE_SUPPORTED */
00786 
00787 #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
00788 #ifdef PNG_SIZE_T
00789 /* Added at libpng version 1.2.6 */
00790    PNG_EXTERN png_size_t PNGAPI png_convert_size PNGARG((size_t size));
00791 png_size_t PNGAPI
00792 png_convert_size(size_t size)
00793 {
00794   if (size > (png_size_t)-1)
00795      PNG_ABORT();  /* We haven't got access to png_ptr, so no png_error() */
00796   return ((png_size_t)size);
00797 }
00798 #endif /* PNG_SIZE_T */
00799 #endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */


openhrp3
Author(s): AIST, General Robotix Inc., Nakamura Lab of Dept. of Mechano Informatics at University of Tokyo
autogenerated on Thu Apr 11 2019 03:30:18