mirror of
https://git.code.sf.net/p/libpng/code.git
synced 2025-07-10 18:04:09 +02:00
[libpng17] Made 8-bit compose and rgb_to_grayscale accuracy improvements.
These changes cause 16-bit arithmetic to be used for 8-bit data in the gamma
corrected compose and grayscale operations. The arithmetic errors have
three sources all of which are fixed in this commit:
1) 8-bit linear calculations produce massive errors for lower intensity
values.
2) The old 16-bit "16 to 8" gamma table code erroneously wrote the lowest
output value into a table entry which corresponded to multiple output
values (so where the value written should have been the closest to the
transformed input value.)
3) In a number of cases the code to access the 16-bit table did not round;
it did a simple shift, which was wrong and made the side effects of (2)
even worse.
The new gamma code does not have the 16-to-8 problem at the cost of slighly
more calculations and the algorithm used to minimize the number of
calculations has been extended to all the 16-bit tables; it has advantages
for any significant gamma correction.
This commit is contained in:
committed by
Glenn Randers-Pehrson
parent
ac3b4d9b69
commit
3e42c81193
@@ -1832,6 +1832,8 @@ png_handle_tRNS(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
|
||||
*/
|
||||
png_set_tRNS(png_ptr, info_ptr, readbuf, png_ptr->num_trans,
|
||||
&(png_ptr->trans_color));
|
||||
|
||||
png_ptr->trans_alpha = info_ptr->trans_alpha;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -4410,7 +4412,7 @@ defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
|
||||
png_error(png_ptr, "This image requires a row greater than 64KB");
|
||||
#endif
|
||||
|
||||
if (row_bytes + 48 > png_ptr->old_big_row_buf_size)
|
||||
if (row_bytes + 48 > png_ptr->big_row_buf_size)
|
||||
{
|
||||
png_free(png_ptr, png_ptr->big_row_buf);
|
||||
png_free(png_ptr, png_ptr->big_prev_row);
|
||||
@@ -4447,7 +4449,7 @@ defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
|
||||
png_ptr->row_buf = png_ptr->big_row_buf + 31;
|
||||
png_ptr->prev_row = png_ptr->big_prev_row + 31;
|
||||
#endif
|
||||
png_ptr->old_big_row_buf_size = row_bytes + 48;
|
||||
png_ptr->big_row_buf_size = row_bytes + 48;
|
||||
}
|
||||
|
||||
#ifdef PNG_MAX_MALLOC_64K
|
||||
|
||||
Reference in New Issue
Block a user