1 /***************************************************************************
2 * *
3 * copyright : (C) 2007 The University of Toronto *
4 * netterfield@astro.utoronto.ca *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
10 * *
11 ***************************************************************************/
12
13 // application specific includes
14 #include "palette.h"
15 #include <QVector>
16 #include <qapplication.h>
17 #include <math_kst.h>
18 #include "builtinpalettes.h"
19
20 namespace Kst {
21
22
getPaletteList()23 QStringList Palette::getPaletteList() {
24 QStringList paletteList;
25
26 paletteList.append(KstGrayscaleName);
27 paletteList.append(RedTempName);
28 paletteList.append(SpectrumName);
29 paletteList.append(EosAName);
30 paletteList.append(EosBName);
31 paletteList.append(KstColorsName);
32 paletteList.append(CycleName);
33 paletteList.append(HotColdName);
34
35 //TODO: support loading palettes from disk.
36
37 return paletteList;
38 }
39
Palette()40 Palette::Palette(): _colors(0), _count(0) {
41 changePaletteName(DefaultPalette);
42 }
43
44
Palette(const QString & paletteName)45 Palette::Palette(const QString &paletteName): _colors(0), _count(0) {
46 changePaletteName(paletteName);
47 }
48
~Palette()49 Palette::~Palette() {
50 delete[] _colors;
51 delete[] _rgb;
52 _colors = 0;
53 _count = 0;
54 }
55
changePaletteName(const QString & paletteName)56 void Palette::changePaletteName(const QString &paletteName) {
57
58 if (_count==0) {
59 _colors = new QColor[2048];
60 _rgb = new QRgb[2048];
61 }
62
63 if (paletteName.isEmpty()) {
64 _paletteName = KstColorsName;
65 } else {
66 _paletteName = paletteName;
67 }
68
69 if (_paletteName == KstColorsName) {
70 for (int i = 0; i < KstColorsCount; i++) {
71 _colors[i] = QColor(KstColors[i]);
72 _rgb[i] = _colors[i].rgb();
73 }
74 _count = KstColorsCount;
75 } else if (_paletteName == RedTempName) {
76 for (int i = 0; i < RedTempCount; i++) {
77 _colors[i] = QColor(RedTemp[i][0], RedTemp[i][1], RedTemp[i][2]);
78 _rgb[i] = _colors[i].rgb();
79 }
80 _count = RedTempCount;
81 } else if (_paletteName == HotColdName) {
82 for (int i = 0; i < HotColdCount; i++) {
83 _colors[i] = QColor(HotCold[i][0], HotCold[i][1], HotCold[i][2]);
84 _rgb[i] = _colors[i].rgb();
85 }
86 _count = HotColdCount;
87 } else if (_paletteName == SpectrumName) {
88 for (int i = 0; i < SpectrumCount; i++) {
89 _colors[i] = QColor(Spectrum[i][0], Spectrum[i][1], Spectrum[i][2]);
90 _rgb[i] = _colors[i].rgb();
91 }
92 _count = SpectrumCount;
93 } else if (_paletteName == EosAName) {
94 for (int i = 0; i < EosACount; i++) {
95 _colors[i] = QColor(EosA[i][0], EosA[i][1], EosA[i][2]);
96 _rgb[i] = _colors[i].rgb();
97 }
98 _count = EosACount;
99 } else if (_paletteName == EosBName) {
100 for (int i = 0; i < EosBCount; i++) {
101 _colors[i] = QColor(EosB[i][0], EosB[i][1], EosB[i][2]);
102 _rgb[i] = _colors[i].rgb();
103 }
104 _count = EosBCount;
105 } else if (_paletteName == CycleName) {
106 for (int i = 0; i < CycleCount; i++) {
107 _colors[i] = QColor(Cycle[i][0], Cycle[i][1], Cycle[i][2]);
108 _rgb[i] = _colors[i].rgb();
109 }
110 _count = CycleCount;
111 } else {
112 for (int i = 0; i < KstGrayscaleCount; i++) {
113 _colors[i] = QColor(i, i, i);
114 _rgb[i] = _colors[i].rgb();
115 }
116 _count = KstGrayscaleCount;
117 }
118 }
119
120 }
121 // vim: ts=2 sw=2 et
122