Merge branch 'master' of git://factorcode.org/git/factor into clean-linux-x86-32

db4
Maxim Savchenko 2009-04-09 03:57:08 -04:00
commit 4f1e24d74b
5 changed files with 68 additions and 32 deletions

View File

@ -1,6 +1,6 @@
USING: images.bitmap images.viewer io.encodings.binary USING: images.bitmap images.viewer io.encodings.binary
io.files io.files.unique kernel tools.test images.loader io.files io.files.unique kernel tools.test images.loader
literals sequences ; literals sequences checksums.md5 checksums ;
IN: images.bitmap.tests IN: images.bitmap.tests
CONSTANT: test-bitmap24 "vocab:images/test-images/thiswayup24.bmp" CONSTANT: test-bitmap24 "vocab:images/test-images/thiswayup24.bmp"
@ -11,6 +11,11 @@ CONSTANT: test-bitmap4 "vocab:images/test-images/rgb4bit.bmp"
CONSTANT: test-bitmap1 "vocab:images/test-images/1bit.bmp" CONSTANT: test-bitmap1 "vocab:images/test-images/1bit.bmp"
CONSTANT: test-40 "vocab:images/test-images/40red24bit.bmp"
CONSTANT: test-41 "vocab:images/test-images/41red24bit.bmp"
CONSTANT: test-42 "vocab:images/test-images/42red24bit.bmp"
CONSTANT: test-43 "vocab:images/test-images/43red24bit.bmp"
[ t ] [ t ]
[ [
test-bitmap24 test-bitmap24
@ -25,3 +30,22 @@ CONSTANT: test-bitmap1 "vocab:images/test-images/1bit.bmp"
$ test-bitmap24 $ test-bitmap24
"vocab:ui/render/test/reference.bmp" "vocab:ui/render/test/reference.bmp"
} [ [ ] swap [ load-image drop ] curry unit-test ] each } [ [ ] swap [ load-image drop ] curry unit-test ] each
: test-bitmap-save ( path -- ? )
[ md5 checksum-file ]
[ load-image ] bi
"bitmap-save-test" unique-file
[ save-bitmap ]
[ md5 checksum-file ] bi = ;
[
t
] [
{
$ test-40
$ test-41
$ test-42
$ test-43
} [ test-bitmap-save ] all?
] unit-test

View File

@ -37,14 +37,14 @@ M: bitmap-magic summary
ERROR: bmp-not-supported n ; ERROR: bmp-not-supported n ;
: reverse-lines ( byte-array width -- byte-array ) : reverse-lines ( byte-array width -- byte-array )
3 * <sliced-groups> <reversed> concat ; inline <sliced-groups> <reversed> concat ; inline
: raw-bitmap>seq ( loading-bitmap -- array ) : raw-bitmap>seq ( loading-bitmap -- array )
dup bit-count>> dup bit-count>>
{ {
{ 32 [ color-index>> ] } { 32 [ color-index>> ] }
{ 24 [ [ color-index>> ] [ width>> ] bi reverse-lines ] } { 24 [ [ color-index>> ] [ width>> 3 * ] bi reverse-lines ] }
{ 8 [ [ 8bit>buffer ] [ width>> ] bi reverse-lines ] } { 8 [ [ 8bit>buffer ] [ width>> 3 * ] bi reverse-lines ] }
[ bmp-not-supported ] [ bmp-not-supported ]
} case >byte-array ; } case >byte-array ;
@ -81,30 +81,31 @@ ERROR: bmp-not-supported n ;
: image-size ( loading-bitmap -- n ) : image-size ( loading-bitmap -- n )
[ [ width>> ] [ height>> ] bi * ] [ bit-count>> 8 /i ] bi * abs ; [ [ width>> ] [ height>> ] bi * ] [ bit-count>> 8 /i ] bi * abs ;
: bitmap-padding ( width -- n )
3 * 4 mod 4 swap - 4 mod ; inline
:: fixup-color-index ( loading-bitmap -- loading-bitmap ) :: fixup-color-index ( loading-bitmap -- loading-bitmap )
loading-bitmap width>> :> width loading-bitmap width>> :> width
width 3 * :> width*3 width 3 * :> width*3
loading-bitmap height>> abs :> height loading-bitmap width>> bitmap-padding :> padding
loading-bitmap color-index>> length :> color-index-length loading-bitmap [ color-index>> length ] [ height>> abs ] bi /i :> stride
color-index-length height /i :> stride loading-bitmap
color-index-length width*3 height * - height /i :> padding
padding 0 > [ padding 0 > [
loading-bitmap [ [
stride <sliced-groups> stride <sliced-groups>
[ width*3 head-slice ] map concat [ width*3 head-slice ] map concat
] change-color-index ] change-color-index
] [ ] when ;
loading-bitmap
] if ;
: parse-bitmap ( loading-bitmap -- loading-bitmap ) : parse-bitmap ( loading-bitmap -- loading-bitmap )
dup rgb-quads-length read >>rgb-quads dup rgb-quads-length read >>rgb-quads
dup color-index-length read >>color-index dup color-index-length read >>color-index
fixup-color-index ; fixup-color-index ;
: load-bitmap-data ( path loading-bitmap -- loading-bitmap ) : load-bitmap-data ( path -- loading-bitmap )
[ binary ] dip '[ binary [
_ parse-file-header parse-bitmap-header parse-bitmap loading-bitmap new
parse-file-header parse-bitmap-header parse-bitmap
] with-file-reader ; ] with-file-reader ;
ERROR: unknown-component-order bitmap ; ERROR: unknown-component-order bitmap ;
@ -117,8 +118,7 @@ ERROR: unknown-component-order bitmap ;
[ unknown-component-order ] [ unknown-component-order ]
} case ; } case ;
: loading-bitmap>bitmap-image ( loading-bitmap -- bitmap-image ) : loading-bitmap>bitmap-image ( bitmap-image loading-bitmap -- bitmap-image )
[ bitmap-image new ] dip
{ {
[ raw-bitmap>seq >>bitmap ] [ raw-bitmap>seq >>bitmap ]
[ [ width>> ] [ height>> abs ] bi 2array >>dim ] [ [ width>> ] [ height>> abs ] bi 2array >>dim ]
@ -127,20 +127,30 @@ ERROR: unknown-component-order bitmap ;
} cleave ; } cleave ;
M: bitmap-image load-image* ( path loading-bitmap -- bitmap ) M: bitmap-image load-image* ( path loading-bitmap -- bitmap )
drop loading-bitmap new swap load-bitmap-data loading-bitmap>bitmap-image ;
load-bitmap-data
loading-bitmap>bitmap-image ;
PRIVATE> PRIVATE>
: bitmap>color-index ( bitmap-array -- byte-array ) : bitmap>color-index ( bitmap -- byte-array )
4 <sliced-groups> [ 3 head-slice <reversed> ] map B{ } join ; inline [
bitmap>>
4 <sliced-groups>
[ 3 head-slice <reversed> ] map
B{ } join
] [
dim>> first dup bitmap-padding dup 0 > [
[ 3 * group ] dip '[ _ <byte-array> append ] map
B{ } join
] [
2drop
] if
] bi ;
: save-bitmap ( image path -- ) : save-bitmap ( image path -- )
binary [ binary [
B{ CHAR: B CHAR: M } write B{ CHAR: B CHAR: M } write
[ [
bitmap>> bitmap>color-index length 14 + 40 + write4 bitmap>color-index length 14 + 40 + write4
0 write4 0 write4
54 write4 54 write4
40 write4 40 write4
@ -159,7 +169,7 @@ PRIVATE>
[ drop 0 write4 ] [ drop 0 write4 ]
! size-image ! size-image
[ bitmap>> bitmap>color-index length write4 ] [ bitmap>color-index length write4 ]
! x-pels ! x-pels
[ drop 0 write4 ] [ drop 0 write4 ]
@ -175,7 +185,9 @@ PRIVATE>
! rgb-quads ! rgb-quads
[ [
[ bitmap>> bitmap>color-index ] [ dim>> first ] bi [ bitmap>color-index ]
[ dim>> first 3 * ]
[ dim>> first bitmap-padding + ] tri
reverse-lines write reverse-lines write
] ]
} cleave } cleave

View File

@ -62,8 +62,8 @@ HELP: current-temporary-directory
HELP: unique-file HELP: unique-file
{ $values { $values
{ "prefix" string }
{ "path" "a pathname string" } { "path" "a pathname string" }
{ "path'" "a pathname string" }
} }
{ $description "Creates a temporary file in the directory stored in " { $link current-temporary-directory } " and outputs the path name." } ; { $description "Creates a temporary file in the directory stored in " { $link current-temporary-directory } " and outputs the path name." } ;

View File

@ -64,7 +64,7 @@ PRIVATE>
[ unique-directory ] dip [ unique-directory ] dip
'[ _ with-temporary-directory ] [ delete-tree ] bi ; inline '[ _ with-temporary-directory ] [ delete-tree ] bi ; inline
: unique-file ( path -- path' ) : unique-file ( prefix -- path )
"" make-unique-file ; "" make-unique-file ;
{ {

View File

@ -59,10 +59,10 @@ TUPLE: script-string font string metrics ssa size image disposed ;
ssa>> ! ssa ssa>> ! ssa
0 ! iX 0 ! iX
0 ! iY 0 ! iY
0 ! uOptions ETO_OPAQUE ! uOptions
f ! prc
] ]
[ selection-start/end ] bi [ [ { 0 0 } ] dip size>> <RECT> ]
[ selection-start/end ] tri
! iMinSel ! iMinSel
! iMaxSel ! iMaxSel
FALSE ! fDisabled FALSE ! fDisabled
@ -108,7 +108,7 @@ M: script-string dispose*
SYMBOL: cached-script-strings SYMBOL: cached-script-strings
: cached-script-string ( string font -- script-string ) : cached-script-string ( font string -- script-string )
cached-script-strings get-global [ <script-string> ] 2cache ; cached-script-strings get-global [ <script-string> ] 2cache ;
[ <cache-assoc> cached-script-strings set-global ] [ <cache-assoc> cached-script-strings set-global ]