[magick-users] read raw rgb 332 images

Anton Feenstra feenstra at few.vu.nl
Tue Jun 26 00:43:34 PDT 2007


Anthony Thyssen wrote:
> You could use a perl script to unpack the 332 format to a 888 three byte
> format.  Then IM will be able to read it, given the images width and
> height.

Thanks for the hint and the code snippet, Anthony. I've ironed out a few 
typo's and glitches. For those of you who may be interested, this works:

#!/usr/bin/perl
undef $/;        # slurp in whole file
print            # print stuff
     pack("c*",   # repack as characters
	 map(( $_&0xE0, ($_<<3)&0xE0, ($_<<6)&0xC0  ), # separate colors
	     unpack("c*", <>) ));       # read file and convert to ints

# last line

Last thing to work out, is to duplicate bits to fill the trailing zeroes 
(trivial, but not done yet).


-- 
Groetjes,

Anton
  _____________ _______________________________________________________
|             |                                                       |
|  _   _  ___,| K. Anton Feenstra                                     |
| / \ / \'| | | IBIVU/Bioinformatics - Free University  Amsterdam     |
|(   |   )| | | De Boelelaan 1083A - 1081 HV Amsterdam - Netherlands  |
| \_/ \_/ | | | Tel +31 20 59 87783 - Fax +31 20 59 87653 - Room P136 |
|             | Feenstra at few.vu.nl - www.few.vu.nl/~feenstra/         |
|             | "Does All This Money Really Have To Go To Charity ?"  |
|             | (Rick)                                                |
|_____________|_______________________________________________________|


More information about the Magick-users mailing list