RosettaCodeData/Task/Grayscale-image/PureBasic/grayscale-image.basic

36 lines
852 B
Plaintext

Procedure ImageGrayout(image)
Protected w, h, x, y, r, g, b, gray, color
w = ImageWidth(image)
h = ImageHeight(image)
StartDrawing(ImageOutput(image))
For x = 0 To w - 1
For y = 0 To h - 1
color = Point(x, y)
r = Red(color)
g = Green(color)
b = Blue(color)
gray = 0.2126*r + 0.7152*g + 0.0722*b
Plot(x, y, RGB(gray, gray, gray)
Next
Next
StopDrawing()
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