~emersion/go-kdf

5e3a93a27d649e80735e43477f01ef479d076aa5 — Simon Ser 1 year, 4 months ago 95f5b9f
cmd: decode sample position
1 files changed, 14 insertions(+), 4 deletions(-)

M cmd/go-kdf/main.go
M cmd/go-kdf/main.go => cmd/go-kdf/main.go +14 -4
@@ 152,12 152,12 @@ func printBlock(block *kdf.Block) {
		fmt.Printf("Bytes plane: %v\n", basic.BytesPlane)
		for i, info := range basic.SampleInfo {
			fmt.Printf("Sample %v:\n", i)
			printSampleInfo(&info, basic.ColorModel)
			printSampleInfo(&info, basic)
		}
	}
}

func printSampleInfo(info *kdf.SampleInfo, cm kdf.ColorModel) {
func printSampleInfo(info *kdf.SampleInfo, basic *kdf.BlockBasic) {
	var dataType []string
	if info.Float {
		dataType = append(dataType, "float")


@@ 175,11 175,21 @@ func printSampleInfo(info *kdf.SampleInfo, cm kdf.ColorModel) {
		dataType = append(dataType, "none")
	}

	var coords []string
	for i, raw := range info.SamplePosition {
		n := math.Log2(float64(basic.TexelBlockDimension[i]))
		coord := float64(raw) * math.Pow(2, n-8)
		coords = append(coords, fmt.Sprintf("%v", coord))
	}

	fmt.Printf("  Data type qualifiers: %v\n", strings.Join(dataType, ", "))
	fmt.Printf("  Bit length: %v\n", info.BitLength)
	// TODO: handle special value 0xFFFF for bit offset
	// TODO: handle bit offsets indicating paletted formats
	fmt.Printf("  Bit offset: %v\n", info.BitOffset)
	fmt.Printf("  Channel: %v\n", info.Channel.Name(cm))
	fmt.Printf("  Sample position: %v\n", info.SamplePosition)
	fmt.Printf("  Channel: %v\n", info.Channel.Name(basic.ColorModel))
	fmt.Printf("  Sample position: %v\n", strings.Join(coords, ", "))
	// TODO: decode signed and exponent bounds
	if info.Float {
		lower := math.Float32frombits(info.SampleLower)
		upper := math.Float32frombits(info.SampleUpper)