...
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 type TagA302CfaPattern struct {
15 HorizontalRepeat uint16
16 VerticalRepeat uint16
17 CfaValue []byte
18 }
19
20 func (TagA302CfaPattern) EncoderName() string {
21 return "CodecA302CfaPattern"
22 }
23
24 func (cp TagA302CfaPattern) String() string {
25 return fmt.Sprintf("TagA302CfaPattern<HORZ-REPEAT=(%d) VERT-REPEAT=(%d) CFA-VALUE=(%d)>", cp.HorizontalRepeat, cp.VerticalRepeat, len(cp.CfaValue))
26 }
27
28 type CodecA302CfaPattern struct {
29 }
30
31 func (CodecA302CfaPattern) Encode(value interface{}, byteOrder binary.ByteOrder) (encoded []byte, unitCount uint32, err error) {
32 defer func() {
33 if state := recover(); state != nil {
34 err = log.Wrap(state.(error))
35 }
36 }()
37
38
39
40 cp, ok := value.(TagA302CfaPattern)
41 if ok == false {
42 log.Panicf("can only encode a TagA302CfaPattern")
43 }
44
45 b := new(bytes.Buffer)
46
47 err = binary.Write(b, byteOrder, cp.HorizontalRepeat)
48 log.PanicIf(err)
49
50 err = binary.Write(b, byteOrder, cp.VerticalRepeat)
51 log.PanicIf(err)
52
53 _, err = b.Write(cp.CfaValue)
54 log.PanicIf(err)
55
56 encoded = b.Bytes()
57
58
59
60 return encoded, uint32(len(encoded)), nil
61 }
62
63 func (CodecA302CfaPattern) Decode(valueContext *exifcommon.ValueContext) (value EncodeableValue, err error) {
64 defer func() {
65 if state := recover(); state != nil {
66 err = log.Wrap(state.(error))
67 }
68 }()
69
70
71
72 valueContext.SetUndefinedValueType(exifcommon.TypeByte)
73
74 valueBytes, err := valueContext.ReadBytes()
75 log.PanicIf(err)
76
77 cp := TagA302CfaPattern{}
78
79 cp.HorizontalRepeat = valueContext.ByteOrder().Uint16(valueBytes[0:2])
80 cp.VerticalRepeat = valueContext.ByteOrder().Uint16(valueBytes[2:4])
81
82 expectedLength := int(cp.HorizontalRepeat * cp.VerticalRepeat)
83 cp.CfaValue = valueBytes[4 : 4+expectedLength]
84
85 return cp, nil
86 }
87
88 func init() {
89 registerEncoder(
90 TagA302CfaPattern{},
91 CodecA302CfaPattern{})
92
93 registerDecoder(
94 exifcommon.IfdExifStandardIfdIdentity.UnindexedString(),
95 0xa302,
96 CodecA302CfaPattern{})
97 }
98
View as plain text