private byte[][] getStrips(final BufferedImage src, final int samplesPerPixel, final int bitsPerSample, final int rowsPerStrip) {
        final int width = src.getWidth();
        final int height = src.getHeight();

        final int stripCount = (height + rowsPerStrip - 1) / rowsPerStrip;

        // Write Strips
        final byte[][] result = new byte[Allocator.check(stripCount)][];

        int remainingRows = height;

        for (int i = 0; i < stripCount; i++) {
            final int rowsInStrip = Math.min(rowsPerStrip, remainingRows);
            remainingRows -= rowsInStrip;

            final int bitsInRow = bitsPerSample * samplesPerPixel * width;
            final int bytesPerRow = (bitsInRow + 7) / 8;
            final int bytesInStrip = rowsInStrip * bytesPerRow;

            final byte[] uncompressed = Allocator.byteArray(bytesInStrip);

            int counter = 0;
            int y = i * rowsPerStrip;
            final int stop = i * rowsPerStrip + rowsPerStrip;

            for (; y < height && y < stop; y++) {
                int bitCache = 0;
                int bitsInCache = 0;
                for (int x = 0; x < width; x++) {
                    final int rgb = src.getRGB(x, y);
                    final int red = 0xff & rgb >> 16;
                    final int green = 0xff & rgb >> 8;
                    final int blue = 0xff & rgb >> 0;

                    if (bitsPerSample == 1) {
                        int sample = (red + green + blue) / 3;
                        if (sample > 127) {
                            sample = 0;
                        } else {
                            sample = 1;
                        }
                        bitCache <<= 1;
                        bitCache |= sample;
                        bitsInCache++;
                        if (bitsInCache == 8) {
                            uncompressed[counter++] = (byte) bitCache;
                            bitCache = 0;
                            bitsInCache = 0;
                        }
                    } else if (samplesPerPixel == 4) {
                        uncompressed[counter++] = (byte) red;
                        uncompressed[counter++] = (byte) green;
                        uncompressed[counter++] = (byte) blue;
                        uncompressed[counter++] = (byte) (rgb >> 24);
                    } else {
                        // samples per pixel is 3
                        uncompressed[counter++] = (byte) red;
                        uncompressed[counter++] = (byte) green;
                        uncompressed[counter++] = (byte) blue;
                    }
                }
                if (bitsInCache > 0) {
                    bitCache <<= 8 - bitsInCache;
                    uncompressed[counter++] = (byte) bitCache;
                }
            }

            result[i] = uncompressed;
        }

        return result;
    }
Check an image to see if any of its pixels are non-opaque.

@param src a valid image
@return true if at least one non-opaque pixel is found.
src/main/java/org/apache/commons/imaging/formats/tiff/write/AbstractTiffImageWriter.java