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