- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我有一个由 CVPixelbuffer (ARGB) 构建的 CGImage。我想将该 CGImage 转换为 MTLTexture。我使用:
let texture: MTLTexture = try m_textureLoader.newTexture(with: cgImage, options: [MTKTextureLoaderOptionSRGB : NSNumber(value: true)] )
稍后我想在具有 3 个 channel 的 MPSImage 中使用纹理:
let sid = MPSImageDescriptor(channelFormat: MPSImageFeatureChannelFormat.float16, width: 40, height: 40, featureChannels: 3)
preImage = MPSTemporaryImage(commandBuffer: commandBuffer, imageDescriptor: sid)
lanczos.encode(commandBuffer: commandBuffer, sourceTexture: texture!, destinationTexture: preImage.texture)
scale.encode (commandBuffer: commandBuffer, sourceImage: preImage, destinationImage: srcImage)
现在我的问题:textureLoader.newTexture(...) 如何将四个 ARGB channel 映射到 MPSImageDescriptor 中指定的 3 个 channel ?我怎样才能确保使用 RGB 组件而不是例如阿格?有没有办法指定 channel 映射?
谢谢,克里斯
最佳答案
为什么不直接从 CVPixelBuffer 构造 MTLTexture 呢?快多了!
在程序开始时执行一次:
// declare this somewhere, so we can re-use it
var textureCache: CVMetalTextureCache?
// create the texture cache object
guard CVMetalTextureCacheCreate(kCFAllocatorDefault, nil, device, nil, &textureCache) == kCVReturnSuccess else {
print("Error: could not create a texture cache")
return false
}
一旦你有你的 CVPixelBuffer 就这样做:
let width = CVPixelBufferGetWidth(pixelBuffer)
let height = CVPixelBufferGetHeight(pixelBuffer)
var texture: CVMetalTexture?
CVMetalTextureCacheCreateTextureFromImage(kCFAllocatorDefault, textureCache,
pixelBuffer, nil, .bgra8Unorm, width, height, 0, &texture)
if let texture = texture {
metalTexture = CVMetalTextureGetTexture(texture)
}
现在 metalTexture
包含一个包含 CVPixelBuffer 内容的 MTLTexture 对象。
关于swift - CGImage 到 MPSTexture 或 MPSImage,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44906923/
我正在尝试在 MPSNNGraph 上输入两个图像。 但是,即使我在“withSourceImages”上输入像[input1, input2]这样的数组,我也只能输入“input1”作为输入图像。理
我在处理 MPSImage 的底层内存时遇到问题。我一直在 MPSImage 的 texture 成员变量上使用方法 getBytes 和 replace 来读取和写入底层数据。问题是我找不到有关如何
我有一个由 CVPixelbuffer (ARGB) 构建的 CGImage。我想将该 CGImage 转换为 MTLTexture。我使用: let texture: MTLTexture =
我正在尝试手动填充 MPSImage 或 2D Metal 纹理,并将其传递给进行卷积网络操作。 CNN( Metal 性能着色器)的输入通常是图像(像这样 https://developer.app
我是一名优秀的程序员,十分优秀!