Documention for: oneliner-image-to-pgm.r Created by: vincentecuye on: 29-Jan-2013 Last updated by: vincentecuye on: 29-Jan-2013 Format: text/editable Downloaded on: 30-Apr-2025 oneliner-image-to-pgm.r Author: Vincent Ecuyer Date: 30-Jan-2013 ===to-pgm ---Purpose Short code to save an rgb channel from an image! as a gray image in PGM binary (P5) format. It's mostly useful for interacting with the Netpbm tools. ---Usage to-pgm value (image!) channel ('r, 'g, or 'b) ---Example In REBOL 2: write/binary %imageTest-red.pgm to-pgm logo.gif 'r write/binary %imageTest-green.pgm to-pgm logo.gif 'g write/binary %imageTest-blue.pgm to-pgm logo.gif 'b In REBOL 3, 'write is always in binary: write %imageTest.pgm to-pgm make image! [320x256 127.0.0] 'r ---Commented Code to-pgm: func [ "Converts an image RGB channel to a PGM binary format" value [image!] "Image source" channel [word!] "Selected channel: 'r, 'g, or 'b" ] [ ; equivalent to "to-binary rejoin" : we want a binary! result join #{} [ ; the binary PGM file header, followed by a "P5 " ; the image size, in the form width height replace form value/size "x" " " ; a , the max gray value, and a " 255^(0A)" ; selects only one channel (r, g, or b) and skips others extract/index value/rgb 3 index? find [r g b] channel ] ] ===alpha-to-pgm ---Purpose Short code to save the alpha channel of a as a gray image in PGM binary (P5) format. It's useful as a companion for a PPM rgb file, as the PPM format can't store alpha/transparency data with the rgb. ---Usage alpha-to-pgm value (image!) ---Example write/binary %imageTest-alpha.pgm alpha-to-pgm logo.gif ---Commented Code alpha-to-pgm: func [ "Converts the alpha channel of an image to a PGM binary format" value [image!] "Image source" ] [ ; equivalent to "to-binary rejoin" : we want a binary! result join #{} [ ; the binary PGM file header, followed by a "P5 " ; the image size, in the form width height replace form value/size "x" " " ; a , the max gray value, and a " 255^(0A)" ; the alpha channel value/alpha ] ]