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

//#define DJ_DBG
#include "djImageOp.h"
#include <dlfcn.h>

namespace dj {

ImageOp::~ImageOp() {}

const PixelDataInfo ImageOp::workInfo(const InputList & in) const
{
  InfoList tmp;
  dj::copy(in, &tmp);
  return info(tmp);
}

ImageOp1::~ImageOp1() {}

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

ImageOp2::~ImageOp2() {}

ImageOpFactory::~ImageOpFactory()
{
  del();
}

ImageOp * ImageOpFactory::pluginCopy(const Str & in)
{
  for (ListIt<ImageOp *> it = _pluginList; it.isValid(); ++it)
    if (lowercase(in) == lowercase(it()->name()))
      return static_cast<ImageOp *>(it()->copy());
  return 0;
}

void ImageOpFactory::pluginAdd(const List<ImageOp *> & in)
{
  _pluginList += in;
}

bool ImageOpFactory::init(void * in)
{
  ImageOpFnc * fnc = (ImageOpFnc *)dlsym(in, "djImageOp");
  if (! fnc) return false;
  _pluginList += fnc();
  return true;
}

void ImageOpFactory::del()
{
  DJ_DBG_FNC("dj::ImageOpFactory::del");

  for (ListIt<ImageOp *> it = _pluginList; it.isValid(); ++it) delete it();
  _pluginList.del();
  PluginFactory::del();
}

const StrList pluginNameList(const List<ImageOp *> & in)
{
  StrList out;
  for (ConstListIt<ImageOp *> it = in; it.isValid(); ++it)
    out += it()->name();
  return out;
}

}
