-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build(scripts/conv): add script to gen value convs
The script generates tables for converting between different ranges of color values.
- Loading branch information
Showing
1 changed file
with
30 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |