Date: Wed, 8 Oct 2003 11:16:02 +0100 To: lablgtk at kaba.or.jp Subject: Reading RGB values of a colour index from a colormap Message-ID: <20031008101602.GA4920 at redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline From: Richard Jones I'm trying to write a PseudoColor image to a file. Reading pixels from this image gives me colour indexes. I want to map these indexes to (r,g,b) values, but there doesn't seem to be a way. This is my working code so far (see 'XXX'): ---------------------------------------------------------------------- let img = Gdk.Image.get pm ~x:0 ~y:0 ~width ~height in let vis = Gdk.Image.get_visual img in let depth = Gdk.Visual.depth vis in eprintf "visual depth = %d\n" depth; let colparser = match Gdk.Visual.get_type vis with `TRUE_COLOR | `DIRECT_COLOR -> Gdk.Truecolor.color_parser vis | `PSEUDO_COLOR -> (fun i -> XXX) | _ -> failwith "visual type not supported (greyscale monitor?)" in let chan = open_out_bin "print.ppm" in output_string chan (Printf.sprintf "P6 %d %d 255\n" width height); for y = 0 to height-1 do for x = 0 to width-1 do let pix = Gdk.Image.get_pixel img ~x ~y in let r, g, b = colparser pix in output_char chan (char_of_int r); output_char chan (char_of_int g); output_char chan (char_of_int b) done; done; close_out chan; ---------------------------------------------------------------------- Rich. -- Richard Jones. http://www.annexia.org/ http://freshmeat.net/users/rwmj Merjis Ltd. http://www.merjis.com/ - all your business data are belong to you. NET::FTPSERVER is a full-featured, secure, configurable, database-backed FTP server written in Perl: http://www.annexia.org/freeware/netftpserver/