...
1 package exifundefined
2
3 import (
4 "bytes"
5 "fmt"
6
7 "encoding/binary"
8
9 "github.com/dsoprea/go-logging"
10
11 "github.com/dsoprea/go-exif/v3/common"
12 )
13
14 const (
15 TagUndefinedType_9101_ComponentsConfiguration_Channel_Y = 0x1
16 TagUndefinedType_9101_ComponentsConfiguration_Channel_Cb = 0x2
17 TagUndefinedType_9101_ComponentsConfiguration_Channel_Cr = 0x3
18 TagUndefinedType_9101_ComponentsConfiguration_Channel_R = 0x4
19 TagUndefinedType_9101_ComponentsConfiguration_Channel_G = 0x5
20 TagUndefinedType_9101_ComponentsConfiguration_Channel_B = 0x6
21 )
22
23 const (
24 TagUndefinedType_9101_ComponentsConfiguration_OTHER = iota
25 TagUndefinedType_9101_ComponentsConfiguration_RGB = iota
26 TagUndefinedType_9101_ComponentsConfiguration_YCBCR = iota
27 )
28
29 var (
30 TagUndefinedType_9101_ComponentsConfiguration_Names = map[int]string{
31 TagUndefinedType_9101_ComponentsConfiguration_OTHER: "OTHER",
32 TagUndefinedType_9101_ComponentsConfiguration_RGB: "RGB",
33 TagUndefinedType_9101_ComponentsConfiguration_YCBCR: "YCBCR",
34 }
35
36 TagUndefinedType_9101_ComponentsConfiguration_Configurations = map[int][]byte{
37 TagUndefinedType_9101_ComponentsConfiguration_RGB: {
38 TagUndefinedType_9101_ComponentsConfiguration_Channel_R,
39 TagUndefinedType_9101_ComponentsConfiguration_Channel_G,
40 TagUndefinedType_9101_ComponentsConfiguration_Channel_B,
41 0,
42 },
43
44 TagUndefinedType_9101_ComponentsConfiguration_YCBCR: {
45 TagUndefinedType_9101_ComponentsConfiguration_Channel_Y,
46 TagUndefinedType_9101_ComponentsConfiguration_Channel_Cb,
47 TagUndefinedType_9101_ComponentsConfiguration_Channel_Cr,
48 0,
49 },
50 }
51 )
52
53 type TagExif9101ComponentsConfiguration struct {
54 ConfigurationId int
55 ConfigurationBytes []byte
56 }
57
58 func (TagExif9101ComponentsConfiguration) EncoderName() string {
59 return "CodecExif9101ComponentsConfiguration"
60 }
61
62 func (cc TagExif9101ComponentsConfiguration) String() string {
63 return fmt.Sprintf("Exif9101ComponentsConfiguration<ID=[%s] BYTES=%v>", TagUndefinedType_9101_ComponentsConfiguration_Names[cc.ConfigurationId], cc.ConfigurationBytes)
64 }
65
66 type CodecExif9101ComponentsConfiguration struct {
67 }
68
69 func (CodecExif9101ComponentsConfiguration) Encode(value interface{}, byteOrder binary.ByteOrder) (encoded []byte, unitCount uint32, err error) {
70 defer func() {
71 if state := recover(); state != nil {
72 err = log.Wrap(state.(error))
73 }
74 }()
75
76 cc, ok := value.(TagExif9101ComponentsConfiguration)
77 if ok == false {
78 log.Panicf("can only encode a TagExif9101ComponentsConfiguration")
79 }
80
81 return cc.ConfigurationBytes, uint32(len(cc.ConfigurationBytes)), nil
82 }
83
84 func (CodecExif9101ComponentsConfiguration) Decode(valueContext *exifcommon.ValueContext) (value EncodeableValue, err error) {
85 defer func() {
86 if state := recover(); state != nil {
87 err = log.Wrap(state.(error))
88 }
89 }()
90
91 valueContext.SetUndefinedValueType(exifcommon.TypeByte)
92
93 valueBytes, err := valueContext.ReadBytes()
94 log.PanicIf(err)
95
96 for configurationId, configurationBytes := range TagUndefinedType_9101_ComponentsConfiguration_Configurations {
97 if bytes.Equal(configurationBytes, valueBytes) == true {
98 cc := TagExif9101ComponentsConfiguration{
99 ConfigurationId: configurationId,
100 ConfigurationBytes: valueBytes,
101 }
102
103 return cc, nil
104 }
105 }
106
107 cc := TagExif9101ComponentsConfiguration{
108 ConfigurationId: TagUndefinedType_9101_ComponentsConfiguration_OTHER,
109 ConfigurationBytes: valueBytes,
110 }
111
112 return cc, nil
113 }
114
115 func init() {
116 registerEncoder(
117 TagExif9101ComponentsConfiguration{},
118 CodecExif9101ComponentsConfiguration{})
119
120 registerDecoder(
121 exifcommon.IfdExifStandardIfdIdentity.UnindexedString(),
122 0x9101,
123 CodecExif9101ComponentsConfiguration{})
124 }
125
View as plain text