codec/mjpeg/jpeg.go: simplified writing of bytes for SOF and SOS headers

This commit is contained in:
Saxon 2020-01-07 11:08:36 +10:30
parent 4834aa8ca2
commit 83a304037c
1 changed files with 3 additions and 21 deletions

View File

@ -366,7 +366,7 @@ func writeHeader(p []byte, _type, width, height, nbqTab, dri int, qtable []byte)
}
// Derive matrix number.
mtxNo := 0
var mtxNo uint8
if nbqTab == 2 {
mtxNo = 1
}
@ -379,16 +379,7 @@ func writeHeader(p []byte, _type, width, height, nbqTab, dri int, qtable []byte)
idx += 8
// TODO: find meaning of these fields.
p[idx] = 1
p[idx+1] = uint8((2 << 4) | sample)
p[idx+2] = 0
p[idx+3] = 2
p[idx+4] = 1<<4 | 1
p[idx+5] = uint8(mtxNo)
p[idx+6] = 3
p[idx+7] = 1<<4 | 1
p[idx+8] = uint8(mtxNo)
idx += 9
idx += copy(p[idx:], []byte{1, uint8((2 << 4) | sample), 0, 2, 1<<4 | 1, mtxNo, 3, 1<<4 | 1, mtxNo})
// Write start of scan.
binary.BigEndian.PutUint16(p[idx:], 0xff00|codeSOS)
@ -397,16 +388,7 @@ func writeHeader(p []byte, _type, width, height, nbqTab, dri int, qtable []byte)
idx += 5
// TODO: find out what remaining fields are.
p[idx] = 1
p[idx+1] = 0
p[idx+2] = 2
p[idx+3] = 17
p[idx+4] = 3
p[idx+5] = 17
p[idx+6] = 0
p[idx+7] = 63
p[idx+8] = 0
idx += 9
idx += copy(p[idx:], []byte{1, 0, 2, 17, 3, 17, 0, 63, 0})
return idx
}