Add tasks for all the new languages

This commit is contained in:
Tina Müller 2016-12-05 23:44:36 +01:00
parent 9dc3c2bb62
commit bba7bfd280
13208 changed files with 134745 additions and 0 deletions

View file

@ -0,0 +1,33 @@
import strutils
proc readPPM(f: TFile): Image =
if f.readLine != "P6":
raise newException(E_base, "Invalid file format")
var line = ""
while f.readLine(line):
if line[0] != '#':
break
var parts = line.split(" ")
result = img(parseInt parts[0], parseInt parts[1])
if f.readLine != "255":
raise newException(E_base, "Invalid file format")
var
arr: array[256, int8]
read = f.readBytes(arr, 0, 256)
pos = 0
while read != 0:
for i in 0 .. < read:
case pos mod 3
of 0: result.pixels[pos div 3].r = arr[i].uint8
of 1: result.pixels[pos div 3].g = arr[i].uint8
of 2: result.pixels[pos div 3].b = arr[i].uint8
else: discard
inc pos
read = f.readBytes(arr, 0, 256)

View file

@ -0,0 +1,28 @@
function read_ppm(sequence filename)
sequence image, line
integer dimx, dimy, maxcolor
atom fn = open(filename, "rb")
if fn<0 then
return -1 -- unable to open
end if
line = gets(fn)
if line!="P6\n" then
return -1 -- only ppm6 files are supported
end if
line = gets(fn)
{{dimx,dimy}} = scanf(line,"%d %d%s")
line = gets(fn)
{{maxcolor}} = scanf(line,"%d%s")
image = repeat(repeat(0,dimy),dimx)
for y=1 to dimy do
for x=1 to dimx do
image[x][y] = getc(fn)*#10000 + getc(fn)*#100 + getc(fn)
end for
end for
close(fn)
return image
end function
sequence img = read_ppm("Lena.ppm")
img = to_gray(img)
write_ppm("LenaGray.ppm",img)