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

Function stbi__process_marker

Source/Utils/stb_image.h:3098–3199  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3096}
3097
3098static int stbi__process_marker(stbi__jpeg *z, int m)
3099{
3100 int L;
3101 switch (m) {
3102 case STBI__MARKER_none: // no marker found
3103 return stbi__err("expected marker","Corrupt JPEG");
3104
3105 case 0xDD: // DRI - specify restart interval
3106 if (stbi__get16be(z->s) != 4) return stbi__err("bad DRI len","Corrupt JPEG");
3107 z->restart_interval = stbi__get16be(z->s);
3108 return 1;
3109
3110 case 0xDB: // DQT - define quantization table
3111 L = stbi__get16be(z->s)-2;
3112 while (L > 0) {
3113 int q = stbi__get8(z->s);
3114 int p = q >> 4, sixteen = (p != 0);
3115 int t = q & 15,i;
3116 if (p != 0 && p != 1) return stbi__err("bad DQT type","Corrupt JPEG");
3117 if (t > 3) return stbi__err("bad DQT table","Corrupt JPEG");
3118
3119 for (i=0; i < 64; ++i)
3120 z->dequant[t][stbi__jpeg_dezigzag[i]] = (stbi__uint16)(sixteen ? stbi__get16be(z->s) : stbi__get8(z->s));
3121 L -= (sixteen ? 129 : 65);
3122 }
3123 return L==0;
3124
3125 case 0xC4: // DHT - define huffman table
3126 L = stbi__get16be(z->s)-2;
3127 while (L > 0) {
3128 stbi_uc *v;
3129 int sizes[16],i,n=0;
3130 int q = stbi__get8(z->s);
3131 int tc = q >> 4;
3132 int th = q & 15;
3133 if (tc > 1 || th > 3) return stbi__err("bad DHT header","Corrupt JPEG");
3134 for (i=0; i < 16; ++i) {
3135 sizes[i] = stbi__get8(z->s);
3136 n += sizes[i];
3137 }
3138 if(n > 256) return stbi__err("bad DHT header","Corrupt JPEG"); // Loop over i < n would write past end of values!
3139 L -= 17;
3140 if (tc == 0) {
3141 if (!stbi__build_huffman(z->huff_dc+th, sizes)) return 0;
3142 v = z->huff_dc[th].values;
3143 } else {
3144 if (!stbi__build_huffman(z->huff_ac+th, sizes)) return 0;
3145 v = z->huff_ac[th].values;
3146 }
3147 for (i=0; i < n; ++i)
3148 v[i] = stbi__get8(z->s);
3149 if (tc != 0)
3150 stbi__build_fast_ac(z->fast_ac[th], z->huff_ac + th);
3151 L -= n;
3152 }
3153 return L==0;
3154 }
3155

Callers 2

stbi__decode_jpeg_headerFunction · 0.85
stbi__decode_jpeg_imageFunction · 0.85

Calls 6

stbi__errFunction · 0.85
stbi__get16beFunction · 0.85
stbi__get8Function · 0.85
stbi__build_huffmanFunction · 0.85
stbi__build_fast_acFunction · 0.85
stbi__skipFunction · 0.85

Tested by

no test coverage detected