Compare commits
No commits in common. "de1268e6a6b782cd3459a67d1f736534b3dd747f" and "50f50ac0aba95a7d0edf5bed646a91ab19a41891" have entirely different histories.
de1268e6a6
...
50f50ac0ab
2
.gitignore
vendored
2
.gitignore
vendored
@ -11,5 +11,3 @@ cory
|
||||
*test.png
|
||||
|
||||
*.zip
|
||||
*.pb.gz
|
||||
|
||||
|
||||
@ -5,15 +5,14 @@ import (
|
||||
"encoding/json"
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime/pprof"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"git.tuxpa.in/a/nori/renderer"
|
||||
"gitlab.com/gfxlabs/gfximg/apng"
|
||||
"golang.org/x/sync/errgroup"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"git.tuxpa.in/a/nori"
|
||||
"git.tuxpa.in/a/nori/utils"
|
||||
@ -29,23 +28,10 @@ var (
|
||||
destinationPtr = flag.String("dest", "", "directory to bulk dump to")
|
||||
filePtr = flag.String("f", "example.nri", "file to load")
|
||||
outputPtr = flag.String("o", "output.zip", "output zip file")
|
||||
|
||||
cpuprofile = flag.String("cpuprofile", "", "write cpu profile to file")
|
||||
)
|
||||
|
||||
func main() {
|
||||
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 {
|
||||
filename := *filePtr
|
||||
output := *outputPtr
|
||||
@ -64,7 +50,7 @@ func main() {
|
||||
}
|
||||
printIf("output: %s\n", dest)
|
||||
if *bulkDumpPtr || *jsonDumpPtr {
|
||||
files, err := os.ReadDir(dir)
|
||||
files, err := ioutil.ReadDir(dir)
|
||||
if err != nil {
|
||||
printIf("%s: %s\n", dir, err)
|
||||
return
|
||||
@ -77,14 +63,10 @@ func main() {
|
||||
if strings.HasSuffix(f.Name(), ".nri") {
|
||||
egg.Go(func() error {
|
||||
if *bulkDumpPtr {
|
||||
if err := dump_nozip(dir+"/"+f.Name(), dest); err != nil {
|
||||
return err
|
||||
}
|
||||
dump_nozip(dir+"/"+f.Name(), dest)
|
||||
}
|
||||
if *jsonDumpPtr {
|
||||
if err := dump_nozip(dir+"/"+f.Name(), dest); err != nil {
|
||||
return dump_anim_json(dir+"/"+f.Name(), dest)
|
||||
}
|
||||
dump_anim_json(dir+"/"+f.Name(), dest)
|
||||
}
|
||||
return nil
|
||||
})
|
||||
@ -95,6 +77,7 @@ func main() {
|
||||
return
|
||||
}
|
||||
}
|
||||
flag.PrintDefaults()
|
||||
}
|
||||
|
||||
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)
|
||||
if err != nil {
|
||||
return fmt.Errorf("decode: %s", err)
|
||||
log.Panicln("decode: %s", err)
|
||||
}
|
||||
names, err := nori.GetAnimationNames(n)
|
||||
if err != nil {
|
||||
return fmt.Errorf("animation: %s", err)
|
||||
log.Panicln("animation: %s", err)
|
||||
}
|
||||
|
||||
json, err := json.Marshal(names)
|
||||
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)))
|
||||
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
|
||||
}
|
||||
|
||||
func dump_nozip(filename string, destination string) error {
|
||||
printIf("done in %v \n", time.Now().Sub(start))
|
||||
}
|
||||
|
||||
func dump_nozip(filename string, destination string) {
|
||||
start := time.Now()
|
||||
printIf("reading file '%s'\n", filename)
|
||||
n, err := nori.FromFile(filename)
|
||||
if err != nil {
|
||||
return fmt.Errorf("decode: %s", err)
|
||||
log.Panicln("decode: %s", err)
|
||||
}
|
||||
// printIf("rendering %d animation(s)\n", n.AnimationCount)
|
||||
animations, err := renderer.RenderAnimationsApng(n)
|
||||
if err != nil {
|
||||
return fmt.Errorf("animation: %s", err)
|
||||
log.Panicln("animation: %s", err)
|
||||
}
|
||||
|
||||
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)
|
||||
f, fErr := os.OpenFile(output, os.O_CREATE, 0740)
|
||||
if fErr != nil {
|
||||
return fErr
|
||||
panic(fErr)
|
||||
}
|
||||
defer f.Close()
|
||||
if err := apng.Encode(f, *v); err != nil {
|
||||
return err
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
//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))
|
||||
//os.WriteFile(output, out.Bytes(), 0740)
|
||||
return nil
|
||||
}
|
||||
|
||||
func dump(filename string, output string) error {
|
||||
func dump(filename string, output string) {
|
||||
start := time.Now()
|
||||
printIf("reading file '%s'\n", filename)
|
||||
n, err := nori.FromFile(filename)
|
||||
if err != nil {
|
||||
return fmt.Errorf("decode: %s", err)
|
||||
log.Panicln("decode: %s", err)
|
||||
}
|
||||
out := new(bytes.Buffer)
|
||||
printIf("rendering %d animation(s)\n", n.AnimationCount)
|
||||
animations, err := renderer.RenderAnimationsApng(n)
|
||||
if err != nil {
|
||||
return fmt.Errorf("animation: %s", err)
|
||||
log.Panicln("animation: %s", err)
|
||||
}
|
||||
printIf("saving to %s \n", output)
|
||||
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))
|
||||
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
Loading…
Reference in New Issue
Block a user