#!/usr/bin/perl # Author: Alex Wilson, http://alexwilsonphoto.com/ # this takes the low byte (value 0 to 255) in a 16-bit greyscale file and # increases the value of the high byte accordingly. # 0- 35 g r b leave alone # 36- 72 g r B increase blue # 73-108 g R b increase red... # 109-145 g R B # 146-181 G r b # 182-218 G r B # 219-255 G R b ...increase green and red. # usage (rename to "pseudogrey.pl" first): # perl pseudogrey.pl input-16bit-grey-raw output-8bit-colour-raw # input-16bit-grey-raw file should be exported from Adobe as a raw file # you'll need to remember the pixel dimensions to import the # output-8bit-colour-raw file properly. open(I,$ARGV[0]); binmode(I); open(O,">".$ARGV[1]); binmode(O); do { $n=read(I,$s,2); if($n>0){ #this expects a raw file with PC byte order. Switch x and y #for Mac ordered files. $x=ord(substr($s,0,1)); #low byte $y=ord(substr($s,1,1)); #high byte $r=$y; $g=$y; $b=$y; if($y<255){ if(($x>35&&$x<73)||($x>108&&$x<146)||($x>181&&$x<219)){ $b++; } if(($x>72&&$x<146)||($x>218)){ $r++; } if($x>145){ $g++; } } printf(O"%c%c%c",$r,$g,$b); } } while($n>0); close(I); close(O); # Background (email from Alex to Rich, 8 Nov 2004) # I was reading something on the topic of gamma and gamut and # there was just a line mentioning that the different pixel # colours had different lightness values. That got the wheels # turning, and I wrote up the script. It wasn't until I # calculated the number of grey levels and did a search google # for "1786" that I found your page. # Yeah, perl often looks pretty ugly -- mostly because the # writers are trying to make it compact as possbile, even at the # cost of readability. I'm by no means a perl guru, and sure my # version could be condensed further.