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 |
<lang rexx>/*REXX program converts a RGB (red─green─blue) image to a grayscale image. */ |
||
blue='00 00 ff'x |
blue= '00 00 ff'x /*define the blue color (hexadecimal).*/ |
||
@.= blue /*set the entire image to blue color.*/ |
|||
width= 60 /* width of the |
width= 60 /* width of the image (in pixels). */ |
||
height=100 /*height " " " */ |
height= 100 /*height " " " " " */ |
||
do |
do col=1 for width |
||
do |
do row=1 for height /* [↓] C2D convert char ───> decimal*/ |
||
r= left( |
r= left(@.col.row, 1) ; r=c2d(r) /*extract the component red & convert.*/ |
||
g=substr( |
g=substr(@.col.row, 2, 1) ; g=c2d(g) /* " " " green " " */ |
||
b= right( |
b= right(@.col.row, 1) ; b=c2d(b) /* " " " blue " " */ |
||
@.col.row=d2c((.2126*r+.7152*g +.0722*b)%1) /*convert RGB number ───► grayscale. */ |
|||
end /*row*/ /* [↑] D2C convert decimal ───> char*/ |
|||
⚫ | |||
end /*j*/ |
|||
/*stick a fork in it, we're all done. */</lang> |
|||
end /*k*/ |
|||
⚫ | |||
=={{header|Ruby}}== |
=={{header|Ruby}}== |