public static byte[] compressT4_1D(final byte[] uncompressed, final int width, final int height, final boolean hasFill) throws ImagingException {
        final BitInputStreamFlexible inputStream = new BitInputStreamFlexible(new ByteArrayInputStream(uncompressed));
        try (BitArrayOutputStream outputStream = new BitArrayOutputStream()) {
            if (hasFill) {
                T4_T6_Tables.EOL16.writeBits(outputStream);
            } else {
                T4_T6_Tables.EOL.writeBits(outputStream);
            }

            for (int y = 0; y < height; y++) {
                compress1DLine(inputStream, outputStream, null, width);
                if (hasFill) {
                    int bitsAvailable = outputStream.getBitsAvailableInCurrentByte();
                    if (bitsAvailable < 4) {
                        outputStream.flush();
                        bitsAvailable = 8;
                    }
                    for (; bitsAvailable > 4; bitsAvailable--) {
                        outputStream.writeBit(0);
                    }
                }
                T4_T6_Tables.EOL.writeBits(outputStream);
                inputStream.flushCache();
            }

            return outputStream.toByteArray();
        }
    }
Compressed with the "Modified Huffman" encoding of section 10 in the TIFF6 specification. No EOLs, no RTC, rows are padded to end on a byte boundary.

@param uncompressed uncompressed byte data
@param width        image width
@param height       image height
@return the compressed data
@throws ImagingException if it fails to write the compressed data
src/main/java/org/apache/commons/imaging/formats/tiff/itu_t4/T4AndT6Compression.java