getCode static method

int getCode(
  1. int po,
  2. int rlc,
  3. List<int> c_lc,
  4. InputBuffer input,
  5. Uint16List? out,
  6. int oi,
  7. int oe,
)

Implementation

static int getCode(int po, int rlc, List<int> c_lc, InputBuffer input,
    Uint16List? out, int oi, int oe) {
  if (po == rlc) {
    if (c_lc[1] < 8) {
      getChar(c_lc, input);
    }

    c_lc[1] -= 8;

    var cs = (c_lc[0] >> c_lc[1]) & 0xff;

    if (oi + cs > oe) {
      throw ImageException('Error in Huffman-encoded data '
          '(decoded data are longer than expected).');
    }

    final s = out![oi - 1];

    while (cs-- > 0) {
      out[oi++] = s;
    }
  } else if (oi < oe) {
    out![oi++] = po;
  } else {
    throw ImageException('Error in Huffman-encoded data '
        '(decoded data are longer than expected).');
  }
  return oi;
}