code: public static int encodePic(
        double[] data,
        int dataSize,
        byte[] result
    ) {
      long count;
      int ri = 0;
      int hbi;
      byte halfBytes[] = new byte[10];
      int halfByteCount = 0;
  
      //printf("Encoding %d doubles\n", (int)dataSize);
  
      for (int i = 0; i < dataSize; i++) {
        count = (long) (data[i] + 0.5);
        halfByteCount += encodeInt(count, halfBytes, halfByteCount);
  
        for (hbi = 1; hbi < halfByteCount; hbi += 2) {
          result[ri++] = (byte) ((halfBytes[hbi - 1] << 4) | (halfBytes[hbi] & 0xf));
        }
  
        if (halfByteCount % 2 != 0) {
          halfBytes[0] = halfBytes[halfByteCount - 1];
          halfByteCount = 1;
        } else {
          halfByteCount = 0;
        }
  
      }
      if (halfByteCount == 1) {
        result[ri++] = (byte) (halfBytes[0] << 4);
      }
  
      return ri;
    }
docs: Encodes ion counts by simply rounding to the nearest 4 byte integer, and compressing each
  integer with encodeInt.
  <p>
  The handleable range is therefore 0 -&gt; 4294967294. The resulting binary is maximally
  dataSize * 5 bytes, but much less if the data is close to 0 on average.
  
  @param data array of doubles to be encoded
  @param dataSize number of doubles from data to encode
  @param result array were resulting bytes should be stored
  @return the number of encoded bytes