Skip to content

Commit

Permalink
refactor(scale-filter): introduce constants for magic scale filter di…
Browse files Browse the repository at this point in the history
…mensions

Refs: ARC-9901
  • Loading branch information
bajankristof committed Nov 29, 2024
1 parent d5bcb12 commit 75ee73f
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions lib/ffmpeg/filters/scale.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ def scale(width: nil, height: nil, force_original_aspect_ratio: nil, flags: nil)
# The Scale class uses the scale filter
# to resize a multimedia stream.
class Scale < Filter
NEAREST_DIMENSION = -1
NEAREST_EVEN_DIMENSION = -2

class << self
# Returns a scale filter that fits the specified media
# within the specified maximum width and height,
Expand Down Expand Up @@ -44,11 +47,11 @@ def contained(media, max_width: nil, max_height: nil)
return unless max_width || max_height

if media.rotated?
width = max_height || -2
height = max_width || -2
width = max_height || NEAREST_EVEN_DIMENSION
height = max_width || NEAREST_EVEN_DIMENSION
else
width = max_width || -2
height = max_height || -2
width = max_width || NEAREST_EVEN_DIMENSION
height = max_height || NEAREST_EVEN_DIMENSION
end

if width.negative? || height.negative?
Expand Down

0 comments on commit 75ee73f

Please sign in to comment.