Explorar o código

fix: 创意模板Decoder 添加 fg 、fgmask 属性 实现"时空穿越 " 模板

Melody %!s(int64=5) %!d(string=hai) anos
pai
achega
e19a5db316

+ 2 - 0
SuperShow/OJAGPUImageDecoder/Model/OJATemplateDataModel.h

@@ -57,6 +57,8 @@ typedef NS_ENUM(NSInteger, OJATemplateItemFilterType) {
 @property (nonatomic, assign) NSInteger blendFunc;
 @property (nonatomic, assign) NSInteger bgColor;//背景颜色,默认是0即是透明
 @property (nonatomic, strong) NSArray<OJATemplateItemModel *> *items;
+@property (nonatomic, strong)  OJATemplateItemModel * _Nullable fg;
+@property (nonatomic, strong)  OJATemplateItemModel * _Nullable fgm;
 @property (nonatomic, strong) OJATemplateItemModel *bg;
 @property (nonatomic, strong) OJATemplateItemModel *mask;
 @property (nonatomic, strong) OJATemplateItemModel *bottom;

+ 2 - 0
SuperShow/OJAGPUImageDecoder/OJACompositionInput.swift

@@ -45,6 +45,8 @@ class OJACompositionInput: NSObject {
         self.templateModel.bg.destinationPathString = destinationPathString
         self.templateModel.mask.destinationPathString = destinationPathString
         self.templateModel.bottom.destinationPathString = destinationPathString
+        self.templateModel.fg?.destinationPathString = destinationPathString
+        self.templateModel.fgm?.destinationPathString = destinationPathString
         
         templateModel.items.forEach { [unowned self] (itemModel) in
             self.setupTemplateItem(itemModel: itemModel)

+ 21 - 0
SuperShow/OJAGPUImageDecoder/OJADecoder.swift

@@ -24,6 +24,8 @@ class OJADecoder: NSObject {
     //可以是OJAAlphaMovieFrameInput 或者OJAMovieFrameInput
     fileprivate var timeMovieInput: OJAFrameInput
     
+    fileprivate var fgMovieInput: OJAFrameInput? // 实现 “时空穿越 ” 需要用到新的 fg、fgm 参数实现
+    
     fileprivate var allInputArray = [OJAFrameInput]()
     
     fileprivate var lastInputArray = [OJAFrameInput]()
@@ -64,6 +66,11 @@ class OJADecoder: NSObject {
         self.backgroundColor = OJSColor(hexRGBValue: compositionInput.templateModel.bgColor)
         super.init()
         
+        if let fgItemModel = compositionInput.templateModel.fg,
+            let fgMaskItemModel = compositionInput.templateModel.fgm {
+            self.fgMovieInput = OJAAlphaMovieFrameInput(backgroundItem: fgItemModel, maskItem: fgMaskItemModel, bottomItem: nil)
+        }
+
         //初始化的时候要设置一次filter链,因为可能最开始currentInputArray和lastInputArray都是0
         self.lastInputArray = self.currentInputArray()
         self.buildChain()
@@ -127,6 +134,12 @@ private extension OJADecoder {
             self.backgroundColor.getRed(&cr, green: &cg, blue: &cb, alpha: &ca)
             blendFilter.setBackgroundColorRed(GLfloat(cr), green: GLfloat(cg), blue: GLfloat(cb), alpha: GLfloat(ca))
             var tempArray = lastInputArray
+            
+            /// 如果有前景添加前景素材
+            if let fgInput = fgMovieInput {
+                tempArray.append(fgInput)
+            }
+            
             if self.templateDataModel.blend == 1 {
                 tempArray = tempArray.sorted(by: { (input1, input2) -> Bool in
                     return input1.zIndex < input2.zIndex
@@ -233,6 +246,14 @@ extension OJADecoder {
                             input.processFrame(atSampleTime: sampleBufferTime)
                         }
                         
+                        /// 读取 fg 和 fgMask 素材,并且上传纹理
+                        if let fgMovieInput = self.fgMovieInput as? OJAAlphaMovieFrameInput{
+                            if let fgBufferTemp = fgMovieInput.readCoverFrameBuffer(),
+                                let fgMaskBufferTemp = fgMovieInput.readMaskFrameBuffer() {
+                                fgMovieInput.processFrame(atSampleTime: sampleBufferTime, coverBuffer: fgBufferTemp, maskBuffer: fgMaskBufferTemp)
+                            }
+                        }
+                        
                         alphaMovieInput.processFrame(atSampleTime: sampleBufferTime, coverBuffer: coverBuffer, maskBuffer: maskBuffer, bottomBuffer: bottomBufferTemp)
                         print(self.currentFrame)
                         self.currentFrame += 1