Skip to content

Commit 9642e7b

Browse files
committed
Added hflip flag
1 parent 77e61b8 commit 9642e7b

3 files changed

Lines changed: 28 additions & 26 deletions

File tree

pkg/discord/bot.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1785,7 +1785,7 @@ func (b *Bot) getDialogWithContext(mediaID *media.ID) (*DialogWithContext, error
17851785

17861786
func (b *Bot) getBoomerModeInitialLayout() string {
17871787
out := []string{
1788-
"# Remove hash to enable gif. You may also duplicate lines. Cell references start at 0 e.g. 0x3 foo.gif 0.5",
1788+
"# Remove hash to enable gif.\n# You may also duplicate lines.\n#Cell references are decimals and start at 0.\n# Append an 'f' to to flip the gif. e.g. 0x3.5 foo.gif 0.5 f",
17891789
}
17901790
for _, overlayName := range b.overlayCache.All() {
17911791
out = append(out, fmt.Sprintf("# 0x0 %s 1", overlayName))

pkg/render/exec.go

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"github.com/warmans/tvgif/pkg/util"
1212
"io"
1313
"log/slog"
14-
"math/rand/v2"
1514
"os"
1615
"os/exec"
1716
"path"
@@ -89,7 +88,14 @@ func (r *ExecRenderer) RenderFile(
8988
if len(resolvedOverlays) > 0 {
9089
// resize all inputs
9190
for i, overlayConf := range resolvedOverlays {
92-
filterPrefix += fmt.Sprintf("[%d]scale=w=iw*%0.2f:h=ih*%0.2f[i%d];", i+1, overlayConf.scale, overlayConf.scale, i+1)
91+
filterPrefix += fmt.Sprintf(
92+
"[%d]scale=w=iw*%0.2f:h=ih*%0.2f%s[i%d];",
93+
i+1,
94+
overlayConf.scale,
95+
overlayConf.scale,
96+
util.IfElse(overlayConf.hflip, ",hflip", ""),
97+
i+1,
98+
)
9399
}
94100

95101
for i, overlayConf := range resolvedOverlays {
@@ -99,7 +105,7 @@ func (r *ExecRenderer) RenderFile(
99105
// 2. add half the width/height of a grid squareso the image is placed in the middle
100106
// 3. offset the overlay position by half its size so the middle of the overlay aligns with the middle of the grid square.
101107
filterPrefix += fmt.Sprintf(
102-
"[%s][i%d]overlay=x=((((W/%d)*%d)+((W/%d)/2))-w/2):y=((((H/%d)*%d)+((H/%d)/2))-h/2):shortest=1:[o%d];",
108+
"[%s][i%d]overlay=x=((((W/%d)*%0.2f)+((W/%d)/2))-w/2):y=((((H/%d)*%0.2f)+((H/%d)/2))-h/2):shortest=1:[o%d];",
103109
util.IfElse(i == 0, "0", fmt.Sprintf("o%d", i-1)),
104110
i+1,
105111
overlayGridSizeX,
@@ -185,27 +191,18 @@ func flattenArgs(args [][]string) []string {
185191
}
186192

187193
type overlayConfig struct {
188-
numRandomOverlays int
189-
layoutConfig string
194+
layoutConfig string
190195
}
191196

192197
func (o overlayConfig) resolveOverlays(overlayCache *mediacache.OverlayCache, logger *slog.Logger) []overlay {
193-
if o.layoutConfig == "" {
194-
out := []overlay{}
195-
for _, name := range overlayCache.Random(o.numRandomOverlays) {
196-
out = append(out, overlay{name: name, x: rand.IntN(5), y: rand.IntN(3), scale: 1})
197-
}
198-
return out
199-
}
200-
201198
out := []overlay{}
202199
for _, line := range strings.Split(o.layoutConfig, "\n") {
203200
line = strings.TrimSpace(line)
204201
if strings.HasPrefix(line, "#") {
205202
continue
206203
}
207204

208-
parts := strings.SplitN(strings.TrimSpace(strings.TrimPrefix(line, "#")), " ", 3)
205+
parts := strings.SplitN(strings.TrimSpace(strings.TrimPrefix(line, "#")), " ", 4)
209206
if len(parts) < 2 {
210207
logger.Error("line did not have enough elements", slog.String("line", line))
211208
return out
@@ -217,13 +214,13 @@ func (o overlayConfig) resolveOverlays(overlayCache *mediacache.OverlayCache, lo
217214
return out
218215
}
219216

220-
x, err := strconv.ParseInt(xy[0], 10, 8)
217+
x, err := strconv.ParseFloat(xy[0], 64)
221218
if err != nil {
222219
logger.Error("failed to parse X", slog.String("line", line), slog.String("x", xy[0]))
223220
return out
224221
}
225222

226-
y, err := strconv.ParseInt(xy[1], 10, 8)
223+
y, err := strconv.ParseFloat(xy[1], 64)
227224
if err != nil {
228225
logger.Error("failed to parse Y", slog.String("line", line), slog.String("y", xy[1]))
229226
return out
@@ -238,8 +235,18 @@ func (o overlayConfig) resolveOverlays(overlayCache *mediacache.OverlayCache, lo
238235
}
239236
}
240237

241-
if overlayCache.Exists(parts[1]) {
242-
out = append(out, overlay{name: parts[1], x: int(x), y: int(y), scale: min(scale, 5)})
238+
ov := overlay{name: parts[1], x: x, y: y, scale: min(scale, 5), hflip: false}
239+
if len(parts) > 3 {
240+
for _, v := range strings.Split(parts[3], "") {
241+
switch v {
242+
case "f":
243+
ov.hflip = true
244+
}
245+
}
246+
}
247+
248+
if overlayCache.Exists(ov.name) {
249+
out = append(out, ov)
243250
} else {
244251
logger.Error("image does not exist", slog.String("line", line))
245252
}
@@ -250,6 +257,7 @@ func (o overlayConfig) resolveOverlays(overlayCache *mediacache.OverlayCache, lo
250257

251258
type overlay struct {
252259
name string
253-
x, y int
260+
x, y float64
254261
scale float64
262+
hflip bool
255263
}

pkg/render/ffmpeg.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,6 @@ func WithCaptionMode(enable bool) Option {
130130
}
131131
}
132132

133-
func WithRandomGifOverlays(num int) Option {
134-
return func(opts *renderOpts) {
135-
opts.overlayConfig.numRandomOverlays = num
136-
}
137-
}
138-
139133
func WithOverlayLayout(layout string) Option {
140134
return func(opts *renderOpts) {
141135
opts.overlayConfig.layoutConfig = layout

0 commit comments

Comments
 (0)