#!/bin/sh # # intgamma.sh # # Last changed in libpng 1.6.0 [(PENDING RELEASE)] # # COPYRIGHT: Written by John Cunningham Bowler, 2011. # To the extent possible under law, the author has waived all copyright and # related or neighboring rights to this work. This work is published from: # United States. # # Shell script to generate png.c 8-bit and 16-bit log tables (see the code in # png.c for details). # # This script uses the "bc" arbitrary precision calculator to calculate 32-bit # fixed point values of logarithms appropriate to finding the log of an 8-bit # (0..255) value and a similar table for the exponent calculation. # # "bc" must be on the path when the script is executed, and the math library # (-lm) must be available # # function to print out a list of numbers as integers; the function truncates # the integers which must be one-per-line function print(){ awk 'BEGIN{ str = "" } { sub("\\.[0-9]*$", "") if ($0 == "") $0 = "0" if (str == "") t = " " $0 "U" else t = str ", " $0 "U" if (length(t) >= 80) { print str "," str = " " $0 "U" } else str = t } END{ print str }' } # # The logarithm table. cat <= 2^32) x = 2^32-1; x; } END echo '};' echo # # And the table of adjustment values. cat <=0;--i){ (1 - e(-(2^i)/65536*l(2))) * 2^(32-i) } END echo '#endif'