symbian-qemu-0.9.1-12/libpng-1.2.32/pngget.c
changeset 1 2fb8b9db1c86
equal deleted inserted replaced
0:ffa851df0825 1:2fb8b9db1c86
       
     1 
       
     2 /* pngget.c - retrieval of values from info struct
       
     3  *
       
     4  * Last changed in libpng 1.2.30 [August 15, 2008]
       
     5  * For conditions of distribution and use, see copyright notice in png.h
       
     6  * Copyright (c) 1998-2008 Glenn Randers-Pehrson
       
     7  * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
       
     8  * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
       
     9  */
       
    10 
       
    11 #define PNG_INTERNAL
       
    12 #include "png.h"
       
    13 #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
       
    14 
       
    15 png_uint_32 PNGAPI
       
    16 png_get_valid(png_structp png_ptr, png_infop info_ptr, png_uint_32 flag)
       
    17 {
       
    18    if (png_ptr != NULL && info_ptr != NULL)
       
    19       return(info_ptr->valid & flag);
       
    20    else
       
    21       return(0);
       
    22 }
       
    23 
       
    24 png_uint_32 PNGAPI
       
    25 png_get_rowbytes(png_structp png_ptr, png_infop info_ptr)
       
    26 {
       
    27    if (png_ptr != NULL && info_ptr != NULL)
       
    28       return(info_ptr->rowbytes);
       
    29    else
       
    30       return(0);
       
    31 }
       
    32 
       
    33 #if defined(PNG_INFO_IMAGE_SUPPORTED)
       
    34 png_bytepp PNGAPI
       
    35 png_get_rows(png_structp png_ptr, png_infop info_ptr)
       
    36 {
       
    37    if (png_ptr != NULL && info_ptr != NULL)
       
    38       return(info_ptr->row_pointers);
       
    39    else
       
    40       return(0);
       
    41 }
       
    42 #endif
       
    43 
       
    44 #ifdef PNG_EASY_ACCESS_SUPPORTED
       
    45 /* easy access to info, added in libpng-0.99 */
       
    46 png_uint_32 PNGAPI
       
    47 png_get_image_width(png_structp png_ptr, png_infop info_ptr)
       
    48 {
       
    49    if (png_ptr != NULL && info_ptr != NULL)
       
    50    {
       
    51       return info_ptr->width;
       
    52    }
       
    53    return (0);
       
    54 }
       
    55 
       
    56 png_uint_32 PNGAPI
       
    57 png_get_image_height(png_structp png_ptr, png_infop info_ptr)
       
    58 {
       
    59    if (png_ptr != NULL && info_ptr != NULL)
       
    60    {
       
    61       return info_ptr->height;
       
    62    }
       
    63    return (0);
       
    64 }
       
    65 
       
    66 png_byte PNGAPI
       
    67 png_get_bit_depth(png_structp png_ptr, png_infop info_ptr)
       
    68 {
       
    69    if (png_ptr != NULL && info_ptr != NULL)
       
    70    {
       
    71       return info_ptr->bit_depth;
       
    72    }
       
    73    return (0);
       
    74 }
       
    75 
       
    76 png_byte PNGAPI
       
    77 png_get_color_type(png_structp png_ptr, png_infop info_ptr)
       
    78 {
       
    79    if (png_ptr != NULL && info_ptr != NULL)
       
    80    {
       
    81       return info_ptr->color_type;
       
    82    }
       
    83    return (0);
       
    84 }
       
    85 
       
    86 png_byte PNGAPI
       
    87 png_get_filter_type(png_structp png_ptr, png_infop info_ptr)
       
    88 {
       
    89    if (png_ptr != NULL && info_ptr != NULL)
       
    90    {
       
    91       return info_ptr->filter_type;
       
    92    }
       
    93    return (0);
       
    94 }
       
    95 
       
    96 png_byte PNGAPI
       
    97 png_get_interlace_type(png_structp png_ptr, png_infop info_ptr)
       
    98 {
       
    99    if (png_ptr != NULL && info_ptr != NULL)
       
   100    {
       
   101       return info_ptr->interlace_type;
       
   102    }
       
   103    return (0);
       
   104 }
       
   105 
       
   106 png_byte PNGAPI
       
   107 png_get_compression_type(png_structp png_ptr, png_infop info_ptr)
       
   108 {
       
   109    if (png_ptr != NULL && info_ptr != NULL)
       
   110    {
       
   111       return info_ptr->compression_type;
       
   112    }
       
   113    return (0);
       
   114 }
       
   115 
       
   116 png_uint_32 PNGAPI
       
   117 png_get_x_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
       
   118 {
       
   119    if (png_ptr != NULL && info_ptr != NULL)
       
   120 #if defined(PNG_pHYs_SUPPORTED)
       
   121    if (info_ptr->valid & PNG_INFO_pHYs)
       
   122    {
       
   123       png_debug1(1, "in %s retrieval function\n", "png_get_x_pixels_per_meter");
       
   124       if (info_ptr->phys_unit_type != PNG_RESOLUTION_METER)
       
   125           return (0);
       
   126       else return (info_ptr->x_pixels_per_unit);
       
   127    }
       
   128 #else
       
   129    return (0);
       
   130 #endif
       
   131    return (0);
       
   132 }
       
   133 
       
   134 png_uint_32 PNGAPI
       
   135 png_get_y_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
       
   136 {
       
   137    if (png_ptr != NULL && info_ptr != NULL)
       
   138 #if defined(PNG_pHYs_SUPPORTED)
       
   139    if (info_ptr->valid & PNG_INFO_pHYs)
       
   140    {
       
   141       png_debug1(1, "in %s retrieval function\n", "png_get_y_pixels_per_meter");
       
   142       if (info_ptr->phys_unit_type != PNG_RESOLUTION_METER)
       
   143           return (0);
       
   144       else return (info_ptr->y_pixels_per_unit);
       
   145    }
       
   146 #else
       
   147    return (0);
       
   148 #endif
       
   149    return (0);
       
   150 }
       
   151 
       
   152 png_uint_32 PNGAPI
       
   153 png_get_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
       
   154 {
       
   155    if (png_ptr != NULL && info_ptr != NULL)
       
   156 #if defined(PNG_pHYs_SUPPORTED)
       
   157    if (info_ptr->valid & PNG_INFO_pHYs)
       
   158    {
       
   159       png_debug1(1, "in %s retrieval function\n", "png_get_pixels_per_meter");
       
   160       if (info_ptr->phys_unit_type != PNG_RESOLUTION_METER ||
       
   161          info_ptr->x_pixels_per_unit != info_ptr->y_pixels_per_unit)
       
   162           return (0);
       
   163       else return (info_ptr->x_pixels_per_unit);
       
   164    }
       
   165 #else
       
   166    return (0);
       
   167 #endif
       
   168    return (0);
       
   169 }
       
   170 
       
   171 #ifdef PNG_FLOATING_POINT_SUPPORTED
       
   172 float PNGAPI
       
   173 png_get_pixel_aspect_ratio(png_structp png_ptr, png_infop info_ptr)
       
   174    {
       
   175    if (png_ptr != NULL && info_ptr != NULL)
       
   176 #if defined(PNG_pHYs_SUPPORTED)
       
   177    if (info_ptr->valid & PNG_INFO_pHYs)
       
   178    {
       
   179       png_debug1(1, "in %s retrieval function\n", "png_get_aspect_ratio");
       
   180       if (info_ptr->x_pixels_per_unit == 0)
       
   181          return ((float)0.0);
       
   182       else
       
   183          return ((float)((float)info_ptr->y_pixels_per_unit
       
   184             /(float)info_ptr->x_pixels_per_unit));
       
   185    }
       
   186 #else
       
   187    return (0.0);
       
   188 #endif
       
   189    return ((float)0.0);
       
   190 }
       
   191 #endif
       
   192 
       
   193 png_int_32 PNGAPI
       
   194 png_get_x_offset_microns(png_structp png_ptr, png_infop info_ptr)
       
   195 {
       
   196    if (png_ptr != NULL && info_ptr != NULL)
       
   197 #if defined(PNG_oFFs_SUPPORTED)
       
   198    if (info_ptr->valid & PNG_INFO_oFFs)
       
   199    {
       
   200       png_debug1(1, "in %s retrieval function\n", "png_get_x_offset_microns");
       
   201       if (info_ptr->offset_unit_type != PNG_OFFSET_MICROMETER)
       
   202           return (0);
       
   203       else return (info_ptr->x_offset);
       
   204    }
       
   205 #else
       
   206    return (0);
       
   207 #endif
       
   208    return (0);
       
   209 }
       
   210 
       
   211 png_int_32 PNGAPI
       
   212 png_get_y_offset_microns(png_structp png_ptr, png_infop info_ptr)
       
   213 {
       
   214    if (png_ptr != NULL && info_ptr != NULL)
       
   215 #if defined(PNG_oFFs_SUPPORTED)
       
   216    if (info_ptr->valid & PNG_INFO_oFFs)
       
   217    {
       
   218       png_debug1(1, "in %s retrieval function\n", "png_get_y_offset_microns");
       
   219       if (info_ptr->offset_unit_type != PNG_OFFSET_MICROMETER)
       
   220           return (0);
       
   221       else return (info_ptr->y_offset);
       
   222    }
       
   223 #else
       
   224    return (0);
       
   225 #endif
       
   226    return (0);
       
   227 }
       
   228 
       
   229 png_int_32 PNGAPI
       
   230 png_get_x_offset_pixels(png_structp png_ptr, png_infop info_ptr)
       
   231 {
       
   232    if (png_ptr != NULL && info_ptr != NULL)
       
   233 #if defined(PNG_oFFs_SUPPORTED)
       
   234    if (info_ptr->valid & PNG_INFO_oFFs)
       
   235    {
       
   236       png_debug1(1, "in %s retrieval function\n", "png_get_x_offset_microns");
       
   237       if (info_ptr->offset_unit_type != PNG_OFFSET_PIXEL)
       
   238           return (0);
       
   239       else return (info_ptr->x_offset);
       
   240    }
       
   241 #else
       
   242    return (0);
       
   243 #endif
       
   244    return (0);
       
   245 }
       
   246 
       
   247 png_int_32 PNGAPI
       
   248 png_get_y_offset_pixels(png_structp png_ptr, png_infop info_ptr)
       
   249 {
       
   250    if (png_ptr != NULL && info_ptr != NULL)
       
   251 #if defined(PNG_oFFs_SUPPORTED)
       
   252    if (info_ptr->valid & PNG_INFO_oFFs)
       
   253    {
       
   254       png_debug1(1, "in %s retrieval function\n", "png_get_y_offset_microns");
       
   255       if (info_ptr->offset_unit_type != PNG_OFFSET_PIXEL)
       
   256           return (0);
       
   257       else return (info_ptr->y_offset);
       
   258    }
       
   259 #else
       
   260    return (0);
       
   261 #endif
       
   262    return (0);
       
   263 }
       
   264 
       
   265 #if defined(PNG_INCH_CONVERSIONS) && defined(PNG_FLOATING_POINT_SUPPORTED)
       
   266 png_uint_32 PNGAPI
       
   267 png_get_pixels_per_inch(png_structp png_ptr, png_infop info_ptr)
       
   268 {
       
   269    return ((png_uint_32)((float)png_get_pixels_per_meter(png_ptr, info_ptr)
       
   270      *.0254 +.5));
       
   271 }
       
   272 
       
   273 png_uint_32 PNGAPI
       
   274 png_get_x_pixels_per_inch(png_structp png_ptr, png_infop info_ptr)
       
   275 {
       
   276    return ((png_uint_32)((float)png_get_x_pixels_per_meter(png_ptr, info_ptr)
       
   277      *.0254 +.5));
       
   278 }
       
   279 
       
   280 png_uint_32 PNGAPI
       
   281 png_get_y_pixels_per_inch(png_structp png_ptr, png_infop info_ptr)
       
   282 {
       
   283    return ((png_uint_32)((float)png_get_y_pixels_per_meter(png_ptr, info_ptr)
       
   284      *.0254 +.5));
       
   285 }
       
   286 
       
   287 float PNGAPI
       
   288 png_get_x_offset_inches(png_structp png_ptr, png_infop info_ptr)
       
   289 {
       
   290    return ((float)png_get_x_offset_microns(png_ptr, info_ptr)
       
   291      *.00003937);
       
   292 }
       
   293 
       
   294 float PNGAPI
       
   295 png_get_y_offset_inches(png_structp png_ptr, png_infop info_ptr)
       
   296 {
       
   297    return ((float)png_get_y_offset_microns(png_ptr, info_ptr)
       
   298      *.00003937);
       
   299 }
       
   300 
       
   301 #if defined(PNG_pHYs_SUPPORTED)
       
   302 png_uint_32 PNGAPI
       
   303 png_get_pHYs_dpi(png_structp png_ptr, png_infop info_ptr,
       
   304    png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
       
   305 {
       
   306    png_uint_32 retval = 0;
       
   307 
       
   308    if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
       
   309    {
       
   310       png_debug1(1, "in %s retrieval function\n", "pHYs");
       
   311       if (res_x != NULL)
       
   312       {
       
   313          *res_x = info_ptr->x_pixels_per_unit;
       
   314          retval |= PNG_INFO_pHYs;
       
   315       }
       
   316       if (res_y != NULL)
       
   317       {
       
   318          *res_y = info_ptr->y_pixels_per_unit;
       
   319          retval |= PNG_INFO_pHYs;
       
   320       }
       
   321       if (unit_type != NULL)
       
   322       {
       
   323          *unit_type = (int)info_ptr->phys_unit_type;
       
   324          retval |= PNG_INFO_pHYs;
       
   325          if (*unit_type == 1)
       
   326          {
       
   327             if (res_x != NULL) *res_x = (png_uint_32)(*res_x * .0254 + .50);
       
   328             if (res_y != NULL) *res_y = (png_uint_32)(*res_y * .0254 + .50);
       
   329          }
       
   330       }
       
   331    }
       
   332    return (retval);
       
   333 }
       
   334 #endif /* PNG_pHYs_SUPPORTED */
       
   335 #endif  /* PNG_INCH_CONVERSIONS && PNG_FLOATING_POINT_SUPPORTED */
       
   336 
       
   337 /* png_get_channels really belongs in here, too, but it's been around longer */
       
   338 
       
   339 #endif  /* PNG_EASY_ACCESS_SUPPORTED */
       
   340 
       
   341 png_byte PNGAPI
       
   342 png_get_channels(png_structp png_ptr, png_infop info_ptr)
       
   343 {
       
   344    if (png_ptr != NULL && info_ptr != NULL)
       
   345       return(info_ptr->channels);
       
   346    else
       
   347       return (0);
       
   348 }
       
   349 
       
   350 png_bytep PNGAPI
       
   351 png_get_signature(png_structp png_ptr, png_infop info_ptr)
       
   352 {
       
   353    if (png_ptr != NULL && info_ptr != NULL)
       
   354       return(info_ptr->signature);
       
   355    else
       
   356       return (NULL);
       
   357 }
       
   358 
       
   359 #if defined(PNG_bKGD_SUPPORTED)
       
   360 png_uint_32 PNGAPI
       
   361 png_get_bKGD(png_structp png_ptr, png_infop info_ptr,
       
   362    png_color_16p *background)
       
   363 {
       
   364    if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_bKGD)
       
   365       && background != NULL)
       
   366    {
       
   367       png_debug1(1, "in %s retrieval function\n", "bKGD");
       
   368       *background = &(info_ptr->background);
       
   369       return (PNG_INFO_bKGD);
       
   370    }
       
   371    return (0);
       
   372 }
       
   373 #endif
       
   374 
       
   375 #if defined(PNG_cHRM_SUPPORTED)
       
   376 #ifdef PNG_FLOATING_POINT_SUPPORTED
       
   377 png_uint_32 PNGAPI
       
   378 png_get_cHRM(png_structp png_ptr, png_infop info_ptr,
       
   379    double *white_x, double *white_y, double *red_x, double *red_y,
       
   380    double *green_x, double *green_y, double *blue_x, double *blue_y)
       
   381 {
       
   382    if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM))
       
   383    {
       
   384       png_debug1(1, "in %s retrieval function\n", "cHRM");
       
   385       if (white_x != NULL)
       
   386          *white_x = (double)info_ptr->x_white;
       
   387       if (white_y != NULL)
       
   388          *white_y = (double)info_ptr->y_white;
       
   389       if (red_x != NULL)
       
   390          *red_x = (double)info_ptr->x_red;
       
   391       if (red_y != NULL)
       
   392          *red_y = (double)info_ptr->y_red;
       
   393       if (green_x != NULL)
       
   394          *green_x = (double)info_ptr->x_green;
       
   395       if (green_y != NULL)
       
   396          *green_y = (double)info_ptr->y_green;
       
   397       if (blue_x != NULL)
       
   398          *blue_x = (double)info_ptr->x_blue;
       
   399       if (blue_y != NULL)
       
   400          *blue_y = (double)info_ptr->y_blue;
       
   401       return (PNG_INFO_cHRM);
       
   402    }
       
   403    return (0);
       
   404 }
       
   405 #endif
       
   406 #ifdef PNG_FIXED_POINT_SUPPORTED
       
   407 png_uint_32 PNGAPI
       
   408 png_get_cHRM_fixed(png_structp png_ptr, png_infop info_ptr,
       
   409    png_fixed_point *white_x, png_fixed_point *white_y, png_fixed_point *red_x,
       
   410    png_fixed_point *red_y, png_fixed_point *green_x, png_fixed_point *green_y,
       
   411    png_fixed_point *blue_x, png_fixed_point *blue_y)
       
   412 {
       
   413    if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM))
       
   414    {
       
   415       png_debug1(1, "in %s retrieval function\n", "cHRM");
       
   416       if (white_x != NULL)
       
   417          *white_x = info_ptr->int_x_white;
       
   418       if (white_y != NULL)
       
   419          *white_y = info_ptr->int_y_white;
       
   420       if (red_x != NULL)
       
   421          *red_x = info_ptr->int_x_red;
       
   422       if (red_y != NULL)
       
   423          *red_y = info_ptr->int_y_red;
       
   424       if (green_x != NULL)
       
   425          *green_x = info_ptr->int_x_green;
       
   426       if (green_y != NULL)
       
   427          *green_y = info_ptr->int_y_green;
       
   428       if (blue_x != NULL)
       
   429          *blue_x = info_ptr->int_x_blue;
       
   430       if (blue_y != NULL)
       
   431          *blue_y = info_ptr->int_y_blue;
       
   432       return (PNG_INFO_cHRM);
       
   433    }
       
   434    return (0);
       
   435 }
       
   436 #endif
       
   437 #endif
       
   438 
       
   439 #if defined(PNG_gAMA_SUPPORTED)
       
   440 #ifdef PNG_FLOATING_POINT_SUPPORTED
       
   441 png_uint_32 PNGAPI
       
   442 png_get_gAMA(png_structp png_ptr, png_infop info_ptr, double *file_gamma)
       
   443 {
       
   444    if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA)
       
   445       && file_gamma != NULL)
       
   446    {
       
   447       png_debug1(1, "in %s retrieval function\n", "gAMA");
       
   448       *file_gamma = (double)info_ptr->gamma;
       
   449       return (PNG_INFO_gAMA);
       
   450    }
       
   451    return (0);
       
   452 }
       
   453 #endif
       
   454 #ifdef PNG_FIXED_POINT_SUPPORTED
       
   455 png_uint_32 PNGAPI
       
   456 png_get_gAMA_fixed(png_structp png_ptr, png_infop info_ptr,
       
   457     png_fixed_point *int_file_gamma)
       
   458 {
       
   459    if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA)
       
   460       && int_file_gamma != NULL)
       
   461    {
       
   462       png_debug1(1, "in %s retrieval function\n", "gAMA");
       
   463       *int_file_gamma = info_ptr->int_gamma;
       
   464       return (PNG_INFO_gAMA);
       
   465    }
       
   466    return (0);
       
   467 }
       
   468 #endif
       
   469 #endif
       
   470 
       
   471 #if defined(PNG_sRGB_SUPPORTED)
       
   472 png_uint_32 PNGAPI
       
   473 png_get_sRGB(png_structp png_ptr, png_infop info_ptr, int *file_srgb_intent)
       
   474 {
       
   475    if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB)
       
   476       && file_srgb_intent != NULL)
       
   477    {
       
   478       png_debug1(1, "in %s retrieval function\n", "sRGB");
       
   479       *file_srgb_intent = (int)info_ptr->srgb_intent;
       
   480       return (PNG_INFO_sRGB);
       
   481    }
       
   482    return (0);
       
   483 }
       
   484 #endif
       
   485 
       
   486 #if defined(PNG_iCCP_SUPPORTED)
       
   487 png_uint_32 PNGAPI
       
   488 png_get_iCCP(png_structp png_ptr, png_infop info_ptr,
       
   489              png_charpp name, int *compression_type,
       
   490              png_charpp profile, png_uint_32 *proflen)
       
   491 {
       
   492    if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_iCCP)
       
   493       && name != NULL && profile != NULL && proflen != NULL)
       
   494    {
       
   495       png_debug1(1, "in %s retrieval function\n", "iCCP");
       
   496       *name = info_ptr->iccp_name;
       
   497       *profile = info_ptr->iccp_profile;
       
   498       /* compression_type is a dummy so the API won't have to change
       
   499          if we introduce multiple compression types later. */
       
   500       *proflen = (int)info_ptr->iccp_proflen;
       
   501       *compression_type = (int)info_ptr->iccp_compression;
       
   502       return (PNG_INFO_iCCP);
       
   503    }
       
   504    return (0);
       
   505 }
       
   506 #endif
       
   507 
       
   508 #if defined(PNG_sPLT_SUPPORTED)
       
   509 png_uint_32 PNGAPI
       
   510 png_get_sPLT(png_structp png_ptr, png_infop info_ptr,
       
   511              png_sPLT_tpp spalettes)
       
   512 {
       
   513    if (png_ptr != NULL && info_ptr != NULL && spalettes != NULL)
       
   514    {
       
   515      *spalettes = info_ptr->splt_palettes;
       
   516      return ((png_uint_32)info_ptr->splt_palettes_num);
       
   517    }
       
   518    return (0);
       
   519 }
       
   520 #endif
       
   521 
       
   522 #if defined(PNG_hIST_SUPPORTED)
       
   523 png_uint_32 PNGAPI
       
   524 png_get_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p *hist)
       
   525 {
       
   526    if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_hIST)
       
   527       && hist != NULL)
       
   528    {
       
   529       png_debug1(1, "in %s retrieval function\n", "hIST");
       
   530       *hist = info_ptr->hist;
       
   531       return (PNG_INFO_hIST);
       
   532    }
       
   533    return (0);
       
   534 }
       
   535 #endif
       
   536 
       
   537 png_uint_32 PNGAPI
       
   538 png_get_IHDR(png_structp png_ptr, png_infop info_ptr,
       
   539    png_uint_32 *width, png_uint_32 *height, int *bit_depth,
       
   540    int *color_type, int *interlace_type, int *compression_type,
       
   541    int *filter_type)
       
   542 
       
   543 {
       
   544    if (png_ptr != NULL && info_ptr != NULL && width != NULL && height != NULL &&
       
   545       bit_depth != NULL && color_type != NULL)
       
   546    {
       
   547       png_debug1(1, "in %s retrieval function\n", "IHDR");
       
   548       *width = info_ptr->width;
       
   549       *height = info_ptr->height;
       
   550       *bit_depth = info_ptr->bit_depth;
       
   551       if (info_ptr->bit_depth < 1 || info_ptr->bit_depth > 16)
       
   552         png_error(png_ptr, "Invalid bit depth");
       
   553       *color_type = info_ptr->color_type;
       
   554       if (info_ptr->color_type > 6)
       
   555         png_error(png_ptr, "Invalid color type");
       
   556       if (compression_type != NULL)
       
   557          *compression_type = info_ptr->compression_type;
       
   558       if (filter_type != NULL)
       
   559          *filter_type = info_ptr->filter_type;
       
   560       if (interlace_type != NULL)
       
   561          *interlace_type = info_ptr->interlace_type;
       
   562 
       
   563       /* check for potential overflow of rowbytes */
       
   564       if (*width == 0 || *width > PNG_UINT_31_MAX)
       
   565         png_error(png_ptr, "Invalid image width");
       
   566       if (*height == 0 || *height > PNG_UINT_31_MAX)
       
   567         png_error(png_ptr, "Invalid image height");
       
   568       if (info_ptr->width > (PNG_UINT_32_MAX
       
   569                  >> 3)      /* 8-byte RGBA pixels */
       
   570                  - 64       /* bigrowbuf hack */
       
   571                  - 1        /* filter byte */
       
   572                  - 7*8      /* rounding of width to multiple of 8 pixels */
       
   573                  - 8)       /* extra max_pixel_depth pad */
       
   574       {
       
   575          png_warning(png_ptr,
       
   576             "Width too large for libpng to process image data.");
       
   577       }
       
   578       return (1);
       
   579    }
       
   580    return (0);
       
   581 }
       
   582 
       
   583 #if defined(PNG_oFFs_SUPPORTED)
       
   584 png_uint_32 PNGAPI
       
   585 png_get_oFFs(png_structp png_ptr, png_infop info_ptr,
       
   586    png_int_32 *offset_x, png_int_32 *offset_y, int *unit_type)
       
   587 {
       
   588    if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs)
       
   589       && offset_x != NULL && offset_y != NULL && unit_type != NULL)
       
   590    {
       
   591       png_debug1(1, "in %s retrieval function\n", "oFFs");
       
   592       *offset_x = info_ptr->x_offset;
       
   593       *offset_y = info_ptr->y_offset;
       
   594       *unit_type = (int)info_ptr->offset_unit_type;
       
   595       return (PNG_INFO_oFFs);
       
   596    }
       
   597    return (0);
       
   598 }
       
   599 #endif
       
   600 
       
   601 #if defined(PNG_pCAL_SUPPORTED)
       
   602 png_uint_32 PNGAPI
       
   603 png_get_pCAL(png_structp png_ptr, png_infop info_ptr,
       
   604    png_charp *purpose, png_int_32 *X0, png_int_32 *X1, int *type, int *nparams,
       
   605    png_charp *units, png_charpp *params)
       
   606 {
       
   607    if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pCAL)
       
   608       && purpose != NULL && X0 != NULL && X1 != NULL && type != NULL &&
       
   609       nparams != NULL && units != NULL && params != NULL)
       
   610    {
       
   611       png_debug1(1, "in %s retrieval function\n", "pCAL");
       
   612       *purpose = info_ptr->pcal_purpose;
       
   613       *X0 = info_ptr->pcal_X0;
       
   614       *X1 = info_ptr->pcal_X1;
       
   615       *type = (int)info_ptr->pcal_type;
       
   616       *nparams = (int)info_ptr->pcal_nparams;
       
   617       *units = info_ptr->pcal_units;
       
   618       *params = info_ptr->pcal_params;
       
   619       return (PNG_INFO_pCAL);
       
   620    }
       
   621    return (0);
       
   622 }
       
   623 #endif
       
   624 
       
   625 #if defined(PNG_sCAL_SUPPORTED)
       
   626 #ifdef PNG_FLOATING_POINT_SUPPORTED
       
   627 png_uint_32 PNGAPI
       
   628 png_get_sCAL(png_structp png_ptr, png_infop info_ptr,
       
   629              int *unit, double *width, double *height)
       
   630 {
       
   631     if (png_ptr != NULL && info_ptr != NULL &&
       
   632        (info_ptr->valid & PNG_INFO_sCAL))
       
   633     {
       
   634         *unit = info_ptr->scal_unit;
       
   635         *width = info_ptr->scal_pixel_width;
       
   636         *height = info_ptr->scal_pixel_height;
       
   637         return (PNG_INFO_sCAL);
       
   638     }
       
   639     return(0);
       
   640 }
       
   641 #else
       
   642 #ifdef PNG_FIXED_POINT_SUPPORTED
       
   643 png_uint_32 PNGAPI
       
   644 png_get_sCAL_s(png_structp png_ptr, png_infop info_ptr,
       
   645              int *unit, png_charpp width, png_charpp height)
       
   646 {
       
   647     if (png_ptr != NULL && info_ptr != NULL &&
       
   648        (info_ptr->valid & PNG_INFO_sCAL))
       
   649     {
       
   650         *unit = info_ptr->scal_unit;
       
   651         *width = info_ptr->scal_s_width;
       
   652         *height = info_ptr->scal_s_height;
       
   653         return (PNG_INFO_sCAL);
       
   654     }
       
   655     return(0);
       
   656 }
       
   657 #endif
       
   658 #endif
       
   659 #endif
       
   660 
       
   661 #if defined(PNG_pHYs_SUPPORTED)
       
   662 png_uint_32 PNGAPI
       
   663 png_get_pHYs(png_structp png_ptr, png_infop info_ptr,
       
   664    png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
       
   665 {
       
   666    png_uint_32 retval = 0;
       
   667 
       
   668    if (png_ptr != NULL && info_ptr != NULL &&
       
   669       (info_ptr->valid & PNG_INFO_pHYs))
       
   670    {
       
   671       png_debug1(1, "in %s retrieval function\n", "pHYs");
       
   672       if (res_x != NULL)
       
   673       {
       
   674          *res_x = info_ptr->x_pixels_per_unit;
       
   675          retval |= PNG_INFO_pHYs;
       
   676       }
       
   677       if (res_y != NULL)
       
   678       {
       
   679          *res_y = info_ptr->y_pixels_per_unit;
       
   680          retval |= PNG_INFO_pHYs;
       
   681       }
       
   682       if (unit_type != NULL)
       
   683       {
       
   684          *unit_type = (int)info_ptr->phys_unit_type;
       
   685          retval |= PNG_INFO_pHYs;
       
   686       }
       
   687    }
       
   688    return (retval);
       
   689 }
       
   690 #endif
       
   691 
       
   692 png_uint_32 PNGAPI
       
   693 png_get_PLTE(png_structp png_ptr, png_infop info_ptr, png_colorp *palette,
       
   694    int *num_palette)
       
   695 {
       
   696    if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_PLTE)
       
   697        && palette != NULL)
       
   698    {
       
   699       png_debug1(1, "in %s retrieval function\n", "PLTE");
       
   700       *palette = info_ptr->palette;
       
   701       *num_palette = info_ptr->num_palette;
       
   702       png_debug1(3, "num_palette = %d\n", *num_palette);
       
   703       return (PNG_INFO_PLTE);
       
   704    }
       
   705    return (0);
       
   706 }
       
   707 
       
   708 #if defined(PNG_sBIT_SUPPORTED)
       
   709 png_uint_32 PNGAPI
       
   710 png_get_sBIT(png_structp png_ptr, png_infop info_ptr, png_color_8p *sig_bit)
       
   711 {
       
   712    if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sBIT)
       
   713       && sig_bit != NULL)
       
   714    {
       
   715       png_debug1(1, "in %s retrieval function\n", "sBIT");
       
   716       *sig_bit = &(info_ptr->sig_bit);
       
   717       return (PNG_INFO_sBIT);
       
   718    }
       
   719    return (0);
       
   720 }
       
   721 #endif
       
   722 
       
   723 #if defined(PNG_TEXT_SUPPORTED)
       
   724 png_uint_32 PNGAPI
       
   725 png_get_text(png_structp png_ptr, png_infop info_ptr, png_textp *text_ptr,
       
   726    int *num_text)
       
   727 {
       
   728    if (png_ptr != NULL && info_ptr != NULL && info_ptr->num_text > 0)
       
   729    {
       
   730       png_debug1(1, "in %s retrieval function\n",
       
   731          (png_ptr->chunk_name[0] == '\0' ? "text"
       
   732              : (png_const_charp)png_ptr->chunk_name));
       
   733       if (text_ptr != NULL)
       
   734          *text_ptr = info_ptr->text;
       
   735       if (num_text != NULL)
       
   736          *num_text = info_ptr->num_text;
       
   737       return ((png_uint_32)info_ptr->num_text);
       
   738    }
       
   739    if (num_text != NULL)
       
   740      *num_text = 0;
       
   741    return(0);
       
   742 }
       
   743 #endif
       
   744 
       
   745 #if defined(PNG_tIME_SUPPORTED)
       
   746 png_uint_32 PNGAPI
       
   747 png_get_tIME(png_structp png_ptr, png_infop info_ptr, png_timep *mod_time)
       
   748 {
       
   749    if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tIME)
       
   750        && mod_time != NULL)
       
   751    {
       
   752       png_debug1(1, "in %s retrieval function\n", "tIME");
       
   753       *mod_time = &(info_ptr->mod_time);
       
   754       return (PNG_INFO_tIME);
       
   755    }
       
   756    return (0);
       
   757 }
       
   758 #endif
       
   759 
       
   760 #if defined(PNG_tRNS_SUPPORTED)
       
   761 png_uint_32 PNGAPI
       
   762 png_get_tRNS(png_structp png_ptr, png_infop info_ptr,
       
   763    png_bytep *trans, int *num_trans, png_color_16p *trans_values)
       
   764 {
       
   765    png_uint_32 retval = 0;
       
   766    if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS))
       
   767    {
       
   768       png_debug1(1, "in %s retrieval function\n", "tRNS");
       
   769       if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
       
   770       {
       
   771           if (trans != NULL)
       
   772           {
       
   773              *trans = info_ptr->trans;
       
   774              retval |= PNG_INFO_tRNS;
       
   775           }
       
   776           if (trans_values != NULL)
       
   777              *trans_values = &(info_ptr->trans_values);
       
   778       }
       
   779       else /* if (info_ptr->color_type != PNG_COLOR_TYPE_PALETTE) */
       
   780       {
       
   781           if (trans_values != NULL)
       
   782           {
       
   783              *trans_values = &(info_ptr->trans_values);
       
   784              retval |= PNG_INFO_tRNS;
       
   785           }
       
   786           if (trans != NULL)
       
   787              *trans = NULL;
       
   788       }
       
   789       if (num_trans != NULL)
       
   790       {
       
   791          *num_trans = info_ptr->num_trans;
       
   792          retval |= PNG_INFO_tRNS;
       
   793       }
       
   794    }
       
   795    return (retval);
       
   796 }
       
   797 #endif
       
   798 
       
   799 #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
       
   800 png_uint_32 PNGAPI
       
   801 png_get_unknown_chunks(png_structp png_ptr, png_infop info_ptr,
       
   802              png_unknown_chunkpp unknowns)
       
   803 {
       
   804    if (png_ptr != NULL && info_ptr != NULL && unknowns != NULL)
       
   805    {
       
   806      *unknowns = info_ptr->unknown_chunks;
       
   807      return ((png_uint_32)info_ptr->unknown_chunks_num);
       
   808    }
       
   809    return (0);
       
   810 }
       
   811 #endif
       
   812 
       
   813 #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
       
   814 png_byte PNGAPI
       
   815 png_get_rgb_to_gray_status (png_structp png_ptr)
       
   816 {
       
   817    return (png_byte)(png_ptr? png_ptr->rgb_to_gray_status : 0);
       
   818 }
       
   819 #endif
       
   820 
       
   821 #if defined(PNG_USER_CHUNKS_SUPPORTED)
       
   822 png_voidp PNGAPI
       
   823 png_get_user_chunk_ptr(png_structp png_ptr)
       
   824 {
       
   825    return (png_ptr? png_ptr->user_chunk_ptr : NULL);
       
   826 }
       
   827 #endif
       
   828 
       
   829 #ifdef PNG_WRITE_SUPPORTED
       
   830 png_uint_32 PNGAPI
       
   831 png_get_compression_buffer_size(png_structp png_ptr)
       
   832 {
       
   833    return (png_uint_32)(png_ptr? png_ptr->zbuf_size : 0L);
       
   834 }
       
   835 #endif
       
   836 
       
   837 #ifdef PNG_ASSEMBLER_CODE_SUPPORTED
       
   838 #ifndef PNG_1_0_X
       
   839 /* this function was added to libpng 1.2.0 and should exist by default */
       
   840 png_uint_32 PNGAPI
       
   841 png_get_asm_flags (png_structp png_ptr)
       
   842 {
       
   843     /* obsolete, to be removed from libpng-1.4.0 */
       
   844     return (png_ptr? 0L: 0L);
       
   845 }
       
   846 
       
   847 /* this function was added to libpng 1.2.0 and should exist by default */
       
   848 png_uint_32 PNGAPI
       
   849 png_get_asm_flagmask (int flag_select)
       
   850 {
       
   851     /* obsolete, to be removed from libpng-1.4.0 */
       
   852     flag_select=flag_select;
       
   853     return 0L;
       
   854 }
       
   855 
       
   856     /* GRR:  could add this:   && defined(PNG_MMX_CODE_SUPPORTED) */
       
   857 /* this function was added to libpng 1.2.0 */
       
   858 png_uint_32 PNGAPI
       
   859 png_get_mmx_flagmask (int flag_select, int *compilerID)
       
   860 {
       
   861     /* obsolete, to be removed from libpng-1.4.0 */
       
   862     flag_select=flag_select;
       
   863     *compilerID = -1;   /* unknown (i.e., no asm/MMX code compiled) */
       
   864     return 0L;
       
   865 }
       
   866 
       
   867 /* this function was added to libpng 1.2.0 */
       
   868 png_byte PNGAPI
       
   869 png_get_mmx_bitdepth_threshold (png_structp png_ptr)
       
   870 {
       
   871     /* obsolete, to be removed from libpng-1.4.0 */
       
   872     return (png_ptr? 0: 0);
       
   873 }
       
   874 
       
   875 /* this function was added to libpng 1.2.0 */
       
   876 png_uint_32 PNGAPI
       
   877 png_get_mmx_rowbytes_threshold (png_structp png_ptr)
       
   878 {
       
   879     /* obsolete, to be removed from libpng-1.4.0 */
       
   880     return (png_ptr? 0L: 0L);
       
   881 }
       
   882 #endif /* ?PNG_1_0_X */
       
   883 #endif /* ?PNG_ASSEMBLER_CODE_SUPPORTED */
       
   884 
       
   885 #ifdef PNG_SET_USER_LIMITS_SUPPORTED
       
   886 /* these functions were added to libpng 1.2.6 */
       
   887 png_uint_32 PNGAPI
       
   888 png_get_user_width_max (png_structp png_ptr)
       
   889 {
       
   890     return (png_ptr? png_ptr->user_width_max : 0);
       
   891 }
       
   892 png_uint_32 PNGAPI
       
   893 png_get_user_height_max (png_structp png_ptr)
       
   894 {
       
   895     return (png_ptr? png_ptr->user_height_max : 0);
       
   896 }
       
   897 #endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */
       
   898  
       
   899 
       
   900 #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */