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

//#define DJ_DBG
#include "djImageOpCore.h"

namespace dj {

const StrList ImageOpConvert::attrNameList() const
  { return imageOpConvertAttrStr(); }

bool ImageOpConvert::attr(const Str & in, const StrList & data)
{
  StrList tmp = data;
  if (compareCase(attrNameList()[ATTR_PIXEL], in)) {
    if (! inflateStr(tmp, &_pixel)) return false;
  } else
    return false;
  return true;
}

const StrList ImageOpConvert::attr(const Str & in) const
{
  StrList out;
  if (compareCase(attrNameList()[ATTR_PIXEL], in))
    out += deflateStr(_pixel);
  return out;
}

const PixelDataInfo ImageOpConvert::info(const InfoList & in) const
{
  return in.size() ? info(*in[0], _pixel) : PixelDataInfo();
}

const PixelDataInfo ImageOpConvert::info(
  const PixelDataInfo & in, const Pixel & pixel
) {
  return PixelDataInfo(in.size(), pixel);
}

const Image ImageOpConvert::work(const InputList & in) const
{
  return in.size() ? work(*in[0], _pixel) : Image();
}

const Image ImageOpConvert::work(const Image & in, const Pixel & pixel)
{
  DJ_DBG_FNC("dj::ImageOpConvert::work");
  DJ_DBG_PRN("in = " << in);
  DJ_DBG_PRN("pixel = " << pixel);

  // Setup.
  //
  Image out(info(in, pixel));
  out.proxy(in.proxy());
  out.tagList(in.tagList());
  
  // Work.
  //
  pixelCopy(in, &out);

  return out;
}

}
