@@ 167,18 167,57 @@ const (
cr = kdf.ChannelYUVSDA_V
)
-var packedYUVAFormats = map[Format][]kdf.Channel{
+var (
+ texelBlockDim444 = [4]int{1, 1, 1, 1} // non-subsampled
+ texelBlockDim422 = [4]int{2, 1, 1, 1} // 2x1 subsampled
+ texelBlockDim420 = [4]int{2, 2, 1, 1} // 2x2 subsampled
+)
+
+var packedYUVAFormats = map[Format]struct {
+ channels []kdf.Channel
+ texelBlockDim [4]int
+}{
// 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
+ FormatYUYV: {
+ channels: []kdf.Channel{cr, y, cb, y},
+ texelBlockDim: texelBlockDim422,
+ },
+ FormatYVYU: {
+ channels: []kdf.Channel{cb, y, cr, y},
+ texelBlockDim: texelBlockDim422,
+ },
+ FormatUYVY: {
+ channels: []kdf.Channel{y, cr, y, cb},
+ texelBlockDim: texelBlockDim422,
+ },
+ FormatVYUY: {
+ channels: []kdf.Channel{y, cb, y, cr},
+ texelBlockDim: texelBlockDim422,
+ },
+ FormatAYUV: {
+ channels: []kdf.Channel{kdf.ChannelYUVSDA_A, y, cb, cr},
+ texelBlockDim: texelBlockDim444,
+ },
+ FormatAVUY8888: {
+ channels: []kdf.Channel{kdf.ChannelYUVSDA_A, cr, cb, y},
+ texelBlockDim: texelBlockDim444,
+ },
+ FormatXYUV8888: {
+ channels: []kdf.Channel{unusedChannel, y, cb, cr},
+ texelBlockDim: texelBlockDim444,
+ },
+ FormatXVUY8888: {
+ channels: []kdf.Channel{unusedChannel, cr, cb, y},
+ texelBlockDim: texelBlockDim444,
+ },
+ FormatVUY888: {
+ channels: []kdf.Channel{cr, cb, y},
+ texelBlockDim: texelBlockDim444,
+ },
// TODO: VUY101010 has a single Y channel and is 10-bit
- // TODO: more formats
}
-func genYUVAPacked(channels []kdf.Channel, bitsPerChannel []int) *kdf.Block {
+func genYUVAPacked(texelBlockDim [4]int, channels []kdf.Channel, bitsPerChannel []int) *kdf.Block {
sampleInfo := genPackedSamples(channels, bitsPerChannel)
numY := 0
for i := len(sampleInfo) - 1; i >= 0; i-- {
@@ 192,7 231,7 @@ func genYUVAPacked(channels []kdf.Channel, bitsPerChannel []int) *kdf.Block {
return kdf.NewBlockBasic(&kdf.BlockBasic{
ColorModel: kdf.ColorModelYUVSDA,
- TexelBlockDimension: [4]int{2, 1, 1, 1},
+ TexelBlockDimension: texelBlockDim,
BytesPlane: []uint8{getBytesPerPixel(bitsPerChannel)},
SampleInfo: sampleInfo,
})
@@ 230,12 269,15 @@ func genTable() {
blockTable[fmt] = genRGBATwoPlane(fmt)
}
- for fmt, revChannels := range packedYUVAFormats {
- channels := make([]kdf.Channel, len(revChannels))
- copy(channels, revChannels)
+ for fmt, def := range packedYUVAFormats {
+ channels := make([]kdf.Channel, len(def.channels))
+ copy(channels, def.channels)
reverseChannels(channels)
- bitsPerChannel := []int{8, 8, 8, 8}
- blockTable[fmt] = genYUVAPacked(channels, bitsPerChannel)
+ bitsPerChannel := make([]int, len(def.channels))
+ for i := range bitsPerChannel {
+ bitsPerChannel[i] = 8
+ }
+ blockTable[fmt] = genYUVAPacked(def.texelBlockDim, channels, bitsPerChannel)
}
}