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

#ifndef DJ_IMAGE_IO_TIFF_IO_H
#define DJ_IMAGE_IO_TIFF_IO_H
#include "base.h"
#include <djImageIo.h>

namespace djImageIoTiff {

// Image load plugin.
//
class Load : public ImageLoad {
public:

  Load();
  ~Load();
  
  const Str name() const { return djImageIoTiff::name(); }
  Plugin * copy() const { return new Load(*this); }
  const StrList extensionList() const { return djImageIoTiff::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;
  TIFF * _f;
  Header _header;
  Pixel _pixel;
};

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

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

  enum COMPRESS { COMPRESS_NONE, COMPRESS_RLE, COMPRESS_LZW };
  enum CHANNELS { INTERLEAVE, PLANAR };
  enum ATTR { ATTR_COMPRESS, ATTR_CHANNELS };
  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;
  CHANNELS _channels;
  FileInfo _fileInfo;
  TIFF * _f;
  Header _header;
};

// Labels.
//
inline const StrList compressStr()
  { return StrList() + Str("None") + Str("RLE") + Str("LZW"); }
inline const StrList channelsStr()
  { return StrList() + Str("Interleave") + Str("Planar"); }
inline const StrList saveAttrStr()
  { return StrList() + Str("Compress") + Str("Channels"); }

}

#endif
