/* ----------------------------------------------------------------------------
 * This file was automatically generated by SWIG (http://www.swig.org).
 * Version 1.3.40
 *
 * Do not make changes to this file unless you know what you are doing--modify
 * the SWIG interface file instead.
 * ----------------------------------------------------------------------------- */

package com.opencv.jni;

/** image_pool is used for keeping track of a pool of native images.  It stores images as cv::Mat's and
references them by an index.  It allows one to get a pointer to an underlying mat, and handles memory deletion.*/
public class image_pool {
    private long swigCPtr;
    protected boolean swigCMemOwn;
    public image_pool(long cPtr, boolean cMemoryOwn) {
        swigCMemOwn = cMemoryOwn;
        swigCPtr = cPtr;
    }
    public static long getCPtr(image_pool obj) {
        return (obj == null) ? 0 : obj.swigCPtr;
    }

    protected void finalize() {
        delete();
    }

    public synchronized void delete() {
        if (swigCPtr != 0) {
            if (swigCMemOwn) {
                swigCMemOwn = false;
                opencvJNI.delete_image_pool(swigCPtr);
            }
            swigCPtr = 0;
        }
    }

    public image_pool() {
        this(opencvJNI.new_image_pool(), true);
    }


    /** gets a pointer to a stored image, by an index.  If the index is new, returns a null pointer
    	* @param idx the index in the pool that is associated with a cv::Mat
    	* @return the pointer to a cv::Mat, null pointer if the given idx is novel
      */
    public PtrMat getImage(int i) {
        return new PtrMat(opencvJNI.image_pool_getImage(swigCPtr, this, i), true);
    }

    public void addImage(int i, PtrMat mat) {
        opencvJNI.image_pool_addImage(swigCPtr, this, i, PtrMat.getCPtr(mat), mat);
    }

}
