mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-22 22:25:57 +00:00
Camera and editor improvements
This commit is contained in:
@@ -639,7 +639,7 @@ public final class DrawingTextEntityView: DrawingEntityView, UITextViewDelegate
|
||||
let emojiTextPosition = emojiRect.center.offsetBy(dx: -textSize.width / 2.0, dy: -textSize.height / 2.0)
|
||||
|
||||
let entity = DrawingStickerEntity(content: .file(file))
|
||||
entity.referenceDrawingSize = CGSize(width: itemSize * 2.5, height: itemSize * 2.5)
|
||||
entity.referenceDrawingSize = CGSize(width: itemSize * 4.0, height: itemSize * 4.0)
|
||||
entity.scale = scale
|
||||
entity.position = textPosition.offsetBy(
|
||||
dx: (emojiTextPosition.x * cos(rotation) + emojiTextPosition.y * sin(rotation)) * scale,
|
||||
|
||||
@@ -75,7 +75,11 @@ final class MediaEditorComposer {
|
||||
self.drawingImage = nil
|
||||
}
|
||||
|
||||
self.entities = values.entities.map { $0.entity } .compactMap { composerEntityForDrawingEntity(account: account, entity: $0, colorSpace: colorSpace) }
|
||||
var entities: [MediaEditorComposerEntity] = []
|
||||
for entity in values.entities {
|
||||
entities.append(contentsOf: composerEntitiesForDrawingEntity(account: account, entity: entity.entity, colorSpace: colorSpace))
|
||||
}
|
||||
self.entities = entities
|
||||
|
||||
self.device = MTLCreateSystemDefaultDevice()
|
||||
if let device = self.device {
|
||||
@@ -182,7 +186,11 @@ public func makeEditorImageComposition(account: Account, inputImage: UIImage, di
|
||||
drawingImage = image.transformed(by: CGAffineTransform(translationX: -dimensions.width / 2.0, y: -dimensions.height / 2.0))
|
||||
}
|
||||
|
||||
let entities: [MediaEditorComposerEntity] = values.entities.map { $0.entity }.compactMap { composerEntityForDrawingEntity(account: account, entity: $0, colorSpace: colorSpace) }
|
||||
var entities: [MediaEditorComposerEntity] = []
|
||||
for entity in values.entities {
|
||||
entities.append(contentsOf: composerEntitiesForDrawingEntity(account: account, entity: entity.entity, colorSpace: colorSpace))
|
||||
}
|
||||
|
||||
makeEditorImageFrameComposition(inputImage: inputImage, gradientImage: gradientImage, drawingImage: drawingImage, dimensions: dimensions, values: values, entities: entities, time: time, completion: { ciImage in
|
||||
if let ciImage {
|
||||
let context = CIContext(options: [.workingColorSpace : NSNull()])
|
||||
|
||||
@@ -12,7 +12,7 @@ import TelegramAnimatedStickerNode
|
||||
import YuvConversion
|
||||
import StickerResources
|
||||
|
||||
func composerEntityForDrawingEntity(account: Account, entity: DrawingEntity, colorSpace: CGColorSpace) -> MediaEditorComposerEntity? {
|
||||
func composerEntitiesForDrawingEntity(account: Account, entity: DrawingEntity, colorSpace: CGColorSpace) -> [MediaEditorComposerEntity] {
|
||||
if let entity = entity as? DrawingStickerEntity {
|
||||
let content: MediaEditorComposerStickerEntity.Content
|
||||
switch entity.content {
|
||||
@@ -21,19 +21,26 @@ func composerEntityForDrawingEntity(account: Account, entity: DrawingEntity, col
|
||||
case let .image(image):
|
||||
content = .image(image)
|
||||
}
|
||||
return MediaEditorComposerStickerEntity(account: account, content: content, position: entity.position, scale: entity.scale, rotation: entity.rotation, baseSize: entity.baseSize, mirrored: entity.mirrored, colorSpace: colorSpace)
|
||||
return [MediaEditorComposerStickerEntity(account: account, content: content, position: entity.position, scale: entity.scale, rotation: entity.rotation, baseSize: entity.baseSize, mirrored: entity.mirrored, colorSpace: colorSpace)]
|
||||
} else if let renderImage = entity.renderImage, let image = CIImage(image: renderImage, options: [.colorSpace: colorSpace]) {
|
||||
if let entity = entity as? DrawingBubbleEntity {
|
||||
return MediaEditorComposerStaticEntity(image: image, position: entity.position, scale: 1.0, rotation: entity.rotation, baseSize: entity.size, mirrored: false)
|
||||
return [MediaEditorComposerStaticEntity(image: image, position: entity.position, scale: 1.0, rotation: entity.rotation, baseSize: entity.size, mirrored: false)]
|
||||
} else if let entity = entity as? DrawingSimpleShapeEntity {
|
||||
return MediaEditorComposerStaticEntity(image: image, position: entity.position, scale: 1.0, rotation: entity.rotation, baseSize: entity.size, mirrored: false)
|
||||
return [MediaEditorComposerStaticEntity(image: image, position: entity.position, scale: 1.0, rotation: entity.rotation, baseSize: entity.size, mirrored: false)]
|
||||
} else if let entity = entity as? DrawingVectorEntity {
|
||||
return MediaEditorComposerStaticEntity(image: image, position: CGPoint(x: entity.drawingSize.width * 0.5, y: entity.drawingSize.height * 0.5), scale: 1.0, rotation: 0.0, baseSize: entity.drawingSize, mirrored: false)
|
||||
return [MediaEditorComposerStaticEntity(image: image, position: CGPoint(x: entity.drawingSize.width * 0.5, y: entity.drawingSize.height * 0.5), scale: 1.0, rotation: 0.0, baseSize: entity.drawingSize, mirrored: false)]
|
||||
} else if let entity = entity as? DrawingTextEntity {
|
||||
return MediaEditorComposerStaticEntity(image: image, position: entity.position, scale: entity.scale, rotation: entity.rotation, baseSize: nil, mirrored: false)
|
||||
var entities: [MediaEditorComposerEntity] = []
|
||||
entities.append(MediaEditorComposerStaticEntity(image: image, position: entity.position, scale: entity.scale, rotation: entity.rotation, baseSize: nil, mirrored: false))
|
||||
if let renderSubEntities = entity.renderSubEntities {
|
||||
for subEntity in renderSubEntities {
|
||||
entities.append(contentsOf: composerEntitiesForDrawingEntity(account: account, entity: subEntity, colorSpace: colorSpace))
|
||||
}
|
||||
}
|
||||
return nil
|
||||
return entities
|
||||
}
|
||||
}
|
||||
return []
|
||||
}
|
||||
|
||||
private class MediaEditorComposerStaticEntity: MediaEditorComposerEntity {
|
||||
|
||||
@@ -479,7 +479,7 @@ public final class MediaEditorVideoExport {
|
||||
return false
|
||||
}
|
||||
|
||||
let duration: Double = 3.0
|
||||
let duration: Double = 5.0
|
||||
let frameRate: Double = Double(self.configuration.frameRate)
|
||||
var position: CMTime = CMTime(value: 0, timescale: Int32(self.configuration.frameRate))
|
||||
|
||||
@@ -493,6 +493,9 @@ public final class MediaEditorVideoExport {
|
||||
return false
|
||||
}
|
||||
self.pauseDispatchGroup.wait()
|
||||
|
||||
let progress = (position - .zero).seconds / duration
|
||||
self.statusValue = .progress(Float(progress))
|
||||
composer.processImage(inputImage: image, pool: writer.pixelBufferPool, time: position, completion: { pixelBuffer, timestamp in
|
||||
if let pixelBuffer {
|
||||
if !writer.appendPixelBuffer(pixelBuffer, at: timestamp) {
|
||||
|
||||
Reference in New Issue
Block a user