Did it! Perfect.

Thank you very much indeed.

Ciao (tchau)
     Massimo


----------------------------------------------------------------
Massimo De Gregorio
Research Scientist
Istituto di Cibernetica "Eduardo Caianiello" - CNR
Via Campi Flegrei 34
Comprensorio "A. Olivetti" - Ed. 70
80078 Pozzuoli (NA) - ITALIA
Tel. (+ 39) 0818675151
Fax: (+ 39) 0818675158
Skype: massimo.de.gregorio
E-mail: [email protected]
----------------------------------------------------------------

Il giorno 01/nov/2012, alle ore 15:22, Salvador Pinto Abreu ha scritto:

> Hello Massimo,
> 
> Guess you'd do something along the lines of:
> 
> put_bytes([]).
> put_bytes([B|Bs]) :- put_byte(B), put_bytes(Bs).
> 
> 
> and then
> 
> …
> put_bytes("P5\n32 32\n255\n"),
> …
> 
> remember strings in Prolog are lists of integers with the character codes…
> 
> You may consider format_to_codes/3, which may be used as in:
> 
> | ?- format_to_codes(X, "P5\n%d %d\n255\n", [32, 32]).   
> 
> X = [80,53,10,51,50,32,51,50,10,50,53,53,10]
> 
> which produces the exact same string as in your example.
> 
> 
> cheers
> -salvador
> 
> On Nov 1, 2012, at 12:43, [email protected] wrote:
> 
>> It worked perfectly. The only problem I have now is the following.
>> 
>> The PPM format has three line at the beginning such as:
>> 
>> P5
>> 32 32
>> 255
>> 
>> where P5 is the flag for binary greyscale
>> 32 32 are the size of the image
>> 255 number of greylevels
>> 
>> Just after that starts the binary part of the file that I can
>> generate following your good suggestion.
>> 
>> Now, how can I write, in the same file, the first three text line
>> followed by the binaries ones?
>> 
>> Massimo
>> 
>> Citando Salvador Pinto Abreu <[email protected]>:
>> 
>>> On Nov 1, 2012, at 11:30, [email protected] wrote:
>>> 
>>>> I am trying to automatically generate PPM P5 files.
>>>> In order to write the binary part of the files, I am using
>>>> 
>>>> put_code/1
>>> 
>>> maybe, considering you are building a non-text file, you'd be better  off 
>>> having Prolog use a binary stream, in which case you'd be using  the 
>>> put_byte/1 built-in.
>>> 
>>> consider this, for instance:
>>> 
>>> 11:56:56$ gprolog
>>> GNU Prolog 1.4.1
>>> By Daniel Diaz
>>> Copyright (C) 1999-2012 Daniel Diaz
>>> | ?- open(foo, write, _FOO, [type(binary), alias(foo)]),
>>>    set_output(foo),
>>>    put_byte(0), put_byte(1), put_byte(2), put_byte(3),
>>>    close(foo).
>>> 
>>> (1 ms) yes
>>> | ?- halt.
>>> 
>>> 11:57:05$ od -b foo
>>> 0000000   000 001 002 003
>>> 0000004
>>> 11:57:10$ ls -l foo
>>> -rw-r--r--  1 spa  staff     4B Nov  1 11:56 foo
>>> 11:57:19$
>>> 
>>> hope this helps
>>> -salvador
>>> 
>>> 
>> 
>> 
>> 
>> ----------------------------------------------------------------
>> Massimo De Gregorio
>> Research Scientist
>> Istituto di Cibernetica "Eduardo Caianiello" - CNR
>> Via Campi Flegrei 34
>> Comprensorio "A. Olivetti" - Ed. 70
>> 80078 Pozzuoli (NA) - ITALIA
>> Tel. (+ 39) 0818675151
>> Fax: (+ 39) 0818675158
>> Skype: massimo.de.gregorio
>> E-mail: [email protected]
>> ----------------------------------------------------------------
>> 
>> ----------------------------------------------------------------
>> This message was sent using IMP, the Internet Messaging Program.
>> 
>> 
> 

_______________________________________________
Users-prolog mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/users-prolog

Reply via email to