~emersion/go-kdf

f8c5b8314ef943bb4afa8b493e820748228b4289 — Simon Ser 1 year, 1 month ago b172c65
vulkan: add non-subsampled multi-planar formats

References: https://todo.sr.ht/~emersion/pixfmtdb/6
1 files changed, 37 insertions(+), 0 deletions(-)

M vulkan/vulkan.go
M vulkan/vulkan.go => vulkan/vulkan.go +37 -0
@@ 251,6 251,13 @@ var unpackedYUVAFormats = []Format{
	FormatB16G16R16G16_422_UNORM,
}

var multiPlanarFormats = []Format{
	FormatG8_B8_R8_3PLANE_444_UNORM,
	FormatG16_B16_R16_3PLANE_444_UNORM,
	FormatG8_B8R8_2PLANE_444_UNORM,
	FormatG16_B16R16_2PLANE_444_UNORM,
}

func parseFormatBase(s string) (channels []kdf.Channel, bitsPerChannel []int) {
	for s != "" {
		ch, ok := channelMap[s[0:1]]


@@ 298,6 305,21 @@ func parseUnpackedBase(s string) (bytesPerChannel int, channels []kdf.Channel) {
	return bytesPerChannel, channels
}

func mergeMultiPlanar(planes []*kdf.Block) *kdf.Block {
	block := planes[0].Copy()
	basic := block.Basic
	bitOffset := 8 * uint16(basic.BytesPlane[0])
	for _, plane := range planes[1:] {
		basic.BytesPlane = append(basic.BytesPlane, plane.Basic.BytesPlane...)
		for _, sampleInfo := range plane.Basic.SampleInfo {
			sampleInfo.BitOffset += bitOffset
			basic.SampleInfo = append(basic.SampleInfo, sampleInfo)
		}
		bitOffset += 8 * uint16(plane.Basic.BytesPlane[0])
	}
	return block
}

type blockTable struct {
	once sync.Once
	m    map[Format]*kdf.Block


@@ 353,6 375,21 @@ func genTable(endianness kdf.Endianness) map[Format]*kdf.Block {
		blockTable[format] = genYUVAUnpacked(bytesPerChannel, channels, numericFormatUnorm, endianness)
	}

	for _, format := range multiPlanarFormats {
		base := strings.TrimRight(format.String(), "_444_UNORM")
		base = strings.TrimRight(base, "_2PLANE")
		base = strings.TrimRight(base, "_3PLANE")

		var planes []*kdf.Block
		for _, planeBase := range strings.Split(base, "_") {
			bytesPerChannel, channels := parseUnpackedBase(planeBase)
			plane := genRGBAUnpacked(bytesPerChannel, channels, numericFormatUnorm, endianness)
			planes = append(planes, plane)
		}

		blockTable[format] = mergeMultiPlanar(planes)
	}

	return blockTable
}