Texture Map 是一个 Swift 6 包,用于处理图像和纹理。可以在各种格式之间转换图像或原始数据。专为 iOS、macOS 和 visionOS 打造。由 Metal 提供支持。
NSImage
和 UIImage
。8 bit
、16 bit
和 32 bit
的图形。UIImage
/NSImage
、CGImage
、CIImage
、CVPixelBuffer
、CMSampleBuffer
和 MTLTexture
之间进行转换。TIFF
、PNG
和 JPG
数据。UInt8
、Float16
或 Float32
。通过将其作为 Swift 包集成,将 Texture Map 添加到您的项目中。使用仓库 URL
dependencies: [
.package(url: "https://github.com/heestand-xyz/TextureMap", from: "2.0.0")
]
import TextureMap
let image: UIImage = UIImage(named: "Example")!
let texture: MTLTexture = try TextureMap.texture(image: image)
let rawChannels: [UInt8] = try TextureMap.raw8(texture: texture)
let outputImage: UIImage = try await texture.image(colorSpace: .sRGB, bits: ._8)
let originalTexture: MTLTexture = ... // Your Metal texture
do {
let copiedTexture: MTLTexture = try await originalTexture.copy()
print("Copied texture: \(copiedTexture)")
} catch {
print("Error copying texture: \(error)")
}
let rawTexture: MTLTexture = ...
let bits: TMBits = ._8
do {
let normalizedRawData: [CGFloat] = try await TextureMap.rawNormalized(texture: rawTexture, bits: bits)
print("Normalized raw data: \(normalizedRawData)")
} catch {
print("Error extracting raw data: \(error)")
}
let inputTexture: MTLTexture = ...
let fromColorSpace: CGColorSpace = CGColorSpace(name: CGColorSpace.sRGB)!
let toColorSpace: CGColorSpace = CGColorSpace(name: CGColorSpace.displayP3)!
do {
let convertedTexture: MTLTexture = try await inputTexture.convertColorSpace(from: fromColorSpace, to: toColorSpace)
print("Converted texture: \(convertedTexture)")
} catch {
print("Error converting texture color space: \(error)")
}
sRGB
: 标准 RGB 空间。Display P3
: 用于 HDR 内容的扩展色域。XDR
: 用于在 XDR 兼容显示器上显示的高位深图形。欢迎通过提交 pull request 或报告问题来做出贡献。
该库在 MIT 许可证下可用。
由 Anton Heestand 开发