update example
|
@ -38,14 +38,18 @@ func (n *Nori) ExportAnimation(num int) (*apng.APNG, error) {
|
||||||
for _, frame := range n.Animations[num].Frames {
|
for _, frame := range n.Animations[num].Frames {
|
||||||
planes := frame.Planes
|
planes := frame.Planes
|
||||||
var canvasRect image.Rectangle
|
var canvasRect image.Rectangle
|
||||||
for _, plane := range planes {
|
for i, plane := range planes {
|
||||||
if int(plane.BitmapId) >= len(n.Gawi.Images) {
|
if int(plane.BitmapId) >= len(n.Gawi.Images) {
|
||||||
log.Printf("could not find bitmap %d, only have %d", plane.BitmapId, len(n.Gawi.Images))
|
log.Printf("could not find bitmap %d, only have %d", plane.BitmapId, len(n.Gawi.Images))
|
||||||
}
|
}
|
||||||
bitmap := n.Gawi.Images[plane.BitmapId]
|
bitmap := n.Gawi.Images[plane.BitmapId]
|
||||||
pt := image.Pt(int(plane.PlaneX), int(plane.PlaneY)) // where to put the point
|
pt := image.Pt(int(plane.PlaneX), int(plane.PlaneY)) // where to put the point
|
||||||
rc := bitmap.Img.Bounds()
|
rc := bitmap.Img.Bounds().Add(pt) // translate rectangle to put in the global canvas
|
||||||
canvasRect = canvasRect.Union(rc.Add(pt))
|
if i == 0 {
|
||||||
|
canvasRect = rc
|
||||||
|
} else {
|
||||||
|
canvasRect = canvasRect.Union(rc)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
img := image.NewNRGBA64(canvasRect)
|
img := image.NewNRGBA64(canvasRect)
|
||||||
for _, plane := range planes {
|
for _, plane := range planes {
|
||||||
|
@ -63,9 +67,8 @@ func (n *Nori) ExportAnimation(num int) (*apng.APNG, error) {
|
||||||
}
|
}
|
||||||
_ = transparent
|
_ = transparent
|
||||||
pt := image.Pt(int(plane.PlaneX), int(plane.PlaneY)) // where to put the point
|
pt := image.Pt(int(plane.PlaneX), int(plane.PlaneY)) // where to put the point
|
||||||
|
rc := bitmap.Img.Bounds().Add(pt)
|
||||||
src := bitmap.Img
|
src := bitmap.Img
|
||||||
sr := src.Bounds()
|
|
||||||
r := image.Rectangle{pt, pt.Add(sr.Size())}
|
|
||||||
switch plane.Blend {
|
switch plane.Blend {
|
||||||
case BlendMode_Alpha:
|
case BlendMode_Alpha:
|
||||||
case BlendMode_Mul, BlendMode_Mul7:
|
case BlendMode_Mul, BlendMode_Mul7:
|
||||||
|
@ -78,10 +81,11 @@ func (n *Nori) ExportAnimation(num int) (*apng.APNG, error) {
|
||||||
default:
|
default:
|
||||||
return nil, fmt.Errorf("unknown blend mode: %d", plane.Blend)
|
return nil, fmt.Errorf("unknown blend mode: %d", plane.Blend)
|
||||||
}
|
}
|
||||||
draw.Draw(img,
|
draw.Draw(
|
||||||
r,
|
img,
|
||||||
|
rc,
|
||||||
src,
|
src,
|
||||||
sr.Min,
|
src.Bounds().Min,
|
||||||
draw.Src,
|
draw.Src,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -95,12 +99,14 @@ func (n *Nori) ExportAnimation(num int) (*apng.APNG, error) {
|
||||||
return nil, fmt.Errorf("no frames found for animation")
|
return nil, fmt.Errorf("no frames found for animation")
|
||||||
}
|
}
|
||||||
for i, realFrame := range images {
|
for i, realFrame := range images {
|
||||||
|
log.Info().Int("frame", num).Interface("rect", or).Interface("frame", realFrame.Bounds()).Msg("")
|
||||||
|
src := realFrame
|
||||||
big := image.NewNRGBA64(or)
|
big := image.NewNRGBA64(or)
|
||||||
draw.Draw(
|
draw.Draw(
|
||||||
big,
|
big,
|
||||||
big.Rect,
|
src.Bounds(),
|
||||||
realFrame,
|
src,
|
||||||
realFrame.Bounds().Min,
|
src.Bounds().Min,
|
||||||
draw.Src,
|
draw.Src,
|
||||||
)
|
)
|
||||||
fr := apng.Frame{
|
fr := apng.Frame{
|
||||||
|
@ -112,6 +118,5 @@ func (n *Nori) ExportAnimation(num int) (*apng.APNG, error) {
|
||||||
}
|
}
|
||||||
a.Frames = append(a.Frames, fr)
|
a.Frames = append(a.Frames, fr)
|
||||||
}
|
}
|
||||||
log.Println(num, len(a.Frames))
|
|
||||||
return a, nil
|
return a, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,7 +75,7 @@ func writeApng(nori *Nori, name string) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
err = os.WriteFile(fmt.Sprintf("./nori_test/%s%s/animation_%d.apng", name, postfix, i), out.Bytes(), 0740)
|
err = os.WriteFile(fmt.Sprintf("./nori_test/%s%s/animation_%d.png", name, postfix, i), out.Bytes(), 0740)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
Before Width: | Height: | Size: 3.1 KiB After Width: | Height: | Size: 3.1 KiB |
Before Width: | Height: | Size: 3.2 KiB After Width: | Height: | Size: 3.2 KiB |
Before Width: | Height: | Size: 22 KiB |
After Width: | Height: | Size: 22 KiB |
Before Width: | Height: | Size: 79 KiB |
After Width: | Height: | Size: 79 KiB |
Before Width: | Height: | Size: 79 KiB |
After Width: | Height: | Size: 79 KiB |
Before Width: | Height: | Size: 21 KiB After Width: | Height: | Size: 21 KiB |
Before Width: | Height: | Size: 21 KiB After Width: | Height: | Size: 21 KiB |
Before Width: | Height: | Size: 19 KiB |
After Width: | Height: | Size: 19 KiB |
Before Width: | Height: | Size: 18 KiB |
After Width: | Height: | Size: 18 KiB |
Before Width: | Height: | Size: 21 KiB |
After Width: | Height: | Size: 21 KiB |
Before Width: | Height: | Size: 24 KiB |
After Width: | Height: | Size: 24 KiB |
Before Width: | Height: | Size: 24 KiB |
After Width: | Height: | Size: 24 KiB |
Before Width: | Height: | Size: 24 KiB |
After Width: | Height: | Size: 24 KiB |
Before Width: | Height: | Size: 25 KiB |
After Width: | Height: | Size: 25 KiB |
Before Width: | Height: | Size: 21 KiB |
After Width: | Height: | Size: 21 KiB |
Before Width: | Height: | Size: 18 KiB |
After Width: | Height: | Size: 18 KiB |
Before Width: | Height: | Size: 24 KiB |
After Width: | Height: | Size: 24 KiB |
Before Width: | Height: | Size: 30 KiB |
After Width: | Height: | Size: 30 KiB |
Before Width: | Height: | Size: 30 KiB |
After Width: | Height: | Size: 30 KiB |
Before Width: | Height: | Size: 24 KiB |
After Width: | Height: | Size: 24 KiB |
Before Width: | Height: | Size: 23 KiB |
After Width: | Height: | Size: 23 KiB |
Before Width: | Height: | Size: 25 KiB |
After Width: | Height: | Size: 25 KiB |
Before Width: | Height: | Size: 30 KiB |
After Width: | Height: | Size: 30 KiB |
Before Width: | Height: | Size: 31 KiB |
After Width: | Height: | Size: 31 KiB |
Before Width: | Height: | Size: 24 KiB |
After Width: | Height: | Size: 24 KiB |
Before Width: | Height: | Size: 29 KiB |
After Width: | Height: | Size: 29 KiB |
Before Width: | Height: | Size: 31 KiB |
After Width: | Height: | Size: 31 KiB |
Before Width: | Height: | Size: 30 KiB |
After Width: | Height: | Size: 30 KiB |
Before Width: | Height: | Size: 24 KiB |
After Width: | Height: | Size: 24 KiB |
Before Width: | Height: | Size: 3.1 KiB After Width: | Height: | Size: 3.1 KiB |
Before Width: | Height: | Size: 3.2 KiB After Width: | Height: | Size: 3.2 KiB |
Before Width: | Height: | Size: 3.7 KiB After Width: | Height: | Size: 3.7 KiB |
Before Width: | Height: | Size: 4.5 KiB After Width: | Height: | Size: 4.5 KiB |
Before Width: | Height: | Size: 4.0 KiB After Width: | Height: | Size: 4.0 KiB |
Before Width: | Height: | Size: 4.4 KiB After Width: | Height: | Size: 4.4 KiB |
Before Width: | Height: | Size: 26 KiB |
After Width: | Height: | Size: 26 KiB |
Before Width: | Height: | Size: 3.7 KiB After Width: | Height: | Size: 3.7 KiB |
Before Width: | Height: | Size: 3.2 KiB After Width: | Height: | Size: 3.2 KiB |
Before Width: | Height: | Size: 4.0 KiB After Width: | Height: | Size: 4.0 KiB |
Before Width: | Height: | Size: 23 KiB |
After Width: | Height: | Size: 23 KiB |
Before Width: | Height: | Size: 31 KiB |
After Width: | Height: | Size: 31 KiB |
Before Width: | Height: | Size: 31 KiB |
After Width: | Height: | Size: 31 KiB |
Before Width: | Height: | Size: 23 KiB |
After Width: | Height: | Size: 23 KiB |
Before Width: | Height: | Size: 2.9 KiB After Width: | Height: | Size: 2.9 KiB |
Before Width: | Height: | Size: 4.0 KiB After Width: | Height: | Size: 4.0 KiB |
Before Width: | Height: | Size: 4.0 KiB After Width: | Height: | Size: 4.0 KiB |
Before Width: | Height: | Size: 22 KiB |
After Width: | Height: | Size: 22 KiB |
Before Width: | Height: | Size: 2.9 KiB After Width: | Height: | Size: 2.9 KiB |
Before Width: | Height: | Size: 18 KiB |
After Width: | Height: | Size: 18 KiB |
Before Width: | Height: | Size: 3.2 KiB After Width: | Height: | Size: 3.2 KiB |
Before Width: | Height: | Size: 3.2 KiB After Width: | Height: | Size: 3.2 KiB |
Before Width: | Height: | Size: 2.4 KiB After Width: | Height: | Size: 2.4 KiB |
After Width: | Height: | Size: 8.4 KiB |
Before Width: | Height: | Size: 4.4 KiB After Width: | Height: | Size: 4.4 KiB |
Before Width: | Height: | Size: 4.4 KiB After Width: | Height: | Size: 4.4 KiB |
Before Width: | Height: | Size: 2.4 KiB After Width: | Height: | Size: 2.4 KiB |
Before Width: | Height: | Size: 609 B After Width: | Height: | Size: 609 B |
Before Width: | Height: | Size: 609 B After Width: | Height: | Size: 609 B |
Before Width: | Height: | Size: 12 KiB |
After Width: | Height: | Size: 12 KiB |
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 12 KiB |
Before Width: | Height: | Size: 8.4 KiB |
Before Width: | Height: | Size: 8.4 KiB After Width: | Height: | Size: 8.4 KiB |
Before Width: | Height: | Size: 3.7 KiB After Width: | Height: | Size: 3.7 KiB |
Before Width: | Height: | Size: 25 KiB After Width: | Height: | Size: 25 KiB |
Before Width: | Height: | Size: 25 KiB After Width: | Height: | Size: 25 KiB |