mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
Video editor fixes
This commit is contained in:
parent
d0b4ba6f7e
commit
ab64a9699f
@ -3,6 +3,8 @@
|
|||||||
#import <LegacyComponents/TGModernGalleryImageItemImageView.h>
|
#import <LegacyComponents/TGModernGalleryImageItemImageView.h>
|
||||||
#import <AVFoundation/AVFoundation.h>
|
#import <AVFoundation/AVFoundation.h>
|
||||||
|
|
||||||
|
@class TGPhotoEntitiesContainerView;
|
||||||
|
|
||||||
@interface TGMediaPickerGalleryVideoItemView : TGModernGalleryItemView <TGModernGalleryEditableItemView>
|
@interface TGMediaPickerGalleryVideoItemView : TGModernGalleryItemView <TGModernGalleryEditableItemView>
|
||||||
|
|
||||||
@property (nonatomic, strong) TGModernGalleryImageItemImageView *imageView;
|
@property (nonatomic, strong) TGModernGalleryImageItemImageView *imageView;
|
||||||
@ -31,5 +33,6 @@
|
|||||||
- (UIImage *)screenImage;
|
- (UIImage *)screenImage;
|
||||||
- (UIImage *)transitionImage;
|
- (UIImage *)transitionImage;
|
||||||
- (CGRect)editorTransitionViewRect;
|
- (CGRect)editorTransitionViewRect;
|
||||||
|
- (TGPhotoEntitiesContainerView *)entitiesView;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
@class TGPhotoEditorController;
|
@class TGPhotoEditorController;
|
||||||
|
|
||||||
@protocol TGPhotoPaintStickersContext;
|
@protocol TGPhotoPaintStickersContext;
|
||||||
|
@class TGPhotoEntitiesContainerView;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
TGPhotoEditorControllerGenericIntent = 0,
|
TGPhotoEditorControllerGenericIntent = 0,
|
||||||
@ -54,6 +55,8 @@ typedef enum {
|
|||||||
@property (nonatomic, assign) bool dontHideStatusBar;
|
@property (nonatomic, assign) bool dontHideStatusBar;
|
||||||
@property (nonatomic, strong) PGCameraShotMetadata *metadata;
|
@property (nonatomic, strong) PGCameraShotMetadata *metadata;
|
||||||
|
|
||||||
|
@property (nonatomic, strong) TGPhotoEntitiesContainerView *entitiesView;
|
||||||
|
|
||||||
- (instancetype)initWithContext:(id<LegacyComponentsContext>)context item:(id<TGMediaEditableItem>)item intent:(TGPhotoEditorControllerIntent)intent adjustments:(id<TGMediaEditAdjustments>)adjustments caption:(NSString *)caption screenImage:(UIImage *)screenImage availableTabs:(TGPhotoEditorTab)availableTabs selectedTab:(TGPhotoEditorTab)selectedTab;
|
- (instancetype)initWithContext:(id<LegacyComponentsContext>)context item:(id<TGMediaEditableItem>)item intent:(TGPhotoEditorControllerIntent)intent adjustments:(id<TGMediaEditAdjustments>)adjustments caption:(NSString *)caption screenImage:(UIImage *)screenImage availableTabs:(TGPhotoEditorTab)availableTabs selectedTab:(TGPhotoEditorTab)selectedTab;
|
||||||
|
|
||||||
- (void)dismissEditor;
|
- (void)dismissEditor;
|
||||||
|
@ -116,18 +116,22 @@ NSString *const kYUVVideoRangeConversionForLAFragmentShaderString = SHADER_STRIN
|
|||||||
#pragma mark -
|
#pragma mark -
|
||||||
#pragma mark Initialization and teardown
|
#pragma mark Initialization and teardown
|
||||||
|
|
||||||
- (UIInterfaceOrientation)orientationForTrack:(AVAsset *)asset {
|
- (GPUImageRotationMode)rotationForTrack:(AVAsset *)asset {
|
||||||
AVAssetTrack *videoTrack = [[asset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0];
|
AVAssetTrack *videoTrack = [[asset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0];
|
||||||
CGAffineTransform trackTransform = [videoTrack preferredTransform];
|
CGAffineTransform trackTransform = [videoTrack preferredTransform];
|
||||||
|
|
||||||
if (trackTransform.a == -1 && trackTransform.d == -1) {
|
if (trackTransform.a == -1 && trackTransform.d == -1) {
|
||||||
return UIInterfaceOrientationLandscapeRight;
|
return kGPUImageRotate180;
|
||||||
} else if (trackTransform.a == 1 && trackTransform.d == 1) {
|
} else if (trackTransform.a == 1 && trackTransform.d == 1) {
|
||||||
return UIInterfaceOrientationLandscapeLeft;
|
return kGPUImageNoRotation;
|
||||||
} else if (trackTransform.b == -1 && trackTransform.c == 1) {
|
} else if (trackTransform.b == -1 && trackTransform.c == 1) {
|
||||||
return UIInterfaceOrientationPortraitUpsideDown;
|
return kGPUImageRotateLeft;
|
||||||
} else {
|
} else {
|
||||||
return UIInterfaceOrientationPortrait;
|
if (trackTransform.c == 1) {
|
||||||
|
return kGPUImageRotateRightFlipVertical;
|
||||||
|
} else {
|
||||||
|
return kGPUImageRotateRight;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -385,16 +389,8 @@ NSString *const kYUVVideoRangeConversionForLAFragmentShaderString = SHADER_STRIN
|
|||||||
|
|
||||||
AVAsset *asset = self.playerItem.asset;
|
AVAsset *asset = self.playerItem.asset;
|
||||||
if (asset != nil) {
|
if (asset != nil) {
|
||||||
UIInterfaceOrientation orientation = [self orientationForTrack:asset];
|
GPUImageRotationMode rotation = [self rotationForTrack:asset];
|
||||||
if (orientation == UIInterfaceOrientationPortrait) {
|
[currentTarget setInputRotation:rotation atIndex:targetTextureIndex];
|
||||||
[currentTarget setInputRotation:kGPUImageRotateRight atIndex:targetTextureIndex];
|
|
||||||
} else if (orientation == UIInterfaceOrientationLandscapeRight) {
|
|
||||||
[currentTarget setInputRotation:kGPUImageRotate180 atIndex:targetTextureIndex];
|
|
||||||
} else if (orientation == UIInterfaceOrientationPortraitUpsideDown) {
|
|
||||||
[currentTarget setInputRotation:kGPUImageRotateLeft atIndex:targetTextureIndex];
|
|
||||||
} else {
|
|
||||||
[currentTarget setInputRotation:kGPUImageNoRotation atIndex:targetTextureIndex];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,6 +51,8 @@
|
|||||||
#import "TGCameraCapturedPhoto.h"
|
#import "TGCameraCapturedPhoto.h"
|
||||||
#import "TGCameraCapturedVideo.h"
|
#import "TGCameraCapturedVideo.h"
|
||||||
|
|
||||||
|
#import "PGPhotoEditor.h"
|
||||||
|
|
||||||
#import "TGAnimationUtils.h"
|
#import "TGAnimationUtils.h"
|
||||||
|
|
||||||
const CGFloat TGCameraSwipeMinimumVelocity = 600.0f;
|
const CGFloat TGCameraSwipeMinimumVelocity = 600.0f;
|
||||||
@ -2665,10 +2667,17 @@ static CGPoint TGCameraControllerClampPointToScreenSize(__unused id self, __unus
|
|||||||
|
|
||||||
UIImage *(^cropVideoThumbnail)(UIImage *, CGSize, CGSize, bool) = ^UIImage *(UIImage *image, CGSize targetSize, CGSize sourceSize, bool resize)
|
UIImage *(^cropVideoThumbnail)(UIImage *, CGSize, CGSize, bool) = ^UIImage *(UIImage *image, CGSize targetSize, CGSize sourceSize, bool resize)
|
||||||
{
|
{
|
||||||
if ([adjustments cropAppliedForAvatar:false] || adjustments.hasPainting)
|
if ([adjustments cropAppliedForAvatar:false] || adjustments.hasPainting || adjustments.toolsApplied)
|
||||||
{
|
{
|
||||||
CGRect scaledCropRect = CGRectMake(adjustments.cropRect.origin.x * image.size.width / adjustments.originalSize.width, adjustments.cropRect.origin.y * image.size.height / adjustments.originalSize.height, adjustments.cropRect.size.width * image.size.width / adjustments.originalSize.width, adjustments.cropRect.size.height * image.size.height / adjustments.originalSize.height);
|
CGRect scaledCropRect = CGRectMake(adjustments.cropRect.origin.x * image.size.width / adjustments.originalSize.width, adjustments.cropRect.origin.y * image.size.height / adjustments.originalSize.height, adjustments.cropRect.size.width * image.size.width / adjustments.originalSize.width, adjustments.cropRect.size.height * image.size.height / adjustments.originalSize.height);
|
||||||
return TGPhotoEditorCrop(image, adjustments.paintingData.image, adjustments.cropOrientation, 0, scaledCropRect, adjustments.cropMirrored, targetSize, sourceSize, resize);
|
UIImage *paintingImage = adjustments.paintingData.stillImage;
|
||||||
|
if (paintingImage == nil) {
|
||||||
|
paintingImage = adjustments.paintingData.image;
|
||||||
|
}
|
||||||
|
if (adjustments.toolsApplied) {
|
||||||
|
image = [PGPhotoEditor resultImageForImage:image adjustments:adjustments];
|
||||||
|
}
|
||||||
|
return TGPhotoEditorCrop(image, paintingImage, adjustments.cropOrientation, 0, scaledCropRect, adjustments.cropMirrored, targetSize, sourceSize, resize);
|
||||||
}
|
}
|
||||||
|
|
||||||
return image;
|
return image;
|
||||||
|
@ -20,6 +20,8 @@
|
|||||||
|
|
||||||
#import <LegacyComponents/TGSecretTimerMenu.h>
|
#import <LegacyComponents/TGSecretTimerMenu.h>
|
||||||
|
|
||||||
|
#import "TGPhotoEntitiesContainerView.h"
|
||||||
|
|
||||||
@interface TGMediaPickerGalleryModel ()
|
@interface TGMediaPickerGalleryModel ()
|
||||||
{
|
{
|
||||||
TGMediaPickerGalleryInterfaceView *_interfaceView;
|
TGMediaPickerGalleryInterfaceView *_interfaceView;
|
||||||
@ -361,11 +363,17 @@
|
|||||||
UIView *referenceParentView = nil;
|
UIView *referenceParentView = nil;
|
||||||
UIImage *image = nil;
|
UIImage *image = nil;
|
||||||
|
|
||||||
|
TGPhotoEntitiesContainerView *entitiesView = nil;
|
||||||
|
|
||||||
bool isVideo = false;
|
bool isVideo = false;
|
||||||
if ([editorReferenceView isKindOfClass:[UIImageView class]])
|
if ([editorReferenceView isKindOfClass:[UIImageView class]])
|
||||||
{
|
{
|
||||||
screenImage = [(UIImageView *)editorReferenceView image];
|
screenImage = [(UIImageView *)editorReferenceView image];
|
||||||
referenceView = editorReferenceView;
|
referenceView = editorReferenceView;
|
||||||
|
|
||||||
|
if ([editorReferenceView.subviews.firstObject.subviews.firstObject.subviews.firstObject isKindOfClass:[TGPhotoEntitiesContainerView class]]) {
|
||||||
|
entitiesView = editorReferenceView.subviews.firstObject.subviews.firstObject.subviews.firstObject;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if ([editorReferenceView isKindOfClass:[TGMediaPickerGalleryVideoItemView class]])
|
else if ([editorReferenceView isKindOfClass:[TGMediaPickerGalleryVideoItemView class]])
|
||||||
{
|
{
|
||||||
@ -378,6 +386,8 @@
|
|||||||
referenceView = [[UIImageView alloc] initWithImage:screenImage];
|
referenceView = [[UIImageView alloc] initWithImage:screenImage];
|
||||||
referenceParentView = editorReferenceView;
|
referenceParentView = editorReferenceView;
|
||||||
|
|
||||||
|
entitiesView = [videoItemView entitiesView];
|
||||||
|
|
||||||
isVideo = true;
|
isVideo = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -386,6 +396,7 @@
|
|||||||
|
|
||||||
TGPhotoEditorControllerIntent intent = isVideo ? TGPhotoEditorControllerVideoIntent : TGPhotoEditorControllerGenericIntent;
|
TGPhotoEditorControllerIntent intent = isVideo ? TGPhotoEditorControllerVideoIntent : TGPhotoEditorControllerGenericIntent;
|
||||||
TGPhotoEditorController *controller = [[TGPhotoEditorController alloc] initWithContext:_context item:item.editableMediaItem intent:intent adjustments:editorValues caption:caption screenImage:screenImage availableTabs:_interfaceView.currentTabs selectedTab:tab];
|
TGPhotoEditorController *controller = [[TGPhotoEditorController alloc] initWithContext:_context item:item.editableMediaItem intent:intent adjustments:editorValues caption:caption screenImage:screenImage availableTabs:_interfaceView.currentTabs selectedTab:tab];
|
||||||
|
controller.entitiesView =
|
||||||
controller.editingContext = _editingContext;
|
controller.editingContext = _editingContext;
|
||||||
controller.stickersContext = _stickersContext;
|
controller.stickersContext = _stickersContext;
|
||||||
self.editorController = controller;
|
self.editorController = controller;
|
||||||
|
@ -790,7 +790,11 @@
|
|||||||
CGPoint offset = TGPaintSubtractPoints(centerPoint, [TGPhotoPaintController fittedCropRect:cropRect centerScale:scale]);
|
CGPoint offset = TGPaintSubtractPoints(centerPoint, [TGPhotoPaintController fittedCropRect:cropRect centerScale:scale]);
|
||||||
|
|
||||||
CGPoint boundsCenter = TGPaintCenterOfRect(_contentWrapperView.bounds);
|
CGPoint boundsCenter = TGPaintCenterOfRect(_contentWrapperView.bounds);
|
||||||
_entitiesContainerView.center = TGPaintAddPoints(boundsCenter, offset);
|
_entitiesContainerView.center = TGPaintAddPoints(boundsCenter, CGPointMake(offset.x, offset.y));
|
||||||
|
}
|
||||||
|
|
||||||
|
- (TGPhotoEntitiesContainerView *)entitiesView {
|
||||||
|
return _entitiesContainerView;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)singleTap
|
- (void)singleTap
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
- (void)setSnapshotImage:(UIImage *)snapshotImage;
|
- (void)setSnapshotImage:(UIImage *)snapshotImage;
|
||||||
- (void)setSnapshotView:(UIView *)snapshotView;
|
- (void)setSnapshotView:(UIView *)snapshotView;
|
||||||
- (void)setPaintingImage:(UIImage *)paintingImage;
|
- (void)setPaintingImage:(UIImage *)paintingImage;
|
||||||
|
- (void)setEntitiesView:(UIView *)entitiesView;
|
||||||
|
|
||||||
- (void)animateTransitionIn;
|
- (void)animateTransitionIn;
|
||||||
- (void)animateTransitionOut;
|
- (void)animateTransitionOut;
|
||||||
|
@ -40,6 +40,7 @@ const CGFloat TGPhotoCropViewOverscreenSize = 1000;
|
|||||||
UIView *_snapshotView;
|
UIView *_snapshotView;
|
||||||
CGSize _snapshotSize;
|
CGSize _snapshotSize;
|
||||||
UIImageView *_paintingImageView;
|
UIImageView *_paintingImageView;
|
||||||
|
UIView *_entitiesView;
|
||||||
|
|
||||||
UIImage *_paintingImage;
|
UIImage *_paintingImage;
|
||||||
|
|
||||||
@ -398,6 +399,11 @@ const CGFloat TGPhotoCropViewOverscreenSize = 1000;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)setEntitiesView:(UIView *)entitiesView
|
||||||
|
{
|
||||||
|
_entitiesView = entitiesView;
|
||||||
|
}
|
||||||
|
|
||||||
#pragma mark - Crop Area
|
#pragma mark - Crop Area
|
||||||
|
|
||||||
- (void)handleCropAreaChanged
|
- (void)handleCropAreaChanged
|
||||||
|
Loading…
x
Reference in New Issue
Block a user