codec/mjpeg/jpeg.go: renamed fields of putBuffer struct

This commit is contained in:
Saxon 2019-12-29 22:52:53 +10:30
parent bf865e48c5
commit 13e2571230
2 changed files with 18 additions and 22 deletions

View File

@ -223,7 +223,7 @@ func (c *Context) ParsePayload(p []byte, m bool) error {
writeHeader(c.buf, t, width, height, qLen/64, dri, qTable)
}
if c.buf.len() == 0 {
if c.buf.len == 0 {
// Must have missed start of frame? So ignore and wait for start.
return nil
}
@ -293,13 +293,13 @@ func writeHeader(p *putBuffer, _type, width, height, nbqTab, dri int, qtable []b
// Define huffman table.
mark(p, codeDHT)
lenIdx := p.len()
lenIdx := p.len
p.put16(0)
writeHuffman(p, 0, 0, bitsDCLum, valDC)
writeHuffman(p, 0, 1, bitsDCChr, valDC)
writeHuffman(p, 1, 0, bitsACLum, valACLum)
writeHuffman(p, 1, 1, bitsACChr, valACChr)
p.put16At(uint16(p.len()-lenIdx), lenIdx)
p.put16At(uint16(p.len-lenIdx), lenIdx)
// Start of frame.
mark(p, codeSOF0)

View File

@ -30,49 +30,45 @@ import (
)
type putBuffer struct {
i int
b []byte
len int
bytes []byte
}
func newPutBuffer(b []byte) *putBuffer { return &putBuffer{b: b} }
func newPutBuffer(b []byte) *putBuffer { return &putBuffer{bytes: b} }
func (p *putBuffer) Write(b []byte) (int, error) {
copy(p.b[p.i:], b)
p.i += len(b)
copy(p.bytes[p.len:], b)
p.len += len(b)
return len(b), nil
}
func (p *putBuffer) writeTo(d io.Writer) (int, error) {
n, err := d.Write(p.b[0:p.i])
p.i -= n
n, err := d.Write(p.bytes[0:p.len])
p.len -= n
return n, err
}
func (p *putBuffer) put16(v uint16) {
binary.BigEndian.PutUint16(p.b[p.i:], v)
p.i += 2
binary.BigEndian.PutUint16(p.bytes[p.len:], v)
p.len += 2
}
func (p *putBuffer) put8(v uint8) {
p.b[p.i] = byte(v)
p.i++
p.bytes[p.len] = byte(v)
p.len++
}
func (p *putBuffer) putBuf(src []byte) {
copy(p.b[p.i:], src)
p.i += len(src)
copy(p.bytes[p.len:], src)
p.len += len(src)
}
func (p *putBuffer) put16At(v uint16, i int) {
binary.BigEndian.PutUint16(p.b[i:], v)
binary.BigEndian.PutUint16(p.bytes[i:], v)
}
func (p *putBuffer) reset() {
p.i = 0
}
func (p *putBuffer) len() int {
return p.i
p.len = 0
}
type byteStream struct {