2009-09-23 12:06:49 -04:00
|
|
|
! Copyright (C) 2009 Keith Lazuka.
|
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
2009-09-25 16:51:47 -04:00
|
|
|
USING: accessors bitstreams compression.lzw images.gif io
|
2009-09-24 14:54:35 -04:00
|
|
|
io.encodings.binary io.files kernel math math.bitwise
|
2009-09-25 09:34:29 -04:00
|
|
|
math.parser namespaces prettyprint sequences tools.test images.viewer ;
|
2009-09-24 14:54:35 -04:00
|
|
|
QUALIFIED-WITH: bitstreams bs
|
2009-09-23 12:06:49 -04:00
|
|
|
IN: images.gif.tests
|
|
|
|
|
|
|
|
: path>gif ( path -- loading-gif )
|
|
|
|
binary [ input-stream get load-gif ] with-file-reader ;
|
|
|
|
|
|
|
|
: gif-example1 ( -- loading-gif )
|
2009-09-25 09:34:29 -04:00
|
|
|
"resource:extra/images/testing/circle.gif" path>gif ;
|
2009-09-23 12:06:49 -04:00
|
|
|
|
|
|
|
: gif-example2 ( -- loading-gif )
|
2009-09-25 09:34:29 -04:00
|
|
|
"resource:extra/images/testing/checkmark.gif" path>gif ;
|
2009-09-23 12:06:49 -04:00
|
|
|
|
|
|
|
: gif-example3 ( -- loading-gif )
|
|
|
|
"resource:extra/images/testing/monochrome.gif" path>gif ;
|
|
|
|
|
2009-09-24 14:54:35 -04:00
|
|
|
: gif-example4 ( -- loading-gif )
|
|
|
|
"resource:extra/images/testing/noise.gif" path>gif ;
|
|
|
|
|
2009-09-25 09:34:29 -04:00
|
|
|
: gif-example5 ( -- loading-gif )
|
|
|
|
"resource:extra/images/testing/alpha.gif" path>gif ;
|
|
|
|
|
|
|
|
: gif-example6 ( -- loading-gif )
|
|
|
|
"resource:extra/images/testing/astronaut_animation.gif" path>gif ;
|
|
|
|
|
|
|
|
: gif-all. ( -- )
|
|
|
|
{
|
|
|
|
gif-example1 gif-example2 gif-example3 gif-example4 gif-example5
|
|
|
|
gif-example6
|
|
|
|
}
|
2009-09-26 13:15:58 -04:00
|
|
|
[ execute( -- gif ) gif>image image. ] each ;
|
2009-09-25 09:34:29 -04:00
|
|
|
|
2009-09-23 12:06:49 -04:00
|
|
|
: declared-num-colors ( gif -- n ) flags>> 3 bits 1 + 2^ ;
|
2009-09-25 09:34:29 -04:00
|
|
|
: actual-num-colors ( gif -- n ) global-color-table>> length ;
|
2009-09-23 12:06:49 -04:00
|
|
|
|
|
|
|
[ 16 ] [ gif-example1 actual-num-colors ] unit-test
|
|
|
|
[ 16 ] [ gif-example1 declared-num-colors ] unit-test
|
|
|
|
|
|
|
|
[ 256 ] [ gif-example2 actual-num-colors ] unit-test
|
|
|
|
[ 256 ] [ gif-example2 declared-num-colors ] unit-test
|
|
|
|
|
|
|
|
[ 2 ] [ gif-example3 actual-num-colors ] unit-test
|
|
|
|
[ 2 ] [ gif-example3 declared-num-colors ] unit-test
|
2009-09-24 14:54:35 -04:00
|
|
|
|
|
|
|
: >index-stream ( gif -- seq )
|
2009-09-25 11:12:40 -04:00
|
|
|
[ compressed-bytes>> ]
|
|
|
|
[ image-descriptor>> first-code-size>> ] bi
|
2009-09-25 16:51:47 -04:00
|
|
|
gif-lzw-uncompress ;
|
2009-09-24 14:54:35 -04:00
|
|
|
|
|
|
|
[
|
|
|
|
BV{
|
|
|
|
0 0 0 0 0 0
|
|
|
|
1 0 0 0 0 1
|
|
|
|
1 1 0 0 1 1
|
|
|
|
1 1 1 1 1 1
|
|
|
|
1 0 1 1 0 1
|
|
|
|
1 0 0 0 0 1
|
|
|
|
}
|
|
|
|
] [ gif-example3 >index-stream ] unit-test
|
|
|
|
|
2009-09-25 09:34:29 -04:00
|
|
|
[
|
|
|
|
B{
|
|
|
|
255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255
|
|
|
|
0 0 0 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 0 0 0 255
|
|
|
|
0 0 0 255 0 0 0 255 255 255 255 255 255 255 255 255 0 0 0 255 0 0 0 255
|
|
|
|
0 0 0 255 0 0 0 255 0 0 0 255 0 0 0 255 0 0 0 255 0 0 0 255
|
|
|
|
0 0 0 255 255 255 255 255 0 0 0 255 0 0 0 255 255 255 255 255 0 0 0 255
|
|
|
|
0 0 0 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 0 0 0 255
|
|
|
|
}
|
2009-09-26 13:15:58 -04:00
|
|
|
] [ gif-example3 gif>image bitmap>> ] unit-test
|
2009-09-25 09:34:29 -04:00
|
|
|
|
|
|
|
[
|
|
|
|
BV{
|
|
|
|
0 1
|
|
|
|
1 0
|
|
|
|
}
|
|
|
|
] [ gif-example5 >index-stream ] unit-test
|
|
|
|
|
|
|
|
[
|
|
|
|
B{
|
|
|
|
255 000 000 255 000 000 000 000
|
|
|
|
000 000 000 000 255 000 000 255
|
|
|
|
}
|
2009-09-26 13:15:58 -04:00
|
|
|
] [ gif-example5 gif>image bitmap>> ] unit-test
|
2009-09-25 09:34:29 -04:00
|
|
|
|
|
|
|
[ 100 ] [ gif-example1 >index-stream length ] unit-test
|
|
|
|
[ 870 ] [ gif-example2 >index-stream length ] unit-test
|
|
|
|
[ 16384 ] [ gif-example4 >index-stream length ] unit-test
|
2009-09-24 14:54:35 -04:00
|
|
|
|
2009-09-25 09:34:29 -04:00
|
|
|
! example6 is a GIF animation and the first frame contains 1768 pixels
|
|
|
|
[ 1768 ] [ gif-example6 >index-stream length ] unit-test
|