Skip to content

Commit c4b20d0

Browse files
committed
test: add configuration tests and fix bugs
The two new configuation tests, fixed.dfa and float-fixed.dfa verify that the 'standard' configuration of libpng works without floating point arithmetic. Signed-off-by: John Bowler <jbowler@acm.org>
1 parent a8242dd commit c4b20d0

File tree

3 files changed

+53
-0
lines changed

3 files changed

+53
-0
lines changed

contrib/conftest/fixed.dfa

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# fixed.dfa
2+
# Build time configuration of libpng
3+
#
4+
# Author: John Bowler
5+
# Copyright: (c) John Bowler, 2025
6+
# Usage rights:
7+
# To the extent possible under law, the author has waived all copyright and
8+
# related or neighboring rights to this work. This work is published from:
9+
# United States.
10+
#
11+
# Test the standard libpng configuration without floating point (the internal
12+
# fixed point implementations are used instead).
13+
#
14+
option FLOATING_ARITHMETIC off
15+
option FLOATING_POINT off

contrib/conftest/float-fixed.dfa

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# fixed-float.dfa
2+
# Build time configuration of libpng
3+
#
4+
# Author: John Bowler
5+
# Copyright: (c) John Bowler, 2025
6+
# Usage rights:
7+
# To the extent possible under law, the author has waived all copyright and
8+
# related or neighboring rights to this work. This work is published from:
9+
# United States.
10+
#
11+
# Test the standard libpng configuration with the fixed point internal
12+
# implementation in place of the default floating point
13+
#
14+
option FLOATING_ARITHMETIC off

png.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2931,6 +2931,30 @@ png_gamma_significant(png_fixed_point gamma_val)
29312931
gamma_val > PNG_FP_1 + PNG_GAMMA_THRESHOLD_FIXED;
29322932
}
29332933

2934+
#ifndef PNG_FLOATING_ARITHMETIC_SUPPORTED
2935+
/* A local convenience routine. */
2936+
static png_fixed_point
2937+
png_product2(png_fixed_point a, png_fixed_point b)
2938+
{
2939+
/* The required result is a * b; the following preserves accuracy. */
2940+
#ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED /* Should now be unused */
2941+
double r = a * 1E-5;
2942+
r *= b;
2943+
r = floor(r+.5);
2944+
2945+
if (r <= 2147483647. && r >= -2147483648.)
2946+
return (png_fixed_point)r;
2947+
#else
2948+
png_fixed_point res;
2949+
2950+
if (png_muldiv(&res, a, b, 100000) != 0)
2951+
return res;
2952+
#endif
2953+
2954+
return 0; /* overflow */
2955+
}
2956+
#endif /* FLOATING_ARITHMETIC */
2957+
29342958
png_fixed_point
29352959
png_reciprocal2(png_fixed_point a, png_fixed_point b)
29362960
{

0 commit comments

Comments
 (0)