Texture Map is a Swift 6 package for working with images and textures. Covert images or raw data between various formats. Made for iOS, macOS, and visionOS. Powered by Metal.
- Cross-Platform Support:
- Provides seamless support for macOS and iOS, utilizing
NSImage
andUIImage
interchangeably.
- Provides seamless support for macOS and iOS, utilizing
- High Color Bit Support
- Work with
8 bit
,16 bit
and32 bit
graphics.
- Work with
- Image Formats:
- Converts between
UIImage
/NSImage
,CGImage
,CIImage
,CVPixelBuffer
,CMSampleBuffer
andMTLTexture
. - Cross-platofrm support for getting
TIFF
,PNG
andJPG
data.
- Converts between
- Metal Texture Utilities:
- Create empty textures with specified pixel formats and dimensions.
- Support for 2D, 3D, and array textures.
- Texture copying and sampling.
- Raw Data Operations:
- Extract normalized or raw texture data as
UInt8
,Float16
, orFloat32
. - Create textures from raw data arrays.
- Extract normalized or raw texture data as
Add Texture Map to your project by integrating it as a Swift package. Use the repository URL:
dependencies: [
.package(url: "https://github.com/heestand-xyz/TextureMap", from: "2.0.0")
]
- Platforms:
- iOS 16.0+
- macOS 13.0+
- visionOS 1.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
: Standard RGB space.Display P3
: Extended gamut for HDR content.XDR
: For high bit graphics displayed on XDR compatible displays.
Feel free to contribute by submitting pull requests or reporting issues.
This library is available under the MIT License.
Developed by Anton Heestand