Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
38
Task/Bitmap-Read-a-PPM-file/Forth/bitmap-read-a-ppm-file.fth
Normal file
38
Task/Bitmap-Read-a-PPM-file/Forth/bitmap-read-a-ppm-file.fth
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
: read-ppm { fid -- bmp }
|
||||
pad dup 80 fid read-line throw 0= abort" Partial line"
|
||||
s" P6" compare abort" Only P6 supported."
|
||||
pad dup 80 fid read-line throw 0= abort" Partial line"
|
||||
0. 2swap >number
|
||||
1 /string \ skip space
|
||||
0. 2swap >number
|
||||
2drop drop nip ( w h )
|
||||
bitmap { bmp }
|
||||
pad dup 80 fid read-line throw 0= abort" Partial line"
|
||||
s" 255" compare abort" Only 8-bits per color channel supported"
|
||||
0 pad !
|
||||
bmp bdim
|
||||
0 do
|
||||
dup 0 do
|
||||
pad 3 fid read-file throw
|
||||
3 - abort" Not enough pixel data in file"
|
||||
pad @ i j bmp b!
|
||||
loop
|
||||
loop drop
|
||||
bmp ;
|
||||
|
||||
\ testing round-trip
|
||||
4 3 bitmap value test
|
||||
red test bfill
|
||||
green 1 2 test b!
|
||||
|
||||
s" red.ppm" w/o create-file throw
|
||||
test over write-ppm
|
||||
close-file throw
|
||||
|
||||
s" red.ppm" r/o open-file throw
|
||||
dup read-ppm value test2
|
||||
close-file throw
|
||||
|
||||
: bsize ( bmp -- len ) bdim * pixels bdata ;
|
||||
|
||||
test dup bsize test2 dup bsize compare . \ 0 if identical
|
||||
Loading…
Add table
Add a link
Reference in a new issue