summaryrefslogtreecommitdiffstats
path: root/mktablec.pl
diff options
context:
space:
mode:
authorHenning Makholm <henning@makholm.net>2006-01-27 18:00:00 (EST)
committer Julien Jorge <julien.jorge@stuff-o-matic.com>2013-01-10 16:00:40 (EST)
commit7b7cd6da61b1fcc0f2a3ecce2cb9e6c42782c717 (patch)
tree98d2772f50aaddb02ac94492d2b8b151aa3e9465 /mktablec.pl
downloadxcftools-7b7cd6da61b1fcc0f2a3ecce2cb9e6c42782c717.zip
xcftools-7b7cd6da61b1fcc0f2a3ecce2cb9e6c42782c717.tar.gz
xcftools-7b7cd6da61b1fcc0f2a3ecce2cb9e6c42782c717.tar.bz2
Import of release 0.7
Diffstat (limited to 'mktablec.pl')
-rw-r--r--mktablec.pl67
1 files changed, 67 insertions, 0 deletions
diff --git a/mktablec.pl b/mktablec.pl
new file mode 100644
index 0000000..32bb0d0
--- /dev/null
+++ b/mktablec.pl
@@ -0,0 +1,67 @@
+#! /usr/bin/perl
+# This short script creates fixed look-up tables for xcftools
+# Copyright (C) 2006 Henning Makholm
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of version 2 of the GNU General Public License as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+use strict ; use warnings ;
+
+sub shipsubarray (@) {
+ while( @_ > 1 && $_[$#_] == 0 ) {
+ pop @_ ;
+ }
+ my $last = pop @_ ;
+ print " {" ;
+ my $left = 75 ;
+ for my $d ( (map{ $_ . "," } @_), "$last}," ) {
+ if( length($d) > $left ) {
+ print "\n " ;
+ $left = 75 ;
+ }
+ print $d ;
+ $left -= length($d) ;
+ }
+ print "\n" ;
+}
+
+print "/* Autogenerated by $0 */\n" ;
+print "#include \"pixels.h\"\n" ;
+print "const uint8_t scaletable[256][256] = {\n" ;
+for my $p ( 0..255 ) {
+ shipsubarray( map { int(($p*$_+127)/255) } ( 0 .. 255 ) );
+ # This formula has the property that
+ # scaletable[p][q] + scaletable[255-p][q] == q
+ # for all uint8_t values of p and q.
+ # This is important in order that a partially transparent
+ # pixel does not change the color of the underlying pixel
+ # unless the two pixels have different colors.
+}
+print "};\n" ;
+
+if(0) {
+
+print "const uint8_t divtable[256][256] = {\n" ;
+for my $p ( 0..255 ) {
+ shipsubarray( map { $_ >= $p ? 255 : int(0.5 + 255*$_/$p) }
+ ( 0 .. 255 ) );
+}
+print "};\n" ;
+
+}
+
+print "const rgba graytable[256] = {\n" ;
+for my $p ( 0..255 ) {
+ print " (rgba)$p << RED_SHIFT | (rgba)$p << GREEN_SHIFT | (rgba)$p << BLUE_SHIFT,\n" ;
+}
+print "};\n" ;