Search in sources :

Example 1 with Kdu_params

use of kdu_jni.Kdu_params in project imageio-ext by geosolutions-it.

the class JP2KKakaduImageWriter method initializeCodestream.

/**
 * Initialize the codestream params in compliance with the provided arguments.
 *
 * @param codeStream
 *                the output codestream
 * @param ycc
 *                the cycc parameter
 * @param cLevels
 *                the number of DWT decomposition levels
 * @param quality
 *                the quality factor (in the range 0.01 - 1. where 1 = LOSSLESS)
 * @param qualityLayers
 *                the number of quality layers
 * @param colorModel
 *                the input image's colorModel
 * @param writeCodeStreamOnly
 *                <code>true</code> if we need to write only codestream.
 * @param target
 *                the optional {@link Jp2_target} object in case we are
 *                writing only codestream.
 * @param orgGen_plt
 *                if {@code true}, request the insertion of packet length information
 *                in the header of tile-parts.
 * @param orgGen_tlm
 *                the Tile-part-lenght (TLM) marker marker segments in the main header.
 * @param orgT_parts
 *                parameter setting the division of each tile's packets into tile-parts
 * @param qGuard
 *                parameter setting the guard bits
 * @param cOrder
 *                the {@link ProgressionOrder} to be used.
 * @param cPrecincts
 *                the optional Precincts settings
 * @return {@code false} in case we aren't writing codestream only
 *         and a proper {@link Jp2_target} haven't been provided
 *
 * @throws KduException
 */
private boolean initializeCodestream(final Kdu_codestream codeStream, final boolean ycc, final int cLevels, final double quality, final int qualityLayers, final ColorModel colorModel, final boolean writeCodeStreamOnly, final int dataType, final Jp2_target target, final byte[] geoJp2, final boolean orgGen_plt, final int orgGen_tlm, final String orgT_parts, final int qGuard, final ProgressionOrder cOrder, final String cPrecincts, final Compression compression) throws KduException {
    final Siz_params params = codeStream.Access_siz();
    // //
    if (compression != null && compression == Compression.LOSSY) {
        params.Parse_string("Creversible=no");
    } else if (quality == 1 || colorModel instanceof IndexColorModel) {
        params.Parse_string("Creversible=yes");
    } else {
        params.Parse_string("Creversible=no");
    }
    if (cPrecincts != null && cPrecincts.trim().length() > 0) {
        params.Parse_string("Cuse_precincts=yes");
        params.Parse_string("Cprecincts=" + cPrecincts);
    }
    params.Parse_string("Cycc=" + (ycc ? "yes" : "no"));
    params.Parse_string("Clevels=" + cLevels);
    params.Parse_string("Clayers=" + qualityLayers);
    if (dataType == DataBuffer.TYPE_SHORT || dataType == DataBuffer.TYPE_USHORT) {
        params.Parse_string("Qstep=0.0000152588");
    }
    if (qGuard > 0) {
        params.Parse_string("Qguard=" + qGuard);
    }
    // //
    // 
    // Setting ORG_params
    // 
    // //
    Kdu_params org = params.Access_cluster(Kdu_global.ORG_params);
    if (orgGen_plt) {
        org.Set("ORGgen_plt", 0, 0, true);
    }
    if (orgGen_tlm != JP2KKakaduImageWriteParam.UNSPECIFIED_ORG_GEN_TLM) {
        org.Set("ORGgen_tlm", 0, 0, orgGen_tlm);
    }
    if (orgT_parts != null && orgT_parts.length() > 0) {
        org.Parse_string("ORGt_parts=" + orgT_parts);
    }
    // //
    // 
    // Setting COD_params
    // 
    // //
    Kdu_params cod = params.Access_cluster(Kdu_global.COD_params);
    if (cOrder != null) {
        cod.Set("Corder", 0, 0, cOrder.getValue());
    }
    // //
    // 
    // Finalizing params
    // 
    // //
    params.Finalize_all();
    if (!writeCodeStreamOnly) {
        if (target == null) {
            return false;
        }
        // //
        // 
        // Writing header
        // 
        // //
        initializeHeader(target, params, colorModel);
        if (geoJp2 != null && geoJp2.length > 0) {
            // Add geoJP2 box here.
            // This is a quick solution. The ideal would be to leverage on metadata or on top of a better
            // set of entities/helpers
            target.Open_next(UUIDBox.BOX_TYPE);
            byte[] outByte = new byte[GEOJP2_UUID.length];
            for (int i = 0; i < GEOJP2_UUID.length; i++) {
                outByte[i] = (byte) GEOJP2_UUID[i];
            }
            target.Write(outByte, GEOJP2_UUID.length);
            target.Write(geoJp2, geoJp2.length);
            target.Close();
        }
        target.Open_codestream();
    }
    return true;
}
Also used : Siz_params(kdu_jni.Siz_params) Kdu_params(kdu_jni.Kdu_params) IndexColorModel(java.awt.image.IndexColorModel)

Aggregations

IndexColorModel (java.awt.image.IndexColorModel)1 Kdu_params (kdu_jni.Kdu_params)1 Siz_params (kdu_jni.Siz_params)1