From: Richard James Panturis Giuly
Subject: Reading bitmap files with lisp.
Date: 
Message-ID: <395A969D.D2F84170@spam.com>
Are there any libraries for reading and modifying bitmap files?

(I'm using ACL on Linux)

-- 
	ricky
	······@surfsouth.com

From: David Bakhash
Subject: Re: Reading bitmap files with lisp.
Date: 
Message-ID: <c294s6cod9l.fsf@nerd-xing.mit.edu>
Richard James Panturis Giuly <··@spam.com> writes:

> Are there any libraries for reading and modifying bitmap files?

When I wasn't looking, I did come across some such Common Lisp file
which appeared to do this, but it was not what I was looking for, and so 
I just moved on.  I think it's out there.  Does this help?  no.

However, if you understand the format of the particular bitmap you are
trying to read, can't you just read it in, create a data structure, and
then play around with it (i.e. processing, whatever), and then spit it
out?  This seems pretty straightforward, esp. if your bitmap format is
ASCII.  

What exactly are you trying to do?  Do you want a GUI interface for
modifying the bitmaps?  Something like the Unix `bitmap' program?

I'd check to see if Garnet or some other GUI CL thing has either what
you're looking for, or libraries to simplify its creation.

dave
From: Richard James Panturis Giuly
Subject: Re: Reading bitmap files with lisp.
Date: 
Message-ID: <395B7A59.15A8754F@spam.com>
I want to be able to grab a picture like a gif or jpg, convert it to xpm or
bmp or whatever is convenient, and give it to lisp as an array of pixels.


David Bakhash wrote:

>
> What exactly are you trying to do?  Do you want a GUI interface for
> modifying the bitmaps?  Something like the Unix `bitmap' program?
>

--
 ······@surfsouth.com
From: Raymond Toy
Subject: Re: Reading bitmap files with lisp.
Date: 
Message-ID: <4nu2ecbegt.fsf@rtp.ericsson.se>
>>>>> "Richard" == Richard James Panturis Giuly <··@spam.com> writes:

    Richard> I want to be able to grab a picture like a gif or jpg, convert it to xpm or
    Richard> bmp or whatever is convenient, and give it to lisp as an array of pixels.

I think converting the gif or jpeg image to ppm format would make
accessing the image easier from lisp.  ppm is basically a pure text
file of small integers representing the RGB values, plus a few more
integers about the image size.  (Roughly from memory.)

Paul Graham's ANSI CL book has some simple code to read ppm files, I
think.

Ray
From: Pierre R. Mai
Subject: Re: Reading bitmap files with lisp.
Date: 
Message-ID: <87em5gxrh3.fsf@orion.dent.isdn.cs.tu-berlin.de>
Richard James Panturis Giuly <··@spam.com> writes:

> I want to be able to grab a picture like a gif or jpg, convert it to xpm or
> bmp or whatever is convenient, and give it to lisp as an array of pixels.

Since most image formats are mildly to highly complex (involving
convoluted bit-diddling in the form of compression/decompression,
which often involves patented algorithms, and similarly evil things),
it often pays to avoid dealing with said formats.  There are two basic
approaches to do this:

- Use some of the ready-made libraries (like libpng, libjpeg,
  libimlib, etc.) via your implementations FFI.  This has the
  advantage of higher efficiency, but will involve some coding (and
  debugging effort), given that FFI bindings to bit-diddling,
  call-back based code is not something for the faint of heart.

- Use netpbm or a similar conversion library to convert the original
  images on the fly (via sub-processes and pipes) to something much
  more palatable, like ASCII ppm, which can be parsed into your Lisp
  much more easily...  This will likely not be a suitable solution for
  applications that are processing images in tight loops, but will
  otherwise give you easy access to your pictures...

  Binary P(B|G|P)M formats are especially easy to parse, given that
  they're essentially just simple blocks of raw pixels plus
  dimensions...

Regs, Pierre.

-- 
Pierre Mai <····@acm.org>         PGP and GPG keys at your nearest Keyserver
  "One smaller motivation which, in part, stems from altruism is Microsoft-
   bashing." [Microsoft memo, see http://www.opensource.org/halloween1.html]
From: Richard James Panturis Giuly
Subject: Re: Reading bitmap files with lisp.
Date: 
Message-ID: <395BACD2.2B43579C@spam.com>
I will need the efficiency of the first solution. But what is FFI and how do I
use it, I don't even know what the letters stand for. (I'm using FranzACL on
Linux)


"Pierre R. Mai" wrote:

>
> - Use some of the ready-made libraries (like libpng, libjpeg,
>   libimlib, etc.) via your implementations FFI.  This has the
>   advantage of higher efficiency, but will involve some coding (and
>   debugging effort), given that FFI bindings to bit-diddling,
>   call-back based code is not something for the faint of heart.
>
> - Use netpbm or a similar conversion library to convert the original
>   images on the fly (via sub-processes and pipes) to something much
>   more palatable, like ASCII ppm, which can be parsed into your Lisp
>   much more easily...  This will likely not be a suitable solution for
>   applications that are processing images in tight loops, but will
>   otherwise give you easy access to your pictures...

--
 ······@surfsouth.com
From: Thom Goodsell
Subject: Re: Reading bitmap files with lisp.
Date: 
Message-ID: <395BB28C.439B9A86@cra.com>
FFI = Foreign Function Interface: calling non-Lisp code, such as
graphics libraries, from Lisp. 

You will find documentation in
$ACL_HOME/doc/cl/foreign_functions.htm

assuming ACL 5.0+.

Good luck.

Thom


Richard James Panturis Giuly wrote:
> 
> I will need the efficiency of the first solution. But what is FFI and how do I
> use it, I don't even know what the letters stand for. (I'm using FranzACL on
> Linux)
> 
> "Pierre R. Mai" wrote:
> 
> >
> > - Use some of the ready-made libraries (like libpng, libjpeg,
> >   libimlib, etc.) via your implementations FFI.  This has the
> >   advantage of higher efficiency, but will involve some coding (and
> >   debugging effort), given that FFI bindings to bit-diddling,
> >   call-back based code is not something for the faint of heart.
> >
> > - Use netpbm or a similar conversion library to convert the original
> >   images on the fly (via sub-processes and pipes) to something much
> >   more palatable, like ASCII ppm, which can be parsed into your Lisp
> >   much more easily...  This will likely not be a suitable solution for
> >   applications that are processing images in tight loops, but will
> >   otherwise give you easy access to your pictures...
> 
> --
>  ······@surfsouth.com
From: Erik Naggum
Subject: Re: Reading bitmap files with lisp.
Date: 
Message-ID: <3171302184035072@naggum.no>
* Richard James Panturis Giuly <··@spam.com>
| But what is FFI and how do I use it, I don't even know what the
| letters stand for.

  Foreign Function Interface.  Basically, dealing with other/inferior
  languages.  In C, for instance, you specify -l<library> to the
  linker, after having specified "extern foobar(...random junk...)" in
  your source files.  It's slightly more work from Common Lisp, but it
  shouldn't have been.  In your Allegro CL Trial Edition distribution,
  you will find the file .../doc/cl/foreign_functions.htm, which tells
  you the whole story on how to interface with C libraries.

#:Erik
-- 
  If this is not what you expected, please alter your expectations.
From: Simon Brooke
Subject: Re: Reading bitmap files with lisp.
Date: 
Message-ID: <m2r99fzf8h.fsf@gododdin.internal.jasmine.org.uk>
Richard James Panturis Giuly <··@spam.com> writes:

> I will need the efficiency of the first solution. But what is FFI and how do I
> use it, I don't even know what the letters stand for. (I'm using FranzACL on
> Linux)

Foreign Function Interface, see Chapter 10 of you Allegro user
guide. Essentially you develop functions in a foreign language
(normally, but not necessarily C) which have hooks to allow them to be
loaded into a running LISP image and called as if they were LISP
functions.

You need have a good knowledge of both LISP and your foreign language
of choice, and

    - your code won't be trivially portable even between different
	releases of ACL
    - your code may not be trivially portable between platforms
    - your code won't be trivially portable between different CL 
	implementations

Think carefully before doing this. The idea of piping your images
through a PBM filter looks a lot easier to me.

-- 
·····@jasmine.org.uk (Simon Brooke) http://www.jasmine.org.uk/~simon/

	' ' 	<-------  this blank intentionally spaced left
From: Clinton Hyde
Subject: Re: Reading bitmap files with lisp.
Date: 
Message-ID: <399D2926.C48139EB@bbn.com>
I've got lisp code to read GIFs.  i have not used it in quite a
while...I don't know how well
it does with color--I was using it for b&w things in 1993

somewhere hard to get at I have code that reads xbm or something like
that.

but the suggestions of convert it to some standard middle format are
probably best.

modifying: you're on your own there.   I have a tiny little icon diddler
program I wrote years ago,
now it's in CLIM, just ran it last week (or was it earlier this week?).
you're welcome to the code,
but it only works on monochrome bitmaps.  I use it to create icons.

Richard James Panturis Giuly wrote:

> Are there any libraries for reading and modifying bitmap files?
>
> (I'm using ACL on Linux)

 -- clint
From: Christian Nyb�
Subject: Re: Reading bitmap files with lisp.
Date: 
Message-ID: <87em3memra.fsf@lapchr.siteloft.com>
Clinton Hyde <·····@bbn.com> writes:

> I've got lisp code to read GIFs.  i have not used it in quite a
> while...I don't know how well it does with color--I was using it for
> b&w things in 1993
> 
> somewhere hard to get at I have code that reads xbm or something
> like that.
> 
> but the suggestions of convert it to some standard middle format are
> probably best.
> 
> modifying: you're on your own there.  I have a tiny little icon
> diddler program I wrote years ago, now it's in CLIM, just ran it
> last week (or was it earlier this week?).  you're welcome to the
> code, but it only works on monochrome bitmaps.  I use it to create
> icons.
> 
> Richard James Panturis Giuly wrote:
> 
> > Are there any libraries for reading and modifying bitmap files?
> >
> > (I'm using ACL on Linux)

The hacker who later on wrote XEmacs and Xscreensaver left some CL
code in
<URL:ftp://ftp.cs.cmu.edu/user/ai/lang/lisp/code/impdep/explorer/jwz.tgz>

The files ps-interpreter.lisp, read-x11-raster.lisp and
bit-array-editor.lisp may prove interesting, at least for
archeological purposes.  

For gifs you may have luck with Hallvard Tr�ttebergs code in the
CL-HTTP distribution; it's at
<URL:http://wilson.ai.mit.edu/cl-http/contributions/Hallvard/gif.lisp>

In an earlier thread some suggested using existing libraries for C
with the Foreign Functions Interface (FFI).  Using the FFI is
described in doc/cl/foreign_functions.htm in your ACL directory.

-- 
chr
From: Clinton Hyde
Subject: Re: Reading bitmap files with lisp.
Date: 
Message-ID: <39ABCBA5.F08D23ED@bbn.com>
"Christian Nyb�" wrote:

> Clinton Hyde <·····@bbn.com> writes:
>
> > I've got lisp code to read GIFs.  i have not used it in quite a
> > while...I don't know how well it does with color--I was using it for
> > b&w things in 1993
> >
> > Richard James Panturis Giuly wrote:
> >
> > > Are there any libraries for reading and modifying bitmap files?
> > >
> > > (I'm using ACL on Linux)
>
> The hacker who later on wrote XEmacs and Xscreensaver left some CL
>

that hacker is Jamie Zawinski, also the author of Netscape Navigator Version
1 for X.  and he does love those screensavers, has for years...

> code in
> <URL:ftp://ftp.cs.cmu.edu/user/ai/lang/lisp/code/impdep/explorer/jwz.tgz>
>
> The files ps-interpreter.lisp, read-x11-raster.lisp and
> bit-array-editor.lisp may prove interesting, at least for
> archeological purposes.
>

gad, I'd forgotten about those. Jamie also did sun-raster and andrew-raster
readers, but like the x11-raster, those are pretty well useless these days
(well, I thought they were useless at the time, too, but I guess he was doing
something with them)...I could swear someone told me about or maybe gave me a
copy of a TIFF reader a couple of years ago, but I can't find it on my
machine...

must admit I did find that "bit-array-editor.lisp" code interesting--check
the author's name. that's about when I remembered writing that stuff :) and
I'd forgotten who helped.   that's the original version of what I later
rewrote into the CLIM version I now have.  unfortunately, bit-array-ed isn't
very useful without the custom font: what I did was replace the "1" and "0"
glyphs with solid rectangle and empty rectangle. that way when you typed in a
1 or 0 you got the corresponding blob, I wasn't having to draw/manage/index
rectangles...being unable to create/use custom fonts on the PC, I had to go
with the rectangles method, it doesn't quite work as nicely, you have to use
the mouse to change things.  I suppose I could do the arrows and keystrokes
again, but I don't use it as often as I did years ago...

oh, wait. bit-array-editor.ast IS the custom font, with a different name. why
did that happen? oh well, it's a LispM font, not usable elsewhere...

>
> For gifs you may have luck with Hallvard Tr�ttebergs code in the
> CL-HTTP distribution; it's at
> <URL:http://wilson.ai.mit.edu/cl-http/contributions/Hallvard/gif.lisp>
>
> In an earlier thread some suggested using existing libraries for C
> with the Foreign Functions Interface (FFI).  Using the FFI is
> described in doc/cl/foreign_functions.htm in your ACL directory.
>
> --
> chr

 -- clint
From: Christian Nyb�
Subject: Re: Reading bitmap files with lisp.
Date: 
Message-ID: <87n1hg5trq.fsf@lapchr.siteloft.com>
Clinton Hyde <·····@bbn.com> writes:

> > The files ps-interpreter.lisp, read-x11-raster.lisp and
> > bit-array-editor.lisp may prove interesting, at least for
> > archeological purposes.
> >
> 
> gad, I'd forgotten about those. Jamie also did sun-raster and andrew-raster
> readers, but like the x11-raster, those are pretty well useless these days
> (well, I thought they were useless at the time, too, but I guess he was doing
> something with them)...
> I could swear someone told me about or maybe gave me a
> copy of a TIFF reader a couple of years ago, but I can't find it on my
> machine...

I've had a look at the CL web browser called Closure.  It has code for
reading PNG files <URL:http://www.libpng.org/pub/png/>, and appears to
use external apps such as djpeg and gif2png for other bitmap formats.
Closure is at <URL:http://www.uni-karlsruhe.de/~unk6/closure/>, and
its png code resides in closure/src/renderer/png-images.lisp of the
archive.  Closure is written for Allegro CL version 5.
-- 
chr