Grayscale image: Difference between revisions

m
→‎{{header|REXX}}: changed/added comments and whitespace, changed indentations, optimized/simplified the code for calculations.
(→‎{{header|PureBasic}}: Corrected code to include ImageToColor() function)
m (→‎{{header|REXX}}: changed/added comments and whitespace, changed indentations, optimized/simplified the code for calculations.)
Line 1,479:
 
=={{header|REXX}}==
<lang rexx>/*REXX program to convertconverts a RGB image to grayscale. RGB (red─green─blue) image to a grayscale image. */
blue= '00 00 ff'x /*define the blue color. /*define the blue color (hexadecimal).*/
image @.= blue /*set the entire IMAGE image to blue color. */
width= 60 /* width of the IMAGE. image (in pixels). */
height= 100 /*height " " " " " */
 
do j col=1 for width
do krow=1 for height /* [↓] C2D convert char ───> decimal*/
r= left(image@.jcol.krow, 1) ; ; r=c2d(r) /*extract redthe component red & convert.*/
g=substr(image@.jcol.krow, 2, 1) ; ; g=c2d(g) /* " " " green " " */
b= right(image@.jcol.krow, 1) ; ; b=c2d(b) /* " " " blue " " */
ddd @.col.row=rightd2c(trunc(.2126*r + .7152*g + .0722*b),3,0%1) /*──►convert greyscaleRGB number ───► grayscale. */
image.j.k=right(d2c(ddd,6),3,0) end /*row*/ /*... and[↑] D2C convert decimal transform───> back.char*/
end /*col*/ /*stick a[↑] fork inx%1 it, we're done.is the same as TRUNC(x) */</lang>
end /*j*/
/*stick a fork in it, we're all done. */</lang>
end /*k*/
/*stick a fork in it, we're done.*/</lang>
 
=={{header|Ruby}}==