Created
May 4, 2015 08:57
-
-
Save klauspost/0fc7a927ed211e3fac62 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"encoding/xml" | |
"fmt" | |
"io/ioutil" | |
"os" | |
"path/filepath" | |
"strings" | |
"time" | |
) | |
type dcpData struct { | |
ProfileName string `xml:"ProfileName"` | |
CalibrationIlluminant1 int | |
CalibrationIlluminant2 int | |
ColorMatrix1 []ColorMatrix | |
ColorMatrix2 []ColorMatrix | |
ForwardMatrix1 []ColorMatrix | |
ForwardMatrix2 []ColorMatrix | |
Copyright string | |
EmbedPolicy int | |
HueSatDeltas1 []HueSatDeltaTable | |
HueSatDeltas2 []HueSatDeltaTable | |
LookTable []HueSatDeltaTable | |
ToneCurve []ToneCurveTable | |
ProfileCalibrationSignature string | |
UniqueCameraModelRestriction string | |
} | |
type DCPProfile struct { | |
ProfileName string `xml:"ProfileName"` | |
CalibrationIlluminant1 int | |
CalibrationIlluminant2 int | |
ColorMatrix1 []ColorMatrix | |
ColorMatrix2 []ColorMatrix | |
ForwardMatrix1 []ColorMatrix | |
ForwardMatrix2 []ColorMatrix | |
Copyright string | |
EmbedPolicy int | |
HueSatDeltas1 []HueSatDeltaTable | |
HueSatDeltas2 []HueSatDeltaTable | |
LookTable []HueSatDeltaTable | |
ToneCurve []ToneCurveTable | |
ProfileCalibrationSignature string | |
UniqueCameraModelRestriction string | |
} | |
type ColorMatrix struct { | |
Rows int "xml:\"Rows,attr\"" | |
Cols int "xml:\"Cols,attr\"" | |
Elements []MatrixElement `xml:"Element"` | |
} | |
type MatrixElement struct { | |
Row int "xml:\"Row,attr\"" | |
Col int "xml:\"Col,attr\"" | |
Value string `xml:",chardata"` | |
} | |
type HueSatDeltaTable struct { | |
HueDivisions int "xml:\"hueDivisions,attr\"" | |
SatDivisions int "xml:\"satDivisions,attr\"" | |
ValDivisions int "xml:\"valDivisions,attr\"" | |
Elements []HueSatDeltaElement `xml:"Element"` | |
} | |
type HueSatDeltaElement struct { | |
HueDiv int `xml:"HueDiv,attr"` | |
SatDiv int `xml:"SatDiv,attr"` | |
ValDiv int `xml:"ValDiv,attr"` | |
HueShift float64 `xml:"HueShift,attr"` | |
SatScale float64 `xml:"SatScale,attr"` | |
ValScale float64 `xml:"ValScale,attr"` | |
} | |
type ToneCurveTable struct { | |
Size int "xml:\"Size,attr\"" | |
Elements []ToneCurveElement `xml:"Element"` | |
} | |
type ToneCurveElement struct { | |
N int "xml:\"N,attr\"" | |
H float64 "xml:\"h,attr\"" | |
V float64 "xml:\"v,attr\"" | |
} | |
type DcpFile struct { | |
FileName string | |
UploadedBy string | |
UploadedDate time.Time | |
OriginalSHA1 string | |
} | |
var twos = map[string]bool{ | |
"konica": true, | |
"phase": true, | |
} | |
func printUnique(path string, info os.FileInfo, err error) error { | |
if info.IsDir() { | |
return nil | |
} | |
//fmt.Println("Opening", path) | |
xmlFile, err := ioutil.ReadFile(path) | |
if err != nil { | |
return err | |
} | |
var q dcpData | |
xml.Unmarshal(xmlFile, &q) | |
spl := strings.Split(q.UniqueCameraModelRestriction, " ") | |
off := 1 | |
if twos[strings.ToLower(spl[0])] { | |
off = 2 | |
} | |
first := strings.Join(spl[:off], " ") | |
last := strings.Join(spl[off:], " ") | |
fmt.Println(`<ID make="` + first + `" model="` + last + `">` + q.UniqueCameraModelRestriction + `</ID>`) | |
return nil | |
} | |
func main() { | |
args := os.Args | |
if len(args) != 2 { | |
fmt.Println("Please supply filename to convert: " + args[0] + " \"input\"") | |
return | |
} | |
err := filepath.Walk(args[1], printUnique) | |
if err != nil { | |
panic(err) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment