~emersion/go-kdf

78eae9ebc38752b0b302f145fa57853127675e33 — Simon Ser 1 year, 25 days ago 96b6455
drm: use explicit channels for packed YUV formats
1 files changed, 17 insertions(+), 35 deletions(-)

M drm/drm.go
M drm/drm.go => drm/drm.go +17 -35
@@ 161,44 161,23 @@ func genRGBATwoPlane(fmt Format) *kdf.Block {
	return block
}

var packedYUVAFormats = []Format{
	FormatYUYV,
	FormatYVYU,
	FormatUYVY,
	FormatVYUY,
const (
	y  = kdf.ChannelYUVSDA_Y
	cb = kdf.ChannelYUVSDA_U
	cr = kdf.ChannelYUVSDA_V
)

var packedYUVAFormats = map[Format][]kdf.Channel{
	// The following 4 formats have a reversed component order!
	FormatYUYV: {cr, y, cb, y},
	FormatYVYU: {cb, y, cr, y},
	FormatUYVY: {y, cr, y, cb},
	FormatVYUY: {y, cb, y, cr},
	// TODO: AYUV and XYUV8888 have a single Y channel
	// TODO: VUY101010 has a single Y channel and is 10-bit
	// TODO: more formats
}

func parseYUVAPackedFormat(s string) (channels []kdf.Channel, bitsPerChannel []int) {
	yuvaChannelMap := map[rune]kdf.Channel{
		'Y': kdf.ChannelYUVSDA_Y,
		'U': kdf.ChannelYUVSDA_U,
		'V': kdf.ChannelYUVSDA_V,
		'A': kdf.ChannelYUVSDA_A,
		'X': unusedChannel,
	}

	if len(s) != 4 {
		return nil, nil
	}

	for _, c := range s {
		ch, ok := yuvaChannelMap[c]
		if !ok {
			return nil, nil
		}
		channels = append(channels, ch)
	}

	// Note: DRM packed YCbCr formats have a reversed component order!

	bitsPerChannel = []int{8, 8, 8, 8}

	return channels, bitsPerChannel
}

func genYUVAPacked(channels []kdf.Channel, bitsPerChannel []int) *kdf.Block {
	sampleInfo := genPackedSamples(channels, bitsPerChannel)
	numY := 0


@@ 251,8 230,11 @@ func genTable() {
		blockTable[fmt] = genRGBATwoPlane(fmt)
	}

	for _, fmt := range packedYUVAFormats {
		channels, bitsPerChannel := parseYUVAPackedFormat(fmt.String())
	for fmt, revChannels := range packedYUVAFormats {
		channels := make([]kdf.Channel, len(revChannels))
		copy(channels, revChannels)
		reverseChannels(channels)
		bitsPerChannel := []int{8, 8, 8, 8}
		blockTable[fmt] = genYUVAPacked(channels, bitsPerChannel)
	}
}