github.com/bluenviron/mediacommon@v1.9.3/pkg/codecs/jpeg/start_of_scan.go (about)

     1  package jpeg
     2  
     3  import (
     4  	"fmt"
     5  )
     6  
     7  // StartOfScan is a SOS marker.
     8  type StartOfScan struct{}
     9  
    10  // Unmarshal decodes the marker.
    11  func (StartOfScan) Unmarshal(buf []byte) error {
    12  	if len(buf) != 10 {
    13  		return fmt.Errorf("unsupported SOS size of %d", len(buf))
    14  	}
    15  	return nil
    16  }
    17  
    18  // Marshal encodes the marker.
    19  func (StartOfScan) Marshal(buf []byte) []byte {
    20  	buf = append(buf, []byte{0xFF, MarkerStartOfScan}...)
    21  	buf = append(buf, []byte{0, 12}...)   // length
    22  	buf = append(buf, []byte{3}...)       // components
    23  	buf = append(buf, []byte{0, 0}...)    // component 0
    24  	buf = append(buf, []byte{1, 0x11}...) // component 1
    25  	buf = append(buf, []byte{2, 0x11}...) // component 2
    26  	buf = append(buf, []byte{0, 63, 0}...)
    27  	return buf
    28  }