// significant bit.
//
// For baseline JPEGs, these parameters are hard-coded to 0/63/0/0.
- zigStart, zigEnd, ah, al := 0, blockSize-1, uint(0), uint(0)
+ zigStart, zigEnd, ah, al := int32(0), int32(blockSize-1), uint32(0), uint32(0)
if d.progressive {
- zigStart = int(d.tmp[1+2*nComp])
- zigEnd = int(d.tmp[2+2*nComp])
- ah = uint(d.tmp[3+2*nComp] >> 4)
- al = uint(d.tmp[3+2*nComp] & 0x0f)
+ zigStart = int32(d.tmp[1+2*nComp])
+ zigEnd = int32(d.tmp[2+2*nComp])
+ ah = uint32(d.tmp[3+2*nComp] >> 4)
+ al = uint32(d.tmp[3+2*nComp] & 0x0f)
if (zigStart == 0 && zigEnd != 0) || zigStart > zigEnd || blockSize <= zigEnd {
return FormatError("bad spectral selection bounds")
}
var (
// b is the decoded coefficients, in natural (not zig-zag) order.
b block
- dc [nColorComponent]int
+ dc [nColorComponent]int32
// mx0 and my0 are the location of the current (in terms of 8x8 blocks).
// For example, with 4:2:0 chroma subsampling, the block whose top left
// pixel co-ordinates are (16, 8) is the third block in the first row:
val0 := value >> 4
val1 := value & 0x0f
if val1 != 0 {
- zig += int(val0)
+ zig += int32(val0)
if zig > zigEnd {
break
}
// Reset the Huffman decoder.
d.b = bits{}
// Reset the DC components, as per section F.2.1.3.1.
- dc = [nColorComponent]int{}
+ dc = [nColorComponent]int32{}
// Reset the progressive decoder state, as per section G.1.2.2.
d.eobRun = 0
}
// refine decodes a successive approximation refinement block, as specified in
// section G.1.2.
-func (d *decoder) refine(b *block, h *huffman, zigStart, zigEnd, delta int) error {
+func (d *decoder) refine(b *block, h *huffman, zigStart, zigEnd, delta int32) error {
// Refining a DC component is trivial.
if zigStart == 0 {
if zigEnd != 0 {
if d.eobRun == 0 {
loop:
for ; zig <= zigEnd; zig++ {
- z := 0
+ z := int32(0)
value, err := d.decodeHuffman(h)
if err != nil {
return err
return FormatError("unexpected Huffman code")
}
- zig, err = d.refineNonZeroes(b, zig, zigEnd, int(val0), delta)
+ zig, err = d.refineNonZeroes(b, zig, zigEnd, int32(val0), delta)
if err != nil {
return err
}
// refineNonZeroes refines non-zero entries of b in zig-zag order. If nz >= 0,
// the first nz zero entries are skipped over.
-func (d *decoder) refineNonZeroes(b *block, zig, zigEnd, nz, delta int) (int, error) {
+func (d *decoder) refineNonZeroes(b *block, zig, zigEnd, nz, delta int32) (int32, error) {
for ; zig <= zigEnd; zig++ {
u := unzig[zig]
if b[u] == 0 {
}
// div returns a/b rounded to the nearest integer, instead of rounded to zero.
-func div(a int, b int) int {
+func div(a, b int32) int32 {
if a >= 0 {
return (a + (b >> 1)) / b
}
}
// emitHuff emits the given value with the given Huffman encoder.
-func (e *encoder) emitHuff(h huffIndex, value int) {
+func (e *encoder) emitHuff(h huffIndex, value int32) {
x := theHuffmanLUT[h][value]
e.emit(x&(1<<24-1), x>>24)
}
// emitHuffRLE emits a run of runLength copies of value encoded with the given
// Huffman encoder.
-func (e *encoder) emitHuffRLE(h huffIndex, runLength, value int) {
+func (e *encoder) emitHuffRLE(h huffIndex, runLength, value int32) {
a, b := value, value
if a < 0 {
a, b = -value, value-1
} else {
nBits = 8 + uint32(bitCount[a>>8])
}
- e.emitHuff(h, runLength<<4|int(nBits))
+ e.emitHuff(h, runLength<<4|int32(nBits))
if nBits > 0 {
e.emit(uint32(b)&(1<<nBits-1), nBits)
}
// writeBlock writes a block of pixel data using the given quantization table,
// returning the post-quantized DC value of the DCT-transformed block.
// b is in natural (not zig-zag) order.
-func (e *encoder) writeBlock(b *block, q quantIndex, prevDC int) int {
+func (e *encoder) writeBlock(b *block, q quantIndex, prevDC int32) int32 {
fdct(b)
// Emit the DC delta.
- dc := div(b[0], (8 * int(e.quant[q][0])))
+ dc := div(b[0], 8*int32(e.quant[q][0]))
e.emitHuffRLE(huffIndex(2*q+0), 0, dc-prevDC)
// Emit the AC components.
- h, runLength := huffIndex(2*q+1), 0
+ h, runLength := huffIndex(2*q+1), int32(0)
for zig := 1; zig < blockSize; zig++ {
- ac := div(b[unzig[zig]], (8 * int(e.quant[q][zig])))
+ ac := div(b[unzig[zig]], 8*int32(e.quant[q][zig]))
if ac == 0 {
runLength++
} else {
for i := 0; i < 8; i++ {
r, g, b, _ := m.At(min(p.X+i, xmax), min(p.Y+j, ymax)).RGBA()
yy, cb, cr := color.RGBToYCbCr(uint8(r>>8), uint8(g>>8), uint8(b>>8))
- yBlock[8*j+i] = int(yy)
- cbBlock[8*j+i] = int(cb)
- crBlock[8*j+i] = int(cr)
+ yBlock[8*j+i] = int32(yy)
+ cbBlock[8*j+i] = int32(cb)
+ crBlock[8*j+i] = int32(cr)
}
}
}
}
pix := m.Pix[offset+sx*4:]
yy, cb, cr := color.RGBToYCbCr(pix[0], pix[1], pix[2])
- yBlock[8*j+i] = int(yy)
- cbBlock[8*j+i] = int(cb)
- crBlock[8*j+i] = int(cr)
+ yBlock[8*j+i] = int32(yy)
+ cbBlock[8*j+i] = int32(cb)
+ crBlock[8*j+i] = int32(cr)
}
}
}
var (
// Scratch buffers to hold the YCbCr values.
// The blocks are in natural (not zig-zag) order.
- yBlock block
- cbBlock [4]block
- crBlock [4]block
- cBlock block
+ b block
+ cb, cr [4]block
// DC components are delta-encoded.
- prevDCY, prevDCCb, prevDCCr int
+ prevDCY, prevDCCb, prevDCCr int32
)
bounds := m.Bounds()
rgba, _ := m.(*image.RGBA)
yOff := (i & 2) * 4
p := image.Pt(x+xOff, y+yOff)
if rgba != nil {
- rgbaToYCbCr(rgba, p, &yBlock, &cbBlock[i], &crBlock[i])
+ rgbaToYCbCr(rgba, p, &b, &cb[i], &cr[i])
} else {
- toYCbCr(m, p, &yBlock, &cbBlock[i], &crBlock[i])
+ toYCbCr(m, p, &b, &cb[i], &cr[i])
}
- prevDCY = e.writeBlock(&yBlock, 0, prevDCY)
+ prevDCY = e.writeBlock(&b, 0, prevDCY)
}
- scale(&cBlock, &cbBlock)
- prevDCCb = e.writeBlock(&cBlock, 1, prevDCCb)
- scale(&cBlock, &crBlock)
- prevDCCr = e.writeBlock(&cBlock, 1, prevDCCr)
+ scale(&b, &cb)
+ prevDCCb = e.writeBlock(&b, 1, prevDCCb)
+ scale(&b, &cr)
+ prevDCCr = e.writeBlock(&b, 1, prevDCCr)
}
}
// Pad the last byte with 1's.