From: Richard Wang
Subject: >>>>>How to read a IMAGE file?(BMP, GIF)|||||||||
Date: 
Message-ID: <37F039A8.CADFD49E@cs.auckland.ac.nz>
Hi,

Does anybody  knows that how I can read an image file, like BMP or GIF
format?

Thanks,
Richard

From: Eugene Zaikonnikov
Subject: Re: >>>>>How to read a IMAGE file?(BMP, GIF)|||||||||
Date: 
Message-ID: <938529409.900262@lxms.cit.org.by>
Richard Wang <·······@cs.auckland.ac.nz> wrote in message
······················@cs.auckland.ac.nz...
> Hi,
>
> Does anybody  knows that how I can read an image file, like BMP or GIF
> format?
>
BMP and GIF are quite different formats, for GIF you should do a good
portion of decoding to get an actual image.
For BMP things are much simplier. Below is a code which *writes* byte vector
representing BGR image into a 24-bit Windows bitmap. Doing opposite should
be pretty straightforward.
In general, http://doc.thesa.ru seems to have references on most commonly
used image formats.

--
    Eugene.



(defun write-bmp (&key rgb h w outfile)
  (with-open-file (o outfile :direction :output :element-type
'unsigned-byte)
      (let* ((compl (rem w 4))
             (len (+ 54 (* h w 3) (* compl h))))
        ;; BITMAPFILEHEADER
        (write-byte #x42 o) ;type
        (write-byte #x4d o)
        (write-byte (logand len 255) o) ;file size
        (write-byte (logand (ash len -8) 255) o)
        (write-byte (logand (ash len -16) 255) o)
        (write-byte (logand (ash len -24) 255) o)
        (write-byte 0 o) ;reserved
        (write-byte 0 o)
        (write-byte 0 o)
        (write-byte 0 o)
        (write-byte #x36 o) ;offset to raster
        (write-byte 0 o)
        (write-byte 0 o)
        (write-byte 0 o)
        ;; BITMAPINFOHEADER
        (write-byte 40 o) ;struct size
        (write-byte 0 o)
        (write-byte 0 o)
        (write-byte 0 o)
        (write-byte (logand w 255) o) ; image width
        (write-byte (logand (ash w -8) 255) o)
        (write-byte (logand (ash w -16) 255) o)
        (write-byte (logand (ash w -24) 255) o)
        (write-byte (logand h 255) o) ;image height
        (write-byte (logand (ash h -8) 255) o)
        (write-byte (logand (ash h -16) 255) o)
        (write-byte (logand (ash h -24) 255) o)
        (write-byte 1 o) ;planes, always one for BMP
        (write-byte 0 o)
        (write-byte 24 o) ;bitcount, 24-bit BMP
        (write-byte 0 o)
        (write-sequence (make-array 24 :initial-element 0 :element-type
'unsigned-byte) o) ;the rest of header
        ;; actual raster image
        (loop for y fixnum from (1- h) downto 0
              for ypos fixnum = (* y 3 w) do
              (loop for x fixnum from ypos to (+ ypos (* (1- w) 3)) by 3 do
                    (write-byte (the unsigned-byte (svref rgb x)) o)
                    (write-byte (the unsigned-byte (svref rgb (1+ x))) o)
                    (write-byte (the unsigned-byte (svref rgb (+ 2 x))) o))
              (loop for i fixnum from 0 below compl do ;adjusting to
double-word
                    (write-byte 0 o))))))
From: Eugene Zaikonnikov
Subject: Re: >>>>>How to read a IMAGE file?(BMP, GIF)|||||||||
Date: 
Message-ID: <938530288.822723@lxms.cit.org.by>
Richard Wang <·······@cs.auckland.ac.nz> wrote in message
······················@cs.auckland.ac.nz...
> Hi,
>
> Does anybody  knows that how I can read an image file, like BMP or GIF
> format?
>
BMP and GIF are quite different formats, for GIF you should do a good
portion of decoding to get an actual image.
For BMP things are much simplier. Below is a code which *writes* byte vector
representing BGR image into a 24-bit Windows bitmap. Doing opposite should
be pretty straightforward.
In general, http://doc.thesa.ru seems to have references on most commonly
used image formats.

--
    Eugene.



(defun write-bmp (&key rgb h w outfile)
  (with-open-file (o outfile :direction :output :element-type
'unsigned-byte)
      (let* ((compl (rem w 4))
             (len (+ 54 (* h w 3) (* compl h))))
        ;; BITMAPFILEHEADER
        (write-byte #x42 o) ;type
        (write-byte #x4d o)
        (write-byte (logand len 255) o) ;file size
        (write-byte (logand (ash len -8) 255) o)
        (write-byte (logand (ash len -16) 255) o)
        (write-byte (logand (ash len -24) 255) o)
        (write-byte 0 o) ;reserved
        (write-byte 0 o)
        (write-byte 0 o)
        (write-byte 0 o)
        (write-byte #x36 o) ;offset to raster
        (write-byte 0 o)
        (write-byte 0 o)
        (write-byte 0 o)
        ;; BITMAPINFOHEADER
        (write-byte 40 o) ;struct size
        (write-byte 0 o)
        (write-byte 0 o)
        (write-byte 0 o)
        (write-byte (logand w 255) o) ; image width
        (write-byte (logand (ash w -8) 255) o)
        (write-byte (logand (ash w -16) 255) o)
        (write-byte (logand (ash w -24) 255) o)
        (write-byte (logand h 255) o) ;image height
        (write-byte (logand (ash h -8) 255) o)
        (write-byte (logand (ash h -16) 255) o)
        (write-byte (logand (ash h -24) 255) o)
        (write-byte 1 o) ;planes, always one for BMP
        (write-byte 0 o)
        (write-byte 24 o) ;bitcount, 24-bit BMP
        (write-byte 0 o)
        (write-sequence (make-array 24 :initial-element 0 :element-type
'unsigned-byte) o) ;the rest of header
        ;; actual raster image
        (loop for y fixnum from (1- h) downto 0
              for ypos fixnum = (* y 3 w) do
              (loop for x fixnum from ypos to (+ ypos (* (1- w) 3)) by 3 do
                    (write-byte (the unsigned-byte (svref rgb x)) o)
                    (write-byte (the unsigned-byte (svref rgb (1+ x))) o)
                    (write-byte (the unsigned-byte (svref rgb (+ 2 x))) o))
              (loop for i fixnum from 0 below compl do ;adjusting to
double-word
                    (write-byte 0 o))))))
From: Chuck Fry
Subject: Re: >>>>>How to read a IMAGE file?(BMP, GIF)|||||||||
Date: 
Message-ID: <37f0e789$0$201@nntp1.ba.best.com>
In article <················@lxms.cit.org.by>,
Eugene Zaikonnikov <······@removeme.cit.org.by> wrote:
>Richard Wang <·······@cs.auckland.ac.nz> wrote in message
>······················@cs.auckland.ac.nz...
>> Does anybody  knows that how I can read an image file, like BMP or GIF
>> format?
>>
>BMP and GIF are quite different formats, for GIF you should do a good
>portion of decoding to get an actual image.

You should also get a license from Unisys.  They are aggressively
enforcing their patent on the LZW compression used in the GIF encoding.
 -- Chuck
--
	    Chuck Fry -- Jack of all trades, master of none
 ······@chucko.com (text only please)  ········@home.com (MIME enabled)
Lisp bigot, mountain biker, car nut, sometime guitarist and photographer
The addresses above are real.  All spammers will be reported to their ISPs.
From: Kent M Pitman
Subject: Re: >>>>>How to read a IMAGE file?(BMP, GIF)|||||||||
Date: 
Message-ID: <sfwyadqvlc7.fsf@world.std.com>
······@best.com (Chuck Fry) writes:

> You should also get a license from Unisys.  They are aggressively
> enforcing their patent on the LZW compression used in the GIF encoding.

And, incidentally, it's not remarkably expensive to get a license.
It's just the principle of the thing--some people are objecting.
But at considerable risk of legal action.
From: Erik Naggum
Subject: Re: >>>>>How to read a IMAGE file?(BMP, GIF)|||||||||
Date: 
Message-ID: <3147542631496716@naggum.no>
* Chuck Fry
| You should also get a license from Unisys.  They are aggressively
| enforcing their patent on the LZW compression used in the GIF encoding.

  I may be wrong on this, but please check to see whether they actually
  have a patent on the decompression -- last time I heard, they had only
  patented the compression part.  and this is fair by my standards.

#:Erik
From: Kent M Pitman
Subject: Re: >>>>>How to read a IMAGE file?(BMP, GIF)|||||||||
Date: 
Message-ID: <sfwwvta1yzd.fsf@world.std.com>
Erik Naggum <····@naggum.no> writes:

> * Chuck Fry
> | You should also get a license from Unisys.  They are aggressively
> | enforcing their patent on the LZW compression used in the GIF encoding.
> 
>   I may be wrong on this, but please check to see whether they actually
>   have a patent on the decompression -- last time I heard, they had only
>   patented the compression part.  and this is fair by my standards.

Btw, I think you're right that it's only gif encoding, not decoding, 
that is encumbered by the patent.   But it's worth finding out for sure
from some definitive source, which I don't purport to be.  I just wanted
to remove any sense here that I was claiming that decoding was encumbered.
From: Tim Bradshaw
Subject: Re: >>>>>How to read a IMAGE file?(BMP, GIF)|||||||||
Date: 
Message-ID: <ey33dvyaaoe.fsf@lostwithiel.tfeb.org>
* Erik Naggum wrote:

>   I may be wrong on this, but please check to see whether they actually
>   have a patent on the decompression -- last time I heard, they had only
>   patented the compression part.  and this is fair by my standards.

I think this is almost certainly true, since gzip will read
compress-ed files but not generate them, and this is because the
compression but not decompression algorithm is patented (or perhaps
the decompression algorithm is licenced in a way acceptable to the
FSF).

--tim
From: William Deakin
Subject: Re: >>>>>How to read a IMAGE file?(BMP, GIF)|||||||||
Date: 
Message-ID: <37F1F8F0.D5892F0F@pindar.com>
Erik Naggum wrote:

> * Chuck Fry
> | You should also get a license from Unisys.  They are aggressively
> | enforcing their patent on the LZW compression used in the GIF encoding.
>
>   I may be wrong on this, but please check to see whether they actually
>   have a patent on the decompression -- last time I heard, they had only
>   patented the compression part.  and this is fair by my standards.
>
> #:Erik

I think you are correct. FSF have got a little hot under the collar about
this.

See http://www.gnu.org/philosophy/gif.html

Cheers,

:) will
From: Christopher Browne
Subject: Re: >>>>>How to read a IMAGE file?(BMP, GIF)|||||||||
Date: 
Message-ID: <7rdI3.25000$d71.744299@news4.giganews.com>
On 28 Sep 1999 21:23:51 +0000, Erik Naggum <····@naggum.no> wrote:
>* Chuck Fry
>| You should also get a license from Unisys.  They are aggressively
>| enforcing their patent on the LZW compression used in the GIF encoding.
>
>  I may be wrong on this, but please check to see whether they actually
>  have a patent on the decompression -- last time I heard, they had only
>  patented the compression part.  and this is fair by my standards.

Before making a decision, I'd suggest consulting:
<http://corp2.unisys.com/LeadStory/lzwfaq.html>

"Unisys has frequently been asked whether a Unisys license is required
 in order to use LZW software obtained by downloading from the
 Internet or from other sources. The answer is simple. In all cases, a
 written license agreement or statement signed by an authorized Unisys
 representative is required from Unisys for all use, sale or
 distribution of any software (including so-called "freeware") and/or
 hardware providing LZW conversion capability (for example, downloaded
 software used for creating/displaying GIF images)."

That's not my words, and this should not be construed as indicating
that I agree with their contentions.

But the Unisys claims do seem to cover both compression and
decompression...

-- 
Rules of the Evil Overlord #15. "I will make it clear that I do know
the meaning of the word "mercy"; I simply choose not show them any." 
<http://www.eviloverlord.com/lists/overlord.html>
········@hex.net- <http://www.hex.net/~cbbrowne/lsf.html>