#ifndef __DBIMAGE_H__
#define __DBIMAGE_H__

#include "dbtable.h"
#include "image2d.h"
#include "wltcompress.h"
#include "wavelet.h"
#include <set>

// quantization set to 2^24
#ifndef QUANTIZEFACTOR
#define QUANTIZEFACTOR 16777216
#endif

class dbimage : public dbtable
{
 public:
  struct key
  {
    int slice;
    int channel;
    int stack1;
    int stack2;
  };
  dbimage();
  virtual ~dbimage();
  virtual int close();
  virtual int init( DbEnv *env );

  /// adds an image to the database
  /**
   * @param stack1 the xcoor of the stack
   * @param stack2 the ycoor of the stack
   * @param slice the slice the image at in the stack
   * @param channel the channel the image respresents
   * @param im the image
   */
  int addimage( int stack1, int stack2, int slice,
                int channel, image2d &im );

  /// retrieve an image from a stack
  int getimage( int stackx, int stacky,
                int slice, int channel, 
                image2d &im );

  /// return list of valid slices
  int getslices( std::vector< int > &slice );

  /// return list of valid channels
  int getchannels( std::vector< int > &channel );

  /// gets the stacks for a row
  /**
   * @param stackx the row number
   */
  int rowstacks( int stackx, std::vector< int > &stacky );

  /// gets the valid rows
  int rows( std::vector< int > &stackx);

 private:
  Db *mydb_stack1idx;
  Db *mydb_stack2idx;
  Db *mydb_sliceidx;
  Db *mydb_channelidx;
};

#endif
