Grayscale image: Difference between revisions
Content added Content deleted
m (→{{header|Sidef}}: minor code simplifications) |
(Lingo added) |
||
Line 942: | Line 942: | ||
The task description is silent on the issue of companded sRGB versus linear RGB. Most images are actually sRGB, and strictly speaking, the transformation to get Y from RGB is applicable to linear RGB. I imagine that, unlike the ''rc'' version, the ''julia'' version reverses compansion prior to applying the CIE transformation to extract luminance from RGB. |
The task description is silent on the issue of companded sRGB versus linear RGB. Most images are actually sRGB, and strictly speaking, the transformation to get Y from RGB is applicable to linear RGB. I imagine that, unlike the ''rc'' version, the ''julia'' version reverses compansion prior to applying the CIE transformation to extract luminance from RGB. |
||
=={{header|Lingo}}== |
|||
<lang lingo>on rgbToGrayscaleImageFast (img) |
|||
res = image(img.width, img.height, 8) |
|||
res.paletteRef = #grayScale |
|||
res.copyPixels(img, img.rect, img.rect) |
|||
return res |
|||
end |
|||
on rgbToGrayscaleImageCustom (img) |
|||
res = image(img.width, img.height, 8) |
|||
res.paletteRef = #grayScale |
|||
repeat with x = 0 to img.width-1 |
|||
repeat with y = 0 to img.height-1 |
|||
c = img.getPixel(x,y) |
|||
n = c.red*0.2126 + c.green*0.7152 + c.blue*0.0722 |
|||
res.setPixel(x,y, color(256-n)) |
|||
end repeat |
|||
end repeat |
|||
return res |
|||
end</lang> |
|||
=={{header|Lua}}== |
=={{header|Lua}}== |