chore: upgrade Swift interop gen
This commit is contained in:
@@ -6,11 +6,11 @@ public class ThermionFlutterTexture : NSObject, FlutterTexture {
|
||||
|
||||
var flutterTextureId: Int64 = -1
|
||||
var registry: FlutterTextureRegistry
|
||||
var texture: ThermionDartTexture
|
||||
var texture: ThermionTexture
|
||||
|
||||
init(registry:FlutterTextureRegistry, width:Int64, height:Int64) {
|
||||
self.registry = registry
|
||||
self.texture = ThermionDartTexture(width:width, height: height)
|
||||
self.texture = ThermionTexture(width:width, height: height)
|
||||
super.init()
|
||||
self.flutterTextureId = registry.register(self)
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import Foundation
|
||||
import GLKit
|
||||
|
||||
@objc public class ThermionDartTexture : NSObject {
|
||||
@objc public class ThermionTextureSwift : NSObject {
|
||||
|
||||
public var pixelBuffer: CVPixelBuffer?
|
||||
|
||||
@@ -62,37 +62,6 @@ import GLKit
|
||||
metalTexture = CVMetalTextureGetTexture(cvMetalTexture!)
|
||||
let metalTexturePtr = Unmanaged.passRetained(metalTexture!).toOpaque()
|
||||
metalTextureAddress = Int(bitPattern:metalTexturePtr)
|
||||
|
||||
// CVPixelBufferLockBaseAddress(pixelBuffer!, CVPixelBufferLockFlags(rawValue: 0))
|
||||
// let bufferWidth = Int(CVPixelBufferGetWidth(pixelBuffer!))
|
||||
// let bufferHeight = Int(CVPixelBufferGetHeight(pixelBuffer!))
|
||||
// let bytesPerRow = CVPixelBufferGetBytesPerRow(pixelBuffer!)
|
||||
|
||||
// guard let baseAddress = CVPixelBufferGetBaseAddress(pixelBuffer!) else {
|
||||
// return
|
||||
// }
|
||||
|
||||
// for row in 0..<bufferHeight {
|
||||
// var pixel = baseAddress + row * bytesPerRow
|
||||
// for col in 0..<bufferWidth {
|
||||
// let blue = pixel
|
||||
// blue.storeBytes(of: 255, as: UInt8.self)
|
||||
|
||||
// let red = pixel + 1
|
||||
// red.storeBytes(of: 0, as: UInt8.self)
|
||||
|
||||
// let green = pixel + 2
|
||||
// green.storeBytes(of: 0, as: UInt8.self)
|
||||
|
||||
// let alpha = pixel + 3
|
||||
// alpha.storeBytes(of: 255, as: UInt8.self)
|
||||
|
||||
// pixel += 4;
|
||||
// }
|
||||
// }
|
||||
|
||||
// CVPixelBufferUnlockBaseAddress(pixelBuffer!, CVPixelBufferLockFlags(rawValue: 0))
|
||||
|
||||
}
|
||||
|
||||
@objc public func destroyTexture() {
|
||||
@@ -104,5 +73,70 @@ import GLKit
|
||||
self.cvMetalTextureCache = nil
|
||||
}
|
||||
|
||||
@objc public func fillColor() {
|
||||
CVPixelBufferLockBaseAddress(pixelBuffer!, CVPixelBufferLockFlags(rawValue: 0))
|
||||
let bufferWidth = Int(CVPixelBufferGetWidth(pixelBuffer!))
|
||||
let bufferHeight = Int(CVPixelBufferGetHeight(pixelBuffer!))
|
||||
let bytesPerRow = CVPixelBufferGetBytesPerRow(pixelBuffer!)
|
||||
|
||||
guard let baseAddress = CVPixelBufferGetBaseAddress(pixelBuffer!) else {
|
||||
return
|
||||
}
|
||||
|
||||
for row in 0..<bufferHeight {
|
||||
var pixel = baseAddress + row * bytesPerRow
|
||||
for col in 0..<bufferWidth {
|
||||
let blue = pixel
|
||||
blue.storeBytes(of: 255, as: UInt8.self)
|
||||
|
||||
let red = pixel + 1
|
||||
red.storeBytes(of: 0, as: UInt8.self)
|
||||
|
||||
let green = pixel + 2
|
||||
green.storeBytes(of: 0, as: UInt8.self)
|
||||
|
||||
let alpha = pixel + 3
|
||||
alpha.storeBytes(of: 255, as: UInt8.self)
|
||||
|
||||
pixel += 4;
|
||||
}
|
||||
}
|
||||
|
||||
CVPixelBufferUnlockBaseAddress(pixelBuffer!, CVPixelBufferLockFlags(rawValue: 0))
|
||||
}
|
||||
@objc public func getTextureBytes() -> NSData? {
|
||||
guard let texture = self.metalTexture else {
|
||||
print("Metal texture is not available")
|
||||
return nil
|
||||
}
|
||||
|
||||
let width = texture.width
|
||||
let height = texture.height
|
||||
let bytesPerPixel = 4 // RGBA
|
||||
let bytesPerRow = width * bytesPerPixel
|
||||
let byteCount = bytesPerRow * height
|
||||
|
||||
var bytes = [UInt8](repeating: 0, count: byteCount)
|
||||
let region = MTLRegionMake2D(0, 0, width, height)
|
||||
texture.getBytes(&bytes, bytesPerRow: bytesPerRow, from: region, mipmapLevel: 0)
|
||||
|
||||
// Swizzle bytes from BGRA to RGBA
|
||||
for i in stride(from: 0, to: byteCount, by: 4) {
|
||||
let blue = bytes[i]
|
||||
let green = bytes[i + 1]
|
||||
let red = bytes[i + 2]
|
||||
let alpha = bytes[i + 3]
|
||||
|
||||
bytes[i] = red
|
||||
bytes[i + 1] = green
|
||||
bytes[i + 2] = blue
|
||||
bytes[i + 3] = alpha
|
||||
}
|
||||
|
||||
// Convert Swift Data to Objective-C NSData
|
||||
let nsData = Data(bytes: &bytes, count: byteCount) as NSData
|
||||
return nsData
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user