mirror of
https://git.code.sf.net/p/libpng/code.git
synced 2025-07-10 18:04:09 +02:00
[libpng16] Fixed several typos and expanded TAB characters.
This commit is contained in:
parent
f2aacefb3f
commit
9d1ddbb78f
@ -11,7 +11,7 @@
|
|||||||
* Make a test PNG image. The arguments are as follows:
|
* Make a test PNG image. The arguments are as follows:
|
||||||
*
|
*
|
||||||
* makepng [--sRGB|--linear|--1.8] [--color=<color>] color-type bit-depth \
|
* makepng [--sRGB|--linear|--1.8] [--color=<color>] color-type bit-depth \
|
||||||
* [file-name]
|
* [file-name]
|
||||||
*
|
*
|
||||||
* The color-type may be numeric (and must match the numbers used by the PNG
|
* The color-type may be numeric (and must match the numbers used by the PNG
|
||||||
* specification) or one of the format names listed below. The bit-depth is the
|
* specification) or one of the format names listed below. The bit-depth is the
|
||||||
@ -60,7 +60,7 @@
|
|||||||
* 16 bits: 256x256
|
* 16 bits: 256x256
|
||||||
* More than 16 bits: 1024x1024
|
* More than 16 bits: 1024x1024
|
||||||
*
|
*
|
||||||
* Row filtering is turned off (the 'none' filter is used on every row) and the
|
* Row filtering is turned off (the 'none' filter is used on every row) and the
|
||||||
* images are not interlaced.
|
* images are not interlaced.
|
||||||
*
|
*
|
||||||
* If --color is given then the whole image has that color, color-mapped images
|
* If --color is given then the whole image has that color, color-mapped images
|
||||||
@ -251,7 +251,7 @@ set_value(png_bytep row, size_t rowbytes, png_uint_32 x, unsigned int bit_depth,
|
|||||||
{
|
{
|
||||||
unsigned int mask = (1U << bit_depth)-1;
|
unsigned int mask = (1U << bit_depth)-1;
|
||||||
|
|
||||||
x *= bit_depth; /* Maxium x is 4*1024, maxium bit_depth is 16 */
|
x *= bit_depth; /* Maximum x is 4*1024, maximum bit_depth is 16 */
|
||||||
|
|
||||||
if (value <= mask)
|
if (value <= mask)
|
||||||
{
|
{
|
||||||
@ -1232,7 +1232,7 @@ find_insert(png_const_charp what, png_charp param)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* This is a not-very-good parser for a sequence of numbers (including 0). It
|
/* This is a not-very-good parser for a sequence of numbers (including 0). It
|
||||||
* doesn't accept some apparenly valid things, but it accepts all the sensible
|
* doesn't accept some apparently valid things, but it accepts all the sensible
|
||||||
* combinations.
|
* combinations.
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
@ -1318,8 +1318,8 @@ main(int argc, char **argv)
|
|||||||
|
|
||||||
if (strncmp(arg, "--color=", 8) == 0)
|
if (strncmp(arg, "--color=", 8) == 0)
|
||||||
{
|
{
|
||||||
parse_color(arg+8, colors);
|
parse_color(arg+8, colors);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (argc >= 3 && strcmp(arg, "--insert") == 0)
|
if (argc >= 3 && strcmp(arg, "--insert") == 0)
|
||||||
|
@ -92,12 +92,12 @@ int validation_ascii_to_fp(int count, int argc, char **argv)
|
|||||||
showall = 1;
|
showall = 1;
|
||||||
else if (strcmp(*argv, "-e") == 0 && argc > 0)
|
else if (strcmp(*argv, "-e") == 0 && argc > 0)
|
||||||
{
|
{
|
||||||
--argc;
|
--argc;
|
||||||
max_error = atof(*++argv);
|
max_error = atof(*++argv);
|
||||||
}
|
}
|
||||||
else if (strcmp(*argv, "-E") == 0 && argc > 0)
|
else if (strcmp(*argv, "-E") == 0 && argc > 0)
|
||||||
{
|
{
|
||||||
--argc;
|
--argc;
|
||||||
max_error_abs = atof(*++argv);
|
max_error_abs = atof(*++argv);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -118,7 +118,7 @@ int validation_ascii_to_fp(int count, int argc, char **argv)
|
|||||||
++nonfinite;
|
++nonfinite;
|
||||||
|
|
||||||
if (verbose)
|
if (verbose)
|
||||||
fprintf(stderr, "%.*g %d\n", DBL_DIG, test, precision);
|
fprintf(stderr, "%.*g %d\n", DBL_DIG, test, precision);
|
||||||
|
|
||||||
/* Check for overflow in the buffer by setting a marker. */
|
/* Check for overflow in the buffer by setting a marker. */
|
||||||
memset(buffer, 71, sizeof buffer);
|
memset(buffer, 71, sizeof buffer);
|
||||||
@ -131,8 +131,8 @@ int validation_ascii_to_fp(int count, int argc, char **argv)
|
|||||||
if (buffer[precision+7] != 71)
|
if (buffer[precision+7] != 71)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "%g[%d] -> '%s'[%lu] buffer overflow\n", test,
|
fprintf(stderr, "%g[%d] -> '%s'[%lu] buffer overflow\n", test,
|
||||||
precision, buffer, (unsigned long)strlen(buffer));
|
precision, buffer, (unsigned long)strlen(buffer));
|
||||||
failed = 1;
|
failed = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Following are used for the number parser below and must be
|
/* Following are used for the number parser below and must be
|
||||||
@ -143,19 +143,19 @@ int validation_ascii_to_fp(int count, int argc, char **argv)
|
|||||||
if (!isfinite(test))
|
if (!isfinite(test))
|
||||||
{
|
{
|
||||||
/* Expect 'inf' */
|
/* Expect 'inf' */
|
||||||
if (test >= 0 && strcmp(buffer, "inf") ||
|
if (test >= 0 && strcmp(buffer, "inf") ||
|
||||||
test < 0 && strcmp(buffer, "-inf"))
|
test < 0 && strcmp(buffer, "-inf"))
|
||||||
{
|
{
|
||||||
fprintf(stderr, "%g[%d] -> '%s' but expected 'inf'\n", test,
|
fprintf(stderr, "%g[%d] -> '%s' but expected 'inf'\n", test,
|
||||||
precision, buffer);
|
precision, buffer);
|
||||||
failed = 1;
|
failed = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (!png_check_fp_number(buffer, precision+10, &state, &index) ||
|
else if (!png_check_fp_number(buffer, precision+10, &state, &index) ||
|
||||||
buffer[index] != 0)
|
buffer[index] != 0)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "%g[%d] -> '%s' but has bad format ('%c')\n", test,
|
fprintf(stderr, "%g[%d] -> '%s' but has bad format ('%c')\n", test,
|
||||||
precision, buffer, buffer[index]);
|
precision, buffer, buffer[index]);
|
||||||
failed = 1;
|
failed = 1;
|
||||||
}
|
}
|
||||||
else if (PNG_FP_IS_NEGATIVE(state) && !(test < 0))
|
else if (PNG_FP_IS_NEGATIVE(state) && !(test < 0))
|
||||||
@ -185,21 +185,21 @@ int validation_ascii_to_fp(int count, int argc, char **argv)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Check the result against the original. */
|
/* Check the result against the original. */
|
||||||
double out = atof(buffer);
|
double out = atof(buffer);
|
||||||
double change = fabs((out - test)/test);
|
double change = fabs((out - test)/test);
|
||||||
double allow = .5/pow(10,
|
double allow = .5/pow(10,
|
||||||
(precision >= DBL_DIG) ? DBL_DIG-1 : precision-1);
|
(precision >= DBL_DIG) ? DBL_DIG-1 : precision-1);
|
||||||
|
|
||||||
/* NOTE: if you hit this error case are you compiling with gcc
|
/* NOTE: if you hit this error case are you compiling with gcc
|
||||||
* and -O0? Try -O2 - the errors can accumulate if the FP
|
* and -O0? Try -O2 - the errors can accumulate if the FP
|
||||||
* code above is not optimized and may drift outside the .5 in
|
* code above is not optimized and may drift outside the .5 in
|
||||||
* DBL_DIG allowed. In any case a small number of errors may
|
* DBL_DIG allowed. In any case a small number of errors may
|
||||||
* occur (very small ones - 1 or 2%) because of rounding in the
|
* occur (very small ones - 1 or 2%) because of rounding in the
|
||||||
* calculations, either in the conversion API or in atof.
|
* calculations, either in the conversion API or in atof.
|
||||||
*/
|
*/
|
||||||
if (change >= allow && (isfinite(out) ||
|
if (change >= allow && (isfinite(out) ||
|
||||||
fabs(test/DBL_MAX) <= 1-allow))
|
fabs(test/DBL_MAX) <= 1-allow))
|
||||||
{
|
{
|
||||||
double percent = (precision >= DBL_DIG) ? max_error_abs : max_error;
|
double percent = (precision >= DBL_DIG) ? max_error_abs : max_error;
|
||||||
double allowp = (change-allow)*100/allow;
|
double allowp = (change-allow)*100/allow;
|
||||||
|
|
||||||
@ -213,16 +213,16 @@ int validation_ascii_to_fp(int count, int argc, char **argv)
|
|||||||
if (max < allowp) max = allowp;
|
if (max < allowp) max = allowp;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (showall || allowp >= percent)
|
if (showall || allowp >= percent)
|
||||||
{
|
{
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"%.*g[%d] -> '%s' -> %.*g number changed (%g > %g (%d%%))\n",
|
"%.*g[%d] -> '%s' -> %.*g number changed (%g > %g (%d%%))\n",
|
||||||
DBL_DIG, test, precision, buffer, DBL_DIG, out, change, allow,
|
DBL_DIG, test, precision, buffer, DBL_DIG, out, change, allow,
|
||||||
(int)round(allowp));
|
(int)round(allowp));
|
||||||
failed = 1;
|
failed = 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
++minorarith;
|
++minorarith;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -239,15 +239,15 @@ skip:
|
|||||||
|
|
||||||
/* Generate random numbers. */
|
/* Generate random numbers. */
|
||||||
if (test == 0 || !isfinite(test))
|
if (test == 0 || !isfinite(test))
|
||||||
test = precision+1;
|
test = precision+1;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Derive the exponent from the previous rand() value. */
|
/* Derive the exponent from the previous rand() value. */
|
||||||
int exponent = precision % (DBL_MAX_EXP - DBL_MIN_EXP) + DBL_MIN_EXP;
|
int exponent = precision % (DBL_MAX_EXP - DBL_MIN_EXP) + DBL_MIN_EXP;
|
||||||
int tmp;
|
int tmp;
|
||||||
test = frexp(test * rand(), &tmp);
|
test = frexp(test * rand(), &tmp);
|
||||||
test = ldexp(test, exponent);
|
test = ldexp(test, exponent);
|
||||||
precision >>= 8; /* arbitrary */
|
precision >>= 8; /* arbitrary */
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This limits the precision to 32 digits, enough for standard
|
/* This limits the precision to 32 digits, enough for standard
|
||||||
@ -646,17 +646,17 @@ int validation_muldiv(int count, int argc, char **argv)
|
|||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
long u1, u2;
|
long u1, u2;
|
||||||
int n = 0;
|
int n = 0;
|
||||||
if (a < 0) u1 = -a, n = 1; else u1 = a;
|
if (a < 0) u1 = -a, n = 1; else u1 = a;
|
||||||
if (times < 0) u2 = -times, n = !n; else u2 = times;
|
if (times < 0) u2 = -times, n = !n; else u2 = times;
|
||||||
png_64bit_product(u1, u2, &hi, &lo);
|
png_64bit_product(u1, u2, &hi, &lo);
|
||||||
if (n)
|
if (n)
|
||||||
{
|
{
|
||||||
/* -x = ~x+1 */
|
/* -x = ~x+1 */
|
||||||
lo = ((~lo) + 1) & 0xffffffff;
|
lo = ((~lo) + 1) & 0xffffffff;
|
||||||
hi = ~hi;
|
hi = ~hi;
|
||||||
if (lo == 0) ++hi;
|
if (lo == 0) ++hi;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fp = a;
|
fp = a;
|
||||||
@ -664,48 +664,48 @@ int validation_muldiv(int count, int argc, char **argv)
|
|||||||
if ((fp & 0xffffffff) != lo || ((fp >> 32) & 0xffffffff) != hi)
|
if ((fp & 0xffffffff) != lo || ((fp >> 32) & 0xffffffff) != hi)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "png_64bit_product %d * %d -> %lx|%.8lx not %llx\n",
|
fprintf(stderr, "png_64bit_product %d * %d -> %lx|%.8lx not %llx\n",
|
||||||
a, times, hi, lo, fp);
|
a, times, hi, lo, fp);
|
||||||
++error64;
|
++error64;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (div != 0)
|
if (div != 0)
|
||||||
{
|
{
|
||||||
/* Round - this is C round to zero. */
|
/* Round - this is C round to zero. */
|
||||||
if ((fp < 0) != (div < 0))
|
if ((fp < 0) != (div < 0))
|
||||||
fp -= div/2;
|
fp -= div/2;
|
||||||
else
|
else
|
||||||
fp += div/2;
|
fp += div/2;
|
||||||
|
|
||||||
fp /= div;
|
fp /= div;
|
||||||
fpround = fp;
|
fpround = fp;
|
||||||
/* Assume 2's complement here: */
|
/* Assume 2's complement here: */
|
||||||
ok = fpround <= PNG_UINT_31_MAX &&
|
ok = fpround <= PNG_UINT_31_MAX &&
|
||||||
fpround >= -1-(long long int)PNG_UINT_31_MAX;
|
fpround >= -1-(long long int)PNG_UINT_31_MAX;
|
||||||
if (!ok) ++overflow;
|
if (!ok) ++overflow;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
ok = 0, ++overflow, fpround = fp/*misleading*/;
|
ok = 0, ++overflow, fpround = fp/*misleading*/;
|
||||||
|
|
||||||
if (verbose)
|
if (verbose)
|
||||||
fprintf(stderr, "TEST %d * %d / %d -> %lld (%s)\n", a, times, div,
|
fprintf(stderr, "TEST %d * %d / %d -> %lld (%s)\n", a, times, div,
|
||||||
fp, ok ? "ok" : "overflow");
|
fp, ok ? "ok" : "overflow");
|
||||||
|
|
||||||
++tested;
|
++tested;
|
||||||
if (png_muldiv(&result, a, times, div) != ok)
|
if (png_muldiv(&result, a, times, div) != ok)
|
||||||
{
|
{
|
||||||
++error;
|
++error;
|
||||||
if (ok)
|
if (ok)
|
||||||
fprintf(stderr, "%d * %d / %d -> overflow (expected %lld)\n", a,
|
fprintf(stderr, "%d * %d / %d -> overflow (expected %lld)\n", a,
|
||||||
times, div, fp);
|
times, div, fp);
|
||||||
else
|
else
|
||||||
fprintf(stderr, "%d * %d / %d -> %d (expected overflow %lld)\n", a,
|
fprintf(stderr, "%d * %d / %d -> %d (expected overflow %lld)\n", a,
|
||||||
times, div, result, fp);
|
times, div, result, fp);
|
||||||
}
|
}
|
||||||
else if (ok && result != fpround)
|
else if (ok && result != fpround)
|
||||||
{
|
{
|
||||||
++error;
|
++error;
|
||||||
fprintf(stderr, "%d * %d / %d -> %d not %lld\n", a, times, div, result,
|
fprintf(stderr, "%d * %d / %d -> %d not %lld\n", a, times, div, result,
|
||||||
fp);
|
fp);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
++passed;
|
++passed;
|
||||||
@ -775,7 +775,7 @@ int validation_gamma(int argc, char **argv)
|
|||||||
/* Silence the output with -s, just test the gamma functions with -g: */
|
/* Silence the output with -s, just test the gamma functions with -g: */
|
||||||
while (--argc > 0)
|
while (--argc > 0)
|
||||||
if (strcmp(*++argv, "-s") == 0)
|
if (strcmp(*++argv, "-s") == 0)
|
||||||
silent = 1;
|
silent = 1;
|
||||||
else if (strcmp(*argv, "-g") == 0)
|
else if (strcmp(*argv, "-g") == 0)
|
||||||
onlygamma = 1;
|
onlygamma = 1;
|
||||||
else
|
else
|
||||||
@ -790,100 +790,100 @@ int validation_gamma(int argc, char **argv)
|
|||||||
maxerr = 0;
|
maxerr = 0;
|
||||||
for (i=0; i<256; ++i)
|
for (i=0; i<256; ++i)
|
||||||
{
|
{
|
||||||
double correct = -log(i/255.)/log(2.)*65536;
|
double correct = -log(i/255.)/log(2.)*65536;
|
||||||
double error = png_log8bit(i) - correct;
|
double error = png_log8bit(i) - correct;
|
||||||
|
|
||||||
if (i != 0 && fabs(error) > maxerr)
|
if (i != 0 && fabs(error) > maxerr)
|
||||||
maxerr = fabs(error);
|
maxerr = fabs(error);
|
||||||
|
|
||||||
if (i == 0 && png_log8bit(i) != 0xffffffff ||
|
if (i == 0 && png_log8bit(i) != 0xffffffff ||
|
||||||
i != 0 && png_log8bit(i) != floor(correct+.5))
|
i != 0 && png_log8bit(i) != floor(correct+.5))
|
||||||
{
|
{
|
||||||
fprintf(stderr, "8 bit log error: %d: got %u, expected %f\n",
|
fprintf(stderr, "8 bit log error: %d: got %u, expected %f\n",
|
||||||
i, png_log8bit(i), correct);
|
i, png_log8bit(i), correct);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!silent)
|
if (!silent)
|
||||||
printf("maximum 8 bit log error = %f\n", maxerr);
|
printf("maximum 8 bit log error = %f\n", maxerr);
|
||||||
|
|
||||||
maxerr = 0;
|
maxerr = 0;
|
||||||
for (i=0; i<65536; ++i)
|
for (i=0; i<65536; ++i)
|
||||||
{
|
{
|
||||||
double correct = -log(i/65535.)/log(2.)*65536;
|
double correct = -log(i/65535.)/log(2.)*65536;
|
||||||
double error = png_log16bit(i) - correct;
|
double error = png_log16bit(i) - correct;
|
||||||
|
|
||||||
if (i != 0 && fabs(error) > maxerr)
|
if (i != 0 && fabs(error) > maxerr)
|
||||||
maxerr = fabs(error);
|
maxerr = fabs(error);
|
||||||
|
|
||||||
if (i == 0 && png_log16bit(i) != 0xffffffff ||
|
if (i == 0 && png_log16bit(i) != 0xffffffff ||
|
||||||
i != 0 && png_log16bit(i) != floor(correct+.5))
|
i != 0 && png_log16bit(i) != floor(correct+.5))
|
||||||
{
|
{
|
||||||
if (error > .68) /* By experiment error is less than .68 */
|
if (error > .68) /* By experiment error is less than .68 */
|
||||||
{
|
{
|
||||||
fprintf(stderr, "16 bit log error: %d: got %u, expected %f"
|
fprintf(stderr, "16 bit log error: %d: got %u, expected %f"
|
||||||
" error: %f\n", i, png_log16bit(i), correct, error);
|
" error: %f\n", i, png_log16bit(i), correct, error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!silent)
|
if (!silent)
|
||||||
printf("maximum 16 bit log error = %f\n", maxerr);
|
printf("maximum 16 bit log error = %f\n", maxerr);
|
||||||
|
|
||||||
/* Now exponentiations. */
|
/* Now exponentiations. */
|
||||||
maxerr = 0;
|
maxerr = 0;
|
||||||
for (i=0; i<=0xfffff; ++i)
|
for (i=0; i<=0xfffff; ++i)
|
||||||
{
|
{
|
||||||
double correct = exp(-i/65536. * log(2.)) * (65536. * 65536);
|
double correct = exp(-i/65536. * log(2.)) * (65536. * 65536);
|
||||||
double error = png_exp(i) - correct;
|
double error = png_exp(i) - correct;
|
||||||
|
|
||||||
if (fabs(error) > maxerr)
|
if (fabs(error) > maxerr)
|
||||||
maxerr = fabs(error);
|
maxerr = fabs(error);
|
||||||
if (fabs(error) > 1883) /* By experiment. */
|
if (fabs(error) > 1883) /* By experiment. */
|
||||||
{
|
{
|
||||||
fprintf(stderr, "32 bit exp error: %d: got %u, expected %f"
|
fprintf(stderr, "32 bit exp error: %d: got %u, expected %f"
|
||||||
" error: %f\n", i, png_exp(i), correct, error);
|
" error: %f\n", i, png_exp(i), correct, error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!silent)
|
if (!silent)
|
||||||
printf("maximum 32 bit exp error = %f\n", maxerr);
|
printf("maximum 32 bit exp error = %f\n", maxerr);
|
||||||
|
|
||||||
maxerr = 0;
|
maxerr = 0;
|
||||||
for (i=0; i<=0xfffff; ++i)
|
for (i=0; i<=0xfffff; ++i)
|
||||||
{
|
{
|
||||||
double correct = exp(-i/65536. * log(2.)) * 255;
|
double correct = exp(-i/65536. * log(2.)) * 255;
|
||||||
double error = png_exp8bit(i) - correct;
|
double error = png_exp8bit(i) - correct;
|
||||||
|
|
||||||
if (fabs(error) > maxerr)
|
if (fabs(error) > maxerr)
|
||||||
maxerr = fabs(error);
|
maxerr = fabs(error);
|
||||||
if (fabs(error) > .50002) /* By experiment */
|
if (fabs(error) > .50002) /* By experiment */
|
||||||
{
|
{
|
||||||
fprintf(stderr, "8 bit exp error: %d: got %u, expected %f"
|
fprintf(stderr, "8 bit exp error: %d: got %u, expected %f"
|
||||||
" error: %f\n", i, png_exp8bit(i), correct, error);
|
" error: %f\n", i, png_exp8bit(i), correct, error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!silent)
|
if (!silent)
|
||||||
printf("maximum 8 bit exp error = %f\n", maxerr);
|
printf("maximum 8 bit exp error = %f\n", maxerr);
|
||||||
|
|
||||||
maxerr = 0;
|
maxerr = 0;
|
||||||
for (i=0; i<=0xfffff; ++i)
|
for (i=0; i<=0xfffff; ++i)
|
||||||
{
|
{
|
||||||
double correct = exp(-i/65536. * log(2.)) * 65535;
|
double correct = exp(-i/65536. * log(2.)) * 65535;
|
||||||
double error = png_exp16bit(i) - correct;
|
double error = png_exp16bit(i) - correct;
|
||||||
|
|
||||||
if (fabs(error) > maxerr)
|
if (fabs(error) > maxerr)
|
||||||
maxerr = fabs(error);
|
maxerr = fabs(error);
|
||||||
if (fabs(error) > .524) /* By experiment */
|
if (fabs(error) > .524) /* By experiment */
|
||||||
{
|
{
|
||||||
fprintf(stderr, "16 bit exp error: %d: got %u, expected %f"
|
fprintf(stderr, "16 bit exp error: %d: got %u, expected %f"
|
||||||
" error: %f\n", i, png_exp16bit(i), correct, error);
|
" error: %f\n", i, png_exp16bit(i), correct, error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!silent)
|
if (!silent)
|
||||||
printf("maximum 16 bit exp error = %f\n", maxerr);
|
printf("maximum 16 bit exp error = %f\n", maxerr);
|
||||||
} /* !onlygamma */
|
} /* !onlygamma */
|
||||||
|
|
||||||
/* Test the overall gamma correction. */
|
/* Test the overall gamma correction. */
|
||||||
@ -894,45 +894,45 @@ int validation_gamma(int argc, char **argv)
|
|||||||
png_fixed_point gfp = floor(g * PNG_FP_1 + .5);
|
png_fixed_point gfp = floor(g * PNG_FP_1 + .5);
|
||||||
|
|
||||||
if (!silent)
|
if (!silent)
|
||||||
printf("Test gamma %f\n", g);
|
printf("Test gamma %f\n", g);
|
||||||
|
|
||||||
maxerr = 0;
|
maxerr = 0;
|
||||||
for (j=0; j<256; ++j)
|
for (j=0; j<256; ++j)
|
||||||
{
|
{
|
||||||
double correct = pow(j/255., g) * 255;
|
double correct = pow(j/255., g) * 255;
|
||||||
png_byte out = png_gamma_8bit_correct(j, gfp);
|
png_byte out = png_gamma_8bit_correct(j, gfp);
|
||||||
double error = out - correct;
|
double error = out - correct;
|
||||||
|
|
||||||
if (fabs(error) > maxerr)
|
if (fabs(error) > maxerr)
|
||||||
maxerr = fabs(error);
|
maxerr = fabs(error);
|
||||||
if (out != floor(correct+.5))
|
if (out != floor(correct+.5))
|
||||||
{
|
{
|
||||||
fprintf(stderr, "8bit %d ^ %f: got %d expected %f error %f\n",
|
fprintf(stderr, "8bit %d ^ %f: got %d expected %f error %f\n",
|
||||||
j, g, out, correct, error);
|
j, g, out, correct, error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!silent)
|
if (!silent)
|
||||||
printf("gamma %f: maximum 8 bit error %f\n", g, maxerr);
|
printf("gamma %f: maximum 8 bit error %f\n", g, maxerr);
|
||||||
|
|
||||||
maxerr = 0;
|
maxerr = 0;
|
||||||
for (j=0; j<65536; ++j)
|
for (j=0; j<65536; ++j)
|
||||||
{
|
{
|
||||||
double correct = pow(j/65535., g) * 65535;
|
double correct = pow(j/65535., g) * 65535;
|
||||||
png_uint_16 out = png_gamma_16bit_correct(j, gfp);
|
png_uint_16 out = png_gamma_16bit_correct(j, gfp);
|
||||||
double error = out - correct;
|
double error = out - correct;
|
||||||
|
|
||||||
if (fabs(error) > maxerr)
|
if (fabs(error) > maxerr)
|
||||||
maxerr = fabs(error);
|
maxerr = fabs(error);
|
||||||
if (fabs(error) > 1.62)
|
if (fabs(error) > 1.62)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "16bit %d ^ %f: got %d expected %f error %f\n",
|
fprintf(stderr, "16bit %d ^ %f: got %d expected %f error %f\n",
|
||||||
j, g, out, correct, error);
|
j, g, out, correct, error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!silent)
|
if (!silent)
|
||||||
printf("gamma %f: maximum 16 bit error %f\n", g, maxerr);
|
printf("gamma %f: maximum 16 bit error %f\n", g, maxerr);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user