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

wozniak at ci.uchicago.edu wozniak at ci.uchicago.edu
Thu Aug 1 13:55:18 CDT 2013


Author: wozniak
Date: 2013-08-01 13:55:18 -0500 (Thu, 01 Aug 2013)
New Revision: 6698

Added:
   SwiftApps/modis/src/rgb_histogram.c
Log:
Copy perl version to start on C version


Copied: SwiftApps/modis/src/rgb_histogram.c (from rev 6696, SwiftApps/modis/bin/rgb_histogram.pl)
===================================================================
--- SwiftApps/modis/src/rgb_histogram.c	                        (rev 0)
+++ SwiftApps/modis/src/rgb_histogram.c	2013-08-01 18:55:18 UTC (rev 6698)
@@ -0,0 +1,23 @@
+#!/usr/bin/perl -w
+
+# Input to this program should be a raw, greyscale RGB file
+# Usage: rgb_histogram.pl myfile.rgb
+
+my $image_filename = shift;
+open(IMAGEFILE, "$image_filename") || die "Unable to open $image_filename!\n";
+binmode IMAGEFILE;
+
+my @pixelcount;
+foreach my $count (0..255) { $pixelcount[$count] = 0; }
+
+# Read values, three bytes at a time
+$/ = \3; 
+foreach(<IMAGEFILE>) {
+   $pixelcount[unpack('C', $_)]++;
+}
+close(IMAGEFILE);
+
+foreach my $count (0..255) {
+   if($pixelcount[$count] == 0) { next; }
+   printf("%d %d %02x\n", $pixelcount[$count], $count, $count);
+}




More information about the Swift-commit mailing list