12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 * version 2 for more details (a copy is included in the LICENSE file that 14 * accompanied this code). 15 * 16 * You should have received a copy of the GNU General Public License version 17 * 2 along with this work; if not, write to the Free Software Foundation, 18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 19 * 20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 21 * or visit www.oracle.com if you need additional information or have any 22 * questions. 23 */ 24 25 /* pngrtran.c - transforms the data in a row for PNG readers 26 * 27 * This file is available under and governed by the GNU General Public 28 * License version 2 only, as published by the Free Software Foundation. 29 * However, the following notice accompanied the original version of this 30 * file and, per its terms, should not be removed: 31 * 32 * Last changed in libpng 1.6.19 [November 12, 2015] 33 * Copyright (c) 1998-2015 Glenn Randers-Pehrson 34 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) 35 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) 36 * 37 * This code is released under the libpng license. 38 * For conditions of distribution and use, see the disclaimer 39 * and license in png.h 40 * 41 * This file contains functions optionally called by an application 42 * in order to tell libpng how to handle data when reading a PNG. 43 * Transformations that are used in both reading and writing are 44 * in pngtrans.c. 45 */ 46 47 #include "pngpriv.h" 48 49 #ifdef PNG_READ_SUPPORTED 50 51 /* Set the action on getting a CRC error for an ancillary or critical chunk. */ 52 void PNGAPI 53 png_set_crc_action(png_structrp png_ptr, int crit_action, int ancil_action) 300 301 #ifdef PNG_READ_ALPHA_MODE_SUPPORTED 302 void PNGFAPI 303 png_set_alpha_mode_fixed(png_structrp png_ptr, int mode, 304 png_fixed_point output_gamma) 305 { 306 int compose = 0; 307 png_fixed_point file_gamma; 308 309 png_debug(1, "in png_set_alpha_mode"); 310 311 if (png_rtran_ok(png_ptr, 0) == 0) 312 return; 313 314 output_gamma = translate_gamma_flags(png_ptr, output_gamma, 1/*screen*/); 315 316 /* Validate the value to ensure it is in a reasonable range. The value 317 * is expected to be 1 or greater, but this range test allows for some 318 * viewing correction values. The intent is to weed out users of this API 319 * who use the inverse of the gamma value accidentally! Since some of these 320 * values are reasonable this may have to be changed. 321 */ 322 if (output_gamma < 70000 || output_gamma > 300000) 323 png_error(png_ptr, "output gamma out of expected range"); 324 325 /* The default file gamma is the inverse of the output gamma; the output 326 * gamma may be changed below so get the file value first: 327 */ 328 file_gamma = png_reciprocal(output_gamma); 329 330 /* There are really 8 possibilities here, composed of any combination 331 * of: 332 * 333 * premultiply the color channels 334 * do not encode non-opaque pixels 335 * encode the alpha as well as the color channels 336 * 337 * The differences disappear if the input/output ('screen') gamma is 1.0, 338 * because then the encoding is a no-op and there is only the choice of 339 * premultiplying the color channels or not. 340 * 341 * png_set_alpha_mode and png_set_background interact because both use 342 * png_compose to do the work. Calling both is only useful when | 12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 * version 2 for more details (a copy is included in the LICENSE file that 14 * accompanied this code). 15 * 16 * You should have received a copy of the GNU General Public License version 17 * 2 along with this work; if not, write to the Free Software Foundation, 18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 19 * 20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 21 * or visit www.oracle.com if you need additional information or have any 22 * questions. 23 */ 24 25 /* pngrtran.c - transforms the data in a row for PNG readers 26 * 27 * This file is available under and governed by the GNU General Public 28 * License version 2 only, as published by the Free Software Foundation. 29 * However, the following notice accompanied the original version of this 30 * file and, per its terms, should not be removed: 31 * 32 * Last changed in libpng 1.6.22 [May 26, 2016] 33 * Copyright (c) 1998-2002,2004,2006-2016 Glenn Randers-Pehrson 34 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) 35 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) 36 * 37 * This code is released under the libpng license. 38 * For conditions of distribution and use, see the disclaimer 39 * and license in png.h 40 * 41 * This file contains functions optionally called by an application 42 * in order to tell libpng how to handle data when reading a PNG. 43 * Transformations that are used in both reading and writing are 44 * in pngtrans.c. 45 */ 46 47 #include "pngpriv.h" 48 49 #ifdef PNG_READ_SUPPORTED 50 51 /* Set the action on getting a CRC error for an ancillary or critical chunk. */ 52 void PNGAPI 53 png_set_crc_action(png_structrp png_ptr, int crit_action, int ancil_action) 300 301 #ifdef PNG_READ_ALPHA_MODE_SUPPORTED 302 void PNGFAPI 303 png_set_alpha_mode_fixed(png_structrp png_ptr, int mode, 304 png_fixed_point output_gamma) 305 { 306 int compose = 0; 307 png_fixed_point file_gamma; 308 309 png_debug(1, "in png_set_alpha_mode"); 310 311 if (png_rtran_ok(png_ptr, 0) == 0) 312 return; 313 314 output_gamma = translate_gamma_flags(png_ptr, output_gamma, 1/*screen*/); 315 316 /* Validate the value to ensure it is in a reasonable range. The value 317 * is expected to be 1 or greater, but this range test allows for some 318 * viewing correction values. The intent is to weed out users of this API 319 * who use the inverse of the gamma value accidentally! Since some of these 320 * values are reasonable this may have to be changed: 321 * 322 * 1.6.x: changed from 0.07..3 to 0.01..100 (to accomodate the optimal 16-bit 323 * gamma of 36, and its reciprocal.) 324 */ 325 if (output_gamma < 1000 || output_gamma > 10000000) 326 png_error(png_ptr, "output gamma out of expected range"); 327 328 /* The default file gamma is the inverse of the output gamma; the output 329 * gamma may be changed below so get the file value first: 330 */ 331 file_gamma = png_reciprocal(output_gamma); 332 333 /* There are really 8 possibilities here, composed of any combination 334 * of: 335 * 336 * premultiply the color channels 337 * do not encode non-opaque pixels 338 * encode the alpha as well as the color channels 339 * 340 * The differences disappear if the input/output ('screen') gamma is 1.0, 341 * because then the encoding is a no-op and there is only the choice of 342 * premultiplying the color channels or not. 343 * 344 * png_set_alpha_mode and png_set_background interact because both use 345 * png_compose to do the work. Calling both is only useful when |