! Copyright (C) 2010 Gert Meulyzer. ! See http://factorcode.org/license.txt for BSD license. ! using dynamic variables this time USING: accessors combinators command-line grouping images images.bitmap images.loader images.png io io.binary io.encodings.binary io.files io.pathnames kernel math namespaces sequences ; IN: imagecompare ERROR: not-same-resolution ; SYMBOLS: bpp img1 img2 new-image new-name ; : create-output-name ( x x -- x ) [ file-stem ] bi@ "_" glue ".bmp" append ; : save-output-name ( x x -- x x ) 2dup create-output-name new-name set ; : load-imgs ( imgpath1 imgpath2 -- ) save-output-name [ load-image ] bi@ img2 set img1 set ; : same-res? ( -- ? ) img1 get img2 get [ dim>> ] bi@ = ; : create-new ( -- ) img2 get { [ dim>> ] [ component-order>> ] [ component-type>> ] [ upside-down?>> ] } cleave f image boa new-image set ; : to-groups ( -- g1 g2 ) img1 get img2 get [ [ bitmap>> ] [ bytes-per-pixel ] bi ] bi@ ; : compare ( g1 g2 -- ) [ [ le> ] bi@ - 3 >le ] 2map concat new-image get swap >>bitmap drop ; : write-new-img ( -- ) new-image get new-name get binary [ output-bmp ] with-file-writer ; : do-comparison ( -- ) create-new to-groups compare write-new-img ; : go ( x -- ) first2 load-imgs same-res? [ do-comparison ] [ not-same-resolution throw ] if ; : cmdgo ( -- ) (command-line) go ; MAIN: cmdgo