Add tasks for all the new languages
This commit is contained in:
parent
9dc3c2bb62
commit
bba7bfd280
13208 changed files with 134745 additions and 0 deletions
19
Task/Grayscale-image/Lingo/grayscale-image.lingo
Normal file
19
Task/Grayscale-image/Lingo/grayscale-image.lingo
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
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
|
||||
15
Task/Grayscale-image/Phix/grayscale-image.phix
Normal file
15
Task/Grayscale-image/Phix/grayscale-image.phix
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
function to_gray(sequence image)
|
||||
sequence color
|
||||
for i=1 to length(image) do
|
||||
for j=1 to length(image[i]) do
|
||||
-- unpack color triple
|
||||
color = sq_div(sq_and_bits(image[i][j], {#FF0000,#FF00,#FF}),
|
||||
{#010000,#0100,#01})
|
||||
image[i][j] = floor(0.2126*color[1] + 0.7152*color[2] + 0.0722*color[3])*#010101
|
||||
end for
|
||||
end for
|
||||
return image
|
||||
end function
|
||||
|
||||
sequence img = read_ppm("Lena.ppm")
|
||||
img = to_gray(img)
|
||||
19
Task/Grayscale-image/Sidef/grayscale-image.sidef
Normal file
19
Task/Grayscale-image/Sidef/grayscale-image.sidef
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
require('Image::Imlib2')
|
||||
|
||||
func tograyscale(img) {
|
||||
var (width, height) = (img.width, img.height)
|
||||
var gimg = %s'Image::Imlib2'.new(width, height)
|
||||
for y,x in (^height ~X ^width) {
|
||||
var (r, g, b) = img.query_pixel(x, y)
|
||||
var gray = int(0.2126*r + 0.7152*g + 0.0722*b)
|
||||
gimg.set_color(gray, gray, gray, 255)
|
||||
gimg.draw_point(x, y)
|
||||
}
|
||||
return gimg
|
||||
}
|
||||
|
||||
var (input='input.png', output='output.png') = ARGV...
|
||||
var image = %s'Image::Imlib2'.load(input)
|
||||
var gscale = tograyscale(image)
|
||||
gscale.set_quality(80)
|
||||
gscale.save(output)
|
||||
Loading…
Add table
Add a link
Reference in a new issue