Drop ASS tags that don't ever have a visible color
This commit is contained in:
parent
145ae65e5e
commit
a6e9a3917f
|
@ -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
|
||||
```
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,4 +42,5 @@ type ColorTag interface {
|
|||
StyleTag
|
||||
ApplyColorTransform(transform math.ColorTransform) ColorTag
|
||||
TransitionColor(event Event, transform math.ColorTransform) ColorTag
|
||||
HasColor() bool
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue