-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcsvrecipe.go
109 lines (100 loc) · 2.32 KB
/
csvrecipe.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package main
import (
"encoding/csv"
"fmt"
"io"
"log"
"os"
"strconv"
"strings"
)
// FujiSimulationRecipe defines the structure of a film simulation recipe as read in a CSV document.
type FujiSimulationRecipe struct {
Label string
FilmSimulation string
Grain string
CCFx string
CCFxB string
WhiteBalance string
WBShiftR int8
WBShiftB int8
DynamicRange string
HighlightTone int8
ShadowTone int8
Color int8
Sharpness int8
NoiseReduction int8
ExposureBias string
}
// loadCSV loads the CSV document located at the given path and returns an array filled with
// simulation recipes for each row in the CSV document.
func loadCSV(csvPath *string) []*FujiSimulationRecipe {
fmt.Printf("Load Fujifilm simulation recipes from CSV %s\n", *csvPath)
var recipes []*FujiSimulationRecipe
csvFile, err := os.Open(*csvPath)
if err != nil {
log.Fatal(err)
}
defer csvFile.Close()
csvReader := csv.NewReader(csvFile)
// the first tuple should be the header, so we skip it
var header = true
for {
if header {
header = false
_, err := csvReader.Read()
if err == io.EOF {
break
} else if err != nil {
log.Fatal(err)
}
continue
}
tuple, err := csvReader.Read()
if err == io.EOF {
break
} else if err != nil {
log.Fatal(err)
}
var ccfx []string
if len(tuple[3]) == 0 {
ccfx = make([]string, 2)
ccfx[0] = ""
ccfx[1] = ""
} else {
ccfx = strings.Split(tuple[3], "/")
}
recipes = append(recipes, &FujiSimulationRecipe{
Label: tuple[0],
FilmSimulation: tuple[1],
Grain: tuple[2],
CCFx: ccfx[0],
CCFxB: computeCFXB(ccfx),
WhiteBalance: tuple[4],
WBShiftR: toInt(tuple[5]),
WBShiftB: toInt(tuple[6]),
DynamicRange: tuple[7],
HighlightTone: toInt(tuple[8]),
ShadowTone: toInt(tuple[9]),
Color: toInt(tuple[10]),
Sharpness: toInt(tuple[11]),
NoiseReduction: toInt(tuple[12]),
ExposureBias: tuple[13],
})
}
fmt.Printf("Number of loaded recipes: %d\n", len(recipes))
return recipes
}
func computeCFXB(ccfx []string) string {
if len(ccfx) == 1 {
return ccfx[0]
}
return ccfx[1]
}
func toInt(number string) int8 {
n, err := strconv.Atoi(number)
if err != nil {
log.Fatal(err)
}
return int8(n)
}