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

#ifndef DJ_IMAGE_H
#define DJ_IMAGE_H
#include <djPixelData.h>
#include <djColor.h>

namespace dj {

// Image tags.
//
typedef Map<Str, StrList> ImageTagList;
enum IMAGE_TAG {
  IMAGE_TAG_CREATOR, IMAGE_TAG_DESCRIPTION, IMAGE_TAG_COPYRIGHT,
  IMAGE_TAG_TIME_STAMP, IMAGE_TAG_UTC_OFFSET,
  IMAGE_TAG_KEY_CODE, IMAGE_TAG_TIME_CODE
};

// Image.
//
class Image : public PixelData {
public:

  Image();
  Image(const Image &);
  Image(const PixelDataInfo &);
  Image(const Vec2i & size, const Pixel &);
  
  // Get.
  //
  const Pixel & pixel() const { return PixelData::pixel(); }

  // Pixels.
  //
  enum EDGE { EDGE_CLIP, EDGE_CLAMP, EDGE_MIRROR };
  bool pixel(const Color &, const Vec2i &);
  bool pixel(const Color &, int x, int y);
  void pixel(const Vec2i &, Color *, EDGE = EDGE_CLIP, EDGE = EDGE_CLIP) const;
  void pixel(int x, int y, Color *, EDGE = EDGE_CLIP, EDGE = EDGE_CLIP) const;
  
  // Information.
  //
  void proxy(int);
  void tagList(const ImageTagList &);
  int proxy() const { return _proxy; }
  const ImageTagList & tagList() const { return _tagList; }

private:

  void pixel(const Pixel &) {}
  
  int _proxy;
  ImageTagList _tagList;
};

// Functions.
//
int imageEdge(int, int size, Image::EDGE = Image::EDGE_CLIP);
int imageProxyScale(int proxy);

// Conversion.
//
const Str keyCodeToStr(int id, int type, int prefix, int count, int offset);
const Str timeCodeToStr(uint32_t);
bool strToKeyCode(
  const Str &,
  int * id, int * type, int * prefix, int * count, int * offset
);
uint32_t strToTimeCode(const Str &);

// Labels.
//
inline const StrList imageTagStr()
  { return StrList() + Str("Creator") + Str("Description") + Str("Copyright") +
      Str("Time Stamp") + Str("UTC Offset") + Str("Key Code") +
      Str("Time Code"); }
inline const StrList imageEdgeStr()
  { return StrList() + Str("Clip") + Str("Clamp") + Str("Mirror"); }

// Debugging.
//
Dbg & operator << (Dbg &, Image::EDGE);
Dbg & operator << (Dbg &, const Image &);

}

#endif
