mirror of
https://bitbucket.org/s_l_teichmann/mtsatellite
synced 2025-06-28 06:12:08 +02:00
Moved color parsing to common.
This commit is contained in:
@ -1,49 +0,0 @@
|
||||
// Copyright 2014 by Sascha L. Teichmann
|
||||
// Use of this source code is governed by the MIT license
|
||||
// that can be found in the LICENSE file.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"image/color"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type Colors struct {
|
||||
Colors []color.RGBA
|
||||
NameIndex map[string]int32
|
||||
}
|
||||
|
||||
func ParseColors(filename string) (colors *Colors, err error) {
|
||||
|
||||
var file *os.File
|
||||
if file, err = os.Open(filename); err != nil {
|
||||
return
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
nameIndex := make(map[string]int32)
|
||||
cols := make([]color.RGBA, 0, 2200)
|
||||
|
||||
scanner := bufio.NewScanner(file)
|
||||
for scanner.Scan() {
|
||||
line := scanner.Text()
|
||||
if strings.HasPrefix(line, "#") {
|
||||
continue
|
||||
}
|
||||
c := color.RGBA{A: 0xff}
|
||||
var name string
|
||||
if n, _ := fmt.Sscanf(
|
||||
line, "%s %d %d %d %d", &name, &c.R, &c.G, &c.B, &c.A); n > 0 {
|
||||
idx := int32(len(cols))
|
||||
cols = append(cols, c)
|
||||
nameIndex[name] = idx
|
||||
}
|
||||
}
|
||||
err = scanner.Err()
|
||||
colors = &Colors{Colors: cols, NameIndex: nameIndex}
|
||||
return
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -45,9 +45,9 @@ func main() {
|
||||
flag.Parse()
|
||||
|
||||
var err error
|
||||
var colors *Colors
|
||||
var colors *common.Colors
|
||||
|
||||
if colors, err = ParseColors(colorsfile); err != nil {
|
||||
if colors, err = common.ParseColors(colorsfile); err != nil {
|
||||
log.Fatalf("Cannot open color file: %s", err)
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user