// Copyright (C) 1999-2015
// Smithsonian Astrophysical Observatory, Cambridge, MA, USA
// For conditions of distribution and use, see copyright notice in "copyright"

#ifndef __frscale_h__
#define __frscale_h__

#include <stdlib.h>
#include <string.h>

#include <iostream>
using namespace std;

class FitsImage;

class FrScale {
 public:
  enum ColorScaleType {LINEARSCALE, 
		       LOGSCALE, POWSCALE, 
		       SQRTSCALE, SQUAREDSCALE, 
		       ASINHSCALE, SINHSCALE,
		       HISTEQUSCALE, IISSCALE};
  enum ClipScope {GLOBAL, LOCAL};
  enum ClipMode {MINMAX, ZSCALE, ZMAX, AUTOCUT, USERCLIP};
  enum MinMaxMode {SCAN, DATAMIN, IRAFMIN};
  enum ScanMode {IMGSEC, DATASEC, CROPSEC};

 private:
  ColorScaleType colorScaleType_; // color scale type
  ClipScope clipScope_;       // color scale clip scope
  ClipMode clipMode_;         // color scale clip mode
  MinMaxMode mmMode_;         // method to use for determining minmax
  double low_;                // low cut level for all data
  double high_;               // high cut level for all data
  double min_;                // min for all data
  double max_;                // max for all data
  double uLow_;               // low cut via user for all data
  double uHigh_;              // high cut via user for all data
  float expo_;                // log scale exponent
  float zContrast_;           // zscale slope transfer function
  int zSample_;               // zscale optimal sample size
  int zLine_;                 // zscale number of lines to sample
  float autoCutPer_;          // autoCut percentage
  ScanMode scanMode_;         // use keyword DATASEC			  

  double* histequ_;           // image histogram equalization xfer function
  int histequSize_;

  double* histogramX_;        // scale histogram
  double* histogramY_;        // scale histogram
  int histogramSize_;

  int datasec_;

 public:
  FrScale();
  ~FrScale();
  FrScale(const FrScale&);
  FrScale& operator=(const FrScale&);

  ColorScaleType colorScaleType() {return colorScaleType_;}
  ClipScope clipScope() {return clipScope_;}
  ClipMode clipMode() {return clipMode_;}
  MinMaxMode mmMode() {return mmMode_;}
  double low() {return low_;}
  double high() {return high_;}
  double min() {return min_;}
  double max() {return max_;}
  double uLow() {return uLow_;}
  double uHigh() {return uHigh_;}
  float expo() {return expo_;}
  float zContrast() {return zContrast_;}
  int zSample() {return zSample_;}
  int zLine() {return zLine_;}
  float autoCutPer() {return autoCutPer_;}
  ScanMode scanMode() {return scanMode_;}
  double* histogramX() {return histogramX_;}
  double* histogramY() {return histogramY_;}
  int datasec() {return datasec_;}
  
  void setColorScaleType(ColorScaleType v) {colorScaleType_ = v;}
  void setClipScope(ClipScope v) {clipScope_ = v;}
  void setClipMode(ClipMode v) {clipMode_ = v;}
  void setMMMode(MinMaxMode v) {mmMode_ = v;}
  void setLow(double v) {low_ = v;}
  void setHigh(double v) {high_ = v;}
  void setMin(double v) {min_ = v;}
  void setMax(double v) {max_ = v;}
  void setULow(double v) {uLow_ = v;}
  void setUHigh(double v) {uHigh_ = v;}
  void setExpo(float e) {expo_ = e>10 ? e : 10;}
  void setZContrast(float v) {zContrast_ = v;}
  void setZSample(int v) {zSample_ = v;}
  void setZLine(int v) {zLine_ = v;}
  void setAutoCutPer(float v) {autoCutPer_ = v;}

  void setScanMode(ScanMode v) {scanMode_ = v;}
  void resetScanMode() {scanMode_ = datasec_ ? DATASEC : IMGSEC;}
  void setDataSec(int d) {datasec_ = d;}

  double* histequ(FitsImage*);
  void clearHistequ();
  void histogram(FitsImage*, int);
  void clearHistogram();
};

ostream& operator<<(ostream&, FrScale&);

#endif
