[Swift-commit] r6702 - SwiftApps/modis/src

wozniak at ci.uchicago.edu wozniak at ci.uchicago.edu
Thu Aug 1 15:24:16 CDT 2013


Author: wozniak
Date: 2013-08-01 15:24:15 -0500 (Thu, 01 Aug 2013)
New Revision: 6702

Added:
   SwiftApps/modis/src/rgb_adjust_color.c
Log:
Initial rgb_adjust_color from Perl


Copied: SwiftApps/modis/src/rgb_adjust_color.c (from rev 6700, SwiftApps/modis/bin/rgb_adjust_color.pl)
===================================================================
--- SwiftApps/modis/src/rgb_adjust_color.c	                        (rev 0)
+++ SwiftApps/modis/src/rgb_adjust_color.c	2013-08-01 20:24:15 UTC (rev 6702)
@@ -0,0 +1,35 @@
+#!/usr/bin/perl 
+
+# Usage: rgb_adjust_color.pl input.rgb table.txt output.rgb
+
+my ($input_filename, $translation_table, $output_filename) = @ARGV;
+open(FILE_INPUT, "$input_filename") || die "Unable to open $input_filename!";
+open(FILE_OUTPUT, ">$output_filename") || die "Unable to create $output_filename";
+
+# Read translation table into a hash
+my %tr_table = ();
+open(TRANSLATION_TABLE, "$translation_table") || die "Unable to open $translation_table";
+while(<TRANSLATION_TABLE>) {
+   my ($from, $to) = split;
+   $tr_table{$from} = $to;
+}
+
+# Read data
+$/ = \3;
+while(<FILE_INPUT>) {
+   my $hex = sprintf ("#%2.2X%2.2X%2.2X", unpack('C3', $_));
+
+   if(defined($tr_table{$hex})) { 
+      my $new_value = $tr_table{$hex};
+      print FILE_OUTPUT pack('C3', 
+                             hex(substr($new_value,1,2)),
+                             hex(substr($new_value,3,2)),
+                             hex(substr($new_value,5,2))
+      );
+   } 
+
+   else { print FILE_OUTPUT $_; }
+}
+
+close(FILE_INPUT);
+close(FILE_OUTPUT);




More information about the Swift-commit mailing list