Path: blob/master/src/java.desktop/share/native/libsplashscreen/libpng/pngget.c
41155 views
/*1* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.2*3* This code is free software; you can redistribute it and/or modify it4* under the terms of the GNU General Public License version 2 only, as5* published by the Free Software Foundation. Oracle designates this6* particular file as subject to the "Classpath" exception as provided7* by Oracle in the LICENSE file that accompanied this code.8*9* This code is distributed in the hope that it will be useful, but WITHOUT10* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or11* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License12* version 2 for more details (a copy is included in the LICENSE file that13* accompanied this code).14*15* You should have received a copy of the GNU General Public License version16* 2 along with this work; if not, write to the Free Software Foundation,17* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.18*19* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA20* or visit www.oracle.com if you need additional information or have any21* questions.22*/2324/* pngget.c - retrieval of values from info struct25*26* This file is available under and governed by the GNU General Public27* License version 2 only, as published by the Free Software Foundation.28* However, the following notice accompanied the original version of this29* file and, per its terms, should not be removed:30*31* Copyright (c) 2018 Cosmin Truta32* Copyright (c) 1998-2002,2004,2006-2018 Glenn Randers-Pehrson33* Copyright (c) 1996-1997 Andreas Dilger34* Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.35*36* This code is released under the libpng license.37* For conditions of distribution and use, see the disclaimer38* and license in png.h39*40*/4142#include "pngpriv.h"4344#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)4546png_uint_32 PNGAPI47png_get_valid(png_const_structrp png_ptr, png_const_inforp info_ptr,48png_uint_32 flag)49{50if (png_ptr != NULL && info_ptr != NULL)51return(info_ptr->valid & flag);5253return(0);54}5556size_t PNGAPI57png_get_rowbytes(png_const_structrp png_ptr, png_const_inforp info_ptr)58{59if (png_ptr != NULL && info_ptr != NULL)60return(info_ptr->rowbytes);6162return(0);63}6465#ifdef PNG_INFO_IMAGE_SUPPORTED66png_bytepp PNGAPI67png_get_rows(png_const_structrp png_ptr, png_const_inforp info_ptr)68{69if (png_ptr != NULL && info_ptr != NULL)70return(info_ptr->row_pointers);7172return(0);73}74#endif7576#ifdef PNG_EASY_ACCESS_SUPPORTED77/* Easy access to info, added in libpng-0.99 */78png_uint_32 PNGAPI79png_get_image_width(png_const_structrp png_ptr, png_const_inforp info_ptr)80{81if (png_ptr != NULL && info_ptr != NULL)82return info_ptr->width;8384return (0);85}8687png_uint_32 PNGAPI88png_get_image_height(png_const_structrp png_ptr, png_const_inforp info_ptr)89{90if (png_ptr != NULL && info_ptr != NULL)91return info_ptr->height;9293return (0);94}9596png_byte PNGAPI97png_get_bit_depth(png_const_structrp png_ptr, png_const_inforp info_ptr)98{99if (png_ptr != NULL && info_ptr != NULL)100return info_ptr->bit_depth;101102return (0);103}104105png_byte PNGAPI106png_get_color_type(png_const_structrp png_ptr, png_const_inforp info_ptr)107{108if (png_ptr != NULL && info_ptr != NULL)109return info_ptr->color_type;110111return (0);112}113114png_byte PNGAPI115png_get_filter_type(png_const_structrp png_ptr, png_const_inforp info_ptr)116{117if (png_ptr != NULL && info_ptr != NULL)118return info_ptr->filter_type;119120return (0);121}122123png_byte PNGAPI124png_get_interlace_type(png_const_structrp png_ptr, png_const_inforp info_ptr)125{126if (png_ptr != NULL && info_ptr != NULL)127return info_ptr->interlace_type;128129return (0);130}131132png_byte PNGAPI133png_get_compression_type(png_const_structrp png_ptr, png_const_inforp info_ptr)134{135if (png_ptr != NULL && info_ptr != NULL)136return info_ptr->compression_type;137138return (0);139}140141png_uint_32 PNGAPI142png_get_x_pixels_per_meter(png_const_structrp png_ptr, png_const_inforp143info_ptr)144{145#ifdef PNG_pHYs_SUPPORTED146if (png_ptr != NULL && info_ptr != NULL &&147(info_ptr->valid & PNG_INFO_pHYs) != 0)148{149png_debug1(1, "in %s retrieval function",150"png_get_x_pixels_per_meter");151152if (info_ptr->phys_unit_type == PNG_RESOLUTION_METER)153return (info_ptr->x_pixels_per_unit);154}155#else156PNG_UNUSED(png_ptr)157PNG_UNUSED(info_ptr)158#endif159160return (0);161}162163png_uint_32 PNGAPI164png_get_y_pixels_per_meter(png_const_structrp png_ptr, png_const_inforp165info_ptr)166{167#ifdef PNG_pHYs_SUPPORTED168if (png_ptr != NULL && info_ptr != NULL &&169(info_ptr->valid & PNG_INFO_pHYs) != 0)170{171png_debug1(1, "in %s retrieval function",172"png_get_y_pixels_per_meter");173174if (info_ptr->phys_unit_type == PNG_RESOLUTION_METER)175return (info_ptr->y_pixels_per_unit);176}177#else178PNG_UNUSED(png_ptr)179PNG_UNUSED(info_ptr)180#endif181182return (0);183}184185png_uint_32 PNGAPI186png_get_pixels_per_meter(png_const_structrp png_ptr, png_const_inforp info_ptr)187{188#ifdef PNG_pHYs_SUPPORTED189if (png_ptr != NULL && info_ptr != NULL &&190(info_ptr->valid & PNG_INFO_pHYs) != 0)191{192png_debug1(1, "in %s retrieval function", "png_get_pixels_per_meter");193194if (info_ptr->phys_unit_type == PNG_RESOLUTION_METER &&195info_ptr->x_pixels_per_unit == info_ptr->y_pixels_per_unit)196return (info_ptr->x_pixels_per_unit);197}198#else199PNG_UNUSED(png_ptr)200PNG_UNUSED(info_ptr)201#endif202203return (0);204}205206#ifdef PNG_FLOATING_POINT_SUPPORTED207float PNGAPI208png_get_pixel_aspect_ratio(png_const_structrp png_ptr, png_const_inforp209info_ptr)210{211#ifdef PNG_READ_pHYs_SUPPORTED212if (png_ptr != NULL && info_ptr != NULL &&213(info_ptr->valid & PNG_INFO_pHYs) != 0)214{215png_debug1(1, "in %s retrieval function", "png_get_aspect_ratio");216217if (info_ptr->x_pixels_per_unit != 0)218return ((float)((float)info_ptr->y_pixels_per_unit219/(float)info_ptr->x_pixels_per_unit));220}221#else222PNG_UNUSED(png_ptr)223PNG_UNUSED(info_ptr)224#endif225226return ((float)0.0);227}228#endif229230#ifdef PNG_FIXED_POINT_SUPPORTED231png_fixed_point PNGAPI232png_get_pixel_aspect_ratio_fixed(png_const_structrp png_ptr,233png_const_inforp info_ptr)234{235#ifdef PNG_READ_pHYs_SUPPORTED236if (png_ptr != NULL && info_ptr != NULL &&237(info_ptr->valid & PNG_INFO_pHYs) != 0 &&238info_ptr->x_pixels_per_unit > 0 && info_ptr->y_pixels_per_unit > 0 &&239info_ptr->x_pixels_per_unit <= PNG_UINT_31_MAX &&240info_ptr->y_pixels_per_unit <= PNG_UINT_31_MAX)241{242png_fixed_point res;243244png_debug1(1, "in %s retrieval function", "png_get_aspect_ratio_fixed");245246/* The following casts work because a PNG 4 byte integer only has a valid247* range of 0..2^31-1; otherwise the cast might overflow.248*/249if (png_muldiv(&res, (png_int_32)info_ptr->y_pixels_per_unit, PNG_FP_1,250(png_int_32)info_ptr->x_pixels_per_unit) != 0)251return res;252}253#else254PNG_UNUSED(png_ptr)255PNG_UNUSED(info_ptr)256#endif257258return 0;259}260#endif261262png_int_32 PNGAPI263png_get_x_offset_microns(png_const_structrp png_ptr, png_const_inforp info_ptr)264{265#ifdef PNG_oFFs_SUPPORTED266if (png_ptr != NULL && info_ptr != NULL &&267(info_ptr->valid & PNG_INFO_oFFs) != 0)268{269png_debug1(1, "in %s retrieval function", "png_get_x_offset_microns");270271if (info_ptr->offset_unit_type == PNG_OFFSET_MICROMETER)272return (info_ptr->x_offset);273}274#else275PNG_UNUSED(png_ptr)276PNG_UNUSED(info_ptr)277#endif278279return (0);280}281282png_int_32 PNGAPI283png_get_y_offset_microns(png_const_structrp png_ptr, png_const_inforp info_ptr)284{285#ifdef PNG_oFFs_SUPPORTED286if (png_ptr != NULL && info_ptr != NULL &&287(info_ptr->valid & PNG_INFO_oFFs) != 0)288{289png_debug1(1, "in %s retrieval function", "png_get_y_offset_microns");290291if (info_ptr->offset_unit_type == PNG_OFFSET_MICROMETER)292return (info_ptr->y_offset);293}294#else295PNG_UNUSED(png_ptr)296PNG_UNUSED(info_ptr)297#endif298299return (0);300}301302png_int_32 PNGAPI303png_get_x_offset_pixels(png_const_structrp png_ptr, png_const_inforp info_ptr)304{305#ifdef PNG_oFFs_SUPPORTED306if (png_ptr != NULL && info_ptr != NULL &&307(info_ptr->valid & PNG_INFO_oFFs) != 0)308{309png_debug1(1, "in %s retrieval function", "png_get_x_offset_pixels");310311if (info_ptr->offset_unit_type == PNG_OFFSET_PIXEL)312return (info_ptr->x_offset);313}314#else315PNG_UNUSED(png_ptr)316PNG_UNUSED(info_ptr)317#endif318319return (0);320}321322png_int_32 PNGAPI323png_get_y_offset_pixels(png_const_structrp png_ptr, png_const_inforp info_ptr)324{325#ifdef PNG_oFFs_SUPPORTED326if (png_ptr != NULL && info_ptr != NULL &&327(info_ptr->valid & PNG_INFO_oFFs) != 0)328{329png_debug1(1, "in %s retrieval function", "png_get_y_offset_pixels");330331if (info_ptr->offset_unit_type == PNG_OFFSET_PIXEL)332return (info_ptr->y_offset);333}334#else335PNG_UNUSED(png_ptr)336PNG_UNUSED(info_ptr)337#endif338339return (0);340}341342#ifdef PNG_INCH_CONVERSIONS_SUPPORTED343static png_uint_32344ppi_from_ppm(png_uint_32 ppm)345{346#if 0347/* The conversion is *(2.54/100), in binary (32 digits):348* .00000110100000001001110101001001349*/350png_uint_32 t1001, t1101;351ppm >>= 1; /* .1 */352t1001 = ppm + (ppm >> 3); /* .1001 */353t1101 = t1001 + (ppm >> 1); /* .1101 */354ppm >>= 20; /* .000000000000000000001 */355t1101 += t1101 >> 15; /* .1101000000000001101 */356t1001 >>= 11; /* .000000000001001 */357t1001 += t1001 >> 12; /* .000000000001001000000001001 */358ppm += t1001; /* .000000000001001000001001001 */359ppm += t1101; /* .110100000001001110101001001 */360return (ppm + 16) >> 5;/* .00000110100000001001110101001001 */361#else362/* The argument is a PNG unsigned integer, so it is not permitted363* to be bigger than 2^31.364*/365png_fixed_point result;366if (ppm <= PNG_UINT_31_MAX && png_muldiv(&result, (png_int_32)ppm, 127,3675000) != 0)368return (png_uint_32)result;369370/* Overflow. */371return 0;372#endif373}374375png_uint_32 PNGAPI376png_get_pixels_per_inch(png_const_structrp png_ptr, png_const_inforp info_ptr)377{378return ppi_from_ppm(png_get_pixels_per_meter(png_ptr, info_ptr));379}380381png_uint_32 PNGAPI382png_get_x_pixels_per_inch(png_const_structrp png_ptr, png_const_inforp info_ptr)383{384return ppi_from_ppm(png_get_x_pixels_per_meter(png_ptr, info_ptr));385}386387png_uint_32 PNGAPI388png_get_y_pixels_per_inch(png_const_structrp png_ptr, png_const_inforp info_ptr)389{390return ppi_from_ppm(png_get_y_pixels_per_meter(png_ptr, info_ptr));391}392393#ifdef PNG_FIXED_POINT_SUPPORTED394static png_fixed_point395png_fixed_inches_from_microns(png_const_structrp png_ptr, png_int_32 microns)396{397/* Convert from meters * 1,000,000 to inches * 100,000, meters to398* inches is simply *(100/2.54), so we want *(10/2.54) == 500/127.399* Notice that this can overflow - a warning is output and 0 is400* returned.401*/402return png_muldiv_warn(png_ptr, microns, 500, 127);403}404405png_fixed_point PNGAPI406png_get_x_offset_inches_fixed(png_const_structrp png_ptr,407png_const_inforp info_ptr)408{409return png_fixed_inches_from_microns(png_ptr,410png_get_x_offset_microns(png_ptr, info_ptr));411}412#endif413414#ifdef PNG_FIXED_POINT_SUPPORTED415png_fixed_point PNGAPI416png_get_y_offset_inches_fixed(png_const_structrp png_ptr,417png_const_inforp info_ptr)418{419return png_fixed_inches_from_microns(png_ptr,420png_get_y_offset_microns(png_ptr, info_ptr));421}422#endif423424#ifdef PNG_FLOATING_POINT_SUPPORTED425float PNGAPI426png_get_x_offset_inches(png_const_structrp png_ptr, png_const_inforp info_ptr)427{428/* To avoid the overflow do the conversion directly in floating429* point.430*/431return (float)(png_get_x_offset_microns(png_ptr, info_ptr) * .00003937);432}433#endif434435#ifdef PNG_FLOATING_POINT_SUPPORTED436float PNGAPI437png_get_y_offset_inches(png_const_structrp png_ptr, png_const_inforp info_ptr)438{439/* To avoid the overflow do the conversion directly in floating440* point.441*/442return (float)(png_get_y_offset_microns(png_ptr, info_ptr) * .00003937);443}444#endif445446#ifdef PNG_pHYs_SUPPORTED447png_uint_32 PNGAPI448png_get_pHYs_dpi(png_const_structrp png_ptr, png_const_inforp info_ptr,449png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)450{451png_uint_32 retval = 0;452453if (png_ptr != NULL && info_ptr != NULL &&454(info_ptr->valid & PNG_INFO_pHYs) != 0)455{456png_debug1(1, "in %s retrieval function", "pHYs");457458if (res_x != NULL)459{460*res_x = info_ptr->x_pixels_per_unit;461retval |= PNG_INFO_pHYs;462}463464if (res_y != NULL)465{466*res_y = info_ptr->y_pixels_per_unit;467retval |= PNG_INFO_pHYs;468}469470if (unit_type != NULL)471{472*unit_type = (int)info_ptr->phys_unit_type;473retval |= PNG_INFO_pHYs;474475if (*unit_type == 1)476{477if (res_x != NULL) *res_x = (png_uint_32)(*res_x * .0254 + .50);478if (res_y != NULL) *res_y = (png_uint_32)(*res_y * .0254 + .50);479}480}481}482483return (retval);484}485#endif /* pHYs */486#endif /* INCH_CONVERSIONS */487488/* png_get_channels really belongs in here, too, but it's been around longer */489490#endif /* EASY_ACCESS */491492493png_byte PNGAPI494png_get_channels(png_const_structrp png_ptr, png_const_inforp info_ptr)495{496if (png_ptr != NULL && info_ptr != NULL)497return(info_ptr->channels);498499return (0);500}501502#ifdef PNG_READ_SUPPORTED503png_const_bytep PNGAPI504png_get_signature(png_const_structrp png_ptr, png_const_inforp info_ptr)505{506if (png_ptr != NULL && info_ptr != NULL)507return(info_ptr->signature);508509return (NULL);510}511#endif512513#ifdef PNG_bKGD_SUPPORTED514png_uint_32 PNGAPI515png_get_bKGD(png_const_structrp png_ptr, png_inforp info_ptr,516png_color_16p *background)517{518if (png_ptr != NULL && info_ptr != NULL &&519(info_ptr->valid & PNG_INFO_bKGD) != 0 &&520background != NULL)521{522png_debug1(1, "in %s retrieval function", "bKGD");523524*background = &(info_ptr->background);525return (PNG_INFO_bKGD);526}527528return (0);529}530#endif531532#ifdef PNG_cHRM_SUPPORTED533/* The XYZ APIs were added in 1.5.5 to take advantage of the code added at the534* same time to correct the rgb grayscale coefficient defaults obtained from the535* cHRM chunk in 1.5.4536*/537# ifdef PNG_FLOATING_POINT_SUPPORTED538png_uint_32 PNGAPI539png_get_cHRM(png_const_structrp png_ptr, png_const_inforp info_ptr,540double *white_x, double *white_y, double *red_x, double *red_y,541double *green_x, double *green_y, double *blue_x, double *blue_y)542{543/* Quiet API change: this code used to only return the end points if a cHRM544* chunk was present, but the end points can also come from iCCP or sRGB545* chunks, so in 1.6.0 the png_get_ APIs return the end points regardless and546* the png_set_ APIs merely check that set end points are mutually547* consistent.548*/549if (png_ptr != NULL && info_ptr != NULL &&550(info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS) != 0)551{552png_debug1(1, "in %s retrieval function", "cHRM");553554if (white_x != NULL)555*white_x = png_float(png_ptr,556info_ptr->colorspace.end_points_xy.whitex, "cHRM white X");557if (white_y != NULL)558*white_y = png_float(png_ptr,559info_ptr->colorspace.end_points_xy.whitey, "cHRM white Y");560if (red_x != NULL)561*red_x = png_float(png_ptr, info_ptr->colorspace.end_points_xy.redx,562"cHRM red X");563if (red_y != NULL)564*red_y = png_float(png_ptr, info_ptr->colorspace.end_points_xy.redy,565"cHRM red Y");566if (green_x != NULL)567*green_x = png_float(png_ptr,568info_ptr->colorspace.end_points_xy.greenx, "cHRM green X");569if (green_y != NULL)570*green_y = png_float(png_ptr,571info_ptr->colorspace.end_points_xy.greeny, "cHRM green Y");572if (blue_x != NULL)573*blue_x = png_float(png_ptr, info_ptr->colorspace.end_points_xy.bluex,574"cHRM blue X");575if (blue_y != NULL)576*blue_y = png_float(png_ptr, info_ptr->colorspace.end_points_xy.bluey,577"cHRM blue Y");578return (PNG_INFO_cHRM);579}580581return (0);582}583584png_uint_32 PNGAPI585png_get_cHRM_XYZ(png_const_structrp png_ptr, png_const_inforp info_ptr,586double *red_X, double *red_Y, double *red_Z, double *green_X,587double *green_Y, double *green_Z, double *blue_X, double *blue_Y,588double *blue_Z)589{590if (png_ptr != NULL && info_ptr != NULL &&591(info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS) != 0)592{593png_debug1(1, "in %s retrieval function", "cHRM_XYZ(float)");594595if (red_X != NULL)596*red_X = png_float(png_ptr, info_ptr->colorspace.end_points_XYZ.red_X,597"cHRM red X");598if (red_Y != NULL)599*red_Y = png_float(png_ptr, info_ptr->colorspace.end_points_XYZ.red_Y,600"cHRM red Y");601if (red_Z != NULL)602*red_Z = png_float(png_ptr, info_ptr->colorspace.end_points_XYZ.red_Z,603"cHRM red Z");604if (green_X != NULL)605*green_X = png_float(png_ptr,606info_ptr->colorspace.end_points_XYZ.green_X, "cHRM green X");607if (green_Y != NULL)608*green_Y = png_float(png_ptr,609info_ptr->colorspace.end_points_XYZ.green_Y, "cHRM green Y");610if (green_Z != NULL)611*green_Z = png_float(png_ptr,612info_ptr->colorspace.end_points_XYZ.green_Z, "cHRM green Z");613if (blue_X != NULL)614*blue_X = png_float(png_ptr,615info_ptr->colorspace.end_points_XYZ.blue_X, "cHRM blue X");616if (blue_Y != NULL)617*blue_Y = png_float(png_ptr,618info_ptr->colorspace.end_points_XYZ.blue_Y, "cHRM blue Y");619if (blue_Z != NULL)620*blue_Z = png_float(png_ptr,621info_ptr->colorspace.end_points_XYZ.blue_Z, "cHRM blue Z");622return (PNG_INFO_cHRM);623}624625return (0);626}627# endif628629# ifdef PNG_FIXED_POINT_SUPPORTED630png_uint_32 PNGAPI631png_get_cHRM_XYZ_fixed(png_const_structrp png_ptr, png_const_inforp info_ptr,632png_fixed_point *int_red_X, png_fixed_point *int_red_Y,633png_fixed_point *int_red_Z, png_fixed_point *int_green_X,634png_fixed_point *int_green_Y, png_fixed_point *int_green_Z,635png_fixed_point *int_blue_X, png_fixed_point *int_blue_Y,636png_fixed_point *int_blue_Z)637{638if (png_ptr != NULL && info_ptr != NULL &&639(info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS) != 0)640{641png_debug1(1, "in %s retrieval function", "cHRM_XYZ");642643if (int_red_X != NULL)644*int_red_X = info_ptr->colorspace.end_points_XYZ.red_X;645if (int_red_Y != NULL)646*int_red_Y = info_ptr->colorspace.end_points_XYZ.red_Y;647if (int_red_Z != NULL)648*int_red_Z = info_ptr->colorspace.end_points_XYZ.red_Z;649if (int_green_X != NULL)650*int_green_X = info_ptr->colorspace.end_points_XYZ.green_X;651if (int_green_Y != NULL)652*int_green_Y = info_ptr->colorspace.end_points_XYZ.green_Y;653if (int_green_Z != NULL)654*int_green_Z = info_ptr->colorspace.end_points_XYZ.green_Z;655if (int_blue_X != NULL)656*int_blue_X = info_ptr->colorspace.end_points_XYZ.blue_X;657if (int_blue_Y != NULL)658*int_blue_Y = info_ptr->colorspace.end_points_XYZ.blue_Y;659if (int_blue_Z != NULL)660*int_blue_Z = info_ptr->colorspace.end_points_XYZ.blue_Z;661return (PNG_INFO_cHRM);662}663664return (0);665}666667png_uint_32 PNGAPI668png_get_cHRM_fixed(png_const_structrp png_ptr, png_const_inforp info_ptr,669png_fixed_point *white_x, png_fixed_point *white_y, png_fixed_point *red_x,670png_fixed_point *red_y, png_fixed_point *green_x, png_fixed_point *green_y,671png_fixed_point *blue_x, png_fixed_point *blue_y)672{673png_debug1(1, "in %s retrieval function", "cHRM");674675if (png_ptr != NULL && info_ptr != NULL &&676(info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS) != 0)677{678if (white_x != NULL)679*white_x = info_ptr->colorspace.end_points_xy.whitex;680if (white_y != NULL)681*white_y = info_ptr->colorspace.end_points_xy.whitey;682if (red_x != NULL)683*red_x = info_ptr->colorspace.end_points_xy.redx;684if (red_y != NULL)685*red_y = info_ptr->colorspace.end_points_xy.redy;686if (green_x != NULL)687*green_x = info_ptr->colorspace.end_points_xy.greenx;688if (green_y != NULL)689*green_y = info_ptr->colorspace.end_points_xy.greeny;690if (blue_x != NULL)691*blue_x = info_ptr->colorspace.end_points_xy.bluex;692if (blue_y != NULL)693*blue_y = info_ptr->colorspace.end_points_xy.bluey;694return (PNG_INFO_cHRM);695}696697return (0);698}699# endif700#endif701702#ifdef PNG_gAMA_SUPPORTED703# ifdef PNG_FIXED_POINT_SUPPORTED704png_uint_32 PNGAPI705png_get_gAMA_fixed(png_const_structrp png_ptr, png_const_inforp info_ptr,706png_fixed_point *file_gamma)707{708png_debug1(1, "in %s retrieval function", "gAMA");709710if (png_ptr != NULL && info_ptr != NULL &&711(info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_GAMMA) != 0 &&712file_gamma != NULL)713{714*file_gamma = info_ptr->colorspace.gamma;715return (PNG_INFO_gAMA);716}717718return (0);719}720# endif721722# ifdef PNG_FLOATING_POINT_SUPPORTED723png_uint_32 PNGAPI724png_get_gAMA(png_const_structrp png_ptr, png_const_inforp info_ptr,725double *file_gamma)726{727png_debug1(1, "in %s retrieval function", "gAMA(float)");728729if (png_ptr != NULL && info_ptr != NULL &&730(info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_GAMMA) != 0 &&731file_gamma != NULL)732{733*file_gamma = png_float(png_ptr, info_ptr->colorspace.gamma,734"png_get_gAMA");735return (PNG_INFO_gAMA);736}737738return (0);739}740# endif741#endif742743#ifdef PNG_sRGB_SUPPORTED744png_uint_32 PNGAPI745png_get_sRGB(png_const_structrp png_ptr, png_const_inforp info_ptr,746int *file_srgb_intent)747{748png_debug1(1, "in %s retrieval function", "sRGB");749750if (png_ptr != NULL && info_ptr != NULL &&751(info_ptr->valid & PNG_INFO_sRGB) != 0 && file_srgb_intent != NULL)752{753*file_srgb_intent = info_ptr->colorspace.rendering_intent;754return (PNG_INFO_sRGB);755}756757return (0);758}759#endif760761#ifdef PNG_iCCP_SUPPORTED762png_uint_32 PNGAPI763png_get_iCCP(png_const_structrp png_ptr, png_inforp info_ptr,764png_charpp name, int *compression_type,765png_bytepp profile, png_uint_32 *proflen)766{767png_debug1(1, "in %s retrieval function", "iCCP");768769if (png_ptr != NULL && info_ptr != NULL &&770(info_ptr->valid & PNG_INFO_iCCP) != 0 &&771name != NULL && profile != NULL && proflen != NULL)772{773*name = info_ptr->iccp_name;774*profile = info_ptr->iccp_profile;775*proflen = png_get_uint_32(info_ptr->iccp_profile);776/* This is somewhat irrelevant since the profile data returned has777* actually been uncompressed.778*/779if (compression_type != NULL)780*compression_type = PNG_COMPRESSION_TYPE_BASE;781return (PNG_INFO_iCCP);782}783784return (0);785786}787#endif788789#ifdef PNG_sPLT_SUPPORTED790int PNGAPI791png_get_sPLT(png_const_structrp png_ptr, png_inforp info_ptr,792png_sPLT_tpp spalettes)793{794if (png_ptr != NULL && info_ptr != NULL && spalettes != NULL)795{796*spalettes = info_ptr->splt_palettes;797return info_ptr->splt_palettes_num;798}799800return (0);801}802#endif803804#ifdef PNG_eXIf_SUPPORTED805png_uint_32 PNGAPI806png_get_eXIf(png_const_structrp png_ptr, png_inforp info_ptr,807png_bytep *exif)808{809png_warning(png_ptr, "png_get_eXIf does not work; use png_get_eXIf_1");810PNG_UNUSED(info_ptr)811PNG_UNUSED(exif)812return 0;813}814815png_uint_32 PNGAPI816png_get_eXIf_1(png_const_structrp png_ptr, png_const_inforp info_ptr,817png_uint_32 *num_exif, png_bytep *exif)818{819png_debug1(1, "in %s retrieval function", "eXIf");820821if (png_ptr != NULL && info_ptr != NULL &&822(info_ptr->valid & PNG_INFO_eXIf) != 0 && exif != NULL)823{824*num_exif = info_ptr->num_exif;825*exif = info_ptr->exif;826return (PNG_INFO_eXIf);827}828829return (0);830}831#endif832833#ifdef PNG_hIST_SUPPORTED834png_uint_32 PNGAPI835png_get_hIST(png_const_structrp png_ptr, png_inforp info_ptr,836png_uint_16p *hist)837{838png_debug1(1, "in %s retrieval function", "hIST");839840if (png_ptr != NULL && info_ptr != NULL &&841(info_ptr->valid & PNG_INFO_hIST) != 0 && hist != NULL)842{843*hist = info_ptr->hist;844return (PNG_INFO_hIST);845}846847return (0);848}849#endif850851png_uint_32 PNGAPI852png_get_IHDR(png_const_structrp png_ptr, png_const_inforp info_ptr,853png_uint_32 *width, png_uint_32 *height, int *bit_depth,854int *color_type, int *interlace_type, int *compression_type,855int *filter_type)856{857png_debug1(1, "in %s retrieval function", "IHDR");858859if (png_ptr == NULL || info_ptr == NULL)860return (0);861862if (width != NULL)863*width = info_ptr->width;864865if (height != NULL)866*height = info_ptr->height;867868if (bit_depth != NULL)869*bit_depth = info_ptr->bit_depth;870871if (color_type != NULL)872*color_type = info_ptr->color_type;873874if (compression_type != NULL)875*compression_type = info_ptr->compression_type;876877if (filter_type != NULL)878*filter_type = info_ptr->filter_type;879880if (interlace_type != NULL)881*interlace_type = info_ptr->interlace_type;882883/* This is redundant if we can be sure that the info_ptr values were all884* assigned in png_set_IHDR(). We do the check anyhow in case an885* application has ignored our advice not to mess with the members886* of info_ptr directly.887*/888png_check_IHDR(png_ptr, info_ptr->width, info_ptr->height,889info_ptr->bit_depth, info_ptr->color_type, info_ptr->interlace_type,890info_ptr->compression_type, info_ptr->filter_type);891892return (1);893}894895#ifdef PNG_oFFs_SUPPORTED896png_uint_32 PNGAPI897png_get_oFFs(png_const_structrp png_ptr, png_const_inforp info_ptr,898png_int_32 *offset_x, png_int_32 *offset_y, int *unit_type)899{900png_debug1(1, "in %s retrieval function", "oFFs");901902if (png_ptr != NULL && info_ptr != NULL &&903(info_ptr->valid & PNG_INFO_oFFs) != 0 &&904offset_x != NULL && offset_y != NULL && unit_type != NULL)905{906*offset_x = info_ptr->x_offset;907*offset_y = info_ptr->y_offset;908*unit_type = (int)info_ptr->offset_unit_type;909return (PNG_INFO_oFFs);910}911912return (0);913}914#endif915916#ifdef PNG_pCAL_SUPPORTED917png_uint_32 PNGAPI918png_get_pCAL(png_const_structrp png_ptr, png_inforp info_ptr,919png_charp *purpose, png_int_32 *X0, png_int_32 *X1, int *type, int *nparams,920png_charp *units, png_charpp *params)921{922png_debug1(1, "in %s retrieval function", "pCAL");923924if (png_ptr != NULL && info_ptr != NULL &&925(info_ptr->valid & PNG_INFO_pCAL) != 0 &&926purpose != NULL && X0 != NULL && X1 != NULL && type != NULL &&927nparams != NULL && units != NULL && params != NULL)928{929*purpose = info_ptr->pcal_purpose;930*X0 = info_ptr->pcal_X0;931*X1 = info_ptr->pcal_X1;932*type = (int)info_ptr->pcal_type;933*nparams = (int)info_ptr->pcal_nparams;934*units = info_ptr->pcal_units;935*params = info_ptr->pcal_params;936return (PNG_INFO_pCAL);937}938939return (0);940}941#endif942943#ifdef PNG_sCAL_SUPPORTED944# ifdef PNG_FIXED_POINT_SUPPORTED945# if defined(PNG_FLOATING_ARITHMETIC_SUPPORTED) || \946defined(PNG_FLOATING_POINT_SUPPORTED)947png_uint_32 PNGAPI948png_get_sCAL_fixed(png_const_structrp png_ptr, png_const_inforp info_ptr,949int *unit, png_fixed_point *width, png_fixed_point *height)950{951if (png_ptr != NULL && info_ptr != NULL &&952(info_ptr->valid & PNG_INFO_sCAL) != 0)953{954*unit = info_ptr->scal_unit;955/*TODO: make this work without FP support; the API is currently eliminated956* if neither floating point APIs nor internal floating point arithmetic957* are enabled.958*/959*width = png_fixed(png_ptr, atof(info_ptr->scal_s_width), "sCAL width");960*height = png_fixed(png_ptr, atof(info_ptr->scal_s_height),961"sCAL height");962return (PNG_INFO_sCAL);963}964965return(0);966}967# endif /* FLOATING_ARITHMETIC */968# endif /* FIXED_POINT */969# ifdef PNG_FLOATING_POINT_SUPPORTED970png_uint_32 PNGAPI971png_get_sCAL(png_const_structrp png_ptr, png_const_inforp info_ptr,972int *unit, double *width, double *height)973{974if (png_ptr != NULL && info_ptr != NULL &&975(info_ptr->valid & PNG_INFO_sCAL) != 0)976{977*unit = info_ptr->scal_unit;978*width = atof(info_ptr->scal_s_width);979*height = atof(info_ptr->scal_s_height);980return (PNG_INFO_sCAL);981}982983return(0);984}985# endif /* FLOATING POINT */986png_uint_32 PNGAPI987png_get_sCAL_s(png_const_structrp png_ptr, png_const_inforp info_ptr,988int *unit, png_charpp width, png_charpp height)989{990if (png_ptr != NULL && info_ptr != NULL &&991(info_ptr->valid & PNG_INFO_sCAL) != 0)992{993*unit = info_ptr->scal_unit;994*width = info_ptr->scal_s_width;995*height = info_ptr->scal_s_height;996return (PNG_INFO_sCAL);997}998999return(0);1000}1001#endif /* sCAL */10021003#ifdef PNG_pHYs_SUPPORTED1004png_uint_32 PNGAPI1005png_get_pHYs(png_const_structrp png_ptr, png_const_inforp info_ptr,1006png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)1007{1008png_uint_32 retval = 0;10091010png_debug1(1, "in %s retrieval function", "pHYs");10111012if (png_ptr != NULL && info_ptr != NULL &&1013(info_ptr->valid & PNG_INFO_pHYs) != 0)1014{1015if (res_x != NULL)1016{1017*res_x = info_ptr->x_pixels_per_unit;1018retval |= PNG_INFO_pHYs;1019}10201021if (res_y != NULL)1022{1023*res_y = info_ptr->y_pixels_per_unit;1024retval |= PNG_INFO_pHYs;1025}10261027if (unit_type != NULL)1028{1029*unit_type = (int)info_ptr->phys_unit_type;1030retval |= PNG_INFO_pHYs;1031}1032}10331034return (retval);1035}1036#endif /* pHYs */10371038png_uint_32 PNGAPI1039png_get_PLTE(png_const_structrp png_ptr, png_inforp info_ptr,1040png_colorp *palette, int *num_palette)1041{1042png_debug1(1, "in %s retrieval function", "PLTE");10431044if (png_ptr != NULL && info_ptr != NULL &&1045(info_ptr->valid & PNG_INFO_PLTE) != 0 && palette != NULL)1046{1047*palette = info_ptr->palette;1048*num_palette = info_ptr->num_palette;1049png_debug1(3, "num_palette = %d", *num_palette);1050return (PNG_INFO_PLTE);1051}10521053return (0);1054}10551056#ifdef PNG_sBIT_SUPPORTED1057png_uint_32 PNGAPI1058png_get_sBIT(png_const_structrp png_ptr, png_inforp info_ptr,1059png_color_8p *sig_bit)1060{1061png_debug1(1, "in %s retrieval function", "sBIT");10621063if (png_ptr != NULL && info_ptr != NULL &&1064(info_ptr->valid & PNG_INFO_sBIT) != 0 && sig_bit != NULL)1065{1066*sig_bit = &(info_ptr->sig_bit);1067return (PNG_INFO_sBIT);1068}10691070return (0);1071}1072#endif10731074#ifdef PNG_TEXT_SUPPORTED1075int PNGAPI1076png_get_text(png_const_structrp png_ptr, png_inforp info_ptr,1077png_textp *text_ptr, int *num_text)1078{1079if (png_ptr != NULL && info_ptr != NULL && info_ptr->num_text > 0)1080{1081png_debug1(1, "in 0x%lx retrieval function",1082(unsigned long)png_ptr->chunk_name);10831084if (text_ptr != NULL)1085*text_ptr = info_ptr->text;10861087if (num_text != NULL)1088*num_text = info_ptr->num_text;10891090return info_ptr->num_text;1091}10921093if (num_text != NULL)1094*num_text = 0;10951096return(0);1097}1098#endif10991100#ifdef PNG_tIME_SUPPORTED1101png_uint_32 PNGAPI1102png_get_tIME(png_const_structrp png_ptr, png_inforp info_ptr,1103png_timep *mod_time)1104{1105png_debug1(1, "in %s retrieval function", "tIME");11061107if (png_ptr != NULL && info_ptr != NULL &&1108(info_ptr->valid & PNG_INFO_tIME) != 0 && mod_time != NULL)1109{1110*mod_time = &(info_ptr->mod_time);1111return (PNG_INFO_tIME);1112}11131114return (0);1115}1116#endif11171118#ifdef PNG_tRNS_SUPPORTED1119png_uint_32 PNGAPI1120png_get_tRNS(png_const_structrp png_ptr, png_inforp info_ptr,1121png_bytep *trans_alpha, int *num_trans, png_color_16p *trans_color)1122{1123png_uint_32 retval = 0;1124if (png_ptr != NULL && info_ptr != NULL &&1125(info_ptr->valid & PNG_INFO_tRNS) != 0)1126{1127png_debug1(1, "in %s retrieval function", "tRNS");11281129if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)1130{1131if (trans_alpha != NULL)1132{1133*trans_alpha = info_ptr->trans_alpha;1134retval |= PNG_INFO_tRNS;1135}11361137if (trans_color != NULL)1138*trans_color = &(info_ptr->trans_color);1139}11401141else /* if (info_ptr->color_type != PNG_COLOR_TYPE_PALETTE) */1142{1143if (trans_color != NULL)1144{1145*trans_color = &(info_ptr->trans_color);1146retval |= PNG_INFO_tRNS;1147}11481149if (trans_alpha != NULL)1150*trans_alpha = NULL;1151}11521153if (num_trans != NULL)1154{1155*num_trans = info_ptr->num_trans;1156retval |= PNG_INFO_tRNS;1157}1158}11591160return (retval);1161}1162#endif11631164#ifdef PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED1165int PNGAPI1166png_get_unknown_chunks(png_const_structrp png_ptr, png_inforp info_ptr,1167png_unknown_chunkpp unknowns)1168{1169if (png_ptr != NULL && info_ptr != NULL && unknowns != NULL)1170{1171*unknowns = info_ptr->unknown_chunks;1172return info_ptr->unknown_chunks_num;1173}11741175return (0);1176}1177#endif11781179#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED1180png_byte PNGAPI1181png_get_rgb_to_gray_status (png_const_structrp png_ptr)1182{1183return (png_byte)(png_ptr ? png_ptr->rgb_to_gray_status : 0);1184}1185#endif11861187#ifdef PNG_USER_CHUNKS_SUPPORTED1188png_voidp PNGAPI1189png_get_user_chunk_ptr(png_const_structrp png_ptr)1190{1191return (png_ptr ? png_ptr->user_chunk_ptr : NULL);1192}1193#endif11941195size_t PNGAPI1196png_get_compression_buffer_size(png_const_structrp png_ptr)1197{1198if (png_ptr == NULL)1199return 0;12001201#ifdef PNG_WRITE_SUPPORTED1202if ((png_ptr->mode & PNG_IS_READ_STRUCT) != 0)1203#endif1204{1205#ifdef PNG_SEQUENTIAL_READ_SUPPORTED1206return png_ptr->IDAT_read_size;1207#else1208return PNG_IDAT_READ_SIZE;1209#endif1210}12111212#ifdef PNG_WRITE_SUPPORTED1213else1214return png_ptr->zbuffer_size;1215#endif1216}12171218#ifdef PNG_SET_USER_LIMITS_SUPPORTED1219/* These functions were added to libpng 1.2.6 and were enabled1220* by default in libpng-1.4.0 */1221png_uint_32 PNGAPI1222png_get_user_width_max (png_const_structrp png_ptr)1223{1224return (png_ptr ? png_ptr->user_width_max : 0);1225}12261227png_uint_32 PNGAPI1228png_get_user_height_max (png_const_structrp png_ptr)1229{1230return (png_ptr ? png_ptr->user_height_max : 0);1231}12321233/* This function was added to libpng 1.4.0 */1234png_uint_32 PNGAPI1235png_get_chunk_cache_max (png_const_structrp png_ptr)1236{1237return (png_ptr ? png_ptr->user_chunk_cache_max : 0);1238}12391240/* This function was added to libpng 1.4.1 */1241png_alloc_size_t PNGAPI1242png_get_chunk_malloc_max (png_const_structrp png_ptr)1243{1244return (png_ptr ? png_ptr->user_chunk_malloc_max : 0);1245}1246#endif /* SET_USER_LIMITS */12471248/* These functions were added to libpng 1.4.0 */1249#ifdef PNG_IO_STATE_SUPPORTED1250png_uint_32 PNGAPI1251png_get_io_state (png_const_structrp png_ptr)1252{1253return png_ptr->io_state;1254}12551256png_uint_32 PNGAPI1257png_get_io_chunk_type (png_const_structrp png_ptr)1258{1259return png_ptr->chunk_name;1260}1261#endif /* IO_STATE */12621263#ifdef PNG_CHECK_FOR_INVALID_INDEX_SUPPORTED1264# ifdef PNG_GET_PALETTE_MAX_SUPPORTED1265int PNGAPI1266png_get_palette_max(png_const_structp png_ptr, png_const_infop info_ptr)1267{1268if (png_ptr != NULL && info_ptr != NULL)1269return png_ptr->num_palette_max;12701271return (-1);1272}1273# endif1274#endif12751276#endif /* READ || WRITE */127712781279