Bitmap/Read a PPM file: Difference between revisions

→‎{{header|J}}: simplify and reuse verbs from Basic bitmap storage
(add Ruby)
(→‎{{header|J}}: simplify and reuse verbs from Basic bitmap storage)
Line 503:
=={{header|J}}==
'''Solution:'''
Uses <tt>makeRGB</tt> from [[Basic bitmap storage#J|Basic bitmap storage]].
<lang j>
require 'files'
Line 508 ⟶ 509:
readppm=: monad define
dat=. fread y NB. read from file
't shapewbyh maxval dat'=. 4{. <;._2 (, LF -. {:) dat NB. parse
shape'wbyh maxval'=. |. _99&". shape &.> wbyh;maxval NB. convert to numeric and reverse
if. (_99 e. wbyh,maxval=) +. t -.@-: _99"'P6' do. maxval_1 return. end.
(shape , 3) $ a. i. dat) makeRGB |.wbyh NB. convert to basic bitmap format
if. (_99 e. shape,maxval) +. t -.@-: 'P6' do. _1 return. end.
(shape , 3) $ a. i. dat NB. convert to basic bitmap format
)
</lang>
892

edits