/*------------------------------------------------------------------------------
 src/plugin/djImageIoExr/io.h
 
 Copyright (c) 2004-2006 Darby Johnston.
 All rights reserved.
 Use is subject to license terms.
------------------------------------------------------------------------------*/

#ifndef DJ_IMAGE_IO_EXR_IO_H
#define DJ_IMAGE_IO_EXR_IO_H
#include "base.h"
#include <djImageIo.h>
#include <ImfPixelType.h>

namespace Imf {
class InputFile;
class OutputFile;
}

namespace djImageIoExr {

// Image load plugin.
//
class Load : public ImageLoad {
public:
  
  Load();
  ~Load();
  
  const Str name() const { return djImageIoExr::name(); }
  Plugin * copy() const { return new Load(*this); }
  const StrList extensionList() const { return djImageIoExr::extensionList(); }

  bool open(const Str & fileName, ImageIoInfo *);
  
protected:

  bool imageOpen(const Str & fileName, ImageIoInfo *);
  bool imageBegin(int frame, ImageIoInfo *);
  bool imageGet(PixelData *, int proxyScale);

private:

  FileInfo _fileInfo;
  Imf::InputFile * _f;
  PIXEL_FORMAT _format;
  Imf::PixelType _pixelType;
};

// Image save plugin.
//
class Save : public ImageSave {
public:

  Save();
  ~Save();
  
  const Str name() const { return djImageIoExr::name(); }
  Plugin * copy() const { return new Save(*this); }
  const StrList extensionList() const { return djImageIoExr::extensionList(); }

  enum COMPRESS { COMPRESS_NONE, COMPRESS_PIZ, COMPRESS_ZIP, COMPRESS_RLE };
  enum BIT_DEPTH { BIT_DEPTH_AUTO, F16, F32 };
  enum ATTR { ATTR_COMPRESS, ATTR_BIT_DEPTH };
  const StrList attrNameList() const;
  bool attr(const Str &, const StrList &);
  const StrList attr(const Str &) const;
  
  bool open(const Str & fileName, const ImageIoInfo &);

protected:

  bool imageOpen(const Str & fileName, const Image &);
  bool imageBegin(const Image &, int frame);
  bool imageSet(const PixelData &);

private:

  PixelDataInfo _info;
  COMPRESS _compress;
  BIT_DEPTH _bitDepth;
  
  FileInfo _fileInfo;
  Imf::OutputFile * _f;
  Imf::PixelType _pixelType;
};

// Labels.
//
inline const StrList compressStr()
  { return StrList() + Str("None") + Str("PIZ") + Str("ZIP") + Str("RLE"); }
inline const StrList bitDepthStr()
  { return StrList() + Str("Auto") + Str("F16") + Str("F32"); }
inline const StrList saveAttrStr()
  { return StrList() + Str("Compress") + Str("Bit Depth"); }

}

#endif
