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
|
#ifndef shaveXPM_h
#define shaveXPM_h
// Shave and a Haircut
// (c) 2019 Epic Games
// US Patent 6720962
#include <maya/MTypes.h>
#if MAYA_API_VERSION < 20180000
class MString;
#endif
class shaveXPM
{
public:
struct Colour
{
unsigned char r;
unsigned char g;
unsigned char b;
};
static bool write(
int width,
int height,
const unsigned char* rgba,
const MString& filename
);
static MString toHex(unsigned char val);
protected:
class Node
{
public:
Node(
unsigned char irmin, unsigned char igmin,
unsigned char ibmin, unsigned char irmax,
unsigned char igmax, unsigned char ibmax
);
static void addPixel(
unsigned char r,
unsigned char g,
unsigned char b
);
static void cleanup();
static void getColours(struct Colour* colours);
static unsigned long getIndex(
unsigned char r,
unsigned char g,
unsigned char b
);
static void init();
static unsigned long numColours();
static unsigned long prune(unsigned long minError);
protected:
void doAddPixel(
unsigned char r,
unsigned char g,
unsigned char b,
unsigned short level
);
void doCleanup();
void doGetColours(struct Colour* colours);
unsigned long doGetIndex(
unsigned char r,
unsigned char g,
unsigned char b
);
bool doPrune(unsigned long minError, bool force);
unsigned long index;
unsigned long numPixels;
unsigned long numLeafPixels;
unsigned long sumLeafR;
unsigned long sumLeafG;
unsigned long sumLeafB;
unsigned long quantError;
unsigned char rmax;
unsigned char rmid;
unsigned char rmin;
unsigned char gmax;
unsigned char gmid;
unsigned char gmin;
unsigned char bmax;
unsigned char bmid;
unsigned char bmin;
Node* child[8];
static Node* head;
static unsigned long newMinError;
static unsigned long nextIndex;
static unsigned long numLeafNodes;
};
};
inline unsigned long shaveXPM::Node::numColours()
{ return numLeafNodes; }
#endif
|