MCPcopy Create free account
hub / github.com/DFHack/dfhack / addLengthDistance

Function addLengthDistance

depends/lodepng/lodepng.cpp:1466–1487  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1464}
1465
1466static void addLengthDistance(uivector* values, size_t length, size_t distance) {
1467 /*values in encoded vector are those used by deflate:
1468 0-255: literal bytes
1469 256: end
1470 257-285: length/distance pair (length code, followed by extra length bits, distance code, extra distance bits)
1471 286-287: invalid*/
1472
1473 unsigned length_code = (unsigned)searchCodeIndex(LENGTHBASE, 29, length);
1474 unsigned extra_length = (unsigned)(length - LENGTHBASE[length_code]);
1475 unsigned dist_code = (unsigned)searchCodeIndex(DISTANCEBASE, 30, distance);
1476 unsigned extra_distance = (unsigned)(distance - DISTANCEBASE[dist_code]);
1477
1478 size_t pos = values->size;
1479 /*TODO: return error when this fails (out of memory)*/
1480 unsigned ok = uivector_resize(values, values->size + 4);
1481 if(ok) {
1482 values->data[pos + 0] = length_code + FIRST_LENGTH_CODE_INDEX;
1483 values->data[pos + 1] = extra_length;
1484 values->data[pos + 2] = dist_code;
1485 values->data[pos + 3] = extra_distance;
1486 }
1487}
1488
1489/*3 bytes of data get encoded into two bytes. The hash cannot use more than 3
1490bytes as input because 3 is the minimum match length for deflate*/

Callers 1

encodeLZ77Function · 0.85

Calls 2

searchCodeIndexFunction · 0.85
uivector_resizeFunction · 0.85

Tested by

no test coverage detected