Skip to content

Commit

Permalink
Merge pull request #100 from GiacomoLeopizzi/view_aspect_ratio
Browse files Browse the repository at this point in the history
Support for custom aspect ratio
  • Loading branch information
AFathi authored Feb 9, 2020
2 parents 7cc44e3 + e9a88d4 commit cabc553
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions ARVideoKit/Enumerations/ARVideoOptions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
case aspectFit
/// Recommended for iPhone X
case aspectFill
case viewAspectRatio
}

/// Allows specifying the video rendering frame per second `FPS` rate.
Expand Down
7 changes: 7 additions & 0 deletions ARVideoKit/Rendering/RenderAR.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ struct RenderAR {
case .aspectFill:
width = Int(UIScreen.main.nativeBounds.width)
height = Int(UIScreen.main.nativeBounds.height)
case .viewAspectRatio where view is UIView:
let bufferWidth = CVPixelBufferGetWidth(raw)
let bufferHeight = CVPixelBufferGetHeight(raw)
let viewSize = (view as! UIView).bounds.size
let targetSize = AVMakeRect(aspectRatio: viewSize, insideRect: CGRect(x: 0, y: 0, width: bufferWidth, height: bufferHeight)).size
width = Int(targetSize.width)
height = Int(targetSize.height)
default:
if UIScreen.main.isiPhone10 {
width = Int(UIScreen.main.nativeBounds.width)
Expand Down

0 comments on commit cabc553

Please sign in to comment.