Commit 74131e7f authored by Max Maton's avatar Max Maton

First version of converter

parents
all: windows linux
windows: pfmfix.exe
linux: pfmfix
.PHONY: dependencies
dependencies:
pfmfix.exe: src/pfmfix.go dependencies
GOPATH="$$(pwd)" CGO_ENABLED=0 GOOS=windows GOARCH=386 CC=i686-w64-mingw32-gcc go build -ldflags "-linkmode external -extldflags -static" $<
pfmfix: src/pfmfix.go dependencies
GOPATH="$$(pwd)" CGO_ENABLED=0 GOOS=linux GOARCH=386 go build -ldflags "-linkmode external -extldflags -static" $<
package main
import "os"
import "io/ioutil"
import "log"
import "errors"
func main() {
if len(os.Args) < 2 {
log.Fatal(errors.New("Not enough arguments. Usage: pfmfix file.pfm"))
}
path := os.Args[1]
data, err := ioutil.ReadFile(path)
if err != nil {
log.Fatal(err)
return
}
if data[0] == 'P' && data[1] == 'F' && data[2] == '\n' {
//already in good format
log.Print("good")
os.Stdout.Write(data)
return
}
if data[0] != 'P' || data[1] != 'f' || data[2] != '\n' {
log.Fatal("Not a PFM file")
return
}
//Convert to color format
data[1] = 'F'
pos := 3 //Start scanning from last \n
newlinesLeft := 2
for newlinesLeft > 0 {
if data[pos] == '\n' {
newlinesLeft--
}
pos++
}
os.Stdout.Write(data[0:pos])
for pos < len(data) {
slice := data[pos:pos+4]
for channel := 0; channel < 3; channel++ {
os.Stdout.Write(slice)
}
pos = pos + 4
}
}
File added
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment