read ifds for tiff files
parent
790f3b867c
commit
ec7356446f
|
@ -1,15 +1,28 @@
|
||||||
! Copyright (C) 2009 Doug Coleman.
|
! Copyright (C) 2009 Doug Coleman.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: accessors combinators io io.encodings.binary io.files
|
USING: accessors combinators io io.encodings.binary io.files
|
||||||
kernel pack endian ;
|
kernel pack endian tools.hexdump constructors sequences arrays
|
||||||
|
sorting.slots math.order ;
|
||||||
IN: graphics.tiff
|
IN: graphics.tiff
|
||||||
|
|
||||||
TUPLE: tiff
|
TUPLE: tiff
|
||||||
endianness
|
endianness
|
||||||
the-answer
|
the-answer
|
||||||
ifd-offset
|
ifd-offset
|
||||||
|
ifds
|
||||||
;
|
;
|
||||||
|
|
||||||
|
CONSTRUCTOR: tiff ( -- tiff )
|
||||||
|
V{ } clone >>ifds ;
|
||||||
|
|
||||||
|
TUPLE: ifd count ifd-entries ;
|
||||||
|
|
||||||
|
CONSTRUCTOR: ifd ( count ifd-entries -- ifd ) ;
|
||||||
|
|
||||||
|
TUPLE: ifd-entry tag type count offset ;
|
||||||
|
|
||||||
|
CONSTRUCTOR: ifd-entry ( tag type count offset -- ifd-entry ) ;
|
||||||
|
|
||||||
|
|
||||||
ERROR: bad-tiff-magic bytes ;
|
ERROR: bad-tiff-magic bytes ;
|
||||||
|
|
||||||
|
@ -20,6 +33,9 @@ ERROR: bad-tiff-magic bytes ;
|
||||||
[ bad-tiff-magic ]
|
[ bad-tiff-magic ]
|
||||||
} case ;
|
} case ;
|
||||||
|
|
||||||
|
: with-tiff-endianness ( tiff quot -- tiff )
|
||||||
|
[ dup endianness>> ] dip with-endianness ; inline
|
||||||
|
|
||||||
: read-header ( tiff -- tiff )
|
: read-header ( tiff -- tiff )
|
||||||
2 read tiff-endianness [ >>endianness ] keep
|
2 read tiff-endianness [ >>endianness ] keep
|
||||||
[
|
[
|
||||||
|
@ -27,10 +43,27 @@ ERROR: bad-tiff-magic bytes ;
|
||||||
4 read endian> >>ifd-offset
|
4 read endian> >>ifd-offset
|
||||||
] with-endianness ;
|
] with-endianness ;
|
||||||
|
|
||||||
|
: push-ifd ( tiff ifd -- tiff )
|
||||||
|
over ifds>> push ;
|
||||||
|
|
||||||
|
: read-ifd ( -- ifd )
|
||||||
|
2 read endian>
|
||||||
|
2 read endian>
|
||||||
|
4 read endian>
|
||||||
|
4 read endian> <ifd-entry> ;
|
||||||
|
|
||||||
|
: read-ifds ( tiff -- tiff )
|
||||||
|
[
|
||||||
|
dup ifd-offset>> seek
|
||||||
|
2 read endian>
|
||||||
|
dup [ read-ifd ] replicate <ifd> >>ifds
|
||||||
|
] with-tiff-endianness ;
|
||||||
|
|
||||||
: (load-tiff) ( path -- tiff )
|
: (load-tiff) ( path -- tiff )
|
||||||
binary [
|
binary [
|
||||||
tiff new
|
tiff new
|
||||||
read-header
|
read-header
|
||||||
|
read-ifds
|
||||||
] with-file-reader ;
|
] with-file-reader ;
|
||||||
|
|
||||||
: load-tiff ( path -- tiff )
|
: load-tiff ( path -- tiff )
|
||||||
|
|
Loading…
Reference in New Issue