aboutsummaryrefslogtreecommitdiff
path: root/DOPALETT.C
blob: db85b3ea5e65a366538c5fe64bb5a6da1bd947b2 (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
/*----------------------------------------------------------------------*/
/*  									*/
/*      dopalette -- invoke the palette tool				*/
/*  									*/
/*----------------------------------------------------------------------*/

#include <system.h>
#include <prism.h>

extern SHORT nColors;
extern Range cycles[];
extern struct Window *mainW;
extern Range *shadeRange;
extern Box bigBox;
extern BOOL skipRefresh;
extern PaletteGlobals *paletteGlobals;

/* map a  number i, in [0..63], to logarithmic range  */
/* this maps 63 to 8192(OnePerTick), and maps 0 to 36, about 227 ticks 
    per change, i.e. nearly 4 seconds . */
    
rateFromIndex(i) int i; {
    int base;
    i++;
    base = 1 << ((i >> 3) + 5);
    return (base + ((i & 7) * base) / 8);
    }

/* this is the exact inverse of the above function*/
indexFromRate(n) int n; {
    int j;
    int hibit, mod;
    hibit = (1 << 15);
    for (j = 15;  j >= 0;  j--)	{
	if (hibit & n)  {
	    mod = n - hibit;
	    return ((j - 5) * 8 + (mod * 8) / hibit - 1);
	    }
	hibit >>= 1;
	}
    }	
/* ----- Display color pallet Control ----- */
void ShowPallet() { 
    int i;
    BOOL res;
    UndoSave();
    PauseCCyc();
    for (i=1; i<MAXNCYCS; i++) cycles[i].rate = indexFromRate(cycles[i].rate);
    FreeTmpRas();
    for (;;) { 
	res = PaletteTool(mainW,&paletteGlobals);
	WaitRefrMessage();
	if (res) break;
	UpdtDisplay();
	}
    skipRefresh = YES; /* where this extra refresh comes from I don't  know */
    AllocTmpRas();
    PaneRefresh(&bigBox);
    for (i=1; i<MAXNCYCS; i++) cycles[i].rate = rateFromIndex(cycles[i].rate);
    ResumeCCyc();
    SetCycPaint();
    DispPntMode();
    if (cycles[0].low ==cycles[0].high) shadeRange = NULL;
      else shadeRange = cycles;
    }