Grayscale image: Difference between revisions

Content added Content deleted
(→‎{{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: Line 1,479:


=={{header|REXX}}==
=={{header|REXX}}==
<lang rexx>/*REXX program to convert a RGB image to grayscale. */
<lang rexx>/*REXX program converts a RGB (red─green─blue) image to a grayscale image. */
blue='00 00 ff'x /*define the blue color. */
blue= '00 00 ff'x /*define the blue color (hexadecimal).*/
image.=blue /*set the entire IMAGE to blue. */
@.= blue /*set the entire image to blue color.*/
width= 60 /* width of the IMAGE. */
width= 60 /* width of the image (in pixels). */
height=100 /*height " " " */
height= 100 /*height " " " " " */


do j=1 for width
do col=1 for width
do k=1 for height
do row=1 for height /* [↓] C2D convert char ───> decimal*/
r= left(image.j.k,1) ; r=c2d(r) /*extract red & convert*/
r= left(@.col.row, 1) ; r=c2d(r) /*extract the component red & convert.*/
g=substr(image.j.k,2,1) ; g=c2d(g) /* " green " " */
g=substr(@.col.row, 2, 1) ; g=c2d(g) /* " " " green " " */
b= right(image.j.k,1) ; b=c2d(b) /* " blue " " */
b= right(@.col.row, 1) ; b=c2d(b) /* " " " blue " " */
ddd=right(trunc(.2126*r + .7152*g + .0722*b),3,0) /*──► greyscale.*/
@.col.row=d2c((.2126*r+.7152*g +.0722*b)%1) /*convert RGB number ───► grayscale. */
image.j.k=right(d2c(ddd,6),3,0) /*... and transform back.*/
end /*row*/ /* [↑] D2C convert decimal ───> char*/
end /*col*/ /* [↑] x%1 is the same as TRUNC(x) */
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}}==
=={{header|Ruby}}==