sunterlib/scsh/image-info/README

120 lines
4.2 KiB
Plaintext
Raw Normal View History

2003-02-16 16:22:04 -05:00
sunterlib/scsh/image-info -- Extracting Vital Stats from Images
Loose port of small parts from Marco Schmidt's public domain ImageInfo 1.3
2003-04-23 13:24:13 -04:00
Java program. The port supports gif, jpeg, png images and extracts
* the width and height in pixels,
2003-02-16 16:22:04 -05:00
* maybe the physical width and height in dpi,
* the (unreliable) colour depth (#bits / pixel),
* a symbolic format id: GIF87A, GIF89A, JPEG, PNG.
All numbers are integers. The colour depth may deviate from the actual
value in multi-part gifs. (It is taken from the global header, but
local palettes may reset, typically increase, that value.)
The original code, which does much more, is at
http://www.geocities.com/marcoschmidt.geo/image-info.html
2003-04-23 13:24:13 -04:00
Typical use: in web-authoring, generate the width and height tags of
2003-02-16 16:22:04 -05:00
inline images programmatically, like so:
;; ,open image-info
(receive (w h) (with-input-from-file "pix/herb.jpg"
(lambda () (image-dimension (current-input-port))))
`(img ((src "pix/herb.jpg")
(width ,w) (height ,h)
(alt "Enter!"))))
--> (img ((src "pix/herb.jpg") (width 632) (height 474) (alt "Enter!")))
*
Package Dependencies
IMAGE-INFO's structures depend on structures from the following other
sunterlib projects:
krims
bytio
sequences
*
2003-02-16 16:22:04 -05:00
Procedures
exported by structure IMAGE-INFO. IMAGE-DIMENSION is the convenient
user interface for the most common usage: getting pixel width and
height. Some procedures refer to ``b.s.''s. These are described at
bottom.
(image-dimension img) --> [w h]
Synopsis: Extract the (numeric) width W and height H (in pixels) from
the byte source (input port, file descriptor, byte-vector, b.s.(*))
IMG -- or signal an error.
*
2003-04-23 13:24:13 -04:00
2003-02-16 16:22:04 -05:00
(get-image-info bs) --> info | #f
Synopsis: Extract information on the image represented by b.s.(*) BS
and return an image-info record or #f. (Don't believe in the colour
depth for gifs.)
*
(image:info-format info) --> format | #f
Get the symbolic format id from image-info record INFO.
(image:info-depth info) --> depth | #f
Get the colour DEPTH (#bits/pixel) from image-info record INFO.
(image:info-width/pixel info) --> w | #f
2003-04-23 13:24:13 -04:00
(image:info-height/pixel info) --> h | #f
2003-02-16 16:22:04 -05:00
Get the pixel width W resp. height H from image-info record INFO.
(image:info-width/dpi info) --> width | #f
2003-04-23 13:24:13 -04:00
(image:info-height/dpi info) --> height | #f
2003-02-16 16:22:04 -05:00
Get the physical width W resp. height H in dots per inch from INFO.
*
(*) Creating and accessing ``byte streams''
Byte-streams, or b.s.s for short, are random-access lazy byte sources.
The image-info project doesn't commit to the current implementation,
i.e. create and access b.s.s by the procedures below or blame yourself.
2003-04-23 13:24:13 -04:00
[ Why do we need random-access sources? -- Actually, we don't really.
Random-access buys us a minor architectural edge. We could --just
as Marco Schmidt's original Java program-- read the first two bytes
or so from a port, identify the graphics format and dispatch to the
specialist who deals with the rest of the file. That is, we could
scatter the expertise on graphics formats, with the dispatcher knowing
magic numbers, and others knowing the rest. We could -- but we
choose to encapsulate the expert knowledge on gif, jpeg, png formats
in respective parsing procedures. If one expert cannot parse
a file we ask the next. And while this may not be very wise, it is
conveniently done with b.s.s.
]
2003-02-16 16:22:04 -05:00
(inport->byte-stream in) --> bs
Synopsis: Convert the input port (or file descriptor) IN to a
b.s. BS. (The BS will read from IN as needed. It doesn't duplicate
2003-04-23 13:24:13 -04:00
or close IN.)
2003-02-16 16:22:04 -05:00
*
(byte-vector->byte-stream bv) --> bs
Synopsis: Convert the byte-vector bv to a b.s. BS.
*
(segment-byte-stream bs start end) --> [bv bs']
Synopsis: Segment the b.s. BS into the first [start:end) bytes in the
byte-vector BV and the following [end:*) bytes in the b.s. BS', or get
the little that's there up to eof. BV may be short, BV and BS' may be
empty.
oOo