mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
Fix captured photo quality
This commit is contained in:
parent
c9c694d585
commit
d3ee489694
@ -69,6 +69,7 @@ final class CameraDevice {
|
||||
var maxHeight: Int32 = 0
|
||||
var hasSecondaryZoomLevels = false
|
||||
var candidates: [AVCaptureDevice.Format] = []
|
||||
var photoCandidates: [AVCaptureDevice.Format] = []
|
||||
outer: for format in device.formats {
|
||||
if format.mediaType != .video || format.value(forKey: "isPhotoFormat") as? Bool == true {
|
||||
continue
|
||||
@ -94,8 +95,14 @@ final class CameraDevice {
|
||||
if #available(iOS 16.0, *), !format.secondaryNativeResolutionZoomFactors.isEmpty {
|
||||
hasSecondaryZoomLevels = true
|
||||
candidates.append(format)
|
||||
if format.isHighPhotoQualitySupported {
|
||||
photoCandidates.append(format)
|
||||
}
|
||||
} else if !hasSecondaryZoomLevels {
|
||||
candidates.append(format)
|
||||
if #available(iOS 15.0, *), format.isHighPhotoQualitySupported {
|
||||
photoCandidates.append(format)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -103,14 +110,24 @@ final class CameraDevice {
|
||||
|
||||
if !candidates.isEmpty {
|
||||
var bestFormat: AVCaptureDevice.Format?
|
||||
outer: for format in candidates {
|
||||
photoOuter: for format in photoCandidates {
|
||||
for range in format.videoSupportedFrameRateRanges {
|
||||
if range.maxFrameRate > maxFramerate {
|
||||
continue outer
|
||||
continue photoOuter
|
||||
}
|
||||
bestFormat = format
|
||||
}
|
||||
}
|
||||
if bestFormat == nil {
|
||||
outer: for format in candidates {
|
||||
for range in format.videoSupportedFrameRateRanges {
|
||||
if range.maxFrameRate > maxFramerate {
|
||||
continue outer
|
||||
}
|
||||
bestFormat = format
|
||||
}
|
||||
}
|
||||
}
|
||||
if bestFormat == nil {
|
||||
bestFormat = candidates.last
|
||||
}
|
||||
|
@ -96,6 +96,10 @@ final class CameraOutput: NSObject {
|
||||
|
||||
super.init()
|
||||
|
||||
if #available(iOS 13.0, *) {
|
||||
self.photoOutput.maxPhotoQualityPrioritization = .balanced
|
||||
}
|
||||
|
||||
self.videoOutput.alwaysDiscardsLateVideoFrames = false
|
||||
self.videoOutput.videoSettings = [kCVPixelBufferPixelFormatTypeKey: kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange] as [String : Any]
|
||||
}
|
||||
@ -246,12 +250,8 @@ final class CameraOutput: NSObject {
|
||||
settings.previewPhotoFormat = [kCVPixelBufferPixelFormatTypeKey as String: previewPhotoPixelFormatType]
|
||||
}
|
||||
if #available(iOS 13.0, *) {
|
||||
if self.exclusive {
|
||||
if self.photoOutput.maxPhotoQualityPrioritization != .speed {
|
||||
settings.photoQualityPrioritization = .balanced
|
||||
} else {
|
||||
settings.photoQualityPrioritization = .speed
|
||||
}
|
||||
if self.photoOutput.maxPhotoQualityPrioritization != .speed {
|
||||
settings.photoQualityPrioritization = .balanced
|
||||
} else {
|
||||
settings.photoQualityPrioritization = .speed
|
||||
}
|
||||
|
@ -27,6 +27,7 @@ private func prerenderTextTransformations(entity: DrawingTextEntity, image: UIIm
|
||||
let newImage = generateImage(newSize, contextGenerator: { size, context in
|
||||
context.setAllowsAntialiasing(true)
|
||||
context.setShouldAntialias(true)
|
||||
context.interpolationQuality = .high
|
||||
context.clear(CGRect(origin: .zero, size: size))
|
||||
context.translateBy(x: newSize.width * 0.5, y: newSize.height * 0.5)
|
||||
context.rotate(by: angle)
|
||||
|
@ -249,7 +249,7 @@ public final class AccountContextImpl: AccountContext {
|
||||
self.account = account
|
||||
self.engine = TelegramEngine(account: account)
|
||||
|
||||
self.userLimits = EngineConfiguration.UserLimits(UserLimitsConfiguration.defaultValue, isPremium: false)
|
||||
self.userLimits = EngineConfiguration.UserLimits(UserLimitsConfiguration.defaultValue)
|
||||
|
||||
self.downloadedMediaStoreManager = DownloadedMediaStoreManagerImpl(postbox: account.postbox, accountManager: sharedContext.accountManager)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user