BufferedImage bitmap = pngTransformation(((BitmapBufferedImageImpl)inputbitmap).getImage());
// BufferedImage bitmap = ((BitmapBufferedImageImpl)inputbitmap).getImage();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
J2KImageWriter writer = (J2KImageWriter) ImageIO.getImageWritersByFormatName("jpeg2000").next();
J2KImageWriteParam iwp = (J2KImageWriteParam)writer.getDefaultWriteParam();
iwp.setLossless(lossless);
//// //list of all types, only one seems to exist
// String[] ct = iwp.getCompressionTypes();
// for(int i=0;i < ct.length; i++)
// System.out.println("compression type : "+ct[0]);
//
iwp.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
// iwp.setCompressionType(ct[0]);
// iwp.setCompressionQuality(0.01f);
//// iwp.setEncodingRate(0.01);
//TODO Experiment
iwp.setFilter(J2KImageWriteParam.FILTER_97);
iwp.setProgressionType("layer");
//Following is must to generate j2k JPEG 2000 stream
iwp.setWriteCodeStreamOnly(true);
iwp.setNumDecompositionLevels(5);
FileCacheImageOutputStream fileImageOutputStream = new FileCacheImageOutputStream(baos, null);
writer.setOutput(fileImageOutputStream);
//TODO changed
// writer.write(null, new IIOImage(bitmap, null, null), iwp);