SAGA API  v9.9
api_colors.cpp
Go to the documentation of this file.
1 
3 // //
4 // SAGA //
5 // //
6 // System for Automated Geoscientific Analyses //
7 // //
8 // Application Programming Interface //
9 // //
10 // Library: SAGA_API //
11 // //
12 //-------------------------------------------------------//
13 // //
14 // api_colors.cpp //
15 // //
16 // Copyright (C) 2005 by Olaf Conrad //
17 // //
18 //-------------------------------------------------------//
19 // //
20 // This file is part of 'SAGA - System for Automated //
21 // Geoscientific Analyses'. //
22 // //
23 // This library is free software; you can redistribute //
24 // it and/or modify it under the terms of the GNU Lesser //
25 // General Public License as published by the Free //
26 // Software Foundation, either version 2.1 of the //
27 // License, or (at your option) any later version. //
28 // //
29 // This library is distributed in the hope that it will //
30 // be useful, but WITHOUT ANY WARRANTY; without even the //
31 // implied warranty of MERCHANTABILITY or FITNESS FOR A //
32 // PARTICULAR PURPOSE. See the GNU Lesser General Public //
33 // License for more details. //
34 // //
35 // You should have received a copy of the GNU Lesser //
36 // General Public License along with this program; if //
37 // not, see <http://www.gnu.org/licenses/>. //
38 // //
39 //-------------------------------------------------------//
40 // //
41 // contact: Olaf Conrad //
42 // Institute of Geography //
43 // University of Goettingen //
44 // Goldschmidtstr. 5 //
45 // 37077 Goettingen //
46 // Germany //
47 // //
48 // e-mail: oconrad@saga-gis.org //
49 // //
51 
52 //---------------------------------------------------------
53 #include <stdlib.h>
54 #include <string.h>
55 
56 #include "api_core.h"
57 #include "mat_tools.h"
58 
59 
61 // //
62 // //
63 // //
65 
66 //---------------------------------------------------------
68 {
69  return( CSG_Colors::Get_Predefined_Name(Index) );
70 }
71 
72 //---------------------------------------------------------
74 {
76 }
77 
78 //---------------------------------------------------------
79 long SG_Color_From_RGB (int Red, int Green, int Blue, int Alpha)
80 {
81  return( SG_GET_RGBA(Red, Green, Blue, Alpha) );
82 }
83 
84 //---------------------------------------------------------
85 bool SG_Color_From_Text (const CSG_String &Text, long &Color)
86 { // from wx/src/common/colourcmn.cpp, hexadecimal prefixed with # ("HTML syntax") see https://drafts.csswg.org/css-color/#hex-notation
87 
88  if( Text.is_Empty() || Text.Get_Char(0) != L'#' )
89  {
90  return( false );
91  }
92 
93  const char *s = Text.b_str(); unsigned long c;
94 
95  if( sscanf(s + 1, "%lx", &c) == 1 )
96  {
97  switch( Text.Length() - 1 )
98  {
99  case 6: // #rrggbb
100  c = (c << 8) + 0xFF;
101  Color = SG_GET_RGB(
102  (unsigned char)((c >> 24) & 0xFF),
103  (unsigned char)((c >> 16) & 0xFF),
104  (unsigned char)((c >> 8) & 0xFF)
105  );
106  return( true );
107 
108  case 8: // #rrggbbaa
109  Color = SG_GET_RGBA(
110  (unsigned char)((c >> 24) & 0xFF),
111  (unsigned char)((c >> 16) & 0xFF),
112  (unsigned char)((c >> 8) & 0xFF),
113  (unsigned char)((c ) & 0xFF)
114  );
115  return( true );
116 
117  case 3: // #rgb
118  c = (c << 4) + 0xF;
119  Color = SG_GET_RGB(
120  (unsigned char)(((c >> 12) & 0xF) * 0x11),
121  (unsigned char)(((c >> 8) & 0xF) * 0x11),
122  (unsigned char)(((c >> 4) & 0xF) * 0x11)
123  );
124  return( true );
125 
126  case 4: // #rgba
127  Color = SG_GET_RGBA(
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)
132  );
133  return( true );
134 
135  default:
136  return( false ); // unrecognized
137  }
138  }
139 
140  return( false );
141 }
142 
143 //---------------------------------------------------------
144 CSG_String SG_Color_To_Text (long Color, bool bHexadecimal)
145 {
146  CSG_String Text;
147 
148  if( bHexadecimal )
149  {
150  Text.Printf("#%02X%02X%02X",
151  SG_GET_R(Color),
152  SG_GET_G(Color),
153  SG_GET_B(Color)
154  );
155  }
156  else
157  {
158  Text.Printf("%ld", Color);
159  }
160 
161  return( Text );
162 }
163 
164 
166 // //
167 // //
168 // //
170 
171 //---------------------------------------------------------
173 {
174  m_Colors = NULL;
175  m_nColors = 0;
176 
177  Create();
178 }
179 
180 //---------------------------------------------------------
182 {
183  m_Colors = NULL;
184  m_nColors = 0;
185 
186  Create(Colors);
187 }
188 
189 //---------------------------------------------------------
190 CSG_Colors::CSG_Colors(int nColors, int Palette, bool bRevert)
191 {
192  m_Colors = NULL;
193  m_nColors = 0;
194 
195  Create(nColors, Palette, bRevert);
196 }
197 
198 //---------------------------------------------------------
200 {
201  Destroy();
202 }
203 
204 
206 // //
208 
209 //---------------------------------------------------------
211 {
212  return( Create(11) );
213 }
214 
215 //---------------------------------------------------------
216 bool CSG_Colors::Create(const CSG_Colors &Colors)
217 {
218  if( Colors.m_nColors > 0 )
219  {
220  m_nColors = Colors.m_nColors;
221  m_Colors = (long *)SG_Realloc(m_Colors, m_nColors * sizeof(long));
222 
223  memcpy(m_Colors, Colors.m_Colors, m_nColors * sizeof(long));
224 
225  return( true );
226  }
227 
228  return( false );
229 }
230 
231 //---------------------------------------------------------
232 bool CSG_Colors::Create(int nColors, int Palette, bool bRevert)
233 {
234  return( Set_Palette(Palette, bRevert, nColors) || Set_Palette(SG_COLORS_DEFAULT, bRevert, nColors) );
235 }
236 
237 //---------------------------------------------------------
239 {
240  if( m_nColors > 0 )
241  {
242  SG_Free(m_Colors);
243 
244  m_Colors = NULL;
245  m_nColors = 0;
246  }
247 }
248 
249 
251 // //
253 
254 //---------------------------------------------------------
255 bool CSG_Colors::Set_Count(int nColors)
256 {
257  if( nColors == m_nColors )
258  {
259  return( true );
260  }
261 
262  if( nColors < 1 )
263  {
264  return( false );
265  }
266 
267  if( m_nColors == 0 )
268  {
269  return( Set_Default(nColors) );
270  }
271 
272  //-----------------------------------------------------
273  CSG_Colors Colors(*this);
274 
275  m_nColors = nColors;
276  m_Colors = (long *)SG_Realloc(m_Colors, m_nColors * sizeof(long));
277 
278  double dStep = Get_Count() > 1 ? (Colors.Get_Count() - 1.0) / (Get_Count() - 1.0) : 0.0;
279 
280  for(int i=0; i<Get_Count(); i++)
281  {
282  if( Get_Count() < Colors.Get_Count() )
283  {
284  m_Colors[i] = Colors[(int)(i * dStep)];
285  }
286  else // if( Get_Count() > Colors.Get_Count() )
287  {
288  m_Colors[i] = Colors.Get_Interpolated(i * dStep);
289  }
290  }
291 
292  //-----------------------------------------------------
293  return( true );
294 }
295 
296 
298 // //
300 
301 //---------------------------------------------------------
302 bool CSG_Colors::Set_Color(int Index, long Color)
303 {
304  if( Index >= 0 && Index < m_nColors )
305  {
306  m_Colors[Index] = Color;
307 
308  return( true );
309  }
310 
311  return( false );
312 }
313 
314 //---------------------------------------------------------
315 bool CSG_Colors::Set_Color(int Index, int Red, int Green, int Blue)
316 {
317  return( Set_Color(Index, SG_GET_RGB(Red, Green, Blue)) );
318 }
319 
320 //---------------------------------------------------------
321 bool CSG_Colors::Set_Red(int Index, int Value)
322 {
323  return( Set_Color(Index, Value , Get_Green(Index) , Get_Blue(Index)) );
324 }
325 
326 //---------------------------------------------------------
327 bool CSG_Colors::Set_Green(int Index, int Value)
328 {
329  return( Set_Color(Index, Get_Red(Index) , Value , Get_Blue(Index)) );
330 }
331 
332 //---------------------------------------------------------
333 bool CSG_Colors::Set_Blue(int Index, int Value)
334 {
335  return( Set_Color(Index, Get_Red(Index) , Get_Green(Index) , Value) );
336 }
337 
338 //---------------------------------------------------------
339 bool CSG_Colors::Set_Brightness(int Index, int Value)
340 {
341  double r, g, b, ds;
342 
343  //-----------------------------------------------------
344  if( Value < 0 )
345  {
346  Value = 0;
347  }
348  else if( Value > 255 )
349  {
350  Value = 255;
351  }
352 
353  //-----------------------------------------------------
354  r = Get_Red (Index);
355  g = Get_Green(Index);
356  b = Get_Blue (Index);
357  ds = (r + g + b) / 3.0;
358 
359  if( ds > 0.0 )
360  {
361  ds = Value / ds;
362  r *= ds;
363  g *= ds;
364  b *= ds;
365 
366  _Set_Brightness(r, g, b);
367  }
368  else
369  {
370  r = g = b = Value / 3.0;
371  }
372 
373  return( Set_Color(Index, (int)r, (int)g, (int)b) );
374 }
375 
376 //---------------------------------------------------------
377 void CSG_Colors::_Set_Brightness(double &a, double &b, double &c, int Pass)
378 {
379  if( a > 255 )
380  {
381  int addSum;
382 
383  addSum = (int)((a - 255) / 2.0);
384  a = 255;
385 
386  b += addSum;
387  c += addSum;
388 
389  if( b > 255 )
390  {
391  addSum = (int)(b - 255);
392  b = 255;
393 
394  c += addSum;
395 
396  if( c > 255 )
397  {
398  c = 255;
399  }
400  }
401  else if( c > 255 )
402  {
403  addSum = (int)(c - 255);
404  c = 255;
405 
406  b += addSum;
407 
408  if( b > 255 )
409  {
410  b = 255;
411  }
412  }
413  }
414  else if( Pass < 2 )
415  {
416  _Set_Brightness(b, c, a, Pass + 1);
417  }
418 }
419 
420 
422 // //
424 
425 //---------------------------------------------------------
427 {
428  return( SG_COLORS_COUNT );
429 }
430 
431 //---------------------------------------------------------
433 {
434  #define MAKE_NAME(name) CSG_String::Format("[%d] %s", Index, name)
435 
436  switch( Index )
437  {
438  case SG_COLORS_DEFAULT : return( MAKE_NAME(_TL("blue-green-red" )) );
439  case SG_COLORS_DEFAULT_BRIGHT : return( MAKE_NAME(_TL("blue-green-red" )) );
440  case SG_COLORS_RAINBOW : return( MAKE_NAME(_TL("rainbow" )) );
441  case SG_COLORS_RAINBOW_2 : return( MAKE_NAME(_TL("rainbow" )) );
442 
443  case SG_COLORS_BLACK_WHITE : return( MAKE_NAME(_TL("greyscale" )) );
444  case SG_COLORS_BLACK_RED : return( MAKE_NAME(_TL("black-red" )) );
445  case SG_COLORS_BLACK_GREEN : return( MAKE_NAME(_TL("black-green" )) );
446  case SG_COLORS_BLACK_BLUE : return( MAKE_NAME(_TL("black-blue" )) );
447 
448  case SG_COLORS_WHITE_RED : return( MAKE_NAME(_TL("white-red" )) );
449  case SG_COLORS_WHITE_GREEN : return( MAKE_NAME(_TL("white-green" )) );
450  case SG_COLORS_WHITE_BLUE : return( MAKE_NAME(_TL("white-blue" )) );
451 
452  case SG_COLORS_YELLOW_RED : return( MAKE_NAME(_TL("yellow-red" )) );
453  case SG_COLORS_YELLOW_GREEN : return( MAKE_NAME(_TL("yellow-green" )) );
454  case SG_COLORS_YELLOW_BLUE : return( MAKE_NAME(_TL("yellow-blue" )) );
455 
456  case SG_COLORS_BLUE_RED : return( MAKE_NAME(_TL("blue-red" )) );
457  case SG_COLORS_GREEN_RED : return( MAKE_NAME(_TL("green-red" )) );
458  case SG_COLORS_GREEN_BLUE : return( MAKE_NAME(_TL("green-blue" )) );
459 
460  case SG_COLORS_BLUE_WHITE_RED : return( MAKE_NAME(_TL("blue-white-red" )) );
461  case SG_COLORS_GREEN_WHITE_RED : return( MAKE_NAME(_TL("green-white-red" )) );
462  case SG_COLORS_GREEN_WHITE_BLUE : return( MAKE_NAME(_TL("green-white-blue" )) );
463 
464  case SG_COLORS_BLUE_GREY_RED : return( MAKE_NAME(_TL("blue-grey-red" )) );
465  case SG_COLORS_RED_GREY_BLUE : return( MAKE_NAME(_TL("red-grey-blue" )) );
466  case SG_COLORS_GREEN_GREY_RED : return( MAKE_NAME(_TL("green-grey-red" )) );
467  case SG_COLORS_RED_GREY_GREEN : return( MAKE_NAME(_TL("red-grey-green" )) );
468  case SG_COLORS_GREEN_GREY_BLUE : return( MAKE_NAME(_TL("green-grey-blue" )) );
469 
470  case SG_COLORS_BLUE_YELLOW_RED : return( MAKE_NAME(_TL("blue-yellow-red" )) );
471  case SG_COLORS_GREEN_YELLOW_RED : return( MAKE_NAME(_TL("green-yellow-red" )) );
472  case SG_COLORS_RED_YELLOW_GREEN : return( MAKE_NAME(_TL("red-yellow-green" )) );
473  case SG_COLORS_GREEN_YELLOW_BLUE: return( MAKE_NAME(_TL("green-yellow-blue")) );
474 
475  case SG_COLORS_RED_GREEN_BLUE : return( MAKE_NAME(_TL("red-green-blue" )) );
476  case SG_COLORS_RED_BLUE_GREEN : return( MAKE_NAME(_TL("red-blue-green" )) );
477  case SG_COLORS_GREEN_RED_BLUE : return( MAKE_NAME(_TL("green-red-blue" )) );
478  case SG_COLORS_NEON : return( MAKE_NAME(_TL("neon" )) );
479 
480  case SG_COLORS_TOPOGRAPHY : return( MAKE_NAME(_TL("topography" )) );
481  case SG_COLORS_TOPOGRAPHY_2 : return( MAKE_NAME(_TL("topography" )) );
482  case SG_COLORS_TOPOGRAPHY_3 : return( MAKE_NAME(_TL("topography" )) );
483  case SG_COLORS_TOPOGRAPHY_4 : return( MAKE_NAME(_TL("topography" )) );
484 
485  case SG_COLORS_ASPECT_1 : return( MAKE_NAME(_TL("aspect" )) );
486  case SG_COLORS_ASPECT_2 : return( MAKE_NAME(_TL("aspect" )) );
487  case SG_COLORS_ASPECT_3 : return( MAKE_NAME(_TL("aspect" )) );
488 
489  case SG_COLORS_THERMAL_1 : return( MAKE_NAME(_TL("thermal" )) );
490  case SG_COLORS_THERMAL_2 : return( MAKE_NAME(_TL("thermal" )) );
491 
492  case SG_COLORS_PRECIPITATION_1 : return( MAKE_NAME(_TL("precipitation" )) );
493  case SG_COLORS_PRECIPITATION_2 : return( MAKE_NAME(_TL("precipitation" )) );
494  case SG_COLORS_PRECIPITATION_3 : return( MAKE_NAME(_TL("precipitation" )) );
495  case SG_COLORS_PRECIPITATION_4 : return( MAKE_NAME(_TL("precipitation" )) );
496  case SG_COLORS_PRECIPITATION_5 : return( MAKE_NAME(_TL("precipitation" )) );
497 
498  case SG_COLORS_VEGETATION : return( MAKE_NAME(_TL("vegetation" )) );
499 
500  case SG_COLORS_SPECTRUM_1 : return( MAKE_NAME(_TL("spectrum" )) );
501  case SG_COLORS_SPECTRUM_2 : return( MAKE_NAME(_TL("spectrum" )) );
502  case SG_COLORS_SPECTRUM_3 : return( MAKE_NAME(_TL("spectrum" )) );
503 
504  default : return( _TL("") );
505  }
506 }
507 
508 //---------------------------------------------------------
509 bool CSG_Colors::Set_Predefined(int Index, bool bRevert, int nColors)
510 {
511  switch( Index )
512  {
513  case SG_COLORS_DEFAULT:
514  Set_Default(nColors < 17 ? 17 : nColors);
515  break;
516 
518  Set_Default(nColors < 17 ? 17 : nColors);
519  Set_Ramp_Brighness(127, 127);
520  break;
521 
522  case SG_COLORS_RAINBOW:
523  Set_Count(8);
524  Set_Color(0, SG_GET_RGB( 64, 0, 127));
525  Set_Color(1, SG_GET_RGB( 0, 0, 255));
526  Set_Color(2, SG_GET_RGB( 0, 255, 255));
527  Set_Color(3, SG_GET_RGB( 0, 191, 0));
528  Set_Color(4, SG_GET_RGB(255, 255, 0));
529  Set_Color(5, SG_GET_RGB(255, 127, 0));
530  Set_Color(6, SG_GET_RGB(255, 0, 0));
531  Set_Color(7, SG_GET_RGB(127, 0, 0));
532  break;
533 
534  case SG_COLORS_RAINBOW_2:
535  Set_Count(4);
536  Set_Color(0, SG_GET_RGB( 0, 0, 255));
537  Set_Color(1, SG_GET_RGB( 0, 255, 0));
538  Set_Color(2, SG_GET_RGB(255, 255, 0));
539  Set_Color(3, SG_GET_RGB(255, 0, 0));
540  break;
541 
542  //-----------------------------------------------------
544  Set_Count(2);
545  Set_Ramp(SG_GET_RGB( 0, 0, 0), SG_GET_RGB(255, 255, 255));
546  break;
547 
548  case SG_COLORS_BLACK_RED:
549  Set_Count(2);
550  Set_Ramp(SG_GET_RGB( 0, 0, 0), SG_GET_RGB(255, 0, 0));
551  break;
552 
554  Set_Count(2);
555  Set_Ramp(SG_GET_RGB( 0, 0, 0), SG_GET_RGB( 0, 255, 0));
556  break;
557 
559  Set_Count(2);
560  Set_Ramp(SG_GET_RGB( 0, 0, 0), SG_GET_RGB( 0, 0, 255));
561  break;
562 
563  //-----------------------------------------------------
564  case SG_COLORS_WHITE_RED:
565  Set_Count(3);
566  Set_Color(0, SG_GET_RGB(255, 255, 255));
567  Set_Color(1, SG_GET_RGB(255, 127, 0));
568  Set_Color(2, SG_GET_RGB(159, 0, 0));
569  break;
570 
572  Set_Count(2);
573  Set_Ramp(SG_GET_RGB(255, 255, 255), SG_GET_RGB( 0, 127, 0));
574  break;
575 
577  Set_Count(3);
578  Set_Color(0, SG_GET_RGB(255, 255, 255));
579  Set_Color(1, SG_GET_RGB( 0, 127, 255));
580  Set_Color(2, SG_GET_RGB( 0, 0, 159));
581  break;
582 
583  //-----------------------------------------------------
585  Set_Count(3);
586  Set_Color(0, SG_GET_RGB(255, 255, 127));
587  Set_Color(1, SG_GET_RGB(255, 127, 0));
588  Set_Color(2, SG_GET_RGB(127, 0, 0));
589  break;
590 
592  Set_Count(3);
593  Set_Color(0, SG_GET_RGB(255, 255, 127));
594  Set_Color(1, SG_GET_RGB(127, 255, 0));
595  Set_Color(2, SG_GET_RGB( 0, 127, 0));
596  break;
597 
599  Set_Count(3);
600  Set_Color(0, SG_GET_RGB(255, 255, 200));
601  Set_Color(1, SG_GET_RGB(127, 192, 255));
602  Set_Color(2, SG_GET_RGB( 0, 64, 127));
603  break;
604 
605  //-----------------------------------------------------
606  case SG_COLORS_BLUE_RED:
607  Set_Count(2);
608  Set_Ramp(SG_GET_RGB( 0, 0, 255), SG_GET_RGB(255, 0, 0));
609  break;
610 
611  case SG_COLORS_GREEN_RED:
612  Set_Count(2);
613  Set_Ramp(SG_GET_RGB( 0, 255, 0), SG_GET_RGB(255, 0, 0));
614  break;
615 
617  Set_Count(2);
618  Set_Ramp(SG_GET_RGB( 0, 255, 0), SG_GET_RGB( 0, 0, 255));
619  break;
620 
621  //-----------------------------------------------------
623  Set_Count(3);
624  Set_Color(0, SG_GET_RGB( 0, 0, 127));
625  Set_Color(1, SG_GET_RGB(255, 255, 255));
626  Set_Color(2, SG_GET_RGB(255, 0, 0));
627  break;
628 
630  Set_Count(3);
631  Set_Color(0, SG_GET_RGB( 0, 127, 0));
632  Set_Color(1, SG_GET_RGB(255, 255, 255));
633  Set_Color(2, SG_GET_RGB(255, 0, 0));
634  break;
635 
637  Set_Count(3);
638  Set_Color(0, SG_GET_RGB( 0, 127, 0));
639  Set_Color(1, SG_GET_RGB(255, 255, 255));
640  Set_Color(2, SG_GET_RGB( 0, 0, 255));
641  break;
642 
643  //-----------------------------------------------------
645  Set_Count(3);
646  Set_Color(0, SG_GET_RGB( 0, 0, 127));
647  Set_Color(1, SG_GET_RGB(191, 191, 191));
648  Set_Color(2, SG_GET_RGB(127, 0, 0));
649  break;
650 
652  Set_Count(5);
653  Set_Color(0, SG_GET_RGB(127, 0, 0));
654  Set_Color(1, SG_GET_RGB(255, 127, 0));
655  Set_Color(2, SG_GET_RGB(239, 239, 239));
656  Set_Color(3, SG_GET_RGB( 0, 127, 255));
657  Set_Color(4, SG_GET_RGB( 0, 0, 127));
658  break;
659 
661  Set_Count(3);
662  Set_Color(0, SG_GET_RGB( 0, 127, 0));
663  Set_Color(1, SG_GET_RGB(191, 191, 191));
664  Set_Color(2, SG_GET_RGB(127, 0, 0));
665  break;
666 
668  Set_Count(5);
669  Set_Color(0, SG_GET_RGB(127, 0, 0));
670  Set_Color(1, SG_GET_RGB(255, 127, 0));
671  Set_Color(2, SG_GET_RGB(239, 239, 239));
672  Set_Color(3, SG_GET_RGB( 0, 255, 127));
673  Set_Color(4, SG_GET_RGB( 0, 127, 0));
674  break;
675 
677  Set_Count(5);
678  Set_Color(0, SG_GET_RGB( 0, 127, 0));
679  Set_Color(1, SG_GET_RGB(127, 255, 0));
680  Set_Color(2, SG_GET_RGB(191, 191, 191));
681  Set_Color(3, SG_GET_RGB( 0, 127, 255));
682  Set_Color(4, SG_GET_RGB( 0, 0, 127));
683  break;
684 
685  //-----------------------------------------------------
687  Set_Count(3);
688  Set_Color(0, SG_GET_RGB( 0, 0, 255));
689  Set_Color(1, SG_GET_RGB(255, 255, 0));
690  Set_Color(2, SG_GET_RGB(255, 0, 0));
691  break;
692 
694  Set_Count(3);
695  Set_Color(0, SG_GET_RGB( 0, 127, 0));
696  Set_Color(1, SG_GET_RGB(255, 255, 0));
697  Set_Color(2, SG_GET_RGB(255, 0, 0));
698  break;
699 
701  Set_Count(3);
702  Set_Color(0, SG_GET_RGB(200, 0, 0));
703  Set_Color(1, SG_GET_RGB(255, 255, 127));
704  Set_Color(2, SG_GET_RGB( 0, 63, 0));
705  break;
706 
708  Set_Count(3);
709  Set_Color(0, SG_GET_RGB( 0, 127, 0));
710  Set_Color(1, SG_GET_RGB(255, 255, 0));
711  Set_Color(2, SG_GET_RGB( 0, 0, 255));
712  break;
713 
714  //-----------------------------------------------------
716  Set_Count(5);
717  Set_Color(0, SG_GET_RGB(127, 0, 127));
718  Set_Color(1, SG_GET_RGB(255, 0, 0));
719  Set_Color(2, SG_GET_RGB( 0, 255, 0));
720  Set_Color(3, SG_GET_RGB( 0, 0, 255));
721  Set_Color(4, SG_GET_RGB(127, 0, 127));
722  break;
723 
725  Set_Count(5);
726  Set_Color(0, SG_GET_RGB(127, 127, 0));
727  Set_Color(1, SG_GET_RGB(255, 0, 0));
728  Set_Color(2, SG_GET_RGB( 0, 0, 255));
729  Set_Color(3, SG_GET_RGB( 0, 255, 0));
730  Set_Color(4, SG_GET_RGB(127, 127, 0));
731  break;
732 
734  Set_Count(5);
735  Set_Color(0, SG_GET_RGB( 0, 127, 127));
736  Set_Color(1, SG_GET_RGB( 0, 255, 0));
737  Set_Color(2, SG_GET_RGB(255, 0, 0));
738  Set_Color(3, SG_GET_RGB( 0, 0, 255));
739  Set_Color(4, SG_GET_RGB( 0, 127, 127));
740  break;
741 
742  case SG_COLORS_NEON:
743  Set_Count(7);
744  Set_Color(0, SG_GET_RGB( 0, 0, 0));
745  Set_Color(1, SG_GET_RGB(255, 0, 0));
746  Set_Color(2, SG_GET_RGB( 0, 0, 0));
747  Set_Color(3, SG_GET_RGB(255, 255, 0));
748  Set_Color(4, SG_GET_RGB( 0, 0, 0));
749  Set_Color(5, SG_GET_RGB( 0, 255, 0));
750  Set_Color(6, SG_GET_RGB( 0, 0, 0));
751  break;
752 
753  //-----------------------------------------------------
755  Set_Count(5);
756  Set_Color(0, SG_GET_RGB( 0, 143, 127));
757  Set_Color(1, SG_GET_RGB(127, 255, 0));
758  Set_Color(2, SG_GET_RGB(255, 255, 127));
759  Set_Color(3, SG_GET_RGB(255, 192, 0));
760  Set_Color(4, SG_GET_RGB(192, 143, 0));
761  break;
762 
764  Set_Count(3);
765  Set_Color(0, SG_GET_RGB( 0, 128, 0));
766  Set_Color(1, SG_GET_RGB(255, 255, 127));
767  Set_Color(2, SG_GET_RGB(127, 63, 63));
768  break;
769 
771  Set_Count(6);
772  Set_Color(0, SG_GET_RGB( 0, 191, 191));
773  Set_Color(1, SG_GET_RGB( 0, 255, 0));
774  Set_Color(2, SG_GET_RGB(255, 255, 0));
775  Set_Color(3, SG_GET_RGB(255, 127, 0));
776  Set_Color(4, SG_GET_RGB(191, 152, 110));
777  Set_Color(5, SG_GET_RGB(199, 199, 199));
778  break;
779 
781  Set_Count(9);
782  Set_Color(0, SG_GET_RGB(177, 242, 212));
783  Set_Color(1, SG_GET_RGB(248, 252, 179));
784  Set_Color(2, SG_GET_RGB( 11, 128, 064));
785  Set_Color(3, SG_GET_RGB(248, 202, 80));
786  Set_Color(4, SG_GET_RGB(158, 30, 0));
787  Set_Color(5, SG_GET_RGB(128, 064, 064));
788  Set_Color(6, SG_GET_RGB(185, 121, 076));
789  Set_Color(7, SG_GET_RGB(179, 179, 179));
790  Set_Color(8, SG_GET_RGB(255, 255, 255));
791  break;
792 
793  //-----------------------------------------------------
794  case SG_COLORS_ASPECT_1:
795  Set_Count(5);
796  Set_Color(0, SG_GET_RGB(225, 225, 225));
797  Set_Color(1, SG_GET_RGB(127, 127, 255));
798  Set_Color(2, SG_GET_RGB( 20, 20, 20));
799  Set_Color(3, SG_GET_RGB(127, 255, 127));
800  Set_Color(4, SG_GET_RGB(225, 225, 225));
801  break;
802 
803  case SG_COLORS_ASPECT_2:
804  Set_Count(5);
805  Set_Color(0, SG_GET_RGB(225, 225, 225));
806  Set_Color(1, SG_GET_RGB(255, 127, 127));
807  Set_Color(2, SG_GET_RGB( 20, 20, 20));
808  Set_Color(3, SG_GET_RGB(127, 255, 127));
809  Set_Color(4, SG_GET_RGB(225, 225, 225));
810  break;
811 
812  case SG_COLORS_ASPECT_3:
813  Set_Count(5);
814  Set_Color(0, SG_GET_RGB(225, 225, 225));
815  Set_Color(1, SG_GET_RGB(255, 127, 127));
816  Set_Color(2, SG_GET_RGB( 20, 20, 20));
817  Set_Color(3, SG_GET_RGB(127, 127, 255));
818  Set_Color(4, SG_GET_RGB(225, 225, 225));
819  break;
820 
821  //-----------------------------------------------------
822  case SG_COLORS_THERMAL_1:
823  Set_Count(5);
824  Set_Color(0, SG_GET_RGB( 0, 0, 191));
825  Set_Color(1, SG_GET_RGB(255, 0, 255));
826  Set_Color(2, SG_GET_RGB(255, 0, 0));
827  Set_Color(3, SG_GET_RGB(255, 255, 0));
828  Set_Color(4, SG_GET_RGB(245, 245, 163));
829  break;
830 
831  case SG_COLORS_THERMAL_2:
832  Set_Count(6);
833  Set_Color(0, SG_GET_RGB(127, 255, 255));
834  Set_Color(1, SG_GET_RGB( 0, 0, 255));
835  Set_Color(2, SG_GET_RGB(127, 0, 255));
836  Set_Color(3, SG_GET_RGB(255, 0, 0));
837  Set_Color(4, SG_GET_RGB(255, 255, 0));
838  Set_Color(5, SG_GET_RGB(255, 255, 127));
839  break;
840 
841  //-----------------------------------------------------
843  Set_Count(5);
844  Set_Color(0, SG_GET_RGB(255, 255, 127));
845  Set_Color(1, SG_GET_RGB(191, 255, 0));
846  Set_Color(2, SG_GET_RGB( 0, 191, 0));
847  Set_Color(3, SG_GET_RGB( 0, 127, 255));
848  Set_Color(4, SG_GET_RGB( 0, 0, 127));
849  break;
850 
851  case SG_COLORS_PRECIPITATION_2: // juergen's favorite precipitation colour ramp
852  Set_Count(22);
853  Set_Color( 0, SG_GET_RGB(216, 204, 131));
854  Set_Color( 1, SG_GET_RGB(196, 208, 111));
855  Set_Color( 2, SG_GET_RGB(184, 210, 101));
856  Set_Color( 3, SG_GET_RGB(172, 212, 91));
857  Set_Color( 4, SG_GET_RGB(139, 212, 99));
858  Set_Color( 5, SG_GET_RGB(107, 212, 107));
859  Set_Color( 6, SG_GET_RGB( 75, 212, 119));
860  Set_Color( 7, SG_GET_RGB( 42, 212, 131));
861  Set_Color( 8, SG_GET_RGB( 26, 212, 151));
862  Set_Color( 9, SG_GET_RGB( 10, 212, 172));
863  Set_Color(10, SG_GET_RGB( 30, 192, 192));
864  Set_Color(11, SG_GET_RGB( 50, 172, 212));
865  Set_Color(12, SG_GET_RGB( 70, 151, 214));
866  Set_Color(13, SG_GET_RGB( 91, 131, 216));
867  Set_Color(14, SG_GET_RGB( 75, 115, 198));
868  Set_Color(15, SG_GET_RGB( 58, 99, 180));
869  Set_Color(16, SG_GET_RGB( 42, 83, 184));
870  Set_Color(17, SG_GET_RGB( 26, 066, 188));
871  Set_Color(18, SG_GET_RGB( 26, 046, 180));
872  Set_Color(19, SG_GET_RGB( 26, 026, 166));
873  Set_Color(20, SG_GET_RGB( 38, 18, 151));
874  Set_Color(21, SG_GET_RGB( 50, 010, 131));
875  break;
876 
878  Set_Count(10);
879  Set_Color( 0, SG_GET_RGB(255, 255, 185));
880  Set_Color( 1, SG_GET_RGB(229, 253, 139));
881  Set_Color( 2, SG_GET_RGB(204, 252, 94));
882  Set_Color( 3, SG_GET_RGB(178, 251, 49));
883  Set_Color( 4, SG_GET_RGB(153, 251, 0));
884  Set_Color( 5, SG_GET_RGB(128, 212, 43));
885  Set_Color( 6, SG_GET_RGB( 96, 159, 88));
886  Set_Color( 7, SG_GET_RGB( 64, 106, 133));
887  Set_Color( 8, SG_GET_RGB( 32, 53, 179));
888  Set_Color( 9, SG_GET_RGB( 0, 0, 123));
889  break;
890 
892  Set_Count(10);
893  Set_Color( 0, SG_GET_RGB(255, 255, 200));
894  Set_Color( 1, SG_GET_RGB(227, 254, 145));
895  Set_Color( 2, SG_GET_RGB(160, 254, 125));
896  Set_Color( 3, SG_GET_RGB( 93, 254, 168));
897  Set_Color( 4, SG_GET_RGB(027, 237, 211));
898  Set_Color( 5, SG_GET_RGB( 0, 191, 254));
899  Set_Color( 6, SG_GET_RGB( 0, 146, 245));
900  Set_Color( 7, SG_GET_RGB( 0, 100, 210));
901  Set_Color( 8, SG_GET_RGB( 0, 55, 176));
902  Set_Color( 9, SG_GET_RGB( 62, 0, 142));
903  break;
904 
906  Set_Count(10);
907  Set_Color( 0, SG_GET_RGB(254, 135, 000));
908  Set_Color( 1, SG_GET_RGB(254, 194, 063));
909  Set_Color( 2, SG_GET_RGB(254, 254, 126));
910  Set_Color( 3, SG_GET_RGB(231, 231, 227));
911  Set_Color( 4, SG_GET_RGB(132, 222, 254));
912  Set_Color( 5, SG_GET_RGB(042, 163, 239));
913  Set_Color( 6, SG_GET_RGB(000, 105, 224));
914  Set_Color( 7, SG_GET_RGB(000, 047, 210));
915  Set_Color( 8, SG_GET_RGB(000, 001, 156));
916  Set_Color( 9, SG_GET_RGB(000, 000, 103));
917  break;
918 
919  //-----------------------------------------------------
921  Set_Count(5);
922  Set_Color(0, SG_GET_RGB(255, 252, 158));
923  Set_Color(1, SG_GET_RGB(192, 212, 100));
924  Set_Color(2, SG_GET_RGB(128, 172, 58));
925  Set_Color(3, SG_GET_RGB( 64, 132, 88));
926  Set_Color(4, SG_GET_RGB( 0, 94, 118));
927  break;
928 
929  //-----------------------------------------------------
931  Set_Count(11);
932  Set_Color( 0, SG_GET_RGB( 37, 57, 175));
933  Set_Color( 1, SG_GET_RGB( 40, 127, 251));
934  Set_Color( 2, SG_GET_RGB( 50, 190, 255));
935  Set_Color( 3, SG_GET_RGB(106, 235, 255));
936  Set_Color( 4, SG_GET_RGB(138, 236, 174));
937  Set_Color( 5, SG_GET_RGB(205, 255, 162));
938  Set_Color( 6, SG_GET_RGB(240, 236, 121));
939  Set_Color( 7, SG_GET_RGB(255, 189, 87));
940  Set_Color( 8, SG_GET_RGB(255, 161, 68));
941  Set_Color( 9, SG_GET_RGB(255, 186, 133));
942  Set_Color(10, SG_GET_RGB(255, 255, 255));
943  break;
944 
946  Set_Count(8);
947  Set_Color(0, SG_GET_RGB(171, 43, 0));
948  Set_Color(1, SG_GET_RGB(255, 127, 0));
949  Set_Color(2, SG_GET_RGB(255, 255, 0));
950  Set_Color(3, SG_GET_RGB( 0, 255, 0));
951  Set_Color(4, SG_GET_RGB( 0, 255, 255));
952  Set_Color(5, SG_GET_RGB( 0, 0, 255));
953  Set_Color(6, SG_GET_RGB(255, 0, 255));
954  Set_Color(7, SG_GET_RGB(255, 255, 255));
955  break;
956 
958  Set_Count(9);
959  Set_Color(0, SG_GET_RGB(000, 001, 205));
960  Set_Color(1, SG_GET_RGB(000, 132, 254));
961  Set_Color(1, SG_GET_RGB(000, 227, 254));
962  Set_Color(1, SG_GET_RGB(001, 167, 076));
963  Set_Color(1, SG_GET_RGB(118, 218, 076));
964  Set_Color(1, SG_GET_RGB(186, 255, 127));
965  Set_Color(1, SG_GET_RGB(254, 244, 152));
966  Set_Color(1, SG_GET_RGB(254, 203, 128));
967  Set_Color(1, SG_GET_RGB(254, 172, 000));
968  break;
969 
970  //-----------------------------------------------------
971 // case SG_COLORS_COUNT:
972 // Set_Count(nColors);
973 // Random();
974 // break;
975 
976  default:
977  return( false );
978  }
979 
980  //-----------------------------------------------------
981  if( bRevert )
982  {
983  Revert();
984  }
985 
986  if( nColors > 0 )
987  {
988  Set_Count(nColors);
989  }
990 
991  return( true );
992 }
993 
994 //---------------------------------------------------------
995 bool CSG_Colors::Set_Default(int nColors)
996 {
997  if( nColors > 1 )
998  {
999  m_nColors = nColors;
1000  m_Colors = (long *)SG_Realloc(m_Colors, m_nColors * sizeof(long));
1001 
1002  double d = 0., dStep = 2. * M_PI / (m_nColors - 1.);
1003 
1004  for(int i=0; i<m_nColors; i++, d+=dStep)
1005  {
1006  Set_Color(i,
1007  (int)(d < M_PI / 2 ? 0 : 128 - 127 * sin(M_PI - d)),
1008  (int)(128 - 127 * cos(d)),
1009  (int)(d > M_PI * 3 / 2 ? 0 : 128 + 127 * sin(d))
1010  );
1011  }
1012 
1013  return( true );
1014  }
1015 
1016  return( false );
1017 }
1018 
1019 //---------------------------------------------------------
1020 bool CSG_Colors::Set_Ramp(long Color_A, long Color_B)
1021 {
1022  return( Set_Ramp(Color_A, Color_B, 0, Get_Count() - 1) );
1023 }
1024 
1025 //---------------------------------------------------------
1026 bool CSG_Colors::Set_Ramp(long Color_A, long Color_B, int iColor_A, int iColor_B)
1027 {
1028  if( iColor_A > iColor_B )
1029  {
1030  int i = iColor_A;
1031  iColor_A = iColor_B;
1032  iColor_B = i;
1033  }
1034 
1035  if( iColor_A < 0 )
1036  {
1037  iColor_A = 0;
1038  }
1039 
1040  if( iColor_B >= Get_Count() )
1041  {
1042  iColor_B = Get_Count() - 1;
1043  }
1044 
1045  //-----------------------------------------------------
1046  int n = iColor_B - iColor_A;
1047 
1048  if( n > 0 )
1049  {
1050  int ar = SG_GET_R(Color_A);
1051  double dr = (double)(SG_GET_R(Color_B) - ar) / (double)n;
1052 
1053  int ag = SG_GET_G(Color_A);
1054  double dg = (double)(SG_GET_G(Color_B) - ag) / (double)n;
1055 
1056  int ab = SG_GET_B(Color_A);
1057  double db = (double)(SG_GET_B(Color_B) - ab) / (double)n;
1058 
1059  for(int i=0; i<=n; i++)
1060  {
1061  Set_Color(iColor_A + i,
1062  (int)(ar + i * dr),
1063  (int)(ag + i * dg),
1064  (int)(ab + i * db)
1065  );
1066  }
1067 
1068  return( true );
1069  }
1070 
1071  return( false );
1072 }
1073 
1074 //---------------------------------------------------------
1075 bool CSG_Colors::Set_Ramp_Brighness(int Brightness_A, int Brightness_B)
1076 {
1077  return( Set_Ramp_Brighness(Brightness_A, Brightness_B, 0, Get_Count() - 1) );
1078 }
1079 
1080 //---------------------------------------------------------
1081 bool CSG_Colors::Set_Ramp_Brighness(int Brightness_A, int Brightness_B, int iColor_A, int iColor_B)
1082 {
1083  if( iColor_A > iColor_B )
1084  {
1085  int i = iColor_A;
1086  iColor_A = iColor_B;
1087  iColor_B = i;
1088  }
1089 
1090  if( iColor_A < 0 )
1091  {
1092  iColor_A = 0;
1093  }
1094 
1095  if( iColor_B >= Get_Count() )
1096  {
1097  iColor_B = Get_Count() - 1;
1098  }
1099 
1100  //-----------------------------------------------------
1101  int n = iColor_B - iColor_A;
1102 
1103  if( n > 0 )
1104  {
1105  double dBrightness = (double)(Brightness_B - Brightness_A) / (double)n;
1106 
1107  for(int i=0; i<=n; i++)
1108  {
1109  Set_Brightness(iColor_A + i, (int)(Brightness_A + i * dBrightness));
1110  }
1111 
1112  return( true );
1113  }
1114 
1115  return( false );
1116 }
1117 
1118 
1120 // //
1122 
1123 //---------------------------------------------------------
1125 {
1126  for(int i=0; i<Get_Count(); i++)
1127  {
1128  Set_Color(i,
1129  (int)(255.0 * (double)rand() / (double)RAND_MAX),
1130  (int)(255.0 * (double)rand() / (double)RAND_MAX),
1131  (int)(255.0 * (double)rand() / (double)RAND_MAX)
1132  );
1133  }
1134 
1135  return( Get_Count() > 0 );
1136 }
1137 
1138 //---------------------------------------------------------
1140 {
1141  for(int i=0; i<Get_Count(); i++)
1142  {
1143  Set_Color(i, 255 - Get_Red(i), 255 - Get_Green(i), 255 - Get_Blue(i));
1144  }
1145 
1146  return( Get_Count() > 0 );
1147 }
1148 
1149 //---------------------------------------------------------
1151 {
1152  for(int i=0, j=Get_Count()-1; i<j; i++, j--)
1153  {
1154  long c = Get_Color(j);
1155  Set_Color(j, Get_Color(i));
1156  Set_Color(i, c);
1157  }
1158 
1159  return( Get_Count() > 0 );
1160 }
1161 
1162 //---------------------------------------------------------
1164 {
1165  for(int i=0; i<Get_Count(); i++)
1166  {
1167  long c = Get_Brightness(i);
1168 
1169  Set_Color(i, c, c, c);
1170  }
1171 
1172  return( Get_Count() > 0 );
1173 }
1174 
1175 
1177 // //
1179 
1180 //---------------------------------------------------------
1182 {
1183  Create(Colors);
1184 
1185  return( *this );
1186 }
1187 
1188 //---------------------------------------------------------
1189 bool CSG_Colors::Assign(const CSG_Colors &Colors)
1190 {
1191  return( Create(Colors) );
1192 }
1193 
1194 //---------------------------------------------------------
1196 {
1197  return( pColors ? Create(*pColors) : false );
1198 }
1199 
1200 
1202 // //
1204 
1205 //---------------------------------------------------------
1206 #define COLORS_SERIAL_VERSION_BINARY "SAGA_COLORPALETTE_VERSION_0.100_BINARY"
1207 #define COLORS_SERIAL_VERSION__ASCII "SAGA_COLORPALETTE_VERSION_0.100__ASCII"
1208 
1209 //---------------------------------------------------------
1210 bool CSG_Colors::Load(const CSG_String &File_Name)
1211 {
1212  CSG_File Stream;
1213 
1214  if( !Stream.Open(File_Name, SG_FILE_R, true) )
1215  {
1216  return( false );
1217  }
1218 
1219  CSG_String Version;
1220 
1221  Stream.Read(Version, sizeof(COLORS_SERIAL_VERSION__ASCII));
1222 
1223  //-----------------------------------------------------
1224  if( Version.Find(COLORS_SERIAL_VERSION__ASCII) == 0 )
1225  {
1226  return( Serialize(Stream, false, false) );
1227  }
1228 
1229  //-----------------------------------------------------
1230  Stream.Seek_Start();
1231  Stream.Read(Version, sizeof(COLORS_SERIAL_VERSION_BINARY));
1232 
1233  if( Version.Find(COLORS_SERIAL_VERSION_BINARY) == 0 )
1234  {
1235  int nColors;
1236 
1237  Stream.Read(&nColors, sizeof(nColors));
1238 
1239  if( Set_Count(nColors) ) // different os, different sizeof(long) !!
1240  {
1241  size_t ValueSize = (size_t)((Stream.Length() - (sizeof(COLORS_SERIAL_VERSION_BINARY) + sizeof(int))) / nColors);
1242 
1243  if( ValueSize > 0 )
1244  {
1245  BYTE *c = (BYTE *)SG_Malloc(ValueSize);
1246 
1247  for(int i=0; i<nColors; i++)
1248  {
1249  Stream.Read(c, ValueSize);
1250 
1251  Set_Color(i, c[0], c[1], c[2]);
1252  }
1253 
1254  SG_Free(c);
1255  }
1256 
1257  return( true );
1258  }
1259  }
1260 
1261  //-----------------------------------------------------
1262  else // SAGA 1.x compatibility...
1263  {
1264  short nColors;
1265 
1266  Stream.Seek_Start();
1267  Stream.Read(&nColors, sizeof(short));
1268 
1269  if( Stream.Length() == (int)(sizeof(short) + 3 * nColors) && Set_Count(nColors) )
1270  {
1271  BYTE *R = (BYTE *)SG_Malloc(nColors * sizeof(BYTE)); Stream.Read(R, nColors * sizeof(BYTE));
1272  BYTE *G = (BYTE *)SG_Malloc(nColors * sizeof(BYTE)); Stream.Read(G, nColors * sizeof(BYTE));
1273  BYTE *B = (BYTE *)SG_Malloc(nColors * sizeof(BYTE)); Stream.Read(B, nColors * sizeof(BYTE));
1274 
1275  for(int i=0; i<nColors; i++)
1276  {
1277  Set_Color(i, R[i], G[i], B[i]);
1278  }
1279 
1280  SG_Free(R); SG_Free(G); SG_Free(B);
1281 
1282  return( true );
1283  }
1284  }
1285 
1286  //-----------------------------------------------------
1287  return( false );
1288 }
1289 
1290 //---------------------------------------------------------
1291 bool CSG_Colors::Save(const CSG_String &File_Name, bool bBinary)
1292 {
1293  CSG_File Stream;
1294 
1295  if( Stream.Open(File_Name, SG_FILE_W, bBinary) )
1296  {
1297  if( bBinary )
1298  {
1300  }
1301  else
1302  {
1303  Stream.Write(COLORS_SERIAL_VERSION__ASCII); Stream.Write("\n");
1304  }
1305 
1306  Serialize(Stream, true, bBinary);
1307 
1308  return( true );
1309  }
1310 
1311  return( false );
1312 }
1313 
1314 
1316 // //
1318 
1319 //---------------------------------------------------------
1320 bool CSG_Colors::Serialize(CSG_File &Stream, bool bSave, bool bBinary)
1321 {
1322  if( Stream.is_Open() )
1323  {
1324  //-------------------------------------------------
1325  if( bBinary )
1326  {
1327  if( bSave )
1328  {
1329  if( m_nColors > 0 )
1330  {
1331  Stream.Write(&m_nColors, sizeof(m_nColors));
1332  Stream.Write(m_Colors, sizeof(long), m_nColors);
1333  }
1334  }
1335  else
1336  {
1337  int nColors;
1338 
1339  Stream.Read(&nColors, sizeof(m_nColors));
1340 
1341  if( Set_Count(nColors) )
1342  {
1343  Stream.Read(m_Colors, sizeof(long), m_nColors);
1344  }
1345  }
1346 
1347  return( true );
1348  }
1349 
1350  //-------------------------------------------------
1351  else
1352  {
1353  if( bSave )
1354  {
1355  if( Get_Count() > 0 )
1356  {
1357  Stream.Printf("%d\n", Get_Count());
1358 
1359  for(int i=0; i<Get_Count(); i++)
1360  {
1361  Stream.Printf("%03d %03d %03d\n", (int)Get_Red(i), (int)Get_Green(i), (int)Get_Blue(i));
1362  }
1363  }
1364  }
1365  else
1366  {
1367  CSG_String sLine;
1368 
1369  while( Stream.Read_Line(sLine) && sLine.is_Empty() ) {} // skip empty lines
1370 
1371  if( Set_Count(sLine.asInt()) )
1372  {
1373  for(int i=0; i<Get_Count(); i++)
1374  {
1375  Stream.Read_Line(sLine);
1376 
1377  Set_Color(i,
1378  sLine .asInt(),
1379  sLine.AfterFirst(' ').asInt(),
1380  sLine.AfterLast (' ').asInt()
1381  );
1382  }
1383  }
1384  }
1385 
1386  return( true );
1387  }
1388  }
1389 
1390  return( false );
1391 }
1392 
1393 //---------------------------------------------------------
1395 {
1396  if( Get_Count() > 0 )
1397  {
1398  String.Clear();
1399 
1400  for(int i=0; i<Get_Count(); i++)
1401  {
1402  String += CSG_String::Format("%03d %03d %03d;", (int)Get_Red(i), (int)Get_Green(i), (int)Get_Blue(i));
1403  }
1404 
1405  return( true );
1406  }
1407 
1408  return( false );
1409 }
1410 
1411 //---------------------------------------------------------
1413 {
1414  if( Set_Count((int)String.Length() / 12) )
1415  {
1416  for(int i=0, j=0; i<Get_Count(); i++, j+=12)
1417  {
1418  Set_Color(i,
1419  String.Mid(j + 0, 4).asInt(),
1420  String.Mid(j + 4, 4).asInt(),
1421  String.Mid(j + 8, 4).asInt()
1422  );
1423  }
1424 
1425  return( true );
1426  }
1427 
1428  return( false );
1429 }
1430 
1431 
1433 // //
1434 // //
1435 // //
1437 
1438 //---------------------------------------------------------
SG_COLORS_RAINBOW_2
@ SG_COLORS_RAINBOW_2
Definition: api_core.h:1332
CSG_Colors::Set_Brightness
bool Set_Brightness(int Index, int Value)
Definition: api_colors.cpp:339
CSG_Colors::Set_Color
bool Set_Color(int Index, long Color)
Definition: api_colors.cpp:302
CSG_Colors::from_Text
bool from_Text(const CSG_String &String)
Definition: api_colors.cpp:1412
SG_GET_RGB
#define SG_GET_RGB(r, g, b)
Definition: api_core.h:1297
SG_COLORS_RED_BLUE_GREEN
@ SG_COLORS_RED_BLUE_GREEN
Definition: api_core.h:1367
CSG_String::Printf
int Printf(const char *Format,...)
Definition: api_string.cpp:308
CSG_File::Seek_Start
bool Seek_Start(void) const
Definition: api_file.cpp:261
_TL
#define _TL(s)
Definition: api_core.h:1559
CSG_Colors::Greyscale
bool Greyscale(void)
Definition: api_colors.cpp:1163
SG_GET_B
#define SG_GET_B(rgb)
Definition: api_core.h:1302
CSG_String::Length
size_t Length(void) const
Definition: api_string.cpp:172
SG_Color_From_Text
bool SG_Color_From_Text(const CSG_String &Text, long &Color)
Definition: api_colors.cpp:85
SG_Colors_Get_Name
CSG_String SG_Colors_Get_Name(int Index)
Definition: api_colors.cpp:67
CSG_String::b_str
const char * b_str(void) const
Definition: api_string.cpp:242
CSG_Colors::Load
bool Load(const CSG_String &File_Name)
Definition: api_colors.cpp:1210
SG_COLORS_GREEN_BLUE
@ SG_COLORS_GREEN_BLUE
Definition: api_core.h:1349
SG_COLORS_VEGETATION
@ SG_COLORS_VEGETATION
Definition: api_core.h:1389
CSG_Colors::Revert
bool Revert(void)
Definition: api_colors.cpp:1150
CSG_String::Mid
CSG_String Mid(size_t first, size_t count=0) const
Definition: api_string.cpp:746
CSG_Colors::Set_Palette
bool Set_Palette(int Index, bool bRevert=false, int nColors=0)
Definition: api_core.h:1459
SG_COLORS_RED_GREY_BLUE
@ SG_COLORS_RED_GREY_BLUE
Definition: api_core.h:1356
CSG_Colors::Get_Predefined_Name
static CSG_String Get_Predefined_Name(int Identifier)
Definition: api_colors.cpp:432
CSG_Colors::Get_Blue
long Get_Blue(int Index) const
Definition: api_core.h:1439
CSG_Colors::Destroy
void Destroy(void)
Definition: api_colors.cpp:238
CSG_String::asInt
int asInt(void) const
Definition: api_string.cpp:769
SG_COLORS_BLACK_BLUE
@ SG_COLORS_BLACK_BLUE
Definition: api_core.h:1337
CSG_Random::Get_Uniform
static double Get_Uniform(void)
Definition: mat_tools.cpp:274
SG_Malloc
SAGA_API_DLL_EXPORT void * SG_Malloc(size_t size)
Definition: api_memory.cpp:65
SG_COLORS_SPECTRUM_1
@ SG_COLORS_SPECTRUM_1
Definition: api_core.h:1391
CSG_Colors::Invert
bool Invert(void)
Definition: api_colors.cpp:1139
SG_COLORS_SPECTRUM_2
@ SG_COLORS_SPECTRUM_2
Definition: api_core.h:1392
SG_Color_Get_Random
long SG_Color_Get_Random(void)
Definition: api_colors.cpp:73
SG_COLORS_TOPOGRAPHY
@ SG_COLORS_TOPOGRAPHY
Definition: api_core.h:1371
CSG_String::Get_Char
SG_Char Get_Char(size_t i) const
Definition: api_string.cpp:209
api_core.h
SG_COLORS_WHITE_GREEN
@ SG_COLORS_WHITE_GREEN
Definition: api_core.h:1340
SG_COLORS_GREEN_WHITE_BLUE
@ SG_COLORS_GREEN_WHITE_BLUE
Definition: api_core.h:1353
SG_COLORS_RAINBOW
@ SG_COLORS_RAINBOW
Definition: api_core.h:1331
SG_COLORS_BLACK_RED
@ SG_COLORS_BLACK_RED
Definition: api_core.h:1335
SG_COLORS_BLUE_WHITE_RED
@ SG_COLORS_BLUE_WHITE_RED
Definition: api_core.h:1351
SG_Free
SAGA_API_DLL_EXPORT void SG_Free(void *memblock)
Definition: api_memory.cpp:83
SG_COLORS_PRECIPITATION_4
@ SG_COLORS_PRECIPITATION_4
Definition: api_core.h:1386
SG_FILE_R
@ SG_FILE_R
Definition: api_core.h:1114
CSG_Colors::Set_Blue
bool Set_Blue(int Index, int Value)
Definition: api_colors.cpp:333
CSG_Colors::Get_Red
long Get_Red(int Index) const
Definition: api_core.h:1437
SG_COLORS_ASPECT_2
@ SG_COLORS_ASPECT_2
Definition: api_core.h:1377
SG_COLORS_PRECIPITATION_1
@ SG_COLORS_PRECIPITATION_1
Definition: api_core.h:1383
CSG_File::Read
size_t Read(void *Buffer, size_t Size, size_t Count=1) const
Definition: api_file.cpp:338
CSG_Colors::Set_Ramp
bool Set_Ramp(long Color_A, long Color_B)
Definition: api_colors.cpp:1020
CSG_File
Definition: api_core.h:1129
SG_COLORS_SPECTRUM_3
@ SG_COLORS_SPECTRUM_3
Definition: api_core.h:1393
SG_GET_R
#define SG_GET_R(rgb)
Definition: api_core.h:1300
SG_COLORS_NEON
@ SG_COLORS_NEON
Definition: api_core.h:1369
mat_tools.h
CSG_Colors::Get_Predefined_Count
static int Get_Predefined_Count(void)
Definition: api_colors.cpp:426
SG_COLORS_GREEN_GREY_RED
@ SG_COLORS_GREEN_GREY_RED
Definition: api_core.h:1357
COLORS_SERIAL_VERSION__ASCII
#define COLORS_SERIAL_VERSION__ASCII
Definition: api_colors.cpp:1207
SG_COLORS_YELLOW_BLUE
@ SG_COLORS_YELLOW_BLUE
Definition: api_core.h:1345
SG_COLORS_BLACK_WHITE
@ SG_COLORS_BLACK_WHITE
Definition: api_core.h:1334
SG_COLORS_YELLOW_RED
@ SG_COLORS_YELLOW_RED
Definition: api_core.h:1343
CSG_Colors::Get_Count
int Get_Count(void) const
Definition: api_core.h:1424
SG_COLORS_YELLOW_GREEN
@ SG_COLORS_YELLOW_GREEN
Definition: api_core.h:1344
CSG_Colors::Create
bool Create(void)
Definition: api_colors.cpp:210
CSG_Colors::Get_Color
long Get_Color(int Index) const
Definition: api_core.h:1436
SG_COLORS_GREEN_YELLOW_RED
@ SG_COLORS_GREEN_YELLOW_RED
Definition: api_core.h:1362
SG_GET_G
#define SG_GET_G(rgb)
Definition: api_core.h:1301
SG_COLORS_DEFAULT
@ SG_COLORS_DEFAULT
Definition: api_core.h:1329
CSG_Colors::Set_Red
bool Set_Red(int Index, int Value)
Definition: api_colors.cpp:321
SG_Color_From_RGB
long SG_Color_From_RGB(int Red, int Green, int Blue, int Alpha)
Definition: api_colors.cpp:79
SG_COLORS_ASPECT_1
@ SG_COLORS_ASPECT_1
Definition: api_core.h:1376
SG_COLORS_WHITE_BLUE
@ SG_COLORS_WHITE_BLUE
Definition: api_core.h:1341
CSG_Colors::Get_Interpolated
long Get_Interpolated(double Index) const
Definition: api_core.h:1442
MAKE_NAME
#define MAKE_NAME(name)
CSG_File::Open
virtual bool Open(const SG_Char *FileName, int Mode=SG_FILE_R, bool bBinary=true, int Encoding=SG_FILE_ENCODING_ANSI)
Definition: api_file.cpp:113
SG_COLORS_GREEN_RED
@ SG_COLORS_GREEN_RED
Definition: api_core.h:1348
CSG_Colors::Set_Green
bool Set_Green(int Index, int Value)
Definition: api_colors.cpp:327
CSG_Colors::Set_Count
bool Set_Count(int nColors)
Definition: api_colors.cpp:255
SG_COLORS_DEFAULT_BRIGHT
@ SG_COLORS_DEFAULT_BRIGHT
Definition: api_core.h:1330
CSG_Colors::CSG_Colors
CSG_Colors(void)
Definition: api_colors.cpp:172
SG_Color_To_Text
CSG_String SG_Color_To_Text(long Color, bool bHexadecimal)
Definition: api_colors.cpp:144
SG_FILE_W
@ SG_FILE_W
Definition: api_core.h:1115
SG_COLORS_GREEN_YELLOW_BLUE
@ SG_COLORS_GREEN_YELLOW_BLUE
Definition: api_core.h:1364
CSG_Colors::Set_Predefined
bool Set_Predefined(int Index, bool bRevert=false, int nColors=0)
Definition: api_colors.cpp:509
CSG_File::is_Open
bool is_Open(void) const
Definition: api_core.h:1149
SG_COLORS_RED_YELLOW_GREEN
@ SG_COLORS_RED_YELLOW_GREEN
Definition: api_core.h:1363
SG_COLORS_BLACK_GREEN
@ SG_COLORS_BLACK_GREEN
Definition: api_core.h:1336
SG_COLORS_PRECIPITATION_3
@ SG_COLORS_PRECIPITATION_3
Definition: api_core.h:1385
CSG_Colors::operator=
CSG_Colors & operator=(const CSG_Colors &Colors)
Definition: api_colors.cpp:1181
SG_COLORS_BLUE_GREY_RED
@ SG_COLORS_BLUE_GREY_RED
Definition: api_core.h:1355
SG_COLORS_TOPOGRAPHY_4
@ SG_COLORS_TOPOGRAPHY_4
Definition: api_core.h:1374
CSG_String::Format
static CSG_String Format(const char *Format,...)
Definition: api_string.cpp:270
SG_COLORS_GREEN_GREY_BLUE
@ SG_COLORS_GREEN_GREY_BLUE
Definition: api_core.h:1359
SG_COLORS_THERMAL_1
@ SG_COLORS_THERMAL_1
Definition: api_core.h:1380
CSG_String::Find
int Find(char Character, bool fromEnd=false) const
Definition: api_string.cpp:663
SG_COLORS_TOPOGRAPHY_3
@ SG_COLORS_TOPOGRAPHY_3
Definition: api_core.h:1373
CSG_File::Length
sLong Length(void) const
Definition: api_file.cpp:230
CSG_Colors::Set_Default
bool Set_Default(int nColors=11)
Definition: api_colors.cpp:995
SG_COLORS_ASPECT_3
@ SG_COLORS_ASPECT_3
Definition: api_core.h:1378
SG_COLORS_RED_GREY_GREEN
@ SG_COLORS_RED_GREY_GREEN
Definition: api_core.h:1358
CSG_String::AfterFirst
CSG_String AfterFirst(char Character) const
Definition: api_string.cpp:691
CSG_String::Clear
void Clear(void)
Definition: api_string.cpp:259
COLORS_SERIAL_VERSION_BINARY
#define COLORS_SERIAL_VERSION_BINARY
Definition: api_colors.cpp:1206
CSG_Colors::Get_Brightness
long Get_Brightness(int Index) const
Definition: api_core.h:1440
M_PI
#define M_PI
Definition: mat_tools.h:96
B
#define B
CSG_String
Definition: api_core.h:563
SG_COLORS_PRECIPITATION_5
@ SG_COLORS_PRECIPITATION_5
Definition: api_core.h:1387
CSG_Colors::Get_Green
long Get_Green(int Index) const
Definition: api_core.h:1438
SG_COLORS_GREEN_WHITE_RED
@ SG_COLORS_GREEN_WHITE_RED
Definition: api_core.h:1352
CSG_Colors::Serialize
bool Serialize(CSG_File &Stream, bool bSave, bool bBinary)
Definition: api_colors.cpp:1320
CSG_File::Printf
int Printf(const char *Format,...)
Definition: api_file.cpp:287
CSG_String::is_Empty
bool is_Empty(void) const
Definition: api_string.cpp:178
CSG_Colors::to_Text
bool to_Text(CSG_String &String)
Definition: api_colors.cpp:1394
SG_COLORS_BLUE_YELLOW_RED
@ SG_COLORS_BLUE_YELLOW_RED
Definition: api_core.h:1361
SG_COLORS_COUNT
@ SG_COLORS_COUNT
Definition: api_core.h:1395
CSG_File::Read_Line
bool Read_Line(CSG_String &Line) const
Definition: api_file.cpp:399
CSG_String::AfterLast
CSG_String AfterLast(char Character) const
Definition: api_string.cpp:702
SG_COLORS_WHITE_RED
@ SG_COLORS_WHITE_RED
Definition: api_core.h:1339
SG_COLORS_THERMAL_2
@ SG_COLORS_THERMAL_2
Definition: api_core.h:1381
SG_COLORS_PRECIPITATION_2
@ SG_COLORS_PRECIPITATION_2
Definition: api_core.h:1384
SG_COLORS_RED_GREEN_BLUE
@ SG_COLORS_RED_GREEN_BLUE
Definition: api_core.h:1366
CSG_Colors::~CSG_Colors
virtual ~CSG_Colors(void)
Definition: api_colors.cpp:199
CSG_File::Write
size_t Write(void *Buffer, size_t Size, size_t Count=1) const
Definition: api_file.cpp:370
CSG_Colors::Random
bool Random(void)
Definition: api_colors.cpp:1124
SG_Realloc
SAGA_API_DLL_EXPORT void * SG_Realloc(void *memblock, size_t size)
Definition: api_memory.cpp:77
SG_COLORS_GREEN_RED_BLUE
@ SG_COLORS_GREEN_RED_BLUE
Definition: api_core.h:1368
CSG_Colors::Save
bool Save(const CSG_String &File_Name, bool bBinary)
Definition: api_colors.cpp:1291
SG_COLORS_BLUE_RED
@ SG_COLORS_BLUE_RED
Definition: api_core.h:1347
CSG_Colors::Assign
bool Assign(const CSG_Colors &Colors)
Definition: api_colors.cpp:1189
SG_COLORS_TOPOGRAPHY_2
@ SG_COLORS_TOPOGRAPHY_2
Definition: api_core.h:1372
SG_GET_RGBA
#define SG_GET_RGBA(r, g, b, a)
Definition: api_core.h:1298
CSG_Colors
Definition: api_core.h:1408
CSG_Colors::Set_Ramp_Brighness
bool Set_Ramp_Brighness(int Brightness_A, int Brightness_B)
Definition: api_colors.cpp:1075