doc: filters: Further example generator changes
[gfxprim/pasky.git] / doc / images / regen.py
blobcc0e9442ebeb715fbaa212ffa4be7336297fd31a
1 #!/usr/bin/env python
3 import sys
5 import gfxprim.core as core
6 import gfxprim.loaders as loaders
7 import gfxprim.filters as filters
9 class ImgGen:
10 def __init__(self, orig_path):
11 self.orig_path = orig_path
12 self.img = loaders.Load('../' + orig_path + 'lenna.png')
13 self.img_small = loaders.Load('../' + orig_path + 'lenna_small.png')
16 def write_asciidoc_head(self, dst_path, heading):
17 self.f = open('../' + dst_path + 'images.txt', 'w')
18 f = self.f
19 f.write('.Example Images: Original Image; ' + heading + '\n')
20 f.write('image:' + self.orig_path + 'lenna_small.png[\n')
21 f.write('\t"Original Image",\n')
22 f.write('\tlink="' + self.orig_path + 'lenna.png"]\n')
24 def write_img_asciidoc(self, desc, fname, fname_small):
25 f = self.f
26 f.write('image:' + fname_small + '[\n')
27 f.write('\t"' + desc + '",\n')
28 f.write('\tlink="' + fname + '"]\n')
30 def write_asciidoc_tail(self):
31 self.f.write('\n')
32 self.f.close()
34 def gen(self, func, func_params_arr, dst_path, func_name):
36 print("Generating " + func_name)
38 self.write_asciidoc_head(dst_path, func_name + ' ' +
39 ', '.join(map(lambda x: ' '.join([str(i) for i in x]), func_params_arr)))
41 for i in func_params_arr:
42 str_i = [str(x) for x in i]
43 desc = func_name + ' ' + ' '.join(str_i)
45 print(' > ' + desc)
47 fname = dst_path + 'lenna_' + '_'.join(str_i) + '.png'
48 fname_small = dst_path + 'lenna_small_' + '_'.join(str_i) + '.png'
50 self.write_img_asciidoc(desc, fname, fname_small)
52 res = func(self.img, *i)
53 res.loaders.Save('../' + fname)
55 res = func(self.img_small, *i)
56 res.loaders.Save('../' + fname_small)
58 self.write_asciidoc_tail()
60 def main():
61 imggen = ImgGen('images/orig/')
63 imggen.gen(filters.GaussianBlurAlloc,
64 [[2, 2], [0, 4], [4, 0], [4, 4], [10, 10]],
65 'images/blur/', 'Gaussian Blur')
67 imggen.gen(filters.MedianAlloc,
68 [[3, 3], [5, 5], [7, 7], [9, 9], [12, 12]],
69 'images/median/', 'Median')
71 imggen.gen(filters.EdgeSharpeningAlloc,
72 [[0.1], [0.3], [0.5], [0.8], [1.0]],
73 'images/edge_sharpening/', 'Edge Sharpening')
75 if __name__ == '__main__':
76 main()