diff --git a/basis/images/bitmap/bitmap.factor b/basis/images/bitmap/bitmap.factor index 6c14490778..df31c8d983 100644 --- a/basis/images/bitmap/bitmap.factor +++ b/basis/images/bitmap/bitmap.factor @@ -4,7 +4,7 @@ USING: accessors alien.c-types arrays byte-arrays combinators compression.run-length fry grouping images images.loader images.normalization io io.binary io.encodings.8-bit.latin1 io.encodings.string kernel math math.bitwise sequences -specialized-arrays summary ; +specialized-arrays summary io.streams.throwing ; QUALIFIED-WITH: bitstreams b SPECIALIZED-ARRAYS: uint ushort ; IN: images.bitmap @@ -348,20 +348,22 @@ ERROR: unsupported-bitmap-file magic ; : load-bitmap ( stream -- loading-bitmap ) [ - \ loading-bitmap new - parse-file-header [ >>file-header ] [ ] bi magic>> { - { "BM" [ - dup file-header>> header-length>> parse-header >>header - parse-color-palette - parse-color-data - ] } - ! { "BA" [ parse-os2-bitmap-array ] } - ! { "CI" [ parse-os2-color-icon ] } - ! { "CP" [ parse-os2-color-pointer ] } - ! { "IC" [ parse-os2-icon ] } - ! { "PT" [ parse-os2-pointer ] } - [ unsupported-bitmap-file ] - } case + [ + \ loading-bitmap new + parse-file-header [ >>file-header ] [ ] bi magic>> { + { "BM" [ + dup file-header>> header-length>> parse-header >>header + parse-color-palette + parse-color-data + ] } + ! { "BA" [ parse-os2-bitmap-array ] } + ! { "CI" [ parse-os2-color-icon ] } + ! { "CP" [ parse-os2-color-pointer ] } + ! { "IC" [ parse-os2-icon ] } + ! { "PT" [ parse-os2-pointer ] } + [ unsupported-bitmap-file ] + } case + ] input-throws-on-eof ] with-input-stream ; : loading-bitmap>bytes ( loading-bitmap -- byte-array ) diff --git a/basis/images/loader/loader.factor b/basis/images/loader/loader.factor index 7f6a5f1dfd..7e1dc9ca31 100644 --- a/basis/images/loader/loader.factor +++ b/basis/images/loader/loader.factor @@ -34,13 +34,10 @@ GENERIC: stream>image ( stream class -- image ) : load-image ( path -- image ) [ open-image-file ] [ image-class ] bi load-image* ; -M: byte-array load-image* - [ - [ binary ] [ length ] bi - dup - ] dip '[ _ stream>image ] throws-on-eof ; +M: object load-image* stream>image ; -M: limited-stream load-image* stream>image ; +M: byte-array load-image* + [ binary ] dip stream>image ; M: string load-image* [ open-image-file ] dip stream>image ; diff --git a/basis/images/png/png.factor b/basis/images/png/png.factor index 0b46fdf653..a539eb7a0c 100644 --- a/basis/images/png/png.factor +++ b/basis/images/png/png.factor @@ -4,7 +4,7 @@ USING: accessors arrays checksums checksums.crc32 combinators compression.inflate fry grouping images images.loader io io.binary io.encodings.ascii io.encodings.string kernel locals math math.bitwise math.ranges sequences sorting assocs -math.functions math.order byte-arrays ; +math.functions math.order byte-arrays io.streams.throwing ; QUALIFIED-WITH: bitstreams bs IN: images.png @@ -319,10 +319,12 @@ ERROR: invalid-color-type/bit-depth loading-png ; : load-png ( stream -- loading-png ) [ - - read-png-header - read-png-chunks - parse-ihdr-chunk + [ + + read-png-header + read-png-chunks + parse-ihdr-chunk + ] input-throws-on-eof ] with-input-stream ; M: png-image stream>image diff --git a/basis/images/tga/tga.factor b/basis/images/tga/tga.factor index 7a3a400197..3b7a726a1e 100644 --- a/basis/images/tga/tga.factor +++ b/basis/images/tga/tga.factor @@ -3,7 +3,7 @@ USING: accessors images images.loader io io.binary kernel locals math sequences io.encodings.ascii io.encodings.string calendar math.ranges math.parser colors arrays hashtables -ui.pixel-formats combinators continuations ; +ui.pixel-formats combinators continuations io.streams.throwing ; IN: images.tga SINGLETON: tga-image @@ -254,7 +254,7 @@ ERROR: bad-tga-unsupported ; ubyte-components >>component-type ; M: tga-image stream>image - drop [ read-tga ] with-input-stream ; + drop [ [ read-tga ] input-throws-on-eof ] with-input-stream ; M: tga-image image>stream drop diff --git a/basis/images/tiff/tiff.factor b/basis/images/tiff/tiff.factor index a1880a3d3c..3a26cd61d8 100755 --- a/basis/images/tiff/tiff.factor +++ b/basis/images/tiff/tiff.factor @@ -6,7 +6,7 @@ io.binary io.encodings.ascii io.encodings.binary io.encodings.string io.encodings.utf8 io.files kernel math math.bitwise math.order math.parser pack sequences strings math.vectors specialized-arrays locals -images.loader ; +images.loader io.streams.throwing ; FROM: alien.c-types => float ; SPECIALIZED-ARRAY: float IN: images.tiff @@ -519,14 +519,12 @@ ERROR: unknown-component-order ifd ; : with-tiff-endianness ( loading-tiff quot -- ) [ dup endianness>> ] dip with-endianness ; inline -: load-tiff-ifds ( stream -- loading-tiff ) - [ - - read-header [ - dup ifd-offset>> read-ifds - process-ifds - ] with-tiff-endianness - ] with-input-stream* ; +: load-tiff-ifds ( -- loading-tiff ) + + read-header [ + dup ifd-offset>> read-ifds + process-ifds + ] with-tiff-endianness ; : process-chunky-ifd ( ifd -- ) read-strips @@ -556,19 +554,13 @@ ERROR: unknown-component-order ifd ; : process-tif-ifds ( loading-tiff -- ) ifds>> [ process-ifd ] each ; -: load-tiff ( stream -- loading-tiff ) - [ load-tiff-ifds dup ] - [ - [ [ 0 seek-absolute ] dip stream-seek ] - [ - [ - [ process-tif-ifds ] with-tiff-endianness - ] with-input-stream - ] bi - ] bi ; +: load-tiff ( -- loading-tiff ) + load-tiff-ifds dup + 0 seek-absolute seek-input + [ process-tif-ifds ] with-tiff-endianness ; ! tiff files can store several images -- we just take the first for now M: tiff-image stream>image ( stream tiff-image -- image ) - drop load-tiff tiff>image ; + drop [ [ load-tiff tiff>image ] input-throws-on-eof ] with-input-stream ; { "tif" "tiff" } [ tiff-image register-image-class ] each