diff --git a/common/nori/animation.go b/common/nori/animation.go index 215badc..fb640b1 100644 --- a/common/nori/animation.go +++ b/common/nori/animation.go @@ -1,151 +1,38 @@ package nori import ( - "bufio" "encoding/binary" "io" ) -type Frame struct { - Duration uint32 - PlaneCount uint32 - Planes []*Plane - CoordinateCount uint32 - Coordinates [][2]uint32 - Unknown1 string - SoundEffect string - Unknown2 string - Camp CampSection -} -type CampSection struct { - Params [7]uint32 - Array []byte - Extra string -} - -type Plane struct { - BitmapId uint32 - PlaneX int32 - PlaneY int32 - Opacity uint32 - Blend BlendMode - FlagParam uint32 - RenderFlag uint32 -} type Animation struct { Title [32]byte - // std::vector frame_offsets FrameCount uint32 Frames []*Frame + Version int } -func (a *Animation) Decode(rd *bufio.Reader, version int) error { +func NewAnimation(version int) *Animation { + return &Animation{Version: version} +} + +func (a *Animation) Decode(rd io.Reader) error { if err := binary.Read(rd, end, a.Title[:]); err != nil { return err } if err := binary.Read(rd, end, &a.FrameCount); err != nil { return err } - if _, err := rd.Discard(4 * int(a.FrameCount)); err != nil { + if err := discardN(rd, 4*int(a.FrameCount)); err != nil { return err } a.Frames = make([]*Frame, int(a.FrameCount)) for i := range a.Frames { - cf := &Frame{} - a.Frames[i] = cf - if err := binary.Read(rd, end, &cf.Duration); err != nil { + a.Frames[i] = NewFrame(a.Version) + if err := a.Frames[i].Decode(rd); err != nil { return err } - if err := binary.Read(rd, end, &cf.PlaneCount); err != nil { - return err - } - cf.Planes = make([]*Plane, int(cf.PlaneCount)) - for i := range cf.Planes { - cp := &Plane{} - cf.Planes[i] = cp - if err := binary.Read(rd, end, &cp.BitmapId); err != nil { - return err - } - if err := binary.Read(rd, end, &cp.PlaneX); err != nil { - return err - } - if err := binary.Read(rd, end, &cp.PlaneY); err != nil { - return err - } - if err := binary.Read(rd, end, &cp.Opacity); err != nil { - return err - } - if err := binary.Read(rd, end, &cp.RenderFlag); err != nil { - return err - } - if err := binary.Read(rd, end, &cp.Blend); err != nil { - return err - } - if err := binary.Read(rd, end, &cp.FlagParam); err != nil { - return err - } - } - if version != 300 { - if err := binary.Read(rd, end, &cf.CoordinateCount); err != nil { - return err - } - cf.Coordinates = make([][2]uint32, cf.CoordinateCount) - for i := range cf.Coordinates { - if err := binary.Read(rd, end, &cf.Coordinates[i][0]); err != nil { - return err - } - if err := binary.Read(rd, end, &cf.Coordinates[i][1]); err != nil { - return err - } - } - } - switch version { - case 300, 301: - if _, err := rd.Discard(144); err != nil { - return err - } - case 302, 303: - if _, err := rd.Discard(96); err != nil { - return err - } - } - if version >= 302 { - // entry blocks - if _, err := rd.Discard(28 * 6); err != nil { - return err - } - } - // unknown1 - if _, err := rd.Discard(44); err != nil { - return err - } - //sound_effect - if _, err := rd.Discard(18); err != nil { - return err - } - // unknown2 - if _, err := rd.Discard(18); err != nil { - return err - } - var cast uint32 - if err := binary.Read(rd, end, &cast); err != nil { - return err - } - if version >= 303 && (cast > 0) { - cf.Camp = CampSection{} - if err := binary.Read(rd, end, cf.Camp.Params[:]); err != nil { - return err - } - sz := int(cf.Camp.Params[1]) * int(cf.Camp.Params[2]) - cf.Camp.Array = make([]byte, sz) - if _, err := io.ReadFull(rd, cf.Camp.Array); err != nil { - return err - } - if _, err := rd.Discard(20); err != nil { - return err - } - } } return nil } diff --git a/common/nori/blend.go b/common/nori/const.go similarity index 87% rename from common/nori/blend.go rename to common/nori/const.go index d5188ea..effa424 100644 --- a/common/nori/blend.go +++ b/common/nori/const.go @@ -1,5 +1,7 @@ package nori +import "encoding/binary" + type BlendMode uint32 var ( @@ -16,3 +18,5 @@ var ( BlendMode_Mul7 BlendMode = 7 BlendMode_Add8 BlendMode = 8 ) + +var end = binary.LittleEndian diff --git a/common/nori/decoder.go b/common/nori/decoder.go new file mode 100644 index 0000000..362c847 --- /dev/null +++ b/common/nori/decoder.go @@ -0,0 +1,26 @@ +package nori + +import ( + "bufio" + "io" + "os" +) + +func New() *Nori { + return &Nori{} +} + +func FromFile(fp string) (*Nori, error) { + file, err := os.Open(fp) + if err != nil { + return nil, err + } + defer file.Close() + return Decode(bufio.NewReader(file)) +} + +func Decode(r io.Reader) (*Nori, error) { + nori := New() + err := nori.Decode(r) + return nori, err +} diff --git a/common/nori/frame.go b/common/nori/frame.go new file mode 100644 index 0000000..8706e32 --- /dev/null +++ b/common/nori/frame.go @@ -0,0 +1,105 @@ +package nori + +import ( + "encoding/binary" + "io" +) + +type Frame struct { + Duration uint32 + PlaneCount uint32 + Planes []*Plane + CoordinateCount uint32 + Coordinates [][2]uint32 + Unknown1 string + SoundEffect string + Unknown2 string + HasCamp bool + Camp struct { + Params [7]uint32 + Array []byte + Extra string + } + + Version int +} + +func NewFrame(version int) *Frame { + return &Frame{Version: version} +} + +func (f *Frame) Decode(rd io.Reader) error { + if err := binary.Read(rd, end, &f.Duration); err != nil { + return err + } + if err := binary.Read(rd, end, &f.PlaneCount); err != nil { + return err + } + f.Planes = make([]*Plane, int(f.PlaneCount)) + for i := range f.Planes { + f.Planes[i] = &Plane{} + if err := f.Planes[i].Decode(rd); err != nil { + return err + } + } + if f.Version != 300 { + if err := binary.Read(rd, end, &f.CoordinateCount); err != nil { + return err + } + f.Coordinates = make([][2]uint32, f.CoordinateCount) + for i := range f.Coordinates { + if err := binary.Read(rd, end, f.Coordinates[i][:]); err != nil { + return err + } + } + } + switch f.Version { + case 300, 301: + if err := discardN(rd, 144); err != nil { + return err + } + case 302, 303: + if err := discardN(rd, 96); err != nil { + return err + } + } + if f.Version >= 302 { + // entry blocks + if err := discardN(rd, 28*6); err != nil { + return err + } + } + // unknown1 + if err := discardN(rd, 44); err != nil { + return err + } + //sound_effect + if err := discardN(rd, 18); err != nil { + return err + } + // unknown2 + if err := discardN(rd, 18); err != nil { + return err + } + var cast uint32 + if err := binary.Read(rd, end, &cast); err != nil { + return err + } + // camp + f.HasCamp = (f.Version >= 303 && (cast > 0)) + if f.HasCamp { + if err := binary.Read(rd, end, f.Camp.Params[:]); err != nil { + return err + } + sz := int(f.Camp.Params[1]) * int(f.Camp.Params[2]) + f.Camp.Array = make([]byte, sz) + if _, err := io.ReadFull(rd, f.Camp.Array); err != nil { + return err + } + if err := discardN(rd, 20); err != nil { + return err + } + } + + return nil +} diff --git a/common/nori/gawi.go b/common/nori/gawi.go new file mode 100644 index 0000000..40ea080 --- /dev/null +++ b/common/nori/gawi.go @@ -0,0 +1,85 @@ +package nori + +import ( + "encoding/binary" + "fmt" + "io" +) + +type GawiSection struct { + Version uint32 + Bpp uint32 + IsCompressed bool + Params [4]uint32 + BmpCount uint32 + Size uint32 + + HasPalette bool + Palette *PaletteSection + Images []*Image + + lastSignature [4]byte +} + +func (g *GawiSection) Decode(rd io.Reader) error { + if _, err := io.ReadFull(rd, g.lastSignature[:]); err != nil { + return err + } + if sig, target := string(g.lastSignature[:]), "GAWI"; sig != target { + return fmt.Errorf("bad sig: want %s, got %s", target, sig) + } + if err := binary.Read(rd, end, &g.Version); err != nil { + return err + } + if g.Version != 300 { + return fmt.Errorf("bad ver: want 300, got %d", g.Version) + } + if err := binary.Read(rd, end, &g.Bpp); err != nil { + return err + } + good := false + for _, v := range [3]uint32{8, 16, 24} { + if g.Bpp == v { + good = true + } + } + if !good { + return fmt.Errorf("bad bpp: %d", g.Bpp) + } + var container uint32 + if err := binary.Read(rd, end, &container); err != nil { + return err + } + g.IsCompressed = (container == 1) + if err := binary.Read(rd, end, &container); err != nil { + return err + } + g.HasPalette = (container > 0) + + if err := binary.Read(rd, end, g.Params[:]); err != nil { + return err + } + if err := binary.Read(rd, end, &g.BmpCount); err != nil { + return err + } + if err := binary.Read(rd, end, &g.Size); err != nil { + return err + } + if g.HasPalette { + g.Palette = &PaletteSection{} + if err := g.Palette.Decode(rd); err != nil { + return err + } + } + if err := discardN(rd, 4*int(g.BmpCount)); err != nil { + return err + } + g.Images = make([]*Image, int(g.BmpCount)) + for i := range g.Images { + g.Images[i] = &Image{Bpp: g.Bpp} + if err := g.Images[i].Decode(rd, g.Palette); err != nil { + return err + } + } + return nil +} diff --git a/common/nori/image.go b/common/nori/image.go index 807c763..8efae96 100644 --- a/common/nori/image.go +++ b/common/nori/image.go @@ -1,7 +1,6 @@ package nori import ( - "bufio" "encoding/binary" "fmt" "image" @@ -25,7 +24,37 @@ type Image struct { Img image.Image } -func (i *Image) Decode(rd *bufio.Reader, palette *PaletteSection) error { +func (i *Image) Decode(rd io.Reader, palette *PaletteSection) error { + if err := binary.Read(rd, end, &i.Count); err != nil { + return err + } + if i.Count != 1 { + return fmt.Errorf("img count should be 1") + } + + if err := binary.Read(rd, end, &i.Size); err != nil { + return err + } + + if err := binary.Read(rd, end, &i.Width); err != nil { + return err + } + + if err := binary.Read(rd, end, &i.Height); err != nil { + return err + } + + if err := binary.Read(rd, end, &i.Delay); err != nil { + return err + } + + if err := binary.Read(rd, end, &i.OffsetX); err != nil { + return err + } + + if err := binary.Read(rd, end, &i.OffsetY); err != nil { + return err + } cf := image.NewRGBA64(image.Rect(0, 0, int(i.Width), int(i.Height))) i.Img = cf switch i.Bpp { @@ -34,7 +63,7 @@ func (i *Image) Decode(rd *bufio.Reader, palette *PaletteSection) error { return fmt.Errorf("bpp = 8, but no palette") } for idx := 0; idx < int(i.Size); idx++ { - b, err := rd.ReadByte() + b, err := readByte(rd) if err != nil { return err } diff --git a/common/nori/nori.go b/common/nori/nori.go index e1e3f49..9c7dbb0 100644 --- a/common/nori/nori.go +++ b/common/nori/nori.go @@ -1,29 +1,10 @@ package nori -import "image/color" - -type PaletteSection struct { - Version uint32 - Params [4]uint32 - Divided bool - DataLength uint32 - Palette [256]color.Color - MainBound [2]uint32 -} - -type GawiSection struct { - Version uint32 - Bpp uint32 - IsCompressed bool - Params [4]uint32 - BmpCount uint32 - Size uint32 - - HasPalette bool - Palette *PaletteSection - // std::vector bmp_offsets - Images []*Image -} +import ( + "encoding/binary" + "fmt" + "io" +) type Nori struct { Version uint32 @@ -32,9 +13,49 @@ type Nori struct { SizeNoGawi uint32 TotalSize uint32 - Gawi *GawiSection - Animations []*Animation - AnimationByKey map[string]*Animation + Gawi *GawiSection + Animations []*Animation + //AnimationByKey map[string]*Animation lastSignature [4]byte } + +func (n *Nori) Decode(r io.Reader) error { + rd := reflectReader(r) + n.Gawi = &GawiSection{} + if _, err := io.ReadFull(rd, n.lastSignature[:]); err != nil { + return err + } + if sig, target := string(n.lastSignature[:]), "NORI"; sig != target { + return fmt.Errorf("expected header %s, got %s", target, sig) + } + if err := binary.Read(rd, end, &n.Version); err != nil { + return err + } + if err := binary.Read(rd, end, n.Params[:]); err != nil { + return err + } + if err := binary.Read(rd, end, &n.AnimationCount); err != nil { + return err + } + if err := binary.Read(rd, end, &n.SizeNoGawi); err != nil { + return err + } + if err := binary.Read(rd, end, &n.TotalSize); err != nil { + return err + } + if err := n.Gawi.Decode(rd); err != nil { + return err + } + if err := discardN(rd, 4*int(n.AnimationCount)); err != nil { + return err + } + n.Animations = make([]*Animation, n.AnimationCount) + for i := range n.Animations { + n.Animations[i] = NewAnimation(int(n.Version)) + if err := n.Animations[i].Decode(rd); err != nil { + return err + } + } + return nil +} diff --git a/common/nori/palette.go b/common/nori/palette.go new file mode 100644 index 0000000..83fc8c6 --- /dev/null +++ b/common/nori/palette.go @@ -0,0 +1,67 @@ +package nori + +import ( + "encoding/binary" + "fmt" + "image/color" + "io" +) + +type PaletteSection struct { + Version uint32 + Params [4]uint32 + Divided bool + DataLength uint32 + Palette [256]color.Color + MainBound [2]uint32 + + lastSignature [4]byte +} + +func (p *PaletteSection) Decode(rd io.Reader) error { + if _, err := io.ReadFull(rd, p.lastSignature[:]); err != nil { + return err + } + if sig, target := string(p.lastSignature[:]), "PAL_"; sig != target { + return fmt.Errorf("bad sig: want %s, got %s", target, sig) + } + p.Palette = [256]color.Color{} + if err := binary.Read(rd, end, &p.Version); err != nil { + return err + } + if err := binary.Read(rd, end, p.Params[:]); err != nil { + return err + } + var cast uint32 + if err := binary.Read(rd, end, &cast); err != nil { + return err + } + p.Divided = (cast > 0) + if err := binary.Read(rd, end, &p.DataLength); err != nil { + return err + } + for i := 0; i < 256; i++ { + rgb := [3]byte{} + _, err := io.ReadFull(rd, rgb[:]) + if err != nil { + return err + } + alpha := uint8(0xff) + if rgb[0] == 0x00 && rgb[1] == 0xff && rgb[2] == 0x00 { + alpha = 0x00 + } + if rgb[0] == 0xff && rgb[1] == 0x00 && rgb[2] == 0xff { + alpha = 0x00 + } + p.Palette[i] = &color.RGBA{ + rgb[0], rgb[1], rgb[2], + alpha, + } + } + if p.Divided { + if err := binary.Read(rd, end, p.MainBound[:]); err != nil { + return err + } + } + return nil +} diff --git a/common/nori/plane.go b/common/nori/plane.go new file mode 100644 index 0000000..cc3ce61 --- /dev/null +++ b/common/nori/plane.go @@ -0,0 +1,41 @@ +package nori + +import ( + "encoding/binary" + "io" +) + +type Plane struct { + BitmapId uint32 + PlaneX int32 + PlaneY int32 + Opacity uint32 + Blend BlendMode + FlagParam uint32 + RenderFlag uint32 +} + +func (p *Plane) Decode(r io.Reader) error { + if err := binary.Read(r, end, &p.BitmapId); err != nil { + return err + } + if err := binary.Read(r, end, &p.PlaneX); err != nil { + return err + } + if err := binary.Read(r, end, &p.PlaneY); err != nil { + return err + } + if err := binary.Read(r, end, &p.Opacity); err != nil { + return err + } + if err := binary.Read(r, end, &p.RenderFlag); err != nil { + return err + } + if err := binary.Read(r, end, &p.Blend); err != nil { + return err + } + if err := binary.Read(r, end, &p.FlagParam); err != nil { + return err + } + return nil +} diff --git a/common/nori/reader.go b/common/nori/reader.go deleted file mode 100644 index 7ec3660..0000000 --- a/common/nori/reader.go +++ /dev/null @@ -1,219 +0,0 @@ -package nori - -import ( - "bufio" - "encoding/binary" - "fmt" - "image/color" - "io" -) - -var end = binary.LittleEndian - -type Reader struct { - nori *Nori - - r *bufio.Reader -} - -func NewReader(rd io.Reader) *Reader { - o := &Reader{ - nori: &Nori{}, - r: bufio.NewReader(rd), - } - return o -} - -func (n *Reader) Decode() (*Nori, error) { - if _, err := io.ReadFull(n, n.nori.lastSignature[:]); err != nil { - return n.nori, err - } - if sig, target := string(n.nori.lastSignature[:]), "NORI"; sig != target { - return n.nori, fmt.Errorf("expected header %s, got %s", target, sig) - } - if err := binary.Read(n, end, &n.nori.Version); err != nil { - return n.nori, err - } - if err := binary.Read(n, end, n.nori.Params[:]); err != nil { - return n.nori, err - } - if err := binary.Read(n, end, &n.nori.AnimationCount); err != nil { - return n.nori, err - } - if err := binary.Read(n, end, &n.nori.SizeNoGawi); err != nil { - return n.nori, err - } - if err := binary.Read(n, end, &n.nori.TotalSize); err != nil { - return n.nori, err - } - if err := n.decodeGawi(); err != nil { - return n.nori, err - } - return n.nori, nil -} - -func (n *Reader) decodeGawi() error { - g := &GawiSection{} - n.nori.Gawi = g - if _, err := io.ReadFull(n, n.nori.lastSignature[:]); err != nil { - return err - } - if sig, target := string(n.nori.lastSignature[:]), "GAWI"; sig != target { - return fmt.Errorf("bad sig: want %s, got %s", target, sig) - } - if err := binary.Read(n, end, &g.Version); err != nil { - return err - } - if g.Version != 300 { - return fmt.Errorf("bad ver: want 300, got %d", g.Version) - } - if err := binary.Read(n, end, &g.Bpp); err != nil { - return err - } - good := false - for _, v := range [3]uint32{8, 16, 24} { - if g.Bpp == v { - good = true - } - } - if !good { - return fmt.Errorf("bad bpp: %d", g.Bpp) - } - var container uint32 - if err := binary.Read(n, end, &container); err != nil { - return err - } - g.IsCompressed = (container == 1) - if err := binary.Read(n, end, &container); err != nil { - return err - } - g.HasPalette = (container > 0) - - if err := binary.Read(n, end, g.Params[:]); err != nil { - return err - } - if err := binary.Read(n, end, &g.BmpCount); err != nil { - return err - } - if err := binary.Read(n, end, &g.Size); err != nil { - return err - } - if g.HasPalette { - if err := n.decodePalette(); err != nil { - return err - } - } - if _, err := n.r.Discard(4 * int(g.BmpCount)); err != nil { - return err - } - g.Images = make([]*Image, int(g.BmpCount)) - for i := range g.Images { - g.Images[i] = &Image{Bpp: g.Bpp} - if err := n.decodeImage(g.Images[i]); err != nil { - return err - } - } - if _, err := n.r.Discard(4 * int(n.nori.AnimationCount)); err != nil { - return err - } - n.nori.Animations = make([]*Animation, n.nori.AnimationCount) - for i := range n.nori.Animations { - n.nori.Animations[i] = &Animation{} - if err := n.nori.Animations[i].Decode(n.r, int(n.nori.Version)); err != nil { - return err - } - } - return nil -} - -func (n *Reader) decodePalette() error { - if _, err := io.ReadFull(n, n.nori.lastSignature[:]); err != nil { - return err - } - if sig, target := string(n.nori.lastSignature[:]), "PAL_"; sig != target { - return fmt.Errorf("bad sig: want %s, got %s", target, sig) - } - cp := &PaletteSection{ - Palette: [256]color.Color{}, - } - n.nori.Gawi.Palette = cp - if err := binary.Read(n, end, &cp.Version); err != nil { - return err - } - if err := binary.Read(n, end, cp.Params[:]); err != nil { - return err - } - var cast uint32 - if err := binary.Read(n, end, &cast); err != nil { - return err - } - cp.Divided = (cast > 0) - if err := binary.Read(n, end, &cp.DataLength); err != nil { - return err - } - for i := 0; i < 256; i++ { - rgb := [3]byte{} - _, err := io.ReadFull(n, rgb[:]) - if err != nil { - return err - } - alpha := uint8(0xff) - if rgb[0] == 0x00 && rgb[1] == 0xff && rgb[2] == 0x00 { - alpha = 0x00 - } - if rgb[0] == 0xff && rgb[1] == 0x00 && rgb[2] == 0xff { - alpha = 0x00 - } - cp.Palette[i] = &color.RGBA{ - rgb[0], rgb[1], rgb[2], - alpha, - } - } - - if cp.Divided { - if err := binary.Read(n, end, cp.MainBound[:]); err != nil { - return err - } - } - return nil -} -func (n *Reader) decodeImage(img *Image) error { - if err := binary.Read(n, end, &img.Count); err != nil { - return err - } - if img.Count != 1 { - return fmt.Errorf("img count should be 1") - } - - if err := binary.Read(n, end, &img.Size); err != nil { - return err - } - - if err := binary.Read(n, end, &img.Width); err != nil { - return err - } - - if err := binary.Read(n, end, &img.Height); err != nil { - return err - } - - if err := binary.Read(n, end, &img.Delay); err != nil { - return err - } - - if err := binary.Read(n, end, &img.OffsetX); err != nil { - return err - } - - if err := binary.Read(n, end, &img.OffsetY); err != nil { - return err - } - if err := img.Decode(n.r, n.nori.Gawi.Palette); err != nil { - return err - } - return nil -} - -func (n *Reader) Read(b []byte) (int, error) { - return n.r.Read(b) -} diff --git a/common/nori/export.go b/common/nori/render.go similarity index 86% rename from common/nori/export.go rename to common/nori/render.go index d4a1ed1..35f1e82 100644 --- a/common/nori/export.go +++ b/common/nori/render.go @@ -10,23 +10,7 @@ import ( "gitlab.com/gfxlabs/gfximg/apng" ) -func (n *Nori) ShowAnimation() *apng.APNG { - g := n.Gawi - a := &apng.APNG{ - Frames: make([]apng.Frame, 0, len(g.Images)), - } - for i := 0; i < len(g.Images); i++ { - fr := apng.Frame{ - Image: g.Images[i].Img, - DelayNumerator: uint16(g.Images[i].Delay), - DelayDenominator: 1000, - } - a.Frames = append(a.Frames, fr) - } - return a -} - -func (n *Nori) ExportAnimation(num int) (*apng.APNG, error) { +func (n *Nori) RenderAnimation(num int) (*apng.APNG, error) { g := n.Gawi a := &apng.APNG{ Frames: make([]apng.Frame, 0, len(g.Images)), diff --git a/common/nori/nori_test.go b/common/nori/render_test.go similarity index 63% rename from common/nori/nori_test.go rename to common/nori/render_test.go index 4ff89bf..3179c4d 100644 --- a/common/nori/nori_test.go +++ b/common/nori/render_test.go @@ -11,11 +11,7 @@ import ( ) func TestParseFile1(t *testing.T) { - rd, err := os.OpenFile("./nori_test/test1.nri", os.O_RDONLY, 0666) - if err != nil { - t.Errorf("open file: %s", err) - } - nori, err := NewReader(rd).Decode() + nori, err := FromFile("./render_test/test1.nri") if err != nil { t.Errorf("decode: %s", err) } @@ -28,11 +24,7 @@ func TestParseFile1(t *testing.T) { } func TestParseFile2(t *testing.T) { - rd, err := os.OpenFile("./nori_test/test2.nri", os.O_RDONLY, 0666) - if err != nil { - t.Errorf("open file: %s", err) - } - nori, err := NewReader(rd).Decode() + nori, err := FromFile("./render_test/test2.nri") if err != nil { t.Errorf("decode: %s", err) } @@ -44,11 +36,7 @@ func TestParseFile2(t *testing.T) { } func TestParsePalette(t *testing.T) { - rd, err := os.OpenFile("./nori_test/palette.nri", os.O_RDONLY, 0666) - if err != nil { - t.Errorf("open file: %s", err) - } - nori, err := NewReader(rd).Decode() + nori, err := FromFile("./render_test/palette.nri") if err != nil { t.Errorf("decode: %s", err) } @@ -62,9 +50,9 @@ func TestParsePalette(t *testing.T) { func writeApng(nori *Nori, name string) error { postfix := ".example" out := new(bytes.Buffer) - os.MkdirAll(fmt.Sprintf("./nori_test/%s%s", name, postfix), 0740) + os.MkdirAll(fmt.Sprintf("./render_test/%s%s", name, postfix), 0740) for i := range nori.Animations { - a, err := nori.ExportAnimation(i) + a, err := nori.RenderAnimation(i) if err != nil { if strings.Contains(err.Error(), "no frame") { continue @@ -75,7 +63,7 @@ func writeApng(nori *Nori, name string) error { if err != nil { return err } - err = os.WriteFile(fmt.Sprintf("./nori_test/%s%s/animation_%d.png", name, postfix, i), out.Bytes(), 0740) + err = os.WriteFile(fmt.Sprintf("./render_test/%s%s/animation_%d.png", name, postfix, i), out.Bytes(), 0740) if err != nil { return err } diff --git a/common/nori/nori_test/palette.example/animation_0.png b/common/nori/render_test/palette.example/animation_0.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_0.png rename to common/nori/render_test/palette.example/animation_0.png diff --git a/common/nori/nori_test/palette.example/animation_1.png b/common/nori/render_test/palette.example/animation_1.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_1.png rename to common/nori/render_test/palette.example/animation_1.png diff --git a/common/nori/nori_test/palette.example/animation_10.png b/common/nori/render_test/palette.example/animation_10.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_10.png rename to common/nori/render_test/palette.example/animation_10.png diff --git a/common/nori/nori_test/palette.example/animation_100.png b/common/nori/render_test/palette.example/animation_100.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_100.png rename to common/nori/render_test/palette.example/animation_100.png diff --git a/common/nori/nori_test/palette.example/animation_101.png b/common/nori/render_test/palette.example/animation_101.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_101.png rename to common/nori/render_test/palette.example/animation_101.png diff --git a/common/nori/nori_test/palette.example/animation_102.png b/common/nori/render_test/palette.example/animation_102.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_102.png rename to common/nori/render_test/palette.example/animation_102.png diff --git a/common/nori/nori_test/palette.example/animation_103.png b/common/nori/render_test/palette.example/animation_103.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_103.png rename to common/nori/render_test/palette.example/animation_103.png diff --git a/common/nori/nori_test/palette.example/animation_104.png b/common/nori/render_test/palette.example/animation_104.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_104.png rename to common/nori/render_test/palette.example/animation_104.png diff --git a/common/nori/nori_test/palette.example/animation_105.png b/common/nori/render_test/palette.example/animation_105.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_105.png rename to common/nori/render_test/palette.example/animation_105.png diff --git a/common/nori/nori_test/palette.example/animation_106.png b/common/nori/render_test/palette.example/animation_106.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_106.png rename to common/nori/render_test/palette.example/animation_106.png diff --git a/common/nori/nori_test/palette.example/animation_107.png b/common/nori/render_test/palette.example/animation_107.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_107.png rename to common/nori/render_test/palette.example/animation_107.png diff --git a/common/nori/nori_test/palette.example/animation_108.png b/common/nori/render_test/palette.example/animation_108.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_108.png rename to common/nori/render_test/palette.example/animation_108.png diff --git a/common/nori/nori_test/palette.example/animation_109.png b/common/nori/render_test/palette.example/animation_109.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_109.png rename to common/nori/render_test/palette.example/animation_109.png diff --git a/common/nori/nori_test/palette.example/animation_11.png b/common/nori/render_test/palette.example/animation_11.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_11.png rename to common/nori/render_test/palette.example/animation_11.png diff --git a/common/nori/nori_test/palette.example/animation_110.png b/common/nori/render_test/palette.example/animation_110.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_110.png rename to common/nori/render_test/palette.example/animation_110.png diff --git a/common/nori/nori_test/palette.example/animation_111.png b/common/nori/render_test/palette.example/animation_111.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_111.png rename to common/nori/render_test/palette.example/animation_111.png diff --git a/common/nori/nori_test/palette.example/animation_112.png b/common/nori/render_test/palette.example/animation_112.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_112.png rename to common/nori/render_test/palette.example/animation_112.png diff --git a/common/nori/nori_test/palette.example/animation_113.png b/common/nori/render_test/palette.example/animation_113.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_113.png rename to common/nori/render_test/palette.example/animation_113.png diff --git a/common/nori/nori_test/palette.example/animation_114.png b/common/nori/render_test/palette.example/animation_114.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_114.png rename to common/nori/render_test/palette.example/animation_114.png diff --git a/common/nori/nori_test/palette.example/animation_115.png b/common/nori/render_test/palette.example/animation_115.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_115.png rename to common/nori/render_test/palette.example/animation_115.png diff --git a/common/nori/nori_test/palette.example/animation_116.png b/common/nori/render_test/palette.example/animation_116.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_116.png rename to common/nori/render_test/palette.example/animation_116.png diff --git a/common/nori/nori_test/palette.example/animation_117.png b/common/nori/render_test/palette.example/animation_117.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_117.png rename to common/nori/render_test/palette.example/animation_117.png diff --git a/common/nori/nori_test/palette.example/animation_118.png b/common/nori/render_test/palette.example/animation_118.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_118.png rename to common/nori/render_test/palette.example/animation_118.png diff --git a/common/nori/nori_test/palette.example/animation_119.png b/common/nori/render_test/palette.example/animation_119.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_119.png rename to common/nori/render_test/palette.example/animation_119.png diff --git a/common/nori/nori_test/palette.example/animation_12.png b/common/nori/render_test/palette.example/animation_12.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_12.png rename to common/nori/render_test/palette.example/animation_12.png diff --git a/common/nori/nori_test/palette.example/animation_120.png b/common/nori/render_test/palette.example/animation_120.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_120.png rename to common/nori/render_test/palette.example/animation_120.png diff --git a/common/nori/nori_test/palette.example/animation_121.png b/common/nori/render_test/palette.example/animation_121.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_121.png rename to common/nori/render_test/palette.example/animation_121.png diff --git a/common/nori/nori_test/palette.example/animation_122.png b/common/nori/render_test/palette.example/animation_122.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_122.png rename to common/nori/render_test/palette.example/animation_122.png diff --git a/common/nori/nori_test/palette.example/animation_123.png b/common/nori/render_test/palette.example/animation_123.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_123.png rename to common/nori/render_test/palette.example/animation_123.png diff --git a/common/nori/nori_test/palette.example/animation_124.png b/common/nori/render_test/palette.example/animation_124.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_124.png rename to common/nori/render_test/palette.example/animation_124.png diff --git a/common/nori/nori_test/palette.example/animation_125.png b/common/nori/render_test/palette.example/animation_125.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_125.png rename to common/nori/render_test/palette.example/animation_125.png diff --git a/common/nori/nori_test/palette.example/animation_126.png b/common/nori/render_test/palette.example/animation_126.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_126.png rename to common/nori/render_test/palette.example/animation_126.png diff --git a/common/nori/nori_test/palette.example/animation_127.png b/common/nori/render_test/palette.example/animation_127.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_127.png rename to common/nori/render_test/palette.example/animation_127.png diff --git a/common/nori/nori_test/palette.example/animation_128.png b/common/nori/render_test/palette.example/animation_128.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_128.png rename to common/nori/render_test/palette.example/animation_128.png diff --git a/common/nori/nori_test/palette.example/animation_129.png b/common/nori/render_test/palette.example/animation_129.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_129.png rename to common/nori/render_test/palette.example/animation_129.png diff --git a/common/nori/nori_test/palette.example/animation_13.png b/common/nori/render_test/palette.example/animation_13.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_13.png rename to common/nori/render_test/palette.example/animation_13.png diff --git a/common/nori/nori_test/palette.example/animation_130.png b/common/nori/render_test/palette.example/animation_130.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_130.png rename to common/nori/render_test/palette.example/animation_130.png diff --git a/common/nori/nori_test/palette.example/animation_131.png b/common/nori/render_test/palette.example/animation_131.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_131.png rename to common/nori/render_test/palette.example/animation_131.png diff --git a/common/nori/nori_test/palette.example/animation_132.png b/common/nori/render_test/palette.example/animation_132.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_132.png rename to common/nori/render_test/palette.example/animation_132.png diff --git a/common/nori/nori_test/palette.example/animation_133.png b/common/nori/render_test/palette.example/animation_133.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_133.png rename to common/nori/render_test/palette.example/animation_133.png diff --git a/common/nori/nori_test/palette.example/animation_134.png b/common/nori/render_test/palette.example/animation_134.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_134.png rename to common/nori/render_test/palette.example/animation_134.png diff --git a/common/nori/nori_test/palette.example/animation_135.png b/common/nori/render_test/palette.example/animation_135.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_135.png rename to common/nori/render_test/palette.example/animation_135.png diff --git a/common/nori/nori_test/palette.example/animation_136.png b/common/nori/render_test/palette.example/animation_136.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_136.png rename to common/nori/render_test/palette.example/animation_136.png diff --git a/common/nori/nori_test/palette.example/animation_137.png b/common/nori/render_test/palette.example/animation_137.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_137.png rename to common/nori/render_test/palette.example/animation_137.png diff --git a/common/nori/nori_test/palette.example/animation_138.png b/common/nori/render_test/palette.example/animation_138.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_138.png rename to common/nori/render_test/palette.example/animation_138.png diff --git a/common/nori/nori_test/palette.example/animation_139.png b/common/nori/render_test/palette.example/animation_139.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_139.png rename to common/nori/render_test/palette.example/animation_139.png diff --git a/common/nori/nori_test/palette.example/animation_14.png b/common/nori/render_test/palette.example/animation_14.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_14.png rename to common/nori/render_test/palette.example/animation_14.png diff --git a/common/nori/nori_test/palette.example/animation_140.png b/common/nori/render_test/palette.example/animation_140.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_140.png rename to common/nori/render_test/palette.example/animation_140.png diff --git a/common/nori/nori_test/palette.example/animation_15.png b/common/nori/render_test/palette.example/animation_15.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_15.png rename to common/nori/render_test/palette.example/animation_15.png diff --git a/common/nori/nori_test/palette.example/animation_157.png b/common/nori/render_test/palette.example/animation_157.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_157.png rename to common/nori/render_test/palette.example/animation_157.png diff --git a/common/nori/nori_test/palette.example/animation_158.png b/common/nori/render_test/palette.example/animation_158.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_158.png rename to common/nori/render_test/palette.example/animation_158.png diff --git a/common/nori/nori_test/palette.example/animation_159.png b/common/nori/render_test/palette.example/animation_159.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_159.png rename to common/nori/render_test/palette.example/animation_159.png diff --git a/common/nori/nori_test/palette.example/animation_16.png b/common/nori/render_test/palette.example/animation_16.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_16.png rename to common/nori/render_test/palette.example/animation_16.png diff --git a/common/nori/nori_test/palette.example/animation_160.png b/common/nori/render_test/palette.example/animation_160.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_160.png rename to common/nori/render_test/palette.example/animation_160.png diff --git a/common/nori/nori_test/palette.example/animation_161.png b/common/nori/render_test/palette.example/animation_161.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_161.png rename to common/nori/render_test/palette.example/animation_161.png diff --git a/common/nori/nori_test/palette.example/animation_162.png b/common/nori/render_test/palette.example/animation_162.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_162.png rename to common/nori/render_test/palette.example/animation_162.png diff --git a/common/nori/nori_test/palette.example/animation_163.png b/common/nori/render_test/palette.example/animation_163.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_163.png rename to common/nori/render_test/palette.example/animation_163.png diff --git a/common/nori/nori_test/palette.example/animation_166.png b/common/nori/render_test/palette.example/animation_166.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_166.png rename to common/nori/render_test/palette.example/animation_166.png diff --git a/common/nori/nori_test/palette.example/animation_17.png b/common/nori/render_test/palette.example/animation_17.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_17.png rename to common/nori/render_test/palette.example/animation_17.png diff --git a/common/nori/nori_test/palette.example/animation_18.png b/common/nori/render_test/palette.example/animation_18.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_18.png rename to common/nori/render_test/palette.example/animation_18.png diff --git a/common/nori/nori_test/palette.example/animation_19.png b/common/nori/render_test/palette.example/animation_19.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_19.png rename to common/nori/render_test/palette.example/animation_19.png diff --git a/common/nori/nori_test/palette.example/animation_2.png b/common/nori/render_test/palette.example/animation_2.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_2.png rename to common/nori/render_test/palette.example/animation_2.png diff --git a/common/nori/nori_test/palette.example/animation_20.png b/common/nori/render_test/palette.example/animation_20.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_20.png rename to common/nori/render_test/palette.example/animation_20.png diff --git a/common/nori/nori_test/palette.example/animation_21.png b/common/nori/render_test/palette.example/animation_21.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_21.png rename to common/nori/render_test/palette.example/animation_21.png diff --git a/common/nori/nori_test/palette.example/animation_22.png b/common/nori/render_test/palette.example/animation_22.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_22.png rename to common/nori/render_test/palette.example/animation_22.png diff --git a/common/nori/nori_test/palette.example/animation_23.png b/common/nori/render_test/palette.example/animation_23.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_23.png rename to common/nori/render_test/palette.example/animation_23.png diff --git a/common/nori/nori_test/palette.example/animation_24.png b/common/nori/render_test/palette.example/animation_24.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_24.png rename to common/nori/render_test/palette.example/animation_24.png diff --git a/common/nori/nori_test/palette.example/animation_25.png b/common/nori/render_test/palette.example/animation_25.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_25.png rename to common/nori/render_test/palette.example/animation_25.png diff --git a/common/nori/nori_test/palette.example/animation_26.png b/common/nori/render_test/palette.example/animation_26.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_26.png rename to common/nori/render_test/palette.example/animation_26.png diff --git a/common/nori/nori_test/palette.example/animation_27.png b/common/nori/render_test/palette.example/animation_27.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_27.png rename to common/nori/render_test/palette.example/animation_27.png diff --git a/common/nori/nori_test/palette.example/animation_28.png b/common/nori/render_test/palette.example/animation_28.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_28.png rename to common/nori/render_test/palette.example/animation_28.png diff --git a/common/nori/nori_test/palette.example/animation_29.png b/common/nori/render_test/palette.example/animation_29.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_29.png rename to common/nori/render_test/palette.example/animation_29.png diff --git a/common/nori/nori_test/palette.example/animation_3.png b/common/nori/render_test/palette.example/animation_3.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_3.png rename to common/nori/render_test/palette.example/animation_3.png diff --git a/common/nori/nori_test/palette.example/animation_30.png b/common/nori/render_test/palette.example/animation_30.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_30.png rename to common/nori/render_test/palette.example/animation_30.png diff --git a/common/nori/nori_test/palette.example/animation_31.png b/common/nori/render_test/palette.example/animation_31.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_31.png rename to common/nori/render_test/palette.example/animation_31.png diff --git a/common/nori/nori_test/palette.example/animation_32.png b/common/nori/render_test/palette.example/animation_32.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_32.png rename to common/nori/render_test/palette.example/animation_32.png diff --git a/common/nori/nori_test/palette.example/animation_33.png b/common/nori/render_test/palette.example/animation_33.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_33.png rename to common/nori/render_test/palette.example/animation_33.png diff --git a/common/nori/nori_test/palette.example/animation_34.png b/common/nori/render_test/palette.example/animation_34.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_34.png rename to common/nori/render_test/palette.example/animation_34.png diff --git a/common/nori/nori_test/palette.example/animation_35.png b/common/nori/render_test/palette.example/animation_35.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_35.png rename to common/nori/render_test/palette.example/animation_35.png diff --git a/common/nori/nori_test/palette.example/animation_36.png b/common/nori/render_test/palette.example/animation_36.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_36.png rename to common/nori/render_test/palette.example/animation_36.png diff --git a/common/nori/nori_test/palette.example/animation_37.png b/common/nori/render_test/palette.example/animation_37.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_37.png rename to common/nori/render_test/palette.example/animation_37.png diff --git a/common/nori/nori_test/palette.example/animation_38.png b/common/nori/render_test/palette.example/animation_38.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_38.png rename to common/nori/render_test/palette.example/animation_38.png diff --git a/common/nori/nori_test/palette.example/animation_39.png b/common/nori/render_test/palette.example/animation_39.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_39.png rename to common/nori/render_test/palette.example/animation_39.png diff --git a/common/nori/nori_test/palette.example/animation_4.png b/common/nori/render_test/palette.example/animation_4.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_4.png rename to common/nori/render_test/palette.example/animation_4.png diff --git a/common/nori/nori_test/palette.example/animation_40.png b/common/nori/render_test/palette.example/animation_40.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_40.png rename to common/nori/render_test/palette.example/animation_40.png diff --git a/common/nori/nori_test/palette.example/animation_41.png b/common/nori/render_test/palette.example/animation_41.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_41.png rename to common/nori/render_test/palette.example/animation_41.png diff --git a/common/nori/nori_test/palette.example/animation_42.png b/common/nori/render_test/palette.example/animation_42.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_42.png rename to common/nori/render_test/palette.example/animation_42.png diff --git a/common/nori/nori_test/palette.example/animation_43.png b/common/nori/render_test/palette.example/animation_43.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_43.png rename to common/nori/render_test/palette.example/animation_43.png diff --git a/common/nori/nori_test/palette.example/animation_44.png b/common/nori/render_test/palette.example/animation_44.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_44.png rename to common/nori/render_test/palette.example/animation_44.png diff --git a/common/nori/nori_test/palette.example/animation_45.png b/common/nori/render_test/palette.example/animation_45.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_45.png rename to common/nori/render_test/palette.example/animation_45.png diff --git a/common/nori/nori_test/palette.example/animation_46.png b/common/nori/render_test/palette.example/animation_46.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_46.png rename to common/nori/render_test/palette.example/animation_46.png diff --git a/common/nori/nori_test/palette.example/animation_47.png b/common/nori/render_test/palette.example/animation_47.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_47.png rename to common/nori/render_test/palette.example/animation_47.png diff --git a/common/nori/nori_test/palette.example/animation_48.png b/common/nori/render_test/palette.example/animation_48.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_48.png rename to common/nori/render_test/palette.example/animation_48.png diff --git a/common/nori/nori_test/palette.example/animation_49.png b/common/nori/render_test/palette.example/animation_49.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_49.png rename to common/nori/render_test/palette.example/animation_49.png diff --git a/common/nori/nori_test/palette.example/animation_5.png b/common/nori/render_test/palette.example/animation_5.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_5.png rename to common/nori/render_test/palette.example/animation_5.png diff --git a/common/nori/nori_test/palette.example/animation_50.png b/common/nori/render_test/palette.example/animation_50.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_50.png rename to common/nori/render_test/palette.example/animation_50.png diff --git a/common/nori/nori_test/palette.example/animation_51.png b/common/nori/render_test/palette.example/animation_51.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_51.png rename to common/nori/render_test/palette.example/animation_51.png diff --git a/common/nori/nori_test/palette.example/animation_52.png b/common/nori/render_test/palette.example/animation_52.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_52.png rename to common/nori/render_test/palette.example/animation_52.png diff --git a/common/nori/nori_test/palette.example/animation_53.png b/common/nori/render_test/palette.example/animation_53.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_53.png rename to common/nori/render_test/palette.example/animation_53.png diff --git a/common/nori/nori_test/palette.example/animation_54.png b/common/nori/render_test/palette.example/animation_54.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_54.png rename to common/nori/render_test/palette.example/animation_54.png diff --git a/common/nori/nori_test/palette.example/animation_55.png b/common/nori/render_test/palette.example/animation_55.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_55.png rename to common/nori/render_test/palette.example/animation_55.png diff --git a/common/nori/nori_test/palette.example/animation_56.png b/common/nori/render_test/palette.example/animation_56.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_56.png rename to common/nori/render_test/palette.example/animation_56.png diff --git a/common/nori/nori_test/palette.example/animation_57.png b/common/nori/render_test/palette.example/animation_57.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_57.png rename to common/nori/render_test/palette.example/animation_57.png diff --git a/common/nori/nori_test/palette.example/animation_58.png b/common/nori/render_test/palette.example/animation_58.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_58.png rename to common/nori/render_test/palette.example/animation_58.png diff --git a/common/nori/nori_test/palette.example/animation_59.png b/common/nori/render_test/palette.example/animation_59.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_59.png rename to common/nori/render_test/palette.example/animation_59.png diff --git a/common/nori/nori_test/palette.example/animation_6.png b/common/nori/render_test/palette.example/animation_6.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_6.png rename to common/nori/render_test/palette.example/animation_6.png diff --git a/common/nori/nori_test/palette.example/animation_60.png b/common/nori/render_test/palette.example/animation_60.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_60.png rename to common/nori/render_test/palette.example/animation_60.png diff --git a/common/nori/nori_test/palette.example/animation_61.png b/common/nori/render_test/palette.example/animation_61.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_61.png rename to common/nori/render_test/palette.example/animation_61.png diff --git a/common/nori/nori_test/palette.example/animation_62.png b/common/nori/render_test/palette.example/animation_62.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_62.png rename to common/nori/render_test/palette.example/animation_62.png diff --git a/common/nori/nori_test/palette.example/animation_63.png b/common/nori/render_test/palette.example/animation_63.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_63.png rename to common/nori/render_test/palette.example/animation_63.png diff --git a/common/nori/nori_test/palette.example/animation_64.png b/common/nori/render_test/palette.example/animation_64.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_64.png rename to common/nori/render_test/palette.example/animation_64.png diff --git a/common/nori/nori_test/palette.example/animation_65.png b/common/nori/render_test/palette.example/animation_65.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_65.png rename to common/nori/render_test/palette.example/animation_65.png diff --git a/common/nori/nori_test/palette.example/animation_66.png b/common/nori/render_test/palette.example/animation_66.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_66.png rename to common/nori/render_test/palette.example/animation_66.png diff --git a/common/nori/nori_test/palette.example/animation_67.png b/common/nori/render_test/palette.example/animation_67.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_67.png rename to common/nori/render_test/palette.example/animation_67.png diff --git a/common/nori/nori_test/palette.example/animation_68.png b/common/nori/render_test/palette.example/animation_68.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_68.png rename to common/nori/render_test/palette.example/animation_68.png diff --git a/common/nori/nori_test/palette.example/animation_69.png b/common/nori/render_test/palette.example/animation_69.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_69.png rename to common/nori/render_test/palette.example/animation_69.png diff --git a/common/nori/nori_test/palette.example/animation_7.png b/common/nori/render_test/palette.example/animation_7.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_7.png rename to common/nori/render_test/palette.example/animation_7.png diff --git a/common/nori/nori_test/palette.example/animation_70.png b/common/nori/render_test/palette.example/animation_70.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_70.png rename to common/nori/render_test/palette.example/animation_70.png diff --git a/common/nori/nori_test/palette.example/animation_71.png b/common/nori/render_test/palette.example/animation_71.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_71.png rename to common/nori/render_test/palette.example/animation_71.png diff --git a/common/nori/nori_test/palette.example/animation_72.png b/common/nori/render_test/palette.example/animation_72.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_72.png rename to common/nori/render_test/palette.example/animation_72.png diff --git a/common/nori/nori_test/palette.example/animation_73.png b/common/nori/render_test/palette.example/animation_73.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_73.png rename to common/nori/render_test/palette.example/animation_73.png diff --git a/common/nori/nori_test/palette.example/animation_74.png b/common/nori/render_test/palette.example/animation_74.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_74.png rename to common/nori/render_test/palette.example/animation_74.png diff --git a/common/nori/nori_test/palette.example/animation_75.png b/common/nori/render_test/palette.example/animation_75.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_75.png rename to common/nori/render_test/palette.example/animation_75.png diff --git a/common/nori/nori_test/palette.example/animation_76.png b/common/nori/render_test/palette.example/animation_76.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_76.png rename to common/nori/render_test/palette.example/animation_76.png diff --git a/common/nori/nori_test/palette.example/animation_77.png b/common/nori/render_test/palette.example/animation_77.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_77.png rename to common/nori/render_test/palette.example/animation_77.png diff --git a/common/nori/nori_test/palette.example/animation_78.png b/common/nori/render_test/palette.example/animation_78.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_78.png rename to common/nori/render_test/palette.example/animation_78.png diff --git a/common/nori/nori_test/palette.example/animation_79.png b/common/nori/render_test/palette.example/animation_79.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_79.png rename to common/nori/render_test/palette.example/animation_79.png diff --git a/common/nori/nori_test/palette.example/animation_8.png b/common/nori/render_test/palette.example/animation_8.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_8.png rename to common/nori/render_test/palette.example/animation_8.png diff --git a/common/nori/nori_test/palette.example/animation_80.png b/common/nori/render_test/palette.example/animation_80.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_80.png rename to common/nori/render_test/palette.example/animation_80.png diff --git a/common/nori/nori_test/palette.example/animation_81.png b/common/nori/render_test/palette.example/animation_81.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_81.png rename to common/nori/render_test/palette.example/animation_81.png diff --git a/common/nori/nori_test/palette.example/animation_82.png b/common/nori/render_test/palette.example/animation_82.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_82.png rename to common/nori/render_test/palette.example/animation_82.png diff --git a/common/nori/nori_test/palette.example/animation_83.png b/common/nori/render_test/palette.example/animation_83.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_83.png rename to common/nori/render_test/palette.example/animation_83.png diff --git a/common/nori/nori_test/palette.example/animation_84.png b/common/nori/render_test/palette.example/animation_84.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_84.png rename to common/nori/render_test/palette.example/animation_84.png diff --git a/common/nori/nori_test/palette.example/animation_85.png b/common/nori/render_test/palette.example/animation_85.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_85.png rename to common/nori/render_test/palette.example/animation_85.png diff --git a/common/nori/nori_test/palette.example/animation_86.png b/common/nori/render_test/palette.example/animation_86.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_86.png rename to common/nori/render_test/palette.example/animation_86.png diff --git a/common/nori/nori_test/palette.example/animation_87.png b/common/nori/render_test/palette.example/animation_87.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_87.png rename to common/nori/render_test/palette.example/animation_87.png diff --git a/common/nori/nori_test/palette.example/animation_88.png b/common/nori/render_test/palette.example/animation_88.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_88.png rename to common/nori/render_test/palette.example/animation_88.png diff --git a/common/nori/nori_test/palette.example/animation_89.png b/common/nori/render_test/palette.example/animation_89.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_89.png rename to common/nori/render_test/palette.example/animation_89.png diff --git a/common/nori/nori_test/palette.example/animation_9.png b/common/nori/render_test/palette.example/animation_9.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_9.png rename to common/nori/render_test/palette.example/animation_9.png diff --git a/common/nori/nori_test/palette.example/animation_90.png b/common/nori/render_test/palette.example/animation_90.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_90.png rename to common/nori/render_test/palette.example/animation_90.png diff --git a/common/nori/nori_test/palette.example/animation_91.png b/common/nori/render_test/palette.example/animation_91.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_91.png rename to common/nori/render_test/palette.example/animation_91.png diff --git a/common/nori/nori_test/palette.example/animation_92.png b/common/nori/render_test/palette.example/animation_92.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_92.png rename to common/nori/render_test/palette.example/animation_92.png diff --git a/common/nori/nori_test/palette.example/animation_93.png b/common/nori/render_test/palette.example/animation_93.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_93.png rename to common/nori/render_test/palette.example/animation_93.png diff --git a/common/nori/nori_test/palette.example/animation_94.png b/common/nori/render_test/palette.example/animation_94.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_94.png rename to common/nori/render_test/palette.example/animation_94.png diff --git a/common/nori/nori_test/palette.example/animation_95.png b/common/nori/render_test/palette.example/animation_95.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_95.png rename to common/nori/render_test/palette.example/animation_95.png diff --git a/common/nori/nori_test/palette.example/animation_96.png b/common/nori/render_test/palette.example/animation_96.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_96.png rename to common/nori/render_test/palette.example/animation_96.png diff --git a/common/nori/nori_test/palette.example/animation_97.png b/common/nori/render_test/palette.example/animation_97.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_97.png rename to common/nori/render_test/palette.example/animation_97.png diff --git a/common/nori/nori_test/palette.example/animation_98.png b/common/nori/render_test/palette.example/animation_98.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_98.png rename to common/nori/render_test/palette.example/animation_98.png diff --git a/common/nori/nori_test/palette.example/animation_99.png b/common/nori/render_test/palette.example/animation_99.png similarity index 100% rename from common/nori/nori_test/palette.example/animation_99.png rename to common/nori/render_test/palette.example/animation_99.png diff --git a/common/nori/nori_test/palette.nri b/common/nori/render_test/palette.nri similarity index 100% rename from common/nori/nori_test/palette.nri rename to common/nori/render_test/palette.nri diff --git a/common/nori/nori_test/test1.example/animation_0.png b/common/nori/render_test/test1.example/animation_0.png similarity index 100% rename from common/nori/nori_test/test1.example/animation_0.png rename to common/nori/render_test/test1.example/animation_0.png diff --git a/common/nori/nori_test/test1.example/animation_1.png b/common/nori/render_test/test1.example/animation_1.png similarity index 100% rename from common/nori/nori_test/test1.example/animation_1.png rename to common/nori/render_test/test1.example/animation_1.png diff --git a/common/nori/nori_test/test1.nri b/common/nori/render_test/test1.nri similarity index 100% rename from common/nori/nori_test/test1.nri rename to common/nori/render_test/test1.nri diff --git a/common/nori/nori_test/test2.example/animation_0.png b/common/nori/render_test/test2.example/animation_0.png similarity index 100% rename from common/nori/nori_test/test2.example/animation_0.png rename to common/nori/render_test/test2.example/animation_0.png diff --git a/common/nori/nori_test/test2.example/animation_1.png b/common/nori/render_test/test2.example/animation_1.png similarity index 100% rename from common/nori/nori_test/test2.example/animation_1.png rename to common/nori/render_test/test2.example/animation_1.png diff --git a/common/nori/nori_test/test2.nri b/common/nori/render_test/test2.nri similarity index 100% rename from common/nori/nori_test/test2.nri rename to common/nori/render_test/test2.nri diff --git a/common/nori/util.go b/common/nori/util.go new file mode 100644 index 0000000..1b7f777 --- /dev/null +++ b/common/nori/util.go @@ -0,0 +1,48 @@ +package nori + +import ( + "bufio" + "io" +) + +func discardN(r io.Reader, count int) error { + if rd, ok := r.(*bufio.Reader); ok { + if _, err := rd.Discard(count); err != nil { + return err + } + } else if rd, ok := r.(readByteSeeker); ok { + _, err := rd.Seek(int64(count), io.SeekCurrent) + if err != nil { + return err + } + } else if _, err := io.CopyN(io.Discard, r, int64(count)); err != nil { + return err + } + return nil +} + +func readByte(r io.Reader) (byte, error) { + if rd, ok := r.(readByteSeeker); ok { + return rd.ReadByte() + } else { + b := [1]byte{} + _, err := io.ReadFull(r, b[:]) + if err != nil { + return 0, err + } + return b[0], nil + } +} + +type readByteSeeker interface { + io.Reader + io.Seeker + io.ByteReader +} + +func reflectReader(r io.Reader) io.Reader { + if _, ok := r.(readByteSeeker); ok { + return r + } + return bufio.NewReader(r) +}