#!/usr/bin/env perl # rgb2xcms --- convert X11 rgb.txt format to Xcms.txt format # Author: Noah Friedman # Created: 2013-03-13 # Public domain # $Id: rgb2xcms,v 1.1 2013/03/14 00:04:55 friedman Exp $ # Commentary: # The rgb.txt database is used by the server to convert color names to rgb # values. The client-side X Color Management System format supports more # colorspaces. # Code: use strict; use POSIX; $^W = 1; # enable warnings sub main { (my $progname = $0) =~ s=.*/==; my $timestamp = POSIX::strftime ("%Y-%m-%dT%H:%M:%S%z", localtime); printf "# Automatically generated by %s %s\n\n", $progname, $timestamp; print "XCMS_COLORDB_START 0.1\n", # Sample colorspace values from X11R5 "cms red\t\tCIEXYZ:0.3811/0.2073/0.0213\n", "cms green\t\tCIEXYZ:0.3203/0.6805/0.1430\n", "cms blue\t\tCIEXYZ:0.2483/0.1122/1.2417\n"; while (<>) { next unless /^\s*(\d+)\s+(\d+)\s+(\d+)\s+(.*?)\s*$/; my ($r, $g, $b, $name) = ($1, $2, $3, $4); printf "%s\t\trgb:%02x/%02x/%02x\n", $name, $r, $g, $b; } print "XCMS_COLORDB_END\n"; } main (@ARGV); # eof