New gradient global settings
This commit is contained in:
parent
4fc74b0f33
commit
35eac165e5
|
@ -46,6 +46,8 @@ type Settings struct {
|
|||
// GradientBlur Amount of blur to apply to gradients
|
||||
GradientBlur float64
|
||||
|
||||
GradientApplyOverlapOnTransparency bool
|
||||
|
||||
// BitmapPaletteSize Number of colors bitmap shapes will be paletted into.
|
||||
// Transparency is not included and will be handled separately. Set to 0 to disable.
|
||||
BitmapPaletteSize int
|
||||
|
@ -55,6 +57,9 @@ type Settings struct {
|
|||
}
|
||||
|
||||
const GradientAutoSlices = -1
|
||||
|
||||
// DefaultASSDrawingScale libass uses a fixed precision decimal of size 26.6
|
||||
// Using scale 6 allows getting accurate precision without using decimals, as it will be later divided by the drawing scale.
|
||||
const DefaultASSDrawingScale = 6
|
||||
const DefaultASSDrawingPrecision = 2
|
||||
|
||||
|
@ -71,9 +76,11 @@ var GlobalSettings = Settings{
|
|||
|
||||
KeyFrameInterval: 0,
|
||||
|
||||
GradientSlices: GradientAutoSlices,
|
||||
GradientOverlap: 2,
|
||||
GradientBlur: 0.1,
|
||||
GradientSlices: GradientAutoSlices,
|
||||
//TODO: this has issues with transparent backgrounds
|
||||
GradientOverlap: 2,
|
||||
GradientBlur: 0.1,
|
||||
GradientApplyOverlapOnTransparency: false,
|
||||
|
||||
BitmapPaletteSize: 32,
|
||||
BitmapMaxDimension: 256,
|
||||
|
|
|
@ -80,11 +80,11 @@ var GradientBounds = Rectangle[float64]{
|
|||
|
||||
const GradientRatioDivisor = math.MaxUint8
|
||||
|
||||
func InterpolateGradient(gradient Gradient, gradientSlices int) (result []GradientSlice) {
|
||||
items := gradient.GetItems()
|
||||
func (g Gradient) Interpolate(gradientSlices int) (result []GradientSlice) {
|
||||
items := g.GetItems()
|
||||
//TODO: spread modes
|
||||
|
||||
interpolationMode := gradient.InterpolationMode
|
||||
interpolationMode := g.InterpolationMode
|
||||
|
||||
first := items[0]
|
||||
last := items[len(items)-1]
|
||||
|
@ -115,8 +115,8 @@ func InterpolateGradient(gradient Gradient, gradientSlices int) (result []Gradie
|
|||
|
||||
maxColorDistance := max(math.Abs(float64(prevColor.R)-float64(currentColor.R)), math.Abs(float64(prevColor.G)-float64(currentColor.G)), math.Abs(float64(prevColor.B)-float64(currentColor.B)), math.Abs(float64(prevColor.Alpha)-float64(currentColor.Alpha)))
|
||||
|
||||
prevPosition := float64(prevItem.Ratio)
|
||||
currentPosition := float64(item.Ratio)
|
||||
prevPosition := float64(prevItem.Ratio) / GradientRatioDivisor
|
||||
currentPosition := float64(item.Ratio) / GradientRatioDivisor
|
||||
distance := math.Abs(currentPosition - prevPosition)
|
||||
|
||||
var partitions int
|
||||
|
@ -126,7 +126,7 @@ func InterpolateGradient(gradient Gradient, gradientSlices int) (result []Gradie
|
|||
//TODO: better heuristic for change including distance in ratio
|
||||
partitions = max(1, int(math.Ceil(min(GradientRatioDivisor/float64(len(items)+1), max(1, math.Ceil(maxColorDistance))))))
|
||||
} else {
|
||||
partitions = max(1, int(math.Ceil((distance/GradientRatioDivisor)*float64(gradientSlices))))
|
||||
partitions = max(1, int(math.Ceil(distance*float64(gradientSlices))))
|
||||
}
|
||||
|
||||
fromPos := prevPosition
|
||||
|
@ -141,8 +141,8 @@ func InterpolateGradient(gradient Gradient, gradientSlices int) (result []Gradie
|
|||
toPos := math2.Lerp(prevPosition, currentPosition, ratio)
|
||||
|
||||
result = append(result, GradientSlice{
|
||||
Start: fromPos / GradientRatioDivisor,
|
||||
End: toPos / GradientRatioDivisor,
|
||||
Start: fromPos,
|
||||
End: toPos,
|
||||
Color: color,
|
||||
})
|
||||
fromPos = toPos
|
||||
|
|
|
@ -3,6 +3,7 @@ package shapes
|
|||
import (
|
||||
swfsubtypes "git.gammaspectra.live/WeebDataHoarder/swf-go/subtypes"
|
||||
"git.gammaspectra.live/WeebDataHoarder/swf-go/types"
|
||||
"git.gammaspectra.live/WeebDataHoarder/swf2ass-go/settings"
|
||||
"git.gammaspectra.live/WeebDataHoarder/swf2ass-go/types/math"
|
||||
)
|
||||
|
||||
|
@ -27,13 +28,16 @@ func interpolateLinearGradient(self Gradient, overlap, blur float64, gradientSli
|
|||
|
||||
vOverlap := math.NewVector2(overlap, 0).Divide(2)
|
||||
|
||||
items := InterpolateGradient(self, gradientSlices)
|
||||
for _, i := range items {
|
||||
if i.Color.Alpha != 255 {
|
||||
//transparency! remove overlaps
|
||||
blur = 0
|
||||
overlap = 0
|
||||
break
|
||||
items := self.Interpolate(gradientSlices)
|
||||
|
||||
if !settings.GlobalSettings.GradientApplyOverlapOnTransparency {
|
||||
for _, i := range items {
|
||||
if i.Color.Alpha != 255 {
|
||||
//transparency! remove overlaps
|
||||
blur = 0
|
||||
overlap = 0
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ package shapes
|
|||
import (
|
||||
swfsubtypes "git.gammaspectra.live/WeebDataHoarder/swf-go/subtypes"
|
||||
"git.gammaspectra.live/WeebDataHoarder/swf-go/types"
|
||||
"git.gammaspectra.live/WeebDataHoarder/swf2ass-go/settings"
|
||||
"git.gammaspectra.live/WeebDataHoarder/swf2ass-go/types/math"
|
||||
math2 "math"
|
||||
)
|
||||
|
@ -13,13 +14,16 @@ func interpolateRadialGradient(self Gradient, overlap, blur float64, gradientSli
|
|||
|
||||
//TODO spreadMode
|
||||
|
||||
items := InterpolateGradient(self, gradientSlices)
|
||||
for _, i := range items {
|
||||
if i.Color.Alpha != 255 {
|
||||
//transparency! remove overlaps
|
||||
blur = 0
|
||||
overlap = 0
|
||||
break
|
||||
items := self.Interpolate(gradientSlices)
|
||||
|
||||
if !settings.GlobalSettings.GradientApplyOverlapOnTransparency {
|
||||
for _, i := range items {
|
||||
if i.Color.Alpha != 255 {
|
||||
//transparency! remove overlaps
|
||||
blur = 0
|
||||
overlap = 0
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue