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

* Re: [Caml-list] saving/loading Raw to/from file
  2007-10-15 18:54 saving/loading Raw to/from file Orlin Grigorov
@ 2007-10-15 19:03 ` Adrien
  2007-10-15 21:27 ` Christophe Raffalli
  2007-10-15 21:28 ` Jacques Garrigue
  2 siblings, 0 replies; 5+ messages in thread
From: Adrien @ 2007-10-15 19:03 UTC (permalink / raw)
  To: Orlin Grigorov; +Cc: caml-list

Hi,
I'm not an expert in this field but I think the Marshall module do
what you want:
http://caml.inria.fr/pub/docs/manual-ocaml/libref/Marshal.html

 ---
Adrien Nader


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

* Re: [Caml-list] saving/loading Raw to/from file
  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
  2 siblings, 0 replies; 5+ messages in thread
From: Christophe Raffalli @ 2007-10-15 21:27 UTC (permalink / raw)
  To: Orlin Grigorov; +Cc: caml-list


[-- Attachment #1.1: Type: text/plain, Size: 815 bytes --]


You could marshall your data to a string and print this string escaped
and insert the string definition in some ml source file.
Thus, your image will be part of the source and this will simplify the
distribution of you software. This can clearly be automated
by your makefile.

Regards,

-- 
Christophe Raffalli
Universite de Savoie
Batiment Le Chablais, bureau 21
73376 Le Bourget-du-Lac Cedex

tel: (33) 4 79 75 81 03
fax: (33) 4 79 75 87 42
mail: Christophe.Raffalli@univ-savoie.fr
www: http://www.lama.univ-savoie.fr/~RAFFALLI
---------------------------------------------
IMPORTANT: this mail is signed using PGP/MIME
At least Enigmail/Mozilla, mutt or evolution 
can check this signature. The public key is
stored on www.keyserver.net
---------------------------------------------


[-- Attachment #1.2: Christophe.Raffalli.vcf --]
[-- Type: text/x-vcard, Size: 310 bytes --]

begin:vcard
fn:Christophe Raffalli
n:Raffalli;Christophe
org:LAMA (UMR 5127)
email;internet:christophe.raffalli@univ-savoie.fr
title;quoted-printable:Ma=C3=AEtre de conf=C3=A9rences
tel;work:+33 4 79 75 81 03
note:http://www.lama.univ-savoie.fr/~raffalli
x-mozilla-html:TRUE
version:2.1
end:vcard


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 249 bytes --]

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

* Re: [Caml-list] saving/loading Raw to/from file
  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
  2 siblings, 1 reply; 5+ messages in thread
From: Jacques Garrigue @ 2007-10-15 21:28 UTC (permalink / raw)
  To: ogrigorov; +Cc: caml-list

From: "Orlin Grigorov" <ogrigorov@gmail.com>

> 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.

Once it is raw, you can read it with
   Raw.gets_string raw ~pos:0 ~len:(Raw.byte_size raw)

You can read it back in the same way:
   let raw = Raw.create `ubyte ~len:(w*h*4) in
   Raw.sets_string raw ~pos:0 ~len:(w*h*4) s;
   GlPix.of_raw raw ~format:`rgba ~width:w ~height:h

This should be efficient enough.
Once you get a string, you know how to do the I/O.

Jacques Garrigue


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

* Re: [Caml-list] saving/loading Raw to/from file
  2007-10-15 21:28 ` Jacques Garrigue
@ 2007-10-16 23:00   ` Orlin Grigorov
  0 siblings, 0 replies; 5+ messages in thread
From: Orlin Grigorov @ 2007-10-16 23:00 UTC (permalink / raw)
  To: Jacques Garrigue; +Cc: caml-list

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

The last worked like a charm!   Thanks a lot to all of you for the great
help!!!!

Orlin

On 10/15/07, Jacques Garrigue <garrigue@math.nagoya-u.ac.jp> wrote:
>
> From: "Orlin Grigorov" <ogrigorov@gmail.com>
>
> > 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.
>
> Once it is raw, you can read it with
>    Raw.gets_string raw ~pos:0 ~len:(Raw.byte_size raw)
>
> You can read it back in the same way:
>    let raw = Raw.create `ubyte ~len:(w*h*4) in
>    Raw.sets_string raw ~pos:0 ~len:(w*h*4) s;
>    GlPix.of_raw raw ~format:`rgba ~width:w ~height:h
>
> This should be efficient enough.
> Once you get a string, you know how to do the I/O.
>
> Jacques Garrigue
>

[-- Attachment #2: Type: text/html, Size: 1249 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).