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

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

namespace dj {

ImageOpSolid::ImageOpSolid()
{
  _size = Vec2i(500, 500);
  _pixel = Pixel(PIXEL_RGB, PIXEL_U8);
  _color = Color(0.5);
}

const StrList ImageOpSolid::attrNameList() const
  { return imageOpSolidAttrStr(); }

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

const StrList ImageOpSolid::attr(const Str & in) const
{
  StrList out;
  if (compareCase(attrNameList()[ATTR_SIZE], in))
    out += deflateStr(_size);
  else if (compareCase(attrNameList()[ATTR_PIXEL], in))
    out += deflateStr(_pixel);
  else if (compareCase(attrNameList()[ATTR_COLOR], in))
    out += deflateStr(_color);
  return out;
}

const PixelDataInfo ImageOpSolid::info(const InfoList &) const
{
  return PixelDataInfo(_size, _pixel);
}

const Image ImageOpSolid::work(const InputList &) const
{
  return work(_size, _pixel, _color);
}

const Image ImageOpSolid::work(
  const Vec2i & size, const Pixel & pixel, const Color & color
) {
  DJ_DBG_FNC("dj::ImageOpSolid::work");
  DJ_DBG_PRN("size = " << size);
  DJ_DBG_PRN("pixel = " << pixel);
  DJ_DBG_PRN("color = " << color);
  
  // Setup.
  //
  Image out(size, pixel);
  Color tmp(pixel);
  convert(color, &tmp);

  // Work.
  //
  const int w = size.x(), h = size.y();
  for (int x = 0; x < w && h; ++x)
    out.pixel(tmp, x, 0);
  for (int y = 1; y < h; ++y)
    pixelCopy(out.data(0, 0), out.data(0, y), w, pixel, pixel);
  return out;
}

}
