Skip to content
This repository was archived by the owner on Feb 22, 2024. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 12 additions & 29 deletions go/internal/image_processor/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -730,40 +730,23 @@ func (Worker) resizeFrames(ctx global.Context, inputDir string, tmpDir string, t
}

if tsk.ResizeRatio == task.ResizeRatioNothing {
// Get the largest scale factor
scale := 1
for _, s := range tsk.Scales {
if s > scale {
scale = s
}
}

// Divide the width and height by the scale factor
// This is integer division, so it will round down
width /= scale
height /= scale
smwf := float64(tsk.SmallestMaxWidth)
wf := float64(width)
smhf := float64(tsk.SmallestMaxHeight)
hf := float64(height)

// If the height is bigger than the max height, then scale it down
if height > tsk.SmallestMaxHeight {
width = int(float64(width) * (float64(tsk.SmallestMaxHeight) / float64(height)))
height = tsk.SmallestMaxHeight
if smwf < wf {
hf *= smwf / wf
wf = smwf
}

// If the width is bigger than the max width, then scale it down
if width > tsk.SmallestMaxWidth {
height = int(float64(height) * (float64(tsk.SmallestMaxWidth) / float64(width)))
width = tsk.SmallestMaxWidth
if smhf < hf {
wf *= smhf / hf
hf = smhf
}

// If the width is 0, then set it to 1
if width == 0 {
width = 1
}

// If the height is 0, then set it to 1
if height == 0 {
height = 1
}
width = int(math.Round(wf))
height = int(math.Round(hf))

tsk.ResizeRatio = task.ResizeRatioStretch
} else {
Expand Down