Does anybody knows that how I can read an image file, like BMP or GIF
format?
Thanks,
Richard
--
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))))))
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.
> 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.
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
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.
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>
> 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
> * 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