forked from frolovo22/tag
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflac.go
850 lines (714 loc) · 17.8 KB
/
flac.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
package tag
import (
"bytes"
"encoding/binary"
"image"
"image/jpeg"
"image/png"
"io"
"io/ioutil"
"os"
"strconv"
"strings"
"time"
"github.com/go-flac/flacpicture"
)
type FLAC struct {
Blocks []*FlacMetadataBlock
// Vorbis Comment
Vendor string
Tags map[string]string
dataStartPos int64
dataSource io.ReadSeekCloser
}
func (flac *FLAC) GetAllTagNames() []string {
result := make([]string, 0, len(flac.Tags))
for key := range flac.Tags {
result = append(result, key)
}
return result
}
func (flac *FLAC) GetVersion() Version {
return VersionFLAC
}
func (flac *FLAC) GetFileData() []byte {
_, _ = flac.dataSource.Seek(flac.dataStartPos, io.SeekStart)
data, _ := io.ReadAll(flac.dataSource)
return data
}
func (flac *FLAC) GetTitle() (string, error) {
return flac.GetVorbisComment("TITLE")
}
func (flac *FLAC) GetArtist() (string, error) {
return flac.GetVorbisComment("ARTIST")
}
func (flac *FLAC) GetAlbum() (string, error) {
return flac.GetVorbisComment("ALBUM")
}
func (flac *FLAC) GetYear() (int, error) {
return flac.GetVorbisCommentInt("YEAR")
}
func (flac *FLAC) GetComment() (string, error) {
return flac.GetVorbisComment("COMMENT")
}
func (flac *FLAC) GetGenre() (string, error) {
return flac.GetVorbisComment("GENRE")
}
func (flac *FLAC) GetAlbumArtist() (string, error) {
return flac.GetVorbisComment("ALBUMARTIST")
}
func (flac *FLAC) GetDate() (time.Time, error) {
return flac.GetVorbisCommentTime("DATE")
}
func (flac *FLAC) GetArranger() (string, error) {
return flac.GetVorbisComment("ARRANGER")
}
func (flac *FLAC) GetAuthor() (string, error) {
return flac.GetVorbisComment("AUTHOR")
}
func (flac *FLAC) GetBPM() (int, error) {
return flac.GetVorbisCommentInt("BPM")
}
func (flac *FLAC) GetCatalogNumber() (string, error) {
return flac.GetVorbisComment("CATALOGNUMBER")
}
func (flac *FLAC) GetCompilation() (string, error) {
return flac.GetVorbisComment("COMPILATION")
}
func (flac *FLAC) GetComposer() (string, error) {
return flac.GetVorbisComment("COMPOSER")
}
func (flac *FLAC) GetConductor() (string, error) {
return flac.GetVorbisComment("CONDUCTOR")
}
func (flac *FLAC) GetCopyright() (string, error) {
return flac.GetVorbisComment("COPYRIGHT")
}
func (flac *FLAC) GetDescription() (string, error) {
return flac.GetVorbisComment("DESCRIPTION")
}
func (flac *FLAC) GetDiscNumber() (int, int, error) {
number, err := flac.GetVorbisCommentInt("DISCNUMBER")
if err != nil {
return 0, 0, err
}
total, err := flac.GetVorbisCommentInt("DISCTOTAL")
if err != nil {
return 0, 0, err
}
return number, total, nil
}
func (flac *FLAC) GetEncodedBy() (string, error) {
return flac.GetVorbisComment("ENCODED-BY")
}
func (flac *FLAC) GetTrackNumber() (int, int, error) {
number, err := flac.GetVorbisCommentInt("TRACKNUMBER")
if err != nil {
return 0, 0, err
}
total, err := flac.GetVorbisCommentInt("TRACKTOTAL")
if err != nil {
return 0, 0, err
}
return number, total, nil
}
func (flac *FLAC) GetPicture() (image.Image, error) {
pictureBlock, err := flac.GetMetadataBlockPicture()
if err != nil {
return nil, err
}
switch pictureBlock.MIME {
case mimeImageJPEG:
return jpeg.Decode(bytes.NewReader(pictureBlock.PictureData))
case mimeImagePNG:
return png.Decode(bytes.NewReader(pictureBlock.PictureData))
case mimeImageLink:
return downloadImage(string(pictureBlock.PictureData))
}
return nil, ErrIncorrectTag
}
func (flac *FLAC) SetTitle(title string) error {
flac.Tags["TITLE"] = title
return nil
}
func (flac *FLAC) SetArtist(artist string) error {
flac.Tags["ARTIST"] = artist
return nil
}
func (flac *FLAC) SetAlbum(album string) error {
flac.Tags["ALBUM"] = album
return nil
}
func (flac *FLAC) SetYear(year int) error {
flac.Tags["YEAR"] = strconv.Itoa(year)
return nil
}
func (flac *FLAC) SetComment(comment string) error {
flac.Tags["COMMENT"] = comment
return nil
}
func (flac *FLAC) SetGenre(genre string) error {
flac.Tags["GENRE"] = genre
return nil
}
func (flac *FLAC) SetAlbumArtist(albumArtist string) error {
flac.Tags["ALBUMARTIST"] = albumArtist
return nil
}
func (flac *FLAC) SetDate(date time.Time) error {
flac.Tags["DATE"] = date.Format("2006-01-02T15:04:05")
return nil
}
func (flac *FLAC) SetArranger(arranger string) error {
flac.Tags["ARRANGER"] = arranger
return nil
}
func (flac *FLAC) SetAuthor(author string) error {
flac.Tags["AUTHOR"] = author
return nil
}
func (flac *FLAC) SetBPM(bmp int) error {
flac.Tags["BMP"] = strconv.Itoa(bmp)
return nil
}
func (flac *FLAC) SetCatalogNumber(catalogNumber string) error {
flac.Tags["CATALOGNUMBER"] = catalogNumber
return nil
}
func (flac *FLAC) SetCompilation(compilation string) error {
flac.Tags["COMPILATION"] = compilation
return nil
}
func (flac *FLAC) SetComposer(composer string) error {
flac.Tags["COMPOSER"] = composer
return nil
}
func (flac *FLAC) SetConductor(conductor string) error {
flac.Tags["CONDUCTOR"] = conductor
return nil
}
func (flac *FLAC) SetCopyright(copyright string) error {
flac.Tags["COPYRIGHT"] = copyright
return nil
}
func (flac *FLAC) SetDescription(description string) error {
flac.Tags["DESCRIPTION"] = description
return nil
}
func (flac *FLAC) SetDiscNumber(number int, total int) error {
flac.Tags["DISCNUMBER"] = strconv.Itoa(number)
flac.Tags["DISCTOTAL"] = strconv.Itoa(total)
return nil
}
func (flac *FLAC) SetEncodedBy(encodedBy string) error {
flac.Tags["ENCODED-BY"] = encodedBy
return nil
}
func (flac *FLAC) SetTrackNumber(number int, total int) error {
flac.Tags["TRACKNUMBER"] = strconv.Itoa(number)
flac.Tags["TRACKTOTAL"] = strconv.Itoa(total)
return nil
}
func (flac *FLAC) SetPicture(picture image.Image) error {
// TODO
// bitsPerPixel := colorModelToBitsPerPixel(picture.ColorModel())
// pictureBlock := FlacMetadataBlockPicture{
// Type: 3, // Other type
// MIME: "image/png",
// Description: "",
// Width: int32(picture.Bounds().Size().X),
// Height: int32(picture.Bounds().Size().Y),
// BitsPerPixel: int32(bitsPerPixel),
// NumberOfColors: 0,
// PictureData: nil,
//}
var size int
var data []byte
for _, val := range flac.Blocks {
if val.Type == FlacPicture {
val.Size = size
val.Data = data
}
}
return nil
}
func (flac *FLAC) SetFlacPicture(pic *flacpicture.MetadataBlockPicture) error {
metadata := pic.Marshal()
var matched bool
for _, val := range flac.Blocks {
if val.Type == FlacPicture {
val.Size = len(metadata.Data)
val.Data = metadata.Data
matched = true
}
}
if !matched {
flac.Blocks = append(flac.Blocks, &FlacMetadataBlock{
Type: FlacPicture,
Size: len(metadata.Data),
Data: metadata.Data,
})
}
return nil
}
func (flac *FLAC) DeleteAll() error {
flac.Tags = map[string]string{}
return nil
}
func (flac *FLAC) DeleteTitle() error {
delete(flac.Tags, "TITLE")
return nil
}
func (flac *FLAC) DeleteArtist() error {
delete(flac.Tags, "ARTIST")
return nil
}
func (flac *FLAC) DeleteAlbum() error {
delete(flac.Tags, "ALBUM")
return nil
}
func (flac *FLAC) DeleteYear() error {
delete(flac.Tags, "YEAR")
return nil
}
func (flac *FLAC) DeleteComment() error {
delete(flac.Tags, "COMMENT")
return nil
}
func (flac *FLAC) DeleteGenre() error {
delete(flac.Tags, "GENRE")
return nil
}
func (flac *FLAC) DeleteAlbumArtist() error {
delete(flac.Tags, "ALBUMARTIST")
return nil
}
func (flac *FLAC) DeleteDate() error {
delete(flac.Tags, "DATE")
return nil
}
func (flac *FLAC) DeleteArranger() error {
delete(flac.Tags, "ARRANGER")
return nil
}
func (flac *FLAC) DeleteAuthor() error {
delete(flac.Tags, "AUTHOR")
return nil
}
func (flac *FLAC) DeleteBPM() error {
delete(flac.Tags, "BPM")
return nil
}
func (flac *FLAC) DeleteCatalogNumber() error {
delete(flac.Tags, "CATALOGNUMBER")
return nil
}
func (flac *FLAC) DeleteCompilation() error {
delete(flac.Tags, "COMPILATION")
return nil
}
func (flac *FLAC) DeleteComposer() error {
delete(flac.Tags, "COMPOSER")
return nil
}
func (flac *FLAC) DeleteConductor() error {
delete(flac.Tags, "CONDUCTOR")
return nil
}
func (flac *FLAC) DeleteCopyright() error {
delete(flac.Tags, "COPYRIGHT")
return nil
}
func (flac *FLAC) DeleteDescription() error {
delete(flac.Tags, "DESCRIPTION")
return nil
}
func (flac *FLAC) DeleteDiscNumber() error {
delete(flac.Tags, "DISCNUMBER")
delete(flac.Tags, "DISCTOTAL")
return nil
}
func (flac *FLAC) DeleteEncodedBy() error {
delete(flac.Tags, "ENCODED-BY")
return nil
}
func (flac *FLAC) DeleteTrackNumber() error {
delete(flac.Tags, "TRACKNUMBER")
delete(flac.Tags, "TRACKTOTAL")
return nil
}
func (flac *FLAC) DeletePicture() error {
index := -1
for i, val := range flac.Blocks {
if val.Type == FlacPicture {
index = i
}
}
if index != -1 {
flac.Blocks = append(flac.Blocks[:index], flac.Blocks[index+1:]...)
}
return nil
}
func (flac *FLAC) SaveFile(path string) error {
file, err := os.Create(path)
if err != nil {
return err
}
defer file.Close()
return flac.Save(file)
}
func (flac *FLAC) Save(input io.WriteSeeker) error {
// Sync metadata to its parent block
// Write out file header
// Then all metablocks
// Then all audio blocks
// Update comments
if _, err := input.Write([]byte(FLACIdentifier)); err != nil {
return err
}
metadataWritten := false
for i, meta := range flac.Blocks {
if meta.Type == FlacVorbisComment {
flac.Blocks[i].Data = serializeVorbisComments(flac.Tags, flac.Vendor)
flac.Blocks[i].Size = len(flac.Blocks[i].Data)
metadataWritten = true
break
}
//
}
if !metadataWritten {
// Append a metadata block to the list
data := serializeVorbisComments(flac.Tags, flac.Vendor)
block := &FlacMetadataBlock{
IsLast: false,
Type: FlacVorbisComment,
Size: len(data),
Data: data,
}
flac.Blocks = append(flac.Blocks, block)
}
for i, meta := range flac.Blocks {
last := i == len(flac.Blocks)-1
if err := meta.Write(input, last); err != nil {
return err
}
}
if _, err := flac.dataSource.Seek(flac.dataStartPos, io.SeekStart); err != nil {
return err
}
if _, err := io.Copy(input, flac.dataSource); err != nil {
return err
}
return nil
}
func (flac *FLAC) Close() error {
return flac.dataSource.Close()
}
func checkFLAC(input io.ReadSeeker) bool {
data, err := seekAndRead(input, 0, io.SeekStart, 4)
if err != nil {
return false
}
if string(data) != FLACIdentifier {
return false
}
return true
}
type FlacMetadataBlockType byte
/*
BLOCK_TYPE:
0 : STREAMINFO
1 : PADDING
2 : APPLICATION
3 : SEEKTABLE
4 : VORBIS_COMMENT
5 : CUESHEET
6 : PICTURE
7-126 : reserved
127 : invalid, to avoid confusion with a frame sync code
*/
const (
FlacStreamInfo FlacMetadataBlockType = 0
FlacPadding FlacMetadataBlockType = 1
FlacApplication FlacMetadataBlockType = 2
FlacSeekTable FlacMetadataBlockType = 3
FlacVorbisComment FlacMetadataBlockType = 4
FlacCueSheet FlacMetadataBlockType = 5
FlacPicture FlacMetadataBlockType = 6
)
type FlacMetadataBlock struct {
// IsLast - Last-metadata-block flag:
// '1' if this block is the last metadata block before the audio blocks,
// '0' otherwise.
IsLast bool
Type FlacMetadataBlockType
Size int
Data []byte
}
func ReadFLAC(input io.ReadSeekCloser) (*FLAC, error) {
flac := FLAC{
Tags: map[string]string{},
dataSource: input,
}
// FLAC identifier
data, err := seekAndRead(input, 0, io.SeekStart, 4)
if err != nil {
return nil, err
}
if string(data) != "fLaC" {
return nil, ErrFileMarker
}
// read blocks
for {
var block *FlacMetadataBlock
block, err = readMetadataBlock(input)
if err != nil {
return nil, err
}
if block.Type == FlacVorbisComment {
var comments []VorbisComment
var vendor string
comments, vendor, err = readVorbisComments(bytes.NewReader(block.Data))
if err != nil {
return nil, err
}
flac.Vendor = vendor
for i := range comments {
// case insensitive
field := strings.ToUpper(comments[i].Name)
flac.Tags[field] = comments[i].Value
}
} else {
flac.Blocks = append(flac.Blocks, block)
}
// last block before audio frame
if block.IsLast {
break
}
}
flac.dataStartPos, err = input.Seek(0, io.SeekCurrent)
if err != nil {
return nil, err
}
return &flac, nil
}
func readMetadataBlock(input io.Reader) (*FlacMetadataBlock, error) {
header := FlacMetadataBlock{}
// 4 - header size
headerBytes, err := readBytes(input, 4)
if err != nil {
return nil, err
}
// first bit
isLastBit := GetBit(headerBytes[0], 7)
if isLastBit == 1 {
header.IsLast = true
}
// Only 0-6 types
// 1-7 bits
blockType := headerBytes[0] & 0x7F
if blockType > 6 {
return nil, ErrReadFile
}
header.Type = FlacMetadataBlockType(blockType)
// 3 bytes size
header.Size = ByteToInt(headerBytes[1:])
// block data
header.Data, err = readBytes(input, header.Size)
if err != nil {
return nil, err
}
return &header, nil
}
func (block *FlacMetadataBlock) Write(w io.Writer, isLast bool) error {
block.Size = len(block.Data)
block.IsLast = isLast
blockHeader := []byte{byte(block.Type) & 0x7F, 0, 0, 0}
if isLast {
blockHeader[0] |= 1 << 7
}
// 3 bytes encodes the size in big endian
blockHeader[1] = byte((block.Size) >> 16)
blockHeader[2] = byte((block.Size) >> 8 & 0xFF)
blockHeader[3] = byte((block.Size) >> 0 & 0xFF)
if _, err := w.Write(blockHeader); err != nil {
return err
}
if _, err := w.Write(block.Data); err != nil {
return err
}
return nil
}
type VorbisComment struct {
Name string
Value string
}
func (flac *FLAC) GetVorbisComment(key string) (string, error) {
val, ok := flac.Tags[key]
if !ok {
return "", ErrTagNotFound
}
return val, nil
}
// The comment header is decoded as follows:
//
// 1. [vendor_length] = read an unsigned integer of 32 bits
//
// 2. [vendor_string] = read a UTF-8 vector as [vendor_length] octets
//
// 3. [user_comment_list_length] = read an unsigned integer of 32 bits
//
// 4. iterate [user_comment_list_length] times {
//
// 5. [length] = read an unsigned integer of 32 bits
//
// 6. this iteration's user comment = read a UTF-8 vector as [length] octets
//
// }
//
// 7. [framing_bit] = read a single bit as boolean
func readVorbisComments(input io.Reader) ([]VorbisComment, string, error) {
result := []VorbisComment{}
// vendor
vendorByte, err := readLengthData(input, binary.LittleEndian)
if err != nil {
return nil, "", err
}
// user_comment_list_length
var length uint32
err = binary.Read(input, binary.LittleEndian, &length)
if err != nil {
return nil, "", err
}
// iterate
for i := 0; i < int(length); i++ {
data, err := readLengthData(input, binary.LittleEndian)
if err != nil {
return nil, "", err
}
// Parse data
vorbis := strings.SplitN(string(data), "=", 2)
if len(vorbis) != 2 {
return nil, "", ErrIncorrectTag
}
comment := VorbisComment{
Name: vorbis[0],
Value: vorbis[1],
}
result = append(result, comment)
}
return result, string(vendorByte), nil
}
func serializeVorbisComments(comments map[string]string, vendorHeader string) []byte {
// Serialize out the vorbis comments as a metadata block payload
// Spawn out all the tag blobs first
output := bytes.NewBuffer([]byte{})
for key, value := range comments {
line := key + "=" + value
if err := writeLengthData(output, binary.LittleEndian, []byte(line)); err != nil {
return []byte{}
}
}
// Now that we have the payload content figured out, we can reconstruct its headers
dataPayload, err := ioutil.ReadAll(output)
if err != nil {
return []byte{}
}
output.Grow(len(vendorHeader) + 4)
output.Reset() // clear our scratchpad
if err = writeLengthData(output, binary.LittleEndian, []byte(vendorHeader)); err != nil {
return []byte{}
}
userCommentLength := uint32(len(comments))
if err = binary.Write(output, binary.LittleEndian, userCommentLength); err != nil {
return []byte{}
}
output.Write(dataPayload)
payload, err := ioutil.ReadAll(output)
if err != nil {
return []byte{}
}
return payload
}
func (flac *FLAC) GetVorbisCommentInt(key string) (int, error) {
comment, err := flac.GetVorbisComment(key)
if err != nil {
return 0, err
}
return strconv.Atoi(comment)
}
func (flac *FLAC) GetVorbisCommentTime(key string) (time.Time, error) {
comment, err := flac.GetVorbisComment(key)
if err != nil {
return time.Now(), err
}
result, err := time.Parse("2006-01-02T15:04:05", comment)
if err != nil {
return time.Now(), err
}
return result, nil
}
type FlacMetadataBlockPicture struct {
Type int32
MIME string
Description string
Width int32
Height int32
BitsPerPixel int32
NumberOfColors int32
PictureData []byte
}
func (flac *FLAC) GetMetadataBlockPicture() (*FlacMetadataBlockPicture, error) {
for _, block := range flac.Blocks {
if block.Type == FlacPicture {
return readFlacPicture(bytes.NewReader(block.Data))
}
}
return nil, ErrTagNotFound
}
func readFlacPicture(input io.Reader) (*FlacMetadataBlockPicture, error) {
var picture FlacMetadataBlockPicture
// Picture type
err := binary.Read(input, binary.BigEndian, &picture.Type)
if err != nil {
return nil, err
}
// MIME
MIMEBytes, err := readLengthData(input, binary.BigEndian)
if err != nil {
return nil, err
}
picture.MIME = string(MIMEBytes)
// Description
DescriptionBytes, err := readLengthData(input, binary.BigEndian)
if err != nil {
return nil, err
}
picture.Description = string(DescriptionBytes)
// Width
err = binary.Read(input, binary.BigEndian, &picture.Width)
if err != nil {
return nil, err
}
// Height
err = binary.Read(input, binary.BigEndian, &picture.Height)
if err != nil {
return nil, err
}
// Bits per pixel
err = binary.Read(input, binary.BigEndian, &picture.BitsPerPixel)
if err != nil {
return nil, err
}
// Number of colors
err = binary.Read(input, binary.BigEndian, &picture.NumberOfColors)
if err != nil {
return nil, err
}
// Picture data
picture.PictureData, err = readLengthData(input, binary.BigEndian)
if err != nil {
return nil, err
}
return &picture, nil
}