caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* saving/loading Raw to/from file
@ 2007-10-15 18:54 Orlin Grigorov
  2007-10-15 19:03 ` [Caml-list] " Adrien
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Orlin Grigorov @ 2007-10-15 18:54 UTC (permalink / raw)
  To: caml-list

[-- Attachment #1: Type: text/plain, Size: 1823 bytes --]

Hi.  Lately I've been actively seeking help from this message-list, and to
be honest, thanks to your advice and suggestions, my work is going really
fast!   I am extremely grateful, thank you all!

So, I've been struggling with something since yesterday:

I am doing something in OCaml, which uses the Lablgl module to draw stuff in
OpenGL.   For some of the things, I have textures (that is, for all the text
I do, I pass it through LaTeX to make a PS, then I use ImageMagick's convert
to make it as an JPEG, after which I read it in with CamlImages module, and
do some transformations on it before finally making an OpenGL texture out of
it).

The problem is that this is a real slow-down for the start-up of my
program.  I don't want to give-up LaTeX, because I need to display some
equations and stuff, but here's the deal.   A huge part of the chunks of
text I use are repeating with each program start-up.   So, I was thinking to
pre-generate the most common ones, and instead of following the lengthy
process of going through LaTeX etc, to just load them from binary files.
Maybe a little code will make it clearer:

let work_image img =
  let w = img#width and h = img#height in
  let image = GlPix.create `ubyte ~format:`rgba ~width:w ~height:h in
  for i = 0 to h - 1 do
    for j = 0 to w - 1 do
      let pixel = img#get (w-j-1) i in
      let red = pixel.r in
      let green = pixel.g in
      let blue = pixel.b in
      let alpha = if (red == 255 && green == 255 && blue == 255) then 0 else
255 in
      Raw.sets (GlPix.to_raw image) ~pos:(4*(i*w+j))  [| red; green; blue;
alpha |]
    done
  done;
  image
;;

With "GlPix.to_raw image" I can make the it raw, if that will help.

The question is, I really need a way to save this "image" in a file, and be
able to recreate it.

Please help!

Thanks,

Orlin

[-- Attachment #2: Type: text/html, Size: 3414 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2007-10-16 23:00 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-10-15 18:54 saving/loading Raw to/from file Orlin Grigorov
2007-10-15 19:03 ` [Caml-list] " Adrien
2007-10-15 21:27 ` Christophe Raffalli
2007-10-15 21:28 ` Jacques Garrigue
2007-10-16 23:00   ` Orlin Grigorov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).