Newer
Older
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#ifndef _GVIEW_H
#define _GVIEW_H
/*
* Graphical colormap editor
*/
#include <GL/gl.h> /* for GLuint */
#include <stdlib.h>
#include <stdio.h>
#include <FL/Fl.H>
#include <FL/Fl_Gl_Window.H>
#define CMENTMAX 10000
extern "C" {
extern void hsb2rgb(float h, float s, float b, float *rp, float *gp, float *bp);
extern void rgb2hsb(float r, float g, float b, float *hp, float *sp, float *bp);
}
enum CMfield {
HUE, SAT, BRIGHT,
ALPHA,
RED, GREEN, BLUE
};
class CMedit : public Fl_Gl_Window {
public:
CMedit(int x, int y, int h, int w, const char *label = 0);
int cment() const { return cment_; }
void cment( int newcment );
int hsbmode;
float lerpval;
float vh[CMENTMAX], vs[CMENTMAX], vb[CMENTMAX], alpha[CMENTMAX];
float drag( int index, enum CMfield field, float value, float lerp = 1.0 );
void dragrange( int x0, int x1, enum CMfield field, float v0, float v1, float lerp = 1.0 );
float get( int index, enum CMfield field );
void getrgba( int index, float rgba[4] );
void gethsba( int index, float hsba[4] );
int fload( FILE *inf );
int fsave( FILE *outf );
void report( int x );
void reportto( void (*func)(int x, float h,float s,float b,float a, float red,float green,float blue) );
void snapshot() { /* for undo-ing */
for(int k = 0; k < CMENTMAX; k++) {
snap[0][k] = vh[k];
snap[1][k] = vs[k];
snap[2][k] = vb[k];
snap[3][k] = alpha[k];
}
snapcment_ = cment_;
}
int undo() { /* actually undo/redo */
float t;
for(int k = 0; k < CMENTMAX; k++) {
t = vh[k]; vh[k] = snap[0][k]; snap[0][k] = t;
t = vs[k]; vs[k] = snap[1][k]; snap[1][k] = t;
t = vb[k]; vb[k] = snap[2][k]; snap[2][k] = t;
t = alpha[k]; alpha[k] = snap[3][k]; snap[3][k] = t;
}
int i = cment_; cment_ = snapcment_; snapcment_ = i;
redraw();
return 1;
}
virtual void draw();
virtual int handle(int ev);
virtual void resize(int nx, int ny, int nw, int nh) {
w(nw); h(nh); hide(); show();
}
protected:
int cment_, snapcment_;
float snap[4][CMENTMAX];
float huenear(float hue, float hueref);
float hue2y(float hue);
float y2hue(float y);
int wx2x( int wx );
float wy2y( int wy );
void (*reportfunc)(int x, float h,float s,float b,float a, float red,float green,float blue);
float hueshift, huezoom;
int remin, remax; /* repair region */
int dragfrom;
int dragamount;
enum CMfield dragfield;
float dragval;
int draghue;
int locked, lockmin, lockmax;
char **comments;
int ncomments, maxcomments;
void init() {
cment_ = snapcment_ = 256;
remin = 0; remax = cment()-1;
lerpval = 0.5;
hsbmode = 1;
dragfrom = -1; dragval = 0; dragamount = 0;
locked = 0;
lockmin = 0, lockmax = cment()-1;
hueshift = 0;
huezoom = 1;
draghue = 0;
ncomments = 0;
maxcomments = 8;
comments = (char **)malloc( maxcomments * sizeof(char *) );
for(int k = 0; k < cment_; k++) {
vh[k] = 1 - .5*k / cment_;
vs[k] = .5;
vb[k] = .25 + .75*k / cment_;
alpha[k] = .33 + .67 * k*k / (cment_*cment_);
}
snapshot();
}
};
#endif /*_GVIEW_H*/