93 const char *s = Text.
b_str();
unsigned long c;
95 if( sscanf(s + 1,
"%lx", &c) == 1 )
97 switch( Text.
Length() - 1 )
102 (
unsigned char)((c >> 24) & 0xFF),
103 (
unsigned char)((c >> 16) & 0xFF),
104 (
unsigned char)((c >> 8) & 0xFF)
110 (
unsigned char)((c >> 24) & 0xFF),
111 (
unsigned char)((c >> 16) & 0xFF),
112 (
unsigned char)((c >> 8) & 0xFF),
113 (
unsigned char)((c ) & 0xFF)
120 (
unsigned char)(((c >> 12) & 0xF) * 0x11),
121 (
unsigned char)(((c >> 8) & 0xF) * 0x11),
122 (
unsigned char)(((c >> 4) & 0xF) * 0x11)
128 (
unsigned char)(((c >> 12) & 0xF) * 0x11),
129 (
unsigned char)(((c >> 8) & 0xF) * 0x11),
130 (
unsigned char)(((c >> 4) & 0xF) * 0x11),
131 (
unsigned char)(((c ) & 0xF) * 0x11)
150 Text.
Printf(
"#%02X%02X%02X",
158 Text.
Printf(
"%ld", Color);
174 m_Colors = NULL; m_nColors = 0;
182 m_Colors = NULL; m_nColors = 0;
190 m_Colors = NULL; m_nColors = 0;
198 m_Colors = NULL; m_nColors = 0;
200 Create(nColors, Palette, bRevert);
206 m_Colors = NULL; m_nColors = 0;
208 Create(Palette, nColors, bRevert);
231 if( Colors.m_nColors > 0 )
233 m_nColors = Colors.m_nColors;
234 m_Colors = (
long *)
SG_Realloc(m_Colors, m_nColors *
sizeof(
long));
236 memcpy(m_Colors, Colors.m_Colors, m_nColors *
sizeof(
long));
269 m_Colors = NULL; m_nColors = 0;
281 if( nColors == m_nColors )
300 m_Colors = (
long *)
SG_Realloc(m_Colors, m_nColors *
sizeof(
long));
308 m_Colors[i] = Colors[(int)(i * dStep)];
328 if( Index >= 0 && Index < m_nColors )
330 m_Colors[Index] = Color;
372 else if( Value > 255 )
381 ds = (r + g + b) / 3.0;
390 _Set_Brightness(r, g, b);
394 r = g = b = Value / 3.0;
397 return(
Set_Color(Index, (
int)r, (
int)g, (
int)b) );
401void CSG_Colors::_Set_Brightness(
double &a,
double &b,
double &c,
int Pass)
407 addSum = (int)((a - 255) / 2.0);
415 addSum = (int)(b - 255);
427 addSum = (int)(c - 255);
440 _Set_Brightness(b, c, a, Pass + 1);
458 #define MAKE_NAME(name) (bWithIndex ? CSG_String::Format("[%d] %s", Index, name) : CSG_String(name))
532 default :
return(
_TL(
"") );
1054 if( Name.
asInt(Index) )
1067 m_nColors = nColors;
1068 m_Colors = (
long *)
SG_Realloc(m_Colors, m_nColors *
sizeof(
long));
1070 double d = 0., dStep = 2. *
M_PI / (m_nColors - 1.);
1072 for(
int i=0; i<m_nColors; i++, d+=dStep)
1075 (
int)(d <
M_PI / 2 ? 0 : 128 - 127 * sin(
M_PI - d)),
1076 (
int)(128 - 127 * cos(d)),
1077 (
int)(d >
M_PI * 3 / 2 ? 0 : 128 + 127 * sin(d))
1096 if( iColor_A > iColor_B )
1099 iColor_A = iColor_B;
1114 int n = iColor_B - iColor_A;
1119 double dr = (double)(
SG_GET_R(Color_B) - ar) / (double)n;
1122 double dg = (double)(
SG_GET_G(Color_B) - ag) / (double)n;
1125 double db = (double)(
SG_GET_B(Color_B) - ab) / (double)n;
1127 for(
int i=0; i<=n; i++)
1151 if( iColor_A > iColor_B )
1154 iColor_A = iColor_B;
1169 int n = iColor_B - iColor_A;
1173 double dBrightness = (double)(Brightness_B - Brightness_A) / (double)n;
1175 for(
int i=0; i<=n; i++)
1177 Set_Brightness(iColor_A + i, (
int)(Brightness_A + i * dBrightness));
1197 (
int)(255.0 * (
double)rand() / (
double)RAND_MAX),
1198 (
int)(255.0 * (
double)rand() / (
double)RAND_MAX),
1199 (
int)(255.0 * (
double)rand() / (
double)RAND_MAX)
1220 for(
int i=0, j=
Get_Count()-1; i<j; i++, j--)
1259 return(
Create(Colors) );
1265 return( pColors ?
Create(*pColors) :
false );
1274#define COLORS_SERIAL_VERSION_BINARY "SAGA_COLORPALETTE_VERSION_0.100_BINARY"
1275#define COLORS_SERIAL_VERSION__ASCII "SAGA_COLORPALETTE_VERSION_0.100__ASCII"
1294 return(
Serialize(Stream,
false,
false) );
1305 Stream.
Read(&nColors,
sizeof(nColors));
1315 for(
int i=0; i<nColors; i++)
1317 Stream.
Read(c, ValueSize);
1335 Stream.
Read(&nColors,
sizeof(
short));
1337 if( Stream.
Length() == (
int)(
sizeof(
short) + 3 * nColors) &&
Set_Count(nColors) )
1339 BYTE *R = (BYTE *)
SG_Malloc(nColors *
sizeof(BYTE)); Stream.
Read(R, nColors *
sizeof(BYTE));
1340 BYTE *G = (BYTE *)
SG_Malloc(nColors *
sizeof(BYTE)); Stream.
Read(G, nColors *
sizeof(BYTE));
1341 BYTE *
B = (BYTE *)
SG_Malloc(nColors *
sizeof(BYTE)); Stream.
Read(
B, nColors *
sizeof(BYTE));
1343 for(
int i=0; i<nColors; i++)
1399 Stream.
Write(&m_nColors,
sizeof(m_nColors));
1400 Stream.
Write(m_Colors,
sizeof(
long), m_nColors);
1407 Stream.
Read(&nColors,
sizeof(m_nColors));
1411 Stream.
Read(m_Colors,
sizeof(
long), m_nColors);
1484 for(
int i=0, j=0; i<
Get_Count(); i++, j+=12)
#define COLORS_SERIAL_VERSION_BINARY
CSG_String SG_Colors_Get_Name(int Index)
long SG_Color_Get_Random(void)
long SG_Color_From_RGB(int Red, int Green, int Blue, int Alpha)
#define COLORS_SERIAL_VERSION__ASCII
bool SG_Color_From_Text(const CSG_String &Text, long &Color)
CSG_String SG_Color_To_Text(long Color, bool bHexadecimal)
SAGA_API_DLL_EXPORT void * SG_Malloc(size_t size)
SAGA_API_DLL_EXPORT void SG_Free(void *memblock)
SAGA_API_DLL_EXPORT void * SG_Realloc(void *memblock, size_t size)
#define SG_GET_RGBA(r, g, b, a)
#define SG_GET_RGB(r, g, b)
@ SG_COLORS_BLUE_YELLOW_RED
@ SG_COLORS_DEFAULT_BRIGHT
@ SG_COLORS_PRECIPITATION_1
@ SG_COLORS_PRECIPITATION_3
@ SG_COLORS_RED_GREY_BLUE
@ SG_COLORS_GREEN_WHITE_RED
@ SG_COLORS_RED_GREY_GREEN
@ SG_COLORS_GREEN_GREY_BLUE
@ SG_COLORS_RED_BLUE_GREEN
@ SG_COLORS_GREEN_YELLOW_RED
@ SG_COLORS_GREEN_GREY_RED
@ SG_COLORS_GREEN_WHITE_BLUE
@ SG_COLORS_RED_GREEN_BLUE
@ SG_COLORS_PRECIPITATION_4
@ SG_COLORS_RED_YELLOW_GREEN
@ SG_COLORS_GREEN_YELLOW_BLUE
@ SG_COLORS_BLUE_WHITE_RED
@ SG_COLORS_MAGENTA_WHITE
@ SG_COLORS_GREEN_RED_BLUE
@ SG_COLORS_BLUE_GREY_RED
@ SG_COLORS_PRECIPITATION_5
@ SG_COLORS_PRECIPITATION_2
bool Set_Green(int Index, int Value)
bool from_Text(const CSG_String &String)
static CSG_String Get_Predefined_Name(int Index, bool bWithIndex=true)
long Get_Brightness(int Index) const
bool Set_Blue(int Index, int Value)
bool Set_Default(int nColors=11)
long Get_Blue(int Index) const
CSG_Colors & operator=(const CSG_Colors &Colors)
long Get_Color(int Index) const
bool Set_Count(int nColors)
bool Set_Color(int Index, long Color)
bool Serialize(CSG_File &Stream, bool bSave, bool bBinary)
bool Save(const CSG_String &FileName, bool bBinary)
static int Get_Predefined_Count(void)
long Get_Red(int Index) const
bool Load(const CSG_String &FileName)
bool Set_Ramp(long Color_A, long Color_B)
bool to_Text(CSG_String &String)
bool Set_Brightness(int Index, int Value)
virtual ~CSG_Colors(void)
long Get_Green(int Index) const
bool Set_Ramp_Brighness(int Brightness_A, int Brightness_B)
bool Set_Palette(int Index, bool bRevert=false, int nColors=0)
bool Assign(const CSG_Colors &Colors)
int Get_Count(void) const
bool Set_Predefined(int Index, bool bRevert=false, int nColors=0)
bool Set_Red(int Index, int Value)
long Get_Interpolated(double Index) const
virtual bool Open(const SG_Char *FileName, int Mode=SG_FILE_R, bool bBinary=true, int Encoding=SG_FILE_ENCODING_ANSI)
bool Read_Line(CSG_String &Line) const
size_t Write(void *Buffer, size_t Size, size_t Count=1) const
size_t Read(void *Buffer, size_t Size, size_t Count=1) const
int Printf(const char *Format,...)
bool Seek_Start(void) const
static double Get_Uniform(void)
size_t Length(void) const
CSG_String AfterFirst(char Character) const
const char * b_str(void) const
bool asInt(int &Value) const
CSG_String AfterLast(char Character) const
int Cmp(const CSG_String &String) const
static CSG_String Format(const char *Format,...)
int Find(char Character, bool fromEnd=false) const
SG_Char Get_Char(size_t i) const
int Printf(const char *Format,...)
bool is_Empty(void) const
CSG_String Mid(size_t first, size_t count=0) const