Merge branch 'master' of git://github.com/glguy/factor

db4
Slava Pestov 2008-11-10 00:30:27 -06:00
commit 4d317e2d46
7 changed files with 101 additions and 29 deletions
basis
io/windows/files
tools/deploy/windows

2
basis/io/windows/files/files.factor Normal file → Executable file
View File

@ -276,7 +276,7 @@ M: winnt file-system-info ( path -- file-system-info )
swap >>type
swap >>mount-point ;
: find-first-volume ( word -- string handle )
: find-first-volume ( -- string handle )
MAX_PATH 1+ <byte-array> dup length
dupd
FindFirstVolume dup win32-error=0/f

View File

@ -9,16 +9,14 @@ IN: tools.deploy.windows
"resource:factor.dll" swap copy-file-into ;
: copy-freetype ( bundle-name -- )
deploy-ui? get [
{
"resource:freetype6.dll"
"resource:zlib1.dll"
} swap copy-files-into
] [ drop ] if ;
{
"resource:freetype6.dll"
"resource:zlib1.dll"
} swap copy-files-into ;
: create-exe-dir ( vocab bundle-name -- vm )
dup copy-dll
deploy-ui? get [
dup copy-dll
dup copy-freetype
dup "" copy-fonts
] when
@ -26,14 +24,14 @@ IN: tools.deploy.windows
M: winnt deploy*
"resource:" [
deploy-name over deploy-config at
[
{
dup deploy-config [
deploy-name get
[
[ create-exe-dir ]
[ image-name ]
[ drop ]
[ drop deploy-config ]
} 2cleave make-deploy-image
]
[ nip open-in-explorer ] 2bi
2tri namespace make-deploy-image
]
[ nip open-in-explorer ] 2bi
] bind
] with-directory ;

View File

@ -5,7 +5,7 @@ USING: alien arrays byte-arrays combinators summary
io.backend graphics.viewer io io.binary io.files kernel libc
math math.functions namespaces opengl opengl.gl prettyprint
sequences strings ui ui.gadgets.panes io.encodings.binary
accessors ;
accessors grouping ;
IN: graphics.bitmap
! Currently can only handle 24bit bitmaps.
@ -23,16 +23,25 @@ TUPLE: bitmap magic size reserved offset header-length width
swap [ >>array ] [ >>color-index ] bi
24 >>bit-count ;
: raw-bitmap>string ( str n -- str )
: 8bit>array ( bitmap -- array )
[ rgb-quads>> 4 <sliced-groups> [ 3 head-slice ] map ]
[ color-index>> >array ] bi [ swap nth ] with map concat ;
: 4bit>array ( bitmap -- array )
[ rgb-quads>> 4 <sliced-groups> [ 3 head-slice ] map ]
[ color-index>> >array ] bi [ swap nth ] with map concat ;
: raw-bitmap>array ( bitmap -- array )
dup bit-count>>
{
{ 32 [ "32bit" throw ] }
{ 24 [ ] }
{ 24 [ color-index>> ] }
{ 16 [ "16bit" throw ] }
{ 8 [ "8bit" throw ] }
{ 4 [ "4bit" throw ] }
{ 8 [ 8bit>array ] }
{ 4 [ 4bit>array ] }
{ 2 [ "2bit" throw ] }
{ 1 [ "1bit" throw ] }
} case ;
} case >byte-array ;
ERROR: bitmap-magic ;
@ -72,13 +81,12 @@ M: bitmap-magic summary
: load-bitmap ( path -- bitmap )
normalize-path binary [
T{ bitmap } clone
dup parse-file-header
dup parse-bitmap-header
dup parse-bitmap
bitmap new
dup parse-file-header
dup parse-bitmap-header
dup parse-bitmap
] with-file-reader
dup color-index>> over bit-count>>
raw-bitmap>string >byte-array >>array ;
dup raw-bitmap>array >>array ;
: save-bitmap ( bitmap path -- )
binary [
@ -118,6 +126,8 @@ M: bitmap draw-image ( bitmap -- )
bit-count>> {
! { 32 [ GL_BGRA GL_UNSIGNED_INT_8_8_8_8 ] } ! broken
{ 24 [ GL_BGR GL_UNSIGNED_BYTE ] }
{ 8 [ GL_BGR GL_UNSIGNED_BYTE ] }
{ 4 [ GL_BGR GL_UNSIGNED_BYTE ] }
} case
] keep array>> glDrawPixels ;

View File

@ -6,3 +6,6 @@ USING: hexdump kernel sequences tools.test ;
[ t ] [ 256 [ ] map hexdump "Length: 256, 100h\n00000000h: 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f ................\n00000010h: 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f ................\n00000020h: 20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f !\"#$%&'()*+,-./\n00000030h: 30 31 32 33 34 35 36 37 38 39 3a 3b 3c 3d 3e 3f 0123456789:;<=>?\n00000040h: 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f @ABCDEFGHIJKLMNO\n00000050h: 50 51 52 53 54 55 56 57 58 59 5a 5b 5c 5d 5e 5f PQRSTUVWXYZ[\\]^_\n00000060h: 60 61 62 63 64 65 66 67 68 69 6a 6b 6c 6d 6e 6f `abcdefghijklmno\n00000070h: 70 71 72 73 74 75 76 77 78 79 7a 7b 7c 7d 7e 7f pqrstuvwxyz{|}~.\n00000080h: 80 81 82 83 84 85 86 87 88 89 8a 8b 8c 8d 8e 8f ................\n00000090h: 90 91 92 93 94 95 96 97 98 99 9a 9b 9c 9d 9e 9f ................\n000000a0h: a0 a1 a2 a3 a4 a5 a6 a7 a8 a9 aa ab ac ad ae af ................\n000000b0h: b0 b1 b2 b3 b4 b5 b6 b7 b8 b9 ba bb bc bd be bf ................\n000000c0h: c0 c1 c2 c3 c4 c5 c6 c7 c8 c9 ca cb cc cd ce cf ................\n000000d0h: d0 d1 d2 d3 d4 d5 d6 d7 d8 d9 da db dc dd de df ................\n000000e0h: e0 e1 e2 e3 e4 e5 e6 e7 e8 e9 ea eb ec ed ee ef ................\n000000f0h: f0 f1 f2 f3 f4 f5 f6 f7 f8 f9 fa fb fc fd fe ff ................\n" = ] unit-test
[
"Length: 3, 3h\n00000000h: 01 02 03 ...\n" ] [ B{ 1 2 3 } hexdump ] unit-test

View File

@ -21,9 +21,9 @@ IN: hexdump
[ >hex-digit ] { } map-as concat 48 CHAR: \s pad-right ;
: >ascii ( bytes -- str )
[ [ printable? ] keep CHAR: . ? ] map ;
[ [ printable? ] keep CHAR: . ? ] "" map-as ;
: write-hex-line ( str lineno -- )
: write-hex-line ( bytes lineno -- )
write-offset [ >hex-digits write ] [ >ascii write ] bi nl ;
PRIVATE>

View File

@ -0,0 +1,5 @@
USING: project-euler.215 tools.test ;
IN: project-euler.215.tests
[ 8 ] [ 9 3 solve ] unit-test
[ 806844323190414 ] [ euler215 ] unit-test

View File

@ -0,0 +1,56 @@
USING: accessors kernel locals math ;
IN: project-euler.215
TUPLE: block two three ;
TUPLE: end { ways integer } ;
C: <block> block
C: <end> end
: <failure> 0 <end> ; inline
: <success> 1 <end> ; inline
: failure? ( t -- ? ) ways>> 0 = ; inline
: choice ( t p q -- t t ) [ [ two>> ] [ three>> ] bi ] 2dip bi* ; inline
GENERIC: merge ( t t -- t )
GENERIC# block-merge 1 ( t t -- t )
GENERIC# end-merge 1 ( t t -- t )
M: block merge block-merge ;
M: end merge end-merge ;
M: block block-merge [ [ two>> ] bi@ merge ]
[ [ three>> ] bi@ merge ] 2bi <block> ;
M: end block-merge nip ;
M: block end-merge drop ;
M: end end-merge [ ways>> ] bi@ + <end> ;
GENERIC: h-1 ( t -- t )
GENERIC: h0 ( t -- t )
GENERIC: h1 ( t -- t )
GENERIC: h2 ( t -- t )
M: block h-1 [ h1 ] [ h2 ] choice merge ;
M: block h0 drop <failure> ;
M: block h1 [ [ h1 ] [ h2 ] choice merge ]
[ [ h0 ] [ h1 ] choice merge ] bi <block> ;
M: block h2 [ h1 ] [ h2 ] choice merge <failure> swap <block> ;
M: end h-1 drop <failure> ;
M: end h0 ;
M: end h1 drop <failure> ;
M: end h2 dup failure? [ <failure> <block> ] unless ;
: next-row ( t -- t ) [ h-1 ] [ h1 ] choice swap <block> ;
: first-row ( n -- t )
[ <failure> <success> <failure> ] dip
1- [| a b c | b c <block> a b ] times 2drop ;
GENERIC: total ( t -- n )
M: block total [ total ] dup choice + ;
M: end total ways>> ;
: solve ( width height -- ways )
[ first-row ] dip 1- [ next-row ] times total ;
: euler215 ( -- ways ) 32 10 solve ;