Drop ASS tags that don't ever have a visible color

This commit is contained in:
DataHoarder 2023-12-03 04:08:00 +01:00
parent 145ae65e5e
commit a6e9a3917f
Signed by: DataHoarder
SSH key fingerprint: SHA256:OLTRf6Fl87G52SiR7sWLGNzlJt4WOX+tfI2yxo0z7xk
6 changed files with 52 additions and 2 deletions

View file

@ -22,4 +22,9 @@ $ ffmpeg -y \
-c:a copy \
-c:s copy -disposition:s:0 forced -metadata:s:s:0 language=und \
-shortest "${FILENAME}.mkv"
```
### Compress subtitles
```bash
zstd -19 -T24 file.ass -o file.ass.zst
```

View file

@ -3,6 +3,7 @@ package ass
import (
"fmt"
"git.gammaspectra.live/WeebDataHoarder/swf2ass-go/ass/line"
"git.gammaspectra.live/WeebDataHoarder/swf2ass-go/ass/tag"
"git.gammaspectra.live/WeebDataHoarder/swf2ass-go/settings"
"git.gammaspectra.live/WeebDataHoarder/swf2ass-go/types"
"git.gammaspectra.live/WeebDataHoarder/swf2ass-go/types/math"
@ -167,6 +168,19 @@ func threadedRenderer(stats map[uint16]rendererStatsEntry, buf []*line.EventLine
break
}
l := buf[i]
var hasColor bool
for _, t := range l.Tags {
if ct, ok := t.(tag.ColorTag); ok && ct.HasColor() {
hasColor = true
break
}
}
if !hasColor {
//skip lines without any color at all
continue
}
stats[l.ObjectId].Lines.Add(1)
l.Name += fmt.Sprintf(" f:%d>%d~%d", l.Start, l.End, l.End-l.Start+1)

View file

@ -18,6 +18,26 @@ type ContainerTag struct {
BakeTransforms *math.MatrixTransform
}
func (t *ContainerTag) HasColor() bool {
for _, tag := range t.Tags {
if colorTag, ok := tag.(ColorTag); ok {
if colorTag.HasColor() {
return true
}
}
}
for _, tags := range t.Transitions {
for _, tag := range tags {
if colorTag, ok := tag.(ColorTag); ok {
if colorTag.HasColor() {
return true
}
}
}
}
return false
}
func (t *ContainerTag) TransitionColor(event Event, transform math.ColorTransform) ColorTag {
container := t.Clone(false)

View file

@ -5,6 +5,7 @@ import (
"git.gammaspectra.live/WeebDataHoarder/swf2ass-go/ass/time"
"git.gammaspectra.live/WeebDataHoarder/swf2ass-go/types/math"
"git.gammaspectra.live/WeebDataHoarder/swf2ass-go/types/shapes"
math2 "math"
)
type FillColorTag struct {
@ -33,6 +34,10 @@ func (t *FillColorTag) TransitionStyleRecord(event Event, record shapes.StyleRec
return t2
}
func (t *FillColorTag) HasColor() bool {
return t.Color != nil && t.Color.Alpha > 0
}
func (t *FillColorTag) ApplyColorTransform(transform math.ColorTransform) ColorTag {
color := t.Color
if t.OriginalColor != nil {
@ -60,6 +65,6 @@ func (t *FillColorTag) Encode(event time.EventTime) string {
if t.Color == nil {
return "\\1a&HFF&"
} else {
return fmt.Sprintf("\\1c&H%02X%02X%02X&\\1a&H%02X&", t.Color.B, t.Color.G, t.Color.R, 255-t.Color.Alpha)
return fmt.Sprintf("\\1c&H%02X%02X%02X&\\1a&H%02X&", t.Color.B, t.Color.G, t.Color.R, math2.MaxUint8-t.Color.Alpha)
}
}

View file

@ -5,6 +5,7 @@ import (
"git.gammaspectra.live/WeebDataHoarder/swf2ass-go/ass/time"
"git.gammaspectra.live/WeebDataHoarder/swf2ass-go/types/math"
"git.gammaspectra.live/WeebDataHoarder/swf2ass-go/types/shapes"
math2 "math"
)
type LineColorTag struct {
@ -32,6 +33,10 @@ func (t *LineColorTag) TransitionStyleRecord(event Event, record shapes.StyleRec
return t2
}
func (t *LineColorTag) HasColor() bool {
return t.Color != nil && t.Color.Alpha > 0
}
func (t *LineColorTag) ApplyColorTransform(transform math.ColorTransform) ColorTag {
color := t.Color
if t.OriginalColor != nil {
@ -59,6 +64,6 @@ func (t *LineColorTag) Encode(event time.EventTime) string {
if t.Color == nil {
return "\\3a&HFF&"
} else {
return fmt.Sprintf("\\3c&H%02X%02X%02X&\\3a&H%02X&", t.Color.B, t.Color.G, t.Color.R, 255-t.Color.Alpha)
return fmt.Sprintf("\\3c&H%02X%02X%02X&\\3a&H%02X&", t.Color.B, t.Color.G, t.Color.R, math2.MaxUint8-t.Color.Alpha)
}
}

View file

@ -42,4 +42,5 @@ type ColorTag interface {
StyleTag
ApplyColorTransform(transform math.ColorTransform) ColorTag
TransitionColor(event Event, transform math.ColorTransform) ColorTag
HasColor() bool
}