/*------------------------------------------------------------------------------
 src/bin/djview/base.cxx

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

//#define DJ_DBG
#include "base.h"
#include "app.h"
#include <djMath.h>
#include <djPixel.h>
#include <djImageOpStack.h>

namespace djview {

void imageOpDefault()
{
  ImageOpStack & imageOpStack = djviewApp->imageOpStack();
  
  imageOpStack.stackNew("Channel #0");
  imageOpStack.stackNew("Channel #1");
  imageOpStack.stackNew("Channel #2");
  imageOpStack.stackNew("Channel #3");
  imageOpStack.stackNew("Gamma");
  imageOpStack.stackNew("Levels");
  imageOpStack.stackNew("Brightness / Contrast");
  imageOpStack.stackNew("Saturation / Hue");
    
  imageOpStack.opNew("Channel", 0);
  imageOpStack.opNew("Channel", 1);
  imageOpStack.opNew("Channel", 2);
  imageOpStack.opNew("Channel", 3);
  imageOpStack.opNew("Gamma", 4);
  imageOpStack.opNew("Levels In", 5);
  imageOpStack.opNew("Levels Out", 5);
  imageOpStack.opNew("Brightness", 6);
  imageOpStack.opNew("Contrast", 6);
  imageOpStack.opNew("Saturation", 7);
  imageOpStack.opNew("Hue", 7);

  imageOpStack.stack(0)[0]->attr("Channel", deflateStr(0));
  imageOpStack.stack(1)[0]->attr("Channel", deflateStr(1));
  imageOpStack.stack(2)[0]->attr("Channel", deflateStr(2));
  imageOpStack.stack(3)[0]->attr("Channel", deflateStr(3));
  imageOpStack.stack(4)[0]->attr("Value", deflateStr(Color(2.2)));
  imageOpStack.stack(5)[0]->attr("Value", deflateStr(Color(0.25)));
  imageOpStack.stack(5)[0]->attr("Value 2", deflateStr(Color(0.75)));
  imageOpStack.stack(6)[0]->attr("Value", deflateStr(Color(2.0)));
  imageOpStack.stack(7)[0]->attr("Value", deflateStr(Color(2.0)));
}

int playbackFrame(
  int in,
  int start, int end,
  bool inPoint, bool outPoint,
  int inFrame, int outFrame,
  bool wrap
) {
  const int x = inPoint ? inFrame : start;
  const int y = outPoint ? outFrame : end;
  return wrap ? dj::wrap(in, x, y) : clamp(in, x, y);
}

}
