Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Rendering ppm (text) images

78 views
Skip to first unread message

xefaso

unread,
Jun 2, 2006, 4:17:58 AM6/2/06
to
I'm new to tcl and this is what I'm trying to do:

I write some lisp code to generate images in ppm-text format; this is a
well known toy example (sample.ppm) downloaded from somewhere:

P3
4 4
15
0 0 0 0 0 0 0 0 0 15 0 15
0 0 0 0 15 7 0 0 0 0 0 0
0 0 0 0 0 0 0 15 7 0 0 0
15 0 15 0 0 0 0 0 0 0 0 0

Now, the following code doesn't work with the above file, but if I
substitute sample.ppm by any other ppm file in raw format (not text) it
works fine, as well with gif images,

set myimage [image create photo -file path/to/my/sample.ppm]
label .imagedisplayer -image $myimage
pack .imagedisplayer

my question is: is it possible to render ppm-text images this way and
how?

If possible, I'd prefere a solution without additional packages or
external programs, since this is part of a bigger project (Maxima-CAS)
and we don't want more dependencies than tcl itself.

Thanks in advance,

Mario

Aric Bills

unread,
Jun 2, 2006, 6:51:34 AM6/2/06
to
Tk doesn't support the ASCII version of PPM. If you are generating the
PPM files yourself, you're probably better off generating them as
binary files. Another possibility would be to write a routine in Tcl
to convert ASCII PPM to binary PPM (the [binary format] command is your
friend here). A third option is to write Tcl code to read the ASCII
PPM file and convert the contents into something that can be understood
by the "put" subcommand of a photo image object (see the photo man page
for more information: http://www.tcl.tk/man/tcl8.5/TkCmd/photo.htm#M30
)

If you decide to start with an ASCII PPM and convert either to a binary
PPM or directly to an image, I'm sure we can point you to the
appropriate commands to accomplish your goals. Of course, if you start
out with binary files, then your image rendering goals are already
fulfilled by Tk.

xefaso

unread,
Jun 2, 2006, 10:06:46 AM6/2/06
to

Aric Bills wrote:

> Tk doesn't support the ASCII version of PPM. If you are generating the
> PPM files yourself, you're probably better off generating them as
> binary files.


Hi Aric,

Thanks a lot for your quick and accurate response. I'll try to generate
the binaries directly from lisp.

Yours, Mario.

Cameron Laird

unread,
Jun 2, 2006, 10:51:28 AM6/2/06
to
In article <1149245494....@i40g2000cwc.googlegroups.com>,

I personally anticipate even more enthusiastic community
support; if the original questioner merely puts up on the
Wiki a skeleton implementation for either of the two
programming approaches, my bet is that one of us will
flesh and polish it.

suchenwi

unread,
Jun 2, 2006, 11:48:51 AM6/2/06
to
See http://wiki.tcl.tk/PPM whether that does what you wants... It takes
a string as input, so you might call it like this with a ppm file:
set f [open $ppmfilename]
set im [ppm-photo [read $f]]
close $f

Aric Bills

unread,
Jun 2, 2006, 4:53:09 PM6/2/06
to
> I personally anticipate even more enthusiastic community
> support; if the original questioner merely puts up on the
> Wiki a skeleton implementation for either of the two
> programming approaches, my bet is that one of us will
> flesh and polish it.

You're right, of course. The combined talent and generosity in the Tcl
community never cease to amaze me. As someone who's benefitted a great
deal from this, thanks, everybody.

xefaso

unread,
Jun 2, 2006, 6:22:14 PM6/2/06
to

Aric Bills ha escrito:

Finally, I rewrote my lisp code to generate the binary ppm's directly.
After calling 'wish' from lisp, I can see a nice window with the
image.

The Maxima-CAS uses gnuplot and tcl-tk for drawing purposes. At this
moment, bitmap imaging is not supported by Maxima, and I'm trying to
develope a first package on this subject based on tcl's capabilities,
and rendering is (was) the first problem.

Thanks again for your kind help and offers to contribute to solve my
problem.

Best wishes

Mario

0 new messages