Grayscale image: Difference between revisions

Content added Content deleted
m (Added Sidef)
(→‎{{header|PureBasic}}: Corrected code to include ImageToColor() function)
Line 1,300: Line 1,300:
=={{header|PureBasic}}==
=={{header|PureBasic}}==
<lang PureBasic>Procedure ImageGrayout(image)
<lang PureBasic>Procedure ImageGrayout(image)
Protected w, h, x, y, r, g, b, gray, color
w = ImageWidth(image)
w = ImageWidth(image)
h = ImageHeight(image)
h = ImageHeight(image)
Line 1,306: Line 1,308:
For y = 0 To h - 1
For y = 0 To h - 1
color = Point(x, y)
color = Point(x, y)
r = color & $ff
r = Red(color)
g = color >> 8 & $ff
g = Green(color)
b = color >> 16 & $ff
b = Blue(color)
gray = 0.2126*r + 0.7152*g + 0.0722*b
gray = 0.2126*r + 0.7152*g + 0.0722*b
Plot(x, y, gray + gray << 8 + gray << 16)
Plot(x, y, RGB(gray, gray, gray)
Next
Next
Next
Next
StopDrawing()
StopDrawing()
EndProcedure</lang>
EndProcedure


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}}==
=={{header|Python}}==