Handbook
Glossary
read-pgm ( -- image )
Vocabulary
images
.
pgm
Inputs
None
Outputs
image
an
object
Definition
USING:
accessors
combinators
images
io
kernel
make
math
specialized-arrays.instances.alien.c-types.ushort
;
IN:
images.pgm
::
read-pgm
( -- image )
read-token
:>
type
read-number
:>
width
read-number
:>
height
read-number
:>
max width height
*
:>
npixels max 256
>=
:>
wide type
{
{
"P2"
[
[
0 npixels
read-numbers
]
wide
[
ushort-array{
}
]
[
B{
}
]
if
make
]
}
{
"P5"
[
wide
[
2
]
[
1
]
if
npixels
*
read
]
}
}
case
:>
data
image
new
L
>>component-order
{
width height
}
>>dim
f
>>upside-down?
data
>>bitmap
wide
[
ushort-components
]
[
ubyte-components
]
if
>>component-type
;