MCPcopy Create free account
hub / github.com/ARM-software/ComputeLibrary / stbi__compute_huffman_codes

Function stbi__compute_huffman_codes

include/stb/stb_image.h:4359–4407  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4357}
4358
4359static int stbi__compute_huffman_codes(stbi__zbuf *a)
4360{
4361 static const stbi_uc length_dezigzag[19] = { 16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15 };
4362 stbi__zhuffman z_codelength;
4363 stbi_uc lencodes[286+32+137];//padding for maximum single op
4364 stbi_uc codelength_sizes[19];
4365 int i,n;
4366
4367 int hlit = stbi__zreceive(a,5) + 257;
4368 int hdist = stbi__zreceive(a,5) + 1;
4369 int hclen = stbi__zreceive(a,4) + 4;
4370 int ntot = hlit + hdist;
4371
4372 memset(codelength_sizes, 0, sizeof(codelength_sizes));
4373 for (i=0; i < hclen; ++i) {
4374 int s = stbi__zreceive(a,3);
4375 codelength_sizes[length_dezigzag[i]] = (stbi_uc) s;
4376 }
4377 if (!stbi__zbuild_huffman(&z_codelength, codelength_sizes, 19)) return 0;
4378
4379 n = 0;
4380 while (n < ntot) {
4381 int c = stbi__zhuffman_decode(a, &z_codelength);
4382 if (c < 0 || c >= 19) return stbi__err("bad codelengths", "Corrupt PNG");
4383 if (c < 16)
4384 lencodes[n++] = (stbi_uc) c;
4385 else {
4386 stbi_uc fill = 0;
4387 if (c == 16) {
4388 c = stbi__zreceive(a,2)+3;
4389 if (n == 0) return stbi__err("bad codelengths", "Corrupt PNG");
4390 fill = lencodes[n-1];
4391 } else if (c == 17) {
4392 c = stbi__zreceive(a,3)+3;
4393 } else if (c == 18) {
4394 c = stbi__zreceive(a,7)+11;
4395 } else {
4396 return stbi__err("bad codelengths", "Corrupt PNG");
4397 }
4398 if (ntot - n < c) return stbi__err("bad codelengths", "Corrupt PNG");
4399 memset(lencodes+n, fill, c);
4400 n += c;
4401 }
4402 }
4403 if (n != ntot) return stbi__err("bad codelengths","Corrupt PNG");
4404 if (!stbi__zbuild_huffman(&a->z_length, lencodes, hlit)) return 0;
4405 if (!stbi__zbuild_huffman(&a->z_distance, lencodes+hlit, hdist)) return 0;
4406 return 1;
4407}
4408
4409static int stbi__parse_uncompressed_block(stbi__zbuf *a)
4410{

Callers 1

stbi__parse_zlibFunction · 0.85

Calls 4

stbi__zreceiveFunction · 0.85
stbi__zbuild_huffmanFunction · 0.85
stbi__zhuffman_decodeFunction · 0.85
stbi__errFunction · 0.85

Tested by

no test coverage detected