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.21 October 4, 2007
00005  * For conditions of distribution and use, see copyright notice in png.h
00006  * Copyright (c) 1998-2007 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_23 Your_png_h_is_not_version_1_2_23;
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->valid &= ~PNG_INFO_tRNS;
00384 #ifndef PNG_FREE_ME_SUPPORTED
00385     png_ptr->flags &= ~PNG_FLAG_FREE_TRNS;
00386 #endif
00387     info_ptr->trans = NULL;
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 #ifdef PNG_FREE_ME_SUPPORTED
00494 if ((mask & PNG_FREE_UNKN) & info_ptr->free_me)
00495 #else
00496 if (mask & PNG_FREE_UNKN)
00497 #endif
00498 {
00499    if (num != -1)
00500    {
00501        if(info_ptr->unknown_chunks)
00502        {
00503           png_free(png_ptr, info_ptr->unknown_chunks[num].data);
00504           info_ptr->unknown_chunks[num].data = NULL;
00505        }
00506    }
00507    else
00508    {
00509        int i;
00510 
00511        if(info_ptr->unknown_chunks_num)
00512        {
00513          for (i = 0; i < (int)info_ptr->unknown_chunks_num; i++)
00514             png_free_data(png_ptr, info_ptr, PNG_FREE_UNKN, i);
00515 
00516          png_free(png_ptr, info_ptr->unknown_chunks);
00517          info_ptr->unknown_chunks = NULL;
00518          info_ptr->unknown_chunks_num = 0;
00519        }
00520    }
00521 }
00522 #endif
00523 
00524 #if defined(PNG_hIST_SUPPORTED)
00525 /* free any hIST entry */
00526 #ifdef PNG_FREE_ME_SUPPORTED
00527 if ((mask & PNG_FREE_HIST)  & info_ptr->free_me)
00528 #else
00529 if ((mask & PNG_FREE_HIST) && (png_ptr->flags & PNG_FLAG_FREE_HIST))
00530 #endif
00531 {
00532     png_free(png_ptr, info_ptr->hist);
00533     info_ptr->hist = NULL;
00534     info_ptr->valid &= ~PNG_INFO_hIST;
00535 #ifndef PNG_FREE_ME_SUPPORTED
00536     png_ptr->flags &= ~PNG_FLAG_FREE_HIST;
00537 #endif
00538 }
00539 #endif
00540 
00541 /* free any PLTE entry that was internally allocated */
00542 #ifdef PNG_FREE_ME_SUPPORTED
00543 if ((mask & PNG_FREE_PLTE) & info_ptr->free_me)
00544 #else
00545 if ((mask & PNG_FREE_PLTE) && (png_ptr->flags & PNG_FLAG_FREE_PLTE))
00546 #endif
00547 {
00548     png_zfree(png_ptr, info_ptr->palette);
00549     info_ptr->palette = NULL;
00550     info_ptr->valid &= ~PNG_INFO_PLTE;
00551 #ifndef PNG_FREE_ME_SUPPORTED
00552     png_ptr->flags &= ~PNG_FLAG_FREE_PLTE;
00553 #endif
00554     info_ptr->num_palette = 0;
00555 }
00556 
00557 #if defined(PNG_INFO_IMAGE_SUPPORTED)
00558 /* free any image bits attached to the info structure */
00559 #ifdef PNG_FREE_ME_SUPPORTED
00560 if ((mask & PNG_FREE_ROWS) & info_ptr->free_me)
00561 #else
00562 if (mask & PNG_FREE_ROWS)
00563 #endif
00564 {
00565     if(info_ptr->row_pointers)
00566     {
00567        int row;
00568        for (row = 0; row < (int)info_ptr->height; row++)
00569        {
00570           png_free(png_ptr, info_ptr->row_pointers[row]);
00571           info_ptr->row_pointers[row]=NULL;
00572        }
00573        png_free(png_ptr, info_ptr->row_pointers);
00574        info_ptr->row_pointers=NULL;
00575     }
00576     info_ptr->valid &= ~PNG_INFO_IDAT;
00577 }
00578 #endif
00579 
00580 #ifdef PNG_FREE_ME_SUPPORTED
00581    if(num == -1)
00582      info_ptr->free_me &= ~mask;
00583    else
00584      info_ptr->free_me &= ~(mask & ~PNG_FREE_MUL);
00585 #endif
00586 }
00587 
00588 /* This is an internal routine to free any memory that the info struct is
00589  * pointing to before re-using it or freeing the struct itself.  Recall
00590  * that png_free() checks for NULL pointers for us.
00591  */
00592 void /* PRIVATE */
00593 png_info_destroy(png_structp png_ptr, png_infop info_ptr)
00594 {
00595    png_debug(1, "in png_info_destroy\n");
00596 
00597    png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1);
00598 
00599 #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
00600    if (png_ptr->num_chunk_list)
00601    {
00602        png_free(png_ptr, png_ptr->chunk_list);
00603        png_ptr->chunk_list=NULL;
00604        png_ptr->num_chunk_list=0;
00605    }
00606 #endif
00607 
00608    png_info_init_3(&info_ptr, png_sizeof(png_info));
00609 }
00610 #endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */
00611 
00612 /* This function returns a pointer to the io_ptr associated with the user
00613  * functions.  The application should free any memory associated with this
00614  * pointer before png_write_destroy() or png_read_destroy() are called.
00615  */
00616 png_voidp PNGAPI
00617 png_get_io_ptr(png_structp png_ptr)
00618 {
00619    if(png_ptr == NULL) return (NULL);
00620    return (png_ptr->io_ptr);
00621 }
00622 
00623 #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
00624 #if !defined(PNG_NO_STDIO)
00625 /* Initialize the default input/output functions for the PNG file.  If you
00626  * use your own read or write routines, you can call either png_set_read_fn()
00627  * or png_set_write_fn() instead of png_init_io().  If you have defined
00628  * PNG_NO_STDIO, you must use a function of your own because "FILE *" isn't
00629  * necessarily available.
00630  */
00631 void PNGAPI
00632 png_init_io(png_structp png_ptr, png_FILE_p fp)
00633 {
00634    png_debug(1, "in png_init_io\n");
00635    if(png_ptr == NULL) return;
00636    png_ptr->io_ptr = (png_voidp)fp;
00637 }
00638 #endif
00639 
00640 #if defined(PNG_TIME_RFC1123_SUPPORTED)
00641 /* Convert the supplied time into an RFC 1123 string suitable for use in
00642  * a "Creation Time" or other text-based time string.
00643  */
00644 png_charp PNGAPI
00645 png_convert_to_rfc1123(png_structp png_ptr, png_timep ptime)
00646 {
00647    static PNG_CONST char short_months[12][4] =
00648         {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
00649          "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
00650 
00651    if(png_ptr == NULL) return (NULL);
00652    if (png_ptr->time_buffer == NULL)
00653    {
00654       png_ptr->time_buffer = (png_charp)png_malloc(png_ptr, (png_uint_32)(29*
00655          png_sizeof(char)));
00656    }
00657 
00658 #if defined(_WIN32_WCE)
00659    {
00660       wchar_t time_buf[29];
00661       wsprintf(time_buf, TEXT("%d %S %d %02d:%02d:%02d +0000"),
00662           ptime->day % 32, short_months[(ptime->month - 1) % 12],
00663         ptime->year, ptime->hour % 24, ptime->minute % 60,
00664           ptime->second % 61);
00665       WideCharToMultiByte(CP_ACP, 0, time_buf, -1, png_ptr->time_buffer, 29,
00666           NULL, NULL);
00667    }
00668 #else
00669 #ifdef USE_FAR_KEYWORD
00670    {
00671       char near_time_buf[29];
00672       png_snprintf6(near_time_buf,29,"%d %s %d %02d:%02d:%02d +0000",
00673           ptime->day % 32, short_months[(ptime->month - 1) % 12],
00674           ptime->year, ptime->hour % 24, ptime->minute % 60,
00675           ptime->second % 61);
00676       png_memcpy(png_ptr->time_buffer, near_time_buf,
00677           29*png_sizeof(char));
00678    }
00679 #else
00680    png_snprintf6(png_ptr->time_buffer,29,"%d %s %d %02d:%02d:%02d +0000",
00681        ptime->day % 32, short_months[(ptime->month - 1) % 12],
00682        ptime->year, ptime->hour % 24, ptime->minute % 60,
00683        ptime->second % 61);
00684 #endif
00685 #endif /* _WIN32_WCE */
00686    return ((png_charp)png_ptr->time_buffer);
00687 }
00688 #endif /* PNG_TIME_RFC1123_SUPPORTED */
00689 
00690 #endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */
00691 
00692 png_charp PNGAPI
00693 png_get_copyright(png_structp png_ptr)
00694 {
00695    png_ptr = png_ptr;  /* silence compiler warning about unused png_ptr */
00696    return ((png_charp) "\n libpng version 1.2.23 - November 6, 2007\n\
00697    Copyright (c) 1998-2007 Glenn Randers-Pehrson\n\
00698    Copyright (c) 1996-1997 Andreas Dilger\n\
00699    Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.\n");
00700 }
00701 
00702 /* The following return the library version as a short string in the
00703  * format 1.0.0 through 99.99.99zz.  To get the version of *.h files
00704  * used with your application, print out PNG_LIBPNG_VER_STRING, which
00705  * is defined in png.h.
00706  * Note: now there is no difference between png_get_libpng_ver() and
00707  * png_get_header_ver().  Due to the version_nn_nn_nn typedef guard,
00708  * it is guaranteed that png.c uses the correct version of png.h.
00709  */
00710 png_charp PNGAPI
00711 png_get_libpng_ver(png_structp png_ptr)
00712 {
00713    /* Version of *.c files used when building libpng */
00714    png_ptr = png_ptr;  /* silence compiler warning about unused png_ptr */
00715    return ((png_charp) PNG_LIBPNG_VER_STRING);
00716 }
00717 
00718 png_charp PNGAPI
00719 png_get_header_ver(png_structp png_ptr)
00720 {
00721    /* Version of *.h files used when building libpng */
00722    png_ptr = png_ptr;  /* silence compiler warning about unused png_ptr */
00723    return ((png_charp) PNG_LIBPNG_VER_STRING);
00724 }
00725 
00726 png_charp PNGAPI
00727 png_get_header_version(png_structp png_ptr)
00728 {
00729    /* Returns longer string containing both version and date */
00730    png_ptr = png_ptr;  /* silence compiler warning about unused png_ptr */
00731    return ((png_charp) PNG_HEADER_VERSION_STRING
00732 #ifndef PNG_READ_SUPPORTED
00733    "     (NO READ SUPPORT)"
00734 #endif
00735    "\n");
00736 }
00737 
00738 #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
00739 #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
00740 int PNGAPI
00741 png_handle_as_unknown(png_structp png_ptr, png_bytep chunk_name)
00742 {
00743    /* check chunk_name and return "keep" value if it's on the list, else 0 */
00744    int i;
00745    png_bytep p;
00746    if(png_ptr == NULL || chunk_name == NULL || png_ptr->num_chunk_list<=0)
00747       return 0;
00748    p=png_ptr->chunk_list+png_ptr->num_chunk_list*5-5;
00749    for (i = png_ptr->num_chunk_list; i; i--, p-=5)
00750       if (!png_memcmp(chunk_name, p, 4))
00751         return ((int)*(p+4));
00752    return 0;
00753 }
00754 #endif
00755 
00756 /* This function, added to libpng-1.0.6g, is untested. */
00757 int PNGAPI
00758 png_reset_zstream(png_structp png_ptr)
00759 {
00760    if (png_ptr == NULL) return Z_STREAM_ERROR;
00761    return (inflateReset(&png_ptr->zstream));
00762 }
00763 #endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */
00764 
00765 /* This function was added to libpng-1.0.7 */
00766 png_uint_32 PNGAPI
00767 png_access_version_number(void)
00768 {
00769    /* Version of *.c files used when building libpng */
00770    return((png_uint_32) PNG_LIBPNG_VER);
00771 }
00772 
00773 
00774 #if defined(PNG_READ_SUPPORTED) && defined(PNG_ASSEMBLER_CODE_SUPPORTED)
00775 #if !defined(PNG_1_0_X)
00776 /* this function was added to libpng 1.2.0 */
00777 int PNGAPI
00778 png_mmx_support(void)
00779 {
00780    /* obsolete, to be removed from libpng-1.4.0 */
00781     return -1;
00782 }
00783 #endif /* PNG_1_0_X */
00784 #endif /* PNG_READ_SUPPORTED && PNG_ASSEMBLER_CODE_SUPPORTED */
00785 
00786 #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
00787 #ifdef PNG_SIZE_T
00788 /* Added at libpng version 1.2.6 */
00789    PNG_EXTERN png_size_t PNGAPI png_convert_size PNGARG((size_t size));
00790 png_size_t PNGAPI
00791 png_convert_size(size_t size)
00792 {
00793   if (size > (png_size_t)-1)
00794      PNG_ABORT();  /* We haven't got access to png_ptr, so no png_error() */
00795   return ((png_size_t)size);
00796 }
00797 #endif /* PNG_SIZE_T */
00798 #endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */

Generated on Tue Jul 5 14:13:30 2011 for ROOT_528-00b_version by  doxygen 1.5.1