codec/mjpeg/jpeg.go: defining consts for JFIF header

This commit is contained in:
Saxon 2020-01-01 18:34:51 +10:30
parent d146b65c57
commit 3f4561da5b
1 changed files with 26 additions and 8 deletions

View File

@ -52,6 +52,25 @@ const (
codeEOI = 0xd9 // End of image. codeEOI = 0xd9 // End of image.
) )
// Density units.
const (
unitNone = iota
unitPxIN
unitPxCM
)
// JFIF header fields.
const (
jfifLabel = "JFIF\000"
jfifVer = 0x0201
jfifDensityUnit = unitNone // Units for pixel density fields.
jfifXDensity = 1 // Horizontal pixel desnity.
jfifYDensity = 1 // Vertical pixel density.
jfifXThumbCnt = 0 // Horizontal pixel count of embedded thumbnail.
jfifYThumbCnt = 0 // Vertical pixel count of embedded thumbnail.
jfifHeadLen = 16 // Length of JFIF header segment excluding APP0 marker.
)
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")
@ -262,15 +281,14 @@ func writeHeader(p *putBuffer, _type, width, height, nbqTab, dri int, qtable []b
// Write JFIF header. // Write JFIF header.
mark(p, codeAPP0) mark(p, codeAPP0)
p.put16(16) p.put16(jfifHeadLen)
const jfifLabel = "JFIF\000"
p.putBytes([]byte(jfifLabel)) p.putBytes([]byte(jfifLabel))
p.put16(0x0201) p.put16(jfifVer)
p.put8(0) p.put8(jfifDensityUnit)
p.put16(1) p.put16(jfifXDensity)
p.put16(1) p.put16(jfifYDensity)
p.put8(0) p.put8(jfifXThumbCnt)
p.put8(0) p.put8(jfifYThumbCnt)
// If we want to define restart interval then write that. // If we want to define restart interval then write that.
if dri != 0 { if dri != 0 {