@Test public void lossless() throws Exception { File f = File.createTempFile("test-jpeg2000-lossless", ".jp2"); f.deleteOnExit(); Iterator<ImageWriter> writers = ImageIO.getImageWritersBySuffix("jp2"); assertTrue(writers.hasNext()); ImageWriter writer = writers.next(); J2KImageWriteParam writeParams = (J2KImageWriteParam) writer.getDefaultWriteParam(); writeParams.setLossless(true); // writeParams.setFilter(J2KImageWriteParam.FILTER_53); // writeParams.setEncodingRate(64.0f); // writeParams.setCompressionMode(ImageWriteParam.MODE_EXPLICIT); // writeParams.setCompressionType("JPEG2000"); // writeParams.setCompressionQuality(1.0f); ImageOutputStream ios = ImageIO.createImageOutputStream(f); writer.setOutput(ios); writer.write(null, new IIOImage(image, null, null), writeParams); writer.dispose(); ios.close(); assertTrue("Expected file size > 128kB", f.length() > 128 * 1024); // System.out.println(f.length()); BufferedImage read = ImageIO.read(f); assertEquals(SIZE, read.getWidth()); }
/** Constructor to set locales. */ public J2KImageWriteParamJava(IIOImage image, ImageWriteParam param) { super(param.getLocale()); if (image != null) { if (image.hasRaster()) setDefaults(image.getRaster()); else setDefaults(image.getRenderedImage()); } setSourceRegion(param.getSourceRegion()); setSourceBands(param.getSourceBands()); try { setTiling( param.getTileWidth(), param.getTileHeight(), param.getTileGridXOffset(), param.getTileGridYOffset()); } catch (IllegalStateException e) { // tileing is not set do nothing. } setDestinationOffset(param.getDestinationOffset()); setSourceSubsampling( param.getSourceXSubsampling(), param.getSourceYSubsampling(), param.getSubsamplingXOffset(), param.getSubsamplingYOffset()); setDestinationType(param.getDestinationType()); J2KImageWriteParam j2kParam; if (param instanceof J2KImageWriteParam) { j2kParam = (J2KImageWriteParam) param; } else { j2kParam = new J2KImageWriteParam(); } setDecompositionLevel("" + j2kParam.getNumDecompositionLevels()); setEncodingRate(j2kParam.getEncodingRate()); setLossless(j2kParam.getLossless()); setFilters(j2kParam.getFilter()); setEPH("" + j2kParam.getEPH()); setSOP("" + j2kParam.getSOP()); setProgressionName(j2kParam.getProgressionType()); int[] size = j2kParam.getCodeBlockSize(); setCodeBlockSize("" + size[0] + " " + size[1]); enableCT = j2kParam.getComponentTransformation(); setComponentTransformation("" + enableCT); }