1 ! Copyright (C) 2009 Keith Lazuka.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors arrays images images.loader
4 images.normalization images.viewer io io.backend io.directories
5 io.encodings.binary io.files io.pathnames io.streams.byte-array
6 kernel namespaces random sequences serialize tools.test ;
11 : fig-name ( path -- newpath )
12 [ parent-directory normalize-path ]
13 [ file-stem ".fig" append ] bi
18 :: with-matching-files ( dirpath extension quot -- )
21 dup file-extension extension = quot [ drop ] if
23 ] with-directory-files ; inline
25 : images. ( dirpath extension -- )
26 [ image. ] with-matching-files ;
28 : ls ( dirpath extension -- )
29 [ "\"" 1surround print ] with-matching-files ;
31 : save-as-reference-image ( path -- )
32 [ load-image ] [ fig-name ] bi
33 binary [ serialize ] with-file-writer ;
35 : save-all-as-reference-images ( dirpath extension -- )
36 [ save-as-reference-image ] with-matching-files ;
38 : load-reference-image ( path -- image )
39 fig-name binary [ deserialize ] with-file-reader ;
41 :: encode-test ( path image-class -- )
43 path image-class load-image*
44 [ clone normalize-image 1array ] keep
47 _ path file-extension image-class image>stream
48 ] with-byte-writer image-class load-image* normalize-image
52 :: decode-test ( path image-class -- )
54 path image-class load-image* 1array
55 [ path load-reference-image ]
59 : <rgb-image> ( -- image )
62 ubyte-components >>component-type ; inline
64 : randomize-image ( image -- image )
65 dup bytes-per-image random-bytes >>bitmap ;
67 : image-load-must-fail ( path image-class -- )
68 '[ _ _ load-image* ] must-fail ;