Various fixes

This commit is contained in:
Ilya Laktyushin 2025-05-25 16:37:55 +02:00
parent bf15144237
commit ce3af41ebe
7 changed files with 88 additions and 57 deletions

View File

@ -2852,6 +2852,8 @@ static CGPoint TGCameraControllerClampPointToScreenSize(__unused id self, __unus
} }
} }
bool isHighQualityPhoto = editingContext.isHighQualityPhoto;
if (storeAssets && !isScan) { if (storeAssets && !isScan) {
NSMutableArray *fullSizeSignals = [[NSMutableArray alloc] init]; NSMutableArray *fullSizeSignals = [[NSMutableArray alloc] init];
for (id<TGMediaEditableItem> item in selectedItems) for (id<TGMediaEditableItem> item in selectedItems)
@ -2968,7 +2970,9 @@ static CGPoint TGCameraControllerClampPointToScreenSize(__unused id self, __unus
id<TGMediaEditAdjustments> adjustments = [editingContext adjustmentsForItem:asset]; id<TGMediaEditAdjustments> adjustments = [editingContext adjustmentsForItem:asset];
NSNumber *timer = [editingContext timerForItem:asset]; NSNumber *timer = [editingContext timerForItem:asset];
SSignal *inlineSignal = [[asset screenImageSignal:0.0] map:^id(UIImage *originalImage)
SSignal *originalSignal = isHighQualityPhoto ? [asset originalImageSignal:0.0] : [asset screenImageSignal:0.0];
SSignal *inlineSignal = [originalSignal map:^id(UIImage *originalImage)
{ {
NSMutableDictionary *dict = [[NSMutableDictionary alloc] init]; NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
dict[@"type"] = @"editedPhoto"; dict[@"type"] = @"editedPhoto";
@ -2979,6 +2983,9 @@ static CGPoint TGCameraControllerClampPointToScreenSize(__unused id self, __unus
else if (groupedId != nil && !hasAnyTimers) else if (groupedId != nil && !hasAnyTimers)
dict[@"groupedId"] = groupedId; dict[@"groupedId"] = groupedId;
if (isHighQualityPhoto)
dict[@"hd"] = @true;
if (isScan) { if (isScan) {
if (caption != nil) if (caption != nil)
dict[@"caption"] = caption; dict[@"caption"] = caption;
@ -3058,6 +3065,9 @@ static CGPoint TGCameraControllerClampPointToScreenSize(__unused id self, __unus
else if (groupedId != nil && !hasAnyTimers) else if (groupedId != nil && !hasAnyTimers)
dict[@"groupedId"] = groupedId; dict[@"groupedId"] = groupedId;
if (isHighQualityPhoto)
dict[@"hd"] = @true;
if (isScan) { if (isScan) {
if (caption != nil) if (caption != nil)
dict[@"caption"] = caption; dict[@"caption"] = caption;

View File

@ -231,6 +231,10 @@ UIImage *TGScaleAndBlurImage(NSData *data, __unused CGSize size, __autoreleasing
UIImage *TGScaleImageToPixelSize(UIImage *image, CGSize size) UIImage *TGScaleImageToPixelSize(UIImage *image, CGSize size)
{ {
if (image.size.width <= size.width && image.size.height <= size.height) {
return image;
}
UIGraphicsBeginImageContextWithOptions(size, true, 1.0f); UIGraphicsBeginImageContextWithOptions(size, true, 1.0f);
[image drawInRect:CGRectMake(0, 0, size.width, size.height) blendMode:kCGBlendModeCopy alpha:1.0f]; [image drawInRect:CGRectMake(0, 0, size.width, size.height) blendMode:kCGBlendModeCopy alpha:1.0f];
UIImage *result = UIGraphicsGetImageFromCurrentImageContext(); UIImage *result = UIGraphicsGetImageFromCurrentImageContext();

View File

@ -1108,7 +1108,7 @@
TGPhotoEditorButton *qualityButton = [_portraitToolbarView buttonForTab:TGPhotoEditorQualityTab]; TGPhotoEditorButton *qualityButton = [_portraitToolbarView buttonForTab:TGPhotoEditorQualityTab];
if (qualityButton != nil) if (qualityButton != nil)
{ {
bool isPhoto = [_currentItemView isKindOfClass:[TGMediaPickerGalleryPhotoItemView class]]; bool isPhoto = [_currentItemView isKindOfClass:[TGMediaPickerGalleryPhotoItemView class]] || [_currentItem isKindOfClass:[TGCameraCapturedPhoto class]];
if (isPhoto) { if (isPhoto) {
bool isHd = _editingContext.isHighQualityPhoto; bool isHd = _editingContext.isHighQualityPhoto;
UIImage *icon = [TGPhotoEditorInterfaceAssets qualityIconForHighQuality:isHd filled: false]; UIImage *icon = [TGPhotoEditorInterfaceAssets qualityIconForHighQuality:isHd filled: false];

View File

@ -197,7 +197,8 @@
__strong TGModernGalleryController *controller = strongSelf.controller; __strong TGModernGalleryController *controller = strongSelf.controller;
if ([controller.currentItem conformsToProtocol:@protocol(TGModernGalleryEditableItem)]) { if ([controller.currentItem conformsToProtocol:@protocol(TGModernGalleryEditableItem)]) {
if (tab == TGPhotoEditorQualityTab && [controller.currentItem isKindOfClass:[TGMediaPickerGalleryFetchResultItem class]] && [((TGMediaPickerGalleryFetchResultItem *)controller.currentItem).backingItem isKindOfClass:[TGMediaPickerGalleryPhotoItem class]]) { bool isPhoto = [controller.currentItem isKindOfClass:[TGMediaPickerGalleryPhotoItem class]] || ([controller.currentItem isKindOfClass:[TGMediaPickerGalleryFetchResultItem class]] && [((TGMediaPickerGalleryFetchResultItem *)controller.currentItem).backingItem isKindOfClass:[TGMediaPickerGalleryPhotoItem class]]);
if (tab == TGPhotoEditorQualityTab && isPhoto) {
[strongSelf->_editingContext setHighQualityPhoto:!strongSelf->_editingContext.isHighQualityPhoto]; [strongSelf->_editingContext setHighQualityPhoto:!strongSelf->_editingContext.isHighQualityPhoto];
[strongSelf->_interfaceView showPhotoQualityTooltip:strongSelf->_editingContext.isHighQualityPhoto]; [strongSelf->_interfaceView showPhotoQualityTooltip:strongSelf->_editingContext.isHighQualityPhoto];
} else { } else {

View File

@ -6,7 +6,7 @@
#import <AVFoundation/AVFoundation.h> #import <AVFoundation/AVFoundation.h>
#import <Accelerate/Accelerate.h> #import <Accelerate/Accelerate.h>
const CGSize TGPhotoEditorResultImageMaxSize = { 1280, 1280 }; const CGSize TGPhotoEditorResultImageMaxSize = { 2560, 2560 };
const CGSize TGPhotoEditorResultImageWallpaperMaxSize = { 2048, 2048 }; const CGSize TGPhotoEditorResultImageWallpaperMaxSize = { 2048, 2048 };
const CGSize TGPhotoEditorResultImageAvatarMaxSize = { 2048, 2048 }; const CGSize TGPhotoEditorResultImageAvatarMaxSize = { 2048, 2048 };
const CGSize TGPhotoEditorScreenImageHardLimitSize = { 1280, 1280 }; const CGSize TGPhotoEditorScreenImageHardLimitSize = { 1280, 1280 };

View File

@ -175,6 +175,7 @@ public func legacyAssetPickerItemGenerator() -> ((Any?, NSAttributedString?, Str
let image = dict["image"] as! UIImage let image = dict["image"] as! UIImage
let thumbnail = dict["previewImage"] as? UIImage let thumbnail = dict["previewImage"] as? UIImage
let cover = dict["coverImage"] as? UIImage let cover = dict["coverImage"] as? UIImage
let forceHd = (dict["hd"] as? NSNumber)?.boolValue ?? false
var result: [AnyHashable : Any] = [:] var result: [AnyHashable : Any] = [:]
if let isAnimation = dict["isAnimation"] as? NSNumber, isAnimation.boolValue { if let isAnimation = dict["isAnimation"] as? NSNumber, isAnimation.boolValue {
@ -184,7 +185,7 @@ public func legacyAssetPickerItemGenerator() -> ((Any?, NSAttributedString?, Str
result["item" as NSString] = LegacyAssetItemWrapper(item: .video(data: .tempFile(path: url, dimensions: dimensions, duration: 4.0), thumbnail: thumbnail, cover: cover, adjustments: dict["adjustments"] as? TGVideoEditAdjustments, caption: caption, asFile: false, asAnimation: true, stickers: stickers), timer: (dict["timer"] as? NSNumber)?.intValue, spoiler: (dict["spoiler"] as? NSNumber)?.boolValue, price: price, groupedId: (dict["groupedId"] as? NSNumber)?.int64Value, uniqueId: uniqueId) result["item" as NSString] = LegacyAssetItemWrapper(item: .video(data: .tempFile(path: url, dimensions: dimensions, duration: 4.0), thumbnail: thumbnail, cover: cover, adjustments: dict["adjustments"] as? TGVideoEditAdjustments, caption: caption, asFile: false, asAnimation: true, stickers: stickers), timer: (dict["timer"] as? NSNumber)?.intValue, spoiler: (dict["spoiler"] as? NSNumber)?.boolValue, price: price, groupedId: (dict["groupedId"] as? NSNumber)?.int64Value, uniqueId: uniqueId)
} }
} else { } else {
result["item" as NSString] = LegacyAssetItemWrapper(item: .image(data: .image(image), thumbnail: thumbnail, caption: caption, stickers: stickers), timer: (dict["timer"] as? NSNumber)?.intValue, spoiler: (dict["spoiler"] as? NSNumber)?.boolValue, price: price, groupedId: (dict["groupedId"] as? NSNumber)?.int64Value, uniqueId: uniqueId) result["item" as NSString] = LegacyAssetItemWrapper(item: .image(data: .image(image), thumbnail: thumbnail, caption: caption, stickers: stickers), timer: (dict["timer"] as? NSNumber)?.intValue, spoiler: (dict["spoiler"] as? NSNumber)?.boolValue, price: price, forceHd: forceHd, groupedId: (dict["groupedId"] as? NSNumber)?.int64Value, uniqueId: uniqueId)
} }
return result return result
} else if (dict["type"] as! NSString) == "cloudPhoto" { } else if (dict["type"] as! NSString) == "cloudPhoto" {
@ -400,7 +401,9 @@ public func legacyAssetPickerEnqueueMessages(context: AccountContext, account: A
var randomId: Int64 = 0 var randomId: Int64 = 0
arc4random_buf(&randomId, 8) arc4random_buf(&randomId, 8)
let tempFilePath = NSTemporaryDirectory() + "\(randomId).jpeg" let tempFilePath = NSTemporaryDirectory() + "\(randomId).jpeg"
let scaledSize = image.size.aspectFittedOrSmaller(CGSize(width: 1280.0, height: 1280.0)) let maxSize = item.forceHd ? CGSize(width: 2560.0, height: 2560.0) : CGSize(width: 1280.0, height: 1280.0)
let scaledSize = image.size.aspectFittedOrSmaller(maxSize)
if let scaledImage = TGScaleImageToPixelSize(image, scaledSize) { if let scaledImage = TGScaleImageToPixelSize(image, scaledSize) {
let tempFile = TempBox.shared.tempFile(fileName: "file") let tempFile = TempBox.shared.tempFile(fileName: "file")
defer { defer {

View File

@ -596,11 +596,23 @@ public class ShareRootControllerImpl {
//inForeground.set(false) //inForeground.set(false)
self?.getExtensionContext()?.completeRequest(returningItems: nil, completionHandler: nil) self?.getExtensionContext()?.completeRequest(returningItems: nil, completionHandler: nil)
} }
var canShareToStory = true
if let inputItems = self?.getExtensionContext()?.inputItems, inputItems.count == 1, let item = inputItems[0] as? NSExtensionItem, let attachments = item.attachments {
for attachment in attachments {
if attachment.hasItemConformingToTypeIdentifier(kUTTypeImage as String) {
} else if attachment.hasItemConformingToTypeIdentifier(kUTTypeMovie as String) {
} else {
canShareToStory = false
}
}
}
if canShareToStory {
shareController.shareStory = { [weak self] in shareController.shareStory = { [weak self] in
guard let self else { guard let self else {
return return
} }
if let inputItems = self.getExtensionContext()?.inputItems, inputItems.count == 1, let item = inputItems[0] as? NSExtensionItem, let attachments = item.attachments { if let inputItems = self.getExtensionContext()?.inputItems, inputItems.count == 1, let item = inputItems[0] as? NSExtensionItem, let attachments = item.attachments {
let sessionId = Int64.random(in: 1000000 ..< .max) let sessionId = Int64.random(in: 1000000 ..< .max)
@ -651,6 +663,7 @@ public class ShareRootControllerImpl {
} }
} }
} }
}
/*shareController.debugAction = { /*shareController.debugAction = {
guard let strongSelf = self else { guard let strongSelf = self else {
return return