58775bf6d49072902d9b171fe4e88332af50a22c
- Author
- Pavle Portic <pavle.portic@tilda.center>
- Committer
- Pavle Portic <pavle.portic@tilda.center>
- Date
Message
Diff
This diff is truncated to protect this page.
1diff --git a/.gitignore b/.gitignore
2new file mode 100644
3index 0000000000000000000000000000000000000000..37aab56cafd262024883564a4bccee9ab884bbfa
4--- /dev/null
5+++ b/.gitignore
6@@ -0,0 +1,3 @@
7+*.jpg
8+*.png
9+lumetri
10diff --git a/main.go b/main.go
11new file mode 100644
12index 0000000000000000000000000000000000000000..f4ec1e2c79702af5103ecb4e54186ef08425f0e8
13--- /dev/null
14+++ b/main.go
15@@ -0,0 +1,108 @@
16+//
17+// main.go
18+// Copyright (C) 2019 pavle <pavle.portic@tilda.center>
19+//
20+// Distributed under terms of the BSD-3-Clause license.
21+//
22+
23+package main
24+
25+import (
26+ "fmt"
27+ "image"
28+ "image/color"
29+ _ "image/jpeg"
30+ "image/png"
31+ "log"
32+ // "math"
33+ "os"
34+ "time"
35+)
36+
37+func elapsed() func() {
38+ start := time.Now()
39+ return func() {
40+ fmt.Printf("%v\n", time.Since(start))
41+ }
42+}
43+
44+const width uint = 512
45+
46+func main() {
47+ defer elapsed()()
48+
49+ imgfile, err := os.Open("in.jpg")
50+ if err != nil {
51+ log.Fatal(err)
52+ }
53+ defer imgfile.Close()
54+
55+ img, _, err := image.Decode(imgfile)
56+ if err != nil {
57+ log.Fatal(err)
58+ }
59+
60+ bounds := img.Bounds()
61+ scale := float64(width) / float64(bounds.Max.X - bounds.Min.X)
62+ coeff := uint8(scale * 4)
63+ if coeff == 0 {
64+ coeff = 1
65+ }
66+ fmt.Printf("scale: %v, coeff: %v\n", scale, coeff)
67+
68+ scope := image.NewRGBA(image.Rect(0, 0, int(width), 256))
69+ scope_bounds := scope.Bounds()
70+
71+ for y := scope_bounds.Min.Y; y < scope_bounds.Max.Y; y++ {
72+ for x := scope_bounds.Min.X; x < scope_bounds.Max.X; x++ {
73+ scope.SetRGBA(x, y, color.RGBA{0, 0, 0, 255})
74+ }
75+ }
76+
77+ for y := bounds.Min.Y; y < bounds.Max.Y; y++ {
78+ for x := bounds.Min.X; x < bounds.Max.X; x++ {
79+ r, g, b, _:= img.At(x, y).RGBA()
80+ ir := uint8(r >> 8)
81+ ig := uint8(g >> 8)
82+ ib := uint8(b >> 8)
83+
84+ tr, tg, tb, _ := scope.At(int(float64(x) * scale), 255 - int(ir)).RGBA()
85+ sr := uint8(tr >> 8)
86+ sg := uint8(tg >> 8)
87+ sb := uint8(tb >> 8)
88+ if sr > 255 - coeff {
89+ sr = 255
90+ } else {
91+ sr += coeff
92+ }
93+ scope.SetRGBA(int(float64(x) * scale), 255 - int(ir), color.RGBA{sr, sg, sb, 255})
94+
95+ tr, tg, tb, _ = scope.At(int(float64(x) * scale), 255 - int(ig)).RGBA()
96+ sr = uint8(tr >> 8)
97+ sg = uint8(tg >> 8)
98+ sb = uint8(tb >> 8)
99+ if sg > 255 - coeff {
100+ sg = 255
101+ } else {
102+ sg += coeff
103+ }
104+ scope.SetRGBA(int(float64(x) * scale), 255 - int(ig), color.RGBA{sr, sg, sb, 255})
105+
106+ tr, tg, tb, _ = scope.At(int(float64(x) * scale), 255 - int(ib)).RGBA()
107+ sr = uint8(tr >> 8)
108+ sg = uint8(tg >> 8)
109+ sb = uint8(tb >> 8)
110+ if sb > 255 - coeff {
111+ sb = 255
112+ } else {
113+ sb += coeff
114+ }