1 /*	csel.h
2 	Copyright (C) 2006-2011 Dmitry Groshev
3 
4 	This file is part of mtPaint.
5 
6 	mtPaint 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 3 of the License, or
9 	(at your option) any later version.
10 
11 	mtPaint is distributed in the hope that it will be useful,
12 	but WITHOUT ANY WARRANTY; without even the implied warranty of
13 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 	GNU General Public License for more details.
15 
16 	You should have received a copy of the GNU General Public License
17 	along with mtPaint in the file COPYING.
18 */
19 
20 #define CMAPSIZE (64 * 64 * 64 / 16)
21 
22 typedef struct
23 {
24 	/* Input fields */
25 	int center, limit, center_a, limit_a;
26 	int mode, invert;
27 	double range;
28 	/* Cache fields */
29 	guint32 colormap[CMAPSIZE * 2];
30 	guint32 pmap[256 / 32];
31 	int pcache[256], cbase, irange, amin, amax;
32 	double clxn[3], cvec, range2;
33 } csel_info;
34 #define CSEL_SVSIZE offsetof(csel_info, colormap)
35 
36 csel_info *csel_data;
37 int csel_preview, csel_preview_a, csel_overlay;
38 double gamma256[256], gamma64[64];
39 double midgamma256[256];
40 int kgamma256;
41 extern unsigned char ungamma256[];
42 
43 /* This gamma table is for when we need numeric stability */
44 #ifdef NATIVE_DOUBLES
45 #define Fgamma256 gamma256
46 #else
47 float Fgamma256[256];
48 #endif
49 
UNGAMMA256(double x)50 static inline int UNGAMMA256(double x)
51 {
52 	int j = (int)(x * kgamma256);
53 	return (ungamma256[j] - (x < midgamma256[ungamma256[j]]));
54 }
55 
UNGAMMA256X(double x)56 static inline int UNGAMMA256X(double x)
57 {
58 	int j = (int)(x * kgamma256);
59 	return (j < 0 ? 0 : j >= kgamma256 ? 255 :
60 		ungamma256[j] - (x < midgamma256[ungamma256[j]]));
61 }
62 
63 //double gamma65536(int idx);
64 //int ungamma65536(double v);
65 
66 /* Used in and around gradient engine */
67 double gamma65281(int idx);
68 int ungamma65281(double v);
69 
70 double rgb2B(double r, double g, double b);
71 void rgb2LXN(double *tmp, double r, double g, double b);
72 //void rgb2Lab(double *tmp, double r, double g, double b);
73 void init_cols();
74 void get_lxn(double *lxn, int col);
75 
76 int csel_scan(int start, int step, int cnt, unsigned char *mask,
77 	unsigned char *img, csel_info *info);
78 double csel_eval(int mode, int center, int limit);
79 void csel_reset(csel_info *info);
80 void csel_init();
81