diff --git a/basis/images/bitmap/bitmap-tests.factor b/basis/images/bitmap/bitmap-tests.factor index 3373a46c2e..2ac2fed4d1 100644 --- a/basis/images/bitmap/bitmap-tests.factor +++ b/basis/images/bitmap/bitmap-tests.factor @@ -1,43 +1,11 @@ -USING: images.bitmap images.viewer io.encodings.binary -io.files io.files.unique kernel tools.test images.loader -literals sequences checksums.md5 checksums ; +USING: images.bitmap images.testing kernel ; IN: images.bitmap.tests -CONSTANT: test-bitmap24 "vocab:images/testing/bmp/thiswayup24.bmp" +! "vocab:images/testing/bmp/1bit.bmp" decode-test +! "vocab:images/testing/bmp/rgb_4bit.bmp" decode-test -CONSTANT: test-bitmap8 "vocab:images/testing/bmp/rgb8bit.bmp" +"vocab:images/testing/bmp/rgb_8bit.bmp" +[ decode-test ] [ bmp-image encode-test ] bi -CONSTANT: test-bitmap4 "vocab:images/testing/bmp/rgb4bit.bmp" - -CONSTANT: test-bitmap1 "vocab:images/testing/bmp/1bit.bmp" - -CONSTANT: test-40 "vocab:images/testing/bmp/40red24bit.bmp" -CONSTANT: test-41 "vocab:images/testing/bmp/41red24bit.bmp" -CONSTANT: test-42 "vocab:images/testing/bmp/42red24bit.bmp" -CONSTANT: test-43 "vocab:images/testing/bmp/43red24bit.bmp" - -${ - test-bitmap8 - test-bitmap24 - "vocab:ui/render/test/reference.bmp" -} [ [ ] swap [ load-image drop ] curry unit-test ] each - - -: test-bitmap-save ( path -- ? ) - [ md5 checksum-file ] - [ load-image ] bi - "bitmap-save-test" ".bmp" make-unique-file - [ save-bitmap ] - [ md5 checksum-file ] bi = ; - -[ - t -] [ - ${ - test-40 - test-41 - test-42 - test-43 - test-bitmap24 - } [ test-bitmap-save ] all? -] unit-test +"vocab:images/testing/bmp/42red_24bit.bmp" +[ decode-test ] [ bmp-image encode-test ] bi diff --git a/basis/images/png/png-tests.factor b/basis/images/png/png-tests.factor index 65503c4dbe..7e3fb5dc97 100755 --- a/basis/images/png/png-tests.factor +++ b/basis/images/png/png-tests.factor @@ -1,7 +1,6 @@ ! Copyright (C) 2009 Doug Coleman. ! See http://factorcode.org/license.txt for BSD license. -USING: images.png images.testing namespaces tools.test -images.pam ; +USING: images.testing ; IN: images.png.tests "vocab:images/testing/png/rgb.png" decode-test diff --git a/basis/images/testing/bmp/40red24bit.bmp b/basis/images/testing/bmp/40red24bit.bmp deleted file mode 100644 index 5e694559c6..0000000000 Binary files a/basis/images/testing/bmp/40red24bit.bmp and /dev/null differ diff --git a/basis/images/testing/bmp/41red24bit.bmp b/basis/images/testing/bmp/41red24bit.bmp deleted file mode 100644 index 6599dcc107..0000000000 Binary files a/basis/images/testing/bmp/41red24bit.bmp and /dev/null differ diff --git a/basis/images/testing/bmp/42red24bit.bmp b/basis/images/testing/bmp/42red_24bit.bmp similarity index 100% rename from basis/images/testing/bmp/42red24bit.bmp rename to basis/images/testing/bmp/42red_24bit.bmp diff --git a/basis/images/testing/bmp/42red_24bit.fig b/basis/images/testing/bmp/42red_24bit.fig new file mode 100644 index 0000000000..9c2ce17edb Binary files /dev/null and b/basis/images/testing/bmp/42red_24bit.fig differ diff --git a/basis/images/testing/bmp/43red24bit.bmp b/basis/images/testing/bmp/43red24bit.bmp deleted file mode 100644 index d88f2d4c32..0000000000 Binary files a/basis/images/testing/bmp/43red24bit.bmp and /dev/null differ diff --git a/basis/images/testing/bmp/rgb4bit.bmp b/basis/images/testing/bmp/rgb_4bit.bmp similarity index 100% rename from basis/images/testing/bmp/rgb4bit.bmp rename to basis/images/testing/bmp/rgb_4bit.bmp diff --git a/basis/images/testing/bmp/rgb8bit.bmp b/basis/images/testing/bmp/rgb_8bit.bmp similarity index 100% rename from basis/images/testing/bmp/rgb8bit.bmp rename to basis/images/testing/bmp/rgb_8bit.bmp diff --git a/basis/images/testing/bmp/rgb_8bit.fig b/basis/images/testing/bmp/rgb_8bit.fig new file mode 100644 index 0000000000..4b75a10dc0 Binary files /dev/null and b/basis/images/testing/bmp/rgb_8bit.fig differ diff --git a/basis/images/testing/bmp/thiswayup24.bmp b/basis/images/testing/bmp/thiswayup24.bmp deleted file mode 100644 index 202fb15371..0000000000 Binary files a/basis/images/testing/bmp/thiswayup24.bmp and /dev/null differ diff --git a/basis/images/testing/gif/alpha.fig b/basis/images/testing/gif/alpha.fig new file mode 100644 index 0000000000..b36a8f6666 Binary files /dev/null and b/basis/images/testing/gif/alpha.fig differ diff --git a/basis/images/testing/gif/alpha.pam b/basis/images/testing/gif/alpha.pam deleted file mode 100644 index cc72a3d33c..0000000000 Binary files a/basis/images/testing/gif/alpha.pam and /dev/null differ diff --git a/basis/images/testing/gif/astronaut_animation.fig b/basis/images/testing/gif/astronaut_animation.fig new file mode 100644 index 0000000000..905da6d827 Binary files /dev/null and b/basis/images/testing/gif/astronaut_animation.fig differ diff --git a/basis/images/testing/gif/astronaut_animation.pam b/basis/images/testing/gif/astronaut_animation.pam deleted file mode 100644 index 8f4e30d8d7..0000000000 Binary files a/basis/images/testing/gif/astronaut_animation.pam and /dev/null differ diff --git a/basis/images/testing/gif/checkmark.fig b/basis/images/testing/gif/checkmark.fig new file mode 100644 index 0000000000..c177d89250 Binary files /dev/null and b/basis/images/testing/gif/checkmark.fig differ diff --git a/basis/images/testing/gif/checkmark.pam b/basis/images/testing/gif/checkmark.pam deleted file mode 100644 index 7688ecf294..0000000000 Binary files a/basis/images/testing/gif/checkmark.pam and /dev/null differ diff --git a/basis/images/testing/gif/circle.fig b/basis/images/testing/gif/circle.fig new file mode 100644 index 0000000000..330397f7d7 Binary files /dev/null and b/basis/images/testing/gif/circle.fig differ diff --git a/basis/images/testing/gif/circle.pam b/basis/images/testing/gif/circle.pam deleted file mode 100644 index 7c1cf6b7f5..0000000000 Binary files a/basis/images/testing/gif/circle.pam and /dev/null differ diff --git a/basis/images/testing/gif/monochrome.fig b/basis/images/testing/gif/monochrome.fig new file mode 100644 index 0000000000..69de84564e Binary files /dev/null and b/basis/images/testing/gif/monochrome.fig differ diff --git a/basis/images/testing/gif/monochrome.pam b/basis/images/testing/gif/monochrome.pam deleted file mode 100644 index 6a31575f3e..0000000000 Binary files a/basis/images/testing/gif/monochrome.pam and /dev/null differ diff --git a/basis/images/testing/gif/noise.fig b/basis/images/testing/gif/noise.fig new file mode 100644 index 0000000000..a2650e971f Binary files /dev/null and b/basis/images/testing/gif/noise.fig differ diff --git a/basis/images/testing/gif/noise.pam b/basis/images/testing/gif/noise.pam deleted file mode 100644 index 03407020cf..0000000000 Binary files a/basis/images/testing/gif/noise.pam and /dev/null differ diff --git a/basis/images/testing/pam/rgb1x1.pam b/basis/images/testing/pam/rgb1x1.pam deleted file mode 100644 index 412d9e7cd8..0000000000 Binary files a/basis/images/testing/pam/rgb1x1.pam and /dev/null differ diff --git a/basis/images/testing/pam/rgb2x2.pam b/basis/images/testing/pam/rgb2x2.pam deleted file mode 100644 index 70bed6e297..0000000000 Binary files a/basis/images/testing/pam/rgb2x2.pam and /dev/null differ diff --git a/basis/images/testing/pam/rgb3x3.pam b/basis/images/testing/pam/rgb3x3.pam deleted file mode 100644 index dc45e4fa62..0000000000 Binary files a/basis/images/testing/pam/rgb3x3.pam and /dev/null differ diff --git a/basis/images/testing/pam/rgba1x1.pam b/basis/images/testing/pam/rgba1x1.pam deleted file mode 100644 index 0387e9ce91..0000000000 Binary files a/basis/images/testing/pam/rgba1x1.pam and /dev/null differ diff --git a/basis/images/testing/pam/rgba2x2.pam b/basis/images/testing/pam/rgba2x2.pam deleted file mode 100644 index fabbff1aa3..0000000000 Binary files a/basis/images/testing/pam/rgba2x2.pam and /dev/null differ diff --git a/basis/images/testing/pam/rgba3x3.pam b/basis/images/testing/pam/rgba3x3.pam deleted file mode 100644 index 3dd52ada3a..0000000000 Binary files a/basis/images/testing/pam/rgba3x3.pam and /dev/null differ diff --git a/basis/images/testing/png/rgb.pam b/basis/images/testing/png/rgb.fig similarity index 86% rename from basis/images/testing/png/rgb.pam rename to basis/images/testing/png/rgb.fig index 50f86782c6..cbe75e6b87 100644 Binary files a/basis/images/testing/png/rgb.pam and b/basis/images/testing/png/rgb.fig differ diff --git a/basis/images/testing/png/yin_yang.pam b/basis/images/testing/png/yin_yang.fig similarity index 99% rename from basis/images/testing/png/yin_yang.pam rename to basis/images/testing/png/yin_yang.fig index 150f50eeff..59931d73d4 100644 Binary files a/basis/images/testing/png/yin_yang.pam and b/basis/images/testing/png/yin_yang.fig differ diff --git a/basis/images/testing/testing.factor b/basis/images/testing/testing.factor index 7aba0ca8aa..c57a17ffc7 100644 --- a/basis/images/testing/testing.factor +++ b/basis/images/testing/testing.factor @@ -1,33 +1,39 @@ ! Copyright (C) 2009 Keith Lazuka. ! See http://factorcode.org/license.txt for BSD license. -USING: fry images.loader io io.encodings.binary io.files -io.pathnames io.streams.byte-array kernel locals namespaces -quotations sequences tools.test ; +USING: fry images.loader images.normalization io +io.encodings.binary io.files io.pathnames io.streams.byte-array +kernel locals namespaces quotations sequences serialize +tools.test ; IN: images.testing -:: encode-test ( path image-class -- ) - path binary file-contents 1quotation - [ - binary dup [ - path load-image image-class image>stream - ] with-output-stream B{ } like - ] unit-test ; - +: save-as-reference-image ( path -- ) + [ load-image ] [ fig-name ] bi + binary [ serialize ] with-file-writer ; + +: load-reference-image ( path -- image ) + fig-name binary [ deserialize ] with-file-reader ; + +:: encode-test ( path image-class -- ) + f verbose-tests? [ + path load-image dup clone normalize-image 1quotation swap + '[ + binary [ _ image-class image>stream ] with-byte-writer + image-class load-image* normalize-image + ] unit-test + ] with-variable ; + : decode-test ( path -- ) f verbose-tests? [ [ load-image 1quotation ] - [ '[ _ pam-name load-image ] ] bi + [ '[ _ load-reference-image ] ] bi unit-test ] with-variable ; diff --git a/basis/images/testing/tiff/alpha.fig b/basis/images/testing/tiff/alpha.fig new file mode 100644 index 0000000000..b36a8f6666 Binary files /dev/null and b/basis/images/testing/tiff/alpha.fig differ diff --git a/basis/images/testing/tiff/alpha.pam b/basis/images/testing/tiff/alpha.pam deleted file mode 100644 index cc72a3d33c..0000000000 Binary files a/basis/images/testing/tiff/alpha.pam and /dev/null differ diff --git a/basis/images/testing/tiff/color_spectrum.pam b/basis/images/testing/tiff/color_spectrum.fig similarity index 98% rename from basis/images/testing/tiff/color_spectrum.pam rename to basis/images/testing/tiff/color_spectrum.fig index e2f3916726..7050c13f6c 100644 Binary files a/basis/images/testing/tiff/color_spectrum.pam and b/basis/images/testing/tiff/color_spectrum.fig differ diff --git a/basis/images/testing/tiff/elephants.pam b/basis/images/testing/tiff/elephants.pam deleted file mode 100644 index eedc2b5c43..0000000000 Binary files a/basis/images/testing/tiff/elephants.pam and /dev/null differ diff --git a/basis/images/testing/tiff/noise.pam b/basis/images/testing/tiff/noise.fig similarity index 98% rename from basis/images/testing/tiff/noise.pam rename to basis/images/testing/tiff/noise.fig index fd01a773bd..dd582aaef3 100644 Binary files a/basis/images/testing/tiff/noise.pam and b/basis/images/testing/tiff/noise.fig differ diff --git a/basis/images/testing/tiff/octagon.fig b/basis/images/testing/tiff/octagon.fig new file mode 100644 index 0000000000..0b66c62662 Binary files /dev/null and b/basis/images/testing/tiff/octagon.fig differ diff --git a/basis/images/testing/tiff/octagon.pam b/basis/images/testing/tiff/octagon.pam deleted file mode 100644 index 536d068650..0000000000 Binary files a/basis/images/testing/tiff/octagon.pam and /dev/null differ diff --git a/basis/images/testing/tiff/rgb.fig b/basis/images/testing/tiff/rgb.fig new file mode 100644 index 0000000000..c09b1cd10e Binary files /dev/null and b/basis/images/testing/tiff/rgb.fig differ diff --git a/basis/images/tiff/tiff-tests.factor b/basis/images/tiff/tiff-tests.factor index 056ede350c..b0a036ae49 100755 --- a/basis/images/tiff/tiff-tests.factor +++ b/basis/images/tiff/tiff-tests.factor @@ -1,13 +1,11 @@ ! Copyright (C) 2009 Doug Coleman. ! See http://factorcode.org/license.txt for BSD license. -USING: accessors images.testing images.tiff images.viewer io -io.encodings.binary io.files namespaces sequences tools.test -images.pam ; +USING: images.testing ; IN: images.tiff.tests "vocab:images/testing/tiff/octagon.tiff" decode-test -"vocab:images/testing/tiff/elephants.tiff" decode-test +! "vocab:images/testing/tiff/elephants.tiff" decode-test "vocab:images/testing/tiff/noise.tiff" decode-test "vocab:images/testing/tiff/alpha.tiff" decode-test "vocab:images/testing/tiff/color_spectrum.tiff" decode-test -! "vocab:images/testing/tiff/rgb.tiff" decode-test +"vocab:images/testing/tiff/rgb.tiff" decode-test diff --git a/extra/images/gif/gif-tests.factor b/extra/images/gif/gif-tests.factor index 9157bdad72..8c1add1c51 100644 --- a/extra/images/gif/gif-tests.factor +++ b/extra/images/gif/gif-tests.factor @@ -1,21 +1,16 @@ ! Copyright (C) 2009 Keith Lazuka. ! See http://factorcode.org/license.txt for BSD license. -USING: accessors bitstreams compression.lzw fry images.gif -images.loader images.testing images.viewer io -io.encodings.binary io.files io.pathnames kernel math -math.bitwise math.parser namespaces prettyprint quotations -sequences tools.test tools.test.private ; -QUALIFIED-WITH: bitstreams bs +USING: accessors compression.lzw images.gif images.testing io +io.encodings.binary io.files kernel math math.bitwise +namespaces sequences tools.test ; IN: images.gif.tests -verbose-tests? off "vocab:images/testing/gif/circle.gif" decode-test "vocab:images/testing/gif/checkmark.gif" decode-test "vocab:images/testing/gif/monochrome.gif" decode-test "vocab:images/testing/gif/alpha.gif" decode-test "vocab:images/testing/gif/noise.gif" decode-test "vocab:images/testing/gif/astronaut_animation.gif" decode-test -verbose-tests? on : path>gif ( path -- gif ) binary [ input-stream get load-gif ] with-file-reader ; diff --git a/extra/images/pam/pam-tests.factor b/extra/images/pam/pam-tests.factor deleted file mode 100644 index e8d52f87e2..0000000000 --- a/extra/images/pam/pam-tests.factor +++ /dev/null @@ -1,57 +0,0 @@ -! Copyright (C) 2009 Keith Lazuka. -! See http://factorcode.org/license.txt for BSD license. -USING: accessors byte-arrays images.loader images.pam -images.testing io io.encodings.binary io.files -io.streams.byte-array kernel quotations tools.test ; -IN: images.pam.tests - -! ----------- Encoder Tests ------------------------------ - -"vocab:images/testing/pam/rgb1x1.pam" pam-image encode-test -"vocab:images/testing/pam/rgba1x1.pam" pam-image encode-test -"vocab:images/testing/pam/rgb2x2.pam" pam-image encode-test -"vocab:images/testing/pam/rgba2x2.pam" pam-image encode-test -"vocab:images/testing/pam/rgb3x3.pam" pam-image encode-test -"vocab:images/testing/pam/rgba3x3.pam" pam-image encode-test - -! ----------- Decoder Tests ------------------------------ - -! 1x1 - -[ { 1 1 } ] [ "vocab:images/testing/pam/rgb1x1.pam" load-image dim>> ] unit-test - -[ B{ 0 0 0 } ] -[ "vocab:images/testing/pam/rgb1x1.pam" load-image bitmap>> ] unit-test - -[ B{ 0 0 0 0 } ] -[ "vocab:images/testing/pam/rgba1x1.pam" load-image bitmap>> ] unit-test - -! 2x2 - -[ { 2 2 } ] [ "vocab:images/testing/pam/rgb2x2.pam" load-image dim>> ] unit-test - -[ B{ 0 0 0 255 255 255 255 255 255 0 0 0 } ] -[ "vocab:images/testing/pam/rgb2x2.pam" load-image bitmap>> ] unit-test - -[ B{ 0 0 0 255 255 255 255 0 255 255 255 0 0 0 0 255 } ] -[ "vocab:images/testing/pam/rgba2x2.pam" load-image bitmap>> ] unit-test - -! 3x3 - -[ - B{ - 255 0 0 0 255 0 0 0 255 - 4 252 253 254 1 127 252 253 2 - 255 255 255 0 0 0 255 255 255 - } -] -[ "vocab:images/testing/pam/rgb3x3.pam" load-image bitmap>> ] unit-test - -[ - B{ - 255 0 0 255 0 255 0 255 0 0 255 255 - 4 252 253 255 254 1 127 255 252 253 2 255 - 255 255 255 255 0 0 0 255 255 255 255 0 - } -] -[ "vocab:images/testing/pam/rgba3x3.pam" load-image bitmap>> ] unit-test diff --git a/extra/images/pam/pam.factor b/extra/images/pam/pam.factor deleted file mode 100644 index 6e60f13366..0000000000 --- a/extra/images/pam/pam.factor +++ /dev/null @@ -1,99 +0,0 @@ -! Copyright (C) 2009 Keith Lazuka. -! See http://factorcode.org/license.txt for BSD license. -USING: accessors arrays combinators fry grouping images -images.loader io io.encodings io.encodings.ascii -io.encodings.binary io.files io.files.temp kernel math -math.parser prettyprint sequences splitting ; -IN: images.pam - -SINGLETON: pam-image -"pam" pam-image register-image-class - -: output-pam-header ( note num-channels width height -- ) - ascii [ - "P7" print - "HEIGHT " write pprint nl - "WIDTH " write pprint nl - "MAXVAL 255" print - "DEPTH " write pprint nl - "TUPLTYPE " prepend print - "ENDHDR" print - ] with-encoded-output ; inline - -: output-pam ( note num-channels width height pixels -- ) - [ output-pam-header ] dip write ; - -: verify-bitmap-format ( image -- ) - [ component-type>> ubyte-components assert= ] - [ component-order>> { RGB RGBA } memq? [ - "PAM encode: component-order must be RGB or RGBA!" throw - ] unless ] bi ; - -GENERIC: TUPLTYPE ( component-order -- str ) -M: component-order TUPLTYPE name>> ; -M: RGBA TUPLTYPE drop "RGB_ALPHA" ; - -M: pam-image image>stream - drop { - [ verify-bitmap-format ] - [ component-order>> [ TUPLTYPE ] [ component-count ] bi ] - [ dim>> first2 ] - [ bitmap>> ] - } cleave output-pam ; - -! PAM Decoder - -TUPLE: loading-pam width height depth maxval tupltype bitmap ; - -: ?glue ( seq1 seq2 seq3 -- seq ) - pick empty? [ drop nip ] [ glue ] if ; - -: append-tupltype ( pam tupltype -- pam ) - '[ _ " " ?glue ] change-tupltype ; - -: read-header-lines ( pam -- pam ) - readln " " split unclip swap " " join swap { - { "ENDHDR" [ drop ] } - { "HEIGHT" [ string>number >>height read-header-lines ] } - { "WIDTH" [ string>number >>width read-header-lines ] } - { "DEPTH" [ string>number >>depth read-header-lines ] } - { "MAXVAL" [ string>number >>maxval read-header-lines ] } - { "TUPLTYPE" [ append-tupltype read-header-lines ] } - [ 2drop read-header-lines ] - } case ; - -: read-header ( pam -- pam ) - ascii [ - readln "P7" assert= - read-header-lines - ] with-decoded-input ; - -: bytes-per-pixel ( pam -- n ) - [ depth>> ] [ maxval>> 256 < 1 2 ? ] bi * ; - -: bitmap-length ( pam -- num-bytes ) - [ width>> ] [ height>> ] [ bytes-per-pixel ] tri * * ; - -: read-bitmap ( pam -- pam ) - dup bitmap-length read >>bitmap ; - -: load-pam ( stream -- pam ) - [ loading-pam new read-header read-bitmap ] with-input-stream ; - -: tupltype>component-order ( pam -- component-order ) - tupltype>> dup { - { "RGB_ALPHA" [ drop RGBA ] } - { "RGBA" [ drop RGBA ] } - { "RGB" [ drop RGB ] } - [ "Cannot determine component-order from TUPLTYPE " prepend throw ] - } case ; - -: pam>image ( pam -- image ) - [ ] dip { - [ [ width>> ] [ height>> ] bi 2array >>dim ] - [ tupltype>component-order >>component-order ] - [ drop ubyte-components >>component-type ] - [ bitmap>> >>bitmap ] - } cleave ; - -M: pam-image stream>image drop load-pam pam>image ;