github.com/boki/go-xmp@v1.0.1/models/tiff/types.go (about)

     1  // Copyright (c) 2017-2018 Alexander Eichhorn
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License"): you may
     4  // not use this file except in compliance with the License. You may obtain
     5  // a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
    11  // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
    12  // License for the specific language governing permissions and limitations
    13  // under the License.
    14  
    15  package tiff
    16  
    17  import (
    18  	"trimmer.io/go-xmp/xmp"
    19  )
    20  
    21  type YCbCrSubSampling xmp.IntList
    22  
    23  // [2, 1] = YCbCr4:2:2 [2, 2] = YCbCr4:2:0
    24  func (x YCbCrSubSampling) String() string {
    25  	if len(x) < 2 {
    26  		return "undefined"
    27  	}
    28  	switch {
    29  	case x[0] == 1 && x[1] == 1:
    30  		return "4:4:4"
    31  	case x[0] == 1 && x[1] == 2:
    32  		return "4:4:0"
    33  	case x[0] == 1 && x[1] == 4:
    34  		return "4:4:1"
    35  	case x[0] == 2 && x[1] == 1:
    36  		return "4:2:2"
    37  	case x[0] == 2 && x[1] == 2:
    38  		return "4:2:0"
    39  	case x[0] == 2 && x[1] == 4:
    40  		return "4:2:1"
    41  	case x[0] == 4 && x[1] == 1:
    42  		return "4:1:1"
    43  	case x[0] == 4 && x[1] == 2:
    44  		return "4:1:0"
    45  	default:
    46  		return "undefined"
    47  	}
    48  }
    49  
    50  func (x YCbCrSubSampling) IsZero() bool {
    51  	return len(x) < 2 || (x[0] == 0 && x[1] == 0)
    52  }
    53  
    54  func (x YCbCrSubSampling) Typ() xmp.ArrayType {
    55  	return xmp.ArrayTypeOrdered
    56  }
    57  
    58  func (x YCbCrSubSampling) MarshalXMP(e *xmp.Encoder, node *xmp.Node, m xmp.Model) error {
    59  	return xmp.MarshalArray(e, node, x.Typ(), x)
    60  }
    61  
    62  func (x *YCbCrSubSampling) UnmarshalXMP(d *xmp.Decoder, node *xmp.Node, m xmp.Model) error {
    63  	return xmp.UnmarshalArray(d, node, x.Typ(), x)
    64  }