Loading ...
Sorry, an error occurred while loading the content.

1458Re: "ocaml_beginners"::[] Writing binary values to a file

Expand Messages
  • Remi Vanicat
    Nov 3, 2003
    • 0 Attachment
      Andrei Formiga <ktulu_fhtagn@...> writes:

      > Hello everyone,
      > I want to encode an image to a specific binary
      > format (BMP), writing the results in a file. The image
      > has image data plus headers.
      > The first problem is that I can't use OCaml's int
      > type for that, as it's encoded differently. Or at
      > least I can't simply write the int value, not even
      > using output_binary_int, if I understand the manual
      > correctly. Also, the header has fields of 32 and 16
      > bits, and the image data will mostly consist of 8-bit
      > bytes. For the bytes it's possible to use output_byte.
      > What I don't know is how to write the 16-bits and
      > 32-bits values correctly without depending too much on
      > OCaml's internal representation for ints. For some
      > 32-bits values I can use nativeint, but how can I
      > output a nativeint in binary format ?
      > Overall, my question is: how can I do that (write a
      > binary file in a predetermined format) in OCaml ?

      One solution is to map the file using the function

      This function create a one dimension bigarray whose content is a
      file. To modify the bigarray modify the file, So it might be a
      RĂ©mi Vanicat
    • Show all 7 messages in this topic