Skip to content

Commit

Permalink
build(scripts/conv): add script to gen value convs
Browse files Browse the repository at this point in the history
The script generates tables for converting between
different ranges of color values.
  • Loading branch information
dbohdan committed Oct 1, 2023
1 parent ee90b77 commit 68574b7
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions scripts/conversion-tables.tcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#! /usr/bin/env tclsh

package require textutil

set varDeclTemplate {static const uint8_t %s[] = {%s};}

proc table {from to} {
set ratio [expr { $to * 1.0 / $from }]

for {set i 0} {$i < $from} {incr i} {
lappend table [expr { int($i * 1.0 / $from * ($to + $ratio) ) }]
}

return $table
}

proc format-table {name table} {
set lines [textutil::adjust [join $table {, }]]
set indented [join [split $lines \n] "\n "]

return [format $::varDeclTemplate $name "\n $indented\n"]
}

foreach {from to} {256 32 256 64 32 256 64 256} {
dict set tables hicolor_${from}_to_$to [table $from $to]
}

puts [join [lmap {key value} $tables {
format-table $key $value
}] \n\n]

0 comments on commit 68574b7

Please sign in to comment.