Dependencies:   emwin_lib

Fork of DMemWin by Embedded Artists

Committer:
destinyXfate
Date:
Thu Jun 02 04:55:08 2016 +0000
Revision:
4:20387dbf7ecf
Parent:
2:0e2ef1edf01b
;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
destinyXfate 2:0e2ef1edf01b 1
destinyXfate 2:0e2ef1edf01b 2 /* pngset.c - storage of image information into info struct
destinyXfate 2:0e2ef1edf01b 3 *
destinyXfate 2:0e2ef1edf01b 4 * Last changed in libpng 1.2.15 January 5, 2007
destinyXfate 2:0e2ef1edf01b 5 * For conditions of distribution and use, see copyright notice in png.h
destinyXfate 2:0e2ef1edf01b 6 * Copyright (c) 1998-2007 Glenn Randers-Pehrson
destinyXfate 2:0e2ef1edf01b 7 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
destinyXfate 2:0e2ef1edf01b 8 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
destinyXfate 2:0e2ef1edf01b 9 *
destinyXfate 2:0e2ef1edf01b 10 * The functions here are used during reads to store data from the file
destinyXfate 2:0e2ef1edf01b 11 * into the info struct, and during writes to store application data
destinyXfate 2:0e2ef1edf01b 12 * into the info struct for writing into the file. This abstracts the
destinyXfate 2:0e2ef1edf01b 13 * info struct and allows us to change the structure in the future.
destinyXfate 2:0e2ef1edf01b 14 */
destinyXfate 2:0e2ef1edf01b 15
destinyXfate 2:0e2ef1edf01b 16 #define PNG_INTERNAL
destinyXfate 2:0e2ef1edf01b 17 #include "png.h"
destinyXfate 2:0e2ef1edf01b 18
destinyXfate 2:0e2ef1edf01b 19 #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
destinyXfate 2:0e2ef1edf01b 20
destinyXfate 2:0e2ef1edf01b 21 #if defined(PNG_bKGD_SUPPORTED)
destinyXfate 2:0e2ef1edf01b 22 void PNGAPI
destinyXfate 2:0e2ef1edf01b 23 png_set_bKGD(png_structp png_ptr, png_infop info_ptr, png_color_16p background)
destinyXfate 2:0e2ef1edf01b 24 {
destinyXfate 2:0e2ef1edf01b 25 png_debug1(1, "in %s storage function\n", "bKGD");
destinyXfate 2:0e2ef1edf01b 26 if (png_ptr == NULL || info_ptr == NULL)
destinyXfate 2:0e2ef1edf01b 27 return;
destinyXfate 2:0e2ef1edf01b 28
destinyXfate 2:0e2ef1edf01b 29 png_memcpy(&(info_ptr->background), background, png_sizeof(png_color_16));
destinyXfate 2:0e2ef1edf01b 30 info_ptr->valid |= PNG_INFO_bKGD;
destinyXfate 2:0e2ef1edf01b 31 }
destinyXfate 2:0e2ef1edf01b 32 #endif
destinyXfate 2:0e2ef1edf01b 33
destinyXfate 2:0e2ef1edf01b 34 #if defined(PNG_cHRM_SUPPORTED)
destinyXfate 2:0e2ef1edf01b 35 #ifdef PNG_FLOATING_POINT_SUPPORTED
destinyXfate 2:0e2ef1edf01b 36 void PNGAPI
destinyXfate 2:0e2ef1edf01b 37 png_set_cHRM(png_structp png_ptr, png_infop info_ptr,
destinyXfate 2:0e2ef1edf01b 38 double white_x, double white_y, double red_x, double red_y,
destinyXfate 2:0e2ef1edf01b 39 double green_x, double green_y, double blue_x, double blue_y)
destinyXfate 2:0e2ef1edf01b 40 {
destinyXfate 2:0e2ef1edf01b 41 png_debug1(1, "in %s storage function\n", "cHRM");
destinyXfate 2:0e2ef1edf01b 42 if (png_ptr == NULL || info_ptr == NULL)
destinyXfate 2:0e2ef1edf01b 43 return;
destinyXfate 2:0e2ef1edf01b 44
destinyXfate 2:0e2ef1edf01b 45 if (white_x < 0.0 || white_y < 0.0 ||
destinyXfate 2:0e2ef1edf01b 46 red_x < 0.0 || red_y < 0.0 ||
destinyXfate 2:0e2ef1edf01b 47 green_x < 0.0 || green_y < 0.0 ||
destinyXfate 2:0e2ef1edf01b 48 blue_x < 0.0 || blue_y < 0.0)
destinyXfate 2:0e2ef1edf01b 49 {
destinyXfate 2:0e2ef1edf01b 50 png_warning(png_ptr,
destinyXfate 2:0e2ef1edf01b 51 "Ignoring attempt to set negative chromaticity value");
destinyXfate 2:0e2ef1edf01b 52 return;
destinyXfate 2:0e2ef1edf01b 53 }
destinyXfate 2:0e2ef1edf01b 54 if (white_x > 21474.83 || white_y > 21474.83 ||
destinyXfate 2:0e2ef1edf01b 55 red_x > 21474.83 || red_y > 21474.83 ||
destinyXfate 2:0e2ef1edf01b 56 green_x > 21474.83 || green_y > 21474.83 ||
destinyXfate 2:0e2ef1edf01b 57 blue_x > 21474.83 || blue_y > 21474.83)
destinyXfate 2:0e2ef1edf01b 58 {
destinyXfate 2:0e2ef1edf01b 59 png_warning(png_ptr,
destinyXfate 2:0e2ef1edf01b 60 "Ignoring attempt to set chromaticity value exceeding 21474.83");
destinyXfate 2:0e2ef1edf01b 61 return;
destinyXfate 2:0e2ef1edf01b 62 }
destinyXfate 2:0e2ef1edf01b 63
destinyXfate 2:0e2ef1edf01b 64 info_ptr->x_white = (float)white_x;
destinyXfate 2:0e2ef1edf01b 65 info_ptr->y_white = (float)white_y;
destinyXfate 2:0e2ef1edf01b 66 info_ptr->x_red = (float)red_x;
destinyXfate 2:0e2ef1edf01b 67 info_ptr->y_red = (float)red_y;
destinyXfate 2:0e2ef1edf01b 68 info_ptr->x_green = (float)green_x;
destinyXfate 2:0e2ef1edf01b 69 info_ptr->y_green = (float)green_y;
destinyXfate 2:0e2ef1edf01b 70 info_ptr->x_blue = (float)blue_x;
destinyXfate 2:0e2ef1edf01b 71 info_ptr->y_blue = (float)blue_y;
destinyXfate 2:0e2ef1edf01b 72 #ifdef PNG_FIXED_POINT_SUPPORTED
destinyXfate 2:0e2ef1edf01b 73 info_ptr->int_x_white = (png_fixed_point)(white_x*100000.+0.5);
destinyXfate 2:0e2ef1edf01b 74 info_ptr->int_y_white = (png_fixed_point)(white_y*100000.+0.5);
destinyXfate 2:0e2ef1edf01b 75 info_ptr->int_x_red = (png_fixed_point)( red_x*100000.+0.5);
destinyXfate 2:0e2ef1edf01b 76 info_ptr->int_y_red = (png_fixed_point)( red_y*100000.+0.5);
destinyXfate 2:0e2ef1edf01b 77 info_ptr->int_x_green = (png_fixed_point)(green_x*100000.+0.5);
destinyXfate 2:0e2ef1edf01b 78 info_ptr->int_y_green = (png_fixed_point)(green_y*100000.+0.5);
destinyXfate 2:0e2ef1edf01b 79 info_ptr->int_x_blue = (png_fixed_point)( blue_x*100000.+0.5);
destinyXfate 2:0e2ef1edf01b 80 info_ptr->int_y_blue = (png_fixed_point)( blue_y*100000.+0.5);
destinyXfate 2:0e2ef1edf01b 81 #endif
destinyXfate 2:0e2ef1edf01b 82 info_ptr->valid |= PNG_INFO_cHRM;
destinyXfate 2:0e2ef1edf01b 83 }
destinyXfate 2:0e2ef1edf01b 84 #endif
destinyXfate 2:0e2ef1edf01b 85 #ifdef PNG_FIXED_POINT_SUPPORTED
destinyXfate 2:0e2ef1edf01b 86 void PNGAPI
destinyXfate 2:0e2ef1edf01b 87 png_set_cHRM_fixed(png_structp png_ptr, png_infop info_ptr,
destinyXfate 2:0e2ef1edf01b 88 png_fixed_point white_x, png_fixed_point white_y, png_fixed_point red_x,
destinyXfate 2:0e2ef1edf01b 89 png_fixed_point red_y, png_fixed_point green_x, png_fixed_point green_y,
destinyXfate 2:0e2ef1edf01b 90 png_fixed_point blue_x, png_fixed_point blue_y)
destinyXfate 2:0e2ef1edf01b 91 {
destinyXfate 2:0e2ef1edf01b 92 png_debug1(1, "in %s storage function\n", "cHRM");
destinyXfate 2:0e2ef1edf01b 93 if (png_ptr == NULL || info_ptr == NULL)
destinyXfate 2:0e2ef1edf01b 94 return;
destinyXfate 2:0e2ef1edf01b 95
destinyXfate 2:0e2ef1edf01b 96 if (white_x < 0 || white_y < 0 ||
destinyXfate 2:0e2ef1edf01b 97 red_x < 0 || red_y < 0 ||
destinyXfate 2:0e2ef1edf01b 98 green_x < 0 || green_y < 0 ||
destinyXfate 2:0e2ef1edf01b 99 blue_x < 0 || blue_y < 0)
destinyXfate 2:0e2ef1edf01b 100 {
destinyXfate 2:0e2ef1edf01b 101 png_warning(png_ptr,
destinyXfate 2:0e2ef1edf01b 102 "Ignoring attempt to set negative chromaticity value");
destinyXfate 2:0e2ef1edf01b 103 return;
destinyXfate 2:0e2ef1edf01b 104 }
destinyXfate 2:0e2ef1edf01b 105 #ifdef PNG_FLOATING_POINT_SUPPORTED
destinyXfate 2:0e2ef1edf01b 106 if (white_x > (double) PNG_UINT_31_MAX ||
destinyXfate 2:0e2ef1edf01b 107 white_y > (double) PNG_UINT_31_MAX ||
destinyXfate 2:0e2ef1edf01b 108 red_x > (double) PNG_UINT_31_MAX ||
destinyXfate 2:0e2ef1edf01b 109 red_y > (double) PNG_UINT_31_MAX ||
destinyXfate 2:0e2ef1edf01b 110 green_x > (double) PNG_UINT_31_MAX ||
destinyXfate 2:0e2ef1edf01b 111 green_y > (double) PNG_UINT_31_MAX ||
destinyXfate 2:0e2ef1edf01b 112 blue_x > (double) PNG_UINT_31_MAX ||
destinyXfate 2:0e2ef1edf01b 113 blue_y > (double) PNG_UINT_31_MAX)
destinyXfate 2:0e2ef1edf01b 114 #else
destinyXfate 2:0e2ef1edf01b 115 if (white_x > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
destinyXfate 2:0e2ef1edf01b 116 white_y > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
destinyXfate 2:0e2ef1edf01b 117 red_x > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
destinyXfate 2:0e2ef1edf01b 118 red_y > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
destinyXfate 2:0e2ef1edf01b 119 green_x > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
destinyXfate 2:0e2ef1edf01b 120 green_y > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
destinyXfate 2:0e2ef1edf01b 121 blue_x > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
destinyXfate 2:0e2ef1edf01b 122 blue_y > (png_fixed_point) PNG_UINT_31_MAX/100000L)
destinyXfate 2:0e2ef1edf01b 123 #endif
destinyXfate 2:0e2ef1edf01b 124 {
destinyXfate 2:0e2ef1edf01b 125 png_warning(png_ptr,
destinyXfate 2:0e2ef1edf01b 126 "Ignoring attempt to set chromaticity value exceeding 21474.83");
destinyXfate 2:0e2ef1edf01b 127 return;
destinyXfate 2:0e2ef1edf01b 128 }
destinyXfate 2:0e2ef1edf01b 129 info_ptr->int_x_white = white_x;
destinyXfate 2:0e2ef1edf01b 130 info_ptr->int_y_white = white_y;
destinyXfate 2:0e2ef1edf01b 131 info_ptr->int_x_red = red_x;
destinyXfate 2:0e2ef1edf01b 132 info_ptr->int_y_red = red_y;
destinyXfate 2:0e2ef1edf01b 133 info_ptr->int_x_green = green_x;
destinyXfate 2:0e2ef1edf01b 134 info_ptr->int_y_green = green_y;
destinyXfate 2:0e2ef1edf01b 135 info_ptr->int_x_blue = blue_x;
destinyXfate 2:0e2ef1edf01b 136 info_ptr->int_y_blue = blue_y;
destinyXfate 2:0e2ef1edf01b 137 #ifdef PNG_FLOATING_POINT_SUPPORTED
destinyXfate 2:0e2ef1edf01b 138 info_ptr->x_white = (float)(white_x/100000.);
destinyXfate 2:0e2ef1edf01b 139 info_ptr->y_white = (float)(white_y/100000.);
destinyXfate 2:0e2ef1edf01b 140 info_ptr->x_red = (float)( red_x/100000.);
destinyXfate 2:0e2ef1edf01b 141 info_ptr->y_red = (float)( red_y/100000.);
destinyXfate 2:0e2ef1edf01b 142 info_ptr->x_green = (float)(green_x/100000.);
destinyXfate 2:0e2ef1edf01b 143 info_ptr->y_green = (float)(green_y/100000.);
destinyXfate 2:0e2ef1edf01b 144 info_ptr->x_blue = (float)( blue_x/100000.);
destinyXfate 2:0e2ef1edf01b 145 info_ptr->y_blue = (float)( blue_y/100000.);
destinyXfate 2:0e2ef1edf01b 146 #endif
destinyXfate 2:0e2ef1edf01b 147 info_ptr->valid |= PNG_INFO_cHRM;
destinyXfate 2:0e2ef1edf01b 148 }
destinyXfate 2:0e2ef1edf01b 149 #endif
destinyXfate 2:0e2ef1edf01b 150 #endif
destinyXfate 2:0e2ef1edf01b 151
destinyXfate 2:0e2ef1edf01b 152 #if defined(PNG_gAMA_SUPPORTED)
destinyXfate 2:0e2ef1edf01b 153 #ifdef PNG_FLOATING_POINT_SUPPORTED
destinyXfate 2:0e2ef1edf01b 154 void PNGAPI
destinyXfate 2:0e2ef1edf01b 155 png_set_gAMA(png_structp png_ptr, png_infop info_ptr, double file_gamma)
destinyXfate 2:0e2ef1edf01b 156 {
destinyXfate 2:0e2ef1edf01b 157 double gamma;
destinyXfate 2:0e2ef1edf01b 158 png_debug1(1, "in %s storage function\n", "gAMA");
destinyXfate 2:0e2ef1edf01b 159 if (png_ptr == NULL || info_ptr == NULL)
destinyXfate 2:0e2ef1edf01b 160 return;
destinyXfate 2:0e2ef1edf01b 161
destinyXfate 2:0e2ef1edf01b 162 /* Check for overflow */
destinyXfate 2:0e2ef1edf01b 163 if (file_gamma > 21474.83)
destinyXfate 2:0e2ef1edf01b 164 {
destinyXfate 2:0e2ef1edf01b 165 png_warning(png_ptr, "Limiting gamma to 21474.83");
destinyXfate 2:0e2ef1edf01b 166 gamma=21474.83;
destinyXfate 2:0e2ef1edf01b 167 }
destinyXfate 2:0e2ef1edf01b 168 else
destinyXfate 2:0e2ef1edf01b 169 gamma=file_gamma;
destinyXfate 2:0e2ef1edf01b 170 info_ptr->gamma = (float)gamma;
destinyXfate 2:0e2ef1edf01b 171 #ifdef PNG_FIXED_POINT_SUPPORTED
destinyXfate 2:0e2ef1edf01b 172 info_ptr->int_gamma = (int)(gamma*100000.+.5);
destinyXfate 2:0e2ef1edf01b 173 #endif
destinyXfate 2:0e2ef1edf01b 174 info_ptr->valid |= PNG_INFO_gAMA;
destinyXfate 2:0e2ef1edf01b 175 if(gamma == 0.0)
destinyXfate 2:0e2ef1edf01b 176 png_warning(png_ptr, "Setting gamma=0");
destinyXfate 2:0e2ef1edf01b 177 }
destinyXfate 2:0e2ef1edf01b 178 #endif
destinyXfate 2:0e2ef1edf01b 179 void PNGAPI
destinyXfate 2:0e2ef1edf01b 180 png_set_gAMA_fixed(png_structp png_ptr, png_infop info_ptr, png_fixed_point
destinyXfate 2:0e2ef1edf01b 181 int_gamma)
destinyXfate 2:0e2ef1edf01b 182 {
destinyXfate 2:0e2ef1edf01b 183 png_fixed_point gamma;
destinyXfate 2:0e2ef1edf01b 184
destinyXfate 2:0e2ef1edf01b 185 png_debug1(1, "in %s storage function\n", "gAMA");
destinyXfate 2:0e2ef1edf01b 186 if (png_ptr == NULL || info_ptr == NULL)
destinyXfate 2:0e2ef1edf01b 187 return;
destinyXfate 2:0e2ef1edf01b 188
destinyXfate 2:0e2ef1edf01b 189 if (int_gamma > (png_fixed_point) PNG_UINT_31_MAX)
destinyXfate 2:0e2ef1edf01b 190 {
destinyXfate 2:0e2ef1edf01b 191 png_warning(png_ptr, "Limiting gamma to 21474.83");
destinyXfate 2:0e2ef1edf01b 192 gamma=PNG_UINT_31_MAX;
destinyXfate 2:0e2ef1edf01b 193 }
destinyXfate 2:0e2ef1edf01b 194 else
destinyXfate 2:0e2ef1edf01b 195 {
destinyXfate 2:0e2ef1edf01b 196 if (int_gamma < 0)
destinyXfate 2:0e2ef1edf01b 197 {
destinyXfate 2:0e2ef1edf01b 198 png_warning(png_ptr, "Setting negative gamma to zero");
destinyXfate 2:0e2ef1edf01b 199 gamma=0;
destinyXfate 2:0e2ef1edf01b 200 }
destinyXfate 2:0e2ef1edf01b 201 else
destinyXfate 2:0e2ef1edf01b 202 gamma=int_gamma;
destinyXfate 2:0e2ef1edf01b 203 }
destinyXfate 2:0e2ef1edf01b 204 #ifdef PNG_FLOATING_POINT_SUPPORTED
destinyXfate 2:0e2ef1edf01b 205 info_ptr->gamma = (float)(gamma/100000.);
destinyXfate 2:0e2ef1edf01b 206 #endif
destinyXfate 2:0e2ef1edf01b 207 #ifdef PNG_FIXED_POINT_SUPPORTED
destinyXfate 2:0e2ef1edf01b 208 info_ptr->int_gamma = gamma;
destinyXfate 2:0e2ef1edf01b 209 #endif
destinyXfate 2:0e2ef1edf01b 210 info_ptr->valid |= PNG_INFO_gAMA;
destinyXfate 2:0e2ef1edf01b 211 if(gamma == 0)
destinyXfate 2:0e2ef1edf01b 212 png_warning(png_ptr, "Setting gamma=0");
destinyXfate 2:0e2ef1edf01b 213 }
destinyXfate 2:0e2ef1edf01b 214 #endif
destinyXfate 2:0e2ef1edf01b 215
destinyXfate 2:0e2ef1edf01b 216 #if defined(PNG_hIST_SUPPORTED)
destinyXfate 2:0e2ef1edf01b 217 void PNGAPI
destinyXfate 2:0e2ef1edf01b 218 png_set_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p hist)
destinyXfate 2:0e2ef1edf01b 219 {
destinyXfate 2:0e2ef1edf01b 220 int i;
destinyXfate 2:0e2ef1edf01b 221
destinyXfate 2:0e2ef1edf01b 222 png_debug1(1, "in %s storage function\n", "hIST");
destinyXfate 2:0e2ef1edf01b 223 if (png_ptr == NULL || info_ptr == NULL)
destinyXfate 2:0e2ef1edf01b 224 return;
destinyXfate 2:0e2ef1edf01b 225 if (info_ptr->num_palette <= 0 || info_ptr->num_palette
destinyXfate 2:0e2ef1edf01b 226 > PNG_MAX_PALETTE_LENGTH)
destinyXfate 2:0e2ef1edf01b 227 {
destinyXfate 2:0e2ef1edf01b 228 png_warning(png_ptr,
destinyXfate 2:0e2ef1edf01b 229 "Invalid palette size, hIST allocation skipped.");
destinyXfate 2:0e2ef1edf01b 230 return;
destinyXfate 2:0e2ef1edf01b 231 }
destinyXfate 2:0e2ef1edf01b 232
destinyXfate 2:0e2ef1edf01b 233 #ifdef PNG_FREE_ME_SUPPORTED
destinyXfate 2:0e2ef1edf01b 234 png_free_data(png_ptr, info_ptr, PNG_FREE_HIST, 0);
destinyXfate 2:0e2ef1edf01b 235 #endif
destinyXfate 2:0e2ef1edf01b 236 /* Changed from info->num_palette to PNG_MAX_PALETTE_LENGTH in version
destinyXfate 2:0e2ef1edf01b 237 1.2.1 */
destinyXfate 2:0e2ef1edf01b 238 png_ptr->hist = (png_uint_16p)png_malloc_warn(png_ptr,
destinyXfate 2:0e2ef1edf01b 239 (png_uint_32)(PNG_MAX_PALETTE_LENGTH * png_sizeof (png_uint_16)));
destinyXfate 2:0e2ef1edf01b 240 if (png_ptr->hist == NULL)
destinyXfate 2:0e2ef1edf01b 241 {
destinyXfate 2:0e2ef1edf01b 242 png_warning(png_ptr, "Insufficient memory for hIST chunk data.");
destinyXfate 2:0e2ef1edf01b 243 return;
destinyXfate 2:0e2ef1edf01b 244 }
destinyXfate 2:0e2ef1edf01b 245
destinyXfate 2:0e2ef1edf01b 246 for (i = 0; i < info_ptr->num_palette; i++)
destinyXfate 2:0e2ef1edf01b 247 png_ptr->hist[i] = hist[i];
destinyXfate 2:0e2ef1edf01b 248 info_ptr->hist = png_ptr->hist;
destinyXfate 2:0e2ef1edf01b 249 info_ptr->valid |= PNG_INFO_hIST;
destinyXfate 2:0e2ef1edf01b 250
destinyXfate 2:0e2ef1edf01b 251 #ifdef PNG_FREE_ME_SUPPORTED
destinyXfate 2:0e2ef1edf01b 252 info_ptr->free_me |= PNG_FREE_HIST;
destinyXfate 2:0e2ef1edf01b 253 #else
destinyXfate 2:0e2ef1edf01b 254 png_ptr->flags |= PNG_FLAG_FREE_HIST;
destinyXfate 2:0e2ef1edf01b 255 #endif
destinyXfate 2:0e2ef1edf01b 256 }
destinyXfate 2:0e2ef1edf01b 257 #endif
destinyXfate 2:0e2ef1edf01b 258
destinyXfate 2:0e2ef1edf01b 259 void PNGAPI
destinyXfate 2:0e2ef1edf01b 260 png_set_IHDR(png_structp png_ptr, png_infop info_ptr,
destinyXfate 2:0e2ef1edf01b 261 png_uint_32 width, png_uint_32 height, int bit_depth,
destinyXfate 2:0e2ef1edf01b 262 int color_type, int interlace_type, int compression_type,
destinyXfate 2:0e2ef1edf01b 263 int filter_type)
destinyXfate 2:0e2ef1edf01b 264 {
destinyXfate 2:0e2ef1edf01b 265 png_debug1(1, "in %s storage function\n", "IHDR");
destinyXfate 2:0e2ef1edf01b 266 if (png_ptr == NULL || info_ptr == NULL)
destinyXfate 2:0e2ef1edf01b 267 return;
destinyXfate 2:0e2ef1edf01b 268
destinyXfate 2:0e2ef1edf01b 269 /* check for width and height valid values */
destinyXfate 2:0e2ef1edf01b 270 if (width == 0 || height == 0)
destinyXfate 2:0e2ef1edf01b 271 png_error(png_ptr, "Image width or height is zero in IHDR");
destinyXfate 2:0e2ef1edf01b 272 #ifdef PNG_SET_USER_LIMITS_SUPPORTED
destinyXfate 2:0e2ef1edf01b 273 if (width > png_ptr->user_width_max || height > png_ptr->user_height_max)
destinyXfate 2:0e2ef1edf01b 274 png_error(png_ptr, "image size exceeds user limits in IHDR");
destinyXfate 2:0e2ef1edf01b 275 #else
destinyXfate 2:0e2ef1edf01b 276 if (width > PNG_USER_WIDTH_MAX || height > PNG_USER_HEIGHT_MAX)
destinyXfate 2:0e2ef1edf01b 277 png_error(png_ptr, "image size exceeds user limits in IHDR");
destinyXfate 2:0e2ef1edf01b 278 #endif
destinyXfate 2:0e2ef1edf01b 279 if (width > PNG_UINT_31_MAX || height > PNG_UINT_31_MAX)
destinyXfate 2:0e2ef1edf01b 280 png_error(png_ptr, "Invalid image size in IHDR");
destinyXfate 2:0e2ef1edf01b 281 if ( width > (PNG_UINT_32_MAX
destinyXfate 2:0e2ef1edf01b 282 >> 3) /* 8-byte RGBA pixels */
destinyXfate 2:0e2ef1edf01b 283 - 64 /* bigrowbuf hack */
destinyXfate 2:0e2ef1edf01b 284 - 1 /* filter byte */
destinyXfate 2:0e2ef1edf01b 285 - 7*8 /* rounding of width to multiple of 8 pixels */
destinyXfate 2:0e2ef1edf01b 286 - 8) /* extra max_pixel_depth pad */
destinyXfate 2:0e2ef1edf01b 287 png_warning(png_ptr, "Width is too large for libpng to process pixels");
destinyXfate 2:0e2ef1edf01b 288
destinyXfate 2:0e2ef1edf01b 289 /* check other values */
destinyXfate 2:0e2ef1edf01b 290 if (bit_depth != 1 && bit_depth != 2 && bit_depth != 4 &&
destinyXfate 2:0e2ef1edf01b 291 bit_depth != 8 && bit_depth != 16)
destinyXfate 2:0e2ef1edf01b 292 png_error(png_ptr, "Invalid bit depth in IHDR");
destinyXfate 2:0e2ef1edf01b 293
destinyXfate 2:0e2ef1edf01b 294 if (color_type < 0 || color_type == 1 ||
destinyXfate 2:0e2ef1edf01b 295 color_type == 5 || color_type > 6)
destinyXfate 2:0e2ef1edf01b 296 png_error(png_ptr, "Invalid color type in IHDR");
destinyXfate 2:0e2ef1edf01b 297
destinyXfate 2:0e2ef1edf01b 298 if (((color_type == PNG_COLOR_TYPE_PALETTE) && bit_depth > 8) ||
destinyXfate 2:0e2ef1edf01b 299 ((color_type == PNG_COLOR_TYPE_RGB ||
destinyXfate 2:0e2ef1edf01b 300 color_type == PNG_COLOR_TYPE_GRAY_ALPHA ||
destinyXfate 2:0e2ef1edf01b 301 color_type == PNG_COLOR_TYPE_RGB_ALPHA) && bit_depth < 8))
destinyXfate 2:0e2ef1edf01b 302 png_error(png_ptr, "Invalid color type/bit depth combination in IHDR");
destinyXfate 2:0e2ef1edf01b 303
destinyXfate 2:0e2ef1edf01b 304 if (interlace_type >= PNG_INTERLACE_LAST)
destinyXfate 2:0e2ef1edf01b 305 png_error(png_ptr, "Unknown interlace method in IHDR");
destinyXfate 2:0e2ef1edf01b 306
destinyXfate 2:0e2ef1edf01b 307 if (compression_type != PNG_COMPRESSION_TYPE_BASE)
destinyXfate 2:0e2ef1edf01b 308 png_error(png_ptr, "Unknown compression method in IHDR");
destinyXfate 2:0e2ef1edf01b 309
destinyXfate 2:0e2ef1edf01b 310 #if defined(PNG_MNG_FEATURES_SUPPORTED)
destinyXfate 2:0e2ef1edf01b 311 /* Accept filter_method 64 (intrapixel differencing) only if
destinyXfate 2:0e2ef1edf01b 312 * 1. Libpng was compiled with PNG_MNG_FEATURES_SUPPORTED and
destinyXfate 2:0e2ef1edf01b 313 * 2. Libpng did not read a PNG signature (this filter_method is only
destinyXfate 2:0e2ef1edf01b 314 * used in PNG datastreams that are embedded in MNG datastreams) and
destinyXfate 2:0e2ef1edf01b 315 * 3. The application called png_permit_mng_features with a mask that
destinyXfate 2:0e2ef1edf01b 316 * included PNG_FLAG_MNG_FILTER_64 and
destinyXfate 2:0e2ef1edf01b 317 * 4. The filter_method is 64 and
destinyXfate 2:0e2ef1edf01b 318 * 5. The color_type is RGB or RGBA
destinyXfate 2:0e2ef1edf01b 319 */
destinyXfate 2:0e2ef1edf01b 320 if((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)&&png_ptr->mng_features_permitted)
destinyXfate 2:0e2ef1edf01b 321 png_warning(png_ptr,"MNG features are not allowed in a PNG datastream");
destinyXfate 2:0e2ef1edf01b 322 if(filter_type != PNG_FILTER_TYPE_BASE)
destinyXfate 2:0e2ef1edf01b 323 {
destinyXfate 2:0e2ef1edf01b 324 if(!((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
destinyXfate 2:0e2ef1edf01b 325 (filter_type == PNG_INTRAPIXEL_DIFFERENCING) &&
destinyXfate 2:0e2ef1edf01b 326 ((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE) == 0) &&
destinyXfate 2:0e2ef1edf01b 327 (color_type == PNG_COLOR_TYPE_RGB ||
destinyXfate 2:0e2ef1edf01b 328 color_type == PNG_COLOR_TYPE_RGB_ALPHA)))
destinyXfate 2:0e2ef1edf01b 329 png_error(png_ptr, "Unknown filter method in IHDR");
destinyXfate 2:0e2ef1edf01b 330 if(png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)
destinyXfate 2:0e2ef1edf01b 331 png_warning(png_ptr, "Invalid filter method in IHDR");
destinyXfate 2:0e2ef1edf01b 332 }
destinyXfate 2:0e2ef1edf01b 333 #else
destinyXfate 2:0e2ef1edf01b 334 if(filter_type != PNG_FILTER_TYPE_BASE)
destinyXfate 2:0e2ef1edf01b 335 png_error(png_ptr, "Unknown filter method in IHDR");
destinyXfate 2:0e2ef1edf01b 336 #endif
destinyXfate 2:0e2ef1edf01b 337
destinyXfate 2:0e2ef1edf01b 338 info_ptr->width = width;
destinyXfate 2:0e2ef1edf01b 339 info_ptr->height = height;
destinyXfate 2:0e2ef1edf01b 340 info_ptr->bit_depth = (png_byte)bit_depth;
destinyXfate 2:0e2ef1edf01b 341 info_ptr->color_type =(png_byte) color_type;
destinyXfate 2:0e2ef1edf01b 342 info_ptr->compression_type = (png_byte)compression_type;
destinyXfate 2:0e2ef1edf01b 343 info_ptr->filter_type = (png_byte)filter_type;
destinyXfate 2:0e2ef1edf01b 344 info_ptr->interlace_type = (png_byte)interlace_type;
destinyXfate 2:0e2ef1edf01b 345 if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
destinyXfate 2:0e2ef1edf01b 346 info_ptr->channels = 1;
destinyXfate 2:0e2ef1edf01b 347 else if (info_ptr->color_type & PNG_COLOR_MASK_COLOR)
destinyXfate 2:0e2ef1edf01b 348 info_ptr->channels = 3;
destinyXfate 2:0e2ef1edf01b 349 else
destinyXfate 2:0e2ef1edf01b 350 info_ptr->channels = 1;
destinyXfate 2:0e2ef1edf01b 351 if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA)
destinyXfate 2:0e2ef1edf01b 352 info_ptr->channels++;
destinyXfate 2:0e2ef1edf01b 353 info_ptr->pixel_depth = (png_byte)(info_ptr->channels * info_ptr->bit_depth);
destinyXfate 2:0e2ef1edf01b 354
destinyXfate 2:0e2ef1edf01b 355 /* check for potential overflow */
destinyXfate 2:0e2ef1edf01b 356 if ( width > (PNG_UINT_32_MAX
destinyXfate 2:0e2ef1edf01b 357 >> 3) /* 8-byte RGBA pixels */
destinyXfate 2:0e2ef1edf01b 358 - 64 /* bigrowbuf hack */
destinyXfate 2:0e2ef1edf01b 359 - 1 /* filter byte */
destinyXfate 2:0e2ef1edf01b 360 - 7*8 /* rounding of width to multiple of 8 pixels */
destinyXfate 2:0e2ef1edf01b 361 - 8) /* extra max_pixel_depth pad */
destinyXfate 2:0e2ef1edf01b 362 info_ptr->rowbytes = (png_size_t)0;
destinyXfate 2:0e2ef1edf01b 363 else
destinyXfate 2:0e2ef1edf01b 364 info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth,width);
destinyXfate 2:0e2ef1edf01b 365 }
destinyXfate 2:0e2ef1edf01b 366
destinyXfate 2:0e2ef1edf01b 367 #if defined(PNG_oFFs_SUPPORTED)
destinyXfate 2:0e2ef1edf01b 368 void PNGAPI
destinyXfate 2:0e2ef1edf01b 369 png_set_oFFs(png_structp png_ptr, png_infop info_ptr,
destinyXfate 2:0e2ef1edf01b 370 png_int_32 offset_x, png_int_32 offset_y, int unit_type)
destinyXfate 2:0e2ef1edf01b 371 {
destinyXfate 2:0e2ef1edf01b 372 png_debug1(1, "in %s storage function\n", "oFFs");
destinyXfate 2:0e2ef1edf01b 373 if (png_ptr == NULL || info_ptr == NULL)
destinyXfate 2:0e2ef1edf01b 374 return;
destinyXfate 2:0e2ef1edf01b 375
destinyXfate 2:0e2ef1edf01b 376 info_ptr->x_offset = offset_x;
destinyXfate 2:0e2ef1edf01b 377 info_ptr->y_offset = offset_y;
destinyXfate 2:0e2ef1edf01b 378 info_ptr->offset_unit_type = (png_byte)unit_type;
destinyXfate 2:0e2ef1edf01b 379 info_ptr->valid |= PNG_INFO_oFFs;
destinyXfate 2:0e2ef1edf01b 380 }
destinyXfate 2:0e2ef1edf01b 381 #endif
destinyXfate 2:0e2ef1edf01b 382
destinyXfate 2:0e2ef1edf01b 383 #if defined(PNG_pCAL_SUPPORTED)
destinyXfate 2:0e2ef1edf01b 384 void PNGAPI
destinyXfate 2:0e2ef1edf01b 385 png_set_pCAL(png_structp png_ptr, png_infop info_ptr,
destinyXfate 2:0e2ef1edf01b 386 png_charp purpose, png_int_32 X0, png_int_32 X1, int type, int nparams,
destinyXfate 2:0e2ef1edf01b 387 png_charp units, png_charpp params)
destinyXfate 2:0e2ef1edf01b 388 {
destinyXfate 2:0e2ef1edf01b 389 png_uint_32 length;
destinyXfate 2:0e2ef1edf01b 390 int i;
destinyXfate 2:0e2ef1edf01b 391
destinyXfate 2:0e2ef1edf01b 392 png_debug1(1, "in %s storage function\n", "pCAL");
destinyXfate 2:0e2ef1edf01b 393 if (png_ptr == NULL || info_ptr == NULL)
destinyXfate 2:0e2ef1edf01b 394 return;
destinyXfate 2:0e2ef1edf01b 395
destinyXfate 2:0e2ef1edf01b 396 length = png_strlen(purpose) + 1;
destinyXfate 2:0e2ef1edf01b 397 png_debug1(3, "allocating purpose for info (%lu bytes)\n", length);
destinyXfate 2:0e2ef1edf01b 398 info_ptr->pcal_purpose = (png_charp)png_malloc_warn(png_ptr, length);
destinyXfate 2:0e2ef1edf01b 399 if (info_ptr->pcal_purpose == NULL)
destinyXfate 2:0e2ef1edf01b 400 {
destinyXfate 2:0e2ef1edf01b 401 png_warning(png_ptr, "Insufficient memory for pCAL purpose.");
destinyXfate 2:0e2ef1edf01b 402 return;
destinyXfate 2:0e2ef1edf01b 403 }
destinyXfate 2:0e2ef1edf01b 404 png_memcpy(info_ptr->pcal_purpose, purpose, (png_size_t)length);
destinyXfate 2:0e2ef1edf01b 405
destinyXfate 2:0e2ef1edf01b 406 png_debug(3, "storing X0, X1, type, and nparams in info\n");
destinyXfate 2:0e2ef1edf01b 407 info_ptr->pcal_X0 = X0;
destinyXfate 2:0e2ef1edf01b 408 info_ptr->pcal_X1 = X1;
destinyXfate 2:0e2ef1edf01b 409 info_ptr->pcal_type = (png_byte)type;
destinyXfate 2:0e2ef1edf01b 410 info_ptr->pcal_nparams = (png_byte)nparams;
destinyXfate 2:0e2ef1edf01b 411
destinyXfate 2:0e2ef1edf01b 412 length = png_strlen(units) + 1;
destinyXfate 2:0e2ef1edf01b 413 png_debug1(3, "allocating units for info (%lu bytes)\n", length);
destinyXfate 2:0e2ef1edf01b 414 info_ptr->pcal_units = (png_charp)png_malloc_warn(png_ptr, length);
destinyXfate 2:0e2ef1edf01b 415 if (info_ptr->pcal_units == NULL)
destinyXfate 2:0e2ef1edf01b 416 {
destinyXfate 2:0e2ef1edf01b 417 png_warning(png_ptr, "Insufficient memory for pCAL units.");
destinyXfate 2:0e2ef1edf01b 418 return;
destinyXfate 2:0e2ef1edf01b 419 }
destinyXfate 2:0e2ef1edf01b 420 png_memcpy(info_ptr->pcal_units, units, (png_size_t)length);
destinyXfate 2:0e2ef1edf01b 421
destinyXfate 2:0e2ef1edf01b 422 info_ptr->pcal_params = (png_charpp)png_malloc_warn(png_ptr,
destinyXfate 2:0e2ef1edf01b 423 (png_uint_32)((nparams + 1) * png_sizeof(png_charp)));
destinyXfate 2:0e2ef1edf01b 424 if (info_ptr->pcal_params == NULL)
destinyXfate 2:0e2ef1edf01b 425 {
destinyXfate 2:0e2ef1edf01b 426 png_warning(png_ptr, "Insufficient memory for pCAL params.");
destinyXfate 2:0e2ef1edf01b 427 return;
destinyXfate 2:0e2ef1edf01b 428 }
destinyXfate 2:0e2ef1edf01b 429
destinyXfate 2:0e2ef1edf01b 430 info_ptr->pcal_params[nparams] = NULL;
destinyXfate 2:0e2ef1edf01b 431
destinyXfate 2:0e2ef1edf01b 432 for (i = 0; i < nparams; i++)
destinyXfate 2:0e2ef1edf01b 433 {
destinyXfate 2:0e2ef1edf01b 434 length = png_strlen(params[i]) + 1;
destinyXfate 2:0e2ef1edf01b 435 png_debug2(3, "allocating parameter %d for info (%lu bytes)\n", i, length);
destinyXfate 2:0e2ef1edf01b 436 info_ptr->pcal_params[i] = (png_charp)png_malloc_warn(png_ptr, length);
destinyXfate 2:0e2ef1edf01b 437 if (info_ptr->pcal_params[i] == NULL)
destinyXfate 2:0e2ef1edf01b 438 {
destinyXfate 2:0e2ef1edf01b 439 png_warning(png_ptr, "Insufficient memory for pCAL parameter.");
destinyXfate 2:0e2ef1edf01b 440 return;
destinyXfate 2:0e2ef1edf01b 441 }
destinyXfate 2:0e2ef1edf01b 442 png_memcpy(info_ptr->pcal_params[i], params[i], (png_size_t)length);
destinyXfate 2:0e2ef1edf01b 443 }
destinyXfate 2:0e2ef1edf01b 444
destinyXfate 2:0e2ef1edf01b 445 info_ptr->valid |= PNG_INFO_pCAL;
destinyXfate 2:0e2ef1edf01b 446 #ifdef PNG_FREE_ME_SUPPORTED
destinyXfate 2:0e2ef1edf01b 447 info_ptr->free_me |= PNG_FREE_PCAL;
destinyXfate 2:0e2ef1edf01b 448 #endif
destinyXfate 2:0e2ef1edf01b 449 }
destinyXfate 2:0e2ef1edf01b 450 #endif
destinyXfate 2:0e2ef1edf01b 451
destinyXfate 2:0e2ef1edf01b 452 #if defined(PNG_READ_sCAL_SUPPORTED) || defined(PNG_WRITE_sCAL_SUPPORTED)
destinyXfate 2:0e2ef1edf01b 453 #ifdef PNG_FLOATING_POINT_SUPPORTED
destinyXfate 2:0e2ef1edf01b 454 void PNGAPI
destinyXfate 2:0e2ef1edf01b 455 png_set_sCAL(png_structp png_ptr, png_infop info_ptr,
destinyXfate 2:0e2ef1edf01b 456 int unit, double width, double height)
destinyXfate 2:0e2ef1edf01b 457 {
destinyXfate 2:0e2ef1edf01b 458 png_debug1(1, "in %s storage function\n", "sCAL");
destinyXfate 2:0e2ef1edf01b 459 if (png_ptr == NULL || info_ptr == NULL)
destinyXfate 2:0e2ef1edf01b 460 return;
destinyXfate 2:0e2ef1edf01b 461
destinyXfate 2:0e2ef1edf01b 462 info_ptr->scal_unit = (png_byte)unit;
destinyXfate 2:0e2ef1edf01b 463 info_ptr->scal_pixel_width = width;
destinyXfate 2:0e2ef1edf01b 464 info_ptr->scal_pixel_height = height;
destinyXfate 2:0e2ef1edf01b 465
destinyXfate 2:0e2ef1edf01b 466 info_ptr->valid |= PNG_INFO_sCAL;
destinyXfate 2:0e2ef1edf01b 467 }
destinyXfate 2:0e2ef1edf01b 468 #else
destinyXfate 2:0e2ef1edf01b 469 #ifdef PNG_FIXED_POINT_SUPPORTED
destinyXfate 2:0e2ef1edf01b 470 void PNGAPI
destinyXfate 2:0e2ef1edf01b 471 png_set_sCAL_s(png_structp png_ptr, png_infop info_ptr,
destinyXfate 2:0e2ef1edf01b 472 int unit, png_charp swidth, png_charp sheight)
destinyXfate 2:0e2ef1edf01b 473 {
destinyXfate 2:0e2ef1edf01b 474 png_uint_32 length;
destinyXfate 2:0e2ef1edf01b 475
destinyXfate 2:0e2ef1edf01b 476 png_debug1(1, "in %s storage function\n", "sCAL");
destinyXfate 2:0e2ef1edf01b 477 if (png_ptr == NULL || info_ptr == NULL)
destinyXfate 2:0e2ef1edf01b 478 return;
destinyXfate 2:0e2ef1edf01b 479
destinyXfate 2:0e2ef1edf01b 480 info_ptr->scal_unit = (png_byte)unit;
destinyXfate 2:0e2ef1edf01b 481
destinyXfate 2:0e2ef1edf01b 482 length = png_strlen(swidth) + 1;
destinyXfate 2:0e2ef1edf01b 483 png_debug1(3, "allocating unit for info (%d bytes)\n", length);
destinyXfate 2:0e2ef1edf01b 484 info_ptr->scal_s_width = (png_charp)png_malloc_warn(png_ptr, length);
destinyXfate 2:0e2ef1edf01b 485 if (info_ptr->scal_s_width == NULL)
destinyXfate 2:0e2ef1edf01b 486 {
destinyXfate 2:0e2ef1edf01b 487 png_warning(png_ptr, "Memory allocation failed while processing sCAL.");
destinyXfate 2:0e2ef1edf01b 488 }
destinyXfate 2:0e2ef1edf01b 489 png_memcpy(info_ptr->scal_s_width, swidth, (png_size_t)length);
destinyXfate 2:0e2ef1edf01b 490
destinyXfate 2:0e2ef1edf01b 491 length = png_strlen(sheight) + 1;
destinyXfate 2:0e2ef1edf01b 492 png_debug1(3, "allocating unit for info (%d bytes)\n", length);
destinyXfate 2:0e2ef1edf01b 493 info_ptr->scal_s_height = (png_charp)png_malloc_warn(png_ptr, length);
destinyXfate 2:0e2ef1edf01b 494 if (info_ptr->scal_s_height == NULL)
destinyXfate 2:0e2ef1edf01b 495 {
destinyXfate 2:0e2ef1edf01b 496 png_free (png_ptr, info_ptr->scal_s_width);
destinyXfate 2:0e2ef1edf01b 497 png_warning(png_ptr, "Memory allocation failed while processing sCAL.");
destinyXfate 2:0e2ef1edf01b 498 }
destinyXfate 2:0e2ef1edf01b 499 png_memcpy(info_ptr->scal_s_height, sheight, (png_size_t)length);
destinyXfate 2:0e2ef1edf01b 500
destinyXfate 2:0e2ef1edf01b 501 info_ptr->valid |= PNG_INFO_sCAL;
destinyXfate 2:0e2ef1edf01b 502 #ifdef PNG_FREE_ME_SUPPORTED
destinyXfate 2:0e2ef1edf01b 503 info_ptr->free_me |= PNG_FREE_SCAL;
destinyXfate 2:0e2ef1edf01b 504 #endif
destinyXfate 2:0e2ef1edf01b 505 }
destinyXfate 2:0e2ef1edf01b 506 #endif
destinyXfate 2:0e2ef1edf01b 507 #endif
destinyXfate 2:0e2ef1edf01b 508 #endif
destinyXfate 2:0e2ef1edf01b 509
destinyXfate 2:0e2ef1edf01b 510 #if defined(PNG_pHYs_SUPPORTED)
destinyXfate 2:0e2ef1edf01b 511 void PNGAPI
destinyXfate 2:0e2ef1edf01b 512 png_set_pHYs(png_structp png_ptr, png_infop info_ptr,
destinyXfate 2:0e2ef1edf01b 513 png_uint_32 res_x, png_uint_32 res_y, int unit_type)
destinyXfate 2:0e2ef1edf01b 514 {
destinyXfate 2:0e2ef1edf01b 515 png_debug1(1, "in %s storage function\n", "pHYs");
destinyXfate 2:0e2ef1edf01b 516 if (png_ptr == NULL || info_ptr == NULL)
destinyXfate 2:0e2ef1edf01b 517 return;
destinyXfate 2:0e2ef1edf01b 518
destinyXfate 2:0e2ef1edf01b 519 info_ptr->x_pixels_per_unit = res_x;
destinyXfate 2:0e2ef1edf01b 520 info_ptr->y_pixels_per_unit = res_y;
destinyXfate 2:0e2ef1edf01b 521 info_ptr->phys_unit_type = (png_byte)unit_type;
destinyXfate 2:0e2ef1edf01b 522 info_ptr->valid |= PNG_INFO_pHYs;
destinyXfate 2:0e2ef1edf01b 523 }
destinyXfate 2:0e2ef1edf01b 524 #endif
destinyXfate 2:0e2ef1edf01b 525
destinyXfate 2:0e2ef1edf01b 526 void PNGAPI
destinyXfate 2:0e2ef1edf01b 527 png_set_PLTE(png_structp png_ptr, png_infop info_ptr,
destinyXfate 2:0e2ef1edf01b 528 png_colorp palette, int num_palette)
destinyXfate 2:0e2ef1edf01b 529 {
destinyXfate 2:0e2ef1edf01b 530
destinyXfate 2:0e2ef1edf01b 531 png_debug1(1, "in %s storage function\n", "PLTE");
destinyXfate 2:0e2ef1edf01b 532 if (png_ptr == NULL || info_ptr == NULL)
destinyXfate 2:0e2ef1edf01b 533 return;
destinyXfate 2:0e2ef1edf01b 534
destinyXfate 2:0e2ef1edf01b 535 if (num_palette < 0 || num_palette > PNG_MAX_PALETTE_LENGTH)
destinyXfate 2:0e2ef1edf01b 536 {
destinyXfate 2:0e2ef1edf01b 537 if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
destinyXfate 2:0e2ef1edf01b 538 png_error(png_ptr, "Invalid palette length");
destinyXfate 2:0e2ef1edf01b 539 else
destinyXfate 2:0e2ef1edf01b 540 {
destinyXfate 2:0e2ef1edf01b 541 png_warning(png_ptr, "Invalid palette length");
destinyXfate 2:0e2ef1edf01b 542 return;
destinyXfate 2:0e2ef1edf01b 543 }
destinyXfate 2:0e2ef1edf01b 544 }
destinyXfate 2:0e2ef1edf01b 545
destinyXfate 2:0e2ef1edf01b 546 /*
destinyXfate 2:0e2ef1edf01b 547 * It may not actually be necessary to set png_ptr->palette here;
destinyXfate 2:0e2ef1edf01b 548 * we do it for backward compatibility with the way the png_handle_tRNS
destinyXfate 2:0e2ef1edf01b 549 * function used to do the allocation.
destinyXfate 2:0e2ef1edf01b 550 */
destinyXfate 2:0e2ef1edf01b 551 #ifdef PNG_FREE_ME_SUPPORTED
destinyXfate 2:0e2ef1edf01b 552 png_free_data(png_ptr, info_ptr, PNG_FREE_PLTE, 0);
destinyXfate 2:0e2ef1edf01b 553 #endif
destinyXfate 2:0e2ef1edf01b 554
destinyXfate 2:0e2ef1edf01b 555 /* Changed in libpng-1.2.1 to allocate PNG_MAX_PALETTE_LENGTH instead
destinyXfate 2:0e2ef1edf01b 556 of num_palette entries,
destinyXfate 2:0e2ef1edf01b 557 in case of an invalid PNG file that has too-large sample values. */
destinyXfate 2:0e2ef1edf01b 558 png_ptr->palette = (png_colorp)png_malloc(png_ptr,
destinyXfate 2:0e2ef1edf01b 559 PNG_MAX_PALETTE_LENGTH * png_sizeof(png_color));
destinyXfate 2:0e2ef1edf01b 560 png_memset(png_ptr->palette, 0, PNG_MAX_PALETTE_LENGTH *
destinyXfate 2:0e2ef1edf01b 561 png_sizeof(png_color));
destinyXfate 2:0e2ef1edf01b 562 png_memcpy(png_ptr->palette, palette, num_palette * png_sizeof (png_color));
destinyXfate 2:0e2ef1edf01b 563 info_ptr->palette = png_ptr->palette;
destinyXfate 2:0e2ef1edf01b 564 info_ptr->num_palette = png_ptr->num_palette = (png_uint_16)num_palette;
destinyXfate 2:0e2ef1edf01b 565
destinyXfate 2:0e2ef1edf01b 566 #ifdef PNG_FREE_ME_SUPPORTED
destinyXfate 2:0e2ef1edf01b 567 info_ptr->free_me |= PNG_FREE_PLTE;
destinyXfate 2:0e2ef1edf01b 568 #else
destinyXfate 2:0e2ef1edf01b 569 png_ptr->flags |= PNG_FLAG_FREE_PLTE;
destinyXfate 2:0e2ef1edf01b 570 #endif
destinyXfate 2:0e2ef1edf01b 571
destinyXfate 2:0e2ef1edf01b 572 info_ptr->valid |= PNG_INFO_PLTE;
destinyXfate 2:0e2ef1edf01b 573 }
destinyXfate 2:0e2ef1edf01b 574
destinyXfate 2:0e2ef1edf01b 575 #if defined(PNG_sBIT_SUPPORTED)
destinyXfate 2:0e2ef1edf01b 576 void PNGAPI
destinyXfate 2:0e2ef1edf01b 577 png_set_sBIT(png_structp png_ptr, png_infop info_ptr,
destinyXfate 2:0e2ef1edf01b 578 png_color_8p sig_bit)
destinyXfate 2:0e2ef1edf01b 579 {
destinyXfate 2:0e2ef1edf01b 580 png_debug1(1, "in %s storage function\n", "sBIT");
destinyXfate 2:0e2ef1edf01b 581 if (png_ptr == NULL || info_ptr == NULL)
destinyXfate 2:0e2ef1edf01b 582 return;
destinyXfate 2:0e2ef1edf01b 583
destinyXfate 2:0e2ef1edf01b 584 png_memcpy(&(info_ptr->sig_bit), sig_bit, png_sizeof (png_color_8));
destinyXfate 2:0e2ef1edf01b 585 info_ptr->valid |= PNG_INFO_sBIT;
destinyXfate 2:0e2ef1edf01b 586 }
destinyXfate 2:0e2ef1edf01b 587 #endif
destinyXfate 2:0e2ef1edf01b 588
destinyXfate 2:0e2ef1edf01b 589 #if defined(PNG_sRGB_SUPPORTED)
destinyXfate 2:0e2ef1edf01b 590 void PNGAPI
destinyXfate 2:0e2ef1edf01b 591 png_set_sRGB(png_structp png_ptr, png_infop info_ptr, int intent)
destinyXfate 2:0e2ef1edf01b 592 {
destinyXfate 2:0e2ef1edf01b 593 png_debug1(1, "in %s storage function\n", "sRGB");
destinyXfate 2:0e2ef1edf01b 594 if (png_ptr == NULL || info_ptr == NULL)
destinyXfate 2:0e2ef1edf01b 595 return;
destinyXfate 2:0e2ef1edf01b 596
destinyXfate 2:0e2ef1edf01b 597 info_ptr->srgb_intent = (png_byte)intent;
destinyXfate 2:0e2ef1edf01b 598 info_ptr->valid |= PNG_INFO_sRGB;
destinyXfate 2:0e2ef1edf01b 599 }
destinyXfate 2:0e2ef1edf01b 600
destinyXfate 2:0e2ef1edf01b 601 void PNGAPI
destinyXfate 2:0e2ef1edf01b 602 png_set_sRGB_gAMA_and_cHRM(png_structp png_ptr, png_infop info_ptr,
destinyXfate 2:0e2ef1edf01b 603 int intent)
destinyXfate 2:0e2ef1edf01b 604 {
destinyXfate 2:0e2ef1edf01b 605 #if defined(PNG_gAMA_SUPPORTED)
destinyXfate 2:0e2ef1edf01b 606 #ifdef PNG_FLOATING_POINT_SUPPORTED
destinyXfate 2:0e2ef1edf01b 607 float file_gamma;
destinyXfate 2:0e2ef1edf01b 608 #endif
destinyXfate 2:0e2ef1edf01b 609 #ifdef PNG_FIXED_POINT_SUPPORTED
destinyXfate 2:0e2ef1edf01b 610 png_fixed_point int_file_gamma;
destinyXfate 2:0e2ef1edf01b 611 #endif
destinyXfate 2:0e2ef1edf01b 612 #endif
destinyXfate 2:0e2ef1edf01b 613 #if defined(PNG_cHRM_SUPPORTED)
destinyXfate 2:0e2ef1edf01b 614 #ifdef PNG_FLOATING_POINT_SUPPORTED
destinyXfate 2:0e2ef1edf01b 615 float white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y;
destinyXfate 2:0e2ef1edf01b 616 #endif
destinyXfate 2:0e2ef1edf01b 617 #ifdef PNG_FIXED_POINT_SUPPORTED
destinyXfate 2:0e2ef1edf01b 618 png_fixed_point int_white_x, int_white_y, int_red_x, int_red_y, int_green_x,
destinyXfate 2:0e2ef1edf01b 619 int_green_y, int_blue_x, int_blue_y;
destinyXfate 2:0e2ef1edf01b 620 #endif
destinyXfate 2:0e2ef1edf01b 621 #endif
destinyXfate 2:0e2ef1edf01b 622 png_debug1(1, "in %s storage function\n", "sRGB_gAMA_and_cHRM");
destinyXfate 2:0e2ef1edf01b 623 if (png_ptr == NULL || info_ptr == NULL)
destinyXfate 2:0e2ef1edf01b 624 return;
destinyXfate 2:0e2ef1edf01b 625
destinyXfate 2:0e2ef1edf01b 626 png_set_sRGB(png_ptr, info_ptr, intent);
destinyXfate 2:0e2ef1edf01b 627
destinyXfate 2:0e2ef1edf01b 628 #if defined(PNG_gAMA_SUPPORTED)
destinyXfate 2:0e2ef1edf01b 629 #ifdef PNG_FLOATING_POINT_SUPPORTED
destinyXfate 2:0e2ef1edf01b 630 file_gamma = (float).45455;
destinyXfate 2:0e2ef1edf01b 631 png_set_gAMA(png_ptr, info_ptr, file_gamma);
destinyXfate 2:0e2ef1edf01b 632 #endif
destinyXfate 2:0e2ef1edf01b 633 #ifdef PNG_FIXED_POINT_SUPPORTED
destinyXfate 2:0e2ef1edf01b 634 int_file_gamma = 45455L;
destinyXfate 2:0e2ef1edf01b 635 png_set_gAMA_fixed(png_ptr, info_ptr, int_file_gamma);
destinyXfate 2:0e2ef1edf01b 636 #endif
destinyXfate 2:0e2ef1edf01b 637 #endif
destinyXfate 2:0e2ef1edf01b 638
destinyXfate 2:0e2ef1edf01b 639 #if defined(PNG_cHRM_SUPPORTED)
destinyXfate 2:0e2ef1edf01b 640 #ifdef PNG_FIXED_POINT_SUPPORTED
destinyXfate 2:0e2ef1edf01b 641 int_white_x = 31270L;
destinyXfate 2:0e2ef1edf01b 642 int_white_y = 32900L;
destinyXfate 2:0e2ef1edf01b 643 int_red_x = 64000L;
destinyXfate 2:0e2ef1edf01b 644 int_red_y = 33000L;
destinyXfate 2:0e2ef1edf01b 645 int_green_x = 30000L;
destinyXfate 2:0e2ef1edf01b 646 int_green_y = 60000L;
destinyXfate 2:0e2ef1edf01b 647 int_blue_x = 15000L;
destinyXfate 2:0e2ef1edf01b 648 int_blue_y = 6000L;
destinyXfate 2:0e2ef1edf01b 649
destinyXfate 2:0e2ef1edf01b 650 png_set_cHRM_fixed(png_ptr, info_ptr,
destinyXfate 2:0e2ef1edf01b 651 int_white_x, int_white_y, int_red_x, int_red_y, int_green_x, int_green_y,
destinyXfate 2:0e2ef1edf01b 652 int_blue_x, int_blue_y);
destinyXfate 2:0e2ef1edf01b 653 #endif
destinyXfate 2:0e2ef1edf01b 654 #ifdef PNG_FLOATING_POINT_SUPPORTED
destinyXfate 2:0e2ef1edf01b 655 white_x = (float).3127;
destinyXfate 2:0e2ef1edf01b 656 white_y = (float).3290;
destinyXfate 2:0e2ef1edf01b 657 red_x = (float).64;
destinyXfate 2:0e2ef1edf01b 658 red_y = (float).33;
destinyXfate 2:0e2ef1edf01b 659 green_x = (float).30;
destinyXfate 2:0e2ef1edf01b 660 green_y = (float).60;
destinyXfate 2:0e2ef1edf01b 661 blue_x = (float).15;
destinyXfate 2:0e2ef1edf01b 662 blue_y = (float).06;
destinyXfate 2:0e2ef1edf01b 663
destinyXfate 2:0e2ef1edf01b 664 png_set_cHRM(png_ptr, info_ptr,
destinyXfate 2:0e2ef1edf01b 665 white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y);
destinyXfate 2:0e2ef1edf01b 666 #endif
destinyXfate 2:0e2ef1edf01b 667 #endif
destinyXfate 2:0e2ef1edf01b 668 }
destinyXfate 2:0e2ef1edf01b 669 #endif
destinyXfate 2:0e2ef1edf01b 670
destinyXfate 2:0e2ef1edf01b 671
destinyXfate 2:0e2ef1edf01b 672 #if defined(PNG_iCCP_SUPPORTED)
destinyXfate 2:0e2ef1edf01b 673 void PNGAPI
destinyXfate 2:0e2ef1edf01b 674 png_set_iCCP(png_structp png_ptr, png_infop info_ptr,
destinyXfate 2:0e2ef1edf01b 675 png_charp name, int compression_type,
destinyXfate 2:0e2ef1edf01b 676 png_charp profile, png_uint_32 proflen)
destinyXfate 2:0e2ef1edf01b 677 {
destinyXfate 2:0e2ef1edf01b 678 png_charp new_iccp_name;
destinyXfate 2:0e2ef1edf01b 679 png_charp new_iccp_profile;
destinyXfate 2:0e2ef1edf01b 680
destinyXfate 2:0e2ef1edf01b 681 png_debug1(1, "in %s storage function\n", "iCCP");
destinyXfate 2:0e2ef1edf01b 682 if (png_ptr == NULL || info_ptr == NULL || name == NULL || profile == NULL)
destinyXfate 2:0e2ef1edf01b 683 return;
destinyXfate 2:0e2ef1edf01b 684
destinyXfate 2:0e2ef1edf01b 685 new_iccp_name = (png_charp)png_malloc_warn(png_ptr, png_strlen(name)+1);
destinyXfate 2:0e2ef1edf01b 686 if (new_iccp_name == NULL)
destinyXfate 2:0e2ef1edf01b 687 {
destinyXfate 2:0e2ef1edf01b 688 png_warning(png_ptr, "Insufficient memory to process iCCP chunk.");
destinyXfate 2:0e2ef1edf01b 689 return;
destinyXfate 2:0e2ef1edf01b 690 }
destinyXfate 2:0e2ef1edf01b 691 png_strcpy(new_iccp_name, name);
destinyXfate 2:0e2ef1edf01b 692 new_iccp_profile = (png_charp)png_malloc_warn(png_ptr, proflen);
destinyXfate 2:0e2ef1edf01b 693 if (new_iccp_profile == NULL)
destinyXfate 2:0e2ef1edf01b 694 {
destinyXfate 2:0e2ef1edf01b 695 png_free (png_ptr, new_iccp_name);
destinyXfate 2:0e2ef1edf01b 696 png_warning(png_ptr, "Insufficient memory to process iCCP profile.");
destinyXfate 2:0e2ef1edf01b 697 return;
destinyXfate 2:0e2ef1edf01b 698 }
destinyXfate 2:0e2ef1edf01b 699 png_memcpy(new_iccp_profile, profile, (png_size_t)proflen);
destinyXfate 2:0e2ef1edf01b 700
destinyXfate 2:0e2ef1edf01b 701 png_free_data(png_ptr, info_ptr, PNG_FREE_ICCP, 0);
destinyXfate 2:0e2ef1edf01b 702
destinyXfate 2:0e2ef1edf01b 703 info_ptr->iccp_proflen = proflen;
destinyXfate 2:0e2ef1edf01b 704 info_ptr->iccp_name = new_iccp_name;
destinyXfate 2:0e2ef1edf01b 705 info_ptr->iccp_profile = new_iccp_profile;
destinyXfate 2:0e2ef1edf01b 706 /* Compression is always zero but is here so the API and info structure
destinyXfate 2:0e2ef1edf01b 707 * does not have to change if we introduce multiple compression types */
destinyXfate 2:0e2ef1edf01b 708 info_ptr->iccp_compression = (png_byte)compression_type;
destinyXfate 2:0e2ef1edf01b 709 #ifdef PNG_FREE_ME_SUPPORTED
destinyXfate 2:0e2ef1edf01b 710 info_ptr->free_me |= PNG_FREE_ICCP;
destinyXfate 2:0e2ef1edf01b 711 #endif
destinyXfate 2:0e2ef1edf01b 712 info_ptr->valid |= PNG_INFO_iCCP;
destinyXfate 2:0e2ef1edf01b 713 }
destinyXfate 2:0e2ef1edf01b 714 #endif
destinyXfate 2:0e2ef1edf01b 715
destinyXfate 2:0e2ef1edf01b 716 #if defined(PNG_TEXT_SUPPORTED)
destinyXfate 2:0e2ef1edf01b 717 void PNGAPI
destinyXfate 2:0e2ef1edf01b 718 png_set_text(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
destinyXfate 2:0e2ef1edf01b 719 int num_text)
destinyXfate 2:0e2ef1edf01b 720 {
destinyXfate 2:0e2ef1edf01b 721 int ret;
destinyXfate 2:0e2ef1edf01b 722 ret=png_set_text_2(png_ptr, info_ptr, text_ptr, num_text);
destinyXfate 2:0e2ef1edf01b 723 if (ret)
destinyXfate 2:0e2ef1edf01b 724 png_error(png_ptr, "Insufficient memory to store text");
destinyXfate 2:0e2ef1edf01b 725 }
destinyXfate 2:0e2ef1edf01b 726
destinyXfate 2:0e2ef1edf01b 727 int /* PRIVATE */
destinyXfate 2:0e2ef1edf01b 728 png_set_text_2(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
destinyXfate 2:0e2ef1edf01b 729 int num_text)
destinyXfate 2:0e2ef1edf01b 730 {
destinyXfate 2:0e2ef1edf01b 731 int i;
destinyXfate 2:0e2ef1edf01b 732
destinyXfate 2:0e2ef1edf01b 733 png_debug1(1, "in %s storage function\n", (png_ptr->chunk_name[0] == '\0' ?
destinyXfate 2:0e2ef1edf01b 734 "text" : (png_const_charp)png_ptr->chunk_name));
destinyXfate 2:0e2ef1edf01b 735
destinyXfate 2:0e2ef1edf01b 736 if (png_ptr == NULL || info_ptr == NULL || num_text == 0)
destinyXfate 2:0e2ef1edf01b 737 return(0);
destinyXfate 2:0e2ef1edf01b 738
destinyXfate 2:0e2ef1edf01b 739 /* Make sure we have enough space in the "text" array in info_struct
destinyXfate 2:0e2ef1edf01b 740 * to hold all of the incoming text_ptr objects.
destinyXfate 2:0e2ef1edf01b 741 */
destinyXfate 2:0e2ef1edf01b 742 if (info_ptr->num_text + num_text > info_ptr->max_text)
destinyXfate 2:0e2ef1edf01b 743 {
destinyXfate 2:0e2ef1edf01b 744 if (info_ptr->text != NULL)
destinyXfate 2:0e2ef1edf01b 745 {
destinyXfate 2:0e2ef1edf01b 746 png_textp old_text;
destinyXfate 2:0e2ef1edf01b 747 int old_max;
destinyXfate 2:0e2ef1edf01b 748
destinyXfate 2:0e2ef1edf01b 749 old_max = info_ptr->max_text;
destinyXfate 2:0e2ef1edf01b 750 info_ptr->max_text = info_ptr->num_text + num_text + 8;
destinyXfate 2:0e2ef1edf01b 751 old_text = info_ptr->text;
destinyXfate 2:0e2ef1edf01b 752 info_ptr->text = (png_textp)png_malloc_warn(png_ptr,
destinyXfate 2:0e2ef1edf01b 753 (png_uint_32)(info_ptr->max_text * png_sizeof (png_text)));
destinyXfate 2:0e2ef1edf01b 754 if (info_ptr->text == NULL)
destinyXfate 2:0e2ef1edf01b 755 {
destinyXfate 2:0e2ef1edf01b 756 png_free(png_ptr, old_text);
destinyXfate 2:0e2ef1edf01b 757 return(1);
destinyXfate 2:0e2ef1edf01b 758 }
destinyXfate 2:0e2ef1edf01b 759 png_memcpy(info_ptr->text, old_text, (png_size_t)(old_max *
destinyXfate 2:0e2ef1edf01b 760 png_sizeof(png_text)));
destinyXfate 2:0e2ef1edf01b 761 png_free(png_ptr, old_text);
destinyXfate 2:0e2ef1edf01b 762 }
destinyXfate 2:0e2ef1edf01b 763 else
destinyXfate 2:0e2ef1edf01b 764 {
destinyXfate 2:0e2ef1edf01b 765 info_ptr->max_text = num_text + 8;
destinyXfate 2:0e2ef1edf01b 766 info_ptr->num_text = 0;
destinyXfate 2:0e2ef1edf01b 767 info_ptr->text = (png_textp)png_malloc_warn(png_ptr,
destinyXfate 2:0e2ef1edf01b 768 (png_uint_32)(info_ptr->max_text * png_sizeof (png_text)));
destinyXfate 2:0e2ef1edf01b 769 if (info_ptr->text == NULL)
destinyXfate 2:0e2ef1edf01b 770 return(1);
destinyXfate 2:0e2ef1edf01b 771 #ifdef PNG_FREE_ME_SUPPORTED
destinyXfate 2:0e2ef1edf01b 772 info_ptr->free_me |= PNG_FREE_TEXT;
destinyXfate 2:0e2ef1edf01b 773 #endif
destinyXfate 2:0e2ef1edf01b 774 }
destinyXfate 2:0e2ef1edf01b 775 png_debug1(3, "allocated %d entries for info_ptr->text\n",
destinyXfate 2:0e2ef1edf01b 776 info_ptr->max_text);
destinyXfate 2:0e2ef1edf01b 777 }
destinyXfate 2:0e2ef1edf01b 778 for (i = 0; i < num_text; i++)
destinyXfate 2:0e2ef1edf01b 779 {
destinyXfate 2:0e2ef1edf01b 780 png_size_t text_length,key_len;
destinyXfate 2:0e2ef1edf01b 781 png_size_t lang_len,lang_key_len;
destinyXfate 2:0e2ef1edf01b 782 png_textp textp = &(info_ptr->text[info_ptr->num_text]);
destinyXfate 2:0e2ef1edf01b 783
destinyXfate 2:0e2ef1edf01b 784 if (text_ptr[i].key == NULL)
destinyXfate 2:0e2ef1edf01b 785 continue;
destinyXfate 2:0e2ef1edf01b 786
destinyXfate 2:0e2ef1edf01b 787 key_len = png_strlen(text_ptr[i].key);
destinyXfate 2:0e2ef1edf01b 788
destinyXfate 2:0e2ef1edf01b 789 if(text_ptr[i].compression <= 0)
destinyXfate 2:0e2ef1edf01b 790 {
destinyXfate 2:0e2ef1edf01b 791 lang_len = 0;
destinyXfate 2:0e2ef1edf01b 792 lang_key_len = 0;
destinyXfate 2:0e2ef1edf01b 793 }
destinyXfate 2:0e2ef1edf01b 794 else
destinyXfate 2:0e2ef1edf01b 795 #ifdef PNG_iTXt_SUPPORTED
destinyXfate 2:0e2ef1edf01b 796 {
destinyXfate 2:0e2ef1edf01b 797 /* set iTXt data */
destinyXfate 2:0e2ef1edf01b 798 if (text_ptr[i].lang != NULL)
destinyXfate 2:0e2ef1edf01b 799 lang_len = png_strlen(text_ptr[i].lang);
destinyXfate 2:0e2ef1edf01b 800 else
destinyXfate 2:0e2ef1edf01b 801 lang_len = 0;
destinyXfate 2:0e2ef1edf01b 802 if (text_ptr[i].lang_key != NULL)
destinyXfate 2:0e2ef1edf01b 803 lang_key_len = png_strlen(text_ptr[i].lang_key);
destinyXfate 2:0e2ef1edf01b 804 else
destinyXfate 2:0e2ef1edf01b 805 lang_key_len = 0;
destinyXfate 2:0e2ef1edf01b 806 }
destinyXfate 2:0e2ef1edf01b 807 #else
destinyXfate 2:0e2ef1edf01b 808 {
destinyXfate 2:0e2ef1edf01b 809 png_warning(png_ptr, "iTXt chunk not supported.");
destinyXfate 2:0e2ef1edf01b 810 continue;
destinyXfate 2:0e2ef1edf01b 811 }
destinyXfate 2:0e2ef1edf01b 812 #endif
destinyXfate 2:0e2ef1edf01b 813
destinyXfate 2:0e2ef1edf01b 814 if (text_ptr[i].text == NULL || text_ptr[i].text[0] == '\0')
destinyXfate 2:0e2ef1edf01b 815 {
destinyXfate 2:0e2ef1edf01b 816 text_length = 0;
destinyXfate 2:0e2ef1edf01b 817 #ifdef PNG_iTXt_SUPPORTED
destinyXfate 2:0e2ef1edf01b 818 if(text_ptr[i].compression > 0)
destinyXfate 2:0e2ef1edf01b 819 textp->compression = PNG_ITXT_COMPRESSION_NONE;
destinyXfate 2:0e2ef1edf01b 820 else
destinyXfate 2:0e2ef1edf01b 821 #endif
destinyXfate 2:0e2ef1edf01b 822 textp->compression = PNG_TEXT_COMPRESSION_NONE;
destinyXfate 2:0e2ef1edf01b 823 }
destinyXfate 2:0e2ef1edf01b 824 else
destinyXfate 2:0e2ef1edf01b 825 {
destinyXfate 2:0e2ef1edf01b 826 text_length = png_strlen(text_ptr[i].text);
destinyXfate 2:0e2ef1edf01b 827 textp->compression = text_ptr[i].compression;
destinyXfate 2:0e2ef1edf01b 828 }
destinyXfate 2:0e2ef1edf01b 829
destinyXfate 2:0e2ef1edf01b 830 textp->key = (png_charp)png_malloc_warn(png_ptr,
destinyXfate 2:0e2ef1edf01b 831 (png_uint_32)(key_len + text_length + lang_len + lang_key_len + 4));
destinyXfate 2:0e2ef1edf01b 832 if (textp->key == NULL)
destinyXfate 2:0e2ef1edf01b 833 return(1);
destinyXfate 2:0e2ef1edf01b 834 png_debug2(2, "Allocated %lu bytes at %x in png_set_text\n",
destinyXfate 2:0e2ef1edf01b 835 (png_uint_32)(key_len + lang_len + lang_key_len + text_length + 4),
destinyXfate 2:0e2ef1edf01b 836 (int)textp->key);
destinyXfate 2:0e2ef1edf01b 837
destinyXfate 2:0e2ef1edf01b 838 png_memcpy(textp->key, text_ptr[i].key,
destinyXfate 2:0e2ef1edf01b 839 (png_size_t)(key_len));
destinyXfate 2:0e2ef1edf01b 840 *(textp->key+key_len) = '\0';
destinyXfate 2:0e2ef1edf01b 841 #ifdef PNG_iTXt_SUPPORTED
destinyXfate 2:0e2ef1edf01b 842 if (text_ptr[i].compression > 0)
destinyXfate 2:0e2ef1edf01b 843 {
destinyXfate 2:0e2ef1edf01b 844 textp->lang=textp->key + key_len + 1;
destinyXfate 2:0e2ef1edf01b 845 png_memcpy(textp->lang, text_ptr[i].lang, lang_len);
destinyXfate 2:0e2ef1edf01b 846 *(textp->lang+lang_len) = '\0';
destinyXfate 2:0e2ef1edf01b 847 textp->lang_key=textp->lang + lang_len + 1;
destinyXfate 2:0e2ef1edf01b 848 png_memcpy(textp->lang_key, text_ptr[i].lang_key, lang_key_len);
destinyXfate 2:0e2ef1edf01b 849 *(textp->lang_key+lang_key_len) = '\0';
destinyXfate 2:0e2ef1edf01b 850 textp->text=textp->lang_key + lang_key_len + 1;
destinyXfate 2:0e2ef1edf01b 851 }
destinyXfate 2:0e2ef1edf01b 852 else
destinyXfate 2:0e2ef1edf01b 853 #endif
destinyXfate 2:0e2ef1edf01b 854 {
destinyXfate 2:0e2ef1edf01b 855 #ifdef PNG_iTXt_SUPPORTED
destinyXfate 2:0e2ef1edf01b 856 textp->lang=NULL;
destinyXfate 2:0e2ef1edf01b 857 textp->lang_key=NULL;
destinyXfate 2:0e2ef1edf01b 858 #endif
destinyXfate 2:0e2ef1edf01b 859 textp->text=textp->key + key_len + 1;
destinyXfate 2:0e2ef1edf01b 860 }
destinyXfate 2:0e2ef1edf01b 861 if(text_length)
destinyXfate 2:0e2ef1edf01b 862 png_memcpy(textp->text, text_ptr[i].text,
destinyXfate 2:0e2ef1edf01b 863 (png_size_t)(text_length));
destinyXfate 2:0e2ef1edf01b 864 *(textp->text+text_length) = '\0';
destinyXfate 2:0e2ef1edf01b 865
destinyXfate 2:0e2ef1edf01b 866 #ifdef PNG_iTXt_SUPPORTED
destinyXfate 2:0e2ef1edf01b 867 if(textp->compression > 0)
destinyXfate 2:0e2ef1edf01b 868 {
destinyXfate 2:0e2ef1edf01b 869 textp->text_length = 0;
destinyXfate 2:0e2ef1edf01b 870 textp->itxt_length = text_length;
destinyXfate 2:0e2ef1edf01b 871 }
destinyXfate 2:0e2ef1edf01b 872 else
destinyXfate 2:0e2ef1edf01b 873 #endif
destinyXfate 2:0e2ef1edf01b 874 {
destinyXfate 2:0e2ef1edf01b 875 textp->text_length = text_length;
destinyXfate 2:0e2ef1edf01b 876 #ifdef PNG_iTXt_SUPPORTED
destinyXfate 2:0e2ef1edf01b 877 textp->itxt_length = 0;
destinyXfate 2:0e2ef1edf01b 878 #endif
destinyXfate 2:0e2ef1edf01b 879 }
destinyXfate 2:0e2ef1edf01b 880 info_ptr->text[info_ptr->num_text]= *textp;
destinyXfate 2:0e2ef1edf01b 881 info_ptr->num_text++;
destinyXfate 2:0e2ef1edf01b 882 png_debug1(3, "transferred text chunk %d\n", info_ptr->num_text);
destinyXfate 2:0e2ef1edf01b 883 }
destinyXfate 2:0e2ef1edf01b 884 return(0);
destinyXfate 2:0e2ef1edf01b 885 }
destinyXfate 2:0e2ef1edf01b 886 #endif
destinyXfate 2:0e2ef1edf01b 887
destinyXfate 2:0e2ef1edf01b 888 #if defined(PNG_tIME_SUPPORTED)
destinyXfate 2:0e2ef1edf01b 889 void PNGAPI
destinyXfate 2:0e2ef1edf01b 890 png_set_tIME(png_structp png_ptr, png_infop info_ptr, png_timep mod_time)
destinyXfate 2:0e2ef1edf01b 891 {
destinyXfate 2:0e2ef1edf01b 892 png_debug1(1, "in %s storage function\n", "tIME");
destinyXfate 2:0e2ef1edf01b 893 if (png_ptr == NULL || info_ptr == NULL ||
destinyXfate 2:0e2ef1edf01b 894 (png_ptr->mode & PNG_WROTE_tIME))
destinyXfate 2:0e2ef1edf01b 895 return;
destinyXfate 2:0e2ef1edf01b 896
destinyXfate 2:0e2ef1edf01b 897 png_memcpy(&(info_ptr->mod_time), mod_time, png_sizeof (png_time));
destinyXfate 2:0e2ef1edf01b 898 info_ptr->valid |= PNG_INFO_tIME;
destinyXfate 2:0e2ef1edf01b 899 }
destinyXfate 2:0e2ef1edf01b 900 #endif
destinyXfate 2:0e2ef1edf01b 901
destinyXfate 2:0e2ef1edf01b 902 #if defined(PNG_tRNS_SUPPORTED)
destinyXfate 2:0e2ef1edf01b 903 void PNGAPI
destinyXfate 2:0e2ef1edf01b 904 png_set_tRNS(png_structp png_ptr, png_infop info_ptr,
destinyXfate 2:0e2ef1edf01b 905 png_bytep trans, int num_trans, png_color_16p trans_values)
destinyXfate 2:0e2ef1edf01b 906 {
destinyXfate 2:0e2ef1edf01b 907 png_debug1(1, "in %s storage function\n", "tRNS");
destinyXfate 2:0e2ef1edf01b 908 if (png_ptr == NULL || info_ptr == NULL)
destinyXfate 2:0e2ef1edf01b 909 return;
destinyXfate 2:0e2ef1edf01b 910
destinyXfate 2:0e2ef1edf01b 911 if (trans != NULL)
destinyXfate 2:0e2ef1edf01b 912 {
destinyXfate 2:0e2ef1edf01b 913 /*
destinyXfate 2:0e2ef1edf01b 914 * It may not actually be necessary to set png_ptr->trans here;
destinyXfate 2:0e2ef1edf01b 915 * we do it for backward compatibility with the way the png_handle_tRNS
destinyXfate 2:0e2ef1edf01b 916 * function used to do the allocation.
destinyXfate 2:0e2ef1edf01b 917 */
destinyXfate 2:0e2ef1edf01b 918 #ifdef PNG_FREE_ME_SUPPORTED
destinyXfate 2:0e2ef1edf01b 919 png_free_data(png_ptr, info_ptr, PNG_FREE_TRNS, 0);
destinyXfate 2:0e2ef1edf01b 920 #endif
destinyXfate 2:0e2ef1edf01b 921 /* Changed from num_trans to PNG_MAX_PALETTE_LENGTH in version 1.2.1 */
destinyXfate 2:0e2ef1edf01b 922 png_ptr->trans = info_ptr->trans = (png_bytep)png_malloc(png_ptr,
destinyXfate 2:0e2ef1edf01b 923 (png_uint_32)PNG_MAX_PALETTE_LENGTH);
destinyXfate 2:0e2ef1edf01b 924 if (num_trans <= PNG_MAX_PALETTE_LENGTH)
destinyXfate 2:0e2ef1edf01b 925 png_memcpy(info_ptr->trans, trans, (png_size_t)num_trans);
destinyXfate 2:0e2ef1edf01b 926 #ifdef PNG_FREE_ME_SUPPORTED
destinyXfate 2:0e2ef1edf01b 927 info_ptr->free_me |= PNG_FREE_TRNS;
destinyXfate 2:0e2ef1edf01b 928 #else
destinyXfate 2:0e2ef1edf01b 929 png_ptr->flags |= PNG_FLAG_FREE_TRNS;
destinyXfate 2:0e2ef1edf01b 930 #endif
destinyXfate 2:0e2ef1edf01b 931 }
destinyXfate 2:0e2ef1edf01b 932
destinyXfate 2:0e2ef1edf01b 933 if (trans_values != NULL)
destinyXfate 2:0e2ef1edf01b 934 {
destinyXfate 2:0e2ef1edf01b 935 png_memcpy(&(info_ptr->trans_values), trans_values,
destinyXfate 2:0e2ef1edf01b 936 png_sizeof(png_color_16));
destinyXfate 2:0e2ef1edf01b 937 if (num_trans == 0)
destinyXfate 2:0e2ef1edf01b 938 num_trans = 1;
destinyXfate 2:0e2ef1edf01b 939 }
destinyXfate 2:0e2ef1edf01b 940 info_ptr->num_trans = (png_uint_16)num_trans;
destinyXfate 2:0e2ef1edf01b 941 info_ptr->valid |= PNG_INFO_tRNS;
destinyXfate 2:0e2ef1edf01b 942 }
destinyXfate 2:0e2ef1edf01b 943 #endif
destinyXfate 2:0e2ef1edf01b 944
destinyXfate 2:0e2ef1edf01b 945 #if defined(PNG_sPLT_SUPPORTED)
destinyXfate 2:0e2ef1edf01b 946 void PNGAPI
destinyXfate 2:0e2ef1edf01b 947 png_set_sPLT(png_structp png_ptr,
destinyXfate 2:0e2ef1edf01b 948 png_infop info_ptr, png_sPLT_tp entries, int nentries)
destinyXfate 2:0e2ef1edf01b 949 {
destinyXfate 2:0e2ef1edf01b 950 png_sPLT_tp np;
destinyXfate 2:0e2ef1edf01b 951 int i;
destinyXfate 2:0e2ef1edf01b 952
destinyXfate 2:0e2ef1edf01b 953 if (png_ptr == NULL || info_ptr == NULL)
destinyXfate 2:0e2ef1edf01b 954 return;
destinyXfate 2:0e2ef1edf01b 955
destinyXfate 2:0e2ef1edf01b 956 np = (png_sPLT_tp)png_malloc_warn(png_ptr,
destinyXfate 2:0e2ef1edf01b 957 (info_ptr->splt_palettes_num + nentries) * png_sizeof(png_sPLT_t));
destinyXfate 2:0e2ef1edf01b 958 if (np == NULL)
destinyXfate 2:0e2ef1edf01b 959 {
destinyXfate 2:0e2ef1edf01b 960 png_warning(png_ptr, "No memory for sPLT palettes.");
destinyXfate 2:0e2ef1edf01b 961 return;
destinyXfate 2:0e2ef1edf01b 962 }
destinyXfate 2:0e2ef1edf01b 963
destinyXfate 2:0e2ef1edf01b 964 png_memcpy(np, info_ptr->splt_palettes,
destinyXfate 2:0e2ef1edf01b 965 info_ptr->splt_palettes_num * png_sizeof(png_sPLT_t));
destinyXfate 2:0e2ef1edf01b 966 png_free(png_ptr, info_ptr->splt_palettes);
destinyXfate 2:0e2ef1edf01b 967 info_ptr->splt_palettes=NULL;
destinyXfate 2:0e2ef1edf01b 968
destinyXfate 2:0e2ef1edf01b 969 for (i = 0; i < nentries; i++)
destinyXfate 2:0e2ef1edf01b 970 {
destinyXfate 2:0e2ef1edf01b 971 png_sPLT_tp to = np + info_ptr->splt_palettes_num + i;
destinyXfate 2:0e2ef1edf01b 972 png_sPLT_tp from = entries + i;
destinyXfate 2:0e2ef1edf01b 973
destinyXfate 2:0e2ef1edf01b 974 to->name = (png_charp)png_malloc(png_ptr,
destinyXfate 2:0e2ef1edf01b 975 png_strlen(from->name) + 1);
destinyXfate 2:0e2ef1edf01b 976 /* TODO: use png_malloc_warn */
destinyXfate 2:0e2ef1edf01b 977 png_strcpy(to->name, from->name);
destinyXfate 2:0e2ef1edf01b 978 to->entries = (png_sPLT_entryp)png_malloc(png_ptr,
destinyXfate 2:0e2ef1edf01b 979 from->nentries * png_sizeof(png_sPLT_entry));
destinyXfate 2:0e2ef1edf01b 980 /* TODO: use png_malloc_warn */
destinyXfate 2:0e2ef1edf01b 981 png_memcpy(to->entries, from->entries,
destinyXfate 2:0e2ef1edf01b 982 from->nentries * png_sizeof(png_sPLT_entry));
destinyXfate 2:0e2ef1edf01b 983 to->nentries = from->nentries;
destinyXfate 2:0e2ef1edf01b 984 to->depth = from->depth;
destinyXfate 2:0e2ef1edf01b 985 }
destinyXfate 2:0e2ef1edf01b 986
destinyXfate 2:0e2ef1edf01b 987 info_ptr->splt_palettes = np;
destinyXfate 2:0e2ef1edf01b 988 info_ptr->splt_palettes_num += nentries;
destinyXfate 2:0e2ef1edf01b 989 info_ptr->valid |= PNG_INFO_sPLT;
destinyXfate 2:0e2ef1edf01b 990 #ifdef PNG_FREE_ME_SUPPORTED
destinyXfate 2:0e2ef1edf01b 991 info_ptr->free_me |= PNG_FREE_SPLT;
destinyXfate 2:0e2ef1edf01b 992 #endif
destinyXfate 2:0e2ef1edf01b 993 }
destinyXfate 2:0e2ef1edf01b 994 #endif /* PNG_sPLT_SUPPORTED */
destinyXfate 2:0e2ef1edf01b 995
destinyXfate 2:0e2ef1edf01b 996 #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
destinyXfate 2:0e2ef1edf01b 997 void PNGAPI
destinyXfate 2:0e2ef1edf01b 998 png_set_unknown_chunks(png_structp png_ptr,
destinyXfate 2:0e2ef1edf01b 999 png_infop info_ptr, png_unknown_chunkp unknowns, int num_unknowns)
destinyXfate 2:0e2ef1edf01b 1000 {
destinyXfate 2:0e2ef1edf01b 1001 png_unknown_chunkp np;
destinyXfate 2:0e2ef1edf01b 1002 int i;
destinyXfate 2:0e2ef1edf01b 1003
destinyXfate 2:0e2ef1edf01b 1004 if (png_ptr == NULL || info_ptr == NULL || num_unknowns == 0)
destinyXfate 2:0e2ef1edf01b 1005 return;
destinyXfate 2:0e2ef1edf01b 1006
destinyXfate 2:0e2ef1edf01b 1007 np = (png_unknown_chunkp)png_malloc_warn(png_ptr,
destinyXfate 2:0e2ef1edf01b 1008 (info_ptr->unknown_chunks_num + num_unknowns) *
destinyXfate 2:0e2ef1edf01b 1009 png_sizeof(png_unknown_chunk));
destinyXfate 2:0e2ef1edf01b 1010 if (np == NULL)
destinyXfate 2:0e2ef1edf01b 1011 {
destinyXfate 2:0e2ef1edf01b 1012 png_warning(png_ptr, "Out of memory while processing unknown chunk.");
destinyXfate 2:0e2ef1edf01b 1013 return;
destinyXfate 2:0e2ef1edf01b 1014 }
destinyXfate 2:0e2ef1edf01b 1015
destinyXfate 2:0e2ef1edf01b 1016 png_memcpy(np, info_ptr->unknown_chunks,
destinyXfate 2:0e2ef1edf01b 1017 info_ptr->unknown_chunks_num * png_sizeof(png_unknown_chunk));
destinyXfate 2:0e2ef1edf01b 1018 png_free(png_ptr, info_ptr->unknown_chunks);
destinyXfate 2:0e2ef1edf01b 1019 info_ptr->unknown_chunks=NULL;
destinyXfate 2:0e2ef1edf01b 1020
destinyXfate 2:0e2ef1edf01b 1021 for (i = 0; i < num_unknowns; i++)
destinyXfate 2:0e2ef1edf01b 1022 {
destinyXfate 2:0e2ef1edf01b 1023 png_unknown_chunkp to = np + info_ptr->unknown_chunks_num + i;
destinyXfate 2:0e2ef1edf01b 1024 png_unknown_chunkp from = unknowns + i;
destinyXfate 2:0e2ef1edf01b 1025
destinyXfate 2:0e2ef1edf01b 1026 png_strncpy((png_charp)to->name, (png_charp)from->name, 5);
destinyXfate 2:0e2ef1edf01b 1027 to->data = (png_bytep)png_malloc_warn(png_ptr, from->size);
destinyXfate 2:0e2ef1edf01b 1028 if (to->data == NULL)
destinyXfate 2:0e2ef1edf01b 1029 {
destinyXfate 2:0e2ef1edf01b 1030 png_warning(png_ptr, "Out of memory processing unknown chunk.");
destinyXfate 2:0e2ef1edf01b 1031 }
destinyXfate 2:0e2ef1edf01b 1032 else
destinyXfate 2:0e2ef1edf01b 1033 {
destinyXfate 2:0e2ef1edf01b 1034 png_memcpy(to->data, from->data, from->size);
destinyXfate 2:0e2ef1edf01b 1035 to->size = from->size;
destinyXfate 2:0e2ef1edf01b 1036
destinyXfate 2:0e2ef1edf01b 1037 /* note our location in the read or write sequence */
destinyXfate 2:0e2ef1edf01b 1038 to->location = (png_byte)(png_ptr->mode & 0xff);
destinyXfate 2:0e2ef1edf01b 1039 }
destinyXfate 2:0e2ef1edf01b 1040 }
destinyXfate 2:0e2ef1edf01b 1041
destinyXfate 2:0e2ef1edf01b 1042 info_ptr->unknown_chunks = np;
destinyXfate 2:0e2ef1edf01b 1043 info_ptr->unknown_chunks_num += num_unknowns;
destinyXfate 2:0e2ef1edf01b 1044 #ifdef PNG_FREE_ME_SUPPORTED
destinyXfate 2:0e2ef1edf01b 1045 info_ptr->free_me |= PNG_FREE_UNKN;
destinyXfate 2:0e2ef1edf01b 1046 #endif
destinyXfate 2:0e2ef1edf01b 1047 }
destinyXfate 2:0e2ef1edf01b 1048 void PNGAPI
destinyXfate 2:0e2ef1edf01b 1049 png_set_unknown_chunk_location(png_structp png_ptr, png_infop info_ptr,
destinyXfate 2:0e2ef1edf01b 1050 int chunk, int location)
destinyXfate 2:0e2ef1edf01b 1051 {
destinyXfate 2:0e2ef1edf01b 1052 if(png_ptr != NULL && info_ptr != NULL && chunk >= 0 && chunk <
destinyXfate 2:0e2ef1edf01b 1053 (int)info_ptr->unknown_chunks_num)
destinyXfate 2:0e2ef1edf01b 1054 info_ptr->unknown_chunks[chunk].location = (png_byte)location;
destinyXfate 2:0e2ef1edf01b 1055 }
destinyXfate 2:0e2ef1edf01b 1056 #endif
destinyXfate 2:0e2ef1edf01b 1057
destinyXfate 2:0e2ef1edf01b 1058 #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
destinyXfate 2:0e2ef1edf01b 1059 #if defined(PNG_READ_EMPTY_PLTE_SUPPORTED) || \
destinyXfate 2:0e2ef1edf01b 1060 defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED)
destinyXfate 2:0e2ef1edf01b 1061 void PNGAPI
destinyXfate 2:0e2ef1edf01b 1062 png_permit_empty_plte (png_structp png_ptr, int empty_plte_permitted)
destinyXfate 2:0e2ef1edf01b 1063 {
destinyXfate 2:0e2ef1edf01b 1064 /* This function is deprecated in favor of png_permit_mng_features()
destinyXfate 2:0e2ef1edf01b 1065 and will be removed from libpng-1.3.0 */
destinyXfate 2:0e2ef1edf01b 1066 png_debug(1, "in png_permit_empty_plte, DEPRECATED.\n");
destinyXfate 2:0e2ef1edf01b 1067 if (png_ptr == NULL)
destinyXfate 2:0e2ef1edf01b 1068 return;
destinyXfate 2:0e2ef1edf01b 1069 png_ptr->mng_features_permitted = (png_byte)
destinyXfate 2:0e2ef1edf01b 1070 ((png_ptr->mng_features_permitted & (~(PNG_FLAG_MNG_EMPTY_PLTE))) |
destinyXfate 2:0e2ef1edf01b 1071 ((empty_plte_permitted & PNG_FLAG_MNG_EMPTY_PLTE)));
destinyXfate 2:0e2ef1edf01b 1072 }
destinyXfate 2:0e2ef1edf01b 1073 #endif
destinyXfate 2:0e2ef1edf01b 1074 #endif
destinyXfate 2:0e2ef1edf01b 1075
destinyXfate 2:0e2ef1edf01b 1076 #if defined(PNG_MNG_FEATURES_SUPPORTED)
destinyXfate 2:0e2ef1edf01b 1077 png_uint_32 PNGAPI
destinyXfate 2:0e2ef1edf01b 1078 png_permit_mng_features (png_structp png_ptr, png_uint_32 mng_features)
destinyXfate 2:0e2ef1edf01b 1079 {
destinyXfate 2:0e2ef1edf01b 1080 png_debug(1, "in png_permit_mng_features\n");
destinyXfate 2:0e2ef1edf01b 1081 if (png_ptr == NULL)
destinyXfate 2:0e2ef1edf01b 1082 return (png_uint_32)0;
destinyXfate 2:0e2ef1edf01b 1083 png_ptr->mng_features_permitted =
destinyXfate 2:0e2ef1edf01b 1084 (png_byte)(mng_features & PNG_ALL_MNG_FEATURES);
destinyXfate 2:0e2ef1edf01b 1085 return (png_uint_32)png_ptr->mng_features_permitted;
destinyXfate 2:0e2ef1edf01b 1086 }
destinyXfate 2:0e2ef1edf01b 1087 #endif
destinyXfate 2:0e2ef1edf01b 1088
destinyXfate 2:0e2ef1edf01b 1089 #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
destinyXfate 2:0e2ef1edf01b 1090 void PNGAPI
destinyXfate 2:0e2ef1edf01b 1091 png_set_keep_unknown_chunks(png_structp png_ptr, int keep, png_bytep
destinyXfate 2:0e2ef1edf01b 1092 chunk_list, int num_chunks)
destinyXfate 2:0e2ef1edf01b 1093 {
destinyXfate 2:0e2ef1edf01b 1094 png_bytep new_list, p;
destinyXfate 2:0e2ef1edf01b 1095 int i, old_num_chunks;
destinyXfate 2:0e2ef1edf01b 1096 if (png_ptr == NULL)
destinyXfate 2:0e2ef1edf01b 1097 return;
destinyXfate 2:0e2ef1edf01b 1098 if (num_chunks == 0)
destinyXfate 2:0e2ef1edf01b 1099 {
destinyXfate 2:0e2ef1edf01b 1100 if(keep == PNG_HANDLE_CHUNK_ALWAYS || keep == PNG_HANDLE_CHUNK_IF_SAFE)
destinyXfate 2:0e2ef1edf01b 1101 png_ptr->flags |= PNG_FLAG_KEEP_UNKNOWN_CHUNKS;
destinyXfate 2:0e2ef1edf01b 1102 else
destinyXfate 2:0e2ef1edf01b 1103 png_ptr->flags &= ~PNG_FLAG_KEEP_UNKNOWN_CHUNKS;
destinyXfate 2:0e2ef1edf01b 1104
destinyXfate 2:0e2ef1edf01b 1105 if(keep == PNG_HANDLE_CHUNK_ALWAYS)
destinyXfate 2:0e2ef1edf01b 1106 png_ptr->flags |= PNG_FLAG_KEEP_UNSAFE_CHUNKS;
destinyXfate 2:0e2ef1edf01b 1107 else
destinyXfate 2:0e2ef1edf01b 1108 png_ptr->flags &= ~PNG_FLAG_KEEP_UNSAFE_CHUNKS;
destinyXfate 2:0e2ef1edf01b 1109 return;
destinyXfate 2:0e2ef1edf01b 1110 }
destinyXfate 2:0e2ef1edf01b 1111 if (chunk_list == NULL)
destinyXfate 2:0e2ef1edf01b 1112 return;
destinyXfate 2:0e2ef1edf01b 1113 old_num_chunks=png_ptr->num_chunk_list;
destinyXfate 2:0e2ef1edf01b 1114 new_list=(png_bytep)png_malloc(png_ptr,
destinyXfate 2:0e2ef1edf01b 1115 (png_uint_32)(5*(num_chunks+old_num_chunks)));
destinyXfate 2:0e2ef1edf01b 1116 if(png_ptr->chunk_list != NULL)
destinyXfate 2:0e2ef1edf01b 1117 {
destinyXfate 2:0e2ef1edf01b 1118 png_memcpy(new_list, png_ptr->chunk_list,
destinyXfate 2:0e2ef1edf01b 1119 (png_size_t)(5*old_num_chunks));
destinyXfate 2:0e2ef1edf01b 1120 png_free(png_ptr, png_ptr->chunk_list);
destinyXfate 2:0e2ef1edf01b 1121 png_ptr->chunk_list=NULL;
destinyXfate 2:0e2ef1edf01b 1122 }
destinyXfate 2:0e2ef1edf01b 1123 png_memcpy(new_list+5*old_num_chunks, chunk_list,
destinyXfate 2:0e2ef1edf01b 1124 (png_size_t)(5*num_chunks));
destinyXfate 2:0e2ef1edf01b 1125 for (p=new_list+5*old_num_chunks+4, i=0; i<num_chunks; i++, p+=5)
destinyXfate 2:0e2ef1edf01b 1126 *p=(png_byte)keep;
destinyXfate 2:0e2ef1edf01b 1127 png_ptr->num_chunk_list=old_num_chunks+num_chunks;
destinyXfate 2:0e2ef1edf01b 1128 png_ptr->chunk_list=new_list;
destinyXfate 2:0e2ef1edf01b 1129 #ifdef PNG_FREE_ME_SUPPORTED
destinyXfate 2:0e2ef1edf01b 1130 png_ptr->free_me |= PNG_FREE_LIST;
destinyXfate 2:0e2ef1edf01b 1131 #endif
destinyXfate 2:0e2ef1edf01b 1132 }
destinyXfate 2:0e2ef1edf01b 1133 #endif
destinyXfate 2:0e2ef1edf01b 1134
destinyXfate 2:0e2ef1edf01b 1135 #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
destinyXfate 2:0e2ef1edf01b 1136 void PNGAPI
destinyXfate 2:0e2ef1edf01b 1137 png_set_read_user_chunk_fn(png_structp png_ptr, png_voidp user_chunk_ptr,
destinyXfate 2:0e2ef1edf01b 1138 png_user_chunk_ptr read_user_chunk_fn)
destinyXfate 2:0e2ef1edf01b 1139 {
destinyXfate 2:0e2ef1edf01b 1140 png_debug(1, "in png_set_read_user_chunk_fn\n");
destinyXfate 2:0e2ef1edf01b 1141 if (png_ptr == NULL)
destinyXfate 2:0e2ef1edf01b 1142 return;
destinyXfate 2:0e2ef1edf01b 1143 png_ptr->read_user_chunk_fn = read_user_chunk_fn;
destinyXfate 2:0e2ef1edf01b 1144 png_ptr->user_chunk_ptr = user_chunk_ptr;
destinyXfate 2:0e2ef1edf01b 1145 }
destinyXfate 2:0e2ef1edf01b 1146 #endif
destinyXfate 2:0e2ef1edf01b 1147
destinyXfate 2:0e2ef1edf01b 1148 #if defined(PNG_INFO_IMAGE_SUPPORTED)
destinyXfate 2:0e2ef1edf01b 1149 void PNGAPI
destinyXfate 2:0e2ef1edf01b 1150 png_set_rows(png_structp png_ptr, png_infop info_ptr, png_bytepp row_pointers)
destinyXfate 2:0e2ef1edf01b 1151 {
destinyXfate 2:0e2ef1edf01b 1152 png_debug1(1, "in %s storage function\n", "rows");
destinyXfate 2:0e2ef1edf01b 1153
destinyXfate 2:0e2ef1edf01b 1154 if (png_ptr == NULL || info_ptr == NULL)
destinyXfate 2:0e2ef1edf01b 1155 return;
destinyXfate 2:0e2ef1edf01b 1156
destinyXfate 2:0e2ef1edf01b 1157 if(info_ptr->row_pointers && (info_ptr->row_pointers != row_pointers))
destinyXfate 2:0e2ef1edf01b 1158 png_free_data(png_ptr, info_ptr, PNG_FREE_ROWS, 0);
destinyXfate 2:0e2ef1edf01b 1159 info_ptr->row_pointers = row_pointers;
destinyXfate 2:0e2ef1edf01b 1160 if(row_pointers)
destinyXfate 2:0e2ef1edf01b 1161 info_ptr->valid |= PNG_INFO_IDAT;
destinyXfate 2:0e2ef1edf01b 1162 }
destinyXfate 2:0e2ef1edf01b 1163 #endif
destinyXfate 2:0e2ef1edf01b 1164
destinyXfate 2:0e2ef1edf01b 1165 #ifdef PNG_WRITE_SUPPORTED
destinyXfate 2:0e2ef1edf01b 1166 void PNGAPI
destinyXfate 2:0e2ef1edf01b 1167 png_set_compression_buffer_size(png_structp png_ptr, png_uint_32 size)
destinyXfate 2:0e2ef1edf01b 1168 {
destinyXfate 2:0e2ef1edf01b 1169 if (png_ptr == NULL)
destinyXfate 2:0e2ef1edf01b 1170 return;
destinyXfate 2:0e2ef1edf01b 1171 if(png_ptr->zbuf)
destinyXfate 2:0e2ef1edf01b 1172 png_free(png_ptr, png_ptr->zbuf);
destinyXfate 2:0e2ef1edf01b 1173 png_ptr->zbuf_size = (png_size_t)size;
destinyXfate 2:0e2ef1edf01b 1174 png_ptr->zbuf = (png_bytep)png_malloc(png_ptr, size);
destinyXfate 2:0e2ef1edf01b 1175 png_ptr->zstream.next_out = png_ptr->zbuf;
destinyXfate 2:0e2ef1edf01b 1176 png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
destinyXfate 2:0e2ef1edf01b 1177 }
destinyXfate 2:0e2ef1edf01b 1178 #endif
destinyXfate 2:0e2ef1edf01b 1179
destinyXfate 2:0e2ef1edf01b 1180 void PNGAPI
destinyXfate 2:0e2ef1edf01b 1181 png_set_invalid(png_structp png_ptr, png_infop info_ptr, int mask)
destinyXfate 2:0e2ef1edf01b 1182 {
destinyXfate 2:0e2ef1edf01b 1183 if (png_ptr && info_ptr)
destinyXfate 2:0e2ef1edf01b 1184 info_ptr->valid &= ~(mask);
destinyXfate 2:0e2ef1edf01b 1185 }
destinyXfate 2:0e2ef1edf01b 1186
destinyXfate 2:0e2ef1edf01b 1187
destinyXfate 2:0e2ef1edf01b 1188 #ifndef PNG_1_0_X
destinyXfate 2:0e2ef1edf01b 1189 #ifdef PNG_ASSEMBLER_CODE_SUPPORTED
destinyXfate 2:0e2ef1edf01b 1190 /* this function was added to libpng 1.2.0 and should always exist by default */
destinyXfate 2:0e2ef1edf01b 1191 void PNGAPI
destinyXfate 2:0e2ef1edf01b 1192 png_set_asm_flags (png_structp png_ptr, png_uint_32 asm_flags)
destinyXfate 2:0e2ef1edf01b 1193 {
destinyXfate 2:0e2ef1edf01b 1194 #ifdef PNG_MMX_CODE_SUPPORTED
destinyXfate 2:0e2ef1edf01b 1195 png_uint_32 settable_asm_flags;
destinyXfate 2:0e2ef1edf01b 1196 png_uint_32 settable_mmx_flags;
destinyXfate 2:0e2ef1edf01b 1197 #endif
destinyXfate 2:0e2ef1edf01b 1198 if (png_ptr == NULL)
destinyXfate 2:0e2ef1edf01b 1199 return;
destinyXfate 2:0e2ef1edf01b 1200 #ifdef PNG_MMX_CODE_SUPPORTED
destinyXfate 2:0e2ef1edf01b 1201
destinyXfate 2:0e2ef1edf01b 1202 settable_mmx_flags =
destinyXfate 2:0e2ef1edf01b 1203 #ifdef PNG_HAVE_ASSEMBLER_COMBINE_ROW
destinyXfate 2:0e2ef1edf01b 1204 PNG_ASM_FLAG_MMX_READ_COMBINE_ROW |
destinyXfate 2:0e2ef1edf01b 1205 #endif
destinyXfate 2:0e2ef1edf01b 1206 #ifdef PNG_HAVE_ASSEMBLER_READ_INTERLACE
destinyXfate 2:0e2ef1edf01b 1207 PNG_ASM_FLAG_MMX_READ_INTERLACE |
destinyXfate 2:0e2ef1edf01b 1208 #endif
destinyXfate 2:0e2ef1edf01b 1209 #ifdef PNG_HAVE_ASSEMBLER_READ_FILTER_ROW
destinyXfate 2:0e2ef1edf01b 1210 PNG_ASM_FLAG_MMX_READ_FILTER_SUB |
destinyXfate 2:0e2ef1edf01b 1211 PNG_ASM_FLAG_MMX_READ_FILTER_UP |
destinyXfate 2:0e2ef1edf01b 1212 PNG_ASM_FLAG_MMX_READ_FILTER_AVG |
destinyXfate 2:0e2ef1edf01b 1213 PNG_ASM_FLAG_MMX_READ_FILTER_PAETH |
destinyXfate 2:0e2ef1edf01b 1214 #endif
destinyXfate 2:0e2ef1edf01b 1215 0;
destinyXfate 2:0e2ef1edf01b 1216
destinyXfate 2:0e2ef1edf01b 1217 /* could be some non-MMX ones in the future, but not currently: */
destinyXfate 2:0e2ef1edf01b 1218 settable_asm_flags = settable_mmx_flags;
destinyXfate 2:0e2ef1edf01b 1219
destinyXfate 2:0e2ef1edf01b 1220 if (!(png_ptr->asm_flags & PNG_ASM_FLAG_MMX_SUPPORT_COMPILED) ||
destinyXfate 2:0e2ef1edf01b 1221 !(png_ptr->asm_flags & PNG_ASM_FLAG_MMX_SUPPORT_IN_CPU))
destinyXfate 2:0e2ef1edf01b 1222 {
destinyXfate 2:0e2ef1edf01b 1223 /* clear all MMX flags if MMX isn't supported */
destinyXfate 2:0e2ef1edf01b 1224 settable_asm_flags &= ~settable_mmx_flags;
destinyXfate 2:0e2ef1edf01b 1225 png_ptr->asm_flags &= ~settable_mmx_flags;
destinyXfate 2:0e2ef1edf01b 1226 }
destinyXfate 2:0e2ef1edf01b 1227
destinyXfate 2:0e2ef1edf01b 1228 /* we're replacing the settable bits with those passed in by the user,
destinyXfate 2:0e2ef1edf01b 1229 * so first zero them out of the master copy, then bitwise-OR in the
destinyXfate 2:0e2ef1edf01b 1230 * allowed subset that was requested */
destinyXfate 2:0e2ef1edf01b 1231
destinyXfate 2:0e2ef1edf01b 1232 png_ptr->asm_flags &= ~settable_asm_flags; /* zero them */
destinyXfate 2:0e2ef1edf01b 1233 png_ptr->asm_flags |= (asm_flags & settable_asm_flags); /* set them */
destinyXfate 2:0e2ef1edf01b 1234 #endif /* ?PNG_MMX_CODE_SUPPORTED */
destinyXfate 2:0e2ef1edf01b 1235 }
destinyXfate 2:0e2ef1edf01b 1236
destinyXfate 2:0e2ef1edf01b 1237 /* this function was added to libpng 1.2.0 */
destinyXfate 2:0e2ef1edf01b 1238 void PNGAPI
destinyXfate 2:0e2ef1edf01b 1239 png_set_mmx_thresholds (png_structp png_ptr,
destinyXfate 2:0e2ef1edf01b 1240 png_byte mmx_bitdepth_threshold,
destinyXfate 2:0e2ef1edf01b 1241 png_uint_32 mmx_rowbytes_threshold)
destinyXfate 2:0e2ef1edf01b 1242 {
destinyXfate 2:0e2ef1edf01b 1243 if (png_ptr == NULL)
destinyXfate 2:0e2ef1edf01b 1244 return;
destinyXfate 2:0e2ef1edf01b 1245 #ifdef PNG_MMX_CODE_SUPPORTED
destinyXfate 2:0e2ef1edf01b 1246 png_ptr->mmx_bitdepth_threshold = mmx_bitdepth_threshold;
destinyXfate 2:0e2ef1edf01b 1247 png_ptr->mmx_rowbytes_threshold = mmx_rowbytes_threshold;
destinyXfate 2:0e2ef1edf01b 1248 #endif /* ?PNG_MMX_CODE_SUPPORTED */
destinyXfate 2:0e2ef1edf01b 1249 }
destinyXfate 2:0e2ef1edf01b 1250 #endif /* ?PNG_ASSEMBLER_CODE_SUPPORTED */
destinyXfate 2:0e2ef1edf01b 1251
destinyXfate 2:0e2ef1edf01b 1252 #ifdef PNG_SET_USER_LIMITS_SUPPORTED
destinyXfate 2:0e2ef1edf01b 1253 /* this function was added to libpng 1.2.6 */
destinyXfate 2:0e2ef1edf01b 1254 void PNGAPI
destinyXfate 2:0e2ef1edf01b 1255 png_set_user_limits (png_structp png_ptr, png_uint_32 user_width_max,
destinyXfate 2:0e2ef1edf01b 1256 png_uint_32 user_height_max)
destinyXfate 2:0e2ef1edf01b 1257 {
destinyXfate 2:0e2ef1edf01b 1258 /* Images with dimensions larger than these limits will be
destinyXfate 2:0e2ef1edf01b 1259 * rejected by png_set_IHDR(). To accept any PNG datastream
destinyXfate 2:0e2ef1edf01b 1260 * regardless of dimensions, set both limits to 0x7ffffffL.
destinyXfate 2:0e2ef1edf01b 1261 */
destinyXfate 2:0e2ef1edf01b 1262 if(png_ptr == NULL) return;
destinyXfate 2:0e2ef1edf01b 1263 png_ptr->user_width_max = user_width_max;
destinyXfate 2:0e2ef1edf01b 1264 png_ptr->user_height_max = user_height_max;
destinyXfate 2:0e2ef1edf01b 1265 }
destinyXfate 2:0e2ef1edf01b 1266 #endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */
destinyXfate 2:0e2ef1edf01b 1267
destinyXfate 2:0e2ef1edf01b 1268 #endif /* ?PNG_1_0_X */
destinyXfate 2:0e2ef1edf01b 1269 #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
destinyXfate 2:0e2ef1edf01b 1270