-
Notifications
You must be signed in to change notification settings - Fork 7
/
color.h
284 lines (248 loc) · 9.88 KB
/
color.h
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
/*
** Daedalus (Version 3.5) File: color.h
** By Walter D. Pullen, Astara@msn.com, http://www.astrolog.org/labyrnth.htm
**
** IMPORTANT NOTICE: Daedalus and all Maze generation and general
** graphics routines used in this program are Copyright (C) 1998-2024 by
** Walter D. Pullen. Permission is granted to freely use, modify, and
** distribute these routines provided these credits and notices remain
** unmodified with any altered or distributed versions of the program.
** The user does have all rights to Mazes and other graphic output
** they make in Daedalus, like a novel created in a word processor.
**
** More formally: This program is free software; you can redistribute it
** and/or modify it under the terms of the GNU General Public License as
** published by the Free Software Foundation; either version 2 of the
** License, or (at your option) any later version. This program is
** distributed in the hope that it will be useful and inspiring, but
** WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
** General Public License for more details, a copy of which is in the
** LICENSE.HTM included with Daedalus, and at http://www.gnu.org
**
** This file contains definitions for general graphics routines, that operate
** on a color bitmap, unrelated to Mazes.
**
** Old last code change: 6/29/1990.
** Last code change: 10/30/2024.
*/
/*
******************************************************************************
** Constants
******************************************************************************
*/
#define xColmap ((lHighest - 3) / 3)
#define yColmap lHighest
#define cColorMain 16
#define cColor 29
#define kvBlack Rgb( 0, 0, 0)
#define kvMaroon Rgb(127, 0, 0)
#define kvDkGreen Rgb( 0, 127, 0)
#define kvMaize Rgb(127, 127, 0)
#define kvDkBlue Rgb( 0, 0, 127)
#define kvPurple Rgb(127, 0, 127)
#define kvDkCyan Rgb( 0, 127, 127)
#define kvLtGray Rgb(191, 191, 191)
#define kvGray Rgb(127, 127, 127)
#define kvRed Rgb(255, 0, 0)
#define kvGreen Rgb( 0, 255, 0)
#define kvYellow Rgb(255, 255, 0)
#define kvBlue Rgb( 0, 0, 255)
#define kvMagenta Rgb(255, 0, 255)
#define kvCyan Rgb( 0, 255, 255)
#define kvWhite Rgb(255, 255, 255)
#define kvDkGray Rgb( 63, 63, 63)
#define kvOrange Rgb(255, 127, 0)
#define kvPink Rgb(255, 127, 127)
#define kvBrown Rgb(127, 63, 0)
#define nHueMax 3600
#define nHueHalf 1800
#define nHue13 1200
#define nHue23 2400
#define nHue16 600
#define rHueMax 3600.0
enum _colorreplace {
crpRing = 1,
crpSpoke = 2,
crpFade = 3,
crpY = 4,
crpX = 5,
crpDiagUL = 6,
crpDiagUR = 7,
crpSquare = 8,
crpDiamond = 9,
crpSpiral = 10,
crpRing2 = 11,
crpRings = 12,
crpSpoke2 = 13,
crpRainbow = 14,
crpRandom = 15,
crpRandom2 = 16,
crpUnknown = 17,
};
/*
******************************************************************************
** Macros
******************************************************************************
*/
#define cbPixelC 3
#define CbColmapRow(x) ((x)*cbPixelC + 3 & ~3)
#define CbColmap(x, y) LMul(y, CbColmapRow(x))
#define cTexture 64
#define NWSE(n, w, s, e) ((n) | (w) << 6 | (long)(s) << 12 | (long)(e) << 18)
#define UD(u, d) ((u) | (d) << 12)
#define UdU(l) ((int)((dword)(l) & 4095))
#define UdD(l) ((int)((dword)(l) >> 12))
#define ITextureWall(kv, d) ((int)(((kv) >> ((d) * 6)) & (cTexture-1)))
#define ITextureWall2(kv, d) ((int)(((kv) >> (FOdd(d) * 12)) & 4095))
#define ITextureWall3(kv, d) ((int)(((kv) >> (((d) > 1) * 12)) & 4095))
#define GetT(c, x, y, d) ITextureWall((c).Get(x, y), d)
#define SetT(c, x, y, d, t) ((c).Get(x, y) & \
~((KV)(cTexture-1) << ((d) * 6)) | ((KV)(t) << ((d) * 6)))
#define SetU(c, x, y, f, t) ((c).Get(x, y) & \
~((KV)4095 << ((f) * 12)) | ((KV)(t) << ((f) * 12)))
/*
******************************************************************************
** Types
******************************************************************************
*/
typedef struct _colorsettings {
// Color replace settings
flag fRainbowBlend;
int nRainbowStart;
int nRainbowDistance;
KV kvBlend1;
KV kvBlend2;
int nReplacePattern;
// Macro accessible only settings
flag fGraphNumber;
long lGrayscale;
flag fMandelbrot;
} CS;
extern CONST KV rgkv[cColor];
extern CONST char *rgszColor[cColor];
extern CS cs;
class CCol : virtual public CMap // Color bitmap
{
public:
INLINE long _Ib(int x, int y) CONST
{ return y*(m_clRow << 2) + (x * cbPixelC); }
INLINE byte *_Pb(long i) CONST
{ return &m_rgb[i]; }
INLINE byte *_Pb(int x, int y) CONST
{ return &m_rgb[_Ib(x, y)]; }
INLINE KV _Get(CONST byte *pb) CONST
{ return (*pb << 16) | (*(pb+1) << 8) | *(pb+2); }
INLINE KV _Get(int x, int y) CONST
{ return _Get(_Pb(x, y)); }
INLINE void _Get(CONST byte *pb, int *r, int *g, int *b) CONST
{ *b = *pb; *g = *(pb+1); *r = *(pb+2); }
INLINE void _Set(byte *pb, int r, int g, int b)
{ *pb = b; *(pb+1) = g; *(pb+2) = r; }
INLINE flag FLegalFill(int x, int y, KV kv) CONST
{ return FLegal(x, y) && Get(x, y) == kv; }
INLINE void BlockPut(CCol &c1, int x, int y, int nOp)
{ BlockMove(c1, 0, 0, c1.m_x-1, c1.m_y-1, x, y, nOp); }
INLINE void ColmapReplaceSimple(KV kvFrom, KV kvTo)
{ ColmapReplace(kvFrom, kvTo, 0, 0, 0, 0); }
INLINE void ColmapReplacePatternSimple(KV kvFrom, int nMode)
{ ColmapReplacePattern(kvFrom, nMode, 0, 0, 0, 0); }
// Core methods each bitmap type implements
virtual CMap *Create() OVERRIDE
{ CCol *c; c = new CCol; if (c == NULL) return NULL; return (CMap *)c; }
virtual void Destroy() OVERRIDE
{ delete this; };
virtual void Set0(int x, int y) OVERRIDE
{ Set(x, y, kvBlack); }
virtual void Set1(int x, int y) OVERRIDE
{ Set(x, y, kvWhite); }
virtual flag FAllocate(int, int, CONST CMap *) OVERRIDE;
virtual KV Get(int, int) CONST OVERRIDE;
virtual void Set(int, int, KV) OVERRIDE;
virtual void Inv(int, int) OVERRIDE;
virtual void LineX(int, int, int, KV) OVERRIDE;
virtual void LineY(int, int, int, KV) OVERRIDE;
virtual void Line(int, int, int, int, KV) OVERRIDE;
virtual flag FTriangle(int, int, int, int, int, int, KV, int) OVERRIDE;
virtual flag FQuadrilateral(int, int, int, int, int, int, int, int,
KV, int) OVERRIDE;
virtual void Block(int, int, int, int, KV) OVERRIDE;
virtual void BlockMove(CONST CMap &, int, int, int, int, int, int) OVERRIDE;
virtual void BitmapSet(KV) OVERRIDE;
virtual long BitmapCount() CONST OVERRIDE;
virtual void BitmapFlipX() OVERRIDE;
virtual flag FBitmapSizeSet(int, int) OVERRIDE;
virtual flag FBitmapZoomTo(int xnew, int ynew, flag fPreserve) OVERRIDE;
virtual flag FBitmapBias(int, int, int, int) OVERRIDE;
virtual flag FBitmapAccentBoundary() OVERRIDE;
// Extra methods specific to color bitmaps
flag FColmapGetFromBitmap(CONST CMon &b, KV kv0, KV kv1);
flag FColmapAntialias(CONST CMon &, KV, KV, int);
void ColmapPalette(CONST CCol &);
int ColmapGraphDistance(CONST CMon &, CONST CMon &, KV, KV, int, int, flag);
long ColmapGraphDistance2(CONST CMon &, KV, KV, flag);
void ColmapGrayscale();
void ColmapBrightness(int, real, int);
void ColmapReplace(KV, KV, int, int, int, int);
void ColmapReplacePattern(KV, int, int, int, int, int);
void ColmapExchange(KV, KV);
void ColmapOrAndKv(KV, int);
void ColmapOrAnd(CONST CCol &, int);
void ColmapAlpha(CONST CCol &, CONST CCol &);
void BlockMove(CONST CCol &, int, int, int, int, int, int, int);
flag FColmapPutToBitmap(CMon &, int) CONST;
void ColmapOrAndFromBitmap(CONST CMon &, KV, KV, int);
flag FColmapBlendFromBitmap(CONST CMon *, CONST CMon *, CONST CMon *);
void ColmapBlendBitmaps(CONST CCol &);
flag FColmapBlur(flag);
void ColmapContrast(flag);
flag FColmapTransform(int, int);
long ColmapFind(int) CONST;
flag FColmapAccentContrast(flag);
void DrawSeen(CONST CMon &, CONST CCol &, int, int, int, flag);
flag FColmapStereogram(CONST CMon &, CONST CCol &, int, int);
long ColmapLifeGenerate(CCol &, flag);
long Evolution(CCol &, int, flag, flag, flag);
void Mandelbrot(real, real, real, real, int, flag);
flag FReadColmapCore(FILE *, int, int, int, int);
void WriteColmap(FILE *) CONST;
flag FReadColmapTarga(FILE *);
void WriteColmapTarga(FILE *) CONST;
flag FReadColmapPaint(FILE *);
flag FReadDaedalusBitmapCore(FILE *, int, int);
void WriteDaedalusBitmap(FILE *, flag) CONST;
void WriteTextColmap(FILE *, flag) CONST;
flag FFill(int, int, KV, KV, flag);
void ColmapStretchToEdge(CONST CCol &, int, int, int, int, int, int,
int, int);
};
/*
******************************************************************************
** Color Primitives
******************************************************************************
*/
// Function hooks implemented by client of module
extern long ParseExpression(char *);
extern KV KvDialog(void);
// Functions implemented locally
extern KV KvShade(KV, real);
extern KV KvBlend(KV, KV);
extern KV KvBlendR(KV, KV, real);
extern KV KvBlendN(KV, KV, int, int);
extern KV KvDiff(KV, KV);
extern KV Hue(int);
#define HueD(d) Hue((int)((d) * (nHueMax / nDegMax)))
#define HueR(r) Hue((int)((r) * (rHueMax / rDegMax)))
#define kvRandom Rgb(Rnd(0, 255), Rnd(0, 255), Rnd(0, 255))
#define kvRandomRainbow Hue(Rnd(0, nHueMax-1))
extern KV Hsl(int, int, int);
/*
******************************************************************************
** Color Bitmap IO Routines
******************************************************************************
*/
extern int GetEditColor(char *);
extern void ConvertKvToSz(KV, char *, int);
extern KV ParseColor(char *, flag);
extern KV ReadColor(FILE *);
/* color.h */