Search in sources :

Example 1 with Jp2_input_box

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

the class JP2KFileWalker method init.

/**
 * Parses this file into a {@link TreeModel} object.
 */
private void init() {
    if (this.initialized)
        return;
    // //
    // 
    // create needed kakadu machinery
    // 
    // //
    familySource = new Jp2_family_src();
    final Jp2_input_box inputBox = new Jp2_input_box();
    final Jp2_locator locator = new Jp2_locator();
    List<? extends Throwable> exceptions = Collections.emptyList();
    try {
        // open the family
        familySource.Open(fileName);
        // create the needed objects
        final JP2KFileBox box = new JP2KFileBox();
        this.tree = new DefaultTreeModel(box);
        // Add a listener: a new instance of a JP2KTreeController on the tree
        final JP2KTreeController controller = new JP2KTreeController(this.tree);
        this.tree.addTreeModelListener(controller);
        // recursive parsing
        if (inputBox.Open(familySource, locator)) {
            parse(inputBox, box, 0);
        }
        controller.checkTreeConsistency();
        // clean up
        inputBox.Close();
    } catch (KduException e) {
        throw new RuntimeException("Error caused by a Kakadu exception during Box management! ", e);
    } finally {
        // clean up
        try {
            familySource.Close();
        } catch (Exception e) {
            if (LOGGER.isLoggable(Level.FINEST))
                LOGGER.log(Level.FINEST, e.getLocalizedMessage(), e);
        }
        try {
            if (inputBox != null)
                inputBox.Close();
        } catch (Exception e) {
            if (LOGGER.isLoggable(Level.FINEST))
                LOGGER.log(Level.FINEST, e.getLocalizedMessage(), e);
        }
    }
    if (!exceptions.isEmpty()) {
        // TODO Create a specific exception that wraps them all!
        throw new IllegalStateException("Tree Check failed");
    }
}
Also used : KduException(kdu_jni.KduException) Jp2_input_box(kdu_jni.Jp2_input_box) Jp2_locator(kdu_jni.Jp2_locator) JP2KFileBox(it.geosolutions.imageio.plugins.jp2k.box.JP2KFileBox) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) Jp2_family_src(kdu_jni.Jp2_family_src) KduException(kdu_jni.KduException)

Example 2 with Jp2_input_box

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

the class JP2KFileWalker method parse.

/**
 * Parses this box, his brothers as well as his children recursively.
 *
 * @param inputBox
 *                the box to begin the parsing with.
 * @param parent
 *                the parent box to which attach this box as well as its
 *                brothers.
 * @param index
 *                the index at which this box should be attached in his
 *                father's children list.
 * @throws KduException
 *                 in case any problem with the low level machinery happens.
 */
private void parse(final Jp2_input_box inputBox, final JP2KBox parent, int index) throws KduException {
    final Jp2_input_box childBox = new Jp2_input_box();
    try {
        // //
        // 
        // get the info for this box
        // 
        // //
        final int boxtype = (int) (0xffffffff & inputBox.Get_box_type());
        final String typeString = BoxUtilities.getTypeString(boxtype);
        if (LOGGER.isLoggable(Level.FINE)) {
            LOGGER.fine("Found box " + typeString);
        }
        LazyJP2KBox currentBox = null;
        // //
        if (BoxUtilities.boxNames.containsKey(boxtype)) {
            final Jp2_locator locator = inputBox.Get_locator();
            // created a lazily loaded box
            currentBox = new LazyJP2KBox(this.fileName, boxtype, locator);
            parent.insert(currentBox, index++);
            this.tree.nodesWereInserted(parent, new int[] { index - 1 });
        } else {
            if (LOGGER.isLoggable(Level.INFO)) {
                LOGGER.info("Box of type " + typeString + " cannot be handled by this file type reader");
            }
        }
        // reopen box
        if (BoxUtilities.SUPERBOX_NAMES.contains(typeString)) {
            if (childBox.Open(inputBox)) {
                if (childBox.Exists()) {
                    parse(childBox, currentBox, 0);
                }
                // close box
                childBox.Close();
            }
        }
        // //
        // 
        // check next
        // 
        // //
        // close box
        inputBox.Close();
        if (inputBox.Open_next()) {
            if (inputBox.Exists()) {
                parse(inputBox, parent, index);
            }
        }
    } catch (KduException e) {
        throw new RuntimeException("Error caused by a Kakadu exception during Box management! ", e);
    } finally {
        // clean up
        try {
            if (childBox != null)
                childBox.Close();
        } catch (Exception e) {
            if (LOGGER.isLoggable(Level.FINEST))
                LOGGER.log(Level.FINEST, e.getLocalizedMessage(), e);
        }
        try {
            if (inputBox != null)
                inputBox.Close();
        } catch (Exception e) {
            if (LOGGER.isLoggable(Level.FINEST))
                LOGGER.log(Level.FINEST, e.getLocalizedMessage(), e);
        }
    }
}
Also used : KduException(kdu_jni.KduException) Jp2_input_box(kdu_jni.Jp2_input_box) Jp2_locator(kdu_jni.Jp2_locator) KduException(kdu_jni.KduException)

Example 3 with Jp2_input_box

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

the class LazyJP2KBox method loadBox.

private synchronized JP2KBox loadBox() {
    JP2KBox retVal = this.boxRef == null ? null : this.boxRef.get();
    if (retVal == null) {
        final Jp2_family_src familySource = new Jp2_family_src();
        final Jp2_input_box box = new Jp2_input_box();
        try {
            familySource.Open(filename);
            // //
            // 
            // Get the required Jp2_input_box using the locator
            // 
            // //
            box.Open(familySource, locator);
            retVal = BoxUtilities.createBox(type, BoxUtilities.getContent(box));
            this.boxRef = new SoftReference<JP2KBox>(retVal);
        } catch (KduException e) {
            throw new RuntimeException("Error caused by a Kakadu exception during Box management! ", e);
        } finally {
            // clean up
            try {
                familySource.Close();
            } catch (Exception e) {
                if (LOGGER.isLoggable(Level.FINEST))
                    LOGGER.log(Level.FINEST, e.getLocalizedMessage(), e);
            }
            try {
                if (box != null)
                    box.Close();
            } catch (Exception e) {
                if (LOGGER.isLoggable(Level.FINEST))
                    LOGGER.log(Level.FINEST, e.getLocalizedMessage(), e);
            }
        }
    }
    return retVal;
}
Also used : KduException(kdu_jni.KduException) Jp2_input_box(kdu_jni.Jp2_input_box) Jp2_family_src(kdu_jni.Jp2_family_src) KduException(kdu_jni.KduException)

Aggregations

Jp2_input_box (kdu_jni.Jp2_input_box)3 KduException (kdu_jni.KduException)3 Jp2_family_src (kdu_jni.Jp2_family_src)2 Jp2_locator (kdu_jni.Jp2_locator)2 JP2KFileBox (it.geosolutions.imageio.plugins.jp2k.box.JP2KFileBox)1 DefaultTreeModel (javax.swing.tree.DefaultTreeModel)1