From 0f3cf634a24c1e7e71da056cfaea80b7c4a7eb8c Mon Sep 17 00:00:00 2001 From: Peter <> Date: Fri, 23 Nov 2018 18:14:47 +0300 Subject: [PATCH] Fix image blur --- TelegramUI/PhotoResources.swift | 25 +++++++++++++++++++++++-- TelegramUI/StorageUsageController.swift | 12 +++++++----- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/TelegramUI/PhotoResources.swift b/TelegramUI/PhotoResources.swift index 2b88d6b757..4d857428f6 100644 --- a/TelegramUI/PhotoResources.swift +++ b/TelegramUI/PhotoResources.swift @@ -639,7 +639,10 @@ public func chatMessagePhotoInternal(photoData: Signal<(Data?, Data?, Bool), NoE var blurredThumbnailImage: UIImage? if let thumbnailImage = thumbnailImage { let thumbnailSize = CGSize(width: thumbnailImage.width, height: thumbnailImage.height) - let thumbnailContextSize = thumbnailSize.aspectFitted(CGSize(width: 150.0, height: 150.0)) + + let initialThumbnailContextFittingSize = fittedSize.fitted(CGSize(width: 100.0, height: 100.0)) + + let thumbnailContextSize = thumbnailSize.aspectFitted(initialThumbnailContextFittingSize) let thumbnailContext = DrawingContext(size: thumbnailContextSize, scale: 1.0) thumbnailContext.withFlippedContext { c in c.interpolationQuality = .none @@ -647,7 +650,25 @@ public func chatMessagePhotoInternal(photoData: Signal<(Data?, Data?, Bool), NoE } telegramFastBlur(Int32(thumbnailContextSize.width), Int32(thumbnailContextSize.height), Int32(thumbnailContext.bytesPerRow), thumbnailContext.bytes) - blurredThumbnailImage = thumbnailContext.generateImage() + var thumbnailContextFittingSize = CGSize(width: floor(arguments.drawingSize.width * 0.5), height: floor(arguments.drawingSize.width * 0.5)) + if thumbnailContextFittingSize.width < 150.0 || thumbnailContextFittingSize.height < 150.0 { + thumbnailContextFittingSize = thumbnailContextFittingSize.aspectFilled(CGSize(width: 150.0, height: 150.0)) + } + + if thumbnailContextFittingSize.width > thumbnailContextSize.width { + let additionalContextSize = thumbnailContextFittingSize + let additionalBlurContext = DrawingContext(size: additionalContextSize, scale: 1.0) + additionalBlurContext.withFlippedContext { c in + c.interpolationQuality = .default + if let image = thumbnailContext.generateImage()?.cgImage { + c.draw(image, in: CGRect(origin: CGPoint(), size: additionalContextSize)) + } + } + telegramFastBlur(Int32(additionalContextSize.width), Int32(additionalContextSize.height), Int32(additionalBlurContext.bytesPerRow), additionalBlurContext.bytes) + blurredThumbnailImage = additionalBlurContext.generateImage() + } else { + blurredThumbnailImage = thumbnailContext.generateImage() + } } context.withFlippedContext { c in diff --git a/TelegramUI/StorageUsageController.swift b/TelegramUI/StorageUsageController.swift index 9fb2ff1273..c1b46b4c6a 100644 --- a/TelegramUI/StorageUsageController.swift +++ b/TelegramUI/StorageUsageController.swift @@ -516,11 +516,13 @@ func storageUsageController(account: Account) -> ViewController { } sizeIndex[categoryId] = (true, categorySize) totalSize += categorySize - let index = itemIndex - items.append(ActionSheetCheckboxItem(title: stringForCategory(strings: presentationData.strings, category: categoryId), label: dataSizeString(categorySize), value: true, action: { value in - toggleCheck(categoryId, index) - })) - itemIndex += 1 + if categorySize > 1024 { + let index = itemIndex + items.append(ActionSheetCheckboxItem(title: stringForCategory(strings: presentationData.strings, category: categoryId), label: dataSizeString(categorySize), value: true, action: { value in + toggleCheck(categoryId, index) + })) + itemIndex += 1 + } } }