return FormatError("bad Tc value")
}
th := d.tmp[0] & 0x0f
- if th > maxTh || !d.progressive && th > 1 {
+ // The baseline th <= 1 restriction is specified in table B.5.
+ if th > maxTh || (d.baseline && th > 1) {
return FormatError("bad Th value")
}
h := &d.huff[tc][th]
)
const (
- sof0Marker = 0xc0 // Start Of Frame (Baseline).
+ sof0Marker = 0xc0 // Start Of Frame (Baseline Sequential).
sof1Marker = 0xc1 // Start Of Frame (Extended Sequential).
sof2Marker = 0xc2 // Start Of Frame (Progressive).
dhtMarker = 0xc4 // Define Huffman Table.
blackPix []byte
blackStride int
- ri int // Restart Interval.
- nComp int
- progressive bool
+ ri int // Restart Interval.
+ nComp int
+
+ // As per section 4.5, there are four modes of operation (selected by the
+ // SOF? markers): sequential DCT, progressive DCT, lossless and
+ // hierarchical, although this implementation does not support the latter
+ // two non-DCT modes. Sequential DCT is further split into baseline and
+ // extended, as per section 4.11.
+ baseline bool
+ progressive bool
+
jfif bool
adobeTransformValid bool
adobeTransform uint8
switch marker {
case sof0Marker, sof1Marker, sof2Marker:
+ d.baseline = marker == sof0Marker
d.progressive = marker == sof2Marker
err = d.processSOF(n)
if configOnly && d.jfif {
}
totalHV += d.comp[compIndex].h * d.comp[compIndex].v
+ // The baseline t <= 1 restriction is specified in table B.3.
scan[i].td = d.tmp[2+2*i] >> 4
- if scan[i].td > maxTh {
+ if t := scan[i].td; t > maxTh || (d.baseline && t > 1) {
return FormatError("bad Td value")
}
scan[i].ta = d.tmp[2+2*i] & 0x0f
- if scan[i].ta > maxTh {
+ if t := scan[i].ta; t > maxTh || (d.baseline && t > 1) {
return FormatError("bad Ta value")
}
}
// by the second-least significant bit, followed by the least
// significant bit.
//
- // For baseline JPEGs, these parameters are hard-coded to 0/63/0/0.
+ // For sequential JPEGs, these parameters are hard-coded to 0/63/0/0, as
+ // per table B.3.
zigStart, zigEnd, ah, al := int32(0), int32(blockSize-1), uint32(0), uint32(0)
if d.progressive {
zigStart = int32(d.tmp[1+2*nComp])
// The blocks are traversed one MCU at a time. For 4:2:0 chroma
// subsampling, there are four Y 8x8 blocks in every 16x16 MCU.
//
- // For a baseline 32x16 pixel image, the Y blocks visiting order is:
+ // For a sequential 32x16 pixel image, the Y blocks visiting order is:
// 0 1 4 5
// 2 3 6 7
//
}
}
-// writeSOF0 writes the Start Of Frame (Baseline) marker.
+// writeSOF0 writes the Start Of Frame (Baseline Sequential) marker.
func (e *encoder) writeSOF0(size image.Point, nComponent int) {
markerlen := 8 + 3*nComponent
e.writeMarkerHeader(sof0Marker, markerlen)