From 55702efe1f8994466b7ad81658a772527553ee07 Mon Sep 17 00:00:00 2001 From: Kubo Ryosuke Date: Sun, 8 Nov 2020 19:20:09 +0900 Subject: [PATCH] Fix colr for unknown colour type --- box_types.go | 29 +++++++++++++++++------------ box_types_test.go | 13 +++++++++++++ 2 files changed, 30 insertions(+), 12 deletions(-) diff --git a/box_types.go b/box_types.go index c78e182..7e2dab8 100644 --- a/box_types.go +++ b/box_types.go @@ -56,22 +56,27 @@ type Colr struct { FullRangeFlag bool `mp4:"size=1,opt=dynamic"` Reserved uint8 `mp4:"size=7,opt=dynamic"` Profile []byte `mp4:"size=8,opt=dynamic"` + Unknown []byte `mp4:"size=8,opt=dynamic"` } func (colr *Colr) IsOptFieldEnabled(name string) bool { - switch name { - case "ColourType", - "ColourPrimaries", - "TransferCharacteristics", - "MatrixCoefficients", - "FullRangeFlag", - "Reserved": - return colr.ColourType == [4]byte{'n', 'c', 'l', 'x'} - case "Profile": - return colr.ColourType == [4]byte{'r', 'I', 'C', 'C'} || - colr.ColourType == [4]byte{'p', 'r', 'o', 'f'} + switch colr.ColourType { + case [4]byte{'n', 'c', 'l', 'x'}: + switch name { + case "ColourType", + "ColourPrimaries", + "TransferCharacteristics", + "MatrixCoefficients", + "FullRangeFlag", + "Reserved": + return true + default: + return false + } + case [4]byte{'r', 'I', 'C', 'C'}, [4]byte{'p', 'r', 'o', 'f'}: + return name == "Profile" default: - return false + return name == "Unknown" } } diff --git a/box_types_test.go b/box_types_test.go index fdc2aa6..84fa8e1 100644 --- a/box_types_test.go +++ b/box_types_test.go @@ -75,6 +75,19 @@ func TestBoxTypes(t *testing.T) { }, str: `ColourType="rICC" Profile=[0x12, 0x34, 0x56, 0x78, 0xab]`, }, + { + name: "colr: nclc", + src: &Colr{ + ColourType: [4]byte{'n', 'c', 'l', 'c'}, + Unknown: []byte{0x01, 0x23, 0x45}, + }, + dst: &Colr{}, + bin: []byte{ + 'n', 'c', 'l', 'c', + 0x01, 0x23, 0x45, + }, + str: `ColourType="nclc" Unknown=[0x1, 0x23, 0x45]`, + }, { name: "ctts: version 0", src: &Ctts{