use of it.geosolutions.imageio.plugins.jp2k.JP2KKakaduImageWriteParam in project imageio-ext by geosolutions-it.
the class NITFImageWriter method prepareJP2Image.
/**
* Encode a RenderedImage as a JP2K codestream on the specified outputFile, using the proper set of compression parameters.
*
* @param outputFile
* @param compression
* @param ri
* @throws FileNotFoundException
* @throws IOException
*/
private void prepareJP2Image(final RenderedImage ri, final File outputFile, final WriteCompression compression) throws FileNotFoundException, IOException {
JP2KKakaduImageWriter kakaduWriter = null;
try {
// TODO: Check PAN/MULTI can really be known from number of bands
final int numBands = ri.getSampleModel().getNumBands();
final boolean isMulti = numBands == 1 ? false : true;
kakaduWriter = new JP2KKakaduImageWriter(KAKADU_SPI);
kakaduWriter.setOutput(outputFile);
JP2KKakaduImageWriteParam param = NITFUtilities.getCompressionParam(kakaduWriter, compression, isMulti);
kakaduWriter.write(null, new IIOImage(ri, null, null), param);
} finally {
if (kakaduWriter != null) {
try {
kakaduWriter.dispose();
} catch (Throwable t) {
}
}
}
}
use of it.geosolutions.imageio.plugins.jp2k.JP2KKakaduImageWriteParam in project imageio-ext by geosolutions-it.
the class NITFUtilities method getCompressionParam.
/**
* Setup a proper set of JP2K writing parameters depending on the type of requested compression.
*
* @param kakaduWriter a writer instance to get default write parameters.
* @param compression the type of {@link WriteCompression} desired
* @param isMulti whether the image to be compressed is multi band or pancromatic.
* @return a {@link JP2KKakaduImageWriteParam} instance with proper writing parameters.
*/
public static JP2KKakaduImageWriteParam getCompressionParam(final JP2KKakaduImageWriter kakaduWriter, final WriteCompression compression, final boolean isMulti) {
final JP2KKakaduImageWriteParam param = (JP2KKakaduImageWriteParam) kakaduWriter.getDefaultWriteParam();
param.setsProfile(1);
if (compression.getCompression() == Compression.NUMERICALLY_LOSSLESS) {
// if (!isMulti) {
// param.setqGuard(2);
// }
}
param.setQualityLayers(compression.getQualityLayers());
param.setQualityLayersBitRates(compression.getBitRates());
param.setCompression(compression.getCompression());
param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
param.setCLevels(5);
if (compression.toString().startsWith("EPJE")) {
param.setcOrder(ProgressionOrder.RLCP);
// param.setOrgT_parts("R");
} else {
param.setcOrder(ProgressionOrder.LRCP);
// param.setOrgT_parts("L");
}
param.setTilingMode(ImageWriteParam.MODE_EXPLICIT);
param.setTiling(DEFAULT_TILE_WIDTH, DEFAULT_TILE_HEIGHT, 0, 0);
param.setOrgGen_plt(true);
param.setOrgGen_tlm(1);
param.setWriteCodeStreamOnly(true);
return param;
}
Aggregations