Grayscale image: Difference between revisions

Content added Content deleted
m (→‎{{header|REXX}}: added whitespace, changed a glyph.)
Line 1,565:
 
=={{header|REXX}}==
Note:   REXX uses decimal (characters) instead of binary for storing numbers,   so there is no rounding   (using characters to
<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;characters to store numbers is almost the same as using decimal floating point).
<lang rexx>/*REXX program converts a RGB (red─green─blue) image into a grayscale/greyscale image. */
blue= '00 00 ff'x /*define the blue color (hexadecimal).*/
@.= blue /*set the entire image to blue color.*/
Line 1,574:
 
do col=1 for width
do row=1 for height /* [↓] C2D convert char ───>───► decimal*/
r= left(@.col.row, 1) ; r= c2d(r) /*extract the component red & convert.*/
g= substr(@.col.row, 2, 1) ; g= c2d(g) /* " " " green " " */
b= right(@.col.row, 1) ; b= c2d(b) /* " " " blue " " */
_= d2c( (.2126*r + .7152*g + .0722*b) % 1) /*convert RGB number ───► grayscale. */
@.col.row= copies(_, 3) /*redefine old RGB ───► grayscale. */
end /*row*/ /* [↑] D2C convert decimal ───► char*/
end /*col*/ /* [↑] x%1 is the same as TRUNC(x) */
/*stick a fork in it, we're all done. */</lang><br><br>
Other alternatives to express the &nbsp; ''blue'' &nbsp; color are:
<lang rexx> blue= "00 00 ff"x /*define the blue color (hexadecimal).*/
blue= '00 00 FF'x /*define the blue color (hexadecimal).*/
blue= '0000ff'x /*define the blue color (hexadecimal).*/
 
blue= '00000000 00000000 11111111'b /*define the blue color (binary). */
blue= '000000000000000011111111'b /*define the blue color (binary) */
 
blue= 'zzy' /*define the blue color (character). */
/*not recommended because of rendering.*/
/*where Z is the character '00'x */
/*where Y is the character 'ff'x */
 
/*Both Z & Y are normally not viewable*/
/*on most terminals (appear as blanks).*/</lang><br><br>
 
=={{header|Ruby}}==