1 ! Copyright (C) 2009 Keith Lazuka.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors arrays fry 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 locals namespaces quotations random sequences serialize
12 : fig-name ( path -- newpath )
13 [ parent-directory normalize-path ]
14 [ file-stem ".fig" append ] bi
19 :: with-matching-files ( dirpath extension quot -- )
22 dup file-extension extension = quot [ drop ] if
24 ] with-directory-files ; inline
26 : images. ( dirpath extension -- )
27 [ image. ] with-matching-files ;
29 : ls ( dirpath extension -- )
30 [ "\"" 1surround print ] with-matching-files ;
32 : save-as-reference-image ( path -- )
33 [ load-image ] [ fig-name ] bi
34 binary [ serialize ] with-file-writer ;
36 : save-all-as-reference-images ( dirpath extension -- )
37 [ save-as-reference-image ] with-matching-files ;
39 : load-reference-image ( path -- image )
40 fig-name binary [ deserialize ] with-file-reader ;
42 :: encode-test ( path image-class -- )
44 path image-class load-image*
45 [ clone normalize-image 1array ] keep
48 _ path file-extension image-class image>stream
49 ] with-byte-writer image-class load-image* normalize-image
53 :: decode-test ( path image-class -- )
55 path image-class load-image* 1array
56 [ path load-reference-image ]
60 : <rgb-image> ( -- image )
63 ubyte-components >>component-type ; inline
65 : randomize-image ( image -- image )
66 dup bytes-per-image random-bytes >>bitmap ;
68 : image-load-must-fail ( path image-class -- )
69 '[ _ _ load-image* ] must-fail ;