This commit is contained in:
Rolf-Thomas Happe 2003-02-16 21:22:04 +00:00
parent d61141c522
commit d6862b856f
2 changed files with 100 additions and 49 deletions

97
scsh/image-info/README Normal file
View File

@ -0,0 +1,97 @@
sunterlib/scsh/image-info -- Extracting Vital Stats from Images
Loose port of small parts from Marco Schmidt's public domain ImageInfo 1.3
Java program. The port supports gif, jpeg, png images and extracts
* the width and height in pixels,
* 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
Typical use: in web-authoring, generate the width and height tags of
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!")))
*
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.
*
(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
(image:info-height/pixel info) --> h | #f
Get the pixel width W resp. height H from image-info record INFO.
(image:info-width/dpi info) --> width | #f
(image:info-height/dpi info) --> height | #f
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.
(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
or close IN.)
*
(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

View File

@ -1,54 +1,6 @@
; Copyright (c) 2003 RT Happe <rthappe at web de> ; Copyright (c) 2003 RT Happe <rthappe at web de>
; See the file COPYING distributed with the Scheme Untergrund Library ; See the file COPYING distributed with the Scheme Untergrund Library
; See the file README for documentation.
#!
Loose port of small parts from Marco Schmidt's public domain ImageInfo 1.3
Java program. The original code is at
http://www.geocities.com/marcoschmidt.geo/image-info.html
Synopses
Extracting the image dimension etc.
(image-dimension img) ==> [w h]
extract the width W and height H (in pixels) from the byte source
(input port, byte-vector, b.s.(*)) repesenting an image -- or signal
an error. Supported formats: gif, jpeg, png.
(get-image-info bs) ==> info | #f
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
(image:info-height/pixel info) ==> h | #f
get the pixel width W resp. height H from image-info record INFO
(image:info-width/dpi info) ==> width | #f
(image:info-height/dpi info) ==> height | #f
get the physical width W resp. height H in dots per inch from etc.
(*) Creating and accessing ``byte streams''
byte-streams are random-access lazy byte sequences
(inport->byte-stream in) ==> bs
convert the input port IN to a b.s. BS
(byte-vector->byte-stream bv) ==> bs
convert the byte-vector bv to a b.s. BS
(segment-byte-stream bs start end) ==> [bv bs']
segment the b.s. BS into the first [start:end) bytes (at most) in the
byte-vector BV and the following [end:*) bytes in the b.s. BS'. BV and
BS' may be empty.
!#
;;; since there is no pre-fab lazy-list facility for s48/scsh but a ;;; since there is no pre-fab lazy-list facility for s48/scsh but a
;;; draft srfi, I don't use what's not there and don't set up a ;;; draft srfi, I don't use what's not there and don't set up a
@ -140,6 +92,8 @@ Extracting the image dimension etc.
(define (image-dimension img) (define (image-dimension img)
(let* ((bs (cond ((input-port? img) (let* ((bs (cond ((input-port? img)
(inport->byte-stream img)) (inport->byte-stream img))
((integer? img) ; fdes?
(inport->byte-stream img))
((byte-vector? img) ((byte-vector? img)
(byte-vector->byte-stream img)) (byte-vector->byte-stream img))
;; should be a promise ;; should be a promise