@Override
    public void writeImage(final BufferedImage src, final OutputStream os, final PnmImagingParameters params) throws ImagingException, IOException {
        PnmWriter writer = null;
        boolean useRawbits = true;

        if (params != null) {
            useRawbits = params.isRawBits();

            final ImageFormats subtype = params.getSubtype();
            if (subtype != null) {
                switch (subtype) {
                case PBM:
                    writer = new PbmWriter(useRawbits);
                    break;
                case PGM:
                    writer = new PgmWriter(useRawbits);
                    break;
                case PPM:
                    writer = new PpmWriter(useRawbits);
                    break;
                case PAM:
                    writer = new PamWriter();
                    break;
                default:
                    // see null-check below
                    break;
                }
            }
        }

        if (writer == null) {
            writer = new PaletteFactory().hasTransparency(src) ? new PamWriter() : new PpmWriter(useRawbits);
        }

        writer.writeImage(src, os, params);
    }
Constructs a new instance with the little-endian byte order.
src/main/java/org/apache/commons/imaging/formats/pnm/PnmImageParser.java