-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcolormap.cpp
83 lines (70 loc) · 1.56 KB
/
colormap.cpp
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
/*
* $Id: colormap.cpp,v 1.5 2003/10/14 11:29:01 inou Exp $
*/
#include <iostream>
#include "colormap.h"
#include "config.h"
using namespace QFract;
#include <qcolor.h>
#include <qstring.h>
#include <qmessagebox.h>
using namespace Qt;
#include <fstream>
using namespace std;
ColorMap::ColorMap()
{
open(DEFAULT_COLORMAP);
}
ColorMap::ColorMap(int r[NUM], int g[NUM], int b[NUM])
{
for ( int i=0; i<NUM; i++ )
rgb[i]= qRgb(r[i], g[i], b[i]);
name = QString(DEFAULT_COLORMAP);
}
ColorMap::ColorMap(int c[NUM][3])
{
for ( int i=0; i<NUM; i++ )
rgb[i]= qRgb(c[i][0], c[i][1], c[i][2]);
name = QString(DEFAULT_COLORMAP);
}
ColorMap::ColorMap(QRgb c[NUM])
{
for ( int i=0; i<NUM; i++ )
rgb[i]= c[i];
name = QString(DEFAULT_COLORMAP);
}
ColorMap::ColorMap(const char *filename)
{
open(filename);
}
ColorMap::ColorMap(const ColorMap& c)
{
for (int i=0; i<NUM; i++)
rgb[i]=c.rgb[i];
name = c.name;
}
void ColorMap::open(const char *filename)
{
ifstream input;
name = QString(filename);
char tmp[PATH_MAX];
if ((*filename != '/') && (*filename != '.') && (*(filename+1) != ':')) {
strcpy(tmp, COLORMAP_PATH);
strcat(tmp, "/");
strcat(tmp, filename);
} else {
strcpy(tmp, filename);
}
qDebug("Open colormap file: %s", tmp);
input.open(tmp);
if (!input) {
cerr << "Cannot open colormap: " << tmp << endl;
//QMessageBox::critical(0, "Error", tr("Cannot open colormap : %1.").arg(tmp));
return;
}
int r, g, b;
for (int i=0; i<NUM; i++) {
input >> r >> g >> b;
rgb[i] = qRgb(r,g,b);
}
}