Skip to content

Conversation

@Kiyoung-Kim-57
Copy link
Member

🤔 배경

  • 촬영 전 화면은 좌우반전이 적용됐는데 촬영된 이미지는 좌우반전이 적용이 안되어 있는 점 해결
  • 영상 프레임 단위의 UIImage 렌더링이 일어나는 것이 성능 상 문제될 것으로 예상됨

📃 작업 내역

  • 좌우 반전 적용
  • 영상 프레임 캡쳐 성능 향상

✅ 리뷰 노트

  1. 영상 화면이 renderFrame을 매 프레임 호출할때마다 UIImage로 매 프레임을 렌더링해서 보관하는 부분이 성능 상 문제될 것이라고 생각하여 매 프레임 저장은 CGImage로 하고 UIImage로 렌더링은 외부에서 호출할 때 시점에 일어나도록 했습니다.
private var capturedCGImage: CGImage?

public var capturedImage: UIImage? {
    guard let capturedCGImage,
          let flipedImage = flipCgImageHorizontally(cgImage: capturedCGImage)
    else { return nil }

    return UIImage(cgImage: flipedImage)
}

🎨 스크린샷

iPhone SE(2세대) iPhone 14 iPhone 16 Pro Max
스샷 스샷 스샷

🚀 테스트 방법

- renderFrame이 호출될때마다 pixelBuffer 데이터를 UIImage로 렌더링 해줬는데 이를 CGImage로 보관하고 capturedImage를 계산 속성으로 변경하여 호출될 때만 UIImage로 렌더링 될 수 있도록 했습니다.
- 저장된 이미지는 좌우반전이 유지된 상태로 반환됩니다.

Co-Authored-By: Youngkyu Song <ace_lephant@naver.com>
@Kiyoung-Kim-57 Kiyoung-Kim-57 added 🔧 fix 버그 수정 ⚙️ refactor 코드 정상화 labels Dec 1, 2024
@Kiyoung-Kim-57 Kiyoung-Kim-57 self-assigned this Dec 1, 2024
@Kiyoung-Kim-57 Kiyoung-Kim-57 linked an issue Dec 1, 2024 that may be closed by this pull request
1 task
Copy link
Member

@youn9k youn9k left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

성능을 고려하는게 좋네요! 고생하셨습니다ㅎㅎ

Copy link
Collaborator

@hsw1920 hsw1920 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍👍👍 불필요한 고수준 객체인 UIImage를 생성하지 않고 저수준 객체인 CGImage로 관리하는군요!
찾아보니 CGImageUIImage와 다르게 메타데이터나 스케일 정보 등을 저장하지 않는다고 하네요

Copy link
Collaborator

@0Hooni 0Hooni left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

성능을 고려한 수정이 너무 좋네요 👍

수고 많으셨습니다!

@youn9k youn9k merged commit 7a411d5 into develop Dec 2, 2024
1 check passed
@youn9k youn9k deleted the fix/#146-flip-captured-image branch December 2, 2024 00:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🔧 fix 버그 수정 ⚙️ refactor 코드 정상화

Projects

None yet

Development

Successfully merging this pull request may close these issues.

촬영된 화면이 다시 좌우반전 되는 것 고치기

5 participants