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

>>>>>How to read a IMAGE file?(BMP, GIF)|||||||||

19 views
Skip to first unread message

Richard Wang

unread,
Sep 28, 1999, 3:00:00 AM9/28/99
to
Hi,

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

Thanks,
Richard


Eugene Zaikonnikov

unread,
Sep 28, 1999, 3:00:00 AM9/28/99
to

Richard Wang <swa...@cs.auckland.ac.nz> wrote in message
news:37F039A8...@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))))))


Eugene Zaikonnikov

unread,
Sep 28, 1999, 3:00:00 AM9/28/99
to

Chuck Fry

unread,
Sep 28, 1999, 3:00:00 AM9/28/99
to
In article <93853028...@lxms.cit.org.by>,

Eugene Zaikonnikov <vik...@removeme.cit.org.by> wrote:
>Richard Wang <swa...@cs.auckland.ac.nz> wrote in message
>news:37F039A8...@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
chu...@chucko.com (text only please) chuc...@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.

Kent M Pitman

unread,
Sep 28, 1999, 3:00:00 AM9/28/99
to
chu...@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.

Erik Naggum

unread,
Sep 28, 1999, 3:00:00 AM9/28/99
to
* 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

Kent M Pitman

unread,
Sep 28, 1999, 3:00:00 AM9/28/99
to
Erik Naggum <er...@naggum.no> writes:

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.

Christopher Browne

unread,
Sep 29, 1999, 3:00:00 AM9/29/99
to
On 28 Sep 1999 21:23:51 +0000, Erik Naggum <er...@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>
cbbr...@hex.net- <http://www.hex.net/~cbbrowne/lsf.html>

Tim Bradshaw

unread,
Sep 29, 1999, 3:00:00 AM9/29/99
to
* 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

William Deakin

unread,
Sep 29, 1999, 3:00:00 AM9/29/99
to
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


0 new messages