Grayscale image: Difference between revisions

→‎{{header|PureBasic}}: Corrected code to include ImageToColor() function
m (Added Sidef)
(→‎{{header|PureBasic}}: Corrected code to include ImageToColor() function)
Line 1,300:
=={{header|PureBasic}}==
<lang PureBasic>Procedure ImageGrayout(image)
Protected w, h, x, y, r, g, b, gray, color
w = ImageWidth(image)
h = ImageHeight(image)
Line 1,306 ⟶ 1,308:
For y = 0 To h - 1
color = Point(x, y)
r = Red(color & $ff)
g = Green(color >> 8 & $ff)
b = Blue(color >> 16 & $ff)
gray = 0.2126*r + 0.7152*g + 0.0722*b
Plot(x, y, RGB(gray +, gray << 8 +, gray << 16)
Next
Next
StopDrawing()
EndProcedure</lang>
 
Procedure ImageToColor(image)
Protected w, h, x, y, v, gray
w = ImageWidth(image)
h = ImageHeight(image)
StartDrawing(ImageOutput(image))
For x = 0 To w - 1
For y = 0 To h - 1
gray = Point(x, y)
v = Red(gray) ;for gray, each of the color's components is the same
;color = RGB(0.2126*v, 0.7152*v, 0.0722*v)
Plot(x, y, RGB(v, v, v))
Next
Next
StopDrawing()
EndProcedure</lang>
 
=={{header|Python}}==
Anonymous user