mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
Video avatar fixes
This commit is contained in:
parent
fb5c983f04
commit
b157e92eb2
@ -23,8 +23,12 @@
|
||||
|
||||
#import <LegacyComponents/TGMenuView.h>
|
||||
|
||||
#import "TGPaintFaceDetector.h"
|
||||
|
||||
@interface TGMediaPickerGalleryPhotoItemView ()
|
||||
{
|
||||
SMetaDisposable *_facesDisposable;
|
||||
|
||||
UILabel *_fileInfoLabel;
|
||||
|
||||
TGMessageImageViewOverlayView *_progressView;
|
||||
@ -57,6 +61,8 @@
|
||||
self = [super initWithFrame:frame];
|
||||
if (self != nil)
|
||||
{
|
||||
_facesDisposable = [[SMetaDisposable alloc] init];
|
||||
|
||||
__weak TGMediaPickerGalleryPhotoItemView *weakSelf = self;
|
||||
_imageView = [[TGModernGalleryImageItemImageView alloc] init];
|
||||
_imageView.clipsToBounds = true;
|
||||
@ -101,6 +107,7 @@
|
||||
{
|
||||
[_adjustmentsDisposable dispose];
|
||||
[_attributesDisposable dispose];
|
||||
[_facesDisposable dispose];
|
||||
}
|
||||
|
||||
- (void)setHiddenAsBeingEdited:(bool)hidden
|
||||
@ -226,8 +233,11 @@
|
||||
|
||||
}]];
|
||||
|
||||
if (!item.asFile)
|
||||
if (!item.asFile) {
|
||||
[_facesDisposable setDisposable:[[TGPaintFaceDetector detectFacesInItem:item.editableMediaItem editingContext:item.editingContext] startWithNext:nil]];
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
_fileInfoLabel.text = nil;
|
||||
|
||||
|
@ -41,6 +41,7 @@
|
||||
#import <LegacyComponents/TGMenuView.h>
|
||||
|
||||
#import "PGPhotoEditor.h"
|
||||
#import "TGPaintFaceDetector.h"
|
||||
|
||||
@interface TGMediaPickerGalleryVideoItemView() <TGMediaPickerGalleryVideoScrubberDataSource, TGMediaPickerGalleryVideoScrubberDelegate>
|
||||
{
|
||||
@ -96,6 +97,7 @@
|
||||
SMetaDisposable *_adjustmentsDisposable;
|
||||
SMetaDisposable *_attributesDisposable;
|
||||
SMetaDisposable *_downloadDisposable;
|
||||
SMetaDisposable *_facesDisposable;
|
||||
SMetaDisposable *_currentAudioSession;
|
||||
|
||||
SVariable *_editableItemVariable;
|
||||
@ -131,6 +133,7 @@
|
||||
|
||||
_currentAudioSession = [[SMetaDisposable alloc] init];
|
||||
_playerItemDisposable = [[SMetaDisposable alloc] init];
|
||||
_facesDisposable = [[SMetaDisposable alloc] init];
|
||||
|
||||
_videoDurationVar = [[SVariable alloc] init];
|
||||
_videoDurationDisposable = [[SMetaDisposable alloc] init];
|
||||
@ -251,6 +254,7 @@
|
||||
[_thumbnailsDisposable dispose];
|
||||
[_attributesDisposable dispose];
|
||||
[_downloadDisposable dispose];
|
||||
[_facesDisposable dispose];
|
||||
[self stopPlayer];
|
||||
|
||||
[self releaseVolumeOverlay];
|
||||
@ -385,9 +389,14 @@
|
||||
|
||||
[super setItem:item synchronously:synchronously];
|
||||
|
||||
if (itemChanged)
|
||||
if (itemChanged) {
|
||||
[self _playerCleanup];
|
||||
|
||||
if (!item.asFile) {
|
||||
[_facesDisposable setDisposable:[[TGPaintFaceDetector detectFacesInItem:item.editableMediaItem editingContext:item.editingContext] startWithNext:nil]];
|
||||
}
|
||||
}
|
||||
|
||||
_scrubberView.allowsTrimming = false;
|
||||
_videoDimensions = item.dimensions;
|
||||
_entitiesContainerView.stickersContext = item.stickersContext;
|
||||
|
@ -1,6 +1,9 @@
|
||||
#import <UIKit/UIKit.h>
|
||||
#import <SSignalKit/SSignalKit.h>
|
||||
|
||||
@protocol TGMediaEditableItem;
|
||||
@class TGMediaEditingContext;
|
||||
|
||||
@interface TGPaintFaceFeature : NSObject
|
||||
{
|
||||
CGPoint _position;
|
||||
@ -49,6 +52,8 @@
|
||||
|
||||
+ (SSignal *)detectFacesInImage:(UIImage *)image originalSize:(CGSize)originalSize;
|
||||
|
||||
+ (SSignal *)detectFacesInItem:(id<TGMediaEditableItem>)item editingContext:(TGMediaEditingContext *)editingContext;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
|
@ -3,6 +3,8 @@
|
||||
#import <LegacyComponents/TGPaintUtils.h>
|
||||
#import <ImageIO/ImageIO.h>
|
||||
|
||||
#import "TGMediaEditingContext.m"
|
||||
|
||||
@interface TGPaintFace ()
|
||||
|
||||
+ (instancetype)faceWithBounds:(CGRect)bounds angle:(CGFloat)angle leftEye:(TGPaintFaceEye *)leftEye rightEye:(TGPaintFaceEye *)rightEye mouth:(TGPaintFaceMouth *)mouth;
|
||||
@ -26,6 +28,41 @@
|
||||
|
||||
@implementation TGPaintFaceDetector
|
||||
|
||||
+ (SSignal *)detectFacesInItem:(id<TGMediaEditableItem>)item editingContext:(TGMediaEditingContext *)editingContext
|
||||
{
|
||||
CGSize originalSize = item.originalSize;
|
||||
|
||||
SSignal *cachedFaces = [editingContext facesForItem:item];
|
||||
SSignal *cachedSignal = [cachedFaces mapToSignal:^SSignal *(id result)
|
||||
{
|
||||
if (result == nil)
|
||||
return [SSignal fail:nil];
|
||||
return [SSignal single:result];
|
||||
}];
|
||||
|
||||
SSignal *imageSignal = [item screenImageSignal:0];
|
||||
SSignal *detectSignal = [[[imageSignal filter:^bool(UIImage *image)
|
||||
{
|
||||
if (![image isKindOfClass:[UIImage class]])
|
||||
return false;
|
||||
|
||||
if (image.degraded)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}] take:1] mapToSignal:^SSignal *(UIImage *image) {
|
||||
return [[TGPaintFaceDetector detectFacesInImage:image originalSize:originalSize] startOn:[SQueue concurrentDefaultQueue]];
|
||||
}];
|
||||
|
||||
return [[[cachedSignal catch:^SSignal *(__unused id error)
|
||||
{
|
||||
return detectSignal;
|
||||
}] deliverOn:[SQueue mainQueue]] onNext:^(NSArray *next)
|
||||
{
|
||||
[editingContext setFaces:next forItem:item];
|
||||
}];
|
||||
}
|
||||
|
||||
+ (SSignal *)detectFacesInImage:(UIImage *)image originalSize:(CGSize)originalSize
|
||||
{
|
||||
return [[SSignal alloc] initWithGenerator:^id<SDisposable>(SSubscriber *subscriber)
|
||||
|
@ -263,6 +263,8 @@ const CGFloat TGPhotoAvatarPreviewLandscapePanelSize = TGPhotoAvatarPreviewPanel
|
||||
- (void)prepareTransitionInWithReferenceView:(UIView *)referenceView referenceFrame:(CGRect)referenceFrame parentView:(UIView *)parentView noTransitionView:(bool)noTransitionView
|
||||
{
|
||||
[super prepareTransitionInWithReferenceView:referenceView referenceFrame:referenceFrame parentView:parentView noTransitionView:noTransitionView];
|
||||
|
||||
if (self.initialAppearance && self.fromCamera)
|
||||
[self.view insertSubview:_transitionView belowSubview:_wrapperView];
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user