diff --git a/extra/graphics/tiff/authors.txt b/extra/graphics/tiff/authors.txt new file mode 100755 index 0000000000..7c1b2f2279 --- /dev/null +++ b/extra/graphics/tiff/authors.txt @@ -0,0 +1 @@ +Doug Coleman diff --git a/extra/graphics/tiff/rgb.tiff b/extra/graphics/tiff/rgb.tiff new file mode 100755 index 0000000000..71cbaa9d6e Binary files /dev/null and b/extra/graphics/tiff/rgb.tiff differ diff --git a/extra/graphics/tiff/tiff-tests.factor b/extra/graphics/tiff/tiff-tests.factor new file mode 100755 index 0000000000..daee9a5d9e --- /dev/null +++ b/extra/graphics/tiff/tiff-tests.factor @@ -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" ; + + diff --git a/extra/graphics/tiff/tiff.factor b/extra/graphics/tiff/tiff.factor new file mode 100755 index 0000000000..4676ea2748 --- /dev/null +++ b/extra/graphics/tiff/tiff.factor @@ -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) ;