summaryrefslogtreecommitdiffstats
path: root/tksao/frame/colorscalergb.C
blob: 96dc0a42d285013f0c74b1a16e05f932d6b8be69 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
// Copyright (C) 1999-2017
// Smithsonian Astrophysical Observatory, Cambridge, MA, USA
// For conditions of distribution and use, see copyright notice in "copyright"

#include "colorscalergb.h"

ColorScaleRGB::ColorScaleRGB(int s)
{
  size_ = s;
  psColors_ = new unsigned char[s];

  memset(psColors_, '0', size_);
}

ColorScaleRGB::~ColorScaleRGB()
{
  if (psColors_)
    delete [] psColors_;
}

LinearScaleRGB::LinearScaleRGB(int jj, int ss, unsigned char* colorCells, 
			       int count) 
  : ColorScaleRGB(ss)
{
  for (int ii=0; ii<ss; ii++) {
    double aa = double(ii)/ss;
    int ll = (int)(aa * count);
    memcpy(psColors_+ii, colorCells+ll*3+jj,1);
  }
}

LogScaleRGB::LogScaleRGB(int jj, int ss, unsigned char* colorCells, 
			 int count, double exp)
  : ColorScaleRGB(ss)
{
  for (int ii=0; ii<ss; ii++) {
    double aa = log10(exp*double(ii)/ss +1) / log10(exp);
    int ll = (int)(aa * count);
    // aa can grow slightly greater than 1
    if (ll>=count)
      ll = count-1;
    memcpy(psColors_+ii, colorCells+ll*3+jj,1);
  }
}

PowScaleRGB::PowScaleRGB(int jj, int ss, unsigned char* colorCells, 
			 int count, double exp)
  : ColorScaleRGB(ss)
{
  for (int ii=0; ii<ss; ii++) {
    double aa = (::pow(exp,double(ii)/ss) -1) / exp;
    int ll = (int)(aa * count);
    // should not be needed
    if (ll>=count)
      ll = count-1;
    memcpy(psColors_+ii, colorCells+ll*3+jj,1);
  }
}

SqrtScaleRGB::SqrtScaleRGB(int jj, int ss, unsigned char* colorCells, int count)
  : ColorScaleRGB(ss)
{
  for(int ii=0; ii<ss; ii++) {
    double aa = double(ii)/ss;
    int ll = (int)(sqrt(aa) * count);
    memcpy(psColors_+ii, colorCells+ll*3+jj,1);
  }
}

SquaredScaleRGB::SquaredScaleRGB(int jj, int ss, unsigned char* colorCells, 
				 int count) 
  : ColorScaleRGB(ss)
{
  for(int ii=0; ii<ss; ii++) {
    double aa = double(ii)/ss;
    int ll = (int)(aa*aa * count);
    memcpy(psColors_+ii, colorCells+ll*3+jj,1);
  }
}

AsinhScaleRGB::AsinhScaleRGB(int jj, int ss, unsigned char* colorCells, 
			     int count) 
  : ColorScaleRGB(ss)
{
  for(int ii=0; ii<ss; ii++) {
    double aa = double(ii)/ss;
    int ll = (int)(asinh(10*aa)/3 * count);
    memcpy(psColors_+ii, colorCells+ll*3+jj,1);
  }
}

SinhScaleRGB::SinhScaleRGB(int jj, int ss, unsigned char* colorCells, 
			   int count) 
  : ColorScaleRGB(ss)
{
  for(int ii=0; ii<ss; ii++) {
    double aa = double(ii)/ss;
    int ll = (int)(sinh(3*aa)/10 * count);
    memcpy(psColors_+ii, colorCells+ll*3+jj,1);
  }
}

HistEquScaleRGB::HistEquScaleRGB(int jj, int ss, unsigned char* colorCells, 
				 int count, double* hist, int histsize)
  : ColorScaleRGB(ss)
{
  // if no histogram, return linear distribution
  if (!hist)
    for (int ii=0; ii<ss; ii++) {
      double aa = double(ii)/ss;
      int ll = (int)(aa * count);
      memcpy(psColors_+ii, colorCells+ll*3+jj,1);
    }
  else
    for (int ii=0; ii<ss; ii++) {
      double aa = hist[ii*histsize/ss];
      int ll = (int)(aa * count);
      memcpy(psColors_+ii, colorCells+ll*3+jj,1);
    }
}