MCPcopy Create free account
hub / github.com/OpenFodder/openfodder / stbi__process_scan_header

Function stbi__process_scan_header

Source/Utils/stb_image.h:3202–3239  ·  view source on GitHub ↗

after we see SOS

Source from the content-addressed store, hash-verified

3200
3201// after we see SOS
3202static int stbi__process_scan_header(stbi__jpeg *z)
3203{
3204 int i;
3205 int Ls = stbi__get16be(z->s);
3206 z->scan_n = stbi__get8(z->s);
3207 if (z->scan_n < 1 || z->scan_n > 4 || z->scan_n > (int) z->s->img_n) return stbi__err("bad SOS component count","Corrupt JPEG");
3208 if (Ls != 6+2*z->scan_n) return stbi__err("bad SOS len","Corrupt JPEG");
3209 for (i=0; i < z->scan_n; ++i) {
3210 int id = stbi__get8(z->s), which;
3211 int q = stbi__get8(z->s);
3212 for (which = 0; which < z->s->img_n; ++which)
3213 if (z->img_comp[which].id == id)
3214 break;
3215 if (which == z->s->img_n) return 0; // no match
3216 z->img_comp[which].hd = q >> 4; if (z->img_comp[which].hd > 3) return stbi__err("bad DC huff","Corrupt JPEG");
3217 z->img_comp[which].ha = q & 15; if (z->img_comp[which].ha > 3) return stbi__err("bad AC huff","Corrupt JPEG");
3218 z->order[i] = which;
3219 }
3220
3221 {
3222 int aa;
3223 z->spec_start = stbi__get8(z->s);
3224 z->spec_end = stbi__get8(z->s); // should be 63, but might be 0
3225 aa = stbi__get8(z->s);
3226 z->succ_high = (aa >> 4);
3227 z->succ_low = (aa & 15);
3228 if (z->progressive) {
3229 if (z->spec_start > 63 || z->spec_end > 63 || z->spec_start > z->spec_end || z->succ_high > 13 || z->succ_low > 13)
3230 return stbi__err("bad SOS", "Corrupt JPEG");
3231 } else {
3232 if (z->spec_start != 0) return stbi__err("bad SOS","Corrupt JPEG");
3233 if (z->succ_high != 0 || z->succ_low != 0) return stbi__err("bad SOS","Corrupt JPEG");
3234 z->spec_end = 63;
3235 }
3236 }
3237
3238 return 1;
3239}
3240
3241static int stbi__free_jpeg_components(stbi__jpeg *z, int ncomp, int why)
3242{

Callers 1

stbi__decode_jpeg_imageFunction · 0.85

Calls 3

stbi__get16beFunction · 0.85
stbi__get8Function · 0.85
stbi__errFunction · 0.85

Tested by

no test coverage detected