caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "Orlin Grigorov" <ogrigorov@gmail.com>
To: caml-list@yquem.inria.fr
Subject: saving/loading Raw to/from file
Date: Mon, 15 Oct 2007 14:54:40 -0400	[thread overview]
Message-ID: <b17e12b30710151154t6f27d5cax977fcdb612b606d3@mail.gmail.com> (raw)

[-- 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 --]

             reply	other threads:[~2007-10-15 18:54 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-10-15 18:54 Orlin Grigorov [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=b17e12b30710151154t6f27d5cax977fcdb612b606d3@mail.gmail.com \
    --to=ogrigorov@gmail.com \
    --cc=caml-list@yquem.inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).