Exemplo n.º 1
0
  private int[] readLengths(
      PngDecodingDataStream stream, int numLengths, PngHuffmanTable lengthsTable, int tableSize)
      throws IOException {
    int[] lengths = new int[tableSize];

    for (int index = 0; index < numLengths; ) {
      int value = lengthsTable.getNextValue(stream);
      if (value < 16) {
        // Literal value
        lengths[index] = value;
        index++;
      } else if (value == 16) {
        // Repeat the previous code 3-6 times.
        int count = stream.getNextIdatBits(2) + 3;
        for (int i = 0; i < count; i++) {
          lengths[index] = lengths[index - 1];
          index++;
        }
      } else if (value == 17) {
        // Repeat 0 3-10 times.
        int count = stream.getNextIdatBits(3) + 3;
        for (int i = 0; i < count; i++) {
          lengths[index] = 0;
          index++;
        }
      } else if (value == 18) {
        // Repeat 0 11-138 times.
        int count = stream.getNextIdatBits(7) + 11;
        for (int i = 0; i < count; i++) {
          lengths[index] = 0;
          index++;
        }
      } else {
        stream.error();
      }
    }
    return lengths;
  }
Exemplo n.º 2
0
 int getNextDistanceValue(PngDecodingDataStream stream) throws IOException {
   return distanceTable.getNextValue(stream);
 }
Exemplo n.º 3
0
 int getNextLiteralValue(PngDecodingDataStream stream) throws IOException {
   return literalTable.getNextValue(stream);
 }