codec/mjpeg/jpeg.go: defining consts for SOF0 header fields

This commit is contained in:
Saxon 2020-01-01 19:15:32 +10:30
parent 1d0c10a402
commit 6bdfdb1f2a
1 changed files with 14 additions and 5 deletions

View File

@ -55,8 +55,8 @@ const (
// Density units. // Density units.
const ( const (
unitNone = iota unitNone = iota
unitPxIN unitPxIN // Pixels per inch.
unitPxCM unitPxCM // Pixels per centimeter.
) )
// JFIF header fields. // JFIF header fields.
@ -71,6 +71,13 @@ const (
jfifHeadLen = 16 // Length of JFIF header segment excluding APP0 marker. jfifHeadLen = 16 // Length of JFIF header segment excluding APP0 marker.
) )
// SOF0 (start of scan) header fields.
const (
sofLen = 17
sofPrecision = 8
sofNoOfComponents = 3
)
var ( var (
errNoQTable = errors.New("no quantization table") errNoQTable = errors.New("no quantization table")
errReservedQ = errors.New("q value is reserved") errReservedQ = errors.New("q value is reserved")
@ -333,11 +340,13 @@ func writeHeader(p *putBuffer, _type, width, height, nbqTab, dri int, qtable []b
mtxNo = 1 mtxNo = 1
} }
p.put16(17) p.put16(sofLen)
p.put8(8) p.put8(sofPrecision)
p.put16(uint16(height)) p.put16(uint16(height))
p.put16(uint16(width)) p.put16(uint16(width))
p.put8(3) p.put8(sofNoOfComponents)
// TODO: find meaning of these fields.
p.put8(1) p.put8(1)
p.put8(uint8((2 << 4) | sample)) p.put8(uint8((2 << 4) | sample))
p.put8(0) p.put8(0)