the start of a tiff library

db4
Doug Coleman 2009-02-06 23:41:59 -06:00
parent 1979fbc61a
commit 26f9df982d
4 changed files with 47 additions and 0 deletions

View File

@ -0,0 +1 @@
Doug Coleman

BIN
extra/graphics/tiff/rgb.tiff Executable file

Binary file not shown.

View File

@ -0,0 +1,9 @@
! Copyright (C) 2009 Your name.
! See http://factorcode.org/license.txt for BSD license.
USING: tools.test graphics.tiff ;
IN: graphics.tiff.tests
: tiff-test-path ( -- path )
"resource:extra/graphics/tiff/rgb.tiff" ;

37
extra/graphics/tiff/tiff.factor Executable file
View File

@ -0,0 +1,37 @@
! Copyright (C) 2009 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors combinators io io.encodings.binary io.files
kernel pack endian ;
IN: graphics.tiff
TUPLE: tiff
endianness
the-answer
ifd-offset
;
ERROR: bad-tiff-magic bytes ;
: tiff-endianness ( byte-array -- ? )
{
{ B{ CHAR: M CHAR: M } [ big-endian ] }
{ B{ CHAR: I CHAR: I } [ little-endian ] }
[ bad-tiff-magic ]
} case ;
: read-header ( tiff -- tiff )
2 read tiff-endianness [ >>endianness ] keep
[
2 read endian> >>the-answer
4 read endian> >>ifd-offset
] with-endianness ;
: (load-tiff) ( path -- tiff )
binary [
tiff new
read-header
] with-file-reader ;
: load-tiff ( path -- tiff )
(load-tiff) ;