/*------------------------------------------------------------------------------
 src/lib/djImage/djImageOpCore.h
 
 Copyright (c) 2004-2006 Darby Johnston.
 All rights reserved.
 Use is subject to license terms.
------------------------------------------------------------------------------*/

#ifndef DJ_IMAGE_OP_CORE_H
#define DJ_IMAGE_OP_CORE_H
#include <djImageOp.h>

namespace dj {

// Image copy operation.
//
class ImageOpCopy : public ImageOp1 {
public:

  const Str name() const { return "Copy"; }
  Plugin * copy() const { return new ImageOpCopy(*this); }
  
  const Image work(const InputList &) const;
};

// Image crop operation.
//
class ImageOpCrop : public ImageOp1 {
public:

  ImageOpCrop();
  
  const Str name() const { return "Crop"; }
  Plugin * copy() const { return new ImageOpCrop(*this); }
  
  enum ATTR { ATTR_AREA };
  const StrList attrNameList() const;
  bool attr(const Str &, const StrList &);
  const StrList attr(const Str &) const;
  
  const PixelDataInfo info(const InfoList &) const;
  const Image work(const InputList &) const;

  static const PixelDataInfo info(const PixelDataInfo &, const Box2i &);
  static const Image work(const Image &, const Box2i &);

private:

  Box2i _area;
};

// Image convert operation.
//
class ImageOpConvert : public ImageOp1 {
public:

  const Str name() const { return "Convert"; }
  Plugin * copy() const { return new ImageOpConvert(*this); }
  
  enum ATTR { ATTR_PIXEL };
  const StrList attrNameList() const;
  bool attr(const Str &, const StrList &);
  const StrList attr(const Str &) const;

  const PixelDataInfo info(const InfoList &) const;
  const Image work(const InputList &) const;

  static const PixelDataInfo info(const PixelDataInfo &, const Pixel &);
  static const Image work(const Image &, const Pixel &);

private:

  Pixel _pixel;
};

// Image channel operations.
//
class ImageOpChannel : public ImageOp1 {
public:

  ImageOpChannel();

  const Str name() const { return "Channel"; }
  Plugin * copy() const { return new ImageOpChannel(*this); }
  
  enum ATTR { ATTR_CHANNEL };
  const StrList attrNameList() const;
  bool attr(const Str &, const StrList &);
  const StrList attr(const Str &) const;

  const PixelDataInfo info(const InfoList &) const;
  const Image work(const InputList &) const;

  static const PixelDataInfo info(const PixelDataInfo &);
  static const Image work(const Image &, int channel);

private:

  int _channel;
};

// Utility.
//
inline const List<ImageOp *> imageOpCoreList()
{
  List<ImageOp *> out;
  out += new ImageOpCopy;
  out += new ImageOpCrop;
  out += new ImageOpConvert;
  out += new ImageOpChannel;
  return out;
}

// Labels.
//
inline const StrList imageOpCropAttrStr()
  { return StrList() + Str("Area"); }
inline const StrList imageOpConvertAttrStr()
  { return StrList() + Str("Pixel"); }
inline const StrList imageOpChannelAttrStr()
  { return StrList() + Str("Channel"); }

}

#endif
