}
for i := 0; i < d.nComp; i++ {
d.comp[i].c = d.tmp[6+3*i]
+ // Section B.2.2 states that "the value of C_i shall be different from
+ // the values of C_1 through C_(i-1)".
+ for j := 0; j < i; j++ {
+ if d.comp[i].c == d.comp[j].c {
+ return FormatError("repeated component identifier")
+ }
+ }
+
d.comp[i].tq = d.tmp[8+3*i]
+
if d.nComp == 1 {
// If a JPEG image has only one component, section A.2 says "this data
// is non-interleaved by definition" and section A.2.2 says "[in this
td uint8 // DC table selector.
ta uint8 // AC table selector.
}
+ totalHV := 0
for i := 0; i < nComp; i++ {
cs := d.tmp[1+2*i] // Component selector.
compIndex := -1
return FormatError("unknown component selector")
}
scan[i].compIndex = uint8(compIndex)
+ // Section B.2.3 states that "the value of Cs_j shall be different from
+ // the values of Cs_1 through Cs_(j-1)". Since we have previously
+ // verified that a frame's component identifiers (C_i values in section
+ // B.2.2) are unique, it suffices to check that the implicit indexes
+ // into d.comp are unique.
+ for j := 0; j < i; j++ {
+ if scan[i].compIndex == scan[j].compIndex {
+ return FormatError("repeated component selector")
+ }
+ }
+ totalHV += d.comp[compIndex].h * d.comp[compIndex].v
+
scan[i].td = d.tmp[2+2*i] >> 4
if scan[i].td > maxTh {
return FormatError("bad Td value")
return FormatError("bad Ta value")
}
}
+ // Section B.2.3 states that if there is more than one component then the
+ // total H*V values in a scan must be <= 10.
+ if d.nComp > 1 && totalHV > 10 {
+ return FormatError("total sampling factors too large")
+ }
// zigStart and zigEnd are the spectral selection bounds.
// ah and al are the successive approximation high and low values.