在设备 (iOS) 上编码 ASTC?

Ger*_*eri 0 textures ios metal astc

是否有任何库能够按需将图像数据编码为 ASTC 纹理?我知道它是 CPU 密集型的,但无论如何都很感兴趣。

use*_*730 8

import ImageIO
import MetalKit

let loader: MTKTextureLoader
let srcImage: CGImage
let ktxData = NSMutableData()
let dest = CGImageDestinationCreateWithData(ktxData, "org.khronos.ktx" as CFString, 1, nil)!
CGImageDestinationAddImage(dest, srcImage, 0, ["kCGImagePropertyASTCBlockSize": 0x88] as CFDictionary)
CGImageDestinationFinalize(dest)
try loader.newTexture(data: ktxData as Data, options: [])
Run Code Online (Sandbox Code Playgroud)

显示的kCGImagePropertyASTCBlockSize选项为您提供 8x8 块大小(即每像素 2 位);唯一允许的其他大小是 4x4(每像素 8 位),这是默认值。

为了获得最佳性能,请添加kCGImageDestinationLossyCompressionQuality: 0.0CGImageDestinationAddImageFromSource.

其他可能的标志是kCGImagePropertyASTCUseLZFSE, kCGImagePropertyASTCPreTwiddle, kCGImagePropertyASTCFlipVerticallyand kCGImagePropertyASTCWeightChannelsEqually(all bools)。