2009-09-30 13:33:10 -04:00
|
|
|
! Copyright (C) 2009 Keith Lazuka.
|
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
2010-09-19 22:54:04 -04:00
|
|
|
USING: accessors fry images images.loader images.normalization
|
|
|
|
images.viewer io io.backend io.directories io.encodings.binary
|
|
|
|
io.files io.pathnames io.streams.byte-array kernel locals
|
|
|
|
namespaces quotations random sequences serialize tools.test ;
|
2009-09-30 13:33:10 -04:00
|
|
|
IN: images.testing
|
|
|
|
|
2009-09-30 16:35:51 -04:00
|
|
|
<PRIVATE
|
|
|
|
|
2009-10-08 06:23:17 -04:00
|
|
|
: fig-name ( path -- newpath )
|
2009-10-28 18:25:50 -04:00
|
|
|
[ parent-directory normalize-path ]
|
2009-10-08 06:23:17 -04:00
|
|
|
[ file-stem ".fig" append ] bi
|
2009-09-30 16:35:51 -04:00
|
|
|
append-path ;
|
|
|
|
|
2009-10-08 06:23:17 -04:00
|
|
|
PRIVATE>
|
|
|
|
|
2009-10-08 12:06:18 -04:00
|
|
|
:: with-matching-files ( dirpath extension quot -- )
|
|
|
|
dirpath [
|
|
|
|
[
|
|
|
|
dup file-extension extension = quot [ drop ] if
|
|
|
|
] each
|
|
|
|
] with-directory-files ; inline
|
|
|
|
|
|
|
|
: images. ( dirpath extension -- )
|
|
|
|
[ image. ] with-matching-files ;
|
|
|
|
|
|
|
|
: ls ( dirpath extension -- )
|
|
|
|
[ "\"" dup surround print ] with-matching-files ;
|
|
|
|
|
2009-09-30 16:35:51 -04:00
|
|
|
: save-as-reference-image ( path -- )
|
2009-10-08 06:23:17 -04:00
|
|
|
[ load-image ] [ fig-name ] bi
|
|
|
|
binary [ serialize ] with-file-writer ;
|
2009-09-30 16:35:51 -04:00
|
|
|
|
2009-10-08 12:06:18 -04:00
|
|
|
: save-all-as-reference-images ( dirpath extension -- )
|
|
|
|
[ save-as-reference-image ] with-matching-files ;
|
|
|
|
|
2009-10-08 06:23:17 -04:00
|
|
|
: 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 ;
|
2009-09-30 16:35:51 -04:00
|
|
|
|
|
|
|
: decode-test ( path -- )
|
2009-10-02 17:20:33 -04:00
|
|
|
f verbose-tests? [
|
|
|
|
[ load-image 1quotation ]
|
2009-10-08 06:23:17 -04:00
|
|
|
[ '[ _ load-reference-image ] ] bi
|
2009-10-02 17:20:33 -04:00
|
|
|
unit-test
|
|
|
|
] with-variable ;
|
2010-09-19 22:54:04 -04:00
|
|
|
|
|
|
|
: <rgb-image> ( -- image )
|
|
|
|
<image>
|
|
|
|
RGB >>component-order
|
|
|
|
ubyte-components >>component-type ; inline
|
|
|
|
|
|
|
|
: randomize-image ( image -- image )
|
|
|
|
dup bytes-per-image random-bytes >>bitmap ;
|