Compare commits

..

No commits in common. "de1268e6a6b782cd3459a67d1f736534b3dd747f" and "50f50ac0aba95a7d0edf5bed646a91ab19a41891" have entirely different histories.

868 changed files with 41 additions and 487 deletions

2
.gitignore vendored
View File

@ -11,5 +11,3 @@ cory
*test.png *test.png
*.zip *.zip
*.pb.gz

View File

@ -5,15 +5,14 @@ import (
"encoding/json" "encoding/json"
"flag" "flag"
"fmt" "fmt"
"os"
"path/filepath"
"runtime/pprof"
"strings"
"time"
"git.tuxpa.in/a/nori/renderer" "git.tuxpa.in/a/nori/renderer"
"gitlab.com/gfxlabs/gfximg/apng" "gitlab.com/gfxlabs/gfximg/apng"
"golang.org/x/sync/errgroup" "golang.org/x/sync/errgroup"
"io/ioutil"
"os"
"path/filepath"
"strings"
"time"
"git.tuxpa.in/a/nori" "git.tuxpa.in/a/nori"
"git.tuxpa.in/a/nori/utils" "git.tuxpa.in/a/nori/utils"
@ -29,23 +28,10 @@ var (
destinationPtr = flag.String("dest", "", "directory to bulk dump to") destinationPtr = flag.String("dest", "", "directory to bulk dump to")
filePtr = flag.String("f", "example.nri", "file to load") filePtr = flag.String("f", "example.nri", "file to load")
outputPtr = flag.String("o", "output.zip", "output zip file") outputPtr = flag.String("o", "output.zip", "output zip file")
cpuprofile = flag.String("cpuprofile", "", "write cpu profile to file")
) )
func main() { func main() {
flag.Parse() flag.Parse()
if len(os.Args) < 2 {
flag.PrintDefaults()
}
if *cpuprofile != "" {
f, err := os.Create(*cpuprofile)
if err != nil {
panic(err)
}
pprof.StartCPUProfile(f)
defer pprof.StopCPUProfile()
}
if *dumpPtr { if *dumpPtr {
filename := *filePtr filename := *filePtr
output := *outputPtr output := *outputPtr
@ -64,7 +50,7 @@ func main() {
} }
printIf("output: %s\n", dest) printIf("output: %s\n", dest)
if *bulkDumpPtr || *jsonDumpPtr { if *bulkDumpPtr || *jsonDumpPtr {
files, err := os.ReadDir(dir) files, err := ioutil.ReadDir(dir)
if err != nil { if err != nil {
printIf("%s: %s\n", dir, err) printIf("%s: %s\n", dir, err)
return return
@ -77,14 +63,10 @@ func main() {
if strings.HasSuffix(f.Name(), ".nri") { if strings.HasSuffix(f.Name(), ".nri") {
egg.Go(func() error { egg.Go(func() error {
if *bulkDumpPtr { if *bulkDumpPtr {
if err := dump_nozip(dir+"/"+f.Name(), dest); err != nil { dump_nozip(dir+"/"+f.Name(), dest)
return err
}
} }
if *jsonDumpPtr { if *jsonDumpPtr {
if err := dump_nozip(dir+"/"+f.Name(), dest); err != nil { dump_anim_json(dir+"/"+f.Name(), dest)
return dump_anim_json(dir+"/"+f.Name(), dest)
}
} }
return nil return nil
}) })
@ -95,6 +77,7 @@ func main() {
return return
} }
} }
flag.PrintDefaults()
} }
func printIf(s string, args ...interface{}) { func printIf(s string, args ...interface{}) {
@ -103,35 +86,47 @@ func printIf(s string, args ...interface{}) {
} }
} }
func dump_anim_json(filename string, destination string) error { func dump_anim_json(filename string, destination string) {
start := time.Now()
printIf("reading file '%s'\n", filename)
n, err := nori.FromFile(filename) n, err := nori.FromFile(filename)
if err != nil { if err != nil {
return fmt.Errorf("decode: %s", err) log.Panicln("decode: %s", err)
} }
names, err := nori.GetAnimationNames(n) names, err := nori.GetAnimationNames(n)
if err != nil { if err != nil {
return fmt.Errorf("animation: %s", err) log.Panicln("animation: %s", err)
} }
json, err := json.Marshal(names) json, err := json.Marshal(names)
if err != nil { if err != nil {
return fmt.Errorf("could not marshal json: %s\n", err) log.Panicln("could not marshal json: %s\n", err)
} }
baseName := filepath.Base(strings.TrimSuffix(filename, filepath.Ext(filename))) baseName := filepath.Base(strings.TrimSuffix(filename, filepath.Ext(filename)))
output := fmt.Sprintf("%s/%s.json", destination, baseName) output := fmt.Sprintf("%s/%s.json", destination, baseName)
return os.WriteFile(output, json, 0o740) f, fErr := os.OpenFile(output, os.O_CREATE, 0740)
if fErr != nil {
panic(fErr)
}
defer f.Close()
if _, err := f.Write(json); err != nil {
return
}
printIf("done in %v \n", time.Now().Sub(start))
} }
func dump_nozip(filename string, destination string) error { func dump_nozip(filename string, destination string) {
start := time.Now() start := time.Now()
printIf("reading file '%s'\n", filename)
n, err := nori.FromFile(filename) n, err := nori.FromFile(filename)
if err != nil { if err != nil {
return fmt.Errorf("decode: %s", err) log.Panicln("decode: %s", err)
} }
// printIf("rendering %d animation(s)\n", n.AnimationCount) // printIf("rendering %d animation(s)\n", n.AnimationCount)
animations, err := renderer.RenderAnimationsApng(n) animations, err := renderer.RenderAnimationsApng(n)
if err != nil { if err != nil {
return fmt.Errorf("animation: %s", err) log.Panicln("animation: %s", err)
} }
baseName := filepath.Base(strings.TrimSuffix(filename, filepath.Ext(filename))) baseName := filepath.Base(strings.TrimSuffix(filename, filepath.Ext(filename)))
@ -140,40 +135,39 @@ func dump_nozip(filename string, destination string) error {
// printIf("saving to %s \n", output) // printIf("saving to %s \n", output)
f, fErr := os.OpenFile(output, os.O_CREATE, 0740) f, fErr := os.OpenFile(output, os.O_CREATE, 0740)
if fErr != nil { if fErr != nil {
return fErr panic(fErr)
} }
defer f.Close() defer f.Close()
if err := apng.Encode(f, *v); err != nil { if err := apng.Encode(f, *v); err != nil {
return err return
} }
} }
// //
//if err := utils.ZipApngs(out, animations); err != nil { //if err := utils.ZipApngs(out, animations); err != nil {
// return fmt.Errorf("zipping: %s", err) // log.Panicln("zipping: %s", err)
//} //}
printIf("done in %v \n", time.Now().Sub(start)) printIf("done in %v \n", time.Now().Sub(start))
//os.WriteFile(output, out.Bytes(), 0740) //os.WriteFile(output, out.Bytes(), 0740)
return nil
} }
func dump(filename string, output string) error { func dump(filename string, output string) {
start := time.Now() start := time.Now()
printIf("reading file '%s'\n", filename)
n, err := nori.FromFile(filename) n, err := nori.FromFile(filename)
if err != nil { if err != nil {
return fmt.Errorf("decode: %s", err) log.Panicln("decode: %s", err)
} }
out := new(bytes.Buffer) out := new(bytes.Buffer)
printIf("rendering %d animation(s)\n", n.AnimationCount) printIf("rendering %d animation(s)\n", n.AnimationCount)
animations, err := renderer.RenderAnimationsApng(n) animations, err := renderer.RenderAnimationsApng(n)
if err != nil { if err != nil {
return fmt.Errorf("animation: %s", err) log.Panicln("animation: %s", err)
} }
printIf("saving to %s \n", output) printIf("saving to %s \n", output)
if err := utils.ZipApngs(out, animations); err != nil { if err := utils.ZipApngs(out, animations); err != nil {
return fmt.Errorf("zipping: %s", err) log.Panicln("zipping: %s", err)
} }
printIf("done in %v \n", time.Now().Sub(start)) printIf("done in %v \n", time.Now().Sub(start))
os.WriteFile(output, out.Bytes(), 0740) os.WriteFile(output, out.Bytes(), 0740)
return nil
} }

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Some files were not shown because too many files have changed in this diff Show More